0030895: Coding Rules - specify std namespace explicitly for std::cout and streams
[occt.git] / src / DDataStd / DDataStd_ConstraintCommands.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
19#include <DDF.hxx>
20#include <Draw_Interpretor.hxx>
21#include <Draw_Appli.hxx>
22
23#include <TDF_Data.hxx>
24#include <TDF_Label.hxx>
25#include <TDF_ChildIterator.hxx>
26#include <TDF_Tool.hxx>
27
28#include <TNaming_NamedShape.hxx>
29
30#include <TDataXtd.hxx>
31#include <TDataStd_Real.hxx>
32#include <TDataStd_Integer.hxx>
33#include <TDataXtd_Constraint.hxx>
34#include <TDataXtd_PatternStd.hxx>
35#include <TDataXtd_Position.hxx>
36#include <TCollection_AsciiString.hxx>
37
38#include <Standard_Macro.hxx>
39
40//=======================================================================
41//function : DDataStd_SetConstraint
42//purpose : SetConstraint (DF,entry,keyword,geometrie/value[,geometrie])",
43//=======================================================================
44static Standard_Integer DDataStd_SetConstraint (Draw_Interpretor& di,
45 Standard_Integer nb,
46 const char** arg)
47{
48 if (nb < 5)
49 {
586db386 50 di << "usage: SetConstraint DF entry keyword geometrie [geometrie ...]\n";
51 di << "or SetConstraint DF entry \"plane\" geometrie - to set plane for existing constraint\n";
52 di << "or SetConstraint DF entry \"value\" value - to set value for existing constraint\n";
7fd59977 53 return 1;
54 }
55
56 Handle(TDF_Data) DF;
57 if (!DDF::GetDF(arg[1],DF)) return 1;
58
59 TDF_Label L;
60 if (!DDF::FindLabel(DF,arg[2],L)) return 1;
61
62 TDataXtd_ConstraintEnum aCT;
63 const char* aT = arg[3];
64
65 if (strcmp(aT,"plane") == 0)
66 {
67 Handle(TDataXtd_Constraint) C;
68 if (!L.FindAttribute(TDataXtd_Constraint::GetID(), C)) return 1;
69
70 TDF_Label aLab;
71 if (!DDF::FindLabel(DF, arg[4], aLab)) return 1;
72 Handle(TNaming_NamedShape) aSh;
73 if (aLab.FindAttribute(TNaming_NamedShape::GetID(), aSh))
74 {
75 C->SetPlane(aSh);
76 }
77 }
78 else if (strcmp(aT,"value") == 0)
79 {
80 Handle(TDataXtd_Constraint) C;
81 if (!L.FindAttribute(TDataXtd_Constraint::GetID(), C)) return 1;
82
83 TDF_Label aLab;
84 if (!DDF::FindLabel(DF, arg[4], aLab)) return 1;
85 Handle(TDataStd_Real) aR;
86 if (aLab.FindAttribute(TDataStd_Real::GetID(), aR))
87 {
88 C->SetValue(aR);
89 }
90 }
91 else
92 {
93 Handle(TDataXtd_Constraint) C = TDataXtd_Constraint::Set(L);
94
95 // planar constraints
96 if (strcmp(aT,"rad") == 0) aCT = TDataXtd_RADIUS;
97 else if (strcmp(aT,"dia") == 0) aCT = TDataXtd_DIAMETER;
98 else if (strcmp(aT,"minr") == 0) aCT = TDataXtd_MINOR_RADIUS;
99 else if (strcmp(aT,"majr") == 0) aCT = TDataXtd_MAJOR_RADIUS;
100 else if (strcmp(aT,"tan") == 0) aCT = TDataXtd_TANGENT;
101 else if (strcmp(aT,"par") == 0) aCT = TDataXtd_PARALLEL;
102 else if (strcmp(aT,"perp") == 0) aCT = TDataXtd_PERPENDICULAR;
103 else if (strcmp(aT,"concentric") == 0) aCT = TDataXtd_CONCENTRIC;
104 else if (strcmp(aT,"equal") == 0) aCT = TDataXtd_COINCIDENT;
105 else if (strcmp(aT,"dist") == 0) aCT = TDataXtd_DISTANCE;
106 else if (strcmp(aT,"angle") == 0) aCT = TDataXtd_ANGLE;
107 else if (strcmp(aT,"eqrad") == 0) aCT = TDataXtd_EQUAL_RADIUS;
108 else if (strcmp(aT,"symm") == 0) aCT = TDataXtd_SYMMETRY;
109 else if (strcmp(aT,"midp") == 0) aCT = TDataXtd_MIDPOINT;
110 else if (strcmp(aT,"eqdist") == 0) aCT = TDataXtd_EQUAL_DISTANCE;
111 else if (strcmp(aT,"fix") == 0) aCT = TDataXtd_FIX;
112 else if (strcmp(aT,"rigid") == 0) aCT = TDataXtd_RIGID;
113 // placement constraints
114 else if (strcmp(aT,"from") == 0) aCT = TDataXtd_FROM;
115 else if (strcmp(aT,"axis") == 0) aCT = TDataXtd_AXIS;
116 else if (strcmp(aT,"mate") == 0) aCT = TDataXtd_MATE;
117 else if (strcmp(aT,"alignf") == 0) aCT = TDataXtd_ALIGN_FACES;
118 else if (strcmp(aT,"aligna") == 0) aCT = TDataXtd_ALIGN_AXES;
119 else if (strcmp(aT,"axesa") == 0) aCT = TDataXtd_AXES_ANGLE;
120 else if (strcmp(aT,"facesa") == 0) aCT = TDataXtd_FACES_ANGLE;
121 else if (strcmp(aT,"round") == 0) aCT = TDataXtd_ROUND;
122 else if (strcmp(aT,"offset") == 0) aCT = TDataXtd_OFFSET;
123 else
124 {
586db386 125 di << "DDataStd_SetConstraint : unknown type, must be one of:\n";
126 di << "rad/dia/minr/majr/tan/par/perp/concentric/equal/dist/angle/eqrad/symm/midp/\n";
127 di << "eqdist/fix/rigid or from/axis/mate/alignf/aligna/axesa/facesa/round/offset\n";
128 di << "or plane/value\n";
7fd59977 129 return 1;
130 }
131
132 // set type
133 C->SetType(aCT);
134
135 // retrieve and set geometries
136 Standard_Integer i = 1, nbSh = nb - 4;
137 Handle(TNaming_NamedShape) aSh;
138 TDF_Label aLab;
139
140 for (i = 1; i <= nbSh; i++)
141 {
142 if (!DDF::FindLabel(DF, arg[i+3], aLab)) return 1;
143 if (aLab.FindAttribute(TNaming_NamedShape::GetID(), aSh))
144 {
145 C->SetGeometry(i, aSh);
146 }
147 }
148 }
149 return 0;
150}
151
152//=======================================================================
153//function : DDataStd_GetConstraint
154//purpose : GetConstraints (document, label)
155//=======================================================================
156static Standard_Integer DDataStd_GetConstraint (Draw_Interpretor& di,
157 Standard_Integer nb,
158 const char** arg)
159{
160 Handle(TDataXtd_Constraint) CTR;
161 if (nb == 3)
162 {
163 Handle(TDF_Data) DF;
164 TDF_Label L;
165 if (!DDF::GetDF(arg[1],DF)) return 1;
166 if (!DDF::FindLabel(DF,arg[2],L)) return 1;
167 if (L.FindAttribute(TDataXtd_Constraint::GetID(),CTR))
168 {
169 Standard_SStream aStream;
170 DDataStd::DumpConstraint (CTR,aStream);
171 di << aStream;
172 }
173 else
174 {
175 TDF_ChildIterator it (L,Standard_True);
176 for (;it.More();it.Next())
177 {
178 const TDF_Label& current = it.Value();
179 if (current.FindAttribute(TDataXtd_Constraint::GetID(),CTR))
180 {
181 Standard_SStream aStream;
182 DDataStd::DumpConstraint (CTR,aStream);
183 di << aStream;
184 }
185 }
186 }
187 return 0;
188 }
586db386 189 di << "DDataStd_GetConstraint : Error : not done\n";
7fd59977 190 return 1;
191}
192
193//=======================================================================
194//function : DDataStd_SetPattern
195//purpose : SetPattern (DF,entry,signature,NSentry[realEntry,intEntry[,NSentry,realEntry,intEntry]])
196//=======================================================================
197static Standard_Integer DDataStd_SetPattern (Draw_Interpretor& di,
198 Standard_Integer nb,
199 const char** arg)
200{
201 if (nb < 5)
202 {
586db386 203 di << "usage: SetPattern (DF,entry,signature,NSentry[realEntry,intEntry[,NSentry,realEntry,intEntry]])\n";
7fd59977 204 return 1;
205 }
206
207 Handle(TDF_Data) DF;
208 if (!DDF::GetDF(arg[1],DF)) return 1;
209
210 TDF_Label L;
211 if (!DDF::FindLabel(DF,arg[2],L)) return 1;
212
213 Handle(TDataXtd_PatternStd) aP = TDataXtd_PatternStd::Set(L);
214
215 // set signature
91322f44 216 Standard_Integer signature = Draw::Atoi(arg[3]);
7fd59977 217 aP->Signature(signature);
218
219 TDF_Label aLab;
220 Handle(TNaming_NamedShape) TNS;
221 Handle(TDataStd_Real) TReal;
222 Handle(TDataStd_Integer) TInt;
223
224 // set other parameters
225 if (signature < 5)
226 {
227 if (nb < 7)
228 {
586db386 229 di<<"usage:\n";
230 di<<"SetPattern (DF,entry,signature<=2,NSentry,realEntry,intEntry)\n";
231 di<<"SetPattern (DF,entry,2<signature<5,NSentry,realEntry,intEntry,NSentry,realEntry,intEntry)\n";
7fd59977 232 return 1;
233 }
234
235 // NSentry
236 if (!DDF::FindLabel(DF, arg[4], aLab)) return 1;
237 if (aLab.FindAttribute(TNaming_NamedShape::GetID(), TNS))
238 {
239 aP->Axis1(TNS);
240 }
241
242 // realEntry
243 if (!DDF::FindLabel(DF, arg[5], aLab)) return 1;
244 if (aLab.FindAttribute(TDataStd_Real::GetID(), TReal))
245 {
246 aP->Value1(TReal);
247 }
248
249 // intEntry
250 if (!DDF::FindLabel(DF, arg[6], aLab)) return 1;
251 if (aLab.FindAttribute(TDataStd_Integer::GetID(), TInt))
252 {
253 aP->NbInstances1(TInt);
254 }
255
256 if (signature > 2)
257 {
258 if (nb < 10)
259 {
586db386 260 di<<"usage:\n";
261 di<<"SetPattern (DF,entry,2<signature<5,NSentry,realEntry,intEntry,NSentry,realEntry,intEntry)\n";
7fd59977 262 return 1;
263 }
264
265 // NSentry
266 if (!DDF::FindLabel(DF, arg[7], aLab)) return 1;
267 if (aLab.FindAttribute(TNaming_NamedShape::GetID(), TNS))
268 {
269 aP->Axis2(TNS);
270 }
271
272 // realEntry
273 if (!DDF::FindLabel(DF, arg[8], aLab)) return 1;
274 if (aLab.FindAttribute(TDataStd_Real::GetID(), TReal))
275 {
276 aP->Value2(TReal);
277 }
278
279 // intEntry
280 if (!DDF::FindLabel(DF, arg[9], aLab)) return 1;
281 if (aLab.FindAttribute(TDataStd_Integer::GetID(), TInt))
282 {
283 aP->NbInstances2(TInt);
284 }
285 }
286 }
287 else
288 {
289 if (nb > 5)
290 {
586db386 291 di<<"usage: SetPattern (DF,entry,signature>=5,NSentry)\n";
7fd59977 292 return 1;
293 }
294
295 if (!DDF::FindLabel(DF, arg[4], aLab)) return 1;
296 if (aLab.FindAttribute(TNaming_NamedShape::GetID(), TNS))
297 {
298 aP->Mirror(TNS);
299 }
300 }
301
302 return 0;
303}
304
305//=======================================================================
306//function : DDataStd_DumpPattern
307//purpose : DumpPattern (DF, entry)
308//=======================================================================
309static Standard_Integer DDataStd_DumpPattern (Draw_Interpretor& di,
310 Standard_Integer nb,
311 const char** arg)
312{
313 Handle(TDataXtd_PatternStd) CTR;
314 if (nb == 3)
315 {
316 Handle(TDF_Data) DF;
317 TDF_Label L;
318 if (!DDF::GetDF(arg[1],DF)) return 1;
319 if (!DDF::FindLabel(DF,arg[2],L)) return 1;
320 if (L.FindAttribute(TDataXtd_PatternStd::GetID(),CTR))
321 {
322// Standard_SStream aStream;
323// CTR->Dump(aStream);
04232180 324// aStream << std::ends;
7fd59977 325// di << aStream.rdbuf()->str();
326
327 TCollection_AsciiString S;
328 TDF_Tool::Entry(CTR->Label(),S);
329 di << S.ToCString() << " signature = " << CTR->Signature();
330
331 if (!CTR->Axis1().IsNull())
332 {
333 TDF_Tool::Entry(CTR->Axis1()->Label(),S);
334 di << " Axis1 (" << S.ToCString() << ")";
335 }
336
337 if (!CTR->Value1().IsNull())
338 {
339 TDF_Tool::Entry(CTR->Value1()->Label(),S);
340 di << " Val1 (" << S.ToCString() << ")";
341 }
342
343 if (!CTR->NbInstances1().IsNull())
344 {
345 TDF_Tool::Entry(CTR->NbInstances1()->Label(),S);
346 di << " NbIns1 (" << S.ToCString() << ")";
347 }
348
349 if (!CTR->Axis2().IsNull())
350 {
351 TDF_Tool::Entry(CTR->Axis2()->Label(),S);
352 di << " Axis2 (" << S.ToCString() << ")";
353 }
354
355 if (!CTR->Value2().IsNull())
356 {
357 TDF_Tool::Entry(CTR->Value2()->Label(),S);
358 di << " Val2 (" << S.ToCString() << ")";
359 }
360
361 if (!CTR->NbInstances2().IsNull())
362 {
363 TDF_Tool::Entry(CTR->NbInstances2()->Label(),S);
364 di << " NbIns2 (" << S.ToCString() << ")";
365 }
366
367 if (!CTR->Mirror().IsNull())
368 {
369 TDF_Tool::Entry(CTR->Mirror()->Label(),S);
370 di << " Mirror (" << S.ToCString() << ")";
371 }
372 }
373 else
374 {
375 TDF_ChildIterator it (L,Standard_True);
376 for (;it.More();it.Next())
377 {
378 const TDF_Label& current = it.Value();
379 if (current.FindAttribute(TDataXtd_PatternStd::GetID(),CTR))
380 {
381 Standard_SStream aStream;
382// DDataStd::DumpPattern (CTR,aStream);
383 CTR->Dump(aStream);
384 di << aStream;
385 }
386 }
387 }
388 return 0;
389 }
586db386 390 di << "DDataStd_DumpPattern : Error : not done\n";
7fd59977 391 return 1;
392}
393
394//=======================================================================
395//function : DDataStd_SetPosition
396//purpose : SetPosition (DF, entry, X, Y, Z)
397//=======================================================================
398static Standard_Integer DDataStd_SetPosition (Draw_Interpretor& di,
399 Standard_Integer nb, const char** arg)
400{
401 if (nb == 6)
402 {
403 Handle(TDF_Data) DF;
404 if (!DDF::GetDF(arg[1],DF)) return 1;
405 TDF_Label L;
406 DDF::AddLabel(DF, arg[2], L);
407
91322f44 408 Standard_Real X = Draw::Atof(arg[3]), Y = Draw::Atof(arg[4]), Z = Draw::Atof(arg[5]);
7fd59977 409 gp_Pnt aPos (X, Y, Z);
410
411 TDataXtd_Position::Set(L,aPos);
412 return 0;
413 }
586db386 414 di << "Usage: SetPosition (DF, entry, X, Y, Z)\n";
7fd59977 415 return 1;
416}
417
418//=======================================================================
419//function : DDataStd_GetPosition
420//purpose : GetPosition (DF, entry, X(out), Y(out), Z(out))
421//=======================================================================
422static Standard_Integer DDataStd_GetPosition (Draw_Interpretor& di,
423 Standard_Integer nb, const char** arg)
424{
425 if (nb == 6)
426 {
427 Handle(TDF_Data) DF;
428 if (!DDF::GetDF(arg[1],DF)) return 1;
429 TDF_Label L;
430 DDF::AddLabel(DF, arg[2], L);
431
432 gp_Pnt aPos;
433 if (!TDataXtd_Position::Get(L, aPos))
434 {
586db386 435 di << "There is no TDataStd_Position attribute on this label\n";
7fd59977 436 return -1;
437 }
438
439 Draw::Set(arg[3],TCollection_AsciiString(aPos.X()).ToCString());
440 Draw::Set(arg[4],TCollection_AsciiString(aPos.Y()).ToCString());
441 Draw::Set(arg[5],TCollection_AsciiString(aPos.Z()).ToCString());
442 return 0;
443 }
586db386 444 di << "Usage: GetPosition (DF, entry, X(out), Y(out), Z(out))\n";
7fd59977 445 return 1;
446}
447
448
449//=======================================================================
450//function : ConstraintCommands
451//purpose :
452//=======================================================================
453void DDataStd::ConstraintCommands (Draw_Interpretor& theCommands)
454
455{
456 static Standard_Boolean done = Standard_False;
457 if (done) return;
458 done = Standard_True;
459 const char* g = "DData : Standard Attribute Commands";
460
461 theCommands.Add ("SetConstraint",
462 "SetConstraint (DF,entry,keyword,geometrie/value[,geometrie])",
463 __FILE__, DDataStd_SetConstraint, g);
464
465 theCommands.Add ("GetConstraint",
466 "GetConstraint (DF, entry)",
467 __FILE__, DDataStd_GetConstraint, g);
468
469 theCommands.Add ("SetPattern",
470 "SetPattern (DF,entry,signature,NSentry[realEntry,intEntry[,NSentry,realEntry,intEntry]])",
471 __FILE__, DDataStd_SetPattern, g);
472
473 theCommands.Add ("DumpPattern",
474 "DumpPattern (DF, entry)",
475 __FILE__, DDataStd_DumpPattern, g);
476
477
478 theCommands.Add ("SetPosition",
479 "SetPosition (DF, entry, X, Y, Z)",
480 __FILE__, DDataStd_SetPosition, g);
481
482 theCommands.Add ("GetPosition",
483 "GetPosition (DF, entry, X(out), Y(out), Z(out))",
484 __FILE__, DDataStd_GetPosition, g);
485}