From 72b59d4f8363f73ceacf51c70275a85f55d1e299 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Fri, 7 Jul 2017 15:56:36 +0000 Subject: [PATCH] EgtMachKernel 1.8g1 : - gestione rototraslazione grezzi sempre come R-T. --- Disposition.cpp | 197 +++++++++++++++++++++++++++++++++----------- Disposition.h | 7 +- EgtMachKernel.rc | Bin 11774 -> 11774 bytes MachMgrRawParts.cpp | 6 +- 4 files changed, 159 insertions(+), 51 deletions(-) diff --git a/Disposition.cpp b/Disposition.cpp index f0d69ce..c2f5863 100644 --- a/Disposition.cpp +++ b/Disposition.cpp @@ -408,14 +408,14 @@ Disposition::Apply( bool bVerifyTab) for ( const auto& vMvrData : m_vMvrData) { switch ( vMvrData.nType) { case MoveRawData::COR : - if ( ! MoveToCornerRawPart( vMvrData.nRawId, vMvrData.ptP, vMvrData.nFlag, false)) { + if ( ! MoveToCornerRawPart( vMvrData.nRawId, vMvrData.ptP, vMvrData.nFlag, false, false)) { string sOut = "Error in MoveToCornerRawPart " + ToString( vMvrData.nRawId) ; m_pMchMgr->SetLastError( 2003, sOut.c_str()) ; bOk = false ; } break ; case MoveRawData::CEN : - if ( ! MoveToCenterRawPart( vMvrData.nRawId, vMvrData.ptP, vMvrData.nFlag, false)) { + if ( ! MoveToCenterRawPart( vMvrData.nRawId, vMvrData.ptP, vMvrData.nFlag, false, false)) { string sOut = "Error in MoveToCenterRawPart " + ToString( vMvrData.nRawId) ; m_pMchMgr->SetLastError( 2004, sOut.c_str()) ; bOk = false ; @@ -745,7 +745,7 @@ Disposition::RemoveFixture( int nId) //---------------------------------------------------------------------------- bool -Disposition::MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList) +Disposition::MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList, bool bVerify) { // verifica validità grezzo if ( m_pMchMgr == nullptr || ! m_pMchMgr->VerifyRawPart( nRawId, false)) @@ -772,9 +772,9 @@ Disposition::MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag, boo vtMove = ( m_ptRef1 + ptP) - Point3d( b3Raw.GetMax().x, b3Raw.GetMin().y, b3Raw.GetMin().z) ; break ; } - // verifico se il grezzo nella posizione finale sarà nella tavola + // se richiesto, verifico se il grezzo nella posizione finale sarà nella tavola b3Raw.Translate( vtMove) ; - if ( ! m_b3Area1.EnclosesXY( b3Raw)) + if ( bVerify && ! m_b3Area1.EnclosesXY( b3Raw)) return false ; // recupero eventuale spostamento corrente della tavola Vector3d vtDelta1 ; @@ -786,22 +786,14 @@ Disposition::MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag, boo if ( ! vtTotMove.IsSmall()) m_pGeomDB->TranslateGlob( nRawId, vtTotMove) ; // se da aggiungere alla lista - if ( bAddToList) { - auto iIter = find_if( m_vMvrData.begin(), m_vMvrData.end(), - [ nRawId]( const MoveRawData& Mrv) - { return ( Mrv.nRawId == nRawId && - ( Mrv.nType == MoveRawData::COR || Mrv.nType == MoveRawData::CEN)) ; }) ; - if ( iIter == m_vMvrData.end()) - m_vMvrData.emplace_back( nRawId, MoveRawData::COR, ptP, nFlag) ; - else - *iIter = MoveRawData( nRawId, MoveRawData::COR, ptP, nFlag) ; - } + if ( bAddToList) + InsertMoveInfoInList( nRawId, MoveRawData::COR, ptP, nFlag) ; return true ; } //---------------------------------------------------------------------------- bool -Disposition::MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList) +Disposition::MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList, bool bVerify) { // verifica validità grezzo if ( m_pMchMgr == nullptr || ! m_pMchMgr->VerifyRawPart( nRawId, false)) @@ -834,9 +826,9 @@ Disposition::MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag, boo vtMove = ( m_ptRef1 + ptP) - Point3d( ptCen.x, ptCen.y, b3Raw.GetMin().z) ; break ; } - // verifico se il grezzo nella posizione finale sarà nella tavola + // se richiesto, verifico se il grezzo nella posizione finale sarà nella tavola b3Raw.Translate( vtMove) ; - if ( ! m_b3Area1.EnclosesXY( b3Raw)) + if ( bVerify && ! m_b3Area1.EnclosesXY( b3Raw)) return false ; // recupero eventuale spostamento corrente della tavola Vector3d vtDelta1 ; @@ -848,16 +840,8 @@ Disposition::MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag, boo if ( ! vtTotMove.IsSmall()) m_pGeomDB->TranslateGlob( nRawId, vtTotMove) ; // se da aggiungere alla lista - if ( bAddToList) { - auto iIter = find_if( m_vMvrData.begin(), m_vMvrData.end(), - [ nRawId]( const MoveRawData& Mrv) - { return ( Mrv.nRawId == nRawId && - ( Mrv.nType == MoveRawData::COR || Mrv.nType == MoveRawData::CEN)) ; }) ; - if ( iIter == m_vMvrData.end()) - m_vMvrData.emplace_back( nRawId, MoveRawData::CEN, ptP, nFlag) ; - else - *iIter = MoveRawData( nRawId, MoveRawData::CEN, ptP, nFlag) ; - } + if ( bAddToList) + InsertMoveInfoInList( nRawId, MoveRawData::CEN, ptP, nFlag) ; return true ; } @@ -871,12 +855,13 @@ Disposition::MoveRawPart( int nRawId, const Vector3d& vtMove) // se movimento nullo, non devo fare alcunché if ( vtMove.IsSmall()) return true ; - // verifico ci sia già un movimento assoluto di questo grezzo - auto iIter = find_if( m_vMvrData.begin(), m_vMvrData.end(), + // cerco il movimento di traslazione assoluto di questo grezzo (per sicurezza cerco l'ultimo) + auto rTras = find_if( m_vMvrData.rbegin(), m_vMvrData.rend(), [ nRawId]( const MoveRawData& Mrv) { return ( Mrv.nRawId == nRawId && ( Mrv.nType == MoveRawData::COR || Mrv.nType == MoveRawData::CEN)) ; }) ; - if ( iIter == m_vMvrData.end()) + // se non c'è non posso fare un movimento incrementale + if ( rTras == m_vMvrData.rend()) return false ; // recupero il solido int nRawSolId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; @@ -896,7 +881,7 @@ Disposition::MoveRawPart( int nRawId, const Vector3d& vtMove) // eseguo traslazione in globale m_pGeomDB->TranslateGlob( nRawId, vtMove) ; // aggiorno comando di movimento - iIter->ptP += vtMove ; + rTras->ptP += vtMove ; return true ; } @@ -911,6 +896,12 @@ Disposition::RotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg) Point3d ptAx ; if ( ! m_pMchMgr->GetRawPartCenter( nRawId, ptAx)) return false ; + // recupero il solido + int nRawSolId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + // recupero box originale del grezzo (solo il solido ovviamente) + BBox3d b3OriRaw ; + if ( ! m_pGeomDB->GetGlobalBBox( nRawSolId, b3OriRaw)) + return false ; // eseguo rotazione in globale attorno al centro del grezzo if ( ! m_pGeomDB->RotateGlob( nRawId, ptAx, vtAx, dAngRotDeg)) return false ; @@ -920,14 +911,77 @@ Disposition::RotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg) // ne calcolo gli angoli di Eulero double dAngCDeg, dAngADeg, dAngC1Deg ; frRaw.GetRotationsCAC1( dAngCDeg, dAngADeg, dAngC1Deg) ; - // aggiungo o modifico nella lista - auto iIter = find_if( m_vMvrData.begin(), m_vMvrData.end(), + // cerco eventuale traslazione di questo grezzo + auto iTras = find_if( m_vMvrData.begin(), m_vMvrData.end(), [ nRawId]( const MoveRawData& Mrv) - { return ( Mrv.nRawId == nRawId && Mrv.nType == MoveRawData::ROT) ; }) ; - if ( iIter == m_vMvrData.end()) - m_vMvrData.emplace_back( nRawId, MoveRawData::ROT, Point3d( dAngCDeg, dAngADeg, dAngC1Deg), 0) ; - else - *iIter = MoveRawData( nRawId, MoveRawData::ROT, Point3d( dAngCDeg, dAngADeg, dAngC1Deg), 0) ; + { return ( Mrv.nRawId == nRawId && + ( Mrv.nType == MoveRawData::COR || Mrv.nType == MoveRawData::CEN)) ; }) ; + // Se c'è traslazione + if ( iTras != m_vMvrData.end()) { + // determino il box del grezzo (solo il solido ovviamente) + BBox3d b3Raw ; + if ( ! m_pGeomDB->GetGlobalBBox( nRawSolId, b3Raw)) + return false ; + // determino la traslazione correttiva da apportare + Vector3d vtCorr ; + if ( iTras->nType == MoveRawData::COR) { + switch ( iTras->nFlag) { + case MCH_CR_TL : + vtCorr = Vector3d( b3Raw.GetMin().x - b3OriRaw.GetMin().x, b3Raw.GetMax().y - b3OriRaw.GetMax().y, b3Raw.GetMin().z - b3OriRaw.GetMin().z) ; + break ; + case MCH_CR_TR : + vtCorr = Vector3d( b3Raw.GetMax().x - b3OriRaw.GetMax().x, b3Raw.GetMax().y - b3OriRaw.GetMax().y, b3Raw.GetMin().z - b3OriRaw.GetMin().z) ; + break ; + default : // RPCP_BL + vtCorr = Vector3d( b3Raw.GetMin().x - b3OriRaw.GetMin().x, b3Raw.GetMin().y - b3OriRaw.GetMin().y, b3Raw.GetMin().z - b3OriRaw.GetMin().z) ; + break ; + case MCH_CR_BR : + vtCorr = Vector3d( b3Raw.GetMax().x - b3OriRaw.GetMax().x, b3Raw.GetMin().y - b3OriRaw.GetMin().y, b3Raw.GetMin().z - b3OriRaw.GetMin().z) ; + break ; + } + } + else { + Point3d ptOriCen ; b3OriRaw.GetCenter( ptOriCen) ; + Point3d ptCen ; b3Raw.GetCenter( ptCen) ; + switch ( iTras->nFlag) { + case MCH_CE_TC : + vtCorr = Vector3d( ptCen.x - ptOriCen.x, b3Raw.GetMax().y - b3OriRaw.GetMax().y, ptCen.z - ptOriCen.z) ; + break ; + default : // RPCE_ML + vtCorr = Vector3d( b3Raw.GetMin().x - b3OriRaw.GetMin().x, ptCen.y - ptOriCen.y, ptCen.z - ptOriCen.z) ; + break ; + case MCH_CE_MR : + vtCorr = Vector3d( b3Raw.GetMax().x - b3OriRaw.GetMax().x, ptCen.y - ptOriCen.y, ptCen.z - ptOriCen.z) ; + break ; + case MCH_CE_BC : + vtCorr = Vector3d( ptCen.x - ptOriCen.x, b3Raw.GetMin().y - b3OriRaw.GetMin().y, ptCen.z - ptOriCen.z) ; + break ; + case MCH_CE_MC : + vtCorr = Vector3d( ptCen.x - ptOriCen.x, ptCen.y - ptOriCen.y, b3Raw.GetMin().z - b3OriRaw.GetMin().z) ; + break ; + } + } + // recupero eventuale spostamento corrente della tavola + Vector3d vtDelta1 ; + Machine* pMch = m_pMchMgr->GetCurrMachine() ; + if ( pMch == nullptr || ! pMch->GetCurrTableDeltaRef1( vtDelta1)) + return false ; + // verifico se il grezzo nella posizione finale sarà nella tavola (espressa in posizione 0) + b3Raw.Translate( - vtDelta1) ; + if ( ! m_b3Area1.EnclosesXY( b3Raw)) { + m_pGeomDB->RotateGlob( nRawId, ptAx, vtAx, - dAngRotDeg) ; + return false ; + } + // modifico valore traslazione che verrà spostata dopo rotazione + iTras->ptP += vtCorr ; + // aggiungo o modifico nella lista + InsertMoveInfoInList( nRawId, MoveRawData::ROT, Point3d( dAngCDeg, dAngADeg, dAngC1Deg), 0) ; + } + // altrimenti + else { + // aggiungo o modifico nella lista + InsertMoveInfoInList( nRawId, MoveRawData::ROT, Point3d( dAngCDeg, dAngADeg, dAngC1Deg), 0) ; + } return true ; } @@ -955,14 +1009,65 @@ Disposition::ApplyRotationToRawPart( int nRawId, double dAngCDeg, double dAngADe pfrRaw->Translate( ptCen - ptNewCen) ; // se da aggiungere alla lista if ( bAddToList) { - auto iIter = find_if( m_vMvrData.begin(), m_vMvrData.end(), - [ nRawId]( const MoveRawData& Mrv) - { return ( Mrv.nRawId == nRawId && - ( Mrv.nType == MoveRawData::COR || Mrv.nType == MoveRawData::CEN)) ; }) ; - if ( iIter == m_vMvrData.end()) - m_vMvrData.emplace_back( nRawId, MoveRawData::ROT, Point3d( dAngCDeg, dAngADeg, dAngC1Deg), 0) ; + // non ci sono problemi di compensazione della traslazione perchè già processata precedentemente in RotateRawPart + InsertMoveInfoInList( nRawId, MoveRawData::ROT, Point3d( dAngCDeg, dAngADeg, dAngC1Deg), 0) ; + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +Disposition::InsertMoveInfoInList( int nRawId, int nType, const Point3d& ptP, int nFlag) +{ + // verifico il tipo + if ( nType != MoveRawData::COR && nType != MoveRawData::CEN && nType != MoveRawData::ROT) + return false ; + + // cerco traslazione di questo grezzo + auto iTras = find_if( m_vMvrData.begin(), m_vMvrData.end(), + [ nRawId]( const MoveRawData& Mrv) + { return ( Mrv.nRawId == nRawId && + ( Mrv.nType == MoveRawData::COR || Mrv.nType == MoveRawData::CEN)) ; }) ; + // cerco rotazione di questo grezzo + auto iRot = find_if( m_vMvrData.begin(), m_vMvrData.end(), + [ nRawId]( const MoveRawData& Mrv) + { return ( Mrv.nRawId == nRawId && + Mrv.nType == MoveRawData::ROT) ; }) ; + // entrambi presenti + if ( iTras != m_vMvrData.end() && iRot != m_vMvrData.end()) { + // se traslazione precede rotazione, li scambio come contenuto e come iteratori + if ( iTras < iRot) { + swap( *iTras, *iRot) ; + swap( iTras, iRot) ; + } + // se inserimento traslazione + if ( nType != MoveRawData::ROT) + *iTras = MoveRawData( nRawId, nType, ptP, nFlag) ; + // altrimenti else - *iIter = MoveRawData( nRawId, MoveRawData::ROT, Point3d( dAngCDeg, dAngADeg, dAngC1Deg), 0) ; + *iRot = MoveRawData( nRawId, nType, ptP, nFlag) ; + } + // presente solo traslazione + else if ( iTras != m_vMvrData.end()) { + // se inserimento traslazione, la modifico + if ( nType != MoveRawData::ROT) + *iTras = MoveRawData( nRawId, nType, ptP, nFlag) ; + // altrimenti inserisco rotazione subito prima della traslazione + m_vMvrData.emplace( iTras, nRawId, nType, ptP, nFlag) ; + } + // presente solo rotazione + else if ( iRot != m_vMvrData.end()) { + // se inserimento traslazione, la inserisco subito dopo la rotazione + if ( nType != MoveRawData::ROT) + m_vMvrData.emplace( iRot + 1, nRawId, nType, ptP, nFlag) ; + // altrimenti la modifico + else + *iRot = MoveRawData( nRawId, nType, ptP, nFlag) ; + } + // assenti + else { + // inserisco alla fine + m_vMvrData.emplace_back( nRawId, nType, ptP, nFlag) ; } return true ; } diff --git a/Disposition.h b/Disposition.h index 7ec16e4..ff50a60 100644 --- a/Disposition.h +++ b/Disposition.h @@ -92,8 +92,8 @@ class Disposition : public Operation 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) ; - bool MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList = true) ; + bool MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList = true, bool bVerify = true) ; + bool MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag, bool bAddToList = true, bool bVerify = true) ; bool MoveRawPart( int nRawId, const Vector3d& vtMove) ; bool RotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg) ; bool ApplyRotationToRawPart( int nRawId, double dAngCDeg, double dAngADeg, double dAngC1Deg, bool bAddToList = true) ; @@ -107,6 +107,9 @@ class Disposition : public Operation bool GetSomeByHand( void) const { return m_bSomeByHand ; } + private : + bool InsertMoveInfoInList( int nRawId, int nType, const Point3d& ptP, int nFlag) ; + private : bool m_bTabOk ; // flag di tavola verificata std::string m_sTabName ; // nome della tavola di appartenenza diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 27d6113320c30bfcccd8de25b300e9e3becad165..4b0d487aa201c45c6d84721ce2398aa200bfa7a8 100644 GIT binary patch delta 121 zcmewt{V#gMH#Syt1|0^&&A-{KnVHiW3@1O7)ZLuM)x!c8zsNNCgkT;*P6$a3MUMyL R=2g-z%(yjz6ex#q0RVBoCa3@a delta 121 zcmewt{V#gMH#Sx?1|0_T&A-{KnVHiV%qKsT)ZLuM)x!c8zsNNCgkT;*P6$a3MUMyL R=2g-z%(yjz6ex#q0RVfkCeQ!? diff --git a/MachMgrRawParts.cpp b/MachMgrRawParts.cpp index 64e1690..9c0bf91 100644 --- a/MachMgrRawParts.cpp +++ b/MachMgrRawParts.cpp @@ -582,13 +582,13 @@ MachMgr::KeepRawPart( int nRawId, int nSouPhase) if ( nId == nRawId) { switch ( nType) { case MoveRawData::COR : - pDisp->MoveToCornerRawPart( nRawId, ptPos, nFlag) ; + pDisp->MoveToCornerRawPart( nRawId, ptPos, nFlag, true, false) ; break ; case MoveRawData::CEN : - pDisp->MoveToCenterRawPart( nRawId, ptPos, nFlag) ; + pDisp->MoveToCenterRawPart( nRawId, ptPos, nFlag, true, false) ; break ; case MoveRawData::ROT : - pDisp->ApplyRotationToRawPart( nRawId, ptPos.x, ptPos.y, ptPos.z) ; + pDisp->ApplyRotationToRawPart( nRawId, ptPos.x, ptPos.y, ptPos.z, true) ; break ; } }