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