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_Tool.hxx>
24 #include <TNaming.hxx>
25 #include <TNaming_NewShapeIterator.hxx>
26 #include <TNaming_OldShapeIterator.hxx>
27 #include <TNaming_Iterator.hxx>
28 #include <TNaming_Tool.hxx>
29 #include <TNaming_MapOfNamedShape.hxx>
31 #include <Draw_Interpretor.hxx>
32 #include <TopoDS_Shape.hxx>
40 // POP : first Wrong Declaration : now it is correct
42 //extern void QADNaming_BuildMap(TDF_LabelMap& Updated, const TDF_Label& Lab);
45 //=======================================================================
46 //function : Ascendants
48 //=======================================================================
50 static Standard_Integer Ascendants (Draw_Interpretor& di, Standard_Integer n, const char ** a)
57 // Handle(TNaming_UsedShapes) US;
59 if (!DDF::GetDF(a[1],ND)) return 1;
60 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
62 TopoDS_Shape S = DBRep::Get (a[2]);
63 if (S.IsNull ()) return 1;
67 if (n > 3) T = Draw::Atoi(a[3]);
68 else T = ND->Transaction ();
70 //TNaming_OldShapeIterator it (S, T, US);
71 TNaming_OldShapeIterator it (S, T, ND->Root());
72 Standard_Integer i = 0;
73 TCollection_AsciiString entry;
74 for (;it.More (); it.Next ()) {
76 Sprintf (name,"%s_%s_%d",a[2],"old", i++);
77 DBRep::Set (name,it.Shape());
78 TDF_Label Label = it.Label ();
79 TDF_Tool::Entry(Label,entry);
80 di<<entry.ToCString()<<"\n";
86 //=======================================================================
87 //function : Descendants
89 //=======================================================================
91 static Standard_Integer Descendants (Draw_Interpretor& di, Standard_Integer n, const char ** a)
98 // Handle(TNaming_UsedShapes) US;
99 if (!DDF::GetDF(a[1],ND)) return 1;
100 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
103 TopoDS_Shape S = DBRep::Get (a[2]);
104 if (S.IsNull ()) return 1;
108 if (n > 3) T = Draw::Atoi(a[3]);
109 else T = ND->Transaction ();
111 TNaming_NewShapeIterator it (S, T, ND->Root());
112 Standard_Integer i = 0;
113 TCollection_AsciiString entry;
114 for (;it.More (); it.Next ()) {
116 Sprintf (name,"%s_%s_%d",a[2],"new", i++);
117 DBRep::Set (name,it.Shape ());
118 TDF_Label Label = it.Label ();
119 TDF_Tool::Entry(Label,entry);
120 di<<entry.ToCString()<<"\n";
126 //=======================================================================
127 //function : GetEntry
129 //=======================================================================
131 static Standard_Integer Getentry (Draw_Interpretor& di, Standard_Integer n, const char ** a)
135 // Handle(TNaming_UsedShapes) US;
137 if (!DDF::GetDF(a[1],ND)) return 1;
138 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
140 TopoDS_Shape S = DBRep::Get(a[2]);
142 di <<"No shape selected\n";
146 Standard_Integer aStatus = 0;
147 TCollection_AsciiString Name = QADNaming::GetEntry (S, ND, aStatus);
152 di <<Name.ToCString();
154 di <<"Several shapes have the same name\n";
160 //=======================================================================
161 //function : NamedShape
162 //purpose : retrieve label of Primitive or a Generated shape
163 //=======================================================================
165 static Standard_Integer NamedShape(Draw_Interpretor& di, Standard_Integer n, const char ** a)
169 // Handle(TNaming_UsedShapes) US;
171 if (!DDF::GetDF(a[1],ND)) return 1;
172 TopoDS_Shape SS = DBRep::Get(a[2]);
174 di <<"No shape selected\n";
179 Handle(TNaming_NamedShape) NS = TNaming_Tool::NamedShape (SS,ND->Root());
185 TCollection_AsciiString Name; TDF_Tool::Entry(NS->Label(),Name);
186 di <<Name.ToCString();
190 //=======================================================================
191 //function : Currentshape
193 //=======================================================================
195 static Standard_Integer Currentshape (Draw_Interpretor& , Standard_Integer n, const char ** a)
200 if (!DDF::GetDF(a[1],ND)) return 1;
202 Standard_CString LabelName = a[2];
203 TopoDS_Shape S = QADNaming::CurrentShape(LabelName,ND);
205 if (n == 4) DBRep::Set(a[3],S);
206 else DBRep::Set(a[2],S);
212 //=======================================================================
213 //function : Initialshape
215 //=======================================================================
217 static Standard_Integer Initialshape (Draw_Interpretor& di, Standard_Integer n, const char ** a)
223 if (!DDF::GetDF(a[1],ND)) return 1;
225 TopoDS_Shape NS = DBRep::Get(a[2]);
226 if (NS.IsNull()) return 1;
228 TDF_LabelList Labels;
229 TopoDS_Shape S = TNaming_Tool::InitialShape (NS,ND->Root(),Labels);
231 DBRep::Set (a[3], S);
233 TDF_ListIteratorOfLabelList itL(Labels);
235 TCollection_AsciiString entry;
237 TDF_Tool::Entry(itL.Value(),entry);
238 di << entry.ToCString();
241 for (; itL.More(); itL.Next()) {
242 TDF_Tool::Entry(itL.Value(),entry);
243 di <<" , "<< entry.ToCString();
249 //=======================================================================
250 //function : GetShape
252 //=======================================================================
254 static Standard_Integer Exploreshape (Draw_Interpretor& di, Standard_Integer n, const char ** a)
260 // Handle(TNaming_UsedShapes) US;
262 if (!DDF::GetDF(a[1],ND)) return 1;
263 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
265 Standard_Integer Trans = ND->Transaction();
266 if (n == 5) { Trans = (Standard_Integer ) Draw::Atof(a[4]);}
269 DDF::FindLabel(ND,a[2],Lab);
270 Handle(TNaming_NamedShape) NS;
271 if (!Lab.FindAttribute(TNaming_NamedShape::GetID(),NS)) {
276 //TNaming::Print(NS->Evolution(),std::cout);
277 Standard_SStream aSStream;
278 TNaming::Print(NS->Evolution(),aSStream);
281 Standard_Integer NbShapes = 1;
283 for (TNaming_Iterator itL(Lab,Trans) ; itL.More(); itL.Next()) {
284 if (!itL.OldShape().IsNull()) {
285 Sprintf(name,"%s%s_%d","old",a[3],NbShapes);
286 DBRep::Set (name,itL.OldShape());
288 if (!itL.NewShape().IsNull()) {
289 Sprintf(name,"%s_%d",a[3],NbShapes);
290 DBRep::Set (name,itL.NewShape());
302 //=======================================================================
303 //function : GeneratedShape
304 //purpose : Generatedshape df shape Generationentry [drawname]
305 //=======================================================================
307 static Standard_Integer Generatedshape (Draw_Interpretor& di,
312 Handle(TNaming_NamedShape) A;
315 if (!DDF::GetDF(arg[1],DF)) return 1;
316 TopoDS_Shape Gen = DBRep::Get(arg[2]);
317 Handle(TNaming_NamedShape) Generation;
318 if (!DDF::Find(DF,arg[3],TNaming_NamedShape::GetID(),Generation)) return 1;
319 S = TNaming_Tool::GeneratedShape(Gen,Generation);
321 if (nb == 4) DBRep::Set(arg[4],S);
322 else DBRep::Set(arg[3],S);
326 di << "GetShape : Error\n";
330 //=======================================================================
331 //function : DDataStd_GetShape
333 //=======================================================================
335 static Standard_Integer Getshape (Draw_Interpretor& di,
340 Handle(TNaming_NamedShape) A;
343 if (!DDF::GetDF(arg[1],DF)) return 1;
344 if (!DDF::Find(DF,arg[2],TNaming_NamedShape::GetID(),A)) return 1;
345 s = TNaming_Tool::GetShape(A);
347 if (nb == 4) DBRep::Set(arg[3],s);
348 else DBRep::Set(arg[2],s);
352 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 = Draw::Atoi(arg[3]) != 0;
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()<<" ";
386 //=======================================================================
387 //function : GetCreationEntry
388 //purpose : retrieve label of Primitive or a Generated shape
389 //=======================================================================
391 static Standard_Integer Getcreationentry (Draw_Interpretor& di, Standard_Integer n, const char ** a)
395 // Handle(TNaming_UsedShapes) US;
397 if (!DDF::GetDF(a[1],ND)) return 1;
398 // ND->Root().FindAttribute(TNaming_UsedShapes::GetID(),US);
400 TopoDS_Shape SS = DBRep::Get(a[2]);
403 di <<"No shape selected\n";
408 TDF_LabelList Labels;
409 TopoDS_Shape S = TNaming_Tool::InitialShape(SS, ND->Root(), Labels);
415 Standard_Integer aStatus = 0;
416 TCollection_AsciiString Name = QADNaming::GetEntry (S, ND, aStatus);
421 di <<Name.ToCString();
423 di <<"Several shapes have the same name\n";
430 //=======================================================================
431 //function : BasicCommands
433 //=======================================================================
435 void QADNaming::BasicCommands(Draw_Interpretor& theCommands)
437 static Standard_Boolean done = Standard_False;
439 done = Standard_True;
441 const char* g = "Naming data commands";
444 theCommands.Add("Ascendants", "Ascendants df shape [trans]", __FILE__,Ascendants, g);
446 theCommands.Add("Descendants", "Descendants df shape [trans]", __FILE__,Descendants, g);
448 theCommands.Add("ExploreShape","ExploreShape df entry res [trans]",__FILE__,Exploreshape, g);
450 theCommands.Add("GetEntry", "GetEntry df shape", __FILE__,Getentry, g);
452 theCommands.Add("GetCreationEntry", "GetCreationEntry df shape",__FILE__,Getcreationentry,g);
454 theCommands.Add("NamedShape", "NamedShape df shape", __FILE__,NamedShape, g);
456 theCommands.Add("InitialShape","InitialShape df shape res", __FILE__,Initialshape, g);
458 theCommands.Add("CurrentShape","Currentshape df entry [drawname]", __FILE__,Currentshape, g);
460 theCommands.Add("GetShape", "GetShape df entry [drawname]", __FILE__,Getshape , g);
462 theCommands.Add("Collect", "Collect df entry [onlymodif 0/1]",__FILE__,Collect , g);
464 theCommands.Add ("GeneratedShape",
465 "Generatedshape df shape Generationentry [drawname]",
466 __FILE__,Generatedshape,g);