NestingTreeSubgraphNode.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #include "NestingTreeSubgraphNode.h"
  2. NestingTreeSubgraphNode::NestingTreeSubgraphNode()
  3. {
  4. m_bIsRoot = false;
  5. m_parentNestingTreeSubraphNode = NULL;
  6. m_gSubgraph = NULL;
  7. m_iMinRank = 0;
  8. m_iMaxRank = 0;
  9. }
  10. NestingTreeSubgraphNode::NestingTreeSubgraphNode(SubGraph &gGraph)
  11. {
  12. m_gSubgraph = &gGraph;
  13. m_bIsRoot = gGraph.is_root();
  14. VertexDescriptor vUpperBorder = m_BoostGraphWrapper.getGraphUpperBorderVertex(gGraph);
  15. VertexDescriptor vLowerBorder = m_BoostGraphWrapper.getGraphLowerBorderVertex(gGraph);
  16. m_iMinRank = m_BoostGraphWrapper.getVertexRank(vUpperBorder , gGraph);
  17. m_iMaxRank = m_BoostGraphWrapper.getVertexRank(vLowerBorder , gGraph);
  18. }
  19. void NestingTreeSubgraphNode::setGraph(SubGraph &gGraph)
  20. {
  21. m_gSubgraph = &gGraph;
  22. m_bIsRoot = gGraph.is_root();
  23. VertexDescriptor vUpperBorder = m_BoostGraphWrapper.getGraphUpperBorderVertex(gGraph);
  24. VertexDescriptor vLowerBorder = m_BoostGraphWrapper.getGraphLowerBorderVertex(gGraph);
  25. m_iMinRank = m_BoostGraphWrapper.getVertexRank(vUpperBorder , gGraph);
  26. m_iMaxRank = m_BoostGraphWrapper.getVertexRank(vLowerBorder , gGraph);
  27. }
  28. SubGraph &NestingTreeSubgraphNode::getGraph()
  29. {
  30. return *m_gSubgraph;
  31. }
  32. NestingTreeSubgraphNode &NestingTreeSubgraphNode::getParent()
  33. {
  34. return *m_parentNestingTreeSubraphNode;
  35. }
  36. void NestingTreeSubgraphNode::setParentNestingTreeSubgraphNode(NestingTreeSubgraphNode &parentNestingTreeSubraphNode)
  37. {
  38. m_parentNestingTreeSubraphNode = &parentNestingTreeSubraphNode;
  39. }
  40. bool NestingTreeSubgraphNode::isRoot()
  41. {
  42. //Q_ASSERT_X(m_gSubgraph != NULL , "Nesting Tree Subgraph Node" , "Checking graph isRoot property without assigning a graph");
  43. LAYOUT_ASSERT(m_gSubgraph != NULL , LayoutException(__FUNCTION__
  44. ,LayoutExceptionEnum::INVALID_OPERATION
  45. ,"Checking graph isRoot property without assigning a graph"
  46. , "Nesting Tree Subgraph Node"));
  47. return m_bIsRoot;
  48. }
  49. NestingTreeSubgraphNode& NestingTreeSubgraphNode::addChildNestingTreeSubgraphNode(SubGraph &gChildGraph)
  50. {
  51. NestingTreeSubgraphNode *newChildNestingTreeSubgraphNode;
  52. newChildNestingTreeSubgraphNode = new NestingTreeSubgraphNode(gChildGraph);
  53. //Add child entry to vec
  54. m_vecChildNestingTreeSubgraphNode.push_back(newChildNestingTreeSubgraphNode);
  55. //Set child subGraph Nodes Parent
  56. newChildNestingTreeSubgraphNode->setParentNestingTreeSubgraphNode(*this);
  57. return *newChildNestingTreeSubgraphNode;
  58. }
  59. const NestingTreeSubgraphNode::VectorNestingTreeSubgraphNodesRef &NestingTreeSubgraphNode::getChildNestingTreeSubgraphNodes()
  60. {
  61. return m_vecChildNestingTreeSubgraphNode;
  62. }
  63. NestingTreeSubgraphNode::IteratorVectorNestingTreeSubgraphNodesRef NestingTreeSubgraphNode::getIteratorChildNestingTreeSubgraphNodes()
  64. {
  65. IteratorVectorNestingTreeSubgraphNodesRef iterVecNestingTreeSubgraphNodesRef(m_vecChildNestingTreeSubgraphNode);
  66. return iterVecNestingTreeSubgraphNodesRef;
  67. }
  68. int NestingTreeSubgraphNode::getCountOfChildNestingTreeSubgraphNodes()
  69. {
  70. return m_vecChildNestingTreeSubgraphNode.size();
  71. }
  72. int NestingTreeSubgraphNode::getCountOfLayerNodes()
  73. {
  74. return m_mapLayerIdToLayerNodeRef.size();
  75. }
  76. NestingTreeSubgraphNode::MultiMapLayerIdToLayerNodeRef& NestingTreeSubgraphNode::getMapLayerIdToLayerNodeRef()
  77. {
  78. return m_mapLayerIdToLayerNodeRef;
  79. }
  80. NestingTreeSubgraphNode::IteratorMultiMapLayerIdToLayerNodeRef NestingTreeSubgraphNode::getChildLayerNodesIterator()
  81. {
  82. IteratorMultiMapLayerIdToLayerNodeRef iterLayerNodes(m_mapLayerIdToLayerNodeRef);
  83. return iterLayerNodes;
  84. }
  85. void NestingTreeSubgraphNode::addLayerIdAndLayerNode(int iLayerRank, LayerNode* layerNodeRef)
  86. {
  87. //Add layer node to LayerIdToLayerNodeRef multimap
  88. m_mapLayerIdToLayerNodeRef.insertMulti(iLayerRank , layerNodeRef);
  89. //Record Layer Id //Edit 4-9-14
  90. recordLayerIdRecurUp(iLayerRank);
  91. }
  92. int NestingTreeSubgraphNode::getMinRank()
  93. {
  94. LAYOUT_ASSERT(m_gSubgraph != NULL , LayoutException(__FUNCTION__
  95. ,LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  96. ,"Subgraph and thus MinRank"
  97. , "Nesting Tree Subgraph Node"));
  98. return m_iMinRank;
  99. }
  100. int NestingTreeSubgraphNode::getMaxRank()
  101. {
  102. LAYOUT_ASSERT(m_gSubgraph != NULL , LayoutException(__FUNCTION__
  103. ,LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  104. ,"Subgraph and thus MaxRank"
  105. , "Nesting Tree Subgraph Node"));
  106. return m_iMaxRank;
  107. }
  108. bool NestingTreeSubgraphNode::isBetweenMinMaxRanks(int iRank)
  109. {
  110. //Q_ASSERT_X(iRank > 0 , "Checking isBetweenMinMaxRanks" , "Invalid rank value. Rank should be greater than 0");
  111. LAYOUT_ASSERT(iRank > 0 , LayoutException(__FUNCTION__ , LayoutExceptionEnum::INVALID_PARAMETER
  112. , "Rank should be greater than 0"
  113. , "iRank"));
  114. //Q_ASSERT_X(m_gSubgraph != NULL , "Checking isBetweenMinMaxRanks" , "Boost Subgraph is not assigned to current Nesting Tree Subgaph Node");
  115. LAYOUT_ASSERT(m_gSubgraph != NULL , LayoutException(__FUNCTION__
  116. , LayoutExceptionEnum::REQUIRED_PARAMETER_NOT_SET
  117. , "Subgraph for current Nesting Tree Node", "" ));
  118. bool bIsBetweenMinMaxRanks = false;
  119. if(m_iMinRank <= iRank && iRank <= m_iMaxRank)
  120. {
  121. bIsBetweenMinMaxRanks = true;
  122. }
  123. return bIsBetweenMinMaxRanks;
  124. }
  125. void NestingTreeSubgraphNode::recordLayerIdRecurUp(int iLayerId)
  126. {
  127. if(doesSubgraphNodeContainLayerId(iLayerId) == false)
  128. {
  129. m_setLayerIds.insert(iLayerId);
  130. //Update parent hierararchy for including new LayerId
  131. if(m_parentNestingTreeSubraphNode != NULL)
  132. {
  133. (*m_parentNestingTreeSubraphNode).recordLayerIdRecurUp(iLayerId);
  134. }
  135. }
  136. }
  137. bool NestingTreeSubgraphNode::doesSubgraphNodeContainLayerId(int iLayerId)
  138. {
  139. return m_setLayerIds.contains(iLayerId);
  140. }
  141. double NestingTreeSubgraphNode::updateAverageBarryCenter()
  142. {
  143. try
  144. {
  145. LAYOUT_ASSERT(m_gSubgraph != NULL , LayoutMemoryException(__FUNCTION__
  146. , LayoutExceptionEnum::NULL_POINTER_EXCEPTION
  147. , "Subgraph for current nesting tree node"));
  148. int iTotalVertices = num_vertices(*m_gSubgraph);
  149. double dTotalBarryCenterWeight = 0.0;
  150. BGL_FORALL_VERTICES(vVertex, *m_gSubgraph , SubGraph)
  151. {
  152. dTotalBarryCenterWeight += m_BoostGraphWrapper.getVertexHorizontalPosition(vVertex , *m_gSubgraph);
  153. }
  154. m_dAverageBarryCenter = dTotalBarryCenterWeight / (double)iTotalVertices;
  155. }
  156. catch(boost::exception &eBoostException)
  157. {
  158. throw *boost::get_error_info<errmsg_info>(eBoostException);
  159. }
  160. catch(LayoutException &eLayoutException)
  161. {
  162. throw eLayoutException;
  163. }
  164. // XXX obselete
  165. // catch(LayoutMemoryException &eMemoryException)
  166. // {
  167. // throw eMemoryException;
  168. // }
  169. catch(...)
  170. {
  171. throw LayoutException(__FUNCTION__ , LayoutExceptionEnum::UNKNOWNLAYOUTEXCEPTION);
  172. }
  173. return m_dAverageBarryCenter;
  174. }
  175. double NestingTreeSubgraphNode::getAverageBarryCenter()
  176. {
  177. return m_dAverageBarryCenter;
  178. }
  179. int NestingTreeSubgraphNode::setSubgraphOrderingGraphVertexIndex(int iSubgraphOrderingGraphVertexIndex)
  180. {
  181. m_iSubgraphOrderingGraphVertexIndex = iSubgraphOrderingGraphVertexIndex;
  182. // XXX must return something
  183. return 0;
  184. }
  185. int NestingTreeSubgraphNode::getSubgraphOrderingGraphVertexIndex()
  186. {
  187. return m_iSubgraphOrderingGraphVertexIndex;
  188. }
  189. int NestingTreeSubgraphNode::setTopologicalOrder(int iTopologicalOrder)
  190. {
  191. m_iTopologocalOrder = iTopologicalOrder;
  192. // XXX must return something
  193. return 0;
  194. }
  195. int NestingTreeSubgraphNode::getTopologicalOrder()
  196. {
  197. return m_iTopologocalOrder;
  198. }
  199. void NestingTreeSubgraphNode::printName()
  200. {
  201. QString sName = m_BoostGraphWrapper.getGraphId(*m_gSubgraph);
  202. qDebug() << sName;
  203. }