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& ,Standard_Integer n,const char** a)
311 Standard_Real tol = 1.e-7;
312 TopoDS_Shape S = DBRep::Get(a[1]);
313 if (S.IsNull()) return 1;
314 Standard_Boolean force = !strcmp(a[0],"fsameparameter");
315 if (n == 3) tol = Draw::Atof(a[2]);
317 BRepLib::SameParameter(S,tol,force);
322 //=======================================================================
323 //function : updatetol
325 //=======================================================================
326 static Standard_Integer updatetol(Draw_Interpretor& ,Standard_Integer n,const char** a)
330 TopoDS_Shape S = DBRep::Get(a[1]);
331 if (S.IsNull()) return 1;
333 if (n==2) BRepLib::UpdateTolerances(S);
334 else BRepLib::UpdateTolerances(S,Standard_True);
340 //=======================================================================
341 //function : OrienSolid
343 //=======================================================================
344 static Standard_Integer orientsolid(Draw_Interpretor& ,Standard_Integer n,const char** a)
348 TopoDS_Shape S = DBRep::Get(a[1]);
349 if (S.IsNull()) return 1;
350 if (S.ShapeType()!=TopAbs_SOLID) return 1;
352 BRepLib::OrientClosedSolid(TopoDS::Solid(S));
359 //=======================================================================
360 //function : boundingstr
362 //=======================================================================
363 static Standard_Integer boundingstr(Draw_Interpretor& di,Standard_Integer n,const char** a)
366 TopoDS_Shape S = DBRep::Get(a[1]);
367 if (S.IsNull()) return 1;
369 BRepBndLib::Add(S,B);
370 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
371 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
372 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
374 Draw::Set(a[2],axmin) ;
375 Draw::Set(a[3],aymin) ;
376 Draw::Set(a[4],azmin) ;
377 Draw::Set(a[5],axmax) ;
378 Draw::Set(a[6],aymax) ;
379 Draw::Set(a[7],azmax) ;
384 //=======================================================================
385 //function : getcoords
387 //=======================================================================
388 static Standard_Integer getcoords(Draw_Interpretor& di,Standard_Integer n,const char** a)
393 for (Standard_Integer i = 1; i < n; i++)
395 const TopoDS_Shape aShape = DBRep::Get (a[i]);
400 if (aShape.ShapeType() == TopAbs_VERTEX)
402 const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape);
403 gp_Pnt aPnt = BRep_Tool::Pnt(aVertex);
405 di << a[i] << " (x,y,z) : " << aPnt.X() << " " << aPnt.Y() << " " << aPnt.Z() << "\n";
412 //=======================================================================
413 //function : bounding
415 //=======================================================================
416 static Standard_Integer bounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
419 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
420 Bnd_Box B; Handle(Draw_Box) DB;
423 TopoDS_Shape S = DBRep::Get(a[1]);
424 if (S.IsNull()) return 1;
425 BRepBndLib::Add(S,B);
426 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
427 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange);
429 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
432 axmin=Draw::Atof(a[1]);
433 aymin=Draw::Atof(a[2]);
434 azmin=Draw::Atof(a[3]);
435 axmax=Draw::Atof(a[4]);
436 aymax=Draw::Atof(a[5]);
437 azmax=Draw::Atof(a[6]);
438 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_orange);
443 //=======================================================================
444 //function : optbounding
446 //=======================================================================
447 static Standard_Integer optbounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
451 di << "Usage: optbounding shape [usetri [usetol]]\n";
452 di << "usetri and usetol can be 0 or 1, by default usetri = 1, usetol = 0\n";
455 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
456 Bnd_Box B; Handle(Draw_Box) DB;
458 TopoDS_Shape S = DBRep::Get(a[1]);
461 di << "Null shape\n";
464 Standard_Boolean useTri = Standard_True;
465 Standard_Boolean useTol = Standard_False;
468 Standard_Integer ii = atoi(a[2]);
473 Standard_Integer ii = atoi(a[3]);
476 BRepBndLib::AddOptimal(S, B, useTri, useTol);
477 B.Get(axmin, aymin, azmin, axmax, aymax, azmax);
478 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_vert);
480 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
483 //=======================================================================
484 //function : gbounding
486 //=======================================================================
487 #include <GeomAdaptor_Surface.hxx>
488 #include <BndLib_AddSurface.hxx>
489 #include <BndLib_Add3dCurve.hxx>
490 #include <BndLib_Add2dCurve.hxx>
491 #include <Draw_Segment2D.hxx>
492 static Standard_Integer gbounding(Draw_Interpretor& di,Standard_Integer n,const char** a)
494 if (n != 2 && n != 3)
496 di << "Usage: gbounding surf/curve/curve2d [-o] \n";
497 di << "[-o] turn on Optimal mode ('off' by default) \n";
502 Standard_Boolean IsOptimal = Standard_False;
503 if (n == 3 && !strcmp(a[2], "-o"))
504 IsOptimal = Standard_True;
506 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
510 Standard_Boolean Is3d = Standard_True;
511 Handle(Geom_Curve) C;
512 Handle(Geom_Surface) S;
513 Handle_Geom2d_Curve C2d;
514 S = DrawTrSurf::GetSurface(a[1]);
518 GeomAdaptor_Surface aGAS(S);
520 BndLib_AddSurface::AddOptimal(aGAS, Precision::Confusion(), B);
522 BndLib_AddSurface::Add(aGAS, Precision::Confusion(), B);
526 C = DrawTrSurf::GetCurve(a[1]);
530 GeomAdaptor_Curve aGAC(C);
532 BndLib_Add3dCurve::AddOptimal(aGAC, Precision::Confusion(), B);
534 BndLib_Add3dCurve::Add(aGAC, Precision::Confusion(), B);
538 C2d = DrawTrSurf::GetCurve2d(a[1]);
542 Is3d = Standard_False;
544 BndLib_Add2dCurve::AddOptimal(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d);
546 BndLib_Add2dCurve::Add(C2d, C2d->FirstParameter(), C2d->LastParameter(), Precision::Confusion(), B2d);
550 di << "Wrong argument \n";
558 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
559 DB = new Draw_Box(gp_Pnt(axmin,aymin,azmin),gp_Pnt(axmax,aymax,azmax),Draw_vert);
561 di << axmin<<" "<< aymin<<" "<< azmin<<" "<< axmax<<" "<< aymax<<" "<< azmax;
565 B2d.Get(axmin,aymin,axmax,aymax);
566 gp_Pnt2d p1(axmin, aymin);
567 gp_Pnt2d p2(axmax, aymin);
568 gp_Pnt2d p3(axmax, aymax);
569 gp_Pnt2d p4(axmin, aymax);
570 Draw_Segment2D* S1 = new Draw_Segment2D(p1, p2, Draw_vert);
571 Draw_Segment2D* S2 = new Draw_Segment2D(p2, p3, Draw_vert);
572 Draw_Segment2D* S3 = new Draw_Segment2D(p3, p4, Draw_vert);
573 Draw_Segment2D* S4 = new Draw_Segment2D(p4, p1, Draw_vert);
574 dout << S1 << S2 << S3 << S4;
575 di << axmin<<" "<< aymin<<" "<< axmax<<" "<< aymax;
581 //=======================================================================
582 //function : findplane
584 //=======================================================================
585 static Standard_Integer findplane(Draw_Interpretor& di,Standard_Integer n,const char** a)
588 TopoDS_Shape S = DBRep::Get(a[1]);
589 if (S.IsNull()) return 1;
590 Standard_Real tolerance = 1.0e-5 ;
591 BRepBuilderAPI_FindPlane a_plane_finder(S,
593 if (a_plane_finder.Found()) {
594 //cout << " a plane is found " ;
595 di << " a plane is found \n";
596 const Handle(Geom_Geometry)& aSurf = a_plane_finder.Plane(); // to avoid ambiguity
597 DrawTrSurf::Set(a[2],aSurf) ;
601 //=======================================================================
602 //function : precision
604 //=======================================================================
606 static Standard_Integer precision(Draw_Interpretor& di,Standard_Integer n,const char** a)
611 //cout << " Current Precision = " << BRepBuilderAPI::Precision() << endl;
612 di << " Current Precision = " << BRepBuilderAPI::Precision() << "\n";
615 BRepBuilderAPI::Precision(Draw::Atof(a[1]));
621 //=======================================================================
622 //function : reperage shape (Int lin Shape) + pointe double click + maxtol
624 //=======================================================================
625 #include <IntCurvesFace_ShapeIntersector.hxx>
626 #include <gp_Lin.hxx>
628 static Standard_Integer reperageshape(Draw_Interpretor& di, Standard_Integer narg , const char** a)
630 Standard_Integer details=0;
632 if(narg==3) details=1;
633 const char *id1 = a[1];
634 TopoDS_Shape TheShape1 = DBRep::Get(id1);
636 //cout << "Pick positions with button "<<endl;
637 di << "Pick positions with button \n";
638 Standard_Integer id,X,Y,b;
641 dout.Select(id,X,Y,b);
645 Standard_Real z = dout.Zoom(id);
646 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z, 0.0);
648 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,-1.0);
652 gp_Ax1 Axe(P1,gp_Vec(P1,P2));
653 IntCurvesFace_ShapeIntersector Inter;
654 Inter.Load(TheShape1,1e-7);
656 Inter.Perform(Axe,-RealLast(),RealLast());
661 for(Standard_Integer i=1; i<=Inter.NbPnt(); i++) {
662 Standard_Integer numface=1;
664 for(ExF.Init(TheShape1,TopAbs_FACE);
666 ExF.Next(),numface++) {
667 TopoDS_Face Face=TopoDS::Face(ExF.Current());
668 if(Face.IsEqual(Inter.Face(i))) {
669 //cout<<" "<<a[1]<<"_"<<numface;
670 di<<" "<<a[1]<<"_"<<numface;
674 const gp_Pnt& P = Inter.Pnt(i);
675 Standard_Real PMin = Inter.WParameter(i);
677 //cout<<" w:"<<PMin<<endl;
678 di<<" w:"<<PMin<< "\n";
680 if(Inter.Transition(i) == IntCurveSurface_In) {
681 if(Inter.State(i) == TopAbs_IN) {
682 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_rouge,2);
683 dout << p; dout.Flush();
685 else if(Inter.State(i) == TopAbs_ON) {
686 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_Square, Draw_vert,2);
687 dout << p; dout.Flush();
691 if(Inter.Transition(i) == IntCurveSurface_Out) {
692 if(Inter.State(i) == TopAbs_IN) {
693 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_rouge,2);
694 dout << p; dout.Flush();
696 else if(Inter.State(i) == TopAbs_ON) {
697 Handle(Draw_Marker3D) p = new Draw_Marker3D(P, Draw_X, Draw_vert,2);
698 dout << p; dout.Flush();
710 static Standard_Integer maxtolerance(Draw_Interpretor& theCommands,
711 Standard_Integer n, const char** a) {
713 TopoDS_Shape TheShape = DBRep::Get(a[1]);
714 if(TheShape.IsNull()) return(1);
716 Standard_Real T,TMF,TME,TMV,TmF,TmE,TmV;
717 Standard_Integer nbF,nbE,nbV;
718 TMF=TME=TMV=-RealLast();
719 TmF=TmE=TmV=RealLast();
721 TopTools_MapOfShape mapS;
724 for(TopExp_Explorer ex(TheShape,TopAbs_FACE);
727 TopoDS_Face Face=TopoDS::Face(ex.Current());
728 T=BRep_Tool::Tolerance(Face);
737 for(TopExp_Explorer ex(TheShape,TopAbs_EDGE);
740 TopoDS_Edge Edge=TopoDS::Edge(ex.Current());
741 T=BRep_Tool::Tolerance(Edge);
750 for(TopExp_Explorer ex(TheShape,TopAbs_VERTEX);
753 TopoDS_Vertex Vertex=TopoDS::Vertex(ex.Current());
754 T=BRep_Tool::Tolerance(Vertex);
762 Standard_SStream sss;
763 sss << "\n## Tolerances on the shape " << a[1] << " (nbFaces:" << nbF
764 << " nbEdges:" << nbE << " nbVtx:" << nbV << ")\n" ;
766 sss.setf(ios::scientific);
767 if(TmF<=TMF) sss << "\n Face : Min " << setw(8) << TmF <<" Max " << setw(8) << TMF << " \n ";
768 if(TmE<=TME) sss << "\n Edge : Min " << setw(8) << TmE <<" Max " << setw(8) << TME << " \n ";
769 if(TmV<=TMV) sss << "\n Vertex : Min " << setw(8) << TmV <<" Max " << setw(8) << TMV << " \n ";
776 static Standard_Integer vecdc(Draw_Interpretor& di,Standard_Integer ,const char** ) {
777 //cout << "Pick positions with button "<<endl;
778 di << "Pick positions with button \n";
780 Standard_Integer id,X,Y,b;
782 gp_Pnt P1,P2,PP1,PP2;
784 //-----------------------------------------------------------
785 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
787 Standard_Real z = dout.Zoom(id);
788 P1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
791 dout.Select(id,X,Y,b); dout.GetTrsf(id,T);
792 T.Invert(); z = dout.Zoom(id);
794 P2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
796 Standard_Real xa,ya,za;
797 if(Abs(P1.X())>Abs(P2.X())) xa = P1.X(); else xa = P2.X();
798 if(Abs(P1.Y())>Abs(P2.Y())) ya = P1.Y(); else ya = P2.Y();
799 if(Abs(P1.Z())>Abs(P2.Z())) za = P1.Z(); else za = P2.Z();
800 P1.SetCoord(xa,ya,za);
801 Handle(Draw_Marker3D) D0 = new Draw_Marker3D(gp_Pnt(P1.X(),
804 Draw_Square,Draw_blanc,1);
808 //-----------------------------------------------------------
809 dout.Select(id,X,Y,b);
813 PP1.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
815 dout.Select(id,X,Y,b);
819 PP2.SetCoord((Standard_Real)X /z,(Standard_Real)Y /z,0.0);
821 if(Abs(PP1.X())>Abs(PP2.X())) xa = PP1.X(); else xa = PP2.X();
822 if(Abs(PP1.Y())>Abs(PP2.Y())) ya = PP1.Y(); else ya = PP2.Y();
823 if(Abs(PP1.Z())>Abs(PP2.Z())) za = PP1.Z(); else za = PP2.Z();
824 PP1.SetCoord(xa,ya,za);
825 Handle(Draw_Segment3D) d = new Draw_Segment3D(P1,PP1,Draw_blanc);
828 //cout<<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<<endl;
829 di <<"\nttran "<<PP1.X()-P1.X()<<" "<<PP1.Y()-P1.Y()<<" "<<PP1.Z()-P1.Z()<< "\n";
831 static Standard_Integer nboxvecdp=0;
832 //cout<<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
833 //cout<<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<<endl;
835 //cout<<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
836 // +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
837 // +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<<endl;
839 di <<"\nbox b"<<++nboxvecdp<<" "<<Min(P1.X(),PP1.X())<<" "<<Min(P1.Y(),PP1.Y())<<" "<<Min(PP1.Z(),P1.Z());
840 di <<" "<<Abs(PP1.X()-P1.X())<<" "<<Abs(PP1.Y()-P1.Y())<<" "<<Abs(PP1.Z()-P1.Z())<< "\n";
842 di <<"\nDistance :"<<sqrt( (PP1.X()-P1.X())*(PP1.X()-P1.X())
843 +(PP1.Y()-P1.Y())*(PP1.Y()-P1.Y())
844 +(PP1.Z()-P1.Z())*(PP1.Z()-P1.Z()))<< "\n";
847 //=======================================================================
849 //=======================================================================
851 #include <TopTools_SequenceOfShape.hxx>
852 static Standard_Integer nproject(Draw_Interpretor& di, Standard_Integer n, const char** a)
854 if ( n < 4) return 1;
855 TopoDS_Shape InpShape;
856 Standard_Integer arg = 2, i;
857 TopTools_SequenceOfShape Args;
859 Standard_Real Tol = 1.e-4;
861 Standard_Real MaxDistance = 1.e-3;
862 GeomAbs_Shape Continuity = GeomAbs_C2;
863 Standard_Integer MaxDeg = 14;
864 Standard_Integer MaxSeg = 16;
866 while((n > arg) && !(InpShape = DBRep::Get(a[arg])).IsNull()){
867 Args.Append(InpShape);
870 if(Args.Length() < 2) return 1;
872 BRepOffsetAPI_NormalProjection OrtProj(Args.Last());
874 for(i = 1; i < Args.Length(); i++)
875 OrtProj.Add(Args(i));
878 if (!strcmp(a[arg],"-g")) {
879 OrtProj.SetLimit(Standard_False);
884 if (!strcmp(a[arg],"-d")) {
887 MaxDistance = Draw::Atof(a[arg++]);
888 OrtProj.SetMaxDistance(MaxDistance);
891 Tol = Max(Draw::Atof(a[arg++]),1.e-10);
895 if (Draw::Atoi(a[arg]) == 0) Continuity = GeomAbs_C0;
896 else if (Draw::Atoi(a[arg]) == 1) Continuity = GeomAbs_C1;
902 MaxDeg = Draw::Atoi(a[arg++]);
903 if (MaxDeg<1 || MaxDeg>14) MaxDeg = 14;
906 if(n > arg) MaxSeg = Draw::Atoi(a[arg]);
908 Tol2d = Pow(Tol, 2./3);
910 OrtProj.SetParams(Tol, Tol2d, Continuity, MaxDeg, MaxSeg);
912 TopTools_ListOfShape Wire;
913 Standard_Boolean IsWire=OrtProj.BuildWire(Wire);
915 //cout << " BuildWire OK " << endl;
916 di << " BuildWire OK \n";
918 DBRep::Set(a[1], OrtProj.Shape());
922 //==========================================================================
924 // exploration of a wire
925 //==========================================================================
926 static Standard_Integer wexplo (Draw_Interpretor&,
927 Standard_Integer argc, const char** argv)
930 if (argc < 2) return 1;
932 TopoDS_Shape C1 = DBRep::Get (argv[1],TopAbs_WIRE);
935 if (argc > 2) C2 = DBRep::Get (argv[2],TopAbs_FACE);
937 if (C1.IsNull()) return 1;
939 BRepTools_WireExplorer we;
940 if (C2.IsNull()) we.Init(TopoDS::Wire(C1));
941 else we.Init(TopoDS::Wire(C1),TopoDS::Face(C2));
943 Standard_Integer k = 1;
945 TopoDS_Edge E = we.Current();
946 Sprintf(name,"WEDGE_%d",k);
955 static Standard_Integer scalexyz(Draw_Interpretor& /*di*/, Standard_Integer n, const char** a)
959 TopoDS_Shape aShapeBase = DBRep::Get(a[2]);
960 if (aShapeBase.IsNull()) return 1;
962 Standard_Real aFactorX = Draw::Atof(a[3]);
963 Standard_Real aFactorY = Draw::Atof(a[4]);
964 Standard_Real aFactorZ = Draw::Atof(a[5]);
967 gp_Mat rot (aFactorX, 0, 0,
970 aGTrsf.SetVectorialPart(rot);
971 BRepBuilderAPI_GTransform aBRepGTrsf (aShapeBase, aGTrsf, Standard_False);
972 if (!aBRepGTrsf.IsDone())
973 throw Standard_ConstructionError("Scaling not done");
974 TopoDS_Shape Result = aBRepGTrsf.Shape();
976 DBRep::Set(a[1], Result);
980 void BRepTest::BasicCommands(Draw_Interpretor& theCommands)
982 static Standard_Boolean done = Standard_False;
984 done = Standard_True;
986 DBRep::BasicCommands(theCommands);
988 const char* g = "TOPOLOGY Basic shape commands";
990 theCommands.Add("addpcurve",
991 "addpcurve edge 2dcurve face [tol (default 1.e-7)]",
995 theCommands.Add("reset",
996 "reset name1 name2 ..., remove location",
1000 theCommands.Add("tmove",
1001 "tmove name1 name2 ... name, set location from name",
1005 theCommands.Add("ttranslate",
1006 "ttranslate name1 name2 ... dx dy dz",
1010 theCommands.Add("trotate",
1011 "trotate name1 name2 ... x y z dx dy dz angle",
1015 theCommands.Add("tmirror",
1016 "tmirror name x y z dx dy dz",
1020 theCommands.Add("tscale",
1021 "tscale name x y z scale",
1025 theCommands.Add("tcopy",
1026 "tcopy [-n(ogeom)] [-m(esh)] name1 result1 [name2 result2 ...]",
1030 theCommands.Add("bmove",
1031 "bmove name1 name2 ... name, set location from name",
1035 theCommands.Add("btranslate",
1036 "btranslate name1 name2 ... dx dy dz",
1040 theCommands.Add("brotate",
1041 "brotate name1 name2 ... x y z dx dy dz angle",
1045 theCommands.Add("bmirror",
1046 "bmirror name x y z dx dy dz",
1050 theCommands.Add("bscale",
1051 "bscale name x y z scale",
1055 theCommands.Add("precision",
1056 "precision [preci]",
1060 theCommands.Add("mkedgecurve",
1061 "mkedgecurve name tolerance",
1065 theCommands.Add("fsameparameter",
1066 "fsameparameter shapename [tol (default 1.e-7)], \nforce sameparameter on all edges of the shape",
1070 theCommands.Add("sameparameter",
1071 "sameparameter shapename [tol (default 1.e-7)]",
1075 theCommands.Add("updatetolerance",
1076 "updatetolerance myShape [param] \n if [param] is absent - not verify of face tolerance, else - perform it",
1080 theCommands.Add("solidorientation",
1081 "orientsolid myClosedSolid",
1085 theCommands.Add("getcoords",
1086 "getcoords vertex1 vertex 2... ; shows coords of input vertices",
1090 theCommands.Add("bounding",
1091 "bounding shape [ xmin ymin zmin xmax ymax zmax] ; draw bounds",
1095 theCommands.Add("optbounding",
1096 "optbounding shape [usetri (0/1) [usetol (0/1)]] ; ",
1100 theCommands.Add("gbounding",
1101 "gbounding surf/curve/curve2d [-o] ",
1105 theCommands.Add("boundingstr",
1106 "boundingstr shape [ xmin ymin zmin xmax ymax zmax] ; print bounding box",
1110 theCommands.Add("nurbsconvert",
1111 "nurbsconvert result name [result name]",
1115 theCommands.Add("deform",
1116 "deform newname name CoeffX CoeffY CoeffZ",
1120 theCommands.Add("findplane",
1121 "findplane name planename ",
1125 theCommands.Add("maxtolerance",
1126 "maxtolerance shape ",
1130 theCommands.Add("reperageshape",
1131 "reperage shape -> list of shape (result of interstion shape , line)",
1135 theCommands.Add("vecdc",
1136 "vecdc + Pointe double click ",
1140 theCommands.Add("nproject","nproject pj e1 e2 e3 ... surf -g -d [dmax] [Tol [continuity [maxdeg [maxseg]]]",
1144 theCommands.Add("wexplo","wexplo wire [face] create WEDGE_i",
1148 theCommands.Add("scalexyz",
1149 "scalexyz res shape factor_x factor_y factor_z",