17470159 |
1 | // Copyright (c) 2015 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
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. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
96f3bacc |
14 | #include <Draw_View.hxx> |
15 | #include <Draw_Viewer.hxx> |
16 | |
17 | #include <gp_Trsf.hxx> |
18 | |
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), |
30 | myId (theId), |
31 | myViewer (theViewer), |
32 | myIsPers (Standard_False), |
33 | myIs2D (Standard_False), |
34 | myFocalDistance(0.0), |
35 | myZoom (0.0), |
36 | myDx (0), |
37 | myDy (0), |
38 | myFrameX0 (0), |
39 | myFrameY0 (0), |
40 | myFrameX1 (0), |
41 | myFrameY1 (0) |
42 | { |
d533dafb |
43 | memset (myType, 0, sizeof (myType)); |
96f3bacc |
44 | } |
45 | |
46 | //======================================================================= |
47 | //function : Draw_View |
48 | //purpose : Constructor |
49 | //======================================================================= |
50 | #if defined(_WIN32) || defined(__WIN32__) |
51 | Draw_View::Draw_View(Standard_Integer theId, |
52 | Draw_Viewer* theViewer, |
53 | Standard_Integer theX, |
54 | Standard_Integer theY, |
55 | Standard_Integer theWidth, |
56 | Standard_Integer theHeight, |
57 | HWND theWindow) |
58 | : Draw_Window("Win", theX, theY, theWidth, theHeight, theWindow), |
59 | myId (theId), |
60 | myViewer (theViewer), |
61 | myIsPers (Standard_False), |
62 | myIs2D (Standard_False), |
63 | myFocalDistance(0.0), |
64 | myZoom (0.0), |
65 | myDx (0), |
66 | myDy (0), |
67 | myFrameX0 (0), |
68 | myFrameY0 (0), |
69 | myFrameX1 (0), |
70 | myFrameY1 (0) |
71 | { |
d533dafb |
72 | memset (myType, 0, sizeof (myType)); |
96f3bacc |
73 | } |
74 | |
75 | //======================================================================= |
76 | //function : Draw_View |
77 | //purpose : Constructor |
78 | //======================================================================= |
79 | #elif defined(__APPLE__) && !defined(MACOSX_USE_GLX) |
80 | Draw_View::Draw_View(Standard_Integer theId, |
81 | Draw_Viewer* theViewer, |
82 | Standard_Integer theX, |
83 | Standard_Integer theY, |
84 | Standard_Integer theWidth, |
85 | Standard_Integer theHeight, |
86 | NSWindow* theWindow) |
87 | : Draw_Window(theWindow, "Win", theX, theY, theWidth, theHeight), |
88 | myId (theId), |
89 | myViewer (theViewer), |
90 | myIsPers (Standard_False), |
91 | myIs2D (Standard_False), |
92 | myFocalDistance(0.0), |
93 | myZoom (0.0), |
94 | myDx (0), |
95 | myDy (0), |
96 | myFrameX0 (0), |
97 | myFrameY0 (0), |
98 | myFrameX1 (0), |
99 | myFrameY1 (0) |
100 | { |
d533dafb |
101 | memset (myType, 0, sizeof (myType)); |
96f3bacc |
102 | } |
103 | #endif |
104 | |
105 | |
106 | //======================================================================= |
107 | //function : Draw_View |
108 | //purpose : Constructor |
109 | //======================================================================= |
110 | #if defined(_WIN32) || defined (__WIN32__) || (defined(__APPLE__) && !defined(MACOSX_USE_GLX)) |
111 | Draw_View::Draw_View(Standard_Integer /*theId*/, |
112 | Draw_Viewer* /*theViewer*/, |
113 | const char* /*theTitle*/) |
114 | : Draw_Window (), |
115 | myId (-1), |
116 | myViewer (NULL), |
117 | #else |
118 | Draw_View::Draw_View(Standard_Integer theId, |
119 | Draw_Viewer* theViewer, |
120 | const char* theTitle) |
121 | : Draw_Window (theTitle), |
122 | myId (theId), |
123 | myViewer (theViewer), |
124 | #endif |
125 | myIsPers (Standard_False), |
126 | myIs2D (Standard_False), |
127 | myFocalDistance(0.0), |
128 | myZoom (0.0), |
129 | myDx (0), |
130 | myDy (0), |
131 | myFrameX0 (0), |
132 | myFrameY0 (0), |
133 | myFrameX1 (0), |
134 | myFrameY1 (0) |
135 | { |
d533dafb |
136 | memset (myType, 0, sizeof (myType)); |
96f3bacc |
137 | } |
138 | |
139 | //======================================================================= |
140 | //function : ~Draw_View |
141 | //purpose : Destructor |
142 | //======================================================================= |
143 | Draw_View::~Draw_View() |
144 | { |
145 | Draw_Window::Destroy(); |
146 | } |
147 | |
148 | //======================================================================= |
149 | //function : Init |
150 | //purpose : |
151 | //======================================================================= |
152 | Standard_Boolean Draw_View::Init(const char* theType) |
153 | { |
154 | { // default fields |
155 | myFocalDistance = 500.; |
156 | myIsPers = Standard_False; |
157 | myIs2D = strcmp("-2D-", theType) ? Standard_False : Standard_True; |
158 | myZoom = 1; |
159 | |
160 | ResetFrame(); |
161 | } |
162 | |
163 | gp_Trsf aRotation; |
164 | gp_Pnt Pvise(0.0, 0.0, 0.0); |
165 | |
166 | if (!strcmp("+X+Y", theType) || myIs2D) |
167 | { |
168 | myMatrix = aRotation; |
169 | } |
170 | else if (!strcmp("-Y+X", theType)) |
171 | { |
172 | const gp_Dir aD(0., 0., 1.); |
173 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI); |
174 | } |
175 | else if (!strcmp("-X-Y", theType)) |
176 | { |
177 | const gp_Dir aD(0., 0., 1.); |
178 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI); |
179 | } |
180 | else if (!strcmp("+Y-X", theType)) |
181 | { |
182 | const gp_Dir aD(0., 0., 1.); |
183 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI); |
184 | } |
185 | else if (!strcmp("+Y+X", theType)) |
186 | { |
187 | const gp_Dir aD1(0., 0., 1.); |
188 | const gp_Dir aD2(0., 1., 0.); |
189 | |
190 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
191 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
192 | myMatrix.Multiply(aRotation); |
193 | } |
194 | else if (!strcmp("-X+Y", theType)) |
195 | { |
196 | const gp_Dir aD(0., 1., 0.); |
197 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI); |
198 | } |
199 | else if (!strcmp("-Y-X", theType)) |
200 | { |
201 | const gp_Dir aD1(0., 0., 1.); |
202 | const gp_Dir aD2(1., 0., 0.); |
203 | |
204 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
205 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
206 | myMatrix.Multiply(aRotation); |
207 | } |
208 | else if (!strcmp("+X-Y", theType)) |
209 | { |
210 | const gp_Dir aD(1., 0., 0.); |
211 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI); |
212 | } |
213 | else if (!strcmp("+X+Z", theType)) |
214 | { |
215 | const gp_Dir aD(1., 0., 0.); |
216 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI); |
217 | } |
218 | else if (!strcmp("-Z+X", theType)) |
219 | { |
220 | const gp_Dir aD1(1., 0., 0.); |
221 | const gp_Dir aD2(0., 1., 0.); |
222 | |
223 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
224 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI); |
225 | myMatrix.Multiply(aRotation); |
226 | } |
227 | else if (!strcmp("-X-Z", theType)) |
228 | { |
229 | const gp_Dir aD1(1., 0., 0.); |
230 | const gp_Dir aD2(0., 1., 0.); |
231 | |
232 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
233 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), -M_PI); |
234 | myMatrix.Multiply(aRotation); |
235 | } |
236 | else if (!strcmp("+Z-X", theType)) |
237 | { |
238 | const gp_Dir aD1(1., 0., 0.); |
239 | const gp_Dir aD2(0., 1., 0.); |
240 | |
241 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
242 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI); |
243 | myMatrix.Multiply(aRotation); |
244 | } |
245 | else if (!strcmp("+Z+X", theType)) |
246 | { |
247 | const gp_Dir aD1(1., 0., 0.); |
248 | const gp_Dir aD2(0., 1., 0.); |
249 | |
250 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI); |
251 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI); |
252 | myMatrix.Multiply(aRotation); |
253 | } |
254 | else if (!strcmp("-X+Z", theType)) |
255 | { |
256 | const gp_Dir aD1(1., 0., 0.); |
257 | const gp_Dir aD2(0., 1., 0.); |
258 | |
259 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI); |
260 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
261 | myMatrix.Multiply(aRotation); |
262 | } |
263 | else if (!strcmp("-Z-X", theType)) |
264 | { |
265 | const gp_Dir aD1(1., 0., 0.); |
266 | const gp_Dir aD2(0., 1., 0.); |
267 | |
268 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI); |
269 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI); |
270 | myMatrix.Multiply(aRotation); |
271 | } |
272 | else if (!strcmp("+X-Z", theType)) |
273 | { |
274 | const gp_Dir aD(1., 0., 0.); |
275 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI); |
276 | } |
277 | else if (!strcmp("+Y+Z", theType)) |
278 | { |
279 | const gp_Dir aD1(0., 1., 0.); |
280 | const gp_Dir aD2(1., 0., 0.); |
281 | |
282 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
283 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI); |
284 | myMatrix.Multiply(aRotation); |
285 | } |
286 | else if (!strcmp("-Z+Y", theType)) |
287 | { |
288 | const gp_Dir aD(0., 1., 0.); |
289 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI); |
290 | } |
291 | else if (!strcmp("-Y-Z", theType)) |
292 | { |
293 | const gp_Dir aD1(0., 1., 0.); |
294 | const gp_Dir aD2(1., 0., 0.); |
295 | |
296 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
297 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI); |
298 | myMatrix.Multiply(aRotation); |
299 | } |
300 | else if (!strcmp("+Z-Y", theType)) |
301 | { |
302 | const gp_Dir aD1(0., 1., 0.); |
303 | const gp_Dir aD2(1., 0., 0.); |
304 | |
305 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
306 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
307 | myMatrix.Multiply(aRotation); |
308 | } |
309 | else if (!strcmp("+Z+Y", theType)) |
310 | { |
311 | const gp_Dir aD(0., 1., 0.); |
312 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI); |
313 | } |
314 | else if (!strcmp("-Y+Z", theType)) |
315 | { |
316 | const gp_Dir aD1(0., 1., 0.); |
317 | const gp_Dir aD2(1., 0., 0.); |
318 | |
319 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI); |
320 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.5 * M_PI); |
321 | myMatrix.Multiply(aRotation); |
322 | } |
323 | else if (!strcmp("-Z-Y", theType)) |
324 | { |
325 | const gp_Dir aD1(0., 1., 0.); |
326 | const gp_Dir aD2(1., 0., 0.); |
327 | |
328 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI); |
329 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
330 | myMatrix.Multiply(aRotation); |
331 | } |
332 | else if (!strcmp("+Y-Z", theType)) |
333 | { |
334 | const gp_Dir aD1(0., 1., 0.); |
335 | const gp_Dir aD2(1., 0., 0.); |
336 | |
337 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI); |
338 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), 0.5 * M_PI); |
339 | myMatrix.Multiply(aRotation); |
340 | } |
341 | else if (!strcmp("AXON", theType)) |
342 | { |
343 | const gp_Dir aD1(1., 0., 0.); |
344 | const gp_Dir aD2(0., 0., 1.); |
345 | |
346 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.25 * M_PI); |
347 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.25 * M_PI); |
348 | myMatrix.Multiply(aRotation); |
349 | } |
350 | else if (!strcmp("PERS", theType)) |
351 | { |
352 | const gp_Dir aD1(1., 0., 0.); |
353 | const gp_Dir aD2(0., 0., 1.); |
354 | |
355 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.25 * M_PI); |
356 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), -0.25 * M_PI); |
357 | myMatrix.Multiply(aRotation); |
358 | |
359 | myIsPers = Standard_True; |
360 | } |
361 | else |
362 | { |
363 | return Standard_False; |
364 | } |
365 | |
366 | strcpy(myType, theType); |
367 | return Standard_True; |
368 | } |
369 | |
370 | //======================================================================= |
371 | //function : Transform |
372 | //purpose : |
373 | //======================================================================= |
374 | void Draw_View::Transform(const gp_Trsf& theTransformation) |
375 | { |
376 | myMatrix.Multiply(theTransformation); |
377 | } |
378 | |
379 | //======================================================================= |
380 | //function : ResetFrame |
381 | //purpose : |
382 | //======================================================================= |
383 | void Draw_View::ResetFrame() |
384 | { |
385 | myFrameX0 = 0; |
386 | myFrameY0 = 0; |
387 | myFrameX1 = 0; |
388 | myFrameY1 = 0; |
389 | } |
390 | |
391 | //======================================================================= |
392 | //function : GetFrame |
393 | //purpose : |
394 | //======================================================================= |
395 | void Draw_View::GetFrame(Standard_Integer& theX0,Standard_Integer& theY0, |
396 | Standard_Integer& theX1,Standard_Integer& theY1) |
397 | { |
398 | if ( myFrameX0 == myFrameX1 ) |
399 | { |
400 | myViewer->GetFrame(myId, theX0, theY0, theX1, theY1); |
401 | myFrameX0 = theX0; |
402 | myFrameX1 = theX1; |
403 | myFrameY0 = theY0; |
404 | myFrameY1 = theY1; |
405 | } |
406 | else |
407 | { |
408 | theX0 = myFrameX0; |
409 | theX1 = myFrameX1; |
410 | theY0 = myFrameY0; |
411 | theY1 = myFrameY1; |
412 | } |
413 | } |
414 | |
415 | //======================================================================= |
416 | //function : WExpose |
417 | //purpose : |
418 | //======================================================================= |
419 | void Draw_View::WExpose() |
420 | { |
421 | ResetFrame(); |
422 | myViewer->RepaintView(myId); |
423 | } |