cgma
ModelEntity.cpp
Go to the documentation of this file.
00001 //-------------------------------------------------------------------------
00002 // Copyright Notice
00003 //
00004 // Copyright (c) 1996 
00005 // by Malcolm J. Panthaki, DBA, and the University of New Mexico.
00006 //-------------------------------------------------------------------------
00007 
00008 //-------------------------------------------------------------------------
00009 // Filename      : ModelEntity.cc
00010 //
00011 // Purpose       : 
00012 //
00013 // Special Notes :
00014 //
00015 // Creator       : Raikanta Sahu
00016 //
00017 // Creation Date : 10/15/96
00018 //
00019 // Owner         : Malcolm J. Panthaki
00020 //-------------------------------------------------------------------------
00021 
00022 // ********** BEGIN STANDARD INCLUDES         **********
00023 // ********** END STANDARD INCLUDES           **********
00024 
00025 // ********** BEGIN MOTIF INCLUDES            **********
00026 // ********** END MOTIF INCLUDES              **********
00027 
00028 // ********** BEGIN OPEN INVENTOR INCLUDES    **********
00029 // ********** END OPEN INVENTOR INCLUDES      **********
00030 
00031 // ********** BEGIN CUBIT INCLUDES            **********
00032 
00033 #include "ModelEntity.hpp"
00034 #include "ModelQueryEngine.hpp"
00035 #include "GeometryQueryTool.hpp"
00036 #include "CastTo.hpp"
00037 #include "CubitObservable.hpp"
00038 #include "CubitObserver.hpp"
00039 #include "DAG.hpp"
00040 #include "RefVolume.hpp"
00041 #include "Loop.hpp"
00042 #include "RefEdge.hpp"
00043 #include "AppUtil.hpp"
00044 
00045 // ********** END CUBIT INCLUDES              **********
00046 
00047 // ********** BEGIN EXTERN DECLARATIONS       **********
00048 // ********** END EXTERN DECLARATIONS         **********
00049 
00050 // ********** BEGIN STATIC DECLARATIONS       **********
00051 // ********** END STATIC DECLARATIONS         **********
00052 
00053 // ********** BEGIN PUBLIC FUNCTIONS          **********
00054 
00055 //-------------------------------------------------------------------------
00056 // Purpose       : The default constructor
00057 //
00058 // Special Notes : 
00059 //
00060 // Creator       : Raikanta Sahu
00061 //
00062 // Creation Date : 10/15/96
00063 //-------------------------------------------------------------------------
00064 
00065 ModelEntity::ModelEntity() : 
00066     deactivatedStatus_(CUBIT_FALSE),
00067     encountered_(CUBIT_FALSE)
00068 {
00069 }
00070 
00071 //-------------------------------------------------------------------------
00072 // Purpose       : The destructor
00073 //
00074 // Special Notes :
00075 //
00076 // Creator       : Raikanta Sahu
00077 //
00078 // Creation Date : 10/15/96
00079 //-------------------------------------------------------------------------
00080 
00081 ModelEntity::~ModelEntity()
00082 {
00083      // Make sure that the ModelEntity class does not have a pointer to this
00084      // ModelEntity in its list.  If it does, then remove the instances
00085      // of the pointer
00086    DAG::instance()->remove(this);
00087   
00088 }
00089 
00090 
00091 //-------------------------------------------------------------------------
00092 // Purpose       : Determine whether this object can be deleted from
00093 //                 memory or not.
00094 //
00095 // Special Notes : This function will recursively remove all the
00096 //                 removable child entities from the DAG and call their
00097 //                 destructors. Destructors of other objects, like
00098 //                 GeometryEntity, need to be called from the destructors 
00099 //                 of different ModEnts. Virtual destructors put to use :) :)
00100 //
00101 // Creator       : Raikanta Sahu
00102 //
00103 // Creation Date : 11/05/96
00104 //-------------------------------------------------------------------------
00105 
00106 CubitStatus ModelEntity::remove_from_DAG(CubitBoolean recurse_flag)
00107 {
00108      // This counter will be used in the recursion to test whether
00109      // the call is from outside or from the function itself. When
00110      // the call comes from outside, the counter should always be
00111      // zero.
00112 
00113   CubitBoolean this_recurse = recurse_flag;
00114   if (recurse_flag == CUBIT_FALSE) recurse_flag = CUBIT_TRUE;
00115   
00116   DLIList<ModelEntity*> childModEntList;
00117    
00118      // Check to see if there are no parents of this object. 
00119    if ( get_parents() == 0 )
00120    {
00121       if (this_recurse == CUBIT_FALSE)
00122       {
00123          // Since we are not recursing, this is a top-level entity.
00124          // Notify the static observers that a top-level entity is being
00125          // destructed.  This must be done before children are disconnected.
00126        CubitObservable *top_level = CAST_TO(this, CubitObservable);
00127        AppUtil::instance()->send_event(top_level, TOP_LEVEL_ENTITY_DESTRUCTED);
00128       }
00129 
00130         // Go through all the children and remove their link to
00131         // the current object.
00132       
00133       ModelEntity* tempModEntPtr = NULL ;
00134       ModelEntity* childModEntPtr = NULL ;
00135       
00136       childModEntList.clean_out();
00137       disconnect_all_children(&childModEntList);
00138       
00139         // The following while conditional may not work...it depends on
00140         // what is_at_end does when you step over the end...CHECK THIS
00141       int i;
00142       for( i = 0 ; i < childModEntList.size() ; i++ )
00143       {
00144            // Get the next ModelEnti in the child list and make sure its
00145            // pointer to its parent is removed.
00146          tempModEntPtr = childModEntList.get_and_step();
00147           
00148            // Try remove() on the child ModEnt. If it comes back with
00149            // a success, then delete it.
00150          childModEntPtr = tempModEntPtr;
00151          
00152          if ( childModEntPtr->remove_from_DAG(recurse_flag) == CUBIT_SUCCESS )
00153          {
00154               // Now deactivate the child ModEnt
00155             childModEntPtr->deactivated(CUBIT_TRUE) ;
00156 
00157               // remove it from observables, just before we go to delete it
00158             CubitObservable *observable = CAST_TO(childModEntPtr, CubitObservable);
00159             if (observable) 
00160             {
00161               AppUtil::instance()->send_event(observable, MODEL_ENTITY_DESTRUCTED );
00162             }
00163          }
00164       }
00165       
00166       
00167         // If this is the top of the recursion, then clean out all the deactivated
00168         // entities.
00169       if (this_recurse == CUBIT_FALSE)
00170       {
00171          this->deactivated(CUBIT_TRUE) ;
00172 
00173          // remove it from observables, just before we go to delete it
00174          CubitObservable *observable = CAST_TO(childModEntPtr, CubitObservable);
00175          if (observable) 
00176          {
00177            AppUtil::instance()->send_event(observable, MODEL_ENTITY_DESTRUCTED );
00178          }
00179          GeometryQueryTool::instance()->cleanout_deactivated_geometry() ;
00180       }
00181       
00182       return CUBIT_SUCCESS ;
00183    }
00184    else
00185    {
00186       return CUBIT_FAILURE ;
00187    }
00188 }
00189 
00190 void ModelEntity::disconnect_from_DAG()
00191 {
00192     // disconnects this entity from any others
00193     // to which it is connected in the DAG; does not delete the DAGNode
00194 
00195   disconnect_all_children();
00196   disconnect_all_parents();
00197 }
00198 
00199 //-------------------------------------------------------------------------
00200 // Purpose       : Get and set functions for the deactivated flag.
00201 //
00202 // Special Notes :
00203 //
00204 // Creator       : Raikanta Sahu
00205 //
00206 // Creation Date : 12/02/96
00207 //-------------------------------------------------------------------------
00208 
00209 void ModelEntity::deactivated(CubitBoolean flag)
00210 {
00211    if (deactivatedStatus_ != flag)
00212    {
00213      deactivatedStatus_ = flag ;
00214      if (flag == CUBIT_TRUE)
00215      {
00216         DAG::instance()->add_deactivated_DAG_node(this) ;
00217      }
00218      else
00219      {
00220         DAG::instance()->remove_deactivated_DAG_node(this) ;
00221      }
00222    }
00223 }
00224 
00225 CubitBoolean ModelEntity::deactivated() const
00226 {
00227    return (CubitBoolean)deactivatedStatus_ ;
00228 }
00229 
00230 
00231 
00232 
00233 // ********** END PUBLIC FUNCTIONS            **********
00234 // ********** BEGIN PROTECTED FUNCTIONS       **********
00235 // ********** END PROTECTED FUNCTIONS         **********
00236 // ********** BEGIN PRIVATE FUNCTIONS         **********
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 
00248 
00249 
00250 
00251 
00252 
00253 // ********** END PRIVATE FUNCTIONS           **********
00254 
00255 // ********** BEGIN HELPER CLASSES            **********
00256 // ********** END HELPER CLASSES              **********
00257 
00258 // ********** BEGIN EXTERN FUNCTIONS          **********
00259 // ********** END EXTERN FUNCTIONS            **********
00260 
00261 // ********** BEGIN STATIC FUNCTIONS          **********
00262 // ********** END STATIC FUNCTIONS            **********
00263 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines