b311480e |
1 | // Created on: 1999-07-15 |
2 | // Created by: Denis PASCAL |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <DDataStd.hxx> |
18 | #include <DDataStd_DrawPresentation.hxx> |
19 | #include <DDF.hxx> |
20 | #include <Draw_Interpretor.hxx> |
21 | #include <Draw_Appli.hxx> |
22 | #include <TDF_Data.hxx> |
23 | #include <TDF_Tool.hxx> |
24 | #include <TDF_ChildIterator.hxx> |
25 | #include <TDF_Label.hxx> |
26 | #include <Standard_GUID.hxx> |
27 | #include <TDataStd_Directory.hxx> |
28 | #include <TDataXtd_Shape.hxx> |
29 | |
30 | |
31 | // LES ATTRIBUTES |
32 | |
33 | #include <TDataStd_NoteBook.hxx> |
34 | #include <TDataXtd_Shape.hxx> |
35 | |
36 | |
37 | #include <TopoDS_Shape.hxx> |
38 | #include <DBRep.hxx> |
39 | |
40 | |
41 | //======================================================================= |
42 | //function : NewDirectory (DF, entry ) |
43 | //======================================================================= |
44 | static Standard_Integer DDataStd_NewDirectory (Draw_Interpretor& di, |
45 | Standard_Integer nb, |
46 | const char** arg) |
47 | { |
48 | if( nb != 3 ) { |
49 | di << "Too few arguments" << "\n"; |
50 | return 1; |
51 | } |
52 | Handle(TDF_Data) DF; |
53 | if (!DDF::GetDF(arg[1],DF)) return 1; |
54 | TDF_Label label; |
55 | DDF::AddLabel(DF, arg[2], label); |
56 | TDataStd_Directory::New(label ); |
57 | return 0; |
58 | } |
59 | |
60 | |
61 | //======================================================================= |
62 | //function : AddDirectory (DF, entry ) |
63 | //======================================================================= |
64 | static Standard_Integer DDataStd_AddDirectory (Draw_Interpretor& di, |
65 | Standard_Integer nb, |
66 | const char** arg) |
67 | { |
68 | if( nb != 3 ) { |
69 | di << "Too few arguments" << "\n"; |
70 | return 1; |
71 | } |
72 | Handle(TDF_Data) DF; |
73 | if (!DDF::GetDF(arg[1],DF)) return 1; |
74 | TDF_Label label; |
75 | if( !DDF::FindLabel(DF, arg[2], label) ) { |
76 | di << "No label for entry" << "\n"; |
77 | return 1; |
78 | } |
79 | Handle(TDataStd_Directory) A; |
80 | if (TDataStd_Directory::Find(label, A)) { |
81 | Handle(TDataStd_Directory) Dir = TDataStd_Directory::AddDirectory (A); |
82 | TCollection_AsciiString entry; |
83 | TDF_Tool::Entry(Dir->Label(), entry); |
84 | di << entry.ToCString()<<" "; //return a label to draw |
85 | return 0; |
86 | } |
87 | di << "No Object Attribute on label" << "\n"; |
88 | return 1; |
89 | } |
90 | |
91 | //======================================================================= |
92 | //function : MakeObjectLabel (DF, entry ) |
93 | //======================================================================= |
94 | static Standard_Integer DDataStd_MakeObjectLabel (Draw_Interpretor& di, |
95 | Standard_Integer nb, |
96 | const char** arg) |
97 | { |
98 | if( nb != 3 ) { |
99 | di << "Too few arguments" << "\n"; |
100 | return 1; |
101 | } |
102 | Handle(TDF_Data) DF; |
103 | if (!DDF::GetDF(arg[1],DF)) return 1; |
104 | TDF_Label label; |
105 | if( !DDF::FindLabel(DF, arg[2], label) ) { |
106 | di << "No label for entry" << "\n"; |
107 | return 1; |
108 | } |
109 | Handle(TDataStd_Directory) A; |
110 | if(TDataStd_Directory::Find(label,A)) { |
111 | TCollection_AsciiString entry; |
112 | TDF_Tool::Entry(TDataStd_Directory::MakeObjectLabel(A), entry); |
113 | di << entry.ToCString()<<" "; //return a label to draw |
114 | return 0; |
115 | } |
116 | di << "No Object Attribute on label" << "\n"; |
117 | return 1; |
118 | } |
119 | |
120 | |
121 | |
122 | //======================================================================= |
123 | //function : DDataStd_NewNoteBook |
124 | //purpose : NewNoteBook (DF, entry) |
125 | //======================================================================= |
126 | |
127 | static Standard_Integer DDataStd_NewNoteBook (Draw_Interpretor& di, |
128 | Standard_Integer nb, |
129 | const char** arg) |
130 | { |
131 | if (nb == 3) { |
132 | Handle(TDF_Data) DF; |
133 | if (!DDF::GetDF(arg[1],DF)) return 1; |
134 | TDF_Label L; |
135 | DDF::AddLabel(DF, arg[2], L); |
136 | TDataStd_NoteBook::New(L); |
137 | return 0; |
138 | } |
586db386 |
139 | di << "DDataStd_NewNoteBook : Error\n"; |
7fd59977 |
140 | return 1; |
141 | } |
142 | |
143 | //======================================================================= |
144 | //function : NewShape (DF, entry, [in_shape] ) |
145 | //======================================================================= |
146 | static Standard_Integer DDataStd_NewShape (Draw_Interpretor& di, |
147 | Standard_Integer nb, |
148 | const char** arg) |
149 | { |
150 | //di << "nb = " <<nb << "\n"; |
151 | if( nb < 3 ) { |
152 | di << "Too few arguments" << "\n"; |
153 | return 1; |
154 | } |
155 | Handle(TDF_Data) DF; |
156 | if (!DDF::GetDF(arg[1],DF)) return 1; |
157 | TDF_Label label; |
158 | DDF::AddLabel(DF, arg[2], label); |
159 | if( nb == 4 ) { |
160 | TopoDS_Shape shape = DBRep::Get( arg[3] ); |
161 | if( shape.IsNull() ) { |
162 | di << "Shape argument is invalid" << "\n"; |
163 | return 1; |
164 | } |
165 | TDataXtd_Shape::Set(label, shape ); |
166 | } |
167 | else TDataXtd_Shape::New(label); |
168 | return 0; |
169 | } |
170 | |
171 | |
172 | //======================================================================= |
173 | //function : GetShape2 (DF, entry, out_shape ) |
174 | //======================================================================= |
175 | static Standard_Integer DDataStd_GetShape2 (Draw_Interpretor& di, |
176 | Standard_Integer nb, |
177 | const char** arg) |
178 | { |
179 | if( nb < 4 ) { |
180 | di << "Too few arguments" << "\n"; |
181 | return 1; |
182 | } |
183 | Handle(TDF_Data) DF; |
184 | if (!DDF::GetDF(arg[1],DF)) return 1; |
185 | TDF_Label label; |
186 | if( !DDF::FindLabel(DF, arg[2], label) ) { |
187 | di << "No label for entry" << "\n"; |
188 | return 1; |
189 | } |
190 | DBRep::Set(arg[3], TDataXtd_Shape::Get(label)); |
191 | |
192 | return 0; |
193 | } |
194 | |
195 | |
196 | |
197 | //======================================================================= |
198 | //function : ObjectComands |
199 | //purpose : |
200 | //======================================================================= |
201 | |
202 | void DDataStd::ObjectCommands (Draw_Interpretor& theCommands) |
203 | { |
204 | |
205 | static Standard_Boolean done = Standard_False; |
206 | if (done) return; |
207 | done = Standard_True; |
208 | const char* g = "DData : Standard Attribute Commands"; |
209 | |
210 | theCommands.Add ("NewNoteBook", |
211 | "NewNoteBook (DF, entry)", |
212 | __FILE__, DDataStd_NewNoteBook, g); |
213 | |
214 | theCommands.Add ("NewShape", |
215 | "NewShape (DF, entry, [in_shape] )", |
216 | __FILE__, DDataStd_NewShape, g); |
217 | |
218 | theCommands.Add ("GetShape2", |
219 | "GetShape2 (DF, entry, out_shape )", |
220 | __FILE__, DDataStd_GetShape2, g); |
221 | |
222 | theCommands.Add ("NewDirectory", |
223 | "NewDirectory (DF, entry)", |
224 | __FILE__, DDataStd_NewDirectory, g); |
225 | |
226 | theCommands.Add ("AddDirectory", |
227 | "AddDirectory (DF, entry)", |
228 | __FILE__, DDataStd_AddDirectory, g); |
229 | |
230 | theCommands.Add ("MakeObjectLabel", |
231 | "MakeObjectLabel (DF, entry)", |
232 | __FILE__, DDataStd_MakeObjectLabel, g); |
233 | |
234 | } |
235 | |