1 // Created on: 1997-07-30
2 // Created by: Denis PASCAL
3 // Copyright (c) 1997-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
9 // under the terms of the GNU Lesser General Public 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.
17 #include <DDataStd.hxx>
19 #include <Draw_Interpretor.hxx>
20 #include <Draw_Appli.hxx>
22 #include <TDF_Data.hxx>
23 #include <TDF_Label.hxx>
26 #include <DrawTrSurf.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>
37 #include <Geom_Line.hxx>
38 #include <Geom_Plane.hxx>
46 #include <TDataXtd_Geometry.hxx>
47 #include <TDataXtd_Point.hxx>
48 #include <TDataXtd_Axis.hxx>
49 #include <TDataXtd_Plane.hxx>
51 #include <TNaming_Builder.hxx>
53 #include <DDataStd_DrawPresentation.hxx>
57 static void Location (Standard_Integer nb, const char** arg, gp_Ax2& Loc) {
60 Standard_Real X = Draw::Atof(arg[3]);
61 Standard_Real Y = Draw::Atof(arg[4]);
62 Standard_Real Z = Draw::Atof(arg[5]);
63 Standard_Real DX = Draw::Atof(arg[6]);
64 Standard_Real DY = Draw::Atof(arg[7]);
65 Standard_Real DZ = Draw::Atof(arg[8]);
66 Loc = gp_Ax2 (gp_Pnt(X,Y,Z), gp_Dir(DX,DY,DZ));
72 //=======================================================================
73 //function : DDataStd_SetPoint
74 //purpose : SetPoint (DF, entry, [drawpoint])
75 //=======================================================================
77 static Standard_Integer DDataStd_SetPoint (Draw_Interpretor& di,
84 if (!DDF::GetDF (arg[1], DF)) return 1;
85 DDF::AddLabel (DF, arg[2], L);
87 TDataXtd_Point::Set (L);
91 if (DrawTrSurf::GetPoint (arg[3],p)) {
92 TDataXtd_Point::Set (L,p);
95 di << "DDataStd_SetPoint : not a point" << "\n";
99 DDataStd_DrawPresentation::Display (L);
104 //=======================================================================
105 //function : DDataStd_SetAxis
106 //purpose : SetAxis (DF, entry, drawline])
107 //=======================================================================
109 static Standard_Integer DDataStd_SetAxis (Draw_Interpretor& di,
113 if (nb < 3) return 1;
116 if (!DDF::GetDF (arg[1], DF)) return 1;
117 DDF::AddLabel (DF, arg[2], L);
119 TDataXtd_Axis::Set (L);
122 Handle(Geom_Line) LINE = Handle(Geom_Line)::DownCast(DrawTrSurf::Get (arg[3]));
124 di << "DDataStd_SetAxis : not a line" << "\n";
127 TDataXtd_Axis::Set (L,LINE->Lin());
129 DDataStd_DrawPresentation::Display (L);
135 //=======================================================================
136 //function : DDataStd_SetPlane
137 //purpose : SetPlane (DF, entry, [drawplane])
138 //=======================================================================
140 static Standard_Integer DDataStd_SetPlane (Draw_Interpretor& di,
144 if (nb < 3) return 1;
147 if (!DDF::GetDF (arg[1], DF)) return 1;
148 DDF::AddLabel (DF, arg[2], L);
150 TDataXtd_Plane::Set(L);
153 Handle(Geom_Plane) PLANE = Handle(Geom_Plane)::DownCast(DrawTrSurf::Get (arg[3]));
154 if (PLANE.IsNull()) {
155 di << "DDataStd_SetPlane : not a plane" << "\n";
158 TDataXtd_Plane::Set (L,PLANE->Pln());
160 DDataStd_DrawPresentation::Display (L);
165 //=======================================================================
166 //function : DDataStd_SetMove
168 //=======================================================================
170 // static Standard_Integer DDataStd_SetMove (Draw_Interpretor&,
171 // Standard_Integer nb,
174 // if (nb < 3) return 1;
176 // Handle(TDF_Data) DF;
177 // if (!DDF::GetDF (arg[1], DF)) return 1;
178 // if (!DDF::FindLabel(DF, arg[2], L)) return 1;
180 // TopLoc_Location Loc;
182 // TopoDS_Shape S = DBRep::Get(arg[3]);
183 // if (S.IsNull()) return 1;
184 // Loc = S.Location();
188 // if (nb < 6) return 1;
191 // Standard_Real x = Draw::Atof(arg[3]);
192 // Standard_Real y = Draw::Atof(arg[4]);
193 // Standard_Real z = Draw::Atof(arg[5]);
196 // T.SetTranslation(gp_Vec(x,y,z));
201 // Standard_Real dx = Draw::Atof(arg[6]);
202 // Standard_Real dy = Draw::Atof(arg[7]);
203 // Standard_Real dz = Draw::Atof(arg[8]);
204 // Standard_Real ang = Draw::Atof(arg[9]);
205 // T.SetRotation(gp_Ax1(gp_Pnt(x,y,z),
206 // gp_Vec(dx,dy,dz)),
207 // ang * (M_PI / 180.0));
211 // TDataStd_CoordSys::Move(L,Loc);
217 //=======================================================================
218 //function : DDataStd_GetPoint
219 //purpose : GetPoint (DF, entry, [drawname])
220 //=======================================================================
222 static Standard_Integer DDataStd_GetPoint (Draw_Interpretor&,
226 if (nb < 3) return 1;
228 if (!DDF::GetDF (arg[1], DF)) return 1;
229 Handle(TDataXtd_Point) A;
231 if (!DDF::Find (DF, arg[2], TDataXtd_Point::GetID(), A)) return 1;
232 if (TDataXtd_Geometry::Point(A->Label(), P)) {
233 if (nb == 4) DrawTrSurf::Set(arg[3], P);
234 else DrawTrSurf::Set(arg[2], P);
241 //=======================================================================
242 //function : DDataStd_GetAxis
243 //purpose : GetAxis (DF, entry, [drawname])
244 //=======================================================================
246 static Standard_Integer DDataStd_GetAxis (Draw_Interpretor&,
250 if (nb < 3) return 1;
252 if (!DDF::GetDF(arg[1],DF)) return 1;
253 Handle(TDataXtd_Axis) A;
254 if (!DDF::Find (DF, arg[2], TDataXtd_Axis::GetID(), A)) return 1;
256 if (TDataXtd_Geometry::Line(A->Label(),l)) {
257 Handle(Geom_Line) L = new Geom_Line (l);
258 if (nb == 4) DrawTrSurf::Set (arg[3], L);
259 else DrawTrSurf::Set (arg[2], L);
265 //=======================================================================
266 //function : DDataStd_GetPlane
267 //purpose : GetPlane (DF, entry, [drawname])
268 //=======================================================================
270 static Standard_Integer DDataStd_GetPlane (Draw_Interpretor&,
274 if (nb < 3) return 1;
276 if (!DDF::GetDF(arg[1],DF)) return 1;
277 Handle(TDataXtd_Plane) A;
278 if (!DDF::Find (DF, arg[2], TDataXtd_Plane::GetID(), A)) return 1;
280 if (TDataXtd_Geometry::Plane(A->Label(),p)) {
281 Handle(Geom_Plane) P = new Geom_Plane (p);
282 if (nb == 4) DrawTrSurf::Set (arg[3], P);
283 else DrawTrSurf::Set (arg[2], P);
289 //=======================================================================
290 //function : DDataStd_SetGeometry
291 //purpose : SetGeometry (DF, entry, [type], [shape])
292 //=======================================================================
293 static Standard_Integer DDataStd_SetGeometry (Draw_Interpretor& di,
297 if (nb < 3) return 1;
300 if (!DDF::GetDF (arg[1], DF)) return 1;
303 if (!DDF::FindLabel(DF, arg[2], L)) DDF::AddLabel(DF, arg[2], L);
308 TopoDS_Shape s = DBRep::Get(arg[4]);
309 if (s.IsNull()) { di <<"shape not found"<< "\n"; return 1;}
310 TNaming_Builder SI (L);
314 // set geometry attribute
315 Handle(TDataXtd_Geometry) aGA = TDataXtd_Geometry::Set(L);
318 TDataXtd_GeometryEnum aType;
321 const char* aT = arg[3];
322 if (strcmp(aT,"any") == 0) aType = TDataXtd_ANY_GEOM;
323 else if (strcmp(aT,"pnt") == 0) aType = TDataXtd_POINT;
324 else if (strcmp(aT,"lin") == 0) aType = TDataXtd_LINE;
325 else if (strcmp(aT,"cir") == 0) aType = TDataXtd_CIRCLE;
326 else if (strcmp(aT,"ell") == 0) aType = TDataXtd_ELLIPSE;
327 else if (strcmp(aT,"spl") == 0) aType = TDataXtd_SPLINE;
328 else if (strcmp(aT,"pln") == 0) aType = TDataXtd_PLANE;
329 else if (strcmp(aT,"cyl") == 0) aType = TDataXtd_CYLINDER;
332 di << "DDataStd_SetGeometry : unknown type, must be one of:" << "\n";
333 di << "any/pnt/lin/cir/ell/spl/pln/cyl" << "\n";
339 aType = TDataXtd_Geometry::Type(L);
343 // DDataStd_DrawPresentation::Display (L);
347 //=======================================================================
348 //function : DDataStd_GetGeometryType
349 //purpose : GetGeometryType (DF, entry)
350 //=======================================================================
351 static Standard_Integer DDataStd_GetGeometryType (Draw_Interpretor& di,
355 if (nb != 3) return 1;
358 if (!DDF::GetDF (arg[1], DF)) return 1;
361 if (!DDF::FindLabel(DF, arg[2], L)) DDF::AddLabel(DF, arg[2], L);
363 // get geometry attribute
364 Handle(TDataXtd_Geometry) aGA;
365 if (!L.FindAttribute(TDataXtd_Geometry::GetID(),aGA))
367 di << "TDataStd_Geometry : attribute not found" << "\n";
372 TDataXtd_GeometryEnum aType = aGA->GetType();
375 case TDataXtd_ANY_GEOM: di << "any"; break;
376 case TDataXtd_POINT: di << "pnt"; break;
377 case TDataXtd_LINE: di << "lin"; break;
378 case TDataXtd_CIRCLE: di << "cir"; break;
379 case TDataXtd_ELLIPSE: di << "ell"; break;
380 case TDataXtd_SPLINE: di << "spl"; break;
381 case TDataXtd_PLANE: di << "pln"; break;
382 case TDataXtd_CYLINDER: di <<"cyl"; break;
385 di << "DDataStd_GetGeometry : unknown type" << "\n";
393 //=======================================================================
394 //function : DatumCommands
396 //=======================================================================
398 void DDataStd::DatumCommands (Draw_Interpretor& theCommands)
401 static Standard_Boolean done = Standard_False;
403 done = Standard_True;
404 const char* g = "DData : Standard Attribute Commands";
406 theCommands.Add ("SetPoint",
407 "SetPoint (DF, entry, [drawpoint])",
408 __FILE__, DDataStd_SetPoint, g);
410 theCommands.Add ("SetAxis",
411 "SetAxis (DF, entry, [drawline])",
412 __FILE__, DDataStd_SetAxis, g);
414 theCommands.Add ("SetPlane",
415 "SetPlane (DF, entry, [drawplane])",
416 __FILE__, DDataStd_SetPlane, g);
418 // theCommands.Add ("SetMove",
419 // "SetMove (DF, entry, Shape | [x, y, z, [dx, dy, dz, angle]])",
420 // __FILE__, DDataStd_SetMove, g);
422 theCommands.Add ("GetPoint",
423 "GetPoint (DF, entry, [drawname])",
424 __FILE__, DDataStd_GetPoint, g);
426 theCommands.Add ("GetAxis",
427 "GetAxis (DF, entry, [drawname])",
428 __FILE__, DDataStd_GetAxis, g);
430 theCommands.Add ("GetPlane",
431 "GetPlane (DF, entry, [drawname])",
432 __FILE__, DDataStd_GetPlane, g);
434 theCommands.Add ("SetGeometry",
435 "SetGeometry (DF, entry, [type], [shape])",
436 __FILE__, DDataStd_SetGeometry, g);
438 theCommands.Add ("GetGeometryType",
439 "GetGeometryType (DF, entry)",
440 __FILE__, DDataStd_GetGeometryType, g);