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