1 // Created on: 1994-12-13
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_Stream.hxx>
18 #include <Standard_Macro.hxx>
20 #include <BRepTest.hxx>
23 #include <Draw_Appli.hxx>
24 #include <Draw_Interpretor.hxx>
25 #include <Draw_Box.hxx>
27 #include <BRepBuilderAPI.hxx>
28 #include <BRepBuilderAPI_FindPlane.hxx>
29 #include <BRepBuilderAPI_Copy.hxx>
30 #include <BRepBuilderAPI_Transform.hxx>
31 #include <BRepBuilderAPI_GTransform.hxx>
32 #include <BRepBuilderAPI_NurbsConvert.hxx>
35 #include <gp_GTrsf.hxx>
36 #include <BRepOffsetAPI_NormalProjection.hxx>
37 #include <BRepLib.hxx>
38 #include <BRep_Builder.hxx>
39 #include <BRepBndLib.hxx>
40 #include <Bnd_Box.hxx>
41 #include <Bnd_Box2d.hxx>
42 #include <TopExp_Explorer.hxx>
44 #include <BRepTools_WireExplorer.hxx>
46 #include <GCPnts_QuasiUniformAbscissa.hxx>
47 #include <Geom2dAdaptor_Curve.hxx>
48 #include <GeomAdaptor_Curve.hxx>
49 #include <ProjLib_ComputeApproxOnPolarSurface.hxx>
50 #include <DrawTrSurf.hxx>
51 #include <Geom_Plane.hxx>
53 #include <OSD_Timer.hxx>
54 #include <Draw_Segment3D.hxx>
55 #include <Draw_Marker3D.hxx>
56 #include <Draw_MarkerShape.hxx>
57 #include <BRepPrimAPI_MakeBox.hxx>
60 Standard_IMPORT Draw_Viewer dout;
62 //=======================================================================
63 //function : ConvertBndToShape
64 //purpose : Creates TopoDS_Solid from theBox
65 //=======================================================================
66 static void ConvertBndToShape(const Bnd_OBB& theBox,
67 const char* const theName)
71 DBRep::Set (theName, TopoDS_Shape());
75 const gp_Pnt &aBaryCenter = theBox.Center();
76 const gp_XYZ &aXDir = theBox.XDirection(),
77 &aYDir = theBox.YDirection(),
78 &aZDir = theBox.ZDirection();
79 Standard_Real aHalfX = theBox.XHSize(),
80 aHalfY = theBox.YHSize(),
81 aHalfZ = theBox.ZHSize();
83 gp_Ax2 anAxes(aBaryCenter, aZDir, aXDir);
84 anAxes.SetLocation(aBaryCenter.XYZ() - aHalfX*aXDir - aHalfY*aYDir - aHalfZ*aZDir);
85 TopoDS_Solid aBox = BRepPrimAPI_MakeBox(anAxes, 2.0*aHalfX, 2.0*aHalfY, 2.0*aHalfZ);
86 DBRep::Set(theName, aBox);
89 //=======================================================================
91 //=======================================================================
93 static Standard_Integer addpcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
96 TopoDS_Shape E = DBRep::Get(a[1]);
97 if (E.IsNull()) return 1;
98 Handle(Geom2d_Curve) PC = DrawTrSurf::GetCurve2d(a[2]);
99 TopoDS_Shape F = DBRep::Get(a[3]);
100 Standard_Real tol = 1.e-7;
102 tol = Draw::Atof(a[4]);
105 BB.UpdateEdge(TopoDS::Edge(E), PC, TopoDS::Face(F),tol);
111 //=======================================================================
113 //=======================================================================
115 static Standard_Integer transform(Draw_Interpretor& ,Standard_Integer n,const char** a)
117 if (n <= 1) return 1;
120 Standard_Integer last = n;
121 const char* aName = a[0];
123 Standard_Boolean isBasic = Standard_False;
124 Standard_Boolean isCopy = Standard_False;
126 // Check "copy" flag.
127 if (!strcmp(a[n-1], "-copy")) {
128 isCopy = Standard_True;
132 if (!strcmp(aName,"reset")) {
135 isBasic = (aName[0] == 'b');
138 if (!strcmp(aName,"move")) {
140 TopoDS_Shape SL = DBRep::Get(a[n-1]);
141 if (SL.IsNull()) return 0;
142 T = SL.Location().Transformation();
145 else if (!strcmp(aName,"translate")) {
147 T.SetTranslation(gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1])));
150 else if (!strcmp(aName,"rotate")) {
152 T.SetRotation(gp_Ax1(gp_Pnt(Draw::Atof(a[n-7]),Draw::Atof(a[n-6]),Draw::Atof(a[n-5])),
153 gp_Vec(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2]))),
154 Draw::Atof(a[n-1])* (M_PI / 180.0));
157 else if (!strcmp(aName,"mirror")) {
159 T.SetMirror(gp_Ax2(gp_Pnt(Draw::Atof(a[n-6]),Draw::Atof(a[n-5]),Draw::Atof(a[n-4])),
160 gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1]))));
163 else if (!strcmp(aName,"scale")) {
165 T.SetScale(gp_Pnt(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2])),Draw::Atof(a[n-1]));
170 if (T.Form() == gp_Identity || isBasic) {
171 TopLoc_Location L(T);
172 for (Standard_Integer i = 1; i < last; i++) {
173 TopoDS_Shape S = DBRep::Get(a[i]);
176 std::cerr << "Error: " << a[i] << " is not a valid shape\n";
180 DBRep::Set(a[i],S.Located(L));
184 BRepBuilderAPI_Transform trf(T);
185 for (Standard_Integer i = 1; i < last; i++) {
186 TopoDS_Shape S = DBRep::Get(a[i]);
188 std::cerr << "Error: " << a[i] << " is not a valid shape\n";
192 trf.Perform(S, isCopy);
195 DBRep::Set(a[i],trf.Shape());
202 ///=======================================================================
204 //=======================================================================
206 static Standard_Integer deform(Draw_Interpretor& di,Standard_Integer n,const char** a)
208 if (n <= 1) return 1;
210 Standard_Integer last = n;
215 // gp_Mat rot(Draw::Atof(a[last-3]),0,0,0,Draw::Atof(a[last-2]),0,0,0,Draw::Atof(a[last-1]));
216 gp_Mat rot(Draw::Atof(a[3]),0,0,0,Draw::Atof(a[4]),0,0,0,Draw::Atof(a[5]));
217 GT.SetVectorialPart(rot);
219 BRepBuilderAPI_GTransform gtrf(GT);
220 BRepBuilderAPI_NurbsConvert nbscv;
221 // for (Standard_Integer i = 1; i < last; i++) {
222 // TopoDS_Shape S = DBRep::Get(a[i]);
223 TopoDS_Shape S = DBRep::Get(a[2]);
225 //std::cout << a[2] << " is not a valid shape" << std::endl;
226 di << a[2] << " is not a valid shape\n";
231 DBRep::Set(a[1],gtrf.Shape());
241 //=======================================================================
243 //=======================================================================
245 static Standard_Integer tcopy(Draw_Interpretor& di,Standard_Integer n,const char** a)
247 Standard_Boolean copyGeom = Standard_True;
248 Standard_Boolean copyMesh = Standard_False;
249 Standard_Integer iFirst = 1; // index of first shape argument
253 for (Standard_Integer i = 1; i <= 2; i++)
259 copyGeom = Standard_False;
262 else if (a[i][1] == 'm')
264 copyMesh = Standard_True;
270 if (n < 3 || (n - iFirst) % 2) {
271 std::cout << "Use: " << a[0] << " [-n(ogeom)] [-m(esh)] shape1 copy1 [shape2 copy2 [...]]" << std::endl;
272 std::cout << "Option -n forbids copying of geometry (it will be shared)" << std::endl;
273 std::cout << "Option -m forces copying of mesh (disabled by default)" << std::endl;
277 BRepBuilderAPI_Copy cop;
278 Standard_Integer nbPairs = (n - iFirst) / 2;
279 for (Standard_Integer i=0; i < nbPairs; i++) {
280 cop.Perform(DBRep::Get(a[i+iFirst]), copyGeom, copyMesh);
281 DBRep::Set(a[i+iFirst+1],cop.Shape());
282 di << a[i+iFirst+1] << " ";
288 //=======================================================================
290 //=======================================================================
292 static Standard_Integer nurbsconvert(Draw_Interpretor& di,Standard_Integer n,const char** a)
295 if ((n-1)%2 != 0) return 1;
296 BRepBuilderAPI_NurbsConvert nbscv;
297 for (Standard_Integer i=0; i<(n-1)/2; i++) {
298 TopoDS_Shape S = DBRep::Get(a[2*i+2]);
300 //std::cout << a[2*i+2] << " is not a valid shape" << std::endl;
301 di << a[2*i+2] << " is not a valid shape\n";
306 DBRep::Set(a[2*i+1],nbscv.Shape());
318 //=======================================================================
319 // make a 3D edge curve
320 //=======================================================================
322 static Standard_Integer mkedgecurve (Draw_Interpretor& ,Standard_Integer n,const char** a)
326 Standard_Real Tolerance = Draw::Atof(a[2]) ;
328 TopoDS_Shape S = DBRep::Get(a[1]);
330 if (S.IsNull()) return 1;
332 BRepLib::BuildCurves3d(S,
337 //=======================================================================
339 //=======================================================================
341 static Standard_Integer sameparameter(Draw_Interpretor& di,Standard_Integer n,const char** a)
345 di << "Use sameparameter [result] shape [toler]\n";
346 di << "shape is an initial shape\n";
347 di << "result is a result shape. if skipped = > initial shape will be modified\n";
348 di << "toler is tolerance (default is 1.e-7)";
351 Standard_Real aTol = 1.e-7;
352 Standard_Boolean force = !strcmp(a[0],"fsameparameter");
354 Standard_Real aTol1 = Draw::Atof(a[n-1]);
355 Standard_Boolean IsUseTol = aTol1>0;
359 TopoDS_Shape anInpS = DBRep::Get(IsUseTol ? a[n-2] : a[n-1]);
363 if ((n == 4 && IsUseTol) || (n == 3 && !IsUseTol))
365 TopoDS_Shape aResultSh;
366 BRepTools_ReShape aResh;
367 BRepLib::SameParameter(anInpS,aResh,aTol,force);
368 aResultSh = aResh.Apply(anInpS);
369 DBRep::Set(a[1],aResultSh);
373 BRepLib::SameParameter(anInpS,aTol,force);
374 DBRep::Set(a[1],anInpS);
379 //=======================================================================
380 //function : updatetol
382 //=======================================================================
383 static Standard_Integer updatetol(Draw_Interpretor& di,Standard_Integer n,const char** a)
387 di << "Use updatetololerance [result] shape [param]\n";
388 di << "shape is an initial shape\n";
389 di << "result is a result shape. if skipped = > initial shape will be modified\n";
390 di << "if [param] is absent - not verify of face tolerance, else - perform it";
393 TopoDS_Shape aSh1 = DBRep::Get(a[n-1]);
394 Standard_Boolean IsF = aSh1.IsNull();
396 TopoDS_Shape anInpS = IsF ? DBRep::Get(a[n-2]) : aSh1;
400 if ((n == 4 && IsF) || (n == 3 && !IsF))
402 TopoDS_Shape aResultSh;
403 BRepTools_ReShape aResh;
404 BRepLib::UpdateTolerances(anInpS,aResh, IsF);
405 aResultSh = aResh.Apply(anInpS);
406 DBRep::Set(a[1],aResultSh);
410 BRepLib::UpdateTolerances(anInpS, IsF);
411 DBRep::Set(a[1],anInpS);
417 //=======================================================================
418 //function : OrienSolid
420 //=======================================================================
421 static Standard_Integer orientsolid(Draw_Interpretor& ,Standard_Integer n,const char** a)
425 TopoDS_Shape S = DBRep::Get(a[1]);
426 if (S.IsNull()) return 1;
427 if (S.ShapeType()!=TopAbs_SOLID) return 1;
429 BRepLib::OrientClosedSolid(TopoDS::Solid(S));
436 //=======================================================================
437 //function : getcoords
439 //=======================================================================
440 static Standard_Integer getcoords(Draw_Interpretor& di,Standard_Integer n,const char** a)
445 for (Standard_Integer i = 1; i < n; i++)
447 const TopoDS_Shape aShape = DBRep::Get (a[i]);
452 if (aShape.ShapeType() == TopAbs_VERTEX)
454 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
455 gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
457 di << a[i] << " (x,y,z) : " << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z() << "\n";
464 //! Parse 6 real values for defining AABB.
465 static Standard_Boolean parseMinMax (const char** theArgVec, Bnd_Box& theBox)
467 const TCollection_AsciiString aMin[3] = { theArgVec[0], theArgVec[1], theArgVec[2] };
468 const TCollection_AsciiString aMax[3] = { theArgVec[3], theArgVec[4], theArgVec[5] };
469 if (!aMin[0].IsRealValue()
470 || !aMin[1].IsRealValue()
471 || !aMin[2].IsRealValue()
472 || !aMax[0].IsRealValue()
473 || !aMax[1].IsRealValue()
474 || !aMax[2].IsRealValue())
476 return Standard_False;
479 const gp_Pnt aPntMin (aMin[0].RealValue(), aMin[1].RealValue(), aMin[2].RealValue());
480 const gp_Pnt aPntMax (aMax[0].RealValue(), aMax[1].RealValue(), aMax[2].RealValue());
482 theBox.Add (aPntMin);
483 theBox.Add (aPntMax);
484 return Standard_True;
487 //=======================================================================
488 //function : BoundBox
490 //=======================================================================
491 static Standard_Integer BoundBox(Draw_Interpretor& theDI,
492 Standard_Integer theNArg,
493 const char** theArgVal)
495 // 1. Parse arguments
500 Standard_Boolean doPrint = Standard_False;
501 Standard_Boolean useOldSyntax = Standard_False;
502 Standard_Boolean isOBB = Standard_False;
503 Standard_Boolean isTriangulationReq = Standard_True;
504 Standard_Boolean isOptimal = Standard_False;
505 Standard_Boolean isTolerUsed = Standard_False;
506 Standard_Boolean isFinitePart = Standard_False;
507 Standard_Boolean hasToDraw = Standard_True;
509 TCollection_AsciiString anOutVars[6];
510 TCollection_AsciiString aResShapeName;
511 for (Standard_Integer anArgIter = 1; anArgIter < theNArg; ++anArgIter)
513 TCollection_AsciiString anArgCase (theArgVal[anArgIter]);
514 anArgCase.LowerCase();
515 if (anArgCase == "-obb")
517 isOBB = Standard_True;
519 else if (anArgCase == "-aabb")
521 isOBB = Standard_False;
523 else if (anArgCase == "-shape"
524 && anArgIter + 1 < theNArg
525 && aResShapeName.IsEmpty())
527 aResShapeName = theArgVal[++anArgIter];
528 hasToDraw = Standard_False;
530 else if (anArgCase == "-dump"
531 || anArgCase == "-print")
533 doPrint = Standard_True;
535 else if (anArgCase == "-save"
536 && anArgIter + 6 < theNArg
537 && anOutVars[0].IsEmpty())
539 for (int aCompIter = 0; aCompIter < 6; ++aCompIter)
541 anOutVars[aCompIter] = theArgVal[anArgIter + aCompIter + 1];
545 else if (anArgCase == "-notriangulation")
547 isTriangulationReq = Standard_False;
549 else if (anArgCase == "-optimal")
551 isOptimal = Standard_True;
553 else if (anArgCase == "-exttoler")
555 isTolerUsed = Standard_True;
557 else if (anArgCase == "-nodraw")
559 hasToDraw = Standard_False;
561 else if (anArgCase == "-finite"
562 || anArgCase == "-finitepart")
564 isFinitePart = Standard_True;
566 else if (aShape.IsNull()
567 && !DBRep::Get (theArgVal[anArgIter]).IsNull())
569 aShape = DBRep::Get (theArgVal[anArgIter]);
571 else if (anAABB.IsVoid()
572 && anArgIter + 5 < theNArg
573 && parseMinMax (theArgVal + anArgIter, anAABB))
579 std::cout << "Syntax error at argument '" << theArgVal[anArgIter] << "'.\n";
587 std::cout << "Syntax error: input is not specified (neither shape nor coordinates)\n";
590 else if (!anAABB.IsVoid()
591 && (isOBB || isOptimal || isTolerUsed))
593 std::cout << "Syntax error: Options -obb, -optimal and -extToler cannot be used for explicitly defined AABB.\n";
597 && !anOutVars[0].IsEmpty())
599 std::cout << "Error: Option -save works only with axes-aligned boxes.\n";
603 // enable printing (old syntax) if neither saving to shape nor to DRAW variables is requested
604 if (! doPrint && anOutVars[0].IsEmpty() && aResShapeName.IsEmpty())
606 doPrint = Standard_True;
607 useOldSyntax = Standard_True;
610 // 2. Compute box and save results
611 Handle(Draw_Box) aDB;
615 BRepBndLib::AddOBB(aShape, anOBB, isTriangulationReq, isOptimal, isTolerUsed);
619 theDI << "Void box.\n";
623 const gp_Pnt &aBaryCenter= anOBB.Center();
624 const gp_XYZ &aXDir = anOBB.XDirection(),
625 &aYDir = anOBB.YDirection(),
626 &aZDir = anOBB.ZDirection();
627 theDI << "Oriented bounding box\n";
628 theDI << "Center: " << aBaryCenter.X() << " " <<
629 aBaryCenter.Y() << " " <<
630 aBaryCenter.Z() << "\n";
631 theDI << "X-axis: " << aXDir.X() << " " << aXDir.Y() << " " << aXDir.Z() << "\n";
632 theDI << "Y-axis: " << aYDir.X() << " " << aYDir.Y() << " " << aYDir.Z() << "\n";
633 theDI << "Z-axis: " << aZDir.X() << " " << aZDir.Y() << " " << aZDir.Z() << "\n";
634 theDI << "Half X: " << anOBB.XHSize() << "\n"
635 << "Half Y: " << anOBB.YHSize() << "\n"
636 << "Half Z: " << anOBB.ZHSize() << "\n";
642 aDB = new Draw_Box (anOBB, Draw_orange);
645 if (!aResShapeName.IsEmpty())
647 ConvertBndToShape (anOBB, aResShapeName.ToCString());
652 if (!aShape.IsNull())
657 BRepBndLib::AddOptimal (aShape, anAABB, isTriangulationReq, isTolerUsed);
661 BRepBndLib::Add (aShape, anAABB, isTriangulationReq);
667 theDI << "Void box.\n";
671 if (isFinitePart && anAABB.IsOpen())
673 anAABB = anAABB.FinitePart();
675 const gp_Pnt aMin = anAABB.CornerMin();
676 const gp_Pnt aMax = anAABB.CornerMax();
683 theDI << aMin.X() << " " << aMin.Y() << " " << aMin.Z() << " "
684 << aMax.X() << " " << aMax.Y() << " " << aMax.Z() << "\n";
688 theDI << "Axes-aligned bounding box\n";
689 theDI << "X-range: " << aMin.X() << " " << aMax.X() << "\n"
690 << "Y-range: " << aMin.Y() << " " << aMax.Y() << "\n"
691 << "Z-range: " << aMin.Z() << " " << aMax.Z() << "\n";
693 && anAABB.HasFinitePart())
695 Bnd_Box aFinitAabb = anAABB.FinitePart();
696 const gp_Pnt aFinMin = aFinitAabb.CornerMin();
697 const gp_Pnt aFinMax = aFinitAabb.CornerMax();
698 theDI << "Finite part\n";
699 theDI << "X-range: " << aFinMin.X() << " " << aFinMax.X() << "\n"
700 << "Y-range: " << aFinMin.Y() << " " << aFinMax.Y() << "\n"
701 << "Z-range: " << aFinMin.Z() << " " << aFinMax.Z() << "\n";
706 // save DRAW variables
707 if (!anOutVars[0].IsEmpty())
709 Draw::Set (anOutVars[0].ToCString(), aMin.X());
710 Draw::Set (anOutVars[1].ToCString(), aMin.Y());
711 Draw::Set (anOutVars[2].ToCString(), aMin.Z());
712 Draw::Set (anOutVars[3].ToCString(), aMax.X());
713 Draw::Set (anOutVars[4].ToCString(), aMax.Y());
714 Draw::Set (anOutVars[5].ToCString(), aMax.Z());
717 // add presentation to DRAW viewer
720 aDB = new Draw_Box (anAABB, Draw_orange);
725 if (!aResShapeName.IsEmpty())
727 ConvertBndToShape (anAABB, aResShapeName.ToCString());
738 //=======================================================================
739 //function : IsBoxesInterfered
741 //=======================================================================
742 static Standard_Integer IsBoxesInterfered(Draw_Interpretor& theDI,
743 Standard_Integer theNArg,
744 const char** theArgVal)
748 theDI << "Use: isbbinterf shape1 shape2 [-o].\n";
752 const TopoDS_Shape aShape1 = DBRep::Get(theArgVal[1]);
753 const TopoDS_Shape aShape2 = DBRep::Get(theArgVal[2]);
755 Standard_Boolean isOBB = (theNArg > 3) && (!strcmp(theArgVal[3], "-o"));
759 Bnd_OBB anOBB1, anOBB2;
760 BRepBndLib::AddOBB(aShape1, anOBB1);
761 BRepBndLib::AddOBB(aShape2, anOBB2);
763 if(anOBB1.IsOut(anOBB2))
765 theDI << "The shapes are NOT interfered by OBB.\n";
769 theDI << "The shapes are interfered by OBB.\n";
774 Bnd_Box anAABB1, anAABB2;
775 BRepBndLib::Add(aShape1, anAABB1);
776 BRepBndLib::Add(aShape2, anAABB2);
778 if(anAABB1.IsOut(anAABB2))
780 theDI << "The shapes are NOT interfered by AABB.\n";
784 theDI << "The shapes are interfered by AABB.\n";
791 //=======================================================================
792 //function : gbounding
794 //=======================================================================
795 #include <GeomAdaptor_Surface.hxx>
796 #include <BndLib_AddSurface.hxx>
797 #include <BndLib_Add3dCurve.hxx>
798 #include <BndLib_Add2dCurve.hxx>
799 #include <Draw_Segment2D.hxx>
800 static Standard_Integer gbounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
802 if (n != 2 && n != 3)
804 di << "Usage: gbounding surf/curve/curve2d [-o] \n";
805 di << "[-o] turn on Optimal mode ('off' by default) \n";
810 Standard_Boolean IsOptimal = Standard_False;
811 if (n == 3 && !strcmp(a[2], "-o"))
812 IsOptimal = Standard_True;
814 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
818 Standard_Boolean Is3d = Standard_True;
819 Handle(Geom_Curve) C;
820 Handle(Geom_Surface) S;
821 Handle_Geom2d_Curve C2d;
822 S = DrawTrSurf::GetSurface(a[1]);
826 GeomAdaptor_Surface aGAS(S);
828 BndLib_AddSurface::AddOptimal(aGAS, Precision::Confusion(), B);
830 BndLib_AddSurface::Add(aGAS, Precision::Confusion(), B);
834 C = DrawTrSurf::GetCurve(a[1]);
838 GeomAdaptor_Curve aGAC(C);
840 BndLib_Add3dCurve::AddOptimal(aGAC, Precision::Confusion(), B);
842 BndLib_Add3dCurve::Add(aGAC, Precision::Confusion(), B);
846 C2d = DrawTrSurf::GetCurve2d(a[1]);
850 Is3d = Standard_False;
852 BndLib_Add2dCurve::AddOptimal(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d);
854 BndLib_Add2dCurve::Add(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d);
858 di << "Wrong argument \n";
866 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
867 DB = new Draw_Box(B, Draw_vert);
869 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
873 B2d.Get(axmin,aymin,axmax,aymax);
874 gp_Pnt2d p1(axmin, aymin);
875 gp_Pnt2d p2(axmax, aymin);
876 gp_Pnt2d p3(axmax, aymax);
877 gp_Pnt2d p4(axmin, aymax);
878 Draw_Segment2D* S1 = new Draw_Segment2D(p1, p2, Draw_vert);
879 Draw_Segment2D* S2 = new Draw_Segment2D(p2, p3, Draw_vert);
880 Draw_Segment2D* S3 = new Draw_Segment2D(p3, p4, Draw_vert);
881 Draw_Segment2D* S4 = new Draw_Segment2D(p4, p1, Draw_vert);
882 dout << S1 << S2 << S3 << S4;
883 di << axmin<<" "<< aymin<<" "<< axmax<<" "<< aymax;
889 //=======================================================================
890 //function : findplane
892 //=======================================================================
893 static Standard_Integer findplane(Draw_Interpretor& di,Standard_Integer n,const char** a)
896 TopoDS_Shape S = DBRep::Get(a[1]);
897 if (S.IsNull()) return 1;
898 Standard_Real tolerance = 1.0e-5 ;
899 BRepBuilderAPI_FindPlane a_plane_finder(S,
901 if (a_plane_finder.Found()) {
902 //std::cout << " a plane is found " ;
903 di << " a plane is found \n";
904 const Handle(Geom_Geometry)& aSurf = a_plane_finder.Plane(); // to avoid ambiguity
905 DrawTrSurf::Set(a[2],aSurf) ;
909 //=======================================================================
910 //function : precision
912 //=======================================================================
914 static Standard_Integer precision(Draw_Interpretor& di,Standard_Integer n,const char** a)
919 //std::cout << " Current Precision = " << BRepBuilderAPI::Precision() << std::endl;
920 di << " Current Precision = " << BRepBuilderAPI::Precision() << "\n";
923 BRepBuilderAPI::Precision(Draw::Atof(a[1]));
929 //=======================================================================
930 //function : reperage shape (Int lin Shape) + pointe double click + maxtol
932 //=======================================================================
933 #include <IntCurvesFace_ShapeIntersector.hxx>
934 #include <gp_Lin.hxx>
936 static Standard_Integer reperageshape(Draw_Interpretor& di, Standard_Integer narg , const char** a)
938 Standard_Integer details=0;
940 if(narg==3) details=1;
941 const char *id1 = a[1];
942 TopoDS_Shape TheShape1 = DBRep::Get(id1);
944 //std::cout << "Pick positions with button "<<std::endl;
945 di << "Pick positions with button \n";
946 Standard_Integer id,X,Y,b;
949 dout.Select(id,X,Y,b);
953 Standard_Real z = dout.Zoom(id);
954 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z, 0.0);
956 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,-1.0);
960 gp_Ax1 Axe(P1,gp_Vec(P1,P2));
961 IntCurvesFace_ShapeIntersector Inter;
962 Inter.Load(TheShape1,1e-7);
964 Inter.Perform(Axe,-RealLast(),RealLast());
966 //std::cout<<"\n --> ";
969 for(Standard_Integer i=1; i<=Inter.NbPnt(); i++) {
970 Standard_Integer numface=1;
972 for(ExF.Init(TheShape1,TopAbs_FACE);
974 ExF.Next(),numface++) {
975 TopoDS_Face Face=TopoDS::Face(ExF.Current());
976 if(Face.IsEqual(Inter.Face(i))) {
977 //std::cout<<" "<<a[1]<<"_"<<numface;
978 di<<" "<<a[1]<<"_"<<numface;
982 const gp_Pnt& P = Inter.Pnt(i);
983 Standard_Real PMin = Inter.WParameter(i);
985 //std::cout<<" w:"<<PMin<<std::endl;
986 di<<" w:"<<PMin<< "\n";
988 if(Inter.Transition(i) == IntCurveSurface_In) {
989 if(Inter.State(i) == TopAbs_IN) {
990 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_rouge,2);
991 dout << p; dout.Flush();
993 else if(Inter.State(i) == TopAbs_ON) {
994 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_vert,2);
995 dout << p; dout.Flush();
999 if(Inter.Transition(i) == IntCurveSurface_Out) {
1000 if(Inter.State(i) == TopAbs_IN) {
1001 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_rouge,2);
1002 dout << p; dout.Flush();
1004 else if(Inter.State(i) == TopAbs_ON) {
1005 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_vert,2);
1006 dout << p; dout.Flush();
1012 //std::cout<<std::endl;
1018 static Standard_Integer maxtolerance(Draw_Interpretor& theCommands,
1019 Standard_Integer n, const char** a) {
1021 TopoDS_Shape TheShape = DBRep::Get(a[1]);
1022 if(TheShape.IsNull()) return(1);
1024 Standard_Real T,TMF,TME,TMV,TmF,TmE,TmV;
1025 Standard_Integer nbF,nbE,nbV;
1026 TMF=TME=TMV=-RealLast();
1027 TmF=TmE=TmV=RealLast();
1029 TopTools_MapOfShape mapS;
1032 for(TopExp_Explorer ex(TheShape,TopAbs_FACE);
1035 TopoDS_Face Face=TopoDS::Face(ex.Current());
1036 T=BRep_Tool::Tolerance(Face);
1042 nbF = mapS.Extent();
1045 for(TopExp_Explorer ex(TheShape,TopAbs_EDGE);
1048 TopoDS_Edge Edge=TopoDS::Edge(ex.Current());
1049 T=BRep_Tool::Tolerance(Edge);
1055 nbE = mapS.Extent();
1058 for(TopExp_Explorer ex(TheShape,TopAbs_VERTEX);
1061 TopoDS_Vertex Vertex=TopoDS::Vertex(ex.Current());
1062 T=BRep_Tool::Tolerance(Vertex);
1068 nbV = mapS.Extent();
1070 Standard_SStream sss;
1071 sss << "\n## Tolerances on the shape " << a[1] << " (nbFaces:" << nbF
1072 << " nbEdges:" << nbE << " nbVtx:" << nbV << ")\n" ;
1074 sss.setf(std::ios::scientific);
1075 if(TmF<=TMF) sss << "\n Face : Min " << std::setw(8) << TmF <<" Max " << std::setw(8) << TMF << " \n ";
1076 if(TmE<=TME) sss << "\n Edge : Min " << std::setw(8) << TmE <<" Max " << std::setw(8) << TME << " \n ";
1077 if(TmV<=TMV) sss << "\n Vertex : Min " << std::setw(8) << TmV <<" Max " << std::setw(8) << TMV << " \n ";
1084 static Standard_Integer vecdc(Draw_Interpretor& di,Standard_Integer ,const char** ) {
1085 //std::cout << "Pick positions with button "<<std::endl;
1086 di << "Pick positions with button \n";
1088 Standard_Integer id,X,Y,b;
1090 gp_Pnt P1,P2,PP1,PP2;
1092 //-----------------------------------------------------------
1093 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
1095 Standard_Real z = dout.Zoom(id);
1096 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
1099 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
1100 T.Invert(); z = dout.Zoom(id);
1102 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
1104 Standard_Real xa,ya,za;
1105 if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X();
1106 if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y();
1107 if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z();
1108 P1.SetCoord(xa,ya,za);
1109 Handle(Draw_Marker3D) D0 = new Draw_Marker3D(gp_Pnt(P1.X(),
1112 Draw_Square,Draw_blanc,1);
1116 //-----------------------------------------------------------
1117 dout.Select(id,X,Y,b);
1121 PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
1123 dout.Select(id,X,Y,b);
1127 PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
1129 if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X();
1130 if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y();
1131 if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z();
1132 PP1.SetCoord(xa,ya,za);
1133 Handle(Draw_Segment3D) d = new Draw_Segment3D(P1,PP1,Draw_blanc);
1136 //std::cout<<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<std::endl;
1137 di <<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<< "\n";
1139 static Standard_Integer nboxvecdp=0;
1140 //std::cout<<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
1141 //std::cout<<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<<std::endl;
1143 //std::cout<<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
1144 // +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
1145 // +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<<std::endl;
1147 di <<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
1148 di <<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<< "\n";
1150 di <<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
1151 +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
1152 +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<< "\n";
1155 //=======================================================================
1157 //=======================================================================
1159 #include <TopTools_SequenceOfShape.hxx>
1160 static Standard_Integer nproject(Draw_Interpretor& di, Standard_Integer n, const char** a)
1162 if ( n < 4) return 1;
1163 TopoDS_Shape InpShape;
1164 Standard_Integer arg = 2, i;
1165 TopTools_SequenceOfShape Args;
1167 Standard_Real Tol = 1.e-4;
1168 Standard_Real Tol2d;
1169 Standard_Real MaxDistance = 1.e-3;
1170 GeomAbs_Shape Continuity = GeomAbs_C2;
1171 Standard_Integer MaxDeg = 14;
1172 Standard_Integer MaxSeg = 16;
1174 while((n > arg) && !(InpShape = DBRep::Get(a[arg])).IsNull()){
1175 Args.Append(InpShape);
1178 if(Args.Length() < 2) return 1;
1180 BRepOffsetAPI_NormalProjection OrtProj(Args.Last());
1182 for(i = 1; i < Args.Length(); i++)
1183 OrtProj.Add(Args(i));
1186 if (!strcmp(a[arg],"-g")) {
1187 OrtProj.SetLimit(Standard_False);
1192 if (!strcmp(a[arg],"-d")) {
1195 MaxDistance = Draw::Atof(a[arg++]);
1196 OrtProj.SetMaxDistance(MaxDistance);
1199 Tol = Max(Draw::Atof(a[arg++]),1.e-10);
1203 if (Draw::Atoi(a[arg]) == 0) Continuity = GeomAbs_C0;
1204 else if (Draw::Atoi(a[arg]) == 1) Continuity = GeomAbs_C1;
1210 MaxDeg = Draw::Atoi(a[arg++]);
1211 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
1214 if(n > arg) MaxSeg = Draw::Atoi(a[arg]);
1216 Tol2d = Pow(Tol, 2./3);
1218 OrtProj.SetParams(Tol, Tol2d, Continuity, MaxDeg, MaxSeg);
1220 TopTools_ListOfShape Wire;
1221 Standard_Boolean IsWire=OrtProj.BuildWire(Wire);
1223 //std::cout << " BuildWire OK " << std::endl;
1224 di << " BuildWire OK \n";
1226 DBRep::Set(a[1], OrtProj.Shape());
1230 //==========================================================================
1232 // exploration of a wire
1233 //==========================================================================
1234 static Standard_Integer wexplo (Draw_Interpretor&,
1235 Standard_Integer argc, const char** argv)
1238 if (argc < 2) return 1;
1240 TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_WIRE);
1243 if (argc > 2) C2 = DBRep::Get (argv[2],TopAbs_FACE);
1245 if (C1.IsNull()) return 1;
1247 BRepTools_WireExplorer we;
1248 if (C2.IsNull()) we.Init(TopoDS::Wire(C1));
1249 else we.Init(TopoDS::Wire(C1),TopoDS::Face(C2));
1251 Standard_Integer k = 1;
1253 TopoDS_Edge E = we.Current();
1254 Sprintf(name,"WEDGE_%d",k);
1263 static Standard_Integer scalexyz(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
1265 if (n < 6) return 1;
1267 TopoDS_Shape aShapeBase = DBRep::Get(a[2]);
1268 if (aShapeBase.IsNull()) return 1;
1270 Standard_Real aFactorX = Draw::Atof(a[3]);
1271 Standard_Real aFactorY = Draw::Atof(a[4]);
1272 Standard_Real aFactorZ = Draw::Atof(a[5]);
1275 gp_Mat rot (aFactorX, 0, 0,
1278 aGTrsf.SetVectorialPart(rot);
1279 BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False);
1280 if (!aBRepGTrsf.IsDone())
1281 throw Standard_ConstructionError("Scaling not done");
1282 TopoDS_Shape Result = aBRepGTrsf.Shape();
1284 DBRep::Set(a[1], Result);
1288 //=======================================================================
1289 //function : compareshapes
1291 //=======================================================================
1292 static Standard_Integer compareshapes(Draw_Interpretor& di,
1297 di << "Compare shapes. Usage: compare shape1 shape2\n";
1301 TopoDS_Shape aS1 = DBRep::Get(a[1]);
1302 TopoDS_Shape aS2 = DBRep::Get(a[2]);
1304 if (aS1.IsNull() || aS2.IsNull()) {
1305 di << "null shapes\n";
1309 if (aS1.IsSame(aS2)) {
1310 di << "same shapes\n";
1311 if (aS1.IsEqual(aS2)) {
1312 di << "equal shapes\n";
1316 di << "shapes are not same\n";
1321 //=======================================================================
1322 //function : issubshape
1324 //=======================================================================
1325 static Standard_Integer issubshape(Draw_Interpretor& di,
1330 di << "Check if the shape is sub-shape of other shape and get its index in the shape.\n";
1331 di << "Usage: issubshape subshape shape\n";
1335 TopoDS_Shape aSubShape = DBRep::Get(a[1]);
1336 TopoDS_Shape aShape = DBRep::Get(a[2]);
1338 if (aSubShape.IsNull() || aShape.IsNull()) {
1339 di << "null shapes\n";
1342 // find index of the sub-shape in the shape
1343 TopTools_MapOfShape aMShapes;
1344 // try to find the SubShape in Shape
1345 TopExp_Explorer anExp(aShape, aSubShape.ShapeType());
1346 for (; anExp.More(); anExp.Next()) {
1347 const TopoDS_Shape& aSS = anExp.Current();
1348 if (aMShapes.Add(aSS)) {
1349 if (aSS.IsSame(aSubShape)) {
1356 di << a[1] << " is sub-shape of " << a[2] << ". Index in the shape: " << aMShapes.Extent() << ".\n";
1359 di << a[1] << " is NOT sub-shape of " << a[2] << ".\n";
1365 void BRepTest::BasicCommands(Draw_Interpretor& theCommands)
1367 static Standard_Boolean done = Standard_False;
1369 done = Standard_True;
1371 DBRep::BasicCommands(theCommands);
1373 const char* g = "TOPOLOGY Basic shape commands";
1375 theCommands.Add("addpcurve",
1376 "addpcurve edge 2dcurve face [tol (default 1.e-7)]",
1380 theCommands.Add("reset",
1381 "reset name1 name2 ..., remove location",
1385 theCommands.Add("tmove",
1386 "tmove name1 name2 ... name, set location from name [-copy]",
1390 theCommands.Add("ttranslate",
1391 "ttranslate name1 name2 ... dx dy dz [-copy]",
1395 theCommands.Add("trotate",
1396 "trotate name1 name2 ... x y z dx dy dz angle [-copy]",
1400 theCommands.Add("tmirror",
1401 "tmirror name x y z dx dy dz [-copy]",
1405 theCommands.Add("tscale",
1406 "tscale name x y z scale [-copy]",
1410 theCommands.Add("tcopy",
1411 "tcopy [-n(ogeom)] [-m(esh)] name1 result1 [name2 result2 ...]",
1415 theCommands.Add("bmove",
1416 "bmove name1 name2 ... name, set location from name",
1420 theCommands.Add("btranslate",
1421 "btranslate name1 name2 ... dx dy dz",
1425 theCommands.Add("brotate",
1426 "brotate name1 name2 ... x y z dx dy dz angle",
1430 theCommands.Add("bmirror",
1431 "bmirror name x y z dx dy dz",
1435 theCommands.Add("bscale",
1436 "bscale name x y z scale",
1440 theCommands.Add("precision",
1441 "precision [preci]",
1445 theCommands.Add("mkedgecurve",
1446 "mkedgecurve name tolerance",
1450 theCommands.Add("fsameparameter",
1451 "fsameparameter shapename [tol (default 1.e-7)], \nforce sameparameter on all edges of the shape",
1455 theCommands.Add("sameparameter",
1456 "sameparameter [result] shape [tol]",
1460 theCommands.Add("updatetolerance",
1461 "updatetolerance [result] shape [param] \n if [param] is absent - not verify of face tolerance, else - perform it",
1465 theCommands.Add("solidorientation",
1466 "orientsolid myClosedSolid",
1470 theCommands.Add("getcoords",
1471 "getcoords vertex1 vertex 2... ; shows coords of input vertices",
1475 theCommands.Add ("bounding",
1476 "bounding {shape | xmin ymin zmin xmax ymax zmax}"
1477 "\n\t\t: [-obb] [-noTriangulation] [-optimal] [-extToler]"
1478 "\n\t\t: [-dump] [-shape name] [-nodraw] [-finitePart]"
1479 "\n\t\t: [-save xmin ymin zmin xmax ymax zmax]"
1481 "\n\t\t: Computes a bounding box. Two types of the source data are supported:"
1482 "\n\t\t: a shape or AABB corners (xmin, ymin, zmin, xmax, ymax, zmax)."
1484 "\n\t\t: Calculation options (applicable only if input is a shape):"
1485 "\n\t\t: -obb Compute Oriented Bounding Box (OBB) instead of AABB."
1486 "\n\t\t: -noTriangulation Force use of exact geometry for calculation"
1487 "\n\t\t: even if triangulation is present."
1488 "\n\t\t: -optimal Force calculation of optimal (more tight) AABB."
1489 "\n\t\t: In case of OBB:"
1490 "\n\t\t: - for PCA approach applies to initial AABB used in OBB calculation"
1491 "\n\t\t: - for DiTo approach modifies the DiTo algorithm to check more axes."
1492 "\n\t\t: -extToler Include tolerance of the shape in the resulting box."
1494 "\n\t\t: Output options:"
1495 "\n\t\t: -dump Prints the information about computed Bounding Box."
1496 "\n\t\t: It is enabled by default (with plain old syntax for AABB)"
1497 "\n\t\t: if neither -shape nor -save is specified."
1498 "\n\t\t: -shape Stores computed box as solid in DRAW variable with specified name."
1499 "\n\t\t: -save Stores min and max coordinates of AABB in specified variables."
1500 "\n\t\t: -noDraw Avoid drawing resulting Bounding Box in DRAW viewer."
1501 "\n\t\t: -finite Return finite part of infinite box.",
1502 __FILE__, BoundBox, g);
1505 theCommands.Add("gbounding",
1506 "gbounding surf/curve/curve2d [-o] ",
1510 theCommands.Add("isbbinterf", "isbbinterf shape1 shape2 [-o]\n"
1511 "Checks whether the bounding-boxes created from "
1512 "the given shapes are interfered. If \"-o\"-option "
1513 "is switched on then the oriented boxes will be checked. "
1514 "Otherwise, axes-aligned boxes will be checked.",
1515 __FILE__, IsBoxesInterfered, g);
1517 theCommands.Add("nurbsconvert",
1518 "nurbsconvert result name [result name]",
1522 theCommands.Add("deform",
1523 "deform newname name CoeffX CoeffY CoeffZ",
1527 theCommands.Add("findplane",
1528 "findplane name planename ",
1532 theCommands.Add("maxtolerance",
1533 "maxtolerance shape ",
1537 theCommands.Add("reperageshape",
1538 "reperage shape -> list of shape (result of interstion shape , line)",
1542 theCommands.Add("vecdc",
1543 "vecdc + Pointe double click ",
1547 theCommands.Add("nproject","nproject pj e1 e2 e3 ... surf -g -d [dmax] [Tol [continuity [maxdeg [maxseg]]]",
1551 theCommands.Add("wexplo","wexplo wire [face] create WEDGE_i",
1555 theCommands.Add("scalexyz",
1556 "scalexyz res shape factor_x factor_y factor_z",
1560 theCommands.Add("compare",
1561 "Compare shapes. Usage: compare shape1 shape2",
1565 theCommands.Add("issubshape",
1566 "issubshape subshape shape\n"
1567 "\t\tCheck if the shape is sub-shape of other shape and get its index in the shape.",