0029355: OCCT 6.9.1 persistence restored in OCCT 7.2.0 not working
[occt.git] / src / DDF / DDF_BasicCommands.cxx
CommitLineData
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
e16302ce 16// ---------------------
7fd59977 17
e16302ce 18// Version: 0.0
19// Version Date Purpose
20// 0.0 Feb 10 1997 Creation
7fd59977 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
66static Standard_Integer DDF_Children (Draw_Interpretor& di,
e16302ce 67 Standard_Integer n,
68 const char** a)
7fd59977 69{
70 if (n < 2) return 1;
e16302ce 71
7fd59977 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
99static Standard_Integer DDF_Attributes (Draw_Interpretor& di,
e16302ce 100 Standard_Integer n,
101 const char** a)
7fd59977 102{
103 if (n != 3) return 1;
e16302ce 104
7fd59977 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
126static Standard_Integer DDF_ForgetAll(Draw_Interpretor& /*di*/,
e16302ce 127 Standard_Integer n,
128 const char** a)
7fd59977 129{
130 if (n != 3) return 1;
e16302ce 131
7fd59977 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();
e16302ce 140 //POP pour NT
7fd59977 141 return 0;
142}
143
e16302ce 144//=======================================================================
145//function : ForgetAttribute
146//purpose : "ForgetAtt dfname Label guid"
147//=======================================================================
148
149static Standard_Integer DDF_ForgetAttribute(Draw_Interpretor& di,
150 Standard_Integer n,
151 const char** a)
152{
153 if (n != 4) return 1;
154 Handle(TDF_Data) DF;
155 if (!DDF::GetDF (a[1], DF)) return 1;
7fd59977 156
e16302ce 157 TDF_Label aLabel;
158 TDF_Tool::Label(DF,a[2],aLabel);
159 if (aLabel.IsNull()) return 1;
160 if (!Standard_GUID::CheckGUIDFormat(a[3]))
161 {
162 di<<"DDF: The format of GUID is invalid\n";
163 return 1;
164 }
165 Standard_GUID guid(a[3]);
166 aLabel.ForgetAttribute(guid);
167 return 0;
168}
7fd59977 169
170// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
171// save/restore & Store/Retrieve commands
172// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
173
174
175
176//==========================================================
177// ErrorMessage
178//==========================================================
179
180void ErrorMessage (const Storage_Error n)
181{
182 cout << "Storage Error: " << flush;
183
184 switch (n) {
185 case Storage_VSOk:
186 cout << "no problem" << endl;
187 break;
188 case Storage_VSOpenError:
189 cout << "while opening the stream" << endl;
190 break;
191 case Storage_VSModeError:
192 cout << "the stream is opened with a wrong mode for operation " << endl;
193 break;
194 case Storage_VSCloseError:
195 cout << "while closing the stream" << endl;
196 break;
197 case Storage_VSAlreadyOpen:
198 cout << "stream is already opened" << endl;
199 break;
200 case Storage_VSNotOpen:
201 cout << "stream not opened" << endl;
202 break;
203 case Storage_VSSectionNotFound:
204 cout << "the section is not found" << endl;
205 break;
206 case Storage_VSWriteError:
207 cout << "error during writing" << endl;
208 break;
209 case Storage_VSFormatError:
210 cout << "wrong format error occured while reading" << endl;
211 break;
212 case Storage_VSUnknownType:
213 cout << "try to read an unknown type" << endl;
214 break;
215 case Storage_VSTypeMismatch:
216 cout << "try to read a wrong primitive type (read a char while expecting a real)" << endl;
217 break;
218 case Storage_VSInternalError:
219 cout << "internal error" << endl;
220 break;
221 case Storage_VSExtCharParityError: cout << "parity error" << endl;
222 break;
223 default:
224 cout << "unknown error code" << endl;
225 break;
226 }
227}
228
229
230//=======================================================================
231//function : DDF_SetTagger
232//purpose : SetTagger (DF, entry)
233//=======================================================================
234
235static Standard_Integer DDF_SetTagger (Draw_Interpretor& di,
e16302ce 236 Standard_Integer nb,
237 const char** arg)
7fd59977 238{
239 if (nb == 3) {
240 Handle(TDF_Data) DF;
241 if (!DDF::GetDF(arg[1],DF)) return 1;
242 TDF_Label L;
243 DDF::AddLabel(DF, arg[2], L);
244 TDF_TagSource::Set(L);
245 return 0;
246 }
586db386 247 di << "DDF_SetTagger : Error\n";
7fd59977 248 return 1;
249}
250
251
252
253//=======================================================================
254//function : DDF_NewTag
255//purpose : NewTag (DF,[father]
256//=======================================================================
257
258static Standard_Integer DDF_NewTag (Draw_Interpretor& di,
e16302ce 259 Standard_Integer nb,
260 const char** arg)
7fd59977 261{
262 if (nb == 3) {
263 Handle(TDF_Data) DF;
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;
267 di << A->NewTag ();
268 return 0;
269 }
586db386 270 di << "DDF_NewTag : Error\n";
7fd59977 271 return 1;
272}
273
274
275//=======================================================================
276//function : DDF_NewChild
277//purpose : NewChild(DF,[father])
278//=======================================================================
279
280static Standard_Integer DDF_NewChild (Draw_Interpretor& di,
e16302ce 281 Standard_Integer nb,
282 const char** arg)
7fd59977 283{
284 Handle(TDF_Data) DF;
285 if (nb>=2){
286 if (!DDF::GetDF(arg[1],DF)) return 1;
287 if (nb == 2) {
288 TDF_Label free = TDF_TagSource::NewChild(DF->Root());
289 di << free.Tag();
290 return 0;
291 }
292 else if (nb == 3) {
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();
297 return 0;
298 }
299 }
586db386 300 di << "DDF_NewChild : Error\n";
7fd59977 301 return 1;
302}
303
304
305//=======================================================================
306//function : Label (DF,freeentry)
307//=======================================================================
308
309static Standard_Integer DDF_Label (Draw_Interpretor& di,Standard_Integer n, const char** a)
310{
311 if (n == 3) {
312 Handle(TDF_Data) DF;
313 if (!DDF::GetDF (a[1],DF)) return 1;
314 TDF_Label L;
315 if (!DDF::FindLabel(DF,a[2],L,Standard_False)) {
316 DDF::AddLabel(DF,a[2],L);
586db386 317 //di << "Label : " << a[2] << " created\n";
7fd59977 318 }
586db386 319 //else di << "Label : " << a[2] << " retrieved\n";
7fd59977 320 DDF::ReturnLabel(di,L);
321 return 0;
322 }
586db386 323 di << "DDF_Label : Error\n";
7fd59977 324 return 1;
325}
326
327
328//=======================================================================
329//function : BasicCommands
330//purpose :
331//=======================================================================
332
333void DDF::BasicCommands (Draw_Interpretor& theCommands)
334{
335 static Standard_Boolean done = Standard_False;
336 if (done) return;
337 done = Standard_True;
338
339 const char* g = "DF basic commands";
340
e16302ce 341 // Label :
7fd59977 342
343 theCommands.Add ("SetTagger",
344 "SetTagger (DF, entry)",
e16302ce 345 __FILE__, DDF_SetTagger, g);
7fd59977 346
347 theCommands.Add ("NewTag",
348 "NewTag (DF, tagger)",
e16302ce 349 __FILE__, DDF_NewTag, g);
7fd59977 350
351 theCommands.Add ("NewChild",
352 "NewChild (DF, [tagger])",
e16302ce 353 __FILE__, DDF_NewChild, g);
7fd59977 354
355 theCommands.Add ("Children",
e16302ce 356 " Returns the list of label children: Children DF label",
357 __FILE__, DDF_Children, g);
7fd59977 358
359 theCommands.Add ("Attributes",
e16302ce 360 " Returns the list of label attributes: Attributes DF label",
361 __FILE__, DDF_Attributes, g);
7fd59977 362
363 theCommands.Add ("ForgetAll",
e16302ce 364 "Forgets all attributes from the label: ForgetAll DF Label",
365 __FILE__, DDF_ForgetAll, g);
7fd59977 366
e16302ce 367 theCommands.Add ("ForgetAtt",
368 "Forgets the specified by guid attribute from the label: ForgetAtt DF Label guid",
369 __FILE__, DDF_ForgetAttribute, g);
7fd59977 370
e16302ce 371 theCommands.Add ("Label",
372 "Label DF entry",
373 __FILE__, DDF_Label, g);
7fd59977 374
375}