1 // Created by: DAUTRY Philippe & VAUTHIER Jean-Claude
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 // ---------------------
17
18 // Version: 0.0
19 // Version Date Purpose
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 #include <TDF_DerivedAttribute.hxx>
58
59 //=======================================================================
60 //function : Children
61 //purpose : Returns a list of sub-label entries.
62 //=======================================================================
63
DDF_Children(Draw_Interpretor & di,Standard_Integer n,const char ** a)64 static Standard_Integer DDF_Children (Draw_Interpretor& di,
65 Standard_Integer n,
66 const char** a)
67 {
68 if (n < 2) return 1;
69
70 Handle(TDF_Data) DF;
71 TCollection_AsciiString entry;
72
73 if (!DDF::GetDF (a[1], DF)) return 1;
74
75 TDF_Label lab;
76 if (n == 3) TDF_Tool::Label(DF,a[2],lab);
77
78 if (lab.IsNull()) {
79 di<<"0";
80 }
81 else {
82 for (TDF_ChildIterator itr(lab); itr.More(); itr.Next()) {
83 TDF_Tool::Entry(itr.Value(),entry);
84 //TCollection_AsciiString entry(itr.Value().Tag());
85 di<<entry.ToCString()<<" ";
86 }
87 }
88 return 0;
89 }
90
91
92 //=======================================================================
93 //function : Attributes
94 //purpose : Returns a list of label attributes.
95 //=======================================================================
96
DDF_Attributes(Draw_Interpretor & di,Standard_Integer n,const char ** a)97 static Standard_Integer DDF_Attributes (Draw_Interpretor& di,
98 Standard_Integer n,
99 const char** a)
100 {
101 if (n != 3) return 1;
102
103 Handle(TDF_Data) DF;
104
105 if (!DDF::GetDF (a[1], DF)) return 1;
106
107 TDF_Label lab;
108 TDF_Tool::Label(DF,a[2],lab);
109
110 if (lab.IsNull()) return 1;
111
112 for (TDF_AttributeIterator itr(lab); itr.More(); itr.Next()) {
113 di<<itr.Value()->DynamicType()->Name()<<" ";
114 }
115 return 0;
116 }
117
118 //=======================================================================
119 //function : SetEmptyAttribute
120 //purpose : Adds an empty attribute to the label by its dynamic type.
121 //=======================================================================
122
DDF_SetEmptyAttribute(Draw_Interpretor & di,Standard_Integer n,const char ** a)123 static Standard_Integer DDF_SetEmptyAttribute (Draw_Interpretor& di,
124 Standard_Integer n,
125 const char** a)
126 {
127 if (n != 4) return 1;
128
129 Handle(TDF_Data) DF;
130
131 if (!DDF::GetDF (a[1], DF)) return 1;
132
133 TDF_Label lab;
134 TDF_Tool::Label(DF,a[2],lab);
135
136 if (lab.IsNull()) return 1;
137
138 Handle(TDF_Attribute) anAttrByType = TDF_DerivedAttribute::Attribute(a[3]);
139 if (anAttrByType.IsNull()) {
140 di<<"DDF: Not registered attribute type '"<<a[3]<<"'\n";
141 return 1;
142 }
143
144 lab.AddAttribute(anAttrByType);
145
146 return 0;
147 }
148
149
150 //=======================================================================
151 //function : ForgetAll
152 //purpose : "ForgetAll dfname Label"
153 //=======================================================================
154
DDF_ForgetAll(Draw_Interpretor &,Standard_Integer n,const char ** a)155 static Standard_Integer DDF_ForgetAll(Draw_Interpretor& /*di*/,
156 Standard_Integer n,
157 const char** a)
158 {
159 if (n != 3) return 1;
160
161 Handle(TDF_Data) DF;
162
163 if (!DDF::GetDF (a[1], DF)) return 1;
164
165 TDF_Label label;
166 TDF_Tool::Label(DF,a[2],label);
167 if (label.IsNull()) return 1;
168 label.ForgetAllAttributes();
169 //POP pour NT
170 return 0;
171 }
172
173 //=======================================================================
174 //function : ForgetAttribute
175 //purpose : "ForgetAtt dfname Label guid_or_type"
176 //=======================================================================
177
DDF_ForgetAttribute(Draw_Interpretor & di,Standard_Integer n,const char ** a)178 static Standard_Integer DDF_ForgetAttribute(Draw_Interpretor& di,
179 Standard_Integer n,
180 const char** a)
181 {
182 if (n != 4) return 1;
183 Handle(TDF_Data) DF;
184 if (!DDF::GetDF (a[1], DF)) return 1;
185
186 TDF_Label aLabel;
187 TDF_Tool::Label(DF,a[2],aLabel);
188 if (aLabel.IsNull()) return 1;
189 if (!Standard_GUID::CheckGUIDFormat(a[3]))
190 {
191 // check this may be derived attribute by its type
192 Handle(TDF_Attribute) anAttrByType = TDF_DerivedAttribute::Attribute(a[3]);
193 if (!anAttrByType.IsNull()) {
194 aLabel.ForgetAttribute(anAttrByType->ID());
195 return 0;
196 }
197 di<<"DDF: The format of GUID is invalid\n";
198 return 1;
199 }
200 Standard_GUID guid(a[3]);
201 aLabel.ForgetAttribute(guid);
202 return 0;
203 }
204
205 //=======================================================================
206 //function : DDF_SetTagger
207 //purpose : SetTagger (DF, entry)
208 //=======================================================================
209
DDF_SetTagger(Draw_Interpretor & di,Standard_Integer nb,const char ** arg)210 static Standard_Integer DDF_SetTagger (Draw_Interpretor& di,
211 Standard_Integer nb,
212 const char** arg)
213 {
214 if (nb == 3) {
215 Handle(TDF_Data) DF;
216 if (!DDF::GetDF(arg[1],DF)) return 1;
217 TDF_Label L;
218 DDF::AddLabel(DF, arg[2], L);
219 TDF_TagSource::Set(L);
220 return 0;
221 }
222 di << "DDF_SetTagger : Error\n";
223 return 1;
224 }
225
226
227
228 //=======================================================================
229 //function : DDF_NewTag
230 //purpose : NewTag (DF,[father]
231 //=======================================================================
232
DDF_NewTag(Draw_Interpretor & di,Standard_Integer nb,const char ** arg)233 static Standard_Integer DDF_NewTag (Draw_Interpretor& di,
234 Standard_Integer nb,
235 const char** arg)
236 {
237 if (nb == 3) {
238 Handle(TDF_Data) DF;
239 if (!DDF::GetDF(arg[1],DF)) return 1;
240 Handle(TDF_TagSource) A;
241 if (!DDF::Find(DF,arg[2],TDF_TagSource::GetID(),A)) return 1;
242 di << A->NewTag ();
243 return 0;
244 }
245 di << "DDF_NewTag : Error\n";
246 return 1;
247 }
248
249
250 //=======================================================================
251 //function : DDF_NewChild
252 //purpose : NewChild(DF,[father])
253 //=======================================================================
254
DDF_NewChild(Draw_Interpretor & di,Standard_Integer nb,const char ** arg)255 static Standard_Integer DDF_NewChild (Draw_Interpretor& di,
256 Standard_Integer nb,
257 const char** arg)
258 {
259 Handle(TDF_Data) DF;
260 if (nb>=2){
261 if (!DDF::GetDF(arg[1],DF)) return 1;
262 if (nb == 2) {
263 TDF_Label free = TDF_TagSource::NewChild(DF->Root());
264 di << free.Tag();
265 return 0;
266 }
267 else if (nb == 3) {
268 TDF_Label fatherlabel;
269 if (!DDF::FindLabel(DF,arg[2],fatherlabel)) return 1;
270 TDF_Label free = TDF_TagSource::NewChild (fatherlabel);
271 di << arg[2] << ":" << free.Tag();
272 return 0;
273 }
274 }
275 di << "DDF_NewChild : Error\n";
276 return 1;
277 }
278
279
280 //=======================================================================
281 //function : Label (DF,freeentry)
282 //=======================================================================
283
DDF_Label(Draw_Interpretor & di,Standard_Integer n,const char ** a)284 static Standard_Integer DDF_Label (Draw_Interpretor& di,Standard_Integer n, const char** a)
285 {
286 if (n == 3) {
287 Handle(TDF_Data) DF;
288 if (!DDF::GetDF (a[1],DF)) return 1;
289 TDF_Label L;
290 if (!DDF::FindLabel(DF,a[2],L,Standard_False)) {
291 DDF::AddLabel(DF,a[2],L);
292 //di << "Label : " << a[2] << " created\n";
293 }
294 //else di << "Label : " << a[2] << " retrieved\n";
295 DDF::ReturnLabel(di,L);
296 return 0;
297 }
298 di << "DDF_Label : Error\n";
299 return 1;
300 }
301
302
303 //=======================================================================
304 //function : BasicCommands
305 //purpose :
306 //=======================================================================
307
BasicCommands(Draw_Interpretor & theCommands)308 void DDF::BasicCommands (Draw_Interpretor& theCommands)
309 {
310 static Standard_Boolean done = Standard_False;
311 if (done) return;
312 done = Standard_True;
313
314 const char* g = "DF basic commands";
315
316 // Label :
317
318 theCommands.Add ("SetTagger",
319 "SetTagger (DF, entry)",
320 __FILE__, DDF_SetTagger, g);
321
322 theCommands.Add ("NewTag",
323 "NewTag (DF, tagger)",
324 __FILE__, DDF_NewTag, g);
325
326 theCommands.Add ("NewChild",
327 "NewChild (DF, [tagger])",
328 __FILE__, DDF_NewChild, g);
329
330 theCommands.Add ("Children",
331 " Returns the list of label children: Children DF label",
332 __FILE__, DDF_Children, g);
333
334 theCommands.Add ("Attributes",
335 " Returns the list of label attributes: Attributes DF label",
336 __FILE__, DDF_Attributes, g);
337
338 theCommands.Add ("SetEmptyAttribute",
339 "Sets an empty attribute by its type (like TDataStd_Tick): SetEmptyAttribute DF label type",
340 __FILE__, DDF_SetEmptyAttribute, g);
341
342 theCommands.Add ("ForgetAll",
343 "Forgets all attributes from the label: ForgetAll DF Label",
344 __FILE__, DDF_ForgetAll, g);
345
346 theCommands.Add ("ForgetAtt",
347 "Forgets the specified by guid attribute or type from the label: ForgetAtt DF Label guid_or_type",
348 __FILE__, DDF_ForgetAttribute, g);
349
350 theCommands.Add ("Label",
351 "Label DF entry",
352 __FILE__, DDF_Label, g);
353
354 }
355