7fd59977 |
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> |
5 | |
6 | #include <XDEDRAW_Shapes.ixx> |
7 | |
8 | #include <DBRep.hxx> |
9 | #include <DDocStd.hxx> |
10 | |
11 | #include <TopoDS_Shape.hxx> |
12 | #include <TopoDS_Compound.hxx> |
13 | #include <BRep_Builder.hxx> |
14 | |
15 | #include <gp_Trsf.hxx> |
16 | |
17 | #include <TDF_Tool.hxx> |
18 | #include <TDF_Label.hxx> |
19 | #include <TDF_LabelSequence.hxx> |
20 | #include <TDocStd_Document.hxx> |
21 | |
22 | #include <XCAFDoc_DocumentTool.hxx> |
23 | #include <XCAFDoc_ShapeTool.hxx> |
24 | #include <XCAFDoc_Location.hxx> |
25 | |
26 | #include <TCollection_AsciiString.hxx> |
27 | |
28 | #include <stdio.h> |
29 | #include <XCAFDoc_GraphNode.hxx> |
30 | #include <TDF_AttributeSequence.hxx> |
31 | #include <TopTools_SequenceOfShape.hxx> |
32 | |
33 | //======================================================================= |
34 | // Section: Work with shapes |
35 | //======================================================================= |
36 | |
37 | static Standard_Integer addShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
38 | { |
39 | if (argc<3) { |
40 | di<<"Use: "<<argv[0]<<" DocName Shape [int makeAssembly (1/0)]"<<"\n"; |
41 | return 1; |
42 | } |
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; } |
46 | |
47 | TopoDS_Shape aShape; |
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; |
52 | TDF_Label aLabel; |
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(); |
58 | return 0; |
59 | } |
60 | |
61 | static Standard_Integer newShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
62 | { |
63 | if (argc!=2) { |
64 | di<<"Use: "<<argv[0]<<" DocName "<<"\n"; |
65 | return 1; |
66 | } |
67 | Handle(TDocStd_Document) Doc; |
68 | TDF_Label aLabel; |
69 | DDocStd::GetDocument(argv[1], Doc); |
70 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
71 | |
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(); |
80 | return 0; |
81 | } |
82 | |
83 | static Standard_Integer setShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
84 | { |
85 | if (argc!=4) { |
86 | di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n"; |
87 | return 1; |
88 | } |
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; } |
92 | |
93 | TDF_Label aLabel; |
94 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
95 | TopoDS_Shape aShape; |
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); |
102 | return 0; |
103 | } |
104 | |
105 | static Standard_Integer getShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
106 | { |
107 | if (argc!=4) { |
108 | di<<"Use: "<<argv[0]<<" Result DocName Label"<<"\n"; |
109 | return 1; |
110 | } |
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; } |
114 | |
115 | TDF_Label aLabel; |
116 | TDF_Tool::Label(Doc->GetData(), argv[3], aLabel); |
117 | if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;} |
118 | TopoDS_Shape aShape; |
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); |
125 | |
126 | return 0; |
127 | } |
128 | |
129 | static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
130 | { |
131 | if (argc!=3) { |
132 | di<<"Use: "<<argv[0]<<" DocName Label"<<"\n"; |
133 | return 1; |
134 | } |
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; } |
138 | |
139 | TDF_Label aLabel; |
140 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
141 | if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;} |
142 | TopoDS_Shape aShape; |
143 | // XCAFDoc_ShapeTool myAssembly; |
144 | // myAssembly.Init(Doc); |
145 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
146 | myAssembly->RemoveShape(aLabel); |
147 | |
148 | return 0; |
149 | } |
150 | |
151 | static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
152 | { |
153 | if (argc!=3) { |
154 | di<<"Use: "<<argv[0]<<" DocName Shape"<<"\n"; |
155 | return 1; |
156 | } |
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; } |
160 | |
161 | TDF_Label aLabel; |
162 | TopoDS_Shape aShape; |
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"; |
172 | return 0; |
173 | } |
174 | |
175 | static Standard_Integer labelInfo (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
176 | { |
177 | if (argc!=3) { |
178 | di<<"Use: "<<argv[0]<<" DocName Label "<<"\n"; |
179 | return 1; |
180 | } |
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; } |
184 | |
185 | TDF_Label aLabel; |
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; |
191 | |
192 | if ( myAssembly->IsShape(aLabel) ) { |
193 | //di<<"There are a TopLevelShape"<<"\n"; |
194 | Entry="There are a TopLevelShape"; |
195 | di << Entry.ToCString(); |
196 | } |
197 | if ( myAssembly->IsComponent(aLabel) ) { |
198 | //di<<"There are a Component"<<"\n"; |
199 | Entry="There are a Component"; |
200 | di << Entry.ToCString(); |
201 | } |
202 | if ( myAssembly->IsAssembly(aLabel) ) { |
203 | //di<<"There are an Assembly"<<"\n"; |
204 | Entry="There are an Assembly"; |
205 | di << Entry.ToCString(); |
206 | } |
207 | if ( myAssembly->IsFree(aLabel) ) { |
208 | //di<<"This Shape don't used"<<"\n"; |
209 | Entry="This Shape don't used"; |
210 | di << Entry.ToCString(); |
211 | } |
212 | return 0; |
213 | } |
214 | |
215 | static Standard_Integer getUsers (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
216 | { |
217 | if (argc<3) { |
218 | di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n"; |
219 | return 1; |
220 | } |
221 | Standard_Boolean getsubchilds = Standard_False; |
222 | if ( (argc==4) && ( atoi(argv[3])==1 ) ) getsubchilds = Standard_True; |
223 | |
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; } |
227 | |
228 | TDF_Label aLabel; |
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"; |
236 | return 0; |
237 | } |
238 | |
239 | static Standard_Integer nbComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
240 | { |
241 | if (argc<3) { |
242 | di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n"; |
243 | return 1; |
244 | } |
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; } |
250 | |
251 | TDF_Label aLabel; |
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"; |
262 | |
263 | return 0; |
264 | } |
265 | |
266 | static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
267 | { |
268 | if (argc!=4) { |
269 | di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n"; |
270 | return 1; |
271 | } |
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; } |
275 | |
276 | TDF_Label aLabel; |
277 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
278 | TopoDS_Shape aShape; |
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(); |
287 | |
288 | return 0; |
289 | } |
290 | |
291 | static Standard_Integer removeComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
292 | { |
293 | if (argc!=3) { |
294 | di<<"Use: "<<argv[0]<<" DocName Label "<<"\n"; |
295 | return 1; |
296 | } |
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; } |
300 | |
301 | TDF_Label aLabel; |
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); |
307 | return 0; |
308 | } |
309 | |
310 | static Standard_Integer getReferredShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
311 | { |
312 | if (argc!=3) { |
313 | di<<"Use: "<<argv[0]<<" DocName Label "<<"\n"; |
314 | return 1; |
315 | } |
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; } |
319 | |
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); |
326 | |
327 | TCollection_AsciiString Entry; |
328 | TDF_Tool::Entry(RootLabel, Entry); |
329 | //di<<"Label with Shape is "; |
330 | di << Entry.ToCString(); |
331 | return 0; |
332 | } |
333 | |
334 | static Standard_Integer getTopLevelShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
335 | { |
336 | if (argc!=2) { |
337 | di<<"Use: "<<argv[0]<<" DocName "<<"\n"; |
338 | return 1; |
339 | } |
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; } |
343 | |
344 | TDF_Label aLabel; |
345 | TDF_LabelSequence Labels; |
346 | |
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() << " "; |
357 | } |
358 | } |
359 | return 0; |
360 | } |
361 | |
362 | static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
363 | { |
364 | if (argc <2) { |
365 | di<<"Use: "<<argv[0]<<" DocName [shape_prefix]"<<"\n"; |
366 | return 1; |
367 | } |
368 | |
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; } |
372 | |
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"; |
378 | return 0; |
379 | } |
380 | |
381 | if ( argc ==2 ) { |
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() << " "; |
386 | } |
387 | } |
388 | else if ( Labels.Length() ==1 ) { |
389 | TopoDS_Shape S = STool->GetShape ( Labels.Value(1) ); |
390 | DBRep::Set ( argv[2], S ); |
391 | di << argv[2]; |
392 | } |
393 | else { |
394 | for ( Standard_Integer i = 1; i<= Labels.Length(); i++) { |
395 | TopoDS_Shape S = STool->GetShape ( Labels.Value(i) ); |
396 | char string[260]; |
397 | sprintf ( string, "%s_%d", argv[2], i ); |
398 | DBRep::Set ( string, S ); |
399 | di << string << " "; |
400 | } |
401 | } |
402 | return 0; |
403 | } |
404 | |
405 | static Standard_Integer getOneShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
406 | { |
407 | if (argc!=3) { |
408 | di<<"Use: "<<argv[0]<<" shape DocName "<<"\n"; |
409 | return 1; |
410 | } |
411 | |
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; } |
415 | |
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"; |
421 | return 0; |
422 | } |
423 | |
424 | if ( Labels.Length() ==1 ) { |
425 | TopoDS_Shape S = STool->GetShape ( Labels.Value(1) ); |
426 | DBRep::Set ( argv[1], S ); |
427 | } |
428 | else { |
429 | TopoDS_Compound C; |
430 | BRep_Builder B; |
431 | B.MakeCompound ( C ); |
432 | for ( Standard_Integer i = 1; i<= Labels.Length(); i++) { |
433 | TopoDS_Shape S = STool->GetShape ( Labels.Value(i) ); |
434 | B.Add ( C, S ); |
435 | } |
436 | DBRep::Set ( argv[1], C ); |
437 | } |
438 | di << argv[1]; |
439 | return 0; |
440 | } |
441 | |
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) |
447 | { |
448 | if (argc != 3) |
449 | { |
450 | di << "Use: " << argv[0] << " Doc Label " << "\n"; |
451 | return 1; |
452 | } |
453 | Handle(TDocStd_Document) Doc; |
454 | DDocStd::GetDocument(argv[1], Doc); |
455 | if (Doc.IsNull()) |
456 | { |
457 | di << argv[1] << " is not a document" << "\n"; |
458 | return 1; |
459 | } |
460 | |
461 | TDF_Label aLabel; |
462 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
463 | |
464 | Handle(XCAFDoc_Location) aLoc; |
465 | if (!aLabel.FindAttribute(XCAFDoc_Location::GetID(), aLoc)) |
466 | { |
467 | di << "Label " << argv[2] << " doesn't contain XCAFDoc_Location attribute" << "\n"; |
468 | return 1; |
469 | } |
470 | |
471 | TopLoc_Location aTopLoc = aLoc->Get(); |
472 | gp_Trsf aTrsf = aTopLoc.Transformation(); |
473 | |
474 | di << "Transformation (3 rows * 4 columns matrix):"; |
475 | for (int i = 1; i <= 3; i++) // row number |
476 | { |
477 | di << " ("; |
478 | for (int j = 1; j <= 4; j++) // column number |
479 | { |
480 | if (j > 1) di << ","; |
481 | di << TCollection_AsciiString(aTrsf.Value(i,j)).ToCString(); |
482 | } |
483 | di << ")"; |
484 | } |
485 | |
486 | return 0; |
487 | } |
488 | |
489 | static Standard_Integer setSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
490 | { |
491 | if (argc < 4) |
492 | { |
493 | di << "Use: " << argv[0] << " Doc UU_Label NU_Label " << "\n"; |
494 | return 1; |
495 | } |
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; } |
499 | |
500 | TDF_LabelSequence aLabSeq; |
501 | for (Standard_Integer i = 3; i <= argc; i++) { |
502 | TDF_Label L; |
503 | TDF_Tool::Label(Doc->GetData(), argv[i - 1], L); |
504 | if (!L.IsNull()) |
505 | aLabSeq.Append( L ); |
506 | else |
507 | di << argv[i - 1] << " is null label" << "\n"; |
508 | } |
509 | if (aLabSeq.Length() < 2) { |
510 | di << "Error: couldnot set SHUO between on less then 2 labels" << "\n"; |
511 | } |
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"; |
517 | return 1; |
518 | } |
519 | |
520 | return 0; |
521 | } |
522 | |
523 | static Standard_Integer getSHUOUpperUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
524 | { |
525 | if (argc < 3) |
526 | { |
527 | di << "Use: " << argv[0] << " Doc NU_Label " << "\n"; |
528 | return 1; |
529 | } |
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; } |
533 | TDF_Label NL; |
534 | TDF_Tool::Label(Doc->GetData(), argv[2], NL); |
535 | if (NL.IsNull()) { |
536 | di << argv[2] << " is null label" << "\n"; |
537 | return 1; |
538 | } |
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() << " "; |
548 | } |
549 | } |
550 | return 0; |
551 | } |
552 | |
553 | static Standard_Integer getSHUONextUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
554 | { |
555 | if (argc < 3) |
556 | { |
557 | di << "Use: " << argv[0] << " Doc UU_Label " << "\n"; |
558 | return 1; |
559 | } |
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; } |
563 | TDF_Label UL; |
564 | TDF_Tool::Label(Doc->GetData(), argv[2], UL); |
565 | if (UL.IsNull()) { |
566 | di << argv[2] << " is null label" << "\n"; |
567 | return 1; |
568 | } |
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() << " "; |
578 | } |
579 | } |
580 | return 0; |
581 | } |
582 | |
583 | static Standard_Integer removeSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
584 | { |
585 | if (argc < 3) |
586 | { |
587 | di << "Use: " << argv[0] << " Doc SHUOComponent_Label " << "\n"; |
588 | return 1; |
589 | } |
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; } |
593 | TDF_Label UL; |
594 | TDF_Tool::Label(Doc->GetData(), argv[2], UL); |
595 | if (UL.IsNull()) { |
596 | di << argv[2] << " is null label" << "\n"; |
597 | return 1; |
598 | } |
599 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
600 | myAssembly->RemoveSHUO( UL ); |
601 | |
602 | return 0; |
603 | } |
604 | |
605 | static Standard_Integer hasSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
606 | { |
607 | if (argc < 3) |
608 | { |
609 | di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n"; |
610 | return 1; |
611 | } |
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; } |
615 | TDF_Label UL; |
616 | TDF_Tool::Label(Doc->GetData(), argv[2], UL); |
617 | if (UL.IsNull()) { |
618 | di << argv[2] << " is null label" << "\n"; |
619 | return 1; |
620 | } |
621 | Handle(XCAFDoc_GraphNode) anAttrSHUO; |
622 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
623 | if (myAssembly->GetSHUO( UL, anAttrSHUO )) |
624 | di << 1; |
625 | else |
626 | di << 0; |
627 | |
628 | return 0; |
629 | } |
630 | |
631 | static Standard_Integer getAllSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
632 | { |
633 | if (argc < 3) |
634 | { |
635 | di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n"; |
636 | return 1; |
637 | } |
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()); |
642 | TDF_Label UL; |
643 | TDF_Tool::Label(Doc->GetData(), argv[2], UL); |
644 | if (UL.IsNull()) { |
645 | di << argv[2] << " is null label" << "\n"; |
646 | return 1; |
647 | } |
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() << " "; |
656 | } |
657 | } |
658 | return 0; |
659 | } |
660 | |
661 | static Standard_Integer findComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
662 | { |
663 | if (argc < 3) |
664 | { |
665 | di << "Use: " << argv[0] << " Doc shape " << "\n"; |
666 | return 1; |
667 | } |
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()); |
672 | TopoDS_Shape aShape; |
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() << " "; |
682 | } |
683 | } |
684 | return 0; |
685 | } |
686 | |
687 | static Standard_Integer getStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
688 | { |
689 | if (argc < 4) |
690 | { |
691 | di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n"; |
692 | return 1; |
693 | } |
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()); |
698 | TopoDS_Shape aShape; |
699 | TDF_Label aLabel; |
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 ); |
704 | |
705 | if (aShape.IsNull()) { |
706 | di << "cannot get component" << "\n"; |
707 | return 1; |
708 | } |
709 | DBRep::Set ( argv[2], aShape ); |
710 | di << argv[2]; |
711 | return 0; |
712 | } |
713 | |
714 | static Standard_Integer getAllStyledComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
715 | { |
716 | if (argc < 4) |
717 | { |
718 | di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n"; |
719 | return 1; |
720 | } |
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; |
726 | TDF_Label aLabel; |
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; |
732 | BRep_Builder B; |
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 ); |
737 | } |
738 | DBRep::Set ( argv[2], aShape ); |
739 | di << argv[2]; |
740 | } |
741 | |
742 | return 0; |
743 | } |
744 | |
745 | static Standard_Integer findSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
746 | { |
747 | if (argc < 4) |
748 | { |
749 | di << "Use: " << argv[0] << " Doc labels " << "\n"; |
750 | return 1; |
751 | } |
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++) { |
758 | TDF_Label L; |
759 | TDF_Tool::Label(Doc->GetData(), argv[i - 1], L); |
760 | if (!L.IsNull()) |
761 | aLabSeq.Append( L ); |
762 | else |
763 | di << argv[i - 1] << " is null label" << "\n"; |
764 | } |
765 | if (aLabSeq.Length() < 2) { |
766 | di << "Error: couldnot find SHUO between on less then 2 labels" << "\n"; |
767 | } |
768 | Handle(XCAFDoc_GraphNode) SHUO; |
769 | myAssembly->FindSHUO( aLabSeq, SHUO ); |
770 | if (SHUO.IsNull()) { |
771 | di << "cannot find SHUO" << "\n"; |
772 | return 1; |
773 | } |
774 | TCollection_AsciiString Entry; |
775 | TDF_Tool::Entry( SHUO->Label(), Entry); |
776 | di << Entry.ToCString() << " "; |
777 | |
778 | return 0; |
779 | } |
780 | |
781 | static Standard_Integer setStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
782 | { |
783 | if (argc < 3) |
784 | { |
785 | di << "Use: " << argv[0] << " Doc shape " << "\n"; |
786 | return 1; |
787 | } |
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()); |
792 | TopoDS_Shape aShape; |
793 | aShape = DBRep::Get(argv[2]); |
794 | if (aShape.IsNull()) { |
795 | di << "Shape " << argv[2] << " is null" << "\n"; |
796 | return 1; |
797 | } |
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"; |
802 | return 1; |
803 | } |
804 | TCollection_AsciiString Entry; |
805 | TDF_Tool::Entry( aSHUOAttr->Label(), Entry); |
806 | di << Entry.ToCString() << " "; |
807 | |
808 | return 0; |
809 | } |
810 | //======================================================================= |
811 | //function : InitCommands |
812 | //purpose : |
813 | //======================================================================= |
814 | |
815 | void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di) |
816 | { |
817 | |
818 | static Standard_Boolean initactor = Standard_False; |
819 | if (initactor) return; initactor = Standard_True; |
820 | |
821 | //===================================== |
822 | // Work with shapes |
823 | //===================================== |
824 | |
825 | Standard_CString g = "XDE shape's commands"; |
826 | |
827 | di.Add ("XAddShape","Doc Shape [makeAssembly = 1]\t: Add shape (or assembly) to Document", |
828 | __FILE__, addShape, g); |
829 | |
830 | di.Add ("XNewShape","Doc \t: Create new empty top-level shape", |
831 | __FILE__, newShape, g); |
832 | |
833 | di.Add ("XSetShape","Doc Label Shape \t: Set shape at indicated label", |
834 | __FILE__, setShape, g); |
835 | |
836 | di.Add ("XGetShape","Result Doc Label \t: Put shape from tree to Result", |
837 | __FILE__, getShape, g); |
838 | |
839 | di.Add ("XRemoveShape","Doc Label \t: Remove shape from document", |
840 | __FILE__, removeShape, g); |
841 | |
842 | di.Add ("XFindShape","Doc Shape \t: Find and print label with indicated top-level shape", |
843 | __FILE__, findShape, g); |
844 | |
845 | di.Add ("XLabelInfo","Doc Label \t: Print information about object at following label", |
846 | __FILE__, labelInfo, g); |
847 | |
848 | di.Add ("XGetUsers","Doc Label [withSubChilds(int)] \t: Print number of assemblies that use shape at following label", |
849 | __FILE__, getUsers, g); |
850 | |
851 | di.Add ("XNbComponents","Doc Label [withSubChilds(int)] \t: Print number of component of assembly ", |
852 | __FILE__, nbComponents, g); |
853 | |
854 | di.Add ("XAddComponent","Doc Label Shape \t: Add component shape to assembly", |
855 | __FILE__, addComponent, g); |
856 | |
857 | di.Add ("XRemoveComponent","Doc Label \t: Remove component from components label", |
858 | __FILE__, removeComponent, g); |
859 | |
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); |
862 | |
863 | di.Add ("XGetTopLevelShapes","Doc \t: Print labels, that contain a top-level shapes", |
864 | __FILE__, getTopLevelShapes, g); |
865 | |
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); |
868 | |
869 | di.Add ("XGetOneShape","shape Doc \t: Put all free shapes of the Doc into signle DRAW shape", |
870 | __FILE__, getOneShape, g); |
871 | |
872 | di.Add ("XDumpLocation","Doc Label \t: Dump Transformation() of XCAFDoc_Location attribute", |
873 | __FILE__, XDumpLocation, g); |
874 | |
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); |
877 | |
878 | di.Add ("XGetUU_SHUO","Doc NU_Label \t: prints the UpperUsages of indicated NextUsage", |
879 | __FILE__, getSHUOUpperUsage, g); |
880 | |
881 | di.Add ("XGetNU_SHUO","Doc UU_Label \t: prints the NextUsages of indicated UpperUsage", |
882 | __FILE__, getSHUONextUsage, g); |
883 | |
884 | di.Add ("XRemoveSHUO","Doc SHUO_Label \t: remove SHUO of indicated component", |
885 | __FILE__, removeSHUO, g); |
886 | |
887 | di.Add ("XIsHasSHUO","Doc SHUO_Label \t: remove SHUO of indicated component", |
888 | __FILE__, hasSHUO, g); |
889 | |
890 | di.Add ("XGetAllSHUO","Doc Comp_Label \t: remove SHUO of indicated component", |
891 | __FILE__, getAllSHUO, g); |
892 | |
893 | di.Add ("XFindComponent","Doc Shape \t: prints sequence of labels of assembly path", |
894 | __FILE__, findComponent, g); |
895 | |
896 | di.Add ("XGetSHUOInstance","Doc res SHUO_Label \t: returns SHUO_styled shape", |
897 | __FILE__, getStyledComponent, g); |
898 | |
899 | di.Add ("XGetAllSHUOInstances","Doc res SHUO_Label \t: returns SHUO_styled shapes as compound", |
900 | __FILE__, getAllStyledComponents, g); |
901 | |
902 | di.Add ("XFindSHUO","Doc labels of SHUO structure \t: prints label of SHUO that found by labels structure", |
903 | __FILE__, findSHUO, g); |
904 | |
905 | di.Add ("XSetInstanceSHUO","Doc shape \t: sets the SHUO structure for indicated component", |
906 | __FILE__, setStyledComponent, g); |
907 | |
908 | } |