3c0d573c46
- aggiunta gestione selezione con mouse - aggiunta gestione selezione punti notevoli (snap points).
125 lines
4.0 KiB
C++
125 lines
4.0 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : SceneSnap.cpp Data : 09.10.14 Versione : 1.5j1
|
|
// Contenuto : Implementazione snap di punti trmite selezione.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 09.10.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "Scene.h"
|
|
#include "/EgtDev/Include/EGkGeomDB.h"
|
|
#include "/EgtDev/Include/EGkFrame3d.h"
|
|
#include "/EgtDev/Include/EGkCurve.h"
|
|
#include "/EgtDev/Include/EGkDistPointCurve.h"
|
|
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Scene::GetSelectedSnapPoint( int nSnap, const Point3d& ptWin, int nW, int nH, Point3d& ptSel)
|
|
{
|
|
// verifico siano state selezionate delle entità
|
|
int nSel ;
|
|
Select( ptWin, nW, nH, nSel) ;
|
|
if ( nSel <= 0)
|
|
return false ;
|
|
// recupero le entità selezionate
|
|
INTVECTOR nIds ;
|
|
GetSelectedObjs( nIds) ;
|
|
// cerco il punto estremo più vicino alla selezione
|
|
bool bFound = false ;
|
|
double dMinSqDist = INFINITO * INFINITO ;
|
|
for ( size_t i = 0 ; i < nIds.size() ; ++ i) {
|
|
// recupero geometria e frame dell'entità
|
|
const ICurve* pCrv = GetCurve( m_pGeomDB->GetGeoObj( nIds[i])) ;
|
|
if ( pCrv == nullptr)
|
|
continue ;
|
|
Frame3d frEnt ;
|
|
if ( ! m_pGeomDB->GetGlobFrame( nIds[i], frEnt))
|
|
continue ;
|
|
// recupero il punto
|
|
Point3d ptP ;
|
|
switch ( nSnap) {
|
|
case SP_END :
|
|
// punto iniziale
|
|
if ( pCrv->GetStartPoint( ptP)) {
|
|
ptP.ToGlob( frEnt) ;
|
|
if ( VerifySnapPoint( ptP, ptWin, dMinSqDist)) {
|
|
bFound = true ;
|
|
ptSel = ptP ;
|
|
}
|
|
}
|
|
// punto finale
|
|
if ( pCrv->GetEndPoint( ptP)) {
|
|
ptP.ToGlob( frEnt) ;
|
|
if ( VerifySnapPoint( ptP, ptWin, dMinSqDist)) {
|
|
bFound = true ;
|
|
ptSel = ptP ;
|
|
}
|
|
}
|
|
break ;
|
|
case SP_MID :
|
|
if ( pCrv->GetMidPoint( ptP)) {
|
|
ptP.ToGlob( frEnt) ;
|
|
if ( VerifySnapPoint( ptP, ptWin, dMinSqDist)) {
|
|
bFound = true ;
|
|
ptSel = ptP ;
|
|
}
|
|
}
|
|
break ;
|
|
case SP_CENTER :
|
|
if ( pCrv->GetCenterPoint( ptP)) {
|
|
ptP.ToGlob( frEnt) ;
|
|
if ( VerifySnapPoint( ptP, ptWin, dMinSqDist)) {
|
|
bFound = true ;
|
|
ptSel = ptP ;
|
|
}
|
|
}
|
|
break ;
|
|
case SP_NEAR :
|
|
{ // il punto di riferimento deriva da XY su viewport e Z da selezione
|
|
Point3d ptRefWin( ptWin.x, ptWin.y, GetSelectedObjWinZ( int( i))) ;
|
|
Point3d ptRef ;
|
|
// lo porto da spazio grafico a spazio geometrico globale
|
|
UnProject( ptRefWin, ptRef) ;
|
|
// lo porto nel frame della curva
|
|
ptRef.ToLoc( frEnt) ;
|
|
// determino il punto più vicino della curva a questo
|
|
int nFlag ;
|
|
DistPointCurve dstPtCurve( ptRef, *pCrv) ;
|
|
if ( dstPtCurve.GetMinDistPoint( 0, ptP, nFlag)) {
|
|
ptP.ToGlob( frEnt) ;
|
|
if ( VerifySnapPoint( ptP, ptWin, dMinSqDist)) {
|
|
bFound = true ;
|
|
ptSel = ptP ;
|
|
}
|
|
}
|
|
} break ;
|
|
}
|
|
}
|
|
return bFound ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Scene::VerifySnapPoint( const Point3d& ptP, const Point3d& ptWin, double& dMinSqDist)
|
|
{
|
|
// proietto il punto sulla viewport
|
|
Point3d ptWinP ;
|
|
Project( ptP, ptWinP) ;
|
|
// confronto le distanze
|
|
double dSqDist = SqDistXY( ptWin, ptWinP) ;
|
|
if ( dSqDist < dMinSqDist) {
|
|
dMinSqDist = dSqDist ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
} |