0030895: Coding Rules - specify std namespace explicitly for std::cout and streams
[occt.git] / src / DDataStd / DDataStd_DrawDisplayCommands.cxx
1 // Created on: 1998-02-12
2 // Created by: Denis PASCAL
3 // Copyright (c) 1998-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <DDataStd.hxx>
18 #include <DDF.hxx>
19 #include <Draw.hxx>
20 #include <Draw_Drawable3D.hxx>
21 #include <Draw_Appli.hxx>
22 #include <Draw_Interpretor.hxx>
23 #include <Draw_Viewer.hxx>
24 #include <Draw_ColorKind.hxx>
25 #include <TCollection_AsciiString.hxx>
26 #include <gp_Trsf.hxx>   
27 #include <gp_Pnt.hxx>
28 #include <gp_Lin.hxx>
29 #include <gp_Pln.hxx>
30 #include <Precision.hxx> 
31 #include <TopAbs.hxx>
32 #include <TopoDS.hxx>
33 #include <TopoDS_Face.hxx>
34 #include <TopoDS_Vertex.hxx> 
35 #include <TopAbs.hxx>
36 #include <TDF_AttributeList.hxx>
37 #include <TDF_ListIteratorOfAttributeList.hxx>
38 #include <TNaming_Tool.hxx>
39 #include <TDF_ChildIterator.hxx>
40 #include <TDF_LabelList.hxx>
41 #include <TDF_ListIteratorOfLabelList.hxx>
42 #include <TDF_Tool.hxx> 
43 #include <TNaming_NamedShape.hxx>
44 #include <TDataXtd_Point.hxx>
45 #include <TDataXtd_Axis.hxx>
46 #include <TDataXtd_Geometry.hxx>
47 #include <TDataXtd_Constraint.hxx> 
48 #include <ElSLib.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Compound.hxx>
51
52 #include <DDataStd_DrawPresentation.hxx>
53 #include <DDataStd_DrawDriver.hxx>
54
55 #ifndef _WIN32
56 extern Draw_Viewer dout;
57 #else
58 Standard_IMPORT Draw_Viewer dout;
59 #endif
60 //=======================================================================
61 //function : DDataStd_PNT
62 //purpose  : SetPoint (DF, entry, x, y, z)
63 //=======================================================================
64
65 static Standard_Integer DDataStd_PNT (Draw_Interpretor& di,
66                                       Standard_Integer nb, 
67                                       const char** arg) 
68
69   if (nb == 6) {
70     Handle(TDF_Data) DF;
71     if (!DDF::GetDF (arg[1], DF)) return 1;  
72     TDF_Label L;
73     DDF::AddLabel (DF, arg[2], L);    
74     Standard_Real x = Draw::Atof(arg[3]);
75     Standard_Real y = Draw::Atof(arg[4]);
76     Standard_Real z = Draw::Atof(arg[5]);
77     TDataXtd_Point::Set (L,gp_Pnt(x,y,z));
78     return 0;
79   }  
80   di << "DDataStd_PNT : Error : not done\n";
81   return 1;
82 }
83  
84 //=======================================================================
85 //function : DDataStd_Rmdraw
86 //purpose  : Rmdraw (name)
87 //=======================================================================
88
89 static Standard_Integer DDataStd_Rmdraw (Draw_Interpretor& ,
90                                               Standard_Integer nb, 
91                                               const char** arg)
92 {
93   if (nb != 2)
94   {
95     std::cout << "Syntax error: wrong number of arguments\n";
96     return 1;
97   }
98
99   if (Handle(Draw_Drawable3D) D3D = Draw::Get (arg[1]))
100   {
101     dout.RemoveDrawable (D3D);
102     return 0;
103   }
104   else
105   {
106     std::cout << "Syntax error: variable '" << arg[1] << "' not found\n";
107     return 1;
108   }
109 }
110
111 //=======================================================================
112 //function : DDataStd_DrawOwner
113 //purpose  : DrawOwner (drawable)
114 //=======================================================================
115
116 static Standard_Integer DDataStd_DrawOwner (Draw_Interpretor& di,
117                                              Standard_Integer nb, 
118                                              const char** arg)
119 {
120   if (nb == 2) {
121     Handle(Draw_Drawable3D) D = Draw::Get(arg[1]);
122     if (!D.IsNull()) {
123       TCollection_AsciiString entry;
124       TCollection_AsciiString name (D->Name());
125       Standard_Integer index = name.Search("_0:");
126       if (index > 0) {
127         entry = name.Split(index);
128         name.Remove(index);
129         di << entry.ToCString();
130       }
131       else di << name.ToCString();
132     }
133     else di << 0;
134     return 0;
135   }
136   di << "DDataStd_DrawOwner : Error\n";
137   return 1;
138 }
139
140 //=======================================================================
141 //function : DDataStd_DrawDisplay
142 //purpose  : DDisplay (DOC,entry)
143 //=======================================================================
144
145 static Standard_Integer DDataStd_DrawDisplay (Draw_Interpretor& di,
146                                                 Standard_Integer nb, 
147                                                 const char** arg) 
148 {   
149   if (nb == 3) {   
150     Handle(TDF_Data) DF;
151     if (!DDF::GetDF(arg[1],DF)) return 1;   
152     TDF_Label L;
153     if (!DDF::FindLabel(DF,arg[2],L)) return 1;
154     DDataStd_DrawPresentation::Display(L);
155     return 0;
156   }
157   di << "DDataStd_DrawDisplay : Error\n";
158   return 1;
159 }
160
161 // //=======================================================================
162 // //function : DDataStd_DrawRedisplay
163 // //purpose  : DrawRedisplay (DOC,entry)
164 // //=======================================================================
165
166 // static Standard_Integer DDataStd_DrawRedisplay (Draw_Interpretor&,
167 //                                                Standard_Integer nb, 
168 //                                                const char** arg) 
169 // {   
170 //   if (nb == 3) {     
171 //     Handle(TDF_Data) DF;
172 //     if (!DDF::GetDF(arg[1],DF)) return 1;   
173 //     TDF_Label L;
174 //     if (!DDF::FindLabel(DF,arg[2],L)) return 1;
175 //     DDataStd_DrawPresentation::Display(L,Standard_True);
176 //     return 0;
177 //   }
178 //   std::cout << "DDataStd_DrawRedisplay : Error" << std::endl;
179 //   return 1;
180 // }
181
182
183 //=======================================================================
184 //function : DDataStd_DrawErase
185 //purpose  : DrawErase (DOC,entry)
186 //=======================================================================
187
188 static Standard_Integer DDataStd_DrawErase (Draw_Interpretor& di,
189                                               Standard_Integer nb, 
190                                               const char** arg) 
191 {   
192   if (nb == 3) {     
193     Handle(TDF_Data) DF;
194     if (!DDF::GetDF(arg[1],DF)) return 1;   
195     TDF_Label L;
196     if (!DDF::FindLabel(DF,arg[2],L)) return 1;
197     DDataStd_DrawPresentation::Erase(L);
198     return 0;
199   }
200   di << "DDataStd_DrawErase : Error\n";
201   return 1;
202 }
203
204 //=======================================================================
205 //function : DDataStd_DrawUpdate
206 //purpose  : DrawUpdate (DOC,entry)
207 //=======================================================================
208
209 static Standard_Integer DDataStd_DrawUpdate (Draw_Interpretor& di,
210                                                Standard_Integer nb, 
211                                                const char** arg) 
212 {   
213   if (nb == 3) {  
214     Handle(TDF_Data) DF;
215     if (!DDF::GetDF(arg[1],DF)) return 1;   
216     TDF_Label L;
217     if (!DDF::FindLabel(DF,arg[2],L)) return 1;     
218     DDataStd_DrawPresentation::Update(L);
219     return 0;
220   }
221   di << "DDataStd_DrawUpdate : Error\n";
222   return 1;
223 }
224
225 //=======================================================================
226 //function : DDataStd_DrawRepaint
227 //purpose  : 
228 //=======================================================================
229
230 static Standard_Integer DDataStd_DrawRepaint (Draw_Interpretor& /*di*/,
231                                               Standard_Integer /*nb*/, 
232                                               const char** /*arg*/) 
233 {  
234   dout.Repaint3D(); 
235   dout.Flush();
236   return 0;
237 }
238
239
240 //=======================================================================
241 //function : DrawDisplayCommands
242 //purpose  : 
243 //=======================================================================
244
245
246 void DDataStd::DrawDisplayCommands (Draw_Interpretor& theCommands)
247 {  
248
249   static Standard_Boolean done = Standard_False;
250   if (done) return;
251   done = Standard_True;
252   const char* g = "SKETCH commands" ;
253
254
255   theCommands.Add ("PNT", 
256                    "PNT (DF, entry, x, y, z)",
257                    __FILE__, DDataStd_PNT, g);
258   
259   
260   // remove drawable
261
262
263   theCommands.Add ("rmdraw", 
264                    "rmdraw(name)",
265                    __FILE__, DDataStd_Rmdraw, g);
266
267
268   // rtetrieve a label from a drawable
269
270
271   theCommands.Add ("DrawOwner", 
272                    "DrawOwner (drawable)",
273                    __FILE__, DDataStd_DrawOwner, g); 
274   
275   // draw display 
276  
277
278   theCommands.Add ("DrawDisplay", 
279                    "DrawDisplay (DF, entry)",
280                    __FILE__, DDataStd_DrawDisplay, g);  
281
282   theCommands.Add ("DrawErase", 
283                    "DrawErase (DF, entry)",
284                    __FILE__, DDataStd_DrawErase, g);    
285
286   theCommands.Add ("DrawUpdate", 
287                    "DrawUpdate (DF, entry)",
288                    __FILE__, DDataStd_DrawUpdate, g);  
289
290   theCommands.Add ("DrawRepaint", 
291                    "update the draw viewer",
292                    __FILE__, DDataStd_DrawRepaint, g);    
293 }
294
295
296
297
298
299
300
301
302
303
304