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 | //======================================================================= |
96f3bacc |
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, |
b69e576a |
29 | Aspect_Drawable theWindow) |
30 | : Draw_Window ("Win", |
31 | NCollection_Vec2<int> (theX, theY), |
32 | NCollection_Vec2<int> (theWidth, theHeight), |
33 | 0, theWindow), |
96f3bacc |
34 | myId (theId), |
35 | myViewer (theViewer), |
36 | myIsPers (Standard_False), |
37 | myIs2D (Standard_False), |
38 | myFocalDistance(0.0), |
39 | myZoom (0.0), |
40 | myDx (0), |
41 | myDy (0), |
42 | myFrameX0 (0), |
43 | myFrameY0 (0), |
44 | myFrameX1 (0), |
45 | myFrameY1 (0) |
46 | { |
d533dafb |
47 | memset (myType, 0, sizeof (myType)); |
96f3bacc |
48 | } |
49 | |
b69e576a |
50 | //! Find window by it's XID - applicable only to X11. |
51 | static Aspect_Drawable findWindow (const char* theWindow) |
96f3bacc |
52 | { |
b69e576a |
53 | Aspect_Drawable aWindow = 0; |
54 | #ifdef HAVE_XLIB |
55 | sscanf (theWindow, "%lx", &aWindow); |
56 | #else |
57 | (void )theWindow; |
96f3bacc |
58 | #endif |
b69e576a |
59 | return aWindow; |
60 | } |
96f3bacc |
61 | |
62 | //======================================================================= |
63 | //function : Draw_View |
64 | //purpose : Constructor |
65 | //======================================================================= |
96f3bacc |
66 | Draw_View::Draw_View(Standard_Integer theId, |
67 | Draw_Viewer* theViewer, |
68 | const char* theTitle) |
b69e576a |
69 | : Draw_Window (theTitle, NCollection_Vec2<int>(0), NCollection_Vec2<int>(50), 0, findWindow (theTitle)), |
96f3bacc |
70 | myId (theId), |
71 | myViewer (theViewer), |
96f3bacc |
72 | myIsPers (Standard_False), |
73 | myIs2D (Standard_False), |
74 | myFocalDistance(0.0), |
75 | myZoom (0.0), |
76 | myDx (0), |
77 | myDy (0), |
78 | myFrameX0 (0), |
79 | myFrameY0 (0), |
80 | myFrameX1 (0), |
81 | myFrameY1 (0) |
82 | { |
d533dafb |
83 | memset (myType, 0, sizeof (myType)); |
96f3bacc |
84 | } |
85 | |
86 | //======================================================================= |
87 | //function : ~Draw_View |
88 | //purpose : Destructor |
89 | //======================================================================= |
90 | Draw_View::~Draw_View() |
91 | { |
92 | Draw_Window::Destroy(); |
93 | } |
94 | |
95 | //======================================================================= |
96 | //function : Init |
97 | //purpose : |
98 | //======================================================================= |
99 | Standard_Boolean Draw_View::Init(const char* theType) |
100 | { |
101 | { // default fields |
102 | myFocalDistance = 500.; |
103 | myIsPers = Standard_False; |
104 | myIs2D = strcmp("-2D-", theType) ? Standard_False : Standard_True; |
105 | myZoom = 1; |
106 | |
107 | ResetFrame(); |
108 | } |
109 | |
110 | gp_Trsf aRotation; |
111 | gp_Pnt Pvise(0.0, 0.0, 0.0); |
112 | |
113 | if (!strcmp("+X+Y", theType) || myIs2D) |
114 | { |
115 | myMatrix = aRotation; |
116 | } |
117 | else if (!strcmp("-Y+X", theType)) |
118 | { |
119 | const gp_Dir aD(0., 0., 1.); |
120 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI); |
121 | } |
122 | else if (!strcmp("-X-Y", theType)) |
123 | { |
124 | const gp_Dir aD(0., 0., 1.); |
125 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI); |
126 | } |
127 | else if (!strcmp("+Y-X", theType)) |
128 | { |
129 | const gp_Dir aD(0., 0., 1.); |
130 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI); |
131 | } |
132 | else if (!strcmp("+Y+X", theType)) |
133 | { |
134 | const gp_Dir aD1(0., 0., 1.); |
135 | const gp_Dir aD2(0., 1., 0.); |
136 | |
137 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
138 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
139 | myMatrix.Multiply(aRotation); |
140 | } |
141 | else if (!strcmp("-X+Y", theType)) |
142 | { |
143 | const gp_Dir aD(0., 1., 0.); |
144 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI); |
145 | } |
146 | else if (!strcmp("-Y-X", theType)) |
147 | { |
148 | const gp_Dir aD1(0., 0., 1.); |
149 | const gp_Dir aD2(1., 0., 0.); |
150 | |
151 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
152 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
153 | myMatrix.Multiply(aRotation); |
154 | } |
155 | else if (!strcmp("+X-Y", theType)) |
156 | { |
157 | const gp_Dir aD(1., 0., 0.); |
158 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), M_PI); |
159 | } |
160 | else if (!strcmp("+X+Z", theType)) |
161 | { |
162 | const gp_Dir aD(1., 0., 0.); |
163 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI); |
164 | } |
165 | else if (!strcmp("-Z+X", theType)) |
166 | { |
167 | const gp_Dir aD1(1., 0., 0.); |
168 | const gp_Dir aD2(0., 1., 0.); |
169 | |
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); |
173 | } |
174 | else if (!strcmp("-X-Z", theType)) |
175 | { |
176 | const gp_Dir aD1(1., 0., 0.); |
177 | const gp_Dir aD2(0., 1., 0.); |
178 | |
179 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
180 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), -M_PI); |
181 | myMatrix.Multiply(aRotation); |
182 | } |
183 | else if (!strcmp("+Z-X", theType)) |
184 | { |
185 | const gp_Dir aD1(1., 0., 0.); |
186 | const gp_Dir aD2(0., 1., 0.); |
187 | |
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); |
191 | } |
192 | else if (!strcmp("+Z+X", theType)) |
193 | { |
194 | const gp_Dir aD1(1., 0., 0.); |
195 | const gp_Dir aD2(0., 1., 0.); |
196 | |
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); |
200 | } |
201 | else if (!strcmp("-X+Z", theType)) |
202 | { |
203 | const gp_Dir aD1(1., 0., 0.); |
204 | const gp_Dir aD2(0., 1., 0.); |
205 | |
206 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI); |
207 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
208 | myMatrix.Multiply(aRotation); |
209 | } |
210 | else if (!strcmp("-Z-X", theType)) |
211 | { |
212 | const gp_Dir aD1(1., 0., 0.); |
213 | const gp_Dir aD2(0., 1., 0.); |
214 | |
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); |
218 | } |
219 | else if (!strcmp("+X-Z", theType)) |
220 | { |
221 | const gp_Dir aD(1., 0., 0.); |
222 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI); |
223 | } |
224 | else if (!strcmp("+Y+Z", theType)) |
225 | { |
226 | const gp_Dir aD1(0., 1., 0.); |
227 | const gp_Dir aD2(1., 0., 0.); |
228 | |
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); |
232 | } |
233 | else if (!strcmp("-Z+Y", theType)) |
234 | { |
235 | const gp_Dir aD(0., 1., 0.); |
236 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), -0.5 * M_PI); |
237 | } |
238 | else if (!strcmp("-Y-Z", theType)) |
239 | { |
240 | const gp_Dir aD1(0., 1., 0.); |
241 | const gp_Dir aD2(1., 0., 0.); |
242 | |
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); |
246 | } |
247 | else if (!strcmp("+Z-Y", theType)) |
248 | { |
249 | const gp_Dir aD1(0., 1., 0.); |
250 | const gp_Dir aD2(1., 0., 0.); |
251 | |
252 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), -0.5 * M_PI); |
253 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
254 | myMatrix.Multiply(aRotation); |
255 | } |
256 | else if (!strcmp("+Z+Y", theType)) |
257 | { |
258 | const gp_Dir aD(0., 1., 0.); |
259 | myMatrix.SetRotation(gp_Ax1(Pvise, aD), 0.5 * M_PI); |
260 | } |
261 | else if (!strcmp("-Y+Z", theType)) |
262 | { |
263 | const gp_Dir aD1(0., 1., 0.); |
264 | const gp_Dir aD2(1., 0., 0.); |
265 | |
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); |
269 | } |
270 | else if (!strcmp("-Z-Y", theType)) |
271 | { |
272 | const gp_Dir aD1(0., 1., 0.); |
273 | const gp_Dir aD2(1., 0., 0.); |
274 | |
275 | myMatrix.SetRotation (gp_Ax1(Pvise, aD1), 0.5 * M_PI); |
276 | aRotation.SetRotation(gp_Ax1(Pvise, aD2), M_PI); |
277 | myMatrix.Multiply(aRotation); |
278 | } |
279 | else if (!strcmp("+Y-Z", theType)) |
280 | { |
281 | const gp_Dir aD1(0., 1., 0.); |
282 | const gp_Dir aD2(1., 0., 0.); |
283 | |
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); |
287 | } |
288 | else if (!strcmp("AXON", theType)) |
289 | { |
290 | const gp_Dir aD1(1., 0., 0.); |
291 | const gp_Dir aD2(0., 0., 1.); |
292 | |
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); |
296 | } |
297 | else if (!strcmp("PERS", theType)) |
298 | { |
299 | const gp_Dir aD1(1., 0., 0.); |
300 | const gp_Dir aD2(0., 0., 1.); |
301 | |
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); |
305 | |
306 | myIsPers = Standard_True; |
307 | } |
308 | else |
309 | { |
310 | return Standard_False; |
311 | } |
312 | |
313 | strcpy(myType, theType); |
314 | return Standard_True; |
315 | } |
316 | |
317 | //======================================================================= |
318 | //function : Transform |
319 | //purpose : |
320 | //======================================================================= |
321 | void Draw_View::Transform(const gp_Trsf& theTransformation) |
322 | { |
323 | myMatrix.Multiply(theTransformation); |
324 | } |
325 | |
326 | //======================================================================= |
327 | //function : ResetFrame |
328 | //purpose : |
329 | //======================================================================= |
330 | void Draw_View::ResetFrame() |
331 | { |
332 | myFrameX0 = 0; |
333 | myFrameY0 = 0; |
334 | myFrameX1 = 0; |
335 | myFrameY1 = 0; |
336 | } |
337 | |
338 | //======================================================================= |
339 | //function : GetFrame |
340 | //purpose : |
341 | //======================================================================= |
342 | void Draw_View::GetFrame(Standard_Integer& theX0,Standard_Integer& theY0, |
343 | Standard_Integer& theX1,Standard_Integer& theY1) |
344 | { |
345 | if ( myFrameX0 == myFrameX1 ) |
346 | { |
347 | myViewer->GetFrame(myId, theX0, theY0, theX1, theY1); |
348 | myFrameX0 = theX0; |
349 | myFrameX1 = theX1; |
350 | myFrameY0 = theY0; |
351 | myFrameY1 = theY1; |
352 | } |
353 | else |
354 | { |
355 | theX0 = myFrameX0; |
356 | theX1 = myFrameX1; |
357 | theY0 = myFrameY0; |
358 | theY1 = myFrameY1; |
359 | } |
360 | } |
361 | |
362 | //======================================================================= |
363 | //function : WExpose |
364 | //purpose : |
365 | //======================================================================= |
366 | void Draw_View::WExpose() |
367 | { |
368 | ResetFrame(); |
369 | myViewer->RepaintView(myId); |
370 | } |