1 // Created by: DAUTRY Philippe & VAUTHIER Jean-Claude
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-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.
20 // ---------------------
23 //Version Date Purpose
24 // 0.0 Feb 10 1997 Creation
29 #include <TDF_ComparisonTool.hxx>
30 #include <TDF_CopyTool.hxx>
31 #include <TDF_ClosureMode.hxx>
32 #include <TDF_ClosureTool.hxx>
34 #include <DDF_Data.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>
43 #include <TColStd_HSequenceOfAsciiString.hxx>
44 #include <TColStd_ListOfInteger.hxx>
45 #include <TColStd_SequenceOfAsciiString.hxx>
47 #include <TCollection_AsciiString.hxx>
48 #include <TCollection_ExtendedString.hxx>
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>
62 #include <DDF_IOStream.hxx>
65 //=======================================================================
67 //purpose : Returns a list of sub-label entries.
68 //=======================================================================
70 static Standard_Integer DDF_Children (Draw_Interpretor& di,
77 TCollection_AsciiString entry;
79 if (!DDF::GetDF (a[1], DF)) return 1;
82 if (n == 3) TDF_Tool::Label(DF,a[2],lab);
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()<<" ";
98 //=======================================================================
99 //function : Attributes
100 //purpose : Returns a list of label attributes.
101 //=======================================================================
103 static Standard_Integer DDF_Attributes (Draw_Interpretor& di,
107 if (n != 3) return 1;
111 if (!DDF::GetDF (a[1], DF)) return 1;
114 TDF_Tool::Label(DF,a[2],lab);
116 if (lab.IsNull()) return 1;
118 for (TDF_AttributeIterator itr(lab); itr.More(); itr.Next()) {
119 di<<itr.Value()->DynamicType()->Name()<<" ";
125 //=======================================================================
126 //function : ForgetAll
127 //purpose : "ForgetAll dfname Label"
128 //=======================================================================
130 static Standard_Integer DDF_ForgetAll(Draw_Interpretor& /*di*/,
134 if (n != 3) return 1;
138 if (!DDF::GetDF (a[1], DF)) return 1;
141 TDF_Tool::Label(DF,a[2],label);
142 if (label.IsNull()) return 1;
143 label.ForgetAllAttributes();
150 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
151 // save/restore & Store/Retrieve commands
152 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
156 //==========================================================
158 //==========================================================
160 void ErrorMessage (const Storage_Error n)
162 cout << "Storage Error: " << flush;
166 cout << "no problem" << endl;
168 case Storage_VSOpenError:
169 cout << "while opening the stream" << endl;
171 case Storage_VSModeError:
172 cout << "the stream is opened with a wrong mode for operation " << endl;
174 case Storage_VSCloseError:
175 cout << "while closing the stream" << endl;
177 case Storage_VSAlreadyOpen:
178 cout << "stream is already opened" << endl;
180 case Storage_VSNotOpen:
181 cout << "stream not opened" << endl;
183 case Storage_VSSectionNotFound:
184 cout << "the section is not found" << endl;
186 case Storage_VSWriteError:
187 cout << "error during writing" << endl;
189 case Storage_VSFormatError:
190 cout << "wrong format error occured while reading" << endl;
192 case Storage_VSUnknownType:
193 cout << "try to read an unknown type" << endl;
195 case Storage_VSTypeMismatch:
196 cout << "try to read a wrong primitive type (read a char while expecting a real)" << endl;
198 case Storage_VSInternalError:
199 cout << "internal error" << endl;
201 case Storage_VSExtCharParityError: cout << "parity error" << endl;
204 cout << "unknown error code" << endl;
210 //=======================================================================
211 //function : DDF_SetTagger
212 //purpose : SetTagger (DF, entry)
213 //=======================================================================
215 static Standard_Integer DDF_SetTagger (Draw_Interpretor& di,
221 if (!DDF::GetDF(arg[1],DF)) return 1;
223 DDF::AddLabel(DF, arg[2], L);
224 TDF_TagSource::Set(L);
227 di << "DDF_SetTagger : Error" << "\n";
233 //=======================================================================
234 //function : DDF_NewTag
235 //purpose : NewTag (DF,[father]
236 //=======================================================================
238 static Standard_Integer DDF_NewTag (Draw_Interpretor& di,
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;
250 di << "DDF_NewTag : Error" << "\n";
255 //=======================================================================
256 //function : DDF_NewChild
257 //purpose : NewChild(DF,[father])
258 //=======================================================================
260 static Standard_Integer DDF_NewChild (Draw_Interpretor& di,
266 if (!DDF::GetDF(arg[1],DF)) return 1;
268 TDF_Label free = TDF_TagSource::NewChild(DF->Root());
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();
280 di << "DDF_NewChild : Error" << "\n";
285 //=======================================================================
286 //function : Label (DF,freeentry)
287 //=======================================================================
289 static Standard_Integer DDF_Label (Draw_Interpretor& di,Standard_Integer n, const char** a)
293 if (!DDF::GetDF (a[1],DF)) return 1;
295 if (!DDF::FindLabel(DF,a[2],L,Standard_False)) {
296 DDF::AddLabel(DF,a[2],L);
297 //di << "Label : " << a[2] << " created" << "\n";
299 //else di << "Label : " << a[2] << " retrieved" << "\n";
300 DDF::ReturnLabel(di,L);
303 di << "DDF_Label : Error" << "\n";
308 //=======================================================================
309 //function : BasicCommands
311 //=======================================================================
313 void DDF::BasicCommands (Draw_Interpretor& theCommands)
315 static Standard_Boolean done = Standard_False;
317 done = Standard_True;
319 const char* g = "DF basic commands";
323 theCommands.Add ("SetTagger",
324 "SetTagger (DF, entry)",
325 __FILE__, DDF_SetTagger, g);
327 theCommands.Add ("NewTag",
328 "NewTag (DF, tagger)",
329 __FILE__, DDF_NewTag, g);
331 theCommands.Add ("NewChild",
332 "NewChild (DF, [tagger])",
333 __FILE__, DDF_NewChild, g);
335 theCommands.Add ("Children",
336 " Returns the list of label children: Children DF label",
337 __FILE__, DDF_Children, g);
339 theCommands.Add ("Attributes",
340 " Returns the list of label attributes: Attributes DF label",
341 __FILE__, DDF_Attributes, g);
343 theCommands.Add ("ForgetAll",
344 "Forgets all attributes from the label: ForgetAll DF Label",
345 __FILE__, DDF_ForgetAll, g);
347 theCommands.Add ("Label",
349 __FILE__, DDF_Label, g);