0025691: Visualization, TKService - fix font corruption on FreeType 2.5.4
[occt.git] / src / BOPTest / BOPTest_CheckCommands.cxx
CommitLineData
b311480e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 2010-2014 OPEN CASCADE SAS
b311480e 3//
973c2be1 4// This file is part of Open CASCADE Technology software library.
b311480e 5//
d5f74e42 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
973c2be1 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.
b311480e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
7fd59977 14
15#include <BOPTest.ixx>
7fd59977 16
63def8e6 17#include <vector>
18#include <algorithm>
19#include <functional>
20
21#include <TCollection_AsciiString.hxx>
7fd59977 22
e98e3990 23#include <TopExp_Explorer.hxx>
24
25#include <TopTools_MapOfShape.hxx>
26#include <TopTools_ShapeMapHasher.hxx>
27
7fd59977 28#include <TopoDS_Shape.hxx>
29#include <TopoDS_Compound.hxx>
30#include <BRep_Builder.hxx>
63def8e6 31#include <BRepBuilderAPI_Copy.hxx>
7fd59977 32
7fd59977 33#include <DBRep.hxx>
4e57c75e 34#include <Draw.hxx>
80db5701 35
36#include <BOPCol_ListOfShape.hxx>
37
38#include <BOPDS_DS.hxx>
63def8e6 39#include <BOPDS_MapOfPassKey.hxx>
80db5701 40
4e57c75e 41#include <BOPAlgo_CheckerSI.hxx>
4e57c75e 42#include <BOPAlgo_ArgumentAnalyzer.hxx>
43#include <BOPAlgo_CheckResult.hxx>
7fd59977 44
e98e3990 45#include <BOPTools_AlgoTools.hxx>
46
63def8e6 47#include <BOPTest_Chronometer.hxx>
48//
7fd59977 49static
63def8e6 50 void MakeShapeForFullOutput (const TCollection_AsciiString&,
51 const Standard_Integer,
52 const BOPCol_ListOfShape&,
53 Standard_Integer& ,
e98e3990 54 Draw_Interpretor&,
55 Standard_Boolean bCurveOnSurf = Standard_False,
56 Standard_Real aMaxDist = 0.,
57 Standard_Real aMaxParameter = 0.);
7fd59977 58//
63def8e6 59static Standard_Integer bopcheck (Draw_Interpretor&, Standard_Integer, const char** );
60static Standard_Integer bopargcheck(Draw_Interpretor&, Standard_Integer, const char** );
e98e3990 61static Standard_Integer xdistef(Draw_Interpretor&, Standard_Integer, const char** );
62static Standard_Integer checkcurveonsurf (Draw_Interpretor&, Standard_Integer, const char**);
7fd59977 63
64//=======================================================================
65//function : CheckCommands
66//purpose :
67//=======================================================================
63def8e6 68void BOPTest::CheckCommands(Draw_Interpretor& theCommands)
7fd59977 69{
70 static Standard_Boolean done = Standard_False;
71 if (done)
72 return;
73
74 done = Standard_True;
75 // Chapter's name
76 const char* g = "CCR commands";
77 //
6f31882a 78 theCommands.Add("bopcheck",
79 "Use >bopcheck Shape [level of check: 0(V/V) - 5(all)]",
80 __FILE__, bopcheck, g);
81 theCommands.Add("bopargcheck" ,
82 "Use bopargcheck without parameters to get ",
83 __FILE__, bopargcheck, g);
e98e3990 84 theCommands.Add ("xdistef" ,
85 "Use xdistef edge face",
86 __FILE__, xdistef, g);
87 theCommands.Add("checkcurveonsurf",
88 "checkcurveonsurf shape",
89 __FILE__, checkcurveonsurf, g);
7fd59977 90}
63def8e6 91//=======================================================================
92//class : BOPTest_Interf
93//purpose : Auxiliary class
94//=======================================================================
95class BOPTest_Interf {
96 public:
97 BOPTest_Interf() : myIndex1(-1), myIndex2(-1), myType(-1) {
98 }
99 //
100 ~BOPTest_Interf() {
101 }
102 //
103 void SetIndices(const Standard_Integer theIndex1,
104 const Standard_Integer theIndex2) {
105 myIndex1=theIndex1;
106 myIndex2=theIndex2;
107 }
108 //
109 void Indices(Standard_Integer& theIndex1,
110 Standard_Integer& theIndex2) const {
111 theIndex1=myIndex1;
112 theIndex2=myIndex2;
113 }
114 //
115 void SetType(const Standard_Integer theType) {
116 myType=theType;
117 }
118 //
119 Standard_Integer Type() const {
120 return myType;
121 }
122 //
123 bool operator < (const BOPTest_Interf& aOther) const {
124 bool bFlag;
125 //
126 if (myType==aOther.myType) {
127 if (myIndex1 == aOther.myIndex1) {
128 bFlag=(myIndex2 < aOther.myIndex2);
129 }
130 else {
131 bFlag=(myIndex1 < aOther.myIndex1);
132 }
133 }
134 else {
135 bFlag=(myType < aOther.myType);
136 }
137 //
138 return bFlag;
139 }
140 //
141 protected:
142 Standard_Integer myIndex1;
143 Standard_Integer myIndex2;
144 Standard_Integer myType;
145};
7fd59977 146//=======================================================================
147//function : bopcheck
148//purpose :
149//=======================================================================
63def8e6 150Standard_Integer bopcheck (Draw_Interpretor& di,
151 Standard_Integer n,
152 const char** a )
7fd59977 153{
7fd59977 154 if (n<2) {
b1d15f53 155 di << " Use > bopcheck Shape [level of check: 0 - 9] [-t -s] [-tol tol]" << "\n";
6f31882a 156 di << " The level of check defines ";
80db5701 157 di << " which interferences will be checked:\n";
158 di << " 0 - V/V only\n";
159 di << " 1 - V/V, V/E\n";
160 di << " 2 - V/V, V/E, E/E\n";
161 di << " 3 - V/V, V/E, E/E , V/F\n";
162 di << " 4 - V/V, V/E, E/E, V/F , E/F\n";
163 di << " 5 - V/V, V/E, E/E, V/F, E/F, F/F;\n";
164 di << " 6 - V/V, V/E, E/E, V/F, E/F, F/F, V/Z\n";
165 di << " 7 - V/V, V/E, E/E, V/F, E/F, F/F, E/Z\n";
166 di << " 8 - V/V, V/E, E/E, V/F, E/F, F/F, E/Z, F/Z\n";
167 di << " 9 - V/V, V/E, E/E, V/F, E/F, F/F, E/Z, F/Z, Z/Z\n";
168 di << " Default level is 9\n";
7fd59977 169 return 1;
170 }
80db5701 171 //
172 TopoDS_Shape aS = DBRep::Get(a[1]);
173 if (aS.IsNull()) {
4e57c75e 174 di << "null shapes are not allowed here!";
175 return 1;
176 }
7fd59977 177 //
63def8e6 178 Standard_Boolean bRunParallel, bShowTime;
179 Standard_Integer i, aLevel, aNbInterfTypes;
b1d15f53 180 Standard_Real aTolerance;
80db5701 181 //
182 aNbInterfTypes=BOPDS_DS::NbInterfTypes();
183 //
63def8e6 184 aLevel=aNbInterfTypes-1;
185 //
186 if (n>2) {
b1d15f53 187 if (a[2][0] != '-') {
188 aLevel=Draw::Atoi(a[2]);
189 }
63def8e6 190 }
191 //
192 if (aLevel < 0 || aLevel > aNbInterfTypes-1) {
80db5701 193 di << "Invalid level";
194 return 1;
195 }
63def8e6 196 //
b1d15f53 197 aTolerance = 0;
63def8e6 198 bShowTime=Standard_False;
199 bRunParallel=Standard_True;
b1d15f53 200 for (i=2; i<n; ++i) {
63def8e6 201 if (!strcmp(a[i], "-s")) {
202 bRunParallel=Standard_False;
203 }
204 else if (!strcmp(a[i], "-t")) {
205 bShowTime=Standard_True;
206 }
b1d15f53 207 else if (!strcmp(a[i], "-tol")) {
208 if (i+1 < n) {
209 ++i;
210 aTolerance = Draw::Atof(a[i]);
211 }
212 }
63def8e6 213 }
214 //
215 //aLevel = (n==3) ? Draw::Atoi(a[2]) : aNbInterfTypes-1;
80db5701 216 //-------------------------------------------------------------------
63def8e6 217 char buf[256], aName1[32], aName2[32];
218 char aInterfTypes[10][4] = {
80db5701 219 "V/V", "V/E", "E/E","V/F", "E/F", "F/F", "V/Z", "E/Z", "F/Z", "Z/Z"
220 };
80db5701 221 //
63def8e6 222 Standard_Integer iErr, iCnt, n1, n2, iT;
223 TopAbs_ShapeEnum aType1, aType2;
224 BOPAlgo_CheckerSI aChecker;
225 BOPCol_ListOfShape aLS;
226 BOPDS_MapIteratorMapOfPassKey aItMPK;
227 BOPTime_Chronometer aChrono;
228 //
229 if (aLevel < (aNbInterfTypes-1)) {
6f31882a 230 di << "Info:\nThe level of check is set to "
63def8e6 231 << aInterfTypes[aLevel] << ", i.e. intersection(s)\n";
232
233 for (i=aLevel+1; i<aNbInterfTypes; ++i) {
234 di << aInterfTypes[i];
80db5701 235 if (i<aNbInterfTypes-1) {
c1fe53c6 236 di << ", ";
237 }
238 }
239 di << " will not be checked.\n\n";
240 }
80db5701 241 //
63def8e6 242 aLS.Append(aS);
243 aChecker.SetArguments(aLS);
244 aChecker.SetLevelOfCheck(aLevel);
245 aChecker.SetRunParallel(bRunParallel);
b1d15f53 246 aChecker.SetFuzzyValue(aTolerance);
80db5701 247 //
63def8e6 248 aChrono.Start();
4e57c75e 249 //
250 aChecker.Perform();
4e57c75e 251 //
63def8e6 252 aChrono.Stop();
4e57c75e 253 //
63def8e6 254 iErr=aChecker.ErrorStatus();
4e57c75e 255 //
63def8e6 256 const BOPDS_DS& aDS=*(aChecker.PDS());
257 //
258 const BOPDS_MapOfPassKey& aMPK=aDS.Interferences();
259 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
260 using namespace std;
261 vector <BOPTest_Interf> aVec;
262 vector <BOPTest_Interf>::iterator aIt;
263 BOPTest_Interf aBInterf;
264 //
265 aItMPK.Initialize(aMPK);
266 for (; aItMPK.More(); aItMPK.Next()) {
267 const BOPDS_PassKey& aPK=aItMPK.Value();
268 aPK.Ids(n1, n2);
269 if(aDS.IsNewShape(n1) || aDS.IsNewShape(n2)) {
270 continue;
271 }
272 //
273 const BOPDS_ShapeInfo& aSI1=aDS.ShapeInfo(n1);
274 const BOPDS_ShapeInfo& aSI2=aDS.ShapeInfo(n2);
275 aType1=aSI1.ShapeType();
276 aType2=aSI2.ShapeType();
277 //
278 iT=BOPDS_Tools::TypeToInteger(aType1, aType2);
279 //
280 aBInterf.SetIndices(n1, n2);
281 aBInterf.SetType(iT);
282 //
283 aVec.push_back(aBInterf);
284 }
285 //
286 sort( aVec.begin(), aVec.end(), less<BOPTest_Interf>());
287 //
288 iCnt=0;
289 for (aIt=aVec.begin(); aIt!=aVec.end(); aIt++) {
290 const BOPTest_Interf& aBI=*aIt;
291 //
292 aBI.Indices(n1, n2);
293 if(aDS.IsNewShape(n1) || aDS.IsNewShape(n2)) {
294 continue;
7fd59977 295 }
63def8e6 296 //
297 const TopoDS_Shape& aS1=aDS.Shape(n1);
298 const TopoDS_Shape& aS2=aDS.Shape(n2);
299 //
300 iT=aBI.Type();
301 di << aInterfTypes[iT] << ": ";
302 //
303 sprintf(aName1, "x%d", n1);
304 //sprintf(aName1, "x%d", iCnt);
305 DBRep::Set (aName1, aS1);
306 //
307 ++iCnt;
308 sprintf(aName2, "x%d", n2);
309 //sprintf(aName2, "x%d", iCnt);
310 DBRep::Set (aName2, aS2);
311 ++iCnt;
312 //
313 sprintf(buf, "%s %s \n", aName1, aName2);
314 di << buf;
7fd59977 315 }
6f31882a 316 //
4e57c75e 317 if (iErr) {
6f31882a 318 di << "There were errors during the operation, ";
319 di << "so the list may be incomplete." << "\n";
4e57c75e 320 }
6f31882a 321 //
63def8e6 322 if (!iCnt) {
7fd59977 323 di << " This shape seems to be OK." << "\n";
324 }
63def8e6 325 if (bShowTime) {
326 Standard_Real aTime;
327 //
328 aTime=aChrono.Time();
329 Sprintf(buf, " Tps: %7.2lf\n", aTime);
330 di << buf;
7fd59977 331 }
63def8e6 332 return 0;
7fd59977 333}
6f31882a 334//=======================================================================
335//function : bopargcheck
336//purpose :
337//=======================================================================
e98e3990 338Standard_Integer bopargcheck (Draw_Interpretor& di,
339 Standard_Integer n,
63def8e6 340 const char** a )
7fd59977 341{
342 if (n<2) {
343 di << "\n";
6f31882a 344 di << " Use >bopargcheck Shape1 [[Shape2] ";
b1d15f53 345 di << "[-F/O/C/T/S/U] [/R|F|T|V|E|I|P|C|S]] [#BF] [-tol tol]" << "\n" << "\n";
7fd59977 346 di << " -<Boolean Operation>" << "\n";
347 di << " F (fuse)" << "\n";
348 di << " O (common)" << "\n";
349 di << " C (cut)" << "\n";
350 di << " T (cut21)" << "\n";
351 di << " S (section)" << "\n";
352 di << " U (unknown)" << "\n";
6f31882a 353 di << " For example: \"bopargcheck s1 s2 -F\" enables" ;
63def8e6 354 di << " checking for Fuse operation" << "\n";
7fd59977 355 di << " default - section" << "\n" << "\n";
7fd59977 356 di << " /<Test Options>" << "\n";
7fd59977 357 di << " R (disable small edges (shrank range) test)" << "\n";
7fd59977 358 di << " F (disable faces verification test)" << "\n";
7fd59977 359 di << " T (disable tangent faces searching test)" << "\n";
7fd59977 360 di << " V (disable test possibility to merge vertices)" << "\n";
7fd59977 361 di << " E (disable test possibility to merge edges)" << "\n";
362 di << " I (disable self-interference test)" << "\n";
363 di << " P (disable shape type test)" << "\n";
0e09ee8e 364 di << " C (disable test for shape continuity)" << "\n";
e98e3990 365 di << " S (disable curve on surface check)" << "\n";
6f31882a 366 di << " For example: \"bopargcheck s1 s2 /RI\" disables ";
367 di << "small edge detection and self-intersection detection" << "\n";
7fd59977 368 di << " default - all options are enabled" << "\n" << "\n";
369 di << " #<Additional Test Options>" << "\n";
370 di << " B (stop test on first faulty found); default OFF" << "\n";
6f31882a 371 di << " F (full output for faulty shapes); default - output ";
372 di << "in a short format" << "\n" << "\n";
373 di << " NOTE: <Boolean Operation> and <Test Options> are ";
374 di << "used only for couple" << "\n";
375 di << " of argument shapes, except I and P options ";
376 di << "that are always used for" << "\n";
377 di << " couple of shapes as well as for ";
378 di <<"single shape test." << "\n";
7fd59977 379 return 1;
380 }
381
6f31882a 382 TopoDS_Shape aS1 = DBRep::Get(a[1]);
7fd59977 383
6f31882a 384 if(aS1.IsNull()) {
7fd59977 385 di << "Error: null shape not allowed!" << "\n";
6f31882a 386 di << "Type bopargcheck without arguments for more ";
387 di <<"information" << "\n";
7fd59977 388 return 1;
389 }
390
391 Standard_Boolean isBO = Standard_False;
392 Standard_Integer indxBO = 0;
393 Standard_Boolean isOP = Standard_False;
394 Standard_Integer indxOP = 0;
395 Standard_Boolean isAD = Standard_False;
396 Standard_Integer indxAD = 0;
397 Standard_Boolean isS2 = Standard_False;
398 Standard_Integer indxS2 = 0;
b1d15f53 399 Standard_Real aTolerance = 0;
7fd59977 400
401 if(n >= 3) {
402 Standard_Integer iIndex = 0;
403 for(iIndex = 2; iIndex < n; iIndex++) {
b1d15f53 404 if(!strcmp(a[iIndex], "-tol"))
405 {
406 if ((iIndex+1) < n) {
407 ++iIndex;
408 aTolerance = Draw::Atof(a[iIndex]);
409 }
410 }
411 else if(a[iIndex][0] == '-')
7fd59977 412 {
413 isBO = Standard_True;
414 indxBO = iIndex;
415 }
416 //else if(a[iIndex][0] == '+')
417 else if(a[iIndex][0] == '/')
418 {
419 isOP = Standard_True;
420 indxOP = iIndex;
421 }
422 else if(a[iIndex][0] == '#')
423 {
424 isAD = Standard_True;
425 indxAD = iIndex;
426 }
427 else {
428 isS2 = Standard_True;
429 indxS2 = iIndex;
430 }
431 }
432 }
b1d15f53 433
7fd59977 434 // set & test second shape
4e57c75e 435 TopoDS_Shape aS22, aS2;
7fd59977 436 if(isS2) {
437 if(indxS2 != 2) {
438 di << "Error: second shape should follow the first one!" << "\n";
439 di << "Type bopargcheck without arguments for more information" << "\n";
440 return 1;
441 }
442 else {
4e57c75e 443 aS22 = DBRep::Get(a[2]);
444 if(aS22.IsNull()) {
7fd59977 445 di << "Error: second shape is null!" << "\n";
446 di << "Type bopargcheck without arguments for more information" << "\n";
447 return 1;
448 }
449 }
450 }
b1d15f53 451
7fd59977 452 // init checker
4e57c75e 453 BOPAlgo_ArgumentAnalyzer aChecker;
b1d15f53 454 aChecker.SetFuzzyValue(aTolerance);
7fd59977 455 aChecker.SetShape1(aS1);
456
457 // set default options (always tested!) for single and couple shapes
e98e3990 458 aChecker.ArgumentTypeMode() = Standard_True;
459 aChecker.SelfInterMode() = Standard_True;
460 aChecker.SmallEdgeMode() = Standard_True;
461 aChecker.RebuildFaceMode() = Standard_True;
462 aChecker.ContinuityMode() = Standard_True;
463 aChecker.CurveOnSurfaceMode() = Standard_True;
7fd59977 464
465 // test & set options and operation for two shapes
4e57c75e 466 if(!aS22.IsNull()) {
467 aS2 = BRepBuilderAPI_Copy(aS22).Shape();
7fd59977 468 aChecker.SetShape2(aS2);
469 // set operation (default - Section)
470 if(isBO) {
471 if(a[indxBO][1] == 'F' || a[indxBO][1] == 'f') {
4e57c75e 472 aChecker.OperationType() = BOPAlgo_FUSE;
7fd59977 473 }
474 else if(a[indxBO][1] == 'O' || a[indxBO][1] == 'o') {
4e57c75e 475 aChecker.OperationType() = BOPAlgo_COMMON;
7fd59977 476 }
477 else if(a[indxBO][1] == 'C' || a[indxBO][1] == 'c') {
4e57c75e 478 aChecker.OperationType() = BOPAlgo_CUT;
7fd59977 479 }
480 else if(a[indxBO][1] == 'T' || a[indxBO][1] == 't') {
4e57c75e 481 aChecker.OperationType() = BOPAlgo_CUT21;
7fd59977 482 }
483 else if(a[indxBO][1] == 'S' || a[indxBO][1] == 's') {
4e57c75e 484 aChecker.OperationType() = BOPAlgo_SECTION;
7fd59977 485 }
486 else if(a[indxBO][1] == 'U' || a[indxBO][1] == 'u') {
4e57c75e 487 aChecker.OperationType() = BOPAlgo_UNKNOWN;
7fd59977 488 }
489 else {
490 di << "Error: invalid boolean operation type!" << "\n";
491 di << "Type bopargcheck without arguments for more information" << "\n";
492 return 1;
493 }
494 }
495 else
4e57c75e 496 aChecker.OperationType() = BOPAlgo_SECTION;
7fd59977 497
7fd59977 498 aChecker.TangentMode() = Standard_True;
499 aChecker.MergeVertexMode() = Standard_True;
500 aChecker.MergeEdgeMode() = Standard_True;
7fd59977 501 }
0e09ee8e 502
503 // set options (default - all ON)
504 if(isOP) {
505 Standard_Integer ind = 1;
506 while(a[indxOP][ind] != 0) {
507 if(a[indxOP][ind] == 'R' || a[indxOP][ind] == 'r') {
508 aChecker.SmallEdgeMode() = Standard_False;
509 }
510 else if(a[indxOP][ind] == 'F' || a[indxOP][ind] == 'f') {
511 aChecker.RebuildFaceMode() = Standard_False;
512 }
513 else if(a[indxOP][ind] == 'T' || a[indxOP][ind] == 't') {
514 aChecker.TangentMode() = Standard_False;
7fd59977 515 }
0e09ee8e 516 else if(a[indxOP][ind] == 'V' || a[indxOP][ind] == 'v') {
517 aChecker.MergeVertexMode() = Standard_False;
518 }
519 else if(a[indxOP][ind] == 'E' || a[indxOP][ind] == 'e') {
520 aChecker.MergeEdgeMode() = Standard_False;
521 }
522 else if(a[indxOP][ind] == 'I' || a[indxOP][ind] == 'i') {
523 aChecker.SelfInterMode() = Standard_False;
524 }
525 else if(a[indxOP][ind] == 'P' || a[indxOP][ind] == 'p') {
526 aChecker.ArgumentTypeMode() = Standard_False;
527 }
528 else if(a[indxOP][ind] == 'C' || a[indxOP][ind] == 'c') {
529 aChecker.ContinuityMode() = Standard_False;
530 }
e98e3990 531 else if(a[indxOP][ind] == 'S' || a[indxOP][ind] == 's') {
532 aChecker.CurveOnSurfaceMode() = Standard_False;
533 }
0e09ee8e 534 else {
535 di << "Error: invalid test option(s)!" << "\n";
536 di << "Type bopargcheck without arguments for more information" << "\n";
537 return 1;
538 }
539 ind++;
7fd59977 540 }
541 }
542
543 // set additional options
544 Standard_Boolean fullOutput = Standard_False;
545 if(isAD) {
546 Standard_Integer ind = 1;
547 while(a[indxAD][ind] != 0) {
548 if(a[indxAD][ind] == 'B' || a[indxAD][ind] == 'b') {
549 aChecker.StopOnFirstFaulty() = Standard_True;
550 }
551 else if(a[indxAD][ind] == 'F' || a[indxAD][ind] == 'f') {
552 fullOutput = Standard_True;
553 }
554 else {
555 di << "Error: invalid additional test option(s)!" << "\n";
556 di << "Type bopargcheck without arguments for more information" << "\n";
557 return 1;
558 }
559 ind++;
560 }
561 }
562
563 // run checker
564 aChecker.Perform();
565
566 // process result of checking
567 if(!aChecker.HasFaulty()) {
568 di << "Shape(s) seem(s) to be valid for BOP." << "\n";
569 }
570 else {
571 if(!fullOutput) {
572 di << "Faulties, that can not be treated by BOP, are detected." << "\n";
573 }
574 else {
4e57c75e 575 const BOPAlgo_ListOfCheckResult& aResultList = aChecker.GetCheckResult();
576 BOPAlgo_ListIteratorOfListOfCheckResult anIt(aResultList);
7fd59977 577
578 Standard_Integer S1_BadType = 0, S1_SelfInt = 0, S1_SmalE = 0, S1_BadF = 0, S1_BadV = 0, S1_BadE = 0;
579 Standard_Integer S1_SelfIntAll = 0, S1_SmalEAll = 0, S1_BadFAll = 0, S1_BadVAll = 0, S1_BadEAll = 0;
580 Standard_Integer S2_BadType = 0, S2_SelfInt = 0, S2_SmalE = 0, S2_BadF = 0, S2_BadV = 0, S2_BadE = 0;
581 Standard_Integer S2_SelfIntAll = 0, S2_SmalEAll = 0, S2_BadFAll = 0, S2_BadVAll = 0, S2_BadEAll = 0;
4e57c75e 582 Standard_Integer S1_OpAb = 0, S2_OpAb = 0;
0e09ee8e 583 Standard_Integer S1_C0 = 0, S2_C0 = 0, S1_C0All = 0, S2_C0All = 0;
e98e3990 584 Standard_Integer S1_COnS = 0, S2_COnS = 0, S1_COnSAll = 0, S2_COnSAll = 0;
7fd59977 585 Standard_Boolean hasUnknown = Standard_False;
586
587 TCollection_AsciiString aS1SIBaseName("s1si_");
588 TCollection_AsciiString aS1SEBaseName("s1se_");
589 TCollection_AsciiString aS1BFBaseName("s1bf_");
590 TCollection_AsciiString aS1BVBaseName("s1bv_");
591 TCollection_AsciiString aS1BEBaseName("s1be_");
0e09ee8e 592 TCollection_AsciiString aS1C0BaseName("s1C0_");
e98e3990 593 TCollection_AsciiString aS1COnSBaseName("s1COnS_");
7fd59977 594 TCollection_AsciiString aS2SIBaseName("s2si_");
595 TCollection_AsciiString aS2SEBaseName("s2se_");
596 TCollection_AsciiString aS2BFBaseName("s2bf_");
597 TCollection_AsciiString aS2BVBaseName("s2bv_");
598 TCollection_AsciiString aS2BEBaseName("s2be_");
0e09ee8e 599 TCollection_AsciiString aS2C0BaseName("s2C0_");
e98e3990 600 TCollection_AsciiString aS2COnSBaseName("s2COnS_");
7fd59977 601
602 for(; anIt.More(); anIt.Next()) {
4e57c75e 603 const BOPAlgo_CheckResult& aResult = anIt.Value();
7fd59977 604 const TopoDS_Shape & aSS1 = aResult.GetShape1();
605 const TopoDS_Shape & aSS2 = aResult.GetShape2();
4e57c75e 606 const BOPCol_ListOfShape & aLS1 = aResult.GetFaultyShapes1();
607 const BOPCol_ListOfShape & aLS2 = aResult.GetFaultyShapes2();
7fd59977 608 Standard_Boolean isL1 = !aLS1.IsEmpty();
609 Standard_Boolean isL2 = !aLS2.IsEmpty();
610
611 switch(aResult.GetCheckStatus()) {
4e57c75e 612 case BOPAlgo_BadType: {
7fd59977 613 if(!aSS1.IsNull()) S1_BadType++;
614 if(!aSS2.IsNull()) S2_BadType++;
615 }
4e57c75e 616 break;
617 case BOPAlgo_SelfIntersect: {
7fd59977 618 if(!aSS1.IsNull()) {
619 S1_SelfInt++;
620 if(isL1)
621 MakeShapeForFullOutput(aS1SIBaseName, S1_SelfInt, aLS1, S1_SelfIntAll, di);
622 }
623 if(!aSS2.IsNull()) {
624 S2_SelfInt++;
625 if(isL2)
626 MakeShapeForFullOutput(aS2SIBaseName, S2_SelfInt, aLS2, S2_SelfIntAll, di);
627 }
628 }
4e57c75e 629 break;
630 case BOPAlgo_TooSmallEdge: {
7fd59977 631 if(!aSS1.IsNull()) {
632 S1_SmalE++;
633 if(isL1)
634 MakeShapeForFullOutput(aS1SEBaseName, S1_SmalE, aLS1, S1_SmalEAll, di);
635 }
636 if(!aSS2.IsNull()) {
637 S2_SmalE++;
638 if(isL2)
639 MakeShapeForFullOutput(aS2SEBaseName, S2_SmalE, aLS2, S2_SmalEAll, di);
640 }
641 }
4e57c75e 642 break;
643 case BOPAlgo_NonRecoverableFace: {
7fd59977 644 if(!aSS1.IsNull()) {
645 S1_BadF++;
646 if(isL1)
647 MakeShapeForFullOutput(aS1BFBaseName, S1_BadF, aLS1, S1_BadFAll, di);
648 }
649 if(!aSS2.IsNull()) {
650 S2_BadF++;
651 if(isL2)
652 MakeShapeForFullOutput(aS2BFBaseName, S2_BadF, aLS2, S2_BadFAll, di);
653 }
654 }
4e57c75e 655 break;
656 case BOPAlgo_IncompatibilityOfVertex: {
7fd59977 657 if(!aSS1.IsNull()) {
658 S1_BadV++;
659 if(isL1) {
660 MakeShapeForFullOutput(aS1BVBaseName, S1_BadV, aLS1, S1_BadVAll, di);
4e57c75e 661 }
7fd59977 662 }
663 if(!aSS2.IsNull()) {
664 S2_BadV++;
665 if(isL2){
666 MakeShapeForFullOutput(aS2BVBaseName, S2_BadV, aLS2, S2_BadVAll, di);
4e57c75e 667 }
7fd59977 668 }
669 }
4e57c75e 670 break;
671 case BOPAlgo_IncompatibilityOfEdge: {
7fd59977 672 if(!aSS1.IsNull()) {
673 S1_BadE++;
674 if(isL1) {
675 MakeShapeForFullOutput(aS1BEBaseName, S1_BadE, aLS1, S1_BadEAll, di);
4e57c75e 676 }
7fd59977 677 }
678 if(!aSS2.IsNull()) {
679 S2_BadE++;
680 if(isL2) {
681 MakeShapeForFullOutput(aS2BEBaseName, S2_BadE, aLS2, S2_BadEAll, di);
4e57c75e 682 }
7fd59977 683 }
684 }
4e57c75e 685 break;
686 case BOPAlgo_IncompatibilityOfFace: {
7fd59977 687 // not yet implemented
688 }
4e57c75e 689 break;
0e09ee8e 690 case BOPAlgo_GeomAbs_C0: {
691 if(!aSS1.IsNull()) {
692 S1_C0++;
693 if(isL1) {
694 MakeShapeForFullOutput(aS1C0BaseName, S1_C0, aLS1, S1_C0All, di);
695 }
696 }
697 if(!aSS2.IsNull()) {
698 S2_C0++;
699 if(isL2) {
700 MakeShapeForFullOutput(aS2C0BaseName, S2_C0, aLS2, S2_C0All, di);
701 }
702 }
703 }
704 break;
e98e3990 705 case BOPAlgo_InvalidCurveOnSurface: {
706 if(!aSS1.IsNull()) {
707 S1_COnS++;
708 if(isL1) {
709 Standard_Real aMaxDist = aResult.GetMaxDistance1();
710 Standard_Real aMaxParameter = aResult.GetMaxParameter1();
711 MakeShapeForFullOutput(aS1COnSBaseName, S1_COnS, aLS1, S1_COnSAll, di,
712 Standard_True, aMaxDist, aMaxParameter);
713 }
714 }
715 if(!aSS2.IsNull()) {
716 S2_COnS++;
717 if(isL2) {
718 Standard_Real aMaxDist = aResult.GetMaxDistance2();
719 Standard_Real aMaxParameter = aResult.GetMaxParameter2();
720 MakeShapeForFullOutput(aS2COnSBaseName, S2_COnS, aLS2, S2_COnSAll, di,
721 Standard_True, aMaxDist, aMaxParameter);
722 }
723 }
724 }
725 break;
4e57c75e 726 case BOPAlgo_OperationAborted: {
727 if(!aSS1.IsNull()) S1_OpAb++;
728 if(!aSS2.IsNull()) S2_OpAb++;
729 }
730 break;
731 case BOPAlgo_CheckUnknown:
7fd59977 732 default: {
733 hasUnknown = Standard_True;
734 }
4e57c75e 735 break;
7fd59977 736 } // switch
737 }// faulties
738
e98e3990 739 Standard_Integer FS1 = S1_SelfInt + S1_SmalE + S1_BadF + S1_BadV + S1_BadE + S1_OpAb + S1_C0 + S1_COnS;
7fd59977 740 FS1 += (S1_BadType != 0) ? 1 : 0;
e98e3990 741 Standard_Integer FS2 = S2_SelfInt + S2_SmalE + S2_BadF + S2_BadV + S2_BadE + S2_OpAb + S2_C0 + S2_COnS;
7fd59977 742 FS2 += (S2_BadType != 0) ? 1 : 0;
743
744 // output for first shape
745 di << "Faulties for FIRST shape found : " << FS1 << "\n";
746 if(FS1 != 0) {
747 di << "---------------------------------" << "\n";
748 Standard_CString CString1;
4e57c75e 749 if (S1_BadType != 0)
750 CString1="YES";
751 else
b1d15f53 752 CString1=aChecker.ArgumentTypeMode() ? "NO" : "DISABLED";
7fd59977 753 di << "Shapes are not suppotrted by BOP: " << CString1 << "\n";
754 Standard_CString CString2;
4e57c75e 755 if (S1_SelfInt != 0)
756 CString2="YES";
757 else
b1d15f53 758 CString2=aChecker.SelfInterMode() ? "NO" : "DISABLED";
7fd59977 759 di << "Self-Intersections : " << CString2;
760 if(S1_SelfInt != 0)
761 di << " Cases(" << S1_SelfInt << ") Total shapes(" << S1_SelfIntAll << ")" << "\n";
762 else
763 di << "\n";
4e57c75e 764 Standard_CString CString13;
765 if (S1_OpAb != 0)
766 CString13="YES";
767 else
b1d15f53 768 CString13=aChecker.SelfInterMode() ? "NO" : "DISABLED";
4e57c75e 769 di << "Check for SI has been aborted : " << CString13 << "\n";
7fd59977 770 Standard_CString CString3;
4e57c75e 771 if (S1_SmalE != 0)
772 CString3="YES";
773 else
b1d15f53 774 CString3=aChecker.SmallEdgeMode() ? "NO" : "DISABLED";
7fd59977 775 di << "Too small edges : " << CString3;
776 if(S1_SmalE != 0)
777 di << " Cases(" << S1_SmalE << ") Total shapes(" << S1_SmalEAll << ")" << "\n";
778 else
779 di << "\n";
780 Standard_CString CString4;
4e57c75e 781 if (S1_BadF != 0)
782 CString4="YES";
783 else
b1d15f53 784 CString4=aChecker.RebuildFaceMode() ? "NO" : "DISABLED";
7fd59977 785 di << "Bad faces : " << CString4;
786 if(S1_BadF != 0)
787 di << " Cases(" << S1_BadF << ") Total shapes(" << S1_BadFAll << ")" << "\n";
788 else
789 di << "\n";
790 Standard_CString CString5;
4e57c75e 791 if (S1_BadV != 0)
792 CString5="YES";
793 else
b1d15f53 794 CString5=aChecker.MergeVertexMode() ? "NO" : "DISABLED";
7fd59977 795 di << "Too close vertices : " << CString5;
796 if(S1_BadV != 0)
797 di << " Cases(" << S1_BadV << ") Total shapes(" << S1_BadVAll << ")" << "\n";
798 else
799 di << "\n";
800 Standard_CString CString6;
4e57c75e 801 if (S1_BadE != 0)
802 CString6="YES";
803 else
b1d15f53 804 CString6=aChecker.MergeEdgeMode() ? "NO" : "DISABLED";
7fd59977 805 di << "Too close edges : " << CString6;
806 if(S1_BadE != 0)
807 di << " Cases(" << S1_BadE << ") Total shapes(" << S1_BadEAll << ")" << "\n";
808 else
809 di << "\n";
0e09ee8e 810 Standard_CString CString15;
811 if (S1_C0 != 0)
812 CString15="YES";
813 else
b1d15f53 814 CString15=aChecker.ContinuityMode() ? "NO" : "DISABLED";
0e09ee8e 815 di << "Shapes with Continuity C0 : " << CString15;
816 if(S1_C0 != 0)
817 di << " Cases(" << S1_C0 << ") Total shapes(" << S1_C0All << ")" << "\n";
818 else
819 di << "\n";
e98e3990 820
821 Standard_CString CString17;
822 if (S1_COnS != 0)
823 CString17="YES";
824 else
b1d15f53 825 CString17=aChecker.CurveOnSurfaceMode() ? "NO" : "DISABLED";
e98e3990 826 di << "Invalid Curve on Surface : " << CString17;
827 if(S1_COnS != 0)
828 di << " Cases(" << S1_COnS << ") Total shapes(" << S1_COnSAll << ")" << "\n";
829 else
830 di << "\n";
7fd59977 831 }
832
833 // output for second shape
834 di << "\n";
835 di << "Faulties for SECOND shape found : " << FS2 << "\n";
836 if(FS2 != 0) {
837 di << "---------------------------------" << "\n";
838 Standard_CString CString7;
4e57c75e 839 if (S2_BadType != 0)
840 CString7="YES";
841 else
b1d15f53 842 CString7=aChecker.ArgumentTypeMode() ? "NO" : "DISABLED";
7fd59977 843 di << "Shapes are not suppotrted by BOP: " << CString7 << "\n";
844 Standard_CString CString8;
4e57c75e 845 if (S2_SelfInt != 0)
846 CString8="YES";
847 else
b1d15f53 848 CString8=aChecker.SelfInterMode() ? "NO" : "DISABLED";
7fd59977 849 di << "Self-Intersections : " << CString8;
850 if(S2_SelfInt != 0)
851 di << " Cases(" << S2_SelfInt << ") Total shapes(" << S2_SelfIntAll << ")" << "\n";
852 else
853 di << "\n";
4e57c75e 854
855 Standard_CString CString14;
856 if (S2_OpAb != 0)
857 CString14="YES";
858 else
b1d15f53 859 CString14=aChecker.SelfInterMode() ? "NO" : "DISABLED";
4e57c75e 860 di << "Check for SI has been aborted : " << CString14 << "\n";
7fd59977 861 Standard_CString CString9;
4e57c75e 862 if (S2_SmalE != 0)
863 CString9="YES";
864 else
b1d15f53 865 CString9=aChecker.SmallEdgeMode() ? "NO" : "DISABLED";
7fd59977 866 di << "Too small edges : " << CString9;
867 if(S2_SmalE != 0)
868 di << " Cases(" << S2_SmalE << ") Total shapes(" << S2_SmalEAll << ")" << "\n";
869 else
870 di << "\n";
871 Standard_CString CString10;
4e57c75e 872 if (S2_BadF != 0)
873 CString10="YES";
874 else
b1d15f53 875 CString10=aChecker.RebuildFaceMode() ? "NO" : "DISABLED";
7fd59977 876 di << "Bad faces : " << CString10;
877 if(S2_BadF != 0)
878 di << " Cases(" << S2_BadF << ") Total shapes(" << S2_BadFAll << ")" << "\n";
879 else
880 di << "\n";
881 Standard_CString CString11;
4e57c75e 882 if (S2_BadV != 0)
883 CString11="YES";
884 else
b1d15f53 885 CString11=aChecker.MergeVertexMode() ? "NO" : "DISABLED";
7fd59977 886 di << "Too close vertices : " << CString11;
887 if(S2_BadV != 0)
888 di << " Cases(" << S2_BadV << ") Total shapes(" << S2_BadVAll << ")" << "\n";
889 else
890 di << "\n";
891 Standard_CString CString12;
4e57c75e 892 if (S2_BadE != 0)
893 CString12="YES";
894 else
b1d15f53 895 CString12=aChecker.MergeEdgeMode() ? "NO" : "DISABLED";
7fd59977 896 di << "Too close edges : " << CString12;
897 if(S2_BadE != 0)
898 di << " Cases(" << S2_BadE << ") Total shapes(" << S2_BadEAll << ")" << "\n";
899 else
900 di << "\n";
0e09ee8e 901 Standard_CString CString16;
902 if (S2_C0 != 0)
903 CString16="YES";
904 else
b1d15f53 905 CString16=aChecker.ContinuityMode() ? "NO" : "DISABLED";
0e09ee8e 906 di << "Shapes with Continuity C0 : " << CString16;
907 if(S2_C0 != 0)
908 di << " Cases(" << S2_C0 << ") Total shapes(" << S2_C0All << ")" << "\n";
909 else
910 di << "\n";
7fd59977 911
e98e3990 912 Standard_CString CString18;
913 if (S2_COnS != 0)
914 CString18="YES";
915 else
b1d15f53 916 CString18=aChecker.CurveOnSurfaceMode() ? "NO" : "DISABLED";
e98e3990 917 di << "Invalid Curve on Surface : " << CString18;
918 if(S2_COnS != 0)
919 di << " Cases(" << S2_COnS << ") Total shapes(" << S2_COnSAll << ")" << "\n";
920 else
921 di << "\n";
922
7fd59977 923 // warning
924 di << "\n";
925 if(hasUnknown)
926 di << "WARNING: The unexpected test break occurs!" << "\n";
927 }
928 } // full output
929 } // has faulties
930
931 return 0;
932}
e98e3990 933
934//=======================================================================
935//function : xdistef
936//purpose :
937//=======================================================================
938Standard_Integer xdistef(Draw_Interpretor& di,
939 Standard_Integer n,
940 const char** a)
941{
942 if(n < 3) {
943 di << "Use efmaxdist edge face\n";
944 return 1;
945 }
946 //
947 const TopoDS_Shape aS1 = DBRep::Get(a[1]);
948 const TopoDS_Shape aS2 = DBRep::Get(a[2]);
949 //
950 if (aS1.IsNull() || aS2.IsNull()) {
951 di << "null shapes\n";
952 return 1;
953 }
954 //
955 if (aS1.ShapeType() != TopAbs_EDGE ||
956 aS2.ShapeType() != TopAbs_FACE) {
957 di << "type mismatch\n";
958 return 1;
959 }
960 //
961 Standard_Real aMaxDist = 0.0, aMaxPar = 0.0;
962 //
963 const TopoDS_Edge& anEdge = *(TopoDS_Edge*)&aS1;
964 const TopoDS_Face& aFace = *(TopoDS_Face*)&aS2;
965 //
966 if(!BOPTools_AlgoTools::ComputeTolerance
967 (aFace, anEdge, aMaxDist, aMaxPar)) {
968 di << "Tolerance cannot be computed\n";
969 return 1;
970 }
971 //
972 di << "Max Distance = " << aMaxDist
973 << "; Parameter on curve = " << aMaxPar << "\n";
974 //
975 return 0;
976}
977
978//=======================================================================
979//function : checkcurveonsurf
980//purpose :
981//=======================================================================
982Standard_Integer checkcurveonsurf(Draw_Interpretor& di,
983 Standard_Integer n,
984 const char** a)
985{
986 if (n != 2) {
987 di << "use checkcurveonsurf shape\n";
988 return 1;
989 }
990 //
991 TopoDS_Shape aS = DBRep::Get(a[1]);
992 if (aS.IsNull()) {
993 di << "null shape\n";
994 return 1;
995 }
996 //
997 Standard_Integer nE, nF, anECounter, aFCounter;
b1d15f53 998 Standard_Real aT, aTolE, aDMax;
e98e3990 999 TopExp_Explorer aExpF, aExpE;
1000 char buf[200], aFName[10], anEName[10];
1001 NCollection_DataMap<TopoDS_Shape, Standard_Real, TopTools_ShapeMapHasher> aDMETol;
1002 BOPCol_DataMapOfShapeInteger aMSI;
1003 //
1004 anECounter = 0;
1005 aFCounter = 0;
1006 //
1007 aExpF.Init(aS, TopAbs_FACE);
1008 for (; aExpF.More(); aExpF.Next()) {
1009 const TopoDS_Face& aF = *(TopoDS_Face*)&aExpF.Current();
1010 //
1011 aExpE.Init(aF, TopAbs_EDGE);
1012 for (; aExpE.More(); aExpE.Next()) {
1013 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExpE.Current();
1014 //
1015 if (!BOPTools_AlgoTools::ComputeTolerance(aF, aE, aDMax, aT)) {
1016 continue;
1017 }
1018 //
1019 aTolE = BRep_Tool::Tolerance(aE);
1020 if (aDMax < aTolE) {
1021 continue;
1022 }
1023 //
1024 if (aDMETol.IsBound(aE)) {
b1d15f53 1025 Standard_Real& aD = aDMETol.ChangeFind(aE);
e98e3990 1026 if (aDMax > aD) {
b1d15f53 1027 aD = aDMax;
e98e3990 1028 }
1029 }
1030 else {
1031 aDMETol.Bind(aE, aDMax);
1032 }
1033 //
1034 if (anECounter == 0) {
1035 di << "Invalid curves on surface:\n";
1036 }
1037 //
1038 if (aMSI.IsBound(aE)) {
1039 nE = aMSI.Find(aE);
1040 }
1041 else {
1042 nE = anECounter;
1043 aMSI.Bind(aE, nE);
1044 ++anECounter;
1045 }
1046 //
1047 if (aMSI.IsBound(aF)) {
1048 nF = aMSI.Find(aF);
1049 } else {
1050 nF = aFCounter;
1051 aMSI.Bind(aF, nF);
1052 ++aFCounter;
1053 }
1054 //
1055 sprintf(anEName, "e_%d", nE);
1056 sprintf(aFName , "f_%d", nF);
1057 sprintf(buf, "edge %s on face %s (max dist: %3.16f, parameter on curve: %3.16f)\n",
1058 anEName, aFName, aDMax, aT);
1059 di << buf;
1060 //
1061 DBRep::Set(anEName, aE);
1062 DBRep::Set(aFName , aF);
1063 }
1064 }
1065 //
1066 if (anECounter > 0) {
1067 di << "\n\nSugestions to fix the shape:\n";
1068 di << "explode " << a[1] << " e;\n";
1069 //
1070 TopTools_MapOfShape M;
1071 aExpE.Init(aS, TopAbs_EDGE);
1072 for (anECounter = 0; aExpE.More(); aExpE.Next()) {
1073 const TopoDS_Shape& aE = aExpE.Current();
1074 if (!M.Add(aE)) {
1075 continue;
1076 }
1077 ++anECounter;
1078 //
1079 if (!aDMETol.IsBound(aE)) {
1080 continue;
1081 }
1082 //
1083 aTolE = aDMETol.Find(aE);
1084 aTolE *= 1.001;
1085 sprintf(buf, "settolerance %s_%d %3.16f;\n", a[1], anECounter, aTolE);
1086 di << buf;
1087 }
1088 }
1089 else {
1090 di << "This shape seems to be OK.\n";
1091 }
1092 //
1093 return 0;
1094}
1095
63def8e6 1096//=======================================================================
1097//function : MakeShapeForFullOutput
1098//purpose :
1099//=======================================================================
1100void MakeShapeForFullOutput (const TCollection_AsciiString & aBaseName,
1101 const Standard_Integer aIndex,
e98e3990 1102 const BOPCol_ListOfShape & aList,
63def8e6 1103 Standard_Integer& aCount,
e98e3990 1104 Draw_Interpretor& di,
1105 Standard_Boolean bCurveOnSurf,
1106 Standard_Real aMaxDist,
1107 Standard_Real aMaxParameter)
63def8e6 1108{
1109 TCollection_AsciiString aNum(aIndex);
1110 TCollection_AsciiString aName = aBaseName + aNum;
1111 Standard_CString name = aName.ToCString();
1112
1113 TopoDS_Compound cmp;
1114 BRep_Builder BB;
1115 BB.MakeCompound(cmp);
1116
1117 BOPCol_ListIteratorOfListOfShape anIt(aList);
1118 for(; anIt.More(); anIt.Next()) {
1119 const TopoDS_Shape & aS = anIt.Value();
1120 BB.Add(cmp, aS);
1121 aCount++;
1122 }
e98e3990 1123 di << "Made faulty shape: " << name;
1124 //
1125 if (bCurveOnSurf) {
1126 di << " (MaxDist = " << aMaxDist
1127 << ", MaxPar = " << aMaxParameter << ")";
1128 }
1129 //
1130 di << "\n";
1131 //
63def8e6 1132 DBRep::Set(name, cmp);
1133}