1 // Created by: Eugeny MALTCHIKOV
2 // Copyright (c) 2015 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <BOPTest.hxx>
17 #include <BOPTest_Objects.hxx>
18 #include <BOPTest_DrawableShape.hxx>
21 #include <Draw_Color.hxx>
25 #include <BRep_Builder.hxx>
27 #include <TopoDS_Compound.hxx>
29 #include <TopExp_Explorer.hxx>
31 #include <BOPDS_DS.hxx>
32 #include <BOPDS_Iterator.hxx>
33 #include <BOPDS_MapOfCommonBlock.hxx>
35 #include <BOPAlgo_Builder.hxx>
36 #include <BOPAlgo_BuilderFace.hxx>
37 #include <BOPAlgo_BuilderSolid.hxx>
39 #include <BOPCol_MapOfShape.hxx>
40 #include <BOPCol_DataMapOfShapeShape.hxx>
41 #include <BOPCol_DataMapOfShapeListOfShape.hxx>
45 void GetTypeByName(const char* theName,
46 TopAbs_ShapeEnum& theType);
48 void GetNameByType(const TopAbs_ShapeEnum& theType,
51 template <class InterfType> static
52 void DumpInterfs(const BOPCol_NCVector<InterfType>& theVInterf,
53 Draw_Interpretor& di);
55 template <class InterfType> static
56 void SearchNewIndex(const char* theCType,
57 const Standard_Integer theInd,
58 const BOPCol_NCVector<InterfType>& theVInterf,
59 Draw_Interpretor& di);
61 Standard_Integer bopfinfo(Draw_Interpretor& di,
64 const Standard_Integer iPriz);
70 static Standard_Integer bopds (Draw_Interpretor&, Standard_Integer, const char**);
71 static Standard_Integer bopiterator (Draw_Interpretor&, Standard_Integer, const char**);
72 static Standard_Integer bopinterf (Draw_Interpretor&, Standard_Integer, const char**);
73 static Standard_Integer bopnews (Draw_Interpretor&, Standard_Integer, const char**);
74 static Standard_Integer bopwho (Draw_Interpretor&, Standard_Integer, const char**);
75 static Standard_Integer bopindex (Draw_Interpretor&, Standard_Integer, const char**);
76 static Standard_Integer bopsd (Draw_Interpretor&, Standard_Integer, const char**);
77 static Standard_Integer bopsc (Draw_Interpretor&, Standard_Integer, const char**);
79 // 1.2 pave blocks commands
80 static Standard_Integer boppb (Draw_Interpretor&, Standard_Integer, const char**);
81 static Standard_Integer bopcb (Draw_Interpretor&, Standard_Integer, const char**);
82 static Standard_Integer bopsp (Draw_Interpretor&, Standard_Integer, const char**);
84 // 1.3 face info commands
85 static Standard_Integer bopfon (Draw_Interpretor&, Standard_Integer, const char**);
86 static Standard_Integer bopfin (Draw_Interpretor&, Standard_Integer, const char**);
87 static Standard_Integer bopfsc (Draw_Interpretor&, Standard_Integer, const char**);
88 static Standard_Integer bopfav (Draw_Interpretor&, Standard_Integer, const char**);
90 // 2. builder commands
91 // 2.1 images commands
92 static Standard_Integer bopimage (Draw_Interpretor&, Standard_Integer, const char**);
93 static Standard_Integer boporigin (Draw_Interpretor&, Standard_Integer, const char**);
94 static Standard_Integer bopfsd (Draw_Interpretor&, Standard_Integer, const char**);
97 static Standard_Integer bopbface (Draw_Interpretor&, Standard_Integer, const char**);
98 // 2.3 building solids
99 static Standard_Integer bopbsolid (Draw_Interpretor&, Standard_Integer, const char**);
102 //=======================================================================
103 //function : DebugCommands
105 //=======================================================================
106 void BOPTest::DebugCommands(Draw_Interpretor& theCommands)
108 static Standard_Boolean done = Standard_False;
110 done = Standard_True;
112 const char* g = "BOPTest commands";
114 theCommands.Add("bopds",
115 "Shows the shapes from DS. Use: bopds [v/e/w/f/sh/s/cs/c]",
117 theCommands.Add("bopiterator",
118 "Shows the pairs of interfered shapes. Use: bopiterator [type1 type2]",
119 __FILE__, bopiterator, g);
120 theCommands.Add("bopinterf", "Shows interferences of given type. Use: bopinterf type1 type2",
121 __FILE__, bopinterf, g);
122 theCommands.Add("bopnews", "Shows the newly created shapes. Use: bopnews [v,e,f]",
123 __FILE__, bopnews, g);
124 theCommands.Add("bopwho", "Shows where the new shape was created. Use: bopwho #",
125 __FILE__, bopwho, g);
126 theCommands.Add("bopindex", "Gets the index of the shape in the DS. Use: bopindex s",
127 __FILE__, bopindex, g);
128 theCommands.Add("bopsd", "Gets the Same domain shape. Use: bopsd #",
130 theCommands.Add("bopsc", "Shows the section curves. Use: bopsc [nF1 nF2]",
132 theCommands.Add("boppb", "Shows information about pave blocks. Use: boppb [#e]",
134 theCommands.Add("bopcb", "Shows information about common blocks. Use: bopcb [#e]",
136 theCommands.Add("bopsp", "Shows the splits of edges. Use: bopsp [#e]",
138 theCommands.Add("bopfon", "Shows ON information for the face. Use: bopfon #f",
139 __FILE__, bopfon, g);
140 theCommands.Add("bopfin", "Shows IN information for the face. Use: bopfin #f",
141 __FILE__, bopfin, g);
142 theCommands.Add("bopfsc", "Shows SC information for the face. Use: bopfsc #f",
143 __FILE__, bopfsc, g);
144 theCommands.Add("bopfav", "Shows information about alone vertices for the face. Use: bopfav #f",
145 __FILE__, bopfav, g);
146 theCommands.Add("bopimage", "Shows split parts of the shape. Use: bopimage s",
147 __FILE__, bopimage, g);
148 theCommands.Add("boporigin", "Shows the original shape for the shape. Use: boporigin s",
149 __FILE__, boporigin, g);
150 theCommands.Add("bopfsd", "Shows SD faces for the face: Use: bopfsd f",
151 __FILE__, bopfsd, g);
152 theCommands.Add("bopbsolid", "Build solids from set of shared faces. Use: bopbsolid sr cx",
153 __FILE__, bopbsolid, g);
154 theCommands.Add("bopbface", "Splits the face by set of shared edges. Use: bopbface fr cx",
155 __FILE__, bopbface, g);
158 //=======================================================================
161 //=======================================================================
162 Standard_Integer bopds (Draw_Interpretor& di,
167 di << "Shows the shapes from DS. Use: bopds [v/e/w/f/sh/s/cs/c]\n";
171 BOPDS_PDS pDS = BOPTest_Objects::PDS();
173 di << " prepare PaveFiller first\n";
178 Standard_CString aText;
179 Standard_Integer i, aNbS;
180 TopAbs_ShapeEnum aType, aTypeShape;
181 Draw_Color aTextColor(Draw_cyan);
183 BOPDS_DS& aDS = *pDS;
184 aNbS = aDS.NbSourceShapes();
186 aType = TopAbs_SHAPE;
188 GetTypeByName(a[1], aType);
191 for (i = 0; i < aNbS; ++i) {
192 const BOPDS_ShapeInfo& aSI = aDS.ShapeInfo(i);
193 const TopoDS_Shape& aS = aSI.Shape();
194 aTypeShape = aSI.ShapeType();
196 if (aTypeShape == TopAbs_COMPOUND ||
197 aTypeShape == TopAbs_COMPSOLID ||
198 aTypeShape == TopAbs_SOLID ||
199 aTypeShape == TopAbs_SHELL ||
200 aTypeShape == TopAbs_WIRE) {
205 if (aTypeShape != aType) {
210 Sprintf(buf, "z%d", i);
212 Handle(BOPTest_DrawableShape) aDShape = new BOPTest_DrawableShape(aS, aText, aTextColor);
213 Draw::Set(aText, aDShape);
219 //=======================================================================
220 //function : bopiterator
222 //=======================================================================
223 Standard_Integer bopiterator (Draw_Interpretor& di,
227 if (n != 1 && n != 3) {
228 di << "Shows the pairs of interfered shapes. Use: bopiterator [type1 type2]\n";
232 BOPDS_PDS pDS = BOPTest_Objects::PDS();
234 di << " prepare PaveFiller first\n";
238 Standard_Integer n1, n2;
239 char buf[64], aST1[10], aST2[10];
242 BOPDS_DS& aDS = *pDS;
247 // type has not been defined. show all pairs
248 Standard_Integer i, j;
249 TopAbs_ShapeEnum aT[4] =
250 {TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID};
251 for (i = 0; i < 4; ++i) {
252 GetNameByType(aT[i], aST1);
254 for (j = i; j < 4; ++j) {
255 GetNameByType(aT[j], aST2);
257 aIt.Initialize(aT[i], aT[j]);
258 for (; aIt.More(); aIt.Next()) {
261 Sprintf(buf, "%s/%s: (z%d z%d)\n", aST1, aST2, n1, n2);
268 TopAbs_ShapeEnum aT1, aT2;
270 GetTypeByName(a[1], aT1);
271 GetTypeByName(a[2], aT2);
273 GetNameByType(aT1, aST1);
274 GetNameByType(aT2, aST2);
276 aIt.Initialize(aT1, aT2);
277 for (; aIt.More(); aIt.Next()) {
280 Sprintf(buf, "%s/%s: (z%d z%d)\n", aST1, aST2, n1, n2);
288 //=======================================================================
289 //function : bopinterf
291 //=======================================================================
292 Standard_Integer bopinterf (Draw_Interpretor& di,
297 di << "Shows interferences of given type. Use: bopinterf type1 type2\n";
301 BOPDS_PDS pDS = BOPTest_Objects::PDS();
303 di << " prepare PaveFiller first\n";
307 TopAbs_ShapeEnum aT1, aT2;
308 GetTypeByName(a[1], aT1);
309 GetTypeByName(a[2], aT2);
311 if (aT1 == TopAbs_VERTEX && aT2 == TopAbs_VERTEX) {
313 DumpInterfs<BOPDS_InterfVV>(pDS->InterfVV(), di);
315 else if ((aT1 == TopAbs_VERTEX && aT2 == TopAbs_EDGE) ||
316 (aT2 == TopAbs_VERTEX && aT1 == TopAbs_EDGE)) {
318 DumpInterfs<BOPDS_InterfVE>(pDS->InterfVE(), di);
320 else if (aT1 == TopAbs_EDGE && aT2 == TopAbs_EDGE) {
322 DumpInterfs<BOPDS_InterfEE>(pDS->InterfEE(), di);
324 else if ((aT1 == TopAbs_VERTEX && aT2 == TopAbs_FACE) ||
325 (aT2 == TopAbs_VERTEX && aT1 == TopAbs_FACE)) {
327 DumpInterfs<BOPDS_InterfVF>(pDS->InterfVF(), di);
329 else if ((aT1 == TopAbs_EDGE && aT2 == TopAbs_FACE) ||
330 (aT2 == TopAbs_EDGE && aT1 == TopAbs_FACE)) {
332 DumpInterfs<BOPDS_InterfEF>(pDS->InterfEF(), di);
334 else if (aT1 == TopAbs_FACE && aT2 == TopAbs_FACE) {
336 DumpInterfs<BOPDS_InterfFF>(pDS->InterfFF(), di);
338 else if ((aT1 == TopAbs_VERTEX && aT2 == TopAbs_SOLID) ||
339 (aT2 == TopAbs_VERTEX && aT1 == TopAbs_SOLID)) {
341 DumpInterfs<BOPDS_InterfVZ>(pDS->InterfVZ(), di);
343 else if ((aT1 == TopAbs_EDGE && aT2 == TopAbs_SOLID) ||
344 (aT2 == TopAbs_EDGE && aT1 == TopAbs_SOLID)) {
346 DumpInterfs<BOPDS_InterfEZ>(pDS->InterfEZ(), di);
348 else if ((aT1 == TopAbs_FACE && aT2 == TopAbs_SOLID) ||
349 (aT2 == TopAbs_FACE && aT1 == TopAbs_SOLID)) {
351 DumpInterfs<BOPDS_InterfFZ>(pDS->InterfFZ(), di);
353 else if (aT1 == TopAbs_SOLID && aT2 == TopAbs_SOLID) {
355 DumpInterfs<BOPDS_InterfZZ>(pDS->InterfZZ(), di);
361 //=======================================================================
364 //=======================================================================
365 Standard_Integer bopwho (Draw_Interpretor& di,
370 di << "Shows where the new shape was created. Use: bopwho #\n";
374 BOPDS_PDS pDS=BOPTest_Objects::PDS();
376 di << " prepare PaveFiller first\n";
380 Standard_Integer ind = Draw::Atoi(a[1]);
382 di << " Index must be grater than 0\n";
386 Standard_Integer i1, i2;
389 i2 = pDS->NbShapes();
390 if (ind < i1 || ind > i2) {
391 di << " DS does not contain the shape\n";
395 if (!pDS->IsNewShape(ind)) {
396 Standard_Integer iRank = pDS->Rank(ind);
397 di << " Rank: " << iRank << "\n";
402 di << "the shape is new\n";
404 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(ind);
405 if (aSI.ShapeType() != TopAbs_VERTEX) {
408 // search among interfs
409 BOPDS_VectorOfInterfVV& aVVs = pDS->InterfVV();
410 BOPDS_VectorOfInterfVE& aVEs = pDS->InterfVE();
411 BOPDS_VectorOfInterfEE& aEEs = pDS->InterfEE();
412 BOPDS_VectorOfInterfVF& aVFs = pDS->InterfVF();
413 BOPDS_VectorOfInterfEF& aEFs = pDS->InterfEF();
415 SearchNewIndex<BOPDS_InterfVV> ("V/V: ", ind, aVVs, di);
416 SearchNewIndex<BOPDS_InterfVE> ("V/E: ", ind, aVEs, di);
417 SearchNewIndex<BOPDS_InterfEE> ("E/E: ", ind, aEEs, di);
418 SearchNewIndex<BOPDS_InterfVF> ("V/F: ", ind, aVFs, di);
419 SearchNewIndex<BOPDS_InterfEF> ("E/F: ", ind, aEFs, di);
421 //--------------------------------------FF
423 Standard_Boolean bFound;
424 Standard_Integer i, n1, n2, k, aNb, aNbC, aNbP, nV1, nV2;
425 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
427 bFound = Standard_False;
428 BOPDS_VectorOfInterfFF& aFFs = pDS->InterfFF();
430 for (i = 0; i < aNb; ++i) {
431 const BOPDS_InterfFF& anInt = aFFs(i);
432 anInt.Indices(n1, n2);
434 const BOPDS_VectorOfCurve& aVNC = anInt.Curves();
435 aNbC = aVNC.Extent();
436 for (k = 0; k < aNbC; ++k) {
437 const BOPDS_Curve& aNC = aVNC(k);
438 const BOPDS_ListOfPaveBlock& aLPB = aNC.PaveBlocks();
439 aItLPB.Initialize(aLPB);
440 for(; aItLPB.More(); aItLPB.Next()) {
441 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
442 aPB->Indices(nV1, nV2);
443 if (ind == nV1 || ind == nV2) {
445 di << " FF curves: ";
446 bFound = Standard_True;
448 Sprintf (buf,"(%d, %d) ", n1, n2);
453 }//for (k=0; k<aNbC; ++k)
458 bFound = Standard_False;
459 const BOPDS_VectorOfPoint& aVNP = anInt.Points();
460 aNbP = aVNP.Extent();
461 for (k = 0; k < aNbP; ++k) {
462 const BOPDS_Point& aNP = aVNP(k);
466 di << " FF points: ";
467 bFound = Standard_True;
469 sprintf (buf,"(%d, %d) ", n1, n2);
472 }//for (k=0; k<aNbP; ++k)
481 //=======================================================================
484 //=======================================================================
485 Standard_Integer bopnews(Draw_Interpretor& di,
490 di << "Shows the newly created shapes. Use: bopnews v/e/f\n";
494 BOPDS_PDS pDS = BOPTest_Objects::PDS();
496 di << " prepare PaveFiller first\n";
500 TopAbs_ShapeEnum aType;
501 GetTypeByName(a[1], aType);
503 if (!(aType == TopAbs_VERTEX ||
504 aType == TopAbs_EDGE ||
505 aType == TopAbs_FACE)) {
506 di << "Use: bopnews v/e/f\n";
511 Standard_CString aText;
512 Standard_Boolean bFound;
513 Standard_Integer i, i1, i2;
514 Draw_Color aTextColor(Draw_cyan);
515 Handle(BOPTest_DrawableShape) aDShape;
517 bFound = Standard_False;
518 i1 = pDS->NbSourceShapes();
519 i2 = pDS->NbShapes();
520 for (i = i1; i < i2; ++i) {
521 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(i);
522 if (aSI.ShapeType() == aType) {
523 const TopoDS_Shape& aS = aSI.Shape();
525 sprintf (buf, "z%d", i);
527 aDShape = new BOPTest_DrawableShape(aS, aText, aTextColor);
528 Draw::Set(aText, aDShape);
530 sprintf (buf, "z%d ", i);
533 bFound = Standard_True;
541 di << " No new shapes found\n";
547 //=======================================================================
548 //function : bopindex
550 //=======================================================================
551 Standard_Integer bopindex (Draw_Interpretor& di,
556 di << "Gets the index of the shape in the DS. Use: bopindex s\n";
560 BOPDS_PDS pDS=BOPTest_Objects::PDS();
562 di << " prepare PaveFiller first\n";
566 TopoDS_Shape aS = DBRep::Get(a[1]);
568 di << a[1] << " is a null shape\n";
572 Standard_Integer ind = pDS->Index(aS);
573 Standard_Boolean bFound = (ind > 0);
575 di << " Index: " << ind << "\n";
578 di << " DS does not contain the shape\n";
584 //=======================================================================
587 //=======================================================================
588 Standard_Integer bopsd(Draw_Interpretor& di,
593 di << "Gets the Same domain shape. Use: bopsd #\n";
597 BOPDS_PDS pDS = BOPTest_Objects::PDS();
599 di << " prepare PaveFiller first\n";
604 Standard_Boolean bHasSD;
605 Standard_Integer ind, i1, i2, iSD;
607 ind = Draw::Atoi(a[1]);
610 i2 = pDS->NbShapes();
611 if (ind < i1 || ind > i2) {
612 di << " DS does not contain the shape\n";
616 bHasSD = pDS->HasShapeSD(ind, iSD);
618 Sprintf(buf, " Shape %d has SD shape %d\n", ind, iSD);
622 Sprintf (buf, " Shape: %d has no SD shape\n", ind);
629 //=======================================================================
632 //=======================================================================
633 Standard_Integer bopsc(Draw_Interpretor& di,
637 if (n != 1 && n != 3) {
638 di << "Shows the section curves. Use: bopsc [nF1 nF2]\n";
642 BOPDS_PDS pDS=BOPTest_Objects::PDS();
644 di << " prepare PaveFiller first\n";
649 Standard_CString aText;
650 Draw_Color aTextColor(Draw_cyan);
651 Standard_Integer nSF1, nSF2, nF1, nF2;
652 Standard_Integer aNb, j, iCnt, k, iPriz, aNbC, aNbP, nSp;
654 Handle(BOPTest_DrawableShape) aDShape;
655 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
659 nSF1 = Draw::Atoi(a[1]);
660 nSF2 = Draw::Atoi(a[2]);
663 BOPDS_VectorOfInterfFF& aFFs = pDS->InterfFF();
668 for (j = 0; j < aNb; ++j) {
669 const BOPDS_InterfFF& aFF = aFFs(j);
671 if (!aFF.Contains(nSF1) || !aFF.Contains(nSF2)) {
677 aFF.Indices(nF1, nF2);
680 const BOPDS_VectorOfCurve& aVNC = aFF.Curves();
681 aNbC = aVNC.Extent();
682 for (k = 0; k < aNbC; ++k) {
683 const BOPDS_Curve& aNC = aVNC(k);
684 const BOPDS_ListOfPaveBlock& aLPB = aNC.PaveBlocks();
685 aItLPB.Initialize(aLPB);
686 for(; aItLPB.More(); aItLPB.Next()) {
687 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
688 if (!aPB->HasEdge(nSp)) {
693 Sprintf (buf, "[%d %d] section edges: ", nF1, nF2);
697 sprintf (buf, "t_%d_%d", k, nSp);
700 const TopoDS_Shape& aSp = pDS->Shape(nSp);
702 aDShape = new BOPTest_DrawableShape(aSp, aText, aTextColor);
703 Draw::Set(aText, aDShape);
713 const BOPDS_VectorOfPoint& aVNP = aFF.Points();
714 aNbP = aVNP.Extent();
715 for (k = 0; k < aNbP; ++k) {
716 const BOPDS_Point& aNP = aVNP(k);
722 sprintf (buf, "[%d %d] section vertices: ", nF1, nF2);
726 sprintf (buf, "p_%d_%d", k, nSp);
729 const TopoDS_Shape& aSp = pDS->Shape(nSp);
731 aDShape = new BOPTest_DrawableShape(aSp, aText, aTextColor);
732 Draw::Set(aText, aDShape);
743 }// for (j=0; j<aNb; ++j) {
749 di << " no sections found\n";
755 //=======================================================================
758 //=======================================================================
759 Standard_Integer boppb(Draw_Interpretor& di,
764 di << "Shows information about pave blocks. Use: boppb [#e]\n";
768 BOPDS_PDS pDS = BOPTest_Objects::PDS();
770 di << " prepare PaveFiller first\n";
774 Standard_Boolean bHasPaveBlocks;
775 Standard_Integer ind, i1, i2;
776 TopAbs_ShapeEnum aType;
777 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
780 i2 = pDS->NbSourceShapes();
782 ind = Draw::Atoi(a[1]);
787 for (ind = i1; ind < i2; ++ind) {
788 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(ind);
789 aType = aSI.ShapeType();
790 if (aType != TopAbs_EDGE) {
794 bHasPaveBlocks = pDS->HasPaveBlocks(ind);
795 if (!bHasPaveBlocks) {
799 const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(ind);
800 aItPB.Initialize(aLPB);
801 for (; aItPB.More(); aItPB.Next()) {
802 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
811 //=======================================================================
814 //=======================================================================
815 Standard_Integer bopcb(Draw_Interpretor& di,
820 di << "Shows information about common blocks. Use: bopcb [#e]\n";
824 BOPDS_PDS pDS = BOPTest_Objects::PDS();
826 di << " prepare PaveFiller first\n";
830 Standard_Boolean bHasPaveBlocks;
831 Standard_Integer ind, i1, i2;
832 TopAbs_ShapeEnum aType;
833 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
834 BOPDS_MapOfCommonBlock aMCB;
837 i2 = pDS->NbSourceShapes();
839 ind = Draw::Atoi(a[1]);
844 for (ind = i1; ind < i2; ++ind) {
845 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(ind);
846 aType = aSI.ShapeType();
847 if (aType != TopAbs_EDGE) {
851 bHasPaveBlocks = pDS->HasPaveBlocks(ind);
852 if (!bHasPaveBlocks) {
856 const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(ind);
857 aItPB.Initialize(aLPB);
858 for (; aItPB.More(); aItPB.Next()) {
859 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
860 if (pDS->IsCommonBlock(aPB)) {
861 const Handle(BOPDS_CommonBlock)& aCB = pDS->CommonBlock(aPB);
873 //=======================================================================
876 //=======================================================================
877 Standard_Integer bopsp(Draw_Interpretor& di,
882 di << "Shows the splits of edges. Use: bopsp [#e]\n";
886 BOPDS_PDS pDS = BOPTest_Objects::PDS();
888 di << " prepare PaveFiller first\n";
893 Standard_Boolean bHasPaveBlocks;
894 Standard_Integer ind, i1, i2, nSp;
895 TopAbs_ShapeEnum aType;
896 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
897 Standard_CString aText;
898 Draw_Color aTextColor(Draw_cyan);
899 Handle(BOPTest_DrawableShape) aDShape;
902 i2 = pDS->NbSourceShapes();
904 ind = Draw::Atoi(a[1]);
909 for (ind = i1; ind < i2; ++ind) {
910 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(ind);
911 aType = aSI.ShapeType();
912 if (aType != TopAbs_EDGE) {
916 bHasPaveBlocks = pDS->HasPaveBlocks(ind);
917 if (!bHasPaveBlocks) {
921 di << "Edge " << ind << ": ";
923 const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(ind);
924 aItPB.Initialize(aLPB);
925 for (; aItPB.More(); aItPB.Next()) {
926 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
928 const TopoDS_Shape& aSp = pDS->Shape(nSp);
930 Sprintf(buf, "z%d_%d", ind, nSp);
932 aDShape = new BOPTest_DrawableShape(aSp, aText, aTextColor);
933 Draw::Set(aText, aDShape);
942 //=======================================================================
945 //=======================================================================
946 Standard_Integer bopfon(Draw_Interpretor& di,
950 return bopfinfo(di, n, a, 0);
953 //=======================================================================
956 //=======================================================================
957 Standard_Integer bopfin(Draw_Interpretor& di,
961 return bopfinfo(di, n, a, 1);
964 //=======================================================================
965 //function : bopfspsc
967 //=======================================================================
968 Standard_Integer bopfsc(Draw_Interpretor& di,
972 return bopfinfo(di, n, a, 2);
975 //=======================================================================
976 //function : bopfinfo
978 //=======================================================================
979 Standard_Integer bopfinfo(Draw_Interpretor& di,
982 const Standard_Integer iPriz)
985 di << "Shows " << ((iPriz == 0) ? "ON" : ((iPriz == 1) ? "IN" : "SC")) <<
986 " information for the face. Use: bopf* #f\n";
990 BOPDS_PDS pDS = BOPTest_Objects::PDS();
992 di << " prepare PaveFiller first\n";
997 Standard_Integer nF, i1, i2, nV, i, aNb;
998 Handle(BOPDS_PaveBlock) aPB;
1000 nF = Draw::Atoi(a[1]);
1002 i2 = pDS->NbSourceShapes();
1003 if (nF < i1 || nF > i2) {
1004 di << " DS does not contain the shape\n";
1008 if (pDS->ShapeInfo(nF).ShapeType() != TopAbs_FACE) {
1009 di << " The shape is not a face\n";
1013 if (!pDS->HasFaceInfo(nF)) {
1014 di << " The face has no face information\n";
1018 BOPDS_FaceInfo& aFI = pDS->ChangeFaceInfo(nF);
1020 BOPDS_IndexedMapOfPaveBlock aMPB;
1021 BOPCol_MapOfInteger aMI;
1023 strcpy(aText, "On");
1024 aMPB = aFI.ChangePaveBlocksOn();
1025 aMI = aFI.ChangeVerticesOn();
1027 else if (iPriz == 1) {
1028 strcpy(aText, "In");
1029 aMPB = aFI.ChangePaveBlocksIn();
1030 aMI = aFI.ChangeVerticesIn();
1032 else if (iPriz == 2) {
1033 strcpy(aText, "Sc");
1034 aMPB = aFI.ChangePaveBlocksSc();
1035 aMI = aFI.ChangeVerticesSc();
1038 if (aMPB.Extent()) {
1039 printf(" pave blocks %s:\n", aText);
1040 aNb = aMPB.Extent();
1041 for (i = 1; i <= aNb; ++i) {
1048 printf(" no pave blocks %s found\n", aText);
1052 printf(" vertices %s:\n", aText);
1053 BOPCol_MapIteratorOfMapOfInteger aItMI(aMI);
1054 for (; aItMI.More(); aItMI.Next()) {
1061 printf(" no verts %s found\n", aText);
1067 //=======================================================================
1069 //purpose : alone vertices on face
1070 //=======================================================================
1071 Standard_Integer bopfav(Draw_Interpretor& di,
1076 di << "Shows information about alone vertices for the face. Use: bopfav #f\n";
1080 BOPDS_PDS pDS = BOPTest_Objects::PDS();
1082 di << " prepare PaveFiller first\n";
1086 Standard_Integer i1, i2, nF, nV;
1088 nF = Draw::Atoi(a[1]);
1090 i2 = pDS->NbSourceShapes();
1091 if (nF < i1 || nF > i2) {
1092 di << "DS does not contain the shape\n";
1096 if (pDS->ShapeInfo(nF).ShapeType() != TopAbs_FACE) {
1097 di << " The shape is not a face\n";
1101 if (!pDS->HasFaceInfo(nF)) {
1102 di << " The face has no face information\n";
1106 BOPCol_ListOfInteger aLI;
1107 pDS->AloneVertices(nF, aLI);
1108 if (!aLI.Extent()) {
1109 di << " no alone vertices found\n";
1113 di << " alone vertices: \n";
1114 BOPCol_ListIteratorOfListOfInteger aItLI(aLI);
1115 for (; aItLI.More(); aItLI.Next()) {
1124 //=======================================================================
1125 //function : bopimage
1127 //=======================================================================
1128 Standard_Integer bopimage(Draw_Interpretor& di,
1133 di << "Shows split parts of the shape. Use: bopimage s\n";
1137 BOPDS_PDS pDS = BOPTest_Objects::PDS();
1139 di << " prepare PaveFiller first\n";
1143 TopoDS_Shape aS = DBRep::Get(a[1]);
1145 di << a[1] << " is a null shape\n";
1149 BOPAlgo_Builder& aBuilder = BOPTest_Objects::Builder();
1150 const BOPCol_DataMapOfShapeListOfShape& anImages = aBuilder.Images();
1151 if (!anImages.IsBound(aS)) {
1152 di << " no images found\n";
1161 aBB.MakeCompound(aC);
1163 const BOPCol_ListOfShape& aLSIm = anImages.Find(aS);
1164 BOPCol_ListIteratorOfListOfShape aIt(aLSIm);
1165 for (i = 0; aIt.More(); aIt.Next(), ++i) {
1166 const TopoDS_Shape& aSIm = aIt.Value();
1170 di << i << " images found\n";
1171 sprintf(buf, "%s_im", a[1]);
1172 DBRep::Set(buf, aC);
1178 //=======================================================================
1179 //function : boporigin
1181 //=======================================================================
1182 Standard_Integer boporigin(Draw_Interpretor& di,
1187 di << "Shows the original shape for the shape. Use: boporigin s\n";
1191 BOPDS_PDS pDS = BOPTest_Objects::PDS();
1193 di << " prepare PaveFiller first\n";
1197 TopoDS_Shape aS = DBRep::Get(a[1]);
1199 di << a[1] << " is a null shape\n";
1203 BOPAlgo_Builder& aBuilder = BOPTest_Objects::Builder();
1204 const BOPCol_DataMapOfShapeListOfShape& aDMI = aBuilder.Origins();
1205 if (!aDMI.IsBound(aS)) {
1206 di << " no origins found\n";
1211 sprintf(buf, "%s_or", a[1]);
1213 const BOPCol_ListOfShape& aLSx = aDMI.Find(aS);
1214 if (aLSx.Extent() == 1) {
1215 DBRep::Set(buf, aLSx.First());
1216 di << "1 origin found\n" << buf << "\n";
1220 TopoDS_Compound aCOr;
1221 BRep_Builder().MakeCompound(aCOr);
1223 BOPCol_ListIteratorOfListOfShape aItLSx(aLSx);
1224 for (; aItLSx.More(); aItLSx.Next()) {
1225 BRep_Builder().Add(aCOr, aItLSx.Value());
1228 DBRep::Set(buf, aCOr);
1230 di << aLSx.Extent() << " origins found\n";
1236 //=======================================================================
1239 //=======================================================================
1240 Standard_Integer bopfsd(Draw_Interpretor& di,
1245 di << "Shows SD faces for the face: Use: bopfsd f\n";
1249 BOPDS_PDS pDS = BOPTest_Objects::PDS();
1251 di << " prepare PaveFiller first\n";
1255 TopoDS_Shape aS = DBRep::Get(a[1]);
1257 di << a[1] << " is a null shape\n";
1261 BOPAlgo_Builder& aBuilder = BOPTest_Objects::Builder();
1262 const BOPCol_DataMapOfShapeShape& aDMSD = aBuilder.ShapesSD();
1263 if (!aDMSD.IsBound(aS)) {
1264 di << " shape has no sd shape\n";
1273 aBB.MakeCompound(aC);
1275 BOPCol_DataMapIteratorOfDataMapOfShapeShape aItSD;
1276 aItSD.Initialize(aDMSD);
1277 for (i = 0; aItSD.More(); aItSD.Next()) {
1278 const TopoDS_Shape& aSK = aItSD.Key();
1279 const TopoDS_Shape& aSV = aItSD.Value();
1280 if (aSK.IsEqual(aS)) {
1281 if (!aSV.IsEqual(aS)) {
1287 else if (aSV.IsEqual(aS)) {
1288 if (!aSK.IsEqual(aS)) {
1295 di << i << " SD shapes found\n";
1297 sprintf(buf, "%s_sd", a[1]);
1298 DBRep::Set(buf, aC);
1304 //=======================================================================
1305 //function : bopbface
1307 //=======================================================================
1308 Standard_Integer bopbface (Draw_Interpretor& di,
1313 di << "Build faces from surface and set of shared edges. Use: bopbface fr cx\n";
1317 TopoDS_Shape aS = DBRep::Get(a[2]);
1319 di << a[1] << " is a null shape\n";
1324 BOPCol_ListOfShape aLE;
1327 TopoDS_Iterator aItS(aS);
1328 for (i=0; aItS.More(); aItS.Next(), ++i) {
1329 const TopoDS_Shape& aSx = aItS.Value();
1331 if (aSx.ShapeType() != TopAbs_FACE) {
1332 di << " shape " << i << " is not a face\n";
1335 aF = *(TopoDS_Face*)&aSx;
1338 if (aSx.ShapeType() != TopAbs_EDGE) {
1339 di << " shape " << i << " is not an edge\n";
1346 BOPAlgo_BuilderFace aBF;
1351 Standard_Integer iErr = aBF.ErrorStatus();
1353 di << " Error: " << iErr << "\n";
1358 const BOPCol_ListOfShape& aLFR = aBF.Areas();
1359 BOPCol_ListIteratorOfListOfShape aIt(aLFR);
1360 for (i = 1; aIt.More(); aIt.Next(), ++i) {
1361 const TopoDS_Shape& aFR = aIt.Value();
1362 sprintf(buf, "%s_%d", a[1], i);
1363 DBRep::Set(buf, aFR);
1369 di << "\n " << i << " faces were built\n";
1372 di << " No faces were built\n";
1378 //=======================================================================
1379 //function : bopbsolid
1381 //=======================================================================
1382 Standard_Integer bopbsolid (Draw_Interpretor& di,
1387 di << "Build solids from set of shared faces. Use: bopbsolid sr cx\n";
1391 TopoDS_Shape aS = DBRep::Get(a[2]);
1393 di << a[1] << " is a null shape\n";
1397 BOPCol_ListOfShape aLF;
1398 TopExp_Explorer aExp(aS, TopAbs_FACE);
1399 for (; aExp.More(); aExp.Next()) {
1400 const TopoDS_Shape& aF = aExp.Current();
1404 if (aLF.IsEmpty()) {
1405 di << " No faces to build solids\n";
1409 BOPAlgo_BuilderSolid aBS;
1413 Standard_Integer iErr = aBS.ErrorStatus();
1415 di << " Error: " << iErr << "\n";
1420 TopoDS_Compound aSolids;
1423 aBB.MakeCompound(aSolids);
1426 const BOPCol_ListOfShape& aLSR = aBS.Areas();
1427 BOPCol_ListIteratorOfListOfShape aIt(aLSR);
1428 for (i = 1; aIt.More(); aIt.Next(), ++i) {
1429 const TopoDS_Shape& aSR = aIt.Value();
1430 sprintf(buf, "%s_%d", a[1], i);
1431 DBRep::Set(buf, aSR);
1437 di << "\n " << i << " solids were built\n";
1440 di << " No solids were built\n";
1446 //=======================================================================
1447 //function : GetTypeByName
1449 //=======================================================================
1450 void GetTypeByName(const char* theName,
1451 TopAbs_ShapeEnum& theType)
1453 if (!strcmp (theName, "v") ||
1454 !strcmp (theName, "V")) {
1455 theType = TopAbs_VERTEX;
1457 else if (!strcmp (theName, "e") ||
1458 !strcmp (theName, "E")) {
1459 theType = TopAbs_EDGE;
1461 else if (!strcmp (theName, "w") ||
1462 !strcmp (theName, "W")) {
1463 theType = TopAbs_WIRE;
1465 else if (!strcmp (theName, "f") ||
1466 !strcmp (theName, "F")) {
1467 theType = TopAbs_FACE;
1469 else if (!strcmp (theName, "sh") ||
1470 !strcmp (theName, "Sh") ||
1471 !strcmp (theName, "SH")) {
1472 theType = TopAbs_SHELL;
1474 else if (!strcmp (theName, "s") ||
1475 !strcmp (theName, "S")) {
1476 theType = TopAbs_SOLID;
1478 else if (!strcmp (theName, "cs") ||
1479 !strcmp (theName, "Cs") ||
1480 !strcmp (theName, "CS")) {
1481 theType = TopAbs_COMPSOLID;
1483 else if (!strcmp (theName, "c") ||
1484 !strcmp (theName, "C")) {
1485 theType = TopAbs_COMPOUND;
1488 theType = TopAbs_SHAPE;
1492 //=======================================================================
1493 //function : GetNameByType
1495 //=======================================================================
1496 void GetNameByType(const TopAbs_ShapeEnum& theType,
1501 strcpy (theName, "V");
1504 strcpy (theName, "E");
1507 strcpy (theName, "w");
1510 strcpy (theName, "F");
1513 strcpy (theName, "Sh");
1516 strcpy (theName, "S");
1518 case TopAbs_COMPSOLID:
1519 strcpy (theName, "Cs");
1521 case TopAbs_COMPOUND:
1522 strcpy (theName, "c");
1525 strcpy (theName, "Shape");
1530 //=======================================================================
1531 //function : DumpInterfs
1533 //=======================================================================
1534 template <class InterfType> void DumpInterfs
1535 (const BOPCol_NCVector<InterfType>& theVInterf,
1536 Draw_Interpretor& di)
1538 Standard_Integer i, aNb, n1, n2, nNew;
1541 aNb = theVInterf.Extent();
1543 di << "Not found\n";
1547 di << aNb << " interference(s) found\n";
1548 for (i = 0; i < aNb; ++i) {
1549 const InterfType& anInt = theVInterf(i);
1550 anInt.Indices(n1, n2);
1551 if (anInt.HasIndexNew()) {
1552 nNew = anInt.IndexNew();
1553 Sprintf(buf, " (%d, %d, %d)\n", n1, n2, nNew);
1556 Sprintf(buf, " (%d, %d)\n", n1, n2);
1562 //=======================================================================
1563 //function : SearchNewIndex
1565 //=======================================================================
1566 template <class InterfType> void SearchNewIndex
1567 (const char* theCType,
1568 const Standard_Integer theInd,
1569 const BOPCol_NCVector<InterfType>& theVInterf,
1570 Draw_Interpretor& di)
1573 Standard_Boolean bFound;
1574 Standard_Integer i, aNb, n1, n2, nNew;
1576 bFound = Standard_False;
1577 aNb = theVInterf.Extent();
1578 for (i = 0 ; i < aNb; ++i) {
1579 const InterfType& anInt = theVInterf(i);
1580 nNew = anInt.IndexNew();
1581 if (theInd == nNew) {
1584 bFound = Standard_True;
1587 anInt.Indices(n1, n2);
1588 sprintf(buf,"(%d, %d) ", n1, n2);