0028895: Visualization, V3d_View::SetComputedMode() - HLR calculation is performed...
[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);
1eeef710 280 myView->Redraw();
7fd59977 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
5c573e69 298void COCCDemoView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/)
7fd59977 299{
300 if (myVisMode == VIS_HLR)
301 {
302 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
303 myView->SetComputedMode(Standard_True);
1eeef710 304 myView->Redraw();
7fd59977 305 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
306 }
307}
308
309void COCCDemoView::OnMouseMove(UINT nFlags, CPoint point)
310{
311 // ============================ LEFT BUTTON =======================
312 if ( nFlags & MK_LBUTTON)
313 {
314 if ( nFlags & MK_CONTROL )
315 {
316 // move with MB1 and Control : on the dynamic zooming
317 // Do the zoom in function of mouse's coordinates
318 myView->Zoom(myXmax,myYmax,point.x,point.y);
319 // save the current mouse coordinate in max
320 myXmax = point.x;
321 myYmax = point.y;
322 }
323 else // if ( Ctrl )
324 {
325 switch (myCurrentMode)
326 {
327 case CurAction3d_Nothing :
328 myXmax = point.x;
329 myYmax = point.y;
330 break;
331 case CurAction3d_DynamicZooming :
332 myView->Zoom(myXmax,myYmax,point.x,point.y);
333 // save the current mouse coordinate in max;
334 myXmax=point.x;
335 myYmax=point.y;
336 break;
337 case CurAction3d_WindowZooming :
338 myXmax = point.x; myYmax = point.y;
339 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
340 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
341 break;
342 case CurAction3d_DynamicPanning :
343 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
344 myXmax = point.x; myYmax = point.y;
345 break;
346 case CurAction3d_GlobalPanning : // nothing
347 break;
348 case CurAction3d_DynamicRotation :
349 myView->Rotation(point.x,point.y);
350 myView->Redraw();
351 break;
352 }
353 }
354 }
355 // ============================ MIDDLE BUTTON =======================
356 else if ( nFlags & MK_MBUTTON)
357 {
358 if ( nFlags & MK_CONTROL )
359 {
360 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
361 myXmax = point.x; myYmax = point.y;
362 }
363 }
364 // ============================ RIGHT BUTTON =======================
365 else if ( nFlags & MK_RBUTTON)
366 {
367 if ( nFlags & MK_CONTROL )
368 {
369 myView->Rotation(point.x,point.y);
370 }
371 }
372 // ============================ NO BUTTON =======================
373 else
374 {
375 myXmax = point.x;
376 myYmax = point.y;
377 }
378}
379
380void COCCDemoView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
381{
382 pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning);
383 pCmdUI->Enable (myCurrentMode != CurAction3d_GlobalPanning);
384}
385
386void COCCDemoView::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
387{
388 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning);
389 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicPanning );
390}
391
392void COCCDemoView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
393{
394 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming );
395 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicZooming);
396}
397
398void COCCDemoView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
399{
400 pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming);
401 pCmdUI->Enable (myCurrentMode != CurAction3d_WindowZooming);
402}
403
404void COCCDemoView::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
405{
406 pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation);
407 pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation);
408}
409
410void COCCDemoView::DrawRectangle(const Standard_Integer MinX,
411 const Standard_Integer MinY,
412 const Standard_Integer MaxX,
413 const Standard_Integer MaxY,
414 const Standard_Boolean Draw,
415 const LineStyle aLineStyle)
416{
417 static int m_DrawMode;
418 if (!m_Pen && aLineStyle ==Solid )
419 {
420 m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;
421 }
422 else if (!m_Pen && aLineStyle ==Dot )
423 {
424 m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;
425 }
426 else if (!m_Pen && aLineStyle == ShortDash)
427 {
428 m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;
429 }
430 else if (!m_Pen && aLineStyle == LongDash)
431 {
432 m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;
433 }
434 else if (aLineStyle == Default)
435 {
436 m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;
437 }
438
5c573e69 439 CPen* aOldPen = NULL;
7fd59977 440 CClientDC clientDC(this);
441 if (m_Pen)
442 aOldPen = clientDC.SelectObject(m_Pen);
443 clientDC.SetROP2(m_DrawMode);
444
445 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
446 static Standard_Boolean m_IsVisible = Standard_False;
447
448 if ( m_IsVisible && !Draw) // move or up : erase at the old position
449 {
450 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
451 clientDC.LineTo(StoredMaxX,StoredMaxY);
452 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
453 m_IsVisible = false;
454 }
455
f751596e 456 StoredMinX = Min ( MinX, MaxX );
457 StoredMinY = Min ( MinY, MaxY );
458 StoredMaxX = Max ( MinX, MaxX );
459 StoredMaxY = Max ( MinY, MaxY);
7fd59977 460
461 if (Draw) // move : draw
462 {
463 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
464 clientDC.LineTo(StoredMaxX,StoredMaxY);
465 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
466 m_IsVisible = true;
467 }
468
469 if (m_Pen)
470 clientDC.SelectObject(aOldPen);
471}
472
473void COCCDemoView::InitButtons()
474{
475 myXmin=0;
476 myYmin=0;
477 myXmax=0;
478 myYmax=0;
479 myCurZoom=0;
480 myCurrentMode = CurAction3d_Nothing;
481}
482
483void COCCDemoView::Reset()
484{
485 InitButtons();
486 myVisMode = VIS_SHADE;
487 if (!myView.IsNull())
488 {
489 RedrawVisMode();
490 myView->Reset();
491 }
492}
493
494void COCCDemoView::RedrawVisMode()
495{
496 switch (myVisMode)
497 {
498 case VIS_WIREFRAME:
0577ae8c 499 GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 500 myView->SetComputedMode (Standard_False);
1eeef710 501 myView->Redraw();
7fd59977 502 break;
503 case VIS_SHADE:
0577ae8c 504 GetDocument()->GetAISContext()->SetDisplayMode (AIS_Shaded, Standard_True);
7fd59977 505 myView->SetComputedMode (Standard_False);
1eeef710 506 myView->Redraw();
7fd59977 507 break;
508 case VIS_HLR:
509 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
510 myView->SetComputedMode (Standard_True);
1eeef710 511 myView->Redraw();
7fd59977 512 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
0577ae8c 513 GetDocument()->GetAISContext()->SetDisplayMode (AIS_WireFrame, Standard_True);
7fd59977 514 break;
515 }
516}
517
518void COCCDemoView::OnBUTTONWire()
519{
520 myVisMode = VIS_WIREFRAME;
521 RedrawVisMode();
522}
523
524void COCCDemoView::OnBUTTONShade()
525{
526 myVisMode = VIS_SHADE;
527 RedrawVisMode();
528}
529
530void COCCDemoView::OnBUTTONHlrOn()
531{
532 myVisMode = VIS_HLR;
533 RedrawVisMode();
534}
535
536void COCCDemoView::OnUpdateBUTTONWire(CCmdUI* pCmdUI)
537{
538 pCmdUI->SetCheck (myVisMode == VIS_WIREFRAME);
539 pCmdUI->Enable (myVisMode != VIS_WIREFRAME);
540}
541
542void COCCDemoView::OnUpdateBUTTONShade(CCmdUI* pCmdUI)
543{
544 pCmdUI->SetCheck (myVisMode == VIS_SHADE);
545 pCmdUI->Enable (myVisMode != VIS_SHADE);
546}
547
548void COCCDemoView::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
549{
550 pCmdUI->SetCheck (myVisMode == VIS_HLR);
551 pCmdUI->Enable (myVisMode != VIS_HLR);
552}
553
ee2be2a8 554void COCCDemoView::GetViewAt (Standard_Real& theX, Standard_Real& theY, Standard_Real& theZ) const
7fd59977 555{
9764ccbb 556 myView->At (theX, theY, theZ);
7fd59977 557}
558
ee2be2a8 559void COCCDemoView::SetViewAt (const Standard_Real theX, const Standard_Real theY, const Standard_Real theZ)
7fd59977 560{
9764ccbb 561 myView->SetAt (theX, theY, theZ);
7fd59977 562}
563
ee2be2a8 564void COCCDemoView::GetViewEye(Standard_Real& X, Standard_Real& Y, Standard_Real& Z)
7fd59977 565{
566 myView->Eye(X,Y,Z);
567}
568
ee2be2a8 569void COCCDemoView::SetViewEye(Standard_Real X, Standard_Real Y, Standard_Real Z)
7fd59977 570{
571 myView->SetEye(X,Y,Z);
572}
573
ee2be2a8 574Standard_Real COCCDemoView::GetViewScale()
7fd59977 575{
576 return myView->Scale();
577}
578
ee2be2a8 579void COCCDemoView::SetViewScale(Standard_Real Coef)
7fd59977 580{
581 myView->SetScale(Coef);
582}
9764ccbb 583
584void COCCDemoView::Translate (const Standard_Real theX, const Standard_Real theY)
585{
586 myView->Panning (theX, theY);
587}