summaryrefslogtreecommitdiff
path: root/src/DDF/DDF_BasicCommands.cxx
blob: 55517b0cfc299d9e689f41aa643ead8ecacce6ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
// File:	DDF_BasicCommands.cxx
//      	---------------------
// Author:	DAUTRY Philippe & VAUTHIER Jean-Claude
// Copyright:	Matra Datavision 1997

// Version:	0.0
// History:	Version	Date		Purpose
//		0.0	Feb 10 1997	Creation


#include <DDF.hxx>

#include <TDF_ComparisonTool.hxx>
#include <TDF_CopyTool.hxx>
#include <TDF_ClosureMode.hxx>
#include <TDF_ClosureTool.hxx>

#include <DDF_Data.hxx>

#include <Draw.hxx>
#include <Draw_Appli.hxx>
#include <Draw_Drawable3D.hxx>
#include <Draw_Interpretor.hxx>
#include <Standard_GUID.hxx>
#include <Standard_NotImplemented.hxx>

#include <TColStd_HSequenceOfAsciiString.hxx>
#include <TColStd_ListOfInteger.hxx>
#include <TColStd_SequenceOfAsciiString.hxx>

#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>

#include <TDF_Attribute.hxx>
#include <TDF_TagSource.hxx>
#include <TDF_AttributeIterator.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_Data.hxx>
#include <TDF_DataSet.hxx>
#include <TDF_Delta.hxx>
#include <TDF_IDFilter.hxx>
#include <TDF_Label.hxx>
#include <TDF_RelocationTable.hxx>
#include <TDF_Tool.hxx>

#include <DDF_IOStream.hxx>


//=======================================================================
//function : Children
//purpose  : Returns a list of sub-label entries.
//=======================================================================

static Standard_Integer DDF_Children (Draw_Interpretor& di, 
				      Standard_Integer  n, 
				      const char**            a)
{
  if (n < 2) return 1;
  
  Handle(TDF_Data) DF;
  TCollection_AsciiString entry;

  if (!DDF::GetDF (a[1], DF)) return 1;

  TDF_Label lab;
  if (n == 3) TDF_Tool::Label(DF,a[2],lab);

  if (lab.IsNull()) {
    di<<"0";
  }
  else {
    for (TDF_ChildIterator itr(lab); itr.More(); itr.Next()) {
      TDF_Tool::Entry(itr.Value(),entry);
      //TCollection_AsciiString entry(itr.Value().Tag());
      di<<entry.ToCString()<<" ";
    }
  }
  return 0;
}


//=======================================================================
//function : Attributes
//purpose  : Returns a list of label attributes.
//=======================================================================

static Standard_Integer DDF_Attributes (Draw_Interpretor& di, 
					Standard_Integer  n, 
					const char**            a)
{
  if (n != 3) return 1;
  
  Handle(TDF_Data) DF;

  if (!DDF::GetDF (a[1], DF)) return 1;

  TDF_Label lab;
  TDF_Tool::Label(DF,a[2],lab);

  if (lab.IsNull()) return 1;

  for (TDF_AttributeIterator itr(lab); itr.More(); itr.Next()) {
    di<<itr.Value()->DynamicType()->Name()<<" ";
  }
  return 0;
}


//=======================================================================
//function : ForgetAll
//purpose  : "ForgetAll dfname Label"
//=======================================================================

static Standard_Integer DDF_ForgetAll(Draw_Interpretor& /*di*/, 
				      Standard_Integer  n, 
				      const char**            a)
{
  if (n != 3) return 1;
  
  Handle(TDF_Data) DF;

  if (!DDF::GetDF (a[1], DF)) return 1;

  TDF_Label label;
  TDF_Tool::Label(DF,a[2],label);
  if (label.IsNull()) return 1;
  label.ForgetAllAttributes();
//POP pour NT
  return 0;
}



// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// save/restore & Store/Retrieve commands
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++



//==========================================================
// ErrorMessage
//==========================================================

void ErrorMessage (const Storage_Error n) 
{
  cout << "Storage Error: " << flush;

  switch (n) {
  case Storage_VSOk:
    cout << "no problem" << endl;
    break;
  case Storage_VSOpenError:
    cout << "while opening the stream" << endl;
    break;
  case Storage_VSModeError:
    cout << "the stream is opened with a wrong mode for operation " << endl;
    break;
  case Storage_VSCloseError:
    cout << "while closing the stream" << endl;
    break;
  case Storage_VSAlreadyOpen:
    cout << "stream is already opened" << endl;
    break;
  case Storage_VSNotOpen:
    cout << "stream not opened" << endl;
    break;
  case Storage_VSSectionNotFound:
    cout << "the section is not found" << endl;
    break;
  case Storage_VSWriteError:
    cout << "error during writing" << endl;
    break;
  case Storage_VSFormatError:
    cout << "wrong format error occured while reading" << endl;
    break;
  case Storage_VSUnknownType:
    cout << "try to read an unknown type" << endl;
    break;
  case Storage_VSTypeMismatch:
    cout << "try to read a wrong primitive type (read a char while expecting a real)" << endl;
    break;
  case Storage_VSInternalError:
    cout << "internal error" << endl;
    break;
  case Storage_VSExtCharParityError:      cout << "parity error" << endl;
    break;
  default:
    cout << "unknown error code" << endl;
    break;
  }
}


//=======================================================================
//function : DDF_SetTagger
//purpose  : SetTagger (DF, entry)
//=======================================================================

static Standard_Integer DDF_SetTagger (Draw_Interpretor& di,
					       Standard_Integer nb, 
					       const char** arg) 
{   
  if (nb == 3) {    
    Handle(TDF_Data) DF;
    if (!DDF::GetDF(arg[1],DF)) return 1;
    TDF_Label L;
    DDF::AddLabel(DF, arg[2], L);
    TDF_TagSource::Set(L); 
    return 0;
  }
  di << "DDF_SetTagger : Error" << "\n";
  return 1;
}



//=======================================================================
//function : DDF_NewTag
//purpose  : NewTag (DF,[father]
//=======================================================================

static Standard_Integer DDF_NewTag (Draw_Interpretor& di,
					 Standard_Integer nb, 
					 const char** arg) 
{ 
  if (nb == 3) {
    Handle(TDF_Data) DF;
    if (!DDF::GetDF(arg[1],DF)) return 1;
    Handle(TDF_TagSource) A;
    if (!DDF::Find(DF,arg[2],TDF_TagSource::GetID(),A)) return 1;
    di << A->NewTag ();
    return 0;
  }
  di << "DDF_NewTag : Error" << "\n";
  return 1;
}


//=======================================================================
//function : DDF_NewChild
//purpose  : NewChild(DF,[father])
//=======================================================================

static Standard_Integer DDF_NewChild (Draw_Interpretor& di,
					   Standard_Integer nb, 
					   const char** arg) 
{ 
  Handle(TDF_Data) DF;
  if (nb>=2){
    if (!DDF::GetDF(arg[1],DF)) return 1;
    if (nb == 2) {
      TDF_Label free = TDF_TagSource::NewChild(DF->Root());
      di << free.Tag();
      return 0;
    } 
    else  if (nb == 3) {
      TDF_Label fatherlabel;
      if (!DDF::FindLabel(DF,arg[2],fatherlabel)) return 1;
      TDF_Label free = TDF_TagSource::NewChild (fatherlabel);
      di << arg[2] << ":" << free.Tag();
      return 0;
    }
  }
  di << "DDF_NewChild : Error" << "\n";
  return 1;
}


//=======================================================================
//function : Label (DF,freeentry)
//=======================================================================

static Standard_Integer DDF_Label (Draw_Interpretor& di,Standard_Integer n, const char** a)
{  
  if (n == 3) {  
    Handle(TDF_Data) DF;  
    if (!DDF::GetDF (a[1],DF)) return 1; 
    TDF_Label L;
    if (!DDF::FindLabel(DF,a[2],L,Standard_False)) { 
      DDF::AddLabel(DF,a[2],L);  
      //di << "Label : " << a[2] << " created" << "\n";
    }
    //else di << "Label : " << a[2] << " retrieved" << "\n";
    DDF::ReturnLabel(di,L);
    return 0;
  }
  di << "DDF_Label : Error" << "\n";
  return 1; 
}


//=======================================================================
//function : BasicCommands
//purpose  : 
//=======================================================================

void DDF::BasicCommands (Draw_Interpretor& theCommands) 
{
  static Standard_Boolean done = Standard_False;
  if (done) return;
  done = Standard_True;

  const char* g = "DF basic commands";

  // Label :  

  theCommands.Add ("SetTagger", 
                   "SetTagger (DF, entry)",
		   __FILE__, DDF_SetTagger, g);  

  theCommands.Add ("NewTag", 
                   "NewTag (DF, tagger)",
		   __FILE__, DDF_NewTag, g);

  theCommands.Add ("NewChild", 
                   "NewChild (DF, [tagger])",
		   __FILE__, DDF_NewChild, g);

  theCommands.Add ("Children",
		   " Returns the list of label children: Children DF label",
		   __FILE__, DDF_Children, g);

  theCommands.Add ("Attributes",
		   " Returns the list of label attributes: Attributes DF label",
		   __FILE__, DDF_Attributes, g);

  theCommands.Add ("ForgetAll",
		   "Forgets all attributes from the label: ForgetAll DF Label",
		   __FILE__, DDF_ForgetAll, g);

  theCommands.Add ("Label",
		   "Label DF entry",
		  __FILE__, DDF_Label, g);  


}