Adding of testing cases from subgroups 937 940 and 941 of CHL group
[occt.git] / src / BOPTest / BOPTest_BOPCommands.cxx
CommitLineData
b311480e 1// Created on: 2000-03-16
2// Created by: Peter KURNEV
3// Copyright (c) 2000-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20
21
22#include <BOPTest.ixx>
23
24#include <stdio.h>
25
26#include <DBRep.hxx>
27#include <DBRep_DrawableShape.hxx>
28
29#include <Draw.hxx>
30#include <Draw_Color.hxx>
31
32#include <TCollection_AsciiString.hxx>
33
34#include <TopAbs_ShapeEnum.hxx>
35#include <TopoDS.hxx>
36#include <TopoDS_Shape.hxx>
37#include <TopoDS_Shell.hxx>
38
39#include <TopExp.hxx>
40#include <TopTools_IndexedMapOfShape.hxx>
41
42#include <BRep_Builder.hxx>
43
44#include <BooleanOperations_ShapesDataStructure.hxx>
45#include <BooleanOperations_StateOfShape.hxx>
46
47#include <BOPTools_SolidStateFiller.hxx>
48#include <BOPTools_DSFiller.hxx>
49#include <BOPTools_SplitShapesPool.hxx>
50#include <BOPTools_ListOfPaveBlock.hxx>
51#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
52#include <BOPTools_PaveBlock.hxx>
53#include <BOPTools_PCurveMaker.hxx>
54#include <BOPTools_InterferencePool.hxx>
55#include <BOPTools_CArray1OfVVInterference.hxx>
56#include <BOPTools_CArray1OfVSInterference.hxx>
57#include <BOPTools_CArray1OfVEInterference.hxx>
58#include <BOPTools_CArray1OfESInterference.hxx>
59#include <BOPTools_CArray1OfEEInterference.hxx>
60#include <BOPTools_CArray1OfSSInterference.hxx>
61#include <BOPTools_VVInterference.hxx>
62#include <BOPTools_VEInterference.hxx>
63#include <BOPTools_VSInterference.hxx>
64#include <BOPTools_EEInterference.hxx>
65#include <BOPTools_ESInterference.hxx>
66#include <BOPTools_SSInterference.hxx>
67
68#include <BOPTest_DrawableShape.hxx>
69
70#include <BRepAlgoAPI_BooleanOperation.hxx>
71#include <BRepAlgoAPI_Section.hxx>
72#include <BRepAlgoAPI_Common.hxx>
73#include <BRepAlgoAPI_Fuse.hxx>
74#include <BRepAlgoAPI_Cut.hxx>
75
7fd59977 76#include <OSD_Chronometer.hxx>
f69df442 77#include <TColStd_IndexedMapOfInteger.hxx>
7fd59977 78
f69df442 79static OSD_Chronometer DRAW_BOP_CHRONO;
7fd59977 80static void StartChrono();
81static void StopChrono(Draw_Interpretor&);
82Standard_Integer btimesum (Draw_Interpretor& , Standard_Integer n, const char** a);
83//XX
84
85//
86static Standard_Integer bop (Draw_Interpretor&, Standard_Integer, const char**);
87//
88static Standard_Integer bcommon (Draw_Interpretor& , Standard_Integer , const char**);
89static Standard_Integer bfuse (Draw_Interpretor& , Standard_Integer , const char**);
90static Standard_Integer bcut (Draw_Interpretor& , Standard_Integer , const char**);
91static Standard_Integer bsection (Draw_Interpretor& , Standard_Integer , const char**);
92
93static Standard_Integer bFillDS (Draw_Interpretor& , Standard_Integer , const char**);
94//
95static Standard_Integer bopcommon (Draw_Interpretor& , Standard_Integer , const char**);
96static Standard_Integer bopfuse (Draw_Interpretor& , Standard_Integer , const char**);
97static Standard_Integer bopcut (Draw_Interpretor& , Standard_Integer , const char**);
98static Standard_Integer boptuc (Draw_Interpretor& , Standard_Integer , const char**);
99static Standard_Integer bopsection (Draw_Interpretor& , Standard_Integer , const char**);
100
101static Standard_Integer boperationFiller (Standard_Integer n, const char** a, const BOP_Operation anOp,
102 Draw_Interpretor&);
103//
104static Standard_Integer bopstates (Draw_Interpretor& , Standard_Integer , const char**);
105//
106static Standard_Integer bopwho (Draw_Interpretor& , Standard_Integer , const char**);
107static Standard_Integer bopsticks (Draw_Interpretor& , Standard_Integer , const char**);
108
109
110static
111 void UnUsedMap(BOPTools_SequenceOfCurves& ,
112 const BOPTools_PaveSet& ,
113 TColStd_IndexedMapOfInteger& );
114//=======================================================================
115//function : BOPCommands
116//purpose :
117//=======================================================================
118 void BOPTest::BOPCommands(Draw_Interpretor& theCommands)
119{
120 static Standard_Boolean done = Standard_False;
121 if (done)
122 return;
123
124 done = Standard_True;
125 // Chapter's name
126 const char* g = "CCR commands";
127 //
128 // Using DSFiller that is ready.
129 theCommands.Add("bop" , "Use >bop Shape1 Shape2", __FILE__, bop, g);
130 theCommands.Add("bopcommon" , "Use >bopcommon R" , __FILE__, bopcommon , g);
131 theCommands.Add("bopfuse" , "Use >bopfuse R" , __FILE__, bopfuse , g);
132 theCommands.Add("bopcut" , "Use >bopcut R" , __FILE__, bopcut , g);
133 theCommands.Add("boptuc" , "Use >boptuc R" , __FILE__, boptuc , g);
134 theCommands.Add("bopsection", "Use >bopsection R", __FILE__, bopsection, g);
135 //
136 // States
137 theCommands.Add("bopstates", "Use bopstates [-f] [-t] [-out]", __FILE__, bopstates, g);
138 //
139 theCommands.Add("bcommon" , "Use >bcommon R a b" , __FILE__, bcommon , g);
140 theCommands.Add("bfuse" , "Use >bfuse R a b" , __FILE__, bfuse , g);
141 theCommands.Add("bcut" , "Use >bcut R a b" , __FILE__, bcut , g);
142 //
143 // bsection
144 theCommands.Add("bsection", "Use >bsection Result s1 s2 [-2d/-2d1/-2d2] [-a]"
145 , __FILE__, bsection, g);
146 //
147 theCommands.Add("btimesum" , "Use >btimesum FileName" , __FILE__, btimesum, g);
148 theCommands.Add("bopwho" , "Use >bopwho Index" , __FILE__, bopwho, g);
149 theCommands.Add("bopsticks" , "Use >bopsticks" , __FILE__, bopsticks, g);
150 //
151}
152//
153//////////////////////////////////
154//
155// The one and only global variable
156//
157BOPTools_DSFiller *pDF;
158//
159//////////////////////////////////
160//
161//=======================================================================
162//function : bop
163//purpose :
164//=======================================================================
165Standard_Integer bop (Draw_Interpretor& di,
166 Standard_Integer n,
167 const char** a)
168{
169 StartChrono();
170
171 if (n<3) {
172 di << " Use >bop Shape1 Shape2\n";
173 StopChrono(di);
174 return 1;
175 }
176
177 TopoDS_Shape S1 = DBRep::Get(a[1]);
178 TopoDS_Shape S2 = DBRep::Get(a[2]);
179
180 if (S1.IsNull() || S2.IsNull()) {
181 di << " Null shapes are not allowed \n";
182 StopChrono(di);
183 return 1;
184 }
185 if (pDF!=NULL) {
186 delete pDF;
187 pDF=NULL;
188 }
189
190 pDF=new BOPTools_DSFiller;
191
192 pDF->SetShapes (S1, S2);
193 if (!pDF->IsDone()) {
194 di << "Check types of the arguments, please\n";
195 if (pDF!=NULL) {
196 delete pDF;
197 pDF=NULL;
198 }
199 StopChrono(di);
200 return 1;
201 }
202
203 pDF->Perform();
204 //printf(" BOPTools_DSFiller is Ready to use\n");
205
206 StopChrono(di);
207
208 return 0;
209}
210
211//=======================================================================
212//function : bFillDS
213//purpose :
214//=======================================================================
215Standard_Integer bFillDS (Draw_Interpretor& di,
216 Standard_Integer n,
217 const char** a)
218{
219 if (n!=4) {
220 di << " Usage: >command Result Shape1 Shape2\n";
221 return 1;
222 }
223
224 return bop(di, n, a+1);
225}
226
227//=======================================================================
228//function : bcommon
229//purpose :
230//=======================================================================
231Standard_Integer bcommon (Draw_Interpretor& di,
232 Standard_Integer n,
233 const char** a)
234{
235 Standard_Integer iFlag;
236
237 iFlag =bFillDS (di, n, a);
238
239 if (iFlag) {
240 return iFlag;
241 }
242
243 return bopcommon(di, n, a);
244}
245//=======================================================================
246//function : bfuse
247//purpose :
248//=======================================================================
249Standard_Integer bfuse(Draw_Interpretor& di,
250 Standard_Integer n,
251 const char** a)
252{
253 Standard_Integer iFlag;
254
255 iFlag =bFillDS (di, n, a);
256
257 if (iFlag) {
258 return iFlag;
259 }
260
261 return bopfuse(di, n, a);
262}
263
264//=======================================================================
265//function : bcut
266//purpose :
267//=======================================================================
268Standard_Integer bcut(Draw_Interpretor& di,
269 Standard_Integer n,
270 const char** a)
271{
272 Standard_Integer iFlag;
273
274 iFlag =bFillDS (di, n, a);
275
276 if (iFlag) {
277 return iFlag;
278 }
279
280 return bopcut(di, n, a);
281}
282//=======================================================================
283//function : bsection
284//purpose :
285//=======================================================================
286Standard_Integer bsection(Draw_Interpretor& di,
287 Standard_Integer n,
288 const char** a)
289{
290 const char* usage = " Usage: bsection Result s1 s2 [-2d/-2d1/-2d2] [-a]\n";
291 if (n < 4) {
292 di << usage;
293 return 1;
294 }
295
296 TopoDS_Shape S1 = DBRep::Get(a[2]);
297 TopoDS_Shape S2 = DBRep::Get(a[3]);
298
299 if (S1.IsNull() || S2.IsNull()) {
300 di << " Null shapes are not allowed \n";
301 return 1;
302 }
303
304
305 BRepAlgoAPI_Section aSec(S1, S2, Standard_False);
306 aSec.Approximation(Standard_False);
307 aSec.ComputePCurveOn1(Standard_False);
308 aSec.ComputePCurveOn2(Standard_False);
309 Standard_Boolean isbadparameter = Standard_False;
310
311 if(n > 4) {
312 const char* key1 = a[4];
313 const char* key2 = (n > 5) ? a[5] : NULL;
314 const char* pcurveconf = NULL;
315 Standard_Boolean approx = Standard_False;
316
317#ifdef WNT
318 if (key1 && !strcasecmp(key1,"-2d")) {
319#else
320 if (key1 && !strncasecmp(key1,"-2d", 3)) {
321#endif
322 pcurveconf = key1;
323 }
324 else {
325 if (!strcasecmp(key1,"-a")) {
326 approx = Standard_True;
327 }
328 else {
329 isbadparameter = Standard_True;
330 }
331 }
332#ifdef WNT
333 if (key2 && !strcasecmp(key2,"-2d")) {
334#else
335 if (key2 && !strncasecmp(key2,"-2d", 3)) {
336#endif
337 if(pcurveconf) {
338 isbadparameter = Standard_True;
339 }
340 else {
341 pcurveconf = key2;
342 }
343 }
344 else {
345 if(key2) {
346 if (!strcasecmp(key2,"-a")) {
347 approx = Standard_True;
348 }
349 else {
350 isbadparameter = Standard_True;
351 }
352 }
353 }
354
355 if(!isbadparameter && pcurveconf) {
356
357 if (strcasecmp(pcurveconf, "-2d") == 0) {
358 aSec.ComputePCurveOn1(Standard_True);
359 aSec.ComputePCurveOn2(Standard_True);
360 }
361 else {
362 if (strcasecmp(pcurveconf, "-2d1") == 0) {
363 aSec.ComputePCurveOn1(Standard_True);
364 }
365 else {
366 if (strcasecmp(pcurveconf, "-2d2") == 0) {
367 aSec.ComputePCurveOn2(Standard_True);
368 }
369 }
370 }
371 }
372 aSec.Approximation(approx);
373 }
374
375 if(!isbadparameter) {
376 aSec.Build();
377 Standard_Boolean anIsDone = aSec.IsDone();
378
379 if (anIsDone) {
380 const TopoDS_Shape& aR = aSec.Shape();
381 DBRep::Set (a[1], aR);
382 }
383 else {
384 di << "not done ErrorStatus()="<< aSec.ErrorStatus() <<"\n";
385 }
386 }
387 else {
388 di << usage;
389 return 1;
390 }
391 return 0;
392}
393
394//=======================================================================
395//function : bopcommon
396//purpose :
397//=======================================================================
398Standard_Integer bopcommon (Draw_Interpretor& di,
399 Standard_Integer n,
400 const char** a)
401{
402 return boperationFiller (n, a, BOP_COMMON, di);
403}
404
405//=======================================================================
406//function : bopfuse
407//purpose :
408//=======================================================================
409Standard_Integer bopfuse(Draw_Interpretor& di,
410 Standard_Integer n,
411 const char** a)
412{
413 return boperationFiller (n, a, BOP_FUSE, di);
414}
415
416//=======================================================================
417//function : bopcut
418//purpose :
419//=======================================================================
420Standard_Integer bopcut (Draw_Interpretor& di,
421 Standard_Integer n,
422 const char** a)
423{
424 return boperationFiller (n, a, BOP_CUT, di);
425}
426//=======================================================================
427//function : boptuc
428//purpose :
429//=======================================================================
430Standard_Integer boptuc (Draw_Interpretor& di,
431 Standard_Integer n,
432 const char** a)
433{
434 return boperationFiller (n, a, BOP_CUT21, di);
435}
436//=======================================================================
437//function : bopsection
438//purpose :
439//=======================================================================
440Standard_Integer bopsection (Draw_Interpretor& di,
441 Standard_Integer n,
442 const char** a)
443{
444 return boperationFiller (n, a, BOP_SECTION, di);
445}
446
447//=======================================================================
448//function : boperationFiller
449//purpose :
450//=======================================================================
451Standard_Integer boperationFiller (Standard_Integer n,
452 const char** a,
453 const BOP_Operation anOp,
454 Draw_Interpretor& di)
455{
456 //XX
457 StartChrono();
458 //XX
459
460 if (n<2) {
461 di << " Use oper> Result [-mf]\n";
462 StopChrono(di);
463 return 1;
464 }
465
466 if (pDF==NULL) {
467 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
468 StopChrono(di);
469 return 1;
470 }
471
472 const TopoDS_Shape& S1 = pDF->Shape1();
473 const TopoDS_Shape& S2 = pDF->Shape2();
474
475 if (S1.IsNull() || S2.IsNull()) {
476 di << " Null shapes are not allowed \n";
477 StopChrono(di);
478 return 1;
479 }
480
481 Standard_Boolean aMFlag, anIsDone;
482
483 aMFlag=Standard_False;
484 //
485 BRepAlgoAPI_BooleanOperation* pBuilder=NULL;
486 //
487 // SECTION
488 if (anOp==BOP_SECTION) {
489 pBuilder=new BRepAlgoAPI_Section(S1, S2, *pDF);
490 }
491 else if (anOp==BOP_COMMON) {
492 pBuilder=new BRepAlgoAPI_Common(S1, S2, *pDF);
493 }
494 else if (anOp==BOP_FUSE) {
495 pBuilder=new BRepAlgoAPI_Fuse(S1, S2, *pDF);
496 }
497 else if (anOp==BOP_CUT) {
498 pBuilder=new BRepAlgoAPI_Cut (S1, S2, *pDF);
499 }
500 else if (anOp==BOP_CUT21) {
501 pBuilder=new BRepAlgoAPI_Cut(S1, S2, *pDF, Standard_False);
502 }
503 //
504 anIsDone=pBuilder->IsDone();
505 if (anIsDone) {
506 const TopoDS_Shape& aR=pBuilder->Shape();
507 DBRep::Set (a[1], aR);
508 }
509 else {
510 di << "not done ErrorStatus()=" << pBuilder->ErrorStatus() << "\n";
511 }
512
513 delete pBuilder;
514
515 StopChrono(di);
516
517 return 0;
518}
519
520//=======================================================================
521// OTHER FUNCTIONS
522//
523static
524 void GetName (const BooleanOperations_StateOfShape aState,
525 TCollection_AsciiString& aNm);
526static
527 TopAbs_ShapeEnum ChooseShapeType(const char* a1);
528
529static
530 BooleanOperations_StateOfShape ChooseShapeState(const char* a3);
531
532//=======================================================================
533//function : bopstates
534//purpose :
535//=======================================================================
536Standard_Integer bopstates(Draw_Interpretor& di,
537 Standard_Integer n,
538 const char** a)
539{
540 if (n>4) {
541 di << " Use bopstates [-f] [-t] [-out]\n";
542 return 1;
543 }
544
545 if (pDF==NULL) {
546 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
547 return 0;
548 }
549
550 Standard_Integer i, aNbLines, aIsSmtToDraw=0;
551 BooleanOperations_StateOfShape aState, aChooseState;
552 aChooseState=BooleanOperations_UNKNOWN;
553 TopAbs_ShapeEnum aEnumToDisplay = TopAbs_COMPOUND;
554 Draw_Color aTextColor(Draw_cyan);
555 //
556 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
557 //
558 // Choose Object or Tool or All
559 i=1;
560 aNbLines=aDS.NumberOfSourceShapes();
561 if (n>=3) {
562 if (!strcmp (a[2], "-o")) {
563 aDS.ObjectRange(i, aNbLines);
564 }
565 if (!strcmp (a[2], "-t")) {
566 aDS.ToolRange(i, aNbLines);
567 }
568 }
569 //
570 // ChooseShapeState
571 if (n==4) {
572 aChooseState=ChooseShapeState(a[3]);
573 }
574 //
575 // ChooseShapeType
576 if (n==1) {
577 aEnumToDisplay=TopAbs_EDGE;
578 }
579 else if (n>1) {
580 aEnumToDisplay=ChooseShapeType(a[1]);
581 }
582 //
583 // Presentation
584 for (; i<=aNbLines; ++i) {
585 const TopoDS_Shape& aS=aDS.GetShape(i);
586 TopAbs_ShapeEnum aCurrentType=aS.ShapeType();
587 if (aCurrentType==aEnumToDisplay) {
588 aState=aDS.GetState(i);
589 TCollection_AsciiString aNm, aInd(i);
590 GetName(aState, aNm);
591
592 if (aState==BooleanOperations_INTERSECTED && aCurrentType==TopAbs_EDGE) {
593
594 const BOPTools_SplitShapesPool& aSpPool=pDF->SplitShapesPool();
595 const BOPTools_ListOfPaveBlock& aSplitsList=aSpPool(aDS.RefEdge(i));
596 BOPTools_ListIteratorOfListOfPaveBlock anIt(aSplitsList);
597 for (; anIt.More();anIt.Next()) {
598 const BOPTools_PaveBlock& aPB=anIt.Value();
599 Standard_Integer nSplit=aPB.Edge();
600 const TopoDS_Shape& aSplit=aDS.GetShape(nSplit);
601 aState=aDS.GetState(nSplit);
602 GetName(aState, aNm);
603 aNm=aNm+aInd;
604 TCollection_AsciiString aNmx, anUnd("_"), aIndx(nSplit);
605 aNmx=aNm+anUnd;
606 aNmx=aNmx+aIndx;
607
608 Standard_CString aTxt=aNmx.ToCString();
609
610 if (aChooseState!=BooleanOperations_UNKNOWN) {
611 if (aState!=aChooseState) {
612 continue;
613 }
614 }
615 aIsSmtToDraw++;
616 //printf("%s ", aTxt);
617 di << aTxt << " ";
618 Handle(BOPTest_DrawableShape) aDSh=
619 new BOPTest_DrawableShape (aSplit, aTxt, aTextColor);
620 Draw::Set (aTxt, aDSh);
621 }
622 continue;
623 }
624
625 aNm=aNm+aInd;
626 Standard_CString aText=aNm.ToCString();
627
628 if (aChooseState!=BooleanOperations_UNKNOWN) {
629 if (aState!=aChooseState) {
630 continue;
631 }
632 }
633 aIsSmtToDraw++;
634 //printf("%s ", aText);
635 di << aText << " ";
636 Handle(BOPTest_DrawableShape) aDShape=
637 new BOPTest_DrawableShape (aS, aText, aTextColor);
638 Draw::Set (aText, aDShape);
639 }
640 }
641
642 if (!aIsSmtToDraw) {
643 di << " No specified shapes\n";
644 }
645 else {
646 di << "\n";
647 }
648
649
650 return 0;
651}
652
653//=======================================================================
654//function : GetName
655//purpose :
656//=======================================================================
657void GetName (const BooleanOperations_StateOfShape aState,
658 TCollection_AsciiString& aNm)
659{
660 TCollection_AsciiString aNmOut("ou_"), aNmIn("in_"),
661 aNmOn("on_"), aNmUn("un_"), aNmInter("intr_");
662
663 switch (aState) {
664 case BooleanOperations_OUT:
665 aNm=aNmOut;
666 break;
667 case BooleanOperations_IN:
668 aNm=aNmIn;
669 break;
670 case BooleanOperations_ON:
671 aNm=aNmOn;
672 break;
673 case BooleanOperations_INTERSECTED:
674 aNm=aNmInter;
675 break;
676 default:
677 aNm=aNmUn;
678 break;
679 }
680}
681
682//=======================================================================
683//function : ChooseShapeType
684//purpose :
685//=======================================================================
686TopAbs_ShapeEnum ChooseShapeType(const char* a1)
687{
688 TopAbs_ShapeEnum aEnumToDisplay;
689
690 if (!strcmp (a1, "-c")) {
691 aEnumToDisplay=TopAbs_COMPOUND;
692 }
693 else if (!strcmp (a1, "-cs")) {
694 aEnumToDisplay=TopAbs_COMPSOLID;
695 }
696 else if (!strcmp (a1, "-s")) {
697 aEnumToDisplay=TopAbs_SOLID;
698 }
699 else if (!strcmp (a1, "-sh")) {
700 aEnumToDisplay=TopAbs_SHELL;
701 }
702 else if (!strcmp (a1, "-f")) {
703 aEnumToDisplay=TopAbs_FACE;
704 }
705 else if (!strcmp (a1, "-w")) {
706 aEnumToDisplay=TopAbs_WIRE;
707 }
708 else if (!strcmp (a1, "-e")) {
709 aEnumToDisplay=TopAbs_EDGE;
710 }
711 else if (!strcmp (a1, "-v")) {
712 aEnumToDisplay=TopAbs_VERTEX;
713 }
714 else {
715 aEnumToDisplay=TopAbs_EDGE;
716 }
717 return aEnumToDisplay;
718}
719
720//=======================================================================
721//function : ChooseShapeState
722//purpose :
723//=======================================================================
724BooleanOperations_StateOfShape ChooseShapeState(const char* a3)
725{
726 BooleanOperations_StateOfShape aChooseState=BooleanOperations_UNKNOWN;
727
728 if (!strcmp (a3, "-out")) {
729 aChooseState=BooleanOperations_OUT;
730 }
731 if (!strcmp (a3, "-in")) {
732 aChooseState=BooleanOperations_IN;
733 }
734 if (!strcmp (a3, "-on")) {
735 aChooseState=BooleanOperations_ON;
736 }
737 return aChooseState;
738}
739//XX
740// CHRONOMETER
741//
742#include <OSD_Chronometer.hxx>
743#include <TCollection_AsciiString.hxx>
744#include <OSD_OpenMode.hxx>
745#include <OSD_Path.hxx>
746#include <OSD_Protection.hxx>
747#include <OSD_File.hxx>
748
749static void SaveTimeInFile(const Standard_CString aFileName,
750 const Standard_Real aChrono,
751 Draw_Interpretor& di);
752
753//=======================================================================
754//function : StartChrono
755//purpose :
756//=======================================================================
757void StartChrono()
758{
759 char *xr=getenv ("BOPCHRONO");
760 if (xr!=NULL){
761 if (!strcmp (xr, "yes")){
f69df442
RK
762 DRAW_BOP_CHRONO.Reset();
763 DRAW_BOP_CHRONO.Start();
7fd59977 764 }
765 }
766}
767
768//=======================================================================
769//function : StopChrono
770//purpose :
771//=======================================================================
772void StopChrono(Draw_Interpretor& di)
773{
774 char *xr=getenv ("BOPCHRONO");
775 if (xr!=NULL){
776 if (!strcmp (xr, "yes")) {
777 Standard_Real Chrono;
f69df442
RK
778 DRAW_BOP_CHRONO.Stop();
779 DRAW_BOP_CHRONO.Show(Chrono);
7fd59977 780 //
781 char *aFileName=getenv("BOPCHRONOFILE");
782 if (aFileName!=NULL){
783 SaveTimeInFile(aFileName, Chrono, di);
784 }
785 else {
786 di << "Tps: " << Chrono << "\n";
787 }
788 //
789 }
790 }
791}
792//=======================================================================
793//function : SaveTimeInFile
794//purpose :
795//=======================================================================
796void SaveTimeInFile(const Standard_CString aFileName,
797 const Standard_Real aChrono,
798 Draw_Interpretor& di)
799{
800 OSD_OpenMode aMode = OSD_ReadWrite;
801 OSD_Protection aProtect(OSD_RW,OSD_RW,OSD_RW,OSD_RW);
802 TCollection_AsciiString anASName(aFileName);
803 OSD_Path aPath (anASName);
804 OSD_File aFile (aPath);
805 aFile.Append(aMode, aProtect);
806 if (!( aFile.Exists() && aFile.IsOpen())) {
807 Standard_CString aStr=anASName.ToCString();
808 di << "Can not open the file: " << aStr << "\n";
809 return;
810 }
811 TCollection_AsciiString aASTime(aChrono), aASendl("\n");
812 aASTime=aASTime+aASendl;
813 aFile.Write (aASTime, aASTime.Length());
814 aFile.Close();
815}
816//XX
817//=======================================================================
818//function : btimesum
819//purpose :
820//=======================================================================
821Standard_Integer btimesum (Draw_Interpretor& di,
822 Standard_Integer n,
823 const char** a)
824{
825 if (n!=2) {
826 di << " Use >btimesum FileName\n";
827 return 1;
828 }
829
830 TCollection_AsciiString anASName(a[1]);
831 OSD_OpenMode aMode = OSD_ReadWrite;
832 OSD_Protection aProtect(OSD_RW,OSD_RW,OSD_RW,OSD_RW);
833 OSD_Path aPath (anASName);
834 OSD_File aFile (aPath);
835 aFile.Open(aMode, aProtect);
836
837 if (!( aFile.Exists() && aFile.IsOpen())) {
838 Standard_CString aStr=anASName.ToCString();
839 di << "Can not open the file: " << aStr << "\n";
840 return 1;
841 }
842
843 Standard_Integer aNbyteRead, aNByte=256, pos;
844 Standard_Real aTC, aTime=0.;
845 while (1) {
846 if (aFile.IsAtEnd()) {
847 break;
848 }
849
850 TCollection_AsciiString aStr(aNByte);
851 aFile.ReadLine(aStr, aNByte, aNbyteRead);
852 //Standard_CString pStr=aStr.ToCString();
853
854 pos=aStr.Search("\n");
855 if (pos>0){
856 aStr.Trunc(pos-1);
857 }
858
859 if (aStr.IsRealValue()) {
860 aTC=aStr.RealValue();
861 aTime=aTime+aTC;
862 }
863 }
864 aFile.Close();
865 //
866 aFile.Append(aMode, aProtect);
867
868 TCollection_AsciiString aASLine("----------\n"), aASTime(aTime), aASendl("\n");
869 aASTime=aASTime+aASendl;
870 aFile.Write (aASLine, aASLine.Length());
871 aFile.Write (aASTime, aASTime.Length());
872 aFile.Close();
873
874 return 0;
875}
876
877
878//=======================================================================
879//
880// ex. BOPTest_TSTCommands
881//
882#include <stdio.h>
883
884#include <BOPTest_DrawableShape.hxx>
885
886#include <DBRep.hxx>
887#include <DBRep_DrawableShape.hxx>
888
889#include <Draw.hxx>
890#include <Draw_Color.hxx>
891
892#include <TCollection_AsciiString.hxx>
893
894#include <TColStd_ListOfInteger.hxx>
895#include <TColStd_ListIteratorOfListOfInteger.hxx>
896
897
898#include <BooleanOperations_ShapesDataStructure.hxx>
899#include <BOPTools_CArray1OfInterferenceLine.hxx>
900#include <BOPTools_InterferenceLine.hxx>
901#include <BOPTools_ListOfInterference.hxx>
902#include <BOPTools_ListIteratorOfListOfInterference.hxx>
903#include <BOPTools_Interference.hxx>
904#include <BOPTools_InterferencePool.hxx>
905
906#include <BOPTools_DSFiller.hxx>
907#include <BOPTools_SplitShapesPool.hxx>
908#include <BOPTools_ListOfPaveBlock.hxx>
909#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
910#include <BOPTools_PaveBlock.hxx>
911
912#include <BOPTools_PavePool.hxx>
913#include <BOPTools_PaveSet.hxx>
914#include <BOPTools_ListOfPave.hxx>
915#include <BOPTools_ListIteratorOfListOfPave.hxx>
916
917#include <BOPTools_CommonBlockPool.hxx>
918#include <BOPTools_ListOfCommonBlock.hxx>
919#include <BOPTools_ListIteratorOfListOfCommonBlock.hxx>
920#include <BOPTools_CommonBlock.hxx>
921#include <BOPTools_PaveFiller.hxx>
922#include <BOPTools_CArray1OfSSInterference.hxx>
923#include <BOPTools_SSInterference.hxx>
924#include <BOPTools_InterferencePool.hxx>
925#include <BOPTools_SequenceOfCurves.hxx>
926#include <BOPTools_Curve.hxx>
927
928#include <BOPTools_SequenceOfCurves.hxx>
929#include <BOPTools_Curve.hxx>
930#include <BOPTools_ListOfPaveBlock.hxx>
931#include <BOPTools_PaveBlock.hxx>
932#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
933
934
935static Standard_Integer bopinterf (Draw_Interpretor&, Standard_Integer, const char**);
936static Standard_Integer bopds (Draw_Interpretor&, Standard_Integer, const char**);
937static Standard_Integer bopsplits (Draw_Interpretor&, Standard_Integer, const char**);
938static Standard_Integer bopscts (Draw_Interpretor&, Standard_Integer, const char**);
939static Standard_Integer bopsamedomain(Draw_Interpretor&, Standard_Integer, const char**);
940static Standard_Integer bopaves (Draw_Interpretor&, Standard_Integer, const char**);
941static Standard_Integer bopsinf (Draw_Interpretor&, Standard_Integer, const char**);
942static Standard_Integer bopsonf (Draw_Interpretor&, Standard_Integer, const char**);
943static Standard_Integer bopnews (Draw_Interpretor& ,Standard_Integer, const char**);
944
945//=======================================================================
946//function : TSTCommands
947//purpose :
948//=======================================================================
949 void BOPTest::TSTCommands(Draw_Interpretor& theCommands)
950{
951 static Standard_Boolean done = Standard_False;
952 if (done) return;
953 done = Standard_True;
954 // Chapter's name
955 const char* g = "CCR commands";
956 //
957 theCommands.Add("bopinterf" , "", __FILE__, bopinterf, g);
958 theCommands.Add("bopds" , "Use bopds [-sw]", __FILE__, bopds, g);
959
960 theCommands.Add("bopsplits" , "", __FILE__, bopsplits, g);
961 theCommands.Add("bopscts" , "", __FILE__, bopscts, g);
962
963 theCommands.Add("bopsamedomain" , "", __FILE__, bopsamedomain, g);//SameDomain Edges
964 theCommands.Add("bopaves" , "", __FILE__, bopaves, g);
965 theCommands.Add("bopnews" , "bopnews [-f,w,e,v]", __FILE__, bopnews, g);
966 //
967 // All Splits of face1 IN face2
968 theCommands.Add("bopsinf" , "Use bopsinf #F1 #F2", __FILE__, bopsinf, g);
969 //
970 // All Splits of face1 ON face2
971 theCommands.Add("bopsonf" , "Use bopsinf #F1 #F2", __FILE__, bopsonf, g);
972}
973
974
975//=======================================================================
976//function : bopinterf
977//purpose :
978//=======================================================================
979Standard_Integer bopinterf (Draw_Interpretor& di,
980 Standard_Integer /*n*/,
981 const char** /*a*/)
982{
983 if (pDF==NULL) {
984 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
985 return 0;
986 }
987
988 Standard_Integer i, aNbLines;
989 //
990 // InterferenceTable
991 Standard_Integer aWith, anIndex, aFst, aLF;
992 BooleanOperations_KindOfInterference aType;
993
994 const BOPTools_InterferencePool& anInterferencePool=pDF->InterfPool();
995 const BOPTools_CArray1OfInterferenceLine& aTableIL=anInterferencePool.InterferenceTable();
996
997 aNbLines=aTableIL.Extent();
998 for (i=1; i<=aNbLines; ++i) {
999 aFst=0;
1000 aLF=0;
1001 const BOPTools_InterferenceLine& aIL=aTableIL(i);
1002 const BOPTools_ListOfInterference& aIList=aIL.List();
1003 BOPTools_ListIteratorOfListOfInterference anIt(aIList);
1004 for (; anIt.More(); anIt.Next()) {
1005 const BOPTools_Interference& anInterf=anIt.Value();
1006 aWith=anInterf.With();
1007 aType=anInterf.Type();
1008 anIndex=anInterf.Index();
1009 if (anIndex) {
1010 if (aFst==0){
1011 //printf(" #%d ", i);
1012 di << " #" << i << " ";
1013 aFst=1;
1014 }
1015 aLF=1;
1016 //printf("(%d, %d, %d),", aWith, aType, anIndex);
1017 di << "(" << aWith << ", " << aType << ", " << anIndex << "),";
1018 }
1019 }
1020 if (aLF) {
1021 //printf("\n");
1022 di << "\n";
1023 }
1024 }
1025 return 0;
1026}
1027
1028//=======================================================================
1029//function : bopds
1030//purpose :
1031//=======================================================================
1032Standard_Integer bopds (Draw_Interpretor& di,
1033 Standard_Integer n,
1034 const char** a)
1035{
1036 if (pDF==NULL) {
1037 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1038 return 0;
1039 }
1040
1041 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1042 Standard_Integer i, aNbLines;
1043
1044 i=1;
1045 aNbLines=aDS.NumberOfSourceShapes();
1046
1047 if (n==3) {
1048 if (!strcmp (a[2], "-o")) {
1049 aDS.ObjectRange(i, aNbLines);
1050 }
1051 if (!strcmp (a[2], "-t")) {
1052 aDS.ToolRange(i, aNbLines);
1053 }
1054 }
1055
1056 Draw_Color aTextColor(Draw_cyan);
1057 TCollection_AsciiString aNm("z");
1058
1059 for (; i<=aNbLines; ++i) {
1060
1061 const TopoDS_Shape& aS=aDS.GetShape(i);
1062 //
1063 // Prestentation
1064 TopAbs_ShapeEnum aType=aS.ShapeType();
1065 if (n==1) {
1066 if (aType==TopAbs_COMPOUND ||
1067 aType==TopAbs_COMPSOLID ||
1068 aType==TopAbs_SOLID ||
1069 aType==TopAbs_SHELL ||
1070 aType==TopAbs_FACE ||
1071 aType==TopAbs_WIRE) {
1072 continue;
1073 }
1074 }
1075
1076 if (n>=2) {
1077 if (!strcmp (a[1], "-c")) {
1078 if (aType!=TopAbs_COMPOUND) {
1079 continue;
1080 }
1081 }
1082 else if (!strcmp (a[1], "-cs")) {
1083 if (aType!=TopAbs_COMPSOLID) {
1084 continue;
1085 }
1086 }
1087 else if (!strcmp (a[1], "-s")) {
1088 if (aType!=TopAbs_SOLID) {
1089 continue;
1090 }
1091 }
1092 else if (!strcmp (a[1], "-sh")) {
1093 if (aType!=TopAbs_SHELL) {
1094 continue;
1095 }
1096 }
1097 else if (!strcmp (a[1], "-f")) {
1098 if (aType!=TopAbs_FACE) {
1099 continue;
1100 }
1101 }
1102 else if (!strcmp (a[1], "-w")) {
1103 if (aType!=TopAbs_WIRE) {
1104 continue;
1105 }
1106 }
1107 else if (!strcmp (a[1], "-e")) {
1108 if (aType!=TopAbs_EDGE) {
1109 continue;
1110 }
1111 }
1112 else if (!strcmp (a[1], "-v")) {
1113 if (aType!=TopAbs_VERTEX) {
1114 continue;
1115 }
1116 }
1117 else {
1118 continue;
1119 }
1120 }
1121
1122 TCollection_AsciiString aInd(i), aName;
1123 aName=aNm+aInd;
1124 Standard_CString aText=aName.ToCString();
1125
1126 Handle(BOPTest_DrawableShape) aDShape=
1127 new BOPTest_DrawableShape (aS, aText, aTextColor);
1128 Draw::Set (aText, aDShape);
1129 }
1130 return 0;
1131}
1132
1133//=======================================================================
1134//function : bopaves
1135//purpose :
1136//=======================================================================
1137Standard_Integer bopaves(Draw_Interpretor& di,
1138 Standard_Integer /*n*/,
1139 const char** /*a*/)
1140{
1141 if (pDF==NULL) {
1142 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1143 return 0;
1144 }
1145 Standard_Integer i, aNbLines, anIndex;
1146 Standard_Real aParam;
1147
1148 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1149 const BOPTools_PavePool& aPavePool=pDF->PavePool();
1150
1151 aNbLines=aDS.NumberOfSourceShapes();
1152 for (i=1; i<=aNbLines; ++i) {
1153 const TopoDS_Shape& aS=aDS.GetShape(i);
1154 if (aS.ShapeType()==TopAbs_EDGE) {
1155 //printf(" Edge#%d\n", i);
1156 di << " Edge#" << i << "\n";
1157 const BOPTools_PaveSet& aPaveSet=aPavePool(aDS.RefEdge(i));
1158 const BOPTools_ListOfPave& aLP= aPaveSet.Set();
1159 BOPTools_ListIteratorOfListOfPave anIt(aLP);
1160 for (; anIt.More(); anIt.Next()){
1161 const BOPTools_Pave& aPave=anIt.Value();
1162 anIndex=aPave.Index();
1163 aParam =aPave.Param();
1164 //printf(" VertIndex=%d, aParam=%f\n", anIndex, aParam);
1165 di << " VertIndex=" << anIndex << ", aParam=" << aParam << "\n";
1166 }
1167 }
1168 }
1169 return 0;
1170}
1171
1172//=======================================================================
1173//function : bopsd
1174//purpose : SameDomain Edges
1175//=======================================================================
1176Standard_Integer bopsamedomain (Draw_Interpretor& di,
1177 Standard_Integer /*n*/,
1178 const char** /*a*/)
1179{
1180 if (pDF==NULL) {
1181 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1182 return 0;
1183 }
1184 TCollection_AsciiString aNm("s");
1185
1186 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1187 const BOPTools_CommonBlockPool& aCommonBlockPool=pDF->CommonBlockPool();
1188
1189 Standard_Integer i, aNbLines, nFSD, nESD1, nESD2, nOriginal2;
1190
1191 aNbLines=aDS.NumberOfSourceShapes();
1192 for (i=1; i<=aNbLines; ++i) {
1193 const TopoDS_Shape& aSE=aDS.GetShape(i);
1194 TopAbs_ShapeEnum aType=aSE.ShapeType();
1195 if (aType==TopAbs_EDGE) {
1196
1197 const BOPTools_ListOfCommonBlock& aLCB=aCommonBlockPool(aDS.RefEdge(i));
1198
1199 if (aLCB.Extent()) {
1200 //
1201 BOPTools_ListIteratorOfListOfCommonBlock anIt(aLCB);
1202 for (; anIt.More(); anIt.Next()) {
1203 const BOPTools_CommonBlock& aCB=anIt.Value();
1204 nFSD=aCB.Face();
1205 if (nFSD) {
1206 const BOPTools_PaveBlock& aPB1=aCB.PaveBlock1();
1207 nESD1=aPB1.Edge();
1208
1209 TCollection_AsciiString aInd(i), anUnd("_"), aName;
1210 aName=aNm+aInd;
1211 aName=aName+anUnd;
1212 aName=aName+nESD1;
1213 Standard_CString aText=aName.ToCString();
1214
1215 //printf(" (EF %s %df),", aText, nFSD);
1216 di << " (EF " << aText << " " << nFSD << "f),";
1217 }
1218
1219 else {
1220 const BOPTools_PaveBlock& aPB1=aCB.PaveBlock1();
1221 nESD1=aPB1.Edge();
1222
1223 TCollection_AsciiString aInd(i), anUnd("_"), aName;
1224 aName=aNm+aInd;
1225 aName=aName+anUnd;
1226 aName=aName+nESD1;
1227 Standard_CString aText=aName.ToCString();
1228
1229 const BOPTools_PaveBlock& aPB2=aCB.PaveBlock2();
1230 nESD2=aPB2.Edge();
1231 nOriginal2=aPB2.OriginalEdge();
1232
1233 TCollection_AsciiString aInd2(nOriginal2), aName2;
1234 aName2=aNm+aInd2;
1235 aName2=aName2+anUnd;
1236 aName2=aName2+nESD2;
1237 Standard_CString aText2=aName2.ToCString();
1238
1239 //printf(" (EE %s %s ),", aText, aText2);
1240 di << " (EE " << aText << " " << aText2 << " ),";
1241 }
1242 }
1243 //printf("\n");
1244 di << "\n";
1245 }
1246 }
1247 }
1248 return 0;
1249}
1250//=======================================================================
1251//function : bopnews
1252//purpose :
1253//=======================================================================
1254Standard_Integer bopnews (Draw_Interpretor& di,
1255 Standard_Integer n,
1256 const char** a)
1257
1258{
1259 if (pDF==NULL) {
1260 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1261 return 0;
1262 }
1263
1264 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1265
1266 Standard_Integer i, iStart, aNbLinesTotal;
1267 Draw_Color aTextColor(Draw_cyan);
1268 TCollection_AsciiString aNm("z");
1269 //
1270
1271 TopAbs_ShapeEnum aType=TopAbs_EDGE;
1272 if (n>1) {
1273 if (!strcmp (a[1], "-f")) {
1274 aType=TopAbs_FACE;
1275 }
1276 else if (!strcmp (a[1], "-w")) {
1277 aType=TopAbs_WIRE;
1278 }
1279 else if (!strcmp (a[1], "-e")) {
1280 aType=TopAbs_EDGE;
1281 }
1282 else if (!strcmp (a[1], "-v")) {
1283 aType=TopAbs_VERTEX;
1284 }
1285 }
1286
1287 //
1288 iStart=aDS.NumberOfSourceShapes()+1;
1289 aNbLinesTotal =aDS.NumberOfInsertedShapes();
1290
1291 for (i=iStart; i<=aNbLinesTotal; ++i) {
1292 const TopoDS_Shape& aS=aDS.Shape(i);
1293 TopAbs_ShapeEnum aTypeCurrent=aS.ShapeType();
1294 if (aTypeCurrent==aType) {
1295 TCollection_AsciiString aName, aInd(i);
1296 aName=aNm+aInd;
1297 Standard_CString aText=aName.ToCString();
1298
1299 Handle(BOPTest_DrawableShape) aDShape=
1300 new BOPTest_DrawableShape (aS, aText, aTextColor);
1301 Draw::Set (aText, aDShape);
1302 //printf("%s ", aText);
1303 di << aText << " ";
1304 }
1305 }
1306
1307 if (iStart>aNbLinesTotal) {
1308 di << " No new shapes occured";
1309 }
1310
1311 di << "\n";
1312 return 0;
1313}
1314
1315//=======================================================================
1316//function : bopsplits
1317//purpose :
1318//=======================================================================
1319Standard_Integer bopsplits (Draw_Interpretor& di,
1320 Standard_Integer /*n*/,
1321 const char** /*a*/)
1322
1323{
1324 if (pDF==NULL) {
1325 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1326 return 0;
1327 }
1328
1329 const BOPTools_SplitShapesPool& aSpPool=pDF->SplitShapesPool();
1330 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1331
1332 Standard_Integer i, aNbLines, aNbSplits, aSplitExist=0;
1333 Draw_Color aTextColor(Draw_cyan);
1334 TCollection_AsciiString aNm("s");
1335
1336 aNbLines=aDS.NumberOfSourceShapes();
1337 for (i=1; i<=aNbLines; ++i) {
1338 const TopoDS_Shape& aSE=aDS.GetShape(i);
1339 TopAbs_ShapeEnum aType=aSE.ShapeType();
1340 if (aType==TopAbs_EDGE) {
1341 //
1342 // Splits' Prestentation
1343 const BOPTools_ListOfPaveBlock& aSplitsList=aSpPool(aDS.RefEdge(i));
1344 aNbSplits=aSplitsList.Extent();
1345 if (aNbSplits) {
1346 if (!aSplitExist) {
1347 di << " Splits: ";
1348 aSplitExist=1;
1349 }
1350
1351 BOPTools_ListIteratorOfListOfPaveBlock anIt(aSplitsList);
1352 for (; anIt.More();anIt.Next()) {
1353 const BOPTools_PaveBlock& aPB=anIt.Value();
1354 Standard_Integer nSplit=aPB.Edge();
1355 const TopoDS_Shape& aS=aDS.GetShape(nSplit);
1356
1357 TCollection_AsciiString aInd(i), anUnd("_"), aName;
1358 aName=aNm+aInd;
1359 aName=aName+anUnd;
1360 aName=aName+nSplit;
1361 Standard_CString aText=aName.ToCString();
1362
1363 Handle(BOPTest_DrawableShape) aDShape=
1364 new BOPTest_DrawableShape (aS, aText, aTextColor);
1365 Draw::Set (aText, aDShape);
1366 di << aText << " ";
1367 }
1368 }
1369 }
1370 }
1371
1372 if (!aSplitExist) {
1373 di << " No splits occured";
1374 }
1375 di << "\n";
1376 return 0;
1377}
1378
1379//=======================================================================
1380//function : bopscts
1381//purpose :
1382//=======================================================================
1383Standard_Integer bopscts (Draw_Interpretor& di,
1384 Standard_Integer /*n*/,
1385 const char** /*a*/)
1386
1387{
1388 if (pDF==NULL) {
1389 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1390 return 0;
1391 }
1392 Standard_Integer i, nF1, nF2, aNbFFs, aNbOldSects, aSectExist=0, nSect;
1393 Standard_Integer j, aNbCurves, aNbPaveBlocks, nNewEdge;
1394 Draw_Color aTextColor(Draw_cyan);
1395 TCollection_AsciiString aNm("t");
1396
1397 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1398 const BOPTools_InterferencePool& anInterfPool=pDF->InterfPool();
1399 BOPTools_InterferencePool* pInterfPool= (BOPTools_InterferencePool*) &anInterfPool;
1400 BOPTools_CArray1OfSSInterference& aFFs=pInterfPool->SSInterferences();
1401
1402 aNbFFs=aFFs.Extent();
1403 for (i=1; i<=aNbFFs; ++i) {
1404 BOPTools_SSInterference& aFFi=aFFs(i);
1405 //
1406 nF1=aFFi.Index1();
1407 nF2=aFFi.Index2();
1408 TCollection_AsciiString aInd(nF1), anUnd("_");
1409 //
1410 // Old Section Edges
1411 const BOPTools_ListOfPaveBlock& aSectList=aFFi.PaveBlocks();
1412 aNbOldSects=aSectList.Extent();
1413 if (aNbOldSects) {
1414 if (!aSectExist) {
1415 di << " Sects: ";
1416 aSectExist=1;
1417 }
1418
1419 BOPTools_ListIteratorOfListOfPaveBlock anIt(aSectList);
1420 for (; anIt.More();anIt.Next()) {
1421 const BOPTools_PaveBlock& aPB=anIt.Value();
1422 nSect=aPB.Edge();
1423 const TopoDS_Shape& aS=aDS.GetShape(nSect);
1424
1425 TCollection_AsciiString aName;
1426 aName=aNm+aInd;
1427 aName=aName+anUnd;
1428 aName=aName+nSect;
1429 Standard_CString aText=aName.ToCString();
1430
1431 Handle(BOPTest_DrawableShape) aDShape=
1432 new BOPTest_DrawableShape (aS, aText, aTextColor);
1433 Draw::Set (aText, aDShape);
1434 di << aText << " ";
1435 }
1436 }
1437 //
1438 // New Section Edges
1439 BOPTools_SequenceOfCurves& aBCurves=aFFi.Curves();
1440 aNbCurves=aBCurves.Length();
1441 for (j=1; j<=aNbCurves; j++) {
1442 BOPTools_Curve& aBC=aBCurves(j);
1443 const BOPTools_ListOfPaveBlock& aSectEdges=aBC.NewPaveBlocks();
1444 aNbPaveBlocks=aSectEdges.Extent();
1445 if (aNbPaveBlocks) {
1446 if (!aSectExist) {
1447 di << " Sects: ";
1448 aSectExist=1;
1449 }
1450 }
1451 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSectEdges);
1452 for (; aPBIt.More(); aPBIt.Next()) {
1453 BOPTools_PaveBlock& aPB=aPBIt.Value();
1454 nNewEdge=aPB.Edge();
1455 const TopoDS_Shape& aSectEdge=aDS.GetShape(nNewEdge);
1456
1457 TCollection_AsciiString aName;
1458 aName=aNm+aInd;
1459 aName=aName+anUnd;
1460 aName=aName+nNewEdge;
1461 Standard_CString aText=aName.ToCString();
1462
1463 Handle(BOPTest_DrawableShape) aDShape=
1464 new BOPTest_DrawableShape (aSectEdge, aText, aTextColor);
1465 Draw::Set (aText, aDShape);
1466 di << aText << " ";
1467 }
1468 }
1469 }
1470
1471 if (!aSectExist) {
1472 di << " No section edges";
1473 }
1474 di << "\n";
1475 return 0;
1476}
1477
1478//=======================================================================
1479//function : bopsinf
1480//purpose :
1481//=======================================================================
1482Standard_Integer bopsinf (Draw_Interpretor& di,
1483 Standard_Integer n,
1484 const char** a)
1485{
1486 if (pDF==NULL) {
1487 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1488 return 0;
1489 }
1490
1491 if (n!=3) {
1492 di << " Use: bopsinf> #F1 #F2\n";
1493 return 0;
1494 }
1495
1496 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1497
1498 Standard_Integer nSp=0, nF1, nF2, anExistFlag=0;
91322f44 1499 nF1=Draw::Atoi(a[1]);
1500 nF2=Draw::Atoi(a[2]);
7fd59977 1501
1502 const TopoDS_Shape& aS1=aDS.GetShape(nF1);
1503 const TopoDS_Shape& aS2=aDS.GetShape(nF2);
1504 if (aS1.IsNull() || aS2.IsNull()) {
1505 //printf(" Null shapes #%d #%d\n", nF1, nF2 );
1506 di << " Null shapes #" << nF1 << " #" << nF2 << "\n";
1507 return 0;
1508 }
1509
1510 if (aS1.ShapeType()!=TopAbs_FACE ||
b2d4add4 1511 aS2.ShapeType()!=TopAbs_FACE ) {
7fd59977 1512 //printf(" Shapes #%d #%d are not faces\n", nF1, nF2 );
1513 di << " Shapes #" << nF1 << " #" << nF2 << " are not faces\n";
1514 return 0;
1515 }
1516
1517 TColStd_ListOfInteger aSplList;
1518 const BOPTools_PaveFiller& aPF=pDF->PaveFiller();
1519 BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)&aPF;
1520
1521 pPF->SplitsInFace (nSp, nF1, nF2, aSplList);
1522
1523 TColStd_ListIteratorOfListOfInteger anIt (aSplList);
1524 for (; anIt.More(); anIt.Next()) {
1525 anExistFlag=1;
1526 nSp=anIt.Value();
1527 //printf("%d, ", nSp);
1528 di << nSp << ", ";
1529 }
1530
1531 if(anExistFlag) {
1532 di << "\n";
1533 }
1534 else {
1535 di << "No splits of Face" << nF1 << " IN Face " << nF2 << "\n";
1536 }
1537
1538return 0;
1539}
1540//=======================================================================
1541//function : bopsonf
1542//purpose :
1543//=======================================================================
1544Standard_Integer bopsonf (Draw_Interpretor& di,
1545 Standard_Integer n,
1546 const char** a)
1547{
1548 if (pDF==NULL) {
1549 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1550 return 0;
1551 }
1552
1553 if (n!=3) {
1554 di << " Use: bopsonf> #F1 #F2\n";
1555 return 0;
1556 }
1557
1558 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1559
1560 Standard_Integer nSp=0, nF1, nF2, anExistFlag=0;
91322f44 1561 nF1=Draw::Atoi(a[1]);
1562 nF2=Draw::Atoi(a[2]);
7fd59977 1563
1564 const TopoDS_Shape& aS1=aDS.GetShape(nF1);
1565 const TopoDS_Shape& aS2=aDS.GetShape(nF2);
1566 if (aS1.IsNull() || aS2.IsNull()) {
1567 //printf(" Null shapes #%d #%d\n", nF1, nF2 );
1568 di << " Null shapes #" << nF1 << " #" << nF2 << "\n";
1569 return 0;
1570 }
1571
1572 if (aS1.ShapeType()!=TopAbs_FACE ||
b2d4add4 1573 aS2.ShapeType()!=TopAbs_FACE ) {
7fd59977 1574 //printf(" Shapes #%d #%d are not faces\n", nF1, nF2 );
1575 di << " Shapes #" << nF1 << " #" << nF2 << " are not faces\n";
1576 return 0;
1577 }
1578
1579 TColStd_ListOfInteger aSplList;
1580 const BOPTools_PaveFiller& aPF=pDF->PaveFiller();
1581 BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)&aPF;
1582
1583 pPF->SplitsOnFace (nSp, nF1, nF2, aSplList);
1584
1585 TColStd_ListIteratorOfListOfInteger anIt (aSplList);
1586 for (; anIt.More(); anIt.Next()) {
1587 anExistFlag=1;
1588 nSp=anIt.Value();
1589 //printf("%d, ", nSp);
1590 di << nSp << ", ";
1591 }
1592
1593 if(anExistFlag) {
1594 di << "\n";
1595 }
1596 else {
1597 di << "No splits of Face" << nF1 << " ON Face " << nF2 << "\n";
1598 }
1599
1600 return 0;
1601}
1602
1603//=======================================================================
1604//function : bopwho
1605//purpose :
1606//=======================================================================
1607Standard_Integer bopwho (Draw_Interpretor& di,
1608 Standard_Integer n,
1609 const char** a)
1610{
1611 if (pDF==NULL) {
1612 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1613 return 0;
1614 }
1615
1616 if (n!=2) {
1617 di << " Use >bopwho Index\n";
1618 return 1;
1619 }
1620 //
1621 Standard_Boolean bIsNewShape;
1622 Standard_Integer iNum, i, aNbLines, aNbObj, aNewShape, aWhat, aWith;
1623 //
91322f44 1624 iNum=Draw::Atoi(a[1]);
7fd59977 1625 if (iNum<=0) {
1626 di << " Shape Index must be >0 .\n";
1627 return 1;
1628 }
1629 //
1630 //printf("Shape #%d is ", iNum);
1631 di << "Shape #" << iNum << " is ";
1632
1633 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1634 aNbLines=aDS.NumberOfSourceShapes();
1635 //
1636 //
1637 // Old shapes processing
1638 //
1639 if (iNum>0 && iNum<=aNbLines) {
1640 di << "from the ";
1641 // Old Shape
1642 aNbObj=aDS.NumberOfShapesOfTheObject();
1643 if (iNum<=aNbObj) {
1644 di << "Object ";
1645 }
1646 else {
1647 di << "Tool ";
1648 }
1649 di << ".\n";
1650 return 0;
1651 }
1652 //
1653 bIsNewShape=aDS.IsNewShape(iNum);
1654 if (bIsNewShape) {
1655 di << "new.\n";
1656 }
1657
1658 else {
1659 di << "undefined.\n";
1660 return 0;
1661 }
1662 //
1663 // New shapes processing
1664 //
1665 const TopoDS_Shape& aShapeToFind=aDS.Shape(iNum);
1666 TopAbs_ShapeEnum aTypeOfShapeToFind=aShapeToFind.ShapeType();
1667 //
1668 // Interferences
1669 const BOPTools_InterferencePool& anInterferencePool=pDF->InterfPool();
1670 //
1671 const BOPTools_CArray1OfVVInterference& aVVInterfs=anInterferencePool.VVInterfs();
1672 const BOPTools_CArray1OfVEInterference& aVEInterfs=anInterferencePool.VEInterfs();
1673 const BOPTools_CArray1OfVSInterference& aVSInterfs=anInterferencePool.VSInterfs();
1674 const BOPTools_CArray1OfEEInterference& aEEInterfs=anInterferencePool.EEInterfs();
1675 const BOPTools_CArray1OfESInterference& aESInterfs=anInterferencePool.ESInterfs();
1676 //
1677 // VV
1678 aNbLines=aVVInterfs.Extent();
1679 for (i=1; i<=aNbLines; ++i) {
1680 aNewShape=aVVInterfs(i).NewShape();
1681 if (aNewShape==iNum) {
1682 aVVInterfs(i).Indices(aWhat, aWith);
1683 //printf(" VV: (%d, %d)\n", aWhat, aWith);
1684 di << " VV: (" << aWhat << ", " << aWith << ")\n";
1685 }
1686 }
1687 //
1688 // VE
1689 aNbLines=aVEInterfs.Extent();
1690 for (i=1; i<=aNbLines; ++i) {
1691 aNewShape=aVEInterfs(i).NewShape();
1692 if (aNewShape==iNum) {
1693 aVEInterfs(i).Indices(aWhat, aWith);
1694 //printf(" VE: (%d, %d)\n", aWhat, aWith);
1695 di << " VE: (" << aWhat << ", " << aWith << ")\n";
1696 }
1697 }
1698 //
1699 // VF
1700 aNbLines=aVSInterfs.Extent();
1701 for (i=1; i<=aNbLines; ++i) {
1702 aNewShape=aVSInterfs(i).NewShape();
1703 if (aNewShape==iNum) {
1704 aVSInterfs(i).Indices(aWhat, aWith);
1705 //printf(" VF: (%d, %d)\n", aWhat, aWith);
1706 di << " VF: (" << aWhat << ", " << aWith << ")\n";
1707 }
1708 }
1709 //
1710 // EE
1711 aNbLines=aEEInterfs.Extent();
1712 for (i=1; i<=aNbLines; ++i) {
1713 aNewShape=aEEInterfs(i).NewShape();
1714 if (aNewShape==iNum) {
1715 aEEInterfs(i).Indices(aWhat, aWith);
1716 //printf(" EE: (%d, %d)\n", aWhat, aWith);
1717 di << " EE: (" << aWhat << ", " << aWith << ")\n";
1718 }
1719 }
1720 //
1721 // EF
1722 aNbLines=aESInterfs.Extent();
1723 for (i=1; i<=aNbLines; ++i) {
1724 aNewShape=aESInterfs(i).NewShape();
1725 if (aNewShape==iNum) {
1726 aESInterfs(i).Indices(aWhat, aWith);
1727 //printf(" EF: (%d, %d)\n", aWhat, aWith);
1728 di << " EF: (" << aWhat << ", " << aWith << ")\n";
1729 }
1730 }
1731 //
1732 // FF
1733 Standard_Integer j, aNbCurves;
1734 //
1735 BOPTools_InterferencePool* pInterPool=(BOPTools_InterferencePool*)&pDF->InterfPool();
1736 BOPTools_CArray1OfSSInterference& aSSInterfs=pInterPool->SSInterferences();
1737 //
1738 aNbLines=aSSInterfs.Extent();
1739 for (i=1; i<=aNbLines; ++i) {
1740 BOPTools_SSInterference& aFF=aSSInterfs(i);
1741 aWhat=aFF.Index1();
1742 aWith=aFF.Index2();
1743
1744
1745 BOPTools_SequenceOfCurves& aSC=aFF.Curves();
1746
1747 aNbCurves=aSC.Length();
1748 for (j=1; j<=aNbCurves; ++j) {
1749 const BOPTools_Curve& aBC=aSC(j);
1750
1751 if (aTypeOfShapeToFind==TopAbs_EDGE) {
1752 const BOPTools_ListOfPaveBlock& aLPB=aBC.NewPaveBlocks();
1753 BOPTools_ListIteratorOfListOfPaveBlock anIt(aLPB);
1754 for (; anIt.More(); anIt.Next()) {
1755 const BOPTools_PaveBlock& aPB=anIt.Value();
1756 aNewShape=aPB.Edge();
1757 if (aNewShape==iNum) {
1758 //printf(" FF: (%d, %d) [Section Edge]\n", aWhat, aWith);
1759 di << " FF: (" << aWhat << ", " << aWith << ") [Section Edge]\n";
1760 }
1761 }
1762 }
1763 //
1764 if (aTypeOfShapeToFind==TopAbs_VERTEX) {
1765 BOPTools_Curve* pBC=(BOPTools_Curve*)&aBC;
1766 TColStd_ListOfInteger& aTVList=pBC->TechnoVertices();
1767 TColStd_ListIteratorOfListOfInteger aTVIt(aTVList);
1768 for (; aTVIt.More(); aTVIt.Next()) {
1769 aNewShape=aTVIt.Value();
1770 if (aNewShape==iNum) {
1771 //printf(" FF: (%d, %d) [Techno Vertex]\n", aWhat, aWith);
1772 di << " FF: (" << aWhat << ", " << aWith << ") [Techno Vertex]\n";
1773 }
1774 }
1775 }
1776 }
1777 //
1778 if (aTypeOfShapeToFind==TopAbs_VERTEX) {
1779 TColStd_ListOfInteger& anAVList=aFF.AloneVertices();
1780 TColStd_ListIteratorOfListOfInteger anAVIt(anAVList);
1781 for (; anAVIt.More(); anAVIt.Next()) {
1782 aNewShape=anAVIt.Value();
1783 if (aNewShape==iNum) {
1784 //printf(" FF: (%d, %d) [Alone Vertex]\n", aWhat, aWith);
1785 di << " FF: (" << aWhat << ", " << aWith << ") [Alone Vertex]\n";
1786 }
1787 }
1788 }
1789 }
1790 //
1791 //
1792 // PaveBlocks
1793 if (aTypeOfShapeToFind==TopAbs_EDGE) {
1794 //
1795 Standard_Integer aNbPaveBlocks, nE, nOriginalEdge, aNbCommonBlocks;
1796 Standard_Integer nFace, nE2, nOriginalEdge2;
1797 //
1798 const BOPTools_CommonBlockPool& aCommonBlockPool=pDF->CommonBlockPool();
1799 const BOPTools_SplitShapesPool& aSplitShapesPool=pDF->SplitShapesPool();
1800 aNbLines=aSplitShapesPool.Extent();
1801 for (i=1; i<=aNbLines; ++i) {
1802 const BOPTools_ListOfPaveBlock& aSplitEdges=aSplitShapesPool(i);
1803 aNbPaveBlocks=aSplitEdges.Extent();
1804
1805 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSplitEdges);
1806 for (; aPBIt.More(); aPBIt.Next()) {
1807 const BOPTools_PaveBlock& aPB=aPBIt.Value();
1808 nE=aPB.Edge();
1809 nOriginalEdge=aPB.OriginalEdge();
1810 if (nE==iNum) {
1811 //printf(" PaveBlock [Base Edge #%d]\n", nOriginalEdge);
1812 di << " PaveBlock [Base Edge #" << nOriginalEdge << "]\n";
1813 const BOPTools_ListOfCommonBlock& aLCB=
1814 aCommonBlockPool(aDS.RefEdge(nOriginalEdge));
1815 aNbCommonBlocks=aLCB.Extent();
1816
1817 BOPTools_ListIteratorOfListOfCommonBlock aCBIt(aLCB);
1818 for (; aCBIt.More(); aCBIt.Next()) {
1819 BOPTools_CommonBlock& aCB=aCBIt.Value();
1820 nFace=aCB.Face();
1821 if (nFace) {
1822 //printf(" CommonBlock with Face #%d\n", nFace);
1823 di << " CommonBlock with Face #" << nFace << "\n";
1824 }
1825 else {
1826 BOPTools_PaveBlock& aPB2=aCB.PaveBlock2(nOriginalEdge);
1827 nE2=aPB2.Edge();
1828 nOriginalEdge2=aPB2.OriginalEdge();
1829 //printf(" CommonBlock with Edge #%d [Base Edge #%d]\n",
1830 // nE2, nOriginalEdge2);
1831 di << " CommonBlock with Edge #" << nE2 << " [Base Edge #" << nOriginalEdge2 << "]\n";
1832 }
1833 }
1834
1835 }
1836 }
1837 }
1838
1839 }
1840 return 0;
1841}
1842
1843//=======================================================================
1844//function : bopsticks
1845//purpose :
1846//=======================================================================
1847Standard_Integer bopsticks (Draw_Interpretor& di,
1848 Standard_Integer n,
1849 const char** )
1850{
1851 if (pDF==NULL) {
1852 di << " Prepare BOPTools_DSFiller first >bop S1 S2\n";
1853 return 1;
1854 }
1855 //
1856 if (n!=1) {
1857 di << " Use >bopsticks\n";
1858 return 1;
1859 }
1860 //
1861 Standard_Integer i, j, aNbLines, nF1, nF2, aNbVtx, nV;
1862 //
1863 const BooleanOperations_ShapesDataStructure& aDS=pDF->DS();
1864 const BOPTools_PaveFiller& aPF=pDF->PaveFiller();
1865 BOPTools_PaveFiller* pPF=(BOPTools_PaveFiller*)&aPF;
1866 BOPTools_InterferencePool* pInterPool=(BOPTools_InterferencePool*)&pDF->InterfPool();
1867 BOPTools_CArray1OfSSInterference& aSSInterfs=pInterPool->SSInterferences();
1868 //
1869 aNbLines=aSSInterfs.Extent();
1870 //
1871 for (i=1; i<=aNbLines; ++i) {
1872 TColStd_IndexedMapOfInteger aMapUnUsed;
1873 BOPTools_PaveSet aPSF;
1874 //
1875 BOPTools_SSInterference& aFF=aSSInterfs(i);
1876 BOPTools_SequenceOfCurves& aSCvs=aFF.Curves();
1877
1878 nF1=aFF.Index1();
1879 nF2=aFF.Index2();
1880
1881 pPF->PrepareSetForFace(nF1, nF2, aPSF);
1882 UnUsedMap(aSCvs, aPSF, aMapUnUsed);
1883 aNbVtx=aMapUnUsed.Extent();
1884 for (j=1; j<=aNbVtx; ++j) {
1885 nV=aMapUnUsed(j);
1886 if (aDS.IsNewShape(nV)) {
1887 //printf(" Vertex #%d [FF:(%d, %d)]\n", nV, nF1, nF2);
1888 di << " Vertex #" << nV << " [FF:(" << nF1 << ", " << nF2 << ")]\n";
1889 }
1890 }
1891 }
1892 return 0;
1893}
1894
1895//=======================================================================
1896// function: UnUsedMap
1897// purpose:
1898//=======================================================================
1899void UnUsedMap(BOPTools_SequenceOfCurves& aSCvs,
1900 const BOPTools_PaveSet& aPSF,
1901 TColStd_IndexedMapOfInteger& aMapUnUsed)
1902{
1903 //
1904 // What stick/non-stick vertices we used
1905 TColStd_IndexedMapOfInteger aMapUsed, aMapMustBeUsed;
1906 Standard_Integer j, aNbCurves, aNbVtx, nV1;//, nV2;
1907 BOPTools_ListIteratorOfListOfPave anLPIt;
1908
1909 aNbCurves=aSCvs.Length();
1910 for (j=1; j<=aNbCurves; ++j) {
1911 BOPTools_Curve& aBC=aSCvs(j);
1912 //const IntTools_Curve& aC= aBC.Curve();// Wng in Gcc 3.0
1913
1914 const BOPTools_PaveSet& aPaveSet=aBC.Set();
1915 const BOPTools_ListOfPave& aLPAlreadyUsed=aPaveSet.Set();
1916 anLPIt.Initialize(aLPAlreadyUsed);
1917 for (; anLPIt.More(); anLPIt.Next()) {
1918 const BOPTools_Pave& aPave=anLPIt.Value();
1919 nV1=aPave.Index();
1920 aMapUsed.Add(nV1);
1921 }
1922 }
1923 //
1924 // 2. Stick vertices that must be used
1925 const BOPTools_ListOfPave& aLPMustUsed=aPSF.Set();
1926 anLPIt.Initialize(aLPMustUsed);
1927 for (; anLPIt.More(); anLPIt.Next()) {
1928 const BOPTools_Pave& aPave=anLPIt.Value();
1929 nV1=aPave.Index();
1930 aMapMustBeUsed.Add(nV1);
1931 }
1932 //
1933 // 3.Unused Stick vertices .
1934 aNbVtx=aMapMustBeUsed.Extent();
1935 for (j=1; j<=aNbVtx; ++j) {
1936 nV1=aMapMustBeUsed(j);
1937 if (!aMapUsed.Contains(nV1)) {
1938 aMapUnUsed.Add(nV1);
1939 }
1940 }
1941 //
1942}