7fd59977 |
1 | // File: QADNaming_BasicCommands.cxx |
2 | // Created: Mon Jan 13 14:25:34 1997 |
3 | // Author: VAUTHIER Jean-Claude |
4 | |
5 | #include <QADNaming.hxx> |
6 | #include <TCollection_AsciiString.hxx> |
7 | #include <TDF_Data.hxx> |
8 | #include <TDF_ListIteratorOfLabelList.hxx> |
9 | #include <TDF_LabelList.hxx> |
10 | #include <TDF_LabelMap.hxx> |
11 | #include <TDF_Tool.hxx> |
12 | |
13 | #include <DDF.hxx> |
14 | |
15 | #include <TNaming.hxx> |
16 | #include <TNaming_NamedShape.hxx> |
17 | #include <TNaming_NewShapeIterator.hxx> |
18 | #include <TNaming_OldShapeIterator.hxx> |
19 | #include <TNaming_Iterator.hxx> |
20 | #include <TNaming_Tool.hxx> |
21 | #include <TNaming_MapOfNamedShape.hxx> |
22 | #include <TNaming_MapIteratorOfMapOfNamedShape.hxx> |
23 | #include <Draw_Drawable3D.hxx> |
24 | #include <Draw.hxx> |
25 | #include <Draw_Interpretor.hxx> |
26 | #include <TopTools_ListOfShape.hxx> |
27 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
28 | #include <TopTools_DataMapOfShapeShape.hxx> |
29 | #include <TopoDS_Shape.hxx> |
30 | #include <DBRep.hxx> |
31 | |
32 | |
33 | #include <gp.hxx> |
34 | #include <gp_Vec.hxx> |
35 | #include <gp_Ax1.hxx> |
36 | #include <gp_Ax2.hxx> |
37 | #include <gp_Ax3.hxx> |
38 | #include <gp_Trsf.hxx> |
39 | |
40 | #include <TColStd_HArray1OfInteger.hxx> |
41 | //#ifdef WNT |
42 | #include <stdio.h> |
43 | //#endif |
44 | |
45 | // POP : first Wrong Declaration : now it is correct |
46 | // second not used |
47 | //extern void QADNaming_BuildMap(TDF_LabelMap& Updated, const TDF_Label& Lab); |
48 | |
49 | |
50 | //======================================================================= |
51 | //function : Ascendants |
52 | //purpose : |
53 | //======================================================================= |
54 | |
55 | static Standard_Integer Ascendants (Draw_Interpretor& di, Standard_Integer n, const char ** a) |
56 | { |
57 | if (n < 3) return 1; |
58 | |
59 | char name[100]; |
60 | |
61 | Handle(TDF_Data) ND; |
62 | // Handle(TNaming_UsedShapes) US; |
63 | |
64 | if (!DDF::GetDF(a[1],ND)) return 1; |
65 | // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US); |
66 | |
67 | TopoDS_Shape S = DBRep::Get (a[2]); |
68 | if (S.IsNull ()) return 1; |
69 | |
70 | Standard_Integer T; |
71 | |
72 | if (n > 3) T = atoi(a[3]); |
73 | else T = ND->Transaction (); |
74 | |
75 | //TNaming_OldShapeIterator it (S, T, US); |
76 | TNaming_OldShapeIterator it (S, T, ND->Root()); |
77 | Standard_Integer i = 0; |
78 | TCollection_AsciiString entry; |
79 | for (;it.More (); it.Next ()) { |
80 | S = it.Shape (); |
81 | sprintf (name,"%s_%s_%d",a[2],"old", i++); |
82 | DBRep::Set (name,it.Shape()); |
83 | TDF_Label Label = it.Label (); |
84 | TDF_Tool::Entry(Label,entry); |
85 | di<<entry.ToCString()<<"\n"; |
86 | } |
87 | return 0; |
88 | } |
89 | |
90 | |
91 | //======================================================================= |
92 | //function : Descendants |
93 | //purpose : |
94 | //======================================================================= |
95 | |
96 | static Standard_Integer Descendants (Draw_Interpretor& di, Standard_Integer n, const char ** a) |
97 | |
98 | { |
99 | if (n < 3) return 1; |
100 | |
101 | char name[100]; |
102 | Handle(TDF_Data) ND; |
103 | // Handle(TNaming_UsedShapes) US; |
104 | if (!DDF::GetDF(a[1],ND)) return 1; |
105 | // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US); |
106 | |
107 | |
108 | TopoDS_Shape S = DBRep::Get (a[2]); |
109 | if (S.IsNull ()) return 1; |
110 | |
111 | Standard_Integer T; |
112 | |
113 | if (n > 3) T = atoi(a[3]); |
114 | else T = ND->Transaction (); |
115 | |
116 | TNaming_NewShapeIterator it (S, T, ND->Root()); |
117 | Standard_Integer i = 0; |
118 | TCollection_AsciiString entry; |
119 | for (;it.More (); it.Next ()) { |
120 | S = it.Shape (); |
121 | sprintf (name,"%s_%s_%d",a[2],"new", i++); |
122 | DBRep::Set (name,it.Shape ()); |
123 | TDF_Label Label = it.Label (); |
124 | TDF_Tool::Entry(Label,entry); |
125 | di<<entry.ToCString()<<"\n"; |
126 | } |
127 | |
128 | return 0; |
129 | } |
130 | |
131 | //======================================================================= |
132 | //function : GetEntry |
133 | //purpose : |
134 | //======================================================================= |
135 | |
136 | static Standard_Integer Getentry (Draw_Interpretor& di, Standard_Integer n, const char ** a) |
137 | { |
138 | if (n < 3) return 1; |
139 | Handle(TDF_Data) ND; |
140 | // Handle(TNaming_UsedShapes) US; |
141 | |
142 | if (!DDF::GetDF(a[1],ND)) return 1; |
143 | // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US); |
144 | |
145 | TopoDS_Shape S = DBRep::Get(a[2]); |
146 | if (S.IsNull()) { |
147 | di <<"Noone shape selected"<<"\n"; |
148 | di << 0; |
149 | return 0; |
150 | } |
151 | Standard_Integer Status ; |
152 | TCollection_AsciiString Name = QADNaming::GetEntry(S,ND,Status); |
153 | if (Status == 0) { |
154 | di <<"E_NoName"; |
155 | } |
156 | else { |
157 | di <<Name.ToCString(); |
158 | if (Status == 2) { |
159 | di <<"Several shapes have the same name"<<"\n"; |
160 | } |
161 | } |
162 | return 0; |
163 | } |
164 | |
165 | //======================================================================= |
166 | //function : NamedShape |
167 | //purpose : retrive label of Primitive or a Generated shape |
168 | //======================================================================= |
169 | |
170 | static Standard_Integer NamedShape(Draw_Interpretor& di, Standard_Integer n, const char ** a) |
171 | { |
172 | if (n < 3) return 1; |
173 | Handle(TDF_Data) ND; |
174 | // Handle(TNaming_UsedShapes) US; |
175 | |
176 | if (!DDF::GetDF(a[1],ND)) return 1; |
177 | TopoDS_Shape SS = DBRep::Get(a[2]); |
178 | if (SS.IsNull()) { |
179 | di <<"Noone shape selected"<<"\n"; |
180 | di << 0; |
181 | return 0; |
182 | } |
183 | |
184 | Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape (SS,ND->Root()); |
185 | |
186 | if (NS.IsNull()) { |
187 | di <<"E_NoName"; |
188 | return 0; |
189 | } |
190 | TCollection_AsciiString Name; TDF_Tool::Entry(NS->Label(),Name); |
191 | di <<Name.ToCString(); |
192 | return 0; |
193 | } |
194 | |
195 | //======================================================================= |
196 | //function : Currentshape |
197 | //purpose : |
198 | //======================================================================= |
199 | |
200 | static Standard_Integer Currentshape (Draw_Interpretor& , Standard_Integer n, const char ** a) |
201 | { |
202 | if (n < 4) return 1; |
203 | |
204 | Handle(TDF_Data) ND; |
205 | if (!DDF::GetDF(a[1],ND)) return 1; |
206 | |
207 | Standard_CString LabelName = a[2]; |
208 | TopoDS_Shape S = QADNaming::CurrentShape(LabelName,ND); |
209 | if (!S.IsNull()) { |
210 | if (n == 4) DBRep::Set(a[3],S); |
211 | else DBRep::Set(a[2],S); |
212 | return 0; |
213 | } |
214 | return 0; |
215 | } |
216 | |
217 | //======================================================================= |
218 | //function : Initialshape |
219 | //purpose : |
220 | //======================================================================= |
221 | |
222 | static Standard_Integer Initialshape (Draw_Interpretor& di, Standard_Integer n, const char ** a) |
223 | { |
224 | if (n < 4) return 1; |
225 | |
226 | Handle(TDF_Data) ND; |
227 | |
228 | if (!DDF::GetDF(a[1],ND)) return 1; |
229 | |
230 | TopoDS_Shape NS = DBRep::Get(a[2]); |
231 | if (NS.IsNull()) return 1; |
232 | |
233 | TDF_LabelList Labels; |
234 | TopoDS_Shape S = TNaming_Tool::InitialShape (NS,ND->Root(),Labels); |
235 | if (!S.IsNull()) { |
236 | DBRep::Set (a[3], S); |
237 | } |
238 | TDF_ListIteratorOfLabelList itL(Labels); |
239 | |
240 | TCollection_AsciiString entry; |
241 | if (itL.More()) { |
242 | TDF_Tool::Entry(itL.Value(),entry); |
243 | di << entry.ToCString(); |
244 | itL.Next(); |
245 | } |
246 | for (; itL.More(); itL.Next()) { |
247 | TDF_Tool::Entry(itL.Value(),entry); |
248 | di <<" , "<< entry.ToCString(); |
249 | } |
250 | di <<"."<<"\n"; |
251 | return 0; |
252 | } |
253 | |
254 | //======================================================================= |
255 | //function : GetShape |
256 | //purpose : |
257 | //======================================================================= |
258 | |
259 | static Standard_Integer Exploreshape (Draw_Interpretor& di, Standard_Integer n, const char ** a) |
260 | { |
261 | char name[100]; |
262 | |
263 | if (n < 4) return 1; |
264 | Handle(TDF_Data) ND; |
265 | // Handle(TNaming_UsedShapes) US; |
266 | |
267 | if (!DDF::GetDF(a[1],ND)) return 1; |
268 | // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US); |
269 | |
270 | Standard_Integer Trans = ND->Transaction(); |
271 | if (n == 5) { Trans = (Standard_Integer ) atof(a[4]);} |
272 | |
273 | TDF_Label Lab; |
274 | DDF::FindLabel(ND,a[2],Lab); |
275 | Handle(TNaming_NamedShape) NS; |
276 | if (!Lab.FindAttribute(TNaming_NamedShape::GetID(),NS)) { |
277 | di <<"No shape"<<"\n"; |
278 | return 0; |
279 | } |
280 | |
281 | //TNaming::Print(NS->Evolution(),cout); |
282 | Standard_SStream aSStream; |
283 | TNaming::Print(NS->Evolution(),aSStream); |
284 | di << aSStream; |
285 | |
286 | Standard_Integer NbShapes = 1; |
287 | |
288 | for (TNaming_Iterator itL(Lab,Trans) ; itL.More(); itL.Next()) { |
289 | if (!itL.OldShape().IsNull()) { |
290 | sprintf(name,"%s%s_%d","old",a[3],NbShapes); |
291 | DBRep::Set (name,itL.OldShape()); |
292 | } |
293 | if (!itL.NewShape().IsNull()) { |
294 | sprintf(name,"%s_%d",a[3],NbShapes); |
295 | DBRep::Set (name,itL.NewShape()); |
296 | } |
297 | NbShapes++; |
298 | } |
299 | di <<"\n"; |
300 | if (NbShapes == 0) { |
301 | di <<"No shape"<<"\n"; |
302 | } |
303 | |
304 | return 0; |
305 | } |
306 | |
307 | //======================================================================= |
308 | //function : GeneratedShape |
309 | //purpose : Generatedshape df shape Generationentry [drawname] |
310 | //======================================================================= |
311 | |
312 | static Standard_Integer Generatedshape (Draw_Interpretor& di, |
313 | Standard_Integer nb, |
314 | const char ** arg) |
315 | { |
316 | TopoDS_Shape S; |
317 | Handle(TNaming_NamedShape) A; |
318 | if (nb >= 4) { |
319 | Handle(TDF_Data) DF; |
320 | if (!DDF::GetDF(arg[1],DF)) return 1; |
321 | TopoDS_Shape Gen = DBRep::Get(arg[2]); |
322 | Handle(TNaming_NamedShape) Generation; |
323 | if (!DDF::Find(DF,arg[3],TNaming_NamedShape::GetID(),Generation)) return 1; |
324 | S = TNaming_Tool::GeneratedShape(Gen,Generation); |
325 | if (!S.IsNull()) { |
326 | if (nb == 4) DBRep::Set(arg[4],S); |
327 | else DBRep::Set(arg[3],S); |
328 | return 0; |
329 | } |
330 | } |
331 | di << "GetShape : Error" << "\n"; |
332 | return 1; |
333 | } |
334 | |
335 | //======================================================================= |
336 | //function : DDataStd_GetShape |
337 | //purpose : |
338 | //======================================================================= |
339 | |
340 | static Standard_Integer Getshape (Draw_Interpretor& di, |
341 | Standard_Integer nb, |
342 | const char ** arg) |
343 | { |
344 | TopoDS_Shape s; |
345 | Handle(TNaming_NamedShape) A; |
346 | if (nb >= 3) { |
347 | Handle(TDF_Data) DF; |
348 | if (!DDF::GetDF(arg[1],DF)) return 1; |
349 | if (!DDF::Find(DF,arg[2],TNaming_NamedShape::GetID(),A)) return 1; |
350 | s = TNaming_Tool::GetShape(A); |
351 | if (!s.IsNull()) { |
352 | if (nb == 4) DBRep::Set(arg[3],s); |
353 | else DBRep::Set(arg[2],s); |
354 | return 0; |
355 | } |
356 | } |
357 | di << "DDataStd_GetShape : Error" << "\n"; |
358 | return 1; |
359 | } |
360 | |
361 | //======================================================================= |
362 | //function : Collect |
363 | //purpose : |
364 | //======================================================================= |
365 | |
366 | static Standard_Integer Collect (Draw_Interpretor& di, |
367 | Standard_Integer nb, |
368 | const char ** arg) |
369 | { |
370 | TNaming_MapOfNamedShape MNS; |
371 | Handle(TNaming_NamedShape) A; |
372 | Standard_Boolean OnlyModif = 1; |
373 | |
374 | if (nb >= 3) { |
375 | Handle(TDF_Data) DF; |
376 | if (!DDF::GetDF(arg[1],DF)) return 1; |
377 | if (!DDF::Find(DF,arg[2],TNaming_NamedShape::GetID(),A)) return 1; |
378 | if (nb >= 4) { |
379 | OnlyModif = atoi(arg[3]); |
380 | } |
381 | TNaming_Tool::Collect(A,MNS,OnlyModif); |
382 | for (TNaming_MapIteratorOfMapOfNamedShape it(MNS); it.More(); it.Next()) { |
383 | TCollection_AsciiString Name; |
384 | TDF_Tool::Entry(it.Key()->Label(),Name); |
385 | di <<Name.ToCString()<<" "; |
386 | } |
387 | } |
388 | return 1; |
389 | } |
390 | |
391 | //======================================================================= |
392 | //function : GetCreationEntry |
393 | //purpose : retrive label of Primitive or a Generated shape |
394 | //======================================================================= |
395 | |
396 | static Standard_Integer Getcreationentry (Draw_Interpretor& di, Standard_Integer n, const char ** a) |
397 | { |
398 | if (n < 3) return 1; |
399 | Handle(TDF_Data) ND; |
400 | // Handle(TNaming_UsedShapes) US; |
401 | |
402 | if (!DDF::GetDF(a[1],ND)) return 1; |
403 | // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US); |
404 | |
405 | TopoDS_Shape SS = DBRep::Get(a[2]); |
406 | |
407 | if (SS.IsNull()) { |
408 | di <<"Noone shape selected"<<"\n"; |
409 | di << 0; |
410 | return 0; |
411 | } |
412 | |
413 | TDF_LabelList Labels; |
414 | TopoDS_Shape S = TNaming_Tool::InitialShape(SS, ND->Root(), Labels); |
415 | |
416 | if (S.IsNull()) { |
417 | di <<"E_NoName"; |
418 | return 0; |
419 | } |
420 | Standard_Integer Status ; |
421 | |
422 | TCollection_AsciiString Name = QADNaming::GetEntry(S,ND,Status); |
423 | if (Status == 0) { |
424 | di <<"E_NoName"; |
425 | } |
426 | else { |
427 | di <<Name.ToCString(); |
428 | if (Status == 2) { |
429 | di <<"Several shapes have the same name"<<"\n"; |
430 | } |
431 | } |
432 | return 0; |
433 | } |
434 | |
435 | |
436 | //======================================================================= |
437 | //function : BasicCommands |
438 | //purpose : |
439 | //======================================================================= |
440 | |
441 | void QADNaming::BasicCommands(Draw_Interpretor& theCommands) |
442 | { |
443 | static Standard_Boolean done = Standard_False; |
444 | if (done) return; |
445 | done = Standard_True; |
446 | |
447 | const char* g = "Naming data commands"; |
448 | |
449 | // Exploration |
450 | theCommands.Add("Ascendants", "Ascendants df shape [trans]", __FILE__,Ascendants, g); |
451 | |
452 | theCommands.Add("Descendants", "Descendants df shape [trans]", __FILE__,Descendants, g); |
453 | |
454 | theCommands.Add("ExploreShape","ExploreShape df entry res [trans]",__FILE__,Exploreshape, g); |
455 | |
456 | theCommands.Add("GetEntry", "GetEntry df shape", __FILE__,Getentry, g); |
457 | |
458 | theCommands.Add("GetCreationEntry", "GetCreationEntry df shape",__FILE__,Getcreationentry,g); |
459 | |
460 | theCommands.Add("NamedShape", "NamedShape df shape", __FILE__,NamedShape, g); |
461 | |
462 | theCommands.Add("InitialShape","InitialShape df shape res", __FILE__,Initialshape, g); |
463 | |
464 | theCommands.Add("CurrentShape","Currentshape df entry [drawname]", __FILE__,Currentshape, g); |
465 | |
466 | theCommands.Add("GetShape", "GetShape df entry [drawname]", __FILE__,Getshape , g); |
467 | |
468 | theCommands.Add("Collect", "Collect df entry [onlymodif 0/1]",__FILE__,Collect , g); |
469 | |
470 | theCommands.Add ("GeneratedShape", |
471 | "Generatedshape df shape Generationentry [drawname]", |
472 | __FILE__,Generatedshape,g); |
473 | } |