1 // Created on: 1997-01-13
2 // Created by: VAUTHIER Jean-Claude
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <QADNaming.hxx>
18 #include <TCollection_AsciiString.hxx>
19 #include <TDF_Data.hxx>
20 #include <TDF_ListIteratorOfLabelList.hxx>
21 #include <TDF_LabelList.hxx>
22 #include <TDF_LabelMap.hxx>
23 #include <TDF_Tool.hxx>
27 #include <TNaming.hxx>
28 #include <TNaming_NamedShape.hxx>
29 #include <TNaming_NewShapeIterator.hxx>
30 #include <TNaming_OldShapeIterator.hxx>
31 #include <TNaming_Iterator.hxx>
32 #include <TNaming_Tool.hxx>
33 #include <TNaming_MapOfNamedShape.hxx>
34 #include <TNaming_MapIteratorOfMapOfNamedShape.hxx>
35 #include <Draw_Drawable3D.hxx>
37 #include <Draw_Interpretor.hxx>
38 #include <TopTools_ListOfShape.hxx>
39 #include <TopTools_ListIteratorOfListOfShape.hxx>
40 #include <TopTools_DataMapOfShapeShape.hxx>
41 #include <TopoDS_Shape.hxx>
50 #include <gp_Trsf.hxx>
52 #include <TColStd_HArray1OfInteger.hxx>
57 // POP : first Wrong Declaration : now it is correct
59 //extern void QADNaming_BuildMap(TDF_LabelMap& Updated, const TDF_Label& Lab);
62 //=======================================================================
63 //function : Ascendants
65 //=======================================================================
67 static Standard_Integer Ascendants (Draw_Interpretor& di, Standard_Integer n, const char ** a)
74 // Handle(TNaming_UsedShapes) US;
76 if (!DDF::GetDF(a[1],ND)) return 1;
77 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
79 TopoDS_Shape S = DBRep::Get (a[2]);
80 if (S.IsNull ()) return 1;
84 if (n > 3) T = Draw::Atoi(a[3]);
85 else T = ND->Transaction ();
87 //TNaming_OldShapeIterator it (S, T, US);
88 TNaming_OldShapeIterator it (S, T, ND->Root());
89 Standard_Integer i = 0;
90 TCollection_AsciiString entry;
91 for (;it.More (); it.Next ()) {
93 Sprintf (name,"%s_%s_%d",a[2],"old", i++);
94 DBRep::Set (name,it.Shape());
95 TDF_Label Label = it.Label ();
96 TDF_Tool::Entry(Label,entry);
97 di<<entry.ToCString()<<"\n";
103 //=======================================================================
104 //function : Descendants
106 //=======================================================================
108 static Standard_Integer Descendants (Draw_Interpretor& di, Standard_Integer n, const char ** a)
115 // Handle(TNaming_UsedShapes) US;
116 if (!DDF::GetDF(a[1],ND)) return 1;
117 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
120 TopoDS_Shape S = DBRep::Get (a[2]);
121 if (S.IsNull ()) return 1;
125 if (n > 3) T = Draw::Atoi(a[3]);
126 else T = ND->Transaction ();
128 TNaming_NewShapeIterator it (S, T, ND->Root());
129 Standard_Integer i = 0;
130 TCollection_AsciiString entry;
131 for (;it.More (); it.Next ()) {
133 Sprintf (name,"%s_%s_%d",a[2],"new", i++);
134 DBRep::Set (name,it.Shape ());
135 TDF_Label Label = it.Label ();
136 TDF_Tool::Entry(Label,entry);
137 di<<entry.ToCString()<<"\n";
143 //=======================================================================
144 //function : GetEntry
146 //=======================================================================
148 static Standard_Integer Getentry (Draw_Interpretor& di, Standard_Integer n, const char ** a)
152 // Handle(TNaming_UsedShapes) US;
154 if (!DDF::GetDF(a[1],ND)) return 1;
155 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
157 TopoDS_Shape S = DBRep::Get(a[2]);
159 di <<"Noone shape selected\n";
163 Standard_Integer aStatus = 0;
164 TCollection_AsciiString Name = QADNaming::GetEntry (S, ND, aStatus);
169 di <<Name.ToCString();
171 di <<"Several shapes have the same name\n";
177 //=======================================================================
178 //function : NamedShape
179 //purpose : retrive label of Primitive or a Generated shape
180 //=======================================================================
182 static Standard_Integer NamedShape(Draw_Interpretor& di, Standard_Integer n, const char ** a)
186 // Handle(TNaming_UsedShapes) US;
188 if (!DDF::GetDF(a[1],ND)) return 1;
189 TopoDS_Shape SS = DBRep::Get(a[2]);
191 di <<"Noone shape selected\n";
196 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape (SS,ND->Root());
202 TCollection_AsciiString Name; TDF_Tool::Entry(NS->Label(),Name);
203 di <<Name.ToCString();
207 //=======================================================================
208 //function : Currentshape
210 //=======================================================================
212 static Standard_Integer Currentshape (Draw_Interpretor& , Standard_Integer n, const char ** a)
217 if (!DDF::GetDF(a[1],ND)) return 1;
219 Standard_CString LabelName = a[2];
220 TopoDS_Shape S = QADNaming::CurrentShape(LabelName,ND);
222 if (n == 4) DBRep::Set(a[3],S);
223 else DBRep::Set(a[2],S);
229 //=======================================================================
230 //function : Initialshape
232 //=======================================================================
234 static Standard_Integer Initialshape (Draw_Interpretor& di, Standard_Integer n, const char ** a)
240 if (!DDF::GetDF(a[1],ND)) return 1;
242 TopoDS_Shape NS = DBRep::Get(a[2]);
243 if (NS.IsNull()) return 1;
245 TDF_LabelList Labels;
246 TopoDS_Shape S = TNaming_Tool::InitialShape (NS,ND->Root(),Labels);
248 DBRep::Set (a[3], S);
250 TDF_ListIteratorOfLabelList itL(Labels);
252 TCollection_AsciiString entry;
254 TDF_Tool::Entry(itL.Value(),entry);
255 di << entry.ToCString();
258 for (; itL.More(); itL.Next()) {
259 TDF_Tool::Entry(itL.Value(),entry);
260 di <<" , "<< entry.ToCString();
266 //=======================================================================
267 //function : GetShape
269 //=======================================================================
271 static Standard_Integer Exploreshape (Draw_Interpretor& di, Standard_Integer n, const char ** a)
277 // Handle(TNaming_UsedShapes) US;
279 if (!DDF::GetDF(a[1],ND)) return 1;
280 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
282 Standard_Integer Trans = ND->Transaction();
283 if (n == 5) { Trans = (Standard_Integer ) Draw::Atof(a[4]);}
286 DDF::FindLabel(ND,a[2],Lab);
287 Handle(TNaming_NamedShape) NS;
288 if (!Lab.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
293 //TNaming::Print(NS->Evolution(),std::cout);
294 Standard_SStream aSStream;
295 TNaming::Print(NS->Evolution(),aSStream);
298 Standard_Integer NbShapes = 1;
300 for (TNaming_Iterator itL(Lab,Trans) ; itL.More(); itL.Next()) {
301 if (!itL.OldShape().IsNull()) {
302 Sprintf(name,"%s%s_%d","old",a[3],NbShapes);
303 DBRep::Set (name,itL.OldShape());
305 if (!itL.NewShape().IsNull()) {
306 Sprintf(name,"%s_%d",a[3],NbShapes);
307 DBRep::Set (name,itL.NewShape());
319 //=======================================================================
320 //function : GeneratedShape
321 //purpose : Generatedshape df shape Generationentry [drawname]
322 //=======================================================================
324 static Standard_Integer Generatedshape (Draw_Interpretor& di,
329 Handle(TNaming_NamedShape) A;
332 if (!DDF::GetDF(arg[1],DF)) return 1;
333 TopoDS_Shape Gen = DBRep::Get(arg[2]);
334 Handle(TNaming_NamedShape) Generation;
335 if (!DDF::Find(DF,arg[3],TNaming_NamedShape::GetID(),Generation)) return 1;
336 S = TNaming_Tool::GeneratedShape(Gen,Generation);
338 if (nb == 4) DBRep::Set(arg[4],S);
339 else DBRep::Set(arg[3],S);
343 di << "GetShape : Error\n";
347 //=======================================================================
348 //function : DDataStd_GetShape
350 //=======================================================================
352 static Standard_Integer Getshape (Draw_Interpretor& di,
357 Handle(TNaming_NamedShape) A;
360 if (!DDF::GetDF(arg[1],DF)) return 1;
361 if (!DDF::Find(DF,arg[2],TNaming_NamedShape::GetID(),A)) return 1;
362 s = TNaming_Tool::GetShape(A);
364 if (nb == 4) DBRep::Set(arg[3],s);
365 else DBRep::Set(arg[2],s);
369 di << "DDataStd_GetShape : Error\n";
373 //=======================================================================
376 //=======================================================================
378 static Standard_Integer Collect (Draw_Interpretor& di,
382 TNaming_MapOfNamedShape MNS;
383 Handle(TNaming_NamedShape) A;
384 Standard_Boolean OnlyModif = 1;
388 if (!DDF::GetDF(arg[1],DF)) return 1;
389 if (!DDF::Find(DF,arg[2],TNaming_NamedShape::GetID(),A)) return 1;
391 OnlyModif = Draw::Atoi(arg[3]) != 0;
393 TNaming_Tool::Collect(A,MNS,OnlyModif);
394 for (TNaming_MapIteratorOfMapOfNamedShape it(MNS); it.More(); it.Next()) {
395 TCollection_AsciiString Name;
396 TDF_Tool::Entry(it.Key()->Label(),Name);
397 di <<Name.ToCString()<<" ";
403 //=======================================================================
404 //function : GetCreationEntry
405 //purpose : retrive label of Primitive or a Generated shape
406 //=======================================================================
408 static Standard_Integer Getcreationentry (Draw_Interpretor& di, Standard_Integer n, const char ** a)
412 // Handle(TNaming_UsedShapes) US;
414 if (!DDF::GetDF(a[1],ND)) return 1;
415 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
417 TopoDS_Shape SS = DBRep::Get(a[2]);
420 di <<"Noone shape selected\n";
425 TDF_LabelList Labels;
426 TopoDS_Shape S = TNaming_Tool::InitialShape(SS, ND->Root(), Labels);
432 Standard_Integer aStatus = 0;
433 TCollection_AsciiString Name = QADNaming::GetEntry (S, ND, aStatus);
438 di <<Name.ToCString();
440 di <<"Several shapes have the same name\n";
447 //=======================================================================
448 //function : BasicCommands
450 //=======================================================================
452 void QADNaming::BasicCommands(Draw_Interpretor& theCommands)
454 static Standard_Boolean done = Standard_False;
456 done = Standard_True;
458 const char* g = "Naming data commands";
461 theCommands.Add("Ascendants", "Ascendants df shape [trans]", __FILE__,Ascendants, g);
463 theCommands.Add("Descendants", "Descendants df shape [trans]", __FILE__,Descendants, g);
465 theCommands.Add("ExploreShape","ExploreShape df entry res [trans]",__FILE__,Exploreshape, g);
467 theCommands.Add("GetEntry", "GetEntry df shape", __FILE__,Getentry, g);
469 theCommands.Add("GetCreationEntry", "GetCreationEntry df shape",__FILE__,Getcreationentry,g);
471 theCommands.Add("NamedShape", "NamedShape df shape", __FILE__,NamedShape, g);
473 theCommands.Add("InitialShape","InitialShape df shape res", __FILE__,Initialshape, g);
475 theCommands.Add("CurrentShape","Currentshape df entry [drawname]", __FILE__,Currentshape, g);
477 theCommands.Add("GetShape", "GetShape df entry [drawname]", __FILE__,Getshape , g);
479 theCommands.Add("Collect", "Collect df entry [onlymodif 0/1]",__FILE__,Collect , g);
481 theCommands.Add ("GeneratedShape",
482 "Generatedshape df shape Generationentry [drawname]",
483 __FILE__,Generatedshape,g);