0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / XDEDRAW / XDEDRAW_Shapes.cxx
CommitLineData
b311480e 1// Created on: 2000-08-04
2// Created by: Pavel TELKOV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 7// This library is free software; you can redistribute it and/or modify it under
8// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 9// by the Free Software Foundation, with special exception defined in the file
10// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11// distribution for complete text of the license and disclaimer of any warranty.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
7fd59977 16
42cf5bc1 17#include <BRep_Builder.hxx>
7fd59977 18#include <DBRep.hxx>
19#include <DDocStd.hxx>
42cf5bc1 20#include <Draw.hxx>
f8d4cfbb 21#include <gp_Ax1.hxx>
22#include <gp_Pnt.hxx>
7fd59977 23#include <gp_Trsf.hxx>
1b423e32 24#include <Message.hxx>
25#include <NCollection_DataMap.hxx>
42cf5bc1 26#include <TCollection_AsciiString.hxx>
1b423e32 27#include <TDF_ChildIterator.hxx>
42cf5bc1 28#include <TDF_Tool.hxx>
7fd59977 29#include <TDocStd_Document.hxx>
42cf5bc1 30#include <TopoDS_Compound.hxx>
31#include <TopoDS_Shape.hxx>
7fd59977 32#include <XCAFDoc_DocumentTool.hxx>
42cf5bc1 33#include <XCAFDoc_GraphNode.hxx>
7fd59977 34#include <XCAFDoc_Location.hxx>
42cf5bc1 35#include <XCAFDoc_ShapeTool.hxx>
36#include <XDEDRAW_Shapes.hxx>
da80ff68 37#include <XSAlgo.hxx>
38#include <XSAlgo_AlgoContainer.hxx>
39#include <UnitsMethods.hxx>
7fd59977 40
41#include <stdio.h>
7fd59977 42//=======================================================================
43// Section: Work with shapes
44//=======================================================================
7fd59977 45static Standard_Integer addShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
46{
47 if (argc<3) {
586db386 48 di<<"Use: "<<argv[0]<<" DocName Shape [int makeAssembly (1/0)]\n";
7fd59977 49 return 1;
50 }
51 Handle(TDocStd_Document) Doc;
52 DDocStd::GetDocument(argv[1], Doc);
586db386 53 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 54
85831628 55 TopoDS_Shape aShape = DBRep::Get(argv[2]);
56 if (aShape.IsNull())
57 {
d99f0355 58 di << "Syntax error: shape '" << argv[2] << "' is undefined\n";
85831628 59 return 1;
60 }
61
da80ff68 62 Standard_Real aLengthUnit = 1.;
63 if (!XCAFDoc_DocumentTool::GetLengthUnit(Doc, aLengthUnit))
64 {
65 XSAlgo::AlgoContainer()->PrepareForTransfer(); // update unit info
66 aLengthUnit = UnitsMethods::GetCasCadeLengthUnit(UnitsMethods_LengthUnit_Meter);
67 XCAFDoc_DocumentTool::SetLengthUnit(Doc, aLengthUnit);
68 }
69
7fd59977 70 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
71 Standard_Boolean makeAssembly = Standard_True;
91322f44 72 if ( argc==4 && Draw::Atoi(argv[3]) == 0 ) makeAssembly = Standard_False;
7fd59977 73 TDF_Label aLabel;
74 aLabel = myAssembly->AddShape(aShape, makeAssembly);
586db386 75 if (aLabel.IsNull()) di<<"Null Label\n";
7fd59977 76 TCollection_AsciiString Entry;
77 TDF_Tool::Entry(aLabel, Entry);
78 di << Entry.ToCString();
79 return 0;
80}
81
82static Standard_Integer newShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
83{
84 if (argc!=2) {
586db386 85 di<<"Use: "<<argv[0]<<" DocName \n";
7fd59977 86 return 1;
87 }
88 Handle(TDocStd_Document) Doc;
89 TDF_Label aLabel;
90 DDocStd::GetDocument(argv[1], Doc);
586db386 91 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 92
93 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
94//XCAFDoc_ShapeTool myAssembly;
95// myAssembly.Init(Doc);
96 aLabel=myAssembly->NewShape();
97 // di<<"New Shape at ChildTag"<<aLabel.Tag()<<"\n";
98 TCollection_AsciiString Entry;
99 TDF_Tool::Entry(aLabel, Entry);
100 di << Entry.ToCString();
101 return 0;
102}
103
104static Standard_Integer setShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
105{
106 if (argc!=4) {
586db386 107 di<<"Use: "<<argv[0]<<" DocName Label Shape \n";
7fd59977 108 return 1;
109 }
110 Handle(TDocStd_Document) Doc;
111 DDocStd::GetDocument(argv[1], Doc);
586db386 112 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 113
114 TDF_Label aLabel;
115 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
116 TopoDS_Shape aShape;
586db386 117 // if (aLabel.IsNull()) di<<"Null Label\n";
7fd59977 118 aShape = DBRep::Get(argv[3]);
119// XCAFDoc_ShapeTool myAssembly;
120// myAssembly.Init(Doc);
121 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
9baa8534 122 myAssembly->SetShape(aLabel, aShape);
7fd59977 123 return 0;
124}
125
126static Standard_Integer getShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
127{
128 if (argc!=4) {
586db386 129 di<<"Use: "<<argv[0]<<" Result DocName Label\n";
7fd59977 130 return 1;
131 }
132 Handle(TDocStd_Document) Doc;
133 DDocStd::GetDocument(argv[2], Doc);
586db386 134 if ( Doc.IsNull() ) { di << argv[2] << " is not a document\n"; return 1; }
7fd59977 135
136 TDF_Label aLabel;
137 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
586db386 138 if (aLabel.IsNull()) {di<<"No such Label\n"; return 1;}
7fd59977 139 TopoDS_Shape aShape;
140// XCAFDoc_ShapeTool myAssembly;
141// myAssembly.Init(Doc);
142 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
143 aShape = myAssembly->GetShape(aLabel);
144 Standard_CString name1 = argv[1];
145 DBRep::Set(name1, aShape);
146
147 return 0;
148}
149
150static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
151{
a7aa1465 152 if (argc != 3 && argc != 4)
153 {
586db386 154 di<<"Use: "<<argv[0]<<" DocName Label [int removeCompletely (1/0)]\n";
7fd59977 155 return 1;
156 }
157 Handle(TDocStd_Document) Doc;
158 DDocStd::GetDocument(argv[1], Doc);
586db386 159 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 160
161 TDF_Label aLabel;
162 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
586db386 163 if (aLabel.IsNull()) {di<<"No such Label\n"; return 1;}
7fd59977 164 TopoDS_Shape aShape;
165// XCAFDoc_ShapeTool myAssembly;
166// myAssembly.Init(Doc);
167 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
a7aa1465 168 Standard_Boolean removeCompletely = Standard_True;
91322f44 169 if ( argc == 4 && Draw::Atoi(argv[3]) == 0 )
a7aa1465 170 removeCompletely = Standard_False;
171 myAssembly->RemoveShape(aLabel, removeCompletely);
7fd59977 172
173 return 0;
174}
175
176static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
177{
7783ba11 178 if (argc < 3) {
179 di << "Use: " << argv[0] << " DocName Shape [0/1]\n";
7fd59977 180 return 1;
181 }
182 Handle(TDocStd_Document) Doc;
183 DDocStd::GetDocument(argv[1], Doc);
586db386 184 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 185
186 TDF_Label aLabel;
187 TopoDS_Shape aShape;
188 aShape = DBRep::Get(argv[2]);
189// XCAFDoc_ShapeTool myAssembly;
190// myAssembly.Init(Doc);
191 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
7783ba11 192 Standard_Boolean findInstance = ((argc == 4) && argv[3][0] == '1');
193 aLabel = myAssembly->FindShape(aShape, findInstance);
7fd59977 194 TCollection_AsciiString Entry;
195 TDF_Tool::Entry(aLabel, Entry);
196 di << Entry.ToCString();
197 //di<<"Label with Shape is "<<Entry<<"\n";
198 return 0;
199}
200
f277ba37 201static Standard_Integer findSubShape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
202{
203 if (argc != 4) {
204 di << "Use: " << argv[0] << " DocName Shape ParentLabel\n";
205 return 1;
206 }
207 Handle(TDocStd_Document) aDoc;
208 DDocStd::GetDocument(argv[1], aDoc);
209 if (aDoc.IsNull()) {
210 di << argv[1] << " is not a document\n";
211 return 1;
212 }
213
214 TopoDS_Shape aShape;
215 aShape = DBRep::Get(argv[2]);
216
217 TDF_Label aParentLabel;
218 TDF_Tool::Label(aDoc->GetData(), argv[3], aParentLabel);
219
220 TDF_Label aLabel;
221 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
222 aShapeTool->FindSubShape(aParentLabel, aShape, aLabel);
223
224 TCollection_AsciiString anEntry;
225 TDF_Tool::Entry(aLabel, anEntry);
226 di << anEntry.ToCString();
227 return 0;
228}
229
7783ba11 230static Standard_Integer findMainShape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
231{
232 if (argc != 3) {
233 di << "Use: " << argv[0] << " DocName SubShape\n";
234 return 1;
235 }
236 Handle(TDocStd_Document) aDoc;
237 DDocStd::GetDocument(argv[1], aDoc);
238 if (aDoc.IsNull()) {
239 di << argv[1] << " is not a document\n";
240 return 1;
241 }
242
243 TopoDS_Shape aShape;
244 aShape = DBRep::Get(argv[2]);
245
246 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
247 TDF_Label aLabel = aShapeTool->FindMainShape(aShape);
248
249 TCollection_AsciiString anEntry;
250 TDF_Tool::Entry(aLabel, anEntry);
251 di << anEntry.ToCString();
252 return 0;
253}
254
255
f277ba37 256static Standard_Integer addSubShape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
257{
258 if (argc != 4) {
259 di << "Use: " << argv[0] << " DocName Shape ParentLabel\n";
260 return 1;
261 }
262 Handle(TDocStd_Document) aDoc;
263 DDocStd::GetDocument(argv[1], aDoc);
264 if (aDoc.IsNull()) { di << argv[1] << " is not a document\n"; return 1; }
265
266 TopoDS_Shape aShape;
267 aShape = DBRep::Get(argv[2]);
268
269 TDF_Label aParentLabel;
270 TDF_Tool::Label(aDoc->GetData(), argv[3], aParentLabel);
271
272 TDF_Label aLabel;
273 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
274 aLabel = aShapeTool->AddSubShape(aParentLabel, aShape);
275
276 TCollection_AsciiString anEntry;
277 TDF_Tool::Entry(aLabel, anEntry);
278 di << anEntry.ToCString();
279 return 0;
280}
281
7fd59977 282static Standard_Integer labelInfo (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
283{
284 if (argc!=3) {
586db386 285 di<<"Use: "<<argv[0]<<" DocName Label \n";
7fd59977 286 return 1;
287 }
288 Handle(TDocStd_Document) Doc;
289 DDocStd::GetDocument(argv[1], Doc);
586db386 290 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 291
292 TDF_Label aLabel;
293 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
294// XCAFDoc_ShapeTool myAssembly;
295// myAssembly.Init(Doc);
296 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
297 TCollection_AsciiString Entry;
298
299 if ( myAssembly->IsShape(aLabel) ) {
586db386 300 //di<<"There are a TopLevelShape\n";
7fd59977 301 Entry="There are a TopLevelShape";
302 di << Entry.ToCString();
303 }
304 if ( myAssembly->IsComponent(aLabel) ) {
586db386 305 //di<<"There are a Component\n";
7fd59977 306 Entry="There are a Component";
307 di << Entry.ToCString();
308 }
309 if ( myAssembly->IsAssembly(aLabel) ) {
586db386 310 //di<<"There are an Assembly\n";
7fd59977 311 Entry="There are an Assembly";
312 di << Entry.ToCString();
313 }
314 if ( myAssembly->IsFree(aLabel) ) {
586db386 315 //di<<"This Shape don't used\n";
7fd59977 316 Entry="This Shape don't used";
317 di << Entry.ToCString();
318 }
319 return 0;
320}
321
322static Standard_Integer getUsers (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
323{
324 if (argc<3) {
586db386 325 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]\n";
7fd59977 326 return 1;
327 }
328 Standard_Boolean getsubchilds = Standard_False;
91322f44 329 if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
7fd59977 330
331 Handle(TDocStd_Document) Doc;
332 DDocStd::GetDocument(argv[1], Doc);
586db386 333 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 334
335 TDF_Label aLabel;
336 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
337 TDF_LabelSequence labseq;
338 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
339 TCollection_AsciiString Entry;
340 Entry=myAssembly->GetUsers(aLabel, labseq, getsubchilds);
341 di << Entry.ToCString();
586db386 342 //di<<myAssembly->GetUsers(aLabel, labseq, getsubchilds)<<" assemblies use this component\n";
7fd59977 343 return 0;
344}
345
346static Standard_Integer nbComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
347{
348 if (argc<3) {
586db386 349 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]\n";
7fd59977 350 return 1;
351 }
352 Standard_Boolean getsubchilds = Standard_False;
91322f44 353 if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
7fd59977 354 Handle(TDocStd_Document) Doc;
355 DDocStd::GetDocument(argv[1], Doc);
586db386 356 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 357
358 TDF_Label aLabel;
359 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
360 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
361// XCAFDoc_ShapeTool myAssembly->
362// myAssembly->Init(Doc);
363 //di<<"This assembly has ";
364 TCollection_AsciiString Entry;
365 Entry=myAssembly->NbComponents( aLabel, getsubchilds);
366 di << Entry.ToCString();
586db386 367 //di<<" components\n";
368 //di<<"This assembly has "<<myAssembly->NbComponents( aLabel, getsubchilds )<<" components\n";
7fd59977 369
370 return 0;
371}
372
373static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
374{
375 if (argc!=4) {
586db386 376 di<<"Use: "<<argv[0]<<" DocName Label Shape \n";
7fd59977 377 return 1;
378 }
379 Handle(TDocStd_Document) Doc;
380 DDocStd::GetDocument(argv[1], Doc);
586db386 381 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 382
383 TDF_Label aLabel;
384 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
385 TopoDS_Shape aShape;
386 aShape = DBRep::Get(argv[3]);
387 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
388// XCAFDoc_ShapeTool myAssembly->
389// myAssembly->Init(Doc);
390 myAssembly->AddComponent(aLabel, aShape);
391 TCollection_AsciiString Entry;
392 TDF_Tool::Entry(aLabel, Entry);
393 di << Entry.ToCString();
394
395 return 0;
396}
397
398static Standard_Integer removeComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
399{
400 if (argc!=3) {
586db386 401 di<<"Use: "<<argv[0]<<" DocName Label \n";
7fd59977 402 return 1;
403 }
404 Handle(TDocStd_Document) Doc;
405 DDocStd::GetDocument(argv[1], Doc);
586db386 406 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 407
408 TDF_Label aLabel;
409 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
410 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
411// XCAFDoc_ShapeTool myAssembly->
412// myAssembly->Init(Doc);
413 myAssembly->RemoveComponent(aLabel);
414 return 0;
415}
416
417static Standard_Integer getReferredShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
418{
419 if (argc!=3) {
586db386 420 di<<"Use: "<<argv[0]<<" DocName Label \n";
7fd59977 421 return 1;
422 }
423 Handle(TDocStd_Document) Doc;
424 DDocStd::GetDocument(argv[1], Doc);
586db386 425 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 426
427 TDF_Label aLabel, RootLabel;
428 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
429 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
430// XCAFDoc_ShapeTool myAssembly->
431// myAssembly->Init(Doc);
432 myAssembly->GetReferredShape(aLabel, RootLabel);
433
434 TCollection_AsciiString Entry;
435 TDF_Tool::Entry(RootLabel, Entry);
436 //di<<"Label with Shape is ";
437 di << Entry.ToCString();
438 return 0;
439}
440
441static Standard_Integer getTopLevelShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
442{
443 if (argc!=2) {
586db386 444 di<<"Use: "<<argv[0]<<" DocName \n";
7fd59977 445 return 1;
446 }
447 Handle(TDocStd_Document) Doc;
448 DDocStd::GetDocument(argv[1], Doc);
586db386 449 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 450
451 TDF_Label aLabel;
452 TDF_LabelSequence Labels;
453
454 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
455// XCAFDoc_ShapeTool myAssembly->
456// myAssembly->Init(Doc);
457 myAssembly->GetShapes(Labels);
458 TCollection_AsciiString Entry;
459 if (Labels.Length() >= 1) {
460 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
461 aLabel = Labels.Value(i);
462 TDF_Tool::Entry( aLabel, Entry);
463 di << Entry.ToCString() << " ";
464 }
465 }
466 return 0;
467}
468
469static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
470{
471 if (argc <2) {
586db386 472 di<<"Use: "<<argv[0]<<" DocName [shape_prefix]\n";
7fd59977 473 return 1;
474 }
475
476 Handle(TDocStd_Document) Doc;
477 DDocStd::GetDocument(argv[1], Doc);
586db386 478 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 479
480 TDF_LabelSequence Labels;
481 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
482 STool->GetFreeShapes(Labels);
483 if ( Labels.Length() <=0 ) {
586db386 484 di << "Document " << argv[1] << " contain no shapes\n";
7fd59977 485 return 0;
486 }
487
488 if ( argc ==2 ) {
489 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
490 TCollection_AsciiString Entry;
491 TDF_Tool::Entry( Labels.Value(i), Entry);
492 di << Entry.ToCString() << " ";
493 }
494 }
495 else if ( Labels.Length() ==1 ) {
496 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
497 DBRep::Set ( argv[2], S );
498 di << argv[2];
499 }
500 else {
501 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
502 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
503 char string[260];
91322f44 504 Sprintf ( string, "%s_%d", argv[2], i );
7fd59977 505 DBRep::Set ( string, S );
506 di << string << " ";
507 }
508 }
509 return 0;
510}
511
c772c6ca 512//=======================================================================
513//function : getOneShape
514//purpose :
515//=======================================================================
516static Standard_Integer getOneShape (Draw_Interpretor& theDI,
517 Standard_Integer theNbArgs,
518 const char** theArgVec)
7fd59977 519{
c772c6ca 520 if ( theNbArgs !=3 )
521 {
522 theDI <<"Use: "<< theArgVec[0]<<" shape DocName \n";
7fd59977 523 return 1;
524 }
525
c772c6ca 526 Handle(TDocStd_Document) aDoc;
527 DDocStd::GetDocument(theArgVec[2], aDoc);
528 if ( aDoc.IsNull() )
529 {
530 theDI << "Error: " << theArgVec[2] << " is not a document\n";
531 return 1;
7fd59977 532 }
c772c6ca 533
534 Handle(XCAFDoc_ShapeTool) aSTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
535 TopoDS_Shape aShape = aSTool->GetOneShape();
536 if (aShape.IsNull())
537 {
538 theDI << "Error: Document " << theArgVec[2] << " contain no shapes\n";
539 return 1;
7fd59977 540 }
c772c6ca 541 DBRep::Set (theArgVec[1], aShape);
542 theDI << theArgVec[1];
7fd59977 543 return 0;
544}
545
546//=======================================================================
547//function : XDumpLocation
548//purpose : Dump Transformation() of XCAFDoc_Location attribute
549//=======================================================================
550static Standard_Integer XDumpLocation (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
551{
552 if (argc != 3)
553 {
586db386 554 di << "Use: " << argv[0] << " Doc Label \n";
7fd59977 555 return 1;
556 }
557 Handle(TDocStd_Document) Doc;
558 DDocStd::GetDocument(argv[1], Doc);
559 if (Doc.IsNull())
560 {
586db386 561 di << argv[1] << " is not a document\n";
7fd59977 562 return 1;
563 }
564
565 TDF_Label aLabel;
566 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
567
568 Handle(XCAFDoc_Location) aLoc;
569 if (!aLabel.FindAttribute(XCAFDoc_Location::GetID(), aLoc))
570 {
586db386 571 di << "Label " << argv[2] << " doesn't contain XCAFDoc_Location attribute\n";
7fd59977 572 return 1;
573 }
574
575 TopLoc_Location aTopLoc = aLoc->Get();
576 gp_Trsf aTrsf = aTopLoc.Transformation();
577
578 di << "Transformation (3 rows * 4 columns matrix):";
579 for (int i = 1; i <= 3; i++) // row number
580 {
581 di << " (";
582 for (int j = 1; j <= 4; j++) // column number
583 {
584 if (j > 1) di << ",";
585 di << TCollection_AsciiString(aTrsf.Value(i,j)).ToCString();
586 }
587 di << ")";
588 }
589
590 return 0;
591}
592
593static Standard_Integer setSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
594{
595 if (argc < 4)
596 {
586db386 597 di << "Use: " << argv[0] << " Doc UU_Label NU_Label \n";
7fd59977 598 return 1;
599 }
600 Handle(TDocStd_Document) Doc;
601 DDocStd::GetDocument(argv[1], Doc);
586db386 602 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 603
604 TDF_LabelSequence aLabSeq;
605 for (Standard_Integer i = 3; i <= argc; i++) {
606 TDF_Label L;
607 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
608 if (!L.IsNull())
609 aLabSeq.Append( L );
610 else
611 di << argv[i - 1] << " is null label" << "\n";
612 }
613 if (aLabSeq.Length() < 2) {
586db386 614 di << "Error: couldnot set SHUO between on less then 2 labels\n";
7fd59977 615 }
616 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
617 Handle(XCAFDoc_GraphNode) aMainSHUO;
618 myAssembly->SetSHUO( aLabSeq, aMainSHUO );
619 if (aMainSHUO.IsNull()) {
586db386 620 di << "Error: cannot set the SHUO\n";
7fd59977 621 return 1;
622 }
623
624 return 0;
625}
626
627static Standard_Integer getSHUOUpperUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
628{
629 if (argc < 3)
630 {
586db386 631 di << "Use: " << argv[0] << " Doc NU_Label \n";
7fd59977 632 return 1;
633 }
634 Handle(TDocStd_Document) Doc;
635 DDocStd::GetDocument(argv[1], Doc);
586db386 636 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 637 TDF_Label NL;
638 TDF_Tool::Label(Doc->GetData(), argv[2], NL);
639 if (NL.IsNull()) {
640 di << argv[2] << " is null label" << "\n";
641 return 1;
642 }
643 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
644 TDF_LabelSequence labseq;
645 myAssembly->GetSHUOUpperUsage( NL, labseq );
646 TCollection_AsciiString Entry;
647 if (labseq.Length() >= 1) {
648 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
649 TDF_Label aLabel = labseq.Value(i);
650 TDF_Tool::Entry( aLabel, Entry);
651 di << Entry.ToCString() << " ";
652 }
653 }
654 return 0;
655}
656
657static Standard_Integer getSHUONextUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
658{
659 if (argc < 3)
660 {
586db386 661 di << "Use: " << argv[0] << " Doc UU_Label \n";
7fd59977 662 return 1;
663 }
664 Handle(TDocStd_Document) Doc;
665 DDocStd::GetDocument(argv[1], Doc);
586db386 666 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 667 TDF_Label UL;
668 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
669 if (UL.IsNull()) {
670 di << argv[2] << " is null label" << "\n";
671 return 1;
672 }
673 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
674 TDF_LabelSequence labseq;
675 myAssembly->GetSHUONextUsage( UL, labseq );
676 TCollection_AsciiString Entry;
677 if (labseq.Length() >= 1) {
678 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
679 TDF_Label aLabel = labseq.Value(i);
680 TDF_Tool::Entry( aLabel, Entry);
681 di << Entry.ToCString() << " ";
682 }
683 }
684 return 0;
685}
686
687static Standard_Integer removeSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
688{
689 if (argc < 3)
690 {
586db386 691 di << "Use: " << argv[0] << " Doc SHUOComponent_Label \n";
7fd59977 692 return 1;
693 }
694 Handle(TDocStd_Document) Doc;
695 DDocStd::GetDocument(argv[1], Doc);
586db386 696 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 697 TDF_Label UL;
698 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
699 if (UL.IsNull()) {
700 di << argv[2] << " is null label" << "\n";
701 return 1;
702 }
703 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
704 myAssembly->RemoveSHUO( UL );
705
706 return 0;
707}
708
709static Standard_Integer hasSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
710{
711 if (argc < 3)
712 {
586db386 713 di << "Use: " << argv[0] << " Doc SHUO_Label \n";
7fd59977 714 return 1;
715 }
716 Handle(TDocStd_Document) Doc;
717 DDocStd::GetDocument(argv[1], Doc);
586db386 718 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 719 TDF_Label UL;
720 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
721 if (UL.IsNull()) {
722 di << argv[2] << " is null label" << "\n";
723 return 1;
724 }
725 Handle(XCAFDoc_GraphNode) anAttrSHUO;
726 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
727 if (myAssembly->GetSHUO( UL, anAttrSHUO ))
728 di << 1;
729 else
730 di << 0;
731
732 return 0;
733}
734
735static Standard_Integer getAllSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
736{
737 if (argc < 3)
738 {
586db386 739 di << "Use: " << argv[0] << " Doc SHUO_Label \n";
7fd59977 740 return 1;
741 }
742 Handle(TDocStd_Document) Doc;
743 DDocStd::GetDocument(argv[1], Doc);
586db386 744 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 745 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
746 TDF_Label UL;
747 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
748 if (UL.IsNull()) {
749 di << argv[2] << " is null label" << "\n";
750 return 1;
751 }
752 TDF_AttributeSequence SHUOAttrs;
753 myAssembly->GetAllComponentSHUO( UL, SHUOAttrs );
754 TCollection_AsciiString Entry;
755 if (SHUOAttrs.Length() >= 1) {
756 for ( Standard_Integer i = 1; i<= SHUOAttrs.Length(); i++) {
757 TDF_Label aLabel = SHUOAttrs.Value(i)->Label();
758 TDF_Tool::Entry( aLabel, Entry);
759 di << Entry.ToCString() << " ";
760 }
761 }
762 return 0;
763}
764
765static Standard_Integer findComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
766{
767 if (argc < 3)
768 {
586db386 769 di << "Use: " << argv[0] << " Doc shape \n";
7fd59977 770 return 1;
771 }
772 Handle(TDocStd_Document) Doc;
773 DDocStd::GetDocument(argv[1], Doc);
586db386 774 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 775 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
776 TopoDS_Shape aShape;
777 aShape = DBRep::Get(argv[2]);
778 TDF_LabelSequence labseq;
779 myAssembly->FindComponent( aShape, labseq );
780 TCollection_AsciiString Entry;
781 if (labseq.Length() >= 1) {
782 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
783 TDF_Label aLabel = labseq.Value(i);
784 TDF_Tool::Entry( aLabel, Entry);
785 di << Entry.ToCString() << " ";
786 }
787 }
788 return 0;
789}
790
791static Standard_Integer getStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
792{
793 if (argc < 4)
794 {
586db386 795 di << "Use: " << argv[0] << " Doc res SHUO_label \n";
7fd59977 796 return 1;
797 }
798 Handle(TDocStd_Document) Doc;
799 DDocStd::GetDocument(argv[1], Doc);
586db386 800 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 801 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
802 TopoDS_Shape aShape;
803 TDF_Label aLabel;
804 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
805 Handle(XCAFDoc_GraphNode) SHUO;
806 if (myAssembly->GetSHUO( aLabel, SHUO ))
807 aShape = myAssembly->GetSHUOInstance( SHUO );
808
809 if (aShape.IsNull()) {
586db386 810 di << "cannot get component\n";
7fd59977 811 return 1;
812 }
813 DBRep::Set ( argv[2], aShape );
814 di << argv[2];
815 return 0;
816}
817
818static Standard_Integer getAllStyledComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
819{
820 if (argc < 4)
821 {
586db386 822 di << "Use: " << argv[0] << " Doc res SHUO_label \n";
7fd59977 823 return 1;
824 }
825 Handle(TDocStd_Document) Doc;
826 DDocStd::GetDocument(argv[1], Doc);
586db386 827 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 828 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
829 TopTools_SequenceOfShape aShapes;
830 TDF_Label aLabel;
831 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
832 Handle(XCAFDoc_GraphNode) SHUO;
833 if (myAssembly->GetSHUO( aLabel, SHUO ))
834 if (myAssembly->GetAllSHUOInstances(SHUO, aShapes)) {
835 TopoDS_Compound aShape;
836 BRep_Builder B;
837 B.MakeCompound(aShape);
838 for (Standard_Integer jj = 1; jj <= aShapes.Length(); jj++) {
b2fedee6 839 const TopoDS_Shape& aCurShape = aShapes.Value(jj);
7fd59977 840 B.Add( aShape, aCurShape );
841 }
842 DBRep::Set ( argv[2], aShape );
843 di << argv[2];
844 }
845
846 return 0;
847}
848
849static Standard_Integer findSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
850{
851 if (argc < 4)
852 {
586db386 853 di << "Use: " << argv[0] << " Doc labels \n";
7fd59977 854 return 1;
855 }
856 Handle(TDocStd_Document) Doc;
857 DDocStd::GetDocument(argv[1], Doc);
586db386 858 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 859 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
860 TDF_LabelSequence aLabSeq;
861 for (Standard_Integer i = 3; i <= argc; i++) {
862 TDF_Label L;
863 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
864 if (!L.IsNull())
865 aLabSeq.Append( L );
866 else
867 di << argv[i - 1] << " is null label" << "\n";
868 }
869 if (aLabSeq.Length() < 2) {
586db386 870 di << "Error: couldnot find SHUO between on less then 2 labels\n";
7fd59977 871 }
872 Handle(XCAFDoc_GraphNode) SHUO;
873 myAssembly->FindSHUO( aLabSeq, SHUO );
874 if (SHUO.IsNull()) {
586db386 875 di << "cannot find SHUO\n";
7fd59977 876 return 1;
877 }
878 TCollection_AsciiString Entry;
879 TDF_Tool::Entry( SHUO->Label(), Entry);
880 di << Entry.ToCString() << " ";
881
882 return 0;
883}
884
885static Standard_Integer setStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
886{
887 if (argc < 3)
888 {
586db386 889 di << "Use: " << argv[0] << " Doc shape \n";
7fd59977 890 return 1;
891 }
892 Handle(TDocStd_Document) Doc;
893 DDocStd::GetDocument(argv[1], Doc);
586db386 894 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
7fd59977 895 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
896 TopoDS_Shape aShape;
897 aShape = DBRep::Get(argv[2]);
898 if (aShape.IsNull()) {
586db386 899 di << "Shape " << argv[2] << " is null\n";
7fd59977 900 return 1;
901 }
902 Handle(XCAFDoc_GraphNode) aSHUOAttr;
903 aSHUOAttr = myAssembly->SetInstanceSHUO( aShape );
904 if (aSHUOAttr.IsNull()) {
905 di << "Error: cannot set a SHUO structure for indicated component" << "\n";
906 return 1;
907 }
908 TCollection_AsciiString Entry;
909 TDF_Tool::Entry( aSHUOAttr->Label(), Entry);
910 di << Entry.ToCString() << " ";
911
912 return 0;
913}
acc909a8 914
915static Standard_Integer updateAssemblies(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
916{
917 if (argc != 2)
918 {
919 di << "Use: " << argv[0] << " Doc\n";
920 return 1;
921 }
922
923 // Get XDE document
924 Handle(TDocStd_Document) aDoc;
925 DDocStd::GetDocument(argv[1], aDoc);
926 if ( aDoc.IsNull() )
927 return 1;
928
929 // Get XDE shape tool
930 Handle(XCAFDoc_ShapeTool)
931 aShapeTool = XCAFDoc_DocumentTool::ShapeTool( aDoc->Main() );
932
933 // Update assemblies
934 aShapeTool->UpdateAssemblies();
935
936 return 0;
937}
938
1b423e32 939static Standard_Integer XGetProperties(Draw_Interpretor& theDI,
940 Standard_Integer theArgc,
941 const char** theArgv)
07f20646 942{
1b423e32 943 if (theArgc < 2)
07f20646 944 {
1b423e32 945 theDI.PrintHelp(theArgv[0]);
07f20646 946 return 1;
947 }
948
949 Handle(TDocStd_Document) aDoc;
1b423e32 950 DDocStd::GetDocument(theArgv[1], aDoc);
07f20646 951 if (aDoc.IsNull())
952 {
1b423e32 953 theDI << "Syntax error: " << theArgv[1] << " is not a document\n";
07f20646 954 return 1;
955 }
07f20646 956 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
1b423e32 957 NCollection_IndexedDataMap<TCollection_AsciiString, Handle(TDataStd_NamedData)> aNameDataMap;
958 for (Standard_Integer anInd = 2; anInd < theArgc; anInd++)
07f20646 959 {
1b423e32 960 TDF_Label aLabel;
961 const TCollection_AsciiString anEntry = theArgv[anInd];
962 TDF_Tool::Label(aDoc->GetData(), anEntry, aLabel);
963 if (aLabel.IsNull())
964 {
965 TopoDS_Shape aShape = DBRep::Get(theArgv[anInd]);
966 if (!aShape.IsNull())
967 {
968 aLabel = aShapeTool->FindShape(aShape);
969 }
970 }
971 if (!aLabel.IsNull())
972 {
973 Handle(TDataStd_NamedData) aNamedData = aShapeTool->GetNamedProperties(aLabel);
974 if (!aNamedData.IsNull())
975 {
976 aNameDataMap.Add(anEntry, aNamedData);
977 }
978 }
979 else
07f20646 980 {
1b423e32 981 Message::SendWarning() << "Warning: incorrect argument [" << theArgv[anInd] << "]" << " is not a label";
07f20646 982 }
983 }
1b423e32 984 if (theArgc == 2)
07f20646 985 {
1b423e32 986 for (TDF_ChildIterator anIter(aShapeTool->Label(), Standard_True);
987 anIter.More(); anIter.Next())
07f20646 988 {
1b423e32 989 const TDF_Label& aLabel = anIter.Value();
990 TCollection_AsciiString anEntry;
991 TDF_Tool::Entry(aLabel, anEntry);
992 Handle(TDataStd_NamedData) aNamedData = aShapeTool->GetNamedProperties(aLabel);
993 if (!aNamedData.IsNull())
994 {
995 aNameDataMap.Add(anEntry, aNamedData);
996 }
07f20646 997 }
998 }
1b423e32 999 for (NCollection_IndexedDataMap<TCollection_AsciiString, Handle(TDataStd_NamedData)>::Iterator aNamedDataIter(aNameDataMap);
1000 aNamedDataIter.More(); aNamedDataIter.Next())
07f20646 1001 {
1b423e32 1002 if (theArgc != 3)
1003 {
1004 theDI << "Property for [" << aNamedDataIter.Key() << "]:\n";
1005 }
1006 const Handle(TDataStd_NamedData)& aNamedData = aNamedDataIter.Value();
1007 aNamedData->LoadDeferredData();
1008 if (aNamedData->HasIntegers())
1009 {
1010 const TColStd_DataMapOfStringInteger& anIntProperties = aNamedData->GetIntegersContainer();
1011 for (TColStd_DataMapIteratorOfDataMapOfStringInteger anIter(anIntProperties); anIter.More(); anIter.Next())
1012 {
1013 theDI << anIter.Key() << " : " << anIter.Value() << "\n";
1014 }
1015 }
1016 if (aNamedData->HasReals())
07f20646 1017 {
1b423e32 1018 const TDataStd_DataMapOfStringReal& aRealProperties = aNamedData->GetRealsContainer();
1019 for (TDataStd_DataMapIteratorOfDataMapOfStringReal anIter(aRealProperties); anIter.More(); anIter.Next())
1020 {
1021 theDI << anIter.Key() << " : " << anIter.Value() << "\n";
1022 }
1023 }
1024 if (aNamedData->HasStrings())
1025 {
1026 const TDataStd_DataMapOfStringString& aStringProperties = aNamedData->GetStringsContainer();
1027 for (TDataStd_DataMapIteratorOfDataMapOfStringString anIter(aStringProperties); anIter.More(); anIter.Next())
1028 {
1029 theDI << anIter.Key() << " : " << anIter.Value() << "\n";
1030 }
1031 }
1032 if (aNamedData->HasBytes())
1033 {
1034 const TDataStd_DataMapOfStringByte& aByteProperties = aNamedData->GetBytesContainer();
1035 for (TDataStd_DataMapOfStringByte::Iterator anIter(aByteProperties); anIter.More(); anIter.Next())
1036 {
1037 theDI << anIter.Key() << " : " << anIter.Value() << "\n";
1038 }
1039 }
1040 if (aNamedData->HasArraysOfIntegers())
1041 {
1042 const TDataStd_DataMapOfStringHArray1OfInteger& anArrayIntegerProperties =
1043 aNamedData->GetArraysOfIntegersContainer();
1044 for (TDataStd_DataMapOfStringHArray1OfInteger::Iterator anIter(anArrayIntegerProperties);
1045 anIter.More(); anIter.Next())
1046 {
1047 TCollection_AsciiString aMessage(anIter.Key() + " : ");
1048 for (TColStd_HArray1OfInteger::Iterator anSubIter(anIter.Value()->Array1());
1049 anSubIter.More(); anSubIter.Next())
1050 {
1051 aMessage += " ";
1052 aMessage += anSubIter.Value();
1053 }
1054 theDI << aMessage << "\n";
1055 }
1056 }
1057 if (aNamedData->HasArraysOfReals())
1058 {
1059 const TDataStd_DataMapOfStringHArray1OfReal& anArrayRealsProperties =
1060 aNamedData->GetArraysOfRealsContainer();
1061 for (TDataStd_DataMapOfStringHArray1OfReal::Iterator anIter(anArrayRealsProperties);
1062 anIter.More(); anIter.Next())
1063 {
1064 TCollection_AsciiString aMessage(anIter.Key() + " : ");
1065 for (TColStd_HArray1OfReal::Iterator anSubIter(anIter.Value()->Array1());
1066 anSubIter.More(); anSubIter.Next())
1067 {
1068 aMessage += " ";
1069 aMessage += anSubIter.Value();
1070 }
1071 theDI << aMessage << "\n";
1072 }
07f20646 1073 }
1074 }
1075
1076 return 0;
1077}
1078
16f9b46d 1079static Standard_Integer XAutoNaming (Draw_Interpretor& theDI,
1080 Standard_Integer theNbArgs,
1081 const char** theArgVec)
1082{
1083 if (theNbArgs != 2 && theNbArgs != 3)
1084 {
1085 theDI << "Syntax error: wrong number of arguments";
1086 return 1;
1087 }
1088
1089 Handle(TDocStd_Document) aDoc;
1090 DDocStd::GetDocument (theArgVec[1], aDoc);
1091 if (aDoc.IsNull())
1092 {
1093 theDI << "Syntax error: '" << theArgVec[1] << "' is not a document";
1094 return 1;
1095 }
1096
1097 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
1098 if (theNbArgs == 2)
1099 {
1100 theDI << (aShapeTool->AutoNaming() ? "1" : "0");
1101 return 0;
1102 }
1103
1104 bool toEnable = true;
1105 if (!Draw::ParseOnOff (theArgVec[2], toEnable))
1106 {
1107 theDI << "Syntax error at '" << theArgVec[2] << "'";
1108 return 1;
1109 }
1110
1111 aShapeTool->SetAutoNaming (toEnable);
1112 return 0;
1113}
1114
f8d4cfbb 1115//=======================================================================
1116// function : parseXYZ
1117// purpose : Converts three string arguments, to gp_XYZ with check
1118//=======================================================================
1119static Standard_Boolean parseXYZ (const char** theArgVec, gp_XYZ& thePnt)
1120{
1121 const TCollection_AsciiString aXYZ[3] = {theArgVec[0], theArgVec[1], theArgVec[2] };
1122 if (!aXYZ[0].IsRealValue (Standard_True)
1123 || !aXYZ[1].IsRealValue (Standard_True)
1124 || !aXYZ[2].IsRealValue (Standard_True))
1125 {
1126 return Standard_False;
1127 }
1128
1129 thePnt.SetCoord (aXYZ[0].RealValue(), aXYZ[1].RealValue(), aXYZ[2].RealValue());
1130 return Standard_True;
1131}
1132
1133//=======================================================================
1134// function : setLocation
1135// purpose : Sets location to the shape at the label in XDE document
1136//=======================================================================
1137static Standard_Integer setLocation (Draw_Interpretor& , Standard_Integer theArgNb, const char** theArgVec)
1138{
1139 if (theArgNb < 4)
1140 {
1141 Message::SendFail() << "Error: not enough arguments, see help " << theArgVec[0] << " for details";
1142 return 1;
1143 }
1144 // get and check the document
1145 Handle(TDocStd_Document) aDoc;
1146 DDocStd::GetDocument (theArgVec[1], aDoc);
1147 if (aDoc.IsNull ())
1148 {
1149 Message::SendFail() << "Error: " << theArgVec[1] << " is not a document";
1150 return 1;
1151 }
1152 // get and check the label
1153 TDF_Label aShapeLabel;
1154 TDF_Tool::Label (aDoc->GetData(), theArgVec[2], aShapeLabel);
1155 if (aShapeLabel.IsNull ())
1156 {
1157 Message::SendFail() << "Error: no such Label: " << theArgVec[2];
1158 return 1;
1159 }
1160 // get the transformation
1161 gp_Trsf aTransformation;
1162 for (Standard_Integer anArgIter = 3; anArgIter < theArgNb; ++anArgIter)
1163 {
1164 gp_Trsf aCurTransformation;
1165 gp_XYZ aMoveXYZ, aRotPnt, aRotAxis, aScalePnt;
1166 Standard_Real aRotAngle, aScale;
1167 TCollection_AsciiString anArg = theArgVec[anArgIter];
1168 anArg.LowerCase();
1169
1170 if (anArg == "-rotate" &&
1171 anArgIter + 7 < theArgNb &&
1172 parseXYZ (theArgVec + anArgIter + 1, aRotPnt) &&
1173 parseXYZ (theArgVec + anArgIter + 4, aRotAxis) &&
1174 Draw::ParseReal (theArgVec[anArgIter + 7], aRotAngle))
1175 {
1176 anArgIter += 7;
1177 aCurTransformation.SetRotation (gp_Ax1 (gp_Pnt (aRotPnt), gp_Dir (aRotAxis)), aRotAngle * (M_PI / 180.0));
1178 }
1179 else if (anArg == "-move" &&
1180 anArgIter + 3 < theArgNb &&
1181 parseXYZ (theArgVec + anArgIter + 1, aMoveXYZ))
1182 {
1183 anArgIter += 3;
1184 aCurTransformation.SetTranslation (aMoveXYZ);
1185 }
1186 // first check scale with base point
1187 else if (anArg == "-scale" &&
1188 anArgIter + 4 < theArgNb &&
1189 parseXYZ (theArgVec + anArgIter + 1, aScalePnt) &&
1190 Draw::ParseReal (theArgVec[anArgIter + 4], aScale))
1191 {
1192 anArgIter += 4;
1193 aCurTransformation.SetScale (gp_Pnt (aScalePnt), aScale);
1194 }
1195 // second check for scale with scale factor only
1196 else if (anArg == "-scale" &&
1197 anArgIter + 1 < theArgNb &&
1198 Draw::ParseReal (theArgVec[anArgIter + 1], aScale))
1199 {
1200 anArgIter += 1;
1201 aCurTransformation.SetScaleFactor (aScale);
1202 }
1203 else
1204 {
1205 Message::SendFail() << "Syntax error: unknown options '" << anArg << "', or incorrect option parameters";
1206 return 1;
1207 }
1208 aTransformation.PreMultiply (aCurTransformation);
1209 }
1210 TopLoc_Location aLoc(aTransformation);
1211
1212 // Create the ShapeTool and try to set location
1213 Handle(XCAFDoc_ShapeTool) anAssembly = XCAFDoc_DocumentTool::ShapeTool (aDoc->Main());
1214 TDF_Label aRefLabel;
1215 if (anAssembly->SetLocation (aShapeLabel, aLoc, aRefLabel))
1216 {
1217 if (aShapeLabel == aRefLabel)
1218 {
1219 Message::SendInfo() << "New location was set";
1220 }
1221 else
1222 {
1223 TCollection_AsciiString aLabelStr;
1224 TDF_Tool::Entry(aRefLabel, aLabelStr);
1225 Message::SendInfo() << "Reference to the shape at label " << aLabelStr << " was created and location was set";
1226 }
1227 }
1228 else
1229 {
1230 Message::SendFail() << "Error: an attempt to set the location to a shape to which there is a reference, or to not a shape at all";
1231 }
1232
1233 return 0;
1234}
1235
7fd59977 1236//=======================================================================
1237//function : InitCommands
1238//purpose :
1239//=======================================================================
1240
1241void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di)
1242{
7fd59977 1243 static Standard_Boolean initactor = Standard_False;
c48e2889 1244 if (initactor)
1245 {
1246 return;
1247 }
1248 initactor = Standard_True;
7fd59977 1249
1250 //=====================================
1251 // Work with shapes
1252 //=====================================
1253
1254 Standard_CString g = "XDE shape's commands";
1255
1256 di.Add ("XAddShape","Doc Shape [makeAssembly = 1]\t: Add shape (or assembly) to Document",
1257 __FILE__, addShape, g);
1258
1259 di.Add ("XNewShape","Doc \t: Create new empty top-level shape",
1260 __FILE__, newShape, g);
1261
1262 di.Add ("XSetShape","Doc Label Shape \t: Set shape at indicated label",
1263 __FILE__, setShape, g);
1264
1265 di.Add ("XGetShape","Result Doc Label \t: Put shape from tree to Result",
1266 __FILE__, getShape, g);
1267
1268 di.Add ("XRemoveShape","Doc Label \t: Remove shape from document",
1269 __FILE__, removeShape, g);
1270
7783ba11 1271 di.Add ("XFindShape","Doc Shape [findInstance (0/1), 0 by default]\t: Find and print label with indicated top-level shape",
7fd59977 1272 __FILE__, findShape, g);
1273
f277ba37 1274 di.Add("XFindSubShape", "Doc Shape ParentLabel \t: Find subshape under given parent shape label",
1275 __FILE__, findSubShape, g);
1276
7783ba11 1277 di.Add("XFindMainShape", "Doc SubShape \t: Find main shape for given subshape",
1278 __FILE__, findMainShape, g);
1279
f277ba37 1280 di.Add("XAddSubShape", "Doc Shape ParentLabel \t: Add subshape under given parent shape label",
1281 __FILE__, addSubShape, g);
1282
7fd59977 1283 di.Add ("XLabelInfo","Doc Label \t: Print information about object at following label",
1284 __FILE__, labelInfo, g);
1285
1286 di.Add ("XGetUsers","Doc Label [withSubChilds(int)] \t: Print number of assemblies that use shape at following label",
1287 __FILE__, getUsers, g);
1288
1289 di.Add ("XNbComponents","Doc Label [withSubChilds(int)] \t: Print number of component of assembly ",
1290 __FILE__, nbComponents, g);
1291
1292 di.Add ("XAddComponent","Doc Label Shape \t: Add component shape to assembly",
1293 __FILE__, addComponent, g);
1294
1295 di.Add ("XRemoveComponent","Doc Label \t: Remove component from components label",
1296 __FILE__, removeComponent, g);
1297
1298 di.Add ("XGetReferredShape","Doc Label \t: Print label, that contain a top-level shape, that corresponds shape at following label",
1299 __FILE__, getReferredShape, g);
1300
1301 di.Add ("XGetTopLevelShapes","Doc \t: Print labels, that contain a top-level shapes",
1302 __FILE__, getTopLevelShapes, g);
1303
1304 di.Add ("XGetFreeShapes","Doc [shape_prefix]\t: Print labels or create DRAW shapes for all free shapes in the Doc",
1305 __FILE__, getFreeShapes, g);
1306
4551e1be 1307 di.Add ("XGetOneShape","shape Doc \t: Put all free shapes of the Doc into single DRAW shape",
7fd59977 1308 __FILE__, getOneShape, g);
1309
1310 di.Add ("XDumpLocation","Doc Label \t: Dump Transformation() of XCAFDoc_Location attribute",
1311 __FILE__, XDumpLocation, g);
1312
1313 di.Add ("XSetSHUO","Doc UU_Label [ multi-level labels ] NU_Label \t: sets the SHUO structure between UpperUsage and NextUsage",
1314 __FILE__, setSHUO, g);
1315
1316 di.Add ("XGetUU_SHUO","Doc NU_Label \t: prints the UpperUsages of indicated NextUsage",
1317 __FILE__, getSHUOUpperUsage, g);
1318
1319 di.Add ("XGetNU_SHUO","Doc UU_Label \t: prints the NextUsages of indicated UpperUsage",
1320 __FILE__, getSHUONextUsage, g);
1321
1322 di.Add ("XRemoveSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
1323 __FILE__, removeSHUO, g);
1324
1325 di.Add ("XIsHasSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
1326 __FILE__, hasSHUO, g);
1327
1328 di.Add ("XGetAllSHUO","Doc Comp_Label \t: remove SHUO of indicated component",
1329 __FILE__, getAllSHUO, g);
1330
1331 di.Add ("XFindComponent","Doc Shape \t: prints sequence of labels of assembly path",
1332 __FILE__, findComponent, g);
1333
1334 di.Add ("XGetSHUOInstance","Doc res SHUO_Label \t: returns SHUO_styled shape",
1335 __FILE__, getStyledComponent, g);
1336
1337 di.Add ("XGetAllSHUOInstances","Doc res SHUO_Label \t: returns SHUO_styled shapes as compound",
1338 __FILE__, getAllStyledComponents, g);
1339
1340 di.Add ("XFindSHUO","Doc labels of SHUO structure \t: prints label of SHUO that found by labels structure",
1341 __FILE__, findSHUO, g);
1342
1343 di.Add ("XSetInstanceSHUO","Doc shape \t: sets the SHUO structure for indicated component",
1344 __FILE__, setStyledComponent, g);
f8d4cfbb 1345
1346 di.Add ("XSetLocation", R"(
1347Doc Label transformation [transformation ... ]
1348Applies given complex transformation to the shape at Label from Document.
1349The label may contain a reference to a shape, an assembly or simple shape.
1350The assembly or simple shape should not be referred by any reference.
1351Transformations:
1352 '-move x y z' - move shape
1353 '-rotate x y z dx dy dz angle' - rotate shape
1354 '-scale [x y z] factor' - scale shape
1355Transformations are applied from left to right.
1356There can be more than one transformation of the same type.
1357At least one transformation must be specified.
1358)", __FILE__, setLocation, g);
7fd59977 1359
acc909a8 1360 di.Add ("XUpdateAssemblies","Doc \t: updates assembly compounds",
1361 __FILE__, updateAssemblies, g);
07f20646 1362
1b423e32 1363 di.Add("XGetProperties", "Doc [label1, label2, ...] [shape1, shape2, ...]\t: prints named properties assigned to the all document's shape labels or chosen labels of shapes",
07f20646 1364 __FILE__, XGetProperties, g);
16f9b46d 1365
1366 di.Add ("XAutoNaming","Doc [0|1]\t: Disable/enable autonaming to Document",
1367 __FILE__, XAutoNaming, g);
7fd59977 1368}