1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 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 <BOPAlgo_ArgumentAnalyzer.hxx>
17 #include <BOPAlgo_CheckerSI.hxx>
18 #include <BOPAlgo_CheckResult.hxx>
19 #include <BOPDS_DS.hxx>
20 #include <BOPDS_MapOfPair.hxx>
21 #include <BOPTest.hxx>
22 #include <BOPTest_Objects.hxx>
23 #include <BOPTools_AlgoTools.hxx>
24 #include <BRep_Builder.hxx>
25 #include <BRepAlgoAPI_Check.hxx>
26 #include <BRepBuilderAPI_Copy.hxx>
29 #include <OSD_Timer.hxx>
30 #include <TCollection_AsciiString.hxx>
31 #include <TopExp_Explorer.hxx>
32 #include <TopoDS_Compound.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_MapOfShape.hxx>
36 #include <TopTools_ShapeMapHasher.hxx>
43 void MakeShapeForFullOutput (const TCollection_AsciiString&,
44 const Standard_Integer,
45 const TopTools_ListOfShape&,
48 Standard_Boolean bCurveOnSurf = Standard_False,
49 Standard_Real aMaxDist = 0.,
50 Standard_Real aMaxParameter = 0.);
52 static Standard_Integer bopcheck (Draw_Interpretor&, Standard_Integer, const char** );
53 static Standard_Integer bopargcheck(Draw_Interpretor&, Standard_Integer, const char** );
54 static Standard_Integer bopapicheck(Draw_Interpretor&, Standard_Integer, const char** );
55 static Standard_Integer xdistef(Draw_Interpretor&, Standard_Integer, const char** );
56 static Standard_Integer checkcurveonsurf (Draw_Interpretor&, Standard_Integer, const char**);
58 //=======================================================================
59 //function : CheckCommands
61 //=======================================================================
62 void BOPTest::CheckCommands(Draw_Interpretor& theCommands)
64 static Standard_Boolean done = Standard_False;
70 const char* g = "BOPTest commands";
72 theCommands.Add("bopcheck",
73 "use bopcheck Shape [level of check: 0 - 9] [-t]",
74 __FILE__, bopcheck, g);
75 theCommands.Add("bopargcheck" ,
76 "use bopargcheck without parameters to get ",
77 __FILE__, bopargcheck, g);
78 theCommands.Add ("xdistef" ,
79 "use xdistef edge face",
80 __FILE__, xdistef, g);
81 theCommands.Add("checkcurveonsurf",
82 "use checkcurveonsurf shape",
83 __FILE__, checkcurveonsurf, g);
84 theCommands.Add("bopapicheck",
85 "Checks the validity of shape/pair of shapes.\n"
86 "\t\tUsage: bopapicheck s1 [s2] [-op common/fuse/cut/tuc] [-se] [-si]\n"
88 "\t\ts1, s2 - shapes for checking;\n"
89 "\t\t-op - specifies the type of Boolean operation, for which the validity of shapes should be checked;"
90 " Should be followed by the operation;\n"
91 "\t\t-se - disables the check of the shapes on small edges;\n"
92 "\t\t-si - disables the check of the shapes on self-interference.\n",
93 __FILE__, bopapicheck, g);
95 //=======================================================================
96 //class : BOPTest_Interf
97 //purpose : Auxiliary class
98 //=======================================================================
99 class BOPTest_Interf {
101 BOPTest_Interf() : myIndex1(-1), myIndex2(-1), myType(-1) {
107 void SetIndices(const Standard_Integer theIndex1,
108 const Standard_Integer theIndex2) {
113 void Indices(Standard_Integer& theIndex1,
114 Standard_Integer& theIndex2) const {
119 void SetType(const Standard_Integer theType) {
123 Standard_Integer Type() const {
127 bool operator < (const BOPTest_Interf& aOther) const {
130 if (myType==aOther.myType) {
131 if (myIndex1 == aOther.myIndex1) {
132 bFlag=(myIndex2 < aOther.myIndex2);
135 bFlag=(myIndex1 < aOther.myIndex1);
139 bFlag=(myType < aOther.myType);
146 Standard_Integer myIndex1;
147 Standard_Integer myIndex2;
148 Standard_Integer myType;
150 //=======================================================================
151 //function : bopcheck
153 //=======================================================================
154 Standard_Integer bopcheck (Draw_Interpretor& di,
159 di << " use bopcheck Shape [level of check: 0 - 9] [-t]\n";
160 di << " The level of check defines ";
161 di << " which interferences will be checked:\n";
162 di << " 0 - V/V only\n";
163 di << " 1 - V/V, V/E\n";
164 di << " 2 - V/V, V/E, E/E\n";
165 di << " 3 - V/V, V/E, E/E , V/F\n";
166 di << " 4 - V/V, V/E, E/E, V/F , E/F\n";
167 di << " 5 - V/V, V/E, E/E, V/F, E/F, F/F;\n";
168 di << " 6 - V/V, V/E, E/E, V/F, E/F, F/F, V/Z\n";
169 di << " 7 - V/V, V/E, E/E, V/F, E/F, F/F, E/Z\n";
170 di << " 8 - V/V, V/E, E/E, V/F, E/F, F/F, E/Z, F/Z\n";
171 di << " 9 - V/V, V/E, E/E, V/F, E/F, F/F, E/Z, F/Z, Z/Z\n";
172 di << " Default level is 9\n";
176 TopoDS_Shape aS = DBRep::Get(a[1]);
178 di << "null shapes are not allowed here!";
182 Standard_Boolean bRunParallel, bShowTime;
183 Standard_Integer i, aLevel, aNbInterfTypes;
186 aNbInterfTypes=BOPDS_DS::NbInterfTypes();
188 aLevel=aNbInterfTypes-1;
191 if (a[2][0] != '-') {
192 aLevel=Draw::Atoi(a[2]);
196 if (aLevel < 0 || aLevel > aNbInterfTypes-1) {
197 di << "Invalid level";
201 bShowTime=Standard_False;
202 aTol=BOPTest_Objects::FuzzyValue();
203 bRunParallel=BOPTest_Objects::RunParallel();
205 for (i=2; i<n; ++i) {
206 if (!strcmp(a[i], "-t")) {
207 bShowTime=Standard_True;
211 //aLevel = (n==3) ? Draw::Atoi(a[2]) : aNbInterfTypes-1;
212 //-------------------------------------------------------------------
213 char buf[256], aName1[32], aName2[32];
214 char aInterfTypes[10][4] = {
215 "V/V", "V/E", "E/E","V/F", "E/F", "F/F", "V/Z", "E/Z", "F/Z", "Z/Z"
218 Standard_Integer iErr, iCnt, n1, n2, iT;
219 TopAbs_ShapeEnum aType1, aType2;
220 BOPAlgo_CheckerSI aChecker;
221 TopTools_ListOfShape aLS;
222 BOPDS_MapIteratorOfMapOfPair aItMPK;
224 if (aLevel < (aNbInterfTypes-1)) {
225 di << "Info:\nThe level of check is set to "
226 << aInterfTypes[aLevel] << ", i.e. intersection(s)\n";
228 for (i=aLevel+1; i<aNbInterfTypes; ++i) {
229 di << aInterfTypes[i];
230 if (i<aNbInterfTypes-1) {
234 di << " will not be checked.\n\n";
238 aChecker.SetArguments(aLS);
239 aChecker.SetLevelOfCheck(aLevel);
240 aChecker.SetRunParallel(bRunParallel);
241 aChecker.SetFuzzyValue(aTol);
250 BOPTest::ReportAlerts(aChecker);
252 iErr=aChecker.HasErrors();
254 const BOPDS_DS& aDS=*(aChecker.PDS());
256 const BOPDS_MapOfPair& aMPK=aDS.Interferences();
257 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259 vector <BOPTest_Interf> aVec;
260 vector <BOPTest_Interf>::iterator aIt;
261 BOPTest_Interf aBInterf;
263 aItMPK.Initialize(aMPK);
264 for (; aItMPK.More(); aItMPK.Next()) {
265 const BOPDS_Pair& aPK=aItMPK.Value();
267 if(aDS.IsNewShape(n1) || aDS.IsNewShape(n2)) {
271 const BOPDS_ShapeInfo& aSI1=aDS.ShapeInfo(n1);
272 const BOPDS_ShapeInfo& aSI2=aDS.ShapeInfo(n2);
273 aType1=aSI1.ShapeType();
274 aType2=aSI2.ShapeType();
276 iT=BOPDS_Tools::TypeToInteger(aType1, aType2);
278 aBInterf.SetIndices(n1, n2);
279 aBInterf.SetType(iT);
281 aVec.push_back(aBInterf);
284 sort( aVec.begin(), aVec.end(), less<BOPTest_Interf>());
287 for (aIt=aVec.begin(); aIt!=aVec.end(); aIt++) {
288 const BOPTest_Interf& aBI=*aIt;
291 if(aDS.IsNewShape(n1) || aDS.IsNewShape(n2)) {
295 const TopoDS_Shape& aS1=aDS.Shape(n1);
296 const TopoDS_Shape& aS2=aDS.Shape(n2);
299 di << aInterfTypes[iT] << ": ";
301 sprintf(aName1, "x%d", n1);
302 //sprintf(aName1, "x%d", iCnt);
303 DBRep::Set (aName1, aS1);
306 sprintf(aName2, "x%d", n2);
307 //sprintf(aName2, "x%d", iCnt);
308 DBRep::Set (aName2, aS2);
311 sprintf(buf, "%s %s \n", aName1, aName2);
316 di << "There were errors during the operation, ";
317 di << "so the list may be incomplete.\n";
321 di << " This shape seems to be OK.\n";
325 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
330 //=======================================================================
331 //function : bopargcheck
333 //=======================================================================
334 Standard_Integer bopargcheck (Draw_Interpretor& di,
340 di << " Use >bopargcheck Shape1 [[Shape2] ";
341 di << "[-F/O/C/T/S/U] [/R|F|T|V|E|I|P|C|S]] [#BF]\n\n";
342 di << " -<Boolean Operation>\n";
344 di << " O (common)\n";
346 di << " T (cut21)\n";
347 di << " S (section)\n";
348 di << " U (unknown)\n";
349 di << " For example: \"bopargcheck s1 s2 -F\" enables" ;
350 di << " checking for Fuse operation\n";
351 di << " default - section\n\n";
352 di << " /<Test Options>\n";
353 di << " R (disable small edges (shrank range) test)\n";
354 di << " F (disable faces verification test)\n";
355 di << " T (disable tangent faces searching test)\n";
356 di << " V (disable test possibility to merge vertices)\n";
357 di << " E (disable test possibility to merge edges)\n";
358 di << " I (disable self-interference test)\n";
359 di << " P (disable shape type test)\n";
360 di << " C (disable test for shape continuity)\n";
361 di << " S (disable curve on surface check)\n";
362 di << " For example: \"bopargcheck s1 s2 /RI\" disables ";
363 di << "small edge detection and self-intersection detection\n";
364 di << " default - all options are enabled\n\n";
365 di << " #<Additional Test Options>\n";
366 di << " B (stop test on first faulty found); default OFF\n";
367 di << " F (full output for faulty shapes); default - output ";
368 di << "in a short format\n\n";
369 di << " NOTE: <Boolean Operation> and <Test Options> are ";
370 di << "used only for couple\n";
371 di << " of argument shapes, except I and P options ";
372 di << "that are always used for\n";
373 di << " couple of shapes as well as for ";
374 di <<"single shape test.\n";
378 TopoDS_Shape aS1 = DBRep::Get(a[1]);
381 di << "Error: null shape not allowed!\n";
382 di << "Type bopargcheck without arguments for more ";
383 di <<"information\n";
387 Standard_Boolean isBO = Standard_False;
388 Standard_Integer indxBO = 0;
389 Standard_Boolean isOP = Standard_False;
390 Standard_Integer indxOP = 0;
391 Standard_Boolean isAD = Standard_False;
392 Standard_Integer indxAD = 0;
393 Standard_Boolean isS2 = Standard_False;
394 Standard_Integer indxS2 = 0;
395 Standard_Real aTolerance = 0;
396 Standard_Boolean bRunParallel;
398 bRunParallel=BOPTest_Objects::RunParallel();
399 aTolerance=BOPTest_Objects::FuzzyValue();
402 Standard_Integer iIndex = 0;
403 for(iIndex = 2; iIndex < n; iIndex++) {
404 if(a[iIndex][0] == '-') {
405 isBO = Standard_True;
408 else if(a[iIndex][0] == '/') {
409 isOP = Standard_True;
412 else if(a[iIndex][0] == '#') {
413 isAD = Standard_True;
417 isS2 = Standard_True;
423 // set & test second shape
424 TopoDS_Shape aS22, aS2;
427 di << "Error: second shape should follow the first one!\n";
428 di << "Type bopargcheck without arguments for more information\n";
432 aS22 = DBRep::Get(a[2]);
434 di << "Error: second shape is null!\n";
435 di << "Type bopargcheck without arguments for more information\n";
442 BOPAlgo_ArgumentAnalyzer aChecker;
443 aChecker.SetRunParallel(bRunParallel);
444 aChecker.SetFuzzyValue(aTolerance);
445 aChecker.SetShape1(aS1);
447 // set default options (always tested!) for single and couple shapes
448 aChecker.ArgumentTypeMode() = Standard_True;
449 aChecker.SelfInterMode() = Standard_True;
450 aChecker.SmallEdgeMode() = Standard_True;
451 aChecker.RebuildFaceMode() = Standard_True;
452 aChecker.ContinuityMode() = Standard_True;
453 aChecker.CurveOnSurfaceMode() = Standard_True;
455 // test & set options and operation for two shapes
457 aS2 = BRepBuilderAPI_Copy(aS22).Shape();
458 aChecker.SetShape2(aS2);
459 // set operation (default - Section)
461 if(a[indxBO][1] == 'F' || a[indxBO][1] == 'f') {
462 aChecker.OperationType() = BOPAlgo_FUSE;
464 else if(a[indxBO][1] == 'O' || a[indxBO][1] == 'o') {
465 aChecker.OperationType() = BOPAlgo_COMMON;
467 else if(a[indxBO][1] == 'C' || a[indxBO][1] == 'c') {
468 aChecker.OperationType() = BOPAlgo_CUT;
470 else if(a[indxBO][1] == 'T' || a[indxBO][1] == 't') {
471 aChecker.OperationType() = BOPAlgo_CUT21;
473 else if(a[indxBO][1] == 'S' || a[indxBO][1] == 's') {
474 aChecker.OperationType() = BOPAlgo_SECTION;
476 else if(a[indxBO][1] == 'U' || a[indxBO][1] == 'u') {
477 aChecker.OperationType() = BOPAlgo_UNKNOWN;
480 di << "Error: invalid boolean operation type!\n";
481 di << "Type bopargcheck without arguments for more information\n";
486 aChecker.OperationType() = BOPAlgo_SECTION;
488 aChecker.TangentMode() = Standard_True;
489 aChecker.MergeVertexMode() = Standard_True;
490 aChecker.MergeEdgeMode() = Standard_True;
493 // set options (default - all ON)
495 Standard_Integer ind = 1;
496 while(a[indxOP][ind] != 0) {
497 if(a[indxOP][ind] == 'R' || a[indxOP][ind] == 'r') {
498 aChecker.SmallEdgeMode() = Standard_False;
500 else if(a[indxOP][ind] == 'F' || a[indxOP][ind] == 'f') {
501 aChecker.RebuildFaceMode() = Standard_False;
503 else if(a[indxOP][ind] == 'T' || a[indxOP][ind] == 't') {
504 aChecker.TangentMode() = Standard_False;
506 else if(a[indxOP][ind] == 'V' || a[indxOP][ind] == 'v') {
507 aChecker.MergeVertexMode() = Standard_False;
509 else if(a[indxOP][ind] == 'E' || a[indxOP][ind] == 'e') {
510 aChecker.MergeEdgeMode() = Standard_False;
512 else if(a[indxOP][ind] == 'I' || a[indxOP][ind] == 'i') {
513 aChecker.SelfInterMode() = Standard_False;
515 else if(a[indxOP][ind] == 'P' || a[indxOP][ind] == 'p') {
516 aChecker.ArgumentTypeMode() = Standard_False;
518 else if(a[indxOP][ind] == 'C' || a[indxOP][ind] == 'c') {
519 aChecker.ContinuityMode() = Standard_False;
521 else if(a[indxOP][ind] == 'S' || a[indxOP][ind] == 's') {
522 aChecker.CurveOnSurfaceMode() = Standard_False;
525 di << "Error: invalid test option(s)!\n";
526 di << "Type bopargcheck without arguments for more information\n";
533 // set additional options
534 Standard_Boolean fullOutput = Standard_False;
536 Standard_Integer ind = 1;
537 while(a[indxAD][ind] != 0) {
538 if(a[indxAD][ind] == 'B' || a[indxAD][ind] == 'b') {
539 aChecker.StopOnFirstFaulty() = Standard_True;
541 else if(a[indxAD][ind] == 'F' || a[indxAD][ind] == 'f') {
542 fullOutput = Standard_True;
545 di << "Error: invalid additional test option(s)!\n";
546 di << "Type bopargcheck without arguments for more information\n";
556 // process result of checking
557 if(!aChecker.HasFaulty()) {
558 di << "Shape(s) seem(s) to be valid for BOP." << "\n";
562 di << "Faulties, that can not be treated by BOP, are detected.\n";
565 const BOPAlgo_ListOfCheckResult& aResultList = aChecker.GetCheckResult();
566 BOPAlgo_ListIteratorOfListOfCheckResult anIt(aResultList);
568 Standard_Integer S1_BadType = 0, S1_SelfInt = 0, S1_SmalE = 0, S1_BadF = 0, S1_BadV = 0, S1_BadE = 0;
569 Standard_Integer S1_SelfIntAll = 0, S1_SmalEAll = 0, S1_BadFAll = 0, S1_BadVAll = 0, S1_BadEAll = 0;
570 Standard_Integer S2_BadType = 0, S2_SelfInt = 0, S2_SmalE = 0, S2_BadF = 0, S2_BadV = 0, S2_BadE = 0;
571 Standard_Integer S2_SelfIntAll = 0, S2_SmalEAll = 0, S2_BadFAll = 0, S2_BadVAll = 0, S2_BadEAll = 0;
572 Standard_Integer S1_OpAb = 0, S2_OpAb = 0;
573 Standard_Integer S1_C0 = 0, S2_C0 = 0, S1_C0All = 0, S2_C0All = 0;
574 Standard_Integer S1_COnS = 0, S2_COnS = 0, S1_COnSAll = 0, S2_COnSAll = 0;
575 Standard_Boolean hasUnknown = Standard_False;
577 TCollection_AsciiString aS1SIBaseName("s1si_");
578 TCollection_AsciiString aS1SEBaseName("s1se_");
579 TCollection_AsciiString aS1BFBaseName("s1bf_");
580 TCollection_AsciiString aS1BVBaseName("s1bv_");
581 TCollection_AsciiString aS1BEBaseName("s1be_");
582 TCollection_AsciiString aS1C0BaseName("s1C0_");
583 TCollection_AsciiString aS1COnSBaseName("s1COnS_");
584 TCollection_AsciiString aS2SIBaseName("s2si_");
585 TCollection_AsciiString aS2SEBaseName("s2se_");
586 TCollection_AsciiString aS2BFBaseName("s2bf_");
587 TCollection_AsciiString aS2BVBaseName("s2bv_");
588 TCollection_AsciiString aS2BEBaseName("s2be_");
589 TCollection_AsciiString aS2C0BaseName("s2C0_");
590 TCollection_AsciiString aS2COnSBaseName("s2COnS_");
592 for(; anIt.More(); anIt.Next()) {
593 const BOPAlgo_CheckResult& aResult = anIt.Value();
594 const TopoDS_Shape & aSS1 = aResult.GetShape1();
595 const TopoDS_Shape & aSS2 = aResult.GetShape2();
596 const TopTools_ListOfShape & aLS1 = aResult.GetFaultyShapes1();
597 const TopTools_ListOfShape & aLS2 = aResult.GetFaultyShapes2();
598 Standard_Boolean isL1 = !aLS1.IsEmpty();
599 Standard_Boolean isL2 = !aLS2.IsEmpty();
601 switch(aResult.GetCheckStatus()) {
602 case BOPAlgo_BadType: {
603 if(!aSS1.IsNull()) S1_BadType++;
604 if(!aSS2.IsNull()) S2_BadType++;
607 case BOPAlgo_SelfIntersect: {
611 MakeShapeForFullOutput(aS1SIBaseName, S1_SelfInt, aLS1, S1_SelfIntAll, di);
616 MakeShapeForFullOutput(aS2SIBaseName, S2_SelfInt, aLS2, S2_SelfIntAll, di);
620 case BOPAlgo_TooSmallEdge: {
624 MakeShapeForFullOutput(aS1SEBaseName, S1_SmalE, aLS1, S1_SmalEAll, di);
629 MakeShapeForFullOutput(aS2SEBaseName, S2_SmalE, aLS2, S2_SmalEAll, di);
633 case BOPAlgo_NonRecoverableFace: {
637 MakeShapeForFullOutput(aS1BFBaseName, S1_BadF, aLS1, S1_BadFAll, di);
642 MakeShapeForFullOutput(aS2BFBaseName, S2_BadF, aLS2, S2_BadFAll, di);
646 case BOPAlgo_IncompatibilityOfVertex: {
650 MakeShapeForFullOutput(aS1BVBaseName, S1_BadV, aLS1, S1_BadVAll, di);
656 MakeShapeForFullOutput(aS2BVBaseName, S2_BadV, aLS2, S2_BadVAll, di);
661 case BOPAlgo_IncompatibilityOfEdge: {
665 MakeShapeForFullOutput(aS1BEBaseName, S1_BadE, aLS1, S1_BadEAll, di);
671 MakeShapeForFullOutput(aS2BEBaseName, S2_BadE, aLS2, S2_BadEAll, di);
676 case BOPAlgo_IncompatibilityOfFace: {
677 // not yet implemented
680 case BOPAlgo_GeomAbs_C0: {
684 MakeShapeForFullOutput(aS1C0BaseName, S1_C0, aLS1, S1_C0All, di);
690 MakeShapeForFullOutput(aS2C0BaseName, S2_C0, aLS2, S2_C0All, di);
695 case BOPAlgo_InvalidCurveOnSurface: {
699 Standard_Real aMaxDist = aResult.GetMaxDistance1();
700 Standard_Real aMaxParameter = aResult.GetMaxParameter1();
701 MakeShapeForFullOutput(aS1COnSBaseName, S1_COnS, aLS1, S1_COnSAll, di,
702 Standard_True, aMaxDist, aMaxParameter);
708 Standard_Real aMaxDist = aResult.GetMaxDistance2();
709 Standard_Real aMaxParameter = aResult.GetMaxParameter2();
710 MakeShapeForFullOutput(aS2COnSBaseName, S2_COnS, aLS2, S2_COnSAll, di,
711 Standard_True, aMaxDist, aMaxParameter);
716 case BOPAlgo_OperationAborted: {
717 if(!aSS1.IsNull()) S1_OpAb++;
718 if(!aSS2.IsNull()) S2_OpAb++;
721 case BOPAlgo_CheckUnknown:
723 hasUnknown = Standard_True;
729 Standard_Integer FS1 = S1_SelfInt + S1_SmalE + S1_BadF + S1_BadV + S1_BadE + S1_OpAb + S1_C0 + S1_COnS;
730 FS1 += (S1_BadType != 0) ? 1 : 0;
731 Standard_Integer FS2 = S2_SelfInt + S2_SmalE + S2_BadF + S2_BadV + S2_BadE + S2_OpAb + S2_C0 + S2_COnS;
732 FS2 += (S2_BadType != 0) ? 1 : 0;
734 // output for first shape
735 di << "Faulties for FIRST shape found : " << FS1 << "\n";
737 di << "---------------------------------\n";
738 Standard_CString CString1;
742 CString1=aChecker.ArgumentTypeMode() ? "NO" : "DISABLED";
743 di << "Shapes are not suppotrted by BOP: " << CString1 << "\n";
744 Standard_CString CString2;
748 CString2=aChecker.SelfInterMode() ? "NO" : "DISABLED";
749 di << "Self-Intersections : " << CString2;
751 di << " Cases(" << S1_SelfInt << ") Total shapes(" << S1_SelfIntAll << ")\n";
754 Standard_CString CString13;
758 CString13=aChecker.SelfInterMode() ? "NO" : "DISABLED";
759 di << "Check for SI has been aborted : " << CString13 << "\n";
760 Standard_CString CString3;
764 CString3=aChecker.SmallEdgeMode() ? "NO" : "DISABLED";
765 di << "Too small edges : " << CString3;
767 di << " Cases(" << S1_SmalE << ") Total shapes(" << S1_SmalEAll << ")\n";
770 Standard_CString CString4;
774 CString4=aChecker.RebuildFaceMode() ? "NO" : "DISABLED";
775 di << "Bad faces : " << CString4;
777 di << " Cases(" << S1_BadF << ") Total shapes(" << S1_BadFAll << ")\n";
780 Standard_CString CString5;
784 CString5=aChecker.MergeVertexMode() ? "NO" : "DISABLED";
785 di << "Too close vertices : " << CString5;
787 di << " Cases(" << S1_BadV << ") Total shapes(" << S1_BadVAll << ")\n";
790 Standard_CString CString6;
794 CString6=aChecker.MergeEdgeMode() ? "NO" : "DISABLED";
795 di << "Too close edges : " << CString6;
797 di << " Cases(" << S1_BadE << ") Total shapes(" << S1_BadEAll << ")\n";
800 Standard_CString CString15;
804 CString15=aChecker.ContinuityMode() ? "NO" : "DISABLED";
805 di << "Shapes with Continuity C0 : " << CString15;
807 di << " Cases(" << S1_C0 << ") Total shapes(" << S1_C0All << ")\n";
811 Standard_CString CString17;
815 CString17=aChecker.CurveOnSurfaceMode() ? "NO" : "DISABLED";
816 di << "Invalid Curve on Surface : " << CString17;
818 di << " Cases(" << S1_COnS << ") Total shapes(" << S1_COnSAll << ")\n";
823 // output for second shape
825 di << "Faulties for SECOND shape found : " << FS2 << "\n";
827 di << "---------------------------------\n";
828 Standard_CString CString7;
832 CString7=aChecker.ArgumentTypeMode() ? "NO" : "DISABLED";
833 di << "Shapes are not suppotrted by BOP: " << CString7 << "\n";
834 Standard_CString CString8;
838 CString8=aChecker.SelfInterMode() ? "NO" : "DISABLED";
839 di << "Self-Intersections : " << CString8;
841 di << " Cases(" << S2_SelfInt << ") Total shapes(" << S2_SelfIntAll << ")\n";
845 Standard_CString CString14;
849 CString14=aChecker.SelfInterMode() ? "NO" : "DISABLED";
850 di << "Check for SI has been aborted : " << CString14 << "\n";
851 Standard_CString CString9;
855 CString9=aChecker.SmallEdgeMode() ? "NO" : "DISABLED";
856 di << "Too small edges : " << CString9;
858 di << " Cases(" << S2_SmalE << ") Total shapes(" << S2_SmalEAll << ")\n";
861 Standard_CString CString10;
865 CString10=aChecker.RebuildFaceMode() ? "NO" : "DISABLED";
866 di << "Bad faces : " << CString10;
868 di << " Cases(" << S2_BadF << ") Total shapes(" << S2_BadFAll << ")\n";
871 Standard_CString CString11;
875 CString11=aChecker.MergeVertexMode() ? "NO" : "DISABLED";
876 di << "Too close vertices : " << CString11;
878 di << " Cases(" << S2_BadV << ") Total shapes(" << S2_BadVAll << ")\n";
881 Standard_CString CString12;
885 CString12=aChecker.MergeEdgeMode() ? "NO" : "DISABLED";
886 di << "Too close edges : " << CString12;
888 di << " Cases(" << S2_BadE << ") Total shapes(" << S2_BadEAll << ")\n";
891 Standard_CString CString16;
895 CString16=aChecker.ContinuityMode() ? "NO" : "DISABLED";
896 di << "Shapes with Continuity C0 : " << CString16;
898 di << " Cases(" << S2_C0 << ") Total shapes(" << S2_C0All << ")\n";
902 Standard_CString CString18;
906 CString18=aChecker.CurveOnSurfaceMode() ? "NO" : "DISABLED";
907 di << "Invalid Curve on Surface : " << CString18;
909 di << " Cases(" << S2_COnS << ") Total shapes(" << S2_COnSAll << ")\n";
916 di << "WARNING: The unexpected test break occurs!\n";
924 //=======================================================================
925 //function : bopapicheck
927 //=======================================================================
928 Standard_Integer bopapicheck(Draw_Interpretor& di,
938 TopoDS_Shape aS1 = DBRep::Get(a[1]);
942 // Try to get the second shape
943 aS2 = DBRep::Get(a[2]);
946 BOPAlgo_Operation anOp = BOPAlgo_UNKNOWN;
947 Standard_Boolean bTestSE = Standard_True;
948 Standard_Boolean bTestSI = Standard_True;
950 for (Standard_Integer i = aS2.IsNull() ? 2 : 3; i < n; ++i)
952 if (!strcmp(a[i], "-op"))
954 // Get the operation type
956 if (!strcmp(a[i], "common"))
957 anOp = BOPAlgo_COMMON;
958 else if (!strcmp(a[i], "fuse"))
960 else if (!strcmp(a[i], "cut"))
962 else if (!strcmp(a[i], "tuc"))
963 anOp = BOPAlgo_CUT21;
964 else if (!strcmp(a[i], "section"))
965 anOp = BOPAlgo_SECTION;
967 else if (!strcmp(a[i], "-se"))
969 bTestSE = Standard_False;
971 else if (!strcmp(a[i], "-si"))
973 bTestSI = Standard_False;
977 di << "Invalid key: " << a[i] << ". Skipped.\n";
981 BRepAlgoAPI_Check aChecker(aS1, aS2, anOp, bTestSE, bTestSI);
982 if (aChecker.IsValid())
985 di << "The shape seems to be valid\n";
987 di << "The shapes seem to be valid\n";
991 // Shapes seem to be invalid.
992 // Analyze the invalidity.
994 Standard_Boolean isInv1 = Standard_False, isInv2 = Standard_False;
995 Standard_Boolean isBadOp = Standard_False;
996 BOPAlgo_ListIteratorOfListOfCheckResult itF(aChecker.Result());
997 for (; itF.More(); itF.Next())
999 const BOPAlgo_CheckResult& aFaulty = itF.Value();
1000 if (aFaulty.GetCheckStatus() == BOPAlgo_BadType)
1002 isBadOp = Standard_True;
1008 isInv1 = !aFaulty.GetShape1().IsNull();
1012 isInv2 = !aFaulty.GetShape2().IsNull();
1016 if (isInv1 && isInv2 && isBadOp)
1023 di << "The shape is invalid\n";
1025 di << "The first shape is invalid\n";
1029 di << "The second shape is invalid\n";
1034 di << "The shape is empty\n";
1036 di << "The shapes are not valid for Boolean operation\n";
1041 //=======================================================================
1042 //function : xdistef
1044 //=======================================================================
1045 Standard_Integer xdistef(Draw_Interpretor& di,
1050 di << "use xdistef edge face\n";
1054 const TopoDS_Shape aS1 = DBRep::Get(a[1]);
1055 const TopoDS_Shape aS2 = DBRep::Get(a[2]);
1057 if (aS1.IsNull() || aS2.IsNull()) {
1058 di << "null shapes\n";
1062 if (aS1.ShapeType() != TopAbs_EDGE ||
1063 aS2.ShapeType() != TopAbs_FACE) {
1064 di << "type mismatch\n";
1068 Standard_Real aMaxDist = 0.0, aMaxPar = 0.0;
1070 const TopoDS_Edge& anEdge = *(TopoDS_Edge*)&aS1;
1071 const TopoDS_Face& aFace = *(TopoDS_Face*)&aS2;
1073 if(!BOPTools_AlgoTools::ComputeTolerance
1074 (aFace, anEdge, aMaxDist, aMaxPar)) {
1075 di << "Tolerance cannot be computed\n";
1079 di << "Max Distance = " << aMaxDist
1080 << "; Parameter on curve = " << aMaxPar << "\n";
1085 //=======================================================================
1086 //function : checkcurveonsurf
1088 //=======================================================================
1089 Standard_Integer checkcurveonsurf(Draw_Interpretor& di,
1094 di << "use checkcurveonsurf shape\n";
1098 TopoDS_Shape aS = DBRep::Get(a[1]);
1100 di << "null shape\n";
1104 Standard_Integer nE, nF, anECounter, aFCounter;
1105 Standard_Real aT, aTolE, aDMax;
1106 TopExp_Explorer aExpF, aExpE;
1107 char buf[200], aFName[10], anEName[10];
1108 NCollection_DataMap<TopoDS_Shape, Standard_Real, TopTools_ShapeMapHasher> aDMETol;
1109 TopTools_DataMapOfShapeInteger aMSI;
1114 aExpF.Init(aS, TopAbs_FACE);
1115 for (; aExpF.More(); aExpF.Next()) {
1116 const TopoDS_Face& aF = *(TopoDS_Face*)&aExpF.Current();
1118 aExpE.Init(aF, TopAbs_EDGE);
1119 for (; aExpE.More(); aExpE.Next()) {
1120 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExpE.Current();
1122 if (!BOPTools_AlgoTools::ComputeTolerance(aF, aE, aDMax, aT)) {
1126 aTolE = BRep_Tool::Tolerance(aE);
1127 if (!(aDMax > aTolE)) {
1131 if (aDMETol.IsBound(aE)) {
1132 Standard_Real& aD = aDMETol.ChangeFind(aE);
1138 aDMETol.Bind(aE, aDMax);
1141 if (anECounter == 0) {
1142 di << "Invalid curves on surface:\n";
1145 if (aMSI.IsBound(aE)) {
1154 if (aMSI.IsBound(aF)) {
1162 sprintf(anEName, "e_%d", nE);
1163 sprintf(aFName , "f_%d", nF);
1164 sprintf(buf, "edge %s on face %s (max dist: %3.16f, parameter on curve: %3.16f)\n",
1165 anEName, aFName, aDMax, aT);
1168 DBRep::Set(anEName, aE);
1169 DBRep::Set(aFName , aF);
1173 if (anECounter > 0) {
1174 di << "\n\nSugestions to fix the shape:\n";
1175 di << "explode " << a[1] << " e;\n";
1177 TopTools_MapOfShape M;
1178 aExpE.Init(aS, TopAbs_EDGE);
1179 for (anECounter = 0; aExpE.More(); aExpE.Next()) {
1180 const TopoDS_Shape& aE = aExpE.Current();
1186 if (!aDMETol.IsBound(aE)) {
1190 aTolE = aDMETol.Find(aE);
1192 sprintf(buf, "settolerance %s_%d %3.16f;\n", a[1], anECounter, aTolE);
1197 di << "This shape seems to be OK.\n";
1203 //=======================================================================
1204 //function : MakeShapeForFullOutput
1206 //=======================================================================
1207 void MakeShapeForFullOutput (const TCollection_AsciiString & aBaseName,
1208 const Standard_Integer aIndex,
1209 const TopTools_ListOfShape & aList,
1210 Standard_Integer& aCount,
1211 Draw_Interpretor& di,
1212 Standard_Boolean bCurveOnSurf,
1213 Standard_Real aMaxDist,
1214 Standard_Real aMaxParameter)
1216 TCollection_AsciiString aNum(aIndex);
1217 TCollection_AsciiString aName = aBaseName + aNum;
1218 Standard_CString name = aName.ToCString();
1220 TopoDS_Compound cmp;
1222 BB.MakeCompound(cmp);
1224 TopTools_ListIteratorOfListOfShape anIt(aList);
1225 for(; anIt.More(); anIt.Next()) {
1226 const TopoDS_Shape & aS = anIt.Value();
1230 di << "Made faulty shape: " << name;
1233 di << " (MaxDist = " << aMaxDist
1234 << ", MaxPar = " << aMaxParameter << ")";
1239 DBRep::Set(name, cmp);