1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-19 13:40:49 +03:00

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.
This commit is contained in:
kgv
2020-06-20 23:00:17 +03:00
committed by bugmaster
parent 08b7a39f75
commit 64f128c111
12 changed files with 274 additions and 1224 deletions

View File

@@ -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()

View File

@@ -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;

File diff suppressed because it is too large Load Diff

View File

@@ -9,10 +9,12 @@
#pragma once
#endif // _MSC_VER >= 1000
#include "Tune.h"
#include "AnimationDoc.h"
#include "..\..\Common\res\OCC_Resource.h"
#include <AIS_AnimationTimer.hxx>
#include <AIS_ViewController.hxx>
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

View File

@@ -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;
}

View File

@@ -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_)

View File

@@ -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);
}

View File

@@ -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_)