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 | |
17 | #include <DBRep.hxx> |
18 | #include <DDocStd.hxx> |
42cf5bc1 |
19 | #include <Draw.hxx> |
7fd59977 |
20 | #include <TCollection_AsciiString.hxx> |
21 | #include <TColStd_HSequenceOfExtendedString.hxx> |
7fd59977 |
22 | #include <TDF_Label.hxx> |
23 | #include <TDF_LabelSequence.hxx> |
42cf5bc1 |
24 | #include <TDF_Tool.hxx> |
7fd59977 |
25 | #include <TDocStd_Document.hxx> |
42cf5bc1 |
26 | #include <TopoDS_Shape.hxx> |
7fd59977 |
27 | #include <XCAFDoc_DocumentTool.hxx> |
7fd59977 |
28 | #include <XCAFDoc_LayerTool.hxx> |
42cf5bc1 |
29 | #include <XCAFDoc_ShapeTool.hxx> |
30 | #include <XDEDRAW_Layers.hxx> |
7fd59977 |
31 | |
32 | //======================================================================= |
33 | // Section: Work with layers |
34 | //======================================================================= |
7fd59977 |
35 | static Standard_Integer addLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
36 | { |
37 | if (argc!=3) { |
586db386 |
38 | di<<"Use: "<<argv[0]<<" DocName StringLayer \n"; |
7fd59977 |
39 | return 1; |
40 | } |
41 | Handle(TDocStd_Document) Doc; |
42 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
43 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
44 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
45 | |
46 | TCollection_ExtendedString aLayer = argv[2]; |
47 | TDF_Label aLabel = localLayerTool->AddLayer(aLayer); |
48 | TCollection_AsciiString Entry; |
49 | TDF_Tool::Entry(aLabel, Entry); |
50 | di << Entry.ToCString(); |
51 | return 0; |
52 | } |
53 | |
54 | static Standard_Integer findLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
55 | { |
56 | if (argc!=3) { |
586db386 |
57 | di<<"Use: "<<argv[0]<<" DocName StringLayer \n"; |
7fd59977 |
58 | return 1; |
59 | } |
60 | Handle(TDocStd_Document) Doc; |
61 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
62 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
63 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
64 | |
65 | TCollection_ExtendedString aLayer = argv[2]; |
66 | TDF_Label aLabel = localLayerTool->FindLayer(aLayer); |
67 | TCollection_AsciiString Entry; |
68 | TDF_Tool::Entry(aLabel, Entry); |
69 | di << Entry.ToCString(); |
70 | return 0; |
71 | } |
72 | |
73 | static Standard_Integer removeLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
74 | { |
75 | if (argc!=3) { |
586db386 |
76 | di<<"Use: "<<argv[0]<<" DocName {Label|string}\n"; |
7fd59977 |
77 | return 1; |
78 | } |
79 | Handle(TDocStd_Document) Doc; |
80 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
81 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
82 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
83 | |
84 | TDF_Label aLabel; |
85 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
86 | if ( aLabel.IsNull() ) { |
87 | TCollection_ExtendedString aLayer = argv[2]; |
88 | aLabel = localLayerTool->FindLayer(aLayer); |
89 | } |
90 | if ( aLabel.IsNull() ) return 1; |
91 | localLayerTool->RemoveLayer( aLabel); |
92 | return 0; |
93 | } |
94 | |
95 | |
96 | static Standard_Integer setLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
97 | { |
98 | if (argc<4) { |
586db386 |
99 | di<<"Use: "<<argv[0]<<" DocName {Shape|Label} StringLayer [shapeInOneLayer(0/1)]\n"; |
7fd59977 |
100 | return 1; |
101 | } |
102 | Standard_Boolean shapeInOneLayer = Standard_False; |
91322f44 |
103 | if ( (argc==5) && (Draw::Atoi(argv[4])==1) ) shapeInOneLayer = Standard_True; |
7fd59977 |
104 | Handle(TDocStd_Document) Doc; |
105 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
106 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
107 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
108 | TDF_Label aLabel; |
109 | TCollection_ExtendedString aLayer = argv[3]; |
110 | |
111 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
112 | if ( !aLabel.IsNull() ) { |
113 | localLayerTool->SetLayer(aLabel, aLayer, shapeInOneLayer); |
114 | } |
115 | else { |
116 | TopoDS_Shape aShape= DBRep::Get(argv[2]); |
117 | if ( !aShape.IsNull() ) { |
118 | localLayerTool->SetLayer(aShape, aLayer, shapeInOneLayer); |
119 | } |
120 | } |
121 | return 0; |
122 | } |
123 | |
124 | |
125 | static Standard_Integer getLayers (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
126 | { |
127 | if (argc!=3) { |
586db386 |
128 | di<<"Use: "<<argv[0]<<" DocName {Shape|Label} \n"; |
7fd59977 |
129 | return 1; |
130 | } |
131 | // |
132 | Handle(TDocStd_Document) Doc; |
133 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
134 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
135 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
136 | TDF_Label aLabel; |
137 | Handle(TColStd_HSequenceOfExtendedString) aLayerS; |
138 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
139 | if ( !aLabel.IsNull() ) { |
140 | localLayerTool->GetLayers(aLabel, aLayerS); |
141 | } |
142 | else { |
143 | TopoDS_Shape aShape= DBRep::Get(argv[2]); |
144 | if ( !aShape.IsNull() ) { |
145 | localLayerTool->GetLayers(aShape, aLayerS); |
146 | } |
147 | } |
148 | Standard_Integer i = 1; |
149 | if (!aLayerS.IsNull() && aLayerS->Length()!=0) |
150 | for (; i <= aLayerS->Length(); i++) { |
151 | TCollection_AsciiString Entry(aLayerS->Value(i),'?'); |
586db386 |
152 | di << "\"" << Entry.ToCString() << "\" "; |
7fd59977 |
153 | } |
154 | return 0; |
155 | } |
156 | |
157 | |
158 | static Standard_Integer getLayerLabels (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
159 | { |
160 | if (argc!=2) { |
586db386 |
161 | di<<"Use: "<<argv[0]<<" DocName\n"; |
7fd59977 |
162 | return 1; |
163 | } |
164 | Handle(TDocStd_Document) Doc; |
165 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
166 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
167 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
168 | TDF_LabelSequence aLabs; |
169 | localLayerTool->GetLayerLabels(aLabs); |
170 | if (aLabs.Length() ==0 ) { |
171 | return 0; |
172 | } |
173 | Standard_Integer i = 1; |
174 | for (; i <= aLabs.Length(); i++) { |
175 | TDF_Label L = aLabs.Value(i); |
176 | if ( !L.IsNull() ) { |
177 | TCollection_AsciiString Entry; |
178 | TDF_Tool::Entry(L, Entry); |
179 | di << Entry.ToCString() << " "; |
180 | } |
181 | } |
182 | return 0; |
183 | } |
184 | |
185 | |
186 | static Standard_Integer getOneLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
187 | { |
188 | if (argc!=3) { |
586db386 |
189 | di<<"Use: "<<argv[0]<<" DocName LayerLabel\n"; |
7fd59977 |
190 | return 1; |
191 | } |
192 | Handle(TDocStd_Document) Doc; |
193 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
194 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
195 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
196 | TDF_Label aLabel; |
197 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
198 | if ( !aLabel.IsNull() ) { |
199 | TCollection_ExtendedString layerName; |
200 | localLayerTool->GetLayer(aLabel, layerName); |
201 | TCollection_AsciiString Entry(layerName,'?'); |
202 | di << "\"" << Entry.ToCString() <<"\""; |
203 | } |
204 | return 0; |
205 | } |
206 | |
207 | |
208 | static Standard_Integer setLinkLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
209 | { |
210 | if (argc<4) { |
586db386 |
211 | di<<"Use: "<<argv[0]<<" DocName {Shape|Label} LayerL [shapeInOneLayer(0/1)]\n"; |
7fd59977 |
212 | return 1; |
213 | } |
214 | Standard_Boolean shapeInOneLayer = Standard_False; |
91322f44 |
215 | if ( (argc==5) && (Draw::Atoi(argv[4])==1) ) shapeInOneLayer = Standard_True; |
7fd59977 |
216 | Handle(TDocStd_Document) Doc; |
217 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
218 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
219 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
220 | TDF_Label aLabel, layerLabel; |
221 | TDF_Tool::Label(Doc->GetData(), argv[3], layerLabel); |
222 | |
223 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
224 | if ( !layerLabel.IsNull() ) { |
225 | if ( !aLabel.IsNull() ) { |
226 | localLayerTool->SetLayer(aLabel, layerLabel, shapeInOneLayer); |
227 | } |
228 | else { |
229 | TopoDS_Shape aShape= DBRep::Get(argv[2]); |
230 | if ( !aShape.IsNull() ) { |
231 | localLayerTool->SetLayer(aShape, layerLabel, shapeInOneLayer); |
232 | } |
233 | } |
234 | } |
235 | return 0; |
236 | } |
237 | |
238 | |
239 | static Standard_Integer getAllLayers (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
240 | { |
241 | if (argc!=2) { |
586db386 |
242 | di<<"Use: "<<argv[0]<<" DocName\n"; |
7fd59977 |
243 | return 1; |
244 | } |
245 | Handle(TDocStd_Document) Doc; |
246 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
247 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
248 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
249 | TDF_LabelSequence aLabs; |
250 | localLayerTool->GetLayerLabels(aLabs); |
251 | if (aLabs.Length() ==0 ) { |
252 | return 0; |
253 | } |
254 | Standard_Integer i = 1; |
255 | TCollection_ExtendedString layerName; |
256 | |
257 | for (; i <= aLabs.Length(); i++) { |
258 | TDF_Label L = aLabs.Value(i); |
259 | if ( !L.IsNull() ) { |
260 | localLayerTool->GetLayer(L, layerName); |
261 | TCollection_AsciiString Entry(layerName,'?'); |
262 | di << "\"" << Entry.ToCString() <<"\""; |
263 | di << " "; |
264 | } |
265 | } |
266 | return 0; |
267 | } |
268 | |
269 | |
270 | static Standard_Integer unSetLayer (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
271 | { |
272 | if (argc!=4) { |
586db386 |
273 | di<<"Use: "<<argv[0]<<" DocName {Shape|Label} stringL\n"; |
7fd59977 |
274 | return 1; |
275 | } |
276 | Handle(TDocStd_Document) Doc; |
277 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
278 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
279 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
280 | TDF_Label aLabel; |
281 | TCollection_ExtendedString aLayer = argv[3]; |
282 | |
283 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
284 | if ( !aLabel.IsNull() ) { |
285 | localLayerTool->UnSetOneLayer(aLabel, aLayer); |
286 | } |
287 | else { |
288 | TopoDS_Shape aShape= DBRep::Get(argv[2]); |
289 | if ( !aShape.IsNull() ) { |
290 | localLayerTool->UnSetOneLayer(aShape, aLayer); |
291 | } |
292 | } |
293 | return 0; |
294 | } |
295 | |
296 | |
297 | static Standard_Integer unSetAllLayers (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
298 | { |
299 | if (argc!=3) { |
586db386 |
300 | di<<"Use: "<<argv[0]<<" DocName {Shape|Label}\n"; |
7fd59977 |
301 | return 1; |
302 | } |
303 | Handle(TDocStd_Document) Doc; |
304 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
305 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
306 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
307 | TDF_Label aLabel; |
308 | |
309 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
310 | if ( !aLabel.IsNull() ) { |
311 | localLayerTool->UnSetLayers(aLabel); |
312 | } |
313 | else { |
314 | TopoDS_Shape aShape= DBRep::Get(argv[2]); |
315 | if ( !aShape.IsNull() ) { |
316 | localLayerTool->UnSetLayers(aShape); |
317 | } |
318 | } |
319 | return 0; |
320 | } |
321 | |
322 | |
323 | static Standard_Integer removeAllLayers (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
324 | { |
325 | if (argc!=2) { |
586db386 |
326 | di<<"Use: "<<argv[0]<<" DocName\n"; |
7fd59977 |
327 | return 1; |
328 | } |
329 | Handle(TDocStd_Document) Doc; |
330 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
331 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
332 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
333 | |
334 | TDF_LabelSequence aLabs; |
335 | localLayerTool->GetLayerLabels(aLabs); |
336 | if (aLabs.Length() ==0 ) { |
337 | return 0; |
338 | } |
339 | Standard_Integer i = 1; |
340 | for (; i <= aLabs.Length(); i++) { |
341 | TDF_Label L = aLabs.Value(i); |
342 | if ( !L.IsNull() ) { |
343 | localLayerTool->RemoveLayer(L); |
344 | } |
345 | } |
346 | return 0; |
347 | } |
348 | |
349 | static Standard_Integer setVisibility (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
350 | { |
351 | if (argc<3) { |
586db386 |
352 | di<<"Use: "<<argv[0]<<"DocName {layerLable|StringLayer} [isvisible(1/0)]\n"; |
7fd59977 |
353 | return 1; |
354 | } |
355 | Handle(TDocStd_Document) Doc; |
356 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
357 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
358 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
359 | Standard_Boolean isvisible = Standard_False; |
91322f44 |
360 | if ( (argc==4) && (Draw::Atoi(argv[3])==1) ) isvisible = Standard_True; |
7fd59977 |
361 | |
362 | TDF_Label aLabel; |
363 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
364 | if ( aLabel.IsNull() ) { |
365 | TCollection_ExtendedString aLayer = argv[2]; |
366 | aLabel = localLayerTool->FindLayer(aLayer); |
367 | } |
368 | if ( aLabel.IsNull() ) return 1; |
369 | localLayerTool->SetVisibility(aLabel, isvisible); |
370 | return 0; |
371 | } |
372 | |
373 | |
374 | static Standard_Integer isVisible (Draw_Interpretor& di, Standard_Integer argc, const char** argv) |
375 | { |
376 | if (argc!=3) { |
586db386 |
377 | di<<"Use: "<<argv[0]<<" DocName {layerLable|StringLayer}\n"; |
7fd59977 |
378 | return 1; |
379 | } |
380 | Handle(TDocStd_Document) Doc; |
381 | DDocStd::GetDocument(argv[1], Doc); |
586db386 |
382 | if ( Doc.IsNull() ) { di << argv[1] << " is not a document\n"; return 1; } |
7fd59977 |
383 | Handle(XCAFDoc_LayerTool) localLayerTool = XCAFDoc_DocumentTool::LayerTool(Doc->Main()); |
384 | |
385 | TDF_Label aLabel; |
386 | TDF_Tool::Label(Doc->GetData(), argv[2], aLabel); |
387 | if ( aLabel.IsNull() ) { |
388 | TCollection_ExtendedString aLayer = argv[2]; |
389 | aLabel = localLayerTool->FindLayer(aLayer); |
390 | } |
391 | if ( aLabel.IsNull() ) return 1; |
392 | if (localLayerTool->IsVisible( aLabel) ) di << 1; |
393 | else di << 0; |
394 | return 0; |
395 | } |
396 | |
397 | //======================================================================= |
398 | //function : InitCommands |
399 | //purpose : |
400 | //======================================================================= |
401 | |
402 | void XDEDRAW_Layers::InitCommands(Draw_Interpretor& di) |
403 | { |
404 | |
405 | static Standard_Boolean initactor = Standard_False; |
406 | if (initactor) return; initactor = Standard_True; |
407 | |
408 | //===================================== |
409 | // Work with layers |
410 | //===================================== |
411 | |
412 | Standard_CString g = "XDE layer's commands"; |
413 | |
414 | di.Add ("XSetLayer","DocName {Shape|Label} StringLayer [shapeInOneLayer(0/1)] \t: Set reference between Shape and Layer (add layer if nesessary). shapeInOneLayer 0 is default", |
415 | __FILE__, setLayer, g); |
416 | |
417 | di.Add ("XGetLayers","DocName {Shape|Label} \t: Get layers of indicated shape", |
418 | __FILE__, getLayers, g); |
419 | |
420 | di.Add ("XGetOneLayer","DocName LayerLabel \t: Print name of layer.", |
421 | __FILE__, getOneLayer, g); |
422 | |
423 | di.Add ("XAddLayer","DocName StringLayer \t: Adding layer in XCAFDocument.", |
424 | __FILE__, addLayer, g); |
425 | |
426 | di.Add ("XSetLinkLayer","DocName {Shape|Label} LayerL [shapeInOneLayer(0/1)] \t: Set reference between shape and existing layer. shapeInOneLayer 0 is default", |
427 | __FILE__, setLinkLayer, g); |
428 | |
429 | di.Add ("XGetAllLayers","DocName \t: Get all layers in XCAFDocument.", |
430 | __FILE__, getAllLayers, g); |
431 | |
432 | di.Add ("XUnSetLayer","DocName {Shape|Label} stringL \t: unset shape from indicated layer.", |
433 | __FILE__, unSetLayer, g); |
434 | |
435 | di.Add ("XUnSetAllLayers","DocName {Shape|Label} \t: unset shape from all layers.", |
436 | __FILE__, unSetAllLayers, g); |
437 | |
438 | di.Add ("XRemoveLayer","DocName {Label|string} \t:remove layer from XCAFDocument.", |
439 | __FILE__, removeLayer, g); |
440 | |
441 | di.Add ("XRemoveAllLayers","DocName \t: remove all layers from XCAFDocument.", |
442 | __FILE__, removeAllLayers, g); |
443 | |
444 | di.Add ("XFindLayer","DocName string \t: Print label where are layer is situated.", |
445 | __FILE__, findLayer, g); |
446 | |
447 | di.Add ("XGetLayerLabels","DocName \t: Print labels from layertable.", |
448 | __FILE__, getLayerLabels, g); |
449 | |
450 | di.Add ("XSetVisibility","DocName {layerLable|StringLayer} [isvisible(1/0)] \t: Set visibility of layer", |
451 | __FILE__, setVisibility, g); |
452 | |
453 | di.Add ("XIsVisible","DocName {layerLable|StringLayer} \t: Return 1 if layer is visible, 0 if not", |
454 | __FILE__, isVisible, g); |
455 | } |