1 // Created on: 2002-04-25
2 // Created by: Michael PONIKAROV
3 // Copyright (c) 2002-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
18 #include <QADNaming.hxx>
19 #include <TDF_Label.hxx>
20 #include <Draw_Interpretor.hxx>
21 #include <TNaming_Iterator.hxx>
22 #include <TNaming_NewShapeIterator.hxx>
23 #include <TNaming_OldShapeIterator.hxx>
24 #include <TNaming_SameShapeIterator.hxx>
25 #include <TNaming_Tool.hxx>
26 #include <TopoDS_Shape.hxx>
28 #include <TNaming.hxx>
29 #include <TNaming_NamedShape.hxx>
33 #include <TDF_Data.hxx>
34 #include <TDF_Tool.hxx>
36 static const char* EvolutionString(TNaming_Evolution theEvolution) {
38 case TNaming_PRIMITIVE :
40 case TNaming_GENERATED :
46 case TNaming_SELECTED :
48 case TNaming_REPLACE :
51 return "UNKNOWN_Evolution";
55 static Standard_Integer GetNewShapes (Draw_Interpretor& di,
60 if (!QADNaming::Entry(arg, aLabel)) return 1;
61 Handle(TNaming_NamedShape) aNS;
62 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
63 di<<"Label has no NamedShape\n";
66 di<<EvolutionString(aNS->Evolution());
67 TNaming_Iterator anIter(aNS);
70 for(a=1;anIter.More();anIter.Next(),a++) {
71 if (anIter.NewShape().IsNull()) a--;
73 Sprintf(aName,"%s_%d",arg[3],a);
74 DBRep::Set (aName,anIter.NewShape());
79 di<<"Usage: GetNewShapes df entry [res]\n";
85 static Standard_Integer GetOldShapes (Draw_Interpretor& di,
90 if (!QADNaming::Entry(arg, aLabel)) return 1;
91 Handle(TNaming_NamedShape) aNS;
92 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
93 di<<"Label has no NamedShape\n";
96 di<<EvolutionString(aNS->Evolution());
97 TNaming_Iterator anIter(aNS);
100 for(a=1;anIter.More();anIter.Next(),a++) {
101 if (anIter.OldShape().IsNull()) a--;
103 Sprintf(aName,"%s_%d",arg[3],a);
104 DBRep::Set (aName,anIter.OldShape());
109 di<<"Usage: GetOldShapes df entry [res]\n";
115 static int GetAllNew(const TopoDS_Shape& theShape, const TDF_Label& theAccess,
116 const TCollection_AsciiString& theName, Standard_Integer theIndex)
118 TNaming_NewShapeIterator anIter(theShape,theAccess);
119 TCollection_AsciiString aName;
120 for(;anIter.More();anIter.Next())
122 if (!anIter.Shape().IsNull())
125 if (!theName.IsEmpty())
127 aName = theName + "_" + theIndex;
128 DBRep::Set(aName.ToCString(),anIter.Shape());
130 theIndex = GetAllNew(anIter.Shape(),theAccess,theName,theIndex);
136 static Standard_Integer GetAllNewShapes (Draw_Interpretor& di,
139 Standard_Integer aResult = 0;
140 if (nb==3 || nb==4) {
141 TCollection_AsciiString aName ((nb==4) ? arg[3] : "");
143 if (arg[2][0]=='0') { // label
145 if (!QADNaming::Entry(arg, aLabel)) return 1;
146 Handle(TNaming_NamedShape) aNS;
147 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
148 di<<"Label has no NamedShape\n";
152 TNaming_Iterator anIter(aNS);
153 for(a=1;anIter.More();anIter.Next(),a++) {
154 if (!anIter.NewShape().IsNull()) {
155 TCollection_AsciiString aSubName;
156 if (!aName.IsEmpty())
158 aSubName += aName + "_";
161 aResult+=GetAllNew(anIter.NewShape(),aLabel,aSubName,0);
166 if (!DDF::GetDF(arg[1],DF)) {
170 TopoDS_Shape aShape = DBRep::Get(arg[2]);
171 aResult=GetAllNew(aShape,DF->Root(),aName,0);
174 di<<"Usage: GetAllNewShapes df entry/shape [res]\n";
181 static int GetAllOld(const TopoDS_Shape& theShape, const TDF_Label& theAccess,
182 const TCollection_AsciiString& theName, Standard_Integer theIndex)
184 TCollection_AsciiString aName;
185 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(theShape,theAccess);
186 if (aNS.IsNull()) return theIndex;
187 TNaming_Iterator anIter(aNS);
188 for(;anIter.More();anIter.Next())
190 if (!anIter.OldShape().IsNull() && !anIter.NewShape().IsNull()) if (anIter.NewShape().IsSame(theShape))
193 if (!theName.IsEmpty())
195 aName = theName + "_" + theIndex;
196 DBRep::Set(aName.ToCString(),anIter.OldShape());
198 theIndex = GetAllOld(anIter.OldShape(),theAccess,theName,theIndex);
204 static Standard_Integer GetAllOldShapes (Draw_Interpretor& di,
207 Standard_Integer aResult = 0;
208 if (nb==3 || nb==4) {
209 TCollection_AsciiString aName((nb==4) ? arg[3] : "");
211 if (arg[2][0]=='0') { // label
213 if (!QADNaming::Entry(arg, aLabel)) return 1;
214 Handle(TNaming_NamedShape) aNS;
215 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
216 di<<"Label has no NamedShape\n";
220 TNaming_Iterator anIter(aNS);
221 for(a=1;anIter.More();anIter.Next(),a++) {
222 if (!anIter.NewShape().IsNull()) {
223 TCollection_AsciiString aSubName;
224 if (!aName.IsEmpty())
226 aSubName += aName + "_";
229 aResult+=GetAllOld(anIter.NewShape(),aLabel,aSubName,0);
234 if (!DDF::GetDF(arg[1],DF)) {
238 TopoDS_Shape aShape = DBRep::Get(arg[2]);
239 aResult=GetAllOld(aShape,DF->Root(),aName,0);
242 di<<"Usage: GetAllNewShapes df entry/shape [res]\n";
249 static Standard_Integer GetSameShapes (Draw_Interpretor& di,
252 TCollection_AsciiString aRes;
254 Standard_Integer aResult = 0;
256 if (!DDF::GetDF(arg[1],DF)) {
260 TopoDS_Shape aShape = DBRep::Get(arg[2]);
261 TNaming_SameShapeIterator anIter(aShape,DF->Root());
262 for(;anIter.More();anIter.Next()) {
263 if (!anIter.Label().IsNull()) {
264 TCollection_AsciiString Name;
265 TDF_Tool::Entry(anIter.Label(),Name);
266 if (aResult != 0) aRes=aRes+Name+" "; else aRes=Name;
271 di<<"Usage: GetSameShapes df shape\n";
274 di<<aRes.ToCString();
278 void QADNaming::IteratorsCommands(Draw_Interpretor& theCommands)
280 static Standard_Boolean done = Standard_False;
282 done = Standard_True;
284 const char* g = "Naming builder commands";
286 theCommands.Add("GetNewShapes","GetNewShapes df entry [res]",__FILE__,GetNewShapes,g);
288 theCommands.Add("GetOldShapes","GetOldShapes df entry [res]",__FILE__,GetOldShapes,g);
290 theCommands.Add("GetAllNewShapes","GetAllNewShapes df entry/shape [res]",__FILE__,GetAllNewShapes,g);
292 theCommands.Add("GetAllOldShapes","GetAllOldShapes df entry/shape [res]",__FILE__,GetAllOldShapes,g);
294 theCommands.Add("GetSameShapes","GetSameShapes df shape",__FILE__,GetSameShapes,g);