1 // Created by: DAUTRY Philippe & VAUTHIER Jean-Claude
2 // Copyright (c) 1997-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // ---------------------
19 // Version Date Purpose
20 // 0.0 Feb 10 1997 Creation
25 #include <TDF_ComparisonTool.hxx>
26 #include <TDF_CopyTool.hxx>
27 #include <TDF_ClosureMode.hxx>
28 #include <TDF_ClosureTool.hxx>
30 #include <DDF_Data.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>
39 #include <TColStd_HSequenceOfAsciiString.hxx>
40 #include <TColStd_ListOfInteger.hxx>
41 #include <TColStd_SequenceOfAsciiString.hxx>
43 #include <TCollection_AsciiString.hxx>
44 #include <TCollection_ExtendedString.hxx>
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>
58 //=======================================================================
60 //purpose : Returns a list of sub-label entries.
61 //=======================================================================
63 static Standard_Integer DDF_Children (Draw_Interpretor& di,
70 TCollection_AsciiString entry;
72 if (!DDF::GetDF (a[1], DF)) return 1;
75 if (n == 3) TDF_Tool::Label(DF,a[2],lab);
81 for (TDF_ChildIterator itr(lab); itr.More(); itr.Next()) {
82 TDF_Tool::Entry(itr.Value(),entry);
83 //TCollection_AsciiString entry(itr.Value().Tag());
84 di<<entry.ToCString()<<" ";
91 //=======================================================================
92 //function : Attributes
93 //purpose : Returns a list of label attributes.
94 //=======================================================================
96 static Standard_Integer DDF_Attributes (Draw_Interpretor& di,
100 if (n != 3) return 1;
104 if (!DDF::GetDF (a[1], DF)) return 1;
107 TDF_Tool::Label(DF,a[2],lab);
109 if (lab.IsNull()) return 1;
111 for (TDF_AttributeIterator itr(lab); itr.More(); itr.Next()) {
112 di<<itr.Value()->DynamicType()->Name()<<" ";
118 //=======================================================================
119 //function : ForgetAll
120 //purpose : "ForgetAll dfname Label"
121 //=======================================================================
123 static Standard_Integer DDF_ForgetAll(Draw_Interpretor& /*di*/,
127 if (n != 3) return 1;
131 if (!DDF::GetDF (a[1], DF)) return 1;
134 TDF_Tool::Label(DF,a[2],label);
135 if (label.IsNull()) return 1;
136 label.ForgetAllAttributes();
141 //=======================================================================
142 //function : ForgetAttribute
143 //purpose : "ForgetAtt dfname Label guid"
144 //=======================================================================
146 static Standard_Integer DDF_ForgetAttribute(Draw_Interpretor& di,
150 if (n != 4) return 1;
152 if (!DDF::GetDF (a[1], DF)) return 1;
155 TDF_Tool::Label(DF,a[2],aLabel);
156 if (aLabel.IsNull()) return 1;
157 if (!Standard_GUID::CheckGUIDFormat(a[3]))
159 di<<"DDF: The format of GUID is invalid\n";
162 Standard_GUID guid(a[3]);
163 aLabel.ForgetAttribute(guid);
167 //=======================================================================
168 //function : DDF_SetTagger
169 //purpose : SetTagger (DF, entry)
170 //=======================================================================
172 static Standard_Integer DDF_SetTagger (Draw_Interpretor& di,
178 if (!DDF::GetDF(arg[1],DF)) return 1;
180 DDF::AddLabel(DF, arg[2], L);
181 TDF_TagSource::Set(L);
184 di << "DDF_SetTagger : Error\n";
190 //=======================================================================
191 //function : DDF_NewTag
192 //purpose : NewTag (DF,[father]
193 //=======================================================================
195 static Standard_Integer DDF_NewTag (Draw_Interpretor& di,
201 if (!DDF::GetDF(arg[1],DF)) return 1;
202 Handle(TDF_TagSource) A;
203 if (!DDF::Find(DF,arg[2],TDF_TagSource::GetID(),A)) return 1;
207 di << "DDF_NewTag : Error\n";
212 //=======================================================================
213 //function : DDF_NewChild
214 //purpose : NewChild(DF,[father])
215 //=======================================================================
217 static Standard_Integer DDF_NewChild (Draw_Interpretor& di,
223 if (!DDF::GetDF(arg[1],DF)) return 1;
225 TDF_Label free = TDF_TagSource::NewChild(DF->Root());
230 TDF_Label fatherlabel;
231 if (!DDF::FindLabel(DF,arg[2],fatherlabel)) return 1;
232 TDF_Label free = TDF_TagSource::NewChild (fatherlabel);
233 di << arg[2] << ":" << free.Tag();
237 di << "DDF_NewChild : Error\n";
242 //=======================================================================
243 //function : Label (DF,freeentry)
244 //=======================================================================
246 static Standard_Integer DDF_Label (Draw_Interpretor& di,Standard_Integer n, const char** a)
250 if (!DDF::GetDF (a[1],DF)) return 1;
252 if (!DDF::FindLabel(DF,a[2],L,Standard_False)) {
253 DDF::AddLabel(DF,a[2],L);
254 //di << "Label : " << a[2] << " created\n";
256 //else di << "Label : " << a[2] << " retrieved\n";
257 DDF::ReturnLabel(di,L);
260 di << "DDF_Label : Error\n";
265 //=======================================================================
266 //function : BasicCommands
268 //=======================================================================
270 void DDF::BasicCommands (Draw_Interpretor& theCommands)
272 static Standard_Boolean done = Standard_False;
274 done = Standard_True;
276 const char* g = "DF basic commands";
280 theCommands.Add ("SetTagger",
281 "SetTagger (DF, entry)",
282 __FILE__, DDF_SetTagger, g);
284 theCommands.Add ("NewTag",
285 "NewTag (DF, tagger)",
286 __FILE__, DDF_NewTag, g);
288 theCommands.Add ("NewChild",
289 "NewChild (DF, [tagger])",
290 __FILE__, DDF_NewChild, g);
292 theCommands.Add ("Children",
293 " Returns the list of label children: Children DF label",
294 __FILE__, DDF_Children, g);
296 theCommands.Add ("Attributes",
297 " Returns the list of label attributes: Attributes DF label",
298 __FILE__, DDF_Attributes, g);
300 theCommands.Add ("ForgetAll",
301 "Forgets all attributes from the label: ForgetAll DF Label",
302 __FILE__, DDF_ForgetAll, g);
304 theCommands.Add ("ForgetAtt",
305 "Forgets the specified by guid attribute from the label: ForgetAtt DF Label guid",
306 __FILE__, DDF_ForgetAttribute, g);
308 theCommands.Add ("Label",
310 __FILE__, DDF_Label, g);