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 <Draw_Segment3D.hxx>
54 #include <Draw_Marker3D.hxx>
55 #include <Draw_MarkerShape.hxx>
59 Standard_IMPORT Draw_Viewer dout;
63 //=======================================================================
65 //=======================================================================
67 static Standard_Integer addpcurve(Draw_Interpretor& , Standard_Integer n, const char** a)
70 TopoDS_Shape E = DBRep::Get(a[1]);
71 if (E.IsNull()) return 1;
72 Handle(Geom2d_Curve) PC = DrawTrSurf::GetCurve2d(a[2]);
73 TopoDS_Shape F = DBRep::Get(a[3]);
74 Standard_Real tol = 1.e-7;
76 tol = Draw::Atof(a[4]);
79 BB.UpdateEdge(TopoDS::Edge(E), PC, TopoDS::Face(F),tol);
85 //=======================================================================
87 //=======================================================================
89 static Standard_Integer transform(Draw_Interpretor& ,Standard_Integer n,const char** a)
94 Standard_Integer last = n;
95 const char* aName = a[0];
97 Standard_Boolean isBasic = Standard_False;
99 if (!strcmp(aName,"reset")) {
102 isBasic = (aName[0] == 'b');
105 if (!strcmp(aName,"move")) {
107 TopoDS_Shape SL = DBRep::Get(a[n-1]);
108 if (SL.IsNull()) return 0;
109 T = SL.Location().Transformation();
112 else if (!strcmp(aName,"translate")) {
114 T.SetTranslation(gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1])));
117 else if (!strcmp(aName,"rotate")) {
119 T.SetRotation(gp_Ax1(gp_Pnt(Draw::Atof(a[n-7]),Draw::Atof(a[n-6]),Draw::Atof(a[n-5])),
120 gp_Vec(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2]))),
121 Draw::Atof(a[n-1])* (M_PI / 180.0));
124 else if (!strcmp(aName,"mirror")) {
126 T.SetMirror(gp_Ax2(gp_Pnt(Draw::Atof(a[n-6]),Draw::Atof(a[n-5]),Draw::Atof(a[n-4])),
127 gp_Vec(Draw::Atof(a[n-3]),Draw::Atof(a[n-2]),Draw::Atof(a[n-1]))));
130 else if (!strcmp(aName,"scale")) {
132 T.SetScale(gp_Pnt(Draw::Atof(a[n-4]),Draw::Atof(a[n-3]),Draw::Atof(a[n-2])),Draw::Atof(a[n-1]));
137 if (T.Form() == gp_Identity || isBasic) {
138 TopLoc_Location L(T);
139 for (Standard_Integer i = 1; i < last; i++) {
140 TopoDS_Shape S = DBRep::Get(a[i]);
143 std::cerr << "Error: " << a[i] << " is not a valid shape\n";
147 DBRep::Set(a[i],S.Located(L));
151 BRepBuilderAPI_Transform trf(T);
152 for (Standard_Integer i = 1; i < last; i++) {
153 TopoDS_Shape S = DBRep::Get(a[i]);
155 std::cerr << "Error: " << a[i] << " is not a valid shape\n";
162 DBRep::Set(a[i],trf.Shape());
169 ///=======================================================================
171 //=======================================================================
173 static Standard_Integer deform(Draw_Interpretor& di,Standard_Integer n,const char** a)
175 if (n <= 1) return 1;
177 Standard_Integer last = n;
182 // gp_Mat rot(Draw::Atof(a[last-3]),0,0,0,Draw::Atof(a[last-2]),0,0,0,Draw::Atof(a[last-1]));
183 gp_Mat rot(Draw::Atof(a[3]),0,0,0,Draw::Atof(a[4]),0,0,0,Draw::Atof(a[5]));
184 GT.SetVectorialPart(rot);
186 BRepBuilderAPI_GTransform gtrf(GT);
187 BRepBuilderAPI_NurbsConvert nbscv;
188 // for (Standard_Integer i = 1; i < last; i++) {
189 // TopoDS_Shape S = DBRep::Get(a[i]);
190 TopoDS_Shape S = DBRep::Get(a[2]);
192 //cout << a[2] << " is not a valid shape" << endl;
193 di << a[2] << " is not a valid shape\n";
198 DBRep::Set(a[1],gtrf.Shape());
208 //=======================================================================
210 //=======================================================================
212 static Standard_Integer tcopy(Draw_Interpretor& di,Standard_Integer n,const char** a)
214 Standard_Boolean copyGeom = Standard_True;
215 Standard_Boolean copyMesh = Standard_False;
216 Standard_Integer iFirst = 1; // index of first shape argument
220 for (Standard_Integer i = 1; i <= 2; i++)
226 copyGeom = Standard_False;
229 else if (a[i][1] == 'm')
231 copyMesh = Standard_True;
237 if (n < 3 || (n - iFirst) % 2) {
238 cout << "Use: " << a[0] << " [-n(ogeom)] [-m(esh)] shape1 copy1 [shape2 copy2 [...]]" << endl;
239 cout << "Option -n forbids copying of geometry (it will be shared)" << endl;
240 cout << "Option -m forces copying of mesh (disabled by default)" << endl;
244 BRepBuilderAPI_Copy cop;
245 Standard_Integer nbPairs = (n - iFirst) / 2;
246 for (Standard_Integer i=0; i < nbPairs; i++) {
247 cop.Perform(DBRep::Get(a[i+iFirst]), copyGeom, copyMesh);
248 DBRep::Set(a[i+iFirst+1],cop.Shape());
249 di << a[i+iFirst+1] << " ";
255 //=======================================================================
257 //=======================================================================
259 static Standard_Integer nurbsconvert(Draw_Interpretor& di,Standard_Integer n,const char** a)
262 if ((n-1)%2 != 0) return 1;
263 BRepBuilderAPI_NurbsConvert nbscv;
264 for (Standard_Integer i=0; i<(n-1)/2; i++) {
265 TopoDS_Shape S = DBRep::Get(a[2*i+2]);
267 //cout << a[2*i+2] << " is not a valid shape" << endl;
268 di << a[2*i+2] << " is not a valid shape\n";
273 DBRep::Set(a[2*i+1],nbscv.Shape());
285 //=======================================================================
286 // make a 3D edge curve
287 //=======================================================================
289 static Standard_Integer mkedgecurve (Draw_Interpretor& ,Standard_Integer n,const char** a)
293 Standard_Real Tolerance = Draw::Atof(a[2]) ;
295 TopoDS_Shape S = DBRep::Get(a[1]);
297 if (S.IsNull()) return 1;
299 BRepLib::BuildCurves3d(S,
304 //=======================================================================
306 //=======================================================================
308 static Standard_Integer sameparameter(Draw_Interpretor& di,Standard_Integer n,const char** a)
312 di << "Use sameparameter [result] shape [toler]\n";
313 di << "shape is an initial shape\n";
314 di << "result is a result shape. if skipped = > initial shape will be modified\n";
315 di << "toler is tolerance (default is 1.e-7)";
318 Standard_Real aTol = 1.e-7;
319 Standard_Boolean force = !strcmp(a[0],"fsameparameter");
321 Standard_Real aTol1 = Draw::Atof(a[n-1]);
322 Standard_Boolean IsUseTol = aTol1>0;
326 TopoDS_Shape anInpS = DBRep::Get(IsUseTol ? a[n-2] : a[n-1]);
330 if ((n == 4 && IsUseTol) || (n == 3 && !IsUseTol))
332 TopoDS_Shape aResultSh;
333 BRepTools_ReShape aResh;
334 BRepLib::SameParameter(anInpS,aResh,aTol,force);
335 aResultSh = aResh.Apply(anInpS);
336 DBRep::Set(a[1],aResultSh);
340 BRepLib::SameParameter(anInpS,aTol,force);
341 DBRep::Set(a[1],anInpS);
346 //=======================================================================
347 //function : updatetol
349 //=======================================================================
350 static Standard_Integer updatetol(Draw_Interpretor& di,Standard_Integer n,const char** a)
354 di << "Use updatetololerance [result] shape [param]\n";
355 di << "shape is an initial shape\n";
356 di << "result is a result shape. if skipped = > initial shape will be modified\n";
357 di << "if [param] is absent - not verify of face tolerance, else - perform it";
360 TopoDS_Shape aSh1 = DBRep::Get(a[n-1]);
361 Standard_Boolean IsF = aSh1.IsNull();
363 TopoDS_Shape anInpS = IsF ? DBRep::Get(a[n-2]) : aSh1;
367 if ((n == 4 && IsF) || (n == 3 && !IsF))
369 TopoDS_Shape aResultSh;
370 BRepTools_ReShape aResh;
371 BRepLib::UpdateTolerances(anInpS,aResh, IsF);
372 aResultSh = aResh.Apply(anInpS);
373 DBRep::Set(a[1],aResultSh);
377 BRepLib::UpdateTolerances(anInpS, IsF);
378 DBRep::Set(a[1],anInpS);
384 //=======================================================================
385 //function : OrienSolid
387 //=======================================================================
388 static Standard_Integer orientsolid(Draw_Interpretor& ,Standard_Integer n,const char** a)
392 TopoDS_Shape S = DBRep::Get(a[1]);
393 if (S.IsNull()) return 1;
394 if (S.ShapeType()!=TopAbs_SOLID) return 1;
396 BRepLib::OrientClosedSolid(TopoDS::Solid(S));
403 //=======================================================================
404 //function : boundingstr
406 //=======================================================================
407 static Standard_Integer boundingstr(Draw_Interpretor& di,Standard_Integer n,const char** a)
410 TopoDS_Shape S = DBRep::Get(a[1]);
411 if (S.IsNull()) return 1;
413 BRepBndLib::Add(S,B);
414 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
415 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
416 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
418 Draw::Set(a[2],axmin) ;
419 Draw::Set(a[3],aymin) ;
420 Draw::Set(a[4],azmin) ;
421 Draw::Set(a[5],axmax) ;
422 Draw::Set(a[6],aymax) ;
423 Draw::Set(a[7],azmax) ;
428 //=======================================================================
429 //function : getcoords
431 //=======================================================================
432 static Standard_Integer getcoords(Draw_Interpretor& di,Standard_Integer n,const char** a)
437 for (Standard_Integer i = 1; i < n; i++)
439 const TopoDS_Shape aShape = DBRep::Get (a[i]);
444 if (aShape.ShapeType() == TopAbs_VERTEX)
446 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
447 gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
449 di << a[i] << " (x,y,z) : " << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z() << "\n";
456 //=======================================================================
457 //function : bounding
459 //=======================================================================
460 static Standard_Integer bounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
463 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
464 Bnd_Box B; Handle(Draw_Box) DB;
467 TopoDS_Shape S = DBRep::Get(a[1]);
468 if (S.IsNull()) return 1;
469 BRepBndLib::Add(S,B);
470 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
471 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange);
473 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
476 axmin=Draw::Atof(a[1]);
477 aymin=Draw::Atof(a[2]);
478 azmin=Draw::Atof(a[3]);
479 axmax=Draw::Atof(a[4]);
480 aymax=Draw::Atof(a[5]);
481 azmax=Draw::Atof(a[6]);
482 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange);
487 //=======================================================================
488 //function : optbounding
490 //=======================================================================
491 static Standard_Integer optbounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
495 di << "Usage: optbounding shape [usetri [usetol]]\n";
496 di << "usetri and usetol can be 0 or 1, by default usetri = 1, usetol = 0\n";
499 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
500 Bnd_Box B; Handle(Draw_Box) DB;
502 TopoDS_Shape S = DBRep::Get(a[1]);
505 di << "Null shape\n";
508 Standard_Boolean useTri = Standard_True;
509 Standard_Boolean useTol = Standard_False;
512 Standard_Integer ii = atoi(a[2]);
517 Standard_Integer ii = atoi(a[3]);
520 BRepBndLib::AddOptimal(S, B, useTri, useTol);
521 B.Get(axmin, aymin, azmin, axmax, aymax, azmax);
522 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_vert);
524 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
527 //=======================================================================
528 //function : gbounding
530 //=======================================================================
531 #include <GeomAdaptor_Surface.hxx>
532 #include <BndLib_AddSurface.hxx>
533 #include <BndLib_Add3dCurve.hxx>
534 #include <BndLib_Add2dCurve.hxx>
535 #include <Draw_Segment2D.hxx>
536 static Standard_Integer gbounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
538 if (n != 2 && n != 3)
540 di << "Usage: gbounding surf/curve/curve2d [-o] \n";
541 di << "[-o] turn on Optimal mode ('off' by default) \n";
546 Standard_Boolean IsOptimal = Standard_False;
547 if (n == 3 && !strcmp(a[2], "-o"))
548 IsOptimal = Standard_True;
550 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
554 Standard_Boolean Is3d = Standard_True;
555 Handle(Geom_Curve) C;
556 Handle(Geom_Surface) S;
557 Handle_Geom2d_Curve C2d;
558 S = DrawTrSurf::GetSurface(a[1]);
562 GeomAdaptor_Surface aGAS(S);
564 BndLib_AddSurface::AddOptimal(aGAS, Precision::Confusion(), B);
566 BndLib_AddSurface::Add(aGAS, Precision::Confusion(), B);
570 C = DrawTrSurf::GetCurve(a[1]);
574 GeomAdaptor_Curve aGAC(C);
576 BndLib_Add3dCurve::AddOptimal(aGAC, Precision::Confusion(), B);
578 BndLib_Add3dCurve::Add(aGAC, Precision::Confusion(), B);
582 C2d = DrawTrSurf::GetCurve2d(a[1]);
586 Is3d = Standard_False;
588 BndLib_Add2dCurve::AddOptimal(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d);
590 BndLib_Add2dCurve::Add(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d);
594 di << "Wrong argument \n";
602 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
603 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_vert);
605 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
609 B2d.Get(axmin,aymin,axmax,aymax);
610 gp_Pnt2d p1(axmin, aymin);
611 gp_Pnt2d p2(axmax, aymin);
612 gp_Pnt2d p3(axmax, aymax);
613 gp_Pnt2d p4(axmin, aymax);
614 Draw_Segment2D* S1 = new Draw_Segment2D(p1, p2, Draw_vert);
615 Draw_Segment2D* S2 = new Draw_Segment2D(p2, p3, Draw_vert);
616 Draw_Segment2D* S3 = new Draw_Segment2D(p3, p4, Draw_vert);
617 Draw_Segment2D* S4 = new Draw_Segment2D(p4, p1, Draw_vert);
618 dout << S1 << S2 << S3 << S4;
619 di << axmin<<" "<< aymin<<" "<< axmax<<" "<< aymax;
625 //=======================================================================
626 //function : findplane
628 //=======================================================================
629 static Standard_Integer findplane(Draw_Interpretor& di,Standard_Integer n,const char** a)
632 TopoDS_Shape S = DBRep::Get(a[1]);
633 if (S.IsNull()) return 1;
634 Standard_Real tolerance = 1.0e-5 ;
635 BRepBuilderAPI_FindPlane a_plane_finder(S,
637 if (a_plane_finder.Found()) {
638 //cout << " a plane is found " ;
639 di << " a plane is found \n";
640 const Handle(Geom_Geometry)& aSurf = a_plane_finder.Plane(); // to avoid ambiguity
641 DrawTrSurf::Set(a[2],aSurf) ;
645 //=======================================================================
646 //function : precision
648 //=======================================================================
650 static Standard_Integer precision(Draw_Interpretor& di,Standard_Integer n,const char** a)
655 //cout << " Current Precision = " << BRepBuilderAPI::Precision() << endl;
656 di << " Current Precision = " << BRepBuilderAPI::Precision() << "\n";
659 BRepBuilderAPI::Precision(Draw::Atof(a[1]));
665 //=======================================================================
666 //function : reperage shape (Int lin Shape) + pointe double click + maxtol
668 //=======================================================================
669 #include <IntCurvesFace_ShapeIntersector.hxx>
670 #include <gp_Lin.hxx>
672 static Standard_Integer reperageshape(Draw_Interpretor& di, Standard_Integer narg , const char** a)
674 Standard_Integer details=0;
676 if(narg==3) details=1;
677 const char *id1 = a[1];
678 TopoDS_Shape TheShape1 = DBRep::Get(id1);
680 //cout << "Pick positions with button "<<endl;
681 di << "Pick positions with button \n";
682 Standard_Integer id,X,Y,b;
685 dout.Select(id,X,Y,b);
689 Standard_Real z = dout.Zoom(id);
690 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z, 0.0);
692 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,-1.0);
696 gp_Ax1 Axe(P1,gp_Vec(P1,P2));
697 IntCurvesFace_ShapeIntersector Inter;
698 Inter.Load(TheShape1,1e-7);
700 Inter.Perform(Axe,-RealLast(),RealLast());
705 for(Standard_Integer i=1; i<=Inter.NbPnt(); i++) {
706 Standard_Integer numface=1;
708 for(ExF.Init(TheShape1,TopAbs_FACE);
710 ExF.Next(),numface++) {
711 TopoDS_Face Face=TopoDS::Face(ExF.Current());
712 if(Face.IsEqual(Inter.Face(i))) {
713 //cout<<" "<<a[1]<<"_"<<numface;
714 di<<" "<<a[1]<<"_"<<numface;
718 const gp_Pnt& P = Inter.Pnt(i);
719 Standard_Real PMin = Inter.WParameter(i);
721 //cout<<" w:"<<PMin<<endl;
722 di<<" w:"<<PMin<< "\n";
724 if(Inter.Transition(i) == IntCurveSurface_In) {
725 if(Inter.State(i) == TopAbs_IN) {
726 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_rouge,2);
727 dout << p; dout.Flush();
729 else if(Inter.State(i) == TopAbs_ON) {
730 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_vert,2);
731 dout << p; dout.Flush();
735 if(Inter.Transition(i) == IntCurveSurface_Out) {
736 if(Inter.State(i) == TopAbs_IN) {
737 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_rouge,2);
738 dout << p; dout.Flush();
740 else if(Inter.State(i) == TopAbs_ON) {
741 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_vert,2);
742 dout << p; dout.Flush();
754 static Standard_Integer maxtolerance(Draw_Interpretor& theCommands,
755 Standard_Integer n, const char** a) {
757 TopoDS_Shape TheShape = DBRep::Get(a[1]);
758 if(TheShape.IsNull()) return(1);
760 Standard_Real T,TMF,TME,TMV,TmF,TmE,TmV;
761 Standard_Integer nbF,nbE,nbV;
762 TMF=TME=TMV=-RealLast();
763 TmF=TmE=TmV=RealLast();
765 TopTools_MapOfShape mapS;
768 for(TopExp_Explorer ex(TheShape,TopAbs_FACE);
771 TopoDS_Face Face=TopoDS::Face(ex.Current());
772 T=BRep_Tool::Tolerance(Face);
781 for(TopExp_Explorer ex(TheShape,TopAbs_EDGE);
784 TopoDS_Edge Edge=TopoDS::Edge(ex.Current());
785 T=BRep_Tool::Tolerance(Edge);
794 for(TopExp_Explorer ex(TheShape,TopAbs_VERTEX);
797 TopoDS_Vertex Vertex=TopoDS::Vertex(ex.Current());
798 T=BRep_Tool::Tolerance(Vertex);
806 Standard_SStream sss;
807 sss << "\n## Tolerances on the shape " << a[1] << " (nbFaces:" << nbF
808 << " nbEdges:" << nbE << " nbVtx:" << nbV << ")\n" ;
810 sss.setf(ios::scientific);
811 if(TmF<=TMF) sss << "\n Face : Min " << setw(8) << TmF <<" Max " << setw(8) << TMF << " \n ";
812 if(TmE<=TME) sss << "\n Edge : Min " << setw(8) << TmE <<" Max " << setw(8) << TME << " \n ";
813 if(TmV<=TMV) sss << "\n Vertex : Min " << setw(8) << TmV <<" Max " << setw(8) << TMV << " \n ";
820 static Standard_Integer vecdc(Draw_Interpretor& di,Standard_Integer ,const char** ) {
821 //cout << "Pick positions with button "<<endl;
822 di << "Pick positions with button \n";
824 Standard_Integer id,X,Y,b;
826 gp_Pnt P1,P2,PP1,PP2;
828 //-----------------------------------------------------------
829 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
831 Standard_Real z = dout.Zoom(id);
832 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
835 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
836 T.Invert(); z = dout.Zoom(id);
838 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
840 Standard_Real xa,ya,za;
841 if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X();
842 if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y();
843 if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z();
844 P1.SetCoord(xa,ya,za);
845 Handle(Draw_Marker3D) D0 = new Draw_Marker3D(gp_Pnt(P1.X(),
848 Draw_Square,Draw_blanc,1);
852 //-----------------------------------------------------------
853 dout.Select(id,X,Y,b);
857 PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
859 dout.Select(id,X,Y,b);
863 PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
865 if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X();
866 if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y();
867 if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z();
868 PP1.SetCoord(xa,ya,za);
869 Handle(Draw_Segment3D) d = new Draw_Segment3D(P1,PP1,Draw_blanc);
872 //cout<<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<endl;
873 di <<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<< "\n";
875 static Standard_Integer nboxvecdp=0;
876 //cout<<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
877 //cout<<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<<endl;
879 //cout<<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
880 // +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
881 // +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<<endl;
883 di <<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
884 di <<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<< "\n";
886 di <<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
887 +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
888 +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<< "\n";
891 //=======================================================================
893 //=======================================================================
895 #include <TopTools_SequenceOfShape.hxx>
896 static Standard_Integer nproject(Draw_Interpretor& di, Standard_Integer n, const char** a)
898 if ( n < 4) return 1;
899 TopoDS_Shape InpShape;
900 Standard_Integer arg = 2, i;
901 TopTools_SequenceOfShape Args;
903 Standard_Real Tol = 1.e-4;
905 Standard_Real MaxDistance = 1.e-3;
906 GeomAbs_Shape Continuity = GeomAbs_C2;
907 Standard_Integer MaxDeg = 14;
908 Standard_Integer MaxSeg = 16;
910 while((n > arg) && !(InpShape = DBRep::Get(a[arg])).IsNull()){
911 Args.Append(InpShape);
914 if(Args.Length() < 2) return 1;
916 BRepOffsetAPI_NormalProjection OrtProj(Args.Last());
918 for(i = 1; i < Args.Length(); i++)
919 OrtProj.Add(Args(i));
922 if (!strcmp(a[arg],"-g")) {
923 OrtProj.SetLimit(Standard_False);
928 if (!strcmp(a[arg],"-d")) {
931 MaxDistance = Draw::Atof(a[arg++]);
932 OrtProj.SetMaxDistance(MaxDistance);
935 Tol = Max(Draw::Atof(a[arg++]),1.e-10);
939 if (Draw::Atoi(a[arg]) == 0) Continuity = GeomAbs_C0;
940 else if (Draw::Atoi(a[arg]) == 1) Continuity = GeomAbs_C1;
946 MaxDeg = Draw::Atoi(a[arg++]);
947 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
950 if(n > arg) MaxSeg = Draw::Atoi(a[arg]);
952 Tol2d = Pow(Tol, 2./3);
954 OrtProj.SetParams(Tol, Tol2d, Continuity, MaxDeg, MaxSeg);
956 TopTools_ListOfShape Wire;
957 Standard_Boolean IsWire=OrtProj.BuildWire(Wire);
959 //cout << " BuildWire OK " << endl;
960 di << " BuildWire OK \n";
962 DBRep::Set(a[1], OrtProj.Shape());
966 //==========================================================================
968 // exploration of a wire
969 //==========================================================================
970 static Standard_Integer wexplo (Draw_Interpretor&,
971 Standard_Integer argc, const char** argv)
974 if (argc < 2) return 1;
976 TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_WIRE);
979 if (argc > 2) C2 = DBRep::Get (argv[2],TopAbs_FACE);
981 if (C1.IsNull()) return 1;
983 BRepTools_WireExplorer we;
984 if (C2.IsNull()) we.Init(TopoDS::Wire(C1));
985 else we.Init(TopoDS::Wire(C1),TopoDS::Face(C2));
987 Standard_Integer k = 1;
989 TopoDS_Edge E = we.Current();
990 Sprintf(name,"WEDGE_%d",k);
999 static Standard_Integer scalexyz(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
1001 if (n < 6) return 1;
1003 TopoDS_Shape aShapeBase = DBRep::Get(a[2]);
1004 if (aShapeBase.IsNull()) return 1;
1006 Standard_Real aFactorX = Draw::Atof(a[3]);
1007 Standard_Real aFactorY = Draw::Atof(a[4]);
1008 Standard_Real aFactorZ = Draw::Atof(a[5]);
1011 gp_Mat rot (aFactorX, 0, 0,
1014 aGTrsf.SetVectorialPart(rot);
1015 BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False);
1016 if (!aBRepGTrsf.IsDone())
1017 throw Standard_ConstructionError("Scaling not done");
1018 TopoDS_Shape Result = aBRepGTrsf.Shape();
1020 DBRep::Set(a[1], Result);
1024 //=======================================================================
1025 //function : compareshapes
1027 //=======================================================================
1028 static Standard_Integer compareshapes(Draw_Interpretor& di,
1033 di << "Compare shapes. Usage: compare shape1 shape2\n";
1037 TopoDS_Shape aS1 = DBRep::Get(a[1]);
1038 TopoDS_Shape aS2 = DBRep::Get(a[2]);
1040 if (aS1.IsNull() || aS2.IsNull()) {
1041 di << "null shapes\n";
1045 if (aS1.IsSame(aS2)) {
1046 di << "same shapes\n";
1047 if (aS1.IsEqual(aS2)) {
1048 di << "equal shapes\n";
1052 di << "shapes are not same\n";
1057 //=======================================================================
1058 //function : issubshape
1060 //=======================================================================
1061 static Standard_Integer issubshape(Draw_Interpretor& di,
1066 di << "Check if the shape is sub-shape of other shape and get its index in the shape.\n";
1067 di << "Usage: issubshape subshape shape\n";
1071 TopoDS_Shape aSubShape = DBRep::Get(a[1]);
1072 TopoDS_Shape aShape = DBRep::Get(a[2]);
1074 if (aSubShape.IsNull() || aShape.IsNull()) {
1075 di << "null shapes\n";
1078 // find index of the sub-shape in the shape
1079 TopTools_MapOfShape aMShapes;
1080 // try to find the SubShape in Shape
1081 TopExp_Explorer anExp(aShape, aSubShape.ShapeType());
1082 for (; anExp.More(); anExp.Next()) {
1083 const TopoDS_Shape& aSS = anExp.Current();
1084 if (aMShapes.Add(aSS)) {
1085 if (aSS.IsSame(aSubShape)) {
1092 di << a[1] << " is sub-shape of " << a[2] << ". Index in the shape: " << aMShapes.Extent() << ".\n";
1095 di << a[1] << " is NOT sub-shape of " << a[2] << ".\n";
1101 void BRepTest::BasicCommands(Draw_Interpretor& theCommands)
1103 static Standard_Boolean done = Standard_False;
1105 done = Standard_True;
1107 DBRep::BasicCommands(theCommands);
1109 const char* g = "TOPOLOGY Basic shape commands";
1111 theCommands.Add("addpcurve",
1112 "addpcurve edge 2dcurve face [tol (default 1.e-7)]",
1116 theCommands.Add("reset",
1117 "reset name1 name2 ..., remove location",
1121 theCommands.Add("tmove",
1122 "tmove name1 name2 ... name, set location from name",
1126 theCommands.Add("ttranslate",
1127 "ttranslate name1 name2 ... dx dy dz",
1131 theCommands.Add("trotate",
1132 "trotate name1 name2 ... x y z dx dy dz angle",
1136 theCommands.Add("tmirror",
1137 "tmirror name x y z dx dy dz",
1141 theCommands.Add("tscale",
1142 "tscale name x y z scale",
1146 theCommands.Add("tcopy",
1147 "tcopy [-n(ogeom)] [-m(esh)] name1 result1 [name2 result2 ...]",
1151 theCommands.Add("bmove",
1152 "bmove name1 name2 ... name, set location from name",
1156 theCommands.Add("btranslate",
1157 "btranslate name1 name2 ... dx dy dz",
1161 theCommands.Add("brotate",
1162 "brotate name1 name2 ... x y z dx dy dz angle",
1166 theCommands.Add("bmirror",
1167 "bmirror name x y z dx dy dz",
1171 theCommands.Add("bscale",
1172 "bscale name x y z scale",
1176 theCommands.Add("precision",
1177 "precision [preci]",
1181 theCommands.Add("mkedgecurve",
1182 "mkedgecurve name tolerance",
1186 theCommands.Add("fsameparameter",
1187 "fsameparameter shapename [tol (default 1.e-7)], \nforce sameparameter on all edges of the shape",
1191 theCommands.Add("sameparameter",
1192 "sameparameter [result] shape [tol]",
1196 theCommands.Add("updatetolerance",
1197 "updatetolerance [result] shape [param] \n if [param] is absent - not verify of face tolerance, else - perform it",
1201 theCommands.Add("solidorientation",
1202 "orientsolid myClosedSolid",
1206 theCommands.Add("getcoords",
1207 "getcoords vertex1 vertex 2... ; shows coords of input vertices",
1211 theCommands.Add("bounding",
1212 "bounding shape [ xmin ymin zmin xmax ymax zmax] ; draw bounds",
1216 theCommands.Add("optbounding",
1217 "optbounding shape [usetri (0/1) [usetol (0/1)]] ; ",
1221 theCommands.Add("gbounding",
1222 "gbounding surf/curve/curve2d [-o] ",
1226 theCommands.Add("boundingstr",
1227 "boundingstr shape [ xmin ymin zmin xmax ymax zmax] ; print bounding box",
1231 theCommands.Add("nurbsconvert",
1232 "nurbsconvert result name [result name]",
1236 theCommands.Add("deform",
1237 "deform newname name CoeffX CoeffY CoeffZ",
1241 theCommands.Add("findplane",
1242 "findplane name planename ",
1246 theCommands.Add("maxtolerance",
1247 "maxtolerance shape ",
1251 theCommands.Add("reperageshape",
1252 "reperage shape -> list of shape (result of interstion shape , line)",
1256 theCommands.Add("vecdc",
1257 "vecdc + Pointe double click ",
1261 theCommands.Add("nproject","nproject pj e1 e2 e3 ... surf -g -d [dmax] [Tol [continuity [maxdeg [maxseg]]]",
1265 theCommands.Add("wexplo","wexplo wire [face] create WEDGE_i",
1269 theCommands.Add("scalexyz",
1270 "scalexyz res shape factor_x factor_y factor_z",
1274 theCommands.Add("compare",
1275 "Compare shapes. Usage: compare shape1 shape2",
1279 theCommands.Add("issubshape",
1280 "issubshape subshape shape\n"
1281 "\t\tCheck if the shape is sub-shape of other shape and get its index in the shape.",