0023072: Eliminate compiler warnings (level 3) on Windows / MSVC++
[occt.git] / src / DDF / DDF_BasicCommands.cxx
1 // Created by: DAUTRY Philippe & VAUTHIER Jean-Claude
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-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
20 //              ---------------------
21
22 // Version:     0.0
23 //Version       Date            Purpose
24 //              0.0     Feb 10 1997     Creation
25
26
27 #include <DDF.hxx>
28
29 #include <TDF_ComparisonTool.hxx>
30 #include <TDF_CopyTool.hxx>
31 #include <TDF_ClosureMode.hxx>
32 #include <TDF_ClosureTool.hxx>
33
34 #include <DDF_Data.hxx>
35
36 #include <Draw.hxx>
37 #include <Draw_Appli.hxx>
38 #include <Draw_Drawable3D.hxx>
39 #include <Draw_Interpretor.hxx>
40 #include <Standard_GUID.hxx>
41 #include <Standard_NotImplemented.hxx>
42
43 #include <TColStd_HSequenceOfAsciiString.hxx>
44 #include <TColStd_ListOfInteger.hxx>
45 #include <TColStd_SequenceOfAsciiString.hxx>
46
47 #include <TCollection_AsciiString.hxx>
48 #include <TCollection_ExtendedString.hxx>
49
50 #include <TDF_Attribute.hxx>
51 #include <TDF_TagSource.hxx>
52 #include <TDF_AttributeIterator.hxx>
53 #include <TDF_ChildIterator.hxx>
54 #include <TDF_Data.hxx>
55 #include <TDF_DataSet.hxx>
56 #include <TDF_Delta.hxx>
57 #include <TDF_IDFilter.hxx>
58 #include <TDF_Label.hxx>
59 #include <TDF_RelocationTable.hxx>
60 #include <TDF_Tool.hxx>
61
62 #include <DDF_IOStream.hxx>
63
64
65 //=======================================================================
66 //function : Children
67 //purpose  : Returns a list of sub-label entries.
68 //=======================================================================
69
70 static Standard_Integer DDF_Children (Draw_Interpretor& di, 
71                                       Standard_Integer  n, 
72                                       const char**            a)
73 {
74   if (n < 2) return 1;
75   
76   Handle(TDF_Data) DF;
77   TCollection_AsciiString entry;
78
79   if (!DDF::GetDF (a[1], DF)) return 1;
80
81   TDF_Label lab;
82   if (n == 3) TDF_Tool::Label(DF,a[2],lab);
83
84   if (lab.IsNull()) {
85     di<<"0";
86   }
87   else {
88     for (TDF_ChildIterator itr(lab); itr.More(); itr.Next()) {
89       TDF_Tool::Entry(itr.Value(),entry);
90       //TCollection_AsciiString entry(itr.Value().Tag());
91       di<<entry.ToCString()<<" ";
92     }
93   }
94   return 0;
95 }
96
97
98 //=======================================================================
99 //function : Attributes
100 //purpose  : Returns a list of label attributes.
101 //=======================================================================
102
103 static Standard_Integer DDF_Attributes (Draw_Interpretor& di, 
104                                         Standard_Integer  n, 
105                                         const char**            a)
106 {
107   if (n != 3) return 1;
108   
109   Handle(TDF_Data) DF;
110
111   if (!DDF::GetDF (a[1], DF)) return 1;
112
113   TDF_Label lab;
114   TDF_Tool::Label(DF,a[2],lab);
115
116   if (lab.IsNull()) return 1;
117
118   for (TDF_AttributeIterator itr(lab); itr.More(); itr.Next()) {
119     di<<itr.Value()->DynamicType()->Name()<<" ";
120   }
121   return 0;
122 }
123
124
125 //=======================================================================
126 //function : ForgetAll
127 //purpose  : "ForgetAll dfname Label"
128 //=======================================================================
129
130 static Standard_Integer DDF_ForgetAll(Draw_Interpretor& /*di*/, 
131                                       Standard_Integer  n, 
132                                       const char**            a)
133 {
134   if (n != 3) return 1;
135   
136   Handle(TDF_Data) DF;
137
138   if (!DDF::GetDF (a[1], DF)) return 1;
139
140   TDF_Label label;
141   TDF_Tool::Label(DF,a[2],label);
142   if (label.IsNull()) return 1;
143   label.ForgetAllAttributes();
144 //POP pour NT
145   return 0;
146 }
147
148
149
150 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151 // save/restore & Store/Retrieve commands
152 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
153
154
155
156 //==========================================================
157 // ErrorMessage
158 //==========================================================
159
160 void ErrorMessage (const Storage_Error n) 
161 {
162   cout << "Storage Error: " << flush;
163
164   switch (n) {
165   case Storage_VSOk:
166     cout << "no problem" << endl;
167     break;
168   case Storage_VSOpenError:
169     cout << "while opening the stream" << endl;
170     break;
171   case Storage_VSModeError:
172     cout << "the stream is opened with a wrong mode for operation " << endl;
173     break;
174   case Storage_VSCloseError:
175     cout << "while closing the stream" << endl;
176     break;
177   case Storage_VSAlreadyOpen:
178     cout << "stream is already opened" << endl;
179     break;
180   case Storage_VSNotOpen:
181     cout << "stream not opened" << endl;
182     break;
183   case Storage_VSSectionNotFound:
184     cout << "the section is not found" << endl;
185     break;
186   case Storage_VSWriteError:
187     cout << "error during writing" << endl;
188     break;
189   case Storage_VSFormatError:
190     cout << "wrong format error occured while reading" << endl;
191     break;
192   case Storage_VSUnknownType:
193     cout << "try to read an unknown type" << endl;
194     break;
195   case Storage_VSTypeMismatch:
196     cout << "try to read a wrong primitive type (read a char while expecting a real)" << endl;
197     break;
198   case Storage_VSInternalError:
199     cout << "internal error" << endl;
200     break;
201   case Storage_VSExtCharParityError:      cout << "parity error" << endl;
202     break;
203   default:
204     cout << "unknown error code" << endl;
205     break;
206   }
207 }
208
209
210 //=======================================================================
211 //function : DDF_SetTagger
212 //purpose  : SetTagger (DF, entry)
213 //=======================================================================
214
215 static Standard_Integer DDF_SetTagger (Draw_Interpretor& di,
216                                                Standard_Integer nb, 
217                                                const char** arg) 
218 {   
219   if (nb == 3) {    
220     Handle(TDF_Data) DF;
221     if (!DDF::GetDF(arg[1],DF)) return 1;
222     TDF_Label L;
223     DDF::AddLabel(DF, arg[2], L);
224     TDF_TagSource::Set(L); 
225     return 0;
226   }
227   di << "DDF_SetTagger : Error" << "\n";
228   return 1;
229 }
230
231
232
233 //=======================================================================
234 //function : DDF_NewTag
235 //purpose  : NewTag (DF,[father]
236 //=======================================================================
237
238 static Standard_Integer DDF_NewTag (Draw_Interpretor& di,
239                                          Standard_Integer nb, 
240                                          const char** arg) 
241
242   if (nb == 3) {
243     Handle(TDF_Data) DF;
244     if (!DDF::GetDF(arg[1],DF)) return 1;
245     Handle(TDF_TagSource) A;
246     if (!DDF::Find(DF,arg[2],TDF_TagSource::GetID(),A)) return 1;
247     di << A->NewTag ();
248     return 0;
249   }
250   di << "DDF_NewTag : Error" << "\n";
251   return 1;
252 }
253
254
255 //=======================================================================
256 //function : DDF_NewChild
257 //purpose  : NewChild(DF,[father])
258 //=======================================================================
259
260 static Standard_Integer DDF_NewChild (Draw_Interpretor& di,
261                                            Standard_Integer nb, 
262                                            const char** arg) 
263
264   Handle(TDF_Data) DF;
265   if (nb>=2){
266     if (!DDF::GetDF(arg[1],DF)) return 1;
267     if (nb == 2) {
268       TDF_Label free = TDF_TagSource::NewChild(DF->Root());
269       di << free.Tag();
270       return 0;
271     } 
272     else  if (nb == 3) {
273       TDF_Label fatherlabel;
274       if (!DDF::FindLabel(DF,arg[2],fatherlabel)) return 1;
275       TDF_Label free = TDF_TagSource::NewChild (fatherlabel);
276       di << arg[2] << ":" << free.Tag();
277       return 0;
278     }
279   }
280   di << "DDF_NewChild : Error" << "\n";
281   return 1;
282 }
283
284
285 //=======================================================================
286 //function : Label (DF,freeentry)
287 //=======================================================================
288
289 static Standard_Integer DDF_Label (Draw_Interpretor& di,Standard_Integer n, const char** a)
290 {  
291   if (n == 3) {  
292     Handle(TDF_Data) DF;  
293     if (!DDF::GetDF (a[1],DF)) return 1; 
294     TDF_Label L;
295     if (!DDF::FindLabel(DF,a[2],L,Standard_False)) { 
296       DDF::AddLabel(DF,a[2],L);  
297       //di << "Label : " << a[2] << " created" << "\n";
298     }
299     //else di << "Label : " << a[2] << " retrieved" << "\n";
300     DDF::ReturnLabel(di,L);
301     return 0;
302   }
303   di << "DDF_Label : Error" << "\n";
304   return 1; 
305 }
306
307
308 //=======================================================================
309 //function : BasicCommands
310 //purpose  : 
311 //=======================================================================
312
313 void DDF::BasicCommands (Draw_Interpretor& theCommands) 
314 {
315   static Standard_Boolean done = Standard_False;
316   if (done) return;
317   done = Standard_True;
318
319   const char* g = "DF basic commands";
320
321   // Label :  
322
323   theCommands.Add ("SetTagger", 
324                    "SetTagger (DF, entry)",
325                    __FILE__, DDF_SetTagger, g);  
326
327   theCommands.Add ("NewTag", 
328                    "NewTag (DF, tagger)",
329                    __FILE__, DDF_NewTag, g);
330
331   theCommands.Add ("NewChild", 
332                    "NewChild (DF, [tagger])",
333                    __FILE__, DDF_NewChild, g);
334
335   theCommands.Add ("Children",
336                    " Returns the list of label children: Children DF label",
337                    __FILE__, DDF_Children, g);
338
339   theCommands.Add ("Attributes",
340                    " Returns the list of label attributes: Attributes DF label",
341                    __FILE__, DDF_Attributes, g);
342
343   theCommands.Add ("ForgetAll",
344                    "Forgets all attributes from the label: ForgetAll DF Label",
345                    __FILE__, DDF_ForgetAll, g);
346
347   theCommands.Add ("Label",
348                    "Label DF entry",
349                   __FILE__, DDF_Label, g);  
350
351
352 }