1 // Created by: DAUTRY Philippe & VAUTHIER Jean-Claude
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // ---------------------
19 //Version Date Purpose
20 // 0.0 Feb 10 1997 Creation
25 #include <TDF_ComparisonTool.hxx>
26 #include <TDF_CopyTool.hxx>
27 #include <TDF_ClosureMode.hxx>
28 #include <TDF_ClosureTool.hxx>
30 #include <DDF_Data.hxx>
33 #include <Draw_Appli.hxx>
34 #include <Draw_Drawable3D.hxx>
35 #include <Draw_Interpretor.hxx>
36 #include <Standard_GUID.hxx>
37 #include <Standard_NotImplemented.hxx>
39 #include <TColStd_HSequenceOfAsciiString.hxx>
40 #include <TColStd_ListOfInteger.hxx>
41 #include <TColStd_SequenceOfAsciiString.hxx>
43 #include <TCollection_AsciiString.hxx>
44 #include <TCollection_ExtendedString.hxx>
46 #include <TDF_Attribute.hxx>
47 #include <TDF_TagSource.hxx>
48 #include <TDF_AttributeIterator.hxx>
49 #include <TDF_ChildIterator.hxx>
50 #include <TDF_Data.hxx>
51 #include <TDF_DataSet.hxx>
52 #include <TDF_Delta.hxx>
53 #include <TDF_IDFilter.hxx>
54 #include <TDF_Label.hxx>
55 #include <TDF_RelocationTable.hxx>
56 #include <TDF_Tool.hxx>
58 #include <DDF_IOStream.hxx>
61 //=======================================================================
63 //purpose : Returns a list of sub-label entries.
64 //=======================================================================
66 static Standard_Integer DDF_Children (Draw_Interpretor& di,
73 TCollection_AsciiString entry;
75 if (!DDF::GetDF (a[1], DF)) return 1;
78 if (n == 3) TDF_Tool::Label(DF,a[2],lab);
84 for (TDF_ChildIterator itr(lab); itr.More(); itr.Next()) {
85 TDF_Tool::Entry(itr.Value(),entry);
86 //TCollection_AsciiString entry(itr.Value().Tag());
87 di<<entry.ToCString()<<" ";
94 //=======================================================================
95 //function : Attributes
96 //purpose : Returns a list of label attributes.
97 //=======================================================================
99 static Standard_Integer DDF_Attributes (Draw_Interpretor& di,
103 if (n != 3) return 1;
107 if (!DDF::GetDF (a[1], DF)) return 1;
110 TDF_Tool::Label(DF,a[2],lab);
112 if (lab.IsNull()) return 1;
114 for (TDF_AttributeIterator itr(lab); itr.More(); itr.Next()) {
115 di<<itr.Value()->DynamicType()->Name()<<" ";
121 //=======================================================================
122 //function : ForgetAll
123 //purpose : "ForgetAll dfname Label"
124 //=======================================================================
126 static Standard_Integer DDF_ForgetAll(Draw_Interpretor& /*di*/,
130 if (n != 3) return 1;
134 if (!DDF::GetDF (a[1], DF)) return 1;
137 TDF_Tool::Label(DF,a[2],label);
138 if (label.IsNull()) return 1;
139 label.ForgetAllAttributes();
146 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
147 // save/restore & Store/Retrieve commands
148 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
152 //==========================================================
154 //==========================================================
156 void ErrorMessage (const Storage_Error n)
158 cout << "Storage Error: " << flush;
162 cout << "no problem" << endl;
164 case Storage_VSOpenError:
165 cout << "while opening the stream" << endl;
167 case Storage_VSModeError:
168 cout << "the stream is opened with a wrong mode for operation " << endl;
170 case Storage_VSCloseError:
171 cout << "while closing the stream" << endl;
173 case Storage_VSAlreadyOpen:
174 cout << "stream is already opened" << endl;
176 case Storage_VSNotOpen:
177 cout << "stream not opened" << endl;
179 case Storage_VSSectionNotFound:
180 cout << "the section is not found" << endl;
182 case Storage_VSWriteError:
183 cout << "error during writing" << endl;
185 case Storage_VSFormatError:
186 cout << "wrong format error occured while reading" << endl;
188 case Storage_VSUnknownType:
189 cout << "try to read an unknown type" << endl;
191 case Storage_VSTypeMismatch:
192 cout << "try to read a wrong primitive type (read a char while expecting a real)" << endl;
194 case Storage_VSInternalError:
195 cout << "internal error" << endl;
197 case Storage_VSExtCharParityError: cout << "parity error" << endl;
200 cout << "unknown error code" << endl;
206 //=======================================================================
207 //function : DDF_SetTagger
208 //purpose : SetTagger (DF, entry)
209 //=======================================================================
211 static Standard_Integer DDF_SetTagger (Draw_Interpretor& di,
217 if (!DDF::GetDF(arg[1],DF)) return 1;
219 DDF::AddLabel(DF, arg[2], L);
220 TDF_TagSource::Set(L);
223 di << "DDF_SetTagger : Error\n";
229 //=======================================================================
230 //function : DDF_NewTag
231 //purpose : NewTag (DF,[father]
232 //=======================================================================
234 static Standard_Integer DDF_NewTag (Draw_Interpretor& di,
240 if (!DDF::GetDF(arg[1],DF)) return 1;
241 Handle(TDF_TagSource) A;
242 if (!DDF::Find(DF,arg[2],TDF_TagSource::GetID(),A)) return 1;
246 di << "DDF_NewTag : Error\n";
251 //=======================================================================
252 //function : DDF_NewChild
253 //purpose : NewChild(DF,[father])
254 //=======================================================================
256 static Standard_Integer DDF_NewChild (Draw_Interpretor& di,
262 if (!DDF::GetDF(arg[1],DF)) return 1;
264 TDF_Label free = TDF_TagSource::NewChild(DF->Root());
269 TDF_Label fatherlabel;
270 if (!DDF::FindLabel(DF,arg[2],fatherlabel)) return 1;
271 TDF_Label free = TDF_TagSource::NewChild (fatherlabel);
272 di << arg[2] << ":" << free.Tag();
276 di << "DDF_NewChild : Error\n";
281 //=======================================================================
282 //function : Label (DF,freeentry)
283 //=======================================================================
285 static Standard_Integer DDF_Label (Draw_Interpretor& di,Standard_Integer n, const char** a)
289 if (!DDF::GetDF (a[1],DF)) return 1;
291 if (!DDF::FindLabel(DF,a[2],L,Standard_False)) {
292 DDF::AddLabel(DF,a[2],L);
293 //di << "Label : " << a[2] << " created\n";
295 //else di << "Label : " << a[2] << " retrieved\n";
296 DDF::ReturnLabel(di,L);
299 di << "DDF_Label : Error\n";
304 //=======================================================================
305 //function : BasicCommands
307 //=======================================================================
309 void DDF::BasicCommands (Draw_Interpretor& theCommands)
311 static Standard_Boolean done = Standard_False;
313 done = Standard_True;
315 const char* g = "DF basic commands";
319 theCommands.Add ("SetTagger",
320 "SetTagger (DF, entry)",
321 __FILE__, DDF_SetTagger, g);
323 theCommands.Add ("NewTag",
324 "NewTag (DF, tagger)",
325 __FILE__, DDF_NewTag, g);
327 theCommands.Add ("NewChild",
328 "NewChild (DF, [tagger])",
329 __FILE__, DDF_NewChild, g);
331 theCommands.Add ("Children",
332 " Returns the list of label children: Children DF label",
333 __FILE__, DDF_Children, g);
335 theCommands.Add ("Attributes",
336 " Returns the list of label attributes: Attributes DF label",
337 __FILE__, DDF_Attributes, g);
339 theCommands.Add ("ForgetAll",
340 "Forgets all attributes from the label: ForgetAll DF Label",
341 __FILE__, DDF_ForgetAll, g);
343 theCommands.Add ("Label",
345 __FILE__, DDF_Label, g);