1 // Created on: 1997-07-30
2 // Created by: Denis PASCAL
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <DDataStd.hxx>
24 #include <Draw_Interpretor.hxx>
25 #include <Draw_Appli.hxx>
27 #include <TDF_Data.hxx>
28 #include <TDF_Label.hxx>
31 #include <DrawTrSurf.hxx>
35 #include <TopoDS_Vertex.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Wire.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Shell.hxx>
40 #include <TopoDS_Solid.hxx>
42 #include <Geom_Line.hxx>
43 #include <Geom_Plane.hxx>
51 #include <TDataXtd_Geometry.hxx>
52 #include <TDataXtd_Point.hxx>
53 #include <TDataXtd_Axis.hxx>
54 #include <TDataXtd_Plane.hxx>
56 #include <TNaming_Builder.hxx>
58 #include <DDataStd_DrawPresentation.hxx>
62 static void Location (Standard_Integer nb, const char** arg, gp_Ax2& Loc) {
65 Standard_Real X = Draw::Atof(arg[3]);
66 Standard_Real Y = Draw::Atof(arg[4]);
67 Standard_Real Z = Draw::Atof(arg[5]);
68 Standard_Real DX = Draw::Atof(arg[6]);
69 Standard_Real DY = Draw::Atof(arg[7]);
70 Standard_Real DZ = Draw::Atof(arg[8]);
71 Loc = gp_Ax2 (gp_Pnt(X,Y,Z), gp_Dir(DX,DY,DZ));
77 //=======================================================================
78 //function : DDataStd_SetPoint
79 //purpose : SetPoint (DF, entry, [drawpoint])
80 //=======================================================================
82 static Standard_Integer DDataStd_SetPoint (Draw_Interpretor& di,
89 if (!DDF::GetDF (arg[1], DF)) return 1;
90 DDF::AddLabel (DF, arg[2], L);
92 TDataXtd_Point::Set (L);
96 if (DrawTrSurf::GetPoint (arg[3],p)) {
97 TDataXtd_Point::Set (L,p);
100 di << "DDataStd_SetPoint : not a point" << "\n";
104 DDataStd_DrawPresentation::Display (L);
109 //=======================================================================
110 //function : DDataStd_SetAxis
111 //purpose : SetAxis (DF, entry, drawline])
112 //=======================================================================
114 static Standard_Integer DDataStd_SetAxis (Draw_Interpretor& di,
118 if (nb < 3) return 1;
121 if (!DDF::GetDF (arg[1], DF)) return 1;
122 DDF::AddLabel (DF, arg[2], L);
124 TDataXtd_Axis::Set (L);
127 Handle(Geom_Line) LINE = Handle(Geom_Line)::DownCast(DrawTrSurf::Get (arg[3]));
129 di << "DDataStd_SetAxis : not a line" << "\n";
132 TDataXtd_Axis::Set (L,LINE->Lin());
134 DDataStd_DrawPresentation::Display (L);
140 //=======================================================================
141 //function : DDataStd_SetPlane
142 //purpose : SetPlane (DF, entry, [drawplane])
143 //=======================================================================
145 static Standard_Integer DDataStd_SetPlane (Draw_Interpretor& di,
149 if (nb < 3) return 1;
152 if (!DDF::GetDF (arg[1], DF)) return 1;
153 DDF::AddLabel (DF, arg[2], L);
155 TDataXtd_Plane::Set(L);
158 Handle(Geom_Plane) PLANE = Handle(Geom_Plane)::DownCast(DrawTrSurf::Get (arg[3]));
159 if (PLANE.IsNull()) {
160 di << "DDataStd_SetPlane : not a plane" << "\n";
163 TDataXtd_Plane::Set (L,PLANE->Pln());
165 DDataStd_DrawPresentation::Display (L);
170 //=======================================================================
171 //function : DDataStd_SetMove
173 //=======================================================================
175 // static Standard_Integer DDataStd_SetMove (Draw_Interpretor&,
176 // Standard_Integer nb,
179 // if (nb < 3) return 1;
181 // Handle(TDF_Data) DF;
182 // if (!DDF::GetDF (arg[1], DF)) return 1;
183 // if (!DDF::FindLabel(DF, arg[2], L)) return 1;
185 // TopLoc_Location Loc;
187 // TopoDS_Shape S = DBRep::Get(arg[3]);
188 // if (S.IsNull()) return 1;
189 // Loc = S.Location();
193 // if (nb < 6) return 1;
196 // Standard_Real x = Draw::Atof(arg[3]);
197 // Standard_Real y = Draw::Atof(arg[4]);
198 // Standard_Real z = Draw::Atof(arg[5]);
201 // T.SetTranslation(gp_Vec(x,y,z));
206 // Standard_Real dx = Draw::Atof(arg[6]);
207 // Standard_Real dy = Draw::Atof(arg[7]);
208 // Standard_Real dz = Draw::Atof(arg[8]);
209 // Standard_Real ang = Draw::Atof(arg[9]);
210 // T.SetRotation(gp_Ax1(gp_Pnt(x,y,z),
211 // gp_Vec(dx,dy,dz)),
212 // ang * (M_PI / 180.0));
216 // TDataStd_CoordSys::Move(L,Loc);
222 //=======================================================================
223 //function : DDataStd_GetPoint
224 //purpose : GetPoint (DF, entry, [drawname])
225 //=======================================================================
227 static Standard_Integer DDataStd_GetPoint (Draw_Interpretor&,
231 if (nb < 3) return 1;
233 if (!DDF::GetDF (arg[1], DF)) return 1;
234 Handle(TDataXtd_Point) A;
236 if (!DDF::Find (DF, arg[2], TDataXtd_Point::GetID(), A)) return 1;
237 if (TDataXtd_Geometry::Point(A->Label(), P)) {
238 if (nb == 4) DrawTrSurf::Set(arg[3], P);
239 else DrawTrSurf::Set(arg[2], P);
246 //=======================================================================
247 //function : DDataStd_GetAxis
248 //purpose : GetAxis (DF, entry, [drawname])
249 //=======================================================================
251 static Standard_Integer DDataStd_GetAxis (Draw_Interpretor&,
255 if (nb < 3) return 1;
257 if (!DDF::GetDF(arg[1],DF)) return 1;
258 Handle(TDataXtd_Axis) A;
259 if (!DDF::Find (DF, arg[2], TDataXtd_Axis::GetID(), A)) return 1;
261 if (TDataXtd_Geometry::Line(A->Label(),l)) {
262 Handle(Geom_Line) L = new Geom_Line (l);
263 if (nb == 4) DrawTrSurf::Set (arg[3], L);
264 else DrawTrSurf::Set (arg[2], L);
270 //=======================================================================
271 //function : DDataStd_GetPlane
272 //purpose : GetPlane (DF, entry, [drawname])
273 //=======================================================================
275 static Standard_Integer DDataStd_GetPlane (Draw_Interpretor&,
279 if (nb < 3) return 1;
281 if (!DDF::GetDF(arg[1],DF)) return 1;
282 Handle(TDataXtd_Plane) A;
283 if (!DDF::Find (DF, arg[2], TDataXtd_Plane::GetID(), A)) return 1;
285 if (TDataXtd_Geometry::Plane(A->Label(),p)) {
286 Handle(Geom_Plane) P = new Geom_Plane (p);
287 if (nb == 4) DrawTrSurf::Set (arg[3], P);
288 else DrawTrSurf::Set (arg[2], P);
294 //=======================================================================
295 //function : DDataStd_SetGeometry
296 //purpose : SetGeometry (DF, entry, [type], [shape])
297 //=======================================================================
298 static Standard_Integer DDataStd_SetGeometry (Draw_Interpretor& di,
302 if (nb < 3) return 1;
305 if (!DDF::GetDF (arg[1], DF)) return 1;
308 if (!DDF::FindLabel(DF, arg[2], L)) DDF::AddLabel(DF, arg[2], L);
313 TopoDS_Shape s = DBRep::Get(arg[4]);
314 if (s.IsNull()) { di <<"shape not found"<< "\n"; return 1;}
315 TNaming_Builder SI (L);
319 // set geometry attribute
320 Handle(TDataXtd_Geometry) aGA = TDataXtd_Geometry::Set(L);
323 TDataXtd_GeometryEnum aType;
326 const char* aT = arg[3];
327 if (strcmp(aT,"any") == 0) aType = TDataXtd_ANY_GEOM;
328 else if (strcmp(aT,"pnt") == 0) aType = TDataXtd_POINT;
329 else if (strcmp(aT,"lin") == 0) aType = TDataXtd_LINE;
330 else if (strcmp(aT,"cir") == 0) aType = TDataXtd_CIRCLE;
331 else if (strcmp(aT,"ell") == 0) aType = TDataXtd_ELLIPSE;
332 else if (strcmp(aT,"spl") == 0) aType = TDataXtd_SPLINE;
333 else if (strcmp(aT,"pln") == 0) aType = TDataXtd_PLANE;
334 else if (strcmp(aT,"cyl") == 0) aType = TDataXtd_CYLINDER;
337 di << "DDataStd_SetGeometry : unknown type, must be one of:" << "\n";
338 di << "any/pnt/lin/cir/ell/spl/pln/cyl" << "\n";
344 aType = TDataXtd_Geometry::Type(L);
348 // DDataStd_DrawPresentation::Display (L);
352 //=======================================================================
353 //function : DDataStd_GetGeometryType
354 //purpose : GetGeometryType (DF, entry)
355 //=======================================================================
356 static Standard_Integer DDataStd_GetGeometryType (Draw_Interpretor& di,
360 if (nb != 3) return 1;
363 if (!DDF::GetDF (arg[1], DF)) return 1;
366 if (!DDF::FindLabel(DF, arg[2], L)) DDF::AddLabel(DF, arg[2], L);
368 // get geometry attribute
369 Handle(TDataXtd_Geometry) aGA;
370 if (!L.FindAttribute(TDataXtd_Geometry::GetID(),aGA))
372 di << "TDataStd_Geometry : attribute not found" << "\n";
377 TDataXtd_GeometryEnum aType = aGA->GetType();
380 case TDataXtd_ANY_GEOM: di << "any"; break;
381 case TDataXtd_POINT: di << "pnt"; break;
382 case TDataXtd_LINE: di << "lin"; break;
383 case TDataXtd_CIRCLE: di << "cir"; break;
384 case TDataXtd_ELLIPSE: di << "ell"; break;
385 case TDataXtd_SPLINE: di << "spl"; break;
386 case TDataXtd_PLANE: di << "pln"; break;
387 case TDataXtd_CYLINDER: di <<"cyl"; break;
390 di << "DDataStd_GetGeometry : unknown type" << "\n";
398 //=======================================================================
399 //function : DatumCommands
401 //=======================================================================
403 void DDataStd::DatumCommands (Draw_Interpretor& theCommands)
406 static Standard_Boolean done = Standard_False;
408 done = Standard_True;
409 const char* g = "DData : Standard Attribute Commands";
411 theCommands.Add ("SetPoint",
412 "SetPoint (DF, entry, [drawpoint])",
413 __FILE__, DDataStd_SetPoint, g);
415 theCommands.Add ("SetAxis",
416 "SetAxis (DF, entry, [drawline])",
417 __FILE__, DDataStd_SetAxis, g);
419 theCommands.Add ("SetPlane",
420 "SetPlane (DF, entry, [drawplane])",
421 __FILE__, DDataStd_SetPlane, g);
423 // theCommands.Add ("SetMove",
424 // "SetMove (DF, entry, Shape | [x, y, z, [dx, dy, dz, angle]])",
425 // __FILE__, DDataStd_SetMove, g);
427 theCommands.Add ("GetPoint",
428 "GetPoint (DF, entry, [drawname])",
429 __FILE__, DDataStd_GetPoint, g);
431 theCommands.Add ("GetAxis",
432 "GetAxis (DF, entry, [drawname])",
433 __FILE__, DDataStd_GetAxis, g);
435 theCommands.Add ("GetPlane",
436 "GetPlane (DF, entry, [drawname])",
437 __FILE__, DDataStd_GetPlane, g);
439 theCommands.Add ("SetGeometry",
440 "SetGeometry (DF, entry, [type], [shape])",
441 __FILE__, DDataStd_SetGeometry, g);
443 theCommands.Add ("GetGeometryType",
444 "GetGeometryType (DF, entry)",
445 __FILE__, DDataStd_GetGeometryType, g);