1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//-------------------------------------------------------------------------
// Copyright Notice
//
// Copyright (c) 1996 
// by Malcolm J. Panthaki, DBA, and the University of New Mexico.
//-------------------------------------------------------------------------

//-------------------------------------------------------------------------
// Filename      : ModelEntity.cc
//
// Purpose       : 
//
// Special Notes :
//
// Creator       : Raikanta Sahu
//
// Creation Date : 10/15/96
//
// Owner         : Malcolm J. Panthaki
//-------------------------------------------------------------------------

// ********** BEGIN STANDARD INCLUDES         **********
// ********** END STANDARD INCLUDES           **********

// ********** BEGIN MOTIF INCLUDES            **********
// ********** END MOTIF INCLUDES              **********

// ********** BEGIN OPEN INVENTOR INCLUDES    **********
// ********** END OPEN INVENTOR INCLUDES      **********

// ********** BEGIN ACIS INCLUDES             **********
// ********** END ACIS INCLUDES               **********

// ********** BEGIN CUBIT INCLUDES            **********

#include "ModelEntity.hpp"
#include "ModelQueryEngine.hpp"
#include "GeometryQueryTool.hpp"
#include "CastTo.hpp"
#include "CubitObservable.hpp"
#include "CubitObserver.hpp"
#include "DAG.hpp"
#include "RefVolume.hpp"
#include "Loop.hpp"
#include "RefEdge.hpp"
#include "AppUtil.hpp"

// ********** END CUBIT INCLUDES              **********

// ********** BEGIN EXTERN DECLARATIONS       **********
// ********** END EXTERN DECLARATIONS         **********

// ********** BEGIN STATIC DECLARATIONS       **********
// ********** END STATIC DECLARATIONS         **********

// ********** BEGIN PUBLIC FUNCTIONS          **********

//-------------------------------------------------------------------------
// Purpose       : The default constructor
//
// Special Notes : 
//
// Creator       : Raikanta Sahu
//
// Creation Date : 10/15/96
//-------------------------------------------------------------------------

ModelEntity::ModelEntity() : 
    deactivatedStatus_(CUBIT_FALSE),
    encountered_(CUBIT_FALSE)
{
}

//-------------------------------------------------------------------------
// Purpose       : The destructor
//
// Special Notes :
//
// Creator       : Raikanta Sahu
//
// Creation Date : 10/15/96
//-------------------------------------------------------------------------

ModelEntity::~ModelEntity()
{
     // Make sure that the ModelEntity class does not have a pointer to this
     // ModelEntity in its list.  If it does, then remove the instances
     // of the pointer
   DAG::instance()->remove(this);
  
}


//-------------------------------------------------------------------------
// Purpose       : Determine whether this object can be deleted from
//                 memory or not.
//
// Special Notes : This function will recursively remove all the
//                 removable child entities from the DAG and call their
//                 destructors. Destructors of other objects, like
//                 GeometryEntity, need to be called from the destructors 
//                 of different ModEnts. Virtual destructors put to use :) :)
//
// Creator       : Raikanta Sahu
//
// Creation Date : 11/05/96
//-------------------------------------------------------------------------

CubitStatus ModelEntity::remove_from_DAG(CubitBoolean recurse_flag)
{
     // This counter will be used in the recursion to test whether
     // the call is from outside or from the function itself. When
     // the call comes from outside, the counter should always be
     // zero.

  CubitBoolean this_recurse = recurse_flag;
  if (recurse_flag == CUBIT_FALSE) recurse_flag = CUBIT_TRUE;
  
  DLIList<ModelEntity*> childModEntList;
   
     // Check to see if there are no parents of this object. 
   if ( get_parents() == 0 )
   {
      if (this_recurse == CUBIT_FALSE)
      {
         // Since we are not recursing, this is a top-level entity.
         // Notify the static observers that a top-level entity is being
         // destructed.  This must be done before children are disconnected.
       CubitObservable *top_level = CAST_TO(this, CubitObservable);
       AppUtil::instance()->send_event(top_level, TOP_LEVEL_ENTITY_DESTRUCTED);
      }

        // Go through all the children and remove their link to
        // the current object.
      
      ModelEntity* tempModEntPtr = NULL ;
      ModelEntity* childModEntPtr = NULL ;
      
      childModEntList.clean_out();
      disconnect_all_children(&childModEntList);
      
        // The following while conditional may not work...it depends on
        // what is_at_end does when you step over the end...CHECK THIS
      int i;
      for( i = 0 ; i < childModEntList.size() ; i++ )
      {
           // Get the next ModelEnti in the child list and make sure its
           // pointer to its parent is removed.
         tempModEntPtr = childModEntList.get_and_step();
          
           // Try remove() on the child ModEnt. If it comes back with
           // a success, then delete it.
         childModEntPtr = tempModEntPtr;
         
         if ( childModEntPtr->remove_from_DAG(recurse_flag) == CUBIT_SUCCESS )
         {
              // Now deactivate the child ModEnt
            childModEntPtr->deactivated(CUBIT_TRUE) ;

              // remove it from observables, just before we go to delete it
            CubitObservable *observable = CAST_TO(childModEntPtr, CubitObservable);
            if (observable) 
            {
              AppUtil::instance()->send_event(observable, MODEL_ENTITY_DESTRUCTED );
            }
         }
      }
      
      
        // If this is the top of the recursion, then clean out all the deactivated
        // entities.
      if (this_recurse == CUBIT_FALSE)
      {
         this->deactivated(CUBIT_TRUE) ;

         // remove it from observables, just before we go to delete it
         CubitObservable *observable = CAST_TO(childModEntPtr, CubitObservable);
         if (observable) 
         {
           AppUtil::instance()->send_event(observable, MODEL_ENTITY_DESTRUCTED );
         }
         GeometryQueryTool::instance()->cleanout_deactivated_geometry() ;
      }
      
      return CUBIT_SUCCESS ;
   }
   else
   {
      return CUBIT_FAILURE ;
   }
}

void ModelEntity::disconnect_from_DAG()<--- The function 'disconnect_from_DAG' is never used.
{
    // disconnects this entity from any others
    // to which it is connected in the DAG; does not delete the DAGNode

  disconnect_all_children();
  disconnect_all_parents();
}

//-------------------------------------------------------------------------
// Purpose       : Get and set functions for the deactivated flag.
//
// Special Notes :
//
// Creator       : Raikanta Sahu
//
// Creation Date : 12/02/96
//-------------------------------------------------------------------------

void ModelEntity::deactivated(CubitBoolean flag)
{
   if (deactivatedStatus_ != flag)
   {
     deactivatedStatus_ = flag ;
     if (flag == CUBIT_TRUE)
     {
        DAG::instance()->add_deactivated_DAG_node(this) ;
     }
     else
     {
        DAG::instance()->remove_deactivated_DAG_node(this) ;
     }
   }
}

CubitBoolean ModelEntity::deactivated() const
{
   return (CubitBoolean)deactivatedStatus_ ;
}




// ********** END PUBLIC FUNCTIONS            **********
// ********** BEGIN PROTECTED FUNCTIONS       **********
// ********** END PROTECTED FUNCTIONS         **********
// ********** BEGIN PRIVATE FUNCTIONS         **********
















// ********** END PRIVATE FUNCTIONS           **********

// ********** BEGIN HELPER CLASSES            **********
// ********** END HELPER CLASSES              **********

// ********** BEGIN EXTERN FUNCTIONS          **********
// ********** END EXTERN FUNCTIONS            **********

// ********** BEGIN STATIC FUNCTIONS          **********
// ********** END STATIC FUNCTIONS            **********