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