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();
144 //=======================================================================
145 //function : ForgetAttribute
146 //purpose : "ForgetAtt dfname Label guid"
147 //=======================================================================
149 static Standard_Integer DDF_ForgetAttribute(Draw_Interpretor& di,
153 if (n != 4) return 1;
155 if (!DDF::GetDF (a[1], DF)) return 1;
158 TDF_Tool::Label(DF,a[2],aLabel);
159 if (aLabel.IsNull()) return 1;
160 if (!Standard_GUID::CheckGUIDFormat(a[3]))
162 di<<"DDF: The format of GUID is invalid\n";
165 Standard_GUID guid(a[3]);
166 aLabel.ForgetAttribute(guid);
170 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171 // save/restore & Store/Retrieve commands
172 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
176 //==========================================================
178 //==========================================================
180 void ErrorMessage (const Storage_Error n)
182 std::cout << "Storage Error: " << std::flush;
186 std::cout << "no problem" << std::endl;
188 case Storage_VSOpenError:
189 std::cout << "while opening the stream" << std::endl;
191 case Storage_VSModeError:
192 std::cout << "the stream is opened with a wrong mode for operation " << std::endl;
194 case Storage_VSCloseError:
195 std::cout << "while closing the stream" << std::endl;
197 case Storage_VSAlreadyOpen:
198 std::cout << "stream is already opened" << std::endl;
200 case Storage_VSNotOpen:
201 std::cout << "stream not opened" << std::endl;
203 case Storage_VSSectionNotFound:
204 std::cout << "the section is not found" << std::endl;
206 case Storage_VSWriteError:
207 std::cout << "error during writing" << std::endl;
209 case Storage_VSFormatError:
210 std::cout << "wrong format error occured while reading" << std::endl;
212 case Storage_VSUnknownType:
213 std::cout << "try to read an unknown type" << std::endl;
215 case Storage_VSTypeMismatch:
216 std::cout << "try to read a wrong primitive type (read a char while expecting a real)" << std::endl;
218 case Storage_VSInternalError:
219 std::cout << "internal error" << std::endl;
221 case Storage_VSExtCharParityError: std::cout << "parity error" << std::endl;
224 std::cout << "unknown error code" << std::endl;
230 //=======================================================================
231 //function : DDF_SetTagger
232 //purpose : SetTagger (DF, entry)
233 //=======================================================================
235 static Standard_Integer DDF_SetTagger (Draw_Interpretor& di,
241 if (!DDF::GetDF(arg[1],DF)) return 1;
243 DDF::AddLabel(DF, arg[2], L);
244 TDF_TagSource::Set(L);
247 di << "DDF_SetTagger : Error\n";
253 //=======================================================================
254 //function : DDF_NewTag
255 //purpose : NewTag (DF,[father]
256 //=======================================================================
258 static Standard_Integer DDF_NewTag (Draw_Interpretor& di,
264 if (!DDF::GetDF(arg[1],DF)) return 1;
265 Handle(TDF_TagSource) A;
266 if (!DDF::Find(DF,arg[2],TDF_TagSource::GetID(),A)) return 1;
270 di << "DDF_NewTag : Error\n";
275 //=======================================================================
276 //function : DDF_NewChild
277 //purpose : NewChild(DF,[father])
278 //=======================================================================
280 static Standard_Integer DDF_NewChild (Draw_Interpretor& di,
286 if (!DDF::GetDF(arg[1],DF)) return 1;
288 TDF_Label free = TDF_TagSource::NewChild(DF->Root());
293 TDF_Label fatherlabel;
294 if (!DDF::FindLabel(DF,arg[2],fatherlabel)) return 1;
295 TDF_Label free = TDF_TagSource::NewChild (fatherlabel);
296 di << arg[2] << ":" << free.Tag();
300 di << "DDF_NewChild : Error\n";
305 //=======================================================================
306 //function : Label (DF,freeentry)
307 //=======================================================================
309 static Standard_Integer DDF_Label (Draw_Interpretor& di,Standard_Integer n, const char** a)
313 if (!DDF::GetDF (a[1],DF)) return 1;
315 if (!DDF::FindLabel(DF,a[2],L,Standard_False)) {
316 DDF::AddLabel(DF,a[2],L);
317 //di << "Label : " << a[2] << " created\n";
319 //else di << "Label : " << a[2] << " retrieved\n";
320 DDF::ReturnLabel(di,L);
323 di << "DDF_Label : Error\n";
328 //=======================================================================
329 //function : BasicCommands
331 //=======================================================================
333 void DDF::BasicCommands (Draw_Interpretor& theCommands)
335 static Standard_Boolean done = Standard_False;
337 done = Standard_True;
339 const char* g = "DF basic commands";
343 theCommands.Add ("SetTagger",
344 "SetTagger (DF, entry)",
345 __FILE__, DDF_SetTagger, g);
347 theCommands.Add ("NewTag",
348 "NewTag (DF, tagger)",
349 __FILE__, DDF_NewTag, g);
351 theCommands.Add ("NewChild",
352 "NewChild (DF, [tagger])",
353 __FILE__, DDF_NewChild, g);
355 theCommands.Add ("Children",
356 " Returns the list of label children: Children DF label",
357 __FILE__, DDF_Children, g);
359 theCommands.Add ("Attributes",
360 " Returns the list of label attributes: Attributes DF label",
361 __FILE__, DDF_Attributes, g);
363 theCommands.Add ("ForgetAll",
364 "Forgets all attributes from the label: ForgetAll DF Label",
365 __FILE__, DDF_ForgetAll, g);
367 theCommands.Add ("ForgetAtt",
368 "Forgets the specified by guid attribute from the label: ForgetAtt DF Label guid",
369 __FILE__, DDF_ForgetAttribute, g);
371 theCommands.Add ("Label",
373 __FILE__, DDF_Label, g);