cgma
DAG.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      : DAG.cc
00010 //
00011 // Purpose       : 
00012 //
00013 // Special Notes :
00014 //
00015 // Creator       : Raikanta Sahu
00016 //
00017 // Creation Date : 12/02/96
00018 //
00019 // Owner         : Raikanta Sahu
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 "DAG.hpp"
00034 #include "CastTo.hpp"
00035 #include "TopologyEntity.hpp"
00036 #include "CubitObserver.hpp"
00037 
00038 // ********** END CUBIT INCLUDES              **********
00039 
00040 // ********** BEGIN EXTERN DECLARATIONS       **********
00041 // ********** END EXTERN DECLARATIONS         **********
00042 
00043 // ********** BEGIN STATIC DECLARATIONS       **********
00044 
00045 DAG* DAG::instance_ = NULL ;
00046 
00047 // ********** END STATIC DECLARATIONS         **********
00048 
00049 // ********** BEGIN PUBLIC FUNCTIONS          **********
00050 
00051 //-------------------------------------------------------------------------
00052 // Purpose       : Return a pointer to the only instance of the class.
00053 //
00054 // Special Notes :
00055 //
00056 // Creator       : Raikanta Sahu
00057 //
00058 // Creation Date : 12/02/96
00059 //-------------------------------------------------------------------------
00060 DAG* DAG::instance()
00061 {
00062   if (instance_ == NULL ) 
00063   {
00064     instance_ = new DAG;
00065   }
00066   return instance_ ;
00067 }
00068 
00069 //-------------------------------------------------------------------------
00070 // Purpose       : The destructor
00071 //
00072 // Special Notes :
00073 //
00074 // Creator       : Raikanta Sahu
00075 //
00076 // Creation Date : 12/02/96
00077 //-------------------------------------------------------------------------
00078 DAG::~DAG()
00079 {
00080   instance_ = NULL ;
00081 }
00082 
00083 //-------------------------------------------------------------------------
00084 // Purpose       : This function takes a pointer to a deactivated DAG 
00085 //                 node and adds it to the list of deactivated DAG nodes.
00086 //
00087 // Special Notes :
00088 //
00089 // Creator       : Raikanta Sahu
00090 //
00091 // Creation Date : 12/02/96
00092 //-------------------------------------------------------------------------
00093 
00094 void DAG::add_deactivated_DAG_node(TopologyEntity* deactivatedDAGNodePtr)
00095 {
00096   deactivatedDAGNodeList_.append(deactivatedDAGNodePtr) ;
00097 }
00098 
00099 //-------------------------------------------------------------------------
00100 // Purpose       : This function takes a pointer to a deactivated DAG 
00101 //                 node and removes it to the list of deactivated DAG nodes.
00102 //
00103 // Special Notes :
00104 //
00105 // Creator       : Raikanta Sahu
00106 //
00107 // Creation Date : 12/02/96
00108 //-------------------------------------------------------------------------
00109 
00110 void DAG::remove_deactivated_DAG_node(TopologyEntity* deactivatedDAGNodePtr)
00111 {
00112   if (deactivatedDAGNodeList_.move_to(deactivatedDAGNodePtr))
00113     deactivatedDAGNodeList_.extract();
00114 }
00115 
00116 //-------------------------------------------------------------------------
00117 // Purpose       : This function deletes all the deactivated DAG nodes
00118 //                 and cleans the list of deactivated DAG nodes.
00119 // Special Notes :
00120 //
00121 // Creator       : Raikanta Sahu
00122 //
00123 // Creation Date : 12/02/96
00124 //-------------------------------------------------------------------------
00125 void DAG::cleanout_deactivated_DAG_nodes() 
00126 {
00127   TopologyEntity* tempDAGNode = NULL;
00128   while ( deactivatedDAGNodeList_.size() > 0)
00129   {
00130     tempDAGNode = NULL;
00131     deactivatedDAGNodeList_.last();
00132     tempDAGNode = deactivatedDAGNodeList_.get();
00133     if( tempDAGNode != NULL )
00134     {
00135       delete tempDAGNode;
00136     }
00137   }
00138    
00139   deactivatedDAGNodeList_.clean_out() ;
00140 }
00141 
00142 //-------------------------------------------------------------------------
00143 // Purpose       :  This function is used to notify the DAG class that an
00144 //                  event has occurred.  The input object that initiated the
00145 //                  the event is a DAG Node.
00146 //
00147 // Special Notes :
00148 //
00149 // Creator       : Malcolm J. Panthaki
00150 //
00151 // Creation Date : 12/03/96
00152 //-------------------------------------------------------------------------
00153 void DAG::remove(TopologyEntity* DAGNodePtr)
00154 {
00155     // If this input pointer exists in the deactivated DAG Node list,
00156     // remove it
00157   deactivatedDAGNodeList_.remove(DAGNodePtr);
00158 }
00159 
00160 
00161 //-------------------------------------------------------------------------
00162 // Purpose   : Find the children of a node at a specified level in the 
00163 //         DAG, relative to the node.
00164 //
00165 // Special Notes :
00166 //
00167 // Creator   : Jason Kraftcheck
00168 //
00169 // Creation Date : 09/16/97
00170 //-------------------------------------------------------------------------
00171 CubitStatus DAG::get_children_at_level( TopologyEntity* parent, int level,
00172                                         DLIList<TopologyEntity*>& result_set )
00173 {
00174   DLIList<TopologyEntity*> parent_list;  // nodes at current level
00175     
00176     // Start with a parent_list with one node, the passed parent
00177   parent_list.append( parent );
00178     
00179     // Call with list
00180   return get_children_at_level( parent_list, level, result_set );
00181 }
00182 
00183 //-------------------------------------------------------------------------
00184 // Purpose   : Find the parents of a node at a specified level in the 
00185 //         DAG, relative to the node.
00186 //
00187 // Special Notes :
00188 //
00189 // Creator   : Jason Kraftcheck
00190 //
00191 // Creation Date : 09/16/97
00192 //-------------------------------------------------------------------------
00193 CubitStatus DAG::get_parents_at_level( TopologyEntity* child, int level,
00194                                        DLIList<TopologyEntity*>& result_set )
00195 {
00196   DLIList<TopologyEntity*> child_list;  // nodes at current level
00197     
00198     // Start with a parent_list with one node, the passed parent
00199   child_list.append( child );
00200     
00201     // Call with list
00202   return get_parents_at_level( child_list, level, result_set );
00203 }
00204 
00205 
00206 //-------------------------------------------------------------------------
00207 // Purpose   : Find the children of a list of nodes at a specified 
00208 //         level in the DAG, relative to the node.
00209 //
00210 // Special Notes :
00211 //
00212 // Creator   : Jason Kraftcheck
00213 //
00214 // Creation Date : 09/16/97
00215 //-------------------------------------------------------------------------
00216 CubitStatus DAG::get_children_at_level( DLIList<TopologyEntity*>& parent_list,
00217                                         int level,
00218                                         DLIList<TopologyEntity*>& result_set )
00219 {
00220   assert( level > 0 );
00221   if( parent_list.size( ) < 1 ) return CUBIT_FAILURE;
00222     
00223   DLIList<TopologyEntity*> child_list;   // children of all parents
00224   DLIList<TopologyEntity*> current_node_children;
00225     
00226     //Get a list of all the children one level down from 
00227     //the nodes in parent_list.
00228   for( int i = 0; i < parent_list.size( ); i++ )
00229   {
00230     TopologyEntity* current = parent_list.get_and_step( );
00231         
00232     current_node_children.clean_out( );
00233     current->get_children( &current_node_children );
00234         
00235     for( int j = 0; j < current_node_children.size( ); j++ )
00236     {
00237       child_list.append_unique(
00238         current_node_children.get_and_step( ) );
00239     }
00240   }
00241     
00242     //If we found no children, return failure.
00243   if( child_list.size( ) < 1 ) return CUBIT_FAILURE;
00244     
00245     //If level 1, then return the list of children.
00246   if( level == 1 )
00247   {
00248     result_set = child_list;
00249     return CUBIT_SUCCESS;
00250   }
00251     //Otherwise get next level down by recursion.
00252   else
00253   {
00254     return get_children_at_level( child_list, level - 1, 
00255                                   result_set );
00256   } 
00257 }
00258 
00259 //-------------------------------------------------------------------------
00260 // Purpose   : Find the parents of a list of nodes at a specified level
00261 //         in the DAG, relative to the node.
00262 //
00263 // Special Notes :
00264 //
00265 // Creator   : Jason Kraftcheck
00266 //
00267 // Creation Date : 09/16/97
00268 //-------------------------------------------------------------------------
00269 CubitStatus DAG::get_parents_at_level( DLIList<TopologyEntity*>& child_list,
00270                                        int level,
00271                                        DLIList<TopologyEntity*>& result_set )
00272 {
00273   assert( level > 0 );
00274   if( child_list.size( ) < 1 ) return CUBIT_FAILURE;
00275     
00276   DLIList<TopologyEntity*> parent_list;   // children of all parents
00277   DLIList<TopologyEntity*> current_node_parents;
00278     
00279     //Get a list of all the parents one level up from 
00280     //the nodes in child_list.
00281   for( int i = 0; i < child_list.size( ); i++ )
00282   {
00283     TopologyEntity* current = child_list.get_and_step( );
00284         
00285     current_node_parents.clean_out( );
00286     current->get_parents( &current_node_parents );
00287         
00288     for( int j = 0; j < current_node_parents.size( ); j++ )
00289     {
00290       parent_list.append_unique(
00291         current_node_parents.get_and_step( ) );
00292     }
00293   }
00294     
00295     //If we found no parents, return failure.
00296   if( parent_list.size( ) < 1 ) return CUBIT_FAILURE;
00297     
00298     //If level 1, then return the list of parents.
00299   if( level == 1 )
00300   {
00301     result_set = parent_list;
00302     return CUBIT_SUCCESS;
00303   }
00304     //Otherwise get next level down by recursion.
00305   else
00306   {
00307     return get_parents_at_level( parent_list, level - 1, 
00308                                  result_set );
00309   } 
00310 }
00311 
00312 
00313 
00314 
00315 // ********** END PUBLIC FUNCTIONS            **********
00316 
00317 // ********** BEGIN PROTECTED FUNCTIONS       **********
00318 //-------------------------------------------------------------------------
00319 // Purpose       : The default constructor
00320 //
00321 // Special Notes :
00322 //
00323 // Creator       : Raikanta Sahu
00324 //
00325 // Creation Date : 12/02/96
00326 //-------------------------------------------------------------------------
00327 DAG::DAG() : deactivatedDAGNodeList_() 
00328 {
00329 }
00330 
00331 // ********** END PROTECTED FUNCTIONS         **********
00332 
00333 // ********** BEGIN PRIVATE FUNCTIONS         **********
00334 // ********** END PRIVATE FUNCTIONS           **********
00335 
00336 // ********** BEGIN HELPER CLASSES            **********
00337 // ********** END HELPER CLASSES              **********
00338 
00339 // ********** BEGIN EXTERN FUNCTIONS          **********
00340 // ********** END EXTERN FUNCTIONS            **********
00341 
00342 // ********** BEGIN STATIC FUNCTIONS          **********
00343 // ********** END STATIC FUNCTIONS            **********
00344 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines