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