/src/contrib/geom-5.1.2.7/src/GEOMAlgo/GEOMAlgo_Builder_4.cpp

http://pythonocc.googlecode.com/ · C++ · 317 lines · 216 code · 9 blank · 92 comment · 61 complexity · be0d5b9a508a8177afe6a6934dffa1a8 MD5 · raw file

  1. // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
  2. //
  3. // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
  4. // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
  5. //
  6. // This library is free software; you can redistribute it and/or
  7. // modify it under the terms of the GNU Lesser General Public
  8. // License as published by the Free Software Foundation; either
  9. // version 2.1 of the License.
  10. //
  11. // This library is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. // Lesser General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Lesser General Public
  17. // License along with this library; if not, write to the Free Software
  18. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. //
  20. // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
  21. //
  22. // File: GEOMAlgo_Builder_4.cxx
  23. // Created:
  24. // Author: Peter KURNEV
  25. //
  26. #include <GEOMAlgo_Builder.hxx>
  27. #include <TopoDS_Iterator.hxx>
  28. #include <TopTools_ListOfShape.hxx>
  29. #include <TopTools_ListIteratorOfListOfShape.hxx>
  30. #include <TopTools_MapOfShape.hxx>
  31. #include <TopTools_MapIteratorOfMapOfShape.hxx>
  32. #include <IntTools_Context.hxx>
  33. #include <NMTDS_ShapesDataStructure.hxx>
  34. #include <NMTTools_PaveFiller.hxx>
  35. #include <GEOMAlgo_Tools3D.hxx>
  36. static
  37. void MapShapes(const TopoDS_Shape& aS,
  38. TopTools_MapOfShape& aM);
  39. //=======================================================================
  40. //function : Generated
  41. //purpose :
  42. //=======================================================================
  43. const TopTools_ListOfShape& GEOMAlgo_Builder::Generated(const TopoDS_Shape& theS)
  44. {
  45. const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
  46. NMTTools_PaveFiller* pPF=myPaveFiller;
  47. IntTools_Context& aCtx=pPF->ChangeContext();
  48. //
  49. Standard_Boolean bHasImage, bToReverse;
  50. TopAbs_ShapeEnum aType;
  51. TopTools_ListIteratorOfListOfShape aIt;
  52. //
  53. myHistShapes.Clear();
  54. //
  55. if (theS.IsNull()) {
  56. return myHistShapes;
  57. }
  58. //
  59. bHasImage=myImages.HasImage(theS);
  60. if (!bHasImage) {
  61. return myHistShapes;
  62. }
  63. //
  64. aType=theS.ShapeType();
  65. //
  66. if (aType==TopAbs_EDGE || aType==TopAbs_FACE ||
  67. aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
  68. const TopTools_ListOfShape& aLSp=myImages.Image(theS);
  69. aIt.Initialize(aLSp);
  70. for (; aIt.More(); aIt.Next()) {
  71. const TopoDS_Shape& aSp=aIt.Value();
  72. if (mySameDomainShapes.Contains(aSp)) {
  73. if (myMapShape.Contains(aSp)) {
  74. TopoDS_Shape aSpR=mySameDomainShapes.FindFromKey(aSp);
  75. //
  76. if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
  77. aSpR.Orientation(theS.Orientation());
  78. }
  79. else {
  80. bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSpR, theS, aCtx);
  81. if (bToReverse) {
  82. aSpR.Reverse();
  83. }
  84. }
  85. //
  86. myHistShapes.Append(aSpR);
  87. }
  88. }
  89. }
  90. }
  91. //
  92. return myHistShapes;
  93. }
  94. //=======================================================================
  95. //function : Modified
  96. //purpose :
  97. //=======================================================================
  98. const TopTools_ListOfShape& GEOMAlgo_Builder::Modified(const TopoDS_Shape& theS)
  99. {
  100. const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
  101. NMTTools_PaveFiller* pPF=myPaveFiller;
  102. IntTools_Context& aCtx=pPF->ChangeContext();
  103. //
  104. Standard_Boolean bHasImage, bToReverse;
  105. TopAbs_ShapeEnum aType;
  106. TopTools_ListIteratorOfListOfShape aIt;
  107. //
  108. myHistShapes.Clear();
  109. //
  110. if (theS.IsNull()) {
  111. return myHistShapes;
  112. }
  113. //
  114. bHasImage=myImages.HasImage(theS);
  115. if (!bHasImage) {
  116. return myHistShapes;
  117. }
  118. //
  119. aType=theS.ShapeType();
  120. //
  121. if (aType==TopAbs_EDGE || aType==TopAbs_FACE ||
  122. aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
  123. const TopTools_ListOfShape& aLSp=myImages.Image(theS);
  124. aIt.Initialize(aLSp);
  125. for (; aIt.More(); aIt.Next()) {
  126. TopoDS_Shape aSp=aIt.Value();
  127. if (!mySameDomainShapes.Contains(aSp)) {
  128. if (myMapShape.Contains(aSp)) {
  129. //
  130. if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
  131. aSp.Orientation(theS.Orientation());
  132. }
  133. else {
  134. bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aSp, theS, aCtx);
  135. if (bToReverse) {
  136. aSp.Reverse();
  137. }
  138. }
  139. //
  140. myHistShapes.Append(aSp);
  141. }
  142. }
  143. }
  144. }
  145. //
  146. return myHistShapes;
  147. }
  148. //=======================================================================
  149. //function : IsDeleted
  150. //purpose :
  151. //=======================================================================
  152. Standard_Boolean GEOMAlgo_Builder::IsDeleted(const TopoDS_Shape& theS)
  153. {
  154. Standard_Boolean bRet, bHasImage, bContains;
  155. TopAbs_ShapeEnum aType;
  156. TopTools_ListIteratorOfListOfShape aIt;
  157. //
  158. bRet=Standard_False;
  159. //
  160. if (theS.IsNull()) {
  161. return !bRet; //true
  162. }
  163. //
  164. bContains=myMapShape.Contains(theS);
  165. if (bContains) {
  166. return bRet; //false
  167. }
  168. //
  169. bHasImage=myImages.HasImage(theS);
  170. if (!bHasImage) {
  171. return !bRet; //true
  172. }
  173. //
  174. aType=theS.ShapeType();
  175. if (aType==TopAbs_EDGE || aType==TopAbs_FACE ||
  176. aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
  177. const TopTools_ListOfShape& aLSp=myImages.Image(theS);
  178. aIt.Initialize(aLSp);
  179. for (; aIt.More(); aIt.Next()) {
  180. TopoDS_Shape aSp=aIt.Value();
  181. //
  182. if (!mySameDomainShapes.Contains(aSp)) {
  183. if (myMapShape.Contains(aSp)) {
  184. return bRet; //false
  185. }
  186. }
  187. else {
  188. TopoDS_Shape aSpR=mySameDomainShapes.FindFromKey(aSp);
  189. if (myMapShape.Contains(aSpR)) {
  190. return bRet; //false
  191. }
  192. }
  193. }
  194. }
  195. return !bRet; // true
  196. }
  197. //=======================================================================
  198. //function : PrepareHistory
  199. //purpose :
  200. //=======================================================================
  201. void GEOMAlgo_Builder::PrepareHistory()
  202. {
  203. if(myShape.IsNull()) {
  204. return;
  205. }
  206. //
  207. Standard_Boolean bHasImage, bContainsSD;
  208. TopAbs_ShapeEnum aType;
  209. TopTools_MapOfShape aMS;
  210. TopTools_ListIteratorOfListOfShape aIt;
  211. TopTools_MapIteratorOfMapOfShape aItM;
  212. //
  213. // 1. Clearing
  214. GEOMAlgo_BuilderShape::PrepareHistory();
  215. //
  216. // 2. myMapShape - all shapes of result with theirs sub-shapes
  217. MapShapes(myShape, myMapShape);
  218. //
  219. // 3. MS - all argument shapes with theirs sub-shapes
  220. aIt.Initialize(myShapes);
  221. for (; aIt.More(); aIt.Next()) {
  222. const TopoDS_Shape& aSx=aIt.Value();
  223. MapShapes(aSx, aMS);
  224. }
  225. //
  226. // 4. Treatment
  227. aItM.Initialize(aMS);
  228. for (; aItM.More(); aItM.Next()) {
  229. const TopoDS_Shape& aSx=aItM.Key();
  230. aType=aSx.ShapeType();
  231. //modified by NIZNHY-PKV Thu Dec 7 11:34:05 2006f
  232. //
  233. // 4.1 .myImagesResult
  234. TopTools_ListOfShape aLSx;
  235. //
  236. bHasImage=myImages.HasImage(aSx);
  237. if (!bHasImage) {
  238. if (myMapShape.Contains(aSx)) {
  239. aLSx.Append(aSx);
  240. myImagesResult.Add(aSx, aLSx);
  241. }
  242. }
  243. else {
  244. const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
  245. aIt.Initialize(aLSp);
  246. for (; aIt.More(); aIt.Next()) {
  247. const TopoDS_Shape& aSp=aIt.Value();
  248. if (myMapShape.Contains(aSp)) {
  249. aLSx.Append(aSp);
  250. }
  251. }
  252. myImagesResult.Add(aSx, aLSx);
  253. }
  254. //
  255. //modified by NIZNHY-PKV Thu Dec 7 11:34:10 2006t
  256. //
  257. // 4.2 As it was
  258. if (!myHasDeleted) {
  259. myHasDeleted=IsDeleted(aSx);//xx
  260. }
  261. //
  262. if (!myHasGenerated || !myHasModified) {
  263. if (aType==TopAbs_EDGE || aType==TopAbs_FACE ||
  264. aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
  265. //modified by NIZNHY-PKV Thu Dec 7 11:53:01 2006f
  266. //bHasImage=myImages.HasImage(aSx);
  267. //modified by NIZNHY-PKV Thu Dec 7 11:53:04 2006t
  268. if (bHasImage) {
  269. const TopTools_ListOfShape& aLSp=myImages.Image(aSx);
  270. aIt.Initialize(aLSp);
  271. for (; aIt.More(); aIt.Next()) {
  272. const TopoDS_Shape& aSp=aIt.Value();
  273. //
  274. if (myMapShape.Contains(aSp)) {
  275. bContainsSD=mySameDomainShapes.Contains(aSp);
  276. //
  277. if (!myHasGenerated) {
  278. if (bContainsSD) {
  279. myHasGenerated=Standard_True;
  280. }
  281. }
  282. if (!myHasModified) {
  283. if (!bContainsSD) {
  284. myHasModified=Standard_True;
  285. }
  286. }
  287. } // if (myMapShape.Contains(aSp))
  288. }
  289. }
  290. }
  291. }
  292. }
  293. }
  294. //=======================================================================
  295. //function : MapShapes
  296. //purpose :
  297. //=======================================================================
  298. void MapShapes(const TopoDS_Shape& theS,
  299. TopTools_MapOfShape& theM)
  300. {
  301. theM.Add(theS);
  302. TopoDS_Iterator anIt;
  303. anIt.Initialize(theS);
  304. for (; anIt.More(); anIt.Next()) {
  305. const TopoDS_Shape& aSx=anIt.Value();
  306. MapShapes(aSx, theM);
  307. }
  308. }