From 14b99c473b07fd271168ce7b24fbb2c4a1652e90 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 23 Dec 2024 12:09:11 +0100 Subject: [PATCH 1/2] EgtMachkernel : - agli script di ToolMakers ora si passano anche le note utente (TOOL.USERNOTES) - anche nel movimento manuale assi in simulazione si tiene conto dei limiti di corsa assi eventualmente aggiunti dalla testa - notevoli migliorie alla nuova gestione dei link tra lavorazioni. --- MachMgrDBTools.cpp | 4 + Machine.h | 1 + MachineAxes.cpp | 14 +++- MachineCalc.cpp | 17 +++- Operation.cpp | 195 ++++++++++++++++++++++++++++----------------- Operation.h | 21 ++--- 6 files changed, 161 insertions(+), 91 deletions(-) diff --git a/MachMgrDBTools.cpp b/MachMgrDBTools.cpp index 78ec7f6..e3b74c7 100644 --- a/MachMgrDBTools.cpp +++ b/MachMgrDBTools.cpp @@ -667,6 +667,7 @@ MachMgr::UpdateStandardToolDraw( const ToolData* pTdata, int nGenCtx, int nToolC bool bOk = ExeLuaSetGlobIntVar( "TOOL.TYPE", nType) ; bOk = bOk && ExeLuaSetGlobNumVar( "TOOL.SPEED", dSpeed) ; bOk = bOk && ExeLuaSetGlobNumVar( "TOOL.TIPFEED", dTipFeed) ; + bOk = bOk && ExeLuaSetGlobStringVar( "TOOL.USERNOTES", sUserNotes) ; switch ( nType) { case TT_DRILL_STD : case TT_DRILL_LONG : @@ -762,6 +763,8 @@ MachMgr::UpdateCustomToolDraw( const ToolData* pTdata, int nGenCtx, int nToolCtx pTdata->GetParam( TPA_DIST, dDist) ; double dSpeed = 0 ; pTdata->GetParam( TPA_SPEED, dSpeed) ; + string sUserNotes ; + pTdata->GetParam( TPA_USERNOTES, sUserNotes) ; // Imposto contesto per il disegno utensile if ( ! ExeSetCurrentContext( nToolCtx)) return TD_INT_ERR ; @@ -772,6 +775,7 @@ MachMgr::UpdateCustomToolDraw( const ToolData* pTdata, int nGenCtx, int nToolCtx bOk = bOk && ExeLuaSetGlobNumVar( "TOOL.DIAM", dDiam) ; bOk = bOk && ExeLuaSetGlobNumVar( "TOOL.DIST", dDist) ; bOk = bOk && ExeLuaSetGlobNumVar( "TOOL.SPEED", dSpeed) ; + bOk = bOk && ExeLuaSetGlobStringVar( "TOOL.USERNOTES", sUserNotes) ; // Eseguo aggiornamento utensile bOk = bOk && ExeLuaCallFunction( "AdjustCustomTool") ; // Recupero errore diff --git a/Machine.h b/Machine.h index dcf644c..b33655a 100644 --- a/Machine.h +++ b/Machine.h @@ -262,6 +262,7 @@ class Machine bool AdjustExitFrames( int nLay, const MUEXITVECTOR& vMuExit, const Vector3d& vtADir) ; bool CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) ; bool ModifyMachineExitPosition( const std::string& sHead, int nExit, const Point3d& ptPos) ; + bool ClearKinematicChain( void) ; bool CalculateKinematicChain( void) ; bool AddKinematicAxis( bool bOnHead, int nId) ; bool GetMyAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, diff --git a/MachineAxes.cpp b/MachineAxes.cpp index 33327f6..b6b10f8 100644 --- a/MachineAxes.cpp +++ b/MachineAxes.cpp @@ -138,6 +138,15 @@ Machine::SetAxisPos( const string& sAxis, double dVal, bool bInStroke, double* p double dCurrVal = pAx->GetCurrVal() ; // limiti della corsa STROKE Stroke = pAx->GetStroke() ; + // se rotante e corrente, verifico se ci sono limitazioni aggiuntive (dalla testa) + if ( ! bLinear) { + for ( const auto& CalcRotAx : m_vCalcRotAx) { + if ( CalcRotAx.nGrpId == nAxGrp) { + Stroke.Min = max( Stroke.Min, CalcRotAx.stroke.Min) ; + Stroke.Max = min( Stroke.Max, CalcRotAx.stroke.Max) ; + } + } + } // recupero il vettore dell'asse int nV = m_pGeomDB->GetFirstNameInGroup( nAxGrp, sAxis) ; const IGeoVector3d* pGV = GetGeoVector3d( m_pGeomDB->GetGeoObj( nV)) ; @@ -146,8 +155,9 @@ Machine::SetAxisPos( const string& sAxis, double dVal, bool bInStroke, double* p Point3d ptPos = pGV->GetBase() ; Vector3d vtDir = pGV->GetVector() ; vtDir.Normalize() ; - // limito il movimento alla corsa dell'asse - dVal = Clamp( dVal, Stroke.Min, Stroke.Max) ; + // se richiesto, limito il movimento alla corsa dell'asse + if ( bInStroke) + dVal = Clamp( dVal, Stroke.Min, Stroke.Max) ; // eseguo il movimento if ( bLinear) m_pGeomDB->TranslateGroup( nAxGrp, vtDir * ( dVal - dCurrVal)) ; diff --git a/MachineCalc.cpp b/MachineCalc.cpp index d7e1b2e..b2682a6 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -481,11 +481,8 @@ Machine::GetCurrHeadCollGroups( INTVECTOR& vIds) const //---------------------------------------------------------------------------- bool -Machine::CalculateKinematicChain( void) +Machine::ClearKinematicChain( void) { - // controllo GeomDB - if ( m_pGeomDB == nullptr) - return false ; // azzero tutti gli assi della catena cinematica m_nTabLinAxes = 0 ; m_nTabRotAxes = 0 ; @@ -497,6 +494,18 @@ Machine::CalculateKinematicChain( void) m_frLinAx.Reset( false) ; m_frRobot.Reset( false) ; m_nCalcChainType = KIN_CHAIN_NONE ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Machine::CalculateKinematicChain( void) +{ + // controllo GeomDB + if ( m_pGeomDB == nullptr) + return false ; + // azzero tutti gli assi della catena cinematica + ClearKinematicChain() ; // recupero gli assi di tavola if ( m_nCalcTabId == GDB_ID_NULL) return false ; diff --git a/Operation.cpp b/Operation.cpp index 34b38ff..caf0f60 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -2626,7 +2626,7 @@ Operation::AdjustStartEndMovements( bool bVerifyPreviousLink) if ( bVerifyPreviousLink && bNewLink && m_pMchMgr->GetCurrIsCenter()) { // recupero posizione iniziale lavorazione DBLVECTOR vAxIni ; - if ( ! GetInitialAxesValues( true, vAxIni)) + if ( ! GetInitialAxesValues( false, vAxIni)) return false ; // eseguo verifica if ( ! ManageProtectedAreas( vAxVal, vAxIni, nullptr, this, bClimbDone)) @@ -2865,7 +2865,7 @@ Operation::AdjustStartEndMovements( bool bVerifyPreviousLink) // per nuova gestione collegamenti, verifica aree protette if ( bVerifyPreviousLink && bNewLink && m_pMchMgr->GetCurrIsCenter()) { // recupero posizione finale lavorazione - if ( ! pPrevOp->GetFinalAxesValues( true, vAxVal)) + if ( ! pPrevOp->GetFinalAxesValues( false, vAxVal)) return false ; // recupero posizione home DBLVECTOR vAxIni ; @@ -2889,7 +2889,7 @@ Operation::AdjustStartEndMovements( bool bVerifyPreviousLink) if ( bVerifyPreviousLink && bNewLink && m_pMchMgr->GetCurrIsCenter()) { // recupero posizione iniziale lavorazione DBLVECTOR vAxIni ; - if ( ! GetInitialAxesValues( true, vAxIni)) + if ( ! GetInitialAxesValues( false, vAxIni)) return false ; // eseguo verifica if ( ! ManageProtectedAreas( vAxVal, vAxIni, nullptr, this, bClimbDone)) @@ -2923,7 +2923,7 @@ Operation::AdjustStartEndMovements( bool bVerifyPreviousLink) // per nuova gestione collegamenti, verifica aree protette if ( bVerifyPreviousLink && bNewLink && m_pMchMgr->GetCurrIsCenter()) { // recupero posizione finale lavorazione - if ( ! GetFinalAxesValues( true, vAxVal)) + if ( ! GetFinalAxesValues( false, vAxVal)) return false ; // recupero posizione home DBLVECTOR vAxIni ; @@ -2944,91 +2944,113 @@ Operation::AdjustStartEndMovements( bool bVerifyPreviousLink) //---------------------------------------------------------------------------- bool -Operation::ManageProtectedAreas( const DBLVECTOR& vAxVal, const DBLVECTOR& vAxIni, Operation* pPrevOp, Operation* pNextOp, +Operation::ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, Operation* pPrevOp, Operation* pNextOp, bool& bClimbDone) { // se non ci sono aree protette, esco subito. if ( ! m_pMchMgr->GetCurrMachine()->ExistProtectedAreas()) return true ; + // il numero di assi non deve cambiare + if ( vAxStart.size() != vAxEnd.size()) + return false ; + int nAxisTot = int( vAxStart.size()) ; + // recupero flag nuova gestione collegamenti tra lavorazioni bool bNewLink = m_pMchMgr->GetCurrMachine()->GetNewLinkMgr() ; - // verifico se il collegamento le attraversa + // Verifico se il collegamento le attraversa + Point3d ptSta( vAxStart[0], vAxStart[1], vAxStart[2]) ; + Point3d ptEnd( vAxEnd[0], vAxEnd[1], vAxEnd[2]) ; + DBLVECTOR vAngSta ; + for ( int i = 3 ; i < int( vAxStart.size()) && bNewLink ; ++ i) + vAngSta.emplace_back( vAxStart[i]) ; + DBLVECTOR vAngEnd ; + for ( int i = 3 ; i < int( vAxEnd.size()) && bNewLink ; ++ i) + vAngEnd.emplace_back( vAxEnd[i]) ; + // verifico inizio e fine + int nOutstroke = 0 ; + int nStSta = 0 ; + if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptSta.x, ptSta.y, ptSta.z, vAngSta, true, nStSta) || nStSta != 0) + nOutstroke |= 2 ; + int nStEnd = 0 ; + if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptEnd.x, ptEnd.y, ptEnd.z, vAngEnd, true, nStEnd) || nStEnd != 0) + nOutstroke |= 1 ; + // verifico i punti intermedi const double PA_VERIF_LEN = 10 ; - Point3d ptStart( vAxVal[0], vAxVal[1], vAxVal[2]) ; - Point3d ptEnd( vAxIni[0], vAxIni[1], vAxIni[2]) ; - double dLen = DistXY( ptStart, ptEnd) ; - int nStep = int( dLen / PA_VERIF_LEN + 1) ; - bool bOutstroke = false ; - for ( int i = 0 ; i <= nStep ; ++ i) { + double dLen = DistXY( ptSta, ptEnd) ; + int nStep = int( dLen / PA_VERIF_LEN) + 1 ; + for ( int i = 1 ; i < nStep && nOutstroke == 0 ; ++ i) { double dCoeff = double( i) / nStep ; - Point3d ptCurr = Media( ptStart, ptEnd, dCoeff) ; + Point3d ptCurr = Media( ptSta, ptEnd, dCoeff) ; DBLVECTOR vAng ; - int nRotAxisNum = int( vAxVal.size()) - 3 ; - if ( bNewLink && nRotAxisNum > 0) { - vAng.resize( nRotAxisNum) ; - for ( int j = 0 ; j < nRotAxisNum ; ++ j) - vAng[j] = ( 1 - dCoeff) * vAxVal[j+3] + dCoeff * vAxIni[j+3] ; - } + for ( int j = 0 ; j < int( vAngSta.size()) ; ++ j) + vAng.emplace_back( ( 1 - dCoeff) * vAngSta[j] + dCoeff * vAngEnd[j]) ; int nStat = 0 ; - if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptCurr.x, ptCurr.y, ptCurr.z, vAng, true, nStat) || nStat != 0) { - bOutstroke = true ; - break ; - } + if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptCurr.x, ptCurr.y, ptCurr.z, vAng, true, nStat) || nStat != 0) + nOutstroke |= 4 ; } - if ( ! bOutstroke) + if ( nOutstroke == 0) return true ; + // assegno valori assi iniziali e finali, depurati di approcci/retrazioni aggiuntive (CLIMB e RISE) in area protetta + DBLVECTOR vNeatAxSta ; + if ( bNewLink && pPrevOp && ( nOutstroke & 2) != 0) + pPrevOp->GetFinalAxesValues( true, vNeatAxSta) ; + else + vNeatAxSta = vAxStart ; + DBLVECTOR vNeatAxEnd ; + if ( bNewLink && pNextOp && ( nOutstroke & 1) != 0) + pNextOp->GetInitialAxesValues( true, vNeatAxEnd) ; + else + vNeatAxEnd = vAxEnd ; + if ( int( vNeatAxSta.size()) != nAxisTot || int( vNeatAxEnd.size()) != nAxisTot) + return false ; + // chiamo funzione script OnSpecialRapidMove per avere posizioni di movimento int nLinkType = 0 + ( pPrevOp == nullptr ? 0 : 2) + ( pNextOp == nullptr ? 0 : 1) ; POSVECTOR vPosNew ; - bool bModif = false ; - int nErase = 0 ; - bool bOk = ( SpecialMoveRapid( vAxVal, vAxIni, nLinkType, vPosNew, bModif, nErase) && bModif) ; - // se tutto bene, eseguo cancellazioni e einserimenti come richiesto + bool bOk = SpecialMoveRapid( vNeatAxSta, vNeatAxEnd, nOutstroke, nLinkType, vPosNew) ; + // se tutto bene, eseguo cancellazioni e inserimenti come richiesto if ( bOk) { + bClimbDone = bNewLink ; // eventuali cancellazioni - if ( ( nErase & 2) != 0) { - if ( pPrevOp == nullptr) - return false ; + if ( bNewLink && ( nOutstroke & 2) != 0 && pPrevOp != nullptr) pPrevOp->RemoveRise() ; - } - if ( ( nErase & 1) != 0) { - if ( pNextOp == nullptr) - return false ; + if ( bNewLink && ( nOutstroke & 1) != 0 && pNextOp != nullptr) pNextOp->RemoveClimb() ; - bClimbDone = true ; - } // eventuali inserimenti for ( const auto& PosNew : vPosNew) { if ( PosNew.nSide == 2) { - if ( pPrevOp == nullptr) - return false ; - if ( ! pPrevOp->AddSpecialRise( PosNew.vAxis, true, GDB_ID_NULL, PosNew.nFlag, PosNew.nFlag2, PosNew.nMask)) + if ( pPrevOp == nullptr || + ! pPrevOp->AddSpecialRise( PosNew.vAxis, true, GDB_ID_NULL, + PosNew.nFlag, PosNew.nFlag2, PosNew.nMask, PosNew.sInfo)) return false ; } - else if ( PosNew.nSide == 1) { - if ( pNextOp == nullptr) - return false ; - if ( ! pNextOp->AddSpecialClimb( PosNew.vAxis, true, GDB_ID_NULL, PosNew.nFlag, PosNew.nFlag2, PosNew.nMask)) - return false ; - } - else + else if ( PosNew.nSide != 1) return false ; } + for ( int i = int( vPosNew.size()) - 1 ; i >= 0 ; --i) { + const auto& PosNew = vPosNew[i] ; + if ( PosNew.nSide == 1) { + if ( pNextOp == nullptr || + ! pNextOp->AddSpecialClimb( PosNew.vAxis, true, GDB_ID_NULL, + PosNew.nFlag, PosNew.nFlag2, PosNew.nMask, PosNew.sInfo)) + return false ; + } + } } // altrimenti eseguo inserimento con segnalazione di errore else { if ( pPrevOp != nullptr) { - if ( ! pPrevOp->AddSpecialRise( vAxVal, false)) + if ( ! pPrevOp->AddSpecialRise( vAxStart, false)) return false ; } - else if ( pNextOp != nullptr) { - if ( ! pNextOp->AddSpecialClimb( vAxIni, false)) + if ( pNextOp != nullptr) { + if ( ! pNextOp->AddSpecialClimb( vAxEnd, false)) return false ; } - else + if ( pPrevOp == nullptr && pNextOp == nullptr) return false ; } @@ -3379,8 +3401,10 @@ Operation::ToolChangeNeeded( const Operation& Op1, const Operation& Op2) const } //---------------------------------------------------------------------------- +// Inserisce sempre prima della prima entità del percorso bool -Operation::AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, int nFlag, int nFlag2, int nMask) +Operation::AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, + int nFlag, int nFlag2, int nMask, const string& sInfo) { if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; @@ -3399,12 +3423,8 @@ Operation::AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, in if ( nClPathId == GDB_ID_NULL) return false ; } - // cerco la prima entità del percorso che non sia CLIMB - int nEntId = m_pGeomDB->GetLastNameInGroup( nClPathId, MCH_CL_CLIMB) ; - if ( nEntId == GDB_ID_NULL) - nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; - else - nEntId = m_pGeomDB->GetNext( nEntId) ; + // cerco la prima entità del percorso + int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; if ( nEntId == GDB_ID_NULL) return false ; // ne recupero i dati Cam @@ -3417,7 +3437,7 @@ Operation::AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, in return false ; // assegno le coordinate del punto pGP->Set( pCamData->GetEndPoint()) ; - // inserisco l'oggetto nel DB geometrico prima della prima entità non CLIMB + // inserisco l'oggetto nel DB geometrico prima della prima entità int nId = m_pGeomDB->InsertGeoObj( GDB_ID_NULL, nEntId, GDB_BEFORE, Release( pGP)) ; if ( nId == GDB_ID_NULL) return false ; @@ -3436,6 +3456,19 @@ Operation::AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, in pCam->SetFlag2( nFlag2) ; // associo questo oggetto a quello geometrico m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + // inserzione eventuali info + if ( ! IsEmptyOrSpaces( sInfo)) { + STRVECTOR vsTokens ; + Tokenize( sInfo, ";", vsTokens) ; + for ( const auto& sToken : vsTokens) { + if ( ! IsEmptyOrSpaces( sToken)) { + string sKey, sVal ; + SplitFirst( sToken, "=", sKey, sVal) ; + if ( ! IsEmptyOrSpaces( sKey)) + m_pGeomDB->SetInfo( nId, sKey, sVal) ; + } + } + } return true ; } @@ -3634,8 +3667,10 @@ Operation::AddRise( DBLVECTOR& vAxVal, double dDelta, int nClPathId, int nToMinM } //---------------------------------------------------------------------------- +// Inserisce sempre dopo l'ultima entità del percorso bool -Operation::AddSpecialRise( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, int nFlag, int nFlag2, int nMask) +Operation::AddSpecialRise( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, + int nFlag, int nFlag2, int nMask, const string& sInfo) { if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; @@ -3687,6 +3722,20 @@ Operation::AddSpecialRise( const DBLVECTOR& vAxVal, bool bOk, int nClPathId, int pCam->SetFlag2( nFlag2) ; // associo questo oggetto a quello geometrico m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + // inserzione eventuali info + if ( ! IsEmptyOrSpaces( sInfo)) { + STRVECTOR vsTokens ; + Tokenize( sInfo, ";", vsTokens) ; + for ( const auto& sToken : vsTokens) { + if ( ! IsEmptyOrSpaces( sToken)) { + string sKey, sVal ; + SplitFirst( sToken, "=", sKey, sVal) ; + if ( ! IsEmptyOrSpaces( sKey)) + m_pGeomDB->SetInfo( nId, sKey, sVal) ; + } + string sKey, sVal ; + } + } return true ; } @@ -4717,8 +4766,8 @@ Operation::SpecialMoveZup( DBLVECTOR& vAx, Vector3d& vtTool, int& nFlag, int& nF //---------------------------------------------------------------------------- bool -Operation::SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, int nLinkType, - POSVECTOR& vNewPos, bool& bModif, int& nErase) +Operation::SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, int nOutstroke, int nLinkType, + POSVECTOR& vNewPos) { // recupero la macchina corrente Machine* pMch = ( m_pMchMgr != nullptr ? m_pMchMgr->GetCurrMachine() : nullptr) ; @@ -4726,21 +4775,17 @@ Operation::SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, return false ; // costanti static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo - static const string EVAR_LINKTYPE = ".LINKTYPE" ; // IN (int) codice tipo collegamento (1=FinePrec, 2=InizioSucc, 3=Entrambi)) - static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok) - static const string EVAR_MODIF = ".MODIF" ; // OUT (bool) flag di modifica effettuata - static const string EVAR_ERASE = ".ERASE" ; // OUT (int) codice di rimozione movimenti RISE/CLIMB + static const string EVAR_OUTSTROKE = ".OUTSTROKE" ; // IN (int) codice extracorsa posizioni (1=Inizio, 2=Fine, 3=FinePrec+InizioSucc)) + static const string EVAR_LINKTYPE = ".LINKTYPE" ; // IN (int) codice tipo collegamento (1=Inizio, 2=Fine, 3=FinePrec+InizioSucc)) + static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok) static const string EVAR_POSTOT = ".POSTOT" ; // OUT (int) numero di nuove posizioni static const string EVAR_POS = ".POS" ; // OUT (table) vettore di posizioni - static const string EVAR_SIDE = ".SIDE" ; // OUT (int) codice inserimento movimento (-1=prec, 1=curr) + static const string EVAR_SIDE = ".SIDE" ; // OUT (int) codice inserimento movimento (1=Inizio, 2=Fine) static const string ON_SPECIAL_MOVERAPID = "OnSpecialMoveRapid" ; // se la funzione non è definita, esco - if ( ! pMch->LuaExistsFunction( ON_SPECIAL_MOVERAPID)) { - bModif = false ; - nErase = 0 ; - return true ; - } + if ( ! pMch->LuaExistsFunction( ON_SPECIAL_MOVERAPID)) + return false ; // eseguo bool bOk = true ; @@ -4753,6 +4798,7 @@ Operation::SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + GVAR_TCPOS, GetToolTcPos()) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + GVAR_MCHID, GetOwner()) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + GVAR_PHASE, m_nPhase) ; + bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_OUTSTROKE, ( nOutstroke % 4)) ; bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_LINKTYPE, nLinkType) ; // valore degli assi bool bIsRobot = m_pMchMgr->GetCurrIsRobot() ; @@ -4765,10 +4811,7 @@ Operation::SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, bOk = bOk && pMch->LuaCallFunction( ON_SPECIAL_MOVERAPID, false) ; // recupero valori parametri obbligatori bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_ERROR, nErr) ; - bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_MODIF, bModif) ; // recupero i parametri facoltativi - if ( ! pMch->LuaGetGlobVar( EMC_VAR + EVAR_ERASE, nErase)) - nErase = 0 ; int nPosTot ; if ( ! pMch->LuaGetGlobVar( EMC_VAR + EVAR_POSTOT, nPosTot)) nPosTot = -1 ; @@ -4805,6 +4848,8 @@ Operation::SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, CurrPos.nFlag = 0 ; if ( ! pMch->LuaGetGlobVar( sRec + GVAR_FLAG2, CurrPos.nFlag2)) CurrPos.nFlag2 = 0 ; + if ( ! pMch->LuaGetGlobVar( sRec + GVAR_INFO, CurrPos.sInfo)) + CurrPos.sInfo = "" ; vNewPos.emplace_back( CurrPos) ; } } diff --git a/Operation.h b/Operation.h index e5fbaa5..faa6fee 100644 --- a/Operation.h +++ b/Operation.h @@ -116,11 +116,12 @@ class Operation : public IUserObj protected : struct Position { - int nSide ; - DBLVECTOR vAxis ; - int nFlag ; - int nFlag2 ; - int nMask ; + int nSide ; + DBLVECTOR vAxis ; + int nFlag ; + int nFlag2 ; + int nMask ; + std::string sInfo ; Position() : nSide( 0), nFlag( 0), nFlag2( 0), nMask( -1) {} } ; typedef std::vector POSVECTOR ; @@ -209,15 +210,15 @@ class Operation : public IUserObj bool bMaxDeltaR2OnFirst, bool bRotContOnNext, double dAngDeltaMinForHome, const DBLVECTOR& vAxRotHome, DBLVECTOR& vAxRotPrec) ; bool AdjustStartEndMovements( bool bVerifyPreviousLink = true) ; - bool ManageProtectedAreas( const DBLVECTOR& vAxVal, const DBLVECTOR& vAxIni, Operation* pPrevOp, Operation* pNextOp, bool& bClimbDone) ; + bool ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, Operation* pPrevOp, Operation* pNextOp, bool& bClimbDone) ; bool AdjustOneStartEndMovement( int nClPathId, int nPrevClPathId, Operation* pPrevOp, const DBLVECTOR& vAxPrev, bool bMaxZ) ; bool ToolChangeNeeded( const Operation& Op1, const Operation& Op2) const ; bool AddSpecialClimb( const DBLVECTOR& vAxVal, bool bOk = true, int nClPathId = GDB_ID_NULL, - int nFlag = 0, int nFlag2 = 0, int nMask = -1) ; + int nFlag = 0, int nFlag2 = 0, int nMask = -1, const std::string& sInfo = "") ; bool RemoveClimb( int nClPathId = GDB_ID_NULL) ; bool AddRise( DBLVECTOR& vAxVal, double dDelta = NAN, int nClPathId = GDB_ID_NULL, int nToMinMaxZ = 0) ; bool AddSpecialRise( const DBLVECTOR& vAxVal, bool bOk = true, int nClPathId = GDB_ID_NULL, - int nFlag = 0, int nFlag2 = 0, int nMask = -1) ; + int nFlag = 0, int nFlag2 = 0, int nMask = -1, const std::string& sInfo = "") ; bool RemoveRise( int nClPathId = GDB_ID_NULL) ; bool AddHome( void) ; bool RemoveClimbRiseHome( void) ; @@ -239,8 +240,8 @@ class Operation : public IUserObj bool TestCollisionAvoid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd) const ; int SpecialTestCollisionAvoid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd) const ; bool SpecialMoveZup( DBLVECTOR& vAx, Vector3d& vtTool, int& nFlag, int& nFlag2, bool& bModif) ; - bool SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, int nLinkType, - POSVECTOR& vNewPos, bool& bModif, int& nErase) ; + bool SpecialMoveRapid( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, int nOutstroke, int nLinkType, + POSVECTOR& vNewPos) ; bool GetAggrBottomData( const std::string& sHead, AggrBottom& agbData) const ; bool IsAggrBottom( const std::string& sHead) const ; From 265bce38faf838a05f85c8a23eefceed43e76fa8 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 23 Dec 2024 19:13:55 +0100 Subject: [PATCH 2/2] EgtMachKernel : - riportate correzioni a SurfRoughing di RiccardoE - ulterirori modifiche per NewLinkMgr. --- Machine.h | 2 +- MachineCalc.cpp | 8 +- Operation.cpp | 10 ++- SurfRoughing.cpp | 191 +++++++++++++++++++++++------------------------ SurfRoughing.h | 2 +- 5 files changed, 107 insertions(+), 106 deletions(-) diff --git a/Machine.h b/Machine.h index b33655a..dccf2c2 100644 --- a/Machine.h +++ b/Machine.h @@ -178,7 +178,7 @@ class Machine bool VerifyAngleOutstroke( int nInd, double dAng) const ; bool VerifyOutstroke( double dX, double dY, double dZ, const DBLVECTOR& vAng, bool bClear, int& nStat) const ; bool ExistProtectedAreas( void) const ; - bool VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& vAng, bool bIsLink, int& nStat) ; + bool VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& vAng, int nLinkType, int& nStat) ; bool VerifyOutstroke( const std::string& sAxName, double dVal) const ; std::string GetOutstrokeInfo( bool bMM = true) const ; void ResetOutstrokeInfo( void) const diff --git a/MachineCalc.cpp b/MachineCalc.cpp index b2682a6..8a79d89 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -48,7 +48,7 @@ static const string EVAR_R1 = ".R1" ; // (num) valore del pri static const string EVAR_R2 = ".R2" ; // (num) valore del secondo asse rotante static const string EVAR_R3 = ".R3" ; // (num) valore del terzo asse rotante static const string EVAR_R4 = ".R4" ; // (num) valore del quarto asse rotante -static const string EVAR_ISLINK = ".ISLINK" ; // (bool) flag per indicare controllo posizioni in un link +static const string EVAR_LINKTYPE = ".LINKTYPE" ; // (int) tipo collegamento (0=No, 1=Inizio, 2=Fine, 3=Link)) static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok) static const string EVAR_STAT = ".STAT" ; // OUT (int) codice di stato ( 0 = ok) static const string EVAR_AUXINFO = ".AUXINFO" ; // OUT (string) stringa con info ausiliarie @@ -1728,7 +1728,7 @@ Machine::VerifyOutstroke( double dX, double dY, double dZ, const DBLVECTOR& vAng } // verifica delle aree protette if ( nStat == 0) - return const_cast( this)->VerifyProtectedAreas( dX, dY, dZ, vAng, false, nStat) ; + return const_cast( this)->VerifyProtectedAreas( dX, dY, dZ, vAng, 0, nStat) ; return true ; } @@ -1742,7 +1742,7 @@ Machine::VerifyOutstroke( double dX, double dY, double dZ, const DBLVECTOR& vAng //---------------------------------------------------------------------------- bool -Machine::VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& vAng, bool bIsLink, int& nStat) +Machine::VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& vAng, int nLinkType, int& nStat) { // se non esiste funzione gestione aree protette, non devo fare alcunchè if ( ! LuaExistsFunction( ON_VERIFY_PROTECTEDAREAS)) @@ -1770,7 +1770,7 @@ Machine::VerifyProtectedAreas( double dX, double dY, double dZ, const DBLVECTOR& bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_R3, vAng[2]) ; if ( vAng.size() >= 4) bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_R4, vAng[3]) ; - bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_ISLINK, bIsLink) ; + bOk = bOk && LuaSetGlobVar( EMC_VAR + EVAR_LINKTYPE, nLinkType) ; // chiamo funzione bOk = bOk && LuaCallFunction( ON_VERIFY_PROTECTEDAREAS) ; // recupero il risultato diff --git a/Operation.cpp b/Operation.cpp index caf0f60..6e7f7b5 100644 --- a/Operation.cpp +++ b/Operation.cpp @@ -2959,6 +2959,9 @@ Operation::ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAx // recupero flag nuova gestione collegamenti tra lavorazioni bool bNewLink = m_pMchMgr->GetCurrMachine()->GetNewLinkMgr() ; + // codifica tipo di collegamento + int nLinkType = 0 + ( pPrevOp == nullptr ? 0 : 2) + ( pNextOp == nullptr ? 0 : 1) ; + // Verifico se il collegamento le attraversa Point3d ptSta( vAxStart[0], vAxStart[1], vAxStart[2]) ; Point3d ptEnd( vAxEnd[0], vAxEnd[1], vAxEnd[2]) ; @@ -2971,10 +2974,10 @@ Operation::ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAx // verifico inizio e fine int nOutstroke = 0 ; int nStSta = 0 ; - if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptSta.x, ptSta.y, ptSta.z, vAngSta, true, nStSta) || nStSta != 0) + if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptSta.x, ptSta.y, ptSta.z, vAngSta, nLinkType, nStSta) || nStSta != 0) nOutstroke |= 2 ; int nStEnd = 0 ; - if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptEnd.x, ptEnd.y, ptEnd.z, vAngEnd, true, nStEnd) || nStEnd != 0) + if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptEnd.x, ptEnd.y, ptEnd.z, vAngEnd, nLinkType, nStEnd) || nStEnd != 0) nOutstroke |= 1 ; // verifico i punti intermedi const double PA_VERIF_LEN = 10 ; @@ -2987,7 +2990,7 @@ Operation::ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAx for ( int j = 0 ; j < int( vAngSta.size()) ; ++ j) vAng.emplace_back( ( 1 - dCoeff) * vAngSta[j] + dCoeff * vAngEnd[j]) ; int nStat = 0 ; - if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptCurr.x, ptCurr.y, ptCurr.z, vAng, true, nStat) || nStat != 0) + if ( ! m_pMchMgr->GetCurrMachine()->VerifyProtectedAreas( ptCurr.x, ptCurr.y, ptCurr.z, vAng, nLinkType, nStat) || nStat != 0) nOutstroke |= 4 ; } if ( nOutstroke == 0) @@ -3008,7 +3011,6 @@ Operation::ManageProtectedAreas( const DBLVECTOR& vAxStart, const DBLVECTOR& vAx return false ; // chiamo funzione script OnSpecialRapidMove per avere posizioni di movimento - int nLinkType = 0 + ( pPrevOp == nullptr ? 0 : 2) + ( pNextOp == nullptr ? 0 : 1) ; POSVECTOR vPosNew ; bool bOk = SpecialMoveRapid( vNeatAxSta, vNeatAxEnd, nOutstroke, nLinkType, vPosNew) ; // se tutto bene, eseguo cancellazioni e inserimenti come richiesto diff --git a/SurfRoughing.cpp b/SurfRoughing.cpp index 4cbb994..0a24b59 100644 --- a/SurfRoughing.cpp +++ b/SurfRoughing.cpp @@ -78,7 +78,8 @@ using namespace std ; // 3029 = "Error in SurfRoughing : Error in Classifying border" // 3029 = "Error in SurfRoughing : Simplify Chunks for SubSteps failed" // 3030 = "Error in SurfRoughing : Conformal ZigZag not valid at step (xx)" -// 3131 = "Error in SurfRoughing : LeadIn with Mill NoTip in material" +// 3031 = "Error in SurfRoughing : LeadIn with Mill NoTip in material" +// 3032 = "Error in SurfRoughing : Curves with different extrusion" // 3051 = "Warning in SurfRoughing : Skipped entity (xx)" // 3052 = "Warning in SurfRoughing : No machinable path" // 3053 = "Warning in SurfRoughing : Tool name changed (xx)" @@ -1053,6 +1054,7 @@ SurfRoughing::Chain( int nGrpDestId) } } // preparo i dati per il concatenamento + Vector3d vtExtr = Z_AX ; bool bFirst = true ; Point3d ptNear = ORIG ; double dToler = 10 * EPS_SMALL ; @@ -1073,9 +1075,18 @@ SurfRoughing::Chain( int nGrpDestId) return false ; // se prima curva, assegno inizio della ricerca if ( bFirst) { + pCrv->GetExtrusion( vtExtr) ; ptNear = ptStart + 10 * EPS_SMALL * vtStart ; bFirst = false ; } + // altrimenti + else { + Vector3d vtTmpExtr ; pCrv->GetExtrusion( vtTmpExtr) ; + if ( ! AreSameVectorApprox( vtTmpExtr, vtExtr)) { + m_pMchMgr->SetLastError( 3032, "Error in SurfRoughing : Curves with different extrusion") ; + return false ; + } + } } // recupero i percorsi concatenati e definisco la regione piana di sgrossatura SurfFlatRegionByContours SfrByC ; @@ -1086,7 +1097,6 @@ SurfRoughing::Chain( int nGrpDestId) if ( IsNull( pCrvCompo)) return false ; // estrusione e spessore - Vector3d vtExtr = Z_AX ; double dThick = 0 ; // vettore Id originali SELVECTOR vId2 ; @@ -1102,13 +1112,9 @@ SurfRoughing::Chain( int nGrpDestId) 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 ; - } + 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 ; @@ -1134,7 +1140,6 @@ SurfRoughing::Chain( int nGrpDestId) m_pMchMgr->SetLastError( 3006, "Error in SurfRoughing : Tool Dir not perpendicular to Flat Area") ; return false ; } - pFlatCrv->GetExtrusion( vtExtr) ; pCrvCompo->Clear() ; pCrvCompo->AddCurve( Release( pFlatCrv)) ; // salvo vettore estrusione @@ -1154,6 +1159,9 @@ SurfRoughing::Chain( int nGrpDestId) int nGroupName = -1 ; PtrOwner pSfrCurr( SfrByC.GetSurf()) ; while ( ! IsNull( pSfrCurr) && pSfrCurr->IsValid()) { + // la normale del Chunk deve essere coerente con l'estrusione ricavata + if ( AreOppositeVectorApprox( pSfrCurr->GetNormVersor(), vtExtr)) + pSfrCurr->Invert() ; // per ogni Chunk for ( int nC = 0 ; nC < pSfrCurr->GetChunkCount() ; ++ nC) { // creo nuovo gruppo @@ -1169,7 +1177,7 @@ SurfRoughing::Chain( int nGrpDestId) int nNewId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, ::CloneSurfFlatRegion( pSfrChunk)) ; if ( nNewId == GDB_ID_NULL) return false ; - // salvo eventuali lati aperti per il Chunk corrente + // scorro i loop della regione for ( int nL = 0 ; nL < pSfrChunk->GetLoopCount( 0) ; ++ nL) { // recupero il Loop PtrOwner pCrvLoop( ConvertCurveToComposite( pSfrChunk->GetLoop( 0, nL))) ; @@ -1179,8 +1187,6 @@ SurfRoughing::Chain( int nGrpDestId) if ( nL == 0) { double dThick = pCrvLoop->GetTempParam( 1) ; m_pGeomDB->SetInfo( nNewId, KEY_THICK, dThick) ; - Vector3d vtExtr ; - pCrvLoop->GetExtrusion( vtExtr) ; m_pGeomDB->SetInfo( nNewId, KEY_EXTR, vtExtr) ; } } @@ -1225,19 +1231,29 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) int nCopyId = m_pGeomDB->CopyGlob( nSfrId, GDB_ID_NULL, nTempId) ; if ( nCopyId == GDB_ID_NULL) return false ; - PtrOwner pSfrGDB( CloneSurfFlatRegion( m_pGeomDB->GetGeoObj( nCopyId))) ; - if ( IsNull( pSfrGDB) || ! pSfrGDB->IsValid()) + PtrOwner pSfrSgro( CloneSurfFlatRegion( m_pGeomDB->GetGeoObj( nCopyId))) ; + if ( IsNull( pSfrSgro) || ! pSfrSgro->IsValid()) return false ; - // recupero estrusione e spessore + // recupero estrusione Vector3d vtExtr = Z_AX ; if ( m_pGeomDB->ExistsInfo( nSfrId, KEY_EXTR)) m_pGeomDB->GetInfo( nSfrId, KEY_EXTR, vtExtr) ; + // controllo che l'estrusione sia coerente con la normale della superficie + if ( AreSameOrOppositeVectorApprox( pSfrSgro->GetNormVersor(), vtExtr)) { + if ( AreOppositeVectorApprox( pSfrSgro->GetNormVersor(), vtExtr)) + pSfrSgro->Invert() ; + } + else { + m_pMchMgr->SetLastError( 3006, "Error in SurfRoughing : Tool Dir not perpendicular to Flat Area") ; + return false ; + } + + + // recupero lo spessore e valuto l'espressione dell'affondamento double dThick = 0. ; if ( m_pGeomDB->ExistsInfo( nSfrId, KEY_THICK)) m_pGeomDB->GetInfo( nSfrId, KEY_THICK, dThick) ; - - // valuto l'espressione dell'affondamento ExeLuaSetGlobNumVar( "TH", abs( dThick)) ; double dDepth ; string sMyDepth = m_Params.m_sDepth ; @@ -1249,35 +1265,6 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) if ( dThick > 0) dDepth -= dThick ; - // recupero il Loop esterno della regione da svuotatare - PtrOwner pCompo( ConvertCurveToComposite( pSfrGDB->GetLoop( 0, 0))) ; - if ( IsNull( pCompo) || ! pCompo->IsValid()) - return false ; - - // verifico sia piana e sistemo senso antiorario visto dalla direzione di estrusione - Plane3d plPlane ; double dArea ; - if ( ! pCompo->GetArea( plPlane, dArea)) { - m_pMchMgr->SetLastError( 3005, "Error in SurfRoughing : Contour Not Flat") ; - return false ; - } - if ( abs( plPlane.GetVersN() * vtExtr) < cos( 10 * EPS_ANG_SMALL)) { - m_pMchMgr->SetLastError( 3006, "Error in SurfRoughing : Tool Dir not perpendicular to Flat Area") ; - return false ; - } - if ( plPlane.GetVersN() * vtExtr * dArea < 0) - pCompo->Invert() ; - if ( plPlane.GetVersN() * vtExtr < 0) - plPlane.Invert() ; - - // creo un frame centrato sulla curva - Frame3d fr_pCompo ; - if ( ! fr_pCompo.Set( plPlane.GetPoint(), plPlane.GetVersN())) - return false ; - - // unisco le parti allineate - if ( ! pCompo->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL, true)) - 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()) { @@ -1296,6 +1283,12 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) bool bPlaneZDetection = false ; m_bDetectPlaneZ = ( FromString( ExtractInfo( m_Params.m_sUserNotes, "PlaneZ="), bPlaneZDetection) && bPlaneZDetection) ; + // creo un frame centrato sulla superficie + Frame3d frSfr ; + Point3d ptCenter ; pSfrSgro->GetCentroid( ptCenter) ; + if ( ! frSfr.Set( ptCenter, vtTool)) + return false ; + // non prevista gestione anteprima di lavorazione // se richiesta lavorazione @@ -1328,16 +1321,16 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) // inizializzo la classe di intersezione tra grezzo e piani paralleli ( quelli di lavoro) // traslo leggermente il grezzo per gestire il primo e l'ultimo Step pStmRaw->Translate( - vtTool * 5 * EPS_SMALL) ; - IntersParPlanesSurfTm IPPStm( fr_pCompo, *pStmRaw) ; + IntersParPlanesSurfTm IPPStm( frSfr, *pStmRaw) ; // costruisco una superficie di estrusione della curva (devo determinare parte della regione limite) Vector3d vtLimitExtr = - vtTool * 1.5 * max( b3Raw.GetDimX(), max( b3Raw.GetDimY(), b3Raw.GetDimZ())) ; - PtrOwner pStmLimit( GetStmOutSideSfr( pSfrGDB, pStmRaw, vtLimitExtr)) ; + PtrOwner pStmLimit( GetStmOutSideSfr( pSfrSgro, pStmRaw, vtLimitExtr)) ; if ( IsNull( pStmLimit)) return false ; // inizializzo la classe di intersezione tra la superficie trimesh limite e piani paralleli ( quelli di lavoro) - IntersParPlanesSurfTm IPPStm1( fr_pCompo, *pStmLimit) ; + IntersParPlanesSurfTm IPPStm1( frSfr, *pStmLimit) ; // inizializzo la classe di calcolo delle silhouette nei piani come sopra SURFLOCALVECTOR vSurfL ; vSurfL.reserve( vSurfId.size()) ; @@ -1350,11 +1343,9 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) if ( pStm != nullptr && pStm->IsValid() && pStm->GetTriangleCount() > 0) vpStm.emplace_back( pStm) ; } - Frame3d frPlanes ; - frPlanes.Set( plPlane.GetPoint(), vtTool) ; const double SILH_TOL = 1.0 ; PtrOwner pCavParSilh( CreateCAvParSilhouettesSurfTm()) ; - if ( IsNull( pCavParSilh) || ! pCavParSilh->SetData( vpStm, frPlanes, SILH_TOL)) + if ( IsNull( pCavParSilh) || ! pCavParSilh->SetData( vpStm, frSfr, SILH_TOL)) return false ; // vettore Id salvati nel gruppo Temp @@ -1379,7 +1370,7 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) // se richiesto PlaneZ detection, aggiungo altri step intermedi ( planeZSteps ) PLANEZFACEVECTOR vPlaneZ ; if ( m_bDetectPlaneZ) { - if ( ! DetectPlaneZ( vpStm, fr_pCompo, vtTool, vPlaneZ, - GetOffsL(), dDepth - GetOffsL())) + if ( ! DetectPlaneZ( vpStm, frSfr, vtTool, vPlaneZ, - GetOffsL(), dDepth - GetOffsL())) return false ; #if ENABLE_DEBUG_ZPLANE for ( int nP = 0 ; nP < int( vPlaneZ.size()) ; ++ nP) { @@ -1470,18 +1461,11 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) /* ******************** Regione estesa di lavoro ******************** */ // regione di lavoro allo step corrente ( definita dalla curva di lavoro ) - PtrOwner pSfr( CreateSurfFlatRegion()) ; - if ( IsNull( pSfr) || ! pSfr->AddExtLoop( *pCompo)) { + PtrOwner pSfr( CloneSurfFlatRegion( pSfrSgro)) ; + if ( IsNull( pSfr) || ! pSfr->IsValid()) { m_pMchMgr->SetLastError( 3024, "Error in SurfRoughing : region not computable") ; return false ; } - for ( int nL = 1 ; nL < pSfrGDB->GetLoopCount( 0) ; ++ nL) { - // recupero l'isola - PtrOwner pCrvIsl( pSfrGDB->GetLoop( 0, nL)) ; - if ( IsNull( pCrvIsl) || ! pCrvIsl->IsValid() || - ! pSfr->AddIntLoop( *pCrvIsl)) - return false ; - } pSfr->Translate( ( it->dDepth + GetOffsL()) * vtTool) ; /* ******************** Regione adattata al grezzo ******************** */ @@ -1548,6 +1532,7 @@ SurfRoughing::ProcessPath( int nPathId, int nPvId, int nClId) ( vStepInfo[nIndRef].pSfrRemoved == nullptr || ! vStepInfo[nIndRef].pSfrRemoved->IsValid())) { nIndRef = vStepInfo[nIndRef].nIndRef ; } + // recupero la superficie progressiva dello step di riferimento PtrOwner pSfrRef( CloneSurfFlatRegion( vStepInfo[nIndRef].pSfrRemoved)) ; if ( ! IsNull( pSfrRef) && pSfrRef->IsValid()) { // se valida @@ -1850,41 +1835,51 @@ SurfRoughing::GetStmOutSideSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pStmRaw == nullptr || ! pStmRaw->IsValid()) return nullptr ; + // creo una copia della pSfr mediante un piccolo offset correttivo (per problemi con archi) + PtrOwner pSfrOffs( pSfr->CreateOffsetSurf( 100 * EPS_SMALL, ICurve::OFF_FILLET)) ; + if ( IsNull( pSfrOffs) || ! pSfrOffs->IsValid()) + return nullptr ; + // definisco il vettore delle curve dei i bordi della regione CICURVEPVECTOR vpCrv ; + bool bOk = true ; // per ogni Chunk - for ( int nC = 0 ; nC < pSfr->GetChunkCount() ; ++ nC) { + for ( int nC = 0 ; nC < pSfrOffs->GetChunkCount() && bOk ; ++ nC) { // per ogni Loop - for ( int nL = 0 ; nL < pSfr->GetLoopCount( nC) ; ++ nL) { + for ( int nL = 0 ; nL < pSfrOffs->GetLoopCount( nC) && bOk ; ++ nL) { // recupero il Loop come curva composita - PtrOwner pCompoLoop( ConvertCurveToComposite( pSfr->GetLoop( nC, nL))) ; - if ( IsNull( pCompoLoop) || ! pCompoLoop->IsValid()) - return nullptr ; - // recupero la PolyLine associata a tale Loop e la inserisco nel vettore - vpCrv.emplace_back( Release( pCompoLoop)) ; + PtrOwner pLoop( pSfrOffs->GetLoop( nC, nL)) ; + bOk = ( ! IsNull( pLoop) && pLoop->IsValid()) ; + if ( bOk) + vpCrv.emplace_back( Release( pLoop)) ; } } - // definisco la superficie di estrusione - PtrOwner pStmExtr( GetSurfTriMeshByRegionExtrusion( vpCrv, vtExtr)) ; - if ( IsNull( pStmExtr) || ! pStmExtr->IsValid()) - return nullptr ; - - // la superficie deeve definire un volume - double dVol = 0. ; pStmExtr->GetVolume( dVol) ; - if ( dVol < EPS_ZERO) - pStmExtr->Invert() ; - - // sottraggo al grezzo la regione di estrusione + // definisco la TrimMesh limite (inizialmente vuota) PtrOwner pStmLimit( CloneSurfTriMesh( pStmRaw)) ; - bool bOk = ! IsNull( pStmLimit) ; - bOk = bOk && pStmLimit->IsValid() ; - bOk = bOk && pStmLimit->Subtract( *pStmExtr) ; - if ( ! bOk) - return nullptr ; + bOk = bOk && ( ! IsNull( pStmLimit) && pStmLimit->IsValid()) ; - return Release( pStmLimit) ; + // definisco la superficie di estrusione + if ( bOk) { + PtrOwner pStmExtr( GetSurfTriMeshByRegionExtrusion( vpCrv, vtExtr)) ; + bOk = ( ! IsNull( pStmExtr) && pStmExtr->IsValid()) ; + // la superficie deve definire un volume + double dVol = 0. ; + bOk = bOk && pStmExtr->GetVolume( dVol) ; + if ( dVol < EPS_ZERO) + bOk = bOk && pStmExtr->Invert() ; + // sottraggo al grezzo la regione di estrusione + bOk = bOk && pStmLimit->Subtract( *pStmExtr) ; + } + + // rimozione del vettore di curve costanti + for ( int i = 0 ; i < int( vpCrv.size()) ; ++ i) { + delete( vpCrv[i]) ; + vpCrv[i] = nullptr ; + } + + return ( bOk ? Release( pStmLimit) : nullptr) ; } //---------------------------------------------------------------------------- @@ -2166,7 +2161,7 @@ SurfRoughing::CalcPaths( const INTINTVECTOR& vPocket, STEPINFOSRVECTOR& vStepInf // se utensile che non lavora di testa e ingresso non fuori dal pezzo, errore if ( m_TParams.m_nType == TT_MILL_NOTIP && ! vStepInfo[nInd].vPaths[i].bOutStart) { if ( ! LeadInRawIsOk()) { - m_pMchMgr->SetLastError( 2431, "Error in SurfRoughing : LeadIn with Mill NoTip in material") ; + m_pMchMgr->SetLastError( 3031, "Error in SurfRoughing : LeadIn with Mill NoTip in material") ; return false ; } } @@ -2248,11 +2243,13 @@ SurfRoughing::AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, do // riferimento alle informazioni relative allo step i-esimo StepInfoSR& currStep = vStepInfo[i] ; + // scorro i percorsi calcolati per il piano di pocketing i-esimo for ( int j = 0 ; j < int( currStep.vPaths.size()) ; ++ j) { // riferimento alle informazioni relative al percorso j-esimo del piano di pocketing i-esimo PathInfoSR& currPath = currStep.vPaths[j] ; + // ciclo sulle curve elementari del percorso attuale int nMaxInd = currPath.pCrvPath->GetCurveCount() - 1 ; for ( int k = 0 ; k <= nMaxInd ; ++ k) { @@ -2303,7 +2300,7 @@ SurfRoughing::AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, do Point3d ptMyPos ; GetCurrPos( ptMyPos) ; double dMyElev = ( bAbsFirst ? dCurrElev : ( ptMyPos - ptP1) * vtTool) ; double dMyAppr = ( bAbsFirst ? dAppr : 0.) ; - if ( ! AddApproach( ptP1, vtTool, dMySafeZ, dMyElev, dMyAppr, currPath.bOutStart)) { + if ( ! AddApproach( ptP1, vtTool, dMySafeZ, dMyElev, dMyAppr, currPath.bOutStart, bAbsFirst)) { m_pMchMgr->SetLastError( 3011, "Error in SurfRoughing : Approach not computable") ; return false ; } @@ -2438,9 +2435,10 @@ SurfRoughing::AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, do //---------------------------------------------------------------------------- bool SurfRoughing::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, - double dAppr, bool bOutStart) + double dAppr, bool bOutStart, bool bAbsFirst) { - SetFlag( 1) ; + if ( bAbsFirst) + SetFlag( 1) ; // se sopra attacco c'è spazio per sicurezza o approccio double dSafeDist = dSafeZ ; if ( dElev + max( dSafeDist, dAppr) > 10 * EPS_SMALL) { @@ -2448,14 +2446,14 @@ SurfRoughing::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dS if ( dSafeDist < dAppr + 10 * EPS_SMALL) { // 1 -> punto sopra inizio Point3d ptP1 = ptP + vtTool * ( dElev + dAppr) ; - if ( AddRapidStart( ptP1) == GDB_ID_NULL) + if ( bAbsFirst && AddRapidStart( ptP1) == GDB_ID_NULL) return false ; } else { // 1a -> punto sopra inizio Point3d ptP1b = ptP + vtTool * ( dElev + dAppr) ; Point3d ptP1a = ptP1b + vtTool * ( dSafeDist - dAppr) ; - if ( ( AddRapidStart( ptP1a) == GDB_ID_NULL)) + if ( bAbsFirst && AddRapidStart( ptP1a) == GDB_ID_NULL) return false ; // 1b -> punto appena sopra inizio if ( ( dElev + dAppr) > EPS_SMALL) { @@ -2474,7 +2472,7 @@ SurfRoughing::AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dS else { // affondo diretto al punto iniziale SetFlag( 0) ; - if ( AddRapidStart( ptP) == GDB_ID_NULL) + if ( bAbsFirst && AddRapidStart( ptP) == GDB_ID_NULL) return false ; } return true ; @@ -3005,6 +3003,7 @@ SurfRoughing::CloseOpenEdgesUnderTolerance( ISurfFlatRegion* pSfr, double dToler PtrOwner pCrvNewLoop( CreateCurveComposite()) ; if ( IsNull( pCrvNewLoop)) return false ; + for ( int i = 0 ; i < int( vpCrvs.size()) ; ++ i) { // se tratto aperto e non coincidente con tutta la curva if ( vpCrvs[i]->GetTempProp( 0) == TEMP_PROP_OPEN_EDGE && int( vpCrvs.size()) != 1) { @@ -3035,7 +3034,7 @@ SurfRoughing::CloseOpenEdgesUnderTolerance( ISurfFlatRegion* pSfr, double dToler // se il chunk è stato creato correttamente, allora lo aggiungo if ( bOk) { if ( pSfrRegular->IsValid() && pSfrRegular->GetChunkCount() > 0) { - if ( ! pSfrRegular->Add( *Release( pSfrTest))) + if ( ! pSfrRegular->Add( *pSfrTest)) return false ; } else { @@ -3049,7 +3048,7 @@ SurfRoughing::CloseOpenEdgesUnderTolerance( ISurfFlatRegion* pSfr, double dToler if ( IsNull( pSfrChunkCL) || ! pSfrChunkCL->IsValid()) return false ; if ( pSfrRegular->IsValid() && pSfrRegular->GetChunkCount() > 0) { - if ( ! pSfrRegular->Add( *Release( pSfrTest))) + if ( ! pSfrRegular->Add( *pSfrTest)) return false ; } else { diff --git a/SurfRoughing.h b/SurfRoughing.h index b51efcf..d862403 100644 --- a/SurfRoughing.h +++ b/SurfRoughing.h @@ -111,7 +111,7 @@ class SurfRoughing : public Machining double dMinDepth, double dMaxDepth) const ; bool CalcPaths( const INTINTVECTOR& vPocket, STEPINFOSRVECTOR& vStepInfo) const ; bool AddPocket( const INTINTVECTOR& vPocket, const Vector3d& vtTool, double dElev, double dStep, double dSubStep, bool bSplitArcs) ; - bool AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr, bool bOutStart) ; + bool AddApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr, bool bOutStart, bool bAbsFirst) ; bool AddLinkApproach( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr, bool bOutMove) ; bool AddLinkRetract( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) ; bool AddRetract( const Point3d& ptP, const Vector3d& vtTool, double dSafeZ, double dElev, double dAppr) ;