TreeLabel.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*******************************************************************************
  2. 用于显示模型的结构树
  3. 根节点名称定义为Model
  4. 节点分为两种类型,一种为TreeShape,包含子节点,但不包含具体的Face的数据,faceId均为0;
  5. 一种为TreeFace,从属于TreeShape,存储了真正的Face数据,faceId大于0;
  6. *******************************************************************************/
  7. #pragma once
  8. #include <TopoDS_Shape.hxx>
  9. #include <TDF_Label.hxx>
  10. #include <string>
  11. #include <vector>
  12. //#define UPPERBOUND 2147483647
  13. #define UPPERBOUND 1999999999
  14. using namespace std;
  15. enum TreeType
  16. {
  17. TreeShape,
  18. TreeFace
  19. };
  20. struct TreeLabel
  21. {
  22. TreeLabel()
  23. {
  24. id = 0;
  25. Name = "Model";
  26. }
  27. TreeLabel(const TopoDS_Shape &_Shape, TreeType _NodeType = TreeShape, int _Level = 0) :
  28. Shape(_Shape), NodeType(_NodeType), Level(_Level)
  29. {
  30. Name = GetName();
  31. }
  32. TreeLabel(const TDF_Label &_Label, const TopoDS_Shape &_Shape, TreeType _NodeType = TreeShape, int _Level = 0) :
  33. Label(_Label), Shape(_Shape), NodeType(_NodeType), Level(_Level)
  34. {
  35. Name = GetName();
  36. }
  37. TDF_Label Label;
  38. TopoDS_Shape Shape;
  39. TreeType NodeType;
  40. int id;
  41. int Level;
  42. string Name;
  43. vector<int> subFaceIds;
  44. //int HashCode;
  45. //int faceId;
  46. //int sid;
  47. //vector<int> subFaceHashCodes;
  48. friend bool operator < (const TreeLabel& lhs, const TreeLabel& rhs)
  49. {
  50. return lhs.id < rhs.id;
  51. }
  52. friend bool operator == (const TreeLabel& lhs, const TreeLabel& rhs)
  53. {
  54. return lhs.id == rhs.id;
  55. }
  56. string GetName()
  57. {
  58. TCollection_ExtendedString str = "";
  59. if (Label.IsNull() && Shape.IsNull())
  60. {
  61. str = "Model";
  62. }
  63. if (!Label.IsNull())
  64. {
  65. Handle(TDataStd_Name) anAttribute;
  66. if (Label.FindAttribute(TDataStd_Name::GetID(), anAttribute))
  67. {
  68. str = anAttribute->Get();
  69. }
  70. }
  71. if (str == "")
  72. {
  73. switch (Shape.ShapeType())
  74. {
  75. case TopAbs_COMPOUND:
  76. str = "Compound";
  77. break;
  78. case TopAbs_COMPSOLID:
  79. str = "CSolid";
  80. break;
  81. case TopAbs_SOLID:
  82. str = "Solid";
  83. break;
  84. case TopAbs_SHELL:
  85. str = "Shell";
  86. break;
  87. case TopAbs_FACE:
  88. str = "Face";
  89. break;
  90. case TopAbs_WIRE:
  91. str = "Wire";
  92. break;
  93. case TopAbs_EDGE:
  94. str = "Edge";
  95. break;
  96. case TopAbs_VERTEX:
  97. str = "Vertex";
  98. break;
  99. case TopAbs_SHAPE:
  100. str = "Shape";
  101. break;
  102. default:
  103. break;
  104. }
  105. }
  106. char* ch = new char[str.LengthOfCString() + 1];
  107. str.ToUTF8CString(ch);
  108. return ch;
  109. }
  110. string GetJsonName()
  111. {
  112. string tail;
  113. //if (id < 10)
  114. //{
  115. // tail = "_0000" + to_string(id);
  116. //}
  117. //else if (id < 100)
  118. //{
  119. // tail = "_000" + to_string(id);
  120. //}
  121. //else if (id < 1000)
  122. //{
  123. // tail = "_00" + to_string(id);
  124. //}
  125. //else if (id < 10000)
  126. //{
  127. // tail = "_0" + to_string(id);
  128. //}
  129. //else
  130. //{
  131. // tail = "_" + to_string(id);
  132. //}
  133. tail = "_" + to_string(id);
  134. return Name + tail;
  135. }
  136. };