From: kgv Date: Sat, 20 Jun 2020 20:00:17 +0000 (+0300) Subject: 0031622: Samples - update MFC Animation sample with proper frame updates X-Git-Tag: V7_5_0_beta~170 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=64f128c1117c91c5e41a83b0ae2d14e64ed71f64 0031622: Samples - update MFC Animation sample with proper frame updates Animation sample has been updated to: - use reuse AIS_ViewController for general viewer manipulations; - update animation using elapsed time; - do not block camera manipilations; - get rid of redundant controls. --- diff --git a/samples/mfc/standard/09_Animation/CMakeLists.txt b/samples/mfc/standard/09_Animation/CMakeLists.txt index 8868e7e9fa..9cea604460 100644 --- a/samples/mfc/standard/09_Animation/CMakeLists.txt +++ b/samples/mfc/standard/09_Animation/CMakeLists.txt @@ -10,19 +10,15 @@ set (Animation_HEADER_FILES ${Animation_SRC_DIR}/AnimationApp.h ${Animation_SRC_DIR}/AnimationDoc.h ${Animation_SRC_DIR}/AnimationView3D.h ${Animation_SRC_DIR}/Fonc.hxx - ${Animation_SRC_DIR}/Sensitivity.h ${Animation_SRC_DIR}/ShadingDialog.h ${Animation_SRC_DIR}/ThreadDialog.h - ${Animation_SRC_DIR}/Tune.h ${Animation_SRC_DIR}/StdAfx.h ) set (Animation_SOURCE_FILES ${Animation_SRC_DIR}/AnimationApp.cpp ${Animation_SRC_DIR}/AnimationDoc.cpp ${Animation_SRC_DIR}/AnimationView3D.cpp ${Animation_SRC_DIR}/Fonc.cxx - ${Animation_SRC_DIR}/Sensitivity.cpp ${Animation_SRC_DIR}/ShadingDialog.cpp ${Animation_SRC_DIR}/ThreadDialog.cpp - ${Animation_SRC_DIR}/Tune.cpp ${Animation_SRC_DIR}/StdAfx.cpp ) set (Animation_RESOURCE_DIR ${MFC_STANDARD_SAMPLES_DIR}/09_Animation/res) diff --git a/samples/mfc/standard/09_Animation/adm/win/vc10/Animation.vcxproj b/samples/mfc/standard/09_Animation/adm/win/vc10/Animation.vcxproj index 20ff9059ba..f22faa9356 100644 --- a/samples/mfc/standard/09_Animation/adm/win/vc10/Animation.vcxproj +++ b/samples/mfc/standard/09_Animation/adm/win/vc10/Animation.vcxproj @@ -314,7 +314,6 @@ %(PreprocessorDefinitions) - Disabled %(AdditionalIncludeDirectories) @@ -367,7 +366,6 @@ %(AdditionalIncludeDirectories) %(PreprocessorDefinitions) - Disabled %(AdditionalIncludeDirectories) @@ -391,11 +389,9 @@ - - diff --git a/samples/mfc/standard/09_Animation/adm/win/vc10/Animation.vcxproj.filters b/samples/mfc/standard/09_Animation/adm/win/vc10/Animation.vcxproj.filters index 879de1c590..2be10d511f 100644 --- a/samples/mfc/standard/09_Animation/adm/win/vc10/Animation.vcxproj.filters +++ b/samples/mfc/standard/09_Animation/adm/win/vc10/Animation.vcxproj.filters @@ -32,9 +32,6 @@ Source Files - - Source Files - Source Files @@ -44,9 +41,6 @@ Source Files - - Source Files - Source Files @@ -67,9 +61,6 @@ Header Files - - Header Files - Header Files @@ -79,9 +70,6 @@ Header Files - - Header Files - diff --git a/samples/mfc/standard/09_Animation/res/Animation.rc b/samples/mfc/standard/09_Animation/res/Animation.rc index 4ab365477f..f7147777e9 100755 --- a/samples/mfc/standard/09_Animation/res/Animation.rc +++ b/samples/mfc/standard/09_Animation/res/Animation.rc @@ -80,9 +80,6 @@ BEGIN BUTTON ID_SHADING SEPARATOR BUTTON ID_FILE_LOADGRID - BUTTON ID_SENSITIVITY - BUTTON ID_VIEW_DISPLAYSTATUS - BUTTON ID_WALK_WALKTHRU SEPARATOR BUTTON ID_APP_ABOUT END @@ -156,11 +153,6 @@ BEGIN BEGIN MENUITEM "&About DisplayAnimation...", ID_APP_ABOUT END - POPUP "Walk" - BEGIN - MENUITEM "Sensitivity...", ID_SENSITIVITY - MENUITEM "Walkthrough", ID_WALK_WALKTHRU - END END @@ -191,51 +183,6 @@ BEGIN EDITTEXT IDC_Angle,65,27,48,16,ES_AUTOHSCROLL END -IDD_SENS DIALOG 0, 0, 229, 50 -STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Sensitivity" -FONT 8, "MS Sans Serif" -BEGIN - LTEXT "Fly",IDC_STATIC,8,10,10,8 - EDITTEXT IDC_FLY,33,8,76,15,ES_AUTOHSCROLL - CONTROL "Spin1",IDC_SPIN1,"msctls_updown32",UDS_ARROWKEYS,112,8,11,15 - LTEXT "Turn",IDC_STATIC,6,28,16,8 - EDITTEXT IDC_TURN,34,25,76,15,ES_AUTOHSCROLL - CONTROL "Spin1",IDC_SPIN2,"msctls_updown32",UDS_ARROWKEYS,112,25,11,15 - DEFPUSHBUTTON "OK",IDOK,170,7,50,14 - PUSHBUTTON "Cancel",IDCANCEL,170,23,50,14 -END - -IDD_TUNE DIALOG 0, 0, 131, 154 -STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -CAPTION "Display Tuning" -FONT 8, "MS Sans Serif" -BEGIN - LTEXT "Distance",IDC_STATIC,9,8,29,8 - EDITTEXT IDC_FOCDIST,46,5,57,14,ES_AUTOHSCROLL - CONTROL "Spin1",IDC_SPINFOC,"msctls_updown32",UDS_ARROWKEYS,107,6,11,14 - LTEXT "Aperture",IDC_STATIC,9,25,28,8 - EDITTEXT IDC_APPERTURE,46,23,57,14,ES_AUTOHSCROLL - CONTROL "Spin4",IDC_SPINANG,"msctls_updown32",UDS_ARROWKEYS,107,23,11,14 - LTEXT "X :",IDC_STATIC,17,52,12,8 - LTEXT "0.",IDC_XEYE,31,52,66,8 - GROUPBOX "Eye",IDC_STATIC,9,41,110,43 - LTEXT "Y :",IDC_STATIC,17,62,12,8 - LTEXT "0.",IDC_YEYE,31,62,66,8 - LTEXT "Z :",IDC_STATIC,17,72,12,8 - LTEXT "0.",IDC_ZEYE,31,72,66,8 - LTEXT "X :",IDC_STATIC,15,98,12,8 - LTEXT "0.",IDC_XAT,33,98,66,8 - GROUPBOX "Target",IDC_STATIC,9,86,110,45 - LTEXT "Y :",IDC_STATIC,15,109,12,8 - LTEXT "0.",IDC_YAT,33,109,66,8 - LTEXT "Z :",IDC_STATIC,15,120,12,8 - LTEXT "0.",IDC_ZAT,33,120,66,8 - LTEXT "Twist :",IDC_STATIC,11,137,22,8 - LTEXT "0.",IDC_TWIST,35,137,77,8 -END - - ///////////////////////////////////////////////////////////////////////////// // // Version @@ -297,12 +244,6 @@ BEGIN ID_FILE_LOADGRID "Load Grid Files\nLoad Grid File" END -STRINGTABLE -BEGIN - ID_VIEW_DISPLAYSTATUS "Show/Hide the display status Window\nShow/Hide the display status Window" - ID_WALK_WALKTHRU "Toggle Walkthru On/Off\nToggle Walkthru On/Off" -END - #endif // English (U.S.) resources ///////////////////////////////////////////////////////////////////////////// diff --git a/samples/mfc/standard/09_Animation/src/AnimationDoc.cpp b/samples/mfc/standard/09_Animation/src/AnimationDoc.cpp index 2d35a3109f..ecb0f0b6a7 100755 --- a/samples/mfc/standard/09_Animation/src/AnimationDoc.cpp +++ b/samples/mfc/standard/09_Animation/src/AnimationDoc.cpp @@ -45,10 +45,6 @@ CAnimationDoc::CAnimationDoc() { // TODO: add one-time construction code here - static Standard_Integer StaticCount=1; - StaticCount++; - myCount = StaticCount; - Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((CAnimationApp*)AfxGetApp())->GetGraphicDriver(); @@ -60,7 +56,6 @@ CAnimationDoc::CAnimationDoc() myDeviation = 0.0008; thread = 4; - myAngle = 0; BRep_Builder B; TopoDS_Shape CrankArm; @@ -184,90 +179,6 @@ void CAnimationDoc::Dump(CDumpContext& dc) const //----------------------------------------------------------------------------------------- // //----------------------------------------------------------------------------------------- -void CAnimationDoc::DragEvent(const Standard_Integer x , - const Standard_Integer y , - const Standard_Integer TheState , - const Handle(V3d_View)& aView ) -{ - - // TheState == -1 button down - // TheState == 0 move - // TheState == 1 button up - - static Standard_Integer theButtonDownX=0; - static Standard_Integer theButtonDownY=0; - - if (TheState == -1) - { - theButtonDownX=x; - theButtonDownY=y; - } - - if (TheState == 1) - myAISContext->Select (theButtonDownX, theButtonDownY, x, y, aView, Standard_True); -} - -//----------------------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------------------- -void CAnimationDoc::InputEvent(const Standard_Integer /*x*/, - const Standard_Integer /*y*/, - const Handle(V3d_View)& /*aView*/ ) -{ - myAISContext->Select (Standard_True); -} - -//----------------------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------------------- -void CAnimationDoc::MoveEvent(const Standard_Integer x , - const Standard_Integer y , - const Handle(V3d_View)& aView ) -{ - myAISContext->MoveTo (x, y, aView, Standard_True); -} - -//----------------------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------------------- -void CAnimationDoc::ShiftMoveEvent(const Standard_Integer x , - const Standard_Integer y , - const Handle(V3d_View)& aView ) -{ - myAISContext->MoveTo (x, y, aView, Standard_True); -} - -//----------------------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------------------- -void CAnimationDoc::ShiftDragEvent(const Standard_Integer x , - const Standard_Integer y , - const Standard_Integer TheState , - const Handle(V3d_View)& aView ) -{ - static Standard_Integer theButtonDownX=0; - static Standard_Integer theButtonDownY=0; - - if (TheState == -1) - { - theButtonDownX=x; - theButtonDownY=y; - } - - if (TheState == 0) - myAISContext->ShiftSelect (theButtonDownX, theButtonDownY, x, y, aView, Standard_True); -} - - -//----------------------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------------------- -void CAnimationDoc::ShiftInputEvent(const Standard_Integer /*x*/, - const Standard_Integer /*y*/, - const Handle(V3d_View)& /*aView*/) -{ - myAISContext->ShiftSelect (Standard_True); -} //----------------------------------------------------------------------------------------- // @@ -278,7 +189,7 @@ void CAnimationDoc::Popup(const Standard_Integer /*x*/, { } -void CAnimationDoc::OnMyTimer() +void CAnimationDoc::OnMyTimer (double theTimeSec) { // TODO: Add your message handler code here and/or call default @@ -287,9 +198,7 @@ void CAnimationDoc::OnMyTimer() Standard_Real X; gp_Ax1 Ax1(gp_Pnt(0,0,0),gp_Vec(0,0,1)); - myAngle++; - - angleA = thread*myAngle*M_PI/180; + angleA = thread * theTimeSec; X = Sin(angleA)*3/8; angleB = atan(X / Sqrt(-X * X + 1)); Standard_Real decal(25*0.6); @@ -308,8 +217,6 @@ void CAnimationDoc::OnMyTimer() gp_Trsf aPistonTrsf; aPistonTrsf.SetTranslation(gp_Vec(-3*decal*(1-Cos(angleA))-8*decal*(1-Cos(angleB)),0,0)); myAISContext->SetLocation(myAisPiston,aPistonTrsf); - - myAISContext->UpdateCurrentViewer(); } void CAnimationDoc::OnShading() diff --git a/samples/mfc/standard/09_Animation/src/AnimationDoc.h b/samples/mfc/standard/09_Animation/src/AnimationDoc.h index fa5c4cd85d..ce27112b3b 100755 --- a/samples/mfc/standard/09_Animation/src/AnimationDoc.h +++ b/samples/mfc/standard/09_Animation/src/AnimationDoc.h @@ -17,33 +17,6 @@ class CAnimationDoc : public OCC_BaseDoc { public: - - void DragEvent (const Standard_Integer x, - const Standard_Integer y, - const Standard_Integer TheState, - const Handle(V3d_View)& aView); - - void InputEvent (const Standard_Integer x, - const Standard_Integer y, - const Handle(V3d_View)& aView); - - void MoveEvent (const Standard_Integer x, - const Standard_Integer y, - const Handle(V3d_View)& aView); - - void ShiftMoveEvent (const Standard_Integer x, - const Standard_Integer y, - const Handle(V3d_View)& aView); - - void ShiftDragEvent (const Standard_Integer x, - const Standard_Integer y, - const Standard_Integer TheState, - const Handle(V3d_View)& aView); - - void ShiftInputEvent (const Standard_Integer x, - const Standard_Integer y, - const Handle(V3d_View)& aView); - void Popup (const Standard_Integer x, const Standard_Integer y, const Handle(V3d_View)& aView); @@ -78,11 +51,9 @@ private: Handle(AIS_Shape) myAisEngineBlock ; Standard_Real myDeviation; - Standard_Integer myAngle; public: - void OnMyTimer(); - Standard_Integer myCount; + void OnMyTimer (double theTimeSec); Standard_Integer thread; double m_Xmin, m_Ymin, m_Zmin, m_Xmax, m_Ymax, m_Zmax; BOOL m_bIsGridLoaded; diff --git a/samples/mfc/standard/09_Animation/src/AnimationView3D.cpp b/samples/mfc/standard/09_Animation/src/AnimationView3D.cpp index ad4f0d60bb..1cc55b62e7 100755 --- a/samples/mfc/standard/09_Animation/src/AnimationView3D.cpp +++ b/samples/mfc/standard/09_Animation/src/AnimationView3D.cpp @@ -9,8 +9,6 @@ #include "ShadingDialog.h" #include "AnimationDoc.h" -#include "Sensitivity.h" - #include #ifdef _DEBUG @@ -49,6 +47,7 @@ BEGIN_MESSAGE_MAP(CAnimationView3D, CView) ON_WM_SIZE() ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg) ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin) + ON_WM_MOUSEWHEEL() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() ON_WM_MBUTTONDOWN() @@ -69,13 +68,10 @@ BEGIN_MESSAGE_MAP(CAnimationView3D, CView) ON_COMMAND(ID_STOP, OnStop) ON_COMMAND(ID_RESTART, OnRestart) - ON_COMMAND(ID_SENSITIVITY, OnSensitivity) ON_COMMAND(ID_BUTTONFly, OnBUTTONFly) ON_COMMAND(ID_BUTTONTurn, OnBUTTONTurn) ON_UPDATE_COMMAND_UI(ID_BUTTONFly, OnUpdateBUTTONFly) ON_UPDATE_COMMAND_UI(ID_BUTTONTurn, OnUpdateBUTTONTurn) - ON_COMMAND(ID_VIEW_DISPLAYSTATUS, OnViewDisplaystatus) - ON_UPDATE_COMMAND_UI(ID_VIEW_DISPLAYSTATUS, OnUpdateViewDisplaystatus) //}}AFX_MSG_MAP // CasCade @@ -85,18 +81,13 @@ END_MESSAGE_MAP() // CAnimationView3D construction/destruction CAnimationView3D::CAnimationView3D() -: myXmin (0), - myYmin (0), - myXmax (0), - myYmax (0), - myCurZoom (0.0), +: myCurZoom (0.0), myHlrModeIsOn (Standard_False), - myCurrentMode (CurrentAction3d_Nothing), - m_FlySens (500.0), - m_TurnSens (M_PI / 40.0), - myRect (new AIS_RubberBand (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0)) + myIsTurnStarted (Standard_False), + myUpdateRequests (0), + myCurrentMode (CurrentAction3d_Nothing) { - // TODO: add construction code here + myDefaultGestures = myMouseGestureMap; } CAnimationView3D::~CAnimationView3D() @@ -115,29 +106,72 @@ BOOL CAnimationView3D::PreCreateWindow(CREATESTRUCT& cs) ///////////////////////////////////////////////////////////////////////////// // CAnimationView3D drawing -void CAnimationView3D::OnDraw(CDC* /*pDC*/) + +// ================================================================ +// Function : update3dView +// Purpose : +// ================================================================ +void CAnimationView3D::update3dView() { - CAnimationDoc* pDoc = GetDocument(); - ASSERT_VALID(pDoc); + if (myView.IsNull()) + { + return; + } + + if (++myUpdateRequests == 1) + { + Invalidate (FALSE); + UpdateWindow(); + } +} - // TODO: add draw code for native data here +// ================================================================ +// Function : redraw3dView +// Purpose : +// ================================================================ +void CAnimationView3D::redraw3dView() +{ + if (!myView.IsNull()) + { + FlushViewEvents (GetDocument()->GetAISContext(), myView, true); + } +} - myView->Redraw(); +// ================================================================ +// Function : handleViewRedraw +// Purpose : +// ================================================================ +void CAnimationView3D::handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx, + const Handle(V3d_View)& theView) +{ + myUpdateRequests = 0; + if (myAnimTimer.IsStarted()) + { + GetDocument()->OnMyTimer (myAnimTimer.ElapsedTime()); + setAskNextFrame(); + } + AIS_ViewController::handleViewRedraw (theCtx, theView); +} +void CAnimationView3D::OnDraw(CDC* /*pDC*/) +{ + // always redraw immediate layer (dynamic highlighting) on Paint event, + // and redraw entire view content only when it is explicitly invalidated (V3d_View::Invalidate()) + myView->InvalidateImmediate(); + FlushViewEvents (GetDocument()->GetInteractiveContext(), myView, true); } + void CAnimationView3D::OnInitialUpdate() { CView::OnInitialUpdate(); // TODO: Add your specialized code here and/or call the base class // myView = GetDocument()->GetViewer()->CreateView(); - - Handle(V3d_Viewer) aViewer; - - aViewer = GetDocument()->GetViewer(); + Handle(V3d_Viewer) aViewer = GetDocument()->GetViewer(); aViewer->SetDefaultTypeOfView (V3d_PERSPECTIVE); myView = aViewer->CreateView(); + myView->SetImmediateUpdate (false); // store for restore state after rotation (witch is in Degenerated mode) myHlrModeIsOn = myView->ComputedMode(); @@ -148,58 +182,57 @@ void CAnimationView3D::OnInitialUpdate() // store the mode ( nothing , dynamic zooming, dynamic ... ) myCurrentMode = CurrentAction3d_Nothing; + CFrameWnd* pParentFrm = GetParentFrame(); pParentFrm->ActivateFrame(SW_SHOWMAXIMIZED); - - Standard_Integer w=100 , h=100 ; /* Debug Matrox */ - aWNTWindow->Size (w,h) ; /* Keeps me unsatisfied (rlb)..... */ - /* Resize is not supposed to be done on */ - /* Matrox */ - /* I suspect another problem elsewhere */ - ::PostMessage ( GetSafeHwnd () , WM_SIZE , SIZE_RESTORED , w + h*65536 ) ; - - m_Tune.Create ( IDD_TUNE , NULL ) ; - - RECT dlgrect; - m_Tune.GetWindowRect(&dlgrect); - LONG width = dlgrect.right-dlgrect.left; - LONG height = dlgrect.bottom-dlgrect.top; - RECT MainWndRect; - AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect); - LONG left = MainWndRect.left+3; - LONG top = MainWndRect.top + 112; - m_Tune.MoveWindow(left,top,width,height); - - m_Tune.m_pView = this ; - - m_Tune.ShowWindow ( SW_HIDE ); - - // store the mode ( nothing , dynamic zooming, dynamic ... ) - - myCurrentMode = CurrentAction3d_Nothing; - - ReloadData () ; - } -void CAnimationView3D::DisplayTuneDialog() +// ======================================================================= +// function : defineMouseGestures +// purpose : +// ======================================================================= +void CAnimationView3D::defineMouseGestures() { - m_Tune.Create ( IDD_TUNE , NULL ) ; - - RECT dlgrect; - m_Tune.GetWindowRect(&dlgrect); - LONG width = dlgrect.right-dlgrect.left; - LONG height = dlgrect.bottom-dlgrect.top; - RECT MainWndRect; - AfxGetApp()->m_pMainWnd->GetWindowRect(&MainWndRect); - LONG left = MainWndRect.left+3; - LONG top = MainWndRect.top + 112; - m_Tune.MoveWindow(left,top,width,height); - - m_Tune.m_pView = this ; + myMouseGestureMap.Clear(); + switch (myCurrentMode) + { + case CurrentAction3d_Nothing: + { + myMouseGestureMap = myDefaultGestures; + break; + } + case CurrentAction3d_DynamicZooming: + { + myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Zoom); + break; + } + case CurrentAction3d_GlobalPanning: + { + break; + } + case CurrentAction3d_WindowZooming: + { + myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_ZoomWindow); + break; + } + case CurrentAction3d_DynamicPanning: + { + myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Pan); + break; + } + case CurrentAction3d_DynamicRotation: + { + myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_RotateOrbit); + break; + } + case CurrentAction3d_Fly: + { + myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_RotateView); + break; + } + } } - ///////////////////////////////////////////////////////////////////////////// // CAnimationView3D diagnostics @@ -231,10 +264,15 @@ void CAnimationView3D::OnFileExportImage() void CAnimationView3D::OnSize(UINT nType, int cx, int cy) { CView::OnSize (nType, cx, cy); - m_cx = cx ; - m_cy = cy ; - if (!myView.IsNull()) + if (cx != 0 + && cy != 0 + && !myView.IsNull()) + { + myView->Window()->DoResize(); myView->MustBeResized(); + myView->Invalidate(); + update3dView(); + } } void CAnimationView3D::OnBUTTONBack() @@ -273,7 +311,7 @@ void CAnimationView3D::OnBUTTONHlrOn() void CAnimationView3D::OnBUTTONPan() { - myCurrentMode = CurrentAction3d_DynamicPanning; + setCurrentAction (CurrentAction3d_DynamicPanning); } void CAnimationView3D::OnBUTTONPanGlo() @@ -283,289 +321,159 @@ void CAnimationView3D::OnBUTTONPanGlo() // Do a Global Zoom myView->FitAll(); // Set the mode - myCurrentMode = CurrentAction3d_GlobalPanning; + setCurrentAction (CurrentAction3d_GlobalPanning); } void CAnimationView3D::OnBUTTONReset() -{ myView->Reset(); - ReloadData(); +{ + myView->Reset(); } void CAnimationView3D::OnBUTTONRot() -{ myCurrentMode = CurrentAction3d_DynamicRotation; } +{ setCurrentAction (CurrentAction3d_DynamicRotation); } void CAnimationView3D::OnBUTTONZoomAll() { - SetDimensions(); - myView->FitAll(); - myView->ZFitAll(); + FitAll(); } void CAnimationView3D::OnBUTTONZoomProg() -{ myCurrentMode = CurrentAction3d_DynamicZooming; } +{ setCurrentAction (CurrentAction3d_DynamicZooming); } void CAnimationView3D::OnBUTTONZoomWin() -{ myCurrentMode = CurrentAction3d_WindowZooming; } +{ setCurrentAction (CurrentAction3d_WindowZooming); } void CAnimationView3D::OnBUTTONFly() -{ myCurrentMode = CurrentAction3d_Fly; } +{ setCurrentAction (CurrentAction3d_Fly); } void CAnimationView3D::OnBUTTONTurn() -{ myCurrentMode = CurrentAction3d_Turn; } - - -void CAnimationView3D::OnLButtonDown(UINT nFlags, CPoint point) -{ - // save the current mouse coordinate in min - myXmin=point.x; myYmin=point.y; - myXmax=point.x; myYmax=point.y; - - if ( nFlags & MK_CONTROL ) - { - // Button MB1 down Control :start zomming - // SetCursor(AfxGetApp()->LoadStandardCursor()); - } - else // if ( Ctrl ) - { - switch (myCurrentMode) - { - case CurrentAction3d_Nothing : // start a drag - if (nFlags & MK_SHIFT) - GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView); - else - GetDocument()->DragEvent(myXmax,myYmax,-1,myView); - break; - break; - case CurrentAction3d_DynamicZooming : // noting - // SetCursor(AfxGetApp()->LoadStandardCursor()); - break; - case CurrentAction3d_WindowZooming : // noting - break; - case CurrentAction3d_DynamicPanning :// noting - break; - case CurrentAction3d_GlobalPanning :// noting - break; - case CurrentAction3d_DynamicRotation : - if (myHlrModeIsOn) - { - myView->SetComputedMode (Standard_False); - } - myView->StartRotation (point.x, point.y); - break; - case CurrentAction3d_Fly : - KillTimer (1) ; - SetTimer ( 1 , 100 , NULL ) ; - break ; - case CurrentAction3d_Turn : - KillTimer (1) ; - SetTimer ( 1 , 100 , NULL ) ; - break ; - default : - throw Standard_Failure(" incompatible Current Mode "); - break; - } - } +{ setCurrentAction (CurrentAction3d_Turn); } + + +void CAnimationView3D::OnLButtonDown(UINT theFlags, CPoint thePoint) +{ + const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags); + PressMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_LeftButton, aFlags, false); + myClickPos.SetValues (thePoint.x, thePoint.y); + myIsTurnStarted = myCurrentMode == CurrentAction3d_Turn && aFlags == Aspect_VKeyFlags_NONE; + update3dView(); } -void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point) -{ - if ( nFlags & MK_CONTROL ) - { - return; - } - else // if ( Ctrl ) - { - switch (myCurrentMode) - { - case CurrentAction3d_Nothing : - if (point.x == myXmin && point.y == myYmin) - { // no offset between down and up --> selectEvent - myXmax=point.x; - myYmax=point.y; - if (nFlags & MK_SHIFT ) - GetDocument()->ShiftInputEvent(point.x,point.y,myView); - else - GetDocument()->InputEvent (point.x,point.y,myView); - } else - { - DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False); - myXmax=point.x; - myYmax=point.y; - if (nFlags & MK_SHIFT) - GetDocument()->ShiftDragEvent(point.x,point.y,1,myView); - else - GetDocument()->DragEvent(point.x,point.y,1,myView); - } - break; - case CurrentAction3d_DynamicZooming : - // SetCursor(AfxGetApp()->LoadStandardCursor()); - myCurrentMode = CurrentAction3d_Nothing; - break; - case CurrentAction3d_WindowZooming : - myXmax=point.x; myYmax=point.y; - DrawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_False, Aspect_TOL_DASH); - if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin)) - // Test if the zoom window is greater than a minimale window. - { - // Do the zoom window between Pmin and Pmax - myView->WindowFitAll(myXmin,myYmin,myXmax,myYmax); - } - myCurrentMode = CurrentAction3d_Nothing; - break; - case CurrentAction3d_DynamicPanning : - myCurrentMode = CurrentAction3d_Nothing; - break; - case CurrentAction3d_GlobalPanning : - myView->Place(point.x,point.y,myCurZoom); - myCurrentMode = CurrentAction3d_Nothing; - break; - case CurrentAction3d_DynamicRotation : - myCurrentMode = CurrentAction3d_Nothing; - break; - case CurrentAction3d_Fly : - KillTimer ( 1 ) ; - case CurrentAction3d_Turn : - KillTimer ( 1 ) ; - break; - default : - throw Standard_Failure(" incompatible Current Mode "); - break; - } //switch (myCurrentMode) - } // else // if ( Ctrl ) -} - -void CAnimationView3D::OnMButtonDown(UINT nFlags, CPoint /*point*/) -{ - if ( nFlags & MK_CONTROL ) - { - // Button MB2 down Control : panning init - // SetCursor(AfxGetApp()->LoadStandardCursor()); - } -} - -void CAnimationView3D::OnMButtonUp(UINT nFlags, CPoint /*point*/) -{ - if ( nFlags & MK_CONTROL ) - { - // Button MB2 down Control : panning init - // SetCursor(AfxGetApp()->LoadStandardCursor()); - } -} - -void CAnimationView3D::OnRButtonDown(UINT nFlags, CPoint point) -{ - if ( nFlags & MK_CONTROL ) +void CAnimationView3D::OnLButtonUp(UINT theFlags, CPoint thePoint) +{ + const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags); + ReleaseMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_LeftButton, aFlags, false); + if (myCurrentMode == CurrentAction3d_GlobalPanning) { - // SetCursor(AfxGetApp()->LoadStandardCursor()); - if (myHlrModeIsOn) - { - myView->SetComputedMode (Standard_False); - } - myView->StartRotation (point.x, point.y); + myView->Place (thePoint.x, thePoint.y, myCurZoom); + myView->Invalidate(); } - else // if ( Ctrl ) + if (myCurrentMode != CurrentAction3d_Nothing) { - GetDocument()->Popup(point.x,point.y,myView); + setCurrentAction (CurrentAction3d_Nothing); + myIsTurnStarted = false; } + update3dView(); } -void CAnimationView3D::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/) +void CAnimationView3D::OnMButtonDown(UINT theFlags, CPoint thePoint) { - SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); - if (myHlrModeIsOn) - { - myView->SetComputedMode (myHlrModeIsOn); - myView->Redraw(); - } - SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); + const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags); + PressMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_MiddleButton, aFlags, false); + update3dView(); +} + +void CAnimationView3D::OnMButtonUp(UINT theFlags, CPoint thePoint) +{ + const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags); + ReleaseMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_MiddleButton, aFlags, false); + update3dView(); + if (myCurrentMode != CurrentAction3d_Nothing) + { + setCurrentAction (CurrentAction3d_Nothing); + } } -void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point) +void CAnimationView3D::OnRButtonDown(UINT theFlags, CPoint thePoint) { - // ============================ LEFT BUTTON ======================= - m_curx = point.x ; - m_cury = point.y ; + const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags); + PressMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_RightButton, aFlags, false); + update3dView(); + myClickPos.SetValues (thePoint.x, thePoint.y); +} - if ( nFlags & MK_LBUTTON) - { - if ( nFlags & MK_CONTROL ) - { - // move with MB1 and Control : on the dynamic zooming - // Do the zoom in function of mouse's coordinates - myView->Zoom(myXmax,myYmax,point.x,point.y); - // save the current mouse coordinate in min - myXmax = point.x; - myYmax = point.y; - } - else // if ( Ctrl ) - { - switch (myCurrentMode) - { - case CurrentAction3d_Nothing : - myXmax = point.x; myYmax = point.y; - if (nFlags & MK_SHIFT) - GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView); - else - GetDocument()->DragEvent(myXmax,myYmax,0,myView); - DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True); - break; - case CurrentAction3d_DynamicZooming : - myView->Zoom(myXmax,myYmax,point.x,point.y); - // save the current mouse coordinate in min \n"; - myXmax=point.x; myYmax=point.y; - break; - case CurrentAction3d_WindowZooming : - myXmax = point.x; myYmax = point.y; - DrawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_True, Aspect_TOL_DASH); - break; - case CurrentAction3d_DynamicPanning : - myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning - myXmax = point.x; myYmax = point.y; - break; - case CurrentAction3d_GlobalPanning : // nothing - break; - case CurrentAction3d_DynamicRotation : - myView->Rotation(point.x,point.y); - myView->Redraw(); - break; - case CurrentAction3d_Fly : - break ; - case CurrentAction3d_Turn : - break ; - default : - throw Standard_Failure(" incompatible Current Mode "); - break; - }// switch (myCurrentMode) - }// if ( nFlags & MK_CONTROL ) else - } else // if ( nFlags & MK_LBUTTON) - // ============================ MIDDLE BUTTON ======================= - if ( nFlags & MK_MBUTTON) - { - if ( nFlags & MK_CONTROL ) - { - myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning - myXmax = point.x; myYmax = point.y; - - } - } else // if ( nFlags & MK_MBUTTON) - // ============================ RIGHT BUTTON ======================= - if ( nFlags & MK_RBUTTON) +void CAnimationView3D::OnRButtonUp(UINT theFlags, CPoint thePoint) +{ + const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags); + ReleaseMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_RightButton, aFlags, false); + update3dView(); + if (myCurrentMode != CurrentAction3d_Nothing) + { + setCurrentAction (CurrentAction3d_Nothing); + } + if (aFlags == Aspect_VKeyFlags_NONE + && (myClickPos - Graphic3d_Vec2i (thePoint.x, thePoint.y)).cwiseAbs().maxComp() <= 4) + { + GetDocument()->Popup (thePoint.x, thePoint.y, myView); + } +} + +// ======================================================================= +// function : OnMouseWheel +// purpose : +// ======================================================================= +BOOL CAnimationView3D::OnMouseWheel (UINT theFlags, short theDelta, CPoint thePoint) +{ + const Standard_Real aDeltaF = Standard_Real(theDelta) / Standard_Real(WHEEL_DELTA); + CPoint aCursorPnt = thePoint; + ScreenToClient (&aCursorPnt); + const Graphic3d_Vec2i aPos (aCursorPnt.x, aCursorPnt.y); + const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags); + if (UpdateMouseScroll (Aspect_ScrollDelta (aPos, aDeltaF, aFlags))) + { + update3dView(); + } + return true; +} + +void CAnimationView3D::OnMouseMove(UINT theFlags, CPoint thePoint) +{ + TRACKMOUSEEVENT aMouseEvent; // for WM_MOUSELEAVE + aMouseEvent.cbSize = sizeof(aMouseEvent); + aMouseEvent.dwFlags = TME_LEAVE; + aMouseEvent.hwndTrack = m_hWnd; + aMouseEvent.dwHoverTime = HOVER_DEFAULT; + if (!::_TrackMouseEvent (&aMouseEvent)) { TRACE("Track ERROR!\n"); } + + const Graphic3d_Vec2i aNewPnt (thePoint.x, thePoint.y); + const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags); + if (UpdateMousePosition (aNewPnt, PressedMouseButtons(), aFlags, false)) + { + update3dView(); + } + + if (myIsTurnStarted) + { + Graphic3d_Vec2i aWinSize; + myView->Window()->Size (aWinSize.x(), aWinSize.y()); + const Graphic3d_Vec2i aCenter = aWinSize / 2; + if (myClickPos != aCenter + && aNewPnt != aCenter + && aNewPnt != myClickPos) { - if ( nFlags & MK_CONTROL ) - { - rotCount++; - myView->Rotation(point.x,point.y); - } - }else //if ( nFlags & MK_RBUTTON) - // ============================ NO BUTTON ======================= - { // No buttons - myXmax = point.x; myYmax = point.y; - if (nFlags & MK_SHIFT) - GetDocument()->ShiftMoveEvent(point.x,point.y,myView); - else - GetDocument()->MoveEvent(point.x,point.y,myView); - } + const Graphic3d_Vec2i aVecFrom = myClickPos - aCenter; + const Graphic3d_Vec2i aVecTo = aNewPnt - aCenter; + const gp_Dir aDirFrom (aVecFrom.x() / double(aWinSize.x() / 2), aVecFrom.y() / double(aWinSize.y() / 2), 0.0); + const gp_Dir aDirTo (aVecTo.x() / double(aWinSize.x() / 2), aVecTo.y() / double(aWinSize.y() / 2), 0.0); + double anAngle = aDirFrom.AngleWithRef (aDirTo, gp::DZ()); + + myView->SetTwist (myView->Twist() + anAngle); + myView->Invalidate(); + update3dView(); + myClickPos = aNewPnt; + } + } } void CAnimationView3D::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI) @@ -613,13 +521,13 @@ void CAnimationView3D::OnUpdateBUTTONRot(CCmdUI* pCmdUI) void CAnimationView3D::OnUpdateBUTTONFly(CCmdUI* pCmdUI) { - pCmdUI->Enable(GetDocument()->m_bIsGridLoaded); + pCmdUI->Enable(true); pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Fly); } void CAnimationView3D::OnUpdateBUTTONTurn(CCmdUI* pCmdUI) { - pCmdUI->Enable(GetDocument()->m_bIsGridLoaded); + pCmdUI->Enable(true); pCmdUI->SetCheck (myCurrentMode == CurrentAction3d_Turn); } @@ -648,354 +556,13 @@ void CAnimationView3D::OnChangeBackground() //========================================================================================== //========================================================================================== -//----------------------------------------------------------------------------------------- -// -//----------------------------------------------------------------------------------------- -void CAnimationView3D::DrawRectangle (Standard_Integer theMinX, - Standard_Integer theMinY, - Standard_Integer theMaxX, - Standard_Integer theMaxY, - Standard_Boolean theToDraw, - Aspect_TypeOfLine theLineType) -{ - const Handle(AIS_InteractiveContext)& aCtx = GetDocument()->GetAISContext(); - if (!theToDraw) - { - aCtx->Remove (myRect, false); - aCtx->CurrentViewer()->RedrawImmediate(); - return; - } - - CRect aRect; - GetWindowRect (aRect); - myRect->SetLineType (theLineType); - myRect->SetRectangle (theMinX, aRect.Height() - theMinY, theMaxX, aRect.Height() - theMaxY); - if (!aCtx->IsDisplayed (myRect)) - { - aCtx->Display (myRect, false); - } - else - { - aCtx->Redisplay (myRect, false); - } - aCtx->CurrentViewer()->RedrawImmediate(); -} - void CAnimationView3D::OnStop() { - KillTimer(GetDocument()->myCount); + myAnimTimer.Pause(); } void CAnimationView3D::OnRestart() { - KillTimer(GetDocument()->myCount); - SetTimer(GetDocument()->myCount, 1 , NULL); -} - -/* -void CAnimationView3D::OnTimer(UINT nIDEvent) -{ - // TODO: Add your message handler code here and/or call default - GetDocument()->OnMyTimer(); - CView::OnTimer(nIDEvent); -} -*/ - - -/********************************************************************************* -************** W A L K T H R O U G H ****************************************** -/********************************************************************************/ - -void CAnimationView3D::OnTimer(UINT_PTR nIDEvent) -{ - if ( !GetDocument()->m_bIsGridLoaded ) - { - // TODO: Add your message handler code here and/or call default - GetDocument()->OnMyTimer(); - CView::OnTimer(nIDEvent); - } - else - { - CView::OnTimer(nIDEvent); - if ( nIDEvent == 1 ) { - myView->SetImmediateUpdate ( Standard_False ) ; - if ( myCurrentMode == CurrentAction3d_Fly ) { - - Fly ( m_curx , m_cury ) ; - if ( m_bShift ) - Roll ( m_curx , m_cury ) ; - else - Turn ( m_curx , m_cury ) ; - - myView->SetAt ( m_Atx , m_Aty , m_Atz ) ; - myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ; - - } - else if ( myCurrentMode == CurrentAction3d_Turn ) { - Twist ( m_curx , m_cury ) ; - } - else - KillTimer (1) ; - - - myView->SetImmediateUpdate ( Standard_True ) ; - - myView->Update (); - } - - ReloadData () ; - } -} - -void CAnimationView3D::OnSensitivity() -{ - CSensitivity dial ; - - dial.m_SensFly = m_FlySens ; - dial.m_SensTurn = m_TurnSens ; - if ( dial.DoModal () ) { - m_FlySens = dial.m_SensFly ; - m_TurnSens = dial.m_SensTurn ; - } -} - -void CAnimationView3D::Fly (int /*x*/ , int y) -{ - double v [3] ; - double l ; - double sens ; - int i ; - - sens = (double) myYmin - (double) y ; - sens /= (double) m_cy ; - sens *= m_FlySens ; - - v [0] = m_Atx - m_Eyex ; - v [1] = m_Aty - m_Eyey ; - v [2] = m_Atz - m_Eyez ; - l = sqrt ( v[0]*v[0] + v[1]*v[1] + v[2]*v[2] ) ; - if ( l > 1.e-3 ) { - for ( i=0 ; i<3 ; i++ ) - v [i] = v [i] / l * sens ; - - m_Atx += v [0] ; - m_Aty += v [1] ; - m_Atz += v [2] ; - - m_Eyex += v [0] ; - m_Eyey += v [1] ; - m_Eyez += v [2] ; - - } -} - -/* Rotation */ - -void CAnimationView3D::Turn (int x , int /*y*/) -{ - gp_Vec z (0.,0.,1.) ; - - double v [3] ; - double sens ; - double aX , aY , aZ ; - - sens = (double) x - (double) myXmin ; - sens /= (double) m_cx ; - sens *= m_TurnSens ; - - v [0] = m_Atx - m_Eyex ; - v [1] = m_Aty - m_Eyey ; - v [2] = m_Atz - m_Eyez ; - - gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ; - - gp_Vec reg (v[0],v[1],v[2] ); - - gp_Vec vert = reg ^ z ; - gp_Vec haut = vert ^ reg ; - - gp_Dir dh (haut) ; - gp_Ax1 rot (eye,dh); - - reg.Rotate (rot,sens) ; - - reg.Coord ( aX , aY , aZ ) ; - - m_Atx = m_Eyex + aX ; - m_Aty = m_Eyey + aY ; - m_Atz = m_Eyez + aZ ; -} - -void CAnimationView3D::Roll (int x , int /*y*/) -{ - gp_Vec z (0.,0.,1.) ; - - double v [3] ; - double sens ; - double aX , aY , aZ ; - - sens = (double) x - (double) myXmin ; - sens /= (double) m_cx ; - sens *= m_TurnSens ; - - v [0] = m_Atx - m_Eyex ; - v [1] = m_Aty - m_Eyey ; - v [2] = m_Atz - m_Eyez ; - - gp_Pnt eye ( m_Eyex , m_Eyey , m_Eyez ) ; - - gp_Vec reg (v[0],v[1],v[2] ); - - gp_Vec vert = reg ^ z ; - - gp_Dir dh (vert) ; - gp_Ax1 rot (eye,dh); - - reg.Rotate (rot,sens) ; - - reg.Coord ( aX , aY , aZ ) ; - - m_Atx = m_Eyex + aX ; - m_Aty = m_Eyey + aY ; - m_Atz = m_Eyez + aZ ; -} - -void CAnimationView3D::Twist (int x , int /*y*/) -{ - double sens ; - double a ; - - a = myView->Twist () ; - - sens = (double) x - (double) myXmin ; - sens /= (double) m_cx ; - sens *= m_TurnSens ; - - a += sens ; - - myView->SetTwist (a) ; -} - -//============================================================================= -// function: SetFocal -// purpose: -//============================================================================= -void CAnimationView3D::SetFocal (double theFocus, double theAngle) -{ - - Handle(Graphic3d_Camera) aCamera = myView->Camera(); - - gp_Pnt anAt = aCamera->Center(); - gp_Pnt anEye = aCamera->Eye(); - - gp_Vec aLook (anAt, anEye); - - if (aCamera->Distance() > 1.e-3) - { - aLook = aLook / aCamera->Distance() * theFocus; - - m_Focus = theFocus; - - anAt.SetX (aLook.X() + anEye.X()); - anAt.SetY (aLook.Y() + anEye.Y()); - anAt.SetZ (aLook.Z() + anEye.Z()); - - m_dAngle = theAngle; - - aCamera->SetCenter (anAt); - aCamera->SetFOVy (theAngle); - - myView->Update(); - } -} - -void CAnimationView3D::ReloadData() -{ - myView->At ( m_Atx , m_Aty , m_Atz ) ; - myView->Eye ( m_Eyex , m_Eyey , m_Eyez ) ; - double dTwist = myView->Twist() * 180. / M_PI; - - CString aMsg; - aMsg.Format (L"%lf", m_Atx); - m_Tune.GetDlgItem (IDC_XAT)->SetWindowText (aMsg); - aMsg.Format (L"%lf", m_Aty); - m_Tune.GetDlgItem (IDC_YAT)->SetWindowText (aMsg); - aMsg.Format (L"%lf", m_Atz); - m_Tune.GetDlgItem (IDC_ZAT)->SetWindowText (aMsg); - - aMsg.Format (L"%lf", m_Eyex); - m_Tune.GetDlgItem (IDC_XEYE)->SetWindowText (aMsg); - aMsg.Format (L"%lf", m_Eyey); - m_Tune.GetDlgItem (IDC_YEYE)->SetWindowText (aMsg); - aMsg.Format (L"%lf", m_Eyez); - m_Tune.GetDlgItem (IDC_ZEYE)->SetWindowText (aMsg); - - aMsg.Format (L"%lf", dTwist); - m_Tune.GetDlgItem (IDC_TWIST)->SetWindowText (aMsg); - - double dx,dy,dz ; - dx = m_Atx - m_Eyex ; - dy = m_Aty - m_Eyey ; - dz = m_Atz - m_Eyez ; - - m_Focus = sqrt (dx * dx + dy * dy + dz * dz); - - m_dAngle = myView->Camera()->FOVy(); - - m_Tune.m_dAngle = m_dAngle ; - m_Tune.m_dFocus = m_Focus ; - m_Tune.UpdateData ( FALSE ) ; -} - -void CAnimationView3D::SetDimensions() -{ - - CAnimationDoc* pDoc = GetDocument(); - - myView->SetImmediateUpdate ( Standard_False ) ; - - m_Atx = ( pDoc->m_Xmin + pDoc->m_Xmax ) / 2. ; - m_Aty = ( pDoc->m_Ymin + pDoc->m_Ymax ) / 2. ; - m_Atz = ( pDoc->m_Zmin + pDoc->m_Zmax ) / 2. ; - m_Eyex = pDoc->m_Xmax ; - m_Eyey = pDoc->m_Ymax ; - m_Eyez = pDoc->m_Zmax ; - - myView->SetAt ( m_Atx , m_Aty , m_Atz ) ; - myView->SetEye ( m_Eyex , m_Eyey , m_Eyez ) ; - myView->SetTwist (0.) ; - - myView->SetImmediateUpdate ( Standard_False ) ; - myView->FitAll(); - myView->SetImmediateUpdate ( Standard_False ) ; - myView->ZFitAll(); - - myView->SetImmediateUpdate ( Standard_True ) ; - - ReloadData () ; - myView->Update (); -} - -void CAnimationView3D::OnViewDisplaystatus() -{ - // TODO: Add your command handler code here - - if ( m_Tune.IsWindowVisible () ) { - - } - else { - m_Tune.ShowWindow ( SW_SHOWNORMAL ) ; - } -} - -void CAnimationView3D::OnUpdateViewDisplaystatus(CCmdUI* pCmdUI) -{ - // TODO: Add your command update UI handler code here - - if ( m_Tune.IsWindowVisible () ) { - pCmdUI->SetCheck ( 1 ) ; - } - else { - pCmdUI->SetCheck ( 0 ) ; - } + myAnimTimer.Start(); + update3dView(); } diff --git a/samples/mfc/standard/09_Animation/src/AnimationView3D.h b/samples/mfc/standard/09_Animation/src/AnimationView3D.h index fafdc33d89..30db5da030 100755 --- a/samples/mfc/standard/09_Animation/src/AnimationView3D.h +++ b/samples/mfc/standard/09_Animation/src/AnimationView3D.h @@ -9,10 +9,12 @@ #pragma once #endif // _MSC_VER >= 1000 -#include "Tune.h" #include "AnimationDoc.h" #include "..\..\Common\res\OCC_Resource.h" +#include +#include + class AIS_RubberBand; enum View3D_CurrentAction { @@ -26,7 +28,7 @@ enum View3D_CurrentAction { CurrentAction3d_Turn }; -class CAnimationView3D : public CView +class CAnimationView3D : public CView, public AIS_ViewController { protected: // create from serialization only CAnimationView3D(); @@ -58,20 +60,10 @@ public: virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif - void SetDimensions (); - void ReloadData(); - CTune m_Tune; - void SetFocal (double theFocus, double theAngle); - void Fly (int x , int y); - void Turn (int x , int y); - void Roll (int x , int y); - void Twist (int x , int y); protected: double m_dAngle; BOOL m_bShift; - int m_cx , m_cy ; - int m_curx , m_cury ; // Generated message map functions protected: @@ -94,6 +86,7 @@ protected: afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnBUTTONZoomProg(); afx_msg void OnBUTTONZoomWin(); + afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint point); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnMButtonDown(UINT nFlags, CPoint point); @@ -110,15 +103,11 @@ protected: afx_msg void OnUpdateBUTTONRot(CCmdUI* pCmdUI); afx_msg void OnChangeBackground(); - afx_msg void OnTimer(UINT_PTR nIDEvent); - afx_msg void OnSensitivity(); afx_msg void OnBUTTONFly(); afx_msg void OnBUTTONTurn(); afx_msg void OnUpdateBUTTONFly(CCmdUI* pCmdUI); afx_msg void OnUpdateBUTTONTurn(CCmdUI* pCmdUI); - afx_msg void OnViewDisplaystatus(); - afx_msg void OnUpdateViewDisplaystatus(CCmdUI* pCmdUI); //}}AFX_MSG public : @@ -131,26 +120,44 @@ private: Handle(V3d_View) myView; public: Handle(V3d_View)& GetView() { return myView;}; - void DisplayTuneDialog(); + + //! Request view redrawing. + void update3dView(); + + //! Flush events and redraw view. + void redraw3dView(); + +protected: + + //! Handle view redraw. + virtual void handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx, + const Handle(V3d_View)& theView) Standard_OVERRIDE; + +protected: + + //! Setup mouse gestures. + void defineMouseGestures(); + + //! Get current action. + View3D_CurrentAction getCurrentAction() const { return myCurrentMode; } + + //! Set current action. + void setCurrentAction (View3D_CurrentAction theAction) + { + myCurrentMode = theAction; + defineMouseGestures(); + } + private: - Standard_Integer myXmin; - Standard_Integer myYmin; - Standard_Integer myXmax; - Standard_Integer myYmax; + AIS_AnimationTimer myAnimTimer; + AIS_MouseGestureMap myDefaultGestures; + Graphic3d_Vec2i myClickPos; Standard_Real myCurZoom; Standard_Boolean myHlrModeIsOn; + Standard_Boolean myIsTurnStarted; + unsigned int myUpdateRequests; //!< counter for unhandled update requests View3D_CurrentAction myCurrentMode; - double m_Atx , m_Aty , m_Atz ; - double m_Eyex , m_Eyey , m_Eyez ; - double m_FlySens ; - double m_TurnSens ; - double m_Focus ; - -private: - Handle(AIS_RubberBand) myRect; //!< Rubber rectangle for selection - void DrawRectangle (Standard_Integer theMinX, Standard_Integer theMinY, Standard_Integer theMaxX, Standard_Integer theMaxY, - Standard_Boolean theToDraw, Aspect_TypeOfLine theLineType = Aspect_TOL_SOLID); }; #ifndef _DEBUG // debug version in AnimationView.cpp diff --git a/samples/mfc/standard/09_Animation/src/Sensitivity.cpp b/samples/mfc/standard/09_Animation/src/Sensitivity.cpp deleted file mode 100755 index 7da7dd60a7..0000000000 --- a/samples/mfc/standard/09_Animation/src/Sensitivity.cpp +++ /dev/null @@ -1,81 +0,0 @@ -// Sensitivity.cpp : implementation file -// - -#include "stdafx.h" - -#include "Sensitivity.h" - -#include "AnimationApp.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CSensitivity dialog - - -CSensitivity::CSensitivity(CWnd* pParent /*=NULL*/) - : CDialog(CSensitivity::IDD, pParent) -{ - //{{AFX_DATA_INIT(CSensitivity) - m_SensFly = 0.0; - m_SensTurn = 0.0; - //}}AFX_DATA_INIT -} - - -void CSensitivity::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CSensitivity) - DDX_Text(pDX, IDC_FLY, m_SensFly); - DDV_MinMaxDouble(pDX, m_SensFly, 0., 10000000.); - DDX_Text(pDX, IDC_TURN, m_SensTurn); - DDV_MinMaxDouble(pDX, m_SensTurn, 0., 10000000.); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CSensitivity, CDialog) - //{{AFX_MSG_MAP(CSensitivity) - ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaposSpin1) - ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN2, OnDeltaposSpin2) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CSensitivity message handlers - -void CSensitivity::OnDeltaposSpin1(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR; - // TODO: Add your control notification handler code here - if ( pNMUpDown->iDelta > 0 ) { - m_SensFly /= 1.1 ; - } - else { - m_SensFly *= 1.1 ; - } - UpdateData ( FALSE ) ; - - - *pResult = 0; -} - -void CSensitivity::OnDeltaposSpin2(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR; - // TODO: Add your control notification handler code here - if ( pNMUpDown->iDelta > 0 ) { - m_SensTurn /= 1.1 ; - } - else { - m_SensTurn *= 1.1 ; - } - UpdateData ( FALSE ) ; - - *pResult = 0; -} diff --git a/samples/mfc/standard/09_Animation/src/Sensitivity.h b/samples/mfc/standard/09_Animation/src/Sensitivity.h deleted file mode 100755 index 30d8ddf03e..0000000000 --- a/samples/mfc/standard/09_Animation/src/Sensitivity.h +++ /dev/null @@ -1,48 +0,0 @@ -#if !defined(AFX_SENSITIVITY_H__F3897393_7D55_11D2_8E5F_0800369C8A03__INCLUDED_) -#define AFX_SENSITIVITY_H__F3897393_7D55_11D2_8E5F_0800369C8A03__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 -// Sensitivity.h : header file -// - -///////////////////////////////////////////////////////////////////////////// -// CSensitivity dialog - -class CSensitivity : public CDialog -{ -// Construction -public: - CSensitivity(CWnd* pParent = NULL); // standard constructor - -// Dialog Data - //{{AFX_DATA(CSensitivity) - enum { IDD = IDD_SENS }; - double m_SensFly; - double m_SensTurn; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CSensitivity) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - //}}AFX_VIRTUAL - -// Implementation -protected: - - // Generated message map functions - //{{AFX_MSG(CSensitivity) - afx_msg void OnDeltaposSpin1(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnDeltaposSpin2(NMHDR* pNMHDR, LRESULT* pResult); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_SENSITIVITY_H__F3897393_7D55_11D2_8E5F_0800369C8A03__INCLUDED_) diff --git a/samples/mfc/standard/09_Animation/src/Tune.cpp b/samples/mfc/standard/09_Animation/src/Tune.cpp deleted file mode 100755 index 10c8e80485..0000000000 --- a/samples/mfc/standard/09_Animation/src/Tune.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// Tune.cpp : implementation file -// - -#include "stdafx.h" - -#include "Tune.h" - -#include "AnimationApp.h" -#include "Animationdoc.h" -#include "AnimationView3D.h" - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -///////////////////////////////////////////////////////////////////////////// -// CTune dialog - - -CTune::CTune(CWnd* pParent /*=NULL*/) - : CDialog(CTune::IDD, pParent) -{ - //{{AFX_DATA_INIT(CTune) - m_dAngle = 0.0; - m_dFocus = 0.0; - //}}AFX_DATA_INIT -} - - -void CTune::DoDataExchange(CDataExchange* pDX) -{ - CDialog::DoDataExchange(pDX); - //{{AFX_DATA_MAP(CTune) - DDX_Text(pDX, IDC_APPERTURE, m_dAngle); - DDV_MinMaxDouble(pDX, m_dAngle, 5., 179.); - DDX_Text(pDX, IDC_FOCDIST, m_dFocus); - DDV_MinMaxDouble(pDX, m_dFocus, 1.e-003, 10000000.); - //}}AFX_DATA_MAP -} - - -BEGIN_MESSAGE_MAP(CTune, CDialog) - //{{AFX_MSG_MAP(CTune) - ON_NOTIFY(UDN_DELTAPOS, IDC_SPINANG, OnDeltaposSpinang) - ON_NOTIFY(UDN_DELTAPOS, IDC_SPINFOC, OnDeltaposSpinfoc) - ON_EN_CHANGE(IDC_APPERTURE, OnChangeApperture) - ON_EN_CHANGE(IDC_FOCDIST, OnChangeFocdist) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// CTune message handlers - -void CTune::OnDeltaposSpinang(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR; - // TODO: Add your control notification handler code here - - if ( pNMUpDown->iDelta > 0 ) { - if ( m_dAngle > 2. ) - m_dAngle -= 1. ; - } - else { - if ( m_dAngle < 178. ) - m_dAngle += 1 ; - } - UpdateData ( FALSE ) ; - - OnChangeApperture() ; - - *pResult = 0; -} - -void CTune::OnDeltaposSpinfoc(NMHDR* pNMHDR, LRESULT* pResult) -{ - NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR; - // TODO: Add your control notification handler code here - - if ( pNMUpDown->iDelta > 0 ) { - m_dFocus /= 1.1 ; - } - else { - m_dFocus *= 1.1 ; - } - UpdateData ( FALSE ) ; - - OnChangeFocdist() ; - - *pResult = 0; -} - -void CTune::OnChangeApperture() -{ - // TODO: If this is a RICHEDIT control, the control will not - // send this notification unless you override the CDialog::OnInitDialog() - // function to send the EM_SETEVENTMASK message to the control - // with the ENM_CHANGE flag ORed into the lParam mask. - - // TODO: Add your control notification handler code here - - ( (CAnimationView3D *) m_pView) ->SetFocal ( m_dFocus , m_dAngle ) ; -} - -void CTune::OnChangeFocdist() -{ - // TODO: If this is a RICHEDIT control, the control will not - // send this notification unless you override the CDialog::OnInitDialog() - // function to send the EM_SETEVENTMASK message to the control - // with the ENM_CHANGE flag ORed into the lParam mask. - - // TODO: Add your control notification handler code here - - ( (CAnimationView3D *) m_pView) ->SetFocal ( m_dFocus , m_dAngle ) ; -} - -BOOL CTune::OnCommand(WPARAM wParam, LPARAM lParam) -{ - // TODO: Add your specialized code here and/or call the base class - - return CDialog::OnCommand(wParam, lParam); -} - -BOOL CTune::OnInitDialog() -{ - CDialog::OnInitDialog(); - - // TODO: Add extra initialization here - - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -BOOL CTune::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) -{ - // TODO: Add your specialized code here and/or call the base class - - return CDialog::OnNotify(wParam, lParam, pResult); -} diff --git a/samples/mfc/standard/09_Animation/src/Tune.h b/samples/mfc/standard/09_Animation/src/Tune.h deleted file mode 100755 index 53ed11783e..0000000000 --- a/samples/mfc/standard/09_Animation/src/Tune.h +++ /dev/null @@ -1,54 +0,0 @@ -#if !defined(AFX_TUNE_H__D7E45B53_AAD2_11D2_9E97_0800362A0F04__INCLUDED_) -#define AFX_TUNE_H__D7E45B53_AAD2_11D2_9E97_0800362A0F04__INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 -// Tune.h : header file -// - -///////////////////////////////////////////////////////////////////////////// -// CTune dialog - -class CTune : public CDialog -{ -// Construction -public: - CTune(CWnd* pParent = NULL); // standard constructor - CView * m_pView; - -// Dialog Data - //{{AFX_DATA(CTune) - enum { IDD = IDD_TUNE }; - double m_dAngle; - double m_dFocus; - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CTune) - protected: - virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support - virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); - virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult); - //}}AFX_VIRTUAL - -// Implementation -protected: - - // Generated message map functions - //{{AFX_MSG(CTune) - afx_msg void OnDeltaposSpinang(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnDeltaposSpinfoc(NMHDR* pNMHDR, LRESULT* pResult); - afx_msg void OnChangeApperture(); - afx_msg void OnChangeFocdist(); - virtual BOOL OnInitDialog(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(AFX_TUNE_H__D7E45B53_AAD2_11D2_9E97_0800362A0F04__INCLUDED_)