0028316: Coding Rules - Elimilate confusing aliases of Standard_Real type in V3d_View
[occt.git] / samples / mfc / occtdemo / Common / WNT / OCCDemoView.cpp
CommitLineData
7fd59977 1// OCCDemoView.cpp : implementation of the COCCDemoView class
2//
3
4#include "stdafx.h"
5#include "MainFrm.h"
6#include "OCCDemo.h"
7#include "OCCDemoDoc.h"
8#include "OCCDemoView.h"
9
10#include <Graphic3d_GraphicDriver.hxx>
7fd59977 11
12#define ValZWMin 1
13
14#ifdef _DEBUG
15#undef THIS_FILE
16static char THIS_FILE[] = __FILE__;
17#endif
18
19/////////////////////////////////////////////////////////////////////////////
20// COCCDemoView
21
22IMPLEMENT_DYNCREATE(COCCDemoView, CView)
23
24BEGIN_MESSAGE_MAP(COCCDemoView, CView)
25 //{{AFX_MSG_MAP(COCCDemoView)
26 ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo)
27 ON_COMMAND(ID_BUTTONBack, OnBUTTONBack)
28 ON_COMMAND(ID_BUTTONBottom, OnBUTTONBottom)
29 ON_COMMAND(ID_BUTTONFront, OnBUTTONFront)
30 ON_COMMAND(ID_BUTTONHlrOn, OnBUTTONHlrOn)
31 ON_COMMAND(ID_BUTTONLeft, OnBUTTONLeft)
32 ON_COMMAND(ID_BUTTONPan, OnBUTTONPan)
33 ON_COMMAND(ID_BUTTONPanGlo, OnBUTTONPanGlo)
34 ON_COMMAND(ID_BUTTONReset, OnBUTTONReset)
35 ON_COMMAND(ID_BUTTONRight, OnBUTTONRight)
36 ON_COMMAND(ID_BUTTONRot, OnBUTTONRot)
37 ON_COMMAND(ID_BUTTONTop, OnBUTTONTop)
38 ON_COMMAND(ID_BUTTONZoomAll, OnBUTTONZoomAll)
39 ON_WM_SIZE()
40 ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg)
41 ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin)
42 ON_WM_LBUTTONDOWN()
43 ON_WM_LBUTTONUP()
44 ON_WM_MOUSEMOVE()
45 ON_WM_RBUTTONDOWN()
46 ON_WM_RBUTTONUP()
47 ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo)
48 ON_UPDATE_COMMAND_UI(ID_BUTTONPan, OnUpdateBUTTONPan)
49 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomProg, OnUpdateBUTTONZoomProg)
50 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomWin, OnUpdateBUTTONZoomWin)
51 ON_UPDATE_COMMAND_UI(ID_BUTTONRot, OnUpdateBUTTONRot)
52 ON_COMMAND(ID_BUTTONWire, OnBUTTONWire)
53 ON_COMMAND(ID_BUTTONShade, OnBUTTONShade)
54 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn)
55 ON_UPDATE_COMMAND_UI(ID_BUTTONShade, OnUpdateBUTTONShade)
56 ON_UPDATE_COMMAND_UI(ID_BUTTONWire, OnUpdateBUTTONWire)
57 //}}AFX_MSG_MAP
58END_MESSAGE_MAP()
59
60/////////////////////////////////////////////////////////////////////////////
61// COCCDemoView construction/destruction
62
63COCCDemoView::COCCDemoView()
64{
65 myXmin=0;
66 myYmin=0;
67 myXmax=0;
68 myYmax=0;
69 myCurZoom=0;
70 myCurrentMode = CurAction3d_Nothing;
71 myVisMode = VIS_SHADE;
72 m_Pen = NULL;
73 myGraphicDriver = Handle(Graphic3d_GraphicDriver)::DownCast(
74 ((COCCDemoApp*)AfxGetApp())->GetGraphicDevice()->GraphicDriver() );
75}
76
77COCCDemoView::~COCCDemoView()
78{
79 if (!myView.IsNull())
80 myView->Remove();
81 if (m_Pen)
82 delete m_Pen;
83}
84
85BOOL COCCDemoView::PreCreateWindow(CREATESTRUCT& cs)
86{
87 // TODO: Modify the Window class or styles here by modifying
88 // the CREATESTRUCT cs
89
90 return CView::PreCreateWindow(cs);
91}
92
93/////////////////////////////////////////////////////////////////////////////
94// COCCDemoView drawing
95
96void COCCDemoView::OnInitialUpdate()
97{
98 CView::OnInitialUpdate();
99
100 myView = GetDocument()->GetViewer()->CreateView();
101
102 Handle(Graphic3d_WNTGraphicDevice) theGraphicDevice =
103 ((COCCDemoApp*)AfxGetApp())->GetGraphicDevice();
104
105 Handle(WNT_Window) aWNTWindow = new WNT_Window(theGraphicDevice,GetSafeHwnd ());
106 myView->SetWindow(aWNTWindow);
107 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
108
109 myCurrentMode = CurAction3d_Nothing;
110 myVisMode = VIS_SHADE;
111 RedrawVisMode();
112}
113
114void COCCDemoView::OnDraw(CDC* pDC)
115{
116 COCCDemoDoc* pDoc = GetDocument();
117 ASSERT_VALID(pDoc);
118 // TODO: add draw code for native data here
119 myView->Redraw();
120}
121
122/////////////////////////////////////////////////////////////////////////////
123// COCCDemoView diagnostics
124
125#ifdef _DEBUG
126void COCCDemoView::AssertValid() const
127{
128 CView::AssertValid();
129}
130
131void COCCDemoView::Dump(CDumpContext& dc) const
132{
133 CView::Dump(dc);
134}
135
136COCCDemoDoc* COCCDemoView::GetDocument() // non-debug version is inline
137{
138 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COCCDemoDoc)));
139 return (COCCDemoDoc*)m_pDocument;
140}
141#endif //_DEBUG
142
143/////////////////////////////////////////////////////////////////////////////
144// COCCDemoView message handlers
145
146void COCCDemoView::OnSize(UINT nType, int cx, int cy)
147{
148 if (!myView.IsNull())
149 myView->MustBeResized();
150}
151
152void COCCDemoView::OnBUTTONBack()
153{
154 myView->SetProj(V3d_Ypos);
155}
156
157void COCCDemoView::OnBUTTONFront()
158{
159 myView->SetProj(V3d_Yneg);
160}
161
162void COCCDemoView::OnBUTTONBottom()
163{
164 myView->SetProj(V3d_Zneg);
165}
166
167void COCCDemoView::OnBUTTONTop()
168{
169 myView->SetProj(V3d_Zpos);
170}
171
172void COCCDemoView::OnBUTTONLeft()
173{
174 myView->SetProj(V3d_Xneg);
175}
176
177void COCCDemoView::OnBUTTONRight()
178{
179 myView->SetProj(V3d_Xpos);
180}
181
182void COCCDemoView::OnBUTTONAxo()
183{
184 myView->SetProj(V3d_XposYnegZpos);
185}
186
187void COCCDemoView::OnBUTTONPan()
188{
189 myCurrentMode = CurAction3d_DynamicPanning;
190}
191
192void COCCDemoView::OnBUTTONPanGlo()
193{
194 // save the current zoom value
195 myCurZoom = myView->Scale();
196 // Do a Global Zoom
197 myView->FitAll();
198 // Set the mode
199 myCurrentMode = CurAction3d_GlobalPanning;
200}
201
202void COCCDemoView::OnBUTTONReset()
203{
204 myView->Reset();
205}
206
207void COCCDemoView::OnBUTTONRot()
208{
209 myCurrentMode = CurAction3d_DynamicRotation;
210}
211
212void COCCDemoView::OnBUTTONZoomAll()
213{
214 myView->FitAll();
215 myView->ZFitAll();
216}
217
218void COCCDemoView::OnBUTTONZoomProg()
219{
220 myCurrentMode = CurAction3d_DynamicZooming;
221}
222
223void COCCDemoView::OnBUTTONZoomWin()
224{
225 myCurrentMode = CurAction3d_WindowZooming;
226}
227
228void COCCDemoView::OnLButtonDown(UINT nFlags, CPoint point)
229{
230 // save the current mouse coordinate in min
231 myXmin=point.x; myYmin=point.y;
232 myXmax=point.x; myYmax=point.y;
233
234 if ( ! (nFlags & MK_CONTROL) )
235 {
236 if (myCurrentMode == CurAction3d_DynamicRotation)
237 {
238 myView->SetComputedMode(Standard_False);
239 myView->StartRotation(point.x,point.y);
240 }
241 }
242}
243
244void COCCDemoView::OnLButtonUp(UINT nFlags, CPoint point)
245{
246 if ( !(nFlags & MK_CONTROL) )
247 {
248 switch (myCurrentMode)
249 {
250 case CurAction3d_Nothing :
251 myXmax=point.x;
252 myYmax=point.y;
253 break;
254 case CurAction3d_DynamicZooming :
255 myCurrentMode = CurAction3d_Nothing;
256 break;
257 case CurAction3d_WindowZooming :
258 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
259 myXmax=point.x;
260 myYmax=point.y;
261 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
262 // Test if the zoom window is greater than a minimale window.
263 {
264 // Do the zoom window between Pmin and Pmax
265 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
266 }
267 myCurrentMode = CurAction3d_Nothing;
268 break;
269 case CurAction3d_DynamicPanning :
270 myCurrentMode = CurAction3d_Nothing;
271 break;
272 case CurAction3d_GlobalPanning :
273 myView->Place(point.x,point.y,myCurZoom);
274 myCurrentMode = CurAction3d_Nothing;
275 break;
276 case CurAction3d_DynamicRotation :
277 if (myVisMode == VIS_HLR)
278 {
279 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
280 myView->SetComputedMode(Standard_True);
281 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
282 }
283 myCurrentMode = CurAction3d_Nothing;
284 break;
285 } //switch (myCurrentMode)
286 }
287}
288
289void COCCDemoView::OnRButtonDown(UINT nFlags, CPoint point)
290{
291 if ( nFlags & MK_CONTROL )
292 {
293 myView->SetComputedMode(Standard_False);
294 myView->StartRotation(point.x,point.y);
295 }
296}
297
298void COCCDemoView::OnRButtonUp(UINT nFlags, CPoint point)
299{
300 if (myVisMode == VIS_HLR)
301 {
302 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
303 myView->SetComputedMode(Standard_True);
304 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
305 }
306}
307
308void COCCDemoView::OnMouseMove(UINT nFlags, CPoint point)
309{
310 // ============================ LEFT BUTTON =======================
311 if ( nFlags & MK_LBUTTON)
312 {
313 if ( nFlags & MK_CONTROL )
314 {
315 // move with MB1 and Control : on the dynamic zooming
316 // Do the zoom in function of mouse's coordinates
317 myView->Zoom(myXmax,myYmax,point.x,point.y);
318 // save the current mouse coordinate in max
319 myXmax = point.x;
320 myYmax = point.y;
321 }
322 else // if ( Ctrl )
323 {
324 switch (myCurrentMode)
325 {
326 case CurAction3d_Nothing :
327 myXmax = point.x;
328 myYmax = point.y;
329 break;
330 case CurAction3d_DynamicZooming :
331 myView->Zoom(myXmax,myYmax,point.x,point.y);
332 // save the current mouse coordinate in max;
333 myXmax=point.x;
334 myYmax=point.y;
335 break;
336 case CurAction3d_WindowZooming :
337 myXmax = point.x; myYmax = point.y;
338 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
339 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
340 break;
341 case CurAction3d_DynamicPanning :
342 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
343 myXmax = point.x; myYmax = point.y;
344 break;
345 case CurAction3d_GlobalPanning : // nothing
346 break;
347 case CurAction3d_DynamicRotation :
348 myView->Rotation(point.x,point.y);
349 myView->Redraw();
350 break;
351 }
352 }
353 }
354 // ============================ MIDDLE BUTTON =======================
355 else if ( nFlags & MK_MBUTTON)
356 {
357 if ( nFlags & MK_CONTROL )
358 {
359 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
360 myXmax = point.x; myYmax = point.y;
361 }
362 }
363 // ============================ RIGHT BUTTON =======================
364 else if ( nFlags & MK_RBUTTON)
365 {
366 if ( nFlags & MK_CONTROL )
367 {
368 myView->Rotation(point.x,point.y);
369 }
370 }
371 // ============================ NO BUTTON =======================
372 else
373 {
374 myXmax = point.x;
375 myYmax = point.y;
376 }
377}
378
379void COCCDemoView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
380{
381 pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning);
382 pCmdUI->Enable (myCurrentMode != CurAction3d_GlobalPanning);
383}
384
385void COCCDemoView::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
386{
387 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning);
388 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicPanning );
389}
390
391void COCCDemoView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
392{
393 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming );
394 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicZooming);
395}
396
397void COCCDemoView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
398{
399 pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming);
400 pCmdUI->Enable (myCurrentMode != CurAction3d_WindowZooming);
401}
402
403void COCCDemoView::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
404{
405 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation);
406 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation);
407}
408
409void COCCDemoView::DrawRectangle(const Standard_Integer MinX,
410 const Standard_Integer MinY,
411 const Standard_Integer MaxX,
412 const Standard_Integer MaxY,
413 const Standard_Boolean Draw,
414 const LineStyle aLineStyle)
415{
416 static int m_DrawMode;
417 if (!m_Pen && aLineStyle ==Solid )
418 {
419 m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;
420 }
421 else if (!m_Pen && aLineStyle ==Dot )
422 {
423 m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;
424 }
425 else if (!m_Pen && aLineStyle == ShortDash)
426 {
427 m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;
428 }
429 else if (!m_Pen && aLineStyle == LongDash)
430 {
431 m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;
432 }
433 else if (aLineStyle == Default)
434 {
435 m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;
436 }
437
438 CPen* aOldPen;
439 CClientDC clientDC(this);
440 if (m_Pen)
441 aOldPen = clientDC.SelectObject(m_Pen);
442 clientDC.SetROP2(m_DrawMode);
443
444 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
445 static Standard_Boolean m_IsVisible = Standard_False;
446
447 if ( m_IsVisible && !Draw) // move or up : erase at the old position
448 {
449 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
450 clientDC.LineTo(StoredMaxX,StoredMaxY);
451 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
452 m_IsVisible = false;
453 }
454
455 StoredMinX = min ( MinX, MaxX );
456 StoredMinY = min ( MinY, MaxY );
457 StoredMaxX = max ( MinX, MaxX );
458 StoredMaxY = max ( MinY, MaxY);
459
460 if (Draw) // move : draw
461 {
462 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
463 clientDC.LineTo(StoredMaxX,StoredMaxY);
464 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
465 m_IsVisible = true;
466 }
467
468 if (m_Pen)
469 clientDC.SelectObject(aOldPen);
470}
471
472void COCCDemoView::InitButtons()
473{
474 myXmin=0;
475 myYmin=0;
476 myXmax=0;
477 myYmax=0;
478 myCurZoom=0;
479 myCurrentMode = CurAction3d_Nothing;
480}
481
482void COCCDemoView::Reset()
483{
484 InitButtons();
485 myVisMode = VIS_SHADE;
486 if (!myView.IsNull())
487 {
488 RedrawVisMode();
489 myView->Reset();
490 }
491}
492
493void COCCDemoView::RedrawVisMode()
494{
495 switch (myVisMode)
496 {
497 case VIS_WIREFRAME:
498 GetDocument()->GetAISContext()->SetDisplayMode(AIS_WireFrame);
499 myView->SetComputedMode (Standard_False);
500 break;
501 case VIS_SHADE:
502 GetDocument()->GetAISContext()->SetDisplayMode(AIS_Shaded);
503 myView->SetComputedMode (Standard_False);
504 break;
505 case VIS_HLR:
506 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
507 myView->SetComputedMode (Standard_True);
508 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
509 GetDocument()->GetAISContext()->SetDisplayMode(AIS_WireFrame);
510 break;
511 }
512}
513
514void COCCDemoView::OnBUTTONWire()
515{
516 myVisMode = VIS_WIREFRAME;
517 RedrawVisMode();
518}
519
520void COCCDemoView::OnBUTTONShade()
521{
522 myVisMode = VIS_SHADE;
523 RedrawVisMode();
524}
525
526void COCCDemoView::OnBUTTONHlrOn()
527{
528 myVisMode = VIS_HLR;
529 RedrawVisMode();
530}
531
532void COCCDemoView::OnUpdateBUTTONWire(CCmdUI* pCmdUI)
533{
534 pCmdUI->SetCheck (myVisMode == VIS_WIREFRAME);
535 pCmdUI->Enable (myVisMode != VIS_WIREFRAME);
536}
537
538void COCCDemoView::OnUpdateBUTTONShade(CCmdUI* pCmdUI)
539{
540 pCmdUI->SetCheck (myVisMode == VIS_SHADE);
541 pCmdUI->Enable (myVisMode != VIS_SHADE);
542}
543
544void COCCDemoView::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
545{
546 pCmdUI->SetCheck (myVisMode == VIS_HLR);
547 pCmdUI->Enable (myVisMode != VIS_HLR);
548}
549
ee2be2a8 550void COCCDemoView::GetViewCenter(Standard_Real& Xc, Standard_Real& Yc)
7fd59977 551{
552 myView->Center(Xc,Yc);
553}
554
ee2be2a8 555void COCCDemoView::SetViewCenter(Standard_Real Xc, Standard_Real Yc)
7fd59977 556{
557 myView->SetCenter(Xc,Yc);
558}
559
ee2be2a8 560void COCCDemoView::GetViewEye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z)
7fd59977 561{
562 myView->Eye(X,Y,Z);
563}
564
ee2be2a8 565void COCCDemoView::SetViewEye(Standard_Real X, Standard_Real Y, Standard_Real Z)
7fd59977 566{
567 myView->SetEye(X,Y,Z);
568}
569
ee2be2a8 570Standard_Real COCCDemoView::GetViewScale()
7fd59977 571{
572 return myView->Scale();
573}
574
ee2be2a8 575void COCCDemoView::SetViewScale(Standard_Real Coef)
7fd59977 576{
577 myView->SetScale(Coef);
578}