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