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 <TopTools_DataMapOfShapeShape.hxx>
40 #include <TopTools_DataMapOfShapeListOfShape.hxx>
41 #include <TopTools_MapOfShape.hxx>
43 #include <IntTools_Context.hxx>
46 void GetTypeByName(const char* theName,
47 TopAbs_ShapeEnum& theType);
49 void GetNameByType(const TopAbs_ShapeEnum& theType,
52 template <class InterfType> static
53 void DumpInterfs(const NCollection_Vector<InterfType>& theVInterf,
54 Draw_Interpretor& di);
56 template <class InterfType> static
57 void SearchNewIndex(const char* theCType,
58 const Standard_Integer theInd,
59 const NCollection_Vector<InterfType>& theVInterf,
60 Draw_Interpretor& di);
62 Standard_Integer bopfinfo(Draw_Interpretor& di,
65 const Standard_Integer iPriz);
71 static Standard_Integer bopds (Draw_Interpretor&, Standard_Integer, const char**);
72 static Standard_Integer bopiterator (Draw_Interpretor&, Standard_Integer, const char**);
73 static Standard_Integer bopinterf (Draw_Interpretor&, Standard_Integer, const char**);
74 static Standard_Integer bopnews (Draw_Interpretor&, Standard_Integer, const char**);
75 static Standard_Integer bopwho (Draw_Interpretor&, Standard_Integer, const char**);
76 static Standard_Integer bopindex (Draw_Interpretor&, Standard_Integer, const char**);
77 static Standard_Integer bopsd (Draw_Interpretor&, Standard_Integer, const char**);
78 static Standard_Integer bopsc (Draw_Interpretor&, Standard_Integer, const char**);
80 // 1.2 pave blocks commands
81 static Standard_Integer boppb (Draw_Interpretor&, Standard_Integer, const char**);
82 static Standard_Integer bopcb (Draw_Interpretor&, Standard_Integer, const char**);
83 static Standard_Integer bopsp (Draw_Interpretor&, Standard_Integer, const char**);
85 // 1.3 face info commands
86 static Standard_Integer bopfon (Draw_Interpretor&, Standard_Integer, const char**);
87 static Standard_Integer bopfin (Draw_Interpretor&, Standard_Integer, const char**);
88 static Standard_Integer bopfsc (Draw_Interpretor&, Standard_Integer, const char**);
89 static Standard_Integer bopfav (Draw_Interpretor&, Standard_Integer, const char**);
91 // 2. builder commands
92 // 2.1 images commands
93 static Standard_Integer bopimage (Draw_Interpretor&, Standard_Integer, const char**);
94 static Standard_Integer boporigin (Draw_Interpretor&, Standard_Integer, const char**);
95 static Standard_Integer bopfsd (Draw_Interpretor&, Standard_Integer, const char**);
98 static Standard_Integer bopbface (Draw_Interpretor&, Standard_Integer, const char**);
99 // 2.3 building solids
100 static Standard_Integer bopbsolid (Draw_Interpretor&, Standard_Integer, const char**);
103 //=======================================================================
104 //function : DebugCommands
106 //=======================================================================
107 void BOPTest::DebugCommands(Draw_Interpretor& theCommands)
109 static Standard_Boolean done = Standard_False;
111 done = Standard_True;
113 const char* g = "BOPTest commands";
115 theCommands.Add("bopds",
116 "Shows the shapes from DS. Use: bopds [v/e/w/f/sh/s/cs/c]",
118 theCommands.Add("bopiterator",
119 "Shows the pairs of interfered shapes. Use: bopiterator [type1 type2]",
120 __FILE__, bopiterator, g);
121 theCommands.Add("bopinterf", "Shows interferences of given type. Use: bopinterf type1 type2",
122 __FILE__, bopinterf, g);
123 theCommands.Add("bopnews", "Shows the newly created shapes. Use: bopnews [v,e,f]",
124 __FILE__, bopnews, g);
125 theCommands.Add("bopwho", "Shows where the new shape was created. Use: bopwho #",
126 __FILE__, bopwho, g);
127 theCommands.Add("bopindex", "Gets the index of the shape in the DS. Use: bopindex s",
128 __FILE__, bopindex, g);
129 theCommands.Add("bopsd", "Gets the Same domain shape. Use: bopsd #",
131 theCommands.Add("bopsc", "Shows the section curves. Use: bopsc [nF1 nF2]",
133 theCommands.Add("boppb", "Shows information about pave blocks. Use: boppb [#e]",
135 theCommands.Add("bopcb", "Shows information about common blocks. Use: bopcb [#e]",
137 theCommands.Add("bopsp", "Shows the splits of edges. Use: bopsp [#e]",
139 theCommands.Add("bopfon", "Shows ON information for the face. Use: bopfon #f",
140 __FILE__, bopfon, g);
141 theCommands.Add("bopfin", "Shows IN information for the face. Use: bopfin #f",
142 __FILE__, bopfin, g);
143 theCommands.Add("bopfsc", "Shows SC information for the face. Use: bopfsc #f",
144 __FILE__, bopfsc, g);
145 theCommands.Add("bopfav", "Shows information about alone vertices for the face. Use: bopfav #f",
146 __FILE__, bopfav, g);
147 theCommands.Add("bopimage", "Shows split parts of the shape. Use: bopimage s",
148 __FILE__, bopimage, g);
149 theCommands.Add("boporigin", "Shows the original shape for the shape. Use: boporigin s",
150 __FILE__, boporigin, g);
151 theCommands.Add("bopfsd", "Shows SD faces for the face: Use: bopfsd f",
152 __FILE__, bopfsd, g);
153 theCommands.Add("bopbsolid", "Build solids from set of shared faces. Use: bopbsolid sr cx",
154 __FILE__, bopbsolid, g);
155 theCommands.Add("bopbface", "Splits the face by set of shared edges. Use: bopbface fr cx",
156 __FILE__, bopbface, g);
159 //=======================================================================
162 //=======================================================================
163 Standard_Integer bopds (Draw_Interpretor& di,
168 di << "Shows the shapes from DS. Use: bopds [v/e/w/f/sh/s/cs/c]\n";
172 BOPDS_PDS pDS = BOPTest_Objects::PDS();
174 di << " prepare PaveFiller first\n";
179 Standard_CString aText;
180 Standard_Integer i, aNbS;
181 TopAbs_ShapeEnum aType, aTypeShape;
182 Draw_Color aTextColor(Draw_cyan);
184 BOPDS_DS& aDS = *pDS;
185 aNbS = aDS.NbSourceShapes();
187 aType = TopAbs_SHAPE;
189 GetTypeByName(a[1], aType);
192 for (i = 0; i < aNbS; ++i) {
193 const BOPDS_ShapeInfo& aSI = aDS.ShapeInfo(i);
194 const TopoDS_Shape& aS = aSI.Shape();
195 aTypeShape = aSI.ShapeType();
197 if (aTypeShape == TopAbs_COMPOUND ||
198 aTypeShape == TopAbs_COMPSOLID ||
199 aTypeShape == TopAbs_SOLID ||
200 aTypeShape == TopAbs_SHELL ||
201 aTypeShape == TopAbs_WIRE) {
206 if (aTypeShape != aType) {
211 Sprintf(buf, "z%d", i);
213 Handle(BOPTest_DrawableShape) aDShape = new BOPTest_DrawableShape(aS, aText, aTextColor);
214 Draw::Set(aText, aDShape);
220 //=======================================================================
221 //function : bopiterator
223 //=======================================================================
224 Standard_Integer bopiterator (Draw_Interpretor& di,
228 if (n != 1 && n != 3) {
229 di << "Shows the pairs of interfered shapes. Use: bopiterator [type1 type2]\n";
233 BOPDS_PDS pDS = BOPTest_Objects::PDS();
235 di << " prepare PaveFiller first\n";
239 Standard_Integer n1, n2;
240 char buf[64], aST1[10], aST2[10];
243 Handle(IntTools_Context) aCtx = new IntTools_Context();
245 BOPDS_DS& aDS = *pDS;
247 aIt.Prepare(aCtx, BOPTest_Objects::UseOBB(), BOPTest_Objects::FuzzyValue());
250 // type has not been defined. show all pairs
251 Standard_Integer i, j;
252 TopAbs_ShapeEnum aT[4] =
253 {TopAbs_VERTEX, TopAbs_EDGE, TopAbs_FACE, TopAbs_SOLID};
254 for (i = 0; i < 4; ++i) {
255 GetNameByType(aT[i], aST1);
257 for (j = i; j < 4; ++j) {
258 GetNameByType(aT[j], aST2);
260 aIt.Initialize(aT[i], aT[j]);
261 for (; aIt.More(); aIt.Next()) {
264 Sprintf(buf, "%s/%s: (z%d z%d)\n", aST1, aST2, n1, n2);
271 TopAbs_ShapeEnum aT1, aT2;
273 GetTypeByName(a[1], aT1);
274 GetTypeByName(a[2], aT2);
276 GetNameByType(aT1, aST1);
277 GetNameByType(aT2, aST2);
279 aIt.Initialize(aT1, aT2);
280 for (; aIt.More(); aIt.Next()) {
283 Sprintf(buf, "%s/%s: (z%d z%d)\n", aST1, aST2, n1, n2);
291 //=======================================================================
292 //function : bopinterf
294 //=======================================================================
295 Standard_Integer bopinterf (Draw_Interpretor& di,
300 di << "Shows interferences of given type. Use: bopinterf type1 type2\n";
304 BOPDS_PDS pDS = BOPTest_Objects::PDS();
306 di << " prepare PaveFiller first\n";
310 TopAbs_ShapeEnum aT1, aT2;
311 GetTypeByName(a[1], aT1);
312 GetTypeByName(a[2], aT2);
314 if (aT1 == TopAbs_VERTEX && aT2 == TopAbs_VERTEX) {
316 DumpInterfs<BOPDS_InterfVV>(pDS->InterfVV(), di);
318 else if ((aT1 == TopAbs_VERTEX && aT2 == TopAbs_EDGE) ||
319 (aT2 == TopAbs_VERTEX && aT1 == TopAbs_EDGE)) {
321 DumpInterfs<BOPDS_InterfVE>(pDS->InterfVE(), di);
323 else if (aT1 == TopAbs_EDGE && aT2 == TopAbs_EDGE) {
325 DumpInterfs<BOPDS_InterfEE>(pDS->InterfEE(), di);
327 else if ((aT1 == TopAbs_VERTEX && aT2 == TopAbs_FACE) ||
328 (aT2 == TopAbs_VERTEX && aT1 == TopAbs_FACE)) {
330 DumpInterfs<BOPDS_InterfVF>(pDS->InterfVF(), di);
332 else if ((aT1 == TopAbs_EDGE && aT2 == TopAbs_FACE) ||
333 (aT2 == TopAbs_EDGE && aT1 == TopAbs_FACE)) {
335 DumpInterfs<BOPDS_InterfEF>(pDS->InterfEF(), di);
337 else if (aT1 == TopAbs_FACE && aT2 == TopAbs_FACE) {
339 DumpInterfs<BOPDS_InterfFF>(pDS->InterfFF(), di);
341 else if ((aT1 == TopAbs_VERTEX && aT2 == TopAbs_SOLID) ||
342 (aT2 == TopAbs_VERTEX && aT1 == TopAbs_SOLID)) {
344 DumpInterfs<BOPDS_InterfVZ>(pDS->InterfVZ(), di);
346 else if ((aT1 == TopAbs_EDGE && aT2 == TopAbs_SOLID) ||
347 (aT2 == TopAbs_EDGE && aT1 == TopAbs_SOLID)) {
349 DumpInterfs<BOPDS_InterfEZ>(pDS->InterfEZ(), di);
351 else if ((aT1 == TopAbs_FACE && aT2 == TopAbs_SOLID) ||
352 (aT2 == TopAbs_FACE && aT1 == TopAbs_SOLID)) {
354 DumpInterfs<BOPDS_InterfFZ>(pDS->InterfFZ(), di);
356 else if (aT1 == TopAbs_SOLID && aT2 == TopAbs_SOLID) {
358 DumpInterfs<BOPDS_InterfZZ>(pDS->InterfZZ(), di);
364 //=======================================================================
367 //=======================================================================
368 Standard_Integer bopwho (Draw_Interpretor& di,
373 di << "Shows where the new shape was created. Use: bopwho #\n";
377 BOPDS_PDS pDS=BOPTest_Objects::PDS();
379 di << " prepare PaveFiller first\n";
383 Standard_Integer ind = Draw::Atoi(a[1]);
385 di << " Index must be grater than 0\n";
389 Standard_Integer i1, i2;
392 i2 = pDS->NbShapes();
393 if (ind < i1 || ind > i2) {
394 di << " DS does not contain the shape\n";
398 if (!pDS->IsNewShape(ind)) {
399 Standard_Integer iRank = pDS->Rank(ind);
400 di << " Rank: " << iRank << "\n";
405 di << "the shape is new\n";
407 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(ind);
408 if (aSI.ShapeType() != TopAbs_VERTEX) {
411 // search among interfs
412 BOPDS_VectorOfInterfVV& aVVs = pDS->InterfVV();
413 BOPDS_VectorOfInterfVE& aVEs = pDS->InterfVE();
414 BOPDS_VectorOfInterfEE& aEEs = pDS->InterfEE();
415 BOPDS_VectorOfInterfVF& aVFs = pDS->InterfVF();
416 BOPDS_VectorOfInterfEF& aEFs = pDS->InterfEF();
418 SearchNewIndex<BOPDS_InterfVV> ("V/V: ", ind, aVVs, di);
419 SearchNewIndex<BOPDS_InterfVE> ("V/E: ", ind, aVEs, di);
420 SearchNewIndex<BOPDS_InterfEE> ("E/E: ", ind, aEEs, di);
421 SearchNewIndex<BOPDS_InterfVF> ("V/F: ", ind, aVFs, di);
422 SearchNewIndex<BOPDS_InterfEF> ("E/F: ", ind, aEFs, di);
424 //--------------------------------------FF
426 Standard_Boolean bFound;
427 Standard_Integer i, n1, n2, k, aNb, aNbC, aNbP, nV1, nV2;
428 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
430 bFound = Standard_False;
431 BOPDS_VectorOfInterfFF& aFFs = pDS->InterfFF();
433 for (i = 0; i < aNb; ++i) {
434 const BOPDS_InterfFF& anInt = aFFs(i);
435 anInt.Indices(n1, n2);
437 const BOPDS_VectorOfCurve& aVNC = anInt.Curves();
438 aNbC = aVNC.Length();
439 for (k = 0; k < aNbC; ++k) {
440 const BOPDS_Curve& aNC = aVNC(k);
441 const BOPDS_ListOfPaveBlock& aLPB = aNC.PaveBlocks();
442 aItLPB.Initialize(aLPB);
443 for(; aItLPB.More(); aItLPB.Next()) {
444 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
445 aPB->Indices(nV1, nV2);
446 if (ind == nV1 || ind == nV2) {
448 di << " FF curves: ";
449 bFound = Standard_True;
451 Sprintf (buf,"(%d, %d) ", n1, n2);
456 }//for (k=0; k<aNbC; ++k)
461 bFound = Standard_False;
462 const BOPDS_VectorOfPoint& aVNP = anInt.Points();
463 aNbP = aVNP.Length();
464 for (k = 0; k < aNbP; ++k) {
465 const BOPDS_Point& aNP = aVNP(k);
469 di << " FF points: ";
470 bFound = Standard_True;
472 sprintf (buf,"(%d, %d) ", n1, n2);
475 }//for (k=0; k<aNbP; ++k)
484 //=======================================================================
487 //=======================================================================
488 Standard_Integer bopnews(Draw_Interpretor& di,
493 di << "Shows the newly created shapes. Use: bopnews v/e/f\n";
497 BOPDS_PDS pDS = BOPTest_Objects::PDS();
499 di << " prepare PaveFiller first\n";
503 TopAbs_ShapeEnum aType;
504 GetTypeByName(a[1], aType);
506 if (!(aType == TopAbs_VERTEX ||
507 aType == TopAbs_EDGE ||
508 aType == TopAbs_FACE)) {
509 di << "Use: bopnews v/e/f\n";
514 Standard_CString aText;
515 Standard_Boolean bFound;
516 Standard_Integer i, i1, i2;
517 Draw_Color aTextColor(Draw_cyan);
518 Handle(BOPTest_DrawableShape) aDShape;
520 bFound = Standard_False;
521 i1 = pDS->NbSourceShapes();
522 i2 = pDS->NbShapes();
523 for (i = i1; i < i2; ++i) {
524 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(i);
525 if (aSI.ShapeType() == aType) {
526 const TopoDS_Shape& aS = aSI.Shape();
528 sprintf (buf, "z%d", i);
530 aDShape = new BOPTest_DrawableShape(aS, aText, aTextColor);
531 Draw::Set(aText, aDShape);
533 sprintf (buf, "z%d ", i);
536 bFound = Standard_True;
544 di << " No new shapes found\n";
550 //=======================================================================
551 //function : bopindex
553 //=======================================================================
554 Standard_Integer bopindex (Draw_Interpretor& di,
559 di << "Gets the index of the shape in the DS. Use: bopindex s\n";
563 BOPDS_PDS pDS=BOPTest_Objects::PDS();
565 di << " prepare PaveFiller first\n";
569 TopoDS_Shape aS = DBRep::Get(a[1]);
571 di << a[1] << " is a null shape\n";
575 Standard_Integer ind = pDS->Index(aS);
576 Standard_Boolean bFound = (ind > 0);
578 di << " Index: " << ind << "\n";
581 di << " DS does not contain the shape\n";
587 //=======================================================================
590 //=======================================================================
591 Standard_Integer bopsd(Draw_Interpretor& di,
596 di << "Gets the Same domain shape. Use: bopsd #\n";
600 BOPDS_PDS pDS = BOPTest_Objects::PDS();
602 di << " prepare PaveFiller first\n";
607 Standard_Boolean bHasSD;
608 Standard_Integer ind, i1, i2, iSD;
610 ind = Draw::Atoi(a[1]);
613 i2 = pDS->NbShapes();
614 if (ind < i1 || ind > i2) {
615 di << " DS does not contain the shape\n";
619 bHasSD = pDS->HasShapeSD(ind, iSD);
621 Sprintf(buf, " Shape %d has SD shape %d\n", ind, iSD);
625 Sprintf (buf, " Shape: %d has no SD shape\n", ind);
632 //=======================================================================
635 //=======================================================================
636 Standard_Integer bopsc(Draw_Interpretor& di,
640 if (n != 1 && n != 3) {
641 di << "Shows the section curves. Use: bopsc [nF1 nF2]\n";
645 BOPDS_PDS pDS=BOPTest_Objects::PDS();
647 di << " prepare PaveFiller first\n";
652 Standard_CString aText;
653 Draw_Color aTextColor(Draw_cyan);
654 Standard_Integer nSF1, nSF2, nF1, nF2;
655 Standard_Integer aNb, j, iCnt, k, iPriz, aNbC, aNbP, nSp;
657 Handle(BOPTest_DrawableShape) aDShape;
658 BOPDS_ListIteratorOfListOfPaveBlock aItLPB;
662 nSF1 = Draw::Atoi(a[1]);
663 nSF2 = Draw::Atoi(a[2]);
666 BOPDS_VectorOfInterfFF& aFFs = pDS->InterfFF();
671 for (j = 0; j < aNb; ++j) {
672 const BOPDS_InterfFF& aFF = aFFs(j);
674 if (!aFF.Contains(nSF1) || !aFF.Contains(nSF2)) {
680 aFF.Indices(nF1, nF2);
683 const BOPDS_VectorOfCurve& aVNC = aFF.Curves();
684 aNbC = aVNC.Length();
685 for (k = 0; k < aNbC; ++k) {
686 const BOPDS_Curve& aNC = aVNC(k);
687 const BOPDS_ListOfPaveBlock& aLPB = aNC.PaveBlocks();
688 aItLPB.Initialize(aLPB);
689 for(; aItLPB.More(); aItLPB.Next()) {
690 const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value();
691 if (!aPB->HasEdge(nSp)) {
696 Sprintf (buf, "[%d %d] section edges: ", nF1, nF2);
700 sprintf (buf, "t_%d_%d", k, nSp);
703 const TopoDS_Shape& aSp = pDS->Shape(nSp);
705 aDShape = new BOPTest_DrawableShape(aSp, aText, aTextColor);
706 Draw::Set(aText, aDShape);
716 const BOPDS_VectorOfPoint& aVNP = aFF.Points();
717 aNbP = aVNP.Length();
718 for (k = 0; k < aNbP; ++k) {
719 const BOPDS_Point& aNP = aVNP(k);
725 sprintf (buf, "[%d %d] section vertices: ", nF1, nF2);
729 sprintf (buf, "p_%d_%d", k, nSp);
732 const TopoDS_Shape& aSp = pDS->Shape(nSp);
734 aDShape = new BOPTest_DrawableShape(aSp, aText, aTextColor);
735 Draw::Set(aText, aDShape);
746 }// for (j=0; j<aNb; ++j) {
752 di << " no sections found\n";
758 //=======================================================================
761 //=======================================================================
762 Standard_Integer boppb(Draw_Interpretor& di,
767 di << "Shows information about pave blocks. Use: boppb [#e]\n";
771 BOPDS_PDS pDS = BOPTest_Objects::PDS();
773 di << " prepare PaveFiller first\n";
777 Standard_Boolean bHasPaveBlocks;
778 Standard_Integer ind, i1, i2;
779 TopAbs_ShapeEnum aType;
780 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
783 i2 = pDS->NbSourceShapes();
785 ind = Draw::Atoi(a[1]);
790 for (ind = i1; ind < i2; ++ind) {
791 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(ind);
792 aType = aSI.ShapeType();
793 if (aType != TopAbs_EDGE) {
797 bHasPaveBlocks = pDS->HasPaveBlocks(ind);
798 if (!bHasPaveBlocks) {
802 const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(ind);
803 aItPB.Initialize(aLPB);
804 for (; aItPB.More(); aItPB.Next()) {
805 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
814 //=======================================================================
817 //=======================================================================
818 Standard_Integer bopcb(Draw_Interpretor& di,
823 di << "Shows information about common blocks. Use: bopcb [#e]\n";
827 BOPDS_PDS pDS = BOPTest_Objects::PDS();
829 di << " prepare PaveFiller first\n";
833 Standard_Boolean bHasPaveBlocks;
834 Standard_Integer ind, i1, i2;
835 TopAbs_ShapeEnum aType;
836 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
837 BOPDS_MapOfCommonBlock aMCB;
840 i2 = pDS->NbSourceShapes();
842 ind = Draw::Atoi(a[1]);
847 for (ind = i1; ind < i2; ++ind) {
848 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(ind);
849 aType = aSI.ShapeType();
850 if (aType != TopAbs_EDGE) {
854 bHasPaveBlocks = pDS->HasPaveBlocks(ind);
855 if (!bHasPaveBlocks) {
859 const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(ind);
860 aItPB.Initialize(aLPB);
861 for (; aItPB.More(); aItPB.Next()) {
862 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
863 if (pDS->IsCommonBlock(aPB)) {
864 const Handle(BOPDS_CommonBlock)& aCB = pDS->CommonBlock(aPB);
876 //=======================================================================
879 //=======================================================================
880 Standard_Integer bopsp(Draw_Interpretor& di,
885 di << "Shows the splits of edges. Use: bopsp [#e]\n";
889 BOPDS_PDS pDS = BOPTest_Objects::PDS();
891 di << " prepare PaveFiller first\n";
896 Standard_Boolean bHasPaveBlocks;
897 Standard_Integer ind, i1, i2, nSp;
898 TopAbs_ShapeEnum aType;
899 BOPDS_ListIteratorOfListOfPaveBlock aItPB;
900 Standard_CString aText;
901 Draw_Color aTextColor(Draw_cyan);
902 Handle(BOPTest_DrawableShape) aDShape;
905 i2 = pDS->NbSourceShapes();
907 ind = Draw::Atoi(a[1]);
912 for (ind = i1; ind < i2; ++ind) {
913 const BOPDS_ShapeInfo& aSI = pDS->ShapeInfo(ind);
914 aType = aSI.ShapeType();
915 if (aType != TopAbs_EDGE) {
919 bHasPaveBlocks = pDS->HasPaveBlocks(ind);
920 if (!bHasPaveBlocks) {
924 di << "Edge " << ind << ": ";
926 const BOPDS_ListOfPaveBlock& aLPB = pDS->PaveBlocks(ind);
927 aItPB.Initialize(aLPB);
928 for (; aItPB.More(); aItPB.Next()) {
929 const Handle(BOPDS_PaveBlock)& aPB = aItPB.Value();
931 const TopoDS_Shape& aSp = pDS->Shape(nSp);
933 Sprintf(buf, "z%d_%d", ind, nSp);
935 aDShape = new BOPTest_DrawableShape(aSp, aText, aTextColor);
936 Draw::Set(aText, aDShape);
945 //=======================================================================
948 //=======================================================================
949 Standard_Integer bopfon(Draw_Interpretor& di,
953 return bopfinfo(di, n, a, 0);
956 //=======================================================================
959 //=======================================================================
960 Standard_Integer bopfin(Draw_Interpretor& di,
964 return bopfinfo(di, n, a, 1);
967 //=======================================================================
968 //function : bopfspsc
970 //=======================================================================
971 Standard_Integer bopfsc(Draw_Interpretor& di,
975 return bopfinfo(di, n, a, 2);
978 //=======================================================================
979 //function : bopfinfo
981 //=======================================================================
982 Standard_Integer bopfinfo(Draw_Interpretor& di,
985 const Standard_Integer iPriz)
988 di << "Shows " << ((iPriz == 0) ? "ON" : ((iPriz == 1) ? "IN" : "SC")) <<
989 " information for the face. Use: bopf* #f\n";
993 BOPDS_PDS pDS = BOPTest_Objects::PDS();
995 di << " prepare PaveFiller first\n";
1000 Standard_Integer nF, i1, i2, nV, i, aNb;
1001 Handle(BOPDS_PaveBlock) aPB;
1003 nF = Draw::Atoi(a[1]);
1005 i2 = pDS->NbSourceShapes();
1006 if (nF < i1 || nF > i2) {
1007 di << " DS does not contain the shape\n";
1011 if (pDS->ShapeInfo(nF).ShapeType() != TopAbs_FACE) {
1012 di << " The shape is not a face\n";
1016 if (!pDS->HasFaceInfo(nF)) {
1017 di << " The face has no face information\n";
1021 BOPDS_FaceInfo& aFI = pDS->ChangeFaceInfo(nF);
1023 BOPDS_IndexedMapOfPaveBlock aMPB;
1024 TColStd_MapOfInteger aMI;
1026 strcpy(aText, "On");
1027 aMPB = aFI.ChangePaveBlocksOn();
1028 aMI = aFI.ChangeVerticesOn();
1030 else if (iPriz == 1) {
1031 strcpy(aText, "In");
1032 aMPB = aFI.ChangePaveBlocksIn();
1033 aMI = aFI.ChangeVerticesIn();
1035 else if (iPriz == 2) {
1036 strcpy(aText, "Sc");
1037 aMPB = aFI.ChangePaveBlocksSc();
1038 aMI = aFI.ChangeVerticesSc();
1041 if (aMPB.Extent()) {
1042 printf(" pave blocks %s:\n", aText);
1043 aNb = aMPB.Extent();
1044 for (i = 1; i <= aNb; ++i) {
1051 printf(" no pave blocks %s found\n", aText);
1055 printf(" vertices %s:\n", aText);
1056 TColStd_MapIteratorOfMapOfInteger aItMI(aMI);
1057 for (; aItMI.More(); aItMI.Next()) {
1064 printf(" no verts %s found\n", aText);
1070 //=======================================================================
1072 //purpose : alone vertices on face
1073 //=======================================================================
1074 Standard_Integer bopfav(Draw_Interpretor& di,
1079 di << "Shows information about alone vertices for the face. Use: bopfav #f\n";
1083 BOPDS_PDS pDS = BOPTest_Objects::PDS();
1085 di << " prepare PaveFiller first\n";
1089 Standard_Integer i1, i2, nF, nV;
1091 nF = Draw::Atoi(a[1]);
1093 i2 = pDS->NbSourceShapes();
1094 if (nF < i1 || nF > i2) {
1095 di << "DS does not contain the shape\n";
1099 if (pDS->ShapeInfo(nF).ShapeType() != TopAbs_FACE) {
1100 di << " The shape is not a face\n";
1104 if (!pDS->HasFaceInfo(nF)) {
1105 di << " The face has no face information\n";
1109 TColStd_ListOfInteger aLI;
1110 pDS->AloneVertices(nF, aLI);
1111 if (!aLI.Extent()) {
1112 di << " no alone vertices found\n";
1116 di << " alone vertices: \n";
1117 TColStd_ListIteratorOfListOfInteger aItLI(aLI);
1118 for (; aItLI.More(); aItLI.Next()) {
1127 //=======================================================================
1128 //function : bopimage
1130 //=======================================================================
1131 Standard_Integer bopimage(Draw_Interpretor& di,
1136 di << "Shows split parts of the shape. Use: bopimage s\n";
1140 BOPDS_PDS pDS = BOPTest_Objects::PDS();
1142 di << " prepare PaveFiller first\n";
1146 TopoDS_Shape aS = DBRep::Get(a[1]);
1148 di << a[1] << " is a null shape\n";
1152 BOPAlgo_Builder& aBuilder = BOPTest_Objects::Builder();
1153 const TopTools_DataMapOfShapeListOfShape& anImages = aBuilder.Images();
1154 if (!anImages.IsBound(aS)) {
1155 di << " no images found\n";
1164 aBB.MakeCompound(aC);
1166 const TopTools_ListOfShape& aLSIm = anImages.Find(aS);
1167 TopTools_ListIteratorOfListOfShape aIt(aLSIm);
1168 for (i = 0; aIt.More(); aIt.Next(), ++i) {
1169 const TopoDS_Shape& aSIm = aIt.Value();
1173 di << i << " images found\n";
1174 sprintf(buf, "%s_im", a[1]);
1175 DBRep::Set(buf, aC);
1181 //=======================================================================
1182 //function : boporigin
1184 //=======================================================================
1185 Standard_Integer boporigin(Draw_Interpretor& di,
1190 di << "Shows the original shape for the shape. Use: boporigin s\n";
1194 BOPDS_PDS pDS = BOPTest_Objects::PDS();
1196 di << " prepare PaveFiller first\n";
1200 TopoDS_Shape aS = DBRep::Get(a[1]);
1202 di << a[1] << " is a null shape\n";
1206 BOPAlgo_Builder& aBuilder = BOPTest_Objects::Builder();
1207 const TopTools_DataMapOfShapeListOfShape& aDMI = aBuilder.Origins();
1208 if (!aDMI.IsBound(aS)) {
1209 di << " no origins found\n";
1214 sprintf(buf, "%s_or", a[1]);
1216 const TopTools_ListOfShape& aLSx = aDMI.Find(aS);
1217 if (aLSx.Extent() == 1) {
1218 DBRep::Set(buf, aLSx.First());
1219 di << "1 origin found\n" << buf << "\n";
1223 TopoDS_Compound aCOr;
1224 BRep_Builder().MakeCompound(aCOr);
1226 TopTools_ListIteratorOfListOfShape aItLSx(aLSx);
1227 for (; aItLSx.More(); aItLSx.Next()) {
1228 BRep_Builder().Add(aCOr, aItLSx.Value());
1231 DBRep::Set(buf, aCOr);
1233 di << aLSx.Extent() << " origins found\n";
1239 //=======================================================================
1242 //=======================================================================
1243 Standard_Integer bopfsd(Draw_Interpretor& di,
1248 di << "Shows SD faces for the face: Use: bopfsd f\n";
1252 BOPDS_PDS pDS = BOPTest_Objects::PDS();
1254 di << " prepare PaveFiller first\n";
1258 TopoDS_Shape aS = DBRep::Get(a[1]);
1260 di << a[1] << " is a null shape\n";
1264 BOPAlgo_Builder& aBuilder = BOPTest_Objects::Builder();
1265 const TopTools_DataMapOfShapeShape& aDMSD = aBuilder.ShapesSD();
1266 if (!aDMSD.IsBound(aS)) {
1267 di << " shape has no sd shape\n";
1276 aBB.MakeCompound(aC);
1278 TopTools_DataMapIteratorOfDataMapOfShapeShape aItSD;
1279 aItSD.Initialize(aDMSD);
1280 for (i = 0; aItSD.More(); aItSD.Next()) {
1281 const TopoDS_Shape& aSK = aItSD.Key();
1282 const TopoDS_Shape& aSV = aItSD.Value();
1283 if (aSK.IsEqual(aS)) {
1284 if (!aSV.IsEqual(aS)) {
1290 else if (aSV.IsEqual(aS)) {
1291 if (!aSK.IsEqual(aS)) {
1298 di << i << " SD shapes found\n";
1300 sprintf(buf, "%s_sd", a[1]);
1301 DBRep::Set(buf, aC);
1307 //=======================================================================
1308 //function : bopbface
1310 //=======================================================================
1311 Standard_Integer bopbface (Draw_Interpretor& di,
1316 di << "Build faces from surface and set of shared edges. Use: bopbface fr cx\n";
1320 TopoDS_Shape aS = DBRep::Get(a[2]);
1322 di << a[1] << " is a null shape\n";
1327 TopTools_ListOfShape aLE;
1330 TopoDS_Iterator aItS(aS);
1331 for (i=0; aItS.More(); aItS.Next(), ++i) {
1332 const TopoDS_Shape& aSx = aItS.Value();
1334 if (aSx.ShapeType() != TopAbs_FACE) {
1335 di << " shape " << i << " is not a face\n";
1338 aF = *(TopoDS_Face*)&aSx;
1341 if (aSx.ShapeType() != TopAbs_EDGE) {
1342 di << " shape " << i << " is not an edge\n";
1349 BOPAlgo_BuilderFace aBF;
1353 BOPTest::ReportAlerts(aBF.GetReport());
1354 if (aBF.HasErrors()) {
1359 const TopTools_ListOfShape& aLFR = aBF.Areas();
1360 TopTools_ListIteratorOfListOfShape aIt(aLFR);
1361 for (i = 1; aIt.More(); aIt.Next(), ++i) {
1362 const TopoDS_Shape& aFR = aIt.Value();
1363 sprintf(buf, "%s_%d", a[1], i);
1364 DBRep::Set(buf, aFR);
1370 di << "\n " << i << " faces were built\n";
1373 di << " No faces were built\n";
1379 //=======================================================================
1380 //function : bopbsolid
1382 //=======================================================================
1383 Standard_Integer bopbsolid (Draw_Interpretor& di,
1388 di << "Build solids from set of shared faces. Use: bopbsolid sr cx\n";
1392 TopoDS_Shape aS = DBRep::Get(a[2]);
1394 di << a[1] << " is a null shape\n";
1398 TopTools_ListOfShape aLF;
1399 TopExp_Explorer aExp(aS, TopAbs_FACE);
1400 for (; aExp.More(); aExp.Next()) {
1401 const TopoDS_Shape& aF = aExp.Current();
1405 if (aLF.IsEmpty()) {
1406 di << " No faces to build solids\n";
1410 BOPAlgo_BuilderSolid aBS;
1413 BOPTest::ReportAlerts(aBS.GetReport());
1414 if (aBS.HasErrors()) {
1419 TopoDS_Compound aSolids;
1422 aBB.MakeCompound(aSolids);
1425 const TopTools_ListOfShape& aLSR = aBS.Areas();
1426 TopTools_ListIteratorOfListOfShape aIt(aLSR);
1427 for (i = 1; aIt.More(); aIt.Next(), ++i) {
1428 const TopoDS_Shape& aSR = aIt.Value();
1429 sprintf(buf, "%s_%d", a[1], i);
1430 DBRep::Set(buf, aSR);
1436 di << "\n " << i << " solids were built\n";
1439 di << " No solids were built\n";
1445 //=======================================================================
1446 //function : GetTypeByName
1448 //=======================================================================
1449 void GetTypeByName(const char* theName,
1450 TopAbs_ShapeEnum& theType)
1452 if (!strcmp (theName, "v") ||
1453 !strcmp (theName, "V")) {
1454 theType = TopAbs_VERTEX;
1456 else if (!strcmp (theName, "e") ||
1457 !strcmp (theName, "E")) {
1458 theType = TopAbs_EDGE;
1460 else if (!strcmp (theName, "w") ||
1461 !strcmp (theName, "W")) {
1462 theType = TopAbs_WIRE;
1464 else if (!strcmp (theName, "f") ||
1465 !strcmp (theName, "F")) {
1466 theType = TopAbs_FACE;
1468 else if (!strcmp (theName, "sh") ||
1469 !strcmp (theName, "Sh") ||
1470 !strcmp (theName, "SH")) {
1471 theType = TopAbs_SHELL;
1473 else if (!strcmp (theName, "s") ||
1474 !strcmp (theName, "S")) {
1475 theType = TopAbs_SOLID;
1477 else if (!strcmp (theName, "cs") ||
1478 !strcmp (theName, "Cs") ||
1479 !strcmp (theName, "CS")) {
1480 theType = TopAbs_COMPSOLID;
1482 else if (!strcmp (theName, "c") ||
1483 !strcmp (theName, "C")) {
1484 theType = TopAbs_COMPOUND;
1487 theType = TopAbs_SHAPE;
1491 //=======================================================================
1492 //function : GetNameByType
1494 //=======================================================================
1495 void GetNameByType(const TopAbs_ShapeEnum& theType,
1500 strcpy (theName, "V");
1503 strcpy (theName, "E");
1506 strcpy (theName, "w");
1509 strcpy (theName, "F");
1512 strcpy (theName, "Sh");
1515 strcpy (theName, "S");
1517 case TopAbs_COMPSOLID:
1518 strcpy (theName, "Cs");
1520 case TopAbs_COMPOUND:
1521 strcpy (theName, "c");
1524 strcpy (theName, "Shape");
1529 //=======================================================================
1530 //function : DumpInterfs
1532 //=======================================================================
1533 template <class InterfType> void DumpInterfs
1534 (const NCollection_Vector<InterfType>& theVInterf,
1535 Draw_Interpretor& di)
1537 Standard_Integer i, aNb, n1, n2, nNew;
1540 aNb = theVInterf.Length();
1542 di << "Not found\n";
1546 di << aNb << " interference(s) found\n";
1547 for (i = 0; i < aNb; ++i) {
1548 const InterfType& anInt = theVInterf(i);
1549 anInt.Indices(n1, n2);
1550 if (anInt.HasIndexNew()) {
1551 nNew = anInt.IndexNew();
1552 Sprintf(buf, " (%d, %d, %d)\n", n1, n2, nNew);
1555 Sprintf(buf, " (%d, %d)\n", n1, n2);
1561 //=======================================================================
1562 //function : SearchNewIndex
1564 //=======================================================================
1565 template <class InterfType> void SearchNewIndex
1566 (const char* theCType,
1567 const Standard_Integer theInd,
1568 const NCollection_Vector<InterfType>& theVInterf,
1569 Draw_Interpretor& di)
1572 Standard_Boolean bFound;
1573 Standard_Integer i, aNb, n1, n2, nNew;
1575 bFound = Standard_False;
1576 aNb = theVInterf.Length();
1577 for (i = 0 ; i < aNb; ++i) {
1578 const InterfType& anInt = theVInterf(i);
1579 nNew = anInt.IndexNew();
1580 if (theInd == nNew) {
1583 bFound = Standard_True;
1586 anInt.Indices(n1, n2);
1587 sprintf(buf,"(%d, %d) ", n1, n2);