1 // Created on: 2000-08-04
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2000-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
21 #include <XDEDRAW_Shapes.ixx>
24 #include <DDocStd.hxx>
26 #include <TopoDS_Shape.hxx>
27 #include <TopoDS_Compound.hxx>
28 #include <BRep_Builder.hxx>
30 #include <gp_Trsf.hxx>
32 #include <TDF_Tool.hxx>
33 #include <TDF_Label.hxx>
34 #include <TDF_LabelSequence.hxx>
35 #include <TDocStd_Document.hxx>
37 #include <XCAFDoc_DocumentTool.hxx>
38 #include <XCAFDoc_ShapeTool.hxx>
39 #include <XCAFDoc_Location.hxx>
41 #include <TCollection_AsciiString.hxx>
44 #include <XCAFDoc_GraphNode.hxx>
45 #include <TDF_AttributeSequence.hxx>
46 #include <TopTools_SequenceOfShape.hxx>
48 //=======================================================================
49 // Section: Work with shapes
50 //=======================================================================
52 static Standard_Integer addShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
55 di<<"Use: "<<argv[0]<<" DocName Shape [int makeAssembly (1/0)]"<<"\n";
58 Handle(TDocStd_Document) Doc;
59 DDocStd::GetDocument(argv[1], Doc);
60 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
63 aShape = DBRep::Get(argv[2]);
64 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
65 Standard_Boolean makeAssembly = Standard_True;
66 if ( argc==4 && atoi(argv[3]) == 0 ) makeAssembly = Standard_False;
68 aLabel = myAssembly->AddShape(aShape, makeAssembly);
69 if (aLabel.IsNull()) di<<"Null Label"<<"\n";
70 TCollection_AsciiString Entry;
71 TDF_Tool::Entry(aLabel, Entry);
72 di << Entry.ToCString();
76 static Standard_Integer newShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
79 di<<"Use: "<<argv[0]<<" DocName "<<"\n";
82 Handle(TDocStd_Document) Doc;
84 DDocStd::GetDocument(argv[1], Doc);
85 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
87 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
88 //XCAFDoc_ShapeTool myAssembly;
89 // myAssembly.Init(Doc);
90 aLabel=myAssembly->NewShape();
91 // di<<"New Shape at ChildTag"<<aLabel.Tag()<<"\n";
92 TCollection_AsciiString Entry;
93 TDF_Tool::Entry(aLabel, Entry);
94 di << Entry.ToCString();
98 static Standard_Integer setShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
101 di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n";
104 Handle(TDocStd_Document) Doc;
105 DDocStd::GetDocument(argv[1], Doc);
106 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
109 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
111 // if (aLabel.IsNull()) di<<"Null Label"<<"\n";
112 aShape = DBRep::Get(argv[3]);
113 // XCAFDoc_ShapeTool myAssembly;
114 // myAssembly.Init(Doc);
115 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
116 myAssembly->SetShape(aLabel, aShape);
120 static Standard_Integer getShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
123 di<<"Use: "<<argv[0]<<" Result DocName Label"<<"\n";
126 Handle(TDocStd_Document) Doc;
127 DDocStd::GetDocument(argv[2], Doc);
128 if ( Doc.IsNull() ) { di << argv[2] << " is not a document" << "\n"; return 1; }
131 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
132 if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;}
134 // XCAFDoc_ShapeTool myAssembly;
135 // myAssembly.Init(Doc);
136 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
137 aShape = myAssembly->GetShape(aLabel);
138 Standard_CString name1 = argv[1];
139 DBRep::Set(name1, aShape);
144 static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
146 if (argc != 3 && argc != 4)
148 di<<"Use: "<<argv[0]<<" DocName Label [int removeCompletely (1/0)]"<<"\n";
151 Handle(TDocStd_Document) Doc;
152 DDocStd::GetDocument(argv[1], Doc);
153 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
156 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
157 if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;}
159 // XCAFDoc_ShapeTool myAssembly;
160 // myAssembly.Init(Doc);
161 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
162 Standard_Boolean removeCompletely = Standard_True;
163 if ( argc == 4 && atoi(argv[3]) == 0 )
164 removeCompletely = Standard_False;
165 myAssembly->RemoveShape(aLabel, removeCompletely);
170 static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
173 di<<"Use: "<<argv[0]<<" DocName Shape"<<"\n";
176 Handle(TDocStd_Document) Doc;
177 DDocStd::GetDocument(argv[1], Doc);
178 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
182 aShape = DBRep::Get(argv[2]);
183 // XCAFDoc_ShapeTool myAssembly;
184 // myAssembly.Init(Doc);
185 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
186 aLabel = myAssembly->FindShape(aShape);
187 TCollection_AsciiString Entry;
188 TDF_Tool::Entry(aLabel, Entry);
189 di << Entry.ToCString();
190 //di<<"Label with Shape is "<<Entry<<"\n";
194 static Standard_Integer labelInfo (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
197 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
200 Handle(TDocStd_Document) Doc;
201 DDocStd::GetDocument(argv[1], Doc);
202 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
205 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
206 // XCAFDoc_ShapeTool myAssembly;
207 // myAssembly.Init(Doc);
208 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
209 TCollection_AsciiString Entry;
211 if ( myAssembly->IsShape(aLabel) ) {
212 //di<<"There are a TopLevelShape"<<"\n";
213 Entry="There are a TopLevelShape";
214 di << Entry.ToCString();
216 if ( myAssembly->IsComponent(aLabel) ) {
217 //di<<"There are a Component"<<"\n";
218 Entry="There are a Component";
219 di << Entry.ToCString();
221 if ( myAssembly->IsAssembly(aLabel) ) {
222 //di<<"There are an Assembly"<<"\n";
223 Entry="There are an Assembly";
224 di << Entry.ToCString();
226 if ( myAssembly->IsFree(aLabel) ) {
227 //di<<"This Shape don't used"<<"\n";
228 Entry="This Shape don't used";
229 di << Entry.ToCString();
234 static Standard_Integer getUsers (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
237 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n";
240 Standard_Boolean getsubchilds = Standard_False;
241 if ( (argc==4) && ( atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
243 Handle(TDocStd_Document) Doc;
244 DDocStd::GetDocument(argv[1], Doc);
245 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
248 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
249 TDF_LabelSequence labseq;
250 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
251 TCollection_AsciiString Entry;
252 Entry=myAssembly->GetUsers(aLabel, labseq, getsubchilds);
253 di << Entry.ToCString();
254 //di<<myAssembly->GetUsers(aLabel, labseq, getsubchilds)<<" assemblies use this component"<<"\n";
258 static Standard_Integer nbComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
261 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n";
264 Standard_Boolean getsubchilds = Standard_False;
265 if ( (argc==4) && ( atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
266 Handle(TDocStd_Document) Doc;
267 DDocStd::GetDocument(argv[1], Doc);
268 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
271 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
272 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
273 // XCAFDoc_ShapeTool myAssembly->
274 // myAssembly->Init(Doc);
275 //di<<"This assembly has ";
276 TCollection_AsciiString Entry;
277 Entry=myAssembly->NbComponents( aLabel, getsubchilds);
278 di << Entry.ToCString();
279 //di<<" components"<<"\n";
280 //di<<"This assembly has "<<myAssembly->NbComponents( aLabel, getsubchilds )<<" components"<<"\n";
285 static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
288 di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n";
291 Handle(TDocStd_Document) Doc;
292 DDocStd::GetDocument(argv[1], Doc);
293 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
296 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
298 aShape = DBRep::Get(argv[3]);
299 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
300 // XCAFDoc_ShapeTool myAssembly->
301 // myAssembly->Init(Doc);
302 myAssembly->AddComponent(aLabel, aShape);
303 TCollection_AsciiString Entry;
304 TDF_Tool::Entry(aLabel, Entry);
305 di << Entry.ToCString();
310 static Standard_Integer removeComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
313 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
316 Handle(TDocStd_Document) Doc;
317 DDocStd::GetDocument(argv[1], Doc);
318 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
321 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
322 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
323 // XCAFDoc_ShapeTool myAssembly->
324 // myAssembly->Init(Doc);
325 myAssembly->RemoveComponent(aLabel);
329 static Standard_Integer getReferredShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
332 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
335 Handle(TDocStd_Document) Doc;
336 DDocStd::GetDocument(argv[1], Doc);
337 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
339 TDF_Label aLabel, RootLabel;
340 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
341 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
342 // XCAFDoc_ShapeTool myAssembly->
343 // myAssembly->Init(Doc);
344 myAssembly->GetReferredShape(aLabel, RootLabel);
346 TCollection_AsciiString Entry;
347 TDF_Tool::Entry(RootLabel, Entry);
348 //di<<"Label with Shape is ";
349 di << Entry.ToCString();
353 static Standard_Integer getTopLevelShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
356 di<<"Use: "<<argv[0]<<" DocName "<<"\n";
359 Handle(TDocStd_Document) Doc;
360 DDocStd::GetDocument(argv[1], Doc);
361 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
364 TDF_LabelSequence Labels;
366 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
367 // XCAFDoc_ShapeTool myAssembly->
368 // myAssembly->Init(Doc);
369 myAssembly->GetShapes(Labels);
370 TCollection_AsciiString Entry;
371 if (Labels.Length() >= 1) {
372 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
373 aLabel = Labels.Value(i);
374 TDF_Tool::Entry( aLabel, Entry);
375 di << Entry.ToCString() << " ";
381 static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
384 di<<"Use: "<<argv[0]<<" DocName [shape_prefix]"<<"\n";
388 Handle(TDocStd_Document) Doc;
389 DDocStd::GetDocument(argv[1], Doc);
390 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
392 TDF_LabelSequence Labels;
393 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
394 STool->GetFreeShapes(Labels);
395 if ( Labels.Length() <=0 ) {
396 di << "Document " << argv[1] << " contain no shapes" << "\n";
401 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
402 TCollection_AsciiString Entry;
403 TDF_Tool::Entry( Labels.Value(i), Entry);
404 di << Entry.ToCString() << " ";
407 else if ( Labels.Length() ==1 ) {
408 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
409 DBRep::Set ( argv[2], S );
413 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
414 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
416 sprintf ( string, "%s_%d", argv[2], i );
417 DBRep::Set ( string, S );
424 static Standard_Integer getOneShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
427 di<<"Use: "<<argv[0]<<" shape DocName "<<"\n";
431 Handle(TDocStd_Document) Doc;
432 DDocStd::GetDocument(argv[2], Doc);
433 if ( Doc.IsNull() ) { di << argv[2] << " is not a document" << "\n"; return 1; }
435 TDF_LabelSequence Labels;
436 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
437 STool->GetFreeShapes(Labels);
438 if ( Labels.Length() <=0 ) {
439 di << "Document " << argv[2] << " contain no shapes" << "\n";
443 if ( Labels.Length() ==1 ) {
444 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
445 DBRep::Set ( argv[1], S );
450 B.MakeCompound ( C );
451 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
452 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
455 DBRep::Set ( argv[1], C );
461 //=======================================================================
462 //function : XDumpLocation
463 //purpose : Dump Transformation() of XCAFDoc_Location attribute
464 //=======================================================================
465 static Standard_Integer XDumpLocation (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
469 di << "Use: " << argv[0] << " Doc Label " << "\n";
472 Handle(TDocStd_Document) Doc;
473 DDocStd::GetDocument(argv[1], Doc);
476 di << argv[1] << " is not a document" << "\n";
481 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
483 Handle(XCAFDoc_Location) aLoc;
484 if (!aLabel.FindAttribute(XCAFDoc_Location::GetID(), aLoc))
486 di << "Label " << argv[2] << " doesn't contain XCAFDoc_Location attribute" << "\n";
490 TopLoc_Location aTopLoc = aLoc->Get();
491 gp_Trsf aTrsf = aTopLoc.Transformation();
493 di << "Transformation (3 rows * 4 columns matrix):";
494 for (int i = 1; i <= 3; i++) // row number
497 for (int j = 1; j <= 4; j++) // column number
499 if (j > 1) di << ",";
500 di << TCollection_AsciiString(aTrsf.Value(i,j)).ToCString();
508 static Standard_Integer setSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
512 di << "Use: " << argv[0] << " Doc UU_Label NU_Label " << "\n";
515 Handle(TDocStd_Document) Doc;
516 DDocStd::GetDocument(argv[1], Doc);
517 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
519 TDF_LabelSequence aLabSeq;
520 for (Standard_Integer i = 3; i <= argc; i++) {
522 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
526 di << argv[i - 1] << " is null label" << "\n";
528 if (aLabSeq.Length() < 2) {
529 di << "Error: couldnot set SHUO between on less then 2 labels" << "\n";
531 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
532 Handle(XCAFDoc_GraphNode) aMainSHUO;
533 myAssembly->SetSHUO( aLabSeq, aMainSHUO );
534 if (aMainSHUO.IsNull()) {
535 di << "Error: cannot set the SHUO" << "\n";
542 static Standard_Integer getSHUOUpperUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
546 di << "Use: " << argv[0] << " Doc NU_Label " << "\n";
549 Handle(TDocStd_Document) Doc;
550 DDocStd::GetDocument(argv[1], Doc);
551 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
553 TDF_Tool::Label(Doc->GetData(), argv[2], NL);
555 di << argv[2] << " is null label" << "\n";
558 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
559 TDF_LabelSequence labseq;
560 myAssembly->GetSHUOUpperUsage( NL, labseq );
561 TCollection_AsciiString Entry;
562 if (labseq.Length() >= 1) {
563 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
564 TDF_Label aLabel = labseq.Value(i);
565 TDF_Tool::Entry( aLabel, Entry);
566 di << Entry.ToCString() << " ";
572 static Standard_Integer getSHUONextUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
576 di << "Use: " << argv[0] << " Doc UU_Label " << "\n";
579 Handle(TDocStd_Document) Doc;
580 DDocStd::GetDocument(argv[1], Doc);
581 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
583 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
585 di << argv[2] << " is null label" << "\n";
588 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
589 TDF_LabelSequence labseq;
590 myAssembly->GetSHUONextUsage( UL, labseq );
591 TCollection_AsciiString Entry;
592 if (labseq.Length() >= 1) {
593 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
594 TDF_Label aLabel = labseq.Value(i);
595 TDF_Tool::Entry( aLabel, Entry);
596 di << Entry.ToCString() << " ";
602 static Standard_Integer removeSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
606 di << "Use: " << argv[0] << " Doc SHUOComponent_Label " << "\n";
609 Handle(TDocStd_Document) Doc;
610 DDocStd::GetDocument(argv[1], Doc);
611 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
613 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
615 di << argv[2] << " is null label" << "\n";
618 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
619 myAssembly->RemoveSHUO( UL );
624 static Standard_Integer hasSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
628 di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n";
631 Handle(TDocStd_Document) Doc;
632 DDocStd::GetDocument(argv[1], Doc);
633 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
635 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
637 di << argv[2] << " is null label" << "\n";
640 Handle(XCAFDoc_GraphNode) anAttrSHUO;
641 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
642 if (myAssembly->GetSHUO( UL, anAttrSHUO ))
650 static Standard_Integer getAllSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
654 di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n";
657 Handle(TDocStd_Document) Doc;
658 DDocStd::GetDocument(argv[1], Doc);
659 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
660 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
662 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
664 di << argv[2] << " is null label" << "\n";
667 TDF_AttributeSequence SHUOAttrs;
668 myAssembly->GetAllComponentSHUO( UL, SHUOAttrs );
669 TCollection_AsciiString Entry;
670 if (SHUOAttrs.Length() >= 1) {
671 for ( Standard_Integer i = 1; i<= SHUOAttrs.Length(); i++) {
672 TDF_Label aLabel = SHUOAttrs.Value(i)->Label();
673 TDF_Tool::Entry( aLabel, Entry);
674 di << Entry.ToCString() << " ";
680 static Standard_Integer findComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
684 di << "Use: " << argv[0] << " Doc shape " << "\n";
687 Handle(TDocStd_Document) Doc;
688 DDocStd::GetDocument(argv[1], Doc);
689 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
690 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
692 aShape = DBRep::Get(argv[2]);
693 TDF_LabelSequence labseq;
694 myAssembly->FindComponent( aShape, labseq );
695 TCollection_AsciiString Entry;
696 if (labseq.Length() >= 1) {
697 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
698 TDF_Label aLabel = labseq.Value(i);
699 TDF_Tool::Entry( aLabel, Entry);
700 di << Entry.ToCString() << " ";
706 static Standard_Integer getStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
710 di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n";
713 Handle(TDocStd_Document) Doc;
714 DDocStd::GetDocument(argv[1], Doc);
715 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
716 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
719 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
720 Handle(XCAFDoc_GraphNode) SHUO;
721 if (myAssembly->GetSHUO( aLabel, SHUO ))
722 aShape = myAssembly->GetSHUOInstance( SHUO );
724 if (aShape.IsNull()) {
725 di << "cannot get component" << "\n";
728 DBRep::Set ( argv[2], aShape );
733 static Standard_Integer getAllStyledComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
737 di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n";
740 Handle(TDocStd_Document) Doc;
741 DDocStd::GetDocument(argv[1], Doc);
742 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
743 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
744 TopTools_SequenceOfShape aShapes;
746 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
747 Handle(XCAFDoc_GraphNode) SHUO;
748 if (myAssembly->GetSHUO( aLabel, SHUO ))
749 if (myAssembly->GetAllSHUOInstances(SHUO, aShapes)) {
750 TopoDS_Compound aShape;
752 B.MakeCompound(aShape);
753 for (Standard_Integer jj = 1; jj <= aShapes.Length(); jj++) {
754 TopoDS_Shape aCurShape = aShapes.Value(jj);
755 B.Add( aShape, aCurShape );
757 DBRep::Set ( argv[2], aShape );
764 static Standard_Integer findSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
768 di << "Use: " << argv[0] << " Doc labels " << "\n";
771 Handle(TDocStd_Document) Doc;
772 DDocStd::GetDocument(argv[1], Doc);
773 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
774 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
775 TDF_LabelSequence aLabSeq;
776 for (Standard_Integer i = 3; i <= argc; i++) {
778 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
782 di << argv[i - 1] << " is null label" << "\n";
784 if (aLabSeq.Length() < 2) {
785 di << "Error: couldnot find SHUO between on less then 2 labels" << "\n";
787 Handle(XCAFDoc_GraphNode) SHUO;
788 myAssembly->FindSHUO( aLabSeq, SHUO );
790 di << "cannot find SHUO" << "\n";
793 TCollection_AsciiString Entry;
794 TDF_Tool::Entry( SHUO->Label(), Entry);
795 di << Entry.ToCString() << " ";
800 static Standard_Integer setStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
804 di << "Use: " << argv[0] << " Doc shape " << "\n";
807 Handle(TDocStd_Document) Doc;
808 DDocStd::GetDocument(argv[1], Doc);
809 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
810 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
812 aShape = DBRep::Get(argv[2]);
813 if (aShape.IsNull()) {
814 di << "Shape " << argv[2] << " is null" << "\n";
817 Handle(XCAFDoc_GraphNode) aSHUOAttr;
818 aSHUOAttr = myAssembly->SetInstanceSHUO( aShape );
819 if (aSHUOAttr.IsNull()) {
820 di << "Error: cannot set a SHUO structure for indicated component" << "\n";
823 TCollection_AsciiString Entry;
824 TDF_Tool::Entry( aSHUOAttr->Label(), Entry);
825 di << Entry.ToCString() << " ";
829 //=======================================================================
830 //function : InitCommands
832 //=======================================================================
834 void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di)
837 static Standard_Boolean initactor = Standard_False;
838 if (initactor) return; initactor = Standard_True;
840 //=====================================
842 //=====================================
844 Standard_CString g = "XDE shape's commands";
846 di.Add ("XAddShape","Doc Shape [makeAssembly = 1]\t: Add shape (or assembly) to Document",
847 __FILE__, addShape, g);
849 di.Add ("XNewShape","Doc \t: Create new empty top-level shape",
850 __FILE__, newShape, g);
852 di.Add ("XSetShape","Doc Label Shape \t: Set shape at indicated label",
853 __FILE__, setShape, g);
855 di.Add ("XGetShape","Result Doc Label \t: Put shape from tree to Result",
856 __FILE__, getShape, g);
858 di.Add ("XRemoveShape","Doc Label \t: Remove shape from document",
859 __FILE__, removeShape, g);
861 di.Add ("XFindShape","Doc Shape \t: Find and print label with indicated top-level shape",
862 __FILE__, findShape, g);
864 di.Add ("XLabelInfo","Doc Label \t: Print information about object at following label",
865 __FILE__, labelInfo, g);
867 di.Add ("XGetUsers","Doc Label [withSubChilds(int)] \t: Print number of assemblies that use shape at following label",
868 __FILE__, getUsers, g);
870 di.Add ("XNbComponents","Doc Label [withSubChilds(int)] \t: Print number of component of assembly ",
871 __FILE__, nbComponents, g);
873 di.Add ("XAddComponent","Doc Label Shape \t: Add component shape to assembly",
874 __FILE__, addComponent, g);
876 di.Add ("XRemoveComponent","Doc Label \t: Remove component from components label",
877 __FILE__, removeComponent, g);
879 di.Add ("XGetReferredShape","Doc Label \t: Print label, that contain a top-level shape, that corresponds shape at following label",
880 __FILE__, getReferredShape, g);
882 di.Add ("XGetTopLevelShapes","Doc \t: Print labels, that contain a top-level shapes",
883 __FILE__, getTopLevelShapes, g);
885 di.Add ("XGetFreeShapes","Doc [shape_prefix]\t: Print labels or create DRAW shapes for all free shapes in the Doc",
886 __FILE__, getFreeShapes, g);
888 di.Add ("XGetOneShape","shape Doc \t: Put all free shapes of the Doc into signle DRAW shape",
889 __FILE__, getOneShape, g);
891 di.Add ("XDumpLocation","Doc Label \t: Dump Transformation() of XCAFDoc_Location attribute",
892 __FILE__, XDumpLocation, g);
894 di.Add ("XSetSHUO","Doc UU_Label [ multi-level labels ] NU_Label \t: sets the SHUO structure between UpperUsage and NextUsage",
895 __FILE__, setSHUO, g);
897 di.Add ("XGetUU_SHUO","Doc NU_Label \t: prints the UpperUsages of indicated NextUsage",
898 __FILE__, getSHUOUpperUsage, g);
900 di.Add ("XGetNU_SHUO","Doc UU_Label \t: prints the NextUsages of indicated UpperUsage",
901 __FILE__, getSHUONextUsage, g);
903 di.Add ("XRemoveSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
904 __FILE__, removeSHUO, g);
906 di.Add ("XIsHasSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
907 __FILE__, hasSHUO, g);
909 di.Add ("XGetAllSHUO","Doc Comp_Label \t: remove SHUO of indicated component",
910 __FILE__, getAllSHUO, g);
912 di.Add ("XFindComponent","Doc Shape \t: prints sequence of labels of assembly path",
913 __FILE__, findComponent, g);
915 di.Add ("XGetSHUOInstance","Doc res SHUO_Label \t: returns SHUO_styled shape",
916 __FILE__, getStyledComponent, g);
918 di.Add ("XGetAllSHUOInstances","Doc res SHUO_Label \t: returns SHUO_styled shapes as compound",
919 __FILE__, getAllStyledComponents, g);
921 di.Add ("XFindSHUO","Doc labels of SHUO structure \t: prints label of SHUO that found by labels structure",
922 __FILE__, findSHUO, g);
924 di.Add ("XSetInstanceSHUO","Doc shape \t: sets the SHUO structure for indicated component",
925 __FILE__, setStyledComponent, g);