From 64c0e3826c3fbfa6849a4b167c4333244f1ef3ac Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 13 Oct 2016 15:11:27 +0000 Subject: [PATCH] EgtMachKernel : - GetFirst/GetNextFixture ora operano sui soli bloccaggi della fase corrente - esportate RemoveFixture, MoveFixture, RotateFixture e MoveFixtureMobile - aggiunta GetRawPartFromPart - gestione bloccaggi con diverse fasi - corretta inizializzazione tavola in simulazione alla seconda disposizione e successive - in fresatura a spirale si ignora overlap - in fresatura se parametri tang e perp di attacco o uscita sono nulli si mette attacco/uscita nullo. --- Disposition.cpp | 80 ++++++++++++++++++++++++++-- Disposition.h | 5 +- MachMgr.h | 7 ++- MachMgrFixtures.cpp | 123 ++++++++++++++++++++++++++++++-------------- MachMgrParts.cpp | 15 ++++++ MachMgrPhases.cpp | 18 +++++-- Milling.cpp | 75 +++++++++++++++++---------- Simulator.cpp | 2 + 8 files changed, 247 insertions(+), 78 deletions(-) diff --git a/Disposition.cpp b/Disposition.cpp index 2c6d956..3535485 100644 --- a/Disposition.cpp +++ b/Disposition.cpp @@ -459,6 +459,44 @@ Disposition::AddFixture( const string& sName, const Point3d& ptPos, double dAngD return nFixtId ; } +//---------------------------------------------------------------------------- +int +Disposition::GetFirstFixture( void) +{ + // verifico se ci sono bloccaggi + if ( m_vFixData.empty()) + return GDB_ID_NULL ; + // recupero il primo + int nId = m_vFixData.front().nId ; + // ne verifico la validità + if ( ! VerifyFixture( nId)) + return GDB_ID_NULL ; + return nId ; +} + +//---------------------------------------------------------------------------- +int +Disposition::GetNextFixture( int nId) +{ + // verifica validità bloccaggio + if ( ! VerifyFixture( nId)) + return GDB_ID_NULL ; + // ciclo sui bloccaggi + int nFxtTot = int( m_vFixData.size()) ; + for ( int i = 0 ; i < nFxtTot ; ++ i) { + // se trovato + if ( m_vFixData[i].nId == nId) { + // se esiste successivo e valido + int j = i + 1 ; + if ( j < nFxtTot && VerifyFixture( m_vFixData[j].nId)) + return m_vFixData[j].nId ; + else + return GDB_ID_NULL ; + } + } + return GDB_ID_NULL ; +} + //---------------------------------------------------------------------------- bool Disposition::MoveFixture( int nId, const Vector3d& vtMove) @@ -471,7 +509,7 @@ Disposition::MoveFixture( int nId, const Vector3d& vtMove) return false ; // verifico che la posizione finale sia nell'area della tavola Frame3d frFixt ; - if ( ! m_pGeomDB->GetGlobFrame( nId, frFixt) || + if ( ! m_pGeomDB->GetGroupFrame( nId, frFixt) || ! m_b3Area1.EnclosesXY( frFixt.Orig() + vtMove)) return false ; // muovo l'oggetto @@ -488,7 +526,7 @@ Disposition::MoveFixture( int nId, const Vector3d& vtMove) //---------------------------------------------------------------------------- bool -Disposition::RotateFixture( int nId, double dAngDeg) +Disposition::RotateFixture( int nId, double dDeltaAngDeg) { // verifica validità sottopezzo if ( ! VerifyFixture( nId)) @@ -496,12 +534,42 @@ Disposition::RotateFixture( int nId, double dAngDeg) // verifico aggiornamento tavola if ( ! m_bTabOk && ! SetTable( m_sTabName)) return false ; - // muovo l'oggetto - m_pGeomDB->RotateGroup( nId, ORIG, Z_AX, dAngDeg) ; + // ruoto l'oggetto + m_pGeomDB->RotateGroup( nId, ORIG, Z_AX, dDeltaAngDeg) ; // aggiorno la posizione dell'oggetto nel vettore dei comandi for ( auto& FixData : m_vFixData) { if ( FixData.nId == nId) { - FixData.dAng += dAngDeg ; + FixData.dAng += dDeltaAngDeg ; + break ; + } + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +Disposition::MoveFixtureMobile( int nId, double dDeltaMov) +{ + // verifica validità sottopezzo + if ( ! VerifyFixture( nId)) + return false ; + // verifico aggiornamento tavola + if ( ! m_bTabOk && ! SetTable( m_sTabName)) + return false ; + // muovo eventuale parte mobile + int nMobId = m_pGeomDB->GetFirstNameInGroup( nId, FXT_MOBILE) ; + if ( nMobId != GDB_ID_NULL) { + double dCurrVal = 0 ; + m_pGeomDB->GetInfo( nMobId, FXT_MOB_CPOS, dCurrVal) ; + if ( abs( dDeltaMov) > EPS_SMALL) { + m_pGeomDB->TranslateGroup( nMobId, Vector3d( 0, 0, dDeltaMov)) ; + m_pGeomDB->SetInfo( nMobId, FXT_MOB_CPOS, ( dCurrVal + dDeltaMov)) ; + } + } + // aggiorno la posizione dell'oggetto nel vettore dei comandi + for ( auto& FixData : m_vFixData) { + if ( FixData.nId == nId) { + FixData.dMov += dDeltaMov ; break ; } } @@ -521,6 +589,8 @@ Disposition::PlaceFixture( int nId, const Point3d& ptPos, double dAngDeg, double // verifico che la posizione sia nell'area della tavola if ( ! m_b3Area1.EnclosesXY( m_ptRef1 + ptPos)) return false ; + // aggiorno visualizzazione + m_pGeomDB->SetStatus( nId, GDB_ST_ON) ; // resetto il riferimento del gruppo Frame3d* pfrFixt = m_pGeomDB->GetGroupFrame( nId) ; pfrFixt->Reset() ; diff --git a/Disposition.h b/Disposition.h index 8091805..41b1b66 100644 --- a/Disposition.h +++ b/Disposition.h @@ -85,8 +85,11 @@ class Disposition : public Operation bool GetTableArea1( BBox3d& b3Area1) const ; int AddFixture( const std::string& sName, const Point3d& ptPos, double dAngDeg = 0, double dMov = 0, bool bAddToList = true) ; + int GetFirstFixture( void) ; + int GetNextFixture( int nId) ; bool MoveFixture( int nId, const Vector3d& vtMove) ; - bool RotateFixture( int nId, double dAngDeg) ; + bool RotateFixture( int nId, double dDeltaAngDeg) ; + bool MoveFixtureMobile( int nId, double dDeltaMov) ; bool PlaceFixture( int nId, const Point3d& ptPos, double dAngDeg, double dMov) ; bool RemoveFixture( int nId) ; bool MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList = true) ; diff --git a/MachMgr.h b/MachMgr.h index ed1de70..28a793a 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -113,6 +113,7 @@ class MachMgr : public IMachMgr int GetFirstPartInRawPart( int nRawId) const override ; int GetNextPartInRawPart( int nId) const override ; bool AddPartToRawPart( int nPartId, const Point3d& ptPos, int nRawId) override ; + int GetRawPartFromPart( int nPartId) override ; bool RemovePartFromRawPart( int nPartId) override ; bool TranslatePartInRawPart( int nPartId, const Vector3d& vtMove) override ; bool RotatePartInRawPart( int nPartId, const Vector3d& vtAx, double dAngRotDeg) override ; @@ -121,10 +122,14 @@ class MachMgr : public IMachMgr bool GetTable( std::string& sTable) override ; bool GetTableRef( int nInd, Point3d& ptPos) override ; bool GetTableArea( int nInd, BBox3d& b3Area) override ; + bool ShowOnlyTable( bool bVal) override ; int AddFixture( const std::string& sName, const Point3d& ptPos, double dAngRotDeg, double dMov) override ; + bool RemoveFixture( int nFxtId) override ; int GetFirstFixture( void) override ; int GetNextFixture( int nFxtId) override ; - bool ShowOnlyTable( bool bVal) override ; + bool MoveFixture( int nId, const Vector3d& vtMove) override ; + bool RotateFixture( int nId, double dDeltaAngDeg) override ; + bool MoveFixtureMobile( int nId, double dDeltaMov) override ; // Tools DataBase bool TdbGetToolNewName( std::string& sName) const override ; bool TdbAddTool( const std::string& sName, int nType) override ; diff --git a/MachMgrFixtures.cpp b/MachMgrFixtures.cpp index 54f95a5..40e27d0 100644 --- a/MachMgrFixtures.cpp +++ b/MachMgrFixtures.cpp @@ -74,45 +74,6 @@ MachMgr::GetTableArea( int nInd, BBox3d& b3Area1) return pDisp->GetTableArea1( b3Area1) ; } -//---------------------------------------------------------------------------- -int -MachMgr::AddFixture( const string& sName, const Point3d& ptPos, double dAngRotDeg, double dMov) -{ - // recupero l'oggetto disposizione corrente - Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; - if ( pDisp == nullptr) - return false ; - // eseguo l'operazione - return pDisp->AddFixture( sName, ptPos, dAngRotDeg, dMov) ; -} - -//---------------------------------------------------------------------------- -int -MachMgr::GetFirstFixture( void) -{ - // recupero il gruppo delle fixtures nella macchinata corrente - int nFixtGrpId = GetCurrFixtGroupId() ; - if ( nFixtGrpId == GDB_ID_NULL) - return GDB_ID_NULL ; - // restituisco identificativo del primo oggetto nel gruppo - return m_pGeomDB->GetFirstInGroup( nFixtGrpId) ; -} - -//---------------------------------------------------------------------------- -int -MachMgr::GetNextFixture( int nFxtId) -{ - // recupero il gruppo delle fixtures nella macchinata corrente - int nFixtGrpId = GetCurrFixtGroupId() ; - if ( nFixtGrpId == GDB_ID_NULL) - return GDB_ID_NULL ; - // verifico che l'oggetto ricevuto appartenga al gruppo delle fixtures - if ( m_pGeomDB->GetParentId( nFxtId) != nFixtGrpId) - return GDB_ID_NULL ; - // restituisco identificativo del primo oggetto nel gruppo - return m_pGeomDB->GetNext( nFxtId) ; -} - //---------------------------------------------------------------------------- bool MachMgr::ShowOnlyTable( bool bVal) @@ -129,3 +90,87 @@ MachMgr::ShowOnlyTable( bool bVal) // imposto visualizzazione della sola tavola o di tutto return pMch->SetLook( bVal ? MCH_LOOK_TAB : MCH_LOOK_ALL) ; } + +//---------------------------------------------------------------------------- +int +MachMgr::AddFixture( const string& sName, const Point3d& ptPos, double dAngRotDeg, double dMov) +{ + // recupero l'oggetto disposizione corrente + Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; + if ( pDisp == nullptr) + return GDB_ID_NULL ; + // eseguo l'operazione + return pDisp->AddFixture( sName, ptPos, dAngRotDeg, dMov) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::RemoveFixture( int nFxtId) +{ + // recupero l'oggetto disposizione corrente + Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; + if ( pDisp == nullptr) + return false ; + // eseguo l'operazione + return pDisp->RemoveFixture( nFxtId) ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetFirstFixture( void) +{ + // recupero l'oggetto disposizione corrente + Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; + if ( pDisp == nullptr) + return GDB_ID_NULL ; + // eseguo l'operazione + return pDisp->GetFirstFixture() ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetNextFixture( int nFxtId) +{ + // recupero l'oggetto disposizione corrente + Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; + if ( pDisp == nullptr) + return GDB_ID_NULL ; + // eseguo l'operazione + return pDisp->GetNextFixture( nFxtId) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::MoveFixture( int nId, const Vector3d& vtMove) +{ + // recupero l'oggetto disposizione corrente + Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; + if ( pDisp == nullptr) + return false ; + // eseguo l'operazione + return pDisp->MoveFixture( nId, vtMove) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::RotateFixture( int nId, double dDeltaAngDeg) +{ + // recupero l'oggetto disposizione corrente + Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; + if ( pDisp == nullptr) + return false ; + // eseguo l'operazione + return pDisp->RotateFixture( nId, dDeltaAngDeg) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::MoveFixtureMobile( int nId, double dDeltaMov) +{ + // recupero l'oggetto disposizione corrente + Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; + if ( pDisp == nullptr) + return false ; + // eseguo l'operazione + return pDisp->MoveFixtureMobile( nId, dDeltaMov) ; +} diff --git a/MachMgrParts.cpp b/MachMgrParts.cpp index 840ceeb..7f51a32 100644 --- a/MachMgrParts.cpp +++ b/MachMgrParts.cpp @@ -109,6 +109,21 @@ MachMgr::AddPartToRawPart( int nPartId, const Point3d& ptPos, int nRawId) return true ; } +//---------------------------------------------------------------------------- +int +MachMgr::GetRawPartFromPart( int nPartId) +{ + // verifico DB geometrico + if ( m_pGeomDB == nullptr) + return false ; + // recupero l'indice del grezzo + int nRawId = m_pGeomDB->GetParentId( nPartId) ; + // verifica validità grezzo + if ( ! VerifyRawPart( nRawId)) + return GDB_ID_NULL ; + return nRawId ; +} + //---------------------------------------------------------------------------- bool MachMgr::RemovePartFromRawPart( int nPartId) diff --git a/MachMgrPhases.cpp b/MachMgrPhases.cpp index 6b7f2fe..bcbcb93 100644 --- a/MachMgrPhases.cpp +++ b/MachMgrPhases.cpp @@ -65,6 +65,10 @@ MachMgr::SetCurrPhase( int nPhase, bool bForced) bool MachMgr::PrepareCurrPhase( int nPhase, bool bDoDisp, bool bForced) { + // verifico esistenza macchina + Machine* pMach = GetCurrMachine() ; + if ( pMach == nullptr) + return false ; // verifico esistenza fase if ( nPhase <= 0 || nPhase > m_nPhasesCount) return false ; @@ -75,10 +79,16 @@ MachMgr::PrepareCurrPhase( int nPhase, bool bDoDisp, bool bForced) const Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( GetCurrMachining())) ; if ( pMch != nullptr && pMch->GetPhase() != nPhase) ResetCurrMachining() ; - // riporto tutti i grezzi linkati nel gruppo dei grezzi - Machine* pMach = GetCurrMachine() ; - if ( pMach != nullptr) - pMach->UnlinkAllRawPartsFromGroups() ; + // riporto tutti i bloccaggi linkati nel gruppo dei bloccaggi + pMach->UnlinkAllFixturesFromGroups() ; + // nascondo tutti i bloccaggi + int nFxtId = m_pGeomDB->GetFirstGroupInGroup( GetCurrFixtGroupId()) ; + while ( nFxtId != GDB_ID_NULL) { + m_pGeomDB->SetStatus( nFxtId, GDB_ST_OFF) ; + nFxtId = m_pGeomDB->GetNextGroup( nFxtId) ; + } + // riporto tutti i grezzi linkati nel gruppo dei grezzi + pMach->UnlinkAllRawPartsFromGroups() ; // tolgo i pezzi dai grezzi che non appartengono alla fase int nRawId = GetFirstRawPart() ; while ( nRawId != GDB_ID_NULL) { diff --git a/Milling.cpp b/Milling.cpp index 2325e4e..017442a 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -377,14 +377,9 @@ Milling::SetGeometry( const SELVECTOR& vIds) continue ; } // posso aggiungere alla lista - //if ( nSubs == 0) - m_vId.emplace_back( Id) ; - //else { - // for ( int i = 0 ; i < nSubs ; ++ i) - // m_vId.emplace_back( Id.nId, i) ; - //} + m_vId.emplace_back( Id) ; } - return ( ! m_vId.empty()) ; + return ( ! m_vId.empty() || vIds.empty()) ; } //---------------------------------------------------------------------------- @@ -930,11 +925,34 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) if ( m_Params.m_bInvert) pCompo->Invert() ; - // recupero il punto di inizio (per poi salvarlo nelle info di CL path) - Point3d ptStart ; - pCompo->GetStartPoint( ptStart) ; + // recupero estrusione e spessore + Vector3d vtExtr ; + pCompo->GetExtrusion( vtExtr) ; + double dThick ; + pCompo->GetThickness( dThick) ; + + // se utensile non centrato, eseguo correzione raggio utensile ed eventuale offset + double dOffs = 0.5 * m_TParams.m_dDiam + GetOffsR() ; + if ( m_Params.m_nWorkSide != MILL_WS_CENTER && abs( dOffs) > EPS_SMALL) { + // valore offset + double dSignOffs = ( m_Params.m_nWorkSide == MILL_WS_RIGHT) ? dOffs : - dOffs ; + // flag offset + int nFlag = ICurve::OFF_EXTEND ; + 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)) { + LOG_INFO( GetEMkLogger(), "Error in Milling : SimpleOffset not computable") ; + return false ; + } + } // eventuali allungamenti per percorso aperto + bool bOverlapOn = false ; if ( ! pCompo->IsClosed()) { // eventuale allungamento/accorciamento dell'inizio if ( abs( m_Params.m_dStartAddLen) > EPS_SMALL) { @@ -967,8 +985,10 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) if ( pCompo->GetParamAtLength( 0.0, dParS) && pCompo->GetParamAtLength( m_Params.m_dOverlap, dParE)) { PtrOwner pCrv( pCompo->CopyParamRange( dParS, dParE)) ; - if ( ! IsNull( pCrv)) + if ( ! IsNull( pCrv)) { pCompo->AddCurve( Release( pCrv)) ; + bOverlapOn = true ; + } } } } @@ -977,21 +997,9 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) if ( ! pCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL, false)) return false ; - // se utensile non centrato, eseguo correzione raggio utensile ed eventuale offset - double dOffs = 0.5 * m_TParams.m_dDiam + GetOffsR() ; - if ( m_Params.m_nWorkSide != MILL_WS_CENTER && abs( dOffs) > EPS_SMALL) { - double dSignOffs = ( m_Params.m_nWorkSide == MILL_WS_RIGHT) ? dOffs : - dOffs ; - if ( ! pCompo->SimpleOffset( dSignOffs, ICurve::OFF_EXTEND)) { - LOG_INFO( GetEMkLogger(), "Error in Milling : SimpleOffset not computable") ; - return false ; - } - } - - // recupero estrusione e spessore - Vector3d vtExtr ; - pCompo->GetExtrusion( vtExtr) ; - double dThick ; - pCompo->GetThickness( dThick) ; + // recupero il punto di inizio (per poi salvarlo nelle info di CL path) + Point3d ptStart ; + pCompo->GetStartPoint( ptStart) ; // recupero il box del grezzo in globale BBox3d b3Raw ; @@ -1134,6 +1142,13 @@ Milling::ProcessPath( int nPathId, int nPvId, int nClId) } // se altrimenti passate a spirale else if ( m_Params.m_nStepType == MILL_ST_SPIRAL) { + // elimino eventuale overlap prima aggiunto + if ( bOverlapOn) { + double dLen ; + if ( pCompo->GetLength( dLen)) + pCompo->TrimEndAtLen( dLen - m_Params.m_dOverlap) ; + } + // eseguo if ( ! AddSpiralMilling( pCompo, vtTool, vtExtr, dDepth, dElev, bSplitArcs)) return false ; } @@ -1962,8 +1977,6 @@ Milling::CalcLeadInStart( const Point3d& ptStart, const Vector3d& vtStart, const return true ; case MILL_LI_LINEAR : case MILL_LI_TANGENT : { - if ( dTang < 10 * EPS_SMALL && abs( dPerp) < 10 * EPS_SMALL) - return false ; Vector3d vtPerp = vtStart ; vtPerp.Rotate( vtN, ( bCcwRot ? 90 : - 90)) ; ptP1 = ptStart - vtStart * dTang + vtPerp * dPerp + vtN * dElev ; @@ -2001,6 +2014,9 @@ Milling::AddLeadIn( const Point3d& ptP1, const Point3d& ptStart, const Vector3d& if ( nType == MILL_LI_HELIX) nType = MILL_LI_ZIGZAG ; } + // se parametri tg e perp entrambi nulli, allora nessun attacco + if ( (( ptStart - ptP1) ^ vtN).IsSmall()) + nType = MILL_LI_NONE ; // Eseguo a seconda del tipo switch ( nType) { case MILL_LI_NONE : @@ -2104,6 +2120,9 @@ Milling::AddLeadOut( const Point3d& ptEnd, const Vector3d& vtEnd, const Vector3d if ( nType == MILL_LO_TANGENT) nType = MILL_LO_LINEAR ; } + // se parametri nulli, allora nessuna uscita + if ( abs( dTang) < EPS_SMALL && abs( dPerp) < EPS_SMALL ) + nType = MILL_LO_NONE ; // senso di rotazione da dir tg a dir esterna bool bCcwRot = (( ! bInvert && m_Params.m_nWorkSide == MILL_WS_LEFT) || ( bInvert && m_Params.m_nWorkSide != MILL_WS_LEFT)) ; diff --git a/Simulator.cpp b/Simulator.cpp index 7d44046..ddbd6b0 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -208,6 +208,8 @@ Simulator::Move( int& nStatus) // se disposizione con cambio di fase Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ; if ( pDisp != nullptr) { + // in alcuni casi la disposizione non è inizializzata + pDisp->Init( m_pMchMgr) ; // recupero dati tavola string sTable ; pDisp->GetTable( sTable) ;