1 // Copyright (c) 2015 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <Draw_View.hxx>
15 #include <Draw_Viewer.hxx>
17 #include <gp_Trsf.hxx>
19 //=======================================================================
20 //function : Draw_View
21 //purpose : Constructor
22 //=======================================================================
23 Draw_View::Draw_View(Standard_Integer theId,
24 Draw_Viewer* theViewer,
25 Standard_Integer theX,
26 Standard_Integer theY,
27 Standard_Integer theWidth,
28 Standard_Integer theHeight)
29 : Draw_Window("Win", theX, theY, theWidth, theHeight),
32 myIsPers (Standard_False),
33 myIs2D (Standard_False),
45 //=======================================================================
46 //function : Draw_View
47 //purpose : Constructor
48 //=======================================================================
49 #if defined(_WIN32) || defined(__WIN32__)
50 Draw_View::Draw_View(Standard_Integer theId,
51 Draw_Viewer* theViewer,
52 Standard_Integer theX,
53 Standard_Integer theY,
54 Standard_Integer theWidth,
55 Standard_Integer theHeight,
57 : Draw_Window("Win", theX, theY, theWidth, theHeight, theWindow),
60 myIsPers (Standard_False),
61 myIs2D (Standard_False),
73 //=======================================================================
74 //function : Draw_View
75 //purpose : Constructor
76 //=======================================================================
77 #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX)
78 Draw_View::Draw_View(Standard_Integer theId,
79 Draw_Viewer* theViewer,
80 Standard_Integer theX,
81 Standard_Integer theY,
82 Standard_Integer theWidth,
83 Standard_Integer theHeight,
85 : Draw_Window(theWindow, "Win", theX, theY, theWidth, theHeight),
88 myIsPers (Standard_False),
89 myIs2D (Standard_False),
103 //=======================================================================
104 //function : Draw_View
105 //purpose : Constructor
106 //=======================================================================
107 #if defined(_WIN32) || defined (__WIN32__) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX))
108 Draw_View::Draw_View(Standard_Integer /*theId*/,
109 Draw_Viewer* /*theViewer*/,
110 const char* /*theTitle*/)
115 Draw_View::Draw_View(Standard_Integer theId,
116 Draw_Viewer* theViewer,
117 const char* theTitle)
118 : Draw_Window (theTitle),
120 myViewer (theViewer),
122 myIsPers (Standard_False),
123 myIs2D (Standard_False),
124 myFocalDistance(0.0),
135 //=======================================================================
136 //function : ~Draw_View
137 //purpose : Destructor
138 //=======================================================================
139 Draw_View::~Draw_View()
141 Draw_Window::Destroy();
144 //=======================================================================
147 //=======================================================================
148 Standard_Boolean Draw_View::Init(const char* theType)
151 myFocalDistance = 500.;
152 myIsPers = Standard_False;
153 myIs2D = strcmp("-2D-", theType) ? Standard_False : Standard_True;
160 gp_Pnt Pvise(0.0, 0.0, 0.0);
162 if (!strcmp("+X+Y", theType) || myIs2D)
164 myMatrix = aRotation;
166 else if (!strcmp("-Y+X", theType))
168 const gp_Dir aD(0., 0., 1.);
169 myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI);
171 else if (!strcmp("-X-Y", theType))
173 const gp_Dir aD(0., 0., 1.);
174 myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI);
176 else if (!strcmp("+Y-X", theType))
178 const gp_Dir aD(0., 0., 1.);
179 myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI);
181 else if (!strcmp("+Y+X", theType))
183 const gp_Dir aD1(0., 0., 1.);
184 const gp_Dir aD2(0., 1., 0.);
186 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
187 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
188 myMatrix.Multiply(aRotation);
190 else if (!strcmp("-X+Y", theType))
192 const gp_Dir aD(0., 1., 0.);
193 myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI);
195 else if (!strcmp("-Y-X", theType))
197 const gp_Dir aD1(0., 0., 1.);
198 const gp_Dir aD2(1., 0., 0.);
200 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
201 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
202 myMatrix.Multiply(aRotation);
204 else if (!strcmp("+X-Y", theType))
206 const gp_Dir aD(1., 0., 0.);
207 myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI);
209 else if (!strcmp("+X+Z", theType))
211 const gp_Dir aD(1., 0., 0.);
212 myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI);
214 else if (!strcmp("-Z+X", theType))
216 const gp_Dir aD1(1., 0., 0.);
217 const gp_Dir aD2(0., 1., 0.);
219 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
220 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI);
221 myMatrix.Multiply(aRotation);
223 else if (!strcmp("-X-Z", theType))
225 const gp_Dir aD1(1., 0., 0.);
226 const gp_Dir aD2(0., 1., 0.);
228 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
229 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -M_PI);
230 myMatrix.Multiply(aRotation);
232 else if (!strcmp("+Z-X", theType))
234 const gp_Dir aD1(1., 0., 0.);
235 const gp_Dir aD2(0., 1., 0.);
237 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
238 aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI);
239 myMatrix.Multiply(aRotation);
241 else if (!strcmp("+Z+X", theType))
243 const gp_Dir aD1(1., 0., 0.);
244 const gp_Dir aD2(0., 1., 0.);
246 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
247 aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI);
248 myMatrix.Multiply(aRotation);
250 else if (!strcmp("-X+Z", theType))
252 const gp_Dir aD1(1., 0., 0.);
253 const gp_Dir aD2(0., 1., 0.);
255 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
256 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
257 myMatrix.Multiply(aRotation);
259 else if (!strcmp("-Z-X", theType))
261 const gp_Dir aD1(1., 0., 0.);
262 const gp_Dir aD2(0., 1., 0.);
264 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
265 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI);
266 myMatrix.Multiply(aRotation);
268 else if (!strcmp("+X-Z", theType))
270 const gp_Dir aD(1., 0., 0.);
271 myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI);
273 else if (!strcmp("+Y+Z", theType))
275 const gp_Dir aD1(0., 1., 0.);
276 const gp_Dir aD2(1., 0., 0.);
278 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
279 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI);
280 myMatrix.Multiply(aRotation);
282 else if (!strcmp("-Z+Y", theType))
284 const gp_Dir aD(0., 1., 0.);
285 myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI);
287 else if (!strcmp("-Y-Z", theType))
289 const gp_Dir aD1(0., 1., 0.);
290 const gp_Dir aD2(1., 0., 0.);
292 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
293 aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI);
294 myMatrix.Multiply(aRotation);
296 else if (!strcmp("+Z-Y", theType))
298 const gp_Dir aD1(0., 1., 0.);
299 const gp_Dir aD2(1., 0., 0.);
301 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
302 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
303 myMatrix.Multiply(aRotation);
305 else if (!strcmp("+Z+Y", theType))
307 const gp_Dir aD(0., 1., 0.);
308 myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI);
310 else if (!strcmp("-Y+Z", theType))
312 const gp_Dir aD1(0., 1., 0.);
313 const gp_Dir aD2(1., 0., 0.);
315 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
316 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI);
317 myMatrix.Multiply(aRotation);
319 else if (!strcmp("-Z-Y", theType))
321 const gp_Dir aD1(0., 1., 0.);
322 const gp_Dir aD2(1., 0., 0.);
324 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
325 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
326 myMatrix.Multiply(aRotation);
328 else if (!strcmp("+Y-Z", theType))
330 const gp_Dir aD1(0., 1., 0.);
331 const gp_Dir aD2(1., 0., 0.);
333 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
334 aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI);
335 myMatrix.Multiply(aRotation);
337 else if (!strcmp("AXON", theType))
339 const gp_Dir aD1(1., 0., 0.);
340 const gp_Dir aD2(0., 0., 1.);
342 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.25 * M_PI);
343 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.25 * M_PI);
344 myMatrix.Multiply(aRotation);
346 else if (!strcmp("PERS", theType))
348 const gp_Dir aD1(1., 0., 0.);
349 const gp_Dir aD2(0., 0., 1.);
351 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.25 * M_PI);
352 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.25 * M_PI);
353 myMatrix.Multiply(aRotation);
355 myIsPers = Standard_True;
359 return Standard_False;
362 strcpy(myType, theType);
363 return Standard_True;
366 //=======================================================================
367 //function : Transform
369 //=======================================================================
370 void Draw_View::Transform(const gp_Trsf& theTransformation)
372 myMatrix.Multiply(theTransformation);
375 //=======================================================================
376 //function : ResetFrame
378 //=======================================================================
379 void Draw_View::ResetFrame()
387 //=======================================================================
388 //function : GetFrame
390 //=======================================================================
391 void Draw_View::GetFrame(Standard_Integer& theX0,Standard_Integer& theY0,
392 Standard_Integer& theX1,Standard_Integer& theY1)
394 if ( myFrameX0 == myFrameX1 )
396 myViewer->GetFrame(myId, theX0, theY0, theX1, theY1);
411 //=======================================================================
414 //=======================================================================
415 void Draw_View::WExpose()
418 myViewer->RepaintView(myId);