1 // File: XDEDRAW_Shapes.cxx
2 // Created: Fri Aug 4 14:38:55 2000
3 // Author: Pavel TELKOV
4 // <ptv@zamox.nnov.matra-dtv.fr>
6 #include <XDEDRAW_Shapes.ixx>
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Compound.hxx>
13 #include <BRep_Builder.hxx>
15 #include <gp_Trsf.hxx>
17 #include <TDF_Tool.hxx>
18 #include <TDF_Label.hxx>
19 #include <TDF_LabelSequence.hxx>
20 #include <TDocStd_Document.hxx>
22 #include <XCAFDoc_DocumentTool.hxx>
23 #include <XCAFDoc_ShapeTool.hxx>
24 #include <XCAFDoc_Location.hxx>
26 #include <TCollection_AsciiString.hxx>
29 #include <XCAFDoc_GraphNode.hxx>
30 #include <TDF_AttributeSequence.hxx>
31 #include <TopTools_SequenceOfShape.hxx>
33 //=======================================================================
34 // Section: Work with shapes
35 //=======================================================================
37 static Standard_Integer addShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
40 di<<"Use: "<<argv[0]<<" DocName Shape [int makeAssembly (1/0)]"<<"\n";
43 Handle(TDocStd_Document) Doc;
44 DDocStd::GetDocument(argv[1], Doc);
45 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
48 aShape = DBRep::Get(argv[2]);
49 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
50 Standard_Boolean makeAssembly = Standard_True;
51 if ( argc==4 && atoi(argv[3]) == 0 ) makeAssembly = Standard_False;
53 aLabel = myAssembly->AddShape(aShape, makeAssembly);
54 if (aLabel.IsNull()) di<<"Null Label"<<"\n";
55 TCollection_AsciiString Entry;
56 TDF_Tool::Entry(aLabel, Entry);
57 di << Entry.ToCString();
61 static Standard_Integer newShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
64 di<<"Use: "<<argv[0]<<" DocName "<<"\n";
67 Handle(TDocStd_Document) Doc;
69 DDocStd::GetDocument(argv[1], Doc);
70 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
72 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
73 //XCAFDoc_ShapeTool myAssembly;
74 // myAssembly.Init(Doc);
75 aLabel=myAssembly->NewShape();
76 // di<<"New Shape at ChildTag"<<aLabel.Tag()<<"\n";
77 TCollection_AsciiString Entry;
78 TDF_Tool::Entry(aLabel, Entry);
79 di << Entry.ToCString();
83 static Standard_Integer setShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
86 di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n";
89 Handle(TDocStd_Document) Doc;
90 DDocStd::GetDocument(argv[1], Doc);
91 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
94 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
96 // if (aLabel.IsNull()) di<<"Null Label"<<"\n";
97 aShape = DBRep::Get(argv[3]);
98 // XCAFDoc_ShapeTool myAssembly;
99 // myAssembly.Init(Doc);
100 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
101 myAssembly->SetShape(aLabel, aShape);
105 static Standard_Integer getShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
108 di<<"Use: "<<argv[0]<<" Result DocName Label"<<"\n";
111 Handle(TDocStd_Document) Doc;
112 DDocStd::GetDocument(argv[2], Doc);
113 if ( Doc.IsNull() ) { di << argv[2] << " is not a document" << "\n"; return 1; }
116 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
117 if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;}
119 // XCAFDoc_ShapeTool myAssembly;
120 // myAssembly.Init(Doc);
121 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
122 aShape = myAssembly->GetShape(aLabel);
123 Standard_CString name1 = argv[1];
124 DBRep::Set(name1, aShape);
129 static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
132 di<<"Use: "<<argv[0]<<" DocName Label"<<"\n";
135 Handle(TDocStd_Document) Doc;
136 DDocStd::GetDocument(argv[1], Doc);
137 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
140 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
141 if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;}
143 // XCAFDoc_ShapeTool myAssembly;
144 // myAssembly.Init(Doc);
145 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
146 myAssembly->RemoveShape(aLabel);
151 static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
154 di<<"Use: "<<argv[0]<<" DocName Shape"<<"\n";
157 Handle(TDocStd_Document) Doc;
158 DDocStd::GetDocument(argv[1], Doc);
159 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
163 aShape = DBRep::Get(argv[2]);
164 // XCAFDoc_ShapeTool myAssembly;
165 // myAssembly.Init(Doc);
166 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
167 aLabel = myAssembly->FindShape(aShape);
168 TCollection_AsciiString Entry;
169 TDF_Tool::Entry(aLabel, Entry);
170 di << Entry.ToCString();
171 //di<<"Label with Shape is "<<Entry<<"\n";
175 static Standard_Integer labelInfo (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
178 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
181 Handle(TDocStd_Document) Doc;
182 DDocStd::GetDocument(argv[1], Doc);
183 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
186 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
187 // XCAFDoc_ShapeTool myAssembly;
188 // myAssembly.Init(Doc);
189 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
190 TCollection_AsciiString Entry;
192 if ( myAssembly->IsShape(aLabel) ) {
193 //di<<"There are a TopLevelShape"<<"\n";
194 Entry="There are a TopLevelShape";
195 di << Entry.ToCString();
197 if ( myAssembly->IsComponent(aLabel) ) {
198 //di<<"There are a Component"<<"\n";
199 Entry="There are a Component";
200 di << Entry.ToCString();
202 if ( myAssembly->IsAssembly(aLabel) ) {
203 //di<<"There are an Assembly"<<"\n";
204 Entry="There are an Assembly";
205 di << Entry.ToCString();
207 if ( myAssembly->IsFree(aLabel) ) {
208 //di<<"This Shape don't used"<<"\n";
209 Entry="This Shape don't used";
210 di << Entry.ToCString();
215 static Standard_Integer getUsers (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
218 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n";
221 Standard_Boolean getsubchilds = Standard_False;
222 if ( (argc==4) && ( atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
224 Handle(TDocStd_Document) Doc;
225 DDocStd::GetDocument(argv[1], Doc);
226 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
229 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
230 TDF_LabelSequence labseq;
231 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
232 TCollection_AsciiString Entry;
233 Entry=myAssembly->GetUsers(aLabel, labseq, getsubchilds);
234 di << Entry.ToCString();
235 //di<<myAssembly->GetUsers(aLabel, labseq, getsubchilds)<<" assemblies use this component"<<"\n";
239 static Standard_Integer nbComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
242 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n";
245 Standard_Boolean getsubchilds = Standard_False;
246 if ( (argc==4) && ( atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
247 Handle(TDocStd_Document) Doc;
248 DDocStd::GetDocument(argv[1], Doc);
249 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
252 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
253 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
254 // XCAFDoc_ShapeTool myAssembly->
255 // myAssembly->Init(Doc);
256 //di<<"This assembly has ";
257 TCollection_AsciiString Entry;
258 Entry=myAssembly->NbComponents( aLabel, getsubchilds);
259 di << Entry.ToCString();
260 //di<<" components"<<"\n";
261 //di<<"This assembly has "<<myAssembly->NbComponents( aLabel, getsubchilds )<<" components"<<"\n";
266 static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
269 di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n";
272 Handle(TDocStd_Document) Doc;
273 DDocStd::GetDocument(argv[1], Doc);
274 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
277 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
279 aShape = DBRep::Get(argv[3]);
280 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
281 // XCAFDoc_ShapeTool myAssembly->
282 // myAssembly->Init(Doc);
283 myAssembly->AddComponent(aLabel, aShape);
284 TCollection_AsciiString Entry;
285 TDF_Tool::Entry(aLabel, Entry);
286 di << Entry.ToCString();
291 static Standard_Integer removeComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
294 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
297 Handle(TDocStd_Document) Doc;
298 DDocStd::GetDocument(argv[1], Doc);
299 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
302 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
303 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
304 // XCAFDoc_ShapeTool myAssembly->
305 // myAssembly->Init(Doc);
306 myAssembly->RemoveComponent(aLabel);
310 static Standard_Integer getReferredShape (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; }
320 TDF_Label aLabel, RootLabel;
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->GetReferredShape(aLabel, RootLabel);
327 TCollection_AsciiString Entry;
328 TDF_Tool::Entry(RootLabel, Entry);
329 //di<<"Label with Shape is ";
330 di << Entry.ToCString();
334 static Standard_Integer getTopLevelShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
337 di<<"Use: "<<argv[0]<<" DocName "<<"\n";
340 Handle(TDocStd_Document) Doc;
341 DDocStd::GetDocument(argv[1], Doc);
342 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
345 TDF_LabelSequence Labels;
347 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
348 // XCAFDoc_ShapeTool myAssembly->
349 // myAssembly->Init(Doc);
350 myAssembly->GetShapes(Labels);
351 TCollection_AsciiString Entry;
352 if (Labels.Length() >= 1) {
353 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
354 aLabel = Labels.Value(i);
355 TDF_Tool::Entry( aLabel, Entry);
356 di << Entry.ToCString() << " ";
362 static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
365 di<<"Use: "<<argv[0]<<" DocName [shape_prefix]"<<"\n";
369 Handle(TDocStd_Document) Doc;
370 DDocStd::GetDocument(argv[1], Doc);
371 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
373 TDF_LabelSequence Labels;
374 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
375 STool->GetFreeShapes(Labels);
376 if ( Labels.Length() <=0 ) {
377 di << "Document " << argv[1] << " contain no shapes" << "\n";
382 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
383 TCollection_AsciiString Entry;
384 TDF_Tool::Entry( Labels.Value(i), Entry);
385 di << Entry.ToCString() << " ";
388 else if ( Labels.Length() ==1 ) {
389 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
390 DBRep::Set ( argv[2], S );
394 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
395 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
397 sprintf ( string, "%s_%d", argv[2], i );
398 DBRep::Set ( string, S );
405 static Standard_Integer getOneShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
408 di<<"Use: "<<argv[0]<<" shape DocName "<<"\n";
412 Handle(TDocStd_Document) Doc;
413 DDocStd::GetDocument(argv[2], Doc);
414 if ( Doc.IsNull() ) { di << argv[2] << " is not a document" << "\n"; return 1; }
416 TDF_LabelSequence Labels;
417 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
418 STool->GetFreeShapes(Labels);
419 if ( Labels.Length() <=0 ) {
420 di << "Document " << argv[2] << " contain no shapes" << "\n";
424 if ( Labels.Length() ==1 ) {
425 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
426 DBRep::Set ( argv[1], S );
431 B.MakeCompound ( C );
432 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
433 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
436 DBRep::Set ( argv[1], C );
442 //=======================================================================
443 //function : XDumpLocation
444 //purpose : Dump Transformation() of XCAFDoc_Location attribute
445 //=======================================================================
446 static Standard_Integer XDumpLocation (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
450 di << "Use: " << argv[0] << " Doc Label " << "\n";
453 Handle(TDocStd_Document) Doc;
454 DDocStd::GetDocument(argv[1], Doc);
457 di << argv[1] << " is not a document" << "\n";
462 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
464 Handle(XCAFDoc_Location) aLoc;
465 if (!aLabel.FindAttribute(XCAFDoc_Location::GetID(), aLoc))
467 di << "Label " << argv[2] << " doesn't contain XCAFDoc_Location attribute" << "\n";
471 TopLoc_Location aTopLoc = aLoc->Get();
472 gp_Trsf aTrsf = aTopLoc.Transformation();
474 di << "Transformation (3 rows * 4 columns matrix):";
475 for (int i = 1; i <= 3; i++) // row number
478 for (int j = 1; j <= 4; j++) // column number
480 if (j > 1) di << ",";
481 di << TCollection_AsciiString(aTrsf.Value(i,j)).ToCString();
489 static Standard_Integer setSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
493 di << "Use: " << argv[0] << " Doc UU_Label NU_Label " << "\n";
496 Handle(TDocStd_Document) Doc;
497 DDocStd::GetDocument(argv[1], Doc);
498 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
500 TDF_LabelSequence aLabSeq;
501 for (Standard_Integer i = 3; i <= argc; i++) {
503 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
507 di << argv[i - 1] << " is null label" << "\n";
509 if (aLabSeq.Length() < 2) {
510 di << "Error: couldnot set SHUO between on less then 2 labels" << "\n";
512 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
513 Handle(XCAFDoc_GraphNode) aMainSHUO;
514 myAssembly->SetSHUO( aLabSeq, aMainSHUO );
515 if (aMainSHUO.IsNull()) {
516 di << "Error: cannot set the SHUO" << "\n";
523 static Standard_Integer getSHUOUpperUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
527 di << "Use: " << argv[0] << " Doc NU_Label " << "\n";
530 Handle(TDocStd_Document) Doc;
531 DDocStd::GetDocument(argv[1], Doc);
532 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
534 TDF_Tool::Label(Doc->GetData(), argv[2], NL);
536 di << argv[2] << " is null label" << "\n";
539 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
540 TDF_LabelSequence labseq;
541 myAssembly->GetSHUOUpperUsage( NL, labseq );
542 TCollection_AsciiString Entry;
543 if (labseq.Length() >= 1) {
544 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
545 TDF_Label aLabel = labseq.Value(i);
546 TDF_Tool::Entry( aLabel, Entry);
547 di << Entry.ToCString() << " ";
553 static Standard_Integer getSHUONextUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
557 di << "Use: " << argv[0] << " Doc UU_Label " << "\n";
560 Handle(TDocStd_Document) Doc;
561 DDocStd::GetDocument(argv[1], Doc);
562 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
564 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
566 di << argv[2] << " is null label" << "\n";
569 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
570 TDF_LabelSequence labseq;
571 myAssembly->GetSHUONextUsage( UL, labseq );
572 TCollection_AsciiString Entry;
573 if (labseq.Length() >= 1) {
574 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
575 TDF_Label aLabel = labseq.Value(i);
576 TDF_Tool::Entry( aLabel, Entry);
577 di << Entry.ToCString() << " ";
583 static Standard_Integer removeSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
587 di << "Use: " << argv[0] << " Doc SHUOComponent_Label " << "\n";
590 Handle(TDocStd_Document) Doc;
591 DDocStd::GetDocument(argv[1], Doc);
592 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
594 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
596 di << argv[2] << " is null label" << "\n";
599 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
600 myAssembly->RemoveSHUO( UL );
605 static Standard_Integer hasSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
609 di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n";
612 Handle(TDocStd_Document) Doc;
613 DDocStd::GetDocument(argv[1], Doc);
614 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
616 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
618 di << argv[2] << " is null label" << "\n";
621 Handle(XCAFDoc_GraphNode) anAttrSHUO;
622 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
623 if (myAssembly->GetSHUO( UL, anAttrSHUO ))
631 static Standard_Integer getAllSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
635 di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n";
638 Handle(TDocStd_Document) Doc;
639 DDocStd::GetDocument(argv[1], Doc);
640 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
641 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
643 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
645 di << argv[2] << " is null label" << "\n";
648 TDF_AttributeSequence SHUOAttrs;
649 myAssembly->GetAllComponentSHUO( UL, SHUOAttrs );
650 TCollection_AsciiString Entry;
651 if (SHUOAttrs.Length() >= 1) {
652 for ( Standard_Integer i = 1; i<= SHUOAttrs.Length(); i++) {
653 TDF_Label aLabel = SHUOAttrs.Value(i)->Label();
654 TDF_Tool::Entry( aLabel, Entry);
655 di << Entry.ToCString() << " ";
661 static Standard_Integer findComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
665 di << "Use: " << argv[0] << " Doc shape " << "\n";
668 Handle(TDocStd_Document) Doc;
669 DDocStd::GetDocument(argv[1], Doc);
670 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
671 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
673 aShape = DBRep::Get(argv[2]);
674 TDF_LabelSequence labseq;
675 myAssembly->FindComponent( aShape, 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() << " ";
687 static Standard_Integer getStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
691 di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n";
694 Handle(TDocStd_Document) Doc;
695 DDocStd::GetDocument(argv[1], Doc);
696 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
697 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
700 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
701 Handle(XCAFDoc_GraphNode) SHUO;
702 if (myAssembly->GetSHUO( aLabel, SHUO ))
703 aShape = myAssembly->GetSHUOInstance( SHUO );
705 if (aShape.IsNull()) {
706 di << "cannot get component" << "\n";
709 DBRep::Set ( argv[2], aShape );
714 static Standard_Integer getAllStyledComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
718 di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n";
721 Handle(TDocStd_Document) Doc;
722 DDocStd::GetDocument(argv[1], Doc);
723 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
724 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
725 TopTools_SequenceOfShape aShapes;
727 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
728 Handle(XCAFDoc_GraphNode) SHUO;
729 if (myAssembly->GetSHUO( aLabel, SHUO ))
730 if (myAssembly->GetAllSHUOInstances(SHUO, aShapes)) {
731 TopoDS_Compound aShape;
733 B.MakeCompound(aShape);
734 for (Standard_Integer jj = 1; jj <= aShapes.Length(); jj++) {
735 TopoDS_Shape aCurShape = aShapes.Value(jj);
736 B.Add( aShape, aCurShape );
738 DBRep::Set ( argv[2], aShape );
745 static Standard_Integer findSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
749 di << "Use: " << argv[0] << " Doc labels " << "\n";
752 Handle(TDocStd_Document) Doc;
753 DDocStd::GetDocument(argv[1], Doc);
754 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
755 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
756 TDF_LabelSequence aLabSeq;
757 for (Standard_Integer i = 3; i <= argc; i++) {
759 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
763 di << argv[i - 1] << " is null label" << "\n";
765 if (aLabSeq.Length() < 2) {
766 di << "Error: couldnot find SHUO between on less then 2 labels" << "\n";
768 Handle(XCAFDoc_GraphNode) SHUO;
769 myAssembly->FindSHUO( aLabSeq, SHUO );
771 di << "cannot find SHUO" << "\n";
774 TCollection_AsciiString Entry;
775 TDF_Tool::Entry( SHUO->Label(), Entry);
776 di << Entry.ToCString() << " ";
781 static Standard_Integer setStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
785 di << "Use: " << argv[0] << " Doc shape " << "\n";
788 Handle(TDocStd_Document) Doc;
789 DDocStd::GetDocument(argv[1], Doc);
790 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
791 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
793 aShape = DBRep::Get(argv[2]);
794 if (aShape.IsNull()) {
795 di << "Shape " << argv[2] << " is null" << "\n";
798 Handle(XCAFDoc_GraphNode) aSHUOAttr;
799 aSHUOAttr = myAssembly->SetInstanceSHUO( aShape );
800 if (aSHUOAttr.IsNull()) {
801 di << "Error: cannot set a SHUO structure for indicated component" << "\n";
804 TCollection_AsciiString Entry;
805 TDF_Tool::Entry( aSHUOAttr->Label(), Entry);
806 di << Entry.ToCString() << " ";
810 //=======================================================================
811 //function : InitCommands
813 //=======================================================================
815 void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di)
818 static Standard_Boolean initactor = Standard_False;
819 if (initactor) return; initactor = Standard_True;
821 //=====================================
823 //=====================================
825 Standard_CString g = "XDE shape's commands";
827 di.Add ("XAddShape","Doc Shape [makeAssembly = 1]\t: Add shape (or assembly) to Document",
828 __FILE__, addShape, g);
830 di.Add ("XNewShape","Doc \t: Create new empty top-level shape",
831 __FILE__, newShape, g);
833 di.Add ("XSetShape","Doc Label Shape \t: Set shape at indicated label",
834 __FILE__, setShape, g);
836 di.Add ("XGetShape","Result Doc Label \t: Put shape from tree to Result",
837 __FILE__, getShape, g);
839 di.Add ("XRemoveShape","Doc Label \t: Remove shape from document",
840 __FILE__, removeShape, g);
842 di.Add ("XFindShape","Doc Shape \t: Find and print label with indicated top-level shape",
843 __FILE__, findShape, g);
845 di.Add ("XLabelInfo","Doc Label \t: Print information about object at following label",
846 __FILE__, labelInfo, g);
848 di.Add ("XGetUsers","Doc Label [withSubChilds(int)] \t: Print number of assemblies that use shape at following label",
849 __FILE__, getUsers, g);
851 di.Add ("XNbComponents","Doc Label [withSubChilds(int)] \t: Print number of component of assembly ",
852 __FILE__, nbComponents, g);
854 di.Add ("XAddComponent","Doc Label Shape \t: Add component shape to assembly",
855 __FILE__, addComponent, g);
857 di.Add ("XRemoveComponent","Doc Label \t: Remove component from components label",
858 __FILE__, removeComponent, g);
860 di.Add ("XGetReferredShape","Doc Label \t: Print label, that contain a top-level shape, that corresponds shape at following label",
861 __FILE__, getReferredShape, g);
863 di.Add ("XGetTopLevelShapes","Doc \t: Print labels, that contain a top-level shapes",
864 __FILE__, getTopLevelShapes, g);
866 di.Add ("XGetFreeShapes","Doc [shape_prefix]\t: Print labels or create DRAW shapes for all free shapes in the Doc",
867 __FILE__, getFreeShapes, g);
869 di.Add ("XGetOneShape","shape Doc \t: Put all free shapes of the Doc into signle DRAW shape",
870 __FILE__, getOneShape, g);
872 di.Add ("XDumpLocation","Doc Label \t: Dump Transformation() of XCAFDoc_Location attribute",
873 __FILE__, XDumpLocation, g);
875 di.Add ("XSetSHUO","Doc UU_Label [ multi-level labels ] NU_Label \t: sets the SHUO structure between UpperUsage and NextUsage",
876 __FILE__, setSHUO, g);
878 di.Add ("XGetUU_SHUO","Doc NU_Label \t: prints the UpperUsages of indicated NextUsage",
879 __FILE__, getSHUOUpperUsage, g);
881 di.Add ("XGetNU_SHUO","Doc UU_Label \t: prints the NextUsages of indicated UpperUsage",
882 __FILE__, getSHUONextUsage, g);
884 di.Add ("XRemoveSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
885 __FILE__, removeSHUO, g);
887 di.Add ("XIsHasSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
888 __FILE__, hasSHUO, g);
890 di.Add ("XGetAllSHUO","Doc Comp_Label \t: remove SHUO of indicated component",
891 __FILE__, getAllSHUO, g);
893 di.Add ("XFindComponent","Doc Shape \t: prints sequence of labels of assembly path",
894 __FILE__, findComponent, g);
896 di.Add ("XGetSHUOInstance","Doc res SHUO_Label \t: returns SHUO_styled shape",
897 __FILE__, getStyledComponent, g);
899 di.Add ("XGetAllSHUOInstances","Doc res SHUO_Label \t: returns SHUO_styled shapes as compound",
900 __FILE__, getAllStyledComponents, g);
902 di.Add ("XFindSHUO","Doc labels of SHUO structure \t: prints label of SHUO that found by labels structure",
903 __FILE__, findSHUO, g);
905 di.Add ("XSetInstanceSHUO","Doc shape \t: sets the SHUO structure for indicated component",
906 __FILE__, setStyledComponent, g);