1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0027736: Samples - rectangle selection issues within MFC sample Viewer3d

CViewer3dView, CAnimationView3D, COCCDemoView now use AIS_RubberBand.
This commit is contained in:
kgv 2018-03-25 11:53:09 +03:00 committed by bugmaster
parent fe76088cc7
commit 060811b1b5
6 changed files with 100 additions and 188 deletions

View File

@ -13,6 +13,7 @@
#include "ModelClippingDlg.h" #include "ModelClippingDlg.h"
#include "TrihedronDlg.h" #include "TrihedronDlg.h"
#include <AIS_RubberBand.hxx>
#include <V3d_AmbientLight.hxx> #include <V3d_AmbientLight.hxx>
#include <V3d_DirectionalLight.hxx> #include <V3d_DirectionalLight.hxx>
#include <V3d_PositionalLight.hxx> #include <V3d_PositionalLight.hxx>
@ -109,7 +110,7 @@ CViewer3dView::CViewer3dView()
myCurZoom (0.0), myCurZoom (0.0),
NbActiveLights (2), // There are 2 default active lights NbActiveLights (2), // There are 2 default active lights
myHlrModeIsOn (Standard_False), myHlrModeIsOn (Standard_False),
m_Pen (NULL), myRect (new AIS_RubberBand (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0)),
myAxisKey (0), myAxisKey (0),
myScaleDirection (0) myScaleDirection (0)
{ {
@ -120,7 +121,6 @@ CViewer3dView::CViewer3dView()
CViewer3dView::~CViewer3dView() CViewer3dView::~CViewer3dView()
{ {
myView->Remove(); myView->Remove();
if (m_Pen) delete m_Pen;
} }
BOOL CViewer3dView::PreCreateWindow(CREATESTRUCT& cs) BOOL CViewer3dView::PreCreateWindow(CREATESTRUCT& cs)
@ -646,7 +646,6 @@ void CViewer3dView::OnMouseMove(UINT nFlags, CPoint point)
{ {
case CurAction3d_Nothing : case CurAction3d_Nothing :
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
myXmax = point.x; myYmax = point.y; myXmax = point.x; myYmax = point.y;
if (nFlags & MK_SHIFT) if (nFlags & MK_SHIFT)
GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView); GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
@ -661,8 +660,7 @@ void CViewer3dView::OnMouseMove(UINT nFlags, CPoint point)
break; break;
case CurAction3d_WindowZooming : case CurAction3d_WindowZooming :
myXmax = point.x; myYmax = point.y; myXmax = point.x; myYmax = point.y;
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash); DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True, Aspect_TOL_DASH);
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
break; break;
case CurAction3d_DynamicPanning : case CurAction3d_DynamicPanning :
@ -799,60 +797,34 @@ void CViewer3dView::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation); pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation);
} }
void CViewer3dView::DrawRectangle(const Standard_Integer MinX , void CViewer3dView::DrawRectangle (Standard_Integer theMinX,
const Standard_Integer MinY , Standard_Integer theMinY,
const Standard_Integer MaxX , Standard_Integer theMaxX,
const Standard_Integer MaxY , Standard_Integer theMaxY,
const Standard_Boolean Draw , Standard_Boolean theToDraw,
const LineStyle aLineStyle) Aspect_TypeOfLine theLineType)
{ {
static int m_DrawMode; const Handle(AIS_InteractiveContext)& aCtx = GetDocument()->GetAISContext();
if (!m_Pen && aLineStyle ==Solid ) if (!theToDraw)
{m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;} {
else if (!m_Pen && aLineStyle ==Dot ) aCtx->Remove (myRect, false);
{m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;} aCtx->CurrentViewer()->RedrawImmediate();
else if (!m_Pen && aLineStyle == ShortDash) return;
{m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;} }
else if (!m_Pen && aLineStyle == LongDash)
{m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;}
else if (aLineStyle == Default)
{ m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
CPen* aOldPen = NULL; CRect aRect;
CClientDC clientDC(this); GetWindowRect (aRect);
if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen); myRect->SetLineType (theLineType);
clientDC.SetROP2(m_DrawMode); myRect->SetRectangle (theMinX, aRect.Height() - theMinY, theMaxX, aRect.Height() - theMaxY);
if (!aCtx->IsDisplayed (myRect))
static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY; {
static Standard_Boolean m_IsVisible; aCtx->Display (myRect, false);
}
if ( m_IsVisible && !Draw) // move or up : erase at the old position else
{ {
clientDC.MoveTo(StoredMinX,StoredMinY); aCtx->Redisplay (myRect, false);
clientDC.LineTo(StoredMinX,StoredMaxY); }
clientDC.LineTo(StoredMaxX,StoredMaxY); aCtx->CurrentViewer()->RedrawImmediate();
clientDC.LineTo(StoredMaxX,StoredMinY);
clientDC.LineTo(StoredMinX,StoredMinY);
m_IsVisible = false;
}
StoredMinX = Min ( MinX, MaxX );
StoredMinY = Min ( MinY, MaxY );
StoredMaxX = Max ( MinX, MaxX );
StoredMaxY = Max ( MinY, MaxY);
if (Draw) // move : draw
{
clientDC.MoveTo(StoredMinX,StoredMinY);
clientDC.LineTo(StoredMinX,StoredMaxY);
clientDC.LineTo(StoredMaxX,StoredMaxY);
clientDC.LineTo(StoredMaxX,StoredMinY);
clientDC.LineTo(StoredMinX,StoredMinY);
m_IsVisible = true;
}
if (m_Pen)
clientDC.SelectObject(aOldPen);
} }
void CViewer3dView::OnModifyChangeBackground() void CViewer3dView::OnModifyChangeBackground()

View File

@ -33,6 +33,8 @@ enum View3D_CurrentAction {
CurAction3d_EndDirectionalLight CurAction3d_EndDirectionalLight
}; };
class AIS_RubberBand;
class CViewer3dView : public CView class CViewer3dView : public CView
{ {
protected: // create from serialization only protected: // create from serialization only
@ -145,16 +147,13 @@ private:
Handle(V3d_DirectionalLight) myCurrent_DirectionalLight; Handle(V3d_DirectionalLight) myCurrent_DirectionalLight;
Handle(Graphic3d_ClipPlane) myClippingPlane; Handle(Graphic3d_ClipPlane) myClippingPlane;
Handle(AIS_Shape) myShape; Handle(AIS_Shape) myShape;
Handle(AIS_RubberBand) myRect; //!< Rubber rectangle for selection
private: private:
enum LineStyle { Solid, Dot, ShortDash, LongDash, Default };
CPen* m_Pen; void DrawRectangle (Standard_Integer theMinX, Standard_Integer theMinY, Standard_Integer theMaxX, Standard_Integer theMaxY,
virtual void DrawRectangle (const Standard_Integer MinX , Standard_Boolean theToDraw, Aspect_TypeOfLine theLineType = Aspect_TOL_SOLID);
const Standard_Integer MinY ,
const Standard_Integer MaxX ,
const Standard_Integer MaxY ,
const Standard_Boolean Draw ,
const LineStyle aLineStyle = Default );
UINT myAxisKey; UINT myAxisKey;
UINT myScaleDirection; UINT myScaleDirection;
void RedrawVisMode(); void RedrawVisMode();

View File

@ -11,6 +11,8 @@
#include "Sensitivity.h" #include "Sensitivity.h"
#include <AIS_RubberBand.hxx>
#ifdef _DEBUG #ifdef _DEBUG
//#define new DEBUG_NEW by CasCade //#define new DEBUG_NEW by CasCade
#undef THIS_FILE #undef THIS_FILE
@ -92,7 +94,7 @@ CAnimationView3D::CAnimationView3D()
myCurrentMode (CurrentAction3d_Nothing), myCurrentMode (CurrentAction3d_Nothing),
m_FlySens (500.0), m_FlySens (500.0),
m_TurnSens (M_PI / 40.0), m_TurnSens (M_PI / 40.0),
m_Pen (NULL) myRect (new AIS_RubberBand (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0))
{ {
// TODO: add construction code here // TODO: add construction code here
} }
@ -100,7 +102,6 @@ CAnimationView3D::CAnimationView3D()
CAnimationView3D::~CAnimationView3D() CAnimationView3D::~CAnimationView3D()
{ {
myView->Remove(); myView->Remove();
if (m_Pen) delete m_Pen;
} }
BOOL CAnimationView3D::PreCreateWindow(CREATESTRUCT& cs) BOOL CAnimationView3D::PreCreateWindow(CREATESTRUCT& cs)
@ -403,7 +404,7 @@ void CAnimationView3D::OnLButtonUp(UINT nFlags, CPoint point)
break; break;
case CurrentAction3d_WindowZooming : case CurrentAction3d_WindowZooming :
myXmax=point.x; myYmax=point.y; myXmax=point.x; myYmax=point.y;
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash); DrawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_False, Aspect_TOL_DASH);
if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin)) if ((abs(myXmin-myXmax)>ValZWMin) || (abs(myYmin-myYmax)>ValZWMin))
// Test if the zoom window is greater than a minimale window. // Test if the zoom window is greater than a minimale window.
{ {
@ -503,7 +504,6 @@ void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
{ {
case CurrentAction3d_Nothing : case CurrentAction3d_Nothing :
myXmax = point.x; myYmax = point.y; myXmax = point.x; myYmax = point.y;
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False);
if (nFlags & MK_SHIFT) if (nFlags & MK_SHIFT)
GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView); GetDocument()->ShiftDragEvent(myXmax,myYmax,0,myView);
else else
@ -517,8 +517,7 @@ void CAnimationView3D::OnMouseMove(UINT nFlags, CPoint point)
break; break;
case CurrentAction3d_WindowZooming : case CurrentAction3d_WindowZooming :
myXmax = point.x; myYmax = point.y; myXmax = point.x; myYmax = point.y;
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash); DrawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_True, Aspect_TOL_DASH);
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
break; break;
case CurrentAction3d_DynamicPanning : case CurrentAction3d_DynamicPanning :
myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
@ -652,57 +651,36 @@ void CAnimationView3D::OnChangeBackground()
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
// //
//----------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------
void CAnimationView3D::DrawRectangle(const Standard_Integer MinX , void CAnimationView3D::DrawRectangle (Standard_Integer theMinX,
const Standard_Integer MinY , Standard_Integer theMinY,
const Standard_Integer MaxX , Standard_Integer theMaxX,
const Standard_Integer MaxY , Standard_Integer theMaxY,
const Standard_Boolean Draw , Standard_Boolean theToDraw,
const LineStyle aLineStyle) Aspect_TypeOfLine theLineType)
{ {
static int m_DrawMode; const Handle(AIS_InteractiveContext)& aCtx = GetDocument()->GetAISContext();
if (!m_Pen && aLineStyle ==Solid ) if (!theToDraw)
{m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT;} {
else if (!m_Pen && aLineStyle ==Dot ) aCtx->Remove (myRect, false);
{m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;} aCtx->CurrentViewer()->RedrawImmediate();
else if (!m_Pen && aLineStyle == ShortDash) return;
{m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;} }
else if (!m_Pen && aLineStyle == LongDash)
{m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;}
else if (aLineStyle == Default)
{ m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;}
CPen* aOldPen = NULL; CRect aRect;
CClientDC clientDC(this); GetWindowRect (aRect);
if (m_Pen) aOldPen = clientDC.SelectObject(m_Pen); myRect->SetLineType (theLineType);
clientDC.SetROP2(m_DrawMode); myRect->SetRectangle (theMinX, aRect.Height() - theMinY, theMaxX, aRect.Height() - theMaxY);
if (!aCtx->IsDisplayed (myRect))
static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY; {
static Standard_Boolean m_IsVisible; aCtx->Display (myRect, false);
}
if ( m_IsVisible && !Draw) // move or up : erase at the old position else
{ {
clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY); aCtx->Redisplay (myRect, false);
clientDC.LineTo(StoredMaxX,StoredMaxY); }
clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY); aCtx->CurrentViewer()->RedrawImmediate();
m_IsVisible = false;
}
StoredMinX = Min ( MinX, MaxX );
StoredMinY = Min ( MinY, MaxY );
StoredMaxX = Max ( MinX, MaxX );
StoredMaxY = Max ( MinY, MaxY);
if (Draw) // move : draw
{
clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY);
clientDC.LineTo(StoredMaxX,StoredMaxY);
clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
m_IsVisible = true;
}
if (m_Pen)
clientDC.SelectObject(aOldPen);
} }
void CAnimationView3D::OnStop() void CAnimationView3D::OnStop()
{ {
KillTimer(GetDocument()->myCount); KillTimer(GetDocument()->myCount);

View File

@ -13,6 +13,8 @@
#include "AnimationDoc.h" #include "AnimationDoc.h"
#include "..\..\Common\res\OCC_Resource.h" #include "..\..\Common\res\OCC_Resource.h"
class AIS_RubberBand;
enum View3D_CurrentAction { enum View3D_CurrentAction {
CurrentAction3d_Nothing, CurrentAction3d_Nothing,
CurrentAction3d_DynamicZooming, CurrentAction3d_DynamicZooming,
@ -146,14 +148,9 @@ private:
double m_Focus ; double m_Focus ;
private: private:
enum LineStyle { Solid, Dot, ShortDash, LongDash, Default }; Handle(AIS_RubberBand) myRect; //!< Rubber rectangle for selection
CPen* m_Pen; void DrawRectangle (Standard_Integer theMinX, Standard_Integer theMinY, Standard_Integer theMaxX, Standard_Integer theMaxY,
virtual void DrawRectangle (const Standard_Integer MinX , Standard_Boolean theToDraw, Aspect_TypeOfLine theLineType = Aspect_TOL_SOLID);
const Standard_Integer MinY ,
const Standard_Integer MaxX ,
const Standard_Integer MaxY ,
const Standard_Boolean Draw ,
const LineStyle aLineStyle = Default );
}; };
#ifndef _DEBUG // debug version in AnimationView.cpp #ifndef _DEBUG // debug version in AnimationView.cpp

View File

@ -7,6 +7,7 @@
#include "OCCDemoDoc.h" #include "OCCDemoDoc.h"
#include "OCCDemoView.h" #include "OCCDemoView.h"
#include <AIS_RubberBand.hxx>
#include <Graphic3d_GraphicDriver.hxx> #include <Graphic3d_GraphicDriver.hxx>
#define ValZWMin 1 #define ValZWMin 1
@ -69,7 +70,7 @@ COCCDemoView::COCCDemoView()
myCurZoom=0; myCurZoom=0;
myCurrentMode = CurAction3d_Nothing; myCurrentMode = CurAction3d_Nothing;
myVisMode = VIS_SHADE; myVisMode = VIS_SHADE;
m_Pen = NULL; myRect = new AIS_RubberBand (Quantity_NOC_WHITE, Aspect_TOL_SOLID, 1.0);
myGraphicDriver = ((COCCDemoApp*)AfxGetApp())->GetGraphicDriver(); myGraphicDriver = ((COCCDemoApp*)AfxGetApp())->GetGraphicDriver();
} }
@ -77,8 +78,6 @@ COCCDemoView::~COCCDemoView()
{ {
if (!myView.IsNull()) if (!myView.IsNull())
myView->Remove(); myView->Remove();
if (m_Pen)
delete m_Pen;
} }
BOOL COCCDemoView::PreCreateWindow(CREATESTRUCT& cs) BOOL COCCDemoView::PreCreateWindow(CREATESTRUCT& cs)
@ -336,8 +335,7 @@ void COCCDemoView::OnMouseMove(UINT nFlags, CPoint point)
break; break;
case CurAction3d_WindowZooming : case CurAction3d_WindowZooming :
myXmax = point.x; myYmax = point.y; myXmax = point.x; myYmax = point.y;
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_False,LongDash); DrawRectangle (myXmin, myYmin, myXmax, myYmax, Standard_True, Aspect_TOL_DASH);
DrawRectangle(myXmin,myYmin,myXmax,myYmax,Standard_True,LongDash);
break; break;
case CurAction3d_DynamicPanning : case CurAction3d_DynamicPanning :
myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning myView->Pan(point.x-myXmax,myYmax-point.y); // Realize the panning
@ -407,67 +405,34 @@ void COCCDemoView::OnUpdateBUTTONRot(CCmdUI* pCmdUI)
pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation); pCmdUI->Enable (myCurrentMode != CurAction3d_DynamicRotation);
} }
void COCCDemoView::DrawRectangle(const Standard_Integer MinX, void COCCDemoView::DrawRectangle (Standard_Integer theMinX,
const Standard_Integer MinY, Standard_Integer theMinY,
const Standard_Integer MaxX, Standard_Integer theMaxX,
const Standard_Integer MaxY, Standard_Integer theMaxY,
const Standard_Boolean Draw, Standard_Boolean theToDraw,
const LineStyle aLineStyle) Aspect_TypeOfLine theLineType)
{ {
static int m_DrawMode; const Handle(AIS_InteractiveContext)& aCtx = GetDocument()->GetAISContext();
if (!m_Pen && aLineStyle ==Solid ) if (!theToDraw)
{ {
m_Pen = new CPen(PS_SOLID, 1, RGB(0,0,0)); m_DrawMode = R2_MERGEPENNOT; aCtx->Remove (myRect, false);
} aCtx->CurrentViewer()->RedrawImmediate();
else if (!m_Pen && aLineStyle ==Dot ) return;
{
m_Pen = new CPen(PS_DOT, 1, RGB(0,0,0)); m_DrawMode = R2_XORPEN;
}
else if (!m_Pen && aLineStyle == ShortDash)
{
m_Pen = new CPen(PS_DASH, 1, RGB(255,0,0)); m_DrawMode = R2_XORPEN;
}
else if (!m_Pen && aLineStyle == LongDash)
{
m_Pen = new CPen(PS_DASH, 1, RGB(0,0,0)); m_DrawMode = R2_NOTXORPEN;
}
else if (aLineStyle == Default)
{
m_Pen = NULL; m_DrawMode = R2_MERGEPENNOT;
} }
CPen* aOldPen = NULL; CRect aRect;
CClientDC clientDC(this); GetWindowRect (aRect);
if (m_Pen) myRect->SetLineType (theLineType);
aOldPen = clientDC.SelectObject(m_Pen); myRect->SetRectangle (theMinX, aRect.Height() - theMinY, theMaxX, aRect.Height() - theMaxY);
clientDC.SetROP2(m_DrawMode); if (!aCtx->IsDisplayed (myRect))
static Standard_Integer StoredMinX, StoredMaxX, StoredMinY, StoredMaxY;
static Standard_Boolean m_IsVisible = Standard_False;
if ( m_IsVisible && !Draw) // move or up : erase at the old position
{ {
clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY); aCtx->Display (myRect, false);
clientDC.LineTo(StoredMaxX,StoredMaxY);
clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
m_IsVisible = false;
} }
else
StoredMinX = Min ( MinX, MaxX );
StoredMinY = Min ( MinY, MaxY );
StoredMaxX = Max ( MinX, MaxX );
StoredMaxY = Max ( MinY, MaxY);
if (Draw) // move : draw
{ {
clientDC.MoveTo(StoredMinX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMaxY); aCtx->Redisplay (myRect, false);
clientDC.LineTo(StoredMaxX,StoredMaxY);
clientDC.LineTo(StoredMaxX,StoredMinY); clientDC.LineTo(StoredMinX,StoredMinY);
m_IsVisible = true;
} }
aCtx->CurrentViewer()->RedrawImmediate();
if (m_Pen)
clientDC.SelectObject(aOldPen);
} }
void COCCDemoView::InitButtons() void COCCDemoView::InitButtons()

View File

@ -18,6 +18,8 @@ enum View3D_CurrentAction {
CurAction3d_DynamicRotation CurAction3d_DynamicRotation
}; };
class AIS_RubberBand;
class COCCDemoView : public CView class COCCDemoView : public CView
{ {
protected: // create from serialization only protected: // create from serialization only
@ -119,14 +121,13 @@ private:
Standard_Real myCurZoom; Standard_Real myCurZoom;
private: private:
enum LineStyle { Solid, Dot, ShortDash, LongDash, Default }; Handle(AIS_RubberBand) myRect; //!< Rubber rectangle for selection
CPen* m_Pen;
virtual void DrawRectangle (const Standard_Integer MinX , virtual void DrawRectangle (const Standard_Integer MinX ,
const Standard_Integer MinY , const Standard_Integer MinY ,
const Standard_Integer MaxX , const Standard_Integer MaxX ,
const Standard_Integer MaxY , const Standard_Integer MaxY ,
const Standard_Boolean Draw , const Standard_Boolean Draw ,
const LineStyle aLineStyle = Default ); Aspect_TypeOfLine theLineType = Aspect_TOL_SOLID);
}; };