//---------------------------------------------------------------------------- // EgalTech 2015-2015 //---------------------------------------------------------------------------- // File : API_MachMgr.cpp Data : 23.03.15 Versione : 1.6c8 // Contenuto : Funzioni Machining Manager per API. // // // // Modifiche : 23.03.15 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "API.h" #include "API_Macro.h" #include "AuxTools.h" #include "DllMachKernel.h" #include "/EgtDev/Include/EInAPI.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EGnStringConverter.h" #include "/EgtDev/Include/EgtPointerOwner.h" using namespace std ; //----------------------------------------------------------------------------- BOOL __stdcall EgtInitMachMgr( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX( pGseCtx, FALSE) // inizializzazione gestore lavorazioni PtrOwner pMachMgr( MyCreateMachMgr()) ; VERIFY_NULL( Get( pMachMgr), "Error in CreateMachMgr", FALSE) pMachMgr->Init( pGseCtx->m_pGeomDB) ; // assegno il gestore al contesto pGseCtx->m_pMachMgr = Release( pMachMgr) ; // log avvio Machining Manager string sLog = "MachMgr started " ; LOG_INFO( GetLogger(), sLog.c_str()) return TRUE ; } //----------------------------------------------------------------------------- bool EgtUpdateMachMgr( void) { IMachMgr* pMachMgr = GetCurrMachMgr() ; VERIFY_MACHMGR( pMachMgr, false) // aggiornamento gestore lavorazioni return pMachMgr->Update() ; } //----------------------------------------------------------------------------- bool EgtInsertMachMgr( int nInsGrp) { IMachMgr* pMachMgr = GetCurrMachMgr() ; VERIFY_MACHMGR( pMachMgr, false) // sposto le macchinate dal gruppo di inserimento alla base macchinate return pMachMgr->Insert( nInsGrp) ; } //----------------------------------------------------------------------------- int __stdcall EgtGetMachGroupNbr( void) { IMachMgr* pMachMgr = GetCurrMachMgr() ; VERIFY_MACHMGR( pMachMgr, 0) // recupero il numero di macchinate return pMachMgr->GetMachGroupNbr() ; } //----------------------------------------------------------------------------- int __stdcall EgtGetFirstMachGroup( void) { IMachMgr* pMachMgr = GetCurrMachMgr() ; VERIFY_MACHMGR( pMachMgr, GDB_ID_NULL) // recupero la prima macchinata return pMachMgr->GetFirstMachGroup() ; } //----------------------------------------------------------------------------- int __stdcall EgtGetNextMachGroup( int nId) { IMachMgr* pMachMgr = GetCurrMachMgr() ; VERIFY_MACHMGR( pMachMgr, GDB_ID_NULL) // recupero la successiva macchinata return pMachMgr->GetNextMachGroup( nId) ; } //----------------------------------------------------------------------------- int __stdcall EgtAddMachGroup( const wchar_t* wsName, const wchar_t* wsMachineName) { return EgtAddMachGroup( wstrztoA( wsName), wstrztoA( wsMachineName)) ; } //----------------------------------------------------------------------------- int EgtAddMachGroup( const string& sName, const string& sMachineName) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, GDB_ID_NULL) // aggiungo la macchinata (gruppo di lavorazione) int nId = pGseCtx->m_pMachMgr->AddMachGroup( sName, sMachineName) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtAddMachGroup('" + sName + "','" + sMachineName + "')" + " -- Id=" + ToString( nId) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return nId ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtRemoveMachGroup( int nMGroupId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, GDB_ID_NULL) // rimuovo la macchinata (gruppo di lavorazione) bool bOk = pGseCtx->m_pMachMgr->RemoveMachGroup( nMGroupId) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtRemoveMachGroup(" + ToString( nMGroupId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return ( bOk ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetMachGroupName( int nMGroupInd, wchar_t*& wsName) { if ( &wsName == nullptr) return FALSE ; string sName ; if ( ! EgtGetMachGroupName( nMGroupInd, sName)) return FALSE ; wsName = _wcsdup( stringtoW( sName)) ; return (( wsName == nullptr) ? FALSE : TRUE) ; } //----------------------------------------------------------------------------- bool EgtGetMachGroupName( int nId, string& sName) { IMachMgr* pMachMgr = GetCurrMachMgr() ; VERIFY_MACHMGR( pMachMgr, false) // recupero il nome della macchinata sName = pMachMgr->GetMachGroupName( nId) ; return ( ! sName.empty()) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtGetMachGroupId( const wchar_t* wsName) { return EgtGetMachGroupId( wstrztoA( wsName)) ; } //----------------------------------------------------------------------------- int EgtGetMachGroupId( const string& sName) { IMachMgr* pMachMgr = GetCurrMachMgr() ; VERIFY_MACHMGR( pMachMgr, false) // recupero l'indice della macchinata return pMachMgr->GetMachGroupId( sName) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtSetCurrMachGroup( int nMGroupId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, FALSE) // imposto la macchinata corrente bool bOk = pGseCtx->m_pMachMgr->SetCurrMachGroup( nMGroupId) ; // non cambia lo stato di modificato del progetto // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtSetCurrMachGroup(" + ToString( nMGroupId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return ( bOk ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- BOOL __stdcall EgtResetCurrMachGroup( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, FALSE) // reset macchinata corrente bool bOk = pGseCtx->m_pMachMgr->ResetCurrMachGroup() ; // non cambia lo stato di modificato del progetto // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtResetCurrMachGroup()" " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return ( bOk ? TRUE : FALSE) ; } //----------------------------------------------------------------------------- int __stdcall EgtGetCurrMachGroup( void) { IMachMgr* pMachMgr = GetCurrMachMgr() ; VERIFY_MACHMGR( pMachMgr, GDB_ID_NULL) // restituisco identificativo macchinata corrente return pMachMgr->GetCurrMachGroup() ; } //----------------------------------------------------------------------------- int EgtGetRawPartNbr( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // recupero il numero di grezzi nella macchinata corrente return pGseCtx->m_pMachMgr->GetRawPartNbr() ; } //----------------------------------------------------------------------------- int EgtGetFirstRawPart( void) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // recupero identificativo primo grezzo nella macchinata corrente return pGseCtx->m_pMachMgr->GetFirstRawPart() ; } //----------------------------------------------------------------------------- int EgtGetNextRawPart( int nRawId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // recupero identificativo successivo grezzo nella macchinata corrente return pGseCtx->m_pMachMgr->GetNextRawPart( nRawId) ; } //----------------------------------------------------------------------------- int EgtAddRawPart( Point3d ptOrig, double dWidth, double dLength, double dHeight, Color cCol) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, GDB_ID_NULL) // inserisco grezzo nella macchinata corrente int nId = pGseCtx->m_pMachMgr->AddRawPart( ptOrig, dWidth, dLength, dHeight, cCol) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtAddRawPart({" + ToString( ptOrig) + "}," + ToString( dWidth) + "," + ToString( dLength) + "," + ToString( dHeight) + ",{" + ToString( cCol) + "})" + " -- Id=" + ToString( nId) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return nId ; } //----------------------------------------------------------------------------- int EgtAddRawPartWithPart( int nPartId, int nCrvId, double dOverMat, Color cCol) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, GDB_ID_NULL) // inserisco grezzo con pezzo nella macchinata corrente int nId = pGseCtx->m_pMachMgr->AddRawPartWithPart( nPartId, nCrvId, dOverMat, cCol) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtAddRawPartWithPart(" + ToString( nPartId) + "," + ToString( nCrvId) + "," + ToString( dOverMat) + ",{" + ToString( cCol) + "})" + " -- Id=" + ToString( nId) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return nId ; } //----------------------------------------------------------------------------- bool EgtModifyRawPartHeight( int nRawId, double dHeight) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // modifico lo spessore del grezzo bool bOk = pGseCtx->m_pMachMgr->ModifyRawPartHeight( nRawId, dHeight) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtModifyRawPartHeight(" + ToString( nRawId) + "," + ToString( dHeight) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool EgtRemoveRawPart( int nRawId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // elimino grezzo dalla macchinata corrente bool bOk = pGseCtx->m_pMachMgr->RemoveRawPart( nRawId) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtRemoveRawPart(" + ToString( nRawId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool EgtTranslateRawPart( int nRawId, const Vector3d& vtMove) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // traslo il grezzo bool bOk = pGseCtx->m_pMachMgr->TranslateRawPart( nRawId, vtMove) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtMoveRawPart(" + ToString( nRawId) + ",{" + ToString( vtMove) + "})" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool EgtRotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // ruoto il grezzo bool bOk = pGseCtx->m_pMachMgr->RotateRawPart( nRawId, vtAx, dAngRotDeg) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtRotateRawPart(" + ToString( nRawId) + ",{" + ToString( vtAx) + "}," + ToString( dAngRotDeg) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool EgtMoveToCornerRawPart( int nRawId, const Point3d& ptCorner, int nFlag) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // mando il grezzo nel corner bool bOk = pGseCtx->m_pMachMgr->MoveToCornerRawPart( nRawId, ptCorner, nFlag) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtMoveToCornerRawPart(" + ToString( nRawId) + ",{" + ToString( ptCorner) + "}," + RawPartCornerPosToString( nFlag) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool EgtMoveToCenterRawPart( int nRawId, const Point3d& ptCenter, int nFlag) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // mando il grezzo nel corner bool bOk = pGseCtx->m_pMachMgr->MoveToCenterRawPart( nRawId, ptCenter, nFlag) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtMoveToCenterRawPart(" + ToString( nRawId) + ",{" + ToString( ptCenter) + "}," + RawPartCenterPosToString( nFlag) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- int EgtGetPartInRawPartNbr( int nRawId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // recupero il numero di pezzi nel grezzo return pGseCtx->m_pMachMgr->GetPartInRawPartNbr( nRawId) ; } //----------------------------------------------------------------------------- int EgtGetFirstPartInRawPart( int nRawId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // recupero identificativo primo pezzo nel grezzo return pGseCtx->m_pMachMgr->GetFirstPartInRawPart( nRawId) ; } //----------------------------------------------------------------------------- int EgtGetNextPartInRawPart( int nPartId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // recupero identificativo successivo pezzo nello stesso grezzo return pGseCtx->m_pMachMgr->GetNextPartInRawPart( nPartId) ; } //----------------------------------------------------------------------------- bool EgtAddPartToRawPart( int nPartId, const Point3d& ptPos, int nRawId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // inserisco pezzo in un grezzo della macchinata corrente bool bOk = pGseCtx->m_pMachMgr->AddPartToRawPart( nPartId, ptPos, nRawId) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtAddPartToRawPart(" + ToString( nPartId) + ",{" + ToString( ptPos) + "}," + ToString( nRawId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool EgtRemovePartFromRawPart( int nPartId) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // elimino pezzo da grezzo della macchinata corrente bool bOk = pGseCtx->m_pMachMgr->RemovePartFromRawPart( nPartId) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtRemovePartFromRawPart(" + ToString( nPartId) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool EgtTranslatePartInRawPart( int nPartId, const Vector3d& vtMove) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // traslo il pezzo nel grezzo bool bOk = pGseCtx->m_pMachMgr->TranslatePartInRawPart( nPartId, vtMove) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtMovePartInRawPart(" + ToString( nPartId) + ",{" + ToString( vtMove) + "})" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; } //----------------------------------------------------------------------------- bool EgtRotatePartInRawPart( int nPartId, const Vector3d& vtAx, double dAngRotDeg) { GseContext* pGseCtx = GetCurrGseContext() ; VERIFY_CTX_MACHMGR( pGseCtx, false) // ruoto il pezzo nel grezzo bool bOk = pGseCtx->m_pMachMgr->RotatePartInRawPart( nPartId, vtAx, dAngRotDeg) ; pGseCtx->m_bModified = true ; // se richiesto, salvo il comando Lua equivalente if ( IsCmdLog()) { string sLua = "EgtRotatePartInRawPart(" + ToString( nPartId) + ",{" + ToString( vtAx) + "}," + ToString( dAngRotDeg) + ")" + " -- Ok=" + ToString( bOk) ; LOG_INFO( GetCmdLogger(), sLua.c_str()) ; } // restituisco il risultato return bOk ; }