1 // File: DDF_BasicCommands.cxx
2 // ---------------------
3 // Author: DAUTRY Philippe & VAUTHIER Jean-Claude
4 // Copyright: Matra Datavision 1997
7 // History: Version Date Purpose
8 // 0.0 Feb 10 1997 Creation
13 #include <TDF_ComparisonTool.hxx>
14 #include <TDF_CopyTool.hxx>
15 #include <TDF_ClosureMode.hxx>
16 #include <TDF_ClosureTool.hxx>
18 #include <DDF_Data.hxx>
21 #include <Draw_Appli.hxx>
22 #include <Draw_Drawable3D.hxx>
23 #include <Draw_Interpretor.hxx>
24 #include <Standard_GUID.hxx>
25 #include <Standard_NotImplemented.hxx>
27 #include <TColStd_HSequenceOfAsciiString.hxx>
28 #include <TColStd_ListOfInteger.hxx>
29 #include <TColStd_SequenceOfAsciiString.hxx>
31 #include <TCollection_AsciiString.hxx>
32 #include <TCollection_ExtendedString.hxx>
34 #include <TDF_Attribute.hxx>
35 #include <TDF_TagSource.hxx>
36 #include <TDF_AttributeIterator.hxx>
37 #include <TDF_ChildIterator.hxx>
38 #include <TDF_Data.hxx>
39 #include <TDF_DataSet.hxx>
40 #include <TDF_Delta.hxx>
41 #include <TDF_IDFilter.hxx>
42 #include <TDF_Label.hxx>
43 #include <TDF_RelocationTable.hxx>
44 #include <TDF_Tool.hxx>
46 #include <DDF_IOStream.hxx>
49 //=======================================================================
51 //purpose : Returns a list of sub-label entries.
52 //=======================================================================
54 static Standard_Integer DDF_Children (Draw_Interpretor& di,
61 TCollection_AsciiString entry;
63 if (!DDF::GetDF (a[1], DF)) return 1;
66 if (n == 3) TDF_Tool::Label(DF,a[2],lab);
72 for (TDF_ChildIterator itr(lab); itr.More(); itr.Next()) {
73 TDF_Tool::Entry(itr.Value(),entry);
74 //TCollection_AsciiString entry(itr.Value().Tag());
75 di<<entry.ToCString()<<" ";
82 //=======================================================================
83 //function : Attributes
84 //purpose : Returns a list of label attributes.
85 //=======================================================================
87 static Standard_Integer DDF_Attributes (Draw_Interpretor& di,
95 if (!DDF::GetDF (a[1], DF)) return 1;
98 TDF_Tool::Label(DF,a[2],lab);
100 if (lab.IsNull()) return 1;
102 for (TDF_AttributeIterator itr(lab); itr.More(); itr.Next()) {
103 di<<itr.Value()->DynamicType()->Name()<<" ";
109 //=======================================================================
110 //function : ForgetAll
111 //purpose : "ForgetAll dfname Label"
112 //=======================================================================
114 static Standard_Integer DDF_ForgetAll(Draw_Interpretor& /*di*/,
118 if (n != 3) return 1;
122 if (!DDF::GetDF (a[1], DF)) return 1;
125 TDF_Tool::Label(DF,a[2],label);
126 if (label.IsNull()) return 1;
127 label.ForgetAllAttributes();
134 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
135 // save/restore & Store/Retrieve commands
136 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
140 //==========================================================
142 //==========================================================
144 void ErrorMessage (const Storage_Error n)
146 cout << "Storage Error: " << flush;
150 cout << "no problem" << endl;
152 case Storage_VSOpenError:
153 cout << "while opening the stream" << endl;
155 case Storage_VSModeError:
156 cout << "the stream is opened with a wrong mode for operation " << endl;
158 case Storage_VSCloseError:
159 cout << "while closing the stream" << endl;
161 case Storage_VSAlreadyOpen:
162 cout << "stream is already opened" << endl;
164 case Storage_VSNotOpen:
165 cout << "stream not opened" << endl;
167 case Storage_VSSectionNotFound:
168 cout << "the section is not found" << endl;
170 case Storage_VSWriteError:
171 cout << "error during writing" << endl;
173 case Storage_VSFormatError:
174 cout << "wrong format error occured while reading" << endl;
176 case Storage_VSUnknownType:
177 cout << "try to read an unknown type" << endl;
179 case Storage_VSTypeMismatch:
180 cout << "try to read a wrong primitive type (read a char while expecting a real)" << endl;
182 case Storage_VSInternalError:
183 cout << "internal error" << endl;
185 case Storage_VSExtCharParityError: cout << "parity error" << endl;
188 cout << "unknown error code" << endl;
194 //=======================================================================
195 //function : DDF_SetTagger
196 //purpose : SetTagger (DF, entry)
197 //=======================================================================
199 static Standard_Integer DDF_SetTagger (Draw_Interpretor& di,
205 if (!DDF::GetDF(arg[1],DF)) return 1;
207 DDF::AddLabel(DF, arg[2], L);
208 TDF_TagSource::Set(L);
211 di << "DDF_SetTagger : Error" << "\n";
217 //=======================================================================
218 //function : DDF_NewTag
219 //purpose : NewTag (DF,[father]
220 //=======================================================================
222 static Standard_Integer DDF_NewTag (Draw_Interpretor& di,
228 if (!DDF::GetDF(arg[1],DF)) return 1;
229 Handle(TDF_TagSource) A;
230 if (!DDF::Find(DF,arg[2],TDF_TagSource::GetID(),A)) return 1;
234 di << "DDF_NewTag : Error" << "\n";
239 //=======================================================================
240 //function : DDF_NewChild
241 //purpose : NewChild(DF,[father])
242 //=======================================================================
244 static Standard_Integer DDF_NewChild (Draw_Interpretor& di,
250 if (!DDF::GetDF(arg[1],DF)) return 1;
252 TDF_Label free = TDF_TagSource::NewChild(DF->Root());
257 TDF_Label fatherlabel;
258 if (!DDF::FindLabel(DF,arg[2],fatherlabel)) return 1;
259 TDF_Label free = TDF_TagSource::NewChild (fatherlabel);
260 di << arg[2] << ":" << free.Tag();
264 di << "DDF_NewChild : Error" << "\n";
269 //=======================================================================
270 //function : Label (DF,freeentry)
271 //=======================================================================
273 static Standard_Integer DDF_Label (Draw_Interpretor& di,Standard_Integer n, const char** a)
277 if (!DDF::GetDF (a[1],DF)) return 1;
279 if (!DDF::FindLabel(DF,a[2],L,Standard_False)) {
280 DDF::AddLabel(DF,a[2],L);
281 //di << "Label : " << a[2] << " created" << "\n";
283 //else di << "Label : " << a[2] << " retrieved" << "\n";
284 DDF::ReturnLabel(di,L);
287 di << "DDF_Label : Error" << "\n";
292 //=======================================================================
293 //function : BasicCommands
295 //=======================================================================
297 void DDF::BasicCommands (Draw_Interpretor& theCommands)
299 static Standard_Boolean done = Standard_False;
301 done = Standard_True;
303 const char* g = "DF basic commands";
307 theCommands.Add ("SetTagger",
308 "SetTagger (DF, entry)",
309 __FILE__, DDF_SetTagger, g);
311 theCommands.Add ("NewTag",
312 "NewTag (DF, tagger)",
313 __FILE__, DDF_NewTag, g);
315 theCommands.Add ("NewChild",
316 "NewChild (DF, [tagger])",
317 __FILE__, DDF_NewChild, g);
319 theCommands.Add ("Children",
320 " Returns the list of label children: Children DF label",
321 __FILE__, DDF_Children, g);
323 theCommands.Add ("Attributes",
324 " Returns the list of label attributes: Attributes DF label",
325 __FILE__, DDF_Attributes, g);
327 theCommands.Add ("ForgetAll",
328 "Forgets all attributes from the label: ForgetAll DF Label",
329 __FILE__, DDF_ForgetAll, g);
331 theCommands.Add ("Label",
333 __FILE__, DDF_Label, g);