1 // Created on: 2002-04-25
2 // Created by: Michael PONIKAROV
3 // Copyright (c) 2002-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
23 #include <QADNaming.hxx>
24 #include <TDF_Label.hxx>
25 #include <Draw_Interpretor.hxx>
26 #include <TNaming_Iterator.hxx>
27 #include <TNaming_NewShapeIterator.hxx>
28 #include <TNaming_OldShapeIterator.hxx>
29 #include <TNaming_SameShapeIterator.hxx>
30 #include <TNaming_Tool.hxx>
31 #include <TopoDS_Shape.hxx>
33 #include <TNaming.hxx>
34 #include <TNaming_NamedShape.hxx>
38 #include <TDF_Data.hxx>
39 #include <TDF_Tool.hxx>
41 static const char* EvolutionString(TNaming_Evolution theEvolution) {
43 case TNaming_PRIMITIVE :
45 case TNaming_GENERATED :
51 case TNaming_SELECTED :
53 // case TNaming_REPLACE :
56 return "UNKNOWN_Evolution";
60 static Standard_Integer GetNewShapes (Draw_Interpretor& di,
65 if (!QADNaming::Entry(arg, aLabel)) return 1;
66 Handle(TNaming_NamedShape) aNS;
67 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
68 di<<"Label has no NamedShape"<<"\n";
71 di<<EvolutionString(aNS->Evolution());
72 TNaming_Iterator anIter(aNS);
75 for(a=1;anIter.More();anIter.Next(),a++) {
76 if (anIter.NewShape().IsNull()) a--;
78 Sprintf(aName,"%s_%d",arg[3],a);
79 DBRep::Set (aName,anIter.NewShape());
84 di<<"Usage: GetNewShapes df entry [res]"<<"\n";
90 static Standard_Integer GetOldShapes (Draw_Interpretor& di,
95 if (!QADNaming::Entry(arg, aLabel)) return 1;
96 Handle(TNaming_NamedShape) aNS;
97 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
98 di<<"Label has no NamedShape"<<"\n";
101 di<<EvolutionString(aNS->Evolution());
102 TNaming_Iterator anIter(aNS);
105 for(a=1;anIter.More();anIter.Next(),a++) {
106 if (anIter.OldShape().IsNull()) a--;
108 Sprintf(aName,"%s_%d",arg[3],a);
109 DBRep::Set (aName,anIter.OldShape());
114 di<<"Usage: GetOldShapes df entry [res]"<<"\n";
120 static int GetAllNew(const TopoDS_Shape& theShape, const TDF_Label& theAccess,
121 const TCollection_AsciiString& theName, Standard_Integer theIndex)
123 TNaming_NewShapeIterator anIter(theShape,theAccess);
124 TCollection_AsciiString aName;
125 for(;anIter.More();anIter.Next())
127 if (!anIter.Shape().IsNull())
130 if (!theName.IsEmpty())
132 aName = theName + "_" + theIndex;
133 DBRep::Set(aName.ToCString(),anIter.Shape());
135 theIndex = GetAllNew(anIter.Shape(),theAccess,theName,theIndex);
141 static Standard_Integer GetAllNewShapes (Draw_Interpretor& di,
144 Standard_Integer aResult = 0;
145 if (nb==3 || nb==4) {
146 TCollection_AsciiString aName ((nb==4) ? arg[3] : "");
148 if (arg[2][0]=='0') { // label
150 if (!QADNaming::Entry(arg, aLabel)) return 1;
151 Handle(TNaming_NamedShape) aNS;
152 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
153 di<<"Label has no NamedShape"<<"\n";
157 TNaming_Iterator anIter(aNS);
158 for(a=1;anIter.More();anIter.Next(),a++) {
159 if (!anIter.NewShape().IsNull()) {
160 TCollection_AsciiString aSubName;
161 if (!aName.IsEmpty())
163 aSubName += aName + "_";
166 aResult+=GetAllNew(anIter.NewShape(),aLabel,aSubName,0);
171 if (!DDF::GetDF(arg[1],DF)) {
172 di<<"Wrong df"<<"\n";
175 TopoDS_Shape aShape = DBRep::Get(arg[2]);
176 aResult=GetAllNew(aShape,DF->Root(),aName,0);
179 di<<"Usage: GetAllNewShapes df entry/shape [res]"<<"\n";
186 static int GetAllOld(const TopoDS_Shape& theShape, const TDF_Label& theAccess,
187 const TCollection_AsciiString& theName, Standard_Integer theIndex)
189 TCollection_AsciiString aName;
190 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(theShape,theAccess);
191 if (aNS.IsNull()) return theIndex;
192 TNaming_Iterator anIter(aNS);
193 for(;anIter.More();anIter.Next())
195 if (!anIter.OldShape().IsNull() && !anIter.NewShape().IsNull()) if (anIter.NewShape().IsSame(theShape))
198 if (!theName.IsEmpty())
200 aName = theName + "_" + theIndex;
201 DBRep::Set(aName.ToCString(),anIter.OldShape());
203 theIndex = GetAllOld(anIter.OldShape(),theAccess,theName,theIndex);
209 static Standard_Integer GetAllOldShapes (Draw_Interpretor& di,
212 Standard_Integer aResult = 0;
213 if (nb==3 || nb==4) {
214 TCollection_AsciiString aName((nb==4) ? arg[3] : "");
216 if (arg[2][0]=='0') { // label
218 if (!QADNaming::Entry(arg, aLabel)) return 1;
219 Handle(TNaming_NamedShape) aNS;
220 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
221 di<<"Label has no NamedShape"<<"\n";
225 TNaming_Iterator anIter(aNS);
226 for(a=1;anIter.More();anIter.Next(),a++) {
227 if (!anIter.NewShape().IsNull()) {
228 TCollection_AsciiString aSubName;
229 if (!aName.IsEmpty())
231 aSubName += aName + "_";
234 aResult+=GetAllOld(anIter.NewShape(),aLabel,aSubName,0);
239 if (!DDF::GetDF(arg[1],DF)) {
240 di<<"Wrong df"<<"\n";
243 TopoDS_Shape aShape = DBRep::Get(arg[2]);
244 aResult=GetAllOld(aShape,DF->Root(),aName,0);
247 di<<"Usage: GetAllNewShapes df entry/shape [res]"<<"\n";
254 static Standard_Integer GetSameShapes (Draw_Interpretor& di,
257 TCollection_AsciiString aRes;
259 Standard_Integer aResult = 0;
261 if (!DDF::GetDF(arg[1],DF)) {
262 di<<"Wrong df"<<"\n";
265 TopoDS_Shape aShape = DBRep::Get(arg[2]);
266 TNaming_SameShapeIterator anIter(aShape,DF->Root());
267 for(;anIter.More();anIter.Next()) {
268 if (!anIter.Label().IsNull()) {
269 TCollection_AsciiString Name;
270 TDF_Tool::Entry(anIter.Label(),Name);
271 if (aResult != 0) aRes=aRes+Name+" "; else aRes=Name;
276 di<<"Usage: GetSameShapes df shape"<<"\n";
279 di<<aRes.ToCString();
283 void QADNaming::IteratorsCommands(Draw_Interpretor& theCommands)
285 static Standard_Boolean done = Standard_False;
287 done = Standard_True;
289 const char* g = "Naming builder commands";
291 theCommands.Add("GetNewShapes","GetNewShapes df entry [res]",__FILE__,GetNewShapes,g);
293 theCommands.Add("GetOldShapes","GetOldShapes df entry [res]",__FILE__,GetOldShapes,g);
295 theCommands.Add("GetAllNewShapes","GetAllNewShapes df entry/shape [res]",__FILE__,GetAllNewShapes,g);
297 theCommands.Add("GetAllOldShapes","GetAllOldShapes df entry/shape [res]",__FILE__,GetAllOldShapes,g);
299 theCommands.Add("GetSameShapes","GetSameShapes df shape",__FILE__,GetSameShapes,g);