b311480e |
1 | // Created on: 1996-06-03 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <stdio.h> |
18 | |
19 | #include <DrawDim.hxx> |
20 | |
21 | #include <Draw_Interpretor.hxx> |
22 | #include <Draw_Appli.hxx> |
23 | #include <BRep_Tool.hxx> |
24 | #include <DBRep.hxx> |
25 | #include <Draw.hxx> |
26 | #include <DBRep.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> |
32 | #include <TopoDS.hxx> |
33 | #include <TopExp.hxx> |
34 | #include <Geom_Curve.hxx> |
35 | #include <Geom_Circle.hxx> |
36 | #include <BRep_Builder.hxx> |
37 | #include <gp_Pnt.hxx> |
38 | #include <gp_Circ.hxx> |
39 | #include <TopTools_MapOfShape.hxx> |
40 | #include <TopExp_Explorer.hxx> |
41 | #include <TopoDS_Iterator.hxx> |
42 | #include <gp_Ax3.hxx> |
43 | #include <gp_Pln.hxx> |
44 | #include <DrawTrSurf.hxx> |
57c28b61 |
45 | #ifdef _MSC_VER |
7fd59977 |
46 | #include <stdio.h> |
47 | #endif |
48 | //======================================================================= |
49 | //function : DrawDim_DISTANCE |
50 | //purpose : |
51 | //======================================================================= |
52 | |
53 | static Standard_Integer DrawDim_DISTANCE (Draw_Interpretor& di, |
54 | Standard_Integer nb, |
55 | const char** arg) |
56 | { |
57 | if (nb == 1) { |
58 | di << "distance (name, profile[face],point1[vertex],point2[vertex])\n"; |
59 | di << "distance (name, profile[face],line1[edge],line2[edge])\n"; |
60 | di << "distance (name, profile[face],line[edge],point[vertex])\n"; |
61 | } |
62 | else { |
63 | Handle(DrawDim_PlanarDistance) DIST; |
64 | if (nb == 5) { |
65 | TopoDS_Shape aLocalShape = DBRep::Get(arg[2],TopAbs_FACE); |
66 | TopoDS_Face plan = TopoDS::Face(aLocalShape); |
67 | // TopoDS_Face plan = TopoDS::Face(DBRep::Get(arg[2],TopAbs_FACE)); |
68 | TopoDS_Shape geom1 = DBRep::Get(arg[3]); |
69 | TopoDS_Shape geom2 = DBRep::Get(arg[4]); |
70 | if (!plan.IsNull() && !geom1.IsNull() && !geom2.IsNull()) { |
71 | if (geom1.ShapeType() == TopAbs_VERTEX && geom2.ShapeType() == TopAbs_VERTEX) { |
72 | DIST = new DrawDim_PlanarDistance(TopoDS::Vertex(geom1),TopoDS::Vertex(geom2)); |
73 | } |
74 | else if (geom1.ShapeType() == TopAbs_VERTEX && geom2.ShapeType() == TopAbs_EDGE) { |
75 | DIST = new DrawDim_PlanarDistance(TopoDS::Vertex(geom1),TopoDS::Edge(geom2)); |
76 | } |
77 | else if (geom1.ShapeType() == TopAbs_EDGE && geom2.ShapeType() == TopAbs_EDGE) { |
78 | DIST = new DrawDim_PlanarDistance(TopoDS::Edge(geom1),TopoDS::Edge(geom2)); |
79 | } |
80 | if (!DIST.IsNull()) { |
81 | Draw::Set(arg[1],DIST); |
82 | return 0; |
83 | } |
84 | } |
85 | } |
86 | } |
87 | di << "DrawDim_DISTANCE : error" << "\n"; |
88 | return 1; |
89 | } |
90 | |
91 | |
92 | //======================================================================= |
93 | //function : DrawDim_ANGLE |
94 | //purpose : |
95 | //======================================================================= |
96 | |
97 | static Standard_Integer DrawDim_ANGLE (Draw_Interpretor& di, |
98 | Standard_Integer nb, |
99 | const char** arg) |
100 | { |
101 | if (nb == 1) { |
102 | di << "angle (name, profile[face],line1[edge],line2[edge])\n"; |
103 | } |
104 | else { |
105 | Handle(DrawDim_PlanarAngle) DIST; |
106 | if (nb == 5) { |
107 | TopoDS_Shape aLocalShape = DBRep::Get(arg[2],TopAbs_FACE); |
108 | TopoDS_Face plan = TopoDS::Face(aLocalShape); |
109 | aLocalShape = DBRep::Get(arg[3],TopAbs_EDGE); |
110 | TopoDS_Edge line1 = TopoDS::Edge(aLocalShape); |
111 | aLocalShape = DBRep::Get(arg[4],TopAbs_EDGE); |
112 | TopoDS_Edge line2 = TopoDS::Edge(aLocalShape); |
113 | // TopoDS_Face plan = TopoDS::Face(DBRep::Get(arg[2],TopAbs_FACE)); |
114 | // TopoDS_Edge line1 = TopoDS::Edge(DBRep::Get(arg[3],TopAbs_EDGE)); |
115 | // TopoDS_Edge line2 = TopoDS::Edge(DBRep::Get(arg[4],TopAbs_EDGE)); |
116 | if (!plan.IsNull() && !line1.IsNull() && !line2.IsNull()) { |
117 | DIST = new DrawDim_PlanarAngle(plan,line1,line2); |
118 | } |
119 | if (!DIST.IsNull()) { |
120 | Draw::Set(arg[1],DIST); |
121 | return 0; |
122 | } |
123 | } |
124 | } |
125 | di << "DrawDim_PlanarAngle : error" << "\n"; |
126 | return 1; |
127 | } |
128 | |
129 | //======================================================================= |
130 | //function : DrawDim_RADIUS |
131 | //purpose : |
132 | //======================================================================= |
133 | |
134 | static Standard_Integer DrawDim_RADIUS (Draw_Interpretor& di, |
135 | Standard_Integer nb, |
136 | const char** arg) |
137 | { |
138 | if (nb == 1) { |
139 | di << "radius (name, profile[face],cercle[edge])\n"; |
140 | } |
141 | else { |
142 | Handle(DrawDim_PlanarRadius) DIST; |
143 | if (nb == 4) { |
144 | TopoDS_Shape aLocalShape = DBRep::Get(arg[2],TopAbs_FACE); |
145 | TopoDS_Face plan = TopoDS::Face(aLocalShape); |
146 | aLocalShape = DBRep::Get(arg[3],TopAbs_EDGE); |
147 | TopoDS_Edge cercle = TopoDS::Edge(aLocalShape); |
148 | // TopoDS_Face plan = TopoDS::Face(DBRep::Get(arg[2],TopAbs_FACE)); |
149 | // TopoDS_Edge cercle = TopoDS::Edge(DBRep::Get(arg[3],TopAbs_EDGE)); |
150 | if (!plan.IsNull() && !cercle.IsNull()) { |
151 | DIST = new DrawDim_PlanarRadius(cercle); |
152 | } |
153 | } |
154 | if (!DIST.IsNull()) { |
155 | Draw::Set(arg[1],DIST); |
156 | return 0; |
157 | } |
158 | } |
159 | di << "DrawDim_PlanarRadius : error" << "\n"; |
160 | return 1; |
161 | } |
162 | |
163 | |
164 | //======================================================================= |
165 | //function : DrawDim_CENTER |
166 | //purpose : |
167 | //======================================================================= |
168 | |
169 | static Standard_Integer DrawDim_CENTER (Draw_Interpretor& di, |
170 | Standard_Integer nb, |
171 | const char** arg) |
172 | { |
173 | if (nb == 3) { |
174 | TopoDS_Shape aLocalShape = DBRep::Get(arg[2],TopAbs_EDGE); |
175 | TopoDS_Edge edge = TopoDS::Edge(aLocalShape); |
176 | // TopoDS_Edge edge = TopoDS::Edge(DBRep::Get(arg[2],TopAbs_EDGE)); |
177 | Standard_Real f,l; |
178 | Handle(Geom_Curve) curve = BRep_Tool::Curve (edge,f,l); |
179 | if (curve->IsKind(STANDARD_TYPE(Geom_Circle))) { |
180 | gp_Circ circle = Handle(Geom_Circle)::DownCast(curve)->Circ(); |
181 | gp_Pnt center = circle.Location (); |
182 | //:abv: avoid dependence on TKTopAlgo |
183 | TopoDS_Vertex vc; |
184 | // = BRepBuilderAPI_MakeVertex (center); |
185 | BRep_Builder B; |
186 | B.MakeVertex(vc,center,Precision::Confusion()); |
187 | DBRep::Set(arg[1],vc); |
188 | return 0; |
189 | } |
190 | } |
191 | di << "DrawDim_CENTER : error" << "\n"; |
192 | return 1; |
193 | } |
194 | |
195 | |
196 | //======================================================================= |
197 | //function : DrawDim_VARIABLES |
198 | //purpose : |
199 | //======================================================================= |
200 | |
201 | static Standard_Integer DrawDim_VARIABLES (Draw_Interpretor& di, |
202 | Standard_Integer n, |
203 | const char** a) |
204 | { |
205 | if (n != 2) return 1; |
206 | TopoDS_Shape aLocalShape = DBRep::Get(a[1],TopAbs_FACE); |
207 | TopoDS_Face F = TopoDS::Face(aLocalShape); |
208 | // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[1],TopAbs_FACE)); |
209 | if (F.IsNull()) return 0; |
210 | |
211 | Standard_Integer i = 0; |
212 | TopoDS_Vertex vf,vl; |
213 | TopTools_MapOfShape M; |
214 | M.Add(F); |
215 | TopExp_Explorer ex (F,TopAbs_EDGE); |
216 | while (ex.More()) { |
217 | if (M.Add(ex.Current())) { |
218 | TopExp::Vertices(TopoDS::Edge(ex.Current()),vf,vl); |
219 | if (M.Add(vf)) { |
220 | i++; |
221 | char* p = (char *)malloc(100); |
91322f44 |
222 | Sprintf(p,"%s_%dv",a[1],i); |
7fd59977 |
223 | DBRep::Set(p,vf); |
224 | di.AppendElement(p); |
225 | DrawDim::DrawShapeName (vf,p); |
226 | } |
227 | if (M.Add(vl)) { |
228 | i++; |
229 | char *p = (char *)malloc(100); |
91322f44 |
230 | Sprintf(p,"%s_%dv",a[1],i); |
7fd59977 |
231 | DBRep::Set(p,vl); |
232 | di.AppendElement(p); |
233 | DrawDim::DrawShapeName (vl,p); |
234 | } |
235 | i++; |
236 | char *p = (char *)malloc(100); |
91322f44 |
237 | Sprintf(p,"%s_%de",a[1],i); |
7fd59977 |
238 | DBRep::Set(p,ex.Current()); |
239 | di.AppendElement(p); |
240 | DrawDim::DrawShapeName (ex.Current(),p); |
241 | } |
242 | ex.Next(); |
243 | } |
244 | return 0; |
245 | } |
246 | |
247 | //======================================================================= |
248 | //function : DrawDim_SPLACEMENT |
249 | //purpose : |
250 | //======================================================================= |
251 | |
252 | static Standard_Integer DrawDim_SPLACEMENT (Draw_Interpretor& di, |
253 | Standard_Integer n, |
254 | const char** a) |
255 | { |
256 | if (n == 4) { |
257 | TopoDS_Shape shape = DBRep::Get(a[1]); |
258 | TopoDS_Shape aLocalShape = DBRep::Get(a[2],TopAbs_FACE); |
259 | TopoDS_Face from = TopoDS::Face(aLocalShape); |
260 | aLocalShape = DBRep::Get(a[3],TopAbs_FACE); |
261 | TopoDS_Face to = TopoDS::Face(aLocalShape); |
262 | // TopoDS_Face from = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE)); |
263 | // TopoDS_Face to = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE)); |
264 | if (!shape.IsNull() && !from.IsNull() && !to.IsNull()) { |
265 | gp_Pln pfrom,pto; |
266 | DrawDim::Pln(from,pfrom); |
267 | DrawDim::Pln(to,pto); |
268 | gp_Ax3 axfrom (pfrom.Position()); |
269 | gp_Ax3 axto (pto.Position()); |
270 | gp_Trsf trsf; |
271 | trsf.SetDisplacement(axfrom,axto); |
272 | TopLoc_Location move (trsf); |
273 | shape.Move(move); |
274 | DBRep::Set(a[1],shape); |
275 | return 0; |
276 | } |
277 | } |
278 | di << "DrawDim_SPlacement : error" << "\n"; |
279 | return 1; |
280 | } |
281 | |
282 | //======================================================================= |
283 | //function : DrawDim_GPLACEMENT |
284 | //purpose : |
285 | //======================================================================= |
286 | |
287 | static Standard_Integer DrawDim_GPLACEMENT (Draw_Interpretor& di, |
288 | Standard_Integer n, |
289 | const char** a) |
290 | { |
291 | if (n == 4) { |
292 | Handle(Geom_Geometry) geom = DrawTrSurf::Get(a[1]); |
293 | TopoDS_Shape aLocalShape = DBRep::Get(a[2],TopAbs_FACE); |
294 | TopoDS_Face from = TopoDS::Face(aLocalShape); |
295 | aLocalShape = DBRep::Get(a[3],TopAbs_FACE); |
296 | TopoDS_Face to = TopoDS::Face(aLocalShape); |
297 | // TopoDS_Face from = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE)); |
298 | // TopoDS_Face to = TopoDS::Face(DBRep::Get(a[3],TopAbs_FACE)); |
299 | if (!geom.IsNull() && !from.IsNull() && !to.IsNull()) { |
300 | gp_Pln pfrom,pto; |
301 | DrawDim::Pln(from,pfrom); |
302 | DrawDim::Pln(to,pto); |
303 | gp_Ax3 axfrom (pfrom.Position()); |
304 | gp_Ax3 axto (pto.Position()); |
305 | gp_Trsf trsf; |
306 | trsf.SetDisplacement(axfrom,axto); |
307 | Handle(Geom_Geometry) newgeom = geom->Transformed(trsf); |
308 | DrawTrSurf::Set(a[1],newgeom); |
309 | return 0; |
310 | } |
311 | } |
312 | di << "DrawDim_Placement : error" << "\n"; |
313 | return 1; |
314 | } |
315 | |
316 | |
317 | //======================================================================= |
318 | //function : PlanarDimensionCommands |
319 | //purpose : |
320 | //======================================================================= |
321 | |
322 | void DrawDim::PlanarDimensionCommands (Draw_Interpretor& theCommands) |
323 | { |
324 | // syntaxes |
325 | theCommands.Add ("distance", |
326 | "distance,no args to get help", |
327 | __FILE__, DrawDim_DISTANCE); |
328 | |
329 | theCommands.Add ("radius", |
330 | "radius, no args to get help", |
331 | __FILE__, DrawDim_RADIUS); |
332 | |
333 | theCommands.Add ("angle", |
334 | "angle, no args to get help", |
335 | __FILE__, DrawDim_ANGLE); |
336 | |
337 | theCommands.Add ("center", |
338 | "to extract center of a circle : center ,name, circle", |
339 | __FILE__, DrawDim_CENTER); |
340 | |
341 | theCommands.Add ("variables", |
342 | "to extract variables of a face", |
343 | __FILE__, DrawDim_VARIABLES); |
344 | |
345 | theCommands.Add ("splacement", |
346 | "to move shape from face to face", |
347 | __FILE__, DrawDim_SPLACEMENT); |
348 | |
349 | theCommands.Add ("gplacement", |
350 | "to move geometry from face to face", |
351 | __FILE__, DrawDim_GPLACEMENT); |
352 | } |