0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / XDEDRAW / XDEDRAW_Shapes.cxx
CommitLineData
b311480e 1// Created on: 2000-08-04
2// Created by: Pavel TELKOV
973c2be1 3// Copyright (c) 2000-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
16#include <XDEDRAW_Shapes.ixx>
17
91322f44 18#include <Draw.hxx>
7fd59977 19#include <DBRep.hxx>
20#include <DDocStd.hxx>
21
22#include <TopoDS_Shape.hxx>
23#include <TopoDS_Compound.hxx>
24#include <BRep_Builder.hxx>
25
26#include <gp_Trsf.hxx>
27
28#include <TDF_Tool.hxx>
29#include <TDF_Label.hxx>
30#include <TDF_LabelSequence.hxx>
31#include <TDocStd_Document.hxx>
32
33#include <XCAFDoc_DocumentTool.hxx>
34#include <XCAFDoc_ShapeTool.hxx>
35#include <XCAFDoc_Location.hxx>
36
37#include <TCollection_AsciiString.hxx>
38
39#include <stdio.h>
40#include <XCAFDoc_GraphNode.hxx>
41#include <TDF_AttributeSequence.hxx>
42#include <TopTools_SequenceOfShape.hxx>
43
44//=======================================================================
45// Section: Work with shapes
46//=======================================================================
47
48static Standard_Integer addShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
49{
50 if (argc<3) {
51 di<<"Use: "<<argv[0]<<" DocName Shape [int makeAssembly (1/0)]"<<"\n";
52 return 1;
53 }
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; }
57
58 TopoDS_Shape aShape;
59 aShape = DBRep::Get(argv[2]);
60 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
61 Standard_Boolean makeAssembly = Standard_True;
91322f44 62 if ( argc==4 && Draw::Atoi(argv[3]) == 0 ) makeAssembly = Standard_False;
7fd59977 63 TDF_Label aLabel;
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();
69 return 0;
70}
71
72static Standard_Integer newShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
73{
74 if (argc!=2) {
75 di<<"Use: "<<argv[0]<<" DocName "<<"\n";
76 return 1;
77 }
78 Handle(TDocStd_Document) Doc;
79 TDF_Label aLabel;
80 DDocStd::GetDocument(argv[1], Doc);
81 if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; }
82
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();
91 return 0;
92}
93
94static Standard_Integer setShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
95{
96 if (argc!=4) {
97 di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n";
98 return 1;
99 }
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; }
103
104 TDF_Label aLabel;
105 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
106 TopoDS_Shape aShape;
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);
113 return 0;
114}
115
116static Standard_Integer getShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
117{
118 if (argc!=4) {
119 di<<"Use: "<<argv[0]<<" Result DocName Label"<<"\n";
120 return 1;
121 }
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; }
125
126 TDF_Label aLabel;
127 TDF_Tool::Label(Doc->GetData(), argv[3], aLabel);
128 if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;}
129 TopoDS_Shape aShape;
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);
136
137 return 0;
138}
139
140static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
141{
a7aa1465 142 if (argc != 3 && argc != 4)
143 {
144 di<<"Use: "<<argv[0]<<" DocName Label [int removeCompletely (1/0)]"<<"\n";
7fd59977 145 return 1;
146 }
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; }
150
151 TDF_Label aLabel;
152 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
153 if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;}
154 TopoDS_Shape aShape;
155// XCAFDoc_ShapeTool myAssembly;
156// myAssembly.Init(Doc);
157 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
a7aa1465 158 Standard_Boolean removeCompletely = Standard_True;
91322f44 159 if ( argc == 4 && Draw::Atoi(argv[3]) == 0 )
a7aa1465 160 removeCompletely = Standard_False;
161 myAssembly->RemoveShape(aLabel, removeCompletely);
7fd59977 162
163 return 0;
164}
165
166static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
167{
168 if (argc!=3) {
169 di<<"Use: "<<argv[0]<<" DocName Shape"<<"\n";
170 return 1;
171 }
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; }
175
176 TDF_Label aLabel;
177 TopoDS_Shape aShape;
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";
187 return 0;
188}
189
190static Standard_Integer labelInfo (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
191{
192 if (argc!=3) {
193 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
194 return 1;
195 }
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; }
199
200 TDF_Label aLabel;
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;
206
207 if ( myAssembly->IsShape(aLabel) ) {
208 //di<<"There are a TopLevelShape"<<"\n";
209 Entry="There are a TopLevelShape";
210 di << Entry.ToCString();
211 }
212 if ( myAssembly->IsComponent(aLabel) ) {
213 //di<<"There are a Component"<<"\n";
214 Entry="There are a Component";
215 di << Entry.ToCString();
216 }
217 if ( myAssembly->IsAssembly(aLabel) ) {
218 //di<<"There are an Assembly"<<"\n";
219 Entry="There are an Assembly";
220 di << Entry.ToCString();
221 }
222 if ( myAssembly->IsFree(aLabel) ) {
223 //di<<"This Shape don't used"<<"\n";
224 Entry="This Shape don't used";
225 di << Entry.ToCString();
226 }
227 return 0;
228}
229
230static Standard_Integer getUsers (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
231{
232 if (argc<3) {
233 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n";
234 return 1;
235 }
236 Standard_Boolean getsubchilds = Standard_False;
91322f44 237 if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
7fd59977 238
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; }
242
243 TDF_Label aLabel;
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";
251 return 0;
252}
253
254static Standard_Integer nbComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
255{
256 if (argc<3) {
257 di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n";
258 return 1;
259 }
260 Standard_Boolean getsubchilds = Standard_False;
91322f44 261 if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True;
7fd59977 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; }
265
266 TDF_Label aLabel;
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";
277
278 return 0;
279}
280
281static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
282{
283 if (argc!=4) {
284 di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n";
285 return 1;
286 }
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; }
290
291 TDF_Label aLabel;
292 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
293 TopoDS_Shape aShape;
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();
302
303 return 0;
304}
305
306static Standard_Integer removeComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
307{
308 if (argc!=3) {
309 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
310 return 1;
311 }
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; }
315
316 TDF_Label aLabel;
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);
322 return 0;
323}
324
325static Standard_Integer getReferredShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
326{
327 if (argc!=3) {
328 di<<"Use: "<<argv[0]<<" DocName Label "<<"\n";
329 return 1;
330 }
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; }
334
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);
341
342 TCollection_AsciiString Entry;
343 TDF_Tool::Entry(RootLabel, Entry);
344 //di<<"Label with Shape is ";
345 di << Entry.ToCString();
346 return 0;
347}
348
349static Standard_Integer getTopLevelShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
350{
351 if (argc!=2) {
352 di<<"Use: "<<argv[0]<<" DocName "<<"\n";
353 return 1;
354 }
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; }
358
359 TDF_Label aLabel;
360 TDF_LabelSequence Labels;
361
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() << " ";
372 }
373 }
374 return 0;
375}
376
377static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
378{
379 if (argc <2) {
380 di<<"Use: "<<argv[0]<<" DocName [shape_prefix]"<<"\n";
381 return 1;
382 }
383
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; }
387
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";
393 return 0;
394 }
395
396 if ( argc ==2 ) {
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() << " ";
401 }
402 }
403 else if ( Labels.Length() ==1 ) {
404 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
405 DBRep::Set ( argv[2], S );
406 di << argv[2];
407 }
408 else {
409 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
410 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
411 char string[260];
91322f44 412 Sprintf ( string, "%s_%d", argv[2], i );
7fd59977 413 DBRep::Set ( string, S );
414 di << string << " ";
415 }
416 }
417 return 0;
418}
419
420static Standard_Integer getOneShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
421{
422 if (argc!=3) {
423 di<<"Use: "<<argv[0]<<" shape DocName "<<"\n";
424 return 1;
425 }
426
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; }
430
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";
436 return 0;
437 }
438
439 if ( Labels.Length() ==1 ) {
440 TopoDS_Shape S = STool->GetShape ( Labels.Value(1) );
441 DBRep::Set ( argv[1], S );
442 }
443 else {
444 TopoDS_Compound C;
445 BRep_Builder B;
446 B.MakeCompound ( C );
447 for ( Standard_Integer i = 1; i<= Labels.Length(); i++) {
448 TopoDS_Shape S = STool->GetShape ( Labels.Value(i) );
449 B.Add ( C, S );
450 }
451 DBRep::Set ( argv[1], C );
452 }
453 di << argv[1];
454 return 0;
455}
456
457//=======================================================================
458//function : XDumpLocation
459//purpose : Dump Transformation() of XCAFDoc_Location attribute
460//=======================================================================
461static Standard_Integer XDumpLocation (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
462{
463 if (argc != 3)
464 {
465 di << "Use: " << argv[0] << " Doc Label " << "\n";
466 return 1;
467 }
468 Handle(TDocStd_Document) Doc;
469 DDocStd::GetDocument(argv[1], Doc);
470 if (Doc.IsNull())
471 {
472 di << argv[1] << " is not a document" << "\n";
473 return 1;
474 }
475
476 TDF_Label aLabel;
477 TDF_Tool::Label(Doc->GetData(), argv[2], aLabel);
478
479 Handle(XCAFDoc_Location) aLoc;
480 if (!aLabel.FindAttribute(XCAFDoc_Location::GetID(), aLoc))
481 {
482 di << "Label " << argv[2] << " doesn't contain XCAFDoc_Location attribute" << "\n";
483 return 1;
484 }
485
486 TopLoc_Location aTopLoc = aLoc->Get();
487 gp_Trsf aTrsf = aTopLoc.Transformation();
488
489 di << "Transformation (3 rows * 4 columns matrix):";
490 for (int i = 1; i <= 3; i++) // row number
491 {
492 di << " (";
493 for (int j = 1; j <= 4; j++) // column number
494 {
495 if (j > 1) di << ",";
496 di << TCollection_AsciiString(aTrsf.Value(i,j)).ToCString();
497 }
498 di << ")";
499 }
500
501 return 0;
502}
503
504static Standard_Integer setSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
505{
506 if (argc < 4)
507 {
508 di << "Use: " << argv[0] << " Doc UU_Label NU_Label " << "\n";
509 return 1;
510 }
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; }
514
515 TDF_LabelSequence aLabSeq;
516 for (Standard_Integer i = 3; i <= argc; i++) {
517 TDF_Label L;
518 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
519 if (!L.IsNull())
520 aLabSeq.Append( L );
521 else
522 di << argv[i - 1] << " is null label" << "\n";
523 }
524 if (aLabSeq.Length() < 2) {
525 di << "Error: couldnot set SHUO between on less then 2 labels" << "\n";
526 }
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";
532 return 1;
533 }
534
535 return 0;
536}
537
538static Standard_Integer getSHUOUpperUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
539{
540 if (argc < 3)
541 {
542 di << "Use: " << argv[0] << " Doc NU_Label " << "\n";
543 return 1;
544 }
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; }
548 TDF_Label NL;
549 TDF_Tool::Label(Doc->GetData(), argv[2], NL);
550 if (NL.IsNull()) {
551 di << argv[2] << " is null label" << "\n";
552 return 1;
553 }
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() << " ";
563 }
564 }
565 return 0;
566}
567
568static Standard_Integer getSHUONextUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
569{
570 if (argc < 3)
571 {
572 di << "Use: " << argv[0] << " Doc UU_Label " << "\n";
573 return 1;
574 }
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; }
578 TDF_Label UL;
579 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
580 if (UL.IsNull()) {
581 di << argv[2] << " is null label" << "\n";
582 return 1;
583 }
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() << " ";
593 }
594 }
595 return 0;
596}
597
598static Standard_Integer removeSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
599{
600 if (argc < 3)
601 {
602 di << "Use: " << argv[0] << " Doc SHUOComponent_Label " << "\n";
603 return 1;
604 }
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; }
608 TDF_Label UL;
609 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
610 if (UL.IsNull()) {
611 di << argv[2] << " is null label" << "\n";
612 return 1;
613 }
614 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
615 myAssembly->RemoveSHUO( UL );
616
617 return 0;
618}
619
620static Standard_Integer hasSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
621{
622 if (argc < 3)
623 {
624 di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n";
625 return 1;
626 }
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; }
630 TDF_Label UL;
631 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
632 if (UL.IsNull()) {
633 di << argv[2] << " is null label" << "\n";
634 return 1;
635 }
636 Handle(XCAFDoc_GraphNode) anAttrSHUO;
637 Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
638 if (myAssembly->GetSHUO( UL, anAttrSHUO ))
639 di << 1;
640 else
641 di << 0;
642
643 return 0;
644}
645
646static Standard_Integer getAllSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
647{
648 if (argc < 3)
649 {
650 di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n";
651 return 1;
652 }
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());
657 TDF_Label UL;
658 TDF_Tool::Label(Doc->GetData(), argv[2], UL);
659 if (UL.IsNull()) {
660 di << argv[2] << " is null label" << "\n";
661 return 1;
662 }
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() << " ";
671 }
672 }
673 return 0;
674}
675
676static Standard_Integer findComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
677{
678 if (argc < 3)
679 {
680 di << "Use: " << argv[0] << " Doc shape " << "\n";
681 return 1;
682 }
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());
687 TopoDS_Shape aShape;
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() << " ";
697 }
698 }
699 return 0;
700}
701
702static Standard_Integer getStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
703{
704 if (argc < 4)
705 {
706 di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n";
707 return 1;
708 }
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());
713 TopoDS_Shape aShape;
714 TDF_Label aLabel;
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 );
719
720 if (aShape.IsNull()) {
721 di << "cannot get component" << "\n";
722 return 1;
723 }
724 DBRep::Set ( argv[2], aShape );
725 di << argv[2];
726 return 0;
727}
728
729static Standard_Integer getAllStyledComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
730{
731 if (argc < 4)
732 {
733 di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n";
734 return 1;
735 }
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;
741 TDF_Label aLabel;
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;
747 BRep_Builder B;
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 );
752 }
753 DBRep::Set ( argv[2], aShape );
754 di << argv[2];
755 }
756
757 return 0;
758}
759
760static Standard_Integer findSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
761{
762 if (argc < 4)
763 {
764 di << "Use: " << argv[0] << " Doc labels " << "\n";
765 return 1;
766 }
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++) {
773 TDF_Label L;
774 TDF_Tool::Label(Doc->GetData(), argv[i - 1], L);
775 if (!L.IsNull())
776 aLabSeq.Append( L );
777 else
778 di << argv[i - 1] << " is null label" << "\n";
779 }
780 if (aLabSeq.Length() < 2) {
781 di << "Error: couldnot find SHUO between on less then 2 labels" << "\n";
782 }
783 Handle(XCAFDoc_GraphNode) SHUO;
784 myAssembly->FindSHUO( aLabSeq, SHUO );
785 if (SHUO.IsNull()) {
786 di << "cannot find SHUO" << "\n";
787 return 1;
788 }
789 TCollection_AsciiString Entry;
790 TDF_Tool::Entry( SHUO->Label(), Entry);
791 di << Entry.ToCString() << " ";
792
793 return 0;
794}
795
796static Standard_Integer setStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv)
797{
798 if (argc < 3)
799 {
800 di << "Use: " << argv[0] << " Doc shape " << "\n";
801 return 1;
802 }
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());
807 TopoDS_Shape aShape;
808 aShape = DBRep::Get(argv[2]);
809 if (aShape.IsNull()) {
810 di << "Shape " << argv[2] << " is null" << "\n";
811 return 1;
812 }
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";
817 return 1;
818 }
819 TCollection_AsciiString Entry;
820 TDF_Tool::Entry( aSHUOAttr->Label(), Entry);
821 di << Entry.ToCString() << " ";
822
823 return 0;
824}
825//=======================================================================
826//function : InitCommands
827//purpose :
828//=======================================================================
829
830void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di)
831{
832
833 static Standard_Boolean initactor = Standard_False;
834 if (initactor) return; initactor = Standard_True;
835
836 //=====================================
837 // Work with shapes
838 //=====================================
839
840 Standard_CString g = "XDE shape's commands";
841
842 di.Add ("XAddShape","Doc Shape [makeAssembly = 1]\t: Add shape (or assembly) to Document",
843 __FILE__, addShape, g);
844
845 di.Add ("XNewShape","Doc \t: Create new empty top-level shape",
846 __FILE__, newShape, g);
847
848 di.Add ("XSetShape","Doc Label Shape \t: Set shape at indicated label",
849 __FILE__, setShape, g);
850
851 di.Add ("XGetShape","Result Doc Label \t: Put shape from tree to Result",
852 __FILE__, getShape, g);
853
854 di.Add ("XRemoveShape","Doc Label \t: Remove shape from document",
855 __FILE__, removeShape, g);
856
857 di.Add ("XFindShape","Doc Shape \t: Find and print label with indicated top-level shape",
858 __FILE__, findShape, g);
859
860 di.Add ("XLabelInfo","Doc Label \t: Print information about object at following label",
861 __FILE__, labelInfo, g);
862
863 di.Add ("XGetUsers","Doc Label [withSubChilds(int)] \t: Print number of assemblies that use shape at following label",
864 __FILE__, getUsers, g);
865
866 di.Add ("XNbComponents","Doc Label [withSubChilds(int)] \t: Print number of component of assembly ",
867 __FILE__, nbComponents, g);
868
869 di.Add ("XAddComponent","Doc Label Shape \t: Add component shape to assembly",
870 __FILE__, addComponent, g);
871
872 di.Add ("XRemoveComponent","Doc Label \t: Remove component from components label",
873 __FILE__, removeComponent, g);
874
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);
877
878 di.Add ("XGetTopLevelShapes","Doc \t: Print labels, that contain a top-level shapes",
879 __FILE__, getTopLevelShapes, g);
880
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);
883
884 di.Add ("XGetOneShape","shape Doc \t: Put all free shapes of the Doc into signle DRAW shape",
885 __FILE__, getOneShape, g);
886
887 di.Add ("XDumpLocation","Doc Label \t: Dump Transformation() of XCAFDoc_Location attribute",
888 __FILE__, XDumpLocation, g);
889
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);
892
893 di.Add ("XGetUU_SHUO","Doc NU_Label \t: prints the UpperUsages of indicated NextUsage",
894 __FILE__, getSHUOUpperUsage, g);
895
896 di.Add ("XGetNU_SHUO","Doc UU_Label \t: prints the NextUsages of indicated UpperUsage",
897 __FILE__, getSHUONextUsage, g);
898
899 di.Add ("XRemoveSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
900 __FILE__, removeSHUO, g);
901
902 di.Add ("XIsHasSHUO","Doc SHUO_Label \t: remove SHUO of indicated component",
903 __FILE__, hasSHUO, g);
904
905 di.Add ("XGetAllSHUO","Doc Comp_Label \t: remove SHUO of indicated component",
906 __FILE__, getAllSHUO, g);
907
908 di.Add ("XFindComponent","Doc Shape \t: prints sequence of labels of assembly path",
909 __FILE__, findComponent, g);
910
911 di.Add ("XGetSHUOInstance","Doc res SHUO_Label \t: returns SHUO_styled shape",
912 __FILE__, getStyledComponent, g);
913
914 di.Add ("XGetAllSHUOInstances","Doc res SHUO_Label \t: returns SHUO_styled shapes as compound",
915 __FILE__, getAllStyledComponents, g);
916
917 di.Add ("XFindSHUO","Doc labels of SHUO structure \t: prints label of SHUO that found by labels structure",
918 __FILE__, findSHUO, g);
919
920 di.Add ("XSetInstanceSHUO","Doc shape \t: sets the SHUO structure for indicated component",
921 __FILE__, setStyledComponent, g);
922
923}