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 Aspect_Drawable theWindow)
31 NCollection_Vec2<int> (theX, theY),
32 NCollection_Vec2<int> (theWidth, theHeight),
36 myIsPers (Standard_False),
37 myIs2D (Standard_False),
47 memset (myType, 0, sizeof (myType));
50 //! Find window by it's XID - applicable only to X11.
51 static Aspect_Drawable findWindow (const char* theWindow)
53 Aspect_Drawable aWindow = 0;
55 sscanf (theWindow, "%lx", &aWindow);
62 //=======================================================================
63 //function : Draw_View
64 //purpose : Constructor
65 //=======================================================================
66 Draw_View::Draw_View(Standard_Integer theId,
67 Draw_Viewer* theViewer,
69 : Draw_Window (theTitle, NCollection_Vec2<int>(0), NCollection_Vec2<int>(50), 0, findWindow (theTitle)),
72 myIsPers (Standard_False),
73 myIs2D (Standard_False),
83 memset (myType, 0, sizeof (myType));
86 //=======================================================================
87 //function : ~Draw_View
88 //purpose : Destructor
89 //=======================================================================
90 Draw_View::~Draw_View()
92 Draw_Window::Destroy();
95 //=======================================================================
98 //=======================================================================
99 Standard_Boolean Draw_View::Init(const char* theType)
102 myFocalDistance = 500.;
103 myIsPers = Standard_False;
104 myIs2D = strcmp("-2D-", theType) ? Standard_False : Standard_True;
111 gp_Pnt Pvise(0.0, 0.0, 0.0);
113 if (!strcmp("+X+Y", theType) || myIs2D)
115 myMatrix = aRotation;
117 else if (!strcmp("-Y+X", theType))
119 const gp_Dir aD(0., 0., 1.);
120 myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI);
122 else if (!strcmp("-X-Y", theType))
124 const gp_Dir aD(0., 0., 1.);
125 myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI);
127 else if (!strcmp("+Y-X", theType))
129 const gp_Dir aD(0., 0., 1.);
130 myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI);
132 else if (!strcmp("+Y+X", theType))
134 const gp_Dir aD1(0., 0., 1.);
135 const gp_Dir aD2(0., 1., 0.);
137 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
138 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
139 myMatrix.Multiply(aRotation);
141 else if (!strcmp("-X+Y", theType))
143 const gp_Dir aD(0., 1., 0.);
144 myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI);
146 else if (!strcmp("-Y-X", theType))
148 const gp_Dir aD1(0., 0., 1.);
149 const gp_Dir aD2(1., 0., 0.);
151 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
152 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
153 myMatrix.Multiply(aRotation);
155 else if (!strcmp("+X-Y", theType))
157 const gp_Dir aD(1., 0., 0.);
158 myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI);
160 else if (!strcmp("+X+Z", theType))
162 const gp_Dir aD(1., 0., 0.);
163 myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI);
165 else if (!strcmp("-Z+X", theType))
167 const gp_Dir aD1(1., 0., 0.);
168 const gp_Dir aD2(0., 1., 0.);
170 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
171 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI);
172 myMatrix.Multiply(aRotation);
174 else if (!strcmp("-X-Z", theType))
176 const gp_Dir aD1(1., 0., 0.);
177 const gp_Dir aD2(0., 1., 0.);
179 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
180 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -M_PI);
181 myMatrix.Multiply(aRotation);
183 else if (!strcmp("+Z-X", theType))
185 const gp_Dir aD1(1., 0., 0.);
186 const gp_Dir aD2(0., 1., 0.);
188 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
189 aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI);
190 myMatrix.Multiply(aRotation);
192 else if (!strcmp("+Z+X", theType))
194 const gp_Dir aD1(1., 0., 0.);
195 const gp_Dir aD2(0., 1., 0.);
197 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
198 aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI);
199 myMatrix.Multiply(aRotation);
201 else if (!strcmp("-X+Z", theType))
203 const gp_Dir aD1(1., 0., 0.);
204 const gp_Dir aD2(0., 1., 0.);
206 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
207 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
208 myMatrix.Multiply(aRotation);
210 else if (!strcmp("-Z-X", theType))
212 const gp_Dir aD1(1., 0., 0.);
213 const gp_Dir aD2(0., 1., 0.);
215 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
216 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI);
217 myMatrix.Multiply(aRotation);
219 else if (!strcmp("+X-Z", theType))
221 const gp_Dir aD(1., 0., 0.);
222 myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI);
224 else if (!strcmp("+Y+Z", theType))
226 const gp_Dir aD1(0., 1., 0.);
227 const gp_Dir aD2(1., 0., 0.);
229 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
230 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI);
231 myMatrix.Multiply(aRotation);
233 else if (!strcmp("-Z+Y", theType))
235 const gp_Dir aD(0., 1., 0.);
236 myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI);
238 else if (!strcmp("-Y-Z", theType))
240 const gp_Dir aD1(0., 1., 0.);
241 const gp_Dir aD2(1., 0., 0.);
243 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
244 aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI);
245 myMatrix.Multiply(aRotation);
247 else if (!strcmp("+Z-Y", theType))
249 const gp_Dir aD1(0., 1., 0.);
250 const gp_Dir aD2(1., 0., 0.);
252 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI);
253 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
254 myMatrix.Multiply(aRotation);
256 else if (!strcmp("+Z+Y", theType))
258 const gp_Dir aD(0., 1., 0.);
259 myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI);
261 else if (!strcmp("-Y+Z", theType))
263 const gp_Dir aD1(0., 1., 0.);
264 const gp_Dir aD2(1., 0., 0.);
266 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
267 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI);
268 myMatrix.Multiply(aRotation);
270 else if (!strcmp("-Z-Y", theType))
272 const gp_Dir aD1(0., 1., 0.);
273 const gp_Dir aD2(1., 0., 0.);
275 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
276 aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI);
277 myMatrix.Multiply(aRotation);
279 else if (!strcmp("+Y-Z", theType))
281 const gp_Dir aD1(0., 1., 0.);
282 const gp_Dir aD2(1., 0., 0.);
284 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI);
285 aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI);
286 myMatrix.Multiply(aRotation);
288 else if (!strcmp("AXON", theType))
290 const gp_Dir aD1(1., 0., 0.);
291 const gp_Dir aD2(0., 0., 1.);
293 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.25 * M_PI);
294 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.25 * M_PI);
295 myMatrix.Multiply(aRotation);
297 else if (!strcmp("PERS", theType))
299 const gp_Dir aD1(1., 0., 0.);
300 const gp_Dir aD2(0., 0., 1.);
302 myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.25 * M_PI);
303 aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.25 * M_PI);
304 myMatrix.Multiply(aRotation);
306 myIsPers = Standard_True;
310 return Standard_False;
313 strcpy(myType, theType);
314 return Standard_True;
317 //=======================================================================
318 //function : Transform
320 //=======================================================================
321 void Draw_View::Transform(const gp_Trsf& theTransformation)
323 myMatrix.Multiply(theTransformation);
326 //=======================================================================
327 //function : ResetFrame
329 //=======================================================================
330 void Draw_View::ResetFrame()
338 //=======================================================================
339 //function : GetFrame
341 //=======================================================================
342 void Draw_View::GetFrame(Standard_Integer& theX0,Standard_Integer& theY0,
343 Standard_Integer& theX1,Standard_Integer& theY1)
345 if ( myFrameX0 == myFrameX1 )
347 myViewer->GetFrame(myId, theX0, theY0, theX1, theY1);
362 //=======================================================================
365 //=======================================================================
366 void Draw_View::WExpose()
369 myViewer->RepaintView(myId);