From 5849ad4f41867b61e6da70d1d9aeb79d427b4b5f Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 23 Jan 2017 17:29:20 +0000 Subject: [PATCH] EgtMachKernel : - prime modifiche per gestione aggregato da sotto. --- Drilling.cpp | 47 ++++++++++++++++++++++++++++--- Drilling.h | 1 + Machine.h | 1 + MachineCalc.cpp | 30 ++++++++++++++++++++ Operation.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++-- Operation.h | 1 + 6 files changed, 147 insertions(+), 6 deletions(-) diff --git a/Drilling.cpp b/Drilling.cpp index 0abc01f..c87e516 100644 --- a/Drilling.cpp +++ b/Drilling.cpp @@ -841,16 +841,20 @@ Drilling::GenerateHoleCl( int nInd, const SelData& nCircId, const string& sPName hole.ptIni -= hole.vtDir * hole.dLen ; hole.vtDir.Invert() ; } - // assegno il vettore estrazione al gruppo del percorso - m_pGeomDB->SetInfo( nPathId, KEY_EXTR, hole.vtDir) ; - // assegno il punto di inizio al gruppo del percorso - m_pGeomDB->SetInfo( nPathId, KEY_START, hole.ptIni) ; // limito lunghezza foro a massima lavorazione della punta if ( hole.dLen > m_TParams.m_dMaxMat + EPS_SMALL) { hole.dLen = m_TParams.m_dMaxMat ; string sOut = "Drill bit too short for Hole " + ToString( nCircId) ; LOG_INFO( GetEMkLogger(), sOut.c_str()) ; } + // verifiche per foro verso il basso + if ( ! VerifyHoleFromBottom( hole, nCircId)) { + return false ; + } + // assegno il vettore estrazione al gruppo del percorso + m_pGeomDB->SetInfo( nPathId, KEY_EXTR, hole.vtDir) ; + // assegno il punto di inizio al gruppo del percorso + m_pGeomDB->SetInfo( nPathId, KEY_START, hole.ptIni) ; // foro normale if ( m_Params.m_dStep < EPS_SMALL || m_Params.m_dStep > hole.dLen - EPS_SMALL) { @@ -1180,6 +1184,41 @@ Drilling::GetHoleData( SelData Id, Hole& hole) return true ; } +//---------------------------------------------------------------------------- +bool +Drilling::VerifyHoleFromBottom( const Hole& hole, SelData Id) +{ + // se non è foro dal basso in alto, esco + if ( hole.vtDir.z > - 0.5) + return true ; + // se c'è tavola basculante, esco + bool bTabTilting = false ; + if ( m_pMchMgr->GetCurrMachine()->GetCurrTableIsTilting( bTabTilting) && bTabTilting) + return true ; + // verifico se c'è rinvio da sotto + int nHeadId = m_pMchMgr->GetHeadId( m_TParams.m_sHead) ; + int nAgbType ; + if ( ! m_pGeomDB->GetInfo( nHeadId, "AGB_TYPE", nAgbType) || nAgbType == 0) { + string sOut = "Entity " + ToString( Id) + " skipped by Drilling : missing aggregate from bottom" ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) ; + return false ; + } + // recupero la massima distanza consentita dal rinvio + double dAgbDmax = 0 ; + m_pGeomDB->GetInfo( nHeadId, "AGB_DMAX", dAgbDmax) ; + // calcolo la distanza minima del punto dal contorno del grezzo + double dDist ; + Vector3d vtDir ; + if ( ! GetMinDistanceFromRawSide( m_nPhase, hole.ptIni, dDist, vtDir) || dDist > dAgbDmax) { + string sOut = "Entity " + ToString( Id) + " skipped by Drilling : too far from part sides" ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) ; + return false ; + } + // assegno direzione di accesso + SetAuxDir( vtDir) ; + return true ; +} + //---------------------------------------------------------------------------- bool Drilling::DoStandardDrilling( const Hole& hole, SelData Id, int nPathId) diff --git a/Drilling.h b/Drilling.h index 4a3d6fb..84ba156 100644 --- a/Drilling.h +++ b/Drilling.h @@ -73,6 +73,7 @@ class Drilling : public Machining bool GenerateHoleCl( int nInd, const SelData& nCircId, const string& sPName, int nClId) ; bool GenerateHoleRegionPv( int nFirstId, int nCount, int nPvId) ; bool VerifyDiameter( double dHdiam, double dTdiam, double ddiamTol) ; + bool VerifyHoleFromBottom( const Hole& hole, SelData Id) ; bool DoStandardDrilling( const Hole& hole, SelData Id, int nPathId) ; bool DoPeckDrilling( const Hole& hole, SelData Id, int nPathId) ; diff --git a/Machine.h b/Machine.h index af2b356..622f15e 100644 --- a/Machine.h +++ b/Machine.h @@ -72,6 +72,7 @@ class Machine bool GetCurrTableRef1( Point3d& ptRef1) const ; bool GetCurrTableArea1( BBox3d& b3Area1) const ; bool GetCurrTableDeltaRef1( Vector3d& vtDelta1) const ; + bool GetCurrTableIsTilting( bool& bTilting) const ; bool SetCurrTool( const std::string& sTool, const std::string& sHead, int nExit) ; int GetCurrTool( void) const ; bool GetCurrTool( std::string& sTool) const ; diff --git a/MachineCalc.cpp b/MachineCalc.cpp index c074c7e..a64af6a 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -137,6 +137,36 @@ Machine::GetCurrTableDeltaRef1( Vector3d& vtDelta1) const return true ; } +//---------------------------------------------------------------------------- +bool +Machine::GetCurrTableIsTilting( bool& bTilting) const +{ + // default + bTilting = false ; + // verifico esistenza tavola + if ( m_nCalcTabId == GDB_ID_NULL) + return false ; + // recupero gli eventuali assi rotanti della tavola + int nTParId = m_pGeomDB->GetParentId( m_nCalcTabId) ; + if ( nTParId == GDB_ID_NULL) + return false ; + while ( IsAxisGroup( nTParId)) { + // recupero il gestore dell'asse + Axis* pAx = GetAxis( nTParId) ; + if ( pAx == nullptr) + return false ; + // verifico se asse rotante orizzontale + if ( pAx->GetType() == MCH_AT_ROTARY && abs( pAx->GetDir().z) < EPS_SMALL) { + bTilting = true ; + return true ; + } + // risalgo lungo la catena + nTParId = m_pGeomDB->GetParentId( nTParId) ; + } + + return true ; +} + //---------------------------------------------------------------------------- bool Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) diff --git a/Operation.cpp b/Operation.cpp index ef2edea..26c5a99 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -282,7 +282,7 @@ Operation::GetDistanceFromRawSide( int nPhase, const Point3d& ptP, const Vector3 ptPL.ToLoc( frRaw) ; // verifica con il contorno int nOutCrvId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_OUTLINE) ; - ICurve* pCurve = GetCurve( m_pGeomDB->GetGeoObj( nOutCrvId)) ; + const ICurve* pCurve = GetCurve( m_pGeomDB->GetGeoObj( nOutCrvId)) ; if ( pCurve != nullptr) { int nSide ; double dDist ; @@ -326,6 +326,75 @@ Operation::GetDistanceFromRawSide( int nPhase, const Point3d& ptP, const Vector3 return true ; } + +//---------------------------------------------------------------------------- +bool +Operation::GetMinDistanceFromRawSide( int nPhase, const Point3d& ptP, double& dDist, Vector3d& vtDir) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero il grezzo in cui è incluso il punto + BBox3d b3Pnt( ptP) ; + b3Pnt.Expand( 10, 10, 0) ; + int nRawId = m_pMchMgr->GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // verifico che il grezzo compaia nella fase + if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { + // pre-filtro con il box + BBox3d b3Raw ; + int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + if ( m_pGeomDB->GetGlobalBBox( nRawSolidId, b3Raw) && b3Pnt.OverlapsXY( b3Raw)) { + // porto il punto nel riferimento del grezzo + Frame3d frRaw ; + m_pGeomDB->GetGroupGlobFrame( nRawId, frRaw) ; + Point3d ptPL = ptP ; + ptPL.ToLoc( frRaw) ; + // verifica con il contorno + int nOutCrvId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_OUTLINE) ; + const ICurve* pCurve = GetCurve( m_pGeomDB->GetGeoObj( nOutCrvId)) ; + if ( pCurve != nullptr) { + int nSide ; + DistPointCurve distPC( ptPL, *pCurve) ; + // se punto praticamente sul bordo del grezzo, prendo la normale esterna a questo bordo + if ( distPC.GetDist( dDist) && dDist < 100 * EPS_SMALL) { + double dU ; + int nFlag ; + Point3d ptML ; + Vector3d vtTgL ; + if ( distPC.GetParamAtMinDistPoint( 0, dU, nFlag) && + pCurve->GetPointTang( dU, ICurve::FROM_MINUS, ptML, vtTgL)) { + vtDir = vtTgL ; + vtDir.Rotate( Z_AX, - ANG_RIGHT) ; + vtDir.ToGlob( frRaw) ; + vtDir.Normalize() ; + break ; + } + } + // altrimenti se punto interno, prendo la direzione dal punto al bordo + else if (distPC.GetSideAtMinDistPoint( 0, Z_AX, nSide) && nSide != MDS_RIGHT) { + int nFlag ; + Point3d ptML ; + if ( distPC.GetMinDistPoint( 0, ptML, nFlag)) { + vtDir = ptML - ptPL ; + vtDir.ToGlob( frRaw) ; + vtDir.z = 0 ; + vtDir.Normalize() ; + break ; + } + } + } + } + } + // passo al grezzo successivo + nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; + } + // se il punto non è interno ad alcun grezzo, distanza nulla + if ( nRawId == GDB_ID_NULL) + dDist = 0 ; + + return true ; +} + //---------------------------------------------------------------------------- bool Operation::GetDistanceFromRawBottom( int nPhase, int nPathId, double dToler, double& dRbDist) @@ -1409,7 +1478,7 @@ Operation::TestCollisionAvoid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEn if ( vAxName.size() != vAxStart.size() || vAxName.size() != vAxEnd.size()) return false ; // !!! Temporaneo in attesa di gestione attrezzaggio !!! - // Se testa con Info ZMAXONROT != 0 e variazione assi rotanti -> collisione + // Se testa con Info ZMAXONROT != 0 e movimento assi rotanti -> collisione int nHeadId = pMch->GetCurrHead() ; int nVal = 0 ; if ( m_pGeomDB->GetInfo( nHeadId, "ZMAXONROT", nVal) && nVal != 0) { diff --git a/Operation.h b/Operation.h index a975dca..314aa82 100644 --- a/Operation.h +++ b/Operation.h @@ -63,6 +63,7 @@ class Operation : public IUserObj bool GetElevation( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double dRad, double& dElev) ; bool GetDistanceFromRawSide( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist) ; + bool GetMinDistanceFromRawSide( int nPhase, const Point3d& ptP, double& dDist, Vector3d& vtDir) ; bool GetDistanceFromRawBottom( int nPhase, int nPathId, double dToler, double& dRbDist) ; bool GetRawGlobBox( int nPhase, int nPathId, double dToler, BBox3d& b3Raw) ;