0028895: Visualization, V3d_View::SetComputedMode() - HLR calculation is performed...
[occt.git] / samples / mfc / standard / 09_Animation / src / AnimationView3D.cpp
CommitLineData
7fd59977 1// AnimationView3D.cpp : implementation of the CAnimationView3D class
2//
3
4#include "stdafx.h"
5
6#include "AnimationView3D.h"
7
8#include "AnimationApp.h"
9#include "ShadingDialog.h"
10#include "AnimationDoc.h"
11
12#include "Sensitivity.h"
13
14#ifdef _DEBUG
15//#define new DEBUG_NEW by CasCade
16#undef THIS_FILE
17static char THIS_FILE[] = __FILE__;
18#endif
19static int rotCount = 0;
20
21// for elastic bean selection
22#define ValZWMin 1
23
24
25/////////////////////////////////////////////////////////////////////////////
26// CAnimationView3D
27
28IMPLEMENT_DYNCREATE(CAnimationView3D, CView)
29
30BEGIN_MESSAGE_MAP(CAnimationView3D, CView)
31 //{{AFX_MSG_MAP(CAnimationView3D)
32 ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo)
33 ON_COMMAND(ID_BUTTONBack, OnBUTTONBack)
34 ON_COMMAND(ID_BUTTONBottom, OnBUTTONBottom)
35 ON_COMMAND(ID_BUTTONFront, OnBUTTONFront)
36 ON_COMMAND(ID_BUTTONHlrOff, OnBUTTONHlrOff)
37 ON_COMMAND(ID_BUTTONHlrOn, OnBUTTONHlrOn)
38 ON_COMMAND(ID_BUTTONLeft, OnBUTTONLeft)
39 ON_COMMAND(ID_BUTTONPan, OnBUTTONPan)
40 ON_COMMAND(ID_BUTTONPanGlo, OnBUTTONPanGlo)
41 ON_COMMAND(ID_BUTTONReset, OnBUTTONReset)
42 ON_COMMAND(ID_BUTTONRight, OnBUTTONRight)
43 ON_COMMAND(ID_BUTTONRot, OnBUTTONRot)
44 ON_COMMAND(ID_BUTTONTop, OnBUTTONTop)
45 ON_COMMAND(ID_BUTTONZoomAll, OnBUTTONZoomAll)
46 ON_COMMAND(ID_FILE_EXPORT_IMAGE, OnFileExportImage)
47 ON_WM_SIZE()
48 ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg)
49 ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin)
50 ON_WM_LBUTTONDOWN()
51 ON_WM_LBUTTONUP()
52 ON_WM_MBUTTONDOWN()
53 ON_WM_MBUTTONUP()
54 ON_WM_MOUSEMOVE()
55 ON_WM_RBUTTONDOWN()
56 ON_WM_RBUTTONUP()
57 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOff, OnUpdateBUTTONHlrOff)
58 ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn)
59 ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo)
60 ON_UPDATE_COMMAND_UI(ID_BUTTONPan, OnUpdateBUTTONPan)
61 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomProg, OnUpdateBUTTONZoomProg)
62 ON_UPDATE_COMMAND_UI(ID_BUTTONZoomWin, OnUpdateBUTTONZoomWin)
63 ON_UPDATE_COMMAND_UI(ID_BUTTONRot, OnUpdateBUTTONRot)
64
65 ON_COMMAND(ID_Modify_ChangeBackground , OnChangeBackground)
66 ON_WM_TIMER()
67 ON_COMMAND(ID_STOP, OnStop)
68 ON_COMMAND(ID_RESTART, OnRestart)
69
70 ON_COMMAND(ID_SENSITIVITY, OnSensitivity)
71 ON_COMMAND(ID_BUTTONFly, OnBUTTONFly)
72 ON_COMMAND(ID_BUTTONTurn, OnBUTTONTurn)
73 ON_UPDATE_COMMAND_UI(ID_BUTTONFly, OnUpdateBUTTONFly)
74 ON_UPDATE_COMMAND_UI(ID_BUTTONTurn, OnUpdateBUTTONTurn)
75 ON_COMMAND(ID_VIEW_DISPLAYSTATUS, OnViewDisplaystatus)
76 ON_UPDATE_COMMAND_UI(ID_VIEW_DISPLAYSTATUS, OnUpdateViewDisplaystatus)
77 //}}AFX_MSG_MAP
78// CasCade
79
80END_MESSAGE_MAP()
81
82/////////////////////////////////////////////////////////////////////////////
83// CAnimationView3D construction/destruction
84
85CAnimationView3D::CAnimationView3D()
de75ed09 86: myXmin (0),
87 myYmin (0),
88 myXmax (0),
89 myYmax (0),
90 myCurZoom (0.0),
91 myHlrModeIsOn (Standard_False),
92 myCurrentMode (CurrentAction3d_Nothing),
93 m_FlySens (500.0),
94 m_TurnSens (M_PI / 40.0),
95 m_Pen (NULL)
7fd59977 96{
de75ed09 97 // TODO: add construction code here
7fd59977 98}
99
100CAnimationView3D::~CAnimationView3D()
101{
102 myView->Remove();
103 if (m_Pen) delete m_Pen;
104}
105
106BOOL CAnimationView3D::PreCreateWindow(CREATESTRUCT& cs)
107{
d01ed5fd 108 // TODO: Modify the Window class or styles here by modifying
109 // the CREATESTRUCT cs
110 cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
111 return CView::PreCreateWindow(cs);
7fd59977 112}
113
114/////////////////////////////////////////////////////////////////////////////
115// CAnimationView3D drawing
116
5c573e69 117void CAnimationView3D::OnDraw(CDC* /*pDC*/)
7fd59977 118{
119 CAnimationDoc* pDoc = GetDocument();
120 ASSERT_VALID(pDoc);
121
122 // TODO: add draw code for native data here
123
124 myView->Redraw();
125
126}
127void CAnimationView3D::OnInitialUpdate()
128{
de75ed09 129 CView::OnInitialUpdate();
7fd59977 130
de75ed09 131 // TODO: Add your specialized code here and/or call the base class
132 // myView = GetDocument()->GetViewer()->CreateView();
7fd59977 133
de75ed09 134 Handle(V3d_Viewer) aViewer;
7fd59977 135
de75ed09 136 aViewer = GetDocument()->GetViewer();
de75ed09 137 aViewer->SetDefaultTypeOfView (V3d_PERSPECTIVE);
b5ac8292 138
de75ed09 139 myView = aViewer->CreateView();
7fd59977 140
de75ed09 141 // store for restore state after rotation (witch is in Degenerated mode)
142 myHlrModeIsOn = myView->ComputedMode();
7fd59977 143
de75ed09 144 Handle(WNT_Window) aWNTWindow = new WNT_Window (GetSafeHwnd());
145 myView->SetWindow(aWNTWindow);
146 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
7fd59977 147
de75ed09 148 // store the mode ( nothing , dynamic zooming, dynamic ... )
149 myCurrentMode = CurrentAction3d_Nothing;
150 CFrameWnd* pParentFrm = GetParentFrame();
151 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
7fd59977 152
de75ed09 153 Standard_Integer w=100 , h=100 ; /* Debug Matrox */
154 aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */
155 /* Resize is not supposed to be done on */
156 /* Matrox */
157 /* I suspect another problem elsewhere */
158 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
7fd59977 159
de75ed09 160 m_Tune.Create ( IDD_TUNE , NULL ) ;
161
162 RECT dlgrect;
163 m_Tune.GetWindowRect(&dlgrect);
164 LONG width = dlgrect.right-dlgrect.left;
165 LONG height = dlgrect.bottom-dlgrect.top;
166 RECT MainWndRect;
167 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
168 LONG left = MainWndRect.left+3;
169 LONG top = MainWndRect.top + 112;
170 m_Tune.MoveWindow(left,top,width,height);
7fd59977 171
de75ed09 172 m_Tune.m_pView = this ;
7fd59977 173
de75ed09 174 m_Tune.ShowWindow ( SW_HIDE );
7fd59977 175
de75ed09 176 // store the mode ( nothing , dynamic zooming, dynamic ... )
7fd59977 177
de75ed09 178 myCurrentMode = CurrentAction3d_Nothing;
179
180 ReloadData () ;
7fd59977 181
182}
183
184void CAnimationView3D::DisplayTuneDialog()
185{
186 m_Tune.Create ( IDD_TUNE , NULL ) ;
187
188 RECT dlgrect;
189 m_Tune.GetWindowRect(&dlgrect);
190 LONG width = dlgrect.right-dlgrect.left;
191 LONG height = dlgrect.bottom-dlgrect.top;
192 RECT MainWndRect;
193 AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect);
194 LONG left = MainWndRect.left+3;
195 LONG top = MainWndRect.top + 112;
196 m_Tune.MoveWindow(left,top,width,height);
197
198 m_Tune.m_pView = this ;
199}
200
201
202/////////////////////////////////////////////////////////////////////////////
203// CAnimationView3D diagnostics
204
205#ifdef _DEBUG
206void CAnimationView3D::AssertValid() const
207{
208 CView::AssertValid();
209}
210
211void CAnimationView3D::Dump(CDumpContext& dc) const
212{
213 CView::Dump(dc);
214}
215
216CAnimationDoc* CAnimationView3D::GetDocument() // non-debug version is inline
217{
218 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAnimationDoc)));
219 return (CAnimationDoc*)m_pDocument;
220}
221#endif //_DEBUG
222
223/////////////////////////////////////////////////////////////////////////////
224// CAnimationView3D message handlers
225void CAnimationView3D::OnFileExportImage()
226{
12c76bee 227 GetDocument()->ExportView (myView);
7fd59977 228}
229
d01ed5fd 230void CAnimationView3D::OnSize(UINT nType, int cx, int cy)
7fd59977 231{
d01ed5fd 232 CView::OnSize (nType, cx, cy);
233 m_cx = cx ;
234 m_cy = cy ;
235 if (!myView.IsNull())
236 myView->MustBeResized();
7fd59977 237}
238
239void CAnimationView3D::OnBUTTONBack()
32757c6e 240{ myView->SetProj(V3d_Ypos); } // See the back View
7fd59977 241void CAnimationView3D::OnBUTTONFront()
32757c6e 242{ myView->SetProj(V3d_Yneg); } // See the front View
7fd59977 243
244void CAnimationView3D::OnBUTTONBottom()
245{ myView->SetProj(V3d_Zneg); } // See the bottom View
246void CAnimationView3D::OnBUTTONTop()
247{ myView->SetProj(V3d_Zpos); } // See the top View
248
249void CAnimationView3D::OnBUTTONLeft()
32757c6e 250{ myView->SetProj(V3d_Xneg); } // See the left View
7fd59977 251void CAnimationView3D::OnBUTTONRight()
32757c6e 252{ myView->SetProj(V3d_Xpos); } // See the right View
7fd59977 253
254void CAnimationView3D::OnBUTTONAxo()
255{ myView->SetProj(V3d_XposYnegZpos); } // See the axonometric View
256
257void CAnimationView3D::OnBUTTONHlrOff()
258{
de75ed09 259 myHlrModeIsOn = Standard_False;
260 myView->SetComputedMode (myHlrModeIsOn);
1eeef710 261 myView->Redraw();
7fd59977 262}
263
264void CAnimationView3D::OnBUTTONHlrOn()
265{
266 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
de75ed09 267 myHlrModeIsOn = Standard_True;
268 myView->SetComputedMode (myHlrModeIsOn);
1eeef710 269 myView->Redraw();
7fd59977 270 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
271}
272
273void CAnimationView3D::OnBUTTONPan()
274{
275 myCurrentMode = CurrentAction3d_DynamicPanning;
276}
277
278void CAnimationView3D::OnBUTTONPanGlo()
279{
280 // save the current zoom value
281 myCurZoom = myView->Scale();
282 // Do a Global Zoom
283 myView->FitAll();
284 // Set the mode
285 myCurrentMode = CurrentAction3d_GlobalPanning;
286}
287
288void CAnimationView3D::OnBUTTONReset()
289{ myView->Reset();
290 ReloadData();
291}
292
293void CAnimationView3D::OnBUTTONRot()
294{ myCurrentMode = CurrentAction3d_DynamicRotation; }
295
296
297void CAnimationView3D::OnBUTTONZoomAll()
298{
299 SetDimensions();
300 myView->FitAll();
301 myView->ZFitAll();
302}
303
304void CAnimationView3D::OnBUTTONZoomProg()
305{ myCurrentMode = CurrentAction3d_DynamicZooming; }
306
307void CAnimationView3D::OnBUTTONZoomWin()
308{ myCurrentMode = CurrentAction3d_WindowZooming; }
309
310void CAnimationView3D::OnBUTTONFly()
311{ myCurrentMode = CurrentAction3d_Fly; }
312
313void CAnimationView3D::OnBUTTONTurn()
314{ myCurrentMode = CurrentAction3d_Turn; }
315
316
317void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point)
318{
319 // save the current mouse coordinate in min
320 myXmin=point.x; myYmin=point.y;
321 myXmax=point.x; myYmax=point.y;
322
323 if ( nFlags & MK_CONTROL )
324 {
325 // Button MB1 down Control :start zomming
326 // SetCursor(AfxGetApp()->LoadStandardCursor());
327 }
328 else // if ( Ctrl )
329 {
330 switch (myCurrentMode)
331 {
332 case CurrentAction3d_Nothing : // start a drag
333 if (nFlags & MK_SHIFT)
334 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
335 else
336 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
337 break;
338 break;
339 case CurrentAction3d_DynamicZooming : // noting
340 // SetCursor(AfxGetApp()->LoadStandardCursor());
341 break;
342 case CurrentAction3d_WindowZooming : // noting
343 break;
344 case CurrentAction3d_DynamicPanning :// noting
345 break;
346 case CurrentAction3d_GlobalPanning :// noting
347 break;
348 case CurrentAction3d_DynamicRotation :
de75ed09 349 if (myHlrModeIsOn)
350 {
351 myView->SetComputedMode (Standard_False);
352 }
353 myView->StartRotation (point.x, point.y);
7fd59977 354 break;
355 case CurrentAction3d_Fly :
356 KillTimer (1) ;
357 SetTimer ( 1 , 100 , NULL ) ;
358 break ;
359 case CurrentAction3d_Turn :
360 KillTimer (1) ;
361 SetTimer ( 1 , 100 , NULL ) ;
362 break ;
363 default :
9775fa61 364 throw Standard_Failure(" incompatible Current Mode ");
7fd59977 365 break;
366 }
367 }
368}
369
370void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
371{
372 if ( nFlags & MK_CONTROL )
373 {
374 return;
375 }
376 else // if ( Ctrl )
377 {
378 switch (myCurrentMode)
379 {
380 case CurrentAction3d_Nothing :
381 if (point.x == myXmin && point.y == myYmin)
382 { // no offset between down and up --> selectEvent
383 myXmax=point.x;
384 myYmax=point.y;
385 if (nFlags & MK_SHIFT )
386 GetDocument()->ShiftInputEvent(point.x,point.y,myView);
387 else
388 GetDocument()->InputEvent (point.x,point.y,myView);
389 } else
390 {
391 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
392 myXmax=point.x;
393 myYmax=point.y;
394 if (nFlags & MK_SHIFT)
395 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
396 else
397 GetDocument()->DragEvent(point.x,point.y,1,myView);
398 }
399 break;
400 case CurrentAction3d_DynamicZooming :
401 // SetCursor(AfxGetApp()->LoadStandardCursor());
402 myCurrentMode = CurrentAction3d_Nothing;
403 break;
404 case CurrentAction3d_WindowZooming :
405 myXmax=point.x; myYmax=point.y;
406 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
407 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
408 // Test if the zoom window is greater than a minimale window.
409 {
410 // Do the zoom window between Pmin and Pmax
411 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
412 }
413 myCurrentMode = CurrentAction3d_Nothing;
414 break;
415 case CurrentAction3d_DynamicPanning :
416 myCurrentMode = CurrentAction3d_Nothing;
417 break;
418 case CurrentAction3d_GlobalPanning :
419 myView->Place(point.x,point.y,myCurZoom);
420 myCurrentMode = CurrentAction3d_Nothing;
421 break;
422 case CurrentAction3d_DynamicRotation :
423 myCurrentMode = CurrentAction3d_Nothing;
424 break;
425 case CurrentAction3d_Fly :
426 KillTimer ( 1 ) ;
427 case CurrentAction3d_Turn :
428 KillTimer ( 1 ) ;
429 break;
430 default :
9775fa61 431 throw Standard_Failure(" incompatible Current Mode ");
7fd59977 432 break;
433 } //switch (myCurrentMode)
434 } // else // if ( Ctrl )
435}
436
5c573e69 437void CAnimationView3D::OnMButtonDown(UINT nFlags, CPoint /*point*/)
7fd59977 438{
439 if ( nFlags & MK_CONTROL )
440 {
441 // Button MB2 down Control : panning init
442 // SetCursor(AfxGetApp()->LoadStandardCursor());
443 }
444}
445
5c573e69 446void CAnimationView3D::OnMButtonUp(UINT nFlags, CPoint /*point*/)
7fd59977 447{
448 if ( nFlags & MK_CONTROL )
449 {
450 // Button MB2 down Control : panning init
451 // SetCursor(AfxGetApp()->LoadStandardCursor());
452 }
453}
454
455void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
456{
de75ed09 457 if ( nFlags & MK_CONTROL )
458 {
459 // SetCursor(AfxGetApp()->LoadStandardCursor());
460 if (myHlrModeIsOn)
461 {
462 myView->SetComputedMode (Standard_False);
463 }
464 myView->StartRotation (point.x, point.y);
465 }
466 else // if ( Ctrl )
467 {
468 GetDocument()->Popup(point.x,point.y,myView);
469 }
7fd59977 470}
471
5c573e69 472void CAnimationView3D::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/)
7fd59977 473{
474 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
1eeef710 475 if (myHlrModeIsOn)
476 {
477 myView->SetComputedMode (myHlrModeIsOn);
478 myView->Redraw();
479 }
7fd59977 480 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
481}
482
483void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
484{
485 // ============================ LEFT BUTTON =======================
486 m_curx = point.x ;
487 m_cury = point.y ;
488
489 if ( nFlags & MK_LBUTTON)
490 {
491 if ( nFlags & MK_CONTROL )
492 {
493 // move with MB1 and Control : on the dynamic zooming
494 // Do the zoom in function of mouse's coordinates
495 myView->Zoom(myXmax,myYmax,point.x,point.y);
496 // save the current mouse coordinate in min
497 myXmax = point.x;
498 myYmax = point.y;
499 }
500 else // if ( Ctrl )
501 {
502 switch (myCurrentMode)
503 {
504 case CurrentAction3d_Nothing :
505 myXmax = point.x; myYmax = point.y;
506 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
507 if (nFlags & MK_SHIFT)
508 GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
509 else
510 GetDocument()->DragEvent(myXmax,myYmax,0,myView);
511 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
512 break;
513 case CurrentAction3d_DynamicZooming :
514 myView->Zoom(myXmax,myYmax,point.x,point.y);
515 // save the current mouse coordinate in min \n";
516 myXmax=point.x; myYmax=point.y;
517 break;
518 case CurrentAction3d_WindowZooming :
519 myXmax = point.x; myYmax = point.y;
520 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash);
521 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
522 break;
523 case CurrentAction3d_DynamicPanning :
524 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
525 myXmax = point.x; myYmax = point.y;
526 break;
527 case CurrentAction3d_GlobalPanning : // nothing
528 break;
529 case CurrentAction3d_DynamicRotation :
530 myView->Rotation(point.x,point.y);
531 myView->Redraw();
532 break;
533 case CurrentAction3d_Fly :
534 break ;
535 case CurrentAction3d_Turn :
536 break ;
537 default :
9775fa61 538 throw Standard_Failure(" incompatible Current Mode ");
7fd59977 539 break;
540 }// switch (myCurrentMode)
541 }// if ( nFlags & MK_CONTROL ) else
542 } else // if ( nFlags & MK_LBUTTON)
543 // ============================ MIDDLE BUTTON =======================
544 if ( nFlags & MK_MBUTTON)
545 {
546 if ( nFlags & MK_CONTROL )
547 {
548 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
549 myXmax = point.x; myYmax = point.y;
550
551 }
552 } else // if ( nFlags & MK_MBUTTON)
553 // ============================ RIGHT BUTTON =======================
554 if ( nFlags & MK_RBUTTON)
555 {
556 if ( nFlags & MK_CONTROL )
557 {
558 rotCount++;
559 myView->Rotation(point.x,point.y);
560 }
561 }else //if ( nFlags & MK_RBUTTON)
562 // ============================ NO BUTTON =======================
563 { // No buttons
564 myXmax = point.x; myYmax = point.y;
565 if (nFlags & MK_SHIFT)
566 GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
567 else
568 GetDocument()->MoveEvent(point.x,point.y,myView);
569 }
570}
571
572void CAnimationView3D::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
573{
de75ed09 574 pCmdUI->SetCheck (!myHlrModeIsOn);
575 pCmdUI->Enable (myHlrModeIsOn);
7fd59977 576}
577
578void CAnimationView3D::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
579{
de75ed09 580 pCmdUI->SetCheck (myHlrModeIsOn);
581 pCmdUI->Enable (!myHlrModeIsOn);
7fd59977 582}
583
584void CAnimationView3D::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
585{
586 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_GlobalPanning);
587 pCmdUI->Enable (myCurrentMode != CurrentAction3d_GlobalPanning);
588
589}
590
591void CAnimationView3D::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
592{
593 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicPanning);
594 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicPanning );
595}
596
597void CAnimationView3D::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
598{
599 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicZooming );
600 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicZooming);
601}
602
603void CAnimationView3D::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
604{
605 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_WindowZooming);
606 pCmdUI->Enable (myCurrentMode != CurrentAction3d_WindowZooming);
607}
608
609void CAnimationView3D::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
610{
611 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicRotation);
612 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicRotation);
613}
614
615void CAnimationView3D::OnUpdateBUTTONFly(CCmdUI* pCmdUI)
616{
617 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
618 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Fly);
619}
620
621void CAnimationView3D::OnUpdateBUTTONTurn(CCmdUI* pCmdUI)
622{
623 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
624 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Turn);
625}
626
627void CAnimationView3D::OnChangeBackground()
628{
629 Standard_Real R1;
630 Standard_Real G1;
631 Standard_Real B1;
632 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
633 COLORREF m_clr ;
634 m_clr = RGB(R1*255,G1*255,B1*255);
635
636 CColorDialog dlgColor(m_clr);
637 if (dlgColor.DoModal() == IDOK)
638 {
639 m_clr = dlgColor.GetColor();
640 R1 = GetRValue(m_clr)/255.;
641 G1 = GetGValue(m_clr)/255.;
642 B1 = GetBValue(m_clr)/255.;
643 myView->SetBackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
644 }
645 myView->Redraw();
646}
647
648//==========================================================================================
649//==========================================================================================
650//==========================================================================================
651
652//-----------------------------------------------------------------------------------------
653//
654//-----------------------------------------------------------------------------------------
655void CAnimationView3D::DrawRectangle(const Standard_Integer MinX ,
656 const Standard_Integer MinY ,
657 const Standard_Integer MaxX ,
658 const Standard_Integer MaxY ,
659 const Standard_Boolean Draw ,
660 const LineStyle aLineStyle)
661{
662 static int m_DrawMode;
663 if (!m_Pen && aLineStyle ==Solid )
664 {m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;}
665 else if (!m_Pen && aLineStyle ==Dot )
666 {m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;}
667 else if (!m_Pen && aLineStyle == ShortDash)
668 {m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;}
669 else if (!m_Pen && aLineStyle == LongDash)
670 {m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;}
671 else if (aLineStyle == Default)
672 { m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
673
5c573e69 674 CPen* aOldPen = NULL;
7fd59977 675 CClientDC clientDC(this);
676 if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen);
677 clientDC.SetROP2(m_DrawMode);
678
679 static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
680 static Standard_Boolean m_IsVisible;
681
682 if ( m_IsVisible && !Draw) // move or up : erase at the old position
683 {
684 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
685 clientDC.LineTo(StoredMaxX,StoredMaxY);
686 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
687 m_IsVisible = false;
688 }
689
f751596e 690 StoredMinX = Min ( MinX, MaxX );
691 StoredMinY = Min ( MinY, MaxY );
692 StoredMaxX = Max ( MinX, MaxX );
693 StoredMaxY = Max ( MinY, MaxY);
7fd59977 694
695 if (Draw) // move : draw
696 {
697 clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
698 clientDC.LineTo(StoredMaxX,StoredMaxY);
699 clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
700 m_IsVisible = true;
701 }
702
703 if (m_Pen)
704 clientDC.SelectObject(aOldPen);
705}
706void CAnimationView3D::OnStop()
707{
708 KillTimer(GetDocument()->myCount);
709}
710
711void CAnimationView3D::OnRestart()
712{
713 KillTimer(GetDocument()->myCount);
714 SetTimer(GetDocument()->myCount, 1 , NULL);
715}
716
717/*
718void CAnimationView3D::OnTimer(UINT nIDEvent)
719{
720 // TODO: Add your message handler code here and/or call default
721 GetDocument()->OnMyTimer();
722 CView::OnTimer(nIDEvent);
723}
724*/
725
726
727/*********************************************************************************
728************** W A L K T H R O U G H ******************************************
729/********************************************************************************/
730
731void CAnimationView3D::OnTimer(UINT_PTR nIDEvent)
732{
733 if ( !GetDocument()->m_bIsGridLoaded )
734 {
735 // TODO: Add your message handler code here and/or call default
736 GetDocument()->OnMyTimer();
737 CView::OnTimer(nIDEvent);
738 }
739 else
740 {
741 CView::OnTimer(nIDEvent);
742 if ( nIDEvent == 1 ) {
743 myView->SetImmediateUpdate ( Standard_False ) ;
744 if ( myCurrentMode == CurrentAction3d_Fly ) {
745
746 Fly ( m_curx , m_cury ) ;
747 if ( m_bShift )
748 Roll ( m_curx , m_cury ) ;
749 else
750 Turn ( m_curx , m_cury ) ;
751
752 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
753 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
754
755 }
756 else if ( myCurrentMode == CurrentAction3d_Turn ) {
757 Twist ( m_curx , m_cury ) ;
758 }
759 else
760 KillTimer (1) ;
761
762
763 myView->SetImmediateUpdate ( Standard_True ) ;
764
765 myView->Update ();
766 }
767
768 ReloadData () ;
769 }
770}
771
772void CAnimationView3D::OnSensitivity()
773{
774 CSensitivity dial ;
775
776 dial.m_SensFly = m_FlySens ;
777 dial.m_SensTurn = m_TurnSens ;
778 if ( dial.DoModal () ) {
779 m_FlySens = dial.m_SensFly ;
780 m_TurnSens = dial.m_SensTurn ;
781 }
782}
783
5c573e69 784void CAnimationView3D::Fly (int /*x*/ , int y)
7fd59977 785{
786 double v [3] ;
787 double l ;
788 double sens ;
789 int i ;
790
791 sens = (double) myYmin - (double) y ;
792 sens /= (double) m_cy ;
793 sens *= m_FlySens ;
794
795 v [0] = m_Atx - m_Eyex ;
796 v [1] = m_Aty - m_Eyey ;
797 v [2] = m_Atz - m_Eyez ;
798 l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ;
799 if ( l > 1.e-3 ) {
800 for ( i=0 ; i<3 ; i++ )
801 v [i] = v [i] / l * sens ;
802
803 m_Atx += v [0] ;
804 m_Aty += v [1] ;
805 m_Atz += v [2] ;
806
807 m_Eyex += v [0] ;
808 m_Eyey += v [1] ;
809 m_Eyez += v [2] ;
810
811 }
812}
813
814/* Rotation */
815
5c573e69 816void CAnimationView3D::Turn (int x , int /*y*/)
7fd59977 817{
818 gp_Vec z (0.,0.,1.) ;
819
820 double v [3] ;
821 double sens ;
822 double aX , aY , aZ ;
823
824 sens = (double) x - (double) myXmin ;
825 sens /= (double) m_cx ;
826 sens *= m_TurnSens ;
827
828 v [0] = m_Atx - m_Eyex ;
829 v [1] = m_Aty - m_Eyey ;
830 v [2] = m_Atz - m_Eyez ;
831
832 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
833
834 gp_Vec reg (v[0],v[1],v[2] );
835
836 gp_Vec vert = reg ^ z ;
837 gp_Vec haut = vert ^ reg ;
838
839 gp_Dir dh (haut) ;
840 gp_Ax1 rot (eye,dh);
841
842 reg.Rotate (rot,sens) ;
843
844 reg.Coord ( aX , aY , aZ ) ;
845
846 m_Atx = m_Eyex + aX ;
847 m_Aty = m_Eyey + aY ;
848 m_Atz = m_Eyez + aZ ;
849}
850
5c573e69 851void CAnimationView3D::Roll (int x , int /*y*/)
7fd59977 852{
853 gp_Vec z (0.,0.,1.) ;
854
855 double v [3] ;
856 double sens ;
857 double aX , aY , aZ ;
858
859 sens = (double) x - (double) myXmin ;
860 sens /= (double) m_cx ;
861 sens *= m_TurnSens ;
862
863 v [0] = m_Atx - m_Eyex ;
864 v [1] = m_Aty - m_Eyey ;
865 v [2] = m_Atz - m_Eyez ;
866
867 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
868
869 gp_Vec reg (v[0],v[1],v[2] );
870
871 gp_Vec vert = reg ^ z ;
872
873 gp_Dir dh (vert) ;
874 gp_Ax1 rot (eye,dh);
875
876 reg.Rotate (rot,sens) ;
877
878 reg.Coord ( aX , aY , aZ ) ;
879
880 m_Atx = m_Eyex + aX ;
881 m_Aty = m_Eyey + aY ;
882 m_Atz = m_Eyez + aZ ;
883}
884
5c573e69 885void CAnimationView3D::Twist (int x , int /*y*/)
7fd59977 886{
887 double sens ;
888 double a ;
889
890 a = myView->Twist () ;
891
892 sens = (double) x - (double) myXmin ;
893 sens /= (double) m_cx ;
894 sens *= m_TurnSens ;
895
896 a += sens ;
897
898 myView->SetTwist (a) ;
899}
900
b5ac8292 901//=============================================================================
902// function: SetFocal
903// purpose:
904//=============================================================================
905void CAnimationView3D::SetFocal (double theFocus, double theAngle)
7fd59977 906{
7fd59977 907
b5ac8292 908 Handle(Graphic3d_Camera) aCamera = myView->Camera();
7fd59977 909
b5ac8292 910 gp_Pnt anAt = aCamera->Center();
911 gp_Pnt anEye = aCamera->Eye();
7fd59977 912
b5ac8292 913 gp_Vec aLook (anAt, anEye);
7fd59977 914
b5ac8292 915 if (aCamera->Distance() > 1.e-3)
916 {
917 aLook = aLook / aCamera->Distance() * theFocus;
7fd59977 918
b5ac8292 919 m_Focus = theFocus;
7fd59977 920
b5ac8292 921 anAt.SetX (aLook.X() + anEye.X());
922 anAt.SetY (aLook.Y() + anEye.Y());
923 anAt.SetZ (aLook.Z() + anEye.Z());
924
925 m_dAngle = theAngle;
926
927 aCamera->SetCenter (anAt);
928 aCamera->SetFOVy (theAngle);
929
930 myView->Update();
931 }
7fd59977 932}
933
934void CAnimationView3D::ReloadData()
935{
7fd59977 936 myView->At ( m_Atx , m_Aty , m_Atz ) ;
937 myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ;
576f8b11 938 double dTwist = myView->Twist() * 180. / M_PI;
939
940 CString aMsg;
941 aMsg.Format (L"%lf", m_Atx);
942 m_Tune.GetDlgItem (IDC_XAT)->SetWindowText (aMsg);
943 aMsg.Format (L"%lf", m_Aty);
944 m_Tune.GetDlgItem (IDC_YAT)->SetWindowText (aMsg);
945 aMsg.Format (L"%lf", m_Atz);
946 m_Tune.GetDlgItem (IDC_ZAT)->SetWindowText (aMsg);
947
948 aMsg.Format (L"%lf", m_Eyex);
949 m_Tune.GetDlgItem (IDC_XEYE)->SetWindowText (aMsg);
950 aMsg.Format (L"%lf", m_Eyey);
951 m_Tune.GetDlgItem (IDC_YEYE)->SetWindowText (aMsg);
952 aMsg.Format (L"%lf", m_Eyez);
953 m_Tune.GetDlgItem (IDC_ZEYE)->SetWindowText (aMsg);
954
955 aMsg.Format (L"%lf", dTwist);
956 m_Tune.GetDlgItem (IDC_TWIST)->SetWindowText (aMsg);
7fd59977 957
958 double dx,dy,dz ;
959 dx = m_Atx - m_Eyex ;
960 dy = m_Aty - m_Eyey ;
961 dz = m_Atz - m_Eyez ;
962
b5ac8292 963 m_Focus = sqrt (dx * dx + dy * dy + dz * dz);
964
965 m_dAngle = myView->Camera()->FOVy();
7fd59977 966
967 m_Tune.m_dAngle = m_dAngle ;
968 m_Tune.m_dFocus = m_Focus ;
969 m_Tune.UpdateData ( FALSE ) ;
970}
971
972void CAnimationView3D::SetDimensions()
973{
974
975 CAnimationDoc* pDoc = GetDocument();
976
977 myView->SetImmediateUpdate ( Standard_False ) ;
978
979 m_Atx = ( pDoc->m_Xmin + pDoc->m_Xmax ) / 2. ;
980 m_Aty = ( pDoc->m_Ymin + pDoc->m_Ymax ) / 2. ;
981 m_Atz = ( pDoc->m_Zmin + pDoc->m_Zmax ) / 2. ;
982 m_Eyex = pDoc->m_Xmax ;
983 m_Eyey = pDoc->m_Ymax ;
984 m_Eyez = pDoc->m_Zmax ;
985
986 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
987 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
988 myView->SetTwist (0.) ;
989
990 myView->SetImmediateUpdate ( Standard_False ) ;
991 myView->FitAll();
992 myView->SetImmediateUpdate ( Standard_False ) ;
993 myView->ZFitAll();
994
995 myView->SetImmediateUpdate ( Standard_True ) ;
996
997 ReloadData () ;
998 myView->Update ();
999}
1000
1001void CAnimationView3D::OnViewDisplaystatus()
1002{
1003 // TODO: Add your command handler code here
1004
1005 if ( m_Tune.IsWindowVisible () ) {
1006
1007 }
1008 else {
1009 m_Tune.ShowWindow ( SW_SHOWNORMAL ) ;
1010 }
1011}
1012
1013void CAnimationView3D::OnUpdateViewDisplaystatus(CCmdUI* pCmdUI)
1014{
1015 // TODO: Add your command update UI handler code here
1016
1017 if ( m_Tune.IsWindowVisible () ) {
1018 pCmdUI->SetCheck ( 1 ) ;
1019 }
1020 else {
1021 pCmdUI->SetCheck ( 0 ) ;
1022 }
42e4630c 1023}