1 // File: QADNaming_IteratorsCommands.cxx
2 // Created: Thu Apr 25 11:39:25 2002
3 // Author: Michael PONIKAROV
8 #include <QADNaming.hxx>
9 #include <TDF_Label.hxx>
10 #include <Draw_Interpretor.hxx>
11 #include <TNaming_Iterator.hxx>
12 #include <TNaming_NewShapeIterator.hxx>
13 #include <TNaming_OldShapeIterator.hxx>
14 #include <TNaming_SameShapeIterator.hxx>
15 #include <TNaming_Tool.hxx>
16 #include <TopoDS_Shape.hxx>
18 #include <TNaming.hxx>
19 #include <TNaming_NamedShape.hxx>
23 #include <TDF_Data.hxx>
24 #include <TDF_Tool.hxx>
26 static const char* EvolutionString(TNaming_Evolution theEvolution) {
28 case TNaming_PRIMITIVE :
30 case TNaming_GENERATED :
36 case TNaming_SELECTED :
38 case TNaming_REPLACE :
41 return "UNKNOWN_Evolution";
45 static Standard_Integer GetNewShapes (Draw_Interpretor& di,
50 if (!QADNaming::Entry(arg, aLabel)) return 1;
51 Handle(TNaming_NamedShape) aNS;
52 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
53 di<<"Label has no NamedShape"<<"\n";
56 di<<EvolutionString(aNS->Evolution());
57 TNaming_Iterator anIter(aNS);
60 for(a=1;anIter.More();anIter.Next(),a++) {
61 if (anIter.NewShape().IsNull()) a--;
63 sprintf(aName,"%s_%d",arg[3],a);
64 DBRep::Set (aName,anIter.NewShape());
69 di<<"Usage: GetNewShapes df entry [res]"<<"\n";
75 static Standard_Integer GetOldShapes (Draw_Interpretor& di,
80 if (!QADNaming::Entry(arg, aLabel)) return 1;
81 Handle(TNaming_NamedShape) aNS;
82 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
83 di<<"Label has no NamedShape"<<"\n";
86 di<<EvolutionString(aNS->Evolution());
87 TNaming_Iterator anIter(aNS);
90 for(a=1;anIter.More();anIter.Next(),a++) {
91 if (anIter.OldShape().IsNull()) a--;
93 sprintf(aName,"%s_%d",arg[3],a);
94 DBRep::Set (aName,anIter.OldShape());
99 di<<"Usage: GetOldShapes df entry [res]"<<"\n";
105 static int GetAllNew(const TopoDS_Shape& theShape, const TDF_Label& theAccess, const char* theName, Standard_Integer theIndex) {
106 TNaming_NewShapeIterator anIter(theShape,theAccess);
108 for(;anIter.More();anIter.Next()) {
109 if (!anIter.Shape().IsNull()) {
111 if (theName != NULL) {
112 sprintf(aName,"%s_%d",theName,theIndex);
113 DBRep::Set(aName,anIter.Shape());
115 theIndex = GetAllNew(anIter.Shape(),theAccess,theName,theIndex);
121 static Standard_Integer GetAllNewShapes (Draw_Interpretor& di,
124 Standard_Integer aResult = 0;
125 if (nb==3 || nb==4) {
126 const char* aName = (nb==4) ? arg[3] : NULL;
128 if (arg[2][0]=='0') { // label
130 if (!QADNaming::Entry(arg, aLabel)) return 1;
131 Handle(TNaming_NamedShape) aNS;
132 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
133 di<<"Label has no NamedShape"<<"\n";
137 TNaming_Iterator anIter(aNS);
138 for(a=1;anIter.More();anIter.Next(),a++) {
139 if (!anIter.NewShape().IsNull()) {
142 aSubName = new char[200];
143 sprintf(aSubName,"%s_%d",aName,a);
144 } else aSubName = NULL;
145 aResult+=GetAllNew(anIter.NewShape(),aLabel,aSubName,0);
146 if (aSubName != NULL) delete(aSubName);
151 if (!DDF::GetDF(arg[1],DF)) {
152 di<<"Wrong df"<<"\n";
155 TopoDS_Shape aShape = DBRep::Get(arg[2]);
156 aResult=GetAllNew(aShape,DF->Root(),aName,0);
159 di<<"Usage: GetAllNewShapes df entry/shape [res]"<<"\n";
166 static int GetAllOld(const TopoDS_Shape& theShape, const TDF_Label& theAccess, const char* theName, Standard_Integer theIndex) {
168 Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(theShape,theAccess);
169 if (aNS.IsNull()) return theIndex;
170 TNaming_Iterator anIter(aNS);
171 for(;anIter.More();anIter.Next()) {
172 if (!anIter.OldShape().IsNull() && !anIter.NewShape().IsNull()) if (anIter.NewShape().IsSame(theShape)) {
175 sprintf(aName,"%s_%d",theName,theIndex);
176 DBRep::Set(aName,anIter.OldShape());
178 theIndex = GetAllOld(anIter.OldShape(),theAccess,theName,theIndex);
184 static Standard_Integer GetAllOldShapes (Draw_Interpretor& di,
187 Standard_Integer aResult = 0;
188 if (nb==3 || nb==4) {
189 const char* aName = (nb==4) ? arg[3] : NULL;
191 if (arg[2][0]=='0') { // label
193 if (!QADNaming::Entry(arg, aLabel)) return 1;
194 Handle(TNaming_NamedShape) aNS;
195 if (!aLabel.FindAttribute(TNaming_NamedShape::GetID(),aNS)) {
196 di<<"Label has no NamedShape"<<"\n";
200 TNaming_Iterator anIter(aNS);
201 for(a=1;anIter.More();anIter.Next(),a++) {
202 if (!anIter.NewShape().IsNull()) {
205 aSubName = new char[200];
206 sprintf(aSubName,"%s_%d",aName,a);
207 } else aSubName = NULL;
208 aResult+=GetAllOld(anIter.NewShape(),aLabel,aSubName,0);
213 if (!DDF::GetDF(arg[1],DF)) {
214 di<<"Wrong df"<<"\n";
217 TopoDS_Shape aShape = DBRep::Get(arg[2]);
218 aResult=GetAllOld(aShape,DF->Root(),aName,0);
221 di<<"Usage: GetAllNewShapes df entry/shape [res]"<<"\n";
228 static Standard_Integer GetSameShapes (Draw_Interpretor& di,
231 TCollection_AsciiString aRes;
233 Standard_Integer aResult = 0;
235 if (!DDF::GetDF(arg[1],DF)) {
236 di<<"Wrong df"<<"\n";
239 TopoDS_Shape aShape = DBRep::Get(arg[2]);
240 TNaming_SameShapeIterator anIter(aShape,DF->Root());
241 for(;anIter.More();anIter.Next()) {
242 if (!anIter.Label().IsNull()) {
243 TCollection_AsciiString Name;
244 TDF_Tool::Entry(anIter.Label(),Name);
245 if (aResult != 0) aRes=aRes+Name+" "; else aRes=Name;
250 di<<"Usage: GetSameShapes df shape"<<"\n";
253 di<<aRes.ToCString();
257 void QADNaming::IteratorsCommands(Draw_Interpretor& theCommands)
259 static Standard_Boolean done = Standard_False;
261 done = Standard_True;
263 const char* g = "Naming builder commands";
265 theCommands.Add("GetNewShapes","GetNewShapes df entry [res]",__FILE__,GetNewShapes,g);
267 theCommands.Add("GetOldShapes","GetOldShapes df entry [res]",__FILE__,GetOldShapes,g);
269 theCommands.Add("GetAllNewShapes","GetAllNewShapes df entry/shape [res]",__FILE__,GetAllNewShapes,g);
271 theCommands.Add("GetAllOldShapes","GetAllOldShapes df entry/shape [res]",__FILE__,GetAllOldShapes,g);
273 theCommands.Add("GetSameShapes","GetSameShapes df shape",__FILE__,GetSameShapes,g);