|
cgma
|
#include <DagDrawingTool.hpp>
Public Member Functions | |
| ~DagDrawingTool () | |
| void | printDag (DLIList< RefFace * > &face_list, int depth) |
| Print the DAG of the specified surfaces. | |
| void | printDag (DLIList< Body * > &body_list, int depth) |
| Print the DAG of the specified body. | |
| void | printDag (DLIList< TopologyEntity * > &entity_list, int depth) |
| Print the DAG of the entities. | |
| void | printDag (TopologyEntity *ME_ptr, int depth) |
| Print the DAG of the entity. | |
Static Public Member Functions | |
| static DagDrawingTool * | instance () |
Protected Member Functions | |
| DagDrawingTool () | |
| void | draw_DAG (DLIList< RefEntity * > &enity_list, int up, int down) |
| void | draw_DAG (DLIList< TopologyEntity * > &node_list, int up, int down) |
| void | get_relatives (TopologyEntity *node_ptr, DLIList< TopologyEntity * > &result_set, int direction) |
| void | get_relatives (DLIList< TopologyEntity * > &source_set, DLIList< TopologyEntity * > &result_set, int direction) |
| int | link_type (TopologyEntity *source_node, TopologyEntity *target_node, int direction) |
| int | link_type (int source_row, int source_index, int target_row, int target_index) |
| void | position (int row, int index, float &x, float &y) |
Static Protected Attributes | |
| static DagDrawingTool * | instance_ = 0 |
Private Member Functions | |
| void | print_dag (TopologyEntity *node_ptr, int depth) |
| void | print_dag (TopologyEntity *node_ptr, int indent, int depth) |
| void | print_node (TopologyEntity *node_ptr, int indent, const char *prefix) |
| int | get_id (TopologyEntity *node_ptr) |
| void | one_sort_pass (int start_row, int end_row, float *temp_array) |
| void | sort_row (int row, int rel_row) |
Private Attributes | |
| DagNodeTable * | node_table |
Definition at line 56 of file DagDrawingTool.hpp.
Definition at line 310 of file DagDrawingTool.cpp.
{
instance_ = 0;
assert( ! node_table );
}
| DagDrawingTool::DagDrawingTool | ( | ) | [protected] |
Definition at line 41 of file DagDrawingTool.cpp.
{
node_table = 0;
}
| void DagDrawingTool::draw_DAG | ( | DLIList< RefEntity * > & | enity_list, |
| int | up, | ||
| int | down | ||
| ) | [protected] |
| void DagDrawingTool::draw_DAG | ( | DLIList< TopologyEntity * > & | node_list, |
| int | up, | ||
| int | down | ||
| ) | [protected] |
| int DagDrawingTool::get_id | ( | TopologyEntity * | node_ptr | ) | [private] |
Definition at line 747 of file DagDrawingTool.cpp.
{
static DLT_IdTable SE_table;
static DLT_IdTable GpE_table;
RefEntity* re_ptr = CAST_TO( node_ptr, RefEntity );
GroupingEntity* gpe_ptr = CAST_TO( node_ptr, GroupingEntity );
SenseEntity* se_ptr = CAST_TO( node_ptr, SenseEntity );
if( re_ptr ) return re_ptr->id();
else if( gpe_ptr ) return GpE_table.find_id( gpe_ptr );
else if( se_ptr ) return SE_table.find_id( se_ptr );
else return 0;
}
| void DagDrawingTool::get_relatives | ( | TopologyEntity * | node_ptr, |
| DLIList< TopologyEntity * > & | result_set, | ||
| int | direction | ||
| ) | [protected] |
Definition at line 560 of file DagDrawingTool.cpp.
{
result_set.clean_out();
if( direction == DDT_UP_DAG )
source_ptr->get_parents( &result_set );
else if( direction == DDT_DOWN_DAG )
source_ptr->get_children( &result_set );
else assert( (direction == DDT_UP_DAG) || (direction == DDT_DOWN_DAG) );
}
| void DagDrawingTool::get_relatives | ( | DLIList< TopologyEntity * > & | source_set, |
| DLIList< TopologyEntity * > & | result_set, | ||
| int | direction | ||
| ) | [protected] |
Definition at line 571 of file DagDrawingTool.cpp.
{
DLIList<TopologyEntity*> temp_set;
result_set.clean_out();
for( int i = 0; i < source_set.size(); i++ )
{
get_relatives( source_set.get_and_step(), temp_set, direction );
result_set.merge_unique( temp_set );
}
}
| DagDrawingTool * DagDrawingTool::instance | ( | ) | [static] |
Definition at line 305 of file DagDrawingTool.cpp.
{
return instance_ ? instance_ : instance_ = new DagDrawingTool();
}
| int DagDrawingTool::link_type | ( | TopologyEntity * | source_node, |
| TopologyEntity * | target_node, | ||
| int | direction | ||
| ) | [protected] |
Definition at line 593 of file DagDrawingTool.cpp.
{
int result = DDT_LINK_NONE;
DLIList<TopologyEntity*> parents, children;
if( direction == DDT_UP_DAG )
{
source_node->get_parents(&parents);
target_node->get_children(&children);
bool down = parents.is_in_list(target_node);
bool up = children.is_in_list(source_node);
if ( !down && !up )
result = DDT_LINK_NONE;
else if( down && up )
result = DDT_LINK_BOTH;
else
result = DDT_BAD_LINK;
}
else if( direction == DDT_DOWN_DAG )
{
source_node->get_children(&children);
target_node->get_parents(&parents);
bool up = children.is_in_list(target_node);
bool down = parents.is_in_list(source_node);
if ( !down && !up )
result = DDT_LINK_NONE;
else if( down && up )
result = DDT_LINK_BOTH;
else
result = DDT_BAD_LINK;
}
return result;
}
| int DagDrawingTool::link_type | ( | int | source_row, |
| int | source_index, | ||
| int | target_row, | ||
| int | target_index | ||
| ) | [protected] |
Definition at line 584 of file DagDrawingTool.cpp.
{
DagNodeTable& table = *node_table;
if( abs( source_row - target_row ) != 1 ) return DDT_LINK_NONE;
return link_type( table[source_row][source_index],
table[target_row][target_index],
source_row < target_row ? DDT_UP_DAG : DDT_DOWN_DAG );
}
| void DagDrawingTool::one_sort_pass | ( | int | start_row, |
| int | end_row, | ||
| float * | temp_array | ||
| ) | [private] |
Definition at line 46 of file DagDrawingTool.cpp.
{
int i, j, k;
DagNodeTable& table = *node_table;
//int row_count = table.rows();
int cur_row_len = 0;
if( start == end ) return;
int dir = (start < end) ? 1 : -1;
//for each parent row of the passed row of nodes...
for( i = start; i != (end + dir); i += dir )
{
//populate the array with the values to sort by
cur_row_len = table[i].length();
for( j = 0; j < cur_row_len; j++ )
{
val_list[j] = 0.0;
int link_count = 0;
for( k = 0; k < table[i-dir].length(); k++ )
{
if( link_type( i, j, i - dir, k ) )
{
val_list[j] += (float)k;
link_count++;
}
}
if( link_count ) val_list[j] /= (float)link_count;
}
//sort the row by the values in value_list
for( j = 0; j < cur_row_len - 1; j++ )
{
int smallest = j;
for( k = j + 1; k < cur_row_len; k++ )
{
if( val_list[k] < val_list[smallest] )
smallest = k;
}
if( smallest != j )
{
//float temp = val_list[j];
val_list[j] = val_list[smallest];
val_list[smallest] = val_list[j];
TopologyEntity* node = table[i][j];
table[i][j] = table[i][smallest];
table[i][smallest] = node;
}
}
}
}
| void DagDrawingTool::position | ( | int | row, |
| int | index, | ||
| float & | x, | ||
| float & | y | ||
| ) | [protected] |
| void DagDrawingTool::print_dag | ( | TopologyEntity * | node_ptr, |
| int | depth | ||
| ) | [private] |
Definition at line 729 of file DagDrawingTool.cpp.
{
if( depth >= 0 ) print_node( any_dag_node, 0, "**" );
print_dag( any_dag_node, 1, depth );
if( depth < 0 ) print_node( any_dag_node, 0, "**" );
}
| void DagDrawingTool::print_dag | ( | TopologyEntity * | node_ptr, |
| int | indent, | ||
| int | depth | ||
| ) | [private] |
Definition at line 761 of file DagDrawingTool.cpp.
{
DLIList<TopologyEntity*> relatives;
if( depth > 0 ) {
node_ptr->get_children( &relatives );
for( int i = relatives.size(); i > 0; i-- ) {
TopologyEntity* child_ptr = relatives.get_and_step();
print_node( child_ptr, indent, "<>" );
print_dag( child_ptr, indent + 1, depth - 1 );
}
}
else if( depth < 0 ) {
node_ptr->get_parents( &relatives );
for( int i = relatives.size(); i > 0; i-- ) {
TopologyEntity* parent_ptr = relatives.get_and_step();
print_dag( parent_ptr, indent + 1, depth + 1 );
print_node( parent_ptr, indent, "<>" );
}
}
}
| void DagDrawingTool::print_node | ( | TopologyEntity * | node_ptr, |
| int | indent, | ||
| const char * | prefix | ||
| ) | [private] |
Definition at line 736 of file DagDrawingTool.cpp.
{
const char* name_ptr = typeid(*node_ptr).name();
while (isdigit(*name_ptr)) name_ptr++;
int id = get_id( node_ptr );
PRINT_INFO("%*c%s %s %d", indent*3, ' ', prefix, name_ptr, id);
PRINT_INFO("\n");
}
| void DagDrawingTool::printDag | ( | DLIList< RefFace * > & | face_list, |
| int | depth | ||
| ) |
Print the DAG of the specified surfaces.
Definition at line 700 of file DagDrawingTool.cpp.
{
DLIList<TopologyEntity*> entity_list;
CAST_LIST_TO_PARENT(face_list, entity_list);
printDag(entity_list, depth);
}
| void DagDrawingTool::printDag | ( | DLIList< Body * > & | body_list, |
| int | depth | ||
| ) |
Print the DAG of the specified body.
Definition at line 707 of file DagDrawingTool.cpp.
{
DLIList<TopologyEntity*> entity_list;
CAST_LIST_TO_PARENT(body_list, entity_list);
printDag(entity_list, depth);
}
| void DagDrawingTool::printDag | ( | DLIList< TopologyEntity * > & | entity_list, |
| int | depth | ||
| ) |
Print the DAG of the entities.
Definition at line 714 of file DagDrawingTool.cpp.
{
int i;
for (i = entity_list.size(); i > 0; i--) {
printDag(entity_list.get_and_step(), depth);
}
}
| void DagDrawingTool::printDag | ( | TopologyEntity * | ME_ptr, |
| int | depth | ||
| ) |
Print the DAG of the entity.
Definition at line 722 of file DagDrawingTool.cpp.
{
assert( ME_ptr != NULL );
TopologyEntity* node = ME_ptr;
print_dag( node, depth );
}
| void DagDrawingTool::sort_row | ( | int | row, |
| int | rel_row | ||
| ) | [private] |
Definition at line 122 of file DagDrawingTool.cpp.
{
assert((wrt_dir == 1) || (wrt_dir == -1));
DagNodeTable& table = *node_table;
int row_len = table[row].length();
int rel_row = row + wrt_dir;
if( (row_len < 2) || (rel_row < 0) || (rel_row == table.rows()) )
return;
int* index_array = new int[row_len];
int num_rels = table[rel_row].length();
int i, j, k, l, m;
//Append first node to list
index_array[0] = 0;
//For each remaining node, insert it in the location at which
//it causes the least intersections of links.
for( i = 1; i < row_len; i++ )
{
int best_index = 0;
int intersection_count = 0;
//Get the intersection count if the node were inserted first
//in the row.
//For each possible parent node
for( k = 1; k < num_rels; k++ )
{
//Is it a parent?
if( ! link_type( row, i, rel_row, k ) )
continue;
//Count how many other links that link intersects.
//For all the other nodes in the list...
for( l = 0; l < i; l++ )
{
//For each parent to the left of my parent
for( m = 0; m < k; m++ )
{
if( link_type( row, index_array[l], rel_row, m ) )
intersection_count++;
}
}
}
//Now check the intersection count for each additional
//possible location of insertion.
for( j = 1; j <= i; j++ )
{
int current_count = 0;
//For each possible parent node
for( k = 0; k < num_rels; k++ )
{
//Is it a parent?
if( ! link_type( row, i, rel_row, k ) )
continue;
//Count how many other links from nodes to the
//left of me intersect with my link to this parent.
for( l = 0; l < j; l++ )
{
//For each parent to the right of my parent
for( m = k+1; m < num_rels; m++ )
{
if( link_type( row, index_array[l], rel_row, m ) )
current_count++;
}
}
//Count how many other links from nodes to the
//right of me intersect with my link to this parent.
for( l = j; l < i; l++ )
{
//For each parent to the left of my parent
for( m = 0; m < k; m++ )
{
if( link_type( row, index_array[l], rel_row, m ) )
current_count++;
}
}
}
if( current_count <= intersection_count )
{
intersection_count = current_count;
best_index = j;
}
}
//Now insert this node at the best location.
for( j = i; j > best_index; j-- )
index_array[j] = index_array[j-1];
index_array[best_index] = i;
}
//Now rearrange the nodes in the actual row to match
//what is stored in index_list
TopologyEntity** node_array = new TopologyEntity*[row_len];
for( i = 0; i < row_len; i++ )
{
node_array[i] = table[row][index_array[i]];
}
for( i = 0; i < row_len; i++ )
{
table[row][i] = node_array[i];
}
delete [] node_array;
delete [] index_array;
}
DagDrawingTool * DagDrawingTool::instance_ = 0 [static, protected] |
Definition at line 147 of file DagDrawingTool.hpp.
DagNodeTable* DagDrawingTool::node_table [private] |
Definition at line 234 of file DagDrawingTool.hpp.