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 | // |
d5f74e42 |
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 |
973c2be1 |
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 | |
7fd59977 |
16 | |
42cf5bc1 |
17 | #include <BRep_Builder.hxx> |
7fd59977 |
18 | #include <DBRep.hxx> |
19 | #include <DDocStd.hxx> |
42cf5bc1 |
20 | #include <Draw.hxx> |
7fd59977 |
21 | #include <gp_Trsf.hxx> |
42cf5bc1 |
22 | #include <TCollection_AsciiString.hxx> |
23 | #include <TDF_AttributeSequence.hxx> |
7fd59977 |
24 | #include <TDF_Label.hxx> |
25 | #include <TDF_LabelSequence.hxx> |
42cf5bc1 |
26 | #include <TDF_Tool.hxx> |
7fd59977 |
27 | #include <TDocStd_Document.hxx> |
42cf5bc1 |
28 | #include <TopoDS_Compound.hxx> |
29 | #include <TopoDS_Shape.hxx> |
30 | #include <TopTools_SequenceOfShape.hxx> |
7fd59977 |
31 | #include <XCAFDoc_DocumentTool.hxx> |
42cf5bc1 |
32 | #include <XCAFDoc_GraphNode.hxx> |
7fd59977 |
33 | #include <XCAFDoc_Location.hxx> |
42cf5bc1 |
34 | #include <XCAFDoc_ShapeTool.hxx> |
35 | #include <XDEDRAW_Shapes.hxx> |
7fd59977 |
36 | |
37 | #include <stdio.h> |
7fd59977 |
38 | //======================================================================= |
39 | // Section: Work with shapes |
40 | //======================================================================= |
7fd59977 |
41 | static Standard_Integer addShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
42 | { |
43 | if (argc<3) { |
44 | di<<"Use: "<<argv[0]<<" DocName Shape [int makeAssembly (1/0)]"<<"\n"; |
45 | return 1; |
46 | } |
47 | Handle(TDocStd_Document) Doc; |
48 | DDocStd::GetDocument(argv[1], Doc); |
49 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
50 | |
51 | TopoDS_Shape aShape; |
52 | aShape = DBRep::Get(argv[2]); |
53 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
54 | Standard_Boolean makeAssembly = Standard_True; |
91322f44 |
55 | if ( argc==4 && Draw::Atoi(argv[3]) == 0 ) makeAssembly = Standard_False; |
7fd59977 |
56 | TDF_Label aLabel; |
57 | aLabel = myAssembly->AddShape(aShape, makeAssembly); |
58 | if (aLabel.IsNull()) di<<"Null Label"<<"\n"; |
59 | TCollection_AsciiString Entry; |
60 | TDF_Tool::Entry(aLabel, Entry); |
61 | di << Entry.ToCString(); |
62 | return 0; |
63 | } |
64 | |
65 | static Standard_Integer newShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
66 | { |
67 | if (argc!=2) { |
68 | di<<"Use: "<<argv[0]<<" DocName "<<"\n"; |
69 | return 1; |
70 | } |
71 | Handle(TDocStd_Document) Doc; |
72 | TDF_Label aLabel; |
73 | DDocStd::GetDocument(argv[1], Doc); |
74 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
75 | |
76 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
77 | //XCAFDoc_ShapeTool myAssembly; |
78 | // myAssembly.Init(Doc); |
79 | aLabel=myAssembly->NewShape(); |
80 | // di<<"New Shape at ChildTag"<<aLabel.Tag()<<"\n"; |
81 | TCollection_AsciiString Entry; |
82 | TDF_Tool::Entry(aLabel, Entry); |
83 | di << Entry.ToCString(); |
84 | return 0; |
85 | } |
86 | |
87 | static Standard_Integer setShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
88 | { |
89 | if (argc!=4) { |
90 | di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n"; |
91 | return 1; |
92 | } |
93 | Handle(TDocStd_Document) Doc; |
94 | DDocStd::GetDocument(argv[1], Doc); |
95 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
96 | |
97 | TDF_Label aLabel; |
98 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
99 | TopoDS_Shape aShape; |
100 | // if (aLabel.IsNull()) di<<"Null Label"<<"\n"; |
101 | aShape = DBRep::Get(argv[3]); |
102 | // XCAFDoc_ShapeTool myAssembly; |
103 | // myAssembly.Init(Doc); |
104 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
e2df4541 |
105 | if( !myAssembly->IsAssembly(aLabel)) |
106 | myAssembly->SetShape(aLabel, aShape); |
7fd59977 |
107 | return 0; |
108 | } |
109 | |
110 | static Standard_Integer getShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
111 | { |
112 | if (argc!=4) { |
113 | di<<"Use: "<<argv[0]<<" Result DocName Label"<<"\n"; |
114 | return 1; |
115 | } |
116 | Handle(TDocStd_Document) Doc; |
117 | DDocStd::GetDocument(argv[2], Doc); |
118 | if ( Doc.IsNull() ) { di << argv[2] << " is not a document" << "\n"; return 1; } |
119 | |
120 | TDF_Label aLabel; |
121 | TDF_Tool::Label(Doc->GetData(), argv[3], aLabel); |
122 | if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;} |
123 | TopoDS_Shape aShape; |
124 | // XCAFDoc_ShapeTool myAssembly; |
125 | // myAssembly.Init(Doc); |
126 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
127 | aShape = myAssembly->GetShape(aLabel); |
128 | Standard_CString name1 = argv[1]; |
129 | DBRep::Set(name1, aShape); |
130 | |
131 | return 0; |
132 | } |
133 | |
134 | static Standard_Integer removeShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
135 | { |
a7aa1465 |
136 | if (argc != 3 && argc != 4) |
137 | { |
138 | di<<"Use: "<<argv[0]<<" DocName Label [int removeCompletely (1/0)]"<<"\n"; |
7fd59977 |
139 | return 1; |
140 | } |
141 | Handle(TDocStd_Document) Doc; |
142 | DDocStd::GetDocument(argv[1], Doc); |
143 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
144 | |
145 | TDF_Label aLabel; |
146 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
147 | if (aLabel.IsNull()) {di<<"No such Label"<<"\n"; return 1;} |
148 | TopoDS_Shape aShape; |
149 | // XCAFDoc_ShapeTool myAssembly; |
150 | // myAssembly.Init(Doc); |
151 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
a7aa1465 |
152 | Standard_Boolean removeCompletely = Standard_True; |
91322f44 |
153 | if ( argc == 4 && Draw::Atoi(argv[3]) == 0 ) |
a7aa1465 |
154 | removeCompletely = Standard_False; |
155 | myAssembly->RemoveShape(aLabel, removeCompletely); |
7fd59977 |
156 | |
157 | return 0; |
158 | } |
159 | |
160 | static Standard_Integer findShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
161 | { |
162 | if (argc!=3) { |
163 | di<<"Use: "<<argv[0]<<" DocName Shape"<<"\n"; |
164 | return 1; |
165 | } |
166 | Handle(TDocStd_Document) Doc; |
167 | DDocStd::GetDocument(argv[1], Doc); |
168 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
169 | |
170 | TDF_Label aLabel; |
171 | TopoDS_Shape aShape; |
172 | aShape = DBRep::Get(argv[2]); |
173 | // XCAFDoc_ShapeTool myAssembly; |
174 | // myAssembly.Init(Doc); |
175 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
176 | aLabel = myAssembly->FindShape(aShape); |
177 | TCollection_AsciiString Entry; |
178 | TDF_Tool::Entry(aLabel, Entry); |
179 | di << Entry.ToCString(); |
180 | //di<<"Label with Shape is "<<Entry<<"\n"; |
181 | return 0; |
182 | } |
183 | |
184 | static Standard_Integer labelInfo (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
185 | { |
186 | if (argc!=3) { |
187 | di<<"Use: "<<argv[0]<<" DocName Label "<<"\n"; |
188 | return 1; |
189 | } |
190 | Handle(TDocStd_Document) Doc; |
191 | DDocStd::GetDocument(argv[1], Doc); |
192 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
193 | |
194 | TDF_Label aLabel; |
195 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
196 | // XCAFDoc_ShapeTool myAssembly; |
197 | // myAssembly.Init(Doc); |
198 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
199 | TCollection_AsciiString Entry; |
200 | |
201 | if ( myAssembly->IsShape(aLabel) ) { |
202 | //di<<"There are a TopLevelShape"<<"\n"; |
203 | Entry="There are a TopLevelShape"; |
204 | di << Entry.ToCString(); |
205 | } |
206 | if ( myAssembly->IsComponent(aLabel) ) { |
207 | //di<<"There are a Component"<<"\n"; |
208 | Entry="There are a Component"; |
209 | di << Entry.ToCString(); |
210 | } |
211 | if ( myAssembly->IsAssembly(aLabel) ) { |
212 | //di<<"There are an Assembly"<<"\n"; |
213 | Entry="There are an Assembly"; |
214 | di << Entry.ToCString(); |
215 | } |
216 | if ( myAssembly->IsFree(aLabel) ) { |
217 | //di<<"This Shape don't used"<<"\n"; |
218 | Entry="This Shape don't used"; |
219 | di << Entry.ToCString(); |
220 | } |
221 | return 0; |
222 | } |
223 | |
224 | static Standard_Integer getUsers (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
225 | { |
226 | if (argc<3) { |
227 | di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n"; |
228 | return 1; |
229 | } |
230 | Standard_Boolean getsubchilds = Standard_False; |
91322f44 |
231 | if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True; |
7fd59977 |
232 | |
233 | Handle(TDocStd_Document) Doc; |
234 | DDocStd::GetDocument(argv[1], Doc); |
235 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
236 | |
237 | TDF_Label aLabel; |
238 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
239 | TDF_LabelSequence labseq; |
240 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
241 | TCollection_AsciiString Entry; |
242 | Entry=myAssembly->GetUsers(aLabel, labseq, getsubchilds); |
243 | di << Entry.ToCString(); |
244 | //di<<myAssembly->GetUsers(aLabel, labseq, getsubchilds)<<" assemblies use this component"<<"\n"; |
245 | return 0; |
246 | } |
247 | |
248 | static Standard_Integer nbComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
249 | { |
250 | if (argc<3) { |
251 | di<<"Use: "<<argv[0]<<" Doc Label [withSubChilds(int)]"<<"\n"; |
252 | return 1; |
253 | } |
254 | Standard_Boolean getsubchilds = Standard_False; |
91322f44 |
255 | if ( (argc==4) && ( Draw::Atoi(argv[3])==1 ) ) getsubchilds = Standard_True; |
7fd59977 |
256 | Handle(TDocStd_Document) Doc; |
257 | DDocStd::GetDocument(argv[1], Doc); |
258 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
259 | |
260 | TDF_Label aLabel; |
261 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
262 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
263 | // XCAFDoc_ShapeTool myAssembly-> |
264 | // myAssembly->Init(Doc); |
265 | //di<<"This assembly has "; |
266 | TCollection_AsciiString Entry; |
267 | Entry=myAssembly->NbComponents( aLabel, getsubchilds); |
268 | di << Entry.ToCString(); |
269 | //di<<" components"<<"\n"; |
270 | //di<<"This assembly has "<<myAssembly->NbComponents( aLabel, getsubchilds )<<" components"<<"\n"; |
271 | |
272 | return 0; |
273 | } |
274 | |
275 | static Standard_Integer addComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
276 | { |
277 | if (argc!=4) { |
278 | di<<"Use: "<<argv[0]<<" DocName Label Shape "<<"\n"; |
279 | return 1; |
280 | } |
281 | Handle(TDocStd_Document) Doc; |
282 | DDocStd::GetDocument(argv[1], Doc); |
283 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
284 | |
285 | TDF_Label aLabel; |
286 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
287 | TopoDS_Shape aShape; |
288 | aShape = DBRep::Get(argv[3]); |
289 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
290 | // XCAFDoc_ShapeTool myAssembly-> |
291 | // myAssembly->Init(Doc); |
292 | myAssembly->AddComponent(aLabel, aShape); |
293 | TCollection_AsciiString Entry; |
294 | TDF_Tool::Entry(aLabel, Entry); |
295 | di << Entry.ToCString(); |
296 | |
297 | return 0; |
298 | } |
299 | |
300 | static Standard_Integer removeComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
301 | { |
302 | if (argc!=3) { |
303 | di<<"Use: "<<argv[0]<<" DocName Label "<<"\n"; |
304 | return 1; |
305 | } |
306 | Handle(TDocStd_Document) Doc; |
307 | DDocStd::GetDocument(argv[1], Doc); |
308 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
309 | |
310 | TDF_Label aLabel; |
311 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
312 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
313 | // XCAFDoc_ShapeTool myAssembly-> |
314 | // myAssembly->Init(Doc); |
315 | myAssembly->RemoveComponent(aLabel); |
316 | return 0; |
317 | } |
318 | |
319 | static Standard_Integer getReferredShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
320 | { |
321 | if (argc!=3) { |
322 | di<<"Use: "<<argv[0]<<" DocName Label "<<"\n"; |
323 | return 1; |
324 | } |
325 | Handle(TDocStd_Document) Doc; |
326 | DDocStd::GetDocument(argv[1], Doc); |
327 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
328 | |
329 | TDF_Label aLabel, RootLabel; |
330 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
331 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
332 | // XCAFDoc_ShapeTool myAssembly-> |
333 | // myAssembly->Init(Doc); |
334 | myAssembly->GetReferredShape(aLabel, RootLabel); |
335 | |
336 | TCollection_AsciiString Entry; |
337 | TDF_Tool::Entry(RootLabel, Entry); |
338 | //di<<"Label with Shape is "; |
339 | di << Entry.ToCString(); |
340 | return 0; |
341 | } |
342 | |
343 | static Standard_Integer getTopLevelShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
344 | { |
345 | if (argc!=2) { |
346 | di<<"Use: "<<argv[0]<<" DocName "<<"\n"; |
347 | return 1; |
348 | } |
349 | Handle(TDocStd_Document) Doc; |
350 | DDocStd::GetDocument(argv[1], Doc); |
351 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
352 | |
353 | TDF_Label aLabel; |
354 | TDF_LabelSequence Labels; |
355 | |
356 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
357 | // XCAFDoc_ShapeTool myAssembly-> |
358 | // myAssembly->Init(Doc); |
359 | myAssembly->GetShapes(Labels); |
360 | TCollection_AsciiString Entry; |
361 | if (Labels.Length() >= 1) { |
362 | for ( Standard_Integer i = 1; i<= Labels.Length(); i++) { |
363 | aLabel = Labels.Value(i); |
364 | TDF_Tool::Entry( aLabel, Entry); |
365 | di << Entry.ToCString() << " "; |
366 | } |
367 | } |
368 | return 0; |
369 | } |
370 | |
371 | static Standard_Integer getFreeShapes (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
372 | { |
373 | if (argc <2) { |
374 | di<<"Use: "<<argv[0]<<" DocName [shape_prefix]"<<"\n"; |
375 | return 1; |
376 | } |
377 | |
378 | Handle(TDocStd_Document) Doc; |
379 | DDocStd::GetDocument(argv[1], Doc); |
380 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
381 | |
382 | TDF_LabelSequence Labels; |
383 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
384 | STool->GetFreeShapes(Labels); |
385 | if ( Labels.Length() <=0 ) { |
386 | di << "Document " << argv[1] << " contain no shapes" << "\n"; |
387 | return 0; |
388 | } |
389 | |
390 | if ( argc ==2 ) { |
391 | for ( Standard_Integer i = 1; i<= Labels.Length(); i++) { |
392 | TCollection_AsciiString Entry; |
393 | TDF_Tool::Entry( Labels.Value(i), Entry); |
394 | di << Entry.ToCString() << " "; |
395 | } |
396 | } |
397 | else if ( Labels.Length() ==1 ) { |
398 | TopoDS_Shape S = STool->GetShape ( Labels.Value(1) ); |
399 | DBRep::Set ( argv[2], S ); |
400 | di << argv[2]; |
401 | } |
402 | else { |
403 | for ( Standard_Integer i = 1; i<= Labels.Length(); i++) { |
404 | TopoDS_Shape S = STool->GetShape ( Labels.Value(i) ); |
405 | char string[260]; |
91322f44 |
406 | Sprintf ( string, "%s_%d", argv[2], i ); |
7fd59977 |
407 | DBRep::Set ( string, S ); |
408 | di << string << " "; |
409 | } |
410 | } |
411 | return 0; |
412 | } |
413 | |
414 | static Standard_Integer getOneShape (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
415 | { |
416 | if (argc!=3) { |
417 | di<<"Use: "<<argv[0]<<" shape DocName "<<"\n"; |
418 | return 1; |
419 | } |
420 | |
421 | Handle(TDocStd_Document) Doc; |
422 | DDocStd::GetDocument(argv[2], Doc); |
423 | if ( Doc.IsNull() ) { di << argv[2] << " is not a document" << "\n"; return 1; } |
424 | |
425 | TDF_LabelSequence Labels; |
426 | Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
427 | STool->GetFreeShapes(Labels); |
428 | if ( Labels.Length() <=0 ) { |
429 | di << "Document " << argv[2] << " contain no shapes" << "\n"; |
430 | return 0; |
431 | } |
432 | |
433 | if ( Labels.Length() ==1 ) { |
434 | TopoDS_Shape S = STool->GetShape ( Labels.Value(1) ); |
435 | DBRep::Set ( argv[1], S ); |
436 | } |
437 | else { |
438 | TopoDS_Compound C; |
439 | BRep_Builder B; |
440 | B.MakeCompound ( C ); |
441 | for ( Standard_Integer i = 1; i<= Labels.Length(); i++) { |
442 | TopoDS_Shape S = STool->GetShape ( Labels.Value(i) ); |
443 | B.Add ( C, S ); |
444 | } |
445 | DBRep::Set ( argv[1], C ); |
446 | } |
447 | di << argv[1]; |
448 | return 0; |
449 | } |
450 | |
451 | //======================================================================= |
452 | //function : XDumpLocation |
453 | //purpose : Dump Transformation() of XCAFDoc_Location attribute |
454 | //======================================================================= |
455 | static Standard_Integer XDumpLocation (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
456 | { |
457 | if (argc != 3) |
458 | { |
459 | di << "Use: " << argv[0] << " Doc Label " << "\n"; |
460 | return 1; |
461 | } |
462 | Handle(TDocStd_Document) Doc; |
463 | DDocStd::GetDocument(argv[1], Doc); |
464 | if (Doc.IsNull()) |
465 | { |
466 | di << argv[1] << " is not a document" << "\n"; |
467 | return 1; |
468 | } |
469 | |
470 | TDF_Label aLabel; |
471 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
472 | |
473 | Handle(XCAFDoc_Location) aLoc; |
474 | if (!aLabel.FindAttribute(XCAFDoc_Location::GetID(), aLoc)) |
475 | { |
476 | di << "Label " << argv[2] << " doesn't contain XCAFDoc_Location attribute" << "\n"; |
477 | return 1; |
478 | } |
479 | |
480 | TopLoc_Location aTopLoc = aLoc->Get(); |
481 | gp_Trsf aTrsf = aTopLoc.Transformation(); |
482 | |
483 | di << "Transformation (3 rows * 4 columns matrix):"; |
484 | for (int i = 1; i <= 3; i++) // row number |
485 | { |
486 | di << " ("; |
487 | for (int j = 1; j <= 4; j++) // column number |
488 | { |
489 | if (j > 1) di << ","; |
490 | di << TCollection_AsciiString(aTrsf.Value(i,j)).ToCString(); |
491 | } |
492 | di << ")"; |
493 | } |
494 | |
495 | return 0; |
496 | } |
497 | |
498 | static Standard_Integer setSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
499 | { |
500 | if (argc < 4) |
501 | { |
502 | di << "Use: " << argv[0] << " Doc UU_Label NU_Label " << "\n"; |
503 | return 1; |
504 | } |
505 | Handle(TDocStd_Document) Doc; |
506 | DDocStd::GetDocument(argv[1], Doc); |
507 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
508 | |
509 | TDF_LabelSequence aLabSeq; |
510 | for (Standard_Integer i = 3; i <= argc; i++) { |
511 | TDF_Label L; |
512 | TDF_Tool::Label(Doc->GetData(), argv[i - 1], L); |
513 | if (!L.IsNull()) |
514 | aLabSeq.Append( L ); |
515 | else |
516 | di << argv[i - 1] << " is null label" << "\n"; |
517 | } |
518 | if (aLabSeq.Length() < 2) { |
519 | di << "Error: couldnot set SHUO between on less then 2 labels" << "\n"; |
520 | } |
521 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
522 | Handle(XCAFDoc_GraphNode) aMainSHUO; |
523 | myAssembly->SetSHUO( aLabSeq, aMainSHUO ); |
524 | if (aMainSHUO.IsNull()) { |
525 | di << "Error: cannot set the SHUO" << "\n"; |
526 | return 1; |
527 | } |
528 | |
529 | return 0; |
530 | } |
531 | |
532 | static Standard_Integer getSHUOUpperUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
533 | { |
534 | if (argc < 3) |
535 | { |
536 | di << "Use: " << argv[0] << " Doc NU_Label " << "\n"; |
537 | return 1; |
538 | } |
539 | Handle(TDocStd_Document) Doc; |
540 | DDocStd::GetDocument(argv[1], Doc); |
541 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
542 | TDF_Label NL; |
543 | TDF_Tool::Label(Doc->GetData(), argv[2], NL); |
544 | if (NL.IsNull()) { |
545 | di << argv[2] << " is null label" << "\n"; |
546 | return 1; |
547 | } |
548 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
549 | TDF_LabelSequence labseq; |
550 | myAssembly->GetSHUOUpperUsage( NL, labseq ); |
551 | TCollection_AsciiString Entry; |
552 | if (labseq.Length() >= 1) { |
553 | for ( Standard_Integer i = 1; i<= labseq.Length(); i++) { |
554 | TDF_Label aLabel = labseq.Value(i); |
555 | TDF_Tool::Entry( aLabel, Entry); |
556 | di << Entry.ToCString() << " "; |
557 | } |
558 | } |
559 | return 0; |
560 | } |
561 | |
562 | static Standard_Integer getSHUONextUsage (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
563 | { |
564 | if (argc < 3) |
565 | { |
566 | di << "Use: " << argv[0] << " Doc UU_Label " << "\n"; |
567 | return 1; |
568 | } |
569 | Handle(TDocStd_Document) Doc; |
570 | DDocStd::GetDocument(argv[1], Doc); |
571 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
572 | TDF_Label UL; |
573 | TDF_Tool::Label(Doc->GetData(), argv[2], UL); |
574 | if (UL.IsNull()) { |
575 | di << argv[2] << " is null label" << "\n"; |
576 | return 1; |
577 | } |
578 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
579 | TDF_LabelSequence labseq; |
580 | myAssembly->GetSHUONextUsage( UL, labseq ); |
581 | TCollection_AsciiString Entry; |
582 | if (labseq.Length() >= 1) { |
583 | for ( Standard_Integer i = 1; i<= labseq.Length(); i++) { |
584 | TDF_Label aLabel = labseq.Value(i); |
585 | TDF_Tool::Entry( aLabel, Entry); |
586 | di << Entry.ToCString() << " "; |
587 | } |
588 | } |
589 | return 0; |
590 | } |
591 | |
592 | static Standard_Integer removeSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
593 | { |
594 | if (argc < 3) |
595 | { |
596 | di << "Use: " << argv[0] << " Doc SHUOComponent_Label " << "\n"; |
597 | return 1; |
598 | } |
599 | Handle(TDocStd_Document) Doc; |
600 | DDocStd::GetDocument(argv[1], Doc); |
601 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
602 | TDF_Label UL; |
603 | TDF_Tool::Label(Doc->GetData(), argv[2], UL); |
604 | if (UL.IsNull()) { |
605 | di << argv[2] << " is null label" << "\n"; |
606 | return 1; |
607 | } |
608 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
609 | myAssembly->RemoveSHUO( UL ); |
610 | |
611 | return 0; |
612 | } |
613 | |
614 | static Standard_Integer hasSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
615 | { |
616 | if (argc < 3) |
617 | { |
618 | di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n"; |
619 | return 1; |
620 | } |
621 | Handle(TDocStd_Document) Doc; |
622 | DDocStd::GetDocument(argv[1], Doc); |
623 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
624 | TDF_Label UL; |
625 | TDF_Tool::Label(Doc->GetData(), argv[2], UL); |
626 | if (UL.IsNull()) { |
627 | di << argv[2] << " is null label" << "\n"; |
628 | return 1; |
629 | } |
630 | Handle(XCAFDoc_GraphNode) anAttrSHUO; |
631 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
632 | if (myAssembly->GetSHUO( UL, anAttrSHUO )) |
633 | di << 1; |
634 | else |
635 | di << 0; |
636 | |
637 | return 0; |
638 | } |
639 | |
640 | static Standard_Integer getAllSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
641 | { |
642 | if (argc < 3) |
643 | { |
644 | di << "Use: " << argv[0] << " Doc SHUO_Label " << "\n"; |
645 | return 1; |
646 | } |
647 | Handle(TDocStd_Document) Doc; |
648 | DDocStd::GetDocument(argv[1], Doc); |
649 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
650 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
651 | TDF_Label UL; |
652 | TDF_Tool::Label(Doc->GetData(), argv[2], UL); |
653 | if (UL.IsNull()) { |
654 | di << argv[2] << " is null label" << "\n"; |
655 | return 1; |
656 | } |
657 | TDF_AttributeSequence SHUOAttrs; |
658 | myAssembly->GetAllComponentSHUO( UL, SHUOAttrs ); |
659 | TCollection_AsciiString Entry; |
660 | if (SHUOAttrs.Length() >= 1) { |
661 | for ( Standard_Integer i = 1; i<= SHUOAttrs.Length(); i++) { |
662 | TDF_Label aLabel = SHUOAttrs.Value(i)->Label(); |
663 | TDF_Tool::Entry( aLabel, Entry); |
664 | di << Entry.ToCString() << " "; |
665 | } |
666 | } |
667 | return 0; |
668 | } |
669 | |
670 | static Standard_Integer findComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
671 | { |
672 | if (argc < 3) |
673 | { |
674 | di << "Use: " << argv[0] << " Doc shape " << "\n"; |
675 | return 1; |
676 | } |
677 | Handle(TDocStd_Document) Doc; |
678 | DDocStd::GetDocument(argv[1], Doc); |
679 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
680 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
681 | TopoDS_Shape aShape; |
682 | aShape = DBRep::Get(argv[2]); |
683 | TDF_LabelSequence labseq; |
684 | myAssembly->FindComponent( aShape, labseq ); |
685 | TCollection_AsciiString Entry; |
686 | if (labseq.Length() >= 1) { |
687 | for ( Standard_Integer i = 1; i<= labseq.Length(); i++) { |
688 | TDF_Label aLabel = labseq.Value(i); |
689 | TDF_Tool::Entry( aLabel, Entry); |
690 | di << Entry.ToCString() << " "; |
691 | } |
692 | } |
693 | return 0; |
694 | } |
695 | |
696 | static Standard_Integer getStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
697 | { |
698 | if (argc < 4) |
699 | { |
700 | di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n"; |
701 | return 1; |
702 | } |
703 | Handle(TDocStd_Document) Doc; |
704 | DDocStd::GetDocument(argv[1], Doc); |
705 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
706 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
707 | TopoDS_Shape aShape; |
708 | TDF_Label aLabel; |
709 | TDF_Tool::Label(Doc->GetData(), argv[3], aLabel); |
710 | Handle(XCAFDoc_GraphNode) SHUO; |
711 | if (myAssembly->GetSHUO( aLabel, SHUO )) |
712 | aShape = myAssembly->GetSHUOInstance( SHUO ); |
713 | |
714 | if (aShape.IsNull()) { |
715 | di << "cannot get component" << "\n"; |
716 | return 1; |
717 | } |
718 | DBRep::Set ( argv[2], aShape ); |
719 | di << argv[2]; |
720 | return 0; |
721 | } |
722 | |
723 | static Standard_Integer getAllStyledComponents (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
724 | { |
725 | if (argc < 4) |
726 | { |
727 | di << "Use: " << argv[0] << " Doc res SHUO_label " << "\n"; |
728 | return 1; |
729 | } |
730 | Handle(TDocStd_Document) Doc; |
731 | DDocStd::GetDocument(argv[1], Doc); |
732 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
733 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
734 | TopTools_SequenceOfShape aShapes; |
735 | TDF_Label aLabel; |
736 | TDF_Tool::Label(Doc->GetData(), argv[3], aLabel); |
737 | Handle(XCAFDoc_GraphNode) SHUO; |
738 | if (myAssembly->GetSHUO( aLabel, SHUO )) |
739 | if (myAssembly->GetAllSHUOInstances(SHUO, aShapes)) { |
740 | TopoDS_Compound aShape; |
741 | BRep_Builder B; |
742 | B.MakeCompound(aShape); |
743 | for (Standard_Integer jj = 1; jj <= aShapes.Length(); jj++) { |
744 | TopoDS_Shape aCurShape = aShapes.Value(jj); |
745 | B.Add( aShape, aCurShape ); |
746 | } |
747 | DBRep::Set ( argv[2], aShape ); |
748 | di << argv[2]; |
749 | } |
750 | |
751 | return 0; |
752 | } |
753 | |
754 | static Standard_Integer findSHUO (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
755 | { |
756 | if (argc < 4) |
757 | { |
758 | di << "Use: " << argv[0] << " Doc labels " << "\n"; |
759 | return 1; |
760 | } |
761 | Handle(TDocStd_Document) Doc; |
762 | DDocStd::GetDocument(argv[1], Doc); |
763 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
764 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
765 | TDF_LabelSequence aLabSeq; |
766 | for (Standard_Integer i = 3; i <= argc; i++) { |
767 | TDF_Label L; |
768 | TDF_Tool::Label(Doc->GetData(), argv[i - 1], L); |
769 | if (!L.IsNull()) |
770 | aLabSeq.Append( L ); |
771 | else |
772 | di << argv[i - 1] << " is null label" << "\n"; |
773 | } |
774 | if (aLabSeq.Length() < 2) { |
775 | di << "Error: couldnot find SHUO between on less then 2 labels" << "\n"; |
776 | } |
777 | Handle(XCAFDoc_GraphNode) SHUO; |
778 | myAssembly->FindSHUO( aLabSeq, SHUO ); |
779 | if (SHUO.IsNull()) { |
780 | di << "cannot find SHUO" << "\n"; |
781 | return 1; |
782 | } |
783 | TCollection_AsciiString Entry; |
784 | TDF_Tool::Entry( SHUO->Label(), Entry); |
785 | di << Entry.ToCString() << " "; |
786 | |
787 | return 0; |
788 | } |
789 | |
790 | static Standard_Integer setStyledComponent (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
791 | { |
792 | if (argc < 3) |
793 | { |
794 | di << "Use: " << argv[0] << " Doc shape " << "\n"; |
795 | return 1; |
796 | } |
797 | Handle(TDocStd_Document) Doc; |
798 | DDocStd::GetDocument(argv[1], Doc); |
799 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document" << "\n"; return 1; } |
800 | Handle(XCAFDoc_ShapeTool) myAssembly = XCAFDoc_DocumentTool::ShapeTool(Doc->Main()); |
801 | TopoDS_Shape aShape; |
802 | aShape = DBRep::Get(argv[2]); |
803 | if (aShape.IsNull()) { |
804 | di << "Shape " << argv[2] << " is null" << "\n"; |
805 | return 1; |
806 | } |
807 | Handle(XCAFDoc_GraphNode) aSHUOAttr; |
808 | aSHUOAttr = myAssembly->SetInstanceSHUO( aShape ); |
809 | if (aSHUOAttr.IsNull()) { |
810 | di << "Error: cannot set a SHUO structure for indicated component" << "\n"; |
811 | return 1; |
812 | } |
813 | TCollection_AsciiString Entry; |
814 | TDF_Tool::Entry( aSHUOAttr->Label(), Entry); |
815 | di << Entry.ToCString() << " "; |
816 | |
817 | return 0; |
818 | } |
819 | //======================================================================= |
820 | //function : InitCommands |
821 | //purpose : |
822 | //======================================================================= |
823 | |
824 | void XDEDRAW_Shapes::InitCommands(Draw_Interpretor& di) |
825 | { |
826 | |
827 | static Standard_Boolean initactor = Standard_False; |
828 | if (initactor) return; initactor = Standard_True; |
829 | |
830 | //===================================== |
831 | // Work with shapes |
832 | //===================================== |
833 | |
834 | Standard_CString g = "XDE shape's commands"; |
835 | |
836 | di.Add ("XAddShape","Doc Shape [makeAssembly = 1]\t: Add shape (or assembly) to Document", |
837 | __FILE__, addShape, g); |
838 | |
839 | di.Add ("XNewShape","Doc \t: Create new empty top-level shape", |
840 | __FILE__, newShape, g); |
841 | |
842 | di.Add ("XSetShape","Doc Label Shape \t: Set shape at indicated label", |
843 | __FILE__, setShape, g); |
844 | |
845 | di.Add ("XGetShape","Result Doc Label \t: Put shape from tree to Result", |
846 | __FILE__, getShape, g); |
847 | |
848 | di.Add ("XRemoveShape","Doc Label \t: Remove shape from document", |
849 | __FILE__, removeShape, g); |
850 | |
851 | di.Add ("XFindShape","Doc Shape \t: Find and print label with indicated top-level shape", |
852 | __FILE__, findShape, g); |
853 | |
854 | di.Add ("XLabelInfo","Doc Label \t: Print information about object at following label", |
855 | __FILE__, labelInfo, g); |
856 | |
857 | di.Add ("XGetUsers","Doc Label [withSubChilds(int)] \t: Print number of assemblies that use shape at following label", |
858 | __FILE__, getUsers, g); |
859 | |
860 | di.Add ("XNbComponents","Doc Label [withSubChilds(int)] \t: Print number of component of assembly ", |
861 | __FILE__, nbComponents, g); |
862 | |
863 | di.Add ("XAddComponent","Doc Label Shape \t: Add component shape to assembly", |
864 | __FILE__, addComponent, g); |
865 | |
866 | di.Add ("XRemoveComponent","Doc Label \t: Remove component from components label", |
867 | __FILE__, removeComponent, g); |
868 | |
869 | di.Add ("XGetReferredShape","Doc Label \t: Print label, that contain a top-level shape, that corresponds shape at following label", |
870 | __FILE__, getReferredShape, g); |
871 | |
872 | di.Add ("XGetTopLevelShapes","Doc \t: Print labels, that contain a top-level shapes", |
873 | __FILE__, getTopLevelShapes, g); |
874 | |
875 | di.Add ("XGetFreeShapes","Doc [shape_prefix]\t: Print labels or create DRAW shapes for all free shapes in the Doc", |
876 | __FILE__, getFreeShapes, g); |
877 | |
878 | di.Add ("XGetOneShape","shape Doc \t: Put all free shapes of the Doc into signle DRAW shape", |
879 | __FILE__, getOneShape, g); |
880 | |
881 | di.Add ("XDumpLocation","Doc Label \t: Dump Transformation() of XCAFDoc_Location attribute", |
882 | __FILE__, XDumpLocation, g); |
883 | |
884 | di.Add ("XSetSHUO","Doc UU_Label [ multi-level labels ] NU_Label \t: sets the SHUO structure between UpperUsage and NextUsage", |
885 | __FILE__, setSHUO, g); |
886 | |
887 | di.Add ("XGetUU_SHUO","Doc NU_Label \t: prints the UpperUsages of indicated NextUsage", |
888 | __FILE__, getSHUOUpperUsage, g); |
889 | |
890 | di.Add ("XGetNU_SHUO","Doc UU_Label \t: prints the NextUsages of indicated UpperUsage", |
891 | __FILE__, getSHUONextUsage, g); |
892 | |
893 | di.Add ("XRemoveSHUO","Doc SHUO_Label \t: remove SHUO of indicated component", |
894 | __FILE__, removeSHUO, g); |
895 | |
896 | di.Add ("XIsHasSHUO","Doc SHUO_Label \t: remove SHUO of indicated component", |
897 | __FILE__, hasSHUO, g); |
898 | |
899 | di.Add ("XGetAllSHUO","Doc Comp_Label \t: remove SHUO of indicated component", |
900 | __FILE__, getAllSHUO, g); |
901 | |
902 | di.Add ("XFindComponent","Doc Shape \t: prints sequence of labels of assembly path", |
903 | __FILE__, findComponent, g); |
904 | |
905 | di.Add ("XGetSHUOInstance","Doc res SHUO_Label \t: returns SHUO_styled shape", |
906 | __FILE__, getStyledComponent, g); |
907 | |
908 | di.Add ("XGetAllSHUOInstances","Doc res SHUO_Label \t: returns SHUO_styled shapes as compound", |
909 | __FILE__, getAllStyledComponents, g); |
910 | |
911 | di.Add ("XFindSHUO","Doc labels of SHUO structure \t: prints label of SHUO that found by labels structure", |
912 | __FILE__, findSHUO, g); |
913 | |
914 | di.Add ("XSetInstanceSHUO","Doc shape \t: sets the SHUO structure for indicated component", |
915 | __FILE__, setStyledComponent, g); |
916 | |
917 | } |