b311480e |
1 | // Created on: 1997-07-30 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1997-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 <DDataStd.hxx> |
18 | #include <DDF.hxx> |
19 | #include <Draw_Interpretor.hxx> |
20 | #include <Draw_Appli.hxx> |
21 | |
22 | #include <TDF_Data.hxx> |
23 | #include <TDF_Label.hxx> |
24 | |
25 | #include <DBRep.hxx> |
26 | #include <DrawTrSurf.hxx> |
27 | |
7fd59977 |
28 | #include <TopoDS_Vertex.hxx> |
7fd59977 |
29 | |
30 | #include <Geom_Line.hxx> |
31 | #include <Geom_Plane.hxx> |
32 | |
33 | #include <gp_Pnt.hxx> |
7fd59977 |
34 | #include <gp_Pln.hxx> |
7fd59977 |
35 | |
36 | #include <TDataXtd_Geometry.hxx> |
37 | #include <TDataXtd_Point.hxx> |
38 | #include <TDataXtd_Axis.hxx> |
39 | #include <TDataXtd_Plane.hxx> |
40 | |
41 | #include <TNaming_Builder.hxx> |
42 | |
43 | #include <DDataStd_DrawPresentation.hxx> |
44 | |
7fd59977 |
45 | //======================================================================= |
46 | //function : DDataStd_SetPoint |
47 | //purpose : SetPoint (DF, entry, [drawpoint]) |
48 | //======================================================================= |
49 | |
50 | static Standard_Integer DDataStd_SetPoint (Draw_Interpretor& di, |
51 | Standard_Integer nb, |
52 | const char** arg) |
53 | { |
54 | if (nb < 3) return 1; |
55 | TDF_Label L; |
56 | Handle(TDF_Data) DF; |
57 | if (!DDF::GetDF (arg[1], DF)) return 1; |
58 | DDF::AddLabel (DF, arg[2], L); |
59 | if (nb == 3) { |
60 | TDataXtd_Point::Set (L); |
61 | } |
62 | else if (nb == 4) { |
63 | gp_Pnt p; |
64 | if (DrawTrSurf::GetPoint (arg[3],p)) { |
65 | TDataXtd_Point::Set (L,p); |
66 | } |
67 | else { |
586db386 |
68 | di << "DDataStd_SetPoint : not a point\n"; |
7fd59977 |
69 | return 1; |
70 | } |
71 | } |
72 | DDataStd_DrawPresentation::Display (L); |
73 | return 0; |
74 | } |
75 | |
76 | |
77 | //======================================================================= |
78 | //function : DDataStd_SetAxis |
79 | //purpose : SetAxis (DF, entry, drawline]) |
80 | //======================================================================= |
81 | |
82 | static Standard_Integer DDataStd_SetAxis (Draw_Interpretor& di, |
83 | Standard_Integer nb, |
84 | const char** arg) |
85 | { |
86 | if (nb < 3) return 1; |
87 | TDF_Label L; |
88 | Handle(TDF_Data) DF; |
89 | if (!DDF::GetDF (arg[1], DF)) return 1; |
90 | DDF::AddLabel (DF, arg[2], L); |
91 | if (nb == 3) { |
92 | TDataXtd_Axis::Set (L); |
93 | } |
94 | else if (nb == 4) { |
95 | Handle(Geom_Line) LINE = Handle(Geom_Line)::DownCast(DrawTrSurf::Get (arg[3])); |
96 | if (LINE.IsNull()) { |
586db386 |
97 | di << "DDataStd_SetAxis : not a line\n"; |
7fd59977 |
98 | return 1; |
99 | } |
100 | TDataXtd_Axis::Set (L,LINE->Lin()); |
101 | } |
102 | DDataStd_DrawPresentation::Display (L); |
103 | return 0; |
104 | } |
105 | |
106 | |
107 | |
108 | //======================================================================= |
109 | //function : DDataStd_SetPlane |
110 | //purpose : SetPlane (DF, entry, [drawplane]) |
111 | //======================================================================= |
112 | |
113 | static Standard_Integer DDataStd_SetPlane (Draw_Interpretor& di, |
114 | Standard_Integer nb, |
115 | const char** arg) |
116 | { |
117 | if (nb < 3) return 1; |
118 | TDF_Label L; |
119 | Handle(TDF_Data) DF; |
120 | if (!DDF::GetDF (arg[1], DF)) return 1; |
121 | DDF::AddLabel (DF, arg[2], L); |
122 | if (nb == 3) { |
123 | TDataXtd_Plane::Set(L); |
124 | } |
125 | else if (nb == 4) { |
126 | Handle(Geom_Plane) PLANE = Handle(Geom_Plane)::DownCast(DrawTrSurf::Get (arg[3])); |
127 | if (PLANE.IsNull()) { |
586db386 |
128 | di << "DDataStd_SetPlane : not a plane\n"; |
7fd59977 |
129 | return 1; |
130 | } |
131 | TDataXtd_Plane::Set (L,PLANE->Pln()); |
132 | } |
133 | DDataStd_DrawPresentation::Display (L); |
134 | return 0; |
135 | } |
136 | |
137 | |
7fd59977 |
138 | //======================================================================= |
139 | //function : DDataStd_GetPoint |
140 | //purpose : GetPoint (DF, entry, [drawname]) |
141 | //======================================================================= |
142 | |
143 | static Standard_Integer DDataStd_GetPoint (Draw_Interpretor&, |
144 | Standard_Integer nb, |
145 | const char** arg) |
146 | { |
147 | if (nb < 3) return 1; |
148 | Handle(TDF_Data) DF; |
149 | if (!DDF::GetDF (arg[1], DF)) return 1; |
150 | Handle(TDataXtd_Point) A; |
151 | gp_Pnt P; |
152 | if (!DDF::Find (DF, arg[2], TDataXtd_Point::GetID(), A)) return 1; |
153 | if (TDataXtd_Geometry::Point(A->Label(), P)) { |
154 | if (nb == 4) DrawTrSurf::Set(arg[3], P); |
155 | else DrawTrSurf::Set(arg[2], P); |
156 | return 0; |
157 | } |
158 | return 1; |
159 | } |
160 | |
161 | |
162 | //======================================================================= |
163 | //function : DDataStd_GetAxis |
164 | //purpose : GetAxis (DF, entry, [drawname]) |
165 | //======================================================================= |
166 | |
167 | static Standard_Integer DDataStd_GetAxis (Draw_Interpretor&, |
168 | Standard_Integer nb, |
169 | const char** arg) |
170 | { |
171 | if (nb < 3) return 1; |
172 | Handle(TDF_Data) DF; |
173 | if (!DDF::GetDF(arg[1],DF)) return 1; |
174 | Handle(TDataXtd_Axis) A; |
175 | if (!DDF::Find (DF, arg[2], TDataXtd_Axis::GetID(), A)) return 1; |
176 | gp_Lin l; |
177 | if (TDataXtd_Geometry::Line(A->Label(),l)) { |
178 | Handle(Geom_Line) L = new Geom_Line (l); |
179 | if (nb == 4) DrawTrSurf::Set (arg[3], L); |
180 | else DrawTrSurf::Set (arg[2], L); |
181 | return 0; |
182 | } |
183 | return 1; |
184 | } |
185 | |
186 | //======================================================================= |
187 | //function : DDataStd_GetPlane |
188 | //purpose : GetPlane (DF, entry, [drawname]) |
189 | //======================================================================= |
190 | |
191 | static Standard_Integer DDataStd_GetPlane (Draw_Interpretor&, |
192 | Standard_Integer nb, |
193 | const char** arg) |
194 | { |
195 | if (nb < 3) return 1; |
196 | Handle(TDF_Data) DF; |
197 | if (!DDF::GetDF(arg[1],DF)) return 1; |
198 | Handle(TDataXtd_Plane) A; |
199 | if (!DDF::Find (DF, arg[2], TDataXtd_Plane::GetID(), A)) return 1; |
200 | gp_Pln p; |
201 | if (TDataXtd_Geometry::Plane(A->Label(),p)) { |
202 | Handle(Geom_Plane) P = new Geom_Plane (p); |
203 | if (nb == 4) DrawTrSurf::Set (arg[3], P); |
204 | else DrawTrSurf::Set (arg[2], P); |
205 | return 0; |
206 | } |
207 | return 1; |
208 | } |
209 | |
210 | //======================================================================= |
211 | //function : DDataStd_SetGeometry |
212 | //purpose : SetGeometry (DF, entry, [type], [shape]) |
213 | //======================================================================= |
214 | static Standard_Integer DDataStd_SetGeometry (Draw_Interpretor& di, |
215 | Standard_Integer nb, |
216 | const char** arg) |
217 | { |
218 | if (nb < 3) return 1; |
219 | |
220 | Handle(TDF_Data) DF; |
221 | if (!DDF::GetDF (arg[1], DF)) return 1; |
222 | |
223 | TDF_Label L; |
224 | if (!DDF::FindLabel(DF, arg[2], L)) DDF::AddLabel(DF, arg[2], L); |
225 | |
226 | if (nb == 5) |
227 | { |
228 | // set NS attribute |
229 | TopoDS_Shape s = DBRep::Get(arg[4]); |
586db386 |
230 | if (s.IsNull()) { di <<"shape not found\n"; return 1;} |
7fd59977 |
231 | TNaming_Builder SI (L); |
232 | SI.Generated(s); |
233 | } |
234 | |
235 | // set geometry attribute |
236 | Handle(TDataXtd_Geometry) aGA = TDataXtd_Geometry::Set(L); |
237 | |
238 | // set type |
239 | TDataXtd_GeometryEnum aType; |
240 | if (nb > 3) |
241 | { |
242 | const char* aT = arg[3]; |
243 | if (strcmp(aT,"any") == 0) aType = TDataXtd_ANY_GEOM; |
244 | else if (strcmp(aT,"pnt") == 0) aType = TDataXtd_POINT; |
245 | else if (strcmp(aT,"lin") == 0) aType = TDataXtd_LINE; |
246 | else if (strcmp(aT,"cir") == 0) aType = TDataXtd_CIRCLE; |
247 | else if (strcmp(aT,"ell") == 0) aType = TDataXtd_ELLIPSE; |
248 | else if (strcmp(aT,"spl") == 0) aType = TDataXtd_SPLINE; |
249 | else if (strcmp(aT,"pln") == 0) aType = TDataXtd_PLANE; |
250 | else if (strcmp(aT,"cyl") == 0) aType = TDataXtd_CYLINDER; |
251 | else |
252 | { |
586db386 |
253 | di << "DDataStd_SetGeometry : unknown type, must be one of:\n"; |
254 | di << "any/pnt/lin/cir/ell/spl/pln/cyl\n"; |
7fd59977 |
255 | return 1; |
256 | } |
257 | } |
258 | else |
259 | { |
260 | aType = TDataXtd_Geometry::Type(L); |
261 | } |
262 | aGA->SetType(aType); |
263 | |
264 | // DDataStd_DrawPresentation::Display (L); |
265 | return 0; |
266 | } |
267 | |
268 | //======================================================================= |
269 | //function : DDataStd_GetGeometryType |
270 | //purpose : GetGeometryType (DF, entry) |
271 | //======================================================================= |
272 | static Standard_Integer DDataStd_GetGeometryType (Draw_Interpretor& di, |
273 | Standard_Integer nb, |
274 | const char** arg) |
275 | { |
276 | if (nb != 3) return 1; |
277 | |
278 | Handle(TDF_Data) DF; |
279 | if (!DDF::GetDF (arg[1], DF)) return 1; |
280 | |
281 | TDF_Label L; |
282 | if (!DDF::FindLabel(DF, arg[2], L)) DDF::AddLabel(DF, arg[2], L); |
283 | |
284 | // get geometry attribute |
285 | Handle(TDataXtd_Geometry) aGA; |
286 | if (!L.FindAttribute(TDataXtd_Geometry::GetID(),aGA)) |
287 | { |
586db386 |
288 | di << "TDataStd_Geometry : attribute not found\n"; |
7fd59977 |
289 | return 1; |
290 | } |
291 | |
292 | // get type |
293 | TDataXtd_GeometryEnum aType = aGA->GetType(); |
294 | switch (aType) |
295 | { |
296 | case TDataXtd_ANY_GEOM: di << "any"; break; |
297 | case TDataXtd_POINT: di << "pnt"; break; |
298 | case TDataXtd_LINE: di << "lin"; break; |
299 | case TDataXtd_CIRCLE: di << "cir"; break; |
300 | case TDataXtd_ELLIPSE: di << "ell"; break; |
301 | case TDataXtd_SPLINE: di << "spl"; break; |
302 | case TDataXtd_PLANE: di << "pln"; break; |
303 | case TDataXtd_CYLINDER: di <<"cyl"; break; |
304 | default: |
305 | { |
586db386 |
306 | di << "DDataStd_GetGeometry : unknown type\n"; |
7fd59977 |
307 | return 1; |
308 | } |
309 | } |
310 | |
311 | return 0; |
312 | } |
313 | |
314 | //======================================================================= |
315 | //function : DatumCommands |
316 | //purpose : |
317 | //======================================================================= |
318 | |
319 | void DDataStd::DatumCommands (Draw_Interpretor& theCommands) |
320 | |
321 | { |
322 | static Standard_Boolean done = Standard_False; |
323 | if (done) return; |
324 | done = Standard_True; |
325 | const char* g = "DData : Standard Attribute Commands"; |
326 | |
327 | theCommands.Add ("SetPoint", |
328 | "SetPoint (DF, entry, [drawpoint])", |
329 | __FILE__, DDataStd_SetPoint, g); |
330 | |
331 | theCommands.Add ("SetAxis", |
332 | "SetAxis (DF, entry, [drawline])", |
333 | __FILE__, DDataStd_SetAxis, g); |
334 | |
335 | theCommands.Add ("SetPlane", |
336 | "SetPlane (DF, entry, [drawplane])", |
337 | __FILE__, DDataStd_SetPlane, g); |
338 | |
339 | // theCommands.Add ("SetMove", |
340 | // "SetMove (DF, entry, Shape | [x, y, z, [dx, dy, dz, angle]])", |
341 | // __FILE__, DDataStd_SetMove, g); |
342 | |
343 | theCommands.Add ("GetPoint", |
344 | "GetPoint (DF, entry, [drawname])", |
345 | __FILE__, DDataStd_GetPoint, g); |
346 | |
347 | theCommands.Add ("GetAxis", |
348 | "GetAxis (DF, entry, [drawname])", |
349 | __FILE__, DDataStd_GetAxis, g); |
350 | |
351 | theCommands.Add ("GetPlane", |
352 | "GetPlane (DF, entry, [drawname])", |
353 | __FILE__, DDataStd_GetPlane, g); |
354 | |
355 | theCommands.Add ("SetGeometry", |
356 | "SetGeometry (DF, entry, [type], [shape])", |
357 | __FILE__, DDataStd_SetGeometry, g); |
358 | |
359 | theCommands.Add ("GetGeometryType", |
360 | "GetGeometryType (DF, entry)", |
361 | __FILE__, DDataStd_GetGeometryType, g); |
362 | } |