diff --git a/BeamMgr.cpp b/BeamMgr.cpp index 65945eb..19856cf 100644 --- a/BeamMgr.cpp +++ b/BeamMgr.cpp @@ -100,6 +100,17 @@ BeamMgr::ErasePart( void) return m_BtlGeom.ErasePart() ; } +//---------------------------------------------------------------------------- +bool +BeamMgr::UpdatePart( void) +{ + // Verifico validità GDB + if ( m_pGDB == nullptr) + return false ; + // Forzo aggiornamento del pezzo corrente + return ( m_BtlGeom.UpdateOutLine() && m_BtlGeom.ResetPartSolid()) ; +} + //---------------------------------------------------------------------------- bool BeamMgr::SetPartProdNbr( int nProdNbr) @@ -143,9 +154,11 @@ BeamMgr::SetPartBox( double dLength, double dHeight, double dWidth, bool bUpdate // Imposto le dimensioni al pezzo corrente if ( ! m_BtlGeom.AddPartBox( dLength, dHeight, dWidth)) return false ; - // Se richiesto, aggiorno Outline - if ( bUpdate) + // Se richiesto, aggiorno Outline e cancello Solido + if ( bUpdate) { m_BtlGeom.UpdateOutLine() ; + m_BtlGeom.ResetPartSolid() ; + } return true ; } @@ -175,9 +188,11 @@ BeamMgr::AddProcess( int nGroup, int nProc, int nSide, const string& sDes, int n // Aggiungo la feature if ( ! m_BtlGeom.AddProcess( nGroup, nProc, nSide, sDes, nProcId,frRef, vnDPar, nSPar, vdBtlPar, sBtlPar, vsUAtt, 0)) return GDB_ID_NULL ; - // Se richiesto, aggiorno Outline - if ( bUpdate) + // Se richiesto, aggiorno Outline e cancello Solido + if ( bUpdate) { m_BtlGeom.UpdateOutLine() ; + m_BtlGeom.ResetPartSolid() ; + } // ritorno Id return m_BtlGeom.GetLastProcessId() ; } @@ -207,7 +222,7 @@ BeamMgr::ModifyProcess( int nGeomId, int nGroup, int nProc, int nSide, const str m_pGDB->Relocate( nNewId + nAux, nGeomId, GDB_BEFORE) ; } // Cancello il vecchio processo - EraseProcess( nGeomId, true) ; + EraseProcess( nGeomId, bUpdate) ; // Restituisco nuovo Id return nNewId ; } @@ -231,9 +246,11 @@ BeamMgr::EraseProcess( int nGeomId, bool bUpdate) m_pGDB->Erase( nGeomId + nAux) ; } m_pGDB->Erase( nGeomId) ; - // Se richiesto, aggiorno Outline - if ( bUpdate) + // Se richiesto, aggiorno Outline e cancello Solido + if ( bUpdate) { m_BtlGeom.UpdateOutLine() ; + m_BtlGeom.ResetPartSolid() ; + } return true ; } @@ -241,8 +258,32 @@ BeamMgr::EraseProcess( int nGeomId, bool bUpdate) bool BeamMgr::EnableProcess( int nGeomId, bool bEnable, bool bUpdate) { - - return false ; + // Verifico validità GDB + if ( m_pGDB == nullptr) + return false ; + // Recupero il pezzo di appartenenza + int nLayId = m_pGDB->GetParentId( nGeomId) ; + int nPartId = m_pGDB->GetParentId( nLayId) ; + if ( ! m_BtlGeom.SetPart( nPartId) || m_BtlGeom.GetCurrProcsLayId() != nLayId) + return false ; + // Recupero lo stato corrente + bool bDo = true ; + m_pGDB->GetInfo( nGeomId, IKEY_DO, bDo) ; + // Se lo stato non cambia, esco + if ( bEnable == bDo) + return true ; + // Imposto il nuovo stato e il colore + if ( bEnable) + m_pGDB->RemoveInfo( nGeomId, IKEY_DO) ; + else + m_pGDB->SetInfo( nGeomId, IKEY_DO, 0) ; + m_BtlGeom.SetProcessColor( nGeomId, bEnable) ; + // Se richiesto, aggiorno Outline e cancello Solido + if ( bUpdate) { + m_BtlGeom.UpdateOutLine() ; + m_BtlGeom.ResetPartSolid() ; + } + return true ; } //---------------------------------------------------------------------------- diff --git a/BeamMgr.h b/BeamMgr.h index 8b93322..46d7b08 100644 --- a/BeamMgr.h +++ b/BeamMgr.h @@ -24,6 +24,7 @@ class BeamMgr : public IBeamMgr int CreatePart( void) override ; bool SetPart( int nPartId) override ; bool ErasePart( void) override ; + bool UpdatePart( void) override ; bool SetPartProdNbr( int nProdNbr) override ; bool SetPartName( const std::string& sName) override ; bool SetPartCount( int nCount) override ; diff --git a/BtlGeom.cpp b/BtlGeom.cpp index 4725e39..841e349 100644 --- a/BtlGeom.cpp +++ b/BtlGeom.cpp @@ -37,6 +37,7 @@ BtlGeom::BtlGeom( void) m_BoxCol = Color( 255, 128, 0, 15) ; m_OutsCol = Color( 224, 128, 0, 50) ; m_ProcsCol = Color( 80, 160, 160, 100) ; + m_ProcsOffCol = Color( 160, 160, 160, 100) ; m_MarkCol = Color( 96, 192, 192, 100) ; m_SolidCol = Color(255, 160, 32, 100) ; m_nInfoId = GDB_ID_NULL ; @@ -188,8 +189,18 @@ BtlGeom::SetPart( int nPartId) if ( nProcsId == GDB_ID_NULL) return false ; int nSolidsId = m_pGDB->GetFirstNameInGroup( nPartId, SOLID_LAYER_NAME) ; - if ( nSolidsId == GDB_ID_NULL) - return false ; + if ( nSolidsId == GDB_ID_NULL) { + // nei vecchi progetti può non esserci, quindi lo creo + int nOldPartId = m_nPartId ; + int nOldSolidsId = m_nSolidsId ; + m_nPartId = nPartId ; + if ( ! ResetPartSolid()) { + m_nPartId = nOldPartId ; + m_nSolidsId = nOldSolidsId ; + return false ; + } + nSolidsId = m_nSolidsId ; + } // assegnazione identificativi m_nPartId = nPartId ; m_nAuxId = nAuxId ; @@ -217,12 +228,9 @@ BtlGeom::SetPart( int nPartId) bool BtlGeom::ErasePart( void) { - // se non c'è il DB geometrico, errore - if ( m_pGDB == nullptr) + // se non c'è il DB geometrico o il pezzo corrente, errore + if ( m_pGDB == nullptr || m_nPartId == GDB_ID_NULL) return false ; - // se non esiste un pezzo corrente, esco - if ( m_nPartId == GDB_ID_NULL) - return true ; // cancello il pezzo m_pGDB->Erase( m_nPartId) ; // annullo tutti gli identificativi del pezzo @@ -239,8 +247,10 @@ BtlGeom::ErasePart( void) bool BtlGeom::SetPartProdNbr( int nProdNbr) { - if ( m_pGDB == nullptr) + // se non c'è il DB geometrico o il pezzo corrente, errore + if ( m_pGDB == nullptr || m_nPartId == GDB_ID_NULL) return false ; + // assegno il numero di produzione del pezzo if ( ! m_pGDB->SetInfo( m_nPartId, IKEY_PROD_NBR, nProdNbr)) return false ; string sName = ToString( nProdNbr) ; @@ -252,8 +262,10 @@ BtlGeom::SetPartProdNbr( int nProdNbr) bool BtlGeom::SetPartName( const string& sDes) { - if ( m_pGDB == nullptr) + // se non c'è il DB geometrico o il pezzo corrente, errore + if ( m_pGDB == nullptr || m_nPartId == GDB_ID_NULL) return false ; + // assegno il nome del pezzo if ( ! m_pGDB->SetInfo( m_nPartId, IKEY_NAME, sDes)) return false ; int nProdNbr = 0 ; @@ -269,7 +281,8 @@ BtlGeom::SetPartName( const string& sDes) string BtlGeom::GetPartName( void) { - if ( m_pGDB == nullptr) + // se non c'è il DB geometrico o il pezzo corrente, errore + if ( m_pGDB == nullptr || m_nPartId == GDB_ID_NULL) return "" ; string sName ; m_pGDB->GetName( m_nPartId, sName) ; @@ -280,6 +293,9 @@ BtlGeom::GetPartName( void) bool BtlGeom::SetPartCount( int nCount) { + // se non c'è il DB geometrico o il pezzo corrente, errore + if ( m_pGDB == nullptr || m_nPartId == GDB_ID_NULL) + return false ; m_nCount = nCount ; return ( m_pGDB != nullptr && m_pGDB->SetInfo( m_nPartId, IKEY_COUNT, nCount)) ; } @@ -288,6 +304,9 @@ BtlGeom::SetPartCount( int nCount) bool BtlGeom::AddPartBox( double dLength, double dHeight, double dWidth) { + // se non c'è il DB geometrico o il pezzo corrente, errore + if ( m_pGDB == nullptr || m_nPartId == GDB_ID_NULL) + return false ; // creo il solido (parallelepipedo) PtrOwner pStm( GetSurfTriMeshBox( dLength, dHeight, dWidth)) ; if ( IsNull( pStm)) @@ -450,6 +469,7 @@ BtlGeom::ReadUserAttribute( const string& sString, string& sKey, string& sVal) bool BtlGeom::SetUserAttribute( int nUAttrDest, const string& sString) { + // se non c'è il DB geometrico, errore if ( m_pGDB == nullptr) return false ; // recupero chiave e valore @@ -467,6 +487,7 @@ BtlGeom::SetUserAttribute( int nUAttrDest, const string& sString) bool BtlGeom::SetUserAttribute( int nUAttrDest, const string& sKey, const string& sVal) { + // se non c'è il DB geometrico, errore if ( m_pGDB == nullptr) return false ; // li assegno diff --git a/BtlGeom.h b/BtlGeom.h index c71991f..f815fe6 100644 --- a/BtlGeom.h +++ b/BtlGeom.h @@ -58,6 +58,7 @@ class BtlGeom const INTVECTOR& vnDPar, int nSPar, const DBLVECTOR& vdPar, const std::string& sPar, const STRVECTOR& vsUAtt, int nLine) ; int GetLastProcessId( void) { return m_nProcId ; } bool CreateFreeContours( void) ; + bool SetProcessColor( int nId, bool bEnable) ; private : bool CreateInfoGroup( void) ; @@ -220,6 +221,7 @@ class BtlGeom Color m_BoxCol ; // colore per box pezzi Color m_OutsCol ; // colore per outline pezzi Color m_ProcsCol ; // colore per lavorazioni pezzi + Color m_ProcsOffCol ; // colore per lavorazioni pezzi disabilitate Color m_MarkCol ; // colore per linee di marcatura e testi Color m_SolidCol ; // colore per il solido int m_nInfoId ; // identificativo gruppo per informazioni varie diff --git a/BtlGeomOutline.cpp b/BtlGeomOutline.cpp index 1f3fdeb..9596d53 100644 --- a/BtlGeomOutline.cpp +++ b/BtlGeomOutline.cpp @@ -454,6 +454,9 @@ BtlGeom::AddPartCustomOutline( void) bool BtlGeom::UpdateOutLine( void) { + // verifiche + if ( m_pGDB == nullptr || m_nPartId == GDB_ID_NULL) + return false ; // pulisco il gruppo di Outline (elimino tutte le regioni) int nOutId = m_pGDB->GetFirstInGroup( m_nOutsId) ; while ( nOutId != GDB_ID_NULL) { diff --git a/BtlGeomProc.cpp b/BtlGeomProc.cpp index 2c1ba01..f7437b4 100644 --- a/BtlGeomProc.cpp +++ b/BtlGeomProc.cpp @@ -7018,16 +7018,36 @@ BtlGeom::SetUserAttributes( int nId, const STRVECTOR& vsUAtt) m_pGDB->SetInfo( nId, sKey, sVal) ; // se disabilitazione, cambio colore if ( sKey == IKEY_DO && sVal == "0") { - Color cCol ; - m_pGDB->GetCalcMaterial( nId, cCol) ; - cCol.Set( 160, 160, 160, cCol.GetIntAlpha()) ; - m_pGDB->SetMaterial( nId, cCol) ; + SetProcessColor( nId, false) ; } } } return true ; } +//--------------------------------------------------------------------------- +bool +BtlGeom::SetProcessColor( int nId, bool bEnable) +{ + if ( nId == GDB_ID_NULL) + return false ; + // determino il nuovo colore + Color cOrigCol ; + m_pGDB->GetCalcMaterial( nId, cOrigCol) ; + Color cNewCol = ( bEnable ? m_ProcsCol : m_ProcsOffCol) ; + cNewCol.SetAlpha( cOrigCol.GetIntAlpha()) ; + // assegno il nuovo colore al processo + m_pGDB->SetMaterial( nId, cNewCol) ; + // se ci sono geometrie ausiliarie, assegno il nuovo colore anche a queste + INTVECTOR vAux ; + if ( m_pGDB->GetInfo( nId, IKEY_AUXID, vAux) && ! vAux.empty()) { + for ( auto nAux : vAux) + m_pGDB->SetMaterial( nId + nAux, cNewCol) ; + } + + return true ; +} + //--------------------------------------------------------------------------- bool BtlGeom::SetAuxId( int nId, const INTVECTOR& vnAuxId) @@ -7108,6 +7128,7 @@ BtlGeom::InsertEmptySurface( int nGroup, int nProc, int nSide, const string& sDe SetNameAndInfo( nId, nGroup, nProc, nSide, sDes, nProcId) ; // aggiungo parametri SetParams( nId, vnDPar, vdPar, vsUAtt) ; + m_nProcId = nId ; return true ; }