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