Integration of OCCT 6.5.0 from SVN
[occt.git] / src / DDataStd / DDataStd_ObjectCommands.cxx
CommitLineData
7fd59977 1// File: DDataStd_ObjectCommands.cxx
2// Created: Thu Jul 15 10:19:40 1999
3// Author: Denis PASCAL
4// <dp@dingox.paris1.matra-dtv.fr>
5
6#include <DDataStd.hxx>
7#include <DDataStd_DrawPresentation.hxx>
8#include <DDF.hxx>
9#include <Draw_Interpretor.hxx>
10#include <Draw_Appli.hxx>
11#include <TDF_Data.hxx>
12#include <TDF_Tool.hxx>
13#include <TDF_ChildIterator.hxx>
14#include <TDF_Label.hxx>
15#include <Standard_GUID.hxx>
16#include <TDataStd_Directory.hxx>
17#include <TDataXtd_Shape.hxx>
18
19
20// LES ATTRIBUTES
21
22#include <TDataStd_NoteBook.hxx>
23#include <TDataXtd_Shape.hxx>
24
25
26#include <TopoDS_Shape.hxx>
27#include <DBRep.hxx>
28
29
30//=======================================================================
31//function : NewDirectory (DF, entry )
32//=======================================================================
33static Standard_Integer DDataStd_NewDirectory (Draw_Interpretor& di,
34 Standard_Integer nb,
35 const char** arg)
36{
37 if( nb != 3 ) {
38 di << "Too few arguments" << "\n";
39 return 1;
40 }
41 Handle(TDF_Data) DF;
42 if (!DDF::GetDF(arg[1],DF)) return 1;
43 TDF_Label label;
44 DDF::AddLabel(DF, arg[2], label);
45 TDataStd_Directory::New(label );
46 return 0;
47}
48
49
50//=======================================================================
51//function : AddDirectory (DF, entry )
52//=======================================================================
53static Standard_Integer DDataStd_AddDirectory (Draw_Interpretor& di,
54 Standard_Integer nb,
55 const char** arg)
56{
57 if( nb != 3 ) {
58 di << "Too few arguments" << "\n";
59 return 1;
60 }
61 Handle(TDF_Data) DF;
62 if (!DDF::GetDF(arg[1],DF)) return 1;
63 TDF_Label label;
64 if( !DDF::FindLabel(DF, arg[2], label) ) {
65 di << "No label for entry" << "\n";
66 return 1;
67 }
68 Handle(TDataStd_Directory) A;
69 if (TDataStd_Directory::Find(label, A)) {
70 Handle(TDataStd_Directory) Dir = TDataStd_Directory::AddDirectory (A);
71 TCollection_AsciiString entry;
72 TDF_Tool::Entry(Dir->Label(), entry);
73 di << entry.ToCString()<<" "; //return a label to draw
74 return 0;
75 }
76 di << "No Object Attribute on label" << "\n";
77 return 1;
78}
79
80//=======================================================================
81//function : MakeObjectLabel (DF, entry )
82//=======================================================================
83static Standard_Integer DDataStd_MakeObjectLabel (Draw_Interpretor& di,
84 Standard_Integer nb,
85 const char** arg)
86{
87 if( nb != 3 ) {
88 di << "Too few arguments" << "\n";
89 return 1;
90 }
91 Handle(TDF_Data) DF;
92 if (!DDF::GetDF(arg[1],DF)) return 1;
93 TDF_Label label;
94 if( !DDF::FindLabel(DF, arg[2], label) ) {
95 di << "No label for entry" << "\n";
96 return 1;
97 }
98 Handle(TDataStd_Directory) A;
99 if(TDataStd_Directory::Find(label,A)) {
100 TCollection_AsciiString entry;
101 TDF_Tool::Entry(TDataStd_Directory::MakeObjectLabel(A), entry);
102 di << entry.ToCString()<<" "; //return a label to draw
103 return 0;
104 }
105 di << "No Object Attribute on label" << "\n";
106 return 1;
107}
108
109
110
111//=======================================================================
112//function : DDataStd_NewNoteBook
113//purpose : NewNoteBook (DF, entry)
114//=======================================================================
115
116static Standard_Integer DDataStd_NewNoteBook (Draw_Interpretor& di,
117 Standard_Integer nb,
118 const char** arg)
119{
120 if (nb == 3) {
121 Handle(TDF_Data) DF;
122 if (!DDF::GetDF(arg[1],DF)) return 1;
123 TDF_Label L;
124 DDF::AddLabel(DF, arg[2], L);
125 TDataStd_NoteBook::New(L);
126 return 0;
127 }
128 di << "DDataStd_NewNoteBook : Error" << "\n";
129 return 1;
130}
131
132//=======================================================================
133//function : NewShape (DF, entry, [in_shape] )
134//=======================================================================
135static Standard_Integer DDataStd_NewShape (Draw_Interpretor& di,
136 Standard_Integer nb,
137 const char** arg)
138{
139 //di << "nb = " <<nb << "\n";
140 if( nb < 3 ) {
141 di << "Too few arguments" << "\n";
142 return 1;
143 }
144 Handle(TDF_Data) DF;
145 if (!DDF::GetDF(arg[1],DF)) return 1;
146 TDF_Label label;
147 DDF::AddLabel(DF, arg[2], label);
148 if( nb == 4 ) {
149 TopoDS_Shape shape = DBRep::Get( arg[3] );
150 if( shape.IsNull() ) {
151 di << "Shape argument is invalid" << "\n";
152 return 1;
153 }
154 TDataXtd_Shape::Set(label, shape );
155 }
156 else TDataXtd_Shape::New(label);
157 return 0;
158}
159
160
161//=======================================================================
162//function : GetShape2 (DF, entry, out_shape )
163//=======================================================================
164static Standard_Integer DDataStd_GetShape2 (Draw_Interpretor& di,
165 Standard_Integer nb,
166 const char** arg)
167{
168 if( nb < 4 ) {
169 di << "Too few arguments" << "\n";
170 return 1;
171 }
172 Handle(TDF_Data) DF;
173 if (!DDF::GetDF(arg[1],DF)) return 1;
174 TDF_Label label;
175 if( !DDF::FindLabel(DF, arg[2], label) ) {
176 di << "No label for entry" << "\n";
177 return 1;
178 }
179 DBRep::Set(arg[3], TDataXtd_Shape::Get(label));
180
181 return 0;
182}
183
184
185
186//=======================================================================
187//function : ObjectComands
188//purpose :
189//=======================================================================
190
191void DDataStd::ObjectCommands (Draw_Interpretor& theCommands)
192{
193
194 static Standard_Boolean done = Standard_False;
195 if (done) return;
196 done = Standard_True;
197 const char* g = "DData : Standard Attribute Commands";
198
199 theCommands.Add ("NewNoteBook",
200 "NewNoteBook (DF, entry)",
201 __FILE__, DDataStd_NewNoteBook, g);
202
203 theCommands.Add ("NewShape",
204 "NewShape (DF, entry, [in_shape] )",
205 __FILE__, DDataStd_NewShape, g);
206
207 theCommands.Add ("GetShape2",
208 "GetShape2 (DF, entry, out_shape )",
209 __FILE__, DDataStd_GetShape2, g);
210
211 theCommands.Add ("NewDirectory",
212 "NewDirectory (DF, entry)",
213 __FILE__, DDataStd_NewDirectory, g);
214
215 theCommands.Add ("AddDirectory",
216 "AddDirectory (DF, entry)",
217 __FILE__, DDataStd_AddDirectory, g);
218
219 theCommands.Add ("MakeObjectLabel",
220 "MakeObjectLabel (DF, entry)",
221 __FILE__, DDataStd_MakeObjectLabel, g);
222
223}
224