1 // Created on: 2000-08-04
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Builder.hxx>
19 #include <DDocStd.hxx>
21 #include <gp_Trsf.hxx>
22 #include <TCollection_AsciiString.hxx>
23 #include <TDataStd_NamedData.hxx>
24 #include <TDF_AttributeSequence.hxx>
25 #include <TDF_Label.hxx>
26 #include <TDF_LabelSequence.hxx>
27 #include <TDF_Tool.hxx>
28 #include <TDocStd_Document.hxx>
29 #include <TopoDS_Compound.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopTools_SequenceOfShape.hxx>
32 #include <XCAFDoc_DocumentTool.hxx>
33 #include <XCAFDoc_GraphNode.hxx>
34 #include <XCAFDoc_Location.hxx>
35 #include <XCAFDoc_ShapeTool.hxx>
36 #include <XDEDRAW_Shapes.hxx>
39 //=======================================================================
40 // Section: Work with shapes
41 //=======================================================================
42 static Standard_Integer addShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
45 di<<"Use: "<<argv[0]<<" DocName Shape [int makeAssembly (1/0)]\n";
48 Handle(TDocStd_Document) Doc;
49 DDocStd::GetDocument(argv[1], Doc);
50 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
52 TopoDS_Shape aShape = DBRep::Get(argv[2]);
55 std::cout << "Syntax error: shape '" << argv[2] << "' is undefined\n";
59 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
60 Standard_Boolean makeAssembly = Standard_True;
61 if ( argc==4 && Draw::Atoi(argv[3]) == 0 ) makeAssembly = Standard_False;
63 aLabel = myAssembly->AddShape(aShape, makeAssembly);
64 if (aLabel.IsNull()) di<<"Null Label\n";
65 TCollection_AsciiString Entry;
66 TDF_Tool::Entry(aLabel, Entry);
67 di << Entry.ToCString();
71 static Standard_Integer newShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
74 di<<"Use: "<<argv[0]<<" DocName \n";
77 Handle(TDocStd_Document) Doc;
79 DDocStd::GetDocument(argv[1], Doc);
80 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
82 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
83 //XCAFDoc_ShapeTool myAssembly;
84 // myAssembly.Init(Doc);
85 aLabel=myAssembly->NewShape();
86 // di<<"New Shape at ChildTag"<<aLabel.Tag()<<"\n";
87 TCollection_AsciiString Entry;
88 TDF_Tool::Entry(aLabel, Entry);
89 di << Entry.ToCString();
93 static Standard_Integer setShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
96 di<<"Use: "<<argv[0]<<" DocName Label Shape \n";
99 Handle(TDocStd_Document) Doc;
100 DDocStd::GetDocument(argv[1], Doc);
101 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
104 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
106 // if (aLabel.IsNull()) di<<"Null Label\n";
107 aShape = DBRep::Get(argv[3]);
108 // XCAFDoc_ShapeTool myAssembly;
109 // myAssembly.Init(Doc);
110 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
111 myAssembly->SetShape(aLabel, aShape);
115 static Standard_Integer getShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
118 di<<"Use: "<<argv[0]<<" Result DocName Label\n";
121 Handle(TDocStd_Document) Doc;
122 DDocStd::GetDocument(argv[2], Doc);
123 if ( Doc.IsNull() ) { di << argv[2] << " is not a document\n"; return 1; }
126 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
127 if (aLabel.IsNull()) {di<<"No such Label\n"; return 1;}
129 // XCAFDoc_ShapeTool myAssembly;
130 // myAssembly.Init(Doc);
131 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
132 aShape = myAssembly->GetShape(aLabel);
133 Standard_CString name1 = argv[1];
134 DBRep::Set(name1, aShape);
139 static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
141 if (argc != 3 && argc != 4)
143 di<<"Use: "<<argv[0]<<" DocName Label [int removeCompletely (1/0)]\n";
146 Handle(TDocStd_Document) Doc;
147 DDocStd::GetDocument(argv[1], Doc);
148 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
151 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
152 if (aLabel.IsNull()) {di<<"No such Label\n"; return 1;}
154 // XCAFDoc_ShapeTool myAssembly;
155 // myAssembly.Init(Doc);
156 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
157 Standard_Boolean removeCompletely = Standard_True;
158 if ( argc == 4 && Draw::Atoi(argv[3]) == 0 )
159 removeCompletely = Standard_False;
160 myAssembly->RemoveShape(aLabel, removeCompletely);
165 static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
168 di << "Use: " << argv[0] << " DocName Shape [0/1]\n";
171 Handle(TDocStd_Document) Doc;
172 DDocStd::GetDocument(argv[1], Doc);
173 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
177 aShape = DBRep::Get(argv[2]);
178 // XCAFDoc_ShapeTool myAssembly;
179 // myAssembly.Init(Doc);
180 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
181 Standard_Boolean findInstance = ((argc == 4) && argv[3][0] == '1');
182 aLabel = myAssembly->FindShape(aShape, findInstance);
183 TCollection_AsciiString Entry;
184 TDF_Tool::Entry(aLabel, Entry);
185 di << Entry.ToCString();
186 //di<<"Label with Shape is "<<Entry<<"\n";
190 static Standard_Integer findSubShape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
193 di << "Use: " << argv[0] << " DocName Shape ParentLabel\n";
196 Handle(TDocStd_Document) aDoc;
197 DDocStd::GetDocument(argv[1], aDoc);
199 di << argv[1] << " is not a document\n";
204 aShape = DBRep::Get(argv[2]);
206 TDF_Label aParentLabel;
207 TDF_Tool::Label(aDoc->GetData(), argv[3], aParentLabel);
210 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
211 aShapeTool->FindSubShape(aParentLabel, aShape, aLabel);
213 TCollection_AsciiString anEntry;
214 TDF_Tool::Entry(aLabel, anEntry);
215 di << anEntry.ToCString();
219 static Standard_Integer findMainShape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
222 di << "Use: " << argv[0] << " DocName SubShape\n";
225 Handle(TDocStd_Document) aDoc;
226 DDocStd::GetDocument(argv[1], aDoc);
228 di << argv[1] << " is not a document\n";
233 aShape = DBRep::Get(argv[2]);
235 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
236 TDF_Label aLabel = aShapeTool->FindMainShape(aShape);
238 TCollection_AsciiString anEntry;
239 TDF_Tool::Entry(aLabel, anEntry);
240 di << anEntry.ToCString();
245 static Standard_Integer addSubShape(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
248 di << "Use: " << argv[0] << " DocName Shape ParentLabel\n";
251 Handle(TDocStd_Document) aDoc;
252 DDocStd::GetDocument(argv[1], aDoc);
253 if (aDoc.IsNull()) { di << argv[1] << " is not a document\n"; return 1; }
256 aShape = DBRep::Get(argv[2]);
258 TDF_Label aParentLabel;
259 TDF_Tool::Label(aDoc->GetData(), argv[3], aParentLabel);
262 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
263 aLabel = aShapeTool->AddSubShape(aParentLabel, aShape);
265 TCollection_AsciiString anEntry;
266 TDF_Tool::Entry(aLabel, anEntry);
267 di << anEntry.ToCString();
271 static Standard_Integer labelInfo (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
274 di<<"Use: "<<argv[0]<<" DocName Label \n";
277 Handle(TDocStd_Document) Doc;
278 DDocStd::GetDocument(argv[1], Doc);
279 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
282 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
283 // XCAFDoc_ShapeTool myAssembly;
284 // myAssembly.Init(Doc);
285 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
286 TCollection_AsciiString Entry;
288 if ( myAssembly->IsShape(aLabel) ) {
289 //di<<"There are a TopLevelShape\n";
290 Entry="There are a TopLevelShape";
291 di << Entry.ToCString();
293 if ( myAssembly->IsComponent(aLabel) ) {
294 //di<<"There are a Component\n";
295 Entry="There are a Component";
296 di << Entry.ToCString();
298 if ( myAssembly->IsAssembly(aLabel) ) {
299 //di<<"There are an Assembly\n";
300 Entry="There are an Assembly";
301 di << Entry.ToCString();
303 if ( myAssembly->IsFree(aLabel) ) {
304 //di<<"This Shape don't used\n";
305 Entry="This Shape don't used";
306 di << Entry.ToCString();
311 static Standard_Integer getUsers (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
314 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]\n";
317 Standard_Boolean getsubchilds = Standard_False;
318 if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
320 Handle(TDocStd_Document) Doc;
321 DDocStd::GetDocument(argv[1], Doc);
322 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
325 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
326 TDF_LabelSequence labseq;
327 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
328 TCollection_AsciiString Entry;
329 Entry=myAssembly->GetUsers(aLabel, labseq, getsubchilds);
330 di << Entry.ToCString();
331 //di<<myAssembly->GetUsers(aLabel, labseq, getsubchilds)<<" assemblies use this component\n";
335 static Standard_Integer nbComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
338 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]\n";
341 Standard_Boolean getsubchilds = Standard_False;
342 if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
343 Handle(TDocStd_Document) Doc;
344 DDocStd::GetDocument(argv[1], Doc);
345 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
348 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
349 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
350 // XCAFDoc_ShapeTool myAssembly->
351 // myAssembly->Init(Doc);
352 //di<<"This assembly has ";
353 TCollection_AsciiString Entry;
354 Entry=myAssembly->NbComponents( aLabel, getsubchilds);
355 di << Entry.ToCString();
356 //di<<" components\n";
357 //di<<"This assembly has "<<myAssembly->NbComponents( aLabel, getsubchilds )<<" components\n";
362 static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
365 di<<"Use: "<<argv[0]<<" DocName Label Shape \n";
368 Handle(TDocStd_Document) Doc;
369 DDocStd::GetDocument(argv[1], Doc);
370 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
373 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
375 aShape = DBRep::Get(argv[3]);
376 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
377 // XCAFDoc_ShapeTool myAssembly->
378 // myAssembly->Init(Doc);
379 myAssembly->AddComponent(aLabel, aShape);
380 TCollection_AsciiString Entry;
381 TDF_Tool::Entry(aLabel, Entry);
382 di << Entry.ToCString();
387 static Standard_Integer removeComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
390 di<<"Use: "<<argv[0]<<" DocName Label \n";
393 Handle(TDocStd_Document) Doc;
394 DDocStd::GetDocument(argv[1], Doc);
395 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
398 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
399 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
400 // XCAFDoc_ShapeTool myAssembly->
401 // myAssembly->Init(Doc);
402 myAssembly->RemoveComponent(aLabel);
406 static Standard_Integer getReferredShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
409 di<<"Use: "<<argv[0]<<" DocName Label \n";
412 Handle(TDocStd_Document) Doc;
413 DDocStd::GetDocument(argv[1], Doc);
414 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
416 TDF_Label aLabel, RootLabel;
417 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
418 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
419 // XCAFDoc_ShapeTool myAssembly->
420 // myAssembly->Init(Doc);
421 myAssembly->GetReferredShape(aLabel, RootLabel);
423 TCollection_AsciiString Entry;
424 TDF_Tool::Entry(RootLabel, Entry);
425 //di<<"Label with Shape is ";
426 di << Entry.ToCString();
430 static Standard_Integer getTopLevelShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
433 di<<"Use: "<<argv[0]<<" DocName \n";
436 Handle(TDocStd_Document) Doc;
437 DDocStd::GetDocument(argv[1], Doc);
438 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
441 TDF_LabelSequence Labels;
443 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
444 // XCAFDoc_ShapeTool myAssembly->
445 // myAssembly->Init(Doc);
446 myAssembly->GetShapes(Labels);
447 TCollection_AsciiString Entry;
448 if (Labels.Length() >= 1) {
449 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
450 aLabel = Labels.Value(i);
451 TDF_Tool::Entry( aLabel, Entry);
452 di << Entry.ToCString() << " ";
458 static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
461 di<<"Use: "<<argv[0]<<" DocName [shape_prefix]\n";
465 Handle(TDocStd_Document) Doc;
466 DDocStd::GetDocument(argv[1], Doc);
467 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
469 TDF_LabelSequence Labels;
470 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
471 STool->GetFreeShapes(Labels);
472 if ( Labels.Length() <=0 ) {
473 di << "Document " << argv[1] << " contain no shapes\n";
478 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
479 TCollection_AsciiString Entry;
480 TDF_Tool::Entry( Labels.Value(i), Entry);
481 di << Entry.ToCString() << " ";
484 else if ( Labels.Length() ==1 ) {
485 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
486 DBRep::Set ( argv[2], S );
490 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
491 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
493 Sprintf ( string, "%s_%d", argv[2], i );
494 DBRep::Set ( string, S );
501 static Standard_Integer getOneShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
504 di<<"Use: "<<argv[0]<<" shape DocName \n";
508 Handle(TDocStd_Document) Doc;
509 DDocStd::GetDocument(argv[2], Doc);
510 if ( Doc.IsNull() ) { di << argv[2] << " is not a document\n"; return 1; }
512 TDF_LabelSequence Labels;
513 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
514 STool->GetFreeShapes(Labels);
515 if ( Labels.Length() <=0 ) {
516 di << "Document " << argv[2] << " contain no shapes\n";
520 if ( Labels.Length() ==1 ) {
521 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
522 DBRep::Set ( argv[1], S );
527 B.MakeCompound ( C );
528 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
529 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
532 DBRep::Set ( argv[1], C );
538 //=======================================================================
539 //function : XDumpLocation
540 //purpose : Dump Transformation() of XCAFDoc_Location attribute
541 //=======================================================================
542 static Standard_Integer XDumpLocation (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
546 di << "Use: " << argv[0] << " Doc Label \n";
549 Handle(TDocStd_Document) Doc;
550 DDocStd::GetDocument(argv[1], Doc);
553 di << argv[1] << " is not a document\n";
558 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
560 Handle(XCAFDoc_Location) aLoc;
561 if (!aLabel.FindAttribute(XCAFDoc_Location::GetID(), aLoc))
563 di << "Label " << argv[2] << " doesn't contain XCAFDoc_Location attribute\n";
567 TopLoc_Location aTopLoc = aLoc->Get();
568 gp_Trsf aTrsf = aTopLoc.Transformation();
570 di << "Transformation (3 rows * 4 columns matrix):";
571 for (int i = 1; i <= 3; i++) // row number
574 for (int j = 1; j <= 4; j++) // column number
576 if (j > 1) di << ",";
577 di << TCollection_AsciiString(aTrsf.Value(i,j)).ToCString();
585 static Standard_Integer setSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
589 di << "Use: " << argv[0] << " Doc UU_Label NU_Label \n";
592 Handle(TDocStd_Document) Doc;
593 DDocStd::GetDocument(argv[1], Doc);
594 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
596 TDF_LabelSequence aLabSeq;
597 for (Standard_Integer i = 3; i <= argc; i++) {
599 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
603 di << argv[i - 1] << " is null label" << "\n";
605 if (aLabSeq.Length() < 2) {
606 di << "Error: couldnot set SHUO between on less then 2 labels\n";
608 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
609 Handle(XCAFDoc_GraphNode) aMainSHUO;
610 myAssembly->SetSHUO( aLabSeq, aMainSHUO );
611 if (aMainSHUO.IsNull()) {
612 di << "Error: cannot set the SHUO\n";
619 static Standard_Integer getSHUOUpperUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
623 di << "Use: " << argv[0] << " Doc NU_Label \n";
626 Handle(TDocStd_Document) Doc;
627 DDocStd::GetDocument(argv[1], Doc);
628 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
630 TDF_Tool::Label(Doc->GetData(), argv[2], NL);
632 di << argv[2] << " is null label" << "\n";
635 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
636 TDF_LabelSequence labseq;
637 myAssembly->GetSHUOUpperUsage( NL, labseq );
638 TCollection_AsciiString Entry;
639 if (labseq.Length() >= 1) {
640 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
641 TDF_Label aLabel = labseq.Value(i);
642 TDF_Tool::Entry( aLabel, Entry);
643 di << Entry.ToCString() << " ";
649 static Standard_Integer getSHUONextUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
653 di << "Use: " << argv[0] << " Doc UU_Label \n";
656 Handle(TDocStd_Document) Doc;
657 DDocStd::GetDocument(argv[1], Doc);
658 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
660 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
662 di << argv[2] << " is null label" << "\n";
665 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
666 TDF_LabelSequence labseq;
667 myAssembly->GetSHUONextUsage( UL, labseq );
668 TCollection_AsciiString Entry;
669 if (labseq.Length() >= 1) {
670 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
671 TDF_Label aLabel = labseq.Value(i);
672 TDF_Tool::Entry( aLabel, Entry);
673 di << Entry.ToCString() << " ";
679 static Standard_Integer removeSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
683 di << "Use: " << argv[0] << " Doc SHUOComponent_Label \n";
686 Handle(TDocStd_Document) Doc;
687 DDocStd::GetDocument(argv[1], Doc);
688 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
690 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
692 di << argv[2] << " is null label" << "\n";
695 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
696 myAssembly->RemoveSHUO( UL );
701 static Standard_Integer hasSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
705 di << "Use: " << argv[0] << " Doc SHUO_Label \n";
708 Handle(TDocStd_Document) Doc;
709 DDocStd::GetDocument(argv[1], Doc);
710 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
712 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
714 di << argv[2] << " is null label" << "\n";
717 Handle(XCAFDoc_GraphNode) anAttrSHUO;
718 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
719 if (myAssembly->GetSHUO( UL, anAttrSHUO ))
727 static Standard_Integer getAllSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
731 di << "Use: " << argv[0] << " Doc SHUO_Label \n";
734 Handle(TDocStd_Document) Doc;
735 DDocStd::GetDocument(argv[1], Doc);
736 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
737 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
739 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
741 di << argv[2] << " is null label" << "\n";
744 TDF_AttributeSequence SHUOAttrs;
745 myAssembly->GetAllComponentSHUO( UL, SHUOAttrs );
746 TCollection_AsciiString Entry;
747 if (SHUOAttrs.Length() >= 1) {
748 for ( Standard_Integer i = 1; i<= SHUOAttrs.Length(); i++) {
749 TDF_Label aLabel = SHUOAttrs.Value(i)->Label();
750 TDF_Tool::Entry( aLabel, Entry);
751 di << Entry.ToCString() << " ";
757 static Standard_Integer findComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
761 di << "Use: " << argv[0] << " Doc shape \n";
764 Handle(TDocStd_Document) Doc;
765 DDocStd::GetDocument(argv[1], Doc);
766 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
767 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
769 aShape = DBRep::Get(argv[2]);
770 TDF_LabelSequence labseq;
771 myAssembly->FindComponent( aShape, labseq );
772 TCollection_AsciiString Entry;
773 if (labseq.Length() >= 1) {
774 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
775 TDF_Label aLabel = labseq.Value(i);
776 TDF_Tool::Entry( aLabel, Entry);
777 di << Entry.ToCString() << " ";
783 static Standard_Integer getStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
787 di << "Use: " << argv[0] << " Doc res SHUO_label \n";
790 Handle(TDocStd_Document) Doc;
791 DDocStd::GetDocument(argv[1], Doc);
792 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
793 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
796 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
797 Handle(XCAFDoc_GraphNode) SHUO;
798 if (myAssembly->GetSHUO( aLabel, SHUO ))
799 aShape = myAssembly->GetSHUOInstance( SHUO );
801 if (aShape.IsNull()) {
802 di << "cannot get component\n";
805 DBRep::Set ( argv[2], aShape );
810 static Standard_Integer getAllStyledComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
814 di << "Use: " << argv[0] << " Doc res SHUO_label \n";
817 Handle(TDocStd_Document) Doc;
818 DDocStd::GetDocument(argv[1], Doc);
819 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
820 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
821 TopTools_SequenceOfShape aShapes;
823 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
824 Handle(XCAFDoc_GraphNode) SHUO;
825 if (myAssembly->GetSHUO( aLabel, SHUO ))
826 if (myAssembly->GetAllSHUOInstances(SHUO, aShapes)) {
827 TopoDS_Compound aShape;
829 B.MakeCompound(aShape);
830 for (Standard_Integer jj = 1; jj <= aShapes.Length(); jj++) {
831 TopoDS_Shape aCurShape = aShapes.Value(jj);
832 B.Add( aShape, aCurShape );
834 DBRep::Set ( argv[2], aShape );
841 static Standard_Integer findSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
845 di << "Use: " << argv[0] << " Doc labels \n";
848 Handle(TDocStd_Document) Doc;
849 DDocStd::GetDocument(argv[1], Doc);
850 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
851 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
852 TDF_LabelSequence aLabSeq;
853 for (Standard_Integer i = 3; i <= argc; i++) {
855 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
859 di << argv[i - 1] << " is null label" << "\n";
861 if (aLabSeq.Length() < 2) {
862 di << "Error: couldnot find SHUO between on less then 2 labels\n";
864 Handle(XCAFDoc_GraphNode) SHUO;
865 myAssembly->FindSHUO( aLabSeq, SHUO );
867 di << "cannot find SHUO\n";
870 TCollection_AsciiString Entry;
871 TDF_Tool::Entry( SHUO->Label(), Entry);
872 di << Entry.ToCString() << " ";
877 static Standard_Integer setStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
881 di << "Use: " << argv[0] << " Doc shape \n";
884 Handle(TDocStd_Document) Doc;
885 DDocStd::GetDocument(argv[1], Doc);
886 if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; }
887 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
889 aShape = DBRep::Get(argv[2]);
890 if (aShape.IsNull()) {
891 di << "Shape " << argv[2] << " is null\n";
894 Handle(XCAFDoc_GraphNode) aSHUOAttr;
895 aSHUOAttr = myAssembly->SetInstanceSHUO( aShape );
896 if (aSHUOAttr.IsNull()) {
897 di << "Error: cannot set a SHUO structure for indicated component" << "\n";
900 TCollection_AsciiString Entry;
901 TDF_Tool::Entry( aSHUOAttr->Label(), Entry);
902 di << Entry.ToCString() << " ";
907 static Standard_Integer updateAssemblies(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
911 di << "Use: " << argv[0] << " Doc\n";
916 Handle(TDocStd_Document) aDoc;
917 DDocStd::GetDocument(argv[1], aDoc);
921 // Get XDE shape tool
922 Handle(XCAFDoc_ShapeTool)
923 aShapeTool = XCAFDoc_DocumentTool::ShapeTool( aDoc->Main() );
926 aShapeTool->UpdateAssemblies();
931 static Standard_Integer XGetProperties(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
935 std::cout << "Syntax error: wrong number of arguments\nUse: " << argv[0] << " Doc Label\n";
939 Handle(TDocStd_Document) aDoc;
940 DDocStd::GetDocument(argv[1], aDoc);
943 std::cout << "Syntax error: " << argv[1] << " is not a document\n";
948 TDF_Tool::Label(aDoc->GetData(), argv[2], aLabel);
950 // Get XDE shape tool
951 Handle(XCAFDoc_ShapeTool) aShapeTool = XCAFDoc_DocumentTool::ShapeTool(aDoc->Main());
953 Handle(TDataStd_NamedData) aNamedData = aShapeTool->GetNamedProperties(aLabel);
955 if (aNamedData.IsNull())
957 di << argv[2] << " has no properties\n";
961 aNamedData->LoadDeferredData();
962 if (aNamedData->HasIntegers())
964 TColStd_DataMapOfStringInteger anIntProperties = aNamedData->GetIntegersContainer();
965 for (TColStd_DataMapIteratorOfDataMapOfStringInteger anIter(anIntProperties); anIter.More(); anIter.Next())
967 di << anIter.Key() << " : " << anIter.Value() << "\n";
970 if (aNamedData->HasReals())
972 TDataStd_DataMapOfStringReal aRealProperties = aNamedData->GetRealsContainer();
973 for (TDataStd_DataMapIteratorOfDataMapOfStringReal anIter(aRealProperties); anIter.More(); anIter.Next())
975 di << anIter.Key() << " : " << anIter.Value() << "\n";
978 if (aNamedData->HasStrings())
980 TDataStd_DataMapOfStringString aStringProperties = aNamedData->GetStringsContainer();
981 for (TDataStd_DataMapIteratorOfDataMapOfStringString anIter(aStringProperties); anIter.More(); anIter.Next())
983 di << anIter.Key() << " : " << anIter.Value() << "\n";
990 //=======================================================================
991 //function : InitCommands
993 //=======================================================================
995 void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di)
997 static Standard_Boolean initactor = Standard_False;
1002 initactor = Standard_True;
1004 //=====================================
1006 //=====================================
1008 Standard_CString g = "XDE shape's commands";
1010 di.Add ("XAddShape","Doc Shape [makeAssembly = 1]\t: Add shape (or assembly) to Document",
1011 __FILE__, addShape, g);
1013 di.Add ("XNewShape","Doc \t: Create new empty top-level shape",
1014 __FILE__, newShape, g);
1016 di.Add ("XSetShape","Doc Label Shape \t: Set shape at indicated label",
1017 __FILE__, setShape, g);
1019 di.Add ("XGetShape","Result Doc Label \t: Put shape from tree to Result",
1020 __FILE__, getShape, g);
1022 di.Add ("XRemoveShape","Doc Label \t: Remove shape from document",
1023 __FILE__, removeShape, g);
1025 di.Add ("XFindShape","Doc Shape [findInstance (0/1), 0 by default]\t: Find and print label with indicated top-level shape",
1026 __FILE__, findShape, g);
1028 di.Add("XFindSubShape", "Doc Shape ParentLabel \t: Find subshape under given parent shape label",
1029 __FILE__, findSubShape, g);
1031 di.Add("XFindMainShape", "Doc SubShape \t: Find main shape for given subshape",
1032 __FILE__, findMainShape, g);
1034 di.Add("XAddSubShape", "Doc Shape ParentLabel \t: Add subshape under given parent shape label",
1035 __FILE__, addSubShape, g);
1037 di.Add ("XLabelInfo","Doc Label \t: Print information about object at following label",
1038 __FILE__, labelInfo, g);
1040 di.Add ("XGetUsers","Doc Label [withSubChilds(int)] \t: Print number of assemblies that use shape at following label",
1041 __FILE__, getUsers, g);
1043 di.Add ("XNbComponents","Doc Label [withSubChilds(int)] \t: Print number of component of assembly ",
1044 __FILE__, nbComponents, g);
1046 di.Add ("XAddComponent","Doc Label Shape \t: Add component shape to assembly",
1047 __FILE__, addComponent, g);
1049 di.Add ("XRemoveComponent","Doc Label \t: Remove component from components label",
1050 __FILE__, removeComponent, g);
1052 di.Add ("XGetReferredShape","Doc Label \t: Print label, that contain a top-level shape, that corresponds shape at following label",
1053 __FILE__, getReferredShape, g);
1055 di.Add ("XGetTopLevelShapes","Doc \t: Print labels, that contain a top-level shapes",
1056 __FILE__, getTopLevelShapes, g);
1058 di.Add ("XGetFreeShapes","Doc [shape_prefix]\t: Print labels or create DRAW shapes for all free shapes in the Doc",
1059 __FILE__, getFreeShapes, g);
1061 di.Add ("XGetOneShape","shape Doc \t: Put all free shapes of the Doc into signle DRAW shape",
1062 __FILE__, getOneShape, g);
1064 di.Add ("XDumpLocation","Doc Label \t: Dump Transformation() of XCAFDoc_Location attribute",
1065 __FILE__, XDumpLocation, g);
1067 di.Add ("XSetSHUO","Doc UU_Label [ multi-level labels ] NU_Label \t: sets the SHUO structure between UpperUsage and NextUsage",
1068 __FILE__, setSHUO, g);
1070 di.Add ("XGetUU_SHUO","Doc NU_Label \t: prints the UpperUsages of indicated NextUsage",
1071 __FILE__, getSHUOUpperUsage, g);
1073 di.Add ("XGetNU_SHUO","Doc UU_Label \t: prints the NextUsages of indicated UpperUsage",
1074 __FILE__, getSHUONextUsage, g);
1076 di.Add ("XRemoveSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
1077 __FILE__, removeSHUO, g);
1079 di.Add ("XIsHasSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
1080 __FILE__, hasSHUO, g);
1082 di.Add ("XGetAllSHUO","Doc Comp_Label \t: remove SHUO of indicated component",
1083 __FILE__, getAllSHUO, g);
1085 di.Add ("XFindComponent","Doc Shape \t: prints sequence of labels of assembly path",
1086 __FILE__, findComponent, g);
1088 di.Add ("XGetSHUOInstance","Doc res SHUO_Label \t: returns SHUO_styled shape",
1089 __FILE__, getStyledComponent, g);
1091 di.Add ("XGetAllSHUOInstances","Doc res SHUO_Label \t: returns SHUO_styled shapes as compound",
1092 __FILE__, getAllStyledComponents, g);
1094 di.Add ("XFindSHUO","Doc labels of SHUO structure \t: prints label of SHUO that found by labels structure",
1095 __FILE__, findSHUO, g);
1097 di.Add ("XSetInstanceSHUO","Doc shape \t: sets the SHUO structure for indicated component",
1098 __FILE__, setStyledComponent, g);
1100 di.Add ("XUpdateAssemblies","Doc \t: updates assembly compounds",
1101 __FILE__, updateAssemblies, g);
1103 di.Add("XGetProperties", "Doc Label \t: prints named properties assigned to the Label",
1104 __FILE__, XGetProperties, g);