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