1 // Created on: 1996-06-03
2 // Created by: Denis PASCAL
3 // Copyright (c) 1996-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.
19 #include <DrawDim.hxx>
21 #include <Draw_Interpretor.hxx>
22 #include <Draw_Appli.hxx>
23 #include <BRep_Tool.hxx>
27 #include <DrawDim_PlanarDistance.hxx>
28 #include <DrawDim_PlanarRadius.hxx>
29 #include <DrawDim_PlanarAngle.hxx>
30 #include <TopoDS_Vertex.hxx>
31 #include <TopoDS_Edge.hxx>
34 #include <Geom_Curve.hxx>
35 #include <Geom_Circle.hxx>
36 #include <BRep_Builder.hxx>
38 #include <gp_Circ.hxx>
39 #include <TopTools_MapOfShape.hxx>
40 #include <TopExp_Explorer.hxx>
43 #include <DrawTrSurf.hxx>
49 //=======================================================================
50 //function : DrawDim_DISTANCE
52 //=======================================================================
54 static Standard_Integer DrawDim_DISTANCE (Draw_Interpretor& di,
59 di << "distance (name, profile[face],point1[vertex],point2[vertex])\n";
60 di << "distance (name, profile[face],line1[edge],line2[edge])\n";
61 di << "distance (name, profile[face],line[edge],point[vertex])\n";
64 Handle(DrawDim_PlanarDistance) DIST;
66 TopoDS_Shape aLocalShape = DBRep::Get(arg[2],TopAbs_FACE);
67 TopoDS_Face plan = TopoDS::Face(aLocalShape);
68 // TopoDS_Face plan = TopoDS::Face(DBRep::Get(arg[2],TopAbs_FACE));
69 TopoDS_Shape geom1 = DBRep::Get(arg[3]);
70 TopoDS_Shape geom2 = DBRep::Get(arg[4]);
71 if (!plan.IsNull() && !geom1.IsNull() && !geom2.IsNull()) {
72 if (geom1.ShapeType() == TopAbs_VERTEX && geom2.ShapeType() == TopAbs_VERTEX) {
73 DIST = new DrawDim_PlanarDistance(TopoDS::Vertex(geom1),TopoDS::Vertex(geom2));
75 else if (geom1.ShapeType() == TopAbs_VERTEX && geom2.ShapeType() == TopAbs_EDGE) {
76 DIST = new DrawDim_PlanarDistance(TopoDS::Vertex(geom1),TopoDS::Edge(geom2));
78 else if (geom1.ShapeType() == TopAbs_EDGE && geom2.ShapeType() == TopAbs_EDGE) {
79 DIST = new DrawDim_PlanarDistance(TopoDS::Edge(geom1),TopoDS::Edge(geom2));
82 Draw::Set(arg[1],DIST);
88 di << "DrawDim_DISTANCE : error\n";
93 //=======================================================================
94 //function : DrawDim_ANGLE
96 //=======================================================================
98 static Standard_Integer DrawDim_ANGLE (Draw_Interpretor& di,
103 di << "angle (name, profile[face],line1[edge],line2[edge])\n";
106 Handle(DrawDim_PlanarAngle) DIST;
108 TopoDS_Shape aLocalShape = DBRep::Get(arg[2],TopAbs_FACE);
109 TopoDS_Face plan = TopoDS::Face(aLocalShape);
110 aLocalShape = DBRep::Get(arg[3],TopAbs_EDGE);
111 TopoDS_Edge line1 = TopoDS::Edge(aLocalShape);
112 aLocalShape = DBRep::Get(arg[4],TopAbs_EDGE);
113 TopoDS_Edge line2 = TopoDS::Edge(aLocalShape);
114 // TopoDS_Face plan = TopoDS::Face(DBRep::Get(arg[2],TopAbs_FACE));
115 // TopoDS_Edge line1 = TopoDS::Edge(DBRep::Get(arg[3],TopAbs_EDGE));
116 // TopoDS_Edge line2 = TopoDS::Edge(DBRep::Get(arg[4],TopAbs_EDGE));
117 if (!plan.IsNull() && !line1.IsNull() && !line2.IsNull()) {
118 DIST = new DrawDim_PlanarAngle(plan,line1,line2);
120 if (!DIST.IsNull()) {
121 Draw::Set(arg[1],DIST);
126 di << "DrawDim_PlanarAngle : error\n";
130 //=======================================================================
131 //function : DrawDim_RADIUS
133 //=======================================================================
135 static Standard_Integer DrawDim_RADIUS (Draw_Interpretor& di,
140 di << "radius (name, profile[face],cercle[edge])\n";
143 Handle(DrawDim_PlanarRadius) DIST;
145 TopoDS_Shape aLocalShape = DBRep::Get(arg[2],TopAbs_FACE);
146 TopoDS_Face plan = TopoDS::Face(aLocalShape);
147 aLocalShape = DBRep::Get(arg[3],TopAbs_EDGE);
148 TopoDS_Edge cercle = TopoDS::Edge(aLocalShape);
149 // TopoDS_Face plan = TopoDS::Face(DBRep::Get(arg[2],TopAbs_FACE));
150 // TopoDS_Edge cercle = TopoDS::Edge(DBRep::Get(arg[3],TopAbs_EDGE));
151 if (!plan.IsNull() && !cercle.IsNull()) {
152 DIST = new DrawDim_PlanarRadius(cercle);
155 if (!DIST.IsNull()) {
156 Draw::Set(arg[1],DIST);
160 di << "DrawDim_PlanarRadius : error\n";
165 //=======================================================================
166 //function : DrawDim_CENTER
168 //=======================================================================
170 static Standard_Integer DrawDim_CENTER (Draw_Interpretor& di,
175 TopoDS_Shape aLocalShape = DBRep::Get(arg[2],TopAbs_EDGE);
176 TopoDS_Edge edge = TopoDS::Edge(aLocalShape);
177 // TopoDS_Edge edge = TopoDS::Edge(DBRep::Get(arg[2],TopAbs_EDGE));
179 Handle(Geom_Curve) curve = BRep_Tool::Curve (edge,f,l);
180 if (curve->IsKind(STANDARD_TYPE(Geom_Circle))) {
181 gp_Circ circle = Handle(Geom_Circle)::DownCast(curve)->Circ();
182 gp_Pnt center = circle.Location ();
183 //:abv: avoid dependence on TKTopAlgo
185 // = BRepBuilderAPI_MakeVertex (center);
187 B.MakeVertex(vc,center,Precision::Confusion());
188 DBRep::Set(arg[1],vc);
192 di << "DrawDim_CENTER : error\n";
197 //=======================================================================
198 //function : DrawDim_VARIABLES
200 //=======================================================================
202 static Standard_Integer DrawDim_VARIABLES (Draw_Interpretor& di,
206 if (n != 2) return 1;
207 TopoDS_Shape aLocalShape = DBRep::Get(a[1],TopAbs_FACE);
208 TopoDS_Face F = TopoDS::Face(aLocalShape);
209 // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[1],TopAbs_FACE));
210 if (F.IsNull()) return 0;
212 Standard_Integer i = 0;
214 TopTools_MapOfShape M;
216 TopExp_Explorer ex (F,TopAbs_EDGE);
218 if (M.Add(ex.Current())) {
219 TopExp::Vertices(TopoDS::Edge(ex.Current()),vf,vl);
222 char* p = (char *)malloc(100);
223 Sprintf(p,"%s_%dv",a[1],i);
226 DrawDim::DrawShapeName (vf,p);
230 char *p = (char *)malloc(100);
231 Sprintf(p,"%s_%dv",a[1],i);
234 DrawDim::DrawShapeName (vl,p);
237 char *p = (char *)malloc(100);
238 Sprintf(p,"%s_%de",a[1],i);
239 DBRep::Set(p,ex.Current());
241 DrawDim::DrawShapeName (ex.Current(),p);
248 //=======================================================================
249 //function : DrawDim_SPLACEMENT
251 //=======================================================================
253 static Standard_Integer DrawDim_SPLACEMENT (Draw_Interpretor& di,
258 TopoDS_Shape shape = DBRep::Get(a[1]);
259 TopoDS_Shape aLocalShape = DBRep::Get(a[2],TopAbs_FACE);
260 TopoDS_Face from = TopoDS::Face(aLocalShape);
261 aLocalShape = DBRep::Get(a[3],TopAbs_FACE);
262 TopoDS_Face to = TopoDS::Face(aLocalShape);
263 // TopoDS_Face from = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE));
264 // TopoDS_Face to = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE));
265 if (!shape.IsNull() && !from.IsNull() && !to.IsNull()) {
267 DrawDim::Pln(from,pfrom);
268 DrawDim::Pln(to,pto);
269 gp_Ax3 axfrom (pfrom.Position());
270 gp_Ax3 axto (pto.Position());
272 trsf.SetDisplacement(axfrom,axto);
273 TopLoc_Location move (trsf);
275 DBRep::Set(a[1],shape);
279 di << "DrawDim_SPlacement : error\n";
283 //=======================================================================
284 //function : DrawDim_GPLACEMENT
286 //=======================================================================
288 static Standard_Integer DrawDim_GPLACEMENT (Draw_Interpretor& di,
293 Handle(Geom_Geometry) geom = DrawTrSurf::Get(a[1]);
294 TopoDS_Shape aLocalShape = DBRep::Get(a[2],TopAbs_FACE);
295 TopoDS_Face from = TopoDS::Face(aLocalShape);
296 aLocalShape = DBRep::Get(a[3],TopAbs_FACE);
297 TopoDS_Face to = TopoDS::Face(aLocalShape);
298 // TopoDS_Face from = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE));
299 // TopoDS_Face to = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE));
300 if (!geom.IsNull() && !from.IsNull() && !to.IsNull()) {
302 DrawDim::Pln(from,pfrom);
303 DrawDim::Pln(to,pto);
304 gp_Ax3 axfrom (pfrom.Position());
305 gp_Ax3 axto (pto.Position());
307 trsf.SetDisplacement(axfrom,axto);
308 Handle(Geom_Geometry) newgeom = geom->Transformed(trsf);
309 DrawTrSurf::Set(a[1],newgeom);
313 di << "DrawDim_Placement : error\n";
318 //=======================================================================
319 //function : PlanarDimensionCommands
321 //=======================================================================
323 void DrawDim::PlanarDimensionCommands (Draw_Interpretor& theCommands)
326 theCommands.Add ("distance",
327 "distance,no args to get help",
328 __FILE__, DrawDim_DISTANCE);
330 theCommands.Add ("radius",
331 "radius, no args to get help",
332 __FILE__, DrawDim_RADIUS);
334 theCommands.Add ("angle",
335 "angle, no args to get help",
336 __FILE__, DrawDim_ANGLE);
338 theCommands.Add ("center",
339 "to extract center of a circle : center ,name, circle",
340 __FILE__, DrawDim_CENTER);
342 theCommands.Add ("variables",
343 "to extract variables of a face",
344 __FILE__, DrawDim_VARIABLES);
346 theCommands.Add ("splacement",
347 "to move shape from face to face",
348 __FILE__, DrawDim_SPLACEMENT);
350 theCommands.Add ("gplacement",
351 "to move geometry from face to face",
352 __FILE__, DrawDim_GPLACEMENT);