1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-16 10:08:36 +03:00

0031521: Samples - update MFC ImportExport sample to use AIS_ViewController

The following MFC samples have been updated to use AIS_ViewController:
Geometry, HLR, ImportExport, Modeling, OCAF, Triangulation, Viewer2D.
This commit is contained in:
kgv 2020-04-24 17:03:20 +03:00 committed by bugmaster
parent ab9e277f15
commit 7ff18fb9cc
17 changed files with 593 additions and 1447 deletions

View File

@ -11,17 +11,9 @@
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// CNSGView // CNSGView
IMPLEMENT_DYNCREATE(CGeometryView2D, CView) IMPLEMENT_DYNCREATE(CGeometryView2D, OCC_2dView)
BEGIN_MESSAGE_MAP(CGeometryView2D, OCC_2dView) BEGIN_MESSAGE_MAP(CGeometryView2D, OCC_2dView)
//{{AFX_MSG_MAP(CGeometryView2D) //{{AFX_MSG_MAP(CGeometryView2D)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_SIZE()
//}}AFX_MSG_MAP //}}AFX_MSG_MAP
END_MESSAGE_MAP() END_MESSAGE_MAP()
@ -36,15 +28,9 @@ CGeometryView2D::~CGeometryView2D()
{ {
} }
// CNSGView drawing const Handle(AIS_InteractiveContext)& CGeometryView2D::GetAISContext() const
void CGeometryView2D::OnDraw(CDC* /*pDC*/)
{ {
CGeometryDoc* pDoc = GetDocument(); return ((CGeometryDoc*)m_pDocument)->GetISessionContext();
ASSERT_VALID(pDoc);
if (!myV2dView.IsNull())
myV2dView->Update();
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -71,239 +57,9 @@ CGeometryDoc* CGeometryView2D::GetDocument() // non-debug version is inline
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// CNSGView message handlers // CNSGView message handlers
//================================================================= //=================================================================
void CGeometryView2D::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 CurAction2d_Nothing : // start a drag
GetDocument()->DragEvent2D(point.x,point.y,-1,myV2dView);
break;
case CurAction2d_DynamicZooming : // noting
break;
case CurAction2d_WindowZooming :
break;
case CurAction2d_DynamicPanning :// noting
break;
case CurAction2d_GlobalPanning :// noting
break;
default :
throw Standard_Failure(" incompatible Current Mode ");
break;
}
}
}
void CGeometryView2D::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if ( nFlags & MK_CONTROL )
{
return;
}
else // if ( Ctrl )
{
const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetISessionContext();
switch (myCurrentMode)
{
case CurAction2d_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()->ShiftInputEvent2D(point.x,point.y,myV2dView);
else
GetDocument()->InputEvent2D (point.x,point.y,myV2dView);
} else
{
drawRectangle (myXmin,myYmin,myXmax,myYmax,aContext,Standard_False);
myXmax=point.x;
myYmax=point.y;
if (nFlags & MK_SHIFT)
GetDocument()->ShiftDragEvent2D(point.x,point.y,1,myV2dView);
else
GetDocument()->DragEvent2D(point.x,point.y,1,myV2dView);
}
break;
case CurAction2d_DynamicZooming :
// SetCursor(AfxGetApp()->LoadStandardCursor());
myCurrentMode = CurAction2d_Nothing;
break;
case CurAction2d_WindowZooming :
myXmax=point.x; myYmax=point.y;
drawRectangle (myXmin,myYmin,myXmax,myYmax,aContext,Standard_False);
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
myV2dView->WindowFit(myXmin,myYmin,myXmax,myYmax);
}
myCurrentMode = CurAction2d_Nothing;
break;
case CurAction2d_DynamicPanning :
myCurrentMode = CurAction2d_Nothing;
break;
case CurAction2d_GlobalPanning :
myV2dView->Place(point.x,point.y,myCurZoom);
myCurrentMode = CurAction2d_Nothing;
break;
default :
throw Standard_Failure(" incompatible Current Mode ");
break;
} //switch (myCurrentMode)
} // else // if ( Ctrl )
}
void CGeometryView2D::OnMButtonDown(UINT nFlags, CPoint /*point*/)
{
if ( nFlags & MK_CONTROL )
{
// Button MB2 down Control : panning init
// SetCursor(AfxGetApp()->LoadStandardCursor());
}
}
void CGeometryView2D::OnMButtonUp(UINT nFlags, CPoint /*point*/)
{
if ( nFlags & MK_CONTROL )
{
// Button MB2 up Control : panning stop
// SetCursor(AfxGetApp()->LoadStandardCursor());
}
}
void CGeometryView2D::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if ( nFlags & MK_CONTROL )
{
// SetCursor(AfxGetApp()->LoadStandardCursor());
}
else // if ( Ctrl )
{
GetDocument()->Popup2D(point.x,point.y,myV2dView);
}
}
void CGeometryView2D::OnRButtonUp(UINT /*nFlags*/, CPoint point)
{
OCC_2dView::Popup2D(point.x,point.y);
}
void CGeometryView2D::OnMouseMove(UINT nFlags, CPoint point)
{
// ============================ LEFT BUTTON =======================
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
myV2dView->Zoom(myXmax,myYmax,point.x,point.y);
// save the current mouse coordinate in min
myXmax = point.x;
myYmax = point.y;
}
else // if ( Ctrl )
{
const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetISessionContext();
switch (myCurrentMode)
{
case CurAction2d_Nothing :
myXmax = point.x;
myYmax = point.y;
GetDocument()->DragEvent2D(myXmax,myYmax,0,myV2dView);
drawRectangle (myXmin,myYmin,myXmax,myYmax, aContext);
break;
case CurAction2d_DynamicZooming :
myV2dView->Zoom(myXmax,myYmax,point.x,point.y);
// save the current mouse coordinate in min \n";
myXmax=point.x; myYmax=point.y;
break;
case CurAction2d_WindowZooming :
myXmax = point.x; myYmax = point.y;
drawRectangle (myXmin,myYmin,myXmax,myYmax, aContext);
break;
case CurAction2d_DynamicPanning :
myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
myXmax = point.x; myYmax = point.y;
break;
case CurAction2d_GlobalPanning : // nothing
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 )
{
myV2dView->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)
{
}else //if ( nFlags & MK_RBUTTON)
// ============================ NO BUTTON =======================
{ // No buttons
myXmax = point.x; myYmax = point.y;
if (nFlags & MK_SHIFT)
GetDocument()->ShiftMoveEvent2D(point.x,point.y,myV2dView);
else
GetDocument()->MoveEvent2D(point.x,point.y,myV2dView);
}
}
void CGeometryView2D::OnSize(UINT nType, int cx, int cy)
{
OCC_2dView::OnSize (nType, cx, cy);
if (!myV2dView.IsNull())
{
myV2dView->MustBeResized(); // added sro
}
}
void CGeometryView2D::OnInitialUpdate() void CGeometryView2D::OnInitialUpdate()
{ {
Handle(WNT_Window) aWNTWindow; OCC_2dView::OnInitialUpdate();
aWNTWindow = new WNT_Window(GetSafeHwnd()); myView->SetBackgroundColor (Quantity_NOC_BLACK);
myV2dView = GetDocument()->GetViewer2D()->CreateView();
myV2dView->SetWindow(aWNTWindow);
myV2dView->SetBackgroundColor(Quantity_NOC_BLACK);
// initialyse the grids dialogs
TheRectangularGridDialog.Create(CRectangularGrid::IDD, NULL);
TheCircularGridDialog.Create(CCircularGrid::IDD, NULL);
TheRectangularGridDialog.SetViewer (GetDocument()->GetViewer2D());
TheCircularGridDialog.SetViewer (GetDocument()->GetViewer2D());
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 ) ;
} }

View File

@ -28,7 +28,6 @@ public:
// Overrides // Overrides
// ClassWizard generated virtual function overrides // ClassWizard generated virtual function overrides
public: public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual void OnInitialUpdate(); // called first time after construct virtual void OnInitialUpdate(); // called first time after construct
// Implementation // Implementation
@ -39,17 +38,12 @@ public:
virtual void Dump(CDumpContext& dc) const; virtual void Dump(CDumpContext& dc) const;
#endif #endif
//! Return interactive context for 2d presentations.
virtual const Handle(AIS_InteractiveContext)& GetAISContext() const Standard_OVERRIDE;
// Generated message map functions // Generated message map functions
protected: protected:
//{{AFX_MSG(CGeometryView2D) //{{AFX_MSG(CGeometryView2D)
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG //}}AFX_MSG
DECLARE_MESSAGE_MAP() DECLARE_MESSAGE_MAP()
}; };

View File

@ -128,7 +128,7 @@ void CHLRDoc::FitAll2DViews(Standard_Boolean UpdateViewer)
if(pCurrentView->IsKindOf(RUNTIME_CLASS(OCC_2dView)) ) if(pCurrentView->IsKindOf(RUNTIME_CLASS(OCC_2dView)) )
{ {
ASSERT_VALID(pCurrentView); ASSERT_VALID(pCurrentView);
((OCC_2dView*)pCurrentView)->GetV2dView()->FitAll(); ((OCC_2dView*)pCurrentView)->FitAll();
} }
} }
} }

View File

@ -8,23 +8,12 @@
#include "resource2d\RectangularGrid.h" #include "resource2d\RectangularGrid.h"
#include "resource2d\CircularGrid.h" #include "resource2d\CircularGrid.h"
#define ValZWMin 1
#ifdef _DEBUG #ifdef _DEBUG
//#define new DEBUG_NEW //#define new DEBUG_NEW
#undef THIS_FILE #undef THIS_FILE
static char THIS_FILE[] = __FILE__; static char THIS_FILE[] = __FILE__;
#endif #endif
// the key for multi selection :
#define MULTISELECTIONKEY MK_SHIFT
// the key for shortcut ( use to activate dynamic rotation, panning )
#define CASCADESHORTCUTKEY MK_CONTROL
// define in witch case you want to display the popup
#define POPUPONBUTTONDOWN
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// CHLRView2D // CHLRView2D
@ -32,7 +21,6 @@ IMPLEMENT_DYNCREATE(CHLRView2D, OCC_2dView)
BEGIN_MESSAGE_MAP(CHLRView2D, OCC_2dView) BEGIN_MESSAGE_MAP(CHLRView2D, OCC_2dView)
//{{AFX_MSG_MAP(CHLRView2D) //{{AFX_MSG_MAP(CHLRView2D)
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP //}}AFX_MSG_MAP
END_MESSAGE_MAP() END_MESSAGE_MAP()
@ -41,170 +29,26 @@ END_MESSAGE_MAP()
CHLRView2D::CHLRView2D() CHLRView2D::CHLRView2D()
{ {
/// TODO
/// Override MouseMove event to exclude rectangle selection emulation as
/// no selection is supported in DragEvent2D for this view.
} }
CHLRView2D::~CHLRView2D() CHLRView2D::~CHLRView2D()
{ {
} }
const Handle(AIS_InteractiveContext)& CHLRView2D::GetAISContext() const
{
return ((CHLRDoc*)m_pDocument)->GetInteractiveContext2D();
}
CHLRDoc* CHLRView2D::GetDocument() // non-debug version is inline CHLRDoc* CHLRView2D::GetDocument() // non-debug version is inline
{ {
//ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(OCC_2dDoc))); //ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(OCC_2dDoc)));
return (CHLRDoc*)m_pDocument; return (CHLRDoc*)m_pDocument;
} }
void CHLRView2D::OnInitialUpdate()
{
Handle(WNT_Window) aWNTWindow;
aWNTWindow = new WNT_Window(GetSafeHwnd(),Quantity_NOC_GRAY);
myV2dView = GetDocument()->GetViewer2D()->CreateView();
myV2dView->SetWindow(aWNTWindow);
// initialyse the grids dialogs
TheRectangularGridDialog.Create(CRectangularGrid::IDD, NULL);
TheCircularGridDialog.Create(CCircularGrid::IDD, NULL);
TheRectangularGridDialog.SetViewer (GetDocument()->GetViewer2D());
TheCircularGridDialog.SetViewer (GetDocument()->GetViewer2D());
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 ) ;
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CHLRView2D::DragEvent2D(const Standard_Integer /*x*/,
const Standard_Integer /*y*/,
const Standard_Integer /*TheState*/)
{
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CHLRView2D::InputEvent2D(const Standard_Integer /*x*/,
const Standard_Integer /*y*/)
{
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CHLRView2D::MoveEvent2D(const Standard_Integer /*x*/,
const Standard_Integer /*y*/)
{
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CHLRView2D::MultiMoveEvent2D(const Standard_Integer /*x*/,
const Standard_Integer /*y*/)
{
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CHLRView2D::MultiDragEvent2D(const Standard_Integer /*x*/,
const Standard_Integer /*y*/,
const Standard_Integer /*TheState*/)
{
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CHLRView2D::MultiInputEvent2D(const Standard_Integer /*x*/,
const Standard_Integer /*y*/)
{
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void CHLRView2D::OnMouseMove(UINT nFlags, CPoint point)
{
if ( (nFlags & MK_LBUTTON) &! (nFlags & MK_RBUTTON) ) // Left + Right is specific
{
if ( nFlags & CASCADESHORTCUTKEY )
{
// move with MB1 and CASCADESHORTCUTKEY : on the dynamic zooming
// Do the zoom in function of mouse's coordinates
myV2dView->Zoom(myXmax,myYmax,point.x,point.y);
myXmax = point.x;
myYmax = point.y;
}
else // if ( CASCADESHORTCUTKEY )
{
switch (myCurrentMode)
{
case CurAction2d_Nothing :
myXmax = point.x;
myYmax = point.y;
DragEvent2D(myXmax,myYmax,0);
break;
case CurAction2d_DynamicZooming :
myV2dView->Zoom(myXmax,myYmax,point.x,point.y);
myXmax=point.x;
myYmax=point.y;
break;
case CurAction2d_WindowZooming :
myXmax = point.x;
myYmax = point.y;
break;
case CurAction2d_DynamicPanning :
myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
myXmax = point.x;
myYmax = point.y;
break;
case CurAction2d_GlobalPanning :
break;
default :
throw Standard_Failure(" incompatible Current Mode ");
break;
}
}
} else if ( nFlags & MK_MBUTTON)
{
if ( nFlags & CASCADESHORTCUTKEY )
{
myV2dView->Pan (point.x-myXmax,myYmax-point.y);
myXmax = point.x;
myYmax = point.y;
}
} else if ( (nFlags & MK_RBUTTON) &! (nFlags & MK_LBUTTON) )
{
}
else if ( (nFlags & MK_RBUTTON) && (nFlags & MK_LBUTTON) )
{
if ( nFlags & CASCADESHORTCUTKEY )
{
myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
myXmax = point.x; myYmax = point.y;
}
}
else
{ // No buttons
myXmax = point.x;
myYmax = point.y;
if (nFlags & MULTISELECTIONKEY)
{
MultiMoveEvent2D(point.x,point.y);
}
else
{
MoveEvent2D(point.x,point.y);
}
}
}
#ifdef _DEBUG #ifdef _DEBUG
void CHLRView2D::AssertValid() const void CHLRView2D::AssertValid() const
{ {

View File

@ -20,37 +20,15 @@ class CHLRView2D : public OCC_2dView
protected: // create from serialization only protected: // create from serialization only
CHLRView2D(); CHLRView2D();
DECLARE_DYNCREATE(CHLRView2D) DECLARE_DYNCREATE(CHLRView2D)
// Override MouseMove event to exclude rectangle selection emulation as
// no selection is supported in DragEvent2D for this view.
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
DECLARE_MESSAGE_MAP() DECLARE_MESSAGE_MAP()
// Overrides //! Return interactive context for HLR presentations.
// ClassWizard generated virtual function overrides virtual const Handle(AIS_InteractiveContext)& GetAISContext() const Standard_OVERRIDE;
//{{AFX_VIRTUAL(CHLRView2D)
protected:
virtual void OnInitialUpdate(); // called first time after construct
//}}AFX_VIRTUAL
// Implementation // Implementation
public: public:
virtual ~CHLRView2D(); virtual ~CHLRView2D();
CHLRDoc* GetDocument(); CHLRDoc* GetDocument();
virtual void DragEvent2D (const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer TheState);
virtual void InputEvent2D (const Standard_Integer x,
const Standard_Integer y);
virtual void MoveEvent2D (const Standard_Integer x,
const Standard_Integer y );
virtual void MultiMoveEvent2D (const Standard_Integer x,
const Standard_Integer y );
virtual void MultiDragEvent2D (const Standard_Integer x,
const Standard_Integer y ,
const Standard_Integer TheState);
virtual void MultiInputEvent2D (const Standard_Integer x,
const Standard_Integer y );
#ifdef _DEBUG #ifdef _DEBUG
virtual void AssertValid() const; virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const; virtual void Dump(CDumpContext& dc) const;

View File

@ -18,8 +18,7 @@ IMPLEMENT_DYNCREATE(OCC_2dDoc, CDocument)
OCC_2dDoc::OCC_2dDoc() : OCC_BaseDoc() OCC_2dDoc::OCC_2dDoc() : OCC_BaseDoc()
{ {
// Get the Graphic Driver from the application // Get the Graphic Driver from the application
Handle(Graphic3d_GraphicDriver) aGraphicDriver = Handle(Graphic3d_GraphicDriver) aGraphicDriver = ((OCC_App*)AfxGetApp())->GetGraphicDriver();
((OCC_App*)AfxGetApp())->GetGraphicDriver();
// create the Viewer // create the Viewer
myViewer = new V3d_Viewer (aGraphicDriver); myViewer = new V3d_Viewer (aGraphicDriver);
@ -52,20 +51,23 @@ void OCC_2dDoc::FitAll2DViews(Standard_Boolean theUpdateViewer)
{ {
OCC_2dView* aCurrentView = (OCC_2dView*)GetNextView (aPosition); OCC_2dView* aCurrentView = (OCC_2dView*)GetNextView (aPosition);
ASSERT_VALID (aCurrentView); ASSERT_VALID (aCurrentView);
aCurrentView->GetV2dView()->FitAll(); aCurrentView->GetView()->FitAll();
} }
} }
void OCC_2dDoc::MoveEvent(const Standard_Integer theMouseX, void OCC_2dDoc::Popup (const Standard_Integer theMouseX,
const Standard_Integer theMouseY, const Standard_Integer theMouseY,
const Handle(V3d_View)& theView) const Handle(V3d_View)& theView)
{ {
myAISContext->MoveTo (theMouseX, theMouseY, theView, Standard_True); // load the 'normal' popup
} CMenu aMenu;
VERIFY(aMenu.LoadMenu(IDR_Popup2D));
// activate the sub menu '0'
CMenu* aPopup = aMenu.GetSubMenu(0);
ASSERT(aPopup != NULL);
void OCC_2dDoc::ShiftMoveEvent(const Standard_Integer theMouseX, // display the popup
const Standard_Integer theMouseY, POINT aWinCoord = { theMouseX, theMouseY };
const Handle(V3d_View)& theView) ClientToScreen ((HWND )theView->Window()->NativeHandle(), &aWinCoord);
{ aPopup->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, aWinCoord.x, aWinCoord.y, AfxGetMainWnd());
myAISContext->MoveTo (theMouseX, theMouseY, theView, Standard_True);
} }

View File

@ -28,23 +28,11 @@ public: // New operations
void FitAll2DViews(Standard_Boolean theUpdateViewer = Standard_False); void FitAll2DViews(Standard_Boolean theUpdateViewer = Standard_False);
public: // getters
Handle(V3d_Viewer) GetViewer2D () { return myViewer; };
Handle(AIS_InteractiveContext)& GetInteractiveContext() { return myAISContext; };
public: // Operations to override public: // Operations to override
// Mouse move event tracking for 2D view : no rotation is supported in 2D view. virtual void Popup (const Standard_Integer theMouseX,
virtual void MoveEvent(const Standard_Integer theMouseX,
const Standard_Integer theMouseY, const Standard_Integer theMouseY,
const Handle(V3d_View)& theView); const Handle(V3d_View)& theView) Standard_OVERRIDE;
// Shift move event tracking for 2D view : no rotation is supported in 2D view.
virtual void ShiftMoveEvent(const Standard_Integer theMouseX,
const Standard_Integer theMouseY,
const Handle(V3d_View)& theViewView);
}; };
#endif // !defined(AFX_OCC_2dDOC_H__2E048CC7_38F9_11D7_8611_0060B0EE281E__INCLUDED_) #endif // !defined(AFX_OCC_2dDOC_H__2E048CC7_38F9_11D7_8611_0060B0EE281E__INCLUDED_)

View File

@ -13,23 +13,12 @@
#include "Quantity_Color.hxx" #include "Quantity_Color.hxx"
#include "Quantity_NameOfColor.hxx" #include "Quantity_NameOfColor.hxx"
#define ValZWMin 1
// the key for multi selection :
#define MULTISELECTIONKEY MK_SHIFT
// the key for shortcut ( use to activate dynamic rotation, panning )
#define CASCADESHORTCUTKEY MK_CONTROL
// define in witch case you want to display the popup
#define POPUPONBUTTONDOWN
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// OCC_2dView // OCC_2dView
IMPLEMENT_DYNCREATE(OCC_2dView, CView) IMPLEMENT_DYNCREATE(OCC_2dView, OCC_BaseView)
BEGIN_MESSAGE_MAP(OCC_2dView, CView) BEGIN_MESSAGE_MAP(OCC_2dView, OCC_BaseView)
//{{AFX_MSG_MAP(OCC_2dView) //{{AFX_MSG_MAP(OCC_2dView)
// NOTE - the ClassWizard will add and remove mapping macros here. // NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code! // DO NOT EDIT what you see in these blocks of generated code!
@ -42,13 +31,6 @@ BEGIN_MESSAGE_MAP(OCC_2dView, CView)
ON_UPDATE_COMMAND_UI(ID_BUTTON2DGridValues, OnUpdateBUTTONGridValues) ON_UPDATE_COMMAND_UI(ID_BUTTON2DGridValues, OnUpdateBUTTONGridValues)
ON_COMMAND(ID_BUTTON2DGridCancel, OnBUTTONGridCancel) ON_COMMAND(ID_BUTTON2DGridCancel, OnBUTTONGridCancel)
ON_UPDATE_COMMAND_UI(ID_BUTTON2DGridCancel, OnUpdateBUTTONGridCancel) ON_UPDATE_COMMAND_UI(ID_BUTTON2DGridCancel, OnUpdateBUTTONGridCancel)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_SIZE() ON_WM_SIZE()
ON_COMMAND(ID_BUTTON2DFitAll, OnBUTTONFitAll) ON_COMMAND(ID_BUTTON2DFitAll, OnBUTTONFitAll)
ON_COMMAND(ID_BUTTON2DGlobPanning, OnBUTTONGlobPanning) ON_COMMAND(ID_BUTTON2DGlobPanning, OnBUTTONGlobPanning)
@ -67,57 +49,34 @@ END_MESSAGE_MAP()
// OCC_2dView construction/destruction // OCC_2dView construction/destruction
OCC_2dView::OCC_2dView() OCC_2dView::OCC_2dView()
: myCurrentMode (CurAction2d_Nothing)
{ {
myToAllowRotation = false;
myDefaultGestures.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_SelectRectangle);
myMouseGestureMap = myDefaultGestures;
} }
OCC_2dView::~OCC_2dView() OCC_2dView::~OCC_2dView()
{ {
myV2dView->Remove(); //
}
BOOL OCC_2dView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
return CView::PreCreateWindow(cs);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// OCC_2dView drawing // OCC_2dView drawing
void OCC_2dView::OnDraw(CDC* /*pDC*/)
{
if (!myV2dView.IsNull())
myV2dView->Update();
}
void OCC_2dView::OnInitialUpdate() void OCC_2dView::OnInitialUpdate()
{ {
CView::OnInitialUpdate(); OCC_BaseView::OnInitialUpdate();
Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd(),Quantity_NOC_MATRAGRAY);
myV2dView =((OCC_2dDoc*)GetDocument())->GetViewer2D()->CreateView();
myV2dView->SetWindow(aWNTWindow);
// initialize the grids dialogs // initialize the grids dialogs
TheRectangularGridDialog.Create(CRectangularGrid::IDD, NULL); TheRectangularGridDialog.Create(CRectangularGrid::IDD, NULL);
TheCircularGridDialog.Create(CCircularGrid::IDD, NULL); TheCircularGridDialog.Create(CCircularGrid::IDD, NULL);
TheRectangularGridDialog.SetViewer (((OCC_2dDoc*)GetDocument())->GetViewer2D()); TheRectangularGridDialog.SetViewer (myView->Viewer());
TheCircularGridDialog.SetViewer (((OCC_2dDoc*)GetDocument())->GetViewer2D()); TheCircularGridDialog.SetViewer (myView->Viewer());
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 ) ;
} }
void OCC_2dView::OnFileExportImage() void OCC_2dView::OnFileExportImage()
{ {
GetDocument()->ExportView (myV2dView); GetDocument()->ExportView (myView);
} }
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -142,11 +101,11 @@ OCC_2dDoc* OCC_2dView::GetDocument() // non-debug version is inline
#endif //_DEBUG #endif //_DEBUG
void OCC_2dView::OnBUTTONGridRectLines() void OCC_2dView::OnBUTTONGridRectLines()
{ {
Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); Handle(V3d_Viewer) aViewer = myView->Viewer();
Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2); Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
aViewer->SetGridEcho(aGridAspect); aViewer->SetGridEcho(aGridAspect);
Standard_Integer aWidth=0, aHeight=0, anOffset=0; Standard_Integer aWidth=0, aHeight=0, anOffset=0;
myV2dView->Window()->Size(aWidth,aHeight); myView->Window()->Size(aWidth,aHeight);
aViewer->SetRectangularGridGraphicValues(aWidth,aHeight,anOffset); aViewer->SetRectangularGridGraphicValues(aWidth,aHeight,anOffset);
aViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Lines); aViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Lines);
FitAll(); FitAll();
@ -161,11 +120,11 @@ void OCC_2dView::OnBUTTONGridRectLines()
void OCC_2dView::OnBUTTONGridRectPoints() void OCC_2dView::OnBUTTONGridRectPoints()
{ {
Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); Handle(V3d_Viewer) aViewer = myView->Viewer();
Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2); Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
aViewer->SetGridEcho(aGridAspect); aViewer->SetGridEcho(aGridAspect);
Standard_Integer aWidth=0, aHeight=0, anOffset=0; Standard_Integer aWidth=0, aHeight=0, anOffset=0;
myV2dView->Window()->Size(aWidth,aHeight); myView->Window()->Size(aWidth,aHeight);
aViewer->SetRectangularGridGraphicValues(aWidth,aHeight,anOffset); aViewer->SetRectangularGridGraphicValues(aWidth,aHeight,anOffset);
aViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Points); aViewer->ActivateGrid(Aspect_GT_Rectangular, Aspect_GDM_Points);
FitAll(); FitAll();
@ -180,11 +139,11 @@ void OCC_2dView::OnBUTTONGridRectPoints()
void OCC_2dView::OnBUTTONGridCircLines() void OCC_2dView::OnBUTTONGridCircLines()
{ {
Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); Handle(V3d_Viewer) aViewer = myView->Viewer();
Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2); Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
aViewer->SetGridEcho(aGridAspect); aViewer->SetGridEcho(aGridAspect);
Standard_Integer aWidth=0, aHeight=0, anOffset=0; Standard_Integer aWidth=0, aHeight=0, anOffset=0;
myV2dView->Window()->Size(aWidth,aHeight); myView->Window()->Size(aWidth,aHeight);
aViewer->SetCircularGridGraphicValues(aWidth>aHeight?aWidth:aHeight,anOffset); aViewer->SetCircularGridGraphicValues(aWidth>aHeight?aWidth:aHeight,anOffset);
aViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Lines); aViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Lines);
FitAll(); FitAll();
@ -200,11 +159,11 @@ void OCC_2dView::OnBUTTONGridCircLines()
void OCC_2dView::OnBUTTONGridCircPoints() void OCC_2dView::OnBUTTONGridCircPoints()
{ {
Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); Handle(V3d_Viewer) aViewer = myView->Viewer();
Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2); Handle(Graphic3d_AspectMarker3d) aGridAspect = new Graphic3d_AspectMarker3d(Aspect_TOM_RING1,Quantity_NOC_WHITE,2);
aViewer->SetGridEcho(aGridAspect); aViewer->SetGridEcho(aGridAspect);
Standard_Integer aWidth=0, aHeight=0, anOffset=0; Standard_Integer aWidth=0, aHeight=0, anOffset=0;
myV2dView->Window()->Size(aWidth,aHeight); myView->Window()->Size(aWidth,aHeight);
aViewer->SetCircularGridGraphicValues(aWidth>aHeight?aWidth:aHeight,anOffset); aViewer->SetCircularGridGraphicValues(aWidth>aHeight?aWidth:aHeight,anOffset);
aViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Points); aViewer->ActivateGrid(Aspect_GT_Circular, Aspect_GDM_Points);
FitAll(); FitAll();
@ -218,7 +177,7 @@ void OCC_2dView::OnBUTTONGridCircPoints()
void OCC_2dView::OnBUTTONGridValues() void OCC_2dView::OnBUTTONGridValues()
{ {
Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); Handle(V3d_Viewer) aViewer = myView->Viewer();
Aspect_GridType TheGridtype = aViewer->GridType(); Aspect_GridType TheGridtype = aViewer->GridType();
switch( TheGridtype ) switch( TheGridtype )
@ -237,13 +196,13 @@ void OCC_2dView::OnBUTTONGridValues()
} }
void OCC_2dView::OnUpdateBUTTONGridValues(CCmdUI* pCmdUI) void OCC_2dView::OnUpdateBUTTONGridValues(CCmdUI* pCmdUI)
{ {
Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); Handle(V3d_Viewer) aViewer = myView->Viewer();
pCmdUI-> Enable( aViewer->IsActive() ); pCmdUI-> Enable( aViewer->IsActive() );
} }
void OCC_2dView::OnBUTTONGridCancel() void OCC_2dView::OnBUTTONGridCancel()
{ {
Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); Handle(V3d_Viewer) aViewer = myView->Viewer();
aViewer->DeactivateGrid(); aViewer->DeactivateGrid();
TheRectangularGridDialog.ShowWindow(SW_HIDE); TheRectangularGridDialog.ShowWindow(SW_HIDE);
TheCircularGridDialog.ShowWindow(SW_HIDE); TheCircularGridDialog.ShowWindow(SW_HIDE);
@ -251,266 +210,50 @@ void OCC_2dView::OnBUTTONGridCancel()
} }
void OCC_2dView::OnUpdateBUTTONGridCancel(CCmdUI* pCmdUI) void OCC_2dView::OnUpdateBUTTONGridCancel(CCmdUI* pCmdUI)
{ {
Handle(V3d_Viewer) aViewer = myV2dView->Viewer(); Handle(V3d_Viewer) aViewer = myView->Viewer();
pCmdUI-> Enable( aViewer->IsActive() ); pCmdUI-> Enable( aViewer->IsActive() );
} }
void OCC_2dView::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 & CASCADESHORTCUTKEY )
{
// Button MB1 down Control :start zomming
//
}
else // if ( MULTISELECTIONKEY )
{
switch (myCurrentMode)
{
case CurAction2d_Nothing : // start a drag
DragEvent2D(point.x,point.y,-1);
break;
case CurAction2d_DynamicZooming : // nothing
break;
case CurAction2d_WindowZooming : // nothing
break;
case CurAction2d_DynamicPanning :// nothing
break;
case CurAction2d_GlobalPanning :// nothing
break;
default :
throw Standard_Failure(" incompatible Current Mode ");
break;
}
}
}
void OCC_2dView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if ( nFlags & CASCADESHORTCUTKEY )
{
return;
}
else // if ( Ctrl )
{
const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetAISContext();
switch (myCurrentMode)
{
case CurAction2d_Nothing :
if (point.x == myXmin && point.y == myYmin)
{ // no offset between down and up --> selectEvent
myXmax=point.x;
myYmax=point.y;
if (nFlags & MULTISELECTIONKEY )
MultiInputEvent2D(point.x,point.y);
else
InputEvent2D (point.x,point.y);
} else
{
drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext, Standard_False);
myXmax=point.x;
myYmax=point.y;
if (nFlags & MULTISELECTIONKEY)
MultiDragEvent2D(point.x,point.y,1);
else
DragEvent2D(point.x,point.y,1);
}
break;
case CurAction2d_DynamicZooming :
//
myCurrentMode = CurAction2d_Nothing;
break;
case CurAction2d_WindowZooming :
myXmax=point.x; myYmax=point.y;
drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext, Standard_False);
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
myV2dView->WindowFit(myXmin,myYmin,myXmax,myYmax);
}
myCurrentMode = CurAction2d_Nothing;
break;
case CurAction2d_DynamicPanning :
myCurrentMode = CurAction2d_Nothing;
break;
case CurAction2d_GlobalPanning :
myV2dView->Place(point.x,point.y,myCurZoom);
myCurrentMode = CurAction2d_Nothing;
break;
default :
throw Standard_Failure(" incompatible Current Mode ");
break;
} //switch (myCurrentMode)
} // else // if ( CASCADESHORTCUTKEY )
}
void OCC_2dView::OnMButtonDown(UINT nFlags, CPoint /*point*/)
{
if ( nFlags & CASCADESHORTCUTKEY )
{
// Button MB2 down + CASCADESHORTCUTKEY : panning init
//
}
}
void OCC_2dView::OnMButtonUp(UINT nFlags, CPoint /*point*/)
{
if ( nFlags & CASCADESHORTCUTKEY )
{
// Button MB2 up + CASCADESHORTCUTKEY : panning stop
}
}
void OCC_2dView::OnRButtonDown(UINT nFlags, CPoint point)
{
#ifdef POPUPONBUTTONDOWN
if ( !(nFlags & CASCADESHORTCUTKEY) )
Popup2D(point.x,point.y);
#endif
}
void OCC_2dView::OnRButtonUp(UINT
#ifndef POPUPONBUTTONDOWN
nFlags
#endif
, CPoint
#ifndef POPUPONBUTTONDOWN
point
#endif
)
{
#ifndef POPUPONBUTTONDOWN
if ( !(nFlags & CASCADESHORTCUTKEY) )
Popup2D(point.x,point.y);
#endif
}
void OCC_2dView::OnMouseMove(UINT nFlags, CPoint point)
{
// ============================ LEFT BUTTON =======================
if ( (nFlags & MK_LBUTTON) &! (nFlags & MK_RBUTTON) ) // Left + Right is specific
{
if ( nFlags & CASCADESHORTCUTKEY )
{
// move with MB1 and CASCADESHORTCUTKEY : on the dynamic zooming
// Do the zoom in function of mouse's coordinates
myV2dView->Zoom(myXmax,myYmax,point.x,point.y);
// save the current mouse coordinate in min
myXmax = point.x;
myYmax = point.y;
}
else // if ( CASCADESHORTCUTKEY )
{
const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetAISContext();
switch (myCurrentMode)
{
case CurAction2d_Nothing :
myXmax = point.x; myYmax = point.y;
DragEvent2D(myXmax,myYmax,0);
drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext);
break;
case CurAction2d_DynamicZooming :
myV2dView->Zoom(myXmax,myYmax,point.x,point.y);
// save the current mouse coordinate in min \n";
myXmax=point.x; myYmax=point.y;
break;
case CurAction2d_WindowZooming :
myXmax = point.x;
myYmax = point.y;
drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext);
break;
case CurAction2d_DynamicPanning :
myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
myXmax = point.x; myYmax = point.y;
break;
case CurAction2d_GlobalPanning : // nothing
break;
default :
throw Standard_Failure(" incompatible Current Mode ");
break;
}// switch (myCurrentMode)
}// if ( nFlags & CASCADESHORTCUTKEY ) else
} else // if ( nFlags & MK_LBUTTON)
// ============================ MIDDLE BUTTON =======================
if ( nFlags & MK_MBUTTON)
{
if ( nFlags & CASCADESHORTCUTKEY )
{
myV2dView->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) &! (nFlags & MK_LBUTTON) ) // Left + Right is specific
{
}else //if ( nFlags & MK_RBUTTON)
if ( (nFlags & MK_RBUTTON) && (nFlags & MK_LBUTTON) )
{
// in case of Left + Right : same as Middle
if ( nFlags & CASCADESHORTCUTKEY )
{
myV2dView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
myXmax = point.x; myYmax = point.y;
}
}else //if ( nFlags & MK_RBUTTON)&& (nFlags & MK_LBUTTON)
// ============================ NO BUTTON =======================
{ // No buttons
myXmax = point.x; myYmax = point.y;
if (nFlags & MULTISELECTIONKEY)
MultiMoveEvent2D(point.x,point.y);
else
MoveEvent2D(point.x,point.y);
}
}
void OCC_2dView::OnSize(UINT nType, int cx, int cy) void OCC_2dView::OnSize(UINT nType, int cx, int cy)
{ {
OCC_BaseView::OnSize (nType, cx, cy); OCC_BaseView::OnSize (nType, cx, cy);
// Take care : This fonction is call before OnInitialUpdate // Take care : This fonction is call before OnInitialUpdate
if (!myV2dView.IsNull()) if (!myView.IsNull())
myV2dView->MustBeResized(); myView->MustBeResized();
} }
void OCC_2dView::OnBUTTONFitAll() void OCC_2dView::OnBUTTONFitAll()
{ {
myV2dView->FitAll(); myView->FitAll();
} }
void OCC_2dView::OnBUTTONGlobPanning() void OCC_2dView::OnBUTTONGlobPanning()
{ {
//save the current zoom value //save the current zoom value
myCurZoom = myV2dView->Scale(); myCurZoom = myView->Scale();
// Do a Global Zoom // Do a Global Zoom
myV2dView->FitAll(); myView->FitAll();
// Set the mode // Set the mode
myCurrentMode = CurAction2d_GlobalPanning; setCurrentAction (CurAction3d_GlobalPanning);
} }
void OCC_2dView::OnBUTTONPanning() void OCC_2dView::OnBUTTONPanning()
{ {
myCurrentMode = CurAction2d_DynamicPanning; setCurrentAction (CurAction3d_DynamicPanning);
} }
void OCC_2dView::OnBUTTONZoomProg() void OCC_2dView::OnBUTTONZoomProg()
{ {
myCurrentMode = CurAction2d_DynamicZooming; setCurrentAction (CurAction3d_DynamicZooming);
} }
void OCC_2dView::OnBUTTONZoomWin() void OCC_2dView::OnBUTTONZoomWin()
{ {
myCurrentMode = CurAction2d_WindowZooming; setCurrentAction (CurAction3d_WindowZooming);
} }
void OCC_2dView::OnChangeBackground() void OCC_2dView::OnChangeBackground()
{ {
Standard_Real R1, G1, B1; Standard_Real R1, G1, B1;
Handle(Aspect_Window) aWindow = myV2dView->Window(); Handle(Aspect_Window) aWindow = myView->Window();
Aspect_Background ABack = aWindow->Background(); Aspect_Background ABack = aWindow->Background();
Quantity_Color aColor = ABack.Color(); Quantity_Color aColor = ABack.Color();
aColor.Values(R1,G1,B1,Quantity_TOC_RGB); aColor.Values(R1,G1,B1,Quantity_TOC_RGB);
@ -525,166 +268,32 @@ void OCC_2dView::OnChangeBackground()
G1 = GetGValue(m_clr)/255.; G1 = GetGValue(m_clr)/255.;
B1 = GetBValue(m_clr)/255.; B1 = GetBValue(m_clr)/255.;
aColor.SetValues(R1,G1,B1,Quantity_TOC_RGB); aColor.SetValues(R1,G1,B1,Quantity_TOC_RGB);
myV2dView->SetBackgroundColor(aColor); myView->SetBackgroundColor(aColor);
myV2dView->Update(); myView->Update();
} }
} }
void OCC_2dView::OnUpdateBUTTON2DGlobPanning(CCmdUI* pCmdUI) void OCC_2dView::OnUpdateBUTTON2DGlobPanning(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myCurrentMode == CurAction2d_GlobalPanning); pCmdUI->SetCheck (getCurrentAction() == CurAction3d_GlobalPanning);
pCmdUI->Enable (myCurrentMode != CurAction2d_GlobalPanning); pCmdUI->Enable (getCurrentAction() != CurAction3d_GlobalPanning);
} }
void OCC_2dView::OnUpdateBUTTON2DPanning(CCmdUI* pCmdUI) void OCC_2dView::OnUpdateBUTTON2DPanning(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myCurrentMode == CurAction2d_DynamicPanning); pCmdUI->SetCheck (getCurrentAction() == CurAction3d_DynamicPanning);
pCmdUI->Enable (myCurrentMode != CurAction2d_DynamicPanning); pCmdUI->Enable (getCurrentAction() != CurAction3d_DynamicPanning);
} }
void OCC_2dView::OnUpdateBUTTON2DZoomProg(CCmdUI* pCmdUI) void OCC_2dView::OnUpdateBUTTON2DZoomProg(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myCurrentMode == CurAction2d_DynamicZooming); pCmdUI->SetCheck (getCurrentAction() == CurAction3d_DynamicZooming);
pCmdUI->Enable (myCurrentMode != CurAction2d_DynamicZooming); pCmdUI->Enable (getCurrentAction() != CurAction3d_DynamicZooming);
} }
void OCC_2dView::OnUpdateBUTTON2DZoomWin(CCmdUI* pCmdUI) void OCC_2dView::OnUpdateBUTTON2DZoomWin(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myCurrentMode == CurAction2d_WindowZooming); pCmdUI->SetCheck (getCurrentAction() == CurAction3d_WindowZooming);
pCmdUI->Enable (myCurrentMode != CurAction2d_WindowZooming); pCmdUI->Enable (getCurrentAction() != CurAction3d_WindowZooming);
}
// =====================================================================
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void OCC_2dView::DragEvent2D(const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer TheState)
{
// 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 == 0)
{
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo (x, y, myV2dView, Standard_False);
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->Select (theButtonDownX, theButtonDownY, x, y, myV2dView, Standard_True);
}
if (TheState == 1)
{
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->Select(true);
}
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void OCC_2dView::InputEvent2D(const Standard_Integer /*x*/,
const Standard_Integer /*y*/)
{
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->Select(true);
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void OCC_2dView::MoveEvent2D(const Standard_Integer x,
const Standard_Integer y)
{
if(myV2dView->Viewer()->Grid()->IsActive())
{
Standard_Real aGridX=0,aGridY=0,aGridZ=0;
myV2dView->ConvertToGrid(x,y,aGridX,aGridY,aGridZ);
//View is not updated automatically in ConvertToGrid
myV2dView->Update();
}
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo (x, y, myV2dView, Standard_True);
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void OCC_2dView::MultiMoveEvent2D(const Standard_Integer x,
const Standard_Integer y)
{
// MultiMoveEvent2D means we move the mouse in a multi selection mode
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo (x, y, myV2dView, Standard_True);
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void OCC_2dView::MultiDragEvent2D(const Standard_Integer x ,
const Standard_Integer y ,
const Standard_Integer TheState)
{
static Standard_Integer theButtonDownX=0;
static Standard_Integer theButtonDownY=0;
if (TheState == -1)
{
theButtonDownX=x;
theButtonDownY=y;
}
if (TheState == 0)
{
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->MoveTo (x, y, myV2dView, Standard_False);
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->ShiftSelect (theButtonDownX, theButtonDownY, x, y, myV2dView, Standard_True);
}
if (TheState == 1)
{
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->ShiftSelect(true);
}
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void OCC_2dView::MultiInputEvent2D(const Standard_Integer /*x*/,
const Standard_Integer /*y*/)
{
((OCC_2dDoc*)GetDocument())->GetInteractiveContext()->ShiftSelect(true);
}
//-----------------------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------------------
void OCC_2dView::Popup2D(const Standard_Integer x,
const Standard_Integer y )
{
CMenu menu;
CMenu* pPopup ;
// load the 'normal' popup
VERIFY(menu.LoadMenu(IDR_Popup2D));
// activate the sub menu '0'
pPopup= menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
// display the popup
POINT winCoord = { x , y };
ClientToScreen ( &winCoord);
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON , winCoord.x, winCoord.y , AfxGetMainWnd());
}
void OCC_2dView::FitAll()
{
myV2dView->FitAll();
} }

View File

@ -14,15 +14,6 @@
#include "Resource2d/RectangularGrid.h" #include "Resource2d/RectangularGrid.h"
#include "Resource2d/CircularGrid.h" #include "Resource2d/CircularGrid.h"
enum CurrentAction2d
{
CurAction2d_Nothing,
CurAction2d_DynamicZooming,
CurAction2d_WindowZooming,
CurAction2d_DynamicPanning,
CurAction2d_GlobalPanning,
};
class Standard_EXPORT OCC_2dView : public OCC_BaseView class Standard_EXPORT OCC_2dView : public OCC_BaseView
{ {
DECLARE_DYNCREATE(OCC_2dView) DECLARE_DYNCREATE(OCC_2dView)
@ -35,17 +26,10 @@ public:
OCC_2dDoc* GetDocument(); OCC_2dDoc* GetDocument();
Handle(V3d_View)& GetV2dView() { return myV2dView; }
void FitAll();
// Overrides // Overrides
// ClassWizard generated virtual function overrides // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(OCC_2dView) //{{AFX_VIRTUAL(OCC_2dView)
public: protected:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual void OnInitialUpdate(); // called first time after construct virtual void OnInitialUpdate(); // called first time after construct
//}}AFX_VIRTUAL //}}AFX_VIRTUAL
@ -70,13 +54,6 @@ protected:
afx_msg void OnUpdateBUTTONGridValues(CCmdUI* pCmdUI); afx_msg void OnUpdateBUTTONGridValues(CCmdUI* pCmdUI);
afx_msg void OnBUTTONGridCancel(); afx_msg void OnBUTTONGridCancel();
afx_msg void OnUpdateBUTTONGridCancel(CCmdUI* pCmdUI); afx_msg void OnUpdateBUTTONGridCancel(CCmdUI* pCmdUI);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnBUTTONFitAll(); afx_msg void OnBUTTONFitAll();
afx_msg void OnBUTTONGlobPanning(); afx_msg void OnBUTTONGlobPanning();
@ -92,34 +69,6 @@ protected:
DECLARE_MESSAGE_MAP() DECLARE_MESSAGE_MAP()
protected: protected:
virtual void DragEvent2D (const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer TheState);
virtual void InputEvent2D (const Standard_Integer x,
const Standard_Integer y);
virtual void MoveEvent2D (const Standard_Integer x,
const Standard_Integer y);
virtual void MultiMoveEvent2D (const Standard_Integer x,
const Standard_Integer y);
virtual void MultiDragEvent2D (const Standard_Integer x,
const Standard_Integer y,
const Standard_Integer TheState);
virtual void MultiInputEvent2D (const Standard_Integer x,
const Standard_Integer y);
virtual void Popup2D (const Standard_Integer x,
const Standard_Integer y);
protected:
Handle(V3d_View) myV2dView;
CurrentAction2d myCurrentMode;
CRectangularGrid TheRectangularGridDialog; CRectangularGrid TheRectangularGridDialog;
CCircularGrid TheCircularGridDialog; CCircularGrid TheCircularGridDialog;
}; };

View File

@ -221,9 +221,7 @@ void OCC_3dBaseDoc::Popup (const Standard_Integer theMouseX,
} }
POINT winCoord = { theMouseX , theMouseY }; POINT winCoord = { theMouseX , theMouseY };
Handle(WNT_Window) aWNTWindow= ClientToScreen ((HWND )theView->Window()->NativeHandle(), &winCoord);
Handle(WNT_Window)::DownCast(theView->Window());
ClientToScreen ( (HWND)(aWNTWindow->HWindow()),&winCoord);
pPopup->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, pPopup->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON,
winCoord.x, winCoord.x,
winCoord.y, winCoord.y,

View File

@ -51,7 +51,7 @@ public:
virtual void Popup (const Standard_Integer theMouseX, virtual void Popup (const Standard_Integer theMouseX,
const Standard_Integer theMouseY, const Standard_Integer theMouseY,
const Handle(V3d_View)& theView); const Handle(V3d_View)& theView) Standard_OVERRIDE;
static void Fit(); static void Fit();

View File

@ -12,11 +12,9 @@
#include <OpenGl_GraphicDriver.hxx> #include <OpenGl_GraphicDriver.hxx>
#define ValZWMin 1 IMPLEMENT_DYNCREATE(OCC_3dView, OCC_BaseView)
IMPLEMENT_DYNCREATE(OCC_3dView, CView) BEGIN_MESSAGE_MAP(OCC_3dView, OCC_BaseView)
BEGIN_MESSAGE_MAP(OCC_3dView, CView)
//{{AFX_MSG_MAP(OCC_3dView) //{{AFX_MSG_MAP(OCC_3dView)
ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo) ON_COMMAND(ID_BUTTONAxo, OnBUTTONAxo)
ON_COMMAND(ID_BUTTONBack, OnBUTTONBack) ON_COMMAND(ID_BUTTONBack, OnBUTTONBack)
@ -37,13 +35,6 @@ BEGIN_MESSAGE_MAP(OCC_3dView, CView)
ON_COMMAND(ID_FILE_EXPORT_IMAGE, OnFileExportImage) ON_COMMAND(ID_FILE_EXPORT_IMAGE, OnFileExportImage)
ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg) ON_COMMAND(ID_BUTTONZoomProg, OnBUTTONZoomProg)
ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin) ON_COMMAND(ID_BUTTONZoomWin, OnBUTTONZoomWin)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOff, OnUpdateBUTTONHlrOff) ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOff, OnUpdateBUTTONHlrOff)
ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn) ON_UPDATE_COMMAND_UI(ID_BUTTONHlrOn, OnUpdateBUTTONHlrOn)
ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo) ON_UPDATE_COMMAND_UI(ID_BUTTONPanGlo, OnUpdateBUTTONPanGlo)
@ -60,79 +51,25 @@ END_MESSAGE_MAP()
// OCC_3dView construction/destruction // OCC_3dView construction/destruction
OCC_3dView::OCC_3dView() OCC_3dView::OCC_3dView()
: myCurrentMode (CurAction3d_Nothing),
myWidth (0),
myHeight (0),
myHlrModeIsOn (Standard_False)
{ {
// TODO: add construction code here // TODO: add construction code here
} }
OCC_3dView::~OCC_3dView() OCC_3dView::~OCC_3dView()
{ {
if (myView.IsNull())
{
myView->Remove();
}
delete m_pStereoDlg; delete m_pStereoDlg;
} }
BOOL OCC_3dView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass = ::AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
return CView::PreCreateWindow(cs);
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// OCC_3dView drawing // OCC_3dView drawing
void OCC_3dView::OnInitialUpdate() void OCC_3dView::OnInitialUpdate()
{ {
CView::OnInitialUpdate(); OCC_BaseView::OnInitialUpdate();
myView = GetDocument()->GetViewer()->CreateView();
// store for restore state after rotation (which is in Degenerated mode)
myHlrModeIsOn = Standard_False;
myView->SetComputedMode (myHlrModeIsOn);
Handle(OpenGl_GraphicDriver) aDriver =
Handle(OpenGl_GraphicDriver)::DownCast (((OCC_App*)AfxGetApp())->GetGraphicDriver());
Handle(WNT_Window) aWNTWindow = new WNT_Window(GetSafeHwnd());
myView->SetWindow(aWNTWindow);
myView->Camera()->SetProjectionType (aDriver->Options().contextStereo
? Graphic3d_Camera::Projection_Stereo
: Graphic3d_Camera::Projection_Orthographic);
if (!aWNTWindow->IsMapped())
{
aWNTWindow->Map();
}
// store the mode ( nothing , dynamic zooming, dynamic ... )
myCurrentMode = CurAction3d_Nothing;
m_pStereoDlg = new OCC_StereoConfigDlg (this); m_pStereoDlg = new OCC_StereoConfigDlg (this);
m_pStereoDlg->SetView (myView); m_pStereoDlg->SetView (myView);
m_pStereoDlg->Create (IDD_DIALOG_STEREO, this); m_pStereoDlg->Create (IDD_DIALOG_STEREO, this);
} }
void OCC_3dView::OnDraw(CDC* /*pDC*/)
{
CRect aRect;
GetWindowRect(aRect);
if(myWidth != aRect.Width() || myHeight != aRect.Height()) {
myWidth = aRect.Width();
myHeight = aRect.Height();
::PostMessage ( GetSafeHwnd() , WM_SIZE , SW_SHOW , myWidth + myHeight*65536 );
}
myView->Redraw();
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// OCC_3dView diagnostics // OCC_3dView diagnostics
@ -162,74 +99,72 @@ void OCC_3dView::OnFileExportImage()
GetDocument()->ExportView (myView); GetDocument()->ExportView (myView);
} }
void OCC_3dView::OnSize(UINT nType, int cx, int cy)
{
OCC_BaseView::OnSize (nType, cx, cy);
if (!myView.IsNull())
myView->MustBeResized();
}
// See the back View // See the back View
void OCC_3dView::OnBUTTONBack() void OCC_3dView::OnBUTTONBack()
{ {
myView->SetProj(V3d_Ypos); myView->SetProj(V3d_Ypos);
myView->Redraw();
} }
// See the front View // See the front View
void OCC_3dView::OnBUTTONFront() void OCC_3dView::OnBUTTONFront()
{ {
myView->SetProj(V3d_Yneg); myView->SetProj(V3d_Yneg);
myView->Redraw();
} }
// See the bottom View // See the bottom View
void OCC_3dView::OnBUTTONBottom() void OCC_3dView::OnBUTTONBottom()
{ {
myView->SetProj(V3d_Zneg); myView->SetProj(V3d_Zneg);
myView->Redraw();
} }
// See the top View // See the top View
void OCC_3dView::OnBUTTONTop() void OCC_3dView::OnBUTTONTop()
{ {
myView->SetProj(V3d_Zpos); myView->SetProj(V3d_Zpos);
myView->Redraw();
} }
// See the left View // See the left View
void OCC_3dView::OnBUTTONLeft() void OCC_3dView::OnBUTTONLeft()
{ {
myView->SetProj(V3d_Xneg); myView->SetProj(V3d_Xneg);
myView->Redraw();
} }
// See the right View // See the right View
void OCC_3dView::OnBUTTONRight() void OCC_3dView::OnBUTTONRight()
{ {
myView->SetProj(V3d_Xpos); myView->SetProj(V3d_Xpos);
myView->Redraw();
} }
// See the axonometric View // See the axonometric View
void OCC_3dView::OnBUTTONAxo() void OCC_3dView::OnBUTTONAxo()
{ {
myView->SetProj(V3d_XposYnegZpos); myView->SetProj(V3d_XposYnegZpos);
myView->Redraw();
} }
void OCC_3dView::OnBUTTONHlrOff() void OCC_3dView::OnBUTTONHlrOff()
{ {
myHlrModeIsOn = Standard_False; myView->SetComputedMode (Standard_False);
myView->SetComputedMode (myHlrModeIsOn);
myView->Redraw(); myView->Redraw();
} }
void OCC_3dView::OnBUTTONHlrOn() void OCC_3dView::OnBUTTONHlrOn()
{ {
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT)); SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
myHlrModeIsOn = Standard_True; myView->SetComputedMode (Standard_True);
myView->SetComputedMode (myHlrModeIsOn);
myView->Redraw(); myView->Redraw();
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW)); SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
} }
void OCC_3dView::OnBUTTONPan() void OCC_3dView::OnBUTTONPan()
{ {
myCurrentMode = CurAction3d_DynamicPanning; setCurrentAction (CurAction3d_DynamicPanning);
} }
void OCC_3dView::OnBUTTONPanGlo() void OCC_3dView::OnBUTTONPanGlo()
@ -237,9 +172,9 @@ void OCC_3dView::OnBUTTONPanGlo()
// save the current zoom value // save the current zoom value
myCurZoom = myView->Scale(); myCurZoom = myView->Scale();
// Do a Global Zoom // Do a Global Zoom
//myView->FitAll(); myView->FitAll();
// Set the mode // Set the mode
myCurrentMode = CurAction3d_GlobalPanning; setCurrentAction (CurAction3d_GlobalPanning);
} }
void OCC_3dView::OnBUTTONReset() void OCC_3dView::OnBUTTONReset()
@ -249,7 +184,7 @@ void OCC_3dView::OnBUTTONReset()
void OCC_3dView::OnBUTTONRot() void OCC_3dView::OnBUTTONRot()
{ {
myCurrentMode = CurAction3d_DynamicRotation; setCurrentAction (CurAction3d_DynamicRotation);
} }
void OCC_3dView::OnBUTTONZoomAll() void OCC_3dView::OnBUTTONZoomAll()
@ -259,298 +194,55 @@ void OCC_3dView::OnBUTTONZoomAll()
} }
void OCC_3dView::OnBUTTONZoomProg() void OCC_3dView::OnBUTTONZoomProg()
{ myCurrentMode = CurAction3d_DynamicZooming; } {
setCurrentAction (CurAction3d_DynamicZooming);
}
void OCC_3dView::OnBUTTONZoomWin() void OCC_3dView::OnBUTTONZoomWin()
{ myCurrentMode = CurAction3d_WindowZooming; }
void OCC_3dView::OnLButtonDown(UINT nFlags, CPoint point)
{ {
// save the current mouse coordinate in min setCurrentAction (CurAction3d_WindowZooming);
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 CurAction3d_Nothing : // start a drag
if (nFlags & MK_SHIFT)
GetDocument()->ShiftDragEvent(myXmax,myYmax,-1,myView);
else
GetDocument()->DragEvent(myXmax,myYmax,-1,myView);
break;
break;
case CurAction3d_DynamicZooming : // noting
break;
case CurAction3d_WindowZooming : // noting
break;
case CurAction3d_DynamicPanning :// noting
break;
case CurAction3d_GlobalPanning :// noting
break;
case CurAction3d_DynamicRotation :
if (myHlrModeIsOn)
{
myView->SetComputedMode (Standard_False);
}
myView->StartRotation(point.x,point.y);
break;
default :
throw Standard_Failure(" incompatible Current Mode ");
break;
}
}
}
void OCC_3dView::OnLButtonUp(UINT nFlags, CPoint point)
{
if ( nFlags & MK_CONTROL )
{
return;
}
else // if ( Ctrl )
{
const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetAISContext();
switch (myCurrentMode)
{
case CurAction3d_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
{
myXmax=point.x; myYmax=point.y;
drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext, Standard_False);
if (nFlags & MK_SHIFT)
GetDocument()->ShiftDragEvent(point.x,point.y,1,myView);
else
GetDocument()->DragEvent(point.x,point.y,1,myView);
}
break;
case CurAction3d_DynamicZooming :
myCurrentMode = CurAction3d_Nothing;
break;
case CurAction3d_WindowZooming :
myXmax=point.x; myYmax=point.y;
drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext, Standard_False);
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 = CurAction3d_Nothing;
break;
case CurAction3d_DynamicPanning :
myCurrentMode = CurAction3d_Nothing;
break;
case CurAction3d_GlobalPanning :
myView->Place(point.x,point.y,myCurZoom);
myCurrentMode = CurAction3d_Nothing;
break;
case CurAction3d_DynamicRotation :
myCurrentMode = CurAction3d_Nothing;
if (myHlrModeIsOn)
{
CWaitCursor aWaitCursor;
myView->SetComputedMode (myHlrModeIsOn);
myView->Redraw();
}
else
{
myView->SetComputedMode (myHlrModeIsOn);
}
break;
default :
throw Standard_Failure(" incompatible Current Mode ");
break;
} //switch (myCurrentMode)
} // else // if ( Ctrl )
}
void OCC_3dView::OnMButtonDown(UINT nFlags, CPoint /*point*/)
{
if ( nFlags & MK_CONTROL )
{
// Button MB2 down Control : panning init
// SetCursor(AfxGetApp()->LoadStandardCursor());
}
}
void OCC_3dView::OnMButtonUp(UINT nFlags, CPoint /*point*/)
{
if ( nFlags & MK_CONTROL )
{
// Button MB2 down Control : panning init
// SetCursor(AfxGetApp()->LoadStandardCursor());
}
}
void OCC_3dView::OnRButtonDown(UINT nFlags, CPoint point)
{
if ( nFlags & MK_CONTROL )
{
if (myHlrModeIsOn)
{
myView->SetComputedMode (Standard_False);
}
myView->StartRotation(point.x,point.y);
}
else // if ( Ctrl )
{
GetDocument()->Popup(point.x,point.y,myView);
}
}
void OCC_3dView::OnRButtonUp(UINT /*nFlags*/, CPoint /*point*/)
{
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_WAIT));
if (myHlrModeIsOn)
{
myView->SetComputedMode (myHlrModeIsOn);
myView->Redraw();
}
SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
}
void OCC_3dView::OnMouseMove(UINT nFlags, CPoint point)
{
// ============================ LEFT BUTTON =======================
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 )
{
const Handle(AIS_InteractiveContext)& aContext = GetDocument()->GetAISContext();
switch (myCurrentMode)
{
case CurAction3d_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, aContext);
break;
case CurAction3d_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 CurAction3d_WindowZooming :
myXmax = point.x;
myYmax = point.y;
drawRectangle (myXmin, myYmin, myXmax, myYmax, aContext);
break;
case CurAction3d_DynamicPanning :
myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
myXmax = point.x; myYmax = point.y;
break;
case CurAction3d_GlobalPanning : // nothing
break;
case CurAction3d_DynamicRotation :
myView->Rotation(point.x,point.y);
myView->Redraw();
break;
default :
throw Standard_Failure(" incompatible Current Mode ");
break;
}// switch (myCurrentMode)
}// if ( nFlags & MK_CONTROL ) else
}
else 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_RBUTTON)
{
if ( nFlags & MK_CONTROL )
{
myView->Rotation(point.x,point.y);
}
}
else
{ // 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);
}
} }
void OCC_3dView::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI) void OCC_3dView::OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (!myHlrModeIsOn); pCmdUI->SetCheck (!myView->ComputedMode());
pCmdUI->Enable (myHlrModeIsOn); pCmdUI->Enable (myView->ComputedMode());
} }
void OCC_3dView::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI) void OCC_3dView::OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myHlrModeIsOn); pCmdUI->SetCheck (myView->ComputedMode());
pCmdUI->Enable (!myHlrModeIsOn); pCmdUI->Enable (!myView->ComputedMode());
} }
void OCC_3dView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI) void OCC_3dView::OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myCurrentMode == CurAction3d_GlobalPanning); pCmdUI->SetCheck (getCurrentAction() == CurAction3d_GlobalPanning);
pCmdUI->Enable (myCurrentMode != CurAction3d_GlobalPanning); pCmdUI->Enable (getCurrentAction() != CurAction3d_GlobalPanning);
} }
void OCC_3dView::OnUpdateBUTTONPan(CCmdUI* pCmdUI) void OCC_3dView::OnUpdateBUTTONPan(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicPanning); pCmdUI->SetCheck (getCurrentAction() == CurAction3d_DynamicPanning);
pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicPanning ); pCmdUI->Enable (getCurrentAction() != CurAction3d_DynamicPanning );
} }
void OCC_3dView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI) void OCC_3dView::OnUpdateBUTTONZoomProg(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicZooming ); pCmdUI->SetCheck (getCurrentAction() == CurAction3d_DynamicZooming );
pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicZooming); pCmdUI->Enable (getCurrentAction() != CurAction3d_DynamicZooming);
} }
void OCC_3dView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI) void OCC_3dView::OnUpdateBUTTONZoomWin(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myCurrentMode == CurAction3d_WindowZooming); pCmdUI->SetCheck (getCurrentAction() == CurAction3d_WindowZooming);
pCmdUI->Enable (myCurrentMode != CurAction3d_WindowZooming); pCmdUI->Enable (getCurrentAction() != CurAction3d_WindowZooming);
} }
void OCC_3dView::OnUpdateBUTTONRot(CCmdUI* pCmdUI) void OCC_3dView::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck (myCurrentMode == CurAction3d_DynamicRotation); pCmdUI->SetCheck (getCurrentAction() == CurAction3d_DynamicRotation);
pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation); pCmdUI->Enable (getCurrentAction() != CurAction3d_DynamicRotation);
} }
void OCC_3dView::OnModifyChangeBackground() void OCC_3dView::OnModifyChangeBackground()

View File

@ -14,15 +14,6 @@
#include "OCC_StereoConfigDlg.h" #include "OCC_StereoConfigDlg.h"
#include <Standard_Macro.hxx> #include <Standard_Macro.hxx>
enum CurAction3d {
CurAction3d_Nothing,
CurAction3d_DynamicZooming,
CurAction3d_WindowZooming,
CurAction3d_DynamicPanning,
CurAction3d_GlobalPanning,
CurAction3d_DynamicRotation
};
class Standard_EXPORT OCC_3dView : public OCC_BaseView class Standard_EXPORT OCC_3dView : public OCC_BaseView
{ {
DECLARE_DYNCREATE(OCC_3dView) DECLARE_DYNCREATE(OCC_3dView)
@ -31,18 +22,11 @@ public:
virtual ~OCC_3dView(); virtual ~OCC_3dView();
OCC_3dDoc* GetDocument(); OCC_3dDoc* GetDocument();
void FitAll() { if ( !myView.IsNull() ) myView->FitAll(); myView->ZFitAll(); };
void Redraw() { if ( !myView.IsNull() ) myView->Redraw(); };
void SetZoom ( const Standard_Real& Coef ) { myView->SetZoom ( Coef ); };
Handle(V3d_View)& GetView() { return myView; }
// Overrides // Overrides
// ClassWizard generated virtual function overrides // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(OCC_3dView) //{{AFX_VIRTUAL(OCC_3dView)
public: public:
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
virtual void OnInitialUpdate(); virtual void OnInitialUpdate();
//}}AFX_VIRTUAL //}}AFX_VIRTUAL
@ -64,16 +48,8 @@ protected:
afx_msg void OnBUTTONTop(); afx_msg void OnBUTTONTop();
afx_msg void OnBUTTONZoomAll(); afx_msg void OnBUTTONZoomAll();
afx_msg void OnFileExportImage(); afx_msg void OnFileExportImage();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnBUTTONZoomProg(); afx_msg void OnBUTTONZoomProg();
afx_msg void OnBUTTONZoomWin(); afx_msg void OnBUTTONZoomWin();
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMButtonDown(UINT nFlags, CPoint point);
afx_msg void OnMButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI); afx_msg void OnUpdateBUTTONHlrOff(CCmdUI* pCmdUI);
afx_msg void OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI); afx_msg void OnUpdateBUTTONHlrOn(CCmdUI* pCmdUI);
afx_msg void OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI); afx_msg void OnUpdateBUTTONPanGlo(CCmdUI* pCmdUI);
@ -92,14 +68,6 @@ protected:
virtual void Dump(CDumpContext& dc) const; virtual void Dump(CDumpContext& dc) const;
#endif #endif
protected:
Handle(V3d_View) myView;
CurAction3d myCurrentMode;
Standard_Integer myWidth;
Standard_Integer myHeight;
Standard_Boolean myHlrModeIsOn;
private: private:
//! Persistent non blocking stereo configuration dialog //! Persistent non blocking stereo configuration dialog

View File

@ -78,7 +78,4 @@ void OCC_BaseDoc::ResetDocumentViews (CDocTemplate* theTemplate)
// init frame // init frame
theTemplate->InitialUpdateFrame(aNewFrame, this); theTemplate->InitialUpdateFrame(aNewFrame, this);
} }

View File

@ -28,9 +28,10 @@ public:
virtual ~OCC_BaseDoc(); virtual ~OCC_BaseDoc();
Handle(AIS_InteractiveContext)& GetAISContext() { return myAISContext; } const Handle(AIS_InteractiveContext)& GetAISContext() const { return myAISContext; }
const Handle(AIS_InteractiveContext)& GetInteractiveContext() const { return myAISContext; };
Handle(V3d_Viewer) GetViewer() { return myViewer; } const Handle(V3d_Viewer)& GetViewer() const { return myViewer; }
// Returns string with supported export pixel and vector images formats. // Returns string with supported export pixel and vector images formats.
const CString SupportedImageFormats() const; const CString SupportedImageFormats() const;
@ -69,6 +70,10 @@ public:
const Standard_Integer /*theMouseY*/, const Standard_Integer /*theMouseY*/,
const Handle(V3d_View)& /*theView*/) {} const Handle(V3d_View)& /*theView*/) {}
//! Callback called by handleMoveTo() on Selection in 3D Viewer.
virtual void OnSelectionChanged (const Handle(AIS_InteractiveContext)& ,
const Handle(V3d_View)& ) {}
void ResetDocumentViews (CDocTemplate* theTemplate); void ResetDocumentViews (CDocTemplate* theTemplate);
protected: protected:

View File

@ -5,24 +5,30 @@
#include <stdafx.h> #include <stdafx.h>
#include "OCC_BaseView.h" #include "OCC_BaseView.h"
BEGIN_MESSAGE_MAP(OCC_BaseView, CView)
ON_WM_SIZE()
ON_WM_MOUSEMOVE()
ON_WM_MOUSEWHEEL()
ON_WM_MOUSELEAVE()
ON_WM_NCMOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
END_MESSAGE_MAP()
//======================================================================= //=======================================================================
//function : Constructor //function : Constructor
//purpose : //purpose :
//======================================================================= //=======================================================================
OCC_BaseView::OCC_BaseView() OCC_BaseView::OCC_BaseView()
: myXmin (0), : myUpdateRequests (0),
myYmin (0),
myXmax (0),
myYmax (0),
myCurZoom (0.0), myCurZoom (0.0),
myRect (new AIS_RubberBand (Quantity_Color(Quantity_NOC_WHITE), Aspect_TOL_SOLID, 1.0) ) myCurrentMode (CurAction3d_Nothing)
{ {
myRect->SetTransformPersistence (new Graphic3d_TransformPers (Graphic3d_TMF_2d, Aspect_TOTP_LEFT_LOWER)); myDefaultGestures = myMouseGestureMap;
if (myRect->ZLayer() != Graphic3d_ZLayerId_TopOSD)
{
myRect->SetZLayer (Graphic3d_ZLayerId_TopOSD);
}
} }
//======================================================================= //=======================================================================
@ -31,7 +37,7 @@ OCC_BaseView::OCC_BaseView()
//======================================================================= //=======================================================================
OCC_BaseView::~OCC_BaseView() OCC_BaseView::~OCC_BaseView()
{ {
//
} }
//======================================================================= //=======================================================================
@ -43,37 +49,330 @@ OCC_BaseDoc* OCC_BaseView::GetDocument() // non-debug version is inline
return (OCC_BaseDoc*)m_pDocument; return (OCC_BaseDoc*)m_pDocument;
} }
//======================================================================= // =======================================================================
//function : drawRectangle // function : PostNcDestroy
//purpose : // purpose :
//======================================================================= // =======================================================================
void OCC_BaseView::drawRectangle (const Standard_Integer theMinX, void OCC_BaseView::PostNcDestroy()
const Standard_Integer theMinY,
const Standard_Integer theMaxX,
const Standard_Integer theMaxY,
const Handle(AIS_InteractiveContext)& theContext,
const Standard_Boolean toDraw)
{ {
if (toDraw) if (!myView.IsNull())
{ {
CRect aRect; myView->Remove();
GetWindowRect(aRect); myView.Nullify();
myRect->SetRectangle (theMinX, aRect.Height() - theMinY, theMaxX, aRect.Height() - theMaxY);
if (!theContext->IsDisplayed (myRect))
{
theContext->Display (myRect, Standard_False);
} }
else CView::PostNcDestroy();
{
theContext->Redisplay (myRect, Standard_False);
}
}
else
{
theContext->Remove (myRect, Standard_False);
}
theContext->CurrentViewer()->RedrawImmediate();
} }
// =======================================================================
// function : PreCreateWindow
// purpose :
// =======================================================================
BOOL OCC_BaseView::PreCreateWindow (CREATESTRUCT& cs)
{
cs.lpszClass = ::AfxRegisterWndClass (CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_OWNDC, ::LoadCursor(NULL, IDC_ARROW), NULL, NULL);
return CView::PreCreateWindow (cs);
}
// =======================================================================
// function : OnInitialUpdate
// purpose :
// =======================================================================
void OCC_BaseView::OnInitialUpdate()
{
myCurrentMode = CurAction3d_Nothing;
CView::OnInitialUpdate();
if (!myView.IsNull())
{
return;
}
myView = GetAISContext()->CurrentViewer()->CreateView();
myView->SetImmediateUpdate (false);
myView->SetComputedMode (Standard_False);
Handle(OpenGl_GraphicDriver) aDriver = Handle(OpenGl_GraphicDriver)::DownCast (myView->Viewer()->Driver());
myView->Camera()->SetProjectionType (aDriver->Options().contextStereo
? Graphic3d_Camera::Projection_Stereo
: Graphic3d_Camera::Projection_Orthographic);
Handle(WNT_Window) aWNTWindow = new WNT_Window (GetSafeHwnd());
myView->SetWindow (aWNTWindow);
if (!aWNTWindow->IsMapped()) aWNTWindow->Map();
myView->Redraw();
myView->Invalidate();
}
// ================================================================
// Function : GetAISContext
// Purpose :
// ================================================================
const Handle(AIS_InteractiveContext)& OCC_BaseView::GetAISContext() const
{
return ((OCC_BaseDoc*)m_pDocument)->GetInteractiveContext();
}
// ================================================================
// Function : update3dView
// Purpose :
// ================================================================
void OCC_BaseView::update3dView()
{
if (!myView.IsNull())
{
if (++myUpdateRequests == 1)
{
Invalidate (FALSE);
UpdateWindow();
}
}
}
// ================================================================
// Function : redraw3dView
// Purpose :
// ================================================================
void OCC_BaseView::redraw3dView()
{
if (!myView.IsNull())
{
FlushViewEvents (GetAISContext(), myView, true);
}
}
// ================================================================
// Function : handleViewRedraw
// Purpose :
// ================================================================
void OCC_BaseView::handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
const Handle(V3d_View)& theView)
{
myUpdateRequests = 0;
AIS_ViewController::handleViewRedraw (theCtx, theView);
}
// ================================================================
// Function : OnSelectionChanged
// Purpose :
// ================================================================
void OCC_BaseView::OnSelectionChanged (const Handle(AIS_InteractiveContext)& theCtx,
const Handle(V3d_View)& theView)
{
AIS_ViewController::OnSelectionChanged (theCtx, theView);
GetDocument()->OnSelectionChanged (theCtx, theView);
}
// =======================================================================
// function : OnDraw
// purpose :
// =======================================================================
void OCC_BaseView::OnDraw (CDC* )
{
// 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 (GetAISContext(), myView, true);
}
// =======================================================================
// function : defineMouseGestures
// purpose :
// =======================================================================
void OCC_BaseView::defineMouseGestures()
{
myMouseGestureMap.Clear();
AIS_MouseGesture aRot = AIS_MouseGesture_RotateOrbit;
switch (myCurrentMode)
{
case CurAction3d_Nothing:
{
myMouseGestureMap = myDefaultGestures;
break;
}
case CurAction3d_DynamicZooming:
{
myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Zoom);
break;
}
case CurAction3d_GlobalPanning:
{
break;
}
case CurAction3d_WindowZooming:
{
myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_ZoomWindow);
break;
}
case CurAction3d_DynamicPanning:
{
myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, AIS_MouseGesture_Pan);
break;
}
case CurAction3d_DynamicRotation:
{
myMouseGestureMap.Bind (Aspect_VKeyMouse_LeftButton, aRot);
break;
}
}
}
// =======================================================================
// function : OnMouseMove
// purpose :
// =======================================================================
void OCC_BaseView::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 Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
if (UpdateMousePosition (Graphic3d_Vec2i (thePoint.x, thePoint.y), PressedMouseButtons(), aFlags, false))
{
update3dView();
}
}
// =======================================================================
// function : OnLButtonDown
// purpose :
// =======================================================================
void OCC_BaseView::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);
update3dView();
}
// =======================================================================
// function : OnLButtonUp
// purpose :
// =======================================================================
void OCC_BaseView::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 == CurAction3d_GlobalPanning)
{
myView->Place (thePoint.x, thePoint.y, myCurZoom);
myView->Invalidate();
}
if (myCurrentMode != CurAction3d_Nothing)
{
setCurrentAction (CurAction3d_Nothing);
}
update3dView();
}
// =======================================================================
// function : OnMButtonDown
// purpose :
// =======================================================================
void OCC_BaseView::OnMButtonDown (UINT theFlags, CPoint thePoint)
{
const Aspect_VKeyFlags aFlags = WNT_Window::MouseKeyFlagsFromEvent (theFlags);
PressMouseButton (Graphic3d_Vec2i (thePoint.x, thePoint.y), Aspect_VKeyMouse_MiddleButton, aFlags, false);
update3dView();
}
// =======================================================================
// function : OnMButtonUp
// purpose :
// =======================================================================
void OCC_BaseView::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 != CurAction3d_Nothing)
{
setCurrentAction (CurAction3d_Nothing);
}
}
// =======================================================================
// function : OnRButtonDown
// purpose :
// =======================================================================
void OCC_BaseView::OnRButtonDown (UINT theFlags, CPoint thePoint)
{
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);
}
// =======================================================================
// function : OnRButtonUp
// purpose :
// =======================================================================
void OCC_BaseView::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 != CurAction3d_Nothing)
{
setCurrentAction (CurAction3d_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 OCC_BaseView::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;
}
// =======================================================================
// function : OnSize
// purpose :
// =======================================================================
void OCC_BaseView::OnSize (UINT nType, int cx, int cy)
{
CView::OnSize (nType, cx, cy);
if (cx != 0
&& cy != 0
&& !myView.IsNull())
{
myView->Window()->DoResize();
myView->MustBeResized();
myView->Invalidate();
update3dView();
}
}
// =======================================================================
// function : OnMouseLeave
// purpose :
// =======================================================================
void OCC_BaseView::OnMouseLeave()
{
CPoint aCursorPos;
if (GetCursorPos (&aCursorPos))
{
ReleaseMouseButton (Graphic3d_Vec2i (aCursorPos.x, aCursorPos.y),
PressedMouseButtons(),
Aspect_VKeyMouse_NONE,
false);
}
}

View File

@ -12,9 +12,19 @@
#include <stdafx.h> #include <stdafx.h>
#include "OCC_BaseDoc.h" #include "OCC_BaseDoc.h"
#include "AIS_RubberBand.hxx" #include "AIS_ViewController.hxx"
class Standard_EXPORT OCC_BaseView : public CView enum CurAction3d
{
CurAction3d_Nothing,
CurAction3d_DynamicZooming,
CurAction3d_WindowZooming,
CurAction3d_DynamicPanning,
CurAction3d_GlobalPanning,
CurAction3d_DynamicRotation
};
class Standard_EXPORT OCC_BaseView : public CView, public AIS_ViewController
{ {
public: public:
@ -22,27 +32,84 @@ public:
OCC_BaseView(); OCC_BaseView();
virtual ~OCC_BaseView(); virtual ~OCC_BaseView();
//! Return the view.
const Handle(V3d_View)& GetView() const { return myView; }
void FitAll() { if ( !myView.IsNull() ) myView->FitAll(); myView->ZFitAll(); };
void Redraw() { if ( !myView.IsNull() ) myView->Redraw(); };
void SetZoom ( const Standard_Real& Coef ) { myView->SetZoom ( Coef ); };
//! Return the document.
OCC_BaseDoc* GetDocument(); OCC_BaseDoc* GetDocument();
protected: //! Request view redrawing.
void update3dView();
virtual void drawRectangle (const Standard_Integer theMinX,
const Standard_Integer theMinY,
const Standard_Integer theMaxX,
const Standard_Integer theMaxY,
const Handle(AIS_InteractiveContext)& theContext,
const Standard_Boolean toDraw = Standard_True);
//! Flush events and redraw view.
void redraw3dView();
protected: protected:
//! Handle view redraw.
virtual void handleViewRedraw (const Handle(AIS_InteractiveContext)& theCtx,
const Handle(V3d_View)& theView) Standard_OVERRIDE;
//! Callback called by handleMoveTo() on Selection in 3D Viewer.
virtual void OnSelectionChanged (const Handle(AIS_InteractiveContext)& theCtx,
const Handle(V3d_View)& theView) Standard_OVERRIDE;
//! Return interactive context.
virtual const Handle(AIS_InteractiveContext)& GetAISContext() const;
protected:
//! Setup mouse gestures.
void defineMouseGestures();
//! Get current action.
CurAction3d getCurrentAction() const { return myCurrentMode; }
//! Set current action.
void setCurrentAction (CurAction3d theAction)
{
myCurrentMode = theAction;
defineMouseGestures();
}
public:
virtual BOOL PreCreateWindow (CREATESTRUCT& cs) Standard_OVERRIDE;
virtual void PostNcDestroy() Standard_OVERRIDE;
protected:
Handle(V3d_View) myView;
AIS_MouseGestureMap myDefaultGestures;
Graphic3d_Vec2i myClickPos;
Standard_Real myCurZoom; Standard_Real myCurZoom;
Standard_Integer myXmin; unsigned int myUpdateRequests; //!< counter for unhandled update requests
Standard_Integer myYmin;
Standard_Integer myXmax;
Standard_Integer myYmax;
Handle(AIS_RubberBand) myRect; //!< Rubber rectangle for selection private:
CurAction3d myCurrentMode;
// message map functions
protected:
DECLARE_MESSAGE_MAP()
public:
virtual void OnInitialUpdate() Standard_OVERRIDE;
virtual void OnDraw (CDC* /*pDC*/) Standard_OVERRIDE;
afx_msg void OnSize (UINT nType, int cx, int cy);
afx_msg BOOL OnMouseWheel (UINT theFlags, short theDelta, CPoint thePoint);
afx_msg void OnMouseMove (UINT theFlags, CPoint thePoint);
afx_msg void OnMouseLeave();
afx_msg void OnLButtonDown (UINT theFlags, CPoint thePoint);
afx_msg void OnLButtonUp (UINT theFlags, CPoint thePoint);
afx_msg void OnMButtonDown (UINT theFlags, CPoint thePoint);
afx_msg void OnMButtonUp (UINT theFlags, CPoint thePoint);
afx_msg void OnRButtonDown (UINT theFlags, CPoint thePoint);
afx_msg void OnRButtonUp (UINT theFlags, CPoint thePoint);
}; };
#endif // !defined(AFX_OCC_BASEVIEW_H__2E048CCA_38F9_11D7_8611_0060B0EE281E__INCLUDED_) #endif // !defined(AFX_OCC_BASEVIEW_H__2E048CCA_38F9_11D7_8611_0060B0EE281E__INCLUDED_)