1 // File: DNaming_BasicCommands.cxx
2 // Created: Mon Jan 13 14:25:34 1997
3 // Author: VAUTHIER Jean-Claude
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>
13 #include <DDF_Data.hxx>
14 #include <TNaming.hxx>
15 #include <TNaming_NamedShape.hxx>
16 #include <TNaming_NewShapeIterator.hxx>
17 #include <TNaming_OldShapeIterator.hxx>
18 #include <TNaming_Iterator.hxx>
19 #include <TNaming_Tool.hxx>
20 #include <TNaming_MapOfNamedShape.hxx>
21 #include <TNaming_MapIteratorOfMapOfNamedShape.hxx>
22 #include <Draw_Drawable3D.hxx>
24 #include <Draw_Interpretor.hxx>
25 #include <TopTools_ListOfShape.hxx>
26 #include <TopTools_ListIteratorOfListOfShape.hxx>
27 #include <TopTools_DataMapOfShapeShape.hxx>
28 #include <TopoDS_Shape.hxx>
31 #include <TNaming_Builder.hxx>
32 #include <TDataStd_Name.hxx>
33 #include <TDF_TagSource.hxx>
34 #include <TopExp_Explorer.hxx>
41 #include <gp_Trsf.hxx>
43 #include <TColStd_HArray1OfInteger.hxx>
48 // POP : first Wrong Declaration : now it is correct
50 //extern void DNaming_BuildMap(TDF_LabelMap& Updated, const TDF_Label& Lab);
53 //=======================================================================
54 //function : Ascendants
56 //=======================================================================
57 static Standard_Integer Ascendants (Draw_Interpretor& di, Standard_Integer n, const char** a)
64 // Handle(TNaming_UsedShapes) US;
66 if (!DDF::GetDF(a[1],ND)) return 1;
67 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
69 TopoDS_Shape S = DBRep::Get (a[2]);
70 if (S.IsNull ()) return 1;
74 if (n > 3) T = atoi(a[3]);
75 else T = ND->Transaction ();
77 //TNaming_OldShapeIterator it (S, T, US);
78 TNaming_OldShapeIterator it (S, T, ND->Root());
79 Standard_Integer i = 0;
80 TCollection_AsciiString entry;
81 for (;it.More (); it.Next ()) {
83 sprintf (name,"%s_%s_%d",a[2],"old", i++);
84 DBRep::Set (name,it.Shape());
85 TDF_Label Label = it.Label ();
86 TDF_Tool::Entry(Label,entry);
87 di<<entry.ToCString()<<"\n";
93 //=======================================================================
94 //function : Descendants
96 //=======================================================================
97 static Standard_Integer Descendants (Draw_Interpretor& di, Standard_Integer n, const char** a)
104 // Handle(TNaming_UsedShapes) US;
105 if (!DDF::GetDF(a[1],ND)) return 1;
106 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
109 TopoDS_Shape S = DBRep::Get (a[2]);
110 if (S.IsNull ()) return 1;
114 if (n > 3) T = atoi(a[3]);
115 else T = ND->Transaction ();
117 TNaming_NewShapeIterator it (S, T, ND->Root());
118 Standard_Integer i = 0;
119 TCollection_AsciiString entry;
120 for (;it.More (); it.Next ()) {
122 sprintf (name,"%s_%s_%d",a[2],"new", i++);
123 DBRep::Set (name,it.Shape ());
124 TDF_Label Label = it.Label ();
125 TDF_Tool::Entry(Label,entry);
126 di<<entry.ToCString()<<"\n";
132 //=======================================================================
133 //function : GetEntry
135 //=======================================================================
136 static Standard_Integer Getentry (Draw_Interpretor& di, Standard_Integer n, const char** a)
140 // Handle(TNaming_UsedShapes) US;
142 if (!DDF::GetDF(a[1],ND)) return 1;
143 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
145 TopoDS_Shape S = DBRep::Get(a[2]);
147 di <<"Noone shape selected"<<"\n";
151 Standard_Integer Status ;
152 TCollection_AsciiString Name = DNaming::GetEntry(S,ND,Status);
157 di <<Name.ToCString();
159 di <<"Several shapes have the same name"<<"\n";
165 //=======================================================================
166 //function : NamedShape
167 //purpose : retrive label of Primitive or a Generated shape
168 //=======================================================================
169 static Standard_Integer NamedShape(Draw_Interpretor& di, Standard_Integer n, const char** a)
173 // Handle(TNaming_UsedShapes) US;
175 if (!DDF::GetDF(a[1],ND)) return 1;
176 TopoDS_Shape SS = DBRep::Get(a[2]);
178 di <<"Noone shape selected"<<"\n";
183 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape (SS,ND->Root());
189 TCollection_AsciiString Name; TDF_Tool::Entry(NS->Label(),Name);
190 di <<Name.ToCString();
194 //=======================================================================
195 //function : Currentshape
197 //=======================================================================
198 static Standard_Integer Currentshape (Draw_Interpretor& , Standard_Integer n, const char** a)
203 if (!DDF::GetDF(a[1],ND)) return 1;
205 Standard_CString LabelName = a[2];
206 TopoDS_Shape S = DNaming::CurrentShape(LabelName,ND);
208 if (n == 4) DBRep::Set(a[3],S);
209 else DBRep::Set(a[2],S);
215 //=======================================================================
216 //function : Initialshape
218 //=======================================================================
219 static Standard_Integer Initialshape (Draw_Interpretor& di, Standard_Integer n, const char** a)
225 if (!DDF::GetDF(a[1],ND)) return 1;
227 TopoDS_Shape NS = DBRep::Get(a[2]);
228 if (NS.IsNull()) return 1;
230 TDF_LabelList Labels;
231 TopoDS_Shape S = TNaming_Tool::InitialShape (NS,ND->Root(),Labels);
233 DBRep::Set (a[3], S);
235 TDF_ListIteratorOfLabelList itL(Labels);
237 TCollection_AsciiString entry;
239 TDF_Tool::Entry(itL.Value(),entry);
240 di << entry.ToCString();
243 for (; itL.More(); itL.Next()) {
244 TDF_Tool::Entry(itL.Value(),entry);
245 di <<" , "<< entry.ToCString();
251 //=======================================================================
252 //function : GetShape
254 //=======================================================================
255 static Standard_Integer Exploreshape (Draw_Interpretor& di, Standard_Integer n, const char** a)
261 // Handle(TNaming_UsedShapes) US;
263 if (!DDF::GetDF(a[1],ND)) return 1;
264 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
266 Standard_Integer Trans = ND->Transaction();
267 if (n == 5) { Trans = (Standard_Integer ) atof(a[4]);}
270 DDF::FindLabel(ND,a[2],Lab);
271 Handle(TNaming_NamedShape) NS;
272 if (!Lab.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
273 di <<"No shape"<<"\n";
277 //TNaming::Print(NS->Evolution(),cout);
278 Standard_SStream aStream;
279 TNaming::Print(NS->Evolution(),aStream);
280 di << aStream << "\n";
282 Standard_Integer NbShapes = 1;
284 for (TNaming_Iterator itL(Lab,Trans) ; itL.More(); itL.Next()) {
285 if (!itL.OldShape().IsNull()) {
286 sprintf(name,"%s%s_%d","old",a[3],NbShapes);
287 DBRep::Set (name,itL.OldShape());
289 if (!itL.NewShape().IsNull()) {
290 sprintf(name,"%s_%d",a[3],NbShapes);
291 DBRep::Set (name,itL.NewShape());
297 di <<"No shape"<<"\n";
303 //=======================================================================
304 //function : GeneratedShape
305 //purpose : Generatedshape df shape Generationentry [drawname]
306 //=======================================================================
308 static Standard_Integer Generatedshape (Draw_Interpretor& di,
313 Handle(TNaming_NamedShape) A;
316 if (!DDF::GetDF(arg[1],DF)) return 1;
317 TopoDS_Shape Gen = DBRep::Get(arg[2]);
318 Handle(TNaming_NamedShape) Generation;
319 if (!DDF::Find(DF,arg[3],TNaming_NamedShape::GetID(),Generation)) return 1;
320 S = TNaming_Tool::GeneratedShape(Gen,Generation);
322 if (nb == 4) DBRep::Set(arg[4],S);
323 else DBRep::Set(arg[3],S);
327 di << "GetShape : Error" << "\n";
331 //=======================================================================
332 //function : DDataStd_GetShape
334 //=======================================================================
336 static Standard_Integer Getshape (Draw_Interpretor& di,
341 Handle(TNaming_NamedShape) A;
344 if (!DDF::GetDF(arg[1],DF)) return 1;
345 if (!DDF::Find(DF,arg[2],TNaming_NamedShape::GetID(),A)) return 1;
346 s = TNaming_Tool::GetShape(A);
348 if (nb == 4) DBRep::Set(arg[3],s);
349 else DBRep::Set(arg[2],s);
353 di << "DDataStd_GetShape : Error" << "\n";
356 //=======================================================================
359 //=======================================================================
361 static Standard_Integer Collect (Draw_Interpretor& di,
365 TNaming_MapOfNamedShape MNS;
366 Handle(TNaming_NamedShape) A;
367 Standard_Boolean OnlyModif = 1;
371 if (!DDF::GetDF(arg[1],DF)) return 1;
372 if (!DDF::Find(DF,arg[2],TNaming_NamedShape::GetID(),A)) return 1;
374 OnlyModif = atoi(arg[3]);
376 TNaming_Tool::Collect(A,MNS,OnlyModif);
377 for (TNaming_MapIteratorOfMapOfNamedShape it(MNS); it.More(); it.Next()) {
378 TCollection_AsciiString Name;
379 TDF_Tool::Entry(it.Key()->Label(),Name);
380 di <<Name.ToCString()<<" ";
385 //=======================================================================
386 //function : GetCreationEntry
387 //purpose : retrive label of Primitive or a Generated shape
388 //=======================================================================
389 static Standard_Integer Getcreationentry (Draw_Interpretor& di, Standard_Integer n, const char** a)
393 // Handle(TNaming_UsedShapes) US;
395 if (!DDF::GetDF(a[1],ND)) return 1;
396 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
398 TopoDS_Shape SS = DBRep::Get(a[2]);
401 di <<"Noone shape selected"<<"\n";
406 TDF_LabelList Labels;
407 TopoDS_Shape S = TNaming_Tool::InitialShape(SS, ND->Root(), Labels);
413 Standard_Integer Status ;
415 TCollection_AsciiString Name = DNaming::GetEntry(S,ND,Status);
420 di <<Name.ToCString();
422 di <<"Several shapes have the same name"<<"\n";
428 //=======================================================================
429 //function : ImportShape
430 //purpose : "ImportShape Doc entry Shape Name"
431 //=======================================================================
433 static Standard_Integer DNaming_ImportShape (Draw_Interpretor& di,
438 Handle(TDF_Data) aDF;
439 if(!DDF::GetDF(a[1], aDF)) return 1;
441 DDF::AddLabel(aDF, a[2], L);
442 const TopoDS_Shape& aShape = DBRep::Get(a[3]);
443 if(aShape.IsNull()) return 1;
445 TDataStd_Name::Set(L, a[4]);
448 DNaming::LoadImportedShape(L, aShape);
450 DDF::ReturnLabel(di, L);
453 cout << "DNaming_NewShape : Error" << endl;
457 //=======================================================================
458 //function : BasicCommands
460 //=======================================================================
462 void DNaming::BasicCommands(Draw_Interpretor& theCommands)
464 static Standard_Boolean done = Standard_False;
466 done = Standard_True;
468 const char* g = "Naming data commands";
471 theCommands.Add("Ascendants", "Ascendants df shape [trans]", __FILE__,Ascendants, g);
472 theCommands.Add("Descendants", "Descendants df shape [trans]", __FILE__,Descendants, g);
473 theCommands.Add("ExploreShape","ExploreShape df entry res [trans]",__FILE__,Exploreshape, g);
474 theCommands.Add("GetEntry", "GetEntry df shape", __FILE__,Getentry, g);
475 theCommands.Add("GetCreationEntry", "GetCreationEntry df shape",__FILE__,Getcreationentry,g);
476 theCommands.Add("NamedShape", "NamedShape df shape", __FILE__,NamedShape, g);
477 theCommands.Add("InitialShape","InitialShape df shape res", __FILE__,Initialshape, g);
478 theCommands.Add("CurrentShape","Currentshape df entry [drawname]", __FILE__,Currentshape, g);
479 theCommands.Add("GetShape", "GetShape df entry [drawname]", __FILE__,Getshape , g);
480 theCommands.Add("Collect", "Collect df entry [onlymodif 0/1]",__FILE__,Collect , g);
481 theCommands.Add ("GeneratedShape", "Generatedshape df shape Generationentry [drawname]", __FILE__,Generatedshape,g);
482 theCommands.Add("ImportShape", "ImportShape Doc Entry Shape [Name]",__FILE__,DNaming_ImportShape, g);