0024180: Eliminate CLang / GCC compiler warning -Wswitch
[occt.git] / src / QADNaming / QADNaming_IteratorsCommands.cxx
CommitLineData
b311480e 1// Created on: 2002-04-25
2// Created by: Michael PONIKAROV
3// Copyright (c) 2002-2012 OPEN CASCADE SAS
4//
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.
9//
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.
12//
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.
19
7fd59977 20
21#include <stdio.h>
22
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>
32#include <DBRep.hxx>
33#include <TNaming.hxx>
34#include <TNaming_NamedShape.hxx>
35
36#include <DDF.hxx>
37
38#include <TDF_Data.hxx>
39#include <TDF_Tool.hxx>
40
41static const char* EvolutionString(TNaming_Evolution theEvolution) {
42 switch(theEvolution){
43 case TNaming_PRIMITIVE :
44 return "PRIMITIVE";
45 case TNaming_GENERATED :
46 return "GENERATED";
47 case TNaming_MODIFY :
48 return "MODIFY";
49 case TNaming_DELETE :
50 return "DELETE";
51 case TNaming_SELECTED :
52 return "SELECTED";
566f8441 53 case TNaming_REPLACE :
54 return "MODIFY";
7fd59977 55 }
56 return "UNKNOWN_Evolution";
57}
58
59
60static Standard_Integer GetNewShapes (Draw_Interpretor& di,
61 Standard_Integer nb,
62 const char** arg) {
63 if (nb==3 || nb==4) {
64 TDF_Label aLabel;
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";
69 return 1;
70 }
71 di<<EvolutionString(aNS->Evolution());
72 TNaming_Iterator anIter(aNS);
73 Standard_Integer a;
74 char aName[200];
75 for(a=1;anIter.More();anIter.Next(),a++) {
76 if (anIter.NewShape().IsNull()) a--;
77 else if (nb==4) {
91322f44 78 Sprintf(aName,"%s_%d",arg[3],a);
7fd59977 79 DBRep::Set (aName,anIter.NewShape());
80 }
81 }
82 di<<" "<<a-1;
83 } else {
84 di<<"Usage: GetNewShapes df entry [res]"<<"\n";
85 return 1;
86 }
87 return 0;
88}
89
90static Standard_Integer GetOldShapes (Draw_Interpretor& di,
91 Standard_Integer nb,
92 const char** arg) {
93 if (nb==3 || nb==4) {
94 TDF_Label aLabel;
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";
99 return 1;
100 }
101 di<<EvolutionString(aNS->Evolution());
102 TNaming_Iterator anIter(aNS);
103 Standard_Integer a;
104 char aName[200];
105 for(a=1;anIter.More();anIter.Next(),a++) {
106 if (anIter.OldShape().IsNull()) a--;
107 else if (nb==4) {
91322f44 108 Sprintf(aName,"%s_%d",arg[3],a);
7fd59977 109 DBRep::Set (aName,anIter.OldShape());
110 }
111 }
112 di<<" "<<a-1;
113 } else {
114 di<<"Usage: GetOldShapes df entry [res]"<<"\n";
115 return 1;
116 }
117 return 0;
118}
119
f1e162f2 120static int GetAllNew(const TopoDS_Shape& theShape, const TDF_Label& theAccess,
121 const TCollection_AsciiString& theName, Standard_Integer theIndex)
122{
7fd59977 123 TNaming_NewShapeIterator anIter(theShape,theAccess);
f1e162f2 124 TCollection_AsciiString aName;
125 for(;anIter.More();anIter.Next())
126 {
127 if (!anIter.Shape().IsNull())
128 {
7fd59977 129 theIndex++;
f1e162f2 130 if (!theName.IsEmpty())
131 {
132 aName = theName + "_" + theIndex;
133 DBRep::Set(aName.ToCString(),anIter.Shape());
7fd59977 134 }
135 theIndex = GetAllNew(anIter.Shape(),theAccess,theName,theIndex);
136 }
137 }
138 return theIndex;
139}
140
141static Standard_Integer GetAllNewShapes (Draw_Interpretor& di,
142 Standard_Integer nb,
143 const char** arg) {
144 Standard_Integer aResult = 0;
145 if (nb==3 || nb==4) {
f1e162f2 146 TCollection_AsciiString aName ((nb==4) ? arg[3] : "");
7fd59977 147
148 if (arg[2][0]=='0') { // label
149 TDF_Label aLabel;
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";
154 return 1;
155 }
156 Standard_Integer a;
157 TNaming_Iterator anIter(aNS);
158 for(a=1;anIter.More();anIter.Next(),a++) {
159 if (!anIter.NewShape().IsNull()) {
f1e162f2 160 TCollection_AsciiString aSubName;
161 if (!aName.IsEmpty())
162 {
163 aSubName += aName + "_";
164 aSubName += a;
165 }
166 aResult+=GetAllNew(anIter.NewShape(),aLabel,aSubName,0);
7fd59977 167 }
168 }
169 } else { // shape
170 Handle(TDF_Data) DF;
171 if (!DDF::GetDF(arg[1],DF)) {
172 di<<"Wrong df"<<"\n";
173 return 1;
174 }
175 TopoDS_Shape aShape = DBRep::Get(arg[2]);
176 aResult=GetAllNew(aShape,DF->Root(),aName,0);
177 }
178 } else {
179 di<<"Usage: GetAllNewShapes df entry/shape [res]"<<"\n";
180 return 1;
181 }
182 di<<aResult;
183 return 0;
184}
185
f1e162f2 186static int GetAllOld(const TopoDS_Shape& theShape, const TDF_Label& theAccess,
187 const TCollection_AsciiString& theName, Standard_Integer theIndex)
188{
189 TCollection_AsciiString aName;
7fd59977 190 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(theShape,theAccess);
191 if (aNS.IsNull()) return theIndex;
192 TNaming_Iterator anIter(aNS);
f1e162f2 193 for(;anIter.More();anIter.Next())
194 {
195 if (!anIter.OldShape().IsNull() && !anIter.NewShape().IsNull()) if (anIter.NewShape().IsSame(theShape))
196 {
7fd59977 197 theIndex++;
f1e162f2 198 if (!theName.IsEmpty())
199 {
200 aName = theName + "_" + theIndex;
201 DBRep::Set(aName.ToCString(),anIter.OldShape());
7fd59977 202 }
203 theIndex = GetAllOld(anIter.OldShape(),theAccess,theName,theIndex);
204 }
205 }
206 return theIndex;
207}
208
209static Standard_Integer GetAllOldShapes (Draw_Interpretor& di,
210 Standard_Integer nb,
211 const char** arg) {
212 Standard_Integer aResult = 0;
213 if (nb==3 || nb==4) {
f1e162f2 214 TCollection_AsciiString aName((nb==4) ? arg[3] : "");
7fd59977 215
216 if (arg[2][0]=='0') { // label
217 TDF_Label aLabel;
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";
222 return 1;
223 }
224 Standard_Integer a;
225 TNaming_Iterator anIter(aNS);
226 for(a=1;anIter.More();anIter.Next(),a++) {
227 if (!anIter.NewShape().IsNull()) {
f1e162f2 228 TCollection_AsciiString aSubName;
229 if (!aName.IsEmpty())
230 {
231 aSubName += aName + "_";
232 aSubName += a;
233 }
234 aResult+=GetAllOld(anIter.NewShape(),aLabel,aSubName,0);
7fd59977 235 }
236 }
237 } else { // shape
238 Handle(TDF_Data) DF;
239 if (!DDF::GetDF(arg[1],DF)) {
240 di<<"Wrong df"<<"\n";
241 return 1;
242 }
243 TopoDS_Shape aShape = DBRep::Get(arg[2]);
244 aResult=GetAllOld(aShape,DF->Root(),aName,0);
245 }
246 } else {
247 di<<"Usage: GetAllNewShapes df entry/shape [res]"<<"\n";
248 return 1;
249 }
250 di<<aResult;
251 return 0;
252}
253
254static Standard_Integer GetSameShapes (Draw_Interpretor& di,
255 Standard_Integer nb,
256 const char** arg) {
257 TCollection_AsciiString aRes;
258 if (nb == 3) {
259 Standard_Integer aResult = 0;
260 Handle(TDF_Data) DF;
261 if (!DDF::GetDF(arg[1],DF)) {
262 di<<"Wrong df"<<"\n";
263 return 1;
264 }
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;
272 aResult++;
273 }
274 }
275 } else {
276 di<<"Usage: GetSameShapes df shape"<<"\n";
277 return 1;
278 }
279 di<<aRes.ToCString();
280 return 0;
281}
282
283void QADNaming::IteratorsCommands(Draw_Interpretor& theCommands)
284{
285 static Standard_Boolean done = Standard_False;
286 if (done) return;
287 done = Standard_True;
288
289 const char* g = "Naming builder commands";
290
291 theCommands.Add("GetNewShapes","GetNewShapes df entry [res]",__FILE__,GetNewShapes,g);
292
293 theCommands.Add("GetOldShapes","GetOldShapes df entry [res]",__FILE__,GetOldShapes,g);
294
295 theCommands.Add("GetAllNewShapes","GetAllNewShapes df entry/shape [res]",__FILE__,GetAllNewShapes,g);
296
297 theCommands.Add("GetAllOldShapes","GetAllOldShapes df entry/shape [res]",__FILE__,GetAllOldShapes,g);
298
299 theCommands.Add("GetSameShapes","GetSameShapes df shape",__FILE__,GetSameShapes,g);
300
301}