0024166: Unable to create file with "Save" menu of voxeldemo Qt sample
[occt.git] / src / DDataStd / DDataStd_ObjectCommands.cxx
CommitLineData
b311480e 1// Created on: 1999-07-15
2// Created by: Denis PASCAL
3// Copyright (c) 1999-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22#include <DDataStd.hxx>
23#include <DDataStd_DrawPresentation.hxx>
24#include <DDF.hxx>
25#include <Draw_Interpretor.hxx>
26#include <Draw_Appli.hxx>
27#include <TDF_Data.hxx>
28#include <TDF_Tool.hxx>
29#include <TDF_ChildIterator.hxx>
30#include <TDF_Label.hxx>
31#include <Standard_GUID.hxx>
32#include <TDataStd_Directory.hxx>
33#include <TDataXtd_Shape.hxx>
34
35
36// LES ATTRIBUTES
37
38#include <TDataStd_NoteBook.hxx>
39#include <TDataXtd_Shape.hxx>
40
41
42#include <TopoDS_Shape.hxx>
43#include <DBRep.hxx>
44
45
46//=======================================================================
47//function : NewDirectory (DF, entry )
48//=======================================================================
49static Standard_Integer DDataStd_NewDirectory (Draw_Interpretor& di,
50 Standard_Integer nb,
51 const char** arg)
52{
53 if( nb != 3 ) {
54 di << "Too few arguments" << "\n";
55 return 1;
56 }
57 Handle(TDF_Data) DF;
58 if (!DDF::GetDF(arg[1],DF)) return 1;
59 TDF_Label label;
60 DDF::AddLabel(DF, arg[2], label);
61 TDataStd_Directory::New(label );
62 return 0;
63}
64
65
66//=======================================================================
67//function : AddDirectory (DF, entry )
68//=======================================================================
69static Standard_Integer DDataStd_AddDirectory (Draw_Interpretor& di,
70 Standard_Integer nb,
71 const char** arg)
72{
73 if( nb != 3 ) {
74 di << "Too few arguments" << "\n";
75 return 1;
76 }
77 Handle(TDF_Data) DF;
78 if (!DDF::GetDF(arg[1],DF)) return 1;
79 TDF_Label label;
80 if( !DDF::FindLabel(DF, arg[2], label) ) {
81 di << "No label for entry" << "\n";
82 return 1;
83 }
84 Handle(TDataStd_Directory) A;
85 if (TDataStd_Directory::Find(label, A)) {
86 Handle(TDataStd_Directory) Dir = TDataStd_Directory::AddDirectory (A);
87 TCollection_AsciiString entry;
88 TDF_Tool::Entry(Dir->Label(), entry);
89 di << entry.ToCString()<<" "; //return a label to draw
90 return 0;
91 }
92 di << "No Object Attribute on label" << "\n";
93 return 1;
94}
95
96//=======================================================================
97//function : MakeObjectLabel (DF, entry )
98//=======================================================================
99static Standard_Integer DDataStd_MakeObjectLabel (Draw_Interpretor& di,
100 Standard_Integer nb,
101 const char** arg)
102{
103 if( nb != 3 ) {
104 di << "Too few arguments" << "\n";
105 return 1;
106 }
107 Handle(TDF_Data) DF;
108 if (!DDF::GetDF(arg[1],DF)) return 1;
109 TDF_Label label;
110 if( !DDF::FindLabel(DF, arg[2], label) ) {
111 di << "No label for entry" << "\n";
112 return 1;
113 }
114 Handle(TDataStd_Directory) A;
115 if(TDataStd_Directory::Find(label,A)) {
116 TCollection_AsciiString entry;
117 TDF_Tool::Entry(TDataStd_Directory::MakeObjectLabel(A), entry);
118 di << entry.ToCString()<<" "; //return a label to draw
119 return 0;
120 }
121 di << "No Object Attribute on label" << "\n";
122 return 1;
123}
124
125
126
127//=======================================================================
128//function : DDataStd_NewNoteBook
129//purpose : NewNoteBook (DF, entry)
130//=======================================================================
131
132static Standard_Integer DDataStd_NewNoteBook (Draw_Interpretor& di,
133 Standard_Integer nb,
134 const char** arg)
135{
136 if (nb == 3) {
137 Handle(TDF_Data) DF;
138 if (!DDF::GetDF(arg[1],DF)) return 1;
139 TDF_Label L;
140 DDF::AddLabel(DF, arg[2], L);
141 TDataStd_NoteBook::New(L);
142 return 0;
143 }
144 di << "DDataStd_NewNoteBook : Error" << "\n";
145 return 1;
146}
147
148//=======================================================================
149//function : NewShape (DF, entry, [in_shape] )
150//=======================================================================
151static Standard_Integer DDataStd_NewShape (Draw_Interpretor& di,
152 Standard_Integer nb,
153 const char** arg)
154{
155 //di << "nb = " <<nb << "\n";
156 if( nb < 3 ) {
157 di << "Too few arguments" << "\n";
158 return 1;
159 }
160 Handle(TDF_Data) DF;
161 if (!DDF::GetDF(arg[1],DF)) return 1;
162 TDF_Label label;
163 DDF::AddLabel(DF, arg[2], label);
164 if( nb == 4 ) {
165 TopoDS_Shape shape = DBRep::Get( arg[3] );
166 if( shape.IsNull() ) {
167 di << "Shape argument is invalid" << "\n";
168 return 1;
169 }
170 TDataXtd_Shape::Set(label, shape );
171 }
172 else TDataXtd_Shape::New(label);
173 return 0;
174}
175
176
177//=======================================================================
178//function : GetShape2 (DF, entry, out_shape )
179//=======================================================================
180static Standard_Integer DDataStd_GetShape2 (Draw_Interpretor& di,
181 Standard_Integer nb,
182 const char** arg)
183{
184 if( nb < 4 ) {
185 di << "Too few arguments" << "\n";
186 return 1;
187 }
188 Handle(TDF_Data) DF;
189 if (!DDF::GetDF(arg[1],DF)) return 1;
190 TDF_Label label;
191 if( !DDF::FindLabel(DF, arg[2], label) ) {
192 di << "No label for entry" << "\n";
193 return 1;
194 }
195 DBRep::Set(arg[3], TDataXtd_Shape::Get(label));
196
197 return 0;
198}
199
200
201
202//=======================================================================
203//function : ObjectComands
204//purpose :
205//=======================================================================
206
207void DDataStd::ObjectCommands (Draw_Interpretor& theCommands)
208{
209
210 static Standard_Boolean done = Standard_False;
211 if (done) return;
212 done = Standard_True;
213 const char* g = "DData : Standard Attribute Commands";
214
215 theCommands.Add ("NewNoteBook",
216 "NewNoteBook (DF, entry)",
217 __FILE__, DDataStd_NewNoteBook, g);
218
219 theCommands.Add ("NewShape",
220 "NewShape (DF, entry, [in_shape] )",
221 __FILE__, DDataStd_NewShape, g);
222
223 theCommands.Add ("GetShape2",
224 "GetShape2 (DF, entry, out_shape )",
225 __FILE__, DDataStd_GetShape2, g);
226
227 theCommands.Add ("NewDirectory",
228 "NewDirectory (DF, entry)",
229 __FILE__, DDataStd_NewDirectory, g);
230
231 theCommands.Add ("AddDirectory",
232 "AddDirectory (DF, entry)",
233 __FILE__, DDataStd_AddDirectory, g);
234
235 theCommands.Add ("MakeObjectLabel",
236 "MakeObjectLabel (DF, entry)",
237 __FILE__, DDataStd_MakeObjectLabel, g);
238
239}
240