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

http://pythonocc.googlecode.com/ · C++ · 326 lines · 207 code · 9 blank · 110 comment · 33 complexity · 405d65c997ffc7b1f4c2dddcaff62ec1 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_Splitter.cxx
  23. // Created:
  24. // Author: Peter KURNEV
  25. // <pkv@irinox>
  26. //
  27. #include <GEOMAlgo_Splitter.ixx>
  28. #include <TopAbs_ShapeEnum.hxx>
  29. #include <TopoDS_Shape.hxx>
  30. #include <TopoDS_Compound.hxx>
  31. #include <TopoDS_Iterator.hxx>
  32. #include <TopExp.hxx>
  33. #include <BRep_Builder.hxx>
  34. #include <BRepLib.hxx>
  35. #include <TopTools_MapOfShape.hxx>
  36. #include <TopTools_ListOfShape.hxx>
  37. #include <TopTools_ListIteratorOfListOfShape.hxx>
  38. #include <TopTools_IndexedMapOfShape.hxx>
  39. #include <BOP_CorrectTolerances.hxx>
  40. static
  41. void TreatCompound(const TopoDS_Shape& aC,
  42. TopTools_ListOfShape& aLSX);
  43. //=======================================================================
  44. //function :
  45. //purpose :
  46. //=======================================================================
  47. GEOMAlgo_Splitter::GEOMAlgo_Splitter()
  48. :
  49. GEOMAlgo_Builder()
  50. {
  51. myLimit=TopAbs_SHAPE;
  52. myLimitMode=0;
  53. }
  54. //=======================================================================
  55. //function : ~
  56. //purpose :
  57. //=======================================================================
  58. GEOMAlgo_Splitter::~GEOMAlgo_Splitter()
  59. {
  60. }
  61. //=======================================================================
  62. //function : AddToolCompound
  63. //purpose :
  64. //=======================================================================
  65. void GEOMAlgo_Splitter::AddToolCompound(const TopoDS_Shape& theShape)
  66. {
  67. TopoDS_Iterator aIt;
  68. //
  69. aIt.Initialize(theShape);
  70. for (; aIt.More(); aIt.Next()) {
  71. const TopoDS_Shape& aS=aIt.Value();
  72. AddTool(aS);
  73. }
  74. }
  75. //=======================================================================
  76. //function : AddTool
  77. //purpose :
  78. //=======================================================================
  79. void GEOMAlgo_Splitter::AddTool(const TopoDS_Shape& theShape)
  80. {
  81. if (myMapTools.Add(theShape)) {
  82. myTools.Append(theShape);
  83. //
  84. AddShape(theShape);
  85. }
  86. }
  87. //=======================================================================
  88. //function : Tools
  89. //purpose :
  90. //=======================================================================
  91. const TopTools_ListOfShape& GEOMAlgo_Splitter::Tools()const
  92. {
  93. return myTools;
  94. }
  95. //=======================================================================
  96. //function : SetLimit
  97. //purpose :
  98. //=======================================================================
  99. void GEOMAlgo_Splitter::SetLimit(const TopAbs_ShapeEnum aLimit)
  100. {
  101. myLimit=aLimit;
  102. }
  103. //=======================================================================
  104. //function : Limit
  105. //purpose :
  106. //=======================================================================
  107. TopAbs_ShapeEnum GEOMAlgo_Splitter::Limit()const
  108. {
  109. return myLimit;
  110. }
  111. //=======================================================================
  112. //function : SetLimitMode
  113. //purpose :
  114. //=======================================================================
  115. void GEOMAlgo_Splitter::SetLimitMode(const Standard_Integer aMode)
  116. {
  117. myLimitMode=aMode;
  118. }
  119. //=======================================================================
  120. //function : LimitMode
  121. //purpose :
  122. //=======================================================================
  123. Standard_Integer GEOMAlgo_Splitter::LimitMode()const
  124. {
  125. return myLimitMode;
  126. }
  127. //=======================================================================
  128. //function : Clear
  129. //purpose :
  130. //=======================================================================
  131. void GEOMAlgo_Splitter::Clear()
  132. {
  133. myTools.Clear();
  134. myMapTools.Clear();
  135. myLimit=TopAbs_SHAPE;
  136. GEOMAlgo_Builder::Clear();
  137. }
  138. //=======================================================================
  139. //function : BuildResult
  140. //purpose :
  141. //=======================================================================
  142. void GEOMAlgo_Splitter::BuildResult(const TopAbs_ShapeEnum theType)
  143. {
  144. myErrorStatus=0;
  145. //
  146. TopAbs_ShapeEnum aType;
  147. BRep_Builder aBB;
  148. TopTools_MapOfShape aM;
  149. TopTools_ListIteratorOfListOfShape aIt, aItIm;
  150. //
  151. aIt.Initialize(myShapes);
  152. for (; aIt.More(); aIt.Next()) {
  153. const TopoDS_Shape& aS=aIt.Value();
  154. aType=aS.ShapeType();
  155. if (aType==theType && !myMapTools.Contains(aS)) {
  156. if (myImages.HasImage(aS)) {
  157. const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
  158. aItIm.Initialize(aLSIm);
  159. for (; aItIm.More(); aItIm.Next()) {
  160. const TopoDS_Shape& aSIm=aItIm.Value();
  161. if (aM.Add(aSIm)) {
  162. aBB.Add(myShape, aSIm);
  163. }
  164. }
  165. }
  166. else {
  167. if (aM.Add(aS)) {
  168. aBB.Add(myShape, aS);
  169. }
  170. }
  171. }
  172. }
  173. }
  174. //=======================================================================
  175. //function : PostTreat
  176. //purpose :
  177. //=======================================================================
  178. void GEOMAlgo_Splitter::PostTreat()
  179. {
  180. if (myLimit!=TopAbs_SHAPE) {
  181. Standard_Integer i, aNbS;
  182. BRep_Builder aBB;
  183. TopoDS_Compound aC;
  184. TopTools_IndexedMapOfShape aMx;
  185. //
  186. aBB.MakeCompound(aC);
  187. //
  188. TopExp::MapShapes(myShape, myLimit, aMx);
  189. aNbS=aMx.Extent();
  190. for (i=1; i<=aNbS; ++i) {
  191. const TopoDS_Shape& aS=aMx(i);
  192. aBB.Add(aC, aS);
  193. }
  194. //modified by NIZNHY-PKV Thu Feb 15 17:09:32 2007f
  195. if (myLimitMode) {
  196. Standard_Integer iType, iLimit, iTypeX;
  197. TopAbs_ShapeEnum aType, aTypeX;
  198. TopTools_ListOfShape aLSP, aLSX;
  199. TopTools_ListIteratorOfListOfShape aIt, aItX, aItIm;
  200. TopTools_MapOfShape aM;
  201. //
  202. iLimit=(Standard_Integer)myLimit;
  203. //
  204. // 1. Collect the shapes to process aLSP
  205. aIt.Initialize(myShapes);
  206. for (; aIt.More(); aIt.Next()) {
  207. const TopoDS_Shape& aS=aIt.Value();
  208. if (myMapTools.Contains(aS)) {
  209. continue;
  210. }
  211. //
  212. aType=aS.ShapeType();
  213. iType=(Standard_Integer)aType;
  214. //
  215. if (iType>iLimit) {
  216. aLSP.Append(aS);
  217. }
  218. //
  219. else if (aType==TopAbs_COMPOUND) {
  220. aLSX.Clear();
  221. //
  222. TreatCompound(aS, aLSX);
  223. //
  224. aItX.Initialize(aLSX);
  225. for (; aItX.More(); aItX.Next()) {
  226. const TopoDS_Shape& aSX=aItX.Value();
  227. aTypeX=aSX.ShapeType();
  228. iTypeX=(Standard_Integer)aTypeX;
  229. //
  230. if (iTypeX>iLimit) {
  231. aLSP.Append(aSX);
  232. }
  233. }
  234. }
  235. }// for (; aIt.More(); aIt.Next()) {
  236. //
  237. // 2. Add them to aC
  238. aIt.Initialize(aLSP);
  239. for (; aIt.More(); aIt.Next()) {
  240. const TopoDS_Shape& aS=aIt.Value();
  241. if (myImages.HasImage(aS)) {
  242. const TopTools_ListOfShape& aLSIm=myImages.Image(aS);
  243. aItIm.Initialize(aLSIm);
  244. for (; aItIm.More(); aItIm.Next()) {
  245. const TopoDS_Shape& aSIm=aItIm.Value();
  246. if (aM.Add(aSIm)) {
  247. aBB.Add(aC, aSIm);
  248. }
  249. }
  250. }
  251. else {
  252. if (aM.Add(aS)) {
  253. aBB.Add(aC, aS);
  254. }
  255. }
  256. }
  257. }// if (myLimitMode) {
  258. //modified by NIZNHY-PKV Thu Feb 15 17:09:34 2007t
  259. myShape=aC;
  260. }//if (myLimit!=TopAbs_SHAPE) {
  261. //
  262. GEOMAlgo_Builder::PostTreat();
  263. }
  264. //=======================================================================
  265. //function : TreatCompound
  266. //purpose :
  267. //=======================================================================
  268. void TreatCompound(const TopoDS_Shape& aC1,
  269. TopTools_ListOfShape& aLSX)
  270. {
  271. Standard_Integer aNbC1;
  272. TopAbs_ShapeEnum aType;
  273. TopTools_ListOfShape aLC, aLC1;
  274. TopTools_ListIteratorOfListOfShape aIt, aIt1;
  275. TopoDS_Iterator aItC;
  276. //
  277. aLC.Append (aC1);
  278. while(1) {
  279. aLC1.Clear();
  280. aIt.Initialize(aLC);
  281. for (; aIt.More(); aIt.Next()) {
  282. const TopoDS_Shape& aC=aIt.Value(); //C is compound
  283. //
  284. aItC.Initialize(aC);
  285. for (; aItC.More(); aItC.Next()) {
  286. const TopoDS_Shape& aS=aItC.Value();
  287. aType=aS.ShapeType();
  288. if (aType==TopAbs_COMPOUND) {
  289. aLC1.Append(aS);
  290. }
  291. else {
  292. aLSX.Append(aS);
  293. }
  294. }
  295. }
  296. //
  297. aNbC1=aLC1.Extent();
  298. if (!aNbC1) {
  299. break;
  300. }
  301. //
  302. aLC.Clear();
  303. aIt.Initialize(aLC1);
  304. for (; aIt.More(); aIt.Next()) {
  305. const TopoDS_Shape& aSC=aIt.Value();
  306. aLC.Append(aSC);
  307. }
  308. }// while(1)
  309. }
  310. //
  311. // myErrorStatus
  312. //
  313. // 0 - Ok
  314. // 1 - The object is just initialized
  315. // 2 - PaveFiller is failed
  316. // 10 - No shapes to process
  317. // 30 - SolidBuilder failed