1 // AnimationView3D.cpp : implementation of the CAnimationView3D class
6 #include "AnimationView3D.h"
8 #include "AnimationApp.h"
9 #include "ShadingDialog.h"
10 #include "AnimationDoc.h"
12 #include "Sensitivity.h"
14 #include <AIS_RubberBand.hxx>
17 //#define new DEBUG_NEW by CasCade
19 static char THIS_FILE[] = __FILE__;
21 static int rotCount = 0;
23 // for elastic bean selection
27 /////////////////////////////////////////////////////////////////////////////
30 IMPLEMENT_DYNCREATE(CAnimationView3D, CView)
32 BEGIN_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)
50 ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg)
51 ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin)
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)
67 ON_COMMAND(ID_Modify_ChangeBackground , OnChangeBackground)
69 ON_COMMAND(ID_STOP, OnStop)
70 ON_COMMAND(ID_RESTART, OnRestart)
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)
84 /////////////////////////////////////////////////////////////////////////////
85 // CAnimationView3D construction/destruction
87 CAnimationView3D::CAnimationView3D()
93 myHlrModeIsOn (Standard_False),
94 myCurrentMode (CurrentAction3d_Nothing),
96 m_TurnSens (M_PI / 40.0),
97 myRect (new AIS_RubberBand (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0))
99 // TODO: add construction code here
102 CAnimationView3D::~CAnimationView3D()
107 BOOL CAnimationView3D::PreCreateWindow(CREATESTRUCT& cs)
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);
115 /////////////////////////////////////////////////////////////////////////////
116 // CAnimationView3D drawing
118 void CAnimationView3D::OnDraw(CDC* /*pDC*/)
120 CAnimationDoc* pDoc = GetDocument();
123 // TODO: add draw code for native data here
128 void CAnimationView3D::OnInitialUpdate()
130 CView::OnInitialUpdate();
132 // TODO: Add your specialized code here and/or call the base class
133 // myView = GetDocument()->GetViewer()->CreateView();
135 Handle(V3d_Viewer) aViewer;
137 aViewer = GetDocument()->GetViewer();
138 aViewer->SetDefaultTypeOfView (V3d_PERSPECTIVE);
140 myView = aViewer->CreateView();
142 // store for restore state after rotation (witch is in Degenerated mode)
143 myHlrModeIsOn = myView->ComputedMode();
145 Handle(WNT_Window) aWNTWindow = new WNT_Window (GetSafeHwnd());
146 myView->SetWindow(aWNTWindow);
147 if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
149 // store the mode ( nothing , dynamic zooming, dynamic ... )
150 myCurrentMode = CurrentAction3d_Nothing;
151 CFrameWnd* pParentFrm = GetParentFrame();
152 pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED);
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 */
158 /* I suspect another problem elsewhere */
159 ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ;
161 m_Tune.Create ( IDD_TUNE , NULL ) ;
164 m_Tune.GetWindowRect(&dlgrect);
165 LONG width = dlgrect.right-dlgrect.left;
166 LONG height = dlgrect.bottom-dlgrect.top;
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);
173 m_Tune.m_pView = this ;
175 m_Tune.ShowWindow ( SW_HIDE );
177 // store the mode ( nothing , dynamic zooming, dynamic ... )
179 myCurrentMode = CurrentAction3d_Nothing;
185 void CAnimationView3D::DisplayTuneDialog()
187 m_Tune.Create ( IDD_TUNE , NULL ) ;
190 m_Tune.GetWindowRect(&dlgrect);
191 LONG width = dlgrect.right-dlgrect.left;
192 LONG height = dlgrect.bottom-dlgrect.top;
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);
199 m_Tune.m_pView = this ;
203 /////////////////////////////////////////////////////////////////////////////
204 // CAnimationView3D diagnostics
207 void CAnimationView3D::AssertValid() const
209 CView::AssertValid();
212 void CAnimationView3D::Dump(CDumpContext& dc) const
217 CAnimationDoc* CAnimationView3D::GetDocument() // non-debug version is inline
219 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAnimationDoc)));
220 return (CAnimationDoc*)m_pDocument;
224 /////////////////////////////////////////////////////////////////////////////
225 // CAnimationView3D message handlers
226 void CAnimationView3D::OnFileExportImage()
228 GetDocument()->ExportView (myView);
231 void CAnimationView3D::OnSize(UINT nType, int cx, int cy)
233 CView::OnSize (nType, cx, cy);
236 if (!myView.IsNull())
237 myView->MustBeResized();
240 void CAnimationView3D::OnBUTTONBack()
241 { myView->SetProj(V3d_Ypos); } // See the back View
242 void CAnimationView3D::OnBUTTONFront()
243 { myView->SetProj(V3d_Yneg); } // See the front View
245 void CAnimationView3D::OnBUTTONBottom()
246 { myView->SetProj(V3d_Zneg); } // See the bottom View
247 void CAnimationView3D::OnBUTTONTop()
248 { myView->SetProj(V3d_Zpos); } // See the top View
250 void CAnimationView3D::OnBUTTONLeft()
251 { myView->SetProj(V3d_Xneg); } // See the left View
252 void CAnimationView3D::OnBUTTONRight()
253 { myView->SetProj(V3d_Xpos); } // See the right View
255 void CAnimationView3D::OnBUTTONAxo()
256 { myView->SetProj(V3d_XposYnegZpos); } // See the axonometric View
258 void CAnimationView3D::OnBUTTONHlrOff()
260 myHlrModeIsOn = Standard_False;
261 myView->SetComputedMode (myHlrModeIsOn);
265 void CAnimationView3D::OnBUTTONHlrOn()
267 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
268 myHlrModeIsOn = Standard_True;
269 myView->SetComputedMode (myHlrModeIsOn);
271 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
274 void CAnimationView3D::OnBUTTONPan()
276 myCurrentMode = CurrentAction3d_DynamicPanning;
279 void CAnimationView3D::OnBUTTONPanGlo()
281 // save the current zoom value
282 myCurZoom = myView->Scale();
286 myCurrentMode = CurrentAction3d_GlobalPanning;
289 void CAnimationView3D::OnBUTTONReset()
294 void CAnimationView3D::OnBUTTONRot()
295 { myCurrentMode = CurrentAction3d_DynamicRotation; }
298 void CAnimationView3D::OnBUTTONZoomAll()
305 void CAnimationView3D::OnBUTTONZoomProg()
306 { myCurrentMode = CurrentAction3d_DynamicZooming; }
308 void CAnimationView3D::OnBUTTONZoomWin()
309 { myCurrentMode = CurrentAction3d_WindowZooming; }
311 void CAnimationView3D::OnBUTTONFly()
312 { myCurrentMode = CurrentAction3d_Fly; }
314 void CAnimationView3D::OnBUTTONTurn()
315 { myCurrentMode = CurrentAction3d_Turn; }
318 void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point)
320 // save the current mouse coordinate in min
321 myXmin=point.x; myYmin=point.y;
322 myXmax=point.x; myYmax=point.y;
324 if ( nFlags & MK_CONTROL )
326 // Button MB1 down Control :start zomming
327 // SetCursor(AfxGetApp()->LoadStandardCursor());
331 switch (myCurrentMode)
333 case CurrentAction3d_Nothing : // start a drag
334 if (nFlags & MK_SHIFT)
335 GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
337 GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
340 case CurrentAction3d_DynamicZooming : // noting
341 // SetCursor(AfxGetApp()->LoadStandardCursor());
343 case CurrentAction3d_WindowZooming : // noting
345 case CurrentAction3d_DynamicPanning :// noting
347 case CurrentAction3d_GlobalPanning :// noting
349 case CurrentAction3d_DynamicRotation :
352 myView->SetComputedMode (Standard_False);
354 myView->StartRotation (point.x, point.y);
356 case CurrentAction3d_Fly :
358 SetTimer ( 1 , 100 , NULL ) ;
360 case CurrentAction3d_Turn :
362 SetTimer ( 1 , 100 , NULL ) ;
365 throw Standard_Failure(" incompatible Current Mode ");
371 void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
373 if ( nFlags & MK_CONTROL )
379 switch (myCurrentMode)
381 case CurrentAction3d_Nothing :
382 if (point.x == myXmin && point.y == myYmin)
383 { // no offset between down and up --> selectEvent
386 if (nFlags & MK_SHIFT )
387 GetDocument()->ShiftInputEvent(point.x,point.y,myView);
389 GetDocument()->InputEvent (point.x,point.y,myView);
392 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
395 if (nFlags & MK_SHIFT)
396 GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
398 GetDocument()->DragEvent(point.x,point.y,1,myView);
401 case CurrentAction3d_DynamicZooming :
402 // SetCursor(AfxGetApp()->LoadStandardCursor());
403 myCurrentMode = CurrentAction3d_Nothing;
405 case CurrentAction3d_WindowZooming :
406 myXmax=point.x; myYmax=point.y;
407 DrawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_False, Aspect_TOL_DASH);
408 if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
409 // Test if the zoom window is greater than a minimale window.
411 // Do the zoom window between Pmin and Pmax
412 myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax);
414 myCurrentMode = CurrentAction3d_Nothing;
416 case CurrentAction3d_DynamicPanning :
417 myCurrentMode = CurrentAction3d_Nothing;
419 case CurrentAction3d_GlobalPanning :
420 myView->Place(point.x,point.y,myCurZoom);
421 myCurrentMode = CurrentAction3d_Nothing;
423 case CurrentAction3d_DynamicRotation :
424 myCurrentMode = CurrentAction3d_Nothing;
426 case CurrentAction3d_Fly :
428 case CurrentAction3d_Turn :
432 throw Standard_Failure(" incompatible Current Mode ");
434 } //switch (myCurrentMode)
435 } // else // if ( Ctrl )
438 void CAnimationView3D::OnMButtonDown(UINT nFlags, CPoint /*point*/)
440 if ( nFlags & MK_CONTROL )
442 // Button MB2 down Control : panning init
443 // SetCursor(AfxGetApp()->LoadStandardCursor());
447 void CAnimationView3D::OnMButtonUp(UINT nFlags, CPoint /*point*/)
449 if ( nFlags & MK_CONTROL )
451 // Button MB2 down Control : panning init
452 // SetCursor(AfxGetApp()->LoadStandardCursor());
456 void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point)
458 if ( nFlags & MK_CONTROL )
460 // SetCursor(AfxGetApp()->LoadStandardCursor());
463 myView->SetComputedMode (Standard_False);
465 myView->StartRotation (point.x, point.y);
469 GetDocument()->Popup(point.x,point.y,myView);
473 void CAnimationView3D::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/)
475 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
478 myView->SetComputedMode (myHlrModeIsOn);
481 SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
484 void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
486 // ============================ LEFT BUTTON =======================
490 if ( nFlags & MK_LBUTTON)
492 if ( nFlags & MK_CONTROL )
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
503 switch (myCurrentMode)
505 case CurrentAction3d_Nothing :
506 myXmax = point.x; myYmax = point.y;
507 if (nFlags & MK_SHIFT)
508 GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
510 GetDocument()->DragEvent(myXmax,myYmax,0,myView);
511 DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True);
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;
518 case CurrentAction3d_WindowZooming :
519 myXmax = point.x; myYmax = point.y;
520 DrawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_True, Aspect_TOL_DASH);
522 case CurrentAction3d_DynamicPanning :
523 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
524 myXmax = point.x; myYmax = point.y;
526 case CurrentAction3d_GlobalPanning : // nothing
528 case CurrentAction3d_DynamicRotation :
529 myView->Rotation(point.x,point.y);
532 case CurrentAction3d_Fly :
534 case CurrentAction3d_Turn :
537 throw Standard_Failure(" incompatible Current Mode ");
539 }// switch (myCurrentMode)
540 }// if ( nFlags & MK_CONTROL ) else
541 } else // if ( nFlags & MK_LBUTTON)
542 // ============================ MIDDLE BUTTON =======================
543 if ( nFlags & MK_MBUTTON)
545 if ( nFlags & MK_CONTROL )
547 myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
548 myXmax = point.x; myYmax = point.y;
551 } else // if ( nFlags & MK_MBUTTON)
552 // ============================ RIGHT BUTTON =======================
553 if ( nFlags & MK_RBUTTON)
555 if ( nFlags & MK_CONTROL )
558 myView->Rotation(point.x,point.y);
560 }else //if ( nFlags & MK_RBUTTON)
561 // ============================ NO BUTTON =======================
563 myXmax = point.x; myYmax = point.y;
564 if (nFlags & MK_SHIFT)
565 GetDocument()->ShiftMoveEvent(point.x,point.y,myView);
567 GetDocument()->MoveEvent(point.x,point.y,myView);
571 void CAnimationView3D::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
573 pCmdUI->SetCheck (!myHlrModeIsOn);
574 pCmdUI->Enable (myHlrModeIsOn);
577 void CAnimationView3D::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
579 pCmdUI->SetCheck (myHlrModeIsOn);
580 pCmdUI->Enable (!myHlrModeIsOn);
583 void CAnimationView3D::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
585 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_GlobalPanning);
586 pCmdUI->Enable (myCurrentMode != CurrentAction3d_GlobalPanning);
590 void CAnimationView3D::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
592 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicPanning);
593 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicPanning );
596 void CAnimationView3D::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
598 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicZooming );
599 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicZooming);
602 void CAnimationView3D::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
604 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_WindowZooming);
605 pCmdUI->Enable (myCurrentMode != CurrentAction3d_WindowZooming);
608 void CAnimationView3D::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
610 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_DynamicRotation);
611 pCmdUI->Enable (myCurrentMode != CurrentAction3d_DynamicRotation);
614 void CAnimationView3D::OnUpdateBUTTONFly(CCmdUI* pCmdUI)
616 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
617 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Fly);
620 void CAnimationView3D::OnUpdateBUTTONTurn(CCmdUI* pCmdUI)
622 pCmdUI->Enable(GetDocument()->m_bIsGridLoaded);
623 pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Turn);
626 void CAnimationView3D::OnChangeBackground()
631 myView->BackgroundColor(Quantity_TOC_RGB,R1,G1,B1);
633 m_clr = RGB(R1*255,G1*255,B1*255);
635 CColorDialog dlgColor(m_clr);
636 if (dlgColor.DoModal() == IDOK)
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);
647 //==========================================================================================
648 //==========================================================================================
649 //==========================================================================================
651 //-----------------------------------------------------------------------------------------
653 //-----------------------------------------------------------------------------------------
654 void 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)
661 const Handle(AIS_InteractiveContext)& aCtx = GetDocument()->GetAISContext();
664 aCtx->Remove (myRect, false);
665 aCtx->CurrentViewer()->RedrawImmediate();
670 GetWindowRect (aRect);
671 myRect->SetLineType (theLineType);
672 myRect->SetRectangle (theMinX, aRect.Height() - theMinY, theMaxX, aRect.Height() - theMaxY);
673 if (!aCtx->IsDisplayed (myRect))
675 aCtx->Display (myRect, false);
679 aCtx->Redisplay (myRect, false);
681 aCtx->CurrentViewer()->RedrawImmediate();
684 void CAnimationView3D::OnStop()
686 KillTimer(GetDocument()->myCount);
689 void CAnimationView3D::OnRestart()
691 KillTimer(GetDocument()->myCount);
692 SetTimer(GetDocument()->myCount, 1 , NULL);
696 void CAnimationView3D::OnTimer(UINT nIDEvent)
698 // TODO: Add your message handler code here and/or call default
699 GetDocument()->OnMyTimer();
700 CView::OnTimer(nIDEvent);
705 /*********************************************************************************
706 ************** W A L K T H R O U G H ******************************************
707 /********************************************************************************/
709 void CAnimationView3D::OnTimer(UINT_PTR nIDEvent)
711 if ( !GetDocument()->m_bIsGridLoaded )
713 // TODO: Add your message handler code here and/or call default
714 GetDocument()->OnMyTimer();
715 CView::OnTimer(nIDEvent);
719 CView::OnTimer(nIDEvent);
720 if ( nIDEvent == 1 ) {
721 myView->SetImmediateUpdate ( Standard_False ) ;
722 if ( myCurrentMode == CurrentAction3d_Fly ) {
724 Fly ( m_curx , m_cury ) ;
726 Roll ( m_curx , m_cury ) ;
728 Turn ( m_curx , m_cury ) ;
730 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
731 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
734 else if ( myCurrentMode == CurrentAction3d_Turn ) {
735 Twist ( m_curx , m_cury ) ;
741 myView->SetImmediateUpdate ( Standard_True ) ;
750 void CAnimationView3D::OnSensitivity()
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 ;
762 void CAnimationView3D::Fly (int /*x*/ , int y)
769 sens = (double) myYmin - (double) y ;
770 sens /= (double) m_cy ;
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] ) ;
778 for ( i=0 ; i<3 ; i++ )
779 v [i] = v [i] / l * sens ;
794 void CAnimationView3D::Turn (int x , int /*y*/)
796 gp_Vec z (0.,0.,1.) ;
800 double aX , aY , aZ ;
802 sens = (double) x - (double) myXmin ;
803 sens /= (double) m_cx ;
806 v [0] = m_Atx - m_Eyex ;
807 v [1] = m_Aty - m_Eyey ;
808 v [2] = m_Atz - m_Eyez ;
810 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
812 gp_Vec reg (v[0],v[1],v[2] );
814 gp_Vec vert = reg ^ z ;
815 gp_Vec haut = vert ^ reg ;
820 reg.Rotate (rot,sens) ;
822 reg.Coord ( aX , aY , aZ ) ;
824 m_Atx = m_Eyex + aX ;
825 m_Aty = m_Eyey + aY ;
826 m_Atz = m_Eyez + aZ ;
829 void CAnimationView3D::Roll (int x , int /*y*/)
831 gp_Vec z (0.,0.,1.) ;
835 double aX , aY , aZ ;
837 sens = (double) x - (double) myXmin ;
838 sens /= (double) m_cx ;
841 v [0] = m_Atx - m_Eyex ;
842 v [1] = m_Aty - m_Eyey ;
843 v [2] = m_Atz - m_Eyez ;
845 gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ;
847 gp_Vec reg (v[0],v[1],v[2] );
849 gp_Vec vert = reg ^ z ;
854 reg.Rotate (rot,sens) ;
856 reg.Coord ( aX , aY , aZ ) ;
858 m_Atx = m_Eyex + aX ;
859 m_Aty = m_Eyey + aY ;
860 m_Atz = m_Eyez + aZ ;
863 void CAnimationView3D::Twist (int x , int /*y*/)
868 a = myView->Twist () ;
870 sens = (double) x - (double) myXmin ;
871 sens /= (double) m_cx ;
876 myView->SetTwist (a) ;
879 //=============================================================================
880 // function: SetFocal
882 //=============================================================================
883 void CAnimationView3D::SetFocal (double theFocus, double theAngle)
886 Handle(Graphic3d_Camera) aCamera = myView->Camera();
888 gp_Pnt anAt = aCamera->Center();
889 gp_Pnt anEye = aCamera->Eye();
891 gp_Vec aLook (anAt, anEye);
893 if (aCamera->Distance() > 1.e-3)
895 aLook = aLook / aCamera->Distance() * theFocus;
899 anAt.SetX (aLook.X() + anEye.X());
900 anAt.SetY (aLook.Y() + anEye.Y());
901 anAt.SetZ (aLook.Z() + anEye.Z());
905 aCamera->SetCenter (anAt);
906 aCamera->SetFOVy (theAngle);
912 void CAnimationView3D::ReloadData()
914 myView->At ( m_Atx , m_Aty , m_Atz ) ;
915 myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ;
916 double dTwist = myView->Twist() * 180. / M_PI;
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);
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);
933 aMsg.Format (L"%lf", dTwist);
934 m_Tune.GetDlgItem (IDC_TWIST)->SetWindowText (aMsg);
937 dx = m_Atx - m_Eyex ;
938 dy = m_Aty - m_Eyey ;
939 dz = m_Atz - m_Eyez ;
941 m_Focus = sqrt (dx * dx + dy * dy + dz * dz);
943 m_dAngle = myView->Camera()->FOVy();
945 m_Tune.m_dAngle = m_dAngle ;
946 m_Tune.m_dFocus = m_Focus ;
947 m_Tune.UpdateData ( FALSE ) ;
950 void CAnimationView3D::SetDimensions()
953 CAnimationDoc* pDoc = GetDocument();
955 myView->SetImmediateUpdate ( Standard_False ) ;
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 ;
964 myView->SetAt ( m_Atx , m_Aty , m_Atz ) ;
965 myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ;
966 myView->SetTwist (0.) ;
968 myView->SetImmediateUpdate ( Standard_False ) ;
970 myView->SetImmediateUpdate ( Standard_False ) ;
973 myView->SetImmediateUpdate ( Standard_True ) ;
979 void CAnimationView3D::OnViewDisplaystatus()
981 // TODO: Add your command handler code here
983 if ( m_Tune.IsWindowVisible () ) {
987 m_Tune.ShowWindow ( SW_SHOWNORMAL ) ;
991 void CAnimationView3D::OnUpdateViewDisplaystatus(CCmdUI* pCmdUI)
993 // TODO: Add your command update UI handler code here
995 if ( m_Tune.IsWindowVisible () ) {
996 pCmdUI->SetCheck ( 1 ) ;
999 pCmdUI->SetCheck ( 0 ) ;