2 // Created: Thu Jul 22 16:38:58 1993
3 // Author: Remi LEQUETTE
7 #include <BRepTest.hxx>
8 #include <GeometryTest.hxx>
9 #include <gp_Pnt2d.hxx>
13 #include <gp_Vec2d.hxx>
14 #include <TColgp_HArray1OfPnt2d.hxx>
15 #include <TColgp_Array1OfPnt2d.hxx>
16 #include <BRepBuilderAPI.hxx>
17 #include <BRepBuilderAPI_MakeVertex.hxx>
18 #include <BRepBuilderAPI_MakeEdge.hxx>
19 #include <BRepBuilderAPI_MakeEdge2d.hxx>
20 #include <BRepBuilderAPI_MakeFace.hxx>
21 #include <BRepBuilderAPI_MakeWire.hxx>
22 #include <BRepBuilderAPI_MakePolygon.hxx>
23 #include <BRepOffsetAPI_MakeOffset.hxx>
24 #include <BRepLib.hxx>
25 #include <BRepAlgo.hxx>
26 #include <BRepAdaptor_Curve.hxx>
27 #include <BRep_Builder.hxx>
28 #include <BRep_Tool.hxx>
29 #include <BRepTools.hxx>
30 #include <Geom_Curve.hxx>
31 #include <Geom_TrimmedCurve.hxx>
32 #include <Geom2d_BSplineCurve.hxx>
33 #include <Geom_Surface.hxx>
34 #include <Geom_RectangularTrimmedSurface.hxx>
35 #include <Geom_Plane.hxx>
36 #include <Geom2d_Line.hxx>
37 #include <Geom2d_Circle.hxx>
38 #include <Geom2dAPI_Interpolate.hxx>
39 #include <Geom2d_TrimmedCurve.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopoDS_Wire.hxx>
45 #include <DBRep_DrawableShape.hxx>
46 #include <Draw_Interpretor.hxx>
47 #include <Draw_Appli.hxx>
48 #include <DrawTrSurf.hxx>
49 #include <DrawTrSurf_BSplineCurve2d.hxx>
52 #include <Precision.hxx>
53 #include <GeomAPI.hxx>
54 #include <TopAbs_Orientation.hxx>
55 #include <TopExp_Explorer.hxx>
56 #include <TopOpeBRep_EdgesIntersector.hxx>
57 #include <TopOpeBRep_Point2d.hxx>
58 #include <TopOpeBRepDS_Transition.hxx>
63 Standard_IMPORT Draw_Viewer dout;
66 //=======================================================================
68 //=======================================================================
70 static Standard_Integer vertex(Draw_Interpretor& , Standard_Integer n, const char** a)
75 BRepBuilderAPI_MakeVertex(gp_Pnt(atof(a[2]),atof(a[3]),atof(a[4]))));
78 TopoDS_Shape S = DBRep::Get(a[3]);
79 if (S.IsNull()) return 0;
80 if (S.ShapeType() != TopAbs_EDGE) return 0;
81 BRepAdaptor_Curve C(TopoDS::Edge(S));
84 DBRep::Set(a[1], BRepBuilderAPI_MakeVertex(P));
89 //=======================================================================
91 //=======================================================================
93 static Standard_Integer range(Draw_Interpretor& , Standard_Integer n, const char** a)
96 TopoDS_Shape aLocalShape(DBRep::Get(a[1],TopAbs_EDGE));
97 TopoDS_Edge E = TopoDS::Edge(aLocalShape);
98 // TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[1],TopAbs_EDGE));
99 if (E.IsNull()) return 1;
100 Standard_Real f = atof(a[n-2]);
101 Standard_Real l = atof(a[n-1]);
106 aLocalShape = DBRep::Get(a[2],TopAbs_FACE);
107 TopoDS_Face F = TopoDS::Face(aLocalShape);
108 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE));
109 if (F.IsNull()) return 1;
115 //=======================================================================
117 //=======================================================================
119 static Standard_Integer trim(Draw_Interpretor& di, Standard_Integer n, const char** a)
122 TopoDS_Shape e = DBRep::Get(a[1]);
123 if (e.IsNull()) return 1;
124 if (e.ShapeType() != TopAbs_EDGE) return 1;
125 TopoDS_Shape v1 = DBRep::Get(a[2]);
126 if (v1.IsNull()) return 1;
127 if (v1.ShapeType() != TopAbs_VERTEX) return 1;
130 v2 = DBRep::Get(a[3]);
131 if (v2.IsNull()) return 1;
132 if (v2.ShapeType() != TopAbs_VERTEX) return 1;
136 const Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(e),L,f,l);
137 TopLoc_Location LI = L.Inverted();
138 e.Orientation(TopAbs_FORWARD);
144 if (v1.Orientation() == TopAbs_REVERSED) {
149 BRepBuilderAPI_MakeEdge ME(C,TopoDS::Vertex(v1),TopoDS::Vertex(v2));
156 //cout <<"Error creating edge"<<endl;
157 di <<"Error creating edge"<<"\n";
163 //=======================================================================
165 //=======================================================================
167 static Standard_Integer polyline(Draw_Interpretor& , Standard_Integer n, const char** a)
170 if (((n-2) % 3) != 0) return 1;
171 Standard_Integer i, j, np = (n-2) / 3;
172 BRepBuilderAPI_MakePolygon W;
174 for (i = 1; i <= np; i ++) {
175 W.Add(gp_Pnt(atof(a[j]),atof(a[j+1]),atof(a[j+2])));
178 DBRep::Set(a[1],W.Wire());
182 //=======================================================================
184 //=======================================================================
186 static Standard_Integer polyvertex(Draw_Interpretor& , Standard_Integer n, const char** a)
190 BRepBuilderAPI_MakePolygon W;
191 for (i = 2; i < n; i ++) {
192 TopoDS_Shape S = DBRep::Get(a[i]);
193 if (S.IsNull()) return 1;
194 if (S.ShapeType() != TopAbs_VERTEX) return 1;
195 W.Add(TopoDS::Vertex(S));
197 DBRep::Set(a[1],W.Wire());
201 //=======================================================================
203 //=======================================================================
205 static Standard_Integer wire(Draw_Interpretor& di, Standard_Integer n, const char** a)
209 BRepBuilderAPI_MakeWire MW;
210 for (i = 2; i < n; i ++) {
211 TopoDS_Shape S = DBRep::Get(a[i]);
212 if (S.IsNull()) continue;
213 if (S.ShapeType() == TopAbs_EDGE)
214 MW.Add(TopoDS::Edge(S));
215 else if (S.ShapeType() == TopAbs_WIRE)
216 MW.Add(TopoDS::Wire(S));
221 //cout << "Wire not done" << endl;
222 di << "Wire not done" << "\n";
229 //=======================================================================
231 //=======================================================================
233 static Standard_Integer mkedge(Draw_Interpretor& di, Standard_Integer n, const char** a)
237 Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]);
238 Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[2]);
239 if (C.IsNull() && C2d.IsNull()) {
240 //cout << a[2] << " is not a curve" << endl;
241 di << a[2] << " is not a curve" << "\n";
248 if (!C.IsNull()) edge = BRepBuilderAPI_MakeEdge(C);
249 else edge = BRepBuilderAPI_MakeEdge2d(C2d);
252 Handle(Geom_Surface) S;
253 Standard_Integer i = 0;
255 S = DrawTrSurf::GetSurface(a[3]);
256 if (!S.IsNull()) i = 1;
258 TopoDS_Shape aLocalShape(DBRep::Get(a[3+i],TopAbs_VERTEX));
259 TopoDS_Vertex V1 = TopoDS::Vertex(aLocalShape);
260 // TopoDS_Vertex V1 = TopoDS::Vertex(DBRep::Get(a[3+i],TopAbs_VERTEX));
264 edge = BRepBuilderAPI_MakeEdge(C,atof(a[3]),atof(a[4]));
266 edge = BRepBuilderAPI_MakeEdge2d(C2d,atof(a[3]),atof(a[4]));
268 edge = BRepBuilderAPI_MakeEdge(C2d,S,atof(a[4]),atof(a[5]));
271 aLocalShape = DBRep::Get(a[4+i],TopAbs_VERTEX);
272 TopoDS_Vertex V2 = TopoDS::Vertex(aLocalShape);
273 // TopoDS_Vertex V2 = TopoDS::Vertex(DBRep::Get(a[4+i],TopAbs_VERTEX));
275 edge = BRepBuilderAPI_MakeEdge(C,V1,V2);
277 edge = BRepBuilderAPI_MakeEdge2d(C2d,V1,V2);
279 edge = BRepBuilderAPI_MakeEdge(C2d,S,V1,V2);
283 aLocalShape = DBRep::Get(a[5+i],TopAbs_VERTEX);
284 TopoDS_Vertex V2 = TopoDS::Vertex(aLocalShape);
285 // TopoDS_Vertex V2 = TopoDS::Vertex(DBRep::Get(a[5+i],TopAbs_VERTEX));
287 edge = BRepBuilderAPI_MakeEdge(C,V1,V2,atof(a[4]),atof(a[6]));
289 edge = BRepBuilderAPI_MakeEdge2d(C2d,V1,V2,atof(a[4]),atof(a[6]));
291 edge = BRepBuilderAPI_MakeEdge(C2d,S,V1,V2,atof(a[5]),atof(a[7]));
297 DBRep::Set(a[1],edge);
301 //=======================================================================
303 //=======================================================================
304 Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col);
305 Standard_IMPORT void DBRep_WriteColorOrientation ();
306 Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or);
308 static Standard_Integer mkcurve(Draw_Interpretor& di, Standard_Integer n, const char** a)
312 Standard_Boolean DispOrientation = !strcmp(a[0],"mkoricurve");
314 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_EDGE);
315 if (S.IsNull()) return 1;
319 Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(S),L,f,l);
321 //cout << a[2] << " has no 3d curve" << endl;
322 di << a[2] << " has no 3d curve" << "\n";
325 C = new Geom_TrimmedCurve(C,f,l);
327 Draw_Color col,savecol;
329 if ( DispOrientation) {
330 DBRep_WriteColorOrientation ();
331 col = DBRep_ColorOrientation(TopoDS::Edge(S).Orientation());
332 savecol = DrawTrSurf_CurveColor(col);
334 DrawTrSurf::Set(a[1],C->Transformed(L.Transformation()));
335 if ( DispOrientation) {
336 DrawTrSurf_CurveColor(savecol);
342 //=======================================================================
345 //=======================================================================
347 static Standard_Integer mkpoint(Draw_Interpretor& ,
348 Standard_Integer n, const char** a)
352 TopoDS_Shape S = DBRep::Get(a[2],TopAbs_VERTEX);
353 if ( S.IsNull()) return 1;
355 TopoDS_Vertex V = TopoDS::Vertex(S);
357 gp_Pnt P = BRep_Tool::Pnt(V);
358 DrawTrSurf::Set(a[1],P);
363 //=======================================================================
365 //=======================================================================
367 static Standard_Integer mk2dcurve(Draw_Interpretor& di,
368 Standard_Integer na, const char** a)
370 if (na < 3) return 1;
373 S = DBRep::Get(a[2],TopAbs_EDGE); if (S.IsNull()) return 1;
374 TopoDS_Edge E = TopoDS::Edge(S);
378 Handle(Geom2d_Curve) C;
379 Handle(Geom_Surface) Surf;
382 // get the first PCurve connected to edge E
383 BRep_Tool::CurveOnSurface(E,C,Surf,L,f,l);
385 else if ( na == 4 ) {
386 S = DBRep::Get(a[3],TopAbs_FACE); if (S.IsNull()) return 1;
387 TopoDS_Face F = TopoDS::Face(S);
388 C = BRep_Tool::CurveOnSurface(E,F,f,l);
392 //cout << a[2] << " has no 2d curve"; if (na == 4) cout << " on " << a[3];
394 di << a[2] << " has no 2d curve"; if (na == 4) di << " on " << a[3];
398 C = new Geom2d_TrimmedCurve(C,f,l);
399 DrawTrSurf::Set(a[1],C);
404 //=======================================================================
406 //=======================================================================
408 static Standard_Integer edge(Draw_Interpretor& , Standard_Integer n, const char** a)
411 TopoDS_Shape V1 = DBRep::Get(a[2],TopAbs_VERTEX);
412 TopoDS_Shape V2 = DBRep::Get(a[3],TopAbs_VERTEX);
413 if (V1.IsNull() || V2.IsNull()) return 1;
414 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(TopoDS::Vertex(V1),
420 //=======================================================================
422 //=======================================================================
424 static Standard_Integer isoedge(Draw_Interpretor& , Standard_Integer n, const char** a)
428 Standard_Boolean uiso = *a[0] == 'u';
429 Standard_Real p = atof(a[3]);
430 Standard_Real p1 = atof(a[4]);
431 Standard_Real p2 = atof(a[5]);
432 TopoDS_Shape Sh = DBRep::Get(a[2],TopAbs_FACE);
433 if (Sh.IsNull()) return 1;
435 const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopoDS::Face(Sh),Loc);
436 Standard_Real UMin,UMax,VMin,VMax;
437 BRepTools::UVBounds(TopoDS::Face(Sh),UMin,UMax,VMin,VMax);
439 VMin = Min (VMin , Min (p1,p2));
440 VMax = Max (VMax , Max (p1,p2));
443 UMin = Min (UMin , Min (p1,p2));
444 UMax = Max (VMax , Max (p1,p2));
447 Handle(Geom_RectangularTrimmedSurface) TS = new Geom_RectangularTrimmedSurface(S,UMin,UMax,VMin,VMax);
448 Handle(Geom_Curve) C;
449 Handle(Geom2d_Line) L;
452 L = new Geom2d_Line(gp_Pnt2d(p,0),gp_Dir2d(0,1));
456 L = new Geom2d_Line(gp_Pnt2d(0,p),gp_Dir2d(1,0));
459 TopoDS_Edge E = BRepBuilderAPI_MakeEdge(C,p1,p2);
462 B.UpdateEdge(E,L,TopoDS::Face(Sh),0.);
468 //=======================================================================
470 //=======================================================================
472 static Standard_Integer transfert(Draw_Interpretor& , Standard_Integer n, const char** a)
476 TopoDS_Shape E1 = DBRep::Get(a[1],TopAbs_EDGE);
477 TopoDS_Shape E2 = DBRep::Get(a[2],TopAbs_EDGE);
478 if (E1.IsNull() || E2.IsNull()) return 1;
481 B.Transfert(TopoDS::Edge(E1),TopoDS::Edge(E2));
485 //=======================================================================
487 // command to build a profile
488 //=======================================================================
490 static Standard_Integer profile(Draw_Interpretor& di,
494 // this command build a profile
495 // from a moving point
500 //cout << "profile name [code values] [code values] ...\n";
501 //cout << " Build a profile in the XY plane from a moving point and direction\n";
502 //cout << " The original point and direction are 0 0 and 1 0\n";
503 //cout << " Codes and values describe the point or direction change\n";
504 //cout << " When the point change the direction becomes the tangent\n";
505 //cout << " All angles are in degree (may be negative)\n";
506 //cout << " By default the profile is closed and a face is built\n";
508 //cout << " Instruction Parameters Action\n";
509 //cout << " O X Y Z Set the origin of the plane\n";
510 //cout << " P DX DY DZ UX UY UZ Set the normal and X of the plane\n";
511 //cout << " S Face Set the Plane (Face must be a Face)\n";
512 //cout << " F X Y Set the first point\n";
513 //cout << " X DX Translate point along X\n";
514 //cout << " Y DY Translate point along Y\n";
515 //cout << " L DL Translate point along direction\n";
516 //cout << " XX X Set point X coordinate\n";
517 //cout << " YY Y Set point Y coordinate\n";
518 //cout << " T DX DY Translate point\n";
519 //cout << " TT X Y Set point\n";
520 //cout << " R Angle Rotate direction\n";
521 //cout << " RR Angle Set direction\n";
522 //cout << " D DX DY Set direction\n";
523 //cout << " IX X Intersect with vertical\n";
524 //cout << " IY Y Intersect with horizontal\n";
525 //cout << " C Radius Angle Arc of circle tangent to direction\n";
526 //cout << " W Make a closed wire\n";
527 //cout << " WW Make an open wire\n";
529 di << "profile name [code values] [code values] ...\n";
530 di << " Build a profile in the XY plane from a moving point and direction\n";
531 di << " The original point and direction are 0 0 and 1 0\n";
532 di << " Codes and values describe the point or direction change\n";
533 di << " When the point change the direction becomes the tangent\n";
534 di << " All angles are in degree (may be negative)\n";
535 di << " By default the profile is closed and a face is built\n";
537 di << " Instruction Parameters Action\n";
538 di << " O X Y Z Set the origin of the plane\n";
539 di << " P DX DY DZ UX UY UZ Set the normal and X of the plane\n";
540 di << " S Face Set the Plane (Face must be a Face)\n";
541 di << " F X Y Set the first point\n";
542 di << " X DX Translate point along X\n";
543 di << " Y DY Translate point along Y\n";
544 di << " L DL Translate point along direction\n";
545 di << " XX X Set point X coordinate\n";
546 di << " YY Y Set point Y coordinate\n";
547 di << " T DX DY Translate point\n";
548 di << " TT X Y Set point\n";
549 di << " R Angle Rotate direction\n";
550 di << " RR Angle Set direction\n";
551 di << " D DX DY Set direction\n";
552 di << " IX X Intersect with vertical\n";
553 di << " IY Y Intersect with horizontal\n";
554 di << " C Radius Angle Arc of circle tangent to direction\n";
555 di << " W Make a closed wire\n";
556 di << " WW Make an open wire\n";
561 Standard_Integer i = 2;
562 Standard_Real x0 = 0, y0 = 0, x = 0, y = 0, dx = 1, dy = 0;
563 BRepBuilderAPI_MakeWire MW;
564 gp_Ax3 DummyHP(gp::XOY());
566 enum {line , circle, none} move;
567 Standard_Boolean face = Standard_True;
568 Standard_Boolean close = Standard_True;
569 Standard_Boolean first = Standard_True;
570 Standard_Boolean stayfirst = Standard_False;
571 Standard_Boolean isplanar = Standard_True;
573 TopLoc_Location TheLocation;
574 Handle(Geom_Surface) Surface;
577 Standard_Real length=0,radius=0,angle=0;
585 if (i >= n) goto badargs;
587 di << "profile: The F instruction must precede all moves";
590 x0 = x = atof(a[i-1]);
592 stayfirst = Standard_True;
598 if (i >= n) goto badargs;
599 P.SetLocation(gp_Pnt(atof(a[i-2]),atof(a[i-1]),atof(a[i])));
600 stayfirst = Standard_True;
606 if (i >= n) goto badargs;
608 gp_Vec vn(atof(a[i-5]),atof(a[i-4]),atof(a[i-3]));
609 gp_Vec vx(atof(a[i-2]),atof(a[i-1]),atof(a[i]));
610 if (vn.Magnitude() <= Precision::Confusion()) {
611 di << "profile : null direction";
614 if (vx.Magnitude() <= Precision::Confusion()) {
615 di << "profile : null direction";
618 gp_Ax2 ax(P.Location(),vn,vx);
621 stayfirst = Standard_True;
627 if (i >= n) goto badargs;
629 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
630 TopoDS_Face Face = TopoDS::Face(aLocalShape);
631 // TopoDS_Face Face = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
633 di << "profile : no face found";
636 Surface = BRep_Tool::Surface(Face,TheLocation);
637 Handle(Geom_Plane) Plane = Handle(Geom_Plane)::DownCast(Surface);
638 if ( Plane.IsNull()) {
639 isplanar = Standard_False;
644 stayfirst = Standard_True;
650 if (i >= n) goto badargs;
652 if ((a[i-1][1] == 'X') || (a[i-1][1] == 'x')) {
662 if (i >= n) goto badargs;
664 if ((a[i-1][1] == 'Y') || (a[i-1][1] == 'y')) {
674 if (i >= n) goto badargs;
682 if (i >= n) goto badargs;
684 Standard_Real vx = atof(a[i-1]);
685 Standard_Real vy = atof(a[i]);
686 if ((a[i-2][1] == 'T') || (a[i-2][1] == 't')) {
690 length = Sqrt(vx*vx+vy*vy);
691 if (length > Precision::Confusion()) {
702 if (i >= n) goto badargs;
703 angle = atof(a[i]) * (M_PI / 180.0);
704 if ((a[i-1][1] == 'R') || (a[i-1][1] == 'r')) {
709 Standard_Real c = Cos(angle);
710 Standard_Real s = Sin(angle);
711 Standard_Real t = c * dx - s * dy;
712 dy = s * dx + c * dy;
720 if (i >= n) goto badargs;
722 Standard_Real vx = atof(a[i-1]);
723 Standard_Real vy = atof(a[i]);
724 length = Sqrt(vx*vx+vy*vy);
725 if (length > Precision::Confusion()) {
736 if (i >= n) goto badargs;
737 radius = atof(a[i-1]);
738 if (Abs(radius) > Precision::Confusion()) {
739 angle = atof(a[i]) * (M_PI / 180.0);
747 if (i >= n) goto badargs;
749 if ((a[i-1][1] == 'X') || (a[i-1][1] == 'x')) {
750 if (Abs(dx) < Precision::Confusion()) {
751 di << "Profile : cannot intersect, arg " << i-1;
754 length = (length - x) / dx;
757 else if ((a[i-1][1] == 'Y') || (a[i-1][1] == 'y')) {
758 if (Abs(dy) < Precision::Confusion()) {
759 di << "Profile : cannot intersect, arg " << i-1;
762 length = (length - y) / dy;
770 face = Standard_False;
771 if ((a[i][1] == 'W') || (a[i][1] == 'w')) {
772 close = Standard_False;
778 di <<"profile : unknown code " << a[i];
793 Handle(Geom2d_Line) l =
794 new Geom2d_Line(gp_Pnt2d(x,y),gp_Dir2d(dx,dy));
796 MW.Add(BRepBuilderAPI_MakeEdge(GeomAPI::To3d(l,P),0,length));
798 MW.Add(BRepBuilderAPI_MakeEdge(l,Surface,0,length));
806 Standard_Boolean sense = Standard_True;
813 gp_Ax2d ax(gp_Pnt2d(x-radius*dy,y+radius*dx),gp_Dir2d(dy,-dx));
818 Handle(Geom2d_Circle) c = new Geom2d_Circle(ax,radius,sense);
820 MW.Add(BRepBuilderAPI_MakeEdge(GeomAPI::To3d(c,P),0,angle));
822 MW.Add(BRepBuilderAPI_MakeEdge(c,Surface,0,angle));
839 stayfirst = Standard_False;
843 if ((i == n) && close) {
844 // the closing segment
847 length = Sqrt(dx*dx+dy*dy);
848 if (length > Precision::Confusion()) {
858 // get the result, face or wire
862 S = BRepBuilderAPI_MakeFace(P,MW.Wire());
864 BRepBuilderAPI_MakeFace MFace;
865 MFace.Init(Surface,Standard_False,Precision::Confusion());
866 MFace.Add(MW.Wire());
874 if (!TheLocation.IsIdentity())
878 Standard_Real Tol = 1.e-5;
879 BRepLib::BuildCurves3d(S,Tol);
887 di << "profile : bad number of arguments";
890 //=======================================================================
892 // command to build a profile
893 //=======================================================================
895 static Standard_Integer bsplineprof(Draw_Interpretor& di,
899 // this command build a profile
900 // from a moving point
905 //cout << " bsplineprof name [S face] [W WW] " << endl;
906 //cout << " for an edge : <digitizes> ... <mouse button 2> " << endl ;
907 //cout << " to end profile : <mouse button 3> " << endl ;
908 //cout << " Build a profile in the XY plane from digitizes" << endl ;
909 //cout << " By default the profile is closed and a face is built\n";
911 //cout << " W Make a closed wire\n";
912 //cout << " WW Make an open wire\n";
914 di << " bsplineprof name [S face] [W WW] " << "\n";
915 di << " for an edge : <digitizes> ... <mouse button 2> " << "\n";
916 di << " to end profile : <mouse button 3> " << "\n";
917 di << " Build a profile in the XY plane from digitizes" << "\n";
918 di << " By default the profile is closed and a face is built\n";
920 di << " W Make a closed wire\n";
921 di << " WW Make an open wire\n";
926 gp_Pnt2d last_point(0.0e0,
928 gp_Pnt2d first_point(0.0e0,
930 Standard_Integer i = 2,
932 // Standard_Real x0 = 0, y0 = 0, x = 0, y = 0, dx = 1, dy = 0;
933 Standard_Real x = 0, y = 0, dx = 1, dy = 0;
934 BRepBuilderAPI_MakeWire MW;
935 gp_Ax3 DummyHP(gp::XOY());
937 Standard_Boolean face = Standard_True;
938 Standard_Boolean close = Standard_True;
939 // Standard_Boolean first = Standard_True;
940 Standard_Boolean stayfirst = Standard_False;
941 Standard_Boolean isplanar = Standard_True;
942 Standard_Real length ;
944 TopLoc_Location TheLocation;
945 Handle(Geom_Surface) Surface;
955 TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE));
956 TopoDS_Face Face = TopoDS::Face(aLocalShape);
957 // TopoDS_Face Face = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE));
959 di << "profile : no face found";
962 Surface = BRep_Tool::Surface(Face,TheLocation);
963 Handle(Geom_Plane) Plane = Handle(Geom_Plane)::DownCast(Surface);
964 if ( Plane.IsNull()) {
965 isplanar = Standard_False;
970 stayfirst = Standard_True;
976 face = Standard_False;
977 if ((a[i][1] == 'W') || (a[i][1] == 'w')) {
978 close = Standard_False;
984 di <<"profile : unknown code " << a[i];
990 // to be done : close the profile using the first point of the contour
991 // and the point taken with mouse button 3
993 Handle(Geom2d_BSplineCurve) C ;
994 Handle(Geom_Curve) curve3d_ptr ;
995 Standard_Integer id, ii;
996 Standard_Integer X,Y,b, not_done;
997 Standard_Integer num_points = 0 ;
998 gp_Pnt2d a_point( 0.0e0,
1000 Handle(TColgp_HArray1OfPnt2d) points_array_ptr =
1001 new TColgp_HArray1OfPnt2d(1, 1);
1002 Handle(TColgp_HArray1OfPnt2d) new_points_array_ptr ;
1007 dout.Select(id,X,Y,b,wait);
1008 Standard_Real z = dout.Zoom(id);
1009 a_point.SetCoord(1,(Standard_Real)X /z) ;
1010 a_point.SetCoord(2,(Standard_Real)Y /z) ;
1011 if (num_points == 0) {
1013 new TColgp_HArray1OfPnt2d(1, 1);
1014 points_array_ptr->ChangeArray1()(1) = a_point ;
1015 first_point = a_point ;
1019 if (num_points >= 2) {
1020 new_points_array_ptr =
1021 new TColgp_HArray1OfPnt2d(1, num_points);
1022 for (ii = 1 ; ii <= num_points -1 ; ii++) {
1023 new_points_array_ptr->ChangeArray1()(ii) =
1024 points_array_ptr->Array1()(ii) ;
1026 new_points_array_ptr->ChangeArray1()(num_points) = a_point ;
1027 Geom2dAPI_Interpolate a2dInterpolator(new_points_array_ptr,
1030 a2dInterpolator.Perform() ;
1031 if (a2dInterpolator.IsDone()) {
1032 C = a2dInterpolator.Curve() ;
1034 GeomAPI::To3d(C,P) ;
1035 DrawTrSurf::Set(a[1], curve3d_ptr);
1036 dout.RepaintView(id);
1038 points_array_ptr = new_points_array_ptr ;
1042 if (b == 2 || b == 3) {
1043 if (num_points == 2) {
1044 x = last_point.Coord(1) ;
1045 y = last_point.Coord(2) ;
1046 dx = a_point.Coord(1) - x ;
1047 dy = a_point.Coord(2) - y ;
1048 gp_Vec2d a_vector(dx,
1050 length = a_vector.Magnitude() ;
1051 Handle(Geom2d_Line) l =
1052 new Geom2d_Line(gp_Pnt2d(x,y),gp_Dir2d(dx,dy));
1054 MW.Add(BRepBuilderAPI_MakeEdge(GeomAPI::To3d(l,P),0,length));
1057 MW.Add(BRepBuilderAPI_MakeEdge(l,Surface,0,length));
1061 else if (num_points > 2) {
1063 MW.Add(BRepBuilderAPI_MakeEdge(curve3d_ptr,
1064 curve3d_ptr->FirstParameter(),
1065 curve3d_ptr->LastParameter()));
1068 MW.Add(BRepBuilderAPI_MakeEdge(C,
1070 C->FirstParameter(),
1071 C->LastParameter()));
1074 if (num_points >= 2) {
1075 last_point = a_point ;
1076 points_array_ptr->ChangeArray1()(1) = a_point ;
1078 DBRep::Set(a[1], MW.Wire()) ;
1087 a_point = first_point ;
1090 x = last_point.Coord(1) ;
1091 y = last_point.Coord(2) ;
1092 dx = a_point.Coord(1) - x ;
1093 dy = a_point.Coord(2) - y ;
1094 gp_Vec2d a_vector(dx,
1096 length = a_vector.Magnitude() ;
1097 Handle(Geom2d_Line) l =
1098 new Geom2d_Line(gp_Pnt2d(x,y),gp_Dir2d(dx,dy));
1100 MW.Add(BRepBuilderAPI_MakeEdge(GeomAPI::To3d(l,P),0,length));
1102 MW.Add(BRepBuilderAPI_MakeEdge(l,Surface,0,length));
1106 S = BRepBuilderAPI_MakeFace(P,MW.Wire());
1108 BRepBuilderAPI_MakeFace MFace;
1109 MFace.Init(Surface,Standard_False,Precision::Confusion());
1110 MFace.Add(MW.Wire());
1118 if (!TheLocation.IsIdentity())
1119 S.Move(TheLocation);
1122 Standard_Real Tol = 1.e-5;
1123 BRepLib::BuildCurves3d(S,Tol);
1132 di << "profile : bad number of arguments";
1139 //=======================================================================
1141 // command to build a profile
1142 //=======================================================================
1144 static Standard_Integer profile2d(Draw_Interpretor& di,
1148 // this command build a profile with 2d curves.
1149 // from a moving point
1154 //cout << "profile name [code values] [code values] ...\n";
1155 //cout << " Build a profile in the UV plane from a moving point and direction\n";
1156 //cout << " The original point and direction are 0 0 and 1 0\n";
1157 //cout << " Codes and values describe the point or direction change\n";
1158 //cout << " When the point change the direction becomes the tangent\n";
1159 //cout << " All angles are in degree (may be negative)\n";
1160 //cout << " By default the profile is closed \n";
1162 //cout << " Instruction Parameters Action\n";
1163 //cout << " F X Y Set the first point\n";
1164 //cout << " X DX Translate point along X\n";
1165 //cout << " Y DY Translate point along Y\n";
1166 //cout << " L DL Translate point along direction\n";
1167 //cout << " XX X Set point X coordinate\n";
1168 //cout << " YY Y Set point Y coordinate\n";
1169 //cout << " T DX DY Translate point\n";
1170 //cout << " TT X Y Set point\n";
1171 //cout << " R Angle Rotate direction\n";
1172 //cout << " RR Angle Set direction\n";
1173 //cout << " D DX DY Set direction\n";
1174 //cout << " IX X Intersect with vertical\n";
1175 //cout << " IY Y Intersect with horizontal\n";
1176 //cout << " C Radius Angle Arc of circle tangent to direction\n";
1177 //cout << " W Make a closed wire\n";
1179 di << "profile name [code values] [code values] ...\n";
1180 di << " Build a profile in the UV plane from a moving point and direction\n";
1181 di << " The original point and direction are 0 0 and 1 0\n";
1182 di << " Codes and values describe the point or direction change\n";
1183 di << " When the point change the direction becomes the tangent\n";
1184 di << " All angles are in degree (may be negative)\n";
1185 di << " By default the profile is closed \n";
1187 di << " Instruction Parameters Action\n";
1188 di << " F X Y Set the first point\n";
1189 di << " X DX Translate point along X\n";
1190 di << " Y DY Translate point along Y\n";
1191 di << " L DL Translate point along direction\n";
1192 di << " XX X Set point X coordinate\n";
1193 di << " YY Y Set point Y coordinate\n";
1194 di << " T DX DY Translate point\n";
1195 di << " TT X Y Set point\n";
1196 di << " R Angle Rotate direction\n";
1197 di << " RR Angle Set direction\n";
1198 di << " D DX DY Set direction\n";
1199 di << " IX X Intersect with vertical\n";
1200 di << " IY Y Intersect with horizontal\n";
1201 di << " C Radius Angle Arc of circle tangent to direction\n";
1202 di << " W Make a closed wire\n";
1207 Standard_Integer i = 2, NbCurves = 0;
1208 Standard_Real x0 = 0, y0 = 0, x = 0, y = 0, dx = 1, dy = 0;
1209 enum {line , circle, none} move;
1210 Standard_Boolean close = Standard_True;
1211 Standard_Boolean first = Standard_True;
1212 Standard_Boolean stayfirst = Standard_False;
1213 char* name = new char[100];
1217 Standard_Real length=0,radius=0,angle=0;
1225 if (i >= n) goto badargs;
1227 di << "profile: The F instruction must precede all moves";
1230 x0 = x = atof(a[i-1]);
1231 y0 = y = atof(a[i]);
1232 stayfirst = Standard_True;
1238 if (i >= n) goto badargs;
1239 length = atof(a[i]);
1240 if ((a[i-1][1] == 'X') || (a[i-1][1] == 'x')) {
1250 if (i >= n) goto badargs;
1251 length = atof(a[i]);
1252 if ((a[i-1][1] == 'Y') || (a[i-1][1] == 'y')) {
1262 if (i >= n) goto badargs;
1263 length = atof(a[i]);
1270 if (i >= n) goto badargs;
1272 Standard_Real vx = atof(a[i-1]);
1273 Standard_Real vy = atof(a[i]);
1274 if ((a[i-2][1] == 'T') || (a[i-2][1] == 't')) {
1278 length = Sqrt(vx*vx+vy*vy);
1279 if (length > Precision::Confusion()) {
1290 if (i >= n) goto badargs;
1291 angle = atof(a[i]) * (M_PI / 180.0);
1292 if ((a[i-1][1] == 'R') || (a[i-1][1] == 'r')) {
1297 Standard_Real c = Cos(angle);
1298 Standard_Real s = Sin(angle);
1299 Standard_Real t = c * dx - s * dy;
1300 dy = s * dx + c * dy;
1308 if (i >= n) goto badargs;
1310 Standard_Real vx = atof(a[i-1]);
1311 Standard_Real vy = atof(a[i]);
1312 length = Sqrt(vx*vx+vy*vy);
1313 if (length > Precision::Confusion()) {
1324 if (i >= n) goto badargs;
1325 radius = atof(a[i-1]);
1326 if (Abs(radius) > Precision::Confusion()) {
1327 angle = atof(a[i]) * (M_PI / 180.0);
1335 if (i >= n) goto badargs;
1336 length = atof(a[i]);
1337 if ((a[i-1][1] == 'X') || (a[i-1][1] == 'x')) {
1338 if (Abs(dx) < Precision::Confusion()) {
1339 di << "Profile : cannot intersect, arg " << i-1;
1342 length = (length - x) / dx;
1345 else if ((a[i-1][1] == 'Y') || (a[i-1][1] == 'y')) {
1346 if (Abs(dy) < Precision::Confusion()) {
1347 di << "Profile : cannot intersect, arg " << i-1;
1350 length = (length - y) / dy;
1358 close = Standard_False;
1363 di <<"profile : unknown code " << a[i];
1378 Handle(Geom2d_Line) l = new Geom2d_Line(gp_Pnt2d(x,y),gp_Dir2d(dx,dy));
1379 Handle(Geom2d_TrimmedCurve) ct =
1380 new Geom2d_TrimmedCurve(l,0,length);
1382 sprintf(name,"%s_%d",a[1],NbCurves);
1383 DrawTrSurf::Set(name,ct);
1384 di.AppendElement(name);
1392 Standard_Boolean sense = Standard_True;
1399 gp_Ax2d ax(gp_Pnt2d(x-radius*dy,y+radius*dx),gp_Dir2d(dy,-dx));
1404 Handle(Geom2d_Circle) c = new Geom2d_Circle(ax,radius,sense);
1405 Handle(Geom2d_TrimmedCurve) ct =
1406 new Geom2d_TrimmedCurve(c,0,angle);
1408 sprintf(name,"%s_%d",a[1],NbCurves);
1409 DrawTrSurf::Set(name,ct);
1410 di.AppendElement(name);
1416 dx = v.X() / radius;
1417 dy = v.Y() / radius;
1427 stayfirst = Standard_False;
1431 if ((i == n) && close) {
1432 // the closing segment
1435 length = Sqrt(dx*dx+dy*dy);
1436 if (length > Precision::Confusion()) {
1446 Draw::Set(aName, x);
1448 Draw::Set(aName, y);
1450 Draw::Set(aName, dx);
1452 Draw::Set(aName, dy);
1457 di << "profile : bad number of arguments";
1463 //=======================================================================
1464 //function : mkoffset
1466 //=======================================================================
1468 Standard_Integer mkoffset(Draw_Interpretor& di,
1469 Standard_Integer n, const char** a)
1471 if (n < 5) return 1;
1474 BRepOffsetAPI_MakeOffset Paral;
1475 TopoDS_Shape Base = DBRep::Get(a[2],TopAbs_FACE);
1477 if ( Base.IsNull()) {
1478 Base = DBRep::Get(a[2]);
1479 if (Base.IsNull()) return 1;
1480 Paral.Init(GeomAbs_Arc);
1481 TopExp_Explorer exp;
1482 for (exp.Init(Base,TopAbs_WIRE); exp.More(); exp.Next()) {
1483 TopoDS_Wire aLocalShape = TopoDS::Wire(exp.Current());
1484 Paral.AddWire(aLocalShape);
1485 // Paral.AddWire(TopoDS::Wire(exp.Current()));
1489 Base.Orientation(TopAbs_FORWARD);
1490 // Base = TopoDS::Face(Base.Oriented(TopAbs_FORWARD));
1491 Paral.Init(TopoDS::Face(Base));
1494 Standard_Real U, dU;
1495 Standard_Integer Nb;
1499 Standard_Real Alt = 0.;
1500 if ( n == 6) Alt = atof(a[5]);
1501 Standard_Integer Compt = 1;
1503 for ( Standard_Integer i = 1; i <= Nb; i++) {
1505 Paral.Perform(U,Alt);
1506 if ( !Paral.IsDone()) {
1507 //cout << " Parali aux fraises" << endl;
1508 di << " Parali aux fraises" << "\n";
1511 sprintf(name,"%s_%d", a[1], Compt++);
1512 char* temp = name; // portage WNT
1513 DBRep::Set(temp,Paral.Shape());
1519 //=======================================================================
1520 //function : pickface
1522 //=======================================================================
1524 Standard_Integer pickface(Draw_Interpretor& di,
1525 Standard_Integer , const char** )
1527 Standard_CString pick_name=".";
1529 TopoDS_Shape S = DBRep::Get(pick_name,TopAbs_FACE);
1530 if (S.IsNull()) return 1;
1532 char* name = new char[100];
1533 sprintf(name,"PickedFace %s",pick_name);
1535 di.AppendElement(name);
1540 Standard_Integer edgeintersector(Draw_Interpretor& di,
1541 Standard_Integer n, const char** a)
1543 if (n < 5) return 1;
1546 TopoDS_Shape aLocalShape(DBRep::Get(a[2],TopAbs_EDGE));
1547 E[0] = TopoDS::Edge(aLocalShape);
1548 // E[0] = TopoDS::Edge(DBRep::Get(a[2],TopAbs_EDGE));
1549 if ( E[0].IsNull()) return 1;
1550 aLocalShape = DBRep::Get(a[3],TopAbs_EDGE);
1551 E[1] = TopoDS::Edge(aLocalShape);
1552 // E[1] = TopoDS::Edge(DBRep::Get(a[3],TopAbs_EDGE));
1553 if ( E[1].IsNull()) return 1;
1554 aLocalShape = DBRep::Get(a[4],TopAbs_FACE);
1555 TopoDS_Face F = TopoDS::Face(aLocalShape);
1556 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[4],TopAbs_FACE));
1557 if ( F.IsNull()) return 1;
1559 TopOpeBRep_EdgesIntersector EInter;
1561 //------------------------------------------------------
1562 // Calculate point of intersection 2D
1563 //-----------------------------------------------------
1564 EInter.SetFaces(F,F);
1565 Standard_Real TolInter = 1.e-7;
1566 if (n == 6) TolInter = atof(a[5]);
1567 EInter.ForceTolerances(TolInter,TolInter);
1568 Standard_Boolean reducesegments = Standard_True;
1569 EInter.Perform (E[0],E[1],reducesegments);
1571 if (EInter.IsEmpty()) {
1572 //cout << " No intersection found" << endl;
1573 di << " No intersection found" << "\n";
1579 Standard_Integer NbV = 0;
1580 Standard_Real Tol = Precision::PConfusion();
1582 Standard_Boolean rejectreducedsegmentpoints = Standard_True;
1583 EInter.InitPoint(rejectreducedsegmentpoints);
1584 for (;EInter.MorePoint();EInter.NextPoint()) {
1585 const TopOpeBRep_Point2d& P2D = EInter.Point();
1586 gp_Pnt P = P2D.Value();
1587 TopoDS_Vertex V = BRepLib_MakeVertex(P);
1589 sprintf(name,"%s_%d",a[1],NbV);
1591 for (Standard_Integer i = 1; i <= 2; i++) {
1592 //---------------------------------------------------------------
1593 // to be able to rank parameter on edge
1594 // it is necessary to code it internally
1595 //---------------------------------------------------------------
1596 Standard_Real U = P2D.Parameter(i);
1598 V.Orientation(TopAbs_INTERNAL);
1599 B.UpdateVertex(V,U,E[i-1],Tol);
1600 // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)),
1602 //---------------------------------------------------------------
1603 // Orientation of vertex in the transition.
1604 //---------------------------------------------------------------
1605 TopAbs_Orientation OO = TopAbs_REVERSED;
1606 if (P2D.IsVertex(i)) {
1607 OO = P2D.Vertex(i).Orientation();
1609 else if (P2D.Transition(i).Before() == TopAbs_OUT) {
1610 OO = TopAbs_FORWARD;
1612 //cout << " Orientation of vertex " << NbV << " on " << a[i+1] << ": ";
1613 di << " Orientation of vertex " << NbV << " on " << a[i+1] << ": ";
1614 if (OO == TopAbs_FORWARD) {
1615 //cout << "FORWARD" << endl;
1616 di << "FORWARD" << "\n";
1618 //cout << "REVERSED" << endl;
1619 di << "REVERSED" << "\n";
1627 //=======================================================================
1628 //function : concatwire
1629 //purpose : reduce the multiply degree of the knots to the minimum without
1630 // changing the geometry
1631 //=======================================================================
1633 static Standard_Integer concatwire(Draw_Interpretor&, Standard_Integer n, const char** c)
1634 { GeomAbs_Shape Option=GeomAbs_C1;
1636 if ( n < 3 ) return 1;
1638 if(n==4) //check if it's C1 or G1
1639 if (! strcmp(c[3],"G1"))
1642 TopoDS_Shape S = DBRep::Get(c[2],TopAbs_WIRE) ;
1644 if (S.IsNull()) return 1 ; //test if the shape is empty
1646 TopoDS_Wire W = TopoDS::Wire(S) ;
1650 res=BRepAlgo::ConcatenateWire(W,Option); //processing
1651 DBRep::Set(c[1],res);
1655 //=======================================================================
1656 //function : build3d
1658 //=======================================================================
1660 Standard_Integer build3d(Draw_Interpretor& di,
1661 Standard_Integer n, const char** a)
1664 if ( (n <2) || (n>3) ) {
1665 //cout << " 1 or 2 arguments expected" << endl;
1666 di << " 1 or 2 arguments expected" << "\n";
1670 Standard_Boolean Ok;
1671 TopoDS_Shape S = DBRep::Get(a[1],TopAbs_FACE);
1672 if (S.IsNull()) return 1;
1674 if (n==2) { Ok = BRepLib::BuildCurves3d(S); }
1675 else { Ok = BRepLib::BuildCurves3d(S,atof(a[2])); }
1676 //if (!Ok) {cout << " one of the computation failed" << endl;}
1677 if (!Ok) {di << " one of the computation failed" << "\n";}
1683 //=======================================================================
1684 //function : CurveCommands
1686 //=======================================================================
1688 void BRepTest::CurveCommands(Draw_Interpretor& theCommands)
1690 static Standard_Boolean done = Standard_False;
1692 done = Standard_True;
1694 DBRep::BasicCommands(theCommands);
1695 GeometryTest::CurveCommands(theCommands);
1697 const char* g = "TOPOLOGY Curve topology commands";
1699 theCommands.Add("vertex",
1700 "vertex name [x y z / p edge]",__FILE__,
1703 theCommands.Add("etrim",
1704 "etrim edge v1 [v2]",__FILE__,
1707 theCommands.Add("range",
1708 "range edge [face] first last",__FILE__,
1711 theCommands.Add("polyline",
1712 "polyline name x1 y1 z1 x2 y2 z2 ...",__FILE__,
1715 theCommands.Add("polyvertex",
1716 "polyvertex name v1 v2 ...",__FILE__,
1719 theCommands.Add("wire",
1720 "wire wirename e1/w1 [e2/w2 ...]",__FILE__,
1723 theCommands.Add("profile",
1724 "profile, no args to get help",__FILE__,
1727 theCommands.Add("bsplineprof",
1728 "bsplineprof, no args to get help",__FILE__,
1731 theCommands.Add("2dprofile",
1732 "2dprofile, no args to get help",__FILE__,
1735 theCommands.Add("mkoffset",
1736 "mkoffset result face/compound of wires nboffset stepoffset [alt]",__FILE__,
1740 theCommands.Add("mkedge",
1741 "mkedge edge curve [surface] [pfirst plast] [vfirst [pfirst] vlast [plast]] ",__FILE__,
1744 theCommands.Add("mkcurve",
1745 "mkcurve curve edge",__FILE__,
1748 theCommands.Add("mkoricurve",
1749 "mkoricurve curve edge: \n the curve is colored according to the orientation of the edge",
1753 theCommands.Add("mk2dcurve",
1754 "mk2dcurve curve edge [face]",__FILE__,
1757 theCommands.Add("mkpoint",
1758 "mkpoint point vertex",__FILE__,
1761 theCommands.Add("uisoedge",
1762 "uisoedge edge face u v1 v2",__FILE__,
1765 theCommands.Add("edge",
1766 "edge edgename v1 v2",__FILE__,
1769 theCommands.Add("visoedge",
1770 "visoedge edge face v u1 u2",__FILE__,
1773 theCommands.Add("transfert",
1774 "transfert edge1 edge2",__FILE__,
1777 theCommands.Add("pickface",
1778 "pickface",__FILE__,
1781 theCommands.Add("edgeintersector",
1782 "edgeintersector r E1 E2 F [Tol]",__FILE__,
1785 theCommands.Add("build3d",
1789 theCommands.Add("concatwire",
1790 "concatwire result wire [option](G1/C1)",