From 9bdba6bcaacb33453cc9c869d950cd7da5c17df0 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Fri, 22 Jul 2016 13:06:32 +0000 Subject: [PATCH] EgtMachKernel 1.6s7 : - anteprima fresature. --- Drilling.cpp | 2 + EgtMachKernel.rc | Bin 11782 -> 11782 bytes Milling.cpp | 196 +++++++++++++++++++++++++++++++++++++---------- Milling.h | 1 + 4 files changed, 158 insertions(+), 41 deletions(-) diff --git a/Drilling.cpp b/Drilling.cpp index f125e6e..1026e36 100644 --- a/Drilling.cpp +++ b/Drilling.cpp @@ -897,6 +897,8 @@ Drilling::GenerateHoleRegionPv( int nFirstId, int nCount, int nPvId) return false ; // calcolo la regione pSfr = GetSurfFlatRegionFromFatCurve( Release( pCompo1), dRad + dExtraR, false, true) ; + if ( pSfr == nullptr) + return false ; } // altrimenti else { diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index a43a88a00a17e074c9b4174c0c9f9d63250b565e..2d4900a6897926fe4af0cdbd80cf24030ed30b82 100644 GIT binary patch delta 97 zcmZpRX^YwLhmFyE^ItYwW=8YLj>5W|vxM9jH?QON0rG*u7nvrX5iEd9O=7{OSQ@Kh Hr8(RHRjnXm delta 97 zcmZpRX^YwLhmFx}^ItYwW=6Bgj>5W|vxM9jH?QON0rG*u7nvrX5iEd9O=7{OSQ@Kh Hr8(RHR2d*z diff --git a/Milling.cpp b/Milling.cpp index a07d1f7..125a4a0 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -22,6 +22,7 @@ #include "/EgtDev/Include/EGkCurveComposite.h" #include "/EgtDev/Include/EgkArcSpecial.h" #include "/EgtDev/Include/EgkChainCurves.h" +#include "/EgtDev/Include/EGkSfrCreate.h" #include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGnStringKeyVal.h" #include "/EgtDev/Include/EgtPointerOwner.h" @@ -393,7 +394,60 @@ Milling::Preview( bool bRecalc) // reset numero percorsi di lavoro generati m_nMills = 0 ; - return false ; + // 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()) { + LOG_INFO( GetEMkLogger(), "Error in Milling : UpdateToolData failed") ; + return false ; + } + + // se necessario, eseguo concatenamento ed inserisco i percorsi sotto la geometria ausiliaria + if ( bChain && ! Chain( nAuxId)) + 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 ; } //---------------------------------------------------------------------------- @@ -427,7 +481,7 @@ Milling::Apply( bool bRecalc) // aggiorno dati geometrici dell'utensile if ( ! UpdateToolData()) { - LOG_INFO( GetEMkLogger(), "Error in Sawing : UpdateToolData failed") ; + LOG_INFO( GetEMkLogger(), "Error in Milling : UpdateToolData failed") ; return false ; } @@ -985,13 +1039,6 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) } } - // creo gruppo per geometria di lavorazione del percorso - int nPxId = m_pGeomDB->AddGroup( GDB_ID_NULL, nClId, Frame3d()) ; - if ( nPxId == GDB_ID_NULL) - return false ; - m_pGeomDB->SetName( nPxId, sPathName) ; - m_pGeomDB->SetMaterial( nPxId, BLUE) ; - // calcolo il versore fresa Vector3d vtTool = Z_AX ; if ( ! vtExtr.IsSmall()) @@ -1009,34 +1056,57 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) else return false ; - // assegno il vettore estrazione al gruppo del percorso - m_pGeomDB->SetInfo( nPxId, KEY_EXTR, vtTool) ; - // assegno il punto di inizio al gruppo del percorso - m_pGeomDB->SetInfo( nPxId, KEY_START, ptStart) ; + // se richiesta anteprima + if ( nPvId != GDB_ID_NULL) { + // creo gruppo per geometria di lavorazione del percorso + int nPxId = m_pGeomDB->AddGroup( GDB_ID_NULL, nPvId, Frame3d()) ; + if ( nPxId == GDB_ID_NULL) + return false ; + m_pGeomDB->SetName( nPxId, sPathName) ; + m_pGeomDB->SetMaterial( nPxId, GREEN) ; + // creo l'anteprima del percorso + if ( ! GenerateMillingPv( nPxId, pCompo)) + return false ; + } - // Imposto dati comuni - SetPathId( nPxId) ; - SetToolDir( vtTool) ; + // se richiesta lavorazione + if ( nClId != GDB_ID_NULL) { + // creo gruppo per geometria di lavorazione del percorso + int nPxId = m_pGeomDB->AddGroup( GDB_ID_NULL, nClId, Frame3d()) ; + if ( nPxId == GDB_ID_NULL) + return false ; + m_pGeomDB->SetName( nPxId, sPathName) ; + m_pGeomDB->SetMaterial( nPxId, BLUE) ; - // Se una sola passata - if ( m_Params.m_dStep < EPS_SMALL || dElev <= m_Params.m_dStep) { - if ( ! AddStandardMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) - return false ; - } - // se altrimenti passate a zig-zag - else if ( m_Params.m_nStepType == MILL_ST_ZIGZAG) { - if ( ! AddZigZagMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) - return false ; - } - // se altrimenti passate a one-way - else if ( m_Params.m_nStepType == MILL_ST_ONEWAY) { - if ( ! AddOneWayMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) - return false ; - } - // se altrimenti passate a spirale - else if ( m_Params.m_nStepType == MILL_ST_SPIRAL) { - if ( ! AddSpiralMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) - return false ; + // assegno il vettore estrazione al gruppo del percorso + m_pGeomDB->SetInfo( nPxId, KEY_EXTR, vtTool) ; + // assegno il punto di inizio al gruppo del percorso + m_pGeomDB->SetInfo( nPxId, KEY_START, ptStart) ; + + // Imposto dati comuni + SetPathId( nPxId) ; + SetToolDir( vtTool) ; + + // Se una sola passata + if ( m_Params.m_dStep < EPS_SMALL || dElev <= m_Params.m_dStep) { + if ( ! AddStandardMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) + return false ; + } + // se altrimenti passate a zig-zag + else if ( m_Params.m_nStepType == MILL_ST_ZIGZAG) { + if ( ! AddZigZagMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) + return false ; + } + // se altrimenti passate a one-way + else if ( m_Params.m_nStepType == MILL_ST_ONEWAY) { + if ( ! AddOneWayMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) + return false ; + } + // se altrimenti passate a spirale + else if ( m_Params.m_nStepType == MILL_ST_SPIRAL) { + if ( ! AddSpiralMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) + return false ; + } } // incremento numero di fresate @@ -1074,6 +1144,46 @@ Milling::CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtToo return true ; } +//---------------------------------------------------------------------------- +bool +Milling::GenerateMillingPv( int nPathId, const ICurveComposite* pCompo) +{ + // creo copia della curva composita + PtrOwner< ICurve> pCrv( pCompo->Clone()) ; + if ( IsNull( pCrv)) + return false ; + // calcolo la regione + PtrOwner pSfr ; + pSfr.Set( GetSurfFlatRegionFromFatCurve( Release( pCrv), 0.5 * m_TParams.m_dDiam, false, true)) ; + if ( IsNull( pSfr)) + return false ; + // ne recupero il contorno + PtrOwner< ICurve> pCrv2 ; + pCrv2.Set( pSfr->GetLoop( 0, 0)) ; + if ( IsNull( pCrv2)) + return false ; + // inserisco la curva nel DB + int nCId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, Release( pCrv2)) ; + if ( nCId == GDB_ID_NULL) + return false ; + // assegno nome e colore + m_pGeomDB->SetName( nCId, MCH_PV_CUT) ; + m_pGeomDB->SetMaterial( nCId, LIME) ; + // inserisco la regione nel DB + int nRId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, Release( pSfr)) ; + if ( nRId == GDB_ID_NULL) + return false ; + m_pGeomDB->SetName( nRId, MCH_PV_RCUT) ; + m_pGeomDB->SetMaterial( nRId, INVISIBLE) ; + // la copio anche come regione ridotta + int nRrId = m_pGeomDB->Copy( nRId, GDB_ID_NULL, nPathId) ; + if ( nRrId == GDB_ID_NULL) + return false ; + m_pGeomDB->SetName( nRrId, MCH_PV_RRCUT) ; + m_pGeomDB->SetMaterial( nRrId, INVISIBLE) ; + return true ; +} + //---------------------------------------------------------------------------- bool Milling::AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr, @@ -1441,10 +1551,14 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool double dSafeZ = m_pMchMgr->GetCurrMachiningsMgr()->GetSafeZ() ; // lunghezza di approccio/retrazione double dAppr = m_Params.m_dStartPos ; + // se attacco ad inseguimento (per ora nullo), parto sopra di elevazione in attacco + double dStart = 0 ; + if ( m_Params.m_nLeadInType == MILL_LI_NONE) + dStart = m_Params.m_dLiElev ; // determino numero e affondamento degli step - int nStep = max( 1, static_cast( ceil( dElev / m_Params.m_dStep))) ; - double dStep = dElev / nStep ; + int nStep = max( 1, static_cast( ceil( ( dElev + dStart) / m_Params.m_dStep))) ; + double dStep = ( dElev + dStart) / nStep ; // determino dati del percorso double dTotLen ; pCompo->GetLength( dTotLen) ; @@ -1461,11 +1575,11 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool // curva corrente const ICurve* pCrvC = pCompo->GetCurve( i) ; // affondamento a inizio curva - Vector3d vtStaDepth = vtTool * ( dDepth - dElev + min((( j + dCurrLen / dTotLen) * dStep), dElev)) ; + Vector3d vtStaDepth = vtTool * ( dDepth - dElev - dStart + min((( j + dCurrLen / dTotLen) * dStep), dElev + dStart)) ; // affondamento a fine curva double dCrvLen ; pCrvC->GetLength( dCrvLen) ; dCurrLen += dCrvLen ; - Vector3d vtEndDepth = vtTool * ( dDepth - dElev + min((( j + dCurrLen / dTotLen) * dStep), dElev)) ; + Vector3d vtEndDepth = vtTool * ( dDepth - dElev - dStart + min((( j + dCurrLen / dTotLen) * dStep), dElev + dStart)) ; // se prima entità di primo step, approccio e affondo if ( i == 0 && j == 0) { // dati inizio entità @@ -1573,11 +1687,11 @@ Milling::AddSpiralMilling( const ICurveComposite* pCompo, const Vector3d& vtTool if ( bInvert) pCurve->Invert() ; // affondamento a inizio curva - Vector3d vtStaDepth = vtTool * ( dDepth - dElev + min((( j + dCurrLen / dTotLen) * dStep), dElev)) ; + Vector3d vtStaDepth = vtTool * ( dDepth - dElev - dStart + min((( j + dCurrLen / dTotLen) * dStep), dElev + dStart)) ; // affondamento a fine curva double dCrvLen ; pCrvC->GetLength( dCrvLen) ; dCurrLen += dCrvLen ; - Vector3d vtEndDepth = vtTool * ( dDepth - dElev + min((( j + dCurrLen / dTotLen) * dStep), dElev)) ; + Vector3d vtEndDepth = vtTool * ( dDepth - dElev - dStart + min((( j + dCurrLen / dTotLen) * dStep), dElev + dStart)) ; // se prima entità di primo step, approccio e affondo if ( i == 0 && j == 0) { // dati inizio entità diff --git a/Milling.h b/Milling.h index a373298..6a69413 100644 --- a/Milling.h +++ b/Milling.h @@ -67,6 +67,7 @@ class Milling : public Machining bool Chain( int nGrpDestId) ; bool ProcessPath( int nPathId, int nPvId, int nClId) ; bool CalcPathElevation( const ICurveComposite* pCompo, const Vector3d& vtTool, double dDepth, double& dElev) ; + bool GenerateMillingPv( int nPathId, const ICurveComposite* pCompo) ; bool AddStandardMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr, double dDepth, double dElev, bool bSplitArcs) ; bool AddZigZagMilling( const ICurveComposite* pCompo, const Vector3d& vtTool, const Vector3d& vtExtr,