04bb4165c9
- modifiche a UpdateToolData per impostare lavorazione da riverificare se sono cambiati i dati dell'utensile.
1632 lines
56 KiB
C++
1632 lines
56 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2017-2017
|
|
//----------------------------------------------------------------------------
|
|
// File : Chiseling.cpp Data : 04.02.17 Versione : 1.8b1
|
|
// Contenuto : Implementazione gestione scalpellature.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 04.02.17 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "MachMgr.h"
|
|
#include "DllMain.h"
|
|
#include "Chiseling.h"
|
|
#include "OperationConst.h"
|
|
#include "/EgtDev/Include/EGkCurveLine.h"
|
|
#include "/EgtDev/Include/EGkCurveArc.h"
|
|
#include "/EgtDev/Include/EGkCurveComposite.h"
|
|
#include "/EgtDev/Include/EGkArcSpecial.h"
|
|
#include "/EgtDev/Include/EGkChainCurves.h"
|
|
#include "/EgtDev/Include/EGkOffsetCurve.h"
|
|
#include "/EgtDev/Include/EGkSfrCreate.h"
|
|
#include "/EgtDev/Include/EGkSurfTriMesh.h"
|
|
#include "/EgtDev/Include/EGkExtText.h"
|
|
#include "/EgtDev/Include/EGkUserObjFactory.h"
|
|
#include "/EgtDev/Include/EGnStringKeyVal.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
|
|
using namespace std ;
|
|
|
|
//------------------------------ Errors --------------------------------------
|
|
// 2901 = "Error in Chiseling : UpdateToolData failed"
|
|
// 2902 = "Error in Chiseling : Offset not computable"
|
|
// 2903 = "Error in Chiseling : Empty RawBox"
|
|
// 2904 = "Error in Chiseling : Depth not computable"
|
|
// 2906 = "Error in Chiseling : Entity GetElevation"
|
|
// 2907 = "Error in Chiseling : Chaining failed"
|
|
// 2908 = "Error in Chiseling : axes values not calculable"
|
|
// 2909 = "Error in Chiseling : outstroke xx"
|
|
// 2910 = "Error in Chiseling : link movements not calculable"
|
|
// 2911 = "Error in Chiseling : link outstroke xx"
|
|
// 2912 = "Error in Chiseling : post apply not calculable"
|
|
// 2951 = "Warning in Chiseling : Skipped entity (xx)"
|
|
// 2952 = "Warning in Chiseling : Plunges not found"
|
|
// 2953 = "Warning in Chiseling : Tool name changed (xx)"
|
|
// 2954 = "Warning in Chiseling : Tool data changed (xx)"
|
|
// 2955 = "Warning in Chiseling : machining depth (xxx) bigger than MaxMaterial (yyy)"
|
|
|
|
//----------------------------------------------------------------------------
|
|
struct SqHole
|
|
{
|
|
Point3d ptIni ; // punto iniziale
|
|
Vector3d vtExtr ; // direzione di estrusione (dal fondo in su)
|
|
Vector3d vtAux ; // direzione ausiliaria di orientamento
|
|
Vector3d vtMove ; // direzione di movimento libero
|
|
double dLen ; // lunghezza dell'asse
|
|
SqHole( void)
|
|
: ptIni(), vtExtr(), vtAux(), vtMove(), dLen( 0) {}
|
|
SqHole( const Point3d ptI, const Vector3d& vtE, const Vector3d& vtA, const Vector3d& vtM, double dL)
|
|
: ptIni( ptI), vtExtr( vtE), vtAux( vtA), vtMove( vtM), dLen( dL) {}
|
|
} ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
USEROBJ_REGISTER( GetOperationClass( OPER_CHISELING), Chiseling) ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
const string&
|
|
Chiseling::GetClassName( void) const
|
|
{
|
|
return USEROBJ_GETNAME( Chiseling) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
Chiseling*
|
|
Chiseling::Clone( void) const
|
|
{
|
|
// alloco oggetto
|
|
Chiseling* pChisel = new(nothrow) Chiseling ;
|
|
// eseguo copia dei dati
|
|
if ( pChisel != nullptr) {
|
|
try {
|
|
pChisel->m_vId = m_vId ;
|
|
pChisel->m_pMchMgr = m_pMchMgr ;
|
|
pChisel->m_nPhase = m_nPhase ;
|
|
pChisel->m_Params = m_Params ;
|
|
pChisel->m_TParams = m_TParams ;
|
|
pChisel->m_nStatus = m_nStatus ;
|
|
pChisel->m_nChisels = m_nChisels ;
|
|
}
|
|
catch( ...) {
|
|
delete pChisel ;
|
|
return nullptr ;
|
|
}
|
|
}
|
|
// ritorno l'oggetto
|
|
return pChisel ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::Dump( string& sOut, bool bMM, const char* szNewLine) const
|
|
{
|
|
sOut += GetClassName() + "[mm]" + szNewLine ;
|
|
sOut += KEY_PHASE + EQUAL + ToString( m_nPhase) + szNewLine ;
|
|
sOut += KEY_IDS + EQUAL + ToString( m_vId) + szNewLine ;
|
|
for ( int i = 0 ; i < m_Params.GetSize() ; ++ i)
|
|
sOut += m_Params.ToString( i) + szNewLine ;
|
|
for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i)
|
|
sOut += m_TParams.ToString( i) + szNewLine ;
|
|
sOut += KEY_NUM + EQUAL + ToString( m_nChisels) + szNewLine ;
|
|
sOut += KEY_STAT + EQUAL + ToString( m_nStatus) + szNewLine ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::Save( int nBaseId, STRVECTOR& vString) const
|
|
{
|
|
try {
|
|
int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() + 3 ;
|
|
vString.insert( vString.begin(), nSize, "") ;
|
|
int k = - 1 ;
|
|
if ( ! SetVal( KEY_IDS, m_vId, vString[++k]))
|
|
return false ;
|
|
for ( int i = 0 ; i < m_Params.GetSize() ; ++ i)
|
|
vString[++k] = m_Params.ToString( i) ;
|
|
for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i)
|
|
vString[++k] = m_TParams.ToString( i) ;
|
|
if ( ! SetVal( KEY_PHASE, m_nPhase, vString[++k]))
|
|
return false ;
|
|
if ( ! SetVal( KEY_NUM, m_nChisels, vString[++k]))
|
|
return false ;
|
|
if ( ! SetVal( KEY_STAT, m_nStatus, vString[++k]))
|
|
return false ;
|
|
}
|
|
catch( ...) {
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::Load( const STRVECTOR& vString, int nBaseGdbId)
|
|
{
|
|
int nSize = int( vString.size()) ;
|
|
// lista identificativi geometrie da lavorare
|
|
int k = - 1 ;
|
|
if ( k >= nSize - 1 || ! GetVal( vString[++k], KEY_IDS, m_vId))
|
|
return false ;
|
|
for ( auto& Sel : m_vId)
|
|
Sel.nId += nBaseGdbId ;
|
|
// parametri lavorazione
|
|
for ( int i = 0 ; i < m_Params.GetSize() ; ++ i) {
|
|
int nKey ;
|
|
if ( k >= nSize - 1 || ! m_Params.FromString( vString[++k], nKey) || nKey != i) {
|
|
if ( m_Params.IsOptional( i))
|
|
-- k ;
|
|
else
|
|
return false ;
|
|
}
|
|
}
|
|
// parametri utensile
|
|
for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i) {
|
|
int nKey ;
|
|
if ( k >= nSize - 1 || ! m_TParams.FromString( vString[++k], nKey) || nKey != i)
|
|
return false ;
|
|
}
|
|
// parametri di stato
|
|
while ( k < nSize - 1) {
|
|
// separo chiave da valore
|
|
string sKey, sVal ;
|
|
SplitFirst( vString[++k], "=", sKey, sVal) ;
|
|
// leggo
|
|
if ( sKey == KEY_PHASE) {
|
|
if ( ! FromString( sVal, m_nPhase))
|
|
return false ;
|
|
}
|
|
else if ( sKey == KEY_NUM) {
|
|
if ( ! FromString( sVal, m_nChisels))
|
|
return false ;
|
|
}
|
|
else if ( sKey == KEY_STAT) {
|
|
if ( ! FromString( sVal, m_nStatus))
|
|
return false ;
|
|
}
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
Chiseling::Chiseling( void)
|
|
{
|
|
m_Params.m_sName = "*" ;
|
|
m_Params.m_sToolName = "*" ;
|
|
m_TParams.m_sName = "*" ;
|
|
m_TParams.m_sHead = "*" ;
|
|
m_nStatus = MCH_ST_TO_VERIFY ;
|
|
m_nChisels = 0 ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::Prepare( const string& sMillName)
|
|
{
|
|
// verifico il gestore lavorazioni
|
|
if ( m_pMchMgr == nullptr)
|
|
return false ;
|
|
// recupero il gestore DB utensili della macchina corrente
|
|
ToolsMgr* pTMgr = m_pMchMgr->GetCurrToolsMgr() ;
|
|
if ( pTMgr == nullptr)
|
|
return false ;
|
|
// recupero il gestore DB lavorazioni della macchina corrente
|
|
MachiningsMgr* pMMgr = m_pMchMgr->GetCurrMachiningsMgr() ;
|
|
if ( pMMgr == nullptr)
|
|
return false ;
|
|
// ricerca della lavorazione di libreria con il nome indicato
|
|
const ChiselingData* pDdata = GetChiselingData( pMMgr->GetMachining( sMillName)) ;
|
|
if ( pDdata == nullptr)
|
|
return false ;
|
|
m_Params = *pDdata ;
|
|
// ricerca dell'utensile usato dalla lavorazione
|
|
const ToolData* pTdata = pTMgr->GetTool( m_Params.m_ToolUuid) ;
|
|
if ( pTdata == nullptr)
|
|
return false ;
|
|
m_TParams = *pTdata ;
|
|
m_Params.m_sToolName = m_TParams.m_sName ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::SetParam( int nType, bool bVal)
|
|
{
|
|
switch ( nType) {
|
|
case MPA_INVERT :
|
|
if ( bVal != m_Params.m_bInvert)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_bInvert = bVal ;
|
|
return true ;
|
|
case MPA_TOOLINVERT :
|
|
if ( bVal != m_Params.m_bToolInvert)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_bToolInvert = bVal ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::SetParam( int nType, int nVal)
|
|
{
|
|
switch ( nType) {
|
|
case MPA_WORKSIDE :
|
|
if ( ! m_Params.VerifyWorkSide( nVal))
|
|
return false ;
|
|
if ( nVal != m_Params.m_nWorkSide)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_nWorkSide = nVal ;
|
|
return true ;
|
|
case MPA_SCC :
|
|
if ( ! m_Params.VerifySolCh( nVal))
|
|
return false ;
|
|
if ( nVal != m_Params.m_nSolCh)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_nSolCh = nVal ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::SetParam( int nType, double dVal)
|
|
{
|
|
switch ( nType) {
|
|
case MPA_FEED :
|
|
if ( abs( m_TParams.m_dFeed - dVal) < EPS_MACH_LEN_PAR)
|
|
dVal = 0 ;
|
|
if ( abs( dVal - m_Params.m_dFeed) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dFeed = dVal ;
|
|
return true ;
|
|
case MPA_ENDFEED :
|
|
if ( abs( m_TParams.m_dEndFeed - dVal) < EPS_MACH_LEN_PAR)
|
|
dVal = 0 ;
|
|
if ( abs( dVal - m_Params.m_dEndFeed) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dEndFeed = dVal ;
|
|
return true ;
|
|
case MPA_TIPFEED :
|
|
if ( abs( m_TParams.m_dTipFeed - dVal) < EPS_MACH_LEN_PAR)
|
|
dVal = 0 ;
|
|
if ( abs( dVal - m_Params.m_dTipFeed) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dTipFeed = dVal ;
|
|
return true ;
|
|
case MPA_OFFSR :
|
|
if ( abs( m_TParams.m_dOffsR - dVal) < EPS_MACH_LEN_PAR)
|
|
dVal = UNKNOWN_PAR ;
|
|
if ( abs( dVal - m_Params.m_dOffsR) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dOffsR = dVal ;
|
|
return true ;
|
|
case MPA_OFFSL :
|
|
if ( abs( m_TParams.m_dOffsL - dVal) < EPS_MACH_LEN_PAR)
|
|
dVal = UNKNOWN_PAR ;
|
|
if ( abs( dVal - m_Params.m_dOffsL) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dOffsL = dVal ;
|
|
return true ;
|
|
case MPA_DEPTH: {
|
|
string sVal = ToString( dVal) ;
|
|
if ( sVal != m_Params.m_sDepth)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sDepth = sVal ;
|
|
} return true ;
|
|
case MPA_STARTPOS :
|
|
if ( abs( dVal - m_Params.m_dStartPos) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dStartPos = dVal ;
|
|
return true ;
|
|
case MPA_STEP :
|
|
if ( abs( dVal - m_Params.m_dStep) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dStep = dVal ;
|
|
return true ;
|
|
case MPA_RETURNPOS :
|
|
if ( abs( dVal - m_Params.m_dReturnPos) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dReturnPos = dVal ;
|
|
return true ;
|
|
case MPA_ENDADDLEN :
|
|
if ( abs( dVal - m_Params.m_dEndAddLen) > EPS_MACH_LEN_PAR)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_dEndAddLen = dVal ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::SetParam( int nType, const string& sVal)
|
|
{
|
|
switch ( nType) {
|
|
case MPA_TOOL : {
|
|
const ToolData* pTdata ;
|
|
if ( ! m_Params.VerifyTool( m_pMchMgr->GetCurrToolsMgr(), sVal, pTdata))
|
|
return false ;
|
|
if ( ! SameTool( m_TParams, *pTdata))
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sToolName = sVal ;
|
|
m_Params.m_ToolUuid = pTdata->m_Uuid ;
|
|
m_TParams = *pTdata ;
|
|
} return true ;
|
|
case MPA_DEPTH_STR :
|
|
if ( sVal != m_Params.m_sDepth)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sDepth = sVal ;
|
|
return true ;
|
|
case MPA_SYSNOTES :
|
|
if ( sVal != m_Params.m_sSysNotes)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sSysNotes = sVal ;
|
|
return true ;
|
|
case MPA_USERNOTES :
|
|
if ( sVal != m_Params.m_sUserNotes)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sUserNotes = sVal ;
|
|
return true ;
|
|
case MPA_INITANGS :
|
|
if ( sVal != m_Params.m_sInitAngs)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sInitAngs = sVal ;
|
|
return true ;
|
|
case MPA_BLOCKEDAXIS :
|
|
if ( sVal != m_Params.m_sBlockedAxis)
|
|
m_nStatus |= MCH_ST_PARAM_MODIF ;
|
|
m_Params.m_sBlockedAxis = sVal ;
|
|
return true ;
|
|
}
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::SetGeometry( const SELVECTOR& vIds)
|
|
{
|
|
// verifico validità gestore DB geometrico
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// copia temporanea e reset della geometria corrente
|
|
SELVECTOR vOldId = m_vId ;
|
|
m_vId.clear() ;
|
|
// verifico che gli identificativi rappresentino delle entità ammissibili (tutte curve o tutte facce)
|
|
int nType = GEO_NONE ;
|
|
for ( const auto& Id : vIds) {
|
|
// test sull'entità
|
|
int nSubs ;
|
|
if ( ! VerifyGeometry( Id, nSubs, nType)) {
|
|
string sInfo = "Warning in Chiseling : Skipped entity " + ToString( Id) ;
|
|
m_pMchMgr->SetWarning( 2951, sInfo) ;
|
|
continue ;
|
|
}
|
|
// posso aggiungere alla lista
|
|
m_vId.emplace_back( Id) ;
|
|
}
|
|
// aggiorno lo stato
|
|
if ( m_vId != vOldId)
|
|
m_nStatus |= MCH_ST_GEO_MODIF ;
|
|
// restituisco presenza geometria da lavorare
|
|
return ( ! m_vId.empty() || vIds.empty()) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::Preview( bool bRecalc)
|
|
{
|
|
// reset numero percorsi di lavoro generati
|
|
m_nChisels = 0 ;
|
|
|
|
// verifico validità gestore DB geometrico e Id del gruppo
|
|
if ( m_pGeomDB == nullptr || ! m_pGeomDB->ExistsObj( m_nOwnerId))
|
|
return false ;
|
|
|
|
// recupero gruppo per geometria ausiliaria
|
|
int nAuxId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_AUX) ;
|
|
bool bChain = false ;
|
|
// se non c'è, lo aggiungo
|
|
if ( nAuxId == GDB_ID_NULL) {
|
|
nAuxId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
|
|
if ( nAuxId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nAuxId, MCH_AUX) ;
|
|
m_pGeomDB->SetStatus( nAuxId, GDB_ST_OFF) ;
|
|
bChain = true ;
|
|
}
|
|
// altrimenti, se chiesto ricalcolo, lo svuoto
|
|
else if ( bRecalc) {
|
|
m_pGeomDB->EmptyGroup( nAuxId) ;
|
|
bChain = true ;
|
|
}
|
|
|
|
// aggiorno dati geometrici dell'utensile
|
|
if ( ! UpdateToolData()) {
|
|
m_pMchMgr->SetLastError( 2901, "Error in Chiseling : UpdateToolData failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria
|
|
if ( bChain && ! Chain( nAuxId)) {
|
|
m_pMchMgr->SetLastError( 2907, "Error in Chiseling : Chaining failed") ;
|
|
return false ;
|
|
}
|
|
// recupero gruppo per geometria di Preview
|
|
int nPvId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_PV) ;
|
|
// se non c'è, lo aggiungo
|
|
if ( nPvId == GDB_ID_NULL) {
|
|
nPvId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
|
|
if ( nPvId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nPvId, MCH_PV) ;
|
|
}
|
|
// altrimenti lo svuoto
|
|
else
|
|
m_pGeomDB->EmptyGroup( nPvId) ;
|
|
|
|
// lavoro ogni singola catena
|
|
int nPathId = m_pGeomDB->GetFirstGroupInGroup( nAuxId) ;
|
|
while ( nPathId != GDB_ID_NULL) {
|
|
if ( ! ProcessPath( nPathId, nPvId, GDB_ID_NULL))
|
|
return false ;
|
|
nPathId = m_pGeomDB->GetNextGroup( nPathId) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::Apply( bool bRecalc, bool bPostApply)
|
|
{
|
|
// reset numero scalpellature generate
|
|
int nCurrChisels = m_nChisels ;
|
|
m_nChisels = 0 ;
|
|
|
|
// verifico validità gestore DB geometrico e Id del gruppo
|
|
if ( m_pGeomDB == nullptr || ! m_pGeomDB->ExistsObj( m_nOwnerId))
|
|
return false ;
|
|
|
|
// aggiorno dati geometrici dell'utensile
|
|
if ( ! UpdateToolData()) {
|
|
m_pMchMgr->SetLastError( 2901, "Error in Chiseling : UpdateToolData failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// se modificata geometria, necessario ricalcolo
|
|
if ( ( m_nStatus & MCH_ST_GEO_MODIF) != 0)
|
|
bRecalc = true ;
|
|
|
|
// verifico se necessario continuare nell'aggiornamento
|
|
if ( ! bRecalc && ( m_nStatus == MCH_ST_OK || m_nStatus == MCH_ST_NO_POSTAPPL)) {
|
|
// confermo i percorsi di lavorazione
|
|
m_nChisels = nCurrChisels ;
|
|
string sLog = string( "Chiseling apply skipped : status ") + ( m_nStatus == MCH_ST_OK ? "already ok" : "no postapply") ;
|
|
LOG_DBG_INFO( GetEMkLogger(), sLog.c_str()) ;
|
|
// eseguo aggiornamento assi macchina e collegamento con operazione precedente
|
|
if ( ! Update( bPostApply))
|
|
return false ;
|
|
m_nStatus = ( bPostApply ? MCH_ST_OK : MCH_ST_NO_POSTAPPL) ;
|
|
LOG_DBG_INFO( GetEMkLogger(), "Update done") ;
|
|
// esco con successo
|
|
return true ;
|
|
}
|
|
m_nStatus = MCH_ST_TO_VERIFY ;
|
|
|
|
// recupero gruppo per geometria ausiliaria
|
|
int nAuxId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_AUX) ;
|
|
bool bChain = false ;
|
|
// se non c'è, lo aggiungo
|
|
if ( nAuxId == GDB_ID_NULL) {
|
|
nAuxId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
|
|
if ( nAuxId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nAuxId, MCH_AUX) ;
|
|
m_pGeomDB->SetStatus( nAuxId, GDB_ST_OFF) ;
|
|
bChain = true ;
|
|
}
|
|
// altrimenti, se chiesto ricalcolo, lo svuoto
|
|
else if ( bRecalc) {
|
|
m_pGeomDB->EmptyGroup( nAuxId) ;
|
|
bChain = true ;
|
|
}
|
|
|
|
// se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria
|
|
if ( bChain && ! Chain( nAuxId)) {
|
|
m_pMchMgr->SetLastError( 2907, "Error in Chiseling : Chaining failed") ;
|
|
return false ;
|
|
}
|
|
|
|
// recupero gruppo per geometria di lavorazione (Cutter Location)
|
|
int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ;
|
|
// se non c'è, lo aggiungo
|
|
if ( nClId == GDB_ID_NULL) {
|
|
nClId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
|
|
if ( nClId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nClId, MCH_CL) ;
|
|
}
|
|
// altrimenti lo svuoto
|
|
else
|
|
m_pGeomDB->EmptyGroup( nClId) ;
|
|
|
|
// lavoro ogni singola catena
|
|
bool bOk = true ;
|
|
int nPathId = m_pGeomDB->GetFirstGroupInGroup( nAuxId) ;
|
|
while ( nPathId != GDB_ID_NULL) {
|
|
if ( ! ProcessPath( nPathId, GDB_ID_NULL, nClId))
|
|
bOk = false ;
|
|
nPathId = m_pGeomDB->GetNextGroup( nPathId) ;
|
|
}
|
|
if ( ! bOk)
|
|
return false ;
|
|
|
|
// assegno ingombri dei vari percorsi di lavorazione e della lavorazione nel suo complesso
|
|
CalcAndSetBBox( nClId) ;
|
|
|
|
// eseguo aggiornamento assi macchina e collegamento con operazione precedente
|
|
if ( ! Update( bPostApply))
|
|
return false ;
|
|
|
|
// aggiorno stato della lavorazione
|
|
m_nStatus = ( bPostApply ? MCH_ST_OK : MCH_ST_NO_POSTAPPL) ;
|
|
// dichiaro successiva da aggiornare
|
|
UpdateFollowingOperationsStatus( MCH_ST_OTH_MODIF) ;
|
|
|
|
LOG_DBG_INFO( GetEMkLogger(), "Chiseling apply done") ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::Update( bool bPostApply)
|
|
{
|
|
// verifico validità gestore DB geometrico e Id del gruppo
|
|
if ( m_pGeomDB == nullptr || ! m_pGeomDB->ExistsObj( m_nOwnerId))
|
|
return false ;
|
|
|
|
// se lavorazione vuota, esco
|
|
if ( m_nChisels == 0) {
|
|
m_pMchMgr->SetWarning( 2952, "Warning in Chiseling : Plunges not found") ;
|
|
return true ;
|
|
}
|
|
|
|
// elimino le entità CLIMB, RISE e HOME della lavorazione, potrebbero falsare i calcoli degli assi (in ogni casi vengono riaggiunte dopo)
|
|
RemoveClimbRiseHome() ;
|
|
|
|
// imposto eventuale asse bloccato da lavorazione
|
|
SetBlockedRotAxis( m_Params.m_sBlockedAxis) ;
|
|
|
|
// calcolo gli assi macchina
|
|
string sHint = ExtractHint( m_Params.m_sUserNotes) ;
|
|
if ( ! m_Params.m_sInitAngs.empty())
|
|
sHint = m_Params.m_sInitAngs ;
|
|
if ( ! CalculateAxesValues( sHint)) {
|
|
string sInfo = m_pMchMgr->GetOutstrokeInfo() ;
|
|
if ( sInfo.empty())
|
|
m_pMchMgr->SetLastError( 2908, "Error in Chiseling : axes values not calculable") ;
|
|
else
|
|
m_pMchMgr->SetLastError( 2909, "Error in Chiseling : outstroke ") ;
|
|
return false ;
|
|
}
|
|
|
|
// assegno estremi degli assi dei vari percorsi di lavorazione e della lavorazione nel suo complesso
|
|
CalcAndSetAxesBBox() ;
|
|
|
|
// gestione movimenti all'inizio di ogni singolo percorso di lavorazione e alla fine della lavorazione
|
|
if ( ! AdjustStartEndMovements()) {
|
|
string sInfo = m_pMchMgr->GetOutstrokeInfo() ;
|
|
if ( sInfo.empty())
|
|
m_pMchMgr->SetLastError( 2910, "Error in Chiseling : link movements not calculable") ;
|
|
else
|
|
m_pMchMgr->SetLastError( 2911, "Error in Chiseling : link outstroke ") ;
|
|
return false ;
|
|
}
|
|
|
|
// esecuzione eventuali personalizzazioni
|
|
string sErr ;
|
|
if ( bPostApply && ! PostApply( sErr)) {
|
|
if ( ! IsEmptyOrSpaces( sErr))
|
|
m_pMchMgr->SetLastError( 2912, sErr) ;
|
|
else
|
|
m_pMchMgr->SetLastError( 2912, "Error in Chiseling : post apply not calculable") ;
|
|
return false ;
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::GetParam( int nType, bool& bVal) const
|
|
{
|
|
switch ( nType) {
|
|
case MPA_INVERT :
|
|
bVal = m_Params.m_bInvert ;
|
|
return true ;
|
|
case MPA_TOOLINVERT :
|
|
bVal = m_Params.m_bToolInvert ;
|
|
return true ;
|
|
}
|
|
bVal = false ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::GetParam( int nType, int& nVal) const
|
|
{
|
|
switch ( nType) {
|
|
case MPA_TYPE :
|
|
nVal = MT_CHISELING ;
|
|
return true ;
|
|
case MPA_WORKSIDE :
|
|
nVal = m_Params.m_nWorkSide ;
|
|
return true ;
|
|
case MPA_SCC :
|
|
nVal = m_Params.m_nSolCh ;
|
|
return true ;
|
|
}
|
|
nVal = 0 ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::GetParam( int nType, double& dVal) const
|
|
{
|
|
switch ( nType) {
|
|
case MPA_SPEED :
|
|
dVal = 0 ;
|
|
return true ;
|
|
case MPA_FEED :
|
|
dVal = GetFeed() ;
|
|
return true ;
|
|
case MPA_ENDFEED :
|
|
dVal = GetEndFeed() ;
|
|
return true ;
|
|
case MPA_TIPFEED :
|
|
dVal = GetTipFeed() ;
|
|
return true ;
|
|
case MPA_OFFSR :
|
|
dVal = GetOffsR() ;
|
|
return true ;
|
|
case MPA_OFFSL :
|
|
dVal = GetOffsL() ;
|
|
return true ;
|
|
case MPA_STARTPOS :
|
|
dVal = m_Params.m_dStartPos ;
|
|
return true ;
|
|
case MPA_STEP :
|
|
dVal = m_Params.m_dStep ;
|
|
return true ;
|
|
case MPA_RETURNPOS :
|
|
dVal = m_Params.m_dReturnPos ;
|
|
return true ;
|
|
case MPA_ENDADDLEN :
|
|
dVal = m_Params.m_dEndAddLen ;
|
|
return true ;
|
|
}
|
|
dVal = 0 ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::GetParam( int nType, string& sVal) const
|
|
{
|
|
switch ( nType) {
|
|
case MPA_NAME :
|
|
sVal = m_Params.m_sName ;
|
|
return true ;
|
|
case MPA_TOOL :
|
|
sVal = m_Params.m_sToolName ;
|
|
return true ;
|
|
case MPA_DEPTH_STR :
|
|
sVal = m_Params.m_sDepth ;
|
|
return true ;
|
|
case MPA_TUUID :
|
|
sVal = ToString( m_Params.m_ToolUuid) ;
|
|
return true ;
|
|
case MPA_UUID :
|
|
sVal = ToString( m_Params.m_Uuid) ;
|
|
return true ;
|
|
case MPA_SYSNOTES :
|
|
sVal = m_Params.m_sSysNotes ;
|
|
return true ;
|
|
case MPA_USERNOTES :
|
|
sVal = m_Params.m_sUserNotes ;
|
|
return true ;
|
|
case MPA_INITANGS :
|
|
sVal = m_Params.m_sInitAngs ;
|
|
return true ;
|
|
case MPA_BLOCKEDAXIS :
|
|
sVal = m_Params.m_sBlockedAxis ;
|
|
return true ;
|
|
}
|
|
sVal = "" ;
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
const ToolData&
|
|
Chiseling::GetToolData( void) const
|
|
{
|
|
return m_TParams ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::UpdateToolData( void)
|
|
{
|
|
// recupero il gestore DB utensili della macchina corrente
|
|
ToolsMgr* pTMgr = m_pMchMgr->GetCurrToolsMgr() ;
|
|
if ( pTMgr == nullptr)
|
|
return false ;
|
|
// recupero l'utensile nel DB utensili (se fallisce con UUID provo con il nome)
|
|
const ToolData* pTdata = pTMgr->GetTool( m_Params.m_ToolUuid) ;
|
|
if ( pTdata == nullptr) {
|
|
pTdata = pTMgr->GetTool( m_Params.m_sToolName) ;
|
|
if ( pTdata == nullptr)
|
|
return false ;
|
|
m_Params.m_ToolUuid = m_TParams.m_Uuid ;
|
|
}
|
|
// salvo posizione TC, testa e uscita originali
|
|
string sOrigTcPos = m_TParams.m_sTcPos ;
|
|
string sOrigHead = m_TParams.m_sHead ;
|
|
int nOrigExit = m_TParams.m_nExit ;
|
|
// verifico se sono diversi (ad esclusione di nome, posizione TC, testa e uscita)
|
|
bool bChanged = ( ! SameTool( m_TParams, *pTdata, false)) ;
|
|
// aggiorno comunque i parametri
|
|
m_TParams = *pTdata ;
|
|
// se definito attrezzaggio, aggiorno i parametri che ne possono derivare
|
|
string sTcPos ; string sHead ; int nExit ;
|
|
if ( m_pMchMgr->GetCurrSetupMgr().GetToolData( m_TParams.m_sName, sTcPos, sHead, nExit)) {
|
|
if ( sOrigTcPos != sTcPos ||
|
|
sOrigHead != sHead ||
|
|
nOrigExit != nExit)
|
|
bChanged = true ;
|
|
m_TParams.m_sTcPos = sTcPos ;
|
|
m_TParams.m_sHead = sHead ;
|
|
m_TParams.m_nExit = nExit ;
|
|
}
|
|
else {
|
|
if ( sOrigTcPos != pTdata->m_sTcPos ||
|
|
sOrigHead != pTdata->m_sHead ||
|
|
nOrigExit != pTdata->m_nExit)
|
|
bChanged = true ;
|
|
}
|
|
// eventuali segnalazioni
|
|
if ( ! EqualNoCase( m_Params.m_sToolName, m_TParams.m_sName)) {
|
|
string sInfo = "Warning in Chiseling : tool name changed (" +
|
|
m_Params.m_sToolName + "->" + m_TParams.m_sName + ")" ;
|
|
m_pMchMgr->SetWarning( 2953, sInfo) ;
|
|
m_Params.m_sToolName = m_TParams.m_sName ;
|
|
}
|
|
if ( bChanged) {
|
|
string sInfo = "Warning in Chiseling : tool data changed (" +
|
|
m_Params.m_sToolName + ")" ;
|
|
m_pMchMgr->SetWarning( 2954, sInfo) ;
|
|
}
|
|
// se modificato, aggiusto lo stato
|
|
if ( bChanged)
|
|
m_nStatus = MCH_ST_TO_VERIFY ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::GetGeometry( SELVECTOR& vIds) const
|
|
{
|
|
// restituisco l'elenco delle entità
|
|
vIds = m_vId ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::VerifyGeometry( SelData Id, int& nSubs, int& nType)
|
|
{
|
|
// ammessi : curve, testi, facce di trimesh o regioni
|
|
const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ;
|
|
if ( pGObj == nullptr)
|
|
return false ;
|
|
// se ammesse curve ed è tale
|
|
if ( ( nType == GEO_NONE || nType == GEO_CURVE) && ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
nType = GEO_CURVE ;
|
|
const ICurve* pCurve = nullptr ;
|
|
// se direttamente la curva
|
|
if ( Id.nSub == SEL_SUB_ALL) {
|
|
pCurve = ::GetCurve( pGObj) ;
|
|
if ( pCurve == nullptr)
|
|
return false ;
|
|
if ( pCurve->GetType() == CRV_COMPO)
|
|
nSubs = ::GetCurveComposite( pCurve)->GetCurveCount() ;
|
|
else
|
|
nSubs = 0 ;
|
|
}
|
|
// altrimenti sottocurva di composita
|
|
else {
|
|
const ICurveComposite* pCompo = GetCurveComposite( pGObj) ;
|
|
pCurve = ( pCompo != nullptr ? pCompo->GetCurve( Id.nSub) : nullptr) ;
|
|
if ( pCurve == nullptr)
|
|
return false ;
|
|
nSubs = 0 ;
|
|
}
|
|
return true ;
|
|
}
|
|
// se altrimenti ammessi testi ed è tale
|
|
else if ( ( nType == GEO_NONE || nType == EXT_TEXT) && pGObj->GetType() == EXT_TEXT) {
|
|
nType = EXT_TEXT ;
|
|
const IExtText* pText = ::GetExtText( pGObj) ;
|
|
if ( pText == nullptr)
|
|
return false ;
|
|
// tutto bene
|
|
nSubs = 0 ;
|
|
return true ;
|
|
}
|
|
// se altrimenti ammesse superfici trimesh ed è tale
|
|
else if ( ( nType == GEO_NONE || nType == SRF_TRIMESH) && pGObj->GetType() == SRF_TRIMESH) {
|
|
nType = SRF_TRIMESH ;
|
|
const ISurfTriMesh* pSurf = ::GetSurfTriMesh( pGObj) ;
|
|
if ( pSurf == nullptr)
|
|
return false ;
|
|
// se direttamente la superficie
|
|
if ( Id.nSub == SEL_SUB_ALL) {
|
|
// deve avere una sola faccia
|
|
if ( pSurf->GetFacetCount() != 1)
|
|
return false ;
|
|
nSubs = 1 ;
|
|
}
|
|
// altrimenti faccia di superficie trimesh
|
|
else {
|
|
// se faccia non esistente
|
|
if ( Id.nSub > pSurf->GetFacetCount())
|
|
return false ;
|
|
nSubs = 0 ;
|
|
}
|
|
return true ;
|
|
}
|
|
// se altrimenti ammesse regioni ed è tale
|
|
else if ( ( nType == GEO_NONE || nType == SRF_FLATRGN) && pGObj->GetType() == SRF_FLATRGN) {
|
|
nType = SRF_FLATRGN ;
|
|
const ISurfFlatRegion* pReg = ::GetSurfFlatRegion( pGObj) ;
|
|
if ( pReg == nullptr)
|
|
return false ;
|
|
// se direttamente la regione
|
|
if ( Id.nSub == SEL_SUB_ALL) {
|
|
nSubs = pReg->GetChunkCount() ;
|
|
}
|
|
// altrimenti chunk di regione
|
|
else {
|
|
// se chunk non esistente
|
|
if ( Id.nSub >= pReg->GetChunkCount())
|
|
return false ;
|
|
// tutto bene
|
|
nSubs = 0 ;
|
|
}
|
|
return true ;
|
|
}
|
|
// altrimenti errore
|
|
else
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::GetCurves( SelData Id, ICURVEPLIST& lstPC)
|
|
{
|
|
// ammessi : curve, testi, facce di trimesh o regioni
|
|
const IGeoObj* pGObj = m_pGeomDB->GetGeoObj( Id.nId) ;
|
|
if ( pGObj == nullptr)
|
|
return false ;
|
|
// ne recupero il riferimento globale
|
|
Frame3d frGlob ;
|
|
if ( ! m_pGeomDB->GetGlobFrame( Id.nId, frGlob))
|
|
return false ;
|
|
// se curva
|
|
if ( ( pGObj->GetType() & GEO_CURVE) != 0) {
|
|
PtrOwner<ICurve> pCurve ;
|
|
// se direttamente curva
|
|
if ( Id.nSub == SEL_SUB_ALL) {
|
|
// recupero e duplico la curva
|
|
const ICurve* pOriCurve = ::GetCurve( pGObj) ;
|
|
if ( pOriCurve != nullptr)
|
|
pCurve.Set( pOriCurve->Clone()) ;
|
|
// se estrusione mancante, imposto default
|
|
Vector3d vtExtr ;
|
|
if ( ! pCurve->GetExtrusion( vtExtr) || vtExtr.IsSmall())
|
|
pCurve->SetExtrusion( Z_AX) ;
|
|
}
|
|
// altrimenti sottocurva di composita
|
|
else {
|
|
// recupero la composita
|
|
const ICurveComposite* pCompo = GetCurveComposite( pGObj) ;
|
|
if ( pCompo != nullptr) {
|
|
// duplico la curva semplice
|
|
const ICurve* pOriCurve = ::GetCurve( pCompo->GetCurve( Id.nSub)) ;
|
|
if ( pOriCurve != nullptr) {
|
|
pCurve.Set( pOriCurve->Clone()) ;
|
|
// recupero estrusione e spessore
|
|
Vector3d vtExtr ;
|
|
if ( ! pCompo->GetExtrusion( vtExtr) || vtExtr.IsSmall())
|
|
vtExtr = Z_AX ;
|
|
pCurve->SetExtrusion( vtExtr) ;
|
|
double dThick ;
|
|
if ( pCompo->GetThickness( dThick))
|
|
pCurve->SetThickness( dThick) ;
|
|
}
|
|
}
|
|
}
|
|
if ( IsNull( pCurve))
|
|
return false ;
|
|
// la porto in globale
|
|
pCurve->ToGlob( frGlob) ;
|
|
// la restituisco
|
|
lstPC.emplace_back( Release( pCurve)) ;
|
|
return true ;
|
|
}
|
|
// se altrimenti testo
|
|
else if ( pGObj->GetType() == EXT_TEXT) {
|
|
// recupero il testo
|
|
const IExtText* pText = ::GetExtText( pGObj) ;
|
|
if ( pText == nullptr)
|
|
return false ;
|
|
// recupero l'outline del testo
|
|
if ( ! pText->GetOutline( lstPC))
|
|
return false ;
|
|
// porto le curve in globale
|
|
for ( auto pCrv : lstPC)
|
|
pCrv->ToGlob( frGlob) ;
|
|
// ritorno
|
|
return true ;
|
|
}
|
|
// se altrimenti superficie
|
|
else if ( ( pGObj->GetType() & GEO_SURF) != 0) {
|
|
// recupero la trimesh
|
|
const ISurfTriMesh* pSurf = ::GetSurfTriMesh( pGObj) ;
|
|
if ( pSurf == nullptr)
|
|
return false ;
|
|
// recupero l'indice della faccia
|
|
int nFacet = ( ( Id.nSub == SEL_SUB_ALL) ? 0 : Id.nSub) ;
|
|
// recupero i contorni della faccia
|
|
POLYLINEVECTOR vPL ;
|
|
pSurf->GetFacetLoops( nFacet, vPL) ;
|
|
if ( vPL.empty())
|
|
return false ;
|
|
// recupero la normale esterna della faccia
|
|
Vector3d vtN ;
|
|
if ( ! pSurf->GetFacetNormal( nFacet, vtN))
|
|
return false ;
|
|
// creo la curva a partire da quello esterno
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
pCrvCompo->FromPolyLine( vPL[0]) ;
|
|
if ( ! pCrvCompo->IsValid())
|
|
return false ;
|
|
// assegno l'estrusione dalla normale alla faccia
|
|
pCrvCompo->SetExtrusion( vtN) ;
|
|
// unisco le eventuali parti allineate
|
|
pCrvCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ;
|
|
// la porto in globale
|
|
pCrvCompo->ToGlob( frGlob) ;
|
|
// sistemazioni varie
|
|
AdjustCurveFromSurf( pCrvCompo, TOOL_ORTHO, FACE_CONT, V_NULL, {}, 0) ;
|
|
// la restituisco
|
|
lstPC.emplace_back( Release( pCrvCompo)) ;
|
|
return true ;
|
|
}
|
|
// se altrimenti regione
|
|
else if ( pGObj->GetType() == SRF_FLATRGN) {
|
|
// recupero la regione
|
|
const ISurfFlatRegion* pReg = ::GetSurfFlatRegion( pGObj) ;
|
|
if ( pReg == nullptr)
|
|
return false ;
|
|
// recupero la normale della regione
|
|
Vector3d vtN = pReg->GetNormVersor() ;
|
|
if ( vtN.IsSmall())
|
|
return false ;
|
|
// determino intervallo di chunk
|
|
int nCstart = 0 ;
|
|
int nCend = pReg->GetChunkCount() ;
|
|
if ( Id.nSub != SEL_SUB_ALL) {
|
|
nCstart = Id.nSub ;
|
|
nCend = nCstart + 1 ;
|
|
}
|
|
// ciclo sui chunk
|
|
for ( int nC = nCstart ; nC < nCend ; ++ nC) {
|
|
// recupero i contorni del chunk
|
|
for ( int nL = 0 ; nL < pReg->GetLoopCount( nC) ; ++ nL) {
|
|
PtrOwner<ICurveComposite> pCrvCompo ;
|
|
if ( ! pCrvCompo.Set( ConvertCurveToComposite( pReg->GetLoop( nC, nL))))
|
|
return false ;
|
|
// assegno l'estrusione dalla normale alla regione
|
|
pCrvCompo->SetExtrusion( vtN) ;
|
|
// unisco le eventuali parti allineate
|
|
pCrvCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ;
|
|
// la porto in globale
|
|
pCrvCompo->ToGlob( frGlob) ;
|
|
// sistemazioni varie
|
|
AdjustCurveFromSurf( pCrvCompo, TOOL_ORTHO, FACE_CONT, V_NULL, {}, 0) ;
|
|
// la restituisco
|
|
lstPC.emplace_back( Release( pCrvCompo)) ;
|
|
}
|
|
}
|
|
return true ;
|
|
}
|
|
// altrimenti errore
|
|
else
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::Chain( int nGrpDestId)
|
|
{
|
|
// vettore puntatori alle curve
|
|
ICURVEPOVECTOR vpCrvs ;
|
|
vpCrvs.reserve( m_vId.size()) ;
|
|
// vettore selettori delle curve originali
|
|
SELVECTOR vInds ;
|
|
// recupero tutte le curve e le porto in globale
|
|
for ( const auto& Id : m_vId) {
|
|
// prendo le curve
|
|
ICURVEPLIST lstPC ;
|
|
if ( ! GetCurves( Id, lstPC)) {
|
|
string sInfo = "Warning in Chiseling : Skipped entity " + ToString( Id) ;
|
|
m_pMchMgr->SetWarning( 2951, sInfo) ;
|
|
}
|
|
for ( auto pCrv : lstPC) {
|
|
vpCrvs.emplace_back( pCrv) ;
|
|
vInds.emplace_back( Id) ;
|
|
}
|
|
}
|
|
// preparo i dati per il concatenamento
|
|
bool bFirst = true ;
|
|
Point3d ptNear = ORIG ;
|
|
double dToler = 10 * EPS_SMALL ;
|
|
ChainCurves chainC ;
|
|
chainC.Init( true, dToler, int( vpCrvs.size())) ;
|
|
for ( size_t i = 0 ; i < vpCrvs.size() ; ++ i) {
|
|
// recupero la curva e il suo riferimento
|
|
ICurve* pCrv = vpCrvs[i] ;
|
|
if ( pCrv == nullptr)
|
|
continue ;
|
|
// recupero i dati della curva necessari al concatenamento e li assegno
|
|
Point3d ptStart, ptEnd ;
|
|
Vector3d vtStart, vtEnd ;
|
|
if ( ! pCrv->GetStartPoint( ptStart) || ! pCrv->GetStartDir( vtStart) ||
|
|
! pCrv->GetEndPoint( ptEnd) || ! pCrv->GetEndDir( vtEnd))
|
|
return false ;
|
|
if ( ! chainC.AddCurve( int( i + 1), ptStart, vtStart, ptEnd, vtEnd))
|
|
return false ;
|
|
// se prima curva, assegno inizio della ricerca
|
|
if ( bFirst) {
|
|
ptNear = ptStart + 10 * EPS_SMALL * vtStart ;
|
|
bFirst = false ;
|
|
}
|
|
}
|
|
// recupero i percorsi concatenati
|
|
int nCount = 0 ;
|
|
INTVECTOR vnId2 ;
|
|
while ( chainC.GetChainFromNear( ptNear, false, vnId2)) {
|
|
// creo una curva composita
|
|
PtrOwner<ICurveComposite> pCrvCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCrvCompo))
|
|
return false ;
|
|
// estrusione e spessore
|
|
Vector3d vtExtr = Z_AX ;
|
|
double dThick = 0 ;
|
|
// vettore Id originali
|
|
SELVECTOR vId2 ;
|
|
vId2.reserve( vnId2.size()) ;
|
|
// recupero le curve semplici e le inserisco nella curva composita
|
|
for ( size_t i = 0 ; i < vnId2.size() ; ++ i) {
|
|
int nId = abs( vnId2[i]) - 1 ;
|
|
bool bInvert = ( vnId2[i] < 0) ;
|
|
vId2.emplace_back( vInds[nId]) ;
|
|
// recupero la curva
|
|
ICurve* pCrv = vpCrvs[nId] ;
|
|
// se necessario, la inverto
|
|
if ( bInvert)
|
|
pCrv->Invert() ;
|
|
// recupero eventuali estrusione e spessore
|
|
Vector3d vtTemp ;
|
|
if ( pCrv->GetExtrusion( vtTemp)) {
|
|
vtExtr = vtTemp ;
|
|
double dTemp ;
|
|
if ( pCrv->GetThickness( dTemp) && abs( dTemp) > abs( dThick))
|
|
dThick = dTemp ;
|
|
}
|
|
// la aggiungo alla curva composta
|
|
if ( ! pCrvCompo->AddCurve( ::Release( vpCrvs[nId]), true, dToler))
|
|
return false ;
|
|
}
|
|
// se non sono state inserite curve, vado oltre
|
|
if ( pCrvCompo->GetCurveCount() == 0)
|
|
continue ;
|
|
// imposto estrusione e spessore
|
|
pCrvCompo->SetExtrusion( vtExtr) ;
|
|
pCrvCompo->SetThickness( dThick) ;
|
|
// aggiorno il nuovo punto vicino
|
|
pCrvCompo->GetEndPoint( ptNear) ;
|
|
// creo nuovo gruppo
|
|
int nPathId = m_pGeomDB->AddGroup( GDB_ID_NULL, nGrpDestId, Frame3d()) ;
|
|
if ( nPathId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nPathId, MCH_PATH + ToString( ++ nCount)) ;
|
|
m_pGeomDB->SetInfo( nPathId, KEY_IDS, ToString( vId2)) ;
|
|
// inserisco la curva composita nel gruppo destinazione
|
|
int nNewId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, ::Release( pCrvCompo)) ;
|
|
if ( nNewId == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::ProcessPath( int nPathId, int nPvId, int nClId)
|
|
{
|
|
// recupero gruppo per geometria temporanea
|
|
const string GRP_TEMP = "Temp" ;
|
|
int nTempId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, GRP_TEMP) ;
|
|
// se non c'è, lo aggiungo
|
|
if ( nTempId == GDB_ID_NULL) {
|
|
nTempId = m_pGeomDB->AddGroup( GDB_ID_NULL, m_nOwnerId, Frame3d()) ;
|
|
if ( nTempId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nTempId, GRP_TEMP) ;
|
|
}
|
|
// altrimenti lo svuoto
|
|
else
|
|
m_pGeomDB->EmptyGroup( nTempId) ;
|
|
// in ogni caso lo dichiaro temporaneo e non visibile
|
|
m_pGeomDB->SetLevel( nTempId, GDB_LV_TEMP) ;
|
|
m_pGeomDB->SetStatus( nTempId, GDB_ST_OFF) ;
|
|
|
|
// copio la curva composita da elaborare
|
|
int nCrvId = m_pGeomDB->GetFirstInGroup( nPathId) ;
|
|
if ( m_pGeomDB->GetGeoType( nCrvId) != CRV_COMPO)
|
|
return false ;
|
|
int nCopyId = m_pGeomDB->CopyGlob( nCrvId, GDB_ID_NULL, nTempId) ;
|
|
if ( nCopyId == GDB_ID_NULL)
|
|
return false ;
|
|
ICurveComposite* pCompo = GetCurveComposite( m_pGeomDB->GetGeoObj( nCopyId)) ;
|
|
|
|
// eventuale inversione percorso
|
|
if ( m_Params.m_bInvert)
|
|
pCompo->Invert() ;
|
|
|
|
// recupero estrusione e spessore
|
|
Vector3d vtExtr = Z_AX ;
|
|
pCompo->GetExtrusion( vtExtr) ;
|
|
double dThick ;
|
|
pCompo->GetThickness( dThick) ;
|
|
|
|
// eventuale inversione direzione utensile
|
|
if ( m_Params.m_bToolInvert) {
|
|
vtExtr.Invert() ;
|
|
pCompo->SetExtrusion( vtExtr) ;
|
|
dThick = - dThick ;
|
|
pCompo->SetThickness( dThick) ;
|
|
}
|
|
|
|
// se richiesto offset
|
|
double dOffs = GetOffsR() ;
|
|
if ( abs( dOffs) > EPS_SMALL) {
|
|
// valore offset
|
|
double dSignOffs = ( m_Params.m_nWorkSide == CHISEL_WS_RIGHT) ? dOffs : - dOffs ;
|
|
// flag offset
|
|
int nFlag = ICurve::OFF_EXTEND | ICurve::OFF_MEDIA_INTDZ ;
|
|
// se percorso chiuso senza overlap ed inizio/fine è un angolo esterno
|
|
if ( pCompo->IsClosed()) {
|
|
Vector3d vtStart, vtEnd ;
|
|
if ( pCompo->GetStartDir( vtStart) && pCompo->GetEndDir( vtEnd) &&
|
|
( vtEnd ^ vtStart) * vtExtr * dSignOffs > 0)
|
|
nFlag += ICurve::OFF_FORCE_OPEN ;
|
|
}
|
|
// esecuzione offset
|
|
if ( ! pCompo->SimpleOffset( dSignOffs, nFlag)) {
|
|
// se curva piatta, provo con offset avanzato
|
|
bool bOk = false ;
|
|
Plane3d plPlane ;
|
|
if ( pCompo->IsFlat( plPlane, true, 100 * EPS_SMALL)) {
|
|
OffsetCurve OffsCrv ;
|
|
if ( OffsCrv.Make( pCompo, dSignOffs, nFlag)) {
|
|
ICurve* pOffs = OffsCrv.GetLongerCurve() ;
|
|
if ( pOffs != nullptr) {
|
|
pCompo->Clear() ;
|
|
pCompo->AddCurve( pOffs) ;
|
|
bOk = true ;
|
|
}
|
|
}
|
|
}
|
|
if ( ! bOk) {
|
|
m_pMchMgr->SetLastError( 2902, "Error in Chiseling : Offset not computable") ;
|
|
return false ;
|
|
}
|
|
}
|
|
}
|
|
|
|
// unisco le parti allineate
|
|
if ( ! pCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL))
|
|
return false ;
|
|
|
|
// recupero il box del grezzo in globale
|
|
BBox3d b3Raw ;
|
|
if ( ! GetRawGlobBox( m_nPhase, nPathId, 0.5 * m_TParams.m_dTDiam, b3Raw) || b3Raw.IsEmpty()) {
|
|
m_pMchMgr->SetLastError( 2903, "Error in Chiseling : Empty RawBox") ;
|
|
return false ;
|
|
}
|
|
|
|
// recupero distanza da fondo dei grezzi interessati dal percorso
|
|
double dRbDist = 0 ;
|
|
if ( AreSameVectorApprox( vtExtr, Z_AX)) {
|
|
if ( ! GetDistanceFromRawBottom( m_nPhase, nCopyId, m_TParams.m_dTDiam, dRbDist))
|
|
return false ;
|
|
}
|
|
|
|
// valuto l'espressione dell'affondamento
|
|
ExeLuaSetGlobNumVar( "TH", abs( dThick)) ;
|
|
ExeLuaSetGlobNumVar( "RB", dRbDist) ;
|
|
double dDepth ;
|
|
string sMyDepth = m_Params.m_sDepth ;
|
|
if ( ! ExeLuaEvalNumExpr( ToUpper( sMyDepth), &dDepth)) {
|
|
m_pMchMgr->SetLastError( 2904, "Error in Chiseling : Depth not computable") ;
|
|
return false ;
|
|
}
|
|
// se spessore positivo, lo sottraggo dal risultato
|
|
if ( dThick > 0)
|
|
dDepth -= dThick ;
|
|
// sottraggo eventuale offset longitudinale
|
|
dDepth -= GetOffsL() ;
|
|
|
|
// recupero nome del path
|
|
string sPathName ;
|
|
m_pGeomDB->GetName( nPathId, sPathName) ;
|
|
|
|
// assegno il versore fresa
|
|
Vector3d vtTool = vtExtr ;
|
|
|
|
// calcolo l'elevazione massima
|
|
double dElev ;
|
|
if ( CalcPathElevation( pCompo, vtTool, dDepth, 0.5 * m_TParams.m_dDiam, dElev)) {
|
|
if ( dElev < EPS_SMALL && AreSameVectorApprox( vtExtr, Z_AX)) {
|
|
BBox3d b3Crv ;
|
|
pCompo->GetLocalBBox( b3Crv) ;
|
|
dElev = max( 0., b3Raw.GetMax().z - b3Crv.GetMin().z + min( 0., dThick) + dDepth) ;
|
|
}
|
|
}
|
|
else
|
|
return false ;
|
|
|
|
// verifico di non superare il massimo materiale
|
|
const double MAXMAT_TOL = EPS_SMALL ;
|
|
if ( dElev > m_TParams.m_dMaxMat + MAXMAT_TOL) {
|
|
string sInfo = "Warning in Chiseling : machining depth (" + ToString( dElev, 1) +
|
|
") bigger than MaxMaterial (" + ToString( m_TParams.m_dMaxMat, 1) + ")" ;
|
|
m_pMchMgr->SetWarning( 2955, sInfo) ;
|
|
dDepth -= dElev - m_TParams.m_dMaxMat ;
|
|
dElev = m_TParams.m_dMaxMat ;
|
|
}
|
|
|
|
// vettore dei fori quadrati
|
|
vector<SqHole> vSqHole ;
|
|
|
|
// cerco gli angoli interni in cui fare la scalpellatura
|
|
bool bClosed = pCompo->IsClosed() ;
|
|
const ICurve* pPrevCrv = ( bClosed ? pCompo->GetLastCurve() : pCompo->GetFirstCurve()) ;
|
|
const ICurve* pCurrCrv = ( bClosed ? pCompo->GetFirstCurve() : pCompo->GetNextCurve()) ;
|
|
while ( pPrevCrv != nullptr && pCurrCrv != nullptr) {
|
|
// devono essere due rette
|
|
if ( pPrevCrv->GetType() == CRV_LINE && pCurrCrv->GetType() == CRV_LINE) {
|
|
// devono essere abbastanza lunghe e formare un angolo retto dalla parte della correzione
|
|
double dPrevLen ;
|
|
pPrevCrv->GetLength( dPrevLen) ;
|
|
double dCurrLen ;
|
|
pCurrCrv->GetLength( dCurrLen) ;
|
|
Vector3d vtPrevDir ;
|
|
pPrevCrv->GetEndDir( vtPrevDir) ;
|
|
vtPrevDir -= ( vtPrevDir * vtExtr) * vtExtr ;
|
|
vtPrevDir.Normalize() ;
|
|
Vector3d vtCurrDir ;
|
|
pCurrCrv->GetStartDir( vtCurrDir) ;
|
|
vtCurrDir -= ( vtCurrDir * vtExtr) * vtExtr ;
|
|
vtCurrDir.Normalize() ;
|
|
double dProVett = ( vtPrevDir ^ vtCurrDir) * vtExtr ;
|
|
const double SIN_ANG_LIM = sin( ( ANG_RIGHT - 100 * EPS_ANG_SMALL) * DEGTORAD) ;
|
|
if ( dPrevLen > 0.5 * m_TParams.m_dDiam - EPS_SMALL &&
|
|
dCurrLen > 0.5 * m_TParams.m_dDiam - EPS_SMALL &&
|
|
(( dProVett > SIN_ANG_LIM && m_Params.m_nWorkSide == CHISEL_WS_LEFT) ||
|
|
( dProVett < - SIN_ANG_LIM && m_Params.m_nWorkSide == CHISEL_WS_RIGHT))) {
|
|
Vector3d vtMid = Media( - vtPrevDir, vtCurrDir, 0.5) ;
|
|
Point3d ptIni ; pPrevCrv->GetEndPoint( ptIni) ;
|
|
ptIni += vtMid * m_TParams.m_dDiam + vtTool * ( dElev - dDepth) ;
|
|
vtMid.Normalize() ;
|
|
vSqHole.emplace_back( ptIni, vtTool, vtCurrDir, vtMid, dElev) ;
|
|
}
|
|
}
|
|
// passo alla coppia successiva
|
|
pPrevCrv = pCurrCrv ;
|
|
pCurrCrv = pCompo->GetNextCurve() ;
|
|
}
|
|
|
|
// uniformo il vettore ausiliario
|
|
Frame3d frRef ;
|
|
frRef.Set( ORIG, vtTool) ;
|
|
Vector3d vtRef = frRef.VersY() ;
|
|
for ( size_t i = 0 ; i < vSqHole.size() ; ++ i) {
|
|
if ( AreSameOrOppositeVectorApprox( vSqHole[i].vtAux, vtRef) ||
|
|
AreOrthoApprox( vSqHole[i].vtAux, vtRef))
|
|
vSqHole[i].vtAux = vtRef ;
|
|
else
|
|
vtRef = vSqHole[i].vtAux ;
|
|
}
|
|
|
|
// collasso i fori quadrati coincidenti
|
|
for ( size_t i = 1 ; i < vSqHole.size() ; ++ i) {
|
|
if ( AreSamePointApprox( vSqHole[i-1].ptIni, vSqHole[i].ptIni)) {
|
|
Vector3d vtMid = Media( vSqHole[i-1].vtMove, vSqHole[i].vtMove, 0.5) ;
|
|
vtMid.Normalize() ;
|
|
vSqHole[i-1].vtMove = vtMid ;
|
|
-- i ;
|
|
}
|
|
}
|
|
|
|
// se richiesta anteprima
|
|
if ( nPvId != GDB_ID_NULL) {
|
|
for ( size_t i = 0 ; i < vSqHole.size() ; ++ i) {
|
|
// creo gruppo per geometria di anteprima della scalpellatura
|
|
int nPxId = m_pGeomDB->AddGroup( GDB_ID_NULL, nPvId, Frame3d()) ;
|
|
if ( nPxId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nPxId, sPathName + "_" + ToString( int( i) + 1)) ;
|
|
m_pGeomDB->SetMaterial( nPxId, GREEN) ;
|
|
// creo l'anteprima delle scalpellature
|
|
if ( ! GenerateChiselingPv( vSqHole[i], nPxId))
|
|
return false ;
|
|
}
|
|
}
|
|
|
|
// se richiesta lavorazione
|
|
if ( nClId != GDB_ID_NULL) {
|
|
for ( size_t i = 0 ; i < vSqHole.size() ; ++ i) {
|
|
|
|
// creo gruppo per geometria di lavorazione della scalpellatura
|
|
int nPxId = m_pGeomDB->AddGroup( GDB_ID_NULL, nClId, Frame3d()) ;
|
|
if ( nPxId == GDB_ID_NULL)
|
|
return false ;
|
|
m_pGeomDB->SetName( nPxId, sPathName + "_" + ToString( int( i) + 1)) ;
|
|
m_pGeomDB->SetMaterial( nPxId, GREEN) ;
|
|
|
|
// Calcolo la scalpellatura
|
|
if ( ! GenerateChiselingCl( vSqHole[i], nPxId))
|
|
return false ;
|
|
|
|
// assegno il vettore estrazione al gruppo del percorso
|
|
m_pGeomDB->SetInfo( nPxId, KEY_EXTR, vtTool) ;
|
|
// assegno i punti di inizio e fine al gruppo del percorso
|
|
m_pGeomDB->SetInfo( nPxId, KEY_START, vSqHole[i].ptIni) ;
|
|
m_pGeomDB->SetInfo( nPxId, KEY_END, vSqHole[i].ptIni) ;
|
|
// assegno l'elevazione massima
|
|
m_pGeomDB->SetInfo( nPxId, KEY_ELEV, dElev) ;
|
|
}
|
|
}
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double dRad,
|
|
double& dElev) const
|
|
{
|
|
dElev = 0 ;
|
|
int nMaxInd = pCompo->GetCurveCount() - 1 ;
|
|
for ( int i = 0 ; i <= nMaxInd ; ++ i) {
|
|
// curva corrente
|
|
const ICurve* pCrvC = pCompo->GetCurve( i) ;
|
|
// calcolo elevazione
|
|
double dCurrElev ;
|
|
Point3d ptStart, ptMid, ptEnd ;
|
|
pCrvC->GetStartPoint( ptStart) ;
|
|
pCrvC->GetMidPoint( ptMid) ;
|
|
pCrvC->GetEndPoint( ptEnd) ;
|
|
Vector3d vtStartPerp, vtMidPerp, vtEndPerp, vtTg ;
|
|
pCrvC->GetStartDir( vtTg) ;
|
|
vtStartPerp = vtTg ^ vtTool ;
|
|
vtStartPerp.Normalize() ;
|
|
vtStartPerp *= dRad ;
|
|
pCrvC->GetMidDir( vtTg) ;
|
|
vtMidPerp = vtTg ^ vtTool ;
|
|
vtMidPerp.Normalize() ;
|
|
vtMidPerp *= dRad ;
|
|
pCrvC->GetEndDir( vtTg) ;
|
|
vtEndPerp = vtTg ^ vtTool ;
|
|
vtEndPerp.Normalize() ;
|
|
vtEndPerp *= dRad ;
|
|
Vector3d vtDepth = vtTool * dDepth ;
|
|
// linea centro utensile
|
|
if ( GetElevation( m_nPhase, ptStart - vtDepth, ptMid - vtDepth, ptEnd - vtDepth, vtTool, dCurrElev)) {
|
|
if ( dCurrElev > dElev)
|
|
dElev = dCurrElev ;
|
|
}
|
|
else {
|
|
m_pMchMgr->SetLastError( 2906, "Error in Chiseling : Entity GetElevation") ;
|
|
return false ;
|
|
}
|
|
// da una parte
|
|
if ( GetElevation( m_nPhase, ptStart + vtStartPerp - vtDepth, ptMid + vtMidPerp - vtDepth,
|
|
ptEnd + vtEndPerp - vtDepth, vtTool, dCurrElev)) {
|
|
if ( dCurrElev > dElev)
|
|
dElev = dCurrElev ;
|
|
}
|
|
else {
|
|
m_pMchMgr->SetLastError( 2906, "Error in Chiseling : Entity GetElevation") ;
|
|
return false ;
|
|
}
|
|
// dall'altra parte
|
|
if ( GetElevation( m_nPhase, ptStart - vtStartPerp - vtDepth, ptMid - vtMidPerp - vtDepth,
|
|
ptEnd - vtEndPerp - vtDepth, vtTool, dCurrElev)) {
|
|
if ( dCurrElev > dElev)
|
|
dElev = dCurrElev ;
|
|
}
|
|
else {
|
|
m_pMchMgr->SetLastError( 2906, "Error in Chiseling : Entity GetElevation") ;
|
|
return false ;
|
|
}
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::GenerateChiselingPv( const SqHole& hole, int nPathId)
|
|
{
|
|
// calcolo punti notevoli
|
|
Point3d ptCen = hole.ptIni ;
|
|
Point3d ptCorner = hole.ptIni + hole.vtMove * ( m_TParams.m_dDiam * SQRT1_2 + m_Params.m_dEndAddLen) ;
|
|
// inserisco quadrato che rappresenta la scalpellatura
|
|
PtrOwner<ICurveComposite> pCompo( CreateCurveComposite()) ;
|
|
if ( IsNull( pCompo) ||
|
|
! pCompo->PolygonCenterCorner( 4, ptCen, ptCorner, hole.vtExtr))
|
|
return false ;
|
|
// assegno il versore estrusione e lo spessore
|
|
pCompo->SetExtrusion( hole.vtExtr) ;
|
|
pCompo->SetThickness( - hole.dLen) ;
|
|
// inserisco nel DB
|
|
int nDriId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, Release( pCompo)) ;
|
|
// assegno nome e colore
|
|
m_pGeomDB->SetName( nDriId, MCH_PV_CUT) ;
|
|
m_pGeomDB->SetMaterial( nDriId, LIME) ;
|
|
// incremento numero di scalpellature
|
|
++ m_nChisels ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
Chiseling::GenerateChiselingCl( const SqHole& hole, int nPathId)
|
|
{
|
|
// aggiusto alcuni parametri del ciclo di foratura
|
|
double dStdLen = hole.dLen ;
|
|
double dReturnPos = m_Params.m_dReturnPos ;
|
|
// imposto dati comuni
|
|
SetPathId( nPathId) ;
|
|
SetToolDir( hole.vtExtr) ;
|
|
SetAuxDir( hole.vtAux) ;
|
|
// 1 -> punto approccio
|
|
SetFlag( 1) ;
|
|
double dAppr = GetSafeZ() ;
|
|
Point3d ptP1 = hole.ptIni + hole.vtExtr * dAppr ;
|
|
if ( AddRapidStart( ptP1) == GDB_ID_NULL)
|
|
return false ;
|
|
SetFlag( 0) ;
|
|
// 2 -> punto fuori (se diverso dal precedente)
|
|
if ( m_Params.m_dStartPos < dAppr) {
|
|
Point3d ptP2 = hole.ptIni + hole.vtExtr * m_Params.m_dStartPos ;
|
|
if ( AddRapidMove( ptP2) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
// ciclo di affondamento a step
|
|
const double MIN_STEP = 2 ;
|
|
const double APPR_STEP = 1 ;
|
|
const double MIN_MOVE = 1 ;
|
|
double dStep = max( m_Params.m_dStep, MIN_STEP) ;
|
|
int nStep = int( ceil( hole.dLen / dStep)) ;
|
|
dStep = hole.dLen / nStep ;
|
|
if ( dReturnPos < - dStep + APPR_STEP + MIN_MOVE)
|
|
dReturnPos = - dStep + APPR_STEP + MIN_MOVE ;
|
|
double dCurrLen = 0 ;
|
|
for ( int i = 1 ; i <= nStep ; ++ i) {
|
|
// se non è primo step faccio retrazione e riaffondo
|
|
if ( i != 1) {
|
|
// retrazione
|
|
SetFeed( GetEndFeed()) ;
|
|
SetFlag( 103) ; // punto di scarico truciolo
|
|
Point3d ptPr = hole.ptIni + hole.vtExtr * dReturnPos ;
|
|
if ( AddLinearMove( ptPr) == GDB_ID_NULL)
|
|
return false ;
|
|
// riaffondo
|
|
SetFeed( GetEndFeed()) ;
|
|
SetFlag( 0) ;
|
|
Point3d ptPa = hole.ptIni - hole.vtExtr * ( dCurrLen - APPR_STEP) ;
|
|
if ( AddLinearMove( ptPa) == GDB_ID_NULL)
|
|
return false ;
|
|
}
|
|
// lunghezza di fine step
|
|
double dEndLen = dCurrLen + dStep ;
|
|
// 4 -> punto termine velocità standard (se risulta)
|
|
if ( dCurrLen < dStdLen + EPS_SMALL) {
|
|
// lunghezza di esecuzione
|
|
double dLen = min( hole.dLen, dEndLen) ;
|
|
// determino se arrivo in fondo al foro
|
|
bool bHoleEnd = ( dLen > hole.dLen - EPS_SMALL) ;
|
|
// determino se arrivo in fondo allo step
|
|
bool bStepEnd = ( dLen > dEndLen - EPS_SMALL) ;
|
|
// assegno parametri
|
|
SetFeed( GetFeed()) ;
|
|
if ( bHoleEnd)
|
|
SetFlag( 101) ; // fondo del foro
|
|
else if ( bStepEnd)
|
|
SetFlag( 102) ; // fondo dello step
|
|
// movimento
|
|
Point3d ptP4 = hole.ptIni - hole.vtExtr * dLen ;
|
|
if ( AddLinearMove( ptP4) == GDB_ID_NULL)
|
|
return false ;
|
|
// aggiorno posizione e verifico se step completato
|
|
dCurrLen = dLen ;
|
|
if ( bHoleEnd || bStepEnd)
|
|
continue ;
|
|
}
|
|
}
|
|
|
|
// 5 -> piccola risalita
|
|
const double ADD_RETRACT = 1.0 ;
|
|
SetFeed( GetEndFeed()) ;
|
|
SetFlag( 0) ;
|
|
Point3d ptP5 = hole.ptIni - hole.vtExtr * ( dStdLen - ADD_RETRACT) ;
|
|
if ( AddLinearMove( ptP5) == GDB_ID_NULL)
|
|
return false ;
|
|
|
|
// 6 -> movimento di lato
|
|
SetFeed( GetTipFeed()) ;
|
|
SetFlag( 0) ;
|
|
Point3d ptP6 = ptP5 + hole.vtMove * m_Params.m_dEndAddLen ;
|
|
if ( AddLinearMove( ptP6) == GDB_ID_NULL)
|
|
return false ;
|
|
|
|
// 7 -> ritorno all'approccio del foro
|
|
SetFeed( GetEndFeed()) ;
|
|
SetFlag( 104) ; // risalita sopra il foro
|
|
Point3d ptP7 = ptP1 + hole.vtMove * m_Params.m_dEndAddLen ;
|
|
if ( AddLinearMove( ptP7) == GDB_ID_NULL)
|
|
return false ;
|
|
|
|
// reset dati di movimento
|
|
ResetMoveData() ;
|
|
|
|
// incremento numero di scalpellature
|
|
++ m_nChisels ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
double
|
|
Chiseling::GetRadiusForStartEndElevation( void) const
|
|
{
|
|
const double DELTA_ELEV_RAD = 20.0 ;
|
|
return ( 0.5 * m_TParams.m_dTDiam + DELTA_ELEV_RAD) ;
|
|
}
|