40d784806b
- in ExeCAvToolPathStm disabilitando la tolleranza si disabilita anche il controllo massima lunghezza segmento - eliminata funzione Exe/Lua GetSurfTmSilhouetteEx sostituita con GetSurfTmParSilhouettes.
220 lines
7.9 KiB
C++
220 lines
7.9 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2018-2018
|
|
//----------------------------------------------------------------------------
|
|
// File : EXE_CAvTool.cpp Data : 28.04.18 Versione : 1.9e1
|
|
// Contenuto : Funzioni per evitare collisioni dell'utensile.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 28.04.18 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "EXE.h"
|
|
#include "EXE_Macro.h"
|
|
#include "EXE_Const.h"
|
|
#include "AuxTools.h"
|
|
#include "GeoTools.h"
|
|
#include "/EgtDev/Include/EXeExecutor.h"
|
|
#include "/EgtDev/Include/EXeConst.h"
|
|
#include "/EgtDev/Include/EGkCurve.h"
|
|
#include "/EgtDev/Include/EGkCurveComposite.h"
|
|
#include "/EgtDev/Include/EGkStmStandard.h"
|
|
#include "/EgtDev/Include/EGkCAvToolSurfTm.h"
|
|
#include "/EgtDev/Include/EgtNumUtils.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
static PtrOwner<ICAvToolSurfTm> s_pCAvTlStm( CreateCAvToolSurfTm()) ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCAvSetStdTool( double dToolLen, double dToolDiam, double dToolCornR)
|
|
{
|
|
if ( IsNull( s_pCAvTlStm))
|
|
return false ;
|
|
return s_pCAvTlStm->SetStdTool( dToolLen, dToolDiam / 2, dToolCornR) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCAvSetAdvTool( double dToolLen, double dToolDiam, double dTipLen, double dTipDiam, double dToolCornR)
|
|
{
|
|
if ( IsNull( s_pCAvTlStm))
|
|
return false ;
|
|
return s_pCAvTlStm->SetAdvTool( dToolLen, dToolDiam / 2, dTipLen, dTipDiam / 2, dToolCornR) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCAvSetSawTool( double dToolLen, double dToolDiam, double dThickness, double dStemDiam, double dToolCornR)
|
|
{
|
|
if ( IsNull( s_pCAvTlStm))
|
|
return false ;
|
|
return s_pCAvTlStm->SetSawTool( dToolLen, dToolDiam / 2, dThickness, dStemDiam / 2, dToolCornR) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCAvSetGenTool( int nToolSectId)
|
|
{
|
|
if ( IsNull( s_pCAvTlStm))
|
|
return false ;
|
|
// verifico DB geometrico
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la sezione dell'utensile
|
|
const ICurveComposite* pCC = GetCurveComposite( pGeomDB->GetGeoObj( nToolSectId)) ;
|
|
if ( pCC == nullptr)
|
|
return false ;
|
|
// assegno i dati dell'utensile
|
|
return s_pCAvTlStm->SetGenTool( pCC) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
int
|
|
ExeCAvGetToolOutline( int nDestGrpId, bool bApprox)
|
|
{
|
|
if ( IsNull( s_pCAvTlStm))
|
|
return GDB_ID_NULL ;
|
|
// verifico DB geometrico
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL)
|
|
// recupero outline dell'utensile
|
|
const ICurveComposite& CC = s_pCAvTlStm->GetToolOutline( bApprox) ;
|
|
if ( ! CC.IsValid())
|
|
return GDB_ID_NULL ;
|
|
// ne faccio una copia
|
|
PtrOwner<ICurveComposite> pCopy( CC.Clone()) ;
|
|
if ( IsNull( pCopy))
|
|
return GDB_ID_NULL ;
|
|
// inserisco la copia nel DB geometrico
|
|
int nId = pGeomDB->AddGeoObj( GDB_ID_NULL, nDestGrpId, Release( pCopy)) ;
|
|
ExeSetModified() ;
|
|
return nId ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
double
|
|
ExeCAvToolPosBox( const Point3d& ptP, const Vector3d& vtAx, const BBox3d& b3Box, const Vector3d& vtMove)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// creo la superficie TriMesh
|
|
PtrOwner<ISurfTriMesh> pStm( GetSurfTriMeshBox( b3Box.GetDimX(), b3Box.GetDimY(), b3Box.GetDimZ())) ;
|
|
if ( IsNull( pStm))
|
|
return -1 ;
|
|
pStm->Translate( b3Box.GetMin() - ORIG) ;
|
|
// verifico oggetto per evitare collisioni
|
|
if ( IsNull( s_pCAvTlStm))
|
|
return -1 ;
|
|
// imposto dati
|
|
s_pCAvTlStm->SetSurfTm( *pStm) ;
|
|
double dMove ;
|
|
if ( ! s_pCAvTlStm->TestPosition( ptP, vtAx, vtMove, dMove))
|
|
return -1 ;
|
|
return dMove ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
double
|
|
ExeCAvToolPosStm( const Point3d& ptP, const Vector3d& vtAx, int nSurfTmId, const Vector3d& vtMove, int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la superficie TriMesh
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ;
|
|
if ( pStm == nullptr)
|
|
return -1 ;
|
|
// recupero il riferimento della superficie
|
|
Frame3d frSurf ;
|
|
if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf))
|
|
return -1 ;
|
|
// verifico oggetto per evitare collisioni
|
|
if ( IsNull( s_pCAvTlStm))
|
|
return -1 ;
|
|
// porto i dati geometrici in locale
|
|
Point3d ptPL = GetPointLocal( pGeomDB, ptP, nRefType, frSurf) ;
|
|
Vector3d vtAxL = GetVectorLocal( pGeomDB, vtAx, nRefType, frSurf) ;
|
|
Vector3d vtMoveL = GetVectorLocal( pGeomDB, vtMove, nRefType, frSurf) ;
|
|
// imposto dati
|
|
s_pCAvTlStm->SetSurfTm( *pStm) ;
|
|
double dMove ;
|
|
if ( ! s_pCAvTlStm->TestPosition( ptPL, vtAxL, vtMoveL, dMove))
|
|
return -1 ;
|
|
return dMove ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ExeCAvToolPathStm( int nCrvId, const Vector3d& vtAx, int nSurfTmId, const Vector3d& vtMove, double dLinTol, int nRefType)
|
|
{
|
|
IGeomDB* pGeomDB = GetCurrGeomDB() ;
|
|
VERIFY_GEOMDB( pGeomDB, false)
|
|
// recupero la curva
|
|
const ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nCrvId)) ;
|
|
if ( pCrv == nullptr)
|
|
return false ;
|
|
// recupero il riferimento della curva
|
|
Frame3d frCrv ;
|
|
if ( ! pGeomDB->GetGlobFrame( nCrvId, frCrv))
|
|
return false ;
|
|
// recupero la superficie TriMesh
|
|
const ISurfTriMesh* pStm = GetSurfTriMesh( pGeomDB->GetGeoObj( nSurfTmId)) ;
|
|
if ( pStm == nullptr)
|
|
return false ;
|
|
// recupero il riferimento della superficie
|
|
Frame3d frSurf ;
|
|
if ( ! pGeomDB->GetGlobFrame( nSurfTmId, frSurf))
|
|
return false ;
|
|
// verifico oggetto per evitare collisioni
|
|
if ( IsNull( s_pCAvTlStm))
|
|
return false ;
|
|
// Controllo la tolleranza lineare (se negativa non vanno fatti controlli sui punti medi)
|
|
if ( dLinTol > -EPS_ZERO)
|
|
dLinTol = max( dLinTol, EPS_SMALL) ;
|
|
else
|
|
dLinTol = -1 ;
|
|
// approssimo la curva con una polilinea
|
|
PolyLine PL ;
|
|
if ( ! pCrv->ApproxWithLines( dLinTol, ANG_TOL_STD_DEG, ICurve::APL_SPECIAL, PL))
|
|
return false ;
|
|
// eventuale aggiunta di punti per garantire max distanza
|
|
if ( dLinTol > 0) {
|
|
const double MIN_DIST = 1. ;
|
|
const double MAX_DIST = 50. ;
|
|
double dDist = Clamp( s_pCAvTlStm->GetToolRadius(), MIN_DIST, MAX_DIST) ;
|
|
if ( ! PL.AdjustForMaxSegmentLen( dDist))
|
|
return false ;
|
|
}
|
|
// porto nel riferimento della superficie
|
|
PL.LocToLoc( frCrv, frSurf) ;
|
|
// porto i dati geometrici in locale alla superficie
|
|
Vector3d vtAxL = GetVectorLocal( pGeomDB, vtAx, nRefType, frSurf) ;
|
|
Vector3d vtMoveL = GetVectorLocal( pGeomDB, vtMove, nRefType, frSurf) ;
|
|
// imposto dati
|
|
s_pCAvTlStm->SetSurfTm( *pStm) ;
|
|
// eseguo CAv
|
|
if ( ! s_pCAvTlStm->TestPath( PL.GetUPointList(), vtAxL, vtMoveL, dLinTol))
|
|
return false ;
|
|
// riporto la polilinea nel riferimento della curva
|
|
PL.LocToLoc( frSurf, frCrv) ;
|
|
// elimino i punti allineati
|
|
if ( dLinTol > 0)
|
|
PL.RemoveAlignedPoints( 0.8 * dLinTol) ;
|
|
// creo una curva composita a partire dalla polilinea
|
|
PtrOwner< ICurveComposite> pCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCompo) || ! pCompo->FromPolyLine( PL))
|
|
return false ;
|
|
// sostituisco la vecchia curva con la nuova
|
|
if ( ! pGeomDB->ReplaceGeoObj( nCrvId, Release( pCompo)))
|
|
return false ;
|
|
ExeSetModified() ;
|
|
return true ;
|
|
}
|