//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : EXE_GdbPartLayers.cpp Data : 04.05.15 Versione : 1.6e1 // Contenuto : Funzioni di gestione pezzi e layer relativi per EXE. // // // // Modifiche : 29.01.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "EXE.h" #include "EXE_Const.h" #include "EXE_Macro.h" #include "/EgtDev/Include/EXeExecutor.h" #include "/EgtDev/Include/EGkCurve.h" #include "/EgtDev/Include/EGkChainCurves.h" #include "/EgtDev/Include/EGkStringUtils3d.h" using namespace std ; //------------------------------------------------------------------------------- static bool ExeIsUserObj( IGeomDB* pGeomDB, int nId) { int nLev ; return ( pGeomDB->GetCalcLevel( nId, nLev) && nLev == GDB_LV_USER) ; } //------------------------------------------------------------------------------- static bool ExeIsSystemObj( IGeomDB* pGeomDB, int nId) { int nLev ; return ( pGeomDB->GetCalcLevel( nId, nLev) && nLev == GDB_LV_SYSTEM) ; } //------------------------------------------------------------------------------- static bool ExeIsVisibleObj( IGeomDB* pGeomDB, int nId) { int nStat ; return ( pGeomDB->GetCalcStatus( nId, nStat) && nStat != GDB_ST_OFF) ; } //------------------------------------------------------------------------------- static int ExeVerifyOrNext( IGeomDB* pGeomDB, int nId, bool bOnlyVisible) { while ( nId != GDB_ID_NULL) { if ( ExeIsUserObj( pGeomDB, nId) && ! pGeomDB->ExistsInfo( nId, GDB_SI_SOURCE) && ( ! bOnlyVisible || ExeIsVisibleObj( pGeomDB, nId))) return nId ; nId = pGeomDB->GetNextGroup( nId) ; } return GDB_ID_NULL ; } //------------------------------------------------------------------------------- static int ExeVerifyOrPrev( IGeomDB* pGeomDB, int nId, bool bOnlyVisible) { while ( nId != GDB_ID_NULL) { if ( ExeIsUserObj( pGeomDB, nId) && ( ! bOnlyVisible || ExeIsVisibleObj( pGeomDB, nId))) return nId ; nId = pGeomDB->GetPrevGroup( nId) ; } return GDB_ID_NULL ; } //------------------------------------------------------------------------------- static int ExeGhostVerifyOrNext( IGeomDB* pGeomDB, int nId) { while ( nId != GDB_ID_NULL) { if ( ExeIsSystemObj( pGeomDB, nId) && pGeomDB->ExistsInfo( nId, GDB_SI_SOURCE)) { int nPartId = GDB_ID_NULL ; pGeomDB->GetInfo( nId, GDB_SI_SOURCE, nPartId) ; int nRawId = pGeomDB->GetParentId( nPartId) ; if ( ExeIsRawPart( nRawId)) return nId ; } nId = pGeomDB->GetNextGroup( nId) ; } return GDB_ID_NULL ; } //------------------------------------------------------------------------------- bool ExeIsPart( int nPartId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // verifico sia un pezzo (gruppo sotto la radice con livello utente) if ( pGeomDB->GetGdbType( nPartId) == GDB_TY_GROUP && pGeomDB->GetParentId( nPartId) == GDB_ID_ROOT && ExeIsUserObj( pGeomDB, nPartId)) return true ; else return false ; } //------------------------------------------------------------------------------- bool ExeIsLayer( int nLayerId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // verifico sia un layer (gruppo sotto un pezzo con livello utente) if ( pGeomDB->GetGdbType( nLayerId) == GDB_TY_GROUP && ExeIsPart( pGeomDB->GetParentId( nLayerId)) && ExeIsUserObj( pGeomDB, nLayerId)) return true ; else return false ; } //------------------------------------------------------------------------------- int ExeGetCurrPart( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, GDB_ID_NULL) // recupero il pezzo corrente return pGseCtx->m_nCurrPart ; } //------------------------------------------------------------------------------- int ExeGetCurrLayer( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, GDB_ID_NULL) // recupero il pezzo corrente return pGseCtx->m_nCurrLayer ; } //------------------------------------------------------------------------------- bool ExeSetCurrPartLayer( int nPartId, int nLayerId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) IGeomDB* pGeomDB = pGseCtx->m_pGeomDB ; bool bOk = true ; // verifico validità e visibilità pezzo if ( pGeomDB->GetParentId( nPartId) == GDB_ID_ROOT && ExeIsUserObj( pGeomDB, nPartId) && ExeIsVisibleObj( pGeomDB, nPartId)) { if ( nPartId != pGseCtx->m_nCurrPart) pGseCtx->m_nCurrLayer = GDB_ID_NULL ; pGseCtx->m_nCurrPart = nPartId ; } else { if ( nPartId == pGseCtx->m_nCurrPart || nPartId == GDB_ID_NULL) { pGseCtx->m_nCurrPart = GDB_ID_NULL ; pGseCtx->m_nCurrLayer = GDB_ID_NULL ; } bOk = false ; } // verifico validità e visibilità layer if ( pGeomDB->GetParentId( nLayerId) == pGseCtx->m_nCurrPart && ExeIsUserObj( pGeomDB, nLayerId) && ExeIsVisibleObj( pGeomDB, nLayerId)) { pGseCtx->m_nCurrLayer = nLayerId ; } else { if ( nLayerId == pGseCtx->m_nCurrLayer || nLayerId == GDB_ID_NULL) pGseCtx->m_nCurrLayer = GDB_ID_NULL ; bOk = false ; } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtSetCurrPartLayer(" + ToString( nPartId) + "," + ToString( nLayerId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //------------------------------------------------------------------------------- bool ExeResetCurrPartLayer( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) // reset pGseCtx->m_nCurrPart = GDB_ID_NULL ; pGseCtx->m_nCurrLayer = GDB_ID_NULL ; // cerco il primo pezzo con un layer visibile int nPartId = ExeGetFirstPart( true) ; while ( nPartId != GDB_ID_NULL) { // cerco il primo layer visibile del pezzo int nLayerId = ExeGetFirstLayer( nPartId, true) ; if ( nLayerId != GDB_ID_NULL) { // assegno il pezzo corrente pGseCtx->m_nCurrPart = nPartId ; // assegno il layer corrente pGseCtx->m_nCurrLayer = nLayerId ; // esco dal ciclo di ricerca break ; } nPartId = ExeGetNextPart( nPartId, true) ; } // se non ho trovato layer visibile mi accontento del primo pezzo visibile if ( pGseCtx->m_nCurrPart == GDB_ID_NULL) pGseCtx->m_nCurrPart = ExeGetFirstPart( true) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtResetCurrPartLayer()" " -- Ids=" + ToString( pGseCtx->m_nCurrPart) + "," + ToString( pGseCtx->m_nCurrLayer) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return true ; } //------------------------------------------------------------------------------- int ExeGetPartCount( bool bOnlyVisible) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, 0) // conto i pezzi, considerando richiesta di visibilità int nCount = 0 ; int nPartId = ExeGetFirstPart( bOnlyVisible) ; while ( nPartId != GDB_ID_NULL) { ++ nCount ; nPartId = ExeGetNextPart( nPartId, bOnlyVisible) ; } return nCount ; } //------------------------------------------------------------------------------- int ExeGetFirstPart( bool bOnlyVisible) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il primo gruppo sotto la radice int nPartId = pGeomDB->GetFirstGroupInGroup( GDB_ID_ROOT) ; // verifico oppure passo al primo successivo valido return ExeVerifyOrNext( pGeomDB, nPartId, bOnlyVisible) ; } //------------------------------------------------------------------------------- int ExeGetNextPart( int nId, bool bOnlyVisible) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il successivo gruppo int nPartId = pGeomDB->GetNextGroup( nId) ; // verifico oppure passo al primo successivo valido return ExeVerifyOrNext( pGeomDB, nPartId, bOnlyVisible) ; } //------------------------------------------------------------------------------- int ExeGetLastPart( bool bOnlyVisible) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero l'ultimo gruppo sotto la radice int nPartId = pGeomDB->GetLastGroupInGroup( GDB_ID_ROOT) ; // verifico oppure passo al primo precedente valido return ExeVerifyOrPrev( pGeomDB, nPartId, bOnlyVisible) ; } //------------------------------------------------------------------------------- int ExeGetPrevPart( int nId, bool bOnlyVisible) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il precedente gruppo int nPartId = pGeomDB->GetPrevGroup( nId) ; // verifico oppure passo al primo precedente valido return ExeVerifyOrPrev( pGeomDB, nPartId, bOnlyVisible) ; } //------------------------------------------------------------------------------- int ExeGetFirstLayer( int nPartId, bool bOnlyVisible) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // verifico il pezzo (livello utente e se richiesto visibile) if ( ! ExeIsUserObj( pGeomDB, nPartId) || ( bOnlyVisible && ! ExeIsVisibleObj( pGeomDB, nPartId))) return GDB_ID_NULL ; // recupero il primo layer nel pezzo int nLayerId = pGeomDB->GetFirstGroupInGroup( nPartId) ; // verifico oppure passo al primo successivo valido return ExeVerifyOrNext( pGeomDB, nLayerId, bOnlyVisible) ; } //------------------------------------------------------------------------------- int ExeGetNextLayer( int nId, bool bOnlyVisible) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il successivo gruppo int nLayerId = pGeomDB->GetNextGroup( nId) ; // verifico sia visibile oppure passo al primo successivo visibile return ExeVerifyOrNext( pGeomDB, nLayerId, bOnlyVisible) ; } //------------------------------------------------------------------------------- int ExeGetLastLayer( int nPartId, bool bOnlyVisible) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // verifico il pezzo (livello utente e se richiesto visibile) if ( ! ExeIsUserObj( pGeomDB, nPartId) || ( bOnlyVisible && ! ExeIsVisibleObj( pGeomDB, nPartId))) return GDB_ID_NULL ; // recupero l'ultimo layer nel pezzo int nLayerId = pGeomDB->GetLastGroupInGroup( nPartId) ; // verifico oppure passo al primo precedente valido return ExeVerifyOrPrev( pGeomDB, nLayerId, bOnlyVisible) ; } //------------------------------------------------------------------------------- int ExeGetPrevLayer( int nId, bool bOnlyVisible) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il precedente gruppo int nLayerId = pGeomDB->GetPrevGroup( nId) ; // verifico sia visibile oppure passo al primo precedente visibile return ExeVerifyOrPrev( pGeomDB, nLayerId, bOnlyVisible) ; } //------------------------------------------------------------------------------- bool ExeIsGhostPart( int nGhostId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // verifico sia il segnaposto di un pezzo (Ghost) if ( pGeomDB->GetGdbType( nGhostId) == GDB_TY_GROUP && pGeomDB->GetParentId( nGhostId) == GDB_ID_ROOT && ExeIsSystemObj( pGeomDB, nGhostId) && pGeomDB->ExistsInfo( nGhostId, GDB_SI_SOURCE)) { int nPartId = GDB_ID_NULL ; pGeomDB->GetInfo( nGhostId, GDB_SI_SOURCE, nPartId) ; int nRawId = pGeomDB->GetParentId( nPartId) ; if ( ExeIsRawPart( nRawId)) return true ; } return false ; } //------------------------------------------------------------------------------- int ExeGetFirstGhostPart( void) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il primo gruppo sotto la radice int nPartId = pGeomDB->GetFirstGroupInGroup( GDB_ID_ROOT) ; // verifico oppure passo al primo successivo valido return ExeGhostVerifyOrNext( pGeomDB, nPartId) ; } //------------------------------------------------------------------------------- int ExeGetNextGhostPart( int nId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // recupero il successivo gruppo int nPartId = pGeomDB->GetNextGroup( nId) ; // verifico oppure passo al primo successivo valido return ExeGhostVerifyOrNext( pGeomDB, nPartId) ; } //------------------------------------------------------------------------------- bool ExeEraseEmptyParts( void) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // recupero il primo pezzo int nPartId = ExeVerifyOrNext( pGeomDB, pGeomDB->GetFirstGroupInGroup( GDB_ID_ROOT), false) ; // ciclo sui pezzi while ( nPartId != GDB_ID_NULL) { // verifico se il pezzo non contiene alcuna entità geometrica bool bFound = false ; // ciclo sui layer dei pezzi int nLayerId = ExeVerifyOrNext( pGeomDB, pGeomDB->GetFirstGroupInGroup( nPartId), false) ; while ( nLayerId != GDB_ID_NULL) { // verifico se il layer contiene qualcosa if ( pGeomDB->GetGroupObjs( nLayerId) > 0) { bFound = true ; break ; } // passo al layer successivo nLayerId = ExeVerifyOrNext( pGeomDB, pGeomDB->GetNextGroup( nLayerId), false) ; } // verifico se gruppo sorgente di pezzo in gruppo di lavorazione if ( pGeomDB->ExistsInfo( nPartId, GDB_SI_SOURCE)) bFound = true ; // salvo Id pezzo corrente int nOldId = nPartId ; // passo al pezzo successivo nPartId = ExeVerifyOrNext( pGeomDB, pGeomDB->GetNextGroup( nPartId), false) ; // se corrente da cancellare, procedo if ( ! bFound) pGeomDB->Erase( nOldId) ; } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtEraseEmptyParts()" " -- Ok=" + ToString( true) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } return true ; } //----------------------------------------------------------------------------- static bool MySelectGroupObjs( IGeomDB* pGeomDB, int nGrpId, int nFilter) { bool bOk = true ; // Ciclo sugli oggetti del gruppo int nId = pGeomDB->GetFirstInGroup( nGrpId) ; while ( nId != GDB_ID_NULL) { // Se è gruppo seleziono i suoi componenti (ma non il gruppo) if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) { if ( ! MySelectGroupObjs( pGeomDB, nId, nFilter)) bOk = false ; } // altrimenti, se selezionabile lo seleziono direttamente else { if ( ( pGeomDB->GetGeoType( nId) & nFilter) != 0) { if ( ! pGeomDB->SelectObj( nId)) bOk = false ; } } // Passo al successivo nId = pGeomDB->GetNext( nId) ; } return bOk ; } //----------------------------------------------------------------------------- static bool MyDeselectGroupObjs( IGeomDB* pGeomDB, int nGrpId) { bool bOk = true ; // Ciclo sugli oggetti del gruppo int nId = pGeomDB->GetFirstInGroup( nGrpId) ; while ( nId != GDB_ID_NULL) { // Se è gruppo deseleziono i suoi componenti if ( pGeomDB->GetGdbType( nId) == GDB_TY_GROUP) { if ( ! MyDeselectGroupObjs( pGeomDB, nId)) bOk = false ; } // Eseguo deselezione (anche del gruppo per maggior sicurezza) if ( ! pGeomDB->DeselectObj( nId)) bOk = false ; // Passo al successivo nId = pGeomDB->GetNext( nId) ; } return bOk ; } //----------------------------------------------------------------------------- bool ExeSelectPartObjs( int nPartId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) IGeomDB* pGeomDB = pGseCtx->m_pGeomDB ; // verifico sia veramente un pezzo bool bOk = ExeIsPart( nPartId) ; // eseguo selezione bOk = bOk && MySelectGroupObjs( pGeomDB, nPartId, pGseCtx->m_nObjFilterForSelect) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtSelectPartObjs(" + ToString( nPartId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeDeselectPartObjs( int nPartId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // verifico sia veramente un pezzo bool bOk = ExeIsPart( nPartId) ; // eseguo deselezione (anche del pezzo per maggior sicurezza) bOk = bOk && MyDeselectGroupObjs( pGeomDB, nPartId) && pGeomDB->DeselectObj( nPartId) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtDeselectPartObjs(" + ToString( nPartId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeSelectLayerObjs( int nLayerId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) IGeomDB* pGeomDB = pGseCtx->m_pGeomDB ; // verifico sia veramente un layer o almeno un gruppo di un pezzo bool bOk = ExeIsLayer( nLayerId) || ( ( pGeomDB->GetGdbType( nLayerId) == GDB_TY_GROUP) && ExeIsPart( pGeomDB->GetParentId( nLayerId))) ; // eseguo selezione bOk = bOk && MySelectGroupObjs( pGeomDB, nLayerId, pGseCtx->m_nObjFilterForSelect) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtSelectLayerObjs(" + ToString( nLayerId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeDeselectLayerObjs( int nLayerId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // verifico sia veramente un layer o almeno un gruppo di un pezzo bool bOk = ExeIsLayer( nLayerId) || ( ( pGeomDB->GetGdbType( nLayerId) == GDB_TY_GROUP) && ExeIsPart( pGeomDB->GetParentId( nLayerId))) ; // eseguo deselezione (anche del layer per maggior sicurezza) bOk = bOk && MyDeselectGroupObjs( pGeomDB, nLayerId) && pGeomDB->DeselectObj( nLayerId) ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtDeselectLayerObjs(" + ToString( nLayerId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //----------------------------------------------------------------------------- bool ExeSelectPathObjs( int nId, bool bHaltOnFork) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_GEOMDB( pGseCtx, false) IGeomDB* pGeomDB = pGseCtx->m_pGeomDB ; // verifico appartenga ad un layer (di un pezzo libero o in un grezzo) int nIdLayer = pGeomDB->GetParentId( nId) ; int nIdPart = pGeomDB->GetParentId( nIdLayer) ; bool bOk = ( nIdLayer != GDB_ID_NULL && nIdPart != GDB_ID_NULL && ( ExeIsLayer( nIdLayer) || ExeGetRawPartFromPart( nIdPart) != GDB_ID_NULL)) ; // verifico sia abilitata la selezione di curve bOk = bOk && ( pGseCtx->m_nObjFilterForSelect & GEO_CURVE) != 0 ; // seleziono percorso a partire da entità indicata usando tutte le curve del pezzo const int CHAIN_SIZE = 1000 ; const double CHAIN_TOLER = 10 * EPS_SMALL ; Point3d ptNear ; ChainCurves chainC ; bOk = bOk && chainC.Init( true, CHAIN_TOLER, CHAIN_SIZE) ; // ciclo sui layer del pezzo for ( int nLayId = pGeomDB->GetFirstGroupInGroup( nIdPart) ; nLayId != GDB_ID_NULL ; nLayId = pGeomDB->GetNextGroup( nLayId)) { // ciclo sulle entità del layer for ( int nEntId = pGeomDB->GetFirstInGroup( nLayId) ; nEntId != GDB_ID_NULL ; nEntId = pGeomDB->GetNext( nEntId)) { // non deve essere nascosta int nEntStat ; pGeomDB->GetCalcStatus( nEntId, nEntStat) ; if ( nEntStat == GDB_ST_OFF) continue ; // recupero la curva e il suo riferimento ICurve* pCrv = GetCurve( pGeomDB->GetGeoObj( nEntId)) ; if ( pCrv == nullptr) continue ; Frame3d frCrv ; if ( ! pGeomDB->GetGlobFrame( nEntId, frCrv)) continue ; // recupero i dati della curva necessari al concatenamento e li assegno Point3d ptStart, ptEnd ; Vector3d vtStart, vtEnd ; if ( ! pCrv->GetStartPoint( ptStart) || ! pCrv->GetStartDir( vtStart) || ! pCrv->GetEndPoint( ptEnd) || ! pCrv->GetEndDir( vtEnd)) continue ; ptStart.ToGlob( frCrv) ; vtStart.ToGlob( frCrv) ; ptEnd.ToGlob( frCrv) ; vtEnd.ToGlob( frCrv) ; if ( nEntId == nId) ptNear = ptStart + CHAIN_TOLER * vtStart ; bOk = bOk && chainC.AddCurve( nEntId, ptStart, vtStart, ptEnd, vtEnd) ; } } // recupero il primo percorso concatenato INTVECTOR vId2s ; bOk = bOk && chainC.GetChainFromNear( ptNear, bHaltOnFork, vId2s) ; for ( size_t i = 0 ; i < vId2s.size() ; ++i) { pGeomDB->SetStatus( abs( vId2s[i]), GDB_ST_SEL) ; } // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtSelectPathObjs(" + ToString( nId) + "," + ( bHaltOnFork ? "true" : "false") + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco risultato return bOk ; } //---------------------------------------------------------------------------- bool ExeIsDuploBase( IGeomDB* pGeomDB, int nId) { if ( pGeomDB == nullptr) return false ; int nLevel ; string sName ; return ( pGeomDB->GetLevel( nId, nLevel) && nLevel == GDB_LV_SYSTEM && pGeomDB->GetName( nId, sName) && sName == DUPLO_BASE) ; } //----------------------------------------------------------------------------- static int GetDuploBase( IGeomDB* pGeomDB, bool bCreate = false) { // verifica collegamento a DB geometrico if ( pGeomDB == nullptr) return GDB_ID_NULL ; // cerco il gruppo di base dei duplicati nella radice int nId = pGeomDB->GetFirstGroupInGroup( GDB_ID_ROOT) ; while ( nId != GDB_ID_NULL) { // verifico se gruppo cercato if ( ExeIsDuploBase( pGeomDB, nId)) return nId ; // passo al successivo nId = pGeomDB->GetNextGroup( nId) ; } // non trovato, se non richiesta creazione ritorno if ( ! bCreate) return GDB_ID_NULL ; // devo creare il gruppo di base delle lavorazioni int nDuploBaseId = pGeomDB->InsertGroup( GDB_ID_NULL, GDB_ID_ROOT, GDB_FIRST_SON, GLOB_FRM) ; if ( nDuploBaseId == GDB_ID_NULL) return GDB_ID_NULL ; // imposto nome del gruppo pGeomDB->SetName( nDuploBaseId, DUPLO_BASE) ; // imposto livello del gruppo a System pGeomDB->SetLevel( nDuploBaseId, GDB_LV_SYSTEM) ; // imposto visualizzazione a nascosto pGeomDB->SetStatus( nDuploBaseId, GDB_ST_OFF) ; return nDuploBaseId ; } //----------------------------------------------------------------------------- static bool IsPartForDuplo( IGeomDB* pGeomDB, int nPartId) { // è veramente un pezzo if ( ExeIsPart( nPartId)) return true ; // è un pezzo spostato altrove int nBaseId, nLev ; if ( pGeomDB->GetInfo( nPartId, GDB_SI_BASE, nBaseId) && pGeomDB->GetGdbType( nPartId) == GDB_TY_GROUP && pGeomDB->GetParentId( nBaseId) == GDB_ID_ROOT && pGeomDB->GetLevel( nPartId, nLev) && nLev == GDB_LV_USER) return true ; // altrimenti non è un pezzo return false ; } //----------------------------------------------------------------------------- static bool IsDuplo( IGeomDB* pGeomDB, int nDupId, bool& bInDuploGroup) { // verifica collegamento a DB geometrico if ( pGeomDB == nullptr) return false ; // Recupero il gruppo base dei duplicati int nDuploBaseId = GetDuploBase( pGeomDB) ; if ( nDuploBaseId == GDB_ID_NULL) return false ; // Verifico sia un duplicato (gruppo sotto quello dei duplicati con riferimento a originale) int nBaseId ; if ( pGeomDB->GetGdbType( nDupId) == GDB_TY_GROUP && pGeomDB->ExistsInfo( nDupId, GDB_SI_DUPSOU)) { if ( pGeomDB->GetParentId( nDupId) == nDuploBaseId) { bInDuploGroup = true ; return true ; } else if ( pGeomDB->GetInfo( nDupId, GDB_SI_BASE, nBaseId) && pGeomDB->GetParentId( nBaseId) == nDuploBaseId) { bInDuploGroup = false ; return true ; } } return false ; } //----------------------------------------------------------------------------- int ExeDuploNew( int nSouId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // Verifico sia un pezzo if ( ! IsPartForDuplo( pGeomDB, nSouId)) return GDB_ID_NULL ; // Recupero il gruppo base dei duplicati int nDuploBaseId = GetDuploBase( pGeomDB, true) ; if ( nDuploBaseId == GDB_ID_NULL) return GDB_ID_NULL ; // Eseguo la copia del pezzo int nNewId = pGeomDB->Copy( nSouId, GDB_ID_NULL, nDuploBaseId) ; if ( nNewId == GDB_ID_NULL) return GDB_ID_NULL ; int nBaseId ; if ( pGeomDB->GetInfo( nSouId, GDB_SI_BASE, nBaseId) && pGeomDB->GetGdbType( nBaseId) == GDB_TY_GROUP) *pGeomDB->GetGroupFrame( nNewId) = *pGeomDB->GetGroupFrame( nBaseId) ; // Aggiorno info del sorgente INTVECTOR vnRef ; pGeomDB->GetInfo( nSouId, GDB_SI_DUPLIST, vnRef) ; if ( find( vnRef.begin(), vnRef.end(), nNewId) == vnRef.end()) { vnRef.push_back( nNewId) ; pGeomDB->SetInfo( nSouId, GDB_SI_DUPLIST, vnRef) ; } // Aggiorno info del duplicato pGeomDB->SetInfo( nNewId, GDB_SI_DUPSOU, nSouId) ; pGeomDB->RemoveInfo( nNewId, GDB_SI_DUPLIST) ; // Dichiaro progetto modificato ExeSetModified() ; return nNewId ; } //----------------------------------------------------------------------------- bool ExeDuploCount( int nSouId, int& nCount) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia un pezzo if ( ! IsPartForDuplo( pGeomDB, nSouId)) return false ; // Recupero info del sorgente INTVECTOR vnRef ; pGeomDB->GetInfo( nSouId, GDB_SI_DUPLIST, vnRef) ; // Conto i reali duplo nCount = 0 ; for ( int i = 0 ; i < int( vnRef.size()) ; ++ i) { bool bInDuploGroup ; if ( IsDuplo( pGeomDB, vnRef[i], bInDuploGroup)) ++ nCount ; } return true ; } //----------------------------------------------------------------------------- bool ExeDuploList( int nSouId, INTVECTOR& vnRef) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia un pezzo if ( ! IsPartForDuplo( pGeomDB, nSouId)) return false ; // Recupero info del sorgente pGeomDB->GetInfo( nSouId, GDB_SI_DUPLIST, vnRef) ; // Elimino duplo non più esistenti for ( int i = int( vnRef.size()) - 1 ; i >= 0 ; -- i) { if ( ! ExeIsDuplo( vnRef[i])) vnRef.erase( vnRef.begin() + i) ; } return true ; } //----------------------------------------------------------------------------- bool ExeDuploInRawCount( int nSouId, int& nCount) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia un pezzo if ( ! IsPartForDuplo( pGeomDB, nSouId)) return false ; // Recupero info del sorgente INTVECTOR vnRef ; pGeomDB->GetInfo( nSouId, GDB_SI_DUPLIST, vnRef) ; // Conto i reali duplo che sono riferiti o che stanno in un grezzo nCount = 0 ; for ( int i = 0 ; i < int( vnRef.size()) ; ++ i) { // verifico sia un duplo int nDupId = vnRef[i] ; bool bInDuploGroup ; if ( ! IsDuplo( pGeomDB, nDupId, bInDuploGroup)) continue ; // se nel gruppo dei duplo if ( bInDuploGroup) { // verifico sia incluso in un grezzo di un gruppo di lavoro INTVECTOR vnRef ; if ( ! pGeomDB->GetInfo( nDupId, GDB_SI_LIST, vnRef)) continue ; for ( auto& nId : vnRef) { // verifico esista if ( ! pGeomDB->ExistsObj( nId)) continue ; // verifico sia in un grezzo (previsto solo in uno come massimo) int nMachGrpId = pGeomDB->GetParentId( pGeomDB->GetParentId( pGeomDB->GetParentId( nId))) ; string sMachGrpName ; if ( ExeGetMachGroupName( nMachGrpId, sMachGrpName)) { ++ nCount ; break ; } } } // se in altro gruppo else { // verifico se incluso nel grezzo del gruppo di lavoro corrente (previsto solo in un gruppo) if ( ExeIsRawPart( pGeomDB->GetParentId( nDupId))) ++ nCount ; } } return true ; } //----------------------------------------------------------------------------- bool ExeDuploWithoutRawList( INTVECTOR& vnDup) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Reset del risultato vnDup.clear() ; // Recupero gruppo dei duplo int nDuploBaseId = GetDuploBase( pGeomDB) ; if ( nDuploBaseId == GDB_ID_NULL) return true ; // Ciclo sui duplo for ( int nDuploId = pGeomDB->GetFirstGroupInGroup( nDuploBaseId) ; nDuploId != GDB_ID_NULL ; nDuploId = pGeomDB->GetNextGroup( nDuploId)) { // se marcatore if ( pGeomDB->ExistsInfo( nDuploId, GDB_SI_SOURCE)) { int nPartId = GDB_ID_NULL ; pGeomDB->GetInfo( nDuploId, GDB_SI_SOURCE, nPartId) ; int nMachGrpId = pGeomDB->GetParentId( pGeomDB->GetParentId( pGeomDB->GetParentId( nPartId))) ; string sMachGrpName ; if ( pGeomDB->ExistsInfo( nPartId, GDB_SI_DUPSOU) && ExeGetMachGroupName( nMachGrpId, sMachGrpName)) continue ; } // se vero duplo else if ( pGeomDB->ExistsInfo( nDuploId, GDB_SI_DUPSOU) && pGeomDB->ExistsInfo( nDuploId, GDB_SI_LIST)) { // verifico sia incluso in un grezzo di un gruppo di lavoro bool bFound = false ; INTVECTOR vnRef ; pGeomDB->GetInfo( nDuploId, GDB_SI_LIST, vnRef) ; for ( auto& nId : vnRef) { // verifico sia in un grezzo (previsto solo in uno come massimo) int nMachGrpId = pGeomDB->GetParentId( pGeomDB->GetParentId( pGeomDB->GetParentId( nId))) ; string sMachGrpName ; if ( ExeGetMachGroupName( nMachGrpId, sMachGrpName)) { bFound = true ; break ; } } if ( bFound) continue ; } // inserisco nella lista dei duplo senza grezzo vnDup.emplace_back( nDuploId) ; } return true ; } //----------------------------------------------------------------------------- bool ExeDuploSetModified( int nSouId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia un pezzo if ( ! IsPartForDuplo( pGeomDB, nSouId)) return false ; // Verifico ci siano dei duplicati che dipendono dal pezzo if ( ! pGeomDB->ExistsInfo( nSouId, GDB_SI_DUPLIST)) return true ; // Imposto il flag di modificato if ( ! pGeomDB->SetInfo( nSouId, GDB_SI_DUPMODIF, true)) return false ; // Dichiaro progetto modificato ExeSetModified() ; return true ; } //----------------------------------------------------------------------------- bool ExeDuploGetModified( int nSouId, bool& bModif) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia un pezzo if ( ! IsPartForDuplo( pGeomDB, nSouId)) return false ; // recupero il flag di modificato if ( ! pGeomDB->GetInfo( nSouId, GDB_SI_DUPMODIF, bModif)) bModif = false ; return true ; } //----------------------------------------------------------------------------- bool ExeDuploSetLocked( int nDupId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia un duplo if ( ! ExeIsDuplo( nDupId)) return false ; // Imposto il flag di bloccato if ( ! pGeomDB->SetInfo( nDupId, GDB_SI_DUPLOCKED, true)) return false ; // Dichiaro progetto modificato ExeSetModified() ; return true ; } //----------------------------------------------------------------------------- bool ExeDuploResetLocked( int nDupId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia nel gruppo base dei duplicati o scambiato con un gruppo da esso int nDuploBaseId = GetDuploBase( pGeomDB) ; if ( nDuploBaseId == GDB_ID_NULL) return false ; int nDBaseId = GDB_ID_NULL ; if ( pGeomDB->GetParentId( nDupId) != nDuploBaseId) { if ( ! pGeomDB->GetInfo( nDupId, GDB_SI_BASE, nDBaseId) || pGeomDB->GetParentId( nDBaseId) != nDuploBaseId) return false ; } // Verifico abbia un sorgente int nOrigId ; if ( ! pGeomDB->GetInfo( nDupId, GDB_SI_DUPSOU, nOrigId) || pGeomDB->GetGdbType( nOrigId) != GDB_TY_GROUP) return false ; // Verifico bloccaggio bool bLocked ; if ( ! pGeomDB->GetInfo( nDupId, GDB_SI_DUPLOCKED, bLocked)) bLocked = false ; pGeomDB->RemoveInfo( nDupId, GDB_SI_DUPLOCKED) ; if ( ! bLocked) return true ; // Verifico necessità di aggiornamento bool bToUpdate ; if ( ! pGeomDB->GetInfo( nDupId, GDB_SI_DUPTOUPDATE, bToUpdate)) bToUpdate = false ; pGeomDB->RemoveInfo( nDupId, GDB_SI_DUPTOUPDATE) ; if ( ! bToUpdate) { // Dichiaro progetto modificato ExeSetModified() ; return true ; } // Eseguo aggiornamento int nDStat = GDB_ST_ON ; if ( nDBaseId != GDB_ID_NULL) { pGeomDB->GetStatus( nDupId, nDStat) ; pGeomDB->GroupSwap( nDupId, nDBaseId, true, true) ; } // recupero il riferimento del vecchio duplo Frame3d frCopy ; pGeomDB->GetGroupFrame( nDupId, frCopy) ; // aggiorno pGeomDB->Erase( nDupId) ; int nNewId = pGeomDB->Copy( nOrigId, nDupId, nDuploBaseId) ; if ( nNewId == GDB_ID_NULL) return false ; // riapplico il riferimento vecchio *pGeomDB->GetGroupFrame( nNewId) = frCopy ; // sistemo le info pGeomDB->SetInfo( nNewId, GDB_SI_DUPSOU, nOrigId) ; pGeomDB->RemoveInfo( nNewId, GDB_SI_DUPLIST) ; pGeomDB->RemoveInfo( nNewId, GDB_SI_DUPMODIF) ; // Se necessario rieseguo swap al contrario if ( nDBaseId != GDB_ID_NULL) { pGeomDB->SetStatus( nNewId, nDStat) ; pGeomDB->GroupSwap( nNewId, nDBaseId, true, true) ; } // Dichiaro progetto modificato ExeSetModified() ; return true ; } //----------------------------------------------------------------------------- bool ExeDuploGetLocked( int nDupId, bool& bLocked) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia un duplo if ( ! ExeIsDuplo( nDupId)) return false ; // Recupero il flag di bloccato if ( ! pGeomDB->GetInfo( nDupId, GDB_SI_DUPLOCKED, bLocked)) bLocked = false ; return true ; } //----------------------------------------------------------------------------- bool ExeDuploUpdate( int nSouId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia un pezzo if ( ! IsPartForDuplo( pGeomDB, nSouId)) return false ; // Verifico se modificato da ultimo update bool bModif = false ; pGeomDB->GetInfo( nSouId, GDB_SI_DUPMODIF, bModif) ; if ( ! bModif) return true ; // Recupero il gruppo base dei duplicati int nDuploBaseId = GetDuploBase( pGeomDB) ; if ( nDuploBaseId == GDB_ID_NULL) return false ; // recupero le copie INTVECTOR vnRef ; pGeomDB->GetInfo( nSouId, GDB_SI_DUPLIST, vnRef) ; // verifico siano aggiornabili bool bAllOk = true ; for ( int nCopyId : vnRef) { if ( pGeomDB->GetParentId( nCopyId) != nDuploBaseId) bAllOk = false ; } if ( ! bAllOk) return false ; // eseguo gli aggiornamenti for ( int nCopyId : vnRef) { // se bloccato, non eseguo aggiornamento bool bLocked ; if ( pGeomDB->GetInfo( nCopyId, GDB_SI_DUPLOCKED, bLocked) && bLocked) { pGeomDB->SetInfo( nCopyId, GDB_SI_DUPTOUPDATE, true) ; continue ; } // recupero il riferimento del vecchio duplo Frame3d frCopy ; pGeomDB->GetGroupFrame( nCopyId, frCopy) ; // aggiorno pGeomDB->Erase( nCopyId) ; int nNewId = pGeomDB->Copy( nSouId, nCopyId, nDuploBaseId) ; if ( nNewId == GDB_ID_NULL) { bAllOk = false ; continue ; } // riapplico il riferimento vecchio *pGeomDB->GetGroupFrame( nNewId) = frCopy ; // sistemo le info pGeomDB->SetInfo( nNewId, GDB_SI_DUPSOU, nSouId) ; pGeomDB->RemoveInfo( nNewId, GDB_SI_DUPLIST) ; pGeomDB->RemoveInfo( nNewId, GDB_SI_DUPMODIF) ; } // reset flag di modificato pGeomDB->RemoveInfo( nSouId, GDB_SI_DUPMODIF) ; // Dichiaro progetto modificato ExeSetModified() ; return bAllOk ; } //----------------------------------------------------------------------------- bool ExeIsDuplo( int nDupId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Verifico sia un duplicato bool bPartVsGhost ; return IsDuplo( pGeomDB, nDupId, bPartVsGhost) ; } //----------------------------------------------------------------------------- int ExeDuploGetOriginal( int nDupId) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, GDB_ID_NULL) // Recupero il gruppo base dei duplicati int nDuploBaseId = GetDuploBase( pGeomDB) ; if ( nDuploBaseId == GDB_ID_NULL) return GDB_ID_NULL ; // Verifico sia un duplicato (gruppo sotto quello dei duplicati con riferimento a originale) if ( pGeomDB->GetGdbType( nDupId) != GDB_TY_GROUP || pGeomDB->GetParentId( nDupId) != nDuploBaseId || ! pGeomDB->ExistsInfo( nDupId, GDB_SI_DUPSOU)) return GDB_ID_NULL ; // Recupero l'indice dell'originale int nOrigId = GDB_ID_NULL ; pGeomDB->GetInfo( nDupId, GDB_SI_DUPSOU, nOrigId) ; return nOrigId ; } //----------------------------------------------------------------------------- bool ExeInsertDuplo( int nInsGrp) { IGeomDB* pGeomDB = GetCurrGeomDB() ; VERIFY_GEOMDB( pGeomDB, false) // Cerco il gruppo dei duplicati sotto il gruppo di inserimento int nInsDplId = pGeomDB->GetFirstNameInGroup( nInsGrp, DUPLO_BASE) ; if ( nInsDplId == GDB_ID_NULL) return true ; // Recupero il gruppo base dei duplicati int nDuploBaseId = GetDuploBase( pGeomDB, true) ; if ( nDuploBaseId == GDB_ID_NULL) return false ; // Sistemo i duplicati int nId = pGeomDB->GetFirstInGroup( nInsDplId) ; while ( nId != GDB_ID_NULL) { int nNextId = pGeomDB->GetNext( nId) ; int nSouId ; if ( pGeomDB->GetInfo( nId, GDB_SI_DUPSOU, nSouId) && ExeIsPart( nSouId)) { pGeomDB->Relocate( nId, nDuploBaseId) ; } else pGeomDB->Erase( nId) ; nId = nNextId ; } // Rimuovo il gruppo dei duplicati di inserimento pGeomDB->Erase( nInsDplId) ; return true ; }