cgma
DagDrawingTool.cpp
Go to the documentation of this file.
00001 
00002 
00003 #include "DagDrawingTool.hpp"
00004 #include "RefFace.hpp"
00005 #include "RefEdge.hpp"
00006 #include "RefVertex.hpp"
00007 #include "RefVolume.hpp"
00008 #include "Body.hpp"
00009 #include "DLIList.hpp"
00010 #include "CubitMessage.hpp"
00011 #include "CubitColor.hpp"
00012 #include "SenseEntity.hpp"
00013 #include "CastTo.hpp"
00014 #include "CoVertex.hpp"
00015 #include "Chain.hpp"
00016 #include "CoEdge.hpp"
00017 #include "Loop.hpp"
00018 #include "CoFace.hpp"
00019 #include "Shell.hpp"
00020 
00021 //constants:
00022 
00023 
00024 //Abbreviations used for type names.
00025 //Note: If abbreviations are not used, the
00026 // full type name is taken from 
00027 // CubitEntity::entity_name( EntityType ).
00028 
00029 
00030 //const CubitLink DDT_DEFAULT_TRAVERSE_TYPE = CUBIT_ALL_LINKS;
00031 
00032 DagDrawingTool* DagDrawingTool::instance_ = 0;
00033 
00034 //constants for query direction
00035 const int DDT_UP_DAG   =  1;
00036 const int DDT_DOWN_DAG = -1;
00037 
00038 //bit masks for link type
00039 enum LINK_TYPE {DDT_LINK_NONE = 0, DDT_LINK_UP, DDT_LINK_DOWN, DDT_LINK_BOTH, DDT_BAD_LINK};
00040 
00041 DagDrawingTool::DagDrawingTool()
00042 {
00043     node_table = 0;
00044 }
00045 
00046 void DagDrawingTool::one_sort_pass( int start, int end, float* val_list )
00047 {
00048     int i, j, k;
00049     DagNodeTable& table = *node_table;
00050     //int row_count = table.rows();
00051     int cur_row_len = 0;
00052     if( start == end ) return;
00053     int dir = (start < end) ? 1 : -1;
00054     
00055     //for each parent row of the passed row of nodes...
00056     for( i = start; i != (end + dir); i += dir )
00057     {
00058         //populate the array with the values to sort by
00059         cur_row_len = table[i].length();
00060         for( j = 0; j < cur_row_len; j++ )
00061         {
00062             val_list[j] = 0.0;
00063             int link_count = 0;
00064             for( k = 0; k < table[i-dir].length(); k++ )
00065             {
00066                 if( link_type( i, j, i - dir, k ) )
00067                 {
00068                     val_list[j] += (float)k;
00069                     link_count++;
00070                 }
00071             }
00072             if( link_count ) val_list[j] /= (float)link_count;
00073         }       
00074         
00075         //sort the row by the values in value_list
00076         for( j = 0; j < cur_row_len - 1; j++ )
00077         {
00078             int smallest = j;
00079             for( k = j + 1; k < cur_row_len; k++ )
00080             {
00081                 if( val_list[k] < val_list[smallest] )
00082                     smallest = k;
00083             }
00084             if( smallest != j )
00085             {
00086                                   //float temp = val_list[j];
00087                 val_list[j] = val_list[smallest];
00088                 val_list[smallest] = val_list[j];
00089                 
00090                 TopologyEntity* node = table[i][j];
00091                 table[i][j] = table[i][smallest];
00092                 table[i][smallest] = node;
00093             }
00094         }
00095     }
00096     
00097 }   
00098 /*
00099 void DagDrawingTool::sort_table( )
00100 {
00101     DagNodeTable& table = *node_table;
00102     int passes = table.rows() - 1;
00103     int i;
00104     
00105     int max_row_size = 0;
00106     int row_count = table.rows();
00107     for( i = 0; i < row_count; i++ )
00108         if( table[i].length() > max_row_size )
00109             max_row_size = table[i].length();
00110     float* value_list = new float[max_row_size];
00111 
00112     for( i = 0; i < passes; i++ )
00113     {
00114         one_sort_pass( 1, row_count - 1, value_list );
00115         one_sort_pass( row_count - 2, 0, value_list );
00116     }
00117         
00118     delete [] value_list;
00119 }
00120 */ 
00121 
00122 void DagDrawingTool::sort_row( int row, int wrt_dir )
00123 {
00124   assert((wrt_dir == 1) || (wrt_dir == -1));
00125   
00126   DagNodeTable& table = *node_table;
00127   int row_len = table[row].length();
00128   int rel_row = row + wrt_dir;
00129   if( (row_len < 2) || (rel_row < 0) || (rel_row == table.rows()) )
00130     return;
00131   
00132   int* index_array = new int[row_len];
00133   int num_rels = table[rel_row].length();
00134   int i, j, k, l, m;
00135   
00136   //Append first node to list
00137   index_array[0] = 0;
00138   
00139   //For each remaining node, insert it in the location at which
00140   //it causes the least intersections of links.
00141   for( i = 1; i < row_len; i++ )
00142   {
00143     int best_index = 0;
00144     int intersection_count = 0;
00145     
00146     //Get the intersection count if the node were inserted first
00147     //in the row.
00148 
00149     //For each possible parent node
00150     for( k = 1; k < num_rels; k++ )
00151     {
00152       //Is it a parent?
00153       if( ! link_type( row, i, rel_row, k ) )
00154         continue;
00155       
00156       //Count how many other links that link intersects.
00157       
00158       //For all the other nodes in the list...
00159       for( l = 0; l < i; l++ )
00160       {
00161         //For each parent to the left of my parent
00162         for( m = 0; m < k; m++ )
00163         {
00164           if( link_type( row, index_array[l], rel_row, m ) )
00165             intersection_count++;
00166         }
00167       }
00168     }
00169     
00170     //Now check the intersection count for each additional
00171     //possible location of insertion.       
00172     for( j = 1; j <= i; j++ )
00173     {
00174       int current_count = 0;
00175       
00176       //For each possible parent node
00177       for( k = 0; k < num_rels; k++ )
00178       {
00179         //Is it a parent?
00180         if( ! link_type( row, i, rel_row, k ) )
00181           continue;
00182           
00183         //Count how many other links from nodes to the
00184         //left of me intersect with my link to this parent.
00185         for( l = 0; l < j; l++ )  
00186         {
00187           //For each parent to the right of my parent
00188           for( m = k+1; m < num_rels; m++ )
00189           {
00190             if( link_type( row, index_array[l], rel_row, m ) )
00191               current_count++;
00192           }
00193         }
00194         
00195         //Count how many other links from nodes to the
00196         //right of me intersect with my link to this parent.
00197         for( l = j; l < i; l++ )
00198         {
00199           //For each parent to the left of my parent
00200           for( m = 0; m < k; m++ )
00201           {
00202             if( link_type( row, index_array[l], rel_row, m ) )
00203               current_count++;
00204           }
00205         }
00206       }
00207       
00208       if( current_count <= intersection_count )
00209       {
00210         intersection_count = current_count;
00211         best_index = j;
00212       }
00213     }
00214     
00215     //Now insert this node at the best location.
00216     for( j = i; j > best_index; j-- )
00217       index_array[j] = index_array[j-1];
00218     index_array[best_index] = i;
00219   }
00220   
00221   //Now rearrange the nodes in the actual row to match 
00222   //what is stored in index_list
00223   TopologyEntity** node_array = new TopologyEntity*[row_len];
00224   for( i = 0; i < row_len; i++ )
00225   {
00226     node_array[i] = table[row][index_array[i]];
00227   }
00228   for( i = 0; i < row_len; i++ )
00229   {
00230     table[row][i] = node_array[i];
00231   }
00232   delete [] node_array;
00233   delete [] index_array;
00234 }
00235         
00236         
00237 /*
00238 void DagDrawingTool::draw_table()
00239 {
00240     int i, j, k;
00241     DagNodeTable& table = *node_table;
00242     for( i = 0; i < table.rows(); i++ )
00243     {
00244         int len = table[i].length();
00245         for( j = 0; j < len; j++ )
00246         {
00247             draw_node( i, j );
00248             if( i > 0 ) 
00249             {
00250                 int len2 = table[i-1].length();
00251                 for( k = 0; k < len2; k++ ) draw_link( i, j, i - 1, k );
00252             }
00253       if( draw_host_para_links_ )
00254       {
00255         for( k = 0; k < j; k++ )
00256           draw_host_link( i, k, j );
00257           }
00258     }
00259     }
00260 }
00261 
00262 
00263 void DagDrawingTool::draw_DAG( DLIList<TopologyEntity*>& node_list, int up, int down )
00264 {
00265     int i;
00266     assert( (up >= 0) && (down >= 0) );
00267     if( node_list.size() == 0 ) return;
00268     
00269     DLIList<TopologyEntity*> relatives[2];
00270     int num_rows = up + down + 1;
00271     
00272     assert( ! node_table );
00273     node_table = new DagNodeTable( num_rows );
00274     start_row = down;
00275     node_table->initialize_row( start_row, node_list );
00276     
00277     relatives[ start_row % 2 ] = node_list;
00278     for( i = start_row - 1; i >= 0; i-- )
00279     {
00280         relatives[i % 2].clean_out();
00281         get_relatives( relatives[(i + 1) % 2], relatives[i % 2], DDT_DOWN_DAG );
00282         node_table->initialize_row( i, relatives[i % 2] );
00283     }
00284     relatives[ start_row % 2 ] = node_list;
00285     for( i = start_row + 1; i < num_rows; i++ )
00286     {
00287         relatives[i % 2].clean_out();
00288         get_relatives( relatives[(i - 1) % 2], relatives[i % 2], DDT_UP_DAG );
00289         node_table->initialize_row( i, relatives[i % 2] );
00290     }
00291     
00292 
00293     sort_table();
00294 
00295     initialize_graphics();
00296     draw_table();
00297     finalize_graphics();
00298 
00299     delete node_table;
00300     node_table = 0;
00301 }
00302 */
00303 
00304 
00305 DagDrawingTool* DagDrawingTool::instance()
00306 {
00307     return instance_ ? instance_ : instance_ = new DagDrawingTool();
00308 }
00309 
00310 DagDrawingTool::~DagDrawingTool()
00311 {
00312     instance_ = 0;
00313     assert( ! node_table );
00314 }
00315 
00316 /*
00317 void DagDrawingTool::draw_DAG( Body*      body,           int down ) 
00318 {
00319   DLIList<RefEntity*> entity_list;
00320   entity_list.append(body);
00321   draw_DAG( entity_list, 0, down );
00322 }
00323 
00324 void DagDrawingTool::draw_DAG( RefVolume* volume, int up, int down )
00325 {
00326   DLIList<RefEntity*> entity_list;
00327   entity_list.append(volume);
00328   draw_DAG( entity_list, up, down );
00329 }
00330 
00331 void DagDrawingTool::draw_DAG( RefFace*   face,   int up, int down )
00332 {
00333   DLIList<RefEntity*> entity_list;
00334   entity_list.append(face);
00335   draw_DAG( entity_list, up, down );
00336 }
00337 
00338 void DagDrawingTool::draw_DAG( RefEdge*   edge,   int up, int down )
00339 {
00340   DLIList<RefEntity*> entity_list;
00341   entity_list.append(edge);
00342   draw_DAG( entity_list, up, down );
00343 }
00344 
00345 void DagDrawingTool::draw_DAG( RefVertex* vertex, int up           )
00346 {
00347   DLIList<RefEntity*> entity_list;
00348   entity_list.append(vertex);
00349   draw_DAG( entity_list, up, 0 );
00350 }
00351 
00352 void DagDrawingTool::draw_DAG( DLIList<RefEdge*>& edge_list, int up, int down )
00353 {
00354     DLIList<RefEntity*> entity_list;
00355     CAST_LIST_TO_PARENT( edge_list, entity_list );
00356     draw_DAG( entity_list, up, down );
00357 }
00358 
00359 void DagDrawingTool::draw_DAG( DLIList<RefFace*>& face_list, int up, int down )
00360 {
00361     DLIList<RefEntity*> entity_list;
00362     CAST_LIST_TO_PARENT( face_list, entity_list );
00363     draw_DAG( entity_list, up, down );
00364 }
00365 
00366 void DagDrawingTool::draw_DAG( DLIList<RefVertex*>& vtx_list, int up )
00367 {
00368     DLIList<RefEntity*> entity_list;
00369     CAST_LIST_TO_PARENT( vtx_list, entity_list );
00370     draw_DAG( entity_list, up, 0 );
00371 }
00372 
00373 void DagDrawingTool::draw_DAG( DLIList<RefVolume*>& vol_list, int up, int down )
00374 {
00375     DLIList<RefEntity*> entity_list;
00376     CAST_LIST_TO_PARENT( vol_list, entity_list );
00377     draw_DAG( entity_list, up, down );
00378 }
00379 
00380 void DagDrawingTool::draw_DAG( DLIList<Body*>& body_list, int down )
00381 {
00382     DLIList<RefEntity*> entity_list;
00383     CAST_LIST_TO_PARENT( body_list, entity_list );
00384     draw_DAG( entity_list, 0, down );
00385 }
00386 
00387 void DagDrawingTool::draw_DAG( DLIList<RefEntity*>& entity_list, int up, int down )
00388 {
00389     DLIList<TopologyEntity*> node_list;
00390     for( int i = entity_list.size(); i > 0; i-- )
00391     {
00392         RefEntity* re_ptr = entity_list.get_and_step();
00393         TopologyEntity* me_ptr = CAST_TO( re_ptr, TopologyEntity);
00394         node_list.append_unique( me_ptr );
00395     }
00396     draw_DAG( node_list, up, down );
00397 }
00398 */
00399 
00400 
00401 /*
00402 void DagDrawingTool::draw_host_parasite_links( CubitBoolean yn )
00403 { draw_host_para_links_ = yn; }
00404 CubitBoolean DagDrawingTool::draw_host_parasite_links() const
00405 { return draw_host_para_links_; }
00406 void DagDrawingTool::primary_link_color( int color )
00407 { prim_link_color_ = color; }
00408 void DagDrawingTool::secondary_link_color( int color )
00409 { sec_link_color_ = color; }
00410 void DagDrawingTool::host_para_link_color( int color )
00411 { host_para_color_ = color; }
00412 void DagDrawingTool::bad_link_color( int color )
00413 { bad_link_color_ = color; }
00414 void DagDrawingTool::node_color( int color )
00415 { node_color_ = color; }
00416 void DagDrawingTool::label_color( int color )
00417 { label_color_ = color; }
00418 void DagDrawingTool::background_color( int color )
00419 { background_color_ = color; }
00420 int DagDrawingTool::primary_link_color() const
00421 { return prim_link_color_; }
00422 int DagDrawingTool::secondary_link_color() const
00423 { return sec_link_color_; }
00424 int DagDrawingTool::host_para_link_color() const
00425 { return host_para_color_; }
00426 int DagDrawingTool::bad_link_color() const
00427 { return bad_link_color_; }
00428 int DagDrawingTool::node_color() const
00429 { return node_color_; }
00430 int DagDrawingTool::label_color() const
00431 { return label_color_; }
00432 int DagDrawingTool::background_color() const
00433 { return background_color_; }
00434     
00435 int DagDrawingTool::window_id() const
00436 { return window_id_; }
00437 */
00438 
00439 /*
00440 const char* DagDrawingTool::name( int row, int index )
00441 {
00442     DagNodeTable& table = *node_table;
00443     return name( table[row][index] );
00444 }
00445 */
00446 /*
00447 int DagDrawingTool::name_width( int row )
00448 {
00449     DagNodeTable& table = *(node_table);
00450     TopologyEntity* node_ptr = 0;
00451     if( table[row].length() > 0 )
00452         node_ptr = table[row][0];
00453     return name_width( node_ptr );
00454 }
00455 */
00456     
00457 /*
00458 int DagDrawingTool::name_width( TopologyEntity* node_ptr )
00459 {
00460   if( node_ptr == NULL )
00461      return 4;
00462   else if( CAST_TO( node_ptr, Body ) ||
00463            CAST_TO( node_ptr, RefVolume ) ||
00464            CAST_TO( node_ptr, RefFace ) ||
00465            CAST_TO( node_ptr, RefEdge ) ||
00466            CAST_TO( node_ptr, RefVertex ) )
00467   {
00468     switch( ref_entity_label_type_ )
00469     {
00470       case DDT_LABEL_REFENTITY_WITH_NAME: 
00471          return DDT_DEFAULT_NAME_LEN;
00472       case DDT_LABEL_REFENTITY_WITH_TYPE: 
00473          return DDT_DEFAULT_TYPE_LEN + DDT_DEFAULT_ID_LEN;
00474       case DDT_LABEL_REFENTITY_WITH_ABBR: 
00475          return DDT_DEFAULT_ABBREV_LEN + DDT_DEFAULT_ID_LEN - 1;
00476       case DDT_LABEL_REFENTITY_WITH_ID: 
00477          return DDT_DEFAULT_ID_LEN;
00478       default: 
00479          assert( ! ref_entity_label_type_ );
00480     }
00481   }
00482     else
00483   {
00484     switch( other_entity_label_type_ )
00485     {
00486       case DDT_LABEL_OTHER_WITH_TYPE: return DDT_DEFAULT_TYPE_LEN;
00487       case DDT_LABEL_OTHER_WITH_ABBR: return DDT_DEFAULT_ABBREV_LEN;
00488       case DDT_LABEL_OTHER_NONE: return 1;
00489       default: assert( ! other_entity_label_type_ );
00490     }
00491     }
00492     
00493     return 0;
00494 }
00495 */
00496 /*
00497 const char* DagDrawingTool::name( TopologyEntity* node_ptr )
00498 {
00499     static char buffer[32];
00500     
00501     if( ! node_ptr )
00502     {
00503             strcpy( buffer, "NULL" );
00504             return buffer;
00505     }
00506     
00507     TopologyEntity* entity_ptr = node_ptr;
00508     if( ! entity_ptr )
00509     {
00510         strcpy( buffer, "NODE" );
00511         return buffer;
00512     }
00513     
00514     CubitString s;
00515     RefEntity* re_ptr = CAST_TO( entity_ptr, RefEntity );
00516     if( re_ptr )
00517     {
00518         switch( ref_entity_label_type_ )
00519         {
00520             case DDT_LABEL_REFENTITY_WITH_NAME:
00521                 s = re_ptr->entity_name();
00522                 strncpy( buffer, s.c_str(), 31 );
00523                 break;
00524             case DDT_LABEL_REFENTITY_WITH_TYPE:
00525                 sprintf( buffer, "%0.24s %d",
00526                                                  re_ptr->class_name(), re_ptr->id() );
00527                 break;
00528             case DDT_LABEL_REFENTITY_WITH_ABBR:
00529                 sprintf( buffer, "%0.24s%d", short_name( re_ptr ), re_ptr->id() );
00530                 break;
00531             case DDT_LABEL_REFENTITY_WITH_ID:
00532                 sprintf( buffer, "%d", re_ptr->id() );
00533                 break;
00534             default: assert( ! ref_entity_label_type_ );
00535         }
00536     }
00537     else
00538     {
00539         switch( other_entity_label_type_ )
00540         {
00541             case DDT_LABEL_OTHER_WITH_TYPE:
00542                 strncpy( buffer,  
00543                  entity_ptr->class_name( ), 31 );
00544                 break;
00545             case DDT_LABEL_OTHER_WITH_ABBR:
00546                 strncpy( buffer, short_name( entity_ptr ), 31 );
00547                 break;
00548             case DDT_LABEL_OTHER_NONE:
00549                 buffer[0] = '\0';
00550                 break;
00551             default: assert( ! other_entity_label_type_ );
00552         }
00553     }
00554     return buffer;
00555 }
00556 */
00557 
00558 
00559 
00560 void DagDrawingTool::get_relatives( TopologyEntity* source_ptr,
00561     DLIList<TopologyEntity*>& result_set, int direction )
00562 {
00563     result_set.clean_out();
00564     if( direction == DDT_UP_DAG ) 
00565         source_ptr->get_parents( &result_set );
00566     else if( direction == DDT_DOWN_DAG )
00567       source_ptr->get_children( &result_set  );
00568     else assert( (direction == DDT_UP_DAG) || (direction == DDT_DOWN_DAG) );
00569 }
00570 
00571 void DagDrawingTool::get_relatives( DLIList<TopologyEntity*>& source_set,
00572     DLIList<TopologyEntity*>& result_set, int direction )
00573 {
00574     DLIList<TopologyEntity*> temp_set;
00575     result_set.clean_out();
00576     for( int i = 0; i < source_set.size();  i++ )
00577     {
00578         get_relatives( source_set.get_and_step(), temp_set, direction );
00579         result_set.merge_unique( temp_set );
00580     }
00581 }
00582 
00583 
00584 int DagDrawingTool::link_type( int source_row, int source_index, 
00585                                int target_row, int target_index )
00586 {
00587     DagNodeTable& table = *node_table;
00588     if( abs( source_row - target_row ) != 1 ) return DDT_LINK_NONE;
00589     return link_type( table[source_row][source_index], 
00590                       table[target_row][target_index], 
00591                                         source_row < target_row ? DDT_UP_DAG : DDT_DOWN_DAG );
00592 }
00593 int DagDrawingTool::link_type( TopologyEntity* source_node,
00594     TopologyEntity* target_node, int direction )
00595 {
00596     int result = DDT_LINK_NONE;
00597   DLIList<TopologyEntity*> parents, children;
00598     if( direction == DDT_UP_DAG )
00599     {
00600     source_node->get_parents(&parents);
00601     target_node->get_children(&children);
00602         bool down = parents.is_in_list(target_node);
00603     bool up   = children.is_in_list(source_node);
00604     if ( !down && !up )
00605       result = DDT_LINK_NONE;
00606     else if( down && up )
00607       result = DDT_LINK_BOTH;
00608     else
00609       result = DDT_BAD_LINK;
00610   }
00611     else if( direction == DDT_DOWN_DAG )
00612     {
00613     source_node->get_children(&children);
00614     target_node->get_parents(&parents);
00615         bool up   = children.is_in_list(target_node);
00616     bool down = parents.is_in_list(source_node);
00617     if ( !down && !up )
00618       result = DDT_LINK_NONE;
00619     else if( down && up )
00620       result = DDT_LINK_BOTH;
00621     else
00622       result = DDT_BAD_LINK;
00623     }
00624     return result;
00625 }
00626 
00627 
00628 
00629 DagNodeRow::DagNodeRow( DLIList<TopologyEntity*>& node_list )
00630 {
00631     length_ = node_list.size();
00632     array_ = 0;
00633     if( length_ > 0 )
00634     {
00635         array_ = new TopologyEntity*[length_];
00636         node_list.reset();
00637         for( int i = 0; i < length_; i++ )
00638             array_[i] = node_list.get_and_step();
00639     }
00640 }
00641 
00642 DagNodeRow::~DagNodeRow()
00643 {
00644     if( array_ ) delete [] array_;
00645     array_ = 0;
00646     length_ = 0;
00647 }
00648 
00649 TopologyEntity*& DagNodeRow::operator[]( int index )
00650 {
00651     assert( (index >= 0) && (index < length_) );
00652     return array_[index];
00653 }
00654 
00655 
00656 
00657 
00658 
00659 DagNodeTable::~DagNodeTable( )
00660 {
00661     if( array_ )
00662     {
00663         for( int i = 0; i < length_; i++ )
00664         {
00665             if( array_[i] ) 
00666             {
00667                 delete array_[i];
00668                 array_[i] = 0;
00669             }
00670         }
00671         delete [] array_;
00672     }
00673     array_ = 0;
00674     length_ = 0;
00675 }
00676 
00677 DagNodeRow& DagNodeTable::operator[]( int row )
00678 {
00679     assert( (row >= 0) && (row < length_) && array_[row] );
00680     return *(array_[row]);
00681 }
00682 
00683 
00684 
00685 
00686 
00687 class DLT_IdTable
00688 {
00689 public:
00690   DLT_IdTable( ){ current_insert_pos = 0; }
00691   ~DLT_IdTable( ){ }
00692   
00693   int find_id( TopologyEntity* ME_ptr );
00694   
00695 private:
00696   TopologyEntity* ME_ptrs_[ 500 ];
00697   int current_insert_pos;
00698 };
00699 
00700 void DagDrawingTool::printDag(DLIList<RefFace*> &face_list, int depth) 
00701 {
00702   DLIList<TopologyEntity*> entity_list;
00703   CAST_LIST_TO_PARENT(face_list, entity_list);
00704   printDag(entity_list, depth);
00705 }
00706 
00707 void DagDrawingTool::printDag(DLIList<Body*> &body_list, int depth)
00708 {
00709   DLIList<TopologyEntity*> entity_list;
00710   CAST_LIST_TO_PARENT(body_list, entity_list);
00711   printDag(entity_list, depth);
00712 }
00713 
00714 void DagDrawingTool::printDag(DLIList<TopologyEntity*> &entity_list, int depth)
00715 {
00716   int i;
00717   for (i = entity_list.size(); i > 0; i--) {
00718     printDag(entity_list.get_and_step(), depth);
00719   }
00720 }
00721 
00722 void DagDrawingTool::printDag( TopologyEntity* ME_ptr, int depth )
00723 {
00724   assert( ME_ptr != NULL );
00725   TopologyEntity* node = ME_ptr;
00726   print_dag( node, depth );
00727 }
00728 
00729 void DagDrawingTool::print_dag( TopologyEntity* any_dag_node, int depth )
00730 {
00731     if( depth >= 0 ) print_node( any_dag_node, 0, "**" );
00732     print_dag( any_dag_node, 1, depth );
00733     if( depth < 0 ) print_node( any_dag_node, 0, "**" );
00734 }
00735 
00736 void DagDrawingTool::print_node( TopologyEntity* node_ptr, int indent, const char* prefix )
00737 {
00738     const char* name_ptr = typeid(*node_ptr).name();
00739   while (isdigit(*name_ptr)) name_ptr++;
00740 
00741   int id = get_id( node_ptr );
00742     PRINT_INFO("%*c%s %s %d", indent*3, ' ', prefix, name_ptr, id);
00743   
00744   PRINT_INFO("\n");
00745 }
00746 
00747 int DagDrawingTool::get_id( TopologyEntity* node_ptr )
00748 {
00749   static DLT_IdTable SE_table;
00750   static DLT_IdTable GpE_table;
00751 
00752     RefEntity*       re_ptr = CAST_TO( node_ptr, RefEntity );
00753     GroupingEntity* gpe_ptr = CAST_TO( node_ptr, GroupingEntity );
00754     SenseEntity*     se_ptr = CAST_TO( node_ptr, SenseEntity );
00755     if( re_ptr )      return re_ptr->id();
00756     else if( gpe_ptr ) return GpE_table.find_id( gpe_ptr );
00757     else if( se_ptr )  return SE_table.find_id( se_ptr );
00758     else               return 0;
00759 }
00760 
00761 void DagDrawingTool::print_dag( TopologyEntity* node_ptr, int indent, int depth )
00762 {
00763     DLIList<TopologyEntity*> relatives;
00764     if( depth > 0 ) {
00765         node_ptr->get_children( &relatives );
00766         for( int i = relatives.size(); i > 0; i-- ) {
00767             TopologyEntity* child_ptr = relatives.get_and_step();
00768                 
00769             print_node( child_ptr, indent, "<>" );
00770             print_dag( child_ptr, indent + 1, depth - 1 );
00771         }
00772     }
00773     else if( depth < 0 ) {
00774         node_ptr->get_parents( &relatives );
00775         for( int i = relatives.size(); i > 0; i-- ) {
00776             TopologyEntity* parent_ptr = relatives.get_and_step();
00777                 
00778             print_dag( parent_ptr, indent + 1, depth + 1 );
00779             print_node( parent_ptr, indent, "<>" );
00780         }
00781     }
00782 }
00783 
00784 int DLT_IdTable::find_id( TopologyEntity* ME_ptr )
00785 {
00786   ME_ptr = CAST_TO( ME_ptr, TopologyEntity );
00787   if( ME_ptr == NULL ) return -1;
00788   
00789   for( int i = 0; i < current_insert_pos; i++ )
00790   {
00791     if( ME_ptrs_[i] == ME_ptr ) return i + 1;
00792   }
00793   if( current_insert_pos == 500 ) return -1;
00794   ME_ptrs_[ current_insert_pos ] = ME_ptr;
00795   current_insert_pos++;
00796   return current_insert_pos;
00797 }
00798 
00799 
00800 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines