From e7d5801617f4eddc536a499f8c8dc9d3dd9a2ec1 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Fri, 27 Oct 2017 17:46:48 +0000 Subject: [PATCH] EgtMachKernel : - aggiunte funzioni per gestione preview utensile in lavorazione. --- MachMgr.h | 3 + MachMgrOperations.cpp | 57 +++++++++++++++- Machining.cpp | 154 +++++++++++++++++++++++++++++++++++------- Machining.h | 4 +- Milling.cpp | 5 -- Pocketing.cpp | 5 -- 6 files changed, 191 insertions(+), 37 deletions(-) diff --git a/MachMgr.h b/MachMgr.h index 6939478..3f9d2ba 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -249,6 +249,9 @@ class MachMgr : public IMachMgr bool RemoveMachiningPreview( void) override ; bool MachiningApply( bool bRecalc, bool bPostApply = true) override ; bool MachiningUpdate( bool bPostApply = true) override ; + bool PreparePreviewMachiningTool( void) const override ; + bool RemovePreviewMachiningTool( void) const override ; + int PreviewMachiningTool( int nEntId, int nFlag) const override ; bool GetMachiningParam( int nType, bool& bVal) const override ; bool GetMachiningParam( int nType, int& dVal) const override ; bool GetMachiningParam( int nType, double& dVal) const override ; diff --git a/MachMgrOperations.cpp b/MachMgrOperations.cpp index 3b8a539..656c674 100644 --- a/MachMgrOperations.cpp +++ b/MachMgrOperations.cpp @@ -573,6 +573,9 @@ MachMgr::DispositionSpecialUpdate( int nId) bool MachMgr::SetCurrMachining( int nId) { + // se corrente esiste ed è diversa, ne eseguo il reset + if ( m_nCurrMachiningId != GDB_ID_NULL && nId != m_nCurrMachiningId) + ResetCurrMachining() ; // recupero il gruppo delle operazioni nella macchinata corrente int nOperGrpId = GetCurrOperId() ; if ( nOperGrpId == GDB_ID_NULL) @@ -595,6 +598,9 @@ MachMgr::SetCurrMachining( int nId) bool MachMgr::ResetCurrMachining( void) { + // disabilito preview utensile + RemovePreviewMachiningTool() ; + // reset m_nCurrMachiningId = GDB_ID_NULL ; return true ; } @@ -619,7 +625,7 @@ int MachMgr::AddMachining( const string& sName, const string& sMachining) { // nessuna lavorazione corrente - m_nCurrMachiningId = GDB_ID_NULL ; + ResetCurrMachining() ; // recupero il gestore delle lavorazioni della macchina corrente MachiningsMgr* pMMgr = GetCurrMachiningsMgr() ; if ( pMMgr == nullptr) @@ -674,7 +680,7 @@ int MachMgr::AddMachining( const string& sName, int nMchType, const string& sTool) { // nessuna lavorazione corrente - m_nCurrMachiningId = GDB_ID_NULL ; + ResetCurrMachining() ; // recupero il gestore delle lavorazioni della macchina corrente MachiningsMgr* pMMgr = GetCurrMachiningsMgr() ; if ( pMMgr == nullptr) @@ -924,6 +930,53 @@ MachMgr::MachiningUpdate( bool bPostApply) return pMch->Update( bPostApply) ; } +//---------------------------------------------------------------------------- +bool +MachMgr::PreparePreviewMachiningTool( void) const +{ + // recupero la lavorazione corrente + int nCurrMchId = GetCurrMachining() ; + if ( nCurrMchId == GDB_ID_NULL) + return false ; + // ne recupero il gestore + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; + if ( pMch == nullptr) + return false ; + // eseguo + return pMch->PrepareToolPreview() ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::RemovePreviewMachiningTool( void) const +{ + // verifico la lavorazione corrente (salto volutamente altri controlli) + if ( m_nCurrMachiningId == GDB_ID_NULL) + return false ; + // ne recupero il gestore + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nCurrMachiningId)) ; + if ( pMch == nullptr) + return false ; + // eseguo + return pMch->RemoveToolPreview() ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::PreviewMachiningTool( int nEntId, int nFlag) const +{ + // recupero la lavorazione corrente + int nCurrMchId = GetCurrMachining() ; + if ( nCurrMchId == GDB_ID_NULL) + return GDB_ID_NULL ; + // ne recupero il gestore + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; + if ( pMch == nullptr) + return GDB_ID_NULL ; + // eseguo + return pMch->ToolPreview( nEntId, nFlag) ; +} + //---------------------------------------------------------------------------- bool MachMgr::GetMachiningParam( int nType, bool& bVal) const diff --git a/Machining.cpp b/Machining.cpp index 97d3fb5..d1d6bca 100644 --- a/Machining.cpp +++ b/Machining.cpp @@ -118,32 +118,11 @@ Machining::GetEndPoint( Point3d& ptEnd) const //---------------------------------------------------------------------------- bool -Machining::ShowTool( int nPath, double dFraz) const +Machining::PrepareToolPreview( void) const { - // verifico validità gestore DB geometrico + // verifico validità gestori DB geometrico e CAM if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr) return false ; - Machine* pMch = m_pMchMgr->GetCurrMachine() ; - if ( pMch == nullptr) - return false ; - // recupero gruppo per geometria di lavorazione (Cutter Location) - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; - if ( nClId == GDB_ID_NULL) - return false ; - // recupero la prima entità del primo sottogruppo - int nEntId = m_pGeomDB->GetFirstInGroup( m_pGeomDB->GetFirstGroupInGroup( nClId)) ; - if ( nEntId == GDB_ID_NULL) - return false ; - string sName ; m_pGeomDB->GetName( nEntId, sName) ; - if ( sName == MCH_CL_CLIMB) - nEntId = m_pGeomDB->GetNext( nEntId) ; - // recupero i dati di questa entità - const CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; - if ( pCamData == nullptr) - return false ; - Point3d ptEnd = pCamData->GetEndPoint() ; - Vector3d vtTool = pCamData->GetToolDir() ; - Vector3d vtBAux = pCamData->GetBackAuxDir() ; // creo o svuoto gruppo per anteprima utensile int nStId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_ST) ; // se non c'è, lo aggiungo @@ -157,9 +136,136 @@ Machining::ShowTool( int nPath, double dFraz) const // altrimenti lo svuoto else m_pGeomDB->EmptyGroup( nStId) ; + // se necessario, imposto l'utensile corrente + string sCurrTool ; m_pMchMgr->GetCalcTool( sCurrTool) ; + if ( ! EqualNoCase( sCurrTool, GetToolName())) { + if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + } // copio la testa della lavorazione nel gruppo int nHeadId = m_pMchMgr->GetHeadId( GetHeadName()) ; int nId = m_pGeomDB->CopyGlob( nHeadId, GDB_ID_NULL, nStId) ; + m_pGeomDB->SetStatus( nId, GDB_ST_OFF) ; + return ( nId != GDB_ID_NULL) ; +} + +//---------------------------------------------------------------------------- +bool +Machining::RemoveToolPreview( void) const +{ + // verifico validità gestore DB geometrico + if ( m_pGeomDB == nullptr) + return false ; + // recupero gruppo per anteprima utensile + int nStId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_ST) ; + // lo svuoto + m_pGeomDB->EmptyGroup( nStId) ; + return true ; +} + +//---------------------------------------------------------------------------- +int +GetToolPreviewNext( IGeomDB* pGeomDB, int nEntId, int nParentId) +{ + // recupero la successiva + int nNewId = (( nEntId != GDB_ID_NULL) ? pGeomDB->GetNext( nEntId) : pGeomDB->GetFirstInGroup( nParentId)) ; + int nNewParentId = nParentId ; + // ciclo nei gruppi successivi + do { + // ciclo nel gruppo + while ( nNewId != GDB_ID_NULL) { + string sName ; pGeomDB->GetName( nNewId, sName) ; + if ( sName != MCH_CL_CLIMB && sName != MCH_CL_RISE) + break ; + nNewId = pGeomDB->GetNext( nNewId) ; + } + // se trovata, esco + if ( nNewId != GDB_ID_NULL) + return nNewId ; + // recupero la prima entità del successivo gruppo + nNewParentId = pGeomDB->GetNextGroup( nNewParentId) ; + nNewId = pGeomDB->GetFirstInGroup( nNewParentId) ; + } while ( nNewId != GDB_ID_NULL) ; + return GDB_ID_NULL ; +} + +//---------------------------------------------------------------------------- +int +GetToolPreviewPrev( IGeomDB* pGeomDB, int nEntId, int nParentId) +{ + // recupero la precedente + int nNewId = (( nEntId != GDB_ID_NULL) ? pGeomDB->GetPrev( nEntId) : pGeomDB->GetLastInGroup( nParentId)) ; + int nNewParentId = nParentId ; + // ciclo nei gruppi precedenti + do { + // ciclo nel gruppo + while ( nNewId != GDB_ID_NULL) { + string sName ; pGeomDB->GetName( nNewId, sName) ; + if ( sName != MCH_CL_CLIMB && sName != MCH_CL_RISE) + break ; + nNewId = pGeomDB->GetPrev( nNewId) ; + } + // se trovata, esco + if ( nNewId != GDB_ID_NULL) + return nNewId ; + // recupero l'ultima entità del precedente gruppo + nNewParentId = pGeomDB->GetPrevGroup( nNewParentId) ; + nNewId = pGeomDB->GetLastInGroup( nNewParentId) ; + } while ( nNewId != GDB_ID_NULL) ; + return GDB_ID_NULL ; +} + +//---------------------------------------------------------------------------- +int +Machining::ToolPreview( int nEntId, int nFlag) const +{ + // verifico validità gestori DB geometrico e CAM + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr) + return GDB_ID_NULL ; + // recupero gruppo per geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return GDB_ID_NULL ; + // se entità nulla + if ( nEntId == GDB_ID_NULL || ! m_pGeomDB->ExistsObj( nEntId)) { + // recupero il gruppo di appartenenza + int nParentId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + // se richiesta successiva + if ( nFlag == MCH_TPM_AFTER) + nEntId = GetToolPreviewNext( m_pGeomDB, nEntId, nParentId) ; + // se richiesta precedente + else if ( nFlag == MCH_TPM_BEFORE) + nEntId = GetToolPreviewPrev( m_pGeomDB, nEntId, nParentId) ; + // altrimenti richiesta corrente + else + nEntId = GDB_ID_NULL ; + } + // altrimenti + else { + // verifico che l'entità stia in un sottogruppo di CL + int nParentId = m_pGeomDB->GetParentId( nEntId) ; + if ( m_pGeomDB->GetParentId( nParentId) == nClId) { + // se richiesta successiva + if ( nFlag == MCH_TPM_AFTER) + nEntId = GetToolPreviewNext( m_pGeomDB, nEntId, nParentId) ; + // se richiesta precedente + else if ( nFlag == MCH_TPM_BEFORE) + nEntId = GetToolPreviewPrev( m_pGeomDB, nEntId, nParentId) ; + } + else + nEntId = GDB_ID_NULL ; + } + // recupero i dati di questa entità + const CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; + if ( pCamData == nullptr) + return GDB_ID_NULL ; + Point3d ptEnd = pCamData->GetEndPoint() ; + Vector3d vtTool = pCamData->GetToolDir() ; + Vector3d vtBAux = pCamData->GetBackAuxDir() ; + // recupero la testa nel gruppo per anteprima utensile + int nId = m_pGeomDB->GetFirstGroupInGroup( m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_ST)) ; + if ( nId == GDB_ID_NULL) + return GDB_ID_NULL ; m_pGeomDB->SetStatus( nId, GDB_ST_ON) ; // dati correnti testa/uscita int nExitId = m_pGeomDB->GetFirstNameInGroup( nId, MCH_EXIT + ToString( GetExitNbr())) ; @@ -187,7 +293,7 @@ Machining::ShowTool( int nPath, double dFraz) const frHead.ToGlob( frShow) ; *(m_pGeomDB->GetGroupFrame( nId)) = frHead ; - return true ; + return nEntId ; } //---------------------------------------------------------------------------- diff --git a/Machining.h b/Machining.h index 90f26d2..26ec64b 100644 --- a/Machining.h +++ b/Machining.h @@ -46,7 +46,9 @@ class Machining : public Operation public : bool GetStartPoint( Point3d& ptStart) const ; bool GetEndPoint( Point3d& ptEnd) const ; - bool ShowTool( int nPath, double dFraz) const ; + bool PrepareToolPreview( void) const ; + int ToolPreview( int nEntId, int nFlag) const ; + bool RemoveToolPreview( void) const ; protected : Machining( void) ; diff --git a/Milling.cpp b/Milling.cpp index 7e52fee..c19ed5f 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -554,11 +554,6 @@ Milling::Apply( bool bRecalc, bool bPostApply) if ( ! Update( bPostApply)) return false ; - //// imposto l'utensile per l'anteprima !!! provvisorio per test !!! - // if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) - // return false ; - // ShowTool( 0, 0) ; - return true ; } diff --git a/Pocketing.cpp b/Pocketing.cpp index 83c0f30..2a78db6 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -531,11 +531,6 @@ Pocketing::Apply( bool bRecalc, bool bPostApply) if ( ! Update( bPostApply)) return false ; - //// imposto l'utensile per l'anteprima !!! provvisorio per test !!! - // if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) - // return false ; - // ShowTool( 0, 0) ; - return true ; }