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.
16 #include <XDEDRAW_Shapes.ixx>
20 #include <DDocStd.hxx>
22 #include <TopoDS_Shape.hxx>
23 #include <TopoDS_Compound.hxx>
24 #include <BRep_Builder.hxx>
26 #include <gp_Trsf.hxx>
28 #include <TDF_Tool.hxx>
29 #include <TDF_Label.hxx>
30 #include <TDF_LabelSequence.hxx>
31 #include <TDocStd_Document.hxx>
33 #include <XCAFDoc_DocumentTool.hxx>
34 #include <XCAFDoc_ShapeTool.hxx>
35 #include <XCAFDoc_Location.hxx>
37 #include <TCollection_AsciiString.hxx>
40 #include <XCAFDoc_GraphNode.hxx>
41 #include <TDF_AttributeSequence.hxx>
42 #include <TopTools_SequenceOfShape.hxx>
44 //=======================================================================
45 // Section: Work with shapes
46 //=======================================================================
48 static Standard_Integer addShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
51 di<<"Use: "<<argv[0]<<" DocName Shape [int makeAssembly (1/0)]"<<"\n";
54 Handle(TDocStd_Document) Doc;
55 DDocStd::GetDocument(argv[1], Doc);
56 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
59 aShape = DBRep::Get(argv[2]);
60 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
61 Standard_Boolean makeAssembly = Standard_True;
62 if ( argc==4 && Draw::Atoi(argv[3]) == 0 ) makeAssembly = Standard_False;
64 aLabel = myAssembly->AddShape(aShape, makeAssembly);
65 if (aLabel.IsNull()) di<<"Null Label"<<"\n";
66 TCollection_AsciiString Entry;
67 TDF_Tool::Entry(aLabel, Entry);
68 di << Entry.ToCString();
72 static Standard_Integer newShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
75 di<<"Use: "<<argv[0]<<" DocName "<<"\n";
78 Handle(TDocStd_Document) Doc;
80 DDocStd::GetDocument(argv[1], Doc);
81 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
83 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
84 //XCAFDoc_ShapeTool myAssembly;
85 // myAssembly.Init(Doc);
86 aLabel=myAssembly->NewShape();
87 // di<<"New Shape at ChildTag"<<aLabel.Tag()<<"\n";
88 TCollection_AsciiString Entry;
89 TDF_Tool::Entry(aLabel, Entry);
90 di << Entry.ToCString();
94 static Standard_Integer setShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
97 di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n";
100 Handle(TDocStd_Document) Doc;
101 DDocStd::GetDocument(argv[1], Doc);
102 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
105 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
107 // if (aLabel.IsNull()) di<<"Null Label"<<"\n";
108 aShape = DBRep::Get(argv[3]);
109 // XCAFDoc_ShapeTool myAssembly;
110 // myAssembly.Init(Doc);
111 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
112 myAssembly->SetShape(aLabel, aShape);
116 static Standard_Integer getShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
119 di<<"Use: "<<argv[0]<<" Result DocName Label"<<"\n";
122 Handle(TDocStd_Document) Doc;
123 DDocStd::GetDocument(argv[2], Doc);
124 if ( Doc.IsNull() ) { di << argv[2] << " is not a document" << "\n"; return 1; }
127 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
128 if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;}
130 // XCAFDoc_ShapeTool myAssembly;
131 // myAssembly.Init(Doc);
132 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
133 aShape = myAssembly->GetShape(aLabel);
134 Standard_CString name1 = argv[1];
135 DBRep::Set(name1, aShape);
140 static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
142 if (argc != 3 && argc != 4)
144 di<<"Use: "<<argv[0]<<" DocName Label [int removeCompletely (1/0)]"<<"\n";
147 Handle(TDocStd_Document) Doc;
148 DDocStd::GetDocument(argv[1], Doc);
149 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
152 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
153 if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;}
155 // XCAFDoc_ShapeTool myAssembly;
156 // myAssembly.Init(Doc);
157 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
158 Standard_Boolean removeCompletely = Standard_True;
159 if ( argc == 4 && Draw::Atoi(argv[3]) == 0 )
160 removeCompletely = Standard_False;
161 myAssembly->RemoveShape(aLabel, removeCompletely);
166 static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
169 di<<"Use: "<<argv[0]<<" DocName Shape"<<"\n";
172 Handle(TDocStd_Document) Doc;
173 DDocStd::GetDocument(argv[1], Doc);
174 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
178 aShape = DBRep::Get(argv[2]);
179 // XCAFDoc_ShapeTool myAssembly;
180 // myAssembly.Init(Doc);
181 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
182 aLabel = myAssembly->FindShape(aShape);
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 labelInfo (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
193 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
196 Handle(TDocStd_Document) Doc;
197 DDocStd::GetDocument(argv[1], Doc);
198 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
201 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
202 // XCAFDoc_ShapeTool myAssembly;
203 // myAssembly.Init(Doc);
204 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
205 TCollection_AsciiString Entry;
207 if ( myAssembly->IsShape(aLabel) ) {
208 //di<<"There are a TopLevelShape"<<"\n";
209 Entry="There are a TopLevelShape";
210 di << Entry.ToCString();
212 if ( myAssembly->IsComponent(aLabel) ) {
213 //di<<"There are a Component"<<"\n";
214 Entry="There are a Component";
215 di << Entry.ToCString();
217 if ( myAssembly->IsAssembly(aLabel) ) {
218 //di<<"There are an Assembly"<<"\n";
219 Entry="There are an Assembly";
220 di << Entry.ToCString();
222 if ( myAssembly->IsFree(aLabel) ) {
223 //di<<"This Shape don't used"<<"\n";
224 Entry="This Shape don't used";
225 di << Entry.ToCString();
230 static Standard_Integer getUsers (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
233 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n";
236 Standard_Boolean getsubchilds = Standard_False;
237 if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
239 Handle(TDocStd_Document) Doc;
240 DDocStd::GetDocument(argv[1], Doc);
241 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
244 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
245 TDF_LabelSequence labseq;
246 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
247 TCollection_AsciiString Entry;
248 Entry=myAssembly->GetUsers(aLabel, labseq, getsubchilds);
249 di << Entry.ToCString();
250 //di<<myAssembly->GetUsers(aLabel, labseq, getsubchilds)<<" assemblies use this component"<<"\n";
254 static Standard_Integer nbComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
257 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n";
260 Standard_Boolean getsubchilds = Standard_False;
261 if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
262 Handle(TDocStd_Document) Doc;
263 DDocStd::GetDocument(argv[1], Doc);
264 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
267 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
268 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
269 // XCAFDoc_ShapeTool myAssembly->
270 // myAssembly->Init(Doc);
271 //di<<"This assembly has ";
272 TCollection_AsciiString Entry;
273 Entry=myAssembly->NbComponents( aLabel, getsubchilds);
274 di << Entry.ToCString();
275 //di<<" components"<<"\n";
276 //di<<"This assembly has "<<myAssembly->NbComponents( aLabel, getsubchilds )<<" components"<<"\n";
281 static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
284 di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n";
287 Handle(TDocStd_Document) Doc;
288 DDocStd::GetDocument(argv[1], Doc);
289 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
292 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
294 aShape = DBRep::Get(argv[3]);
295 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
296 // XCAFDoc_ShapeTool myAssembly->
297 // myAssembly->Init(Doc);
298 myAssembly->AddComponent(aLabel, aShape);
299 TCollection_AsciiString Entry;
300 TDF_Tool::Entry(aLabel, Entry);
301 di << Entry.ToCString();
306 static Standard_Integer removeComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
309 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
312 Handle(TDocStd_Document) Doc;
313 DDocStd::GetDocument(argv[1], Doc);
314 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
317 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
318 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
319 // XCAFDoc_ShapeTool myAssembly->
320 // myAssembly->Init(Doc);
321 myAssembly->RemoveComponent(aLabel);
325 static Standard_Integer getReferredShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
328 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
331 Handle(TDocStd_Document) Doc;
332 DDocStd::GetDocument(argv[1], Doc);
333 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
335 TDF_Label aLabel, RootLabel;
336 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
337 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
338 // XCAFDoc_ShapeTool myAssembly->
339 // myAssembly->Init(Doc);
340 myAssembly->GetReferredShape(aLabel, RootLabel);
342 TCollection_AsciiString Entry;
343 TDF_Tool::Entry(RootLabel, Entry);
344 //di<<"Label with Shape is ";
345 di << Entry.ToCString();
349 static Standard_Integer getTopLevelShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
352 di<<"Use: "<<argv[0]<<" DocName "<<"\n";
355 Handle(TDocStd_Document) Doc;
356 DDocStd::GetDocument(argv[1], Doc);
357 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
360 TDF_LabelSequence Labels;
362 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
363 // XCAFDoc_ShapeTool myAssembly->
364 // myAssembly->Init(Doc);
365 myAssembly->GetShapes(Labels);
366 TCollection_AsciiString Entry;
367 if (Labels.Length() >= 1) {
368 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
369 aLabel = Labels.Value(i);
370 TDF_Tool::Entry( aLabel, Entry);
371 di << Entry.ToCString() << " ";
377 static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
380 di<<"Use: "<<argv[0]<<" DocName [shape_prefix]"<<"\n";
384 Handle(TDocStd_Document) Doc;
385 DDocStd::GetDocument(argv[1], Doc);
386 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
388 TDF_LabelSequence Labels;
389 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
390 STool->GetFreeShapes(Labels);
391 if ( Labels.Length() <=0 ) {
392 di << "Document " << argv[1] << " contain no shapes" << "\n";
397 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
398 TCollection_AsciiString Entry;
399 TDF_Tool::Entry( Labels.Value(i), Entry);
400 di << Entry.ToCString() << " ";
403 else if ( Labels.Length() ==1 ) {
404 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
405 DBRep::Set ( argv[2], S );
409 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
410 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
412 Sprintf ( string, "%s_%d", argv[2], i );
413 DBRep::Set ( string, S );
420 static Standard_Integer getOneShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
423 di<<"Use: "<<argv[0]<<" shape DocName "<<"\n";
427 Handle(TDocStd_Document) Doc;
428 DDocStd::GetDocument(argv[2], Doc);
429 if ( Doc.IsNull() ) { di << argv[2] << " is not a document" << "\n"; return 1; }
431 TDF_LabelSequence Labels;
432 Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
433 STool->GetFreeShapes(Labels);
434 if ( Labels.Length() <=0 ) {
435 di << "Document " << argv[2] << " contain no shapes" << "\n";
439 if ( Labels.Length() ==1 ) {
440 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
441 DBRep::Set ( argv[1], S );
446 B.MakeCompound ( C );
447 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
448 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
451 DBRep::Set ( argv[1], C );
457 //=======================================================================
458 //function : XDumpLocation
459 //purpose : Dump Transformation() of XCAFDoc_Location attribute
460 //=======================================================================
461 static Standard_Integer XDumpLocation (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
465 di << "Use: " << argv[0] << " Doc Label " << "\n";
468 Handle(TDocStd_Document) Doc;
469 DDocStd::GetDocument(argv[1], Doc);
472 di << argv[1] << " is not a document" << "\n";
477 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
479 Handle(XCAFDoc_Location) aLoc;
480 if (!aLabel.FindAttribute(XCAFDoc_Location::GetID(), aLoc))
482 di << "Label " << argv[2] << " doesn't contain XCAFDoc_Location attribute" << "\n";
486 TopLoc_Location aTopLoc = aLoc->Get();
487 gp_Trsf aTrsf = aTopLoc.Transformation();
489 di << "Transformation (3 rows * 4 columns matrix):";
490 for (int i = 1; i <= 3; i++) // row number
493 for (int j = 1; j <= 4; j++) // column number
495 if (j > 1) di << ",";
496 di << TCollection_AsciiString(aTrsf.Value(i,j)).ToCString();
504 static Standard_Integer setSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
508 di << "Use: " << argv[0] << " Doc UU_Label NU_Label " << "\n";
511 Handle(TDocStd_Document) Doc;
512 DDocStd::GetDocument(argv[1], Doc);
513 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
515 TDF_LabelSequence aLabSeq;
516 for (Standard_Integer i = 3; i <= argc; i++) {
518 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
522 di << argv[i - 1] << " is null label" << "\n";
524 if (aLabSeq.Length() < 2) {
525 di << "Error: couldnot set SHUO between on less then 2 labels" << "\n";
527 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
528 Handle(XCAFDoc_GraphNode) aMainSHUO;
529 myAssembly->SetSHUO( aLabSeq, aMainSHUO );
530 if (aMainSHUO.IsNull()) {
531 di << "Error: cannot set the SHUO" << "\n";
538 static Standard_Integer getSHUOUpperUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
542 di << "Use: " << argv[0] << " Doc NU_Label " << "\n";
545 Handle(TDocStd_Document) Doc;
546 DDocStd::GetDocument(argv[1], Doc);
547 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
549 TDF_Tool::Label(Doc->GetData(), argv[2], NL);
551 di << argv[2] << " is null label" << "\n";
554 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
555 TDF_LabelSequence labseq;
556 myAssembly->GetSHUOUpperUsage( NL, labseq );
557 TCollection_AsciiString Entry;
558 if (labseq.Length() >= 1) {
559 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
560 TDF_Label aLabel = labseq.Value(i);
561 TDF_Tool::Entry( aLabel, Entry);
562 di << Entry.ToCString() << " ";
568 static Standard_Integer getSHUONextUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
572 di << "Use: " << argv[0] << " Doc UU_Label " << "\n";
575 Handle(TDocStd_Document) Doc;
576 DDocStd::GetDocument(argv[1], Doc);
577 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
579 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
581 di << argv[2] << " is null label" << "\n";
584 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
585 TDF_LabelSequence labseq;
586 myAssembly->GetSHUONextUsage( UL, labseq );
587 TCollection_AsciiString Entry;
588 if (labseq.Length() >= 1) {
589 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
590 TDF_Label aLabel = labseq.Value(i);
591 TDF_Tool::Entry( aLabel, Entry);
592 di << Entry.ToCString() << " ";
598 static Standard_Integer removeSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
602 di << "Use: " << argv[0] << " Doc SHUOComponent_Label " << "\n";
605 Handle(TDocStd_Document) Doc;
606 DDocStd::GetDocument(argv[1], Doc);
607 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
609 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
611 di << argv[2] << " is null label" << "\n";
614 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
615 myAssembly->RemoveSHUO( UL );
620 static Standard_Integer hasSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
624 di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n";
627 Handle(TDocStd_Document) Doc;
628 DDocStd::GetDocument(argv[1], Doc);
629 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
631 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
633 di << argv[2] << " is null label" << "\n";
636 Handle(XCAFDoc_GraphNode) anAttrSHUO;
637 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
638 if (myAssembly->GetSHUO( UL, anAttrSHUO ))
646 static Standard_Integer getAllSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
650 di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n";
653 Handle(TDocStd_Document) Doc;
654 DDocStd::GetDocument(argv[1], Doc);
655 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
656 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
658 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
660 di << argv[2] << " is null label" << "\n";
663 TDF_AttributeSequence SHUOAttrs;
664 myAssembly->GetAllComponentSHUO( UL, SHUOAttrs );
665 TCollection_AsciiString Entry;
666 if (SHUOAttrs.Length() >= 1) {
667 for ( Standard_Integer i = 1; i<= SHUOAttrs.Length(); i++) {
668 TDF_Label aLabel = SHUOAttrs.Value(i)->Label();
669 TDF_Tool::Entry( aLabel, Entry);
670 di << Entry.ToCString() << " ";
676 static Standard_Integer findComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
680 di << "Use: " << argv[0] << " Doc shape " << "\n";
683 Handle(TDocStd_Document) Doc;
684 DDocStd::GetDocument(argv[1], Doc);
685 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
686 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
688 aShape = DBRep::Get(argv[2]);
689 TDF_LabelSequence labseq;
690 myAssembly->FindComponent( aShape, labseq );
691 TCollection_AsciiString Entry;
692 if (labseq.Length() >= 1) {
693 for ( Standard_Integer i = 1; i<= labseq.Length(); i++) {
694 TDF_Label aLabel = labseq.Value(i);
695 TDF_Tool::Entry( aLabel, Entry);
696 di << Entry.ToCString() << " ";
702 static Standard_Integer getStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
706 di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n";
709 Handle(TDocStd_Document) Doc;
710 DDocStd::GetDocument(argv[1], Doc);
711 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
712 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
715 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
716 Handle(XCAFDoc_GraphNode) SHUO;
717 if (myAssembly->GetSHUO( aLabel, SHUO ))
718 aShape = myAssembly->GetSHUOInstance( SHUO );
720 if (aShape.IsNull()) {
721 di << "cannot get component" << "\n";
724 DBRep::Set ( argv[2], aShape );
729 static Standard_Integer getAllStyledComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
733 di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n";
736 Handle(TDocStd_Document) Doc;
737 DDocStd::GetDocument(argv[1], Doc);
738 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
739 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
740 TopTools_SequenceOfShape aShapes;
742 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
743 Handle(XCAFDoc_GraphNode) SHUO;
744 if (myAssembly->GetSHUO( aLabel, SHUO ))
745 if (myAssembly->GetAllSHUOInstances(SHUO, aShapes)) {
746 TopoDS_Compound aShape;
748 B.MakeCompound(aShape);
749 for (Standard_Integer jj = 1; jj <= aShapes.Length(); jj++) {
750 TopoDS_Shape aCurShape = aShapes.Value(jj);
751 B.Add( aShape, aCurShape );
753 DBRep::Set ( argv[2], aShape );
760 static Standard_Integer findSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
764 di << "Use: " << argv[0] << " Doc labels " << "\n";
767 Handle(TDocStd_Document) Doc;
768 DDocStd::GetDocument(argv[1], Doc);
769 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
770 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
771 TDF_LabelSequence aLabSeq;
772 for (Standard_Integer i = 3; i <= argc; i++) {
774 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
778 di << argv[i - 1] << " is null label" << "\n";
780 if (aLabSeq.Length() < 2) {
781 di << "Error: couldnot find SHUO between on less then 2 labels" << "\n";
783 Handle(XCAFDoc_GraphNode) SHUO;
784 myAssembly->FindSHUO( aLabSeq, SHUO );
786 di << "cannot find SHUO" << "\n";
789 TCollection_AsciiString Entry;
790 TDF_Tool::Entry( SHUO->Label(), Entry);
791 di << Entry.ToCString() << " ";
796 static Standard_Integer setStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
800 di << "Use: " << argv[0] << " Doc shape " << "\n";
803 Handle(TDocStd_Document) Doc;
804 DDocStd::GetDocument(argv[1], Doc);
805 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
806 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
808 aShape = DBRep::Get(argv[2]);
809 if (aShape.IsNull()) {
810 di << "Shape " << argv[2] << " is null" << "\n";
813 Handle(XCAFDoc_GraphNode) aSHUOAttr;
814 aSHUOAttr = myAssembly->SetInstanceSHUO( aShape );
815 if (aSHUOAttr.IsNull()) {
816 di << "Error: cannot set a SHUO structure for indicated component" << "\n";
819 TCollection_AsciiString Entry;
820 TDF_Tool::Entry( aSHUOAttr->Label(), Entry);
821 di << Entry.ToCString() << " ";
825 //=======================================================================
826 //function : InitCommands
828 //=======================================================================
830 void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di)
833 static Standard_Boolean initactor = Standard_False;
834 if (initactor) return; initactor = Standard_True;
836 //=====================================
838 //=====================================
840 Standard_CString g = "XDE shape's commands";
842 di.Add ("XAddShape","Doc Shape [makeAssembly = 1]\t: Add shape (or assembly) to Document",
843 __FILE__, addShape, g);
845 di.Add ("XNewShape","Doc \t: Create new empty top-level shape",
846 __FILE__, newShape, g);
848 di.Add ("XSetShape","Doc Label Shape \t: Set shape at indicated label",
849 __FILE__, setShape, g);
851 di.Add ("XGetShape","Result Doc Label \t: Put shape from tree to Result",
852 __FILE__, getShape, g);
854 di.Add ("XRemoveShape","Doc Label \t: Remove shape from document",
855 __FILE__, removeShape, g);
857 di.Add ("XFindShape","Doc Shape \t: Find and print label with indicated top-level shape",
858 __FILE__, findShape, g);
860 di.Add ("XLabelInfo","Doc Label \t: Print information about object at following label",
861 __FILE__, labelInfo, g);
863 di.Add ("XGetUsers","Doc Label [withSubChilds(int)] \t: Print number of assemblies that use shape at following label",
864 __FILE__, getUsers, g);
866 di.Add ("XNbComponents","Doc Label [withSubChilds(int)] \t: Print number of component of assembly ",
867 __FILE__, nbComponents, g);
869 di.Add ("XAddComponent","Doc Label Shape \t: Add component shape to assembly",
870 __FILE__, addComponent, g);
872 di.Add ("XRemoveComponent","Doc Label \t: Remove component from components label",
873 __FILE__, removeComponent, g);
875 di.Add ("XGetReferredShape","Doc Label \t: Print label, that contain a top-level shape, that corresponds shape at following label",
876 __FILE__, getReferredShape, g);
878 di.Add ("XGetTopLevelShapes","Doc \t: Print labels, that contain a top-level shapes",
879 __FILE__, getTopLevelShapes, g);
881 di.Add ("XGetFreeShapes","Doc [shape_prefix]\t: Print labels or create DRAW shapes for all free shapes in the Doc",
882 __FILE__, getFreeShapes, g);
884 di.Add ("XGetOneShape","shape Doc \t: Put all free shapes of the Doc into signle DRAW shape",
885 __FILE__, getOneShape, g);
887 di.Add ("XDumpLocation","Doc Label \t: Dump Transformation() of XCAFDoc_Location attribute",
888 __FILE__, XDumpLocation, g);
890 di.Add ("XSetSHUO","Doc UU_Label [ multi-level labels ] NU_Label \t: sets the SHUO structure between UpperUsage and NextUsage",
891 __FILE__, setSHUO, g);
893 di.Add ("XGetUU_SHUO","Doc NU_Label \t: prints the UpperUsages of indicated NextUsage",
894 __FILE__, getSHUOUpperUsage, g);
896 di.Add ("XGetNU_SHUO","Doc UU_Label \t: prints the NextUsages of indicated UpperUsage",
897 __FILE__, getSHUONextUsage, g);
899 di.Add ("XRemoveSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
900 __FILE__, removeSHUO, g);
902 di.Add ("XIsHasSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
903 __FILE__, hasSHUO, g);
905 di.Add ("XGetAllSHUO","Doc Comp_Label \t: remove SHUO of indicated component",
906 __FILE__, getAllSHUO, g);
908 di.Add ("XFindComponent","Doc Shape \t: prints sequence of labels of assembly path",
909 __FILE__, findComponent, g);
911 di.Add ("XGetSHUOInstance","Doc res SHUO_Label \t: returns SHUO_styled shape",
912 __FILE__, getStyledComponent, g);
914 di.Add ("XGetAllSHUOInstances","Doc res SHUO_Label \t: returns SHUO_styled shapes as compound",
915 __FILE__, getAllStyledComponents, g);
917 di.Add ("XFindSHUO","Doc labels of SHUO structure \t: prints label of SHUO that found by labels structure",
918 __FILE__, findSHUO, g);
920 di.Add ("XSetInstanceSHUO","Doc shape \t: sets the SHUO structure for indicated component",
921 __FILE__, setStyledComponent, g);