TestEgr 1.5j1 :

- aggiornamento per selezione con mouse
- aggiornamento per distanza con punti notevoli.
This commit is contained in:
Dario Sassi
2014-10-10 06:43:42 +00:00
parent 61dea6c98e
commit 578cbb2b55
15 changed files with 470 additions and 13 deletions
+193 -8
View File
@@ -15,15 +15,22 @@
#include "stdafx.h"
#include "TestEGrView.h"
#include "TestEGrUtils.h"
#include "SelectDlg.h"
#include "resource.h"
#include "/EgtDev/Include/EgkGdbConst.h"
#include "/EgtDev/Include/EgkGeomDB.h"
#include "/EgtDev/Include/EgkCurve.h"
#include "/EgtDev/Include/EgkStringUtils3d.h"
#include "/EgtDev/Include/EGrScene.h"
#include "/EgtDev/Include/EgtPerfCounter.h"
#include "/EgtDev/Include/EgtILogger.h"
#include "/EgtDev/Include/EgnStringUtils.h"
#include "/EgtDev/Include/EgnStringConverter.h"
#include "/EgtDev/Include/EGrScene.h"
using namespace std ;
//----------------------------------------------------------------------------
static const int DIM_SEL = 13 ;
//----------------------------------------------------------------------------
#ifdef _DEBUG
#define new DEBUG_NEW
@@ -34,10 +41,14 @@ using namespace std ;
//----------------------------------------------------------------------------
BEGIN_MESSAGE_MAP( TestEGrView, CWnd)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_RBUTTONUP()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_MOUSEWHEEL()
ON_COMMAND_RANGE( IDM_ENDPOINT, IDM_NEARPOINT, OnSelSnapPoint)
END_MESSAGE_MAP()
//----------------------------------------------------------------------------
@@ -46,7 +57,10 @@ TestEGrView::TestEGrView( void)
m_pDC = nullptr ;
m_pScene = nullptr ;
m_nStatus = ST_NULL ;
m_nOldStatus = ST_NULL ;
m_PrevPoint.SetPoint( 0, 0) ;
m_ptPrev.Set( 0, 0, 0) ;
m_nSnapPoint = SP_END ;
}
//----------------------------------------------------------------------------
@@ -78,7 +92,7 @@ TestEGrView::Create( CWnd* pParent, int nID)
if ( CreateEx( 0, className, L"TestEGrView",
WS_VISIBLE | WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, rectWin, pParent, nID) != 0) {
SetWindowPos( &wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE) ;
SetCursor( AfxGetApp()->LoadCursor( IDC_POINTER)) ;
SetCursor( AfxGetApp()->LoadCursor( IDC_SELECT)) ;
m_pDC = new CClientDC( this) ;
m_pScene = CreateEGrScene() ;
@@ -275,19 +289,168 @@ TestEGrView::View( UINT nID)
RedrawWindow() ;
}
//----------------------------------------------------------------------------
void
TestEGrView::SetAnalyze( void)
{
m_nStatus = ST_ANALYZE ;
}
//----------------------------------------------------------------------------
void
TestEGrView::SetGetDistance( void)
{
m_pScene->ResetGeoLine() ;
m_pScene->Draw() ;
m_nStatus = ST_GETDIST ;
}
//----------------------------------------------------------------------------
void
TestEGrView::OnLButtonDown( UINT nFlags, CPoint point)
{
if ( m_nStatus == ST_NULL) {
int nSel ;
m_pScene->Select( Point3d( point.x, point.y), DIM_SEL, DIM_SEL, nSel) ;
if ( nSel == 1) {
int nId = m_pScene->GetFirstSelectedObj() ;
if ( m_pScene->GetGeomDB()->IsSelectedObj( nId))
m_pScene->GetGeomDB()->DeselectObj( nId) ;
else
m_pScene->GetGeomDB()->SelectObj( nId) ;
m_pScene->Draw() ;
}
else if ( nSel > 1) {
CSelectDlg dlgSelect( m_pScene) ;
dlgSelect.DoModal() ;
int nId = dlgSelect.GetCurrId() ;
if ( nId != GDB_ID_NULL) {
if ( m_pScene->GetGeomDB()->IsSelectedObj( nId))
m_pScene->GetGeomDB()->DeselectObj( nId) ;
else
m_pScene->GetGeomDB()->SelectObj( nId) ;
m_pScene->Draw() ;
}
}
}
else if ( m_nStatus == ST_ANALYZE) {
int nSel = 0 ;
int nId = GDB_ID_NULL ;
m_pScene->Select( Point3d( point.x, point.y), DIM_SEL, DIM_SEL, nSel) ;
if ( nSel == 1)
nId = m_pScene->GetFirstSelectedObj() ;
else if ( nSel > 1) {
CSelectDlg dlgSelect( m_pScene) ;
dlgSelect.DoModal() ;
nId = dlgSelect.GetCurrId() ;
}
if ( nId != GDB_ID_NULL)
SelectIdInGeomDbTree( nId) ;
SetCursor( AfxGetApp()->LoadCursor( IDC_SELECT)) ;
m_nStatus = ST_NULL ;
}
else if ( m_nStatus == ST_GETDIST) {
if ( m_pScene->GetSelectedSnapPoint( m_nSnapPoint, Point3d( point.x, point.y), DIM_SEL, DIM_SEL, m_ptPrev)) {
// salvo il punto di riferimento
Point3d ptWin ;
m_pScene->Project( m_ptPrev, ptWin) ;
m_PrevPoint.SetPoint( int( ptWin.x), int( ptWin.y)) ;
m_nStatus = ST_GETDIST2 ;
}
else {
SetCursor( AfxGetApp()->LoadCursor( IDC_SELECT)) ;
m_nStatus = ST_NULL ;
}
}
else if ( m_nStatus == ST_GETDIST2) {
// recupero il punto selezionato
Point3d ptSel ;
if ( m_pScene->GetSelectedSnapPoint( m_nSnapPoint, Point3d( point.x, point.y), DIM_SEL, DIM_SEL, ptSel)) {
// disegno la linea (coordinate geo globali)
m_pScene->SetGeoLine( m_ptPrev, ptSel) ;
RedrawWindow() ;
// calcolo la distanza e il delta e li visualizzo
double dDist = Dist( ptSel, m_ptPrev) ;
Vector3d vtDiff = ptSel - m_ptPrev ;
string sOut ;
sOut = "Dist=" + ToString( dDist, 4) +
" dX=" + ToString( vtDiff.x, 4) +
" dY=" + ToString( vtDiff.y, 4) +
" dZ=" + ToString( vtDiff.z, 4) ;
AfxMessageBox( stringtoW( sOut), MB_ICONINFORMATION | MB_OK) ;
}
// annullo eventuale linea di misura e lo stato
m_pScene->ResetGeoLine() ;
RedrawWindow() ;
m_nStatus = ST_NULL ;
}
}
//----------------------------------------------------------------------------
void
TestEGrView::OnLButtonUp( UINT nFlags, CPoint point)
{
;
}
//----------------------------------------------------------------------------
void
TestEGrView::OnRButtonUp( UINT nFlags, CPoint point)
{
// se utile menù punti notevoli proseguo
if ( m_nStatus != ST_GETDIST && m_nStatus != ST_GETDIST2)
return ;
// inserisco menù per punti notevoli
CMenu Menu ;
Menu.CreatePopupMenu() ;
Menu.AppendMenu( MF_STRING, IDM_ENDPOINT, L"EndPoint") ;
Menu.CheckMenuItem( IDM_ENDPOINT, MF_BYCOMMAND | ( m_nSnapPoint == SP_END ? MF_CHECKED : MF_UNCHECKED)) ;
Menu.AppendMenu( MF_STRING, IDM_MIDPOINT, L"MidPoint") ;
Menu.CheckMenuItem( IDM_MIDPOINT, MF_BYCOMMAND | ( m_nSnapPoint == SP_MID ? MF_CHECKED : MF_UNCHECKED)) ;
Menu.AppendMenu( MF_STRING, IDM_CENTERPOINT, L"CenterPoint") ;
Menu.CheckMenuItem( IDM_CENTERPOINT, MF_BYCOMMAND | ( m_nSnapPoint == SP_CENTER ? MF_CHECKED : MF_UNCHECKED)) ;
Menu.AppendMenu( MF_STRING, IDM_NEARPOINT, L"NearPoint") ;
Menu.CheckMenuItem( IDM_NEARPOINT, MF_BYCOMMAND | ( m_nSnapPoint == SP_NEAR ? MF_CHECKED : MF_UNCHECKED)) ;
ClientToScreen( &point) ;
Menu.TrackPopupMenu( TPM_LEFTALIGN, point.x, point.y, this) ;
}
//----------------------------------------------------------------------------
void
TestEGrView::OnSelSnapPoint( UINT nID)
{
switch ( nID) {
case IDM_ENDPOINT :
m_nSnapPoint = SP_END ;
break ;
case IDM_MIDPOINT :
m_nSnapPoint = SP_MID ;
break ;
case IDM_CENTERPOINT :
m_nSnapPoint = SP_CENTER ;
break ;
case IDM_NEARPOINT :
m_nSnapPoint = SP_NEAR ;
break ;
}
}
//----------------------------------------------------------------------------
void
TestEGrView::OnMButtonDown( UINT nFlags, CPoint point)
{
if ( nFlags & MK_SHIFT) {
m_nOldStatus = ( m_nStatus == ST_GETDIST2) ? ST_GETDIST2 : ST_NULL ;
m_nStatus = ST_ZOOMWIN ;
SetCursor( AfxGetApp()->LoadCursor( IDC_ZOOMWIN)) ;
}
else if ( nFlags & MK_CONTROL) {
m_nOldStatus = ( m_nStatus == ST_GETDIST2) ? ST_GETDIST2 : ST_NULL ;
m_nStatus = ST_ROT ;
SetCursor( AfxGetApp()->LoadCursor( IDC_ROTATE)) ;
}
else {
m_nOldStatus = ( m_nStatus == ST_GETDIST2) ? ST_GETDIST2 : ST_NULL ;
m_nStatus = ST_PAN ;
SetCursor( AfxGetApp()->LoadCursor( IDC_PAN)) ;
}
@@ -310,10 +473,15 @@ TestEGrView::OnMButtonUp( UINT nFlags, CPoint point)
// aggiorno il disegno
RedrawWindow() ;
}
// eventuale ripristino vecchio stato
if ( m_nOldStatus == ST_GETDIST2) {
m_nStatus = ST_GETDIST2 ;
SetCursor( AfxGetApp()->LoadCursor( IDC_GETDIST)) ;
}
// reset dello stato se non NULL
if ( m_nStatus != ST_NULL) {
else if ( m_nStatus != ST_NULL) {
m_nStatus = ST_NULL ;
SetCursor( AfxGetApp()->LoadCursor( IDC_POINTER)) ;
SetCursor( AfxGetApp()->LoadCursor( IDC_SELECT)) ;
}
}
@@ -357,9 +525,26 @@ TestEGrView::OnMouseMove( UINT nFlags, CPoint point)
// salvo il punto di riferimento
m_PrevPoint = point ;
}
// se in modalità ANALYZE
else if ( m_nStatus == ST_ANALYZE) {
SetCursor( AfxGetApp()->LoadCursor( IDC_ANALYZE)) ;
}
// se in modalità GETDIST
else if ( m_nStatus == ST_GETDIST) {
SetCursor( AfxGetApp()->LoadCursor( IDC_GETDIST)) ;
}
// se in modalità GETDIST2
else if ( m_nStatus == ST_GETDIST2) {
SetCursor( AfxGetApp()->LoadCursor( IDC_GETDIST)) ;
Point3d ptP ;
m_pScene->UnProject( Point3d( point.x, point.y, 0.5), ptP) ;
m_pScene->SetGeoLine( m_ptPrev, ptP) ;
// aggiorno il disegno
RedrawWindow() ;
}
// altrimenti reset dello stato e cursore standard
else {
SetCursor( AfxGetApp()->LoadCursor( IDC_POINTER)) ;
SetCursor( AfxGetApp()->LoadCursor( IDC_SELECT)) ;
m_nStatus = ST_NULL ;
}
}
@@ -368,8 +553,8 @@ TestEGrView::OnMouseMove( UINT nFlags, CPoint point)
BOOL
TestEGrView::OnMouseWheel( UINT nFlags, short zDelta, CPoint point)
{
// devo essere nello stato NULL
if ( m_nStatus != ST_NULL)
// devo essere nello stato NULL o GETDIST
if ( m_nStatus != ST_NULL && m_nStatus != ST_GETDIST && m_nStatus != ST_GETDIST2)
return 0 ;
// calcolo coefficiente