1 // Created on: 2000-03-16
2 // Created by: Peter KURNEV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <BOPTest.ixx>
27 #include <NCollection_BaseAllocator.hxx>
28 #include <NCollection_IncAllocator.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Compound.hxx>
32 #include <BRep_Builder.hxx>
34 #include <BOPAlgo_PaveFiller.hxx>
35 #include <BOPAlgo_Operation.hxx>
36 #include <BOPAlgo_BOP.hxx>
37 #include <BOPAlgo_SectionAttribute.hxx>
38 #include <BOPDS_DS.hxx>
39 #include <BOPTest_DrawableShape.hxx>
40 #include <BOPCol_ListOfShape.hxx>
42 #include <TCollection_AsciiString.hxx>
43 #include <IntTools_FaceFace.hxx>
44 #include <IntTools_Curve.hxx>
45 #include <DrawTrSurf.hxx>
46 #include <Draw_Color.hxx>
50 static BOPAlgo_PaveFiller* pPF=NULL;
54 Standard_Integer bopsmt(Draw_Interpretor& di,
57 const BOPAlgo_Operation aOp);
59 Standard_Integer bsmt (Draw_Interpretor& di,
62 const BOPAlgo_Operation aOp);
64 static Standard_Integer bop (Draw_Interpretor&, Standard_Integer, const char**);
65 static Standard_Integer bopsection(Draw_Interpretor&, Standard_Integer, const char**);
66 static Standard_Integer boptuc (Draw_Interpretor&, Standard_Integer, const char**);
67 static Standard_Integer bopcut (Draw_Interpretor&, Standard_Integer, const char**);
68 static Standard_Integer bopfuse (Draw_Interpretor&, Standard_Integer, const char**);
69 static Standard_Integer bopcommon (Draw_Interpretor&, Standard_Integer, const char**);
71 static Standard_Integer bsection (Draw_Interpretor&, Standard_Integer, const char**);
72 static Standard_Integer btuc (Draw_Interpretor&, Standard_Integer, const char**);
73 static Standard_Integer bcut (Draw_Interpretor&, Standard_Integer, const char**);
74 static Standard_Integer bfuse (Draw_Interpretor&, Standard_Integer, const char**);
75 static Standard_Integer bcommon (Draw_Interpretor&, Standard_Integer, const char**);
77 static Standard_Integer bopcurves (Draw_Interpretor&, Standard_Integer, const char**);
78 static Standard_Integer bopnews (Draw_Interpretor&, Standard_Integer, const char**);
80 //=======================================================================
81 //function : BOPCommands
83 //=======================================================================
84 void BOPTest::BOPCommands(Draw_Interpretor& theCommands)
86 static Standard_Boolean done = Standard_False;
90 const char* g = "BOP commands";
93 theCommands.Add("bop" , "use bop s1 s2" , __FILE__, bop, g);
94 theCommands.Add("bopcommon" , "use bopcommon r" , __FILE__, bopcommon, g);
95 theCommands.Add("bopfuse" , "use bopfuse r" , __FILE__,bopfuse, g);
96 theCommands.Add("bopcut" , "use bopcut" , __FILE__,bopcut, g);
97 theCommands.Add("boptuc" , "use boptuc" , __FILE__,boptuc, g);
98 theCommands.Add("bopsection", "use bopsection" , __FILE__,bopsection, g);
100 theCommands.Add("bcommon" , "use bcommon r s1 s2" , __FILE__,bcommon, g);
101 theCommands.Add("bfuse" , "use bfuse r s1 s2" , __FILE__,bfuse, g);
102 theCommands.Add("bcut" , "use bcut r s1 s2" , __FILE__,bcut, g);
103 theCommands.Add("btuc" , "use btuc r s1 s2" , __FILE__,btuc, g);
104 theCommands.Add("bsection", "Use >bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]",
105 __FILE__, bsection, g);
107 theCommands.Add("bopcurves", "use bopcurves F1 F2", __FILE__, bopcurves, g);
108 theCommands.Add("bopnews", "use bopnews -v[e,f]" , __FILE__, bopnews, g);
111 //=======================================================================
114 //=======================================================================
115 Standard_Integer bop (Draw_Interpretor& di, Standard_Integer n, const char** a)
118 Standard_Integer iErr;
119 TopoDS_Shape aS1, aS2;
120 BOPCol_ListOfShape aLC;
123 di << " use bop Shape1 Shape2\n";
127 aS1=DBRep::Get(a[1]);
128 aS2=DBRep::Get(a[2]);
130 if (aS1.IsNull() || aS2.IsNull()) {
131 di << " null shapes are not allowed \n";
140 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
141 pPF=new BOPAlgo_PaveFiller(aAL);
144 pPF->SetArguments(aLC);
147 iErr=pPF->ErrorStatus();
149 Sprintf(buf, " ErrorStatus : %d\n", iErr);
156 //=======================================================================
157 //function : bopcommon
159 //=======================================================================
160 Standard_Integer bopcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
162 return bopsmt(di, n, a, BOPAlgo_COMMON);
164 //=======================================================================
167 //=======================================================================
168 Standard_Integer bopfuse(Draw_Interpretor& di, Standard_Integer n, const char** a)
170 return bopsmt(di, n, a, BOPAlgo_FUSE);
172 //=======================================================================
175 //=======================================================================
176 Standard_Integer bopcut(Draw_Interpretor& di, Standard_Integer n, const char** a)
178 return bopsmt(di, n, a, BOPAlgo_CUT);
180 //=======================================================================
183 //=======================================================================
184 Standard_Integer boptuc(Draw_Interpretor& di, Standard_Integer n, const char** a)
186 return bopsmt(di, n, a, BOPAlgo_CUT21);
188 //=======================================================================
189 //function : bopsection
191 //=======================================================================
192 Standard_Integer bopsection(Draw_Interpretor& di, Standard_Integer n, const char** a)
194 return bopsmt(di, n, a, BOPAlgo_SECTION);
196 //=======================================================================
199 //=======================================================================
200 Standard_Integer bopsmt(Draw_Interpretor& di,
203 const BOPAlgo_Operation aOp)
206 di << " use bopsmt r\n";
211 di << " prepare PaveFiller first\n";
215 if (pPF->ErrorStatus()) {
216 di << " PaveFiller has not been done\n";
221 Standard_Integer aNb, iErr;
224 const BOPCol_ListOfShape& aLC=pPF->Arguments();
227 Sprintf (buf, " wrong number of arguments %s\n", aNb);
232 const TopoDS_Shape& aS1=aLC.First();
233 const TopoDS_Shape& aS2=aLC.Last();
235 aBOP.AddArgument(aS1);
237 aBOP.SetOperation(aOp);
239 aBOP.PerformWithFiller(*pPF);
240 iErr=aBOP.ErrorStatus();
242 Sprintf(buf, " ErrorStatus : %d\n", iErr);
247 const TopoDS_Shape& aR=aBOP.Shape();
249 di << " null shape\n";
253 DBRep::Set(a[1], aR);
256 //=======================================================================
259 //=======================================================================
260 Standard_Integer bcommon (Draw_Interpretor& di, Standard_Integer n, const char** a)
262 return bsmt(di, n, a, BOPAlgo_COMMON);
264 //=======================================================================
267 //=======================================================================
268 Standard_Integer bfuse (Draw_Interpretor& di, Standard_Integer n, const char** a)
270 return bsmt(di, n, a, BOPAlgo_FUSE);
272 //=======================================================================
275 //=======================================================================
276 Standard_Integer bcut (Draw_Interpretor& di, Standard_Integer n, const char** a)
278 return bsmt(di, n, a, BOPAlgo_CUT);
280 //=======================================================================
283 //=======================================================================
284 Standard_Integer btuc (Draw_Interpretor& di, Standard_Integer n, const char** a)
286 return bsmt(di, n, a, BOPAlgo_CUT21);
288 //=======================================================================
289 //function : bsection
291 //=======================================================================
292 Standard_Integer bsection(Draw_Interpretor& di,
296 const char* usage = " Usage: bsection Result s1 s2 [-n2d/-n2d1/-n2d2] [-na]\n";
302 TopoDS_Shape aS1 = DBRep::Get(a[2]);
303 TopoDS_Shape aS2 = DBRep::Get(a[3]);
305 if (aS1.IsNull() || aS2.IsNull()) {
306 di << " Null shapes are not allowed \n";
310 BOPAlgo_SectionAttribute aSec(Standard_True, Standard_True, Standard_True);
311 Standard_Boolean isbadparameter = Standard_False;
314 const char* key1 = a[4];
315 const char* key2 = (n > 5) ? a[5] : NULL;
316 const char* pcurveconf = NULL;
317 Standard_Boolean approx = Standard_True;
320 if (key1 && (!strcasecmp(key1,"-n2d") || !strcasecmp(key1,"-n2d1") || !strcasecmp(key1,"-n2d2"))) {
322 if (key1 && (!strncasecmp(key1,"-n2d", 4) || !strncasecmp(key1,"-n2d1", 5) || !strncasecmp(key1,"-n2d2", 5))) {
328 if (!strcasecmp(key1,"-na")) {
330 if(!strncasecmp(key1,"-na", 3)) {
332 approx = Standard_False;
335 isbadparameter = Standard_True;
340 if(!strcasecmp(key2,"-na")) {
342 if (!strncasecmp(key2,"-na", 3)) {
344 approx = Standard_False;
347 isbadparameter = Standard_True;
351 if(!isbadparameter && pcurveconf) {
353 if (!strcasecmp(pcurveconf, "-n2d1")) {
355 if (!strncasecmp(pcurveconf, "-n2d1", 5)) {
357 aSec.PCurveOnS1(Standard_False);
361 if (!strcasecmp(pcurveconf, "-n2d2")) {
363 if (!strncasecmp(pcurveconf, "-n2d2", 5)) {
365 aSec.PCurveOnS2(Standard_False);
369 if (!strcasecmp(pcurveconf, "-n2d")) {
371 if (!strncasecmp(pcurveconf, "-n2d", 4)) {
373 aSec.PCurveOnS1(Standard_False);
374 aSec.PCurveOnS2(Standard_False);
379 aSec.Approximation(approx);
382 if(!isbadparameter) {
383 BOPCol_ListOfShape aLC;
384 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
385 Standard_Integer iErr;
390 BOPAlgo_PaveFiller aPF(aAL);
391 aPF.SetArguments(aLC);
392 aPF.SetSectionAttribute(aSec);
395 iErr=aPF.ErrorStatus();
397 Sprintf(buf, " ErrorStatus : %d\n", iErr);
403 aBOP.AddArgument(aS1);
405 aBOP.SetOperation(BOPAlgo_SECTION);
407 aBOP.PerformWithFiller(aPF);
408 iErr=aBOP.ErrorStatus();
410 Sprintf(buf, " ErrorStatus : %d\n", iErr);
415 const TopoDS_Shape& aR=aBOP.Shape();
417 di << " null shape\n";
420 DBRep::Set(a[1], aR);
429 //=======================================================================
432 //=======================================================================
433 Standard_Integer bsmt (Draw_Interpretor& di,
436 const BOPAlgo_Operation aOp)
439 Standard_Integer iErr;
440 TopoDS_Shape aS1, aS2;
441 BOPCol_ListOfShape aLC;
443 if (aOp==BOPAlgo_SECTION) {
445 di << " use bsection r s1 s2\n";
451 di << " use bx r s1 s2\n";
455 aS1=DBRep::Get(a[2]);
456 aS2=DBRep::Get(a[3]);
458 if (aS1.IsNull() || aS2.IsNull()) {
459 di << " null shapes are not allowed \n";
466 Handle(NCollection_BaseAllocator)aAL=new NCollection_IncAllocator;
467 BOPAlgo_PaveFiller aPF(aAL);
469 aPF.SetArguments(aLC);
472 iErr=aPF.ErrorStatus();
474 Sprintf(buf, " ErrorStatus : %d\n", iErr);
481 aBOP.AddArgument(aS1);
483 aBOP.SetOperation(aOp);
485 aBOP.PerformWithFiller(aPF);
486 iErr=aBOP.ErrorStatus();
488 Sprintf(buf, " ErrorStatus : %d\n", iErr);
493 const TopoDS_Shape& aR=aBOP.Shape();
495 di << " null shape\n";
498 DBRep::Set(a[1], aR);
502 //=======================================================================
505 //=======================================================================
506 Standard_Integer bopnews (Draw_Interpretor& di,
511 di << " use bopnews -v[e,f]\n";
516 di << " Prepare BOPAlgo_PaveFiller first >bop S1 S2\n";
521 Standard_CString aText;
522 Standard_Integer i, i1, i2, iFound;
523 Draw_Color aTextColor(Draw_cyan);
525 Handle(BOPTest_DrawableShape) aDShape;
527 const BOPDS_PDS& pDS=pPF->PDS();
530 if (!strcmp (a[1], "-f")) {
533 else if (!strcmp (a[1], "-e")){
536 else if (!strcmp (a[1], "-v")){
540 di << " use bopnews -v[e,f]\n";
545 i1=pDS->NbSourceShapes();
547 for (i=i1; i<i2; ++i) {
548 const BOPDS_ShapeInfo& aSI=pDS->ShapeInfo(i);
549 if (aSI.ShapeType()==aT) {
550 const TopoDS_Shape& aS=aSI.Shape();
552 Sprintf (buf, "z%d", i);
554 aDShape=new BOPTest_DrawableShape (aS, aText, aTextColor);
555 Draw::Set (aText, aDShape);
557 Sprintf (buf, " z%d", i);
568 di << " not found\n";
574 //=======================================================================
575 //function : bopcurves
577 //=======================================================================
578 Standard_Integer bopcurves (Draw_Interpretor& di,
583 di << " use bopcurves F1 F2\n";
587 TopoDS_Shape S1 = DBRep::Get(a[1]);
588 TopoDS_Shape S2 = DBRep::Get(a[2]);
589 TopAbs_ShapeEnum aType;
591 if (S1.IsNull() || S2.IsNull()) {
592 di << " Null shapes is not allowed \n";
596 aType=S1.ShapeType();
597 if (aType != TopAbs_FACE) {
598 di << " Type mismatch F1\n";
601 aType=S2.ShapeType();
602 if (aType != TopAbs_FACE) {
603 di << " Type mismatch F2\n";
608 const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1);
609 const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2);
611 Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone;
612 Standard_Integer i, aNbCurves;
613 Standard_Real anAppTol, aTolR;
614 TCollection_AsciiString aNm("c_");
616 aToApproxC3d=Standard_True;
617 aToApproxC2dOnS1=Standard_False;
618 aToApproxC2dOnS2=Standard_False;
622 IntTools_FaceFace aFF;
624 aFF.SetParameters (aToApproxC3d,
629 aFF.Perform (aF1, aF2);
631 anIsDone=aFF.IsDone();
633 di << " anIsDone=" << (Standard_Integer) anIsDone << "\n";
637 aFF.PrepareLines3D();
638 const IntTools_SequenceOfCurves& aSCs=aFF.Lines();
641 aTolR=aFF.TolReached3d();
642 di << "Tolerance Reached=" << aTolR << "\n";
644 aNbCurves=aSCs.Length();
646 di << " has no 3d curve\n";
650 for (i=1; i<=aNbCurves; i++) {
651 const IntTools_Curve& anIC=aSCs(i);
653 Handle (Geom_Curve) aC3D=anIC.Curve();
656 di << " has Null 3d curve# " << i << "%d\n";
660 TCollection_AsciiString anIndx(i), aNmx;
662 Standard_CString name= aNmx.ToCString();
663 DrawTrSurf::Set(name, aC3D);