diff --git a/CamData.cpp b/CamData.cpp index a52a9b3..e01c73b 100644 --- a/CamData.cpp +++ b/CamData.cpp @@ -77,6 +77,8 @@ CamData::Clone( void) const pCam->m_nAxesMask = m_nAxesMask ; pCam->m_vMachAxes = m_vMachAxes ; pCam->m_ptMachCen = m_ptMachCen ; + pCam->m_dMachRad = m_dMachRad ; + pCam->m_dMachAngCen = m_dMachAngCen ; } catch( ...) { delete pCam ; @@ -460,6 +462,7 @@ CamData::CamData( void) m_nAxesMask = 0x00 ; m_vMachAxes.reserve( 8) ; m_dMachRad = 0 ; + m_dMachAngCen = 0 ; } //---------------------------------------------------------------------------- diff --git a/Disposition.cpp b/Disposition.cpp index 3443d37..a27e4e6 100644 --- a/Disposition.cpp +++ b/Disposition.cpp @@ -1,8 +1,8 @@ //---------------------------------------------------------------------------- -// EgalTech 2015-2015 +// EgalTech 2015-2016 //---------------------------------------------------------------------------- -// File : Drilling.cpp Data : 21.05.15 Versione : 1.6e7 -// Contenuto : Implementazione gestione forature. +// File : Drilling.cpp Data : 29.04.16 Versione : 1.6p4 +// Contenuto : Implementazione gestione disposizione. // // // @@ -16,8 +16,8 @@ #include "MachMgr.h" #include "DllMain.h" #include "Disposition.h" -#include "Table.h" #include "/EgtDev/Include/EMkDispositionConst.h" +#include "/EgtDev/Include/EGkAngle.h" #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EGkUserObjFactory.h" #include "/EgtDev/Include/EGnStringKeyVal.h" @@ -40,6 +40,9 @@ static std::string DIS_MVD_TYPE = "MvT" ; static std::string DIS_MVD_PNT = "MvP" ; static std::string DIS_MVD_ANG = "MvA" ; static std::string DIS_MVD_FLAG = "MvF" ; +static std::string DIS_NUM = "NUM" ; +static std::string DIS_HEAD = "Head" ; +static std::string DIS_EXIT = "Exit" ; //---------------------------------------------------------------------------- USEROBJ_REGISTER( "EMkDisposition", Disposition) ; @@ -65,6 +68,9 @@ Disposition::Clone( void) const pDisp->m_bTabOk = m_bTabOk ; pDisp->m_vFixData = m_vFixData ; pDisp->m_vMvrData = m_vMvrData ; + pDisp->m_sHead = m_sHead ; + pDisp->m_nExit = m_nExit ; + pDisp->m_nShifts = m_nShifts ; } catch( ...) { delete pDisp ; @@ -107,6 +113,9 @@ Disposition::Dump( string& sOut, bool bMM, const char* szNewLine) const break ; } } + sOut += "Num=" + ToString( m_nShifts) + szNewLine ; + sOut += "Head=" + m_sHead + szNewLine ; + sOut += "Exit=" + ToString( m_nExit) + szNewLine ; return true ; } @@ -120,7 +129,8 @@ Disposition::Save( STRVECTOR& vString) const int nFxdLines = 1 + 3 * nFxdTot ; int nMvdTot = int( m_vMvrData.size()) ; int nMvdLines = 1 + 4 * nMvdTot ; - vString.insert( vString.begin(), 4 + nFxdLines + nMvdLines, "") ; + int nOther = 3 ; + vString.insert( vString.begin(), 4 + nFxdLines + nMvdLines + nOther, "") ; // Nome if ( ! SetVal( DIS_TABLE, m_sTabName, vString[++k])) return false ; @@ -152,6 +162,13 @@ Disposition::Save( STRVECTOR& vString) const ! SetVal( DIS_MVD_FLAG, MvrData.nFlag, vString[++k])) return false ; } + // altri dati + if ( ! SetVal( DIS_NUM, m_nShifts, vString[++k])) + return false ; + if ( ! SetVal( DIS_HEAD, m_sHead, vString[++k])) + return false ; + if ( ! SetVal( DIS_EXIT, m_nExit, vString[++k])) + return false ; } catch( ...) { return false ; } return true ; @@ -206,53 +223,27 @@ Disposition::Load( const STRVECTOR& vString) ! GetVal( vString[++k], DIS_MVD_FLAG, MvrData.nFlag)) return false ; } + // altri dati aggiuntivi + if ( k + 1 < int( vString.size())) { + if ( ! GetVal( vString[++k], DIS_NUM, m_nShifts)) + return false ; + } + if ( k + 1 < int( vString.size())) { + if ( ! GetVal( vString[++k], DIS_HEAD, m_sHead)) + return false ; + } + if ( k + 1 < int( vString.size())) { + if ( ! GetVal( vString[++k], DIS_EXIT, m_nExit)) + return false ; + } return true ; } -//---------------------------------------------------------------------------- -bool -Disposition::SetOwner( int nId, IGeomDB* pGDB) -{ - m_nOwnerId = nId ; - m_pGeomDB = pGDB ; - return ( m_nOwnerId != GDB_ID_NULL && m_pGeomDB != nullptr) ; -} - -//---------------------------------------------------------------------------- -int -Disposition::GetOwner( void) const -{ - return m_nOwnerId ; -} - -//---------------------------------------------------------------------------- -IGeomDB* -Disposition::GetGeomDB( void) const -{ - return m_pGeomDB ; -} - //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- Disposition::Disposition( void) + : m_bTabOk( false), m_nExit( 0), m_nShifts( 0) { - m_nOwnerId = GDB_ID_NULL ; - m_pGeomDB = nullptr ; - m_pMchMgr = nullptr ; - m_bTabOk = false ; - m_nPhase = 1 ; -} - -//---------------------------------------------------------------------------- -bool -Disposition::Init( MachMgr* pMchMgr) -{ - m_pMchMgr = pMchMgr ; - if ( m_pMchMgr == nullptr) - return false ; - if ( m_pMchMgr->GetGeomDB() != m_pGeomDB) - return false ; - return true ; } //---------------------------------------------------------------------------- @@ -272,12 +263,10 @@ Disposition::SetTable( const string& sTable) if ( ! pMch->SetCurrTable( sTable)) return false ; // recupero il primo riferimento e l'area utile della tavola - Table* pTab = pMch->GetTable( sTable) ; - if ( pTab == nullptr) - return false ; Point3d ptPrevRef1 = m_ptRef1 ; - m_ptRef1 = pTab->GetRef1() ; - m_b3Area1 = pTab->GetArea1() ; + if ( ! pMch->GetCurrTableRef1( m_ptRef1) || + ! pMch->GetCurrTableArea1( m_b3Area1)) + return false ; if ( ! m_sTabName.empty() && EqualNoCase( m_sTabName, sTable) && ! AreSamePointApprox( ptPrevRef1, m_ptRef1)) { string sOut = "Table Ref1 changed : (" + ToString( ptPrevRef1) + ") -> (" + ToString( m_ptRef1) +")" ; @@ -771,3 +760,103 @@ Disposition::GetMoveRawData( int nInd, int& nRawId, int& nType, Point3d& ptPos, nFlag = m_vMvrData[nInd].nFlag ; return true ; } + +//---------------------------------------------------------------------------- +bool +Disposition::SpecialApply( bool bRecalc) +{ + // reset + m_sHead.empty() ; + m_nExit = 0 ; + m_nShifts = 0 ; + // verifico tavola + if ( ! m_bTabOk && ! SetTable( m_sTabName)) + return false ; + // recupero la macchina corrente + Machine* pMch = m_pMchMgr->GetCurrMachine() ; + if ( pMch == nullptr) + return false ; + // costanti + static const string EMC_VAR = "EMC" ; // tabella variabili locali per calcolo + static const string EVAR_TABNAME = ".TABNAME" ; // IN (string) nome della tavola macchina + static const string EVAR_DISPID = ".DISPID" ; // IN (int) identificativo della disposizione + static const string EVAR_ERROR = ".ERR" ; // OUT (int) codice di errore ( 0 = ok) + static const string EVAR_HEAD = ".HEAD" ; // OUT (string) nome della testa + static const string EVAR_EXIT = ".EXIT" ; // OUT (int) indice dell'uscita + static const string EVAR_SHIFTS = ".SHIFTS" ; // OUT (int) numero di movimenti eseguiti + static const string ON_SPECIAL_APPLY = "OnSpecialApplyDisposition" ; + + // eseguo l'azione + if ( pMch->LuaExistsFunction( ON_SPECIAL_APPLY)) { + bool bOk = true ; + int nErr = 99 ; + // imposto valori parametri + bOk = bOk && pMch->LuaCreateGlobTable( EMC_VAR) ; + bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_TABNAME, m_sTabName) ; + bOk = bOk && pMch->LuaSetGlobVar( EMC_VAR + EVAR_DISPID, m_nOwnerId) ; + // eseguo + bOk = bOk && pMch->LuaCallFunction( ON_SPECIAL_APPLY) ; + // recupero valori parametri + bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_ERROR, nErr) ; + bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_HEAD, m_sHead) ; + bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_EXIT, m_nExit) ; + bOk = bOk && pMch->LuaGetGlobVar( EMC_VAR + EVAR_SHIFTS, m_nShifts) ; + bOk = bOk && pMch->LuaResetGlobVar( EMC_VAR) ; + // segnalo errori + if ( nErr != 0) { + bOk = false ; + string sOut = " Error in " + ON_SPECIAL_APPLY + " (" + ToString( nErr) + ")" ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) + } + // se disposizione vuota, esco + if ( m_nShifts == 0) + return bOk ; + // calcolo assi macchina + bOk = bOk && CalculateAxesValues() ; + // gestione movimenti all'inizio di ogni singolo percorso di lavorazione e alla fine di tutti + bOk = bOk && AdjustStartEndMovements() ; + return bOk ; + } + else + return true ; +} + +//---------------------------------------------------------------------------- +bool +Disposition::GetToolData( string& sName, string& sHead, int& nExit) const +{ + sName = "" ; + sHead = m_sHead ; + nExit = m_nExit ; + return true ; +} + +//---------------------------------------------------------------------------- +const string& +Disposition::GetToolName( void) const +{ + static string sDummy = "" ; + return sDummy ; +} + +//---------------------------------------------------------------------------- +const string& +Disposition::GetHeadName( void) const +{ + return m_sHead ; +} + +//---------------------------------------------------------------------------- +int +Disposition::GetExitNbr( void) const +{ + return m_nExit ; +} + +//---------------------------------------------------------------------------- +const string& +Disposition::GetToolTcPos( void) const +{ + static string sDummy = "" ; + return sDummy ; +} diff --git a/Disposition.h b/Disposition.h index 2fc2312..2588655 100644 --- a/Disposition.h +++ b/Disposition.h @@ -13,10 +13,7 @@ #pragma once -#include "/EgtDev/Include/EGkPoint3d.h" -#include "/EgtDev/Include/EGkUserObj.h" -#include "/EgtDev/Include/EgtNumCollection.h" -#include +#include "Operation.h" //---------------------------------------------------------------------------- struct FixtureData @@ -48,7 +45,7 @@ struct MoveRawData typedef std::vector MVRDATAVECTOR ; //---------------------------------------------------------------------------- -class Disposition : public IUserObj +class Disposition : public Operation { public : // IUserObj Disposition* Clone( void) const override ; @@ -58,17 +55,23 @@ class Disposition : public IUserObj { return true ; } bool Save( STRVECTOR& vString) const override ; bool Load( const STRVECTOR& vString) override ; - bool SetOwner( int nId, IGeomDB* pGDB) override ; - int GetOwner( void) const override ; - IGeomDB* GetGeomDB( void) const override ; + + public : // Operation + bool IsEmpty( void) const override + { return ( m_nShifts == 0) ; } + + protected : // Operation + const std::string& GetToolName( void) const ; + const std::string& GetHeadName( void) const ; + int GetExitNbr( void) const ; + const std::string& GetToolTcPos( void) const ; + bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override + { return true ; } public : Disposition( void) ; - bool Init( MachMgr* pMchMgr) ; - bool SetPhase( int nPhase) - { m_nPhase = nPhase ; return true ; } - int GetPhase( void) const - { return m_nPhase ; } + + public : bool SetTable( const std::string& sTable) ; bool Apply( void) ; bool IsSetTableName( void) const @@ -88,22 +91,23 @@ class Disposition : public IUserObj bool RemoveRawPart( int nRawId) ; bool GetFixtureData( int nInd, std::string& sName, int& nId, Point3d& ptPos, double& dAngDeg) const ; bool GetMoveRawData( int nInd, int& nRawId, int& nType, Point3d& ptPos, int& nFlag) const ; + bool SpecialApply( bool bRecalc) ; + bool GetToolData( string& sName, string& sHead, int& nExit) const ; private : bool VerifyFixture( int nFixtId) const ; bool VerifyRawPart( int nRawId) const ; private : - int m_nOwnerId ; - IGeomDB* m_pGeomDB ; - MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni + bool m_bTabOk ; // flag di tavola verificata std::string m_sTabName ; // nome della tavola di appartenenza Point3d m_ptRef1 ; // origine 1 della tavola BBox3d m_b3Area1 ; // area utile 1 della tavola - bool m_bTabOk ; // flag di tavola verificata - int m_nPhase ; // indice della fase di appartenenza (da 1 in su) FIXDATAVECTOR m_vFixData ; // elenco posizionamento bloccaggi MVRDATAVECTOR m_vMvrData ; // elenco movimenti grezzi + std::string m_sHead ; // eventuale testa usata per muovere i pezzi + int m_nExit ; // eventuale uscita sulla testa + int m_nShifts ; // numero eventuali spostamenti con testa } ; //---------------------------------------------------------------------------- diff --git a/Drilling.h b/Drilling.h index d16ee61..851a556 100644 --- a/Drilling.h +++ b/Drilling.h @@ -33,6 +33,13 @@ class Drilling : public Machining bool Save( STRVECTOR& vString) const override ; bool Load( const STRVECTOR& vString) override ; + public : // Operation + bool IsEmpty( void) const override + { return ( m_nDrillings == 0) ; } + + protected : // Operation + bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; + public : // Machining bool Prepare( const std::string& sDriName) override ; bool SetParam( int nType, bool bVal) override ; @@ -48,9 +55,6 @@ class Drilling : public Machining bool GetParam( int nType, std::string& sVal) const override ; const ToolData& GetToolData( void) const override ; bool GetGeometry( SELVECTOR& vIds) const override ; - bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; - bool IsEmpty( void) const override - { return ( m_nDrillings == 0) ; } public : Drilling( void) ; diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index d3d6f1d..4011316 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/EgtMachKernel.vcxproj b/EgtMachKernel.vcxproj index 3202924..3dc7f23 100644 --- a/EgtMachKernel.vcxproj +++ b/EgtMachKernel.vcxproj @@ -227,6 +227,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -244,6 +245,7 @@ copy $(TargetPath) \EgtProg\Dll64 + @@ -289,6 +291,8 @@ copy $(TargetPath) \EgtProg\Dll64 + + diff --git a/EgtMachKernel.vcxproj.filters b/EgtMachKernel.vcxproj.filters index ad9840a..49aa9cf 100644 --- a/EgtMachKernel.vcxproj.filters +++ b/EgtMachKernel.vcxproj.filters @@ -168,6 +168,12 @@ Source Files\Operations + + Source Files\Machine + + + Source Files\Operations + @@ -287,6 +293,12 @@ Header Files + + Header Files + + + Header Files + diff --git a/Generator.cpp b/Generator.cpp index 1c7a722..98862fa 100644 --- a/Generator.cpp +++ b/Generator.cpp @@ -19,6 +19,7 @@ #include "Disposition.h" #include "Machining.h" #include "MachiningConst.h" +#include "OutputConst.h" #include "/EgtDev/Include/EMkToolConst.h" #include "/EgtDev/Include/EMkOperationConst.h" #include "/EgtDev/Include/EGkStringUtils3d.h" @@ -29,84 +30,6 @@ using namespace std ; //---------------------------------------------------------------------------- static const string ERR_EXT = ".err" ; static const int MAX_AXES = 5 ; -static const string GLOB_VAR = "EMT" ; // tavola variabili globali -static const string GVAR_USETO1 = ".USETO1" ; // (bool) flag per utilizzo origine tavola -static const string GVAR_MODAL = ".MODAL" ; // (bool) flag per emissione modale dei valori -static const string GVAR_NUM = ".NUM" ; // (bool) flag numerazione -static const string GVAR_NUMTOK = ".Nt" ; // (string) token per numerazione -static const string GVAR_LINENBR = ".LINENBR" ; // (int) numero progressivo di linea -static const string GVAR_LINEINC = ".LINEINC" ; // (int) incremento per numero di linea -static const string GVAR_F = ".F" ; // (num) valore della feed -static const string GVAR_FT = ".Ft" ; // (string) token per feed -static const string GVAR_S = ".S" ; // (num) valore della speed -static const string GVAR_ST = ".St" ; // (string) token per speed -static const string GVAR_FILE = ".FILE" ; // (string) path file di output -static const string GVAR_INFO = ".INFO" ; // (string) informazioni iniziali -static const string GVAR_DISPID = ".DISPID" ; // (int) identificativo disposizione -static const string GVAR_DISPIND = ".DISPIND" ; // (int) indice disposizione -static const string GVAR_PHASE = ".PHASE" ; // (int) indice fase -static const string GVAR_TABNAME = ".TABNAME" ; // (string) nome tavola -static const string GVAR_TABORI1 = ".TABORI1" ; // (Point3d) prima origine di tavola -static const string GVAR_FIXID = ".FIXID" ; // (int) identificativo bloccaggio (fixture) -static const string GVAR_FIXIND = ".FIXIND" ; // (int) indice bloccaggio -static const string GVAR_FIXNAME = ".FIXNAME" ; // (string) nome bloccaggio -static const string GVAR_FIXPOS = ".FIXPOS" ; // (Point3d) posizione bloccaggio -static const string GVAR_FIXANG = ".FIXANG" ; // (num) angolo di rotazione bloccaggio -static const string GVAR_RAWID = ".RAWID" ; // (int) identificativo grezzo -static const string GVAR_RAWIND = ".RAWIND" ; // (int) indice movimento del grezzo -static const string GVAR_RAWTYPE = ".RAWTYPE" ; // (int) tipo di movimento del grezzo -static const string GVAR_RAWPOS = ".RAWPOS" ; // (Point3d) posizione di movimento del grezzo -static const string GVAR_RAWFLAG = ".RAWFLAG" ; // (int) flag per movimento del grezzo -static const string GVAR_MCHID = ".MCHID" ; // (int) identificativo lavorazione -static const string GVAR_MCHIND = ".MCHIND" ; // (int) indice lavorazione -static const string GVAR_PATHID = ".PATHID" ; // (int) identificativo percorso di lavorazione -static const string GVAR_PATHIND = ".PATHIND" ; // (int) indice percorso di lavorazione -static const string GVAR_MOVE = ".MOVE" ; // (int) tipo di movimento (0,1,2,3) -static const string GVAR_L1 = ".L1" ; // (num) valore del primo asse lineare -static const string GVAR_L2 = ".L2" ; // (num) valore del secondo asse lineare -static const string GVAR_L3 = ".L3" ; // (num) valore del terzo asse lineare -static const string GVAR_R1 = ".R1" ; // (num) valore del primo asse rotante -static const string GVAR_R2 = ".R2" ; // (num) valore del secondo asse rotante -static const string GVAR_C1 = ".C1" ; // (num) valore del primo asse lineare per centro arco -static const string GVAR_C2 = ".C2" ; // (num) valore del secondo asse lineare per centro arco -static const string GVAR_C3 = ".C3" ; // (num) valore del terzo asse lineare per centro arco -static const string GVAR_RR = ".RR" ; // (num) valore raggio per arco -static const string GVAR_AC = ".AC" ; // (num) valore angolo al centro per arco -static const string GVAR_L1P = ".L1p" ; // (num) valore precedente del primo asse lineare -static const string GVAR_L2P = ".L2p" ; // (num) valore precedente del secondo asse lineare -static const string GVAR_L3P = ".L3p" ; // (num) valore precedente del terzo asse lineare -static const string GVAR_R1P = ".R1p" ; // (num) valore precedente del primo asse rotante -static const string GVAR_R2P = ".R2p" ; // (num) valore precedente del secondo asse rotante -static const string GVAR_L1T = ".L1t" ; // (num) token del primo asse lineare -static const string GVAR_L2T = ".L2t" ; // (num) token del secondo asse lineare -static const string GVAR_L3T = ".L3t" ; // (num) token del terzo asse lineare -static const string GVAR_R1T = ".R1t" ; // (num) token del primo asse rotante -static const string GVAR_R2T = ".R2t" ; // (num) token del secondo asse rotante -static const string GVAR_C1T = ".C1t" ; // (num) token del primo asse lineare per centro arco -static const string GVAR_C2T = ".C2t" ; // (num) token del secondo asse lineare per centro arco -static const string GVAR_C3T = ".C3t" ; // (num) token del terzo asse lineare per centro arco -static const string GVAR_RRT = ".RRt" ; // (num) token del raggio per arco -static const string GVAR_MASK = ".MASK" ; // (int) mask associato ai movimenti in rapido -static const string GVAR_FLAG = ".FLAG" ; // (int) flag associato ad ogni movimento -static const string ON_START = "OnStart" ; -static const string ON_END = "OnEnd" ; -static const string ON_PROGRAM_START = "OnProgramStart" ; -static const string ON_PROGRAM_END = "OnProgramEnd" ; -static const string ON_TOOL_SELECT = "OnToolSelect" ; -static const string ON_TOOL_DESELECT = "OnToolDeselect" ; -static const string ON_DISPOSITION_START = "OnDispositionStart" ; -static const string ON_DISPOSITION_END = "OnDispositionEnd" ; -static const string ON_TABLE_DATA = "OnTableData" ; -static const string ON_FIXTURE_DATA = "OnFixtureData" ; -static const string ON_RAWMOVE_DATA = "OnRawMoveData" ; -static const string ON_MACHINING_START = "OnMachiningStart" ; -static const string ON_MACHINING_END = "OnMachiningEnd" ; -static const string ON_PATH_START = "OnPathStart" ; -static const string ON_PATH_END = "OnPathEnd" ; -static const string ON_RAPID = "OnRapid" ; -static const string ON_LINEAR = "OnLinear" ; -static const string ON_ARC = "OnArc" ; - //---------------------------------------------------------------------------- Generator::Generator( void) @@ -161,7 +84,7 @@ Generator::Run( const string& sCncFile, const std::string& sInfo) // evento inizio esecuzione bool bOk = true ; - if ( bOk && ! OnStart()) { + if ( ! OnStart()) { bOk = false ; LOG_INFO( GetEMkLogger(), "OnStart error") ; } @@ -212,7 +135,7 @@ Generator::Run( const string& sCncFile, const std::string& sInfo) RenameFile( sCncFile, sErrFile) ; // evento fine esecuzione - if ( bOk && ! OnEnd()) { + if ( ! OnEnd()) { bOk = false ; LOG_INFO( GetEMkLogger(), "OnEnd error") ; } @@ -232,9 +155,10 @@ Generator::ProcessDisposition( int nOpId, int nOpInd) // Imposto la fase int nPhase = pDisp->GetPhase() ; m_pMchMgr->SetCurrPhase( nPhase) ; + bool bEmpty = pDisp->IsEmpty() ; // Emetto inizio disposizione - if ( ! OnDispositionStart( nOpId, nOpInd, nPhase)) + if ( ! OnDispositionStart( nOpId, nOpInd, nPhase, bEmpty)) return false ; // Emetto dati tavola @@ -273,6 +197,42 @@ Generator::ProcessDisposition( int nOpId, int nOpInd) break ; } + // Se disposizione con movimenti macchina + if ( ! pDisp->IsEmpty()) { + + // Recupero l'utensile della disposizione corrente + string sTool ; string sHead ; int nExit ; + if ( ! pDisp->GetToolData( sTool, sHead, nExit)) + return false ; + // Se utensile cambierà + if ( ! m_sTool.empty() && m_sTool != sTool) { + // emetto deselezione vecchio utensile + if ( ! OnToolDeselect()) + return false ; + } + // Aggiorno utensile e assi macchina + if ( ! UpdateDispTool( sTool, sHead, nExit) || ! UpdateAxes()) + return false ; + // Se utensile cambiato, emetto selezione nuovo utensile + if ( m_sTool != m_sPrevTool) { + if ( ! OnToolSelect()) + return false ; + } + // Ciclo su tutti i percorsi CL della disposizione + bool bOk = true ; + int nClPathInd = 0 ; + int nClId = m_pGeomDB->GetFirstNameInGroup( nOpId, MCH_CL) ; + int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + while ( bOk && nClPathId != GDB_ID_NULL) { + ++ nClPathInd ; + // processo il percorso di lavoro + if ( ! ProcessClPath( nClPathId, nClPathInd, nOpId, nOpInd)) + bOk = false ; + // passo al percorso successivo + nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ; + } + } + // Emetto fine disposizione if ( ! OnDispositionEnd()) return false ; @@ -420,6 +380,22 @@ Generator::UpdateTool( const string& sTool) return true ; } +//---------------------------------------------------------------------------- +bool +Generator::UpdateDispTool( const string& sTool, const string& sHead, int nExit) +{ + // Salvo l'utensile attuale come precedente + m_sPrevTool = m_sTool ; + // Se cambiato ... + if ( sTool != m_sTool) { + // lo carico in macchina + if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) + return false ; + m_sTool = sTool ; + } + return true ; +} + //---------------------------------------------------------------------------- bool Generator::UpdateAxes( void) @@ -458,6 +434,8 @@ Generator::OnEnd( void) { // chiamo la funzione bool bOk = m_pMachine->LuaCallFunction( ON_END) ; + // rimuovo tavola variabili globali + bOk = m_pMachine->LuaResetGlobVar( GLOB_VAR) && bOk ; return bOk ; } @@ -490,13 +468,15 @@ Generator::OnProgramEnd( void) //---------------------------------------------------------------------------- bool -Generator::OnDispositionStart( int nOpId, int nOpInd, int nPhase) +Generator::OnDispositionStart( int nOpId, int nOpInd, int nPhase, bool bEmpty) { // assegno identificativo e indice disposizione bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_DISPID, nOpId) ; bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_DISPIND, nOpInd) ; // assegno nuovo indice di fase bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PHASE, nPhase) ; + // assegno flag disposizione passiva + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_EMPTY, bEmpty) ; // chiamo la funzione di inizio disposizione bOk = bOk && m_pMachine->LuaCallFunction( ON_DISPOSITION_START) ; return bOk ; diff --git a/Generator.h b/Generator.h index 51fd760..07b1bb4 100644 --- a/Generator.h +++ b/Generator.h @@ -34,6 +34,7 @@ class Generator bool ProcessClPath( int nClPathId, int nClPathInd, int nOpId, int nOpInd) ; bool ProcessClEnt( int nEntId, int nEntInd, int nClPathId, int nClPathInd, int nOpId, int nOpInd) ; bool UpdateTool( const std::string& sTool) ; + bool UpdateDispTool( const std::string& sTool, const std::string& sHead, int nExit) ; bool UpdateAxes( void) ; bool OnStart( void) ; bool OnEnd( void) ; @@ -41,7 +42,7 @@ class Generator bool OnProgramEnd( void) ; bool OnToolSelect( void) ; bool OnToolDeselect( void) ; - bool OnDispositionStart( int nOpId, int nOpInd, int nPhase) ; + bool OnDispositionStart( int nOpId, int nOpInd, int nPhase, bool bEmpty) ; bool OnDispositionEnd( void) ; bool OnTableData( const std::string& sName, const Point3d& ptOri1) ; bool OnFixtureData( int nFixId, int nFixInd, const std::string& sName, diff --git a/MachMgr.h b/MachMgr.h index 66995ec..62f3233 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -106,7 +106,6 @@ class MachMgr : public IMachMgr bool TranslatePartInRawPart( int nPartId, const Vector3d& vtMove) override ; bool RotatePartInRawPart( int nPartId, const Vector3d& vtAx, double dAngRotDeg) override ; // Tables and Fixtures - bool ExistsTable( const std::string& sTable) override ; bool SetTable( const std::string& sTable) override ; bool GetTableRef( int nInd, Point3d& ptPos) override ; bool GetTableArea( int nInd, BBox3d& b3Area) override ; @@ -171,6 +170,7 @@ class MachMgr : public IMachMgr int GetOperationPhase( int nId) const override ; std::string GetOperationName( int nId) const override ; int GetOperationId( const std::string& sName) const override ; + bool IsOperationEmpty( int nId) const override ; bool RemoveOperation( int nId) override ; bool RemoveAllPhaseOperations( int nPhase) override ; bool RemoveAllOperations( void) override ; @@ -183,6 +183,7 @@ class MachMgr : public IMachMgr bool ChangeOperationPhase( int nMchId, int nNewPhase) override ; // Operations : dispositions int GetPhaseDisposition( int nPhase) const override ; + bool DispositionSpecialApply( int nId, bool bRecalc) override ; // Operations : machinings int AddMachining( const std::string& sName, const std::string& sMachining) override ; int AddMachining( const std::string& sName, int nMchType, const std::string& sTool) override ; @@ -195,6 +196,8 @@ class MachMgr : public IMachMgr bool SetMachiningParam( int nType, const std::string& sVal) override ; bool SetMachiningGeometry( const SELVECTOR& vIds) override ; bool MachiningPreview( bool bRecalc) override ; + bool ExistsMachiningPreview( void) override ; + bool RemoveMachiningPreview( void) override ; bool MachiningApply( bool bRecalc) override ; bool GetMachiningParam( int nType, bool& bVal) const override ; bool GetMachiningParam( int nType, int& dVal) const override ; @@ -209,6 +212,7 @@ class MachMgr : public IMachMgr bool SimGetToolInfo( std::string& sName, double& dSpeed) override ; bool SimGetMoveInfo( int& nGmove, double& dFeed) override ; bool SimSetStep( double dStep) override ; + bool SimGoHome( void) override ; bool SimStop( void) override ; // Generation bool Generate( const std::string& sCncFile, const std::string& sInfo) override ; @@ -226,10 +230,14 @@ class MachMgr : public IMachMgr bool GetNearestAngleInStroke( int nId, double dAngRef, double& dAng) override ; bool VerifyOutstroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) override ; const std::string& GetOutstrokeInfo( void) const override ; - // Machine Move + // Machine + int GetBaseId( const std::string& sBase) const override ; + int GetTableId( const std::string& sTable) const override ; + int GetAxisId( const std::string& sAxis) const override ; + int GetHeadId( const std::string& sHead) const override ; bool SetAxisPos( const std::string& sAxis, double dVal) override ; - bool GetAxisPos( const std::string& sAxis, double& dVal) override ; - bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) override ; + bool GetAxisPos( const std::string& sAxis, double& dVal) const override ; + bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) const override ; bool ResetAxisPos( const std::string& sAxis) override ; bool ResetAllAxesPos( void) override ; bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) override ; @@ -298,7 +306,7 @@ class MachMgr : public IMachMgr // Machines bool LoadMachine( const std::string& sMachineName) ; int GetMachine( const std::string& sMachineName) const ; - int GetCurrMGeoId( void) const ; + int GetCurrMachineId( void) const ; // Phases bool PrepareCurrPhase( int nPhase, bool bDoDisp) ; int CalcPhaseCount( void) const ; diff --git a/MachMgrFixtures.cpp b/MachMgrFixtures.cpp index fdc5bb5..8d36a64 100644 --- a/MachMgrFixtures.cpp +++ b/MachMgrFixtures.cpp @@ -23,18 +23,6 @@ using namespace std ; -//---------------------------------------------------------------------------- -bool -MachMgr::ExistsTable( const string& sTable) -{ - // recupero la macchina corrente - Machine* pMch = GetCurrMachine() ; - if ( pMch == nullptr) - return false ; - // verifico esistenza della tavola nella macchina corrente - return ( pMch->GetTable( sTable) != nullptr) ; -} - //---------------------------------------------------------------------------- bool MachMgr::SetTable( const string& sTable) diff --git a/MachMgrMachGroups.cpp b/MachMgrMachGroups.cpp index a4fc3be..12eb1c7 100644 --- a/MachMgrMachGroups.cpp +++ b/MachMgrMachGroups.cpp @@ -139,7 +139,7 @@ MachMgr::AddMachGroup( const string& sName, const string& sMachineName) ShowRootParts( false) ; // rendo visibile il nuovo gruppo corrente e la relativa macchina m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_ON) ; - m_pGeomDB->SetStatus( GetCurrMGeoId(), GDB_ST_ON) ; + m_pGeomDB->SetStatus( GetCurrMachineId(), GDB_ST_ON) ; // restituisco l'identificativo del gruppo return nNewId ; } @@ -278,7 +278,7 @@ MachMgr::SetCurrMachGroup( int nId) ShowRootParts( false) ; // rendo visibile il nuovo gruppo corrente e la relativa macchina m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_ON) ; - m_pGeomDB->SetStatus( GetCurrMGeoId(), GDB_ST_ON) ; + m_pGeomDB->SetStatus( GetCurrMachineId(), GDB_ST_ON) ; return true ; } @@ -307,7 +307,7 @@ MachMgr::PrepareCurrMachGroup( int nId) SwapParts( false) ; // nascondo precedente gruppo corrente e la relativa macchina m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_OFF) ; - m_pGeomDB->SetStatus( GetCurrMGeoId(),GDB_ST_OFF) ; + m_pGeomDB->SetStatus( GetCurrMachineId(),GDB_ST_OFF) ; } // imposto i dati del nuovo gruppo corrente m_nCurrMGrpId = nId ; @@ -340,7 +340,7 @@ MachMgr::ResetCurrMachGroup( void) ShowRootParts( true) ; // nascondo gruppo corrente e la relativa macchina m_pGeomDB->SetStatus( m_nCurrMGrpId, GDB_ST_OFF) ; - m_pGeomDB->SetStatus( GetCurrMGeoId(), GDB_ST_OFF) ; + m_pGeomDB->SetStatus( GetCurrMachineId(), GDB_ST_OFF) ; // dichiaro nessun gruppo e lavorazione correnti, lascio corrente la macchina m_nCurrMGrpId = GDB_ID_NULL ; m_nCurrMachiningId = GDB_ID_NULL ; diff --git a/MachMgrMachines.cpp b/MachMgrMachines.cpp index 872b7d7..1f04ae1 100644 --- a/MachMgrMachines.cpp +++ b/MachMgrMachines.cpp @@ -94,22 +94,13 @@ MachMgr::SetCurrMachine( const string& sMachineName) bool MachMgr::GetCurrMachineName( string& sMachineName) const { - if ( GetCurrMachine() == nullptr) + Machine* pMch = GetCurrMachine() ; + if ( pMch == nullptr) return false ; - sMachineName = GetCurrMachine()->GetMachineName() ; + sMachineName = pMch->GetMachineName() ; return true ; } -//---------------------------------------------------------------------------- -int -MachMgr::GetCurrMGeoId( void) const -{ - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return GDB_ID_NULL ; - return m_vMachines[m_nCurrMch].pMachine->GetMGeoId() ; -} - //---------------------------------------------------------------------------- Machine* MachMgr::GetCurrMachine( void) const @@ -137,154 +128,169 @@ MachMgr::GetCurrMachiningsMgr( void) const return m_vMachines[m_nCurrMch].pMsMgr ; } +//---------------------------------------------------------------------------- +int +MachMgr::GetCurrMachineId( void) const +{ + Machine* pMch = GetCurrMachine() ; + // restituisco identificativo della radice della geometria della macchina corrente + return ( ( pMch != nullptr) ? pMch->GetMachineId() : GDB_ID_NULL) ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetBaseId( const string& sBase) const +{ + Machine* pMch = GetCurrMachine() ; + // restituisco identificativo della base indicata nella macchina corrente + return ( ( pMch != nullptr) ? pMch->GetBaseId( sBase) : GDB_ID_NULL) ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetTableId( const string& sTable) const +{ + Machine* pMch = GetCurrMachine() ; + // restituisco identificativo della tavola indicata nella macchina corrente + return ( ( pMch != nullptr) ? pMch->GetTableId( sTable) : GDB_ID_NULL) ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetAxisId( const string& sAxis) const +{ + Machine* pMch = GetCurrMachine() ; + // restituisco identificativo dell'asse indicato nella macchina corrente + return ( ( pMch != nullptr) ? pMch->GetAxisId( sAxis) : GDB_ID_NULL) ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetHeadId( const string& sHead) const +{ + Machine* pMch = GetCurrMachine() ; + // restituisco identificativo della testa indicata nella macchina corrente + return ( ( pMch != nullptr) ? pMch->GetHeadId( sHead) : GDB_ID_NULL) ; +} + //---------------------------------------------------------------------------- bool MachMgr::SetAxisPos( const string& sAxis, double dVal) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return GDB_ID_NULL ; - return m_vMachines[m_nCurrMch].pMachine->SetAxisPos( sAxis, dVal) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->SetAxisPos( sAxis, dVal) : false) ; } //---------------------------------------------------------------------------- bool -MachMgr::GetAxisPos( const string& sAxis, double& dVal) +MachMgr::GetAxisPos( const string& sAxis, double& dVal) const { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return GDB_ID_NULL ; - return m_vMachines[m_nCurrMch].pMachine->GetAxisPos( sAxis, dVal) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetAxisPos( sAxis, dVal) : false) ; } //---------------------------------------------------------------------------- bool -MachMgr::GetAxisHomePos( const string& sAxis, double& dHomeVal) +MachMgr::GetAxisHomePos( const string& sAxis, double& dHomeVal) const { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return GDB_ID_NULL ; - return m_vMachines[m_nCurrMch].pMachine->GetAxisHomePos( sAxis, dHomeVal) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetAxisHomePos( sAxis, dHomeVal) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::ResetAxisPos( const string& sAxis) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return GDB_ID_NULL ; - return m_vMachines[m_nCurrMch].pMachine->ResetAxisPos( sAxis) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->ResetAxisPos( sAxis) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::ResetAllAxesPos( void) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return GDB_ID_NULL ; - return m_vMachines[m_nCurrMch].pMachine->ResetAllAxesPos() ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->ResetAllAxesPos() : false) ; } //---------------------------------------------------------------------------- bool MachMgr::LoadTool( const string& sHead, int nExit, const string& sTool) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->LoadTool( sHead, nExit, sTool) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->LoadTool( sHead, nExit, sTool) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::ResetHeadSet( const string& sHead) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->ResetHeadSet( sHead) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->ResetHeadSet( sHead) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::SetCalcTable( const string& sTable) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->SetCurrTable( sTable) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->SetCurrTable( sTable) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::SetCalcTool( const string& sTool, const string& sHead, int nExit) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->SetCurrTool( sTool, sHead, nExit) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->SetCurrTool( sTool, sHead, nExit) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::GetCalcTool( string& sTool) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->GetCurrTool( sTool) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetCurrTool( sTool) : false) ; } //---------------------------------------------------------------------------- double MachMgr::GetCalcRot1W( void) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return 1 ; - return m_vMachines[m_nCurrMch].pMachine->GetCurrRot1W() ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetCurrRot1W() : false) ; } //---------------------------------------------------------------------------- int MachMgr::GetCurrLinAxes( void) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return 0 ; - return m_vMachines[m_nCurrMch].pMachine->GetCurrLinAxes() ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetCurrLinAxes() : false) ; } //---------------------------------------------------------------------------- int MachMgr::GetCurrRotAxes( void) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return 0 ; - return m_vMachines[m_nCurrMch].pMachine->GetCurrRotAxes() ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetCurrRotAxes() : false) ; } //---------------------------------------------------------------------------- bool MachMgr::GetAllCurrAxesName( STRVECTOR& vAxName) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->GetAllCurrAxesName( vAxName) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetAllCurrAxesName( vAxName) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::GetAllCalcAxesHomePos( DBLVECTOR& vAxHomeVal) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->GetAllCurrAxesHomePos( vAxHomeVal) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetAllCurrAxesHomePos( vAxHomeVal) : false) ; } //---------------------------------------------------------------------------- @@ -292,10 +298,8 @@ bool MachMgr::GetCalcAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->GetAngles( vtDirT, vtDirA, nStat, dAngA1, dAngB1, dAngA2, dAngB2) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetAngles( vtDirT, vtDirA, nStat, dAngA1, dAngB1, dAngA2, dAngB2) : false) ; } //---------------------------------------------------------------------------- @@ -303,10 +307,8 @@ bool MachMgr::GetCalcPositions( const Point3d& ptP, double dAngA, double dAngB, int& nStat, double& dX, double& dY, double& dZ) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->GetPositions( ptP, dAngA, dAngB, nStat, dX, dY, dZ) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetPositions( ptP, dAngA, dAngB, nStat, dX, dY, dZ) : false) ; } //---------------------------------------------------------------------------- @@ -314,61 +316,50 @@ bool MachMgr::GetCalcTipFromPositions( double dX, double dY, double dZ, double dAngA, double dAngB, bool bBottom, Point3d& ptTip) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->GetTipFromPositions( dX, dY, dZ, dAngA, dAngB, bBottom, ptTip) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetTipFromPositions( dX, dY, dZ, dAngA, dAngB, bBottom, ptTip) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::GetCalcToolDirFromAngles( double dAngA, double dAngB, Vector3d& vtDir) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->GetToolDirFromAngles( dAngA, dAngB, vtDir) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetToolDirFromAngles( dAngA, dAngB, vtDir) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::GetNearestAngleInStroke( int nId, double dAngRef, double& dAng) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->GetNearestAngleInStroke( nId, dAngRef, dAng) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->GetNearestAngleInStroke( nId, dAngRef, dAng) : false) ; } //---------------------------------------------------------------------------- bool MachMgr::VerifyOutstroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) - return false ; - return m_vMachines[m_nCurrMch].pMachine->VerifyOutstroke( dX, dY, dZ, dAngA, dAngB, nStat) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->VerifyOutstroke( dX, dY, dZ, dAngA, dAngB, nStat) : false) ; } //---------------------------------------------------------------------------- const std::string& MachMgr::GetOutstrokeInfo( void) const { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) { + Machine* pMch = GetCurrMachine() ; + if ( pMch == nullptr) { static string sNull = "" ; return sNull ; } - return m_vMachines[m_nCurrMch].pMachine->GetOutstrokeInfo() ; + return pMch->GetOutstrokeInfo() ; } //---------------------------------------------------------------------------- bool MachMgr::SetMachineLook( int nFlag) { - if ( m_nCurrMch < 0 || m_nCurrMch >= int( m_vMachines.size()) || - m_vMachines[m_nCurrMch].pMachine == nullptr) { - return false ; - } - return m_vMachines[m_nCurrMch].pMachine->SetLook( nFlag) ; + Machine* pMch = GetCurrMachine() ; + return ( ( pMch != nullptr) ? pMch->SetLook( nFlag) : false) ; } diff --git a/MachMgrOperations.cpp b/MachMgrOperations.cpp index 2e23368..ddfe372 100644 --- a/MachMgrOperations.cpp +++ b/MachMgrOperations.cpp @@ -272,6 +272,37 @@ MachMgr::GetOperationId( const string& sName) const return GDB_ID_NULL ; } +//---------------------------------------------------------------------------- +bool +MachMgr::IsOperationEmpty( int nId) const +{ + // recupero l'operazione + PtrOwner pIter( CreateGdbIterator( m_pGeomDB)) ; + if ( IsNull( pIter) || ! pIter->GoTo( nId)) + return true ; + // verifico che il gruppo ricevuto sia corretto + if ( pIter->GetParentId() != GetCurrOperId()) + return true ; + // recupero user object + IUserObj* pUserObj = pIter->GetUserObj() ; + if ( pUserObj == nullptr) + return true ; + // se disposizione + if ( pUserObj->GetClassName() == USEROBJ_GETNAME( Disposition)) { + const Disposition* pDisp = ::GetDisposition( pUserObj) ; + if ( pDisp != nullptr) + return pDisp->IsEmpty() ; + } + // altrimenti lavorazione + else { + const Machining* pMch = GetMachining( pUserObj) ; + if ( pMch != nullptr) + return pMch->IsEmpty() ; + } + // errore + return true ; +} + //---------------------------------------------------------------------------- bool MachMgr::RemoveOperation( int nId) @@ -515,6 +546,18 @@ MachMgr::GetPhaseDisposition( int nPhase) const return GDB_ID_NULL ; } +//---------------------------------------------------------------------------- +bool +MachMgr::DispositionSpecialApply( int nId, bool bRecalc) +{ + // recupero la disposizione + Disposition* pDisp = ::GetDisposition( m_pGeomDB->GetUserObj( nId)) ; + if ( pDisp == nullptr) + return false ; + // lancio l'azione + return pDisp->SpecialApply( bRecalc) ; +} + //---------------------------------------------------------------------------- // Machinings //---------------------------------------------------------------------------- @@ -744,6 +787,36 @@ MachMgr::MachiningPreview( bool bRecalc) return pMch->Preview( bRecalc) ; } +//---------------------------------------------------------------------------- +bool +MachMgr::ExistsMachiningPreview( void) +{ + // recupero la lavorazione corrente (verifica anche GeomDB) + int nCurrMchId = GetCurrMachining() ; + if ( nCurrMchId == GDB_ID_NULL) + return false ; + // se esiste gruppo di preview, lo svuoto + int nPvId = m_pGeomDB->GetFirstNameInGroup( nCurrMchId, MCH_PV) ; + if ( nPvId == GDB_ID_NULL) + return false ; + return ( m_pGeomDB->GetGroupObjs( nPvId) > 0) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::RemoveMachiningPreview( void) +{ + // recupero la lavorazione corrente (verifica anche GeomDB) + int nCurrMchId = GetCurrMachining() ; + if ( nCurrMchId == GDB_ID_NULL) + return false ; + // se esiste gruppo di preview, lo svuoto + int nPvId = m_pGeomDB->GetFirstNameInGroup( nCurrMchId, MCH_PV) ; + if ( nPvId == GDB_ID_NULL) + return true ; + return m_pGeomDB->EmptyGroup( nPvId) ; +} + //---------------------------------------------------------------------------- bool MachMgr::MachiningApply( bool bRecalc) @@ -863,11 +936,11 @@ MachMgr::IsMachiningEmpty( void) const // recupero la lavorazione corrente int nCurrMchId = GetCurrMachining() ; if ( nCurrMchId == GDB_ID_NULL) - return false ; + return true ; // ne recupero il gestore Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) - return false ; + return true ; // restituisco lo stato return pMch->IsEmpty() ; } diff --git a/MachMgrSimulation.cpp b/MachMgrSimulation.cpp index fd56e3a..965fe0d 100644 --- a/MachMgrSimulation.cpp +++ b/MachMgrSimulation.cpp @@ -94,6 +94,17 @@ MachMgr::SimSetStep( double dStep) return m_pSimul->SetStep( dStep) ; } +//---------------------------------------------------------------------------- +bool +MachMgr::SimGoHome( void) +{ + // verifico simulatore + if ( m_pSimul == nullptr) + return false ; + // eseguo movimento in home + return m_pSimul->GoHome() ; +} + //---------------------------------------------------------------------------- bool MachMgr::SimStop( void) diff --git a/Machine.cpp b/Machine.cpp index d6e23f5..3a6bb20 100644 --- a/Machine.cpp +++ b/Machine.cpp @@ -24,6 +24,7 @@ #include "/EgtDev/Include/EGkStringUtils3d.h" #include "/EgtDev/Include/EGnFileUtils.h" #include "/EgtDev/Include/EgtPointerOwner.h" +#include using namespace std ; @@ -143,7 +144,7 @@ Machine::LoadMachineGeometry( const string& sMGeoName, const Vector3d& vtOffset) //---------------------------------------------------------------------------- bool -Machine::LoadMachineBase( const string& sName, const string& sGeo) +Machine::LoadMachineBase( const string& sName, const string& sGeo, const STRVECTOR& vsAux) { // recupero pezzo e layer della geometria originale della base string sPart, sLay ; @@ -154,18 +155,42 @@ Machine::LoadMachineBase( const string& sName, const string& sGeo) if ( nLay == GDB_ID_NULL) return false ; // lo sposto nella radice della macchina - if ( ! m_pGeomDB->RelocateGlob( nLay, m_nGroupId, GDB_FIRST_SON)) + if ( ! m_pGeomDB->RelocateGlob( nLay, m_nGroupId, GDB_LAST_SON)) return false ; // gli assegno il nome m_pGeomDB->SetName( nLay, sName) ; + // sistemo la geometria ausiliaria + if ( ! AdjustAuxGeometry( vsAux, nLay)) + return false ; // lo inserisco nel dizionario dei gruppi della macchina return m_mapGroups.emplace( sName, nLay).second ; } +//---------------------------------------------------------------------------- +bool +Machine::AdjustAuxGeometry( const STRVECTOR& vsAux, int nLay) +{ + // sistemo la geometria ausiliaria + for ( const auto& sAux : vsAux) { + // recupero pezzo e layer della geometria ausiliaria della base + string sAuxPart, sAuxLay ; + Split( sAux, "/", true, sAuxPart, sAuxLay) ; + // cerco il gruppo nella geometria originale + int nAuxPart = m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sAuxPart) ; + int nAuxLay = m_pGeomDB->GetFirstNameInGroup( nAuxPart, sAuxLay) ; + if ( nAuxLay == GDB_ID_NULL) + return false ; + // lo sposto nel gruppo della base + if ( ! m_pGeomDB->RelocateGlob( nAuxLay, nLay, GDB_LAST_SON)) + return false ; + } + return true ; +} + //---------------------------------------------------------------------------- bool Machine::LoadMachineTable( const string& sName, const string& sParent, int nType, - const Point3d& ptRef1, const string& sGeo) + const Point3d& ptRef1, const string& sGeo, const STRVECTOR& vsAux) { // recupero pezzo e layer della geometria originale della tavola string sPart, sLay ; @@ -178,10 +203,13 @@ Machine::LoadMachineTable( const string& sName, const string& sParent, int nType // cerco il gruppo padre per spostarvelo int nParentId = GetGroup( sParent) ; if ( nParentId == GDB_ID_NULL || - ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON)) + ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_LAST_SON)) return false ; // gli assegno il nome m_pGeomDB->SetName( nLay, sName) ; + // sistemo la geometria ausiliaria + if ( ! AdjustAuxGeometry( vsAux, nLay)) + return false ; // aggiusto la posizione della tavola if ( ! AdjustTablePos( nLay, ptRef1)) return false ; @@ -234,7 +262,7 @@ Machine::AdjustTablePos( int nLay, const Point3d& ptRef1) bool Machine::LoadMachineAxis( const string& sName, const string& sParent, int nType, const Point3d& ptPos, const Vector3d& vtDir, - const STROKE& Stroke, const string& sGeo, double dHome) + const STROKE& Stroke, double dHome, const string& sGeo, const STRVECTOR& vsAux) { // verifico sia di tipo ammesso if ( nType != MCH_AT_LINEAR && nType != MCH_AT_ROTARY) { @@ -255,7 +283,7 @@ Machine::LoadMachineAxis( const string& sName, const string& sParent, int nType, // cerco il gruppo padre per spostarvelo int nParentId = GetGroup( sParent) ; if ( nParentId == GDB_ID_NULL || - ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON)) { + ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_LAST_SON)) { string sOut = " Missing Parent Group " + sParent ; LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; return false ; @@ -267,6 +295,9 @@ Machine::LoadMachineAxis( const string& sName, const string& sParent, int nType, } // gli assegno il nome m_pGeomDB->SetName( nLay, sName) ; + // sistemo la geometria ausiliaria + if ( ! AdjustAuxGeometry( vsAux, nLay)) + return false ; // installo e inizializzo il gestore dell'asse Axis* pAxis = new(nothrow) Axis ; if ( pAxis == nullptr) @@ -391,7 +422,8 @@ Machine::ModifyMachineAxisHome( const string& sName, double dHome) bool Machine::LoadMachineStdHead( const string& sName, const string& sParent, const std::string& sHSet, const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, - double dRot1W, const STROKE& Rot2Stroke, int nSolCh, const string& sGeo) + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, + const string& sGeo, const STRVECTOR& vsAux) { // recupero pezzo e layer della geometria originale dell'asse string sPart, sLay ; @@ -404,13 +436,16 @@ Machine::LoadMachineStdHead( const string& sName, const string& sParent, const s // cerco il gruppo padre per spostarvelo int nParentId = GetGroup( sParent) ; if ( nParentId == GDB_ID_NULL || - ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON)) + ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_LAST_SON)) return false ; // sistemo lo stato di visualizzazione bool bShow = ( sHSet == sName) ; m_pGeomDB->SetStatus( nLay, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ; // gli assegno il nome m_pGeomDB->SetName( nLay, sName) ; + // sistemo la geometria ausiliaria + if ( ! AdjustAuxGeometry( vsAux, nLay)) + return false ; // installo e inizializzo il gestore della testa Head* pHead = new(nothrow) Head ; if ( pHead == nullptr) @@ -420,9 +455,12 @@ Machine::LoadMachineStdHead( const string& sName, const string& sParent, const s // aggiorno la testa capostipite if ( ! AddHeadToSet( sHSet, sName)) return false ; - // trasformazione del riferimento di uscita in gruppo di uscita + // sistemo il riferimento dell'uscita rispetto alla direzione ausiliaria MUEXITVECTOR vMuExit ; vMuExit.emplace_back( ptPos, vtTDir) ; + if ( ! AdjustExitFrames( nLay, vMuExit, vtADir)) + return false ; + // trasformazione del riferimento di uscita in gruppo di uscita if ( ! CreateExitGroups( nLay, vMuExit)) return false ; // lo inserisco nel dizionario dei gruppi della macchina @@ -433,7 +471,8 @@ Machine::LoadMachineStdHead( const string& sName, const string& sParent, const s bool Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const std::string& sHSet, const MUEXITVECTOR& vMuExit, const Vector3d& vtADir, - double dRot1W, const STROKE& Rot2Stroke, int nSolCh, const string& sGeo) + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, + const string& sGeo, const STRVECTOR& vsAux) { // recupero pezzo e layer della geometria originale dell'asse string sPart, sLay ; @@ -446,13 +485,16 @@ Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const // cerco il gruppo padre per spostarvelo int nParentId = GetGroup( sParent) ; if ( nParentId == GDB_ID_NULL || - ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_FIRST_SON)) + ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_LAST_SON)) return false ; // sistemo lo stato di visualizzazione bool bShow = ( sHSet == sName) ; m_pGeomDB->SetStatus( nLay, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ; // gli assegno il nome m_pGeomDB->SetName( nLay, sName) ; + // sistemo la geometria ausiliaria + if ( ! AdjustAuxGeometry( vsAux, nLay)) + return false ; // installo e inizializzo il gestore della testa Head* pHead = new(nothrow) Head ; if ( pHead == nullptr) @@ -462,6 +504,9 @@ Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const // aggiorno la testa capostipite if ( ! AddHeadToSet( sHSet, sName)) return false ; + // sistemo i riferimenti delle uscite rispetto alla direzione ausiliaria + if ( ! AdjustExitFrames( nLay, vMuExit, vtADir)) + return false ; // trasformazione dei riferimenti di uscita in gruppi di uscita if ( ! CreateExitGroups( nLay, vMuExit)) return false ; @@ -469,6 +514,55 @@ Machine::LoadMachineMultiHead( const string& sName, const string& sParent, const return m_mapGroups.emplace( sName, nLay).second ; } +//---------------------------------------------------------------------------- +bool +Machine::LoadMachineSpecialHead( const string& sName, const string& sParent, const std::string& sHSet, + const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, + const string& sGeo, const STRVECTOR& vsAux) +{ + // recupero pezzo e layer della geometria originale della testa + string sPart, sLay ; + Split( sGeo, "/", true, sPart, sLay) ; + // cerco il gruppo nella geometria originale + int nPart = m_pGeomDB->GetFirstNameInGroup( m_nTempGroupId, sPart) ; + int nLay = m_pGeomDB->GetFirstNameInGroup( nPart, sLay) ; + if ( nLay == GDB_ID_NULL) + return false ; + // cerco il gruppo padre per spostarvelo + int nParentId = GetGroup( sParent) ; + if ( nParentId == GDB_ID_NULL || + ! m_pGeomDB->RelocateGlob( nLay, nParentId, GDB_LAST_SON)) + return false ; + // sistemo lo stato di visualizzazione + bool bShow = ( sHSet == sName) ; + m_pGeomDB->SetStatus( nLay, ( bShow ? GDB_ST_ON : GDB_ST_OFF)) ; + // gli assegno il nome + m_pGeomDB->SetName( nLay, sName) ; + // sistemo la geometria ausiliaria + if ( ! AdjustAuxGeometry( vsAux, nLay)) + return false ; + // installo e inizializzo il gestore della testa + Head* pHead = new(nothrow) Head ; + if ( pHead == nullptr) + return false ; + pHead->Set( sName, MCH_HT_SPECIAL, sHSet, vtADir, dRot1W, Rot2Stroke, nSolCh) ; + m_pGeomDB->SetUserObj( nLay, pHead) ; + // aggiorno la testa capostipite + if ( ! AddHeadToSet( sHSet, sName)) + return false ; + // sistemo il riferimento dell'uscita rispetto alla direzione ausiliaria + MUEXITVECTOR vMuExit ; + vMuExit.emplace_back( ptPos, vtTDir) ; + if ( ! AdjustExitFrames( nLay, vMuExit, vtADir)) + return false ; + // trasformazione del riferimento di uscita in gruppo di uscita + if ( ! CreateExitGroups( nLay, vMuExit)) + return false ; + // lo inserisco nel dizionario dei gruppi della macchina + return m_mapGroups.emplace( sName, nLay).second ; +} + //---------------------------------------------------------------------------- int Machine::GetGroup( const string& sGroup) const @@ -477,6 +571,23 @@ Machine::GetGroup( const string& sGroup) const return (( Iter != m_mapGroups.end()) ? Iter->second : GDB_ID_NULL) ; } +//---------------------------------------------------------------------------- +bool +Machine::IsBaseGroup( int nGroup) const +{ + if ( m_pGeomDB == nullptr) + return false ; + // deve essere nel primo gruppo della macchina + return ( m_pGeomDB->GetParentId( nGroup) == m_nGroupId) ; +} + +//---------------------------------------------------------------------------- +Table* +Machine::GetTable( int nGroup) const +{ + return ( dynamic_cast( m_pGeomDB->GetUserObj( nGroup))) ; +} + //---------------------------------------------------------------------------- Axis* Machine::GetAxis( int nGroup) const @@ -500,13 +611,6 @@ Machine::IsRotaryAxisGroup( int nGroup) const return ( pAx != nullptr && pAx->GetType() == MCH_AT_ROTARY) ; } -//---------------------------------------------------------------------------- -Table* -Machine::GetTable( int nGroup) const -{ - return ( dynamic_cast( m_pGeomDB->GetUserObj( nGroup))) ; -} - //---------------------------------------------------------------------------- Head* Machine::GetHead( int nGroup) const @@ -574,6 +678,46 @@ Machine::EnableHeadInSet( const string& sHead) return true ; } +//---------------------------------------------------------------------------- +bool +Machine::AdjustExitFrames( int nLay, const MUEXITVECTOR& vMuExit, const Vector3d& vtADir) +{ + // se il versore ausiliario non è definito, non sono necessari controlli + if ( vtADir.IsSmall()) + return true ; + // riferimento globale del gruppo testa + Frame3d frHead ; + m_pGeomDB->GetGroupGlobFrame( nLay, frHead) ; + // porto il vettore ausiliario nel riferimento testa + Vector3d vtAuxL = vtADir ; + vtAuxL.ToLoc( frHead) ; + // ciclo sulle uscite + for ( int i = 0 ; i < int( vMuExit.size()) ; ++ i) { + string sName = MCH_EXIT + ToString( i + 1) ; + // se trovo riferimento per uscita, lo verifico + int nT = m_pGeomDB->GetFirstNameInGroup( nLay, sName) ; + if ( nT != GDB_ID_NULL && m_pGeomDB->GetGeoType( nT) == GEO_FRAME3D) { + // recupero frame + IGeoFrame3d* pGF = GetGeoFrame3d( m_pGeomDB->GetGeoObj( nT)) ; + Frame3d frFrame = pGF->GetFrame() ; + // determino rotazione attorno a RifAxZ per massimo allineamento RifAxX con direzione ausiliaria + bool bDet ; + double dAngRotDeg ; + if ( frFrame.VersX().GetRotation( vtAuxL, frFrame.VersZ(), dAngRotDeg, bDet) && bDet) { + if ( abs( dAngRotDeg) > EPS_ANG_SMALL) { + frFrame.Rotate( frFrame.Orig(), frFrame.VersZ(), dAngRotDeg) ; + pGF->Set( frFrame) ; + } + } + else { + string sOut = " Exit " + sName + " with frame not adjustable for AuxDir" ; + LOG_ERROR( GetEMkLogger(), sOut.c_str()) ; + } + } + } + return true ; +} + //---------------------------------------------------------------------------- bool Machine::CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) @@ -583,7 +727,7 @@ Machine::CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) m_pGeomDB->GetGroupGlobFrame( nLay, frHead) ; // ciclo sulle uscite for ( int i = 0 ; i < int( vMuExit.size()) ; ++ i) { - string sName = MCH_EXIT + ToString( i+1) ; + string sName = MCH_EXIT + ToString( i + 1) ; // se trovo riferimento per uscita, lo sostituisco con gruppo equivalente int nT = m_pGeomDB->GetFirstNameInGroup( nLay, sName) ; if ( nT != GDB_ID_NULL && m_pGeomDB->GetGeoType( nT) == GEO_FRAME3D) { @@ -653,7 +797,7 @@ Machine::SetLook( int nFlag) return false ; // recupero l'identificativo del gruppo di base della macchina - int nMBaseId = m_pGeomDB->GetFirstInGroup( GetMGeoId()) ; + int nMBaseId = m_pGeomDB->GetFirstInGroup( GetMachineId()) ; // recupero la tavola corrente int nTabId = GetCurrTable() ; @@ -674,15 +818,17 @@ Machine::SetLook( int nFlag) nParentId = m_pGeomDB->GetParentId( nParentId) ; } - // recupero l'utensile corrente + // recupero l'utensile e l'uscita correnti (per gestire casi senza utensile) int nToolId = GetCurrTool() ; + int nExitId = m_nCalcExitId ; // nascondo o visualizzo i fratelli e tutti i fratelli degli ascendenti bool bToolOnly = ( nFlag > MCH_LOOK_TAB && nFlag < MCH_LOOK_ALL) ; - int nToolCurrId = nToolId ; + int nToolCurrId = ( nToolId != GDB_ID_NULL ? nToolId : nExitId) ; nParentId = m_pGeomDB->GetParentId( nToolCurrId) ; while ( nParentId != GDB_ID_NULL && nParentId != nMBaseId) { bool bHide = bToolOnly ; - if ( nFlag == MCH_LOOK_TAB_HEAD) { + if ( nFlag == MCH_LOOK_TAB_HEAD || + ( nFlag == MCH_LOOK_TAB_TOOL && nToolId == GDB_ID_NULL)) { if ( IsHeadGroup( nParentId) || IsRotaryAxisGroup( nParentId)) bHide = false ; } @@ -712,3 +858,64 @@ Machine::SetLook( int nFlag) return true ; } + +//---------------------------------------------------------------------------- +bool +Machine::LinkRawPartToGroup( int nRawPartId, const std::string& sGroupName) +{ + // verifico DB geometrico e gestore lavorazioni + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr) + return false ; + // recupero l'identificativo del gruppo di base dei grezzi + int nRawGrpId = m_pMchMgr->GetCurrRawGroupId() ; + if ( nRawGrpId == GDB_ID_NULL) + return false ; + // verifico che il grezzo appartenga a questo gruppo + if ( m_pGeomDB->GetParentId( nRawPartId) != nRawGrpId) + return false ; + // recupero il gruppo di macchina indicato + int nGrpId = m_pMchLua->GetGroup( sGroupName) ; + if ( nGrpId == GDB_ID_NULL) + return false ; + // aggancio il grezzo al gruppo + if ( ! m_pGeomDB->RelocateGlob( nRawPartId, nGrpId)) + return false ; + // inserisco il grezzo nell'elenco dei linkati + m_vLinkedRawParts.push_back( nRawPartId) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Machine::UnlinkRawPartFromGroup( int nRawPartId) +{ + // verifico DB geometrico e gestore lavorazioni + if ( m_pGeomDB == nullptr || m_pMchMgr == nullptr) + return false ; + // recupero il gruppo dei grezzi dalla macchina + int nRawGrpId = m_pMchLua->m_pMchMgr->GetCurrRawGroupId() ; + if ( nRawGrpId == GDB_ID_NULL) + return false ; + // verifico che il grezzo indicato sia nell'elenco dei linkati + auto iIter = find( m_vLinkedRawParts.begin(), m_vLinkedRawParts.end(), nRawPartId) ; + if ( iIter == m_vLinkedRawParts.end()) + return false ; + // riporto il grezzo nel gruppo dei grezzi + if ( ! m_pMchLua->m_pGeomDB->RelocateGlob( nRawPartId, nRawGrpId)) + return false ; + // tolgo il grezzo dall'elenco dei linkati + m_vLinkedRawParts.erase( iIter) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Machine::UnlinkAllRawPartsFromGroups( void) +{ + while ( m_vLinkedRawParts.size() > 0) { + int nRawId = m_vLinkedRawParts.back() ; + if ( ! UnlinkRawPartFromGroup( nRawId)) + return false ; + } + return true ; +} diff --git a/Machine.h b/Machine.h index 2fa06d9..c336ca8 100644 --- a/Machine.h +++ b/Machine.h @@ -34,43 +34,58 @@ class Machine Machine( void) ; ~Machine( void) ; bool Init( const std::string& sMachinesDir, const std::string& sMachineName, MachMgr* pMchMgr) ; - int GetMGeoId( void) const - { return m_nGroupId ; } const std::string& GetMachineName( void) const { return m_sName ; } - Table* GetTable( const std::string& sTable) const - { return GetTable( GetGroup( sTable)) ; } + int GetMachineId( void) const + { return m_nGroupId ; } + int GetBaseId( const std::string& sBase) const + { int nId = GetGroup( sBase) ; + return ( IsBaseGroup( nId) ? nId : GDB_ID_NULL) ; } + int GetTableId( const std::string& sTable) const + { int nId = GetGroup( sTable) ; + return ( IsTableGroup( nId) ? nId : GDB_ID_NULL) ; } + int GetAxisId( const std::string& sAxis) const + { int nId = GetGroup( sAxis) ; + return ( IsAxisGroup( nId) ? nId : GDB_ID_NULL) ; } + int GetHeadId( const std::string& sHead) const + { int nId = GetGroup( sHead) ; + return ( IsHeadGroup( nId) ? nId : GDB_ID_NULL) ; } bool SetLook( int nFlag) ; bool LoadTool( const std::string& sHead, int nExit, const std::string& sTool) ; bool ResetHeadSet( const std::string& sHead) ; bool SetAxisPos( const std::string& sAxis, double dVal) ; - bool GetAxisPos( const std::string& sAxis, double& dVal) ; - bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) ; + bool GetAxisPos( const std::string& sAxis, double& dVal) const ; + bool GetAxisHomePos( const std::string& sAxis, double& dHomeVal) const ; bool ResetAxisPos( const std::string& sAxis) ; bool ResetAllAxesPos( void) ; bool SetCurrTable( const std::string& sTable) ; - int GetCurrTable( void) ; - bool GetCurrTable( std::string& sTable) ; + int GetCurrTable( void) const ; + bool GetCurrTable( std::string& sTable) const ; + bool GetCurrTableRef1( Point3d& ptRef1) const ; + bool GetCurrTableArea1( BBox3d& b3Area1) const ; bool SetCurrTool( const std::string& sTool, const std::string& sHead, int nExit) ; - int GetCurrTool( void) ; - bool GetCurrTool( std::string& sTool) ; - double GetCurrRot1W( void) ; - std::string GetKinematicAxis( int nInd) ; - int GetCurrLinAxes( void) ; - int GetCurrRotAxes( void) ; - bool GetAllCurrAxesName( STRVECTOR& vAxName) ; - bool GetAllCurrAxesHomePos( DBLVECTOR& vAxHomeVal) ; + int GetCurrTool( void) const ; + bool GetCurrTool( std::string& sTool) const ; + double GetCurrRot1W( void) const ; + std::string GetKinematicAxis( int nInd) const ; + int GetCurrLinAxes( void) const ; + int GetCurrRotAxes( void) const ; + bool GetAllCurrAxesName( STRVECTOR& vAxName) const ; + bool GetAllCurrAxesHomePos( DBLVECTOR& vAxHomeVal) const ; bool GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, - int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) ; + int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) const ; bool GetPositions( const Point3d& ptP, double dA, double dB, - int& nStat, double& dX, double& dY, double& dZ) ; + int& nStat, double& dX, double& dY, double& dZ) const ; bool GetTipFromPositions( double dX, double dY, double dZ, double dAngA, double dAngB, - bool bBottom, Point3d& ptTip) ; - bool GetToolDirFromAngles( double dAngA, double dAngB, Vector3d& vtDir) ; - bool GetNearestAngleInStroke( int nId, double dAngRef, double& dAng) ; - bool VerifyOutstroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) ; + bool bBottom, Point3d& ptTip) const ; + bool GetToolDirFromAngles( double dAngA, double dAngB, Vector3d& vtDir) const ; + bool GetNearestAngleInStroke( int nId, double dAngRef, double& dAng) const ; + bool VerifyOutstroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) const ; const std::string& GetOutstrokeInfo( void) const { return m_sOutstrokeInfo ; } + bool LinkRawPartToGroup( int nRawPartId, const std::string& sGroupName) ; + bool UnlinkRawPartFromGroup( int nRawPartId) ; + bool UnlinkAllRawPartsFromGroups( void) ; bool LuaExistsFunction( const std::string& sFun) ; bool LuaCallFunction( const std::string& sFun) ; bool LuaCreateGlobTable( const std::string& sName) ; @@ -86,24 +101,32 @@ class Machine private : void Clear( void) ; bool LoadMachineGeometry( const std::string& sMGeoName, const Vector3d& vtOffset) ; - bool LoadMachineBase( const std::string& sName, const std::string& sGeo) ; + bool LoadMachineBase( const std::string& sName, const std::string& sGeo, const STRVECTOR& vsAux) ; + bool AdjustAuxGeometry( const STRVECTOR& vsAux, int nLay) ; bool LoadMachineTable( const std::string& sName, const std::string& sParent, int nType, - const Point3d& ptRef1, const std::string& sGeo) ; + const Point3d& ptRef1, const std::string& sGeo, const STRVECTOR& vsAux) ; bool AdjustTablePos( int nLay, const Point3d& ptRef1) ; bool LoadMachineAxis( const std::string& sName, const std::string& sParent, int nType, const Point3d& ptPos, const Vector3d& vtDir, - const STROKE& Stroke, const std::string& sGeo, double dHome) ; + const STROKE& Stroke, double dHome, const std::string& sGeo, const STRVECTOR& vsAux) ; bool AdjustAxisVector( int nLay, const std::string& sPart, const std::string& sName, int nType, const Point3d& ptPos, const Vector3d& vtDir) ; bool ModifyMachineAxisStroke( const std::string& sName, const STROKE& Stroke) ; bool ModifyMachineAxisHome( const std::string& sName, double dHome) ; bool LoadMachineStdHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, - double dRot1W, const STROKE& Rot2Stroke, int nSolCh, const std::string& sGeo) ; + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, + const std::string& sGeo, const STRVECTOR& vsAux) ; bool LoadMachineMultiHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, const MUEXITVECTOR& vMuExit, const Vector3d& vtADir, - double dRot1W, const STROKE& Rot2Stroke, int nSolCh, const std::string& sGeo) ; + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, + const std::string& sGeo, const STRVECTOR& vsAux) ; + bool LoadMachineSpecialHead( const std::string& sName, const std::string& sParent, const std::string& sHSet, + const Point3d& ptPos, const Vector3d& vtTDir, const Vector3d& vtADir, + double dRot1W, const STROKE& Rot2Stroke, int nSolCh, + const std::string& sGeo, const STRVECTOR& vsAux) ; int GetGroup( const std::string& sGroup) const ; + bool IsBaseGroup( int nGroup) const ; Axis* GetAxis( int nGroup) const ; bool IsAxisGroup( int nGroup) const { return ( GetAxis( nGroup) != nullptr) ; } @@ -121,12 +144,13 @@ class Machine bool AddHeadToSet( const std::string& sHSet, const std::string& sName) ; const STRVECTOR& GetHSet( const std::string& sHead) const ; bool EnableHeadInSet( const std::string& sHead) ; + bool AdjustExitFrames( int nLay, const MUEXITVECTOR& vMuExit, const Vector3d& vtADir) ; bool CreateExitGroups( int nLay, const MUEXITVECTOR& vMuExit) ; bool CalculateKinematicChain( void) ; bool AddKinematicAxis( bool bOnHead, int nId) ; - bool GetDirection( const Vector3d& vtDir, double dAngA, double dAngB, Vector3d& vtNew) ; - bool VerifyScc( const Vector3d& vtDirI, const Vector3d& vtDirA, int nSolCh) ; - bool AdjustAngleInStroke( int nId, double& dAng) ; + bool GetDirection( const Vector3d& vtDir, double dAngA, double dAngB, Vector3d& vtNew) const ; + bool VerifyScc( const Vector3d& vtDirI, const Vector3d& vtDirA, int nSolCh) const ; + bool AdjustAngleInStroke( int nId, double& dAng) const ; bool LuaInit( const std::string& sMachineName) ; bool LuaExit( void) ; bool LuaLoadMachine( const std::string& sFile) ; @@ -148,6 +172,7 @@ class Machine STRINT_UMAP m_mapGroups ; // dizionario dei gruppi della macchina double m_dAxisMaxAdjust ; // massimo aggiustamento asse da geometria a descrizione cinematica double m_dExitMaxAdjust ; // massimo aggiustamento uscita da geometria a descrizione cinematica + INTVECTOR m_vLinkedRawParts ; // elenco dei grezzi agganciati a gruppi della macchina // dati di calcolo int m_nCalcTabId ; // tavola corrente per calcoli int m_nCalcHeadId ; // testa corrente per calcoli @@ -162,7 +187,7 @@ class Machine double m_dCalcTRad ; // raggio utensile corrente per calcoli KINAXISVECTOR m_vCalcLinAx ; // vettore assi lineari attivi per calcoli KINAXISVECTOR m_vCalcRotAx ; // vettore assi rotanti attivi per calcoli - std::string m_sOutstrokeInfo ; // informazioni su ultimo extra corsa + mutable std::string m_sOutstrokeInfo ; // informazioni su ultimo extra corsa // Static per interprete Lua di macchina private : @@ -176,8 +201,15 @@ class Machine static int LuaEmtHead( lua_State* L) ; static int LuaEmtStdHead( lua_State* L) ; static int LuaEmtMultiHead( lua_State* L) ; + static int LuaEmtSpecialHead( lua_State* L) ; static int LuaEmtModifyAxisStroke( lua_State* L) ; static int LuaEmtModifyAxisHome( lua_State* L) ; + static int LuaEmtAddRapidStart( lua_State* L) ; + static int LuaEmtAddRapidMove( lua_State* L) ; + static int LuaEmtAddLinearMove( lua_State* L) ; + static int LuaEmtLinkRawPartToGroup( lua_State* L) ; + static int LuaEmtUnlinkRawPartFromGroup( lua_State* L) ; + static int LuaEmtUnlinkAllRawPartsFromGroups( lua_State* L) ; static int LuaEmtWrite( lua_State* L) ; } ; diff --git a/MachineAxes.cpp b/MachineAxes.cpp index 9f1453a..013127a 100644 --- a/MachineAxes.cpp +++ b/MachineAxes.cpp @@ -65,7 +65,7 @@ Machine::SetAxisPos( const string& sAxis, double dVal) //---------------------------------------------------------------------------- bool -Machine::GetAxisPos( const string& sAxis, double& dVal) +Machine::GetAxisPos( const string& sAxis, double& dVal) const { // controllo GeomDB if ( m_pGeomDB == nullptr) @@ -81,7 +81,7 @@ Machine::GetAxisPos( const string& sAxis, double& dVal) //---------------------------------------------------------------------------- bool -Machine::GetAxisHomePos( const string& sAxis, double& dHomeVal) +Machine::GetAxisHomePos( const string& sAxis, double& dHomeVal) const { // controllo GeomDB if ( m_pGeomDB == nullptr) diff --git a/MachineCalc.cpp b/MachineCalc.cpp index ace94ad..dcad448 100644 --- a/MachineCalc.cpp +++ b/MachineCalc.cpp @@ -16,6 +16,7 @@ #include "MachMgr.h" #include "GeoCalc.h" #include "DllMain.h" +#include "Table.h" #include "Axis.h" #include "Head.h" #include "Exit.h" @@ -59,7 +60,7 @@ Machine::SetCurrTable( const string& sTable) //---------------------------------------------------------------------------- int -Machine::GetCurrTable( void) +Machine::GetCurrTable( void) const { // controllo GeomDB if ( m_pGeomDB == nullptr) @@ -70,7 +71,7 @@ Machine::GetCurrTable( void) //---------------------------------------------------------------------------- bool -Machine::GetCurrTable( string& sTable) +Machine::GetCurrTable( string& sTable) const { // controllo GeomDB if ( m_pGeomDB == nullptr) @@ -79,6 +80,28 @@ Machine::GetCurrTable( string& sTable) return m_pGeomDB->GetName( m_nCalcTabId, sTable) ; } +//---------------------------------------------------------------------------- +bool +Machine::GetCurrTableRef1( Point3d& ptRef1) const +{ + Table* pTab = GetTable( m_nCalcTabId) ; + if ( pTab == nullptr) + return false ; + ptRef1 = pTab->GetRef1() ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Machine::GetCurrTableArea1( BBox3d& b3Area1) const +{ + Table* pTab = GetTable( m_nCalcTabId) ; + if ( pTab == nullptr) + return false ; + b3Area1 = pTab->GetArea1() ; + return true ; +} + //---------------------------------------------------------------------------- bool Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) @@ -150,7 +173,7 @@ Machine::SetCurrTool( const string& sTool, const string& sHead, int nExit) //---------------------------------------------------------------------------- int -Machine::GetCurrTool( void) +Machine::GetCurrTool( void) const { // controllo GeomDB if ( m_pGeomDB == nullptr) @@ -161,7 +184,7 @@ Machine::GetCurrTool( void) //---------------------------------------------------------------------------- bool -Machine::GetCurrTool( string& sTool) +Machine::GetCurrTool( string& sTool) const { // controllo GeomDB if ( m_pGeomDB == nullptr) @@ -172,7 +195,7 @@ Machine::GetCurrTool( string& sTool) //---------------------------------------------------------------------------- double -Machine::GetCurrRot1W( void) +Machine::GetCurrRot1W( void) const { // restituisco il peso del primo asse rotante nei confronti di movimento return m_dCalcRot1W ; @@ -284,7 +307,7 @@ Machine::AddKinematicAxis( bool bOnHead, int nId) //---------------------------------------------------------------------------- string -Machine::GetKinematicAxis( int nInd) +Machine::GetKinematicAxis( int nInd) const { // controllo GeomDB if ( m_pGeomDB == nullptr) @@ -306,7 +329,7 @@ Machine::GetKinematicAxis( int nInd) //---------------------------------------------------------------------------- bool Machine::GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, - int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) + int& nStat, double& dAngA1, double& dAngB1, double& dAngA2, double& dAngB2) const { // annullo tutti gli angoli nStat = 0 ; dAngA1 = 0 ; dAngB1 = 0 ; dAngA2 = 0 ; dAngB2 = 0 ; @@ -377,6 +400,7 @@ Machine::GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, if ( fabs( dCompTOrtAxR1 * dCompHSuAxR1 - dCompHOrtAxR1 * dCompTSuAxR1) < SIN_ANG_ERROR) { nStat = 1 ; vtDirH1 = vtDirH ; + vtDirI1 = vtDirI ; // reset secondo angolo dAngB1 = 0 ; } @@ -464,7 +488,7 @@ Machine::GetAngles( const Vector3d& vtDirT, const Vector3d& vtDirA, //---------------------------------------------------------------------------- bool Machine::GetPositions( const Point3d& ptP, double dAngA, double dAngB, - int& nStat, double& dX, double& dY, double& dZ) + int& nStat, double& dX, double& dY, double& dZ) const { // la posizione deve essere espressa rispetto allo ZERO MACCHINA // per ora gestisco solo gli assi rotanti di testa @@ -514,7 +538,7 @@ Machine::GetPositions( const Point3d& ptP, double dAngA, double dAngB, //---------------------------------------------------------------------------- bool -Machine::GetDirection( const Vector3d& vtDir, double dAngA, double dAngB, Vector3d& vtNew) +Machine::GetDirection( const Vector3d& vtDir, double dAngA, double dAngB, Vector3d& vtNew) const { // per ora gestisco solo gli assi rotanti di testa @@ -544,7 +568,7 @@ Machine::GetDirection( const Vector3d& vtDir, double dAngA, double dAngB, Vector //---------------------------------------------------------------------------- bool Machine::GetTipFromPositions( double dX, double dY, double dZ, double dAngA, double dAngB, - bool bBottom, Point3d& ptTip) + bool bBottom, Point3d& ptTip) const { // la posizione deve essere espressa rispetto allo ZERO MACCHINA // per ora gestisco solo gli assi rotanti di testa @@ -576,14 +600,14 @@ Machine::GetTipFromPositions( double dX, double dY, double dZ, double dAngA, dou //---------------------------------------------------------------------------- bool -Machine::GetToolDirFromAngles( double dAngA, double dAngB, Vector3d& vtDir) +Machine::GetToolDirFromAngles( double dAngA, double dAngB, Vector3d& vtDir) const { return GetDirection( m_vtCalcDir, dAngA, dAngB, vtDir) ; } //---------------------------------------------------------------------------- bool -Machine::VerifyScc( const Vector3d& vtDirI, const Vector3d& vtDirA, int nSolCh) +Machine::VerifyScc( const Vector3d& vtDirI, const Vector3d& vtDirA, int nSolCh) const { switch ( nSolCh) { default : @@ -609,65 +633,39 @@ Machine::VerifyScc( const Vector3d& vtDirI, const Vector3d& vtDirA, int nSolCh) //---------------------------------------------------------------------------- bool -Machine::AdjustAngleInStroke( int nId, double& dAng) +Machine::AdjustAngleInStroke( int nId, double& dAng) const { - // se non ci sono assi rotanti, non c'è alcunchè da fare - if ( m_vCalcRotAx.size() == 0) + // se angolo fittizio (non esiste l'asse rotante corrispondente), non c'è alcunchè da fare + if ( nId <= 0 || nId > int( m_vCalcRotAx.size())) return true ; - // se primo angolo ed esiste primo asse rotante - if ( nId == 1 && m_vCalcRotAx.size() >= 1) { - while ( dAng < m_vCalcRotAx[0].stroke.Min) - dAng += ANG_FULL ; - while ( dAng > m_vCalcRotAx[0].stroke.Max) - dAng -= ANG_FULL ; - return ( dAng >= m_vCalcRotAx[0].stroke.Min && - dAng <= m_vCalcRotAx[0].stroke.Max) ; - } - // se secondo angolo ed esiste secondo asse rotante - if ( nId == 2 && m_vCalcRotAx.size() >= 2) { - while ( dAng < m_vCalcRotAx[1].stroke.Min) - dAng += ANG_FULL ; - while ( dAng > m_vCalcRotAx[1].stroke.Max) - dAng -= ANG_FULL ; - return ( dAng >= m_vCalcRotAx[1].stroke.Min && - dAng <= m_vCalcRotAx[1].stroke.Max) ; - } - // errore - return false ; + // eseguo gli aggiustamenti + while ( dAng < m_vCalcRotAx[nId-1].stroke.Min) + dAng += ANG_FULL ; + while ( dAng > m_vCalcRotAx[nId-1].stroke.Max) + dAng -= ANG_FULL ; + return ( dAng >= m_vCalcRotAx[nId-1].stroke.Min && + dAng <= m_vCalcRotAx[nId-1].stroke.Max) ; } //---------------------------------------------------------------------------- bool -Machine::GetNearestAngleInStroke( int nId, double dAngRef, double& dAng) +Machine::GetNearestAngleInStroke( int nId, double dAngRef, double& dAng) const { - // se non ci sono assi rotanti, non c'è alcunchè da fare - if ( m_vCalcRotAx.size() == 0) + // se angolo fittizio (non esiste l'asse rotante corrispondente), non c'è alcunchè da fare + if ( nId <= 0 || nId > int( m_vCalcRotAx.size())) return true ; - // se primo angolo ed esiste primo asse rotante - if ( nId == 1 && m_vCalcRotAx.size() >= 1) { - while ( dAng - dAngRef > ANG_STRAIGHT && dAng - ANG_FULL >= m_vCalcRotAx[0].stroke.Min) - dAng -= ANG_FULL ; - while ( dAng - dAngRef < - ANG_STRAIGHT && dAng + ANG_FULL <= m_vCalcRotAx[0].stroke.Max) - dAng += ANG_FULL ; - return ( dAng >= m_vCalcRotAx[0].stroke.Min && - dAng <= m_vCalcRotAx[0].stroke.Max) ; - } - // se secondo angolo ed esiste secondo asse rotante - if ( nId == 2 && m_vCalcRotAx.size() >= 2) { - while ( dAng - dAngRef > ANG_STRAIGHT && dAng - ANG_FULL >= m_vCalcRotAx[1].stroke.Min) - dAng -= ANG_FULL ; - while ( dAng - dAngRef < - ANG_STRAIGHT && dAng + ANG_FULL <= m_vCalcRotAx[1].stroke.Max) - dAng += ANG_FULL ; - return ( dAng >= m_vCalcRotAx[1].stroke.Min && - dAng <= m_vCalcRotAx[1].stroke.Max) ; - } - // errore - return false ; + // cerco l'angolo più vicino stando nella corsa + while ( dAng - dAngRef > ANG_STRAIGHT && dAng - ANG_FULL >= m_vCalcRotAx[nId-1].stroke.Min) + dAng -= ANG_FULL ; + while ( dAng - dAngRef < - ANG_STRAIGHT && dAng + ANG_FULL <= m_vCalcRotAx[nId-1].stroke.Max) + dAng += ANG_FULL ; + return ( dAng >= m_vCalcRotAx[nId-1].stroke.Min && + dAng <= m_vCalcRotAx[nId-1].stroke.Max) ; } //---------------------------------------------------------------------------- bool -Machine::VerifyOutstroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) +Machine::VerifyOutstroke( double dX, double dY, double dZ, double dAngA, double dAngB, int& nStat) const { // default tutto ok nStat = 0 ; @@ -742,21 +740,21 @@ Machine::VerifyOutstroke( double dX, double dY, double dZ, double dAngA, double //---------------------------------------------------------------------------- int -Machine::GetCurrLinAxes( void) +Machine::GetCurrLinAxes( void) const { return int( m_vCalcLinAx.size()) ; } //---------------------------------------------------------------------------- int -Machine::GetCurrRotAxes( void) +Machine::GetCurrRotAxes( void) const { return int( m_vCalcRotAx.size()) ; } //---------------------------------------------------------------------------- bool -Machine::GetAllCurrAxesName( STRVECTOR& vAxName) +Machine::GetAllCurrAxesName( STRVECTOR& vAxName) const { vAxName.clear() ; bool bOk = true ; @@ -781,7 +779,7 @@ Machine::GetAllCurrAxesName( STRVECTOR& vAxName) //---------------------------------------------------------------------------- bool -Machine::GetAllCurrAxesHomePos( DBLVECTOR& vAxHomeVal) +Machine::GetAllCurrAxesHomePos( DBLVECTOR& vAxHomeVal) const { vAxHomeVal.clear() ; bool bOk = true ; diff --git a/MachineLua.cpp b/MachineLua.cpp index 9d57b55..c2ac471 100644 --- a/MachineLua.cpp +++ b/MachineLua.cpp @@ -23,6 +23,30 @@ using namespace std ; +//---------------------------------------------------------------------------- +static const string FLD_FILE = "File" ; +static const string FLD_OFFSET = "Offset" ; +static const string FLD_SPECIAL = "Special" ; +static const string FLD_PROCESSOR = "Processor" ; +static const string FLD_AXISMAXADJUST = "AxisMaxAdjust" ; +static const string FLD_EXITMAXADJUST = "ExitMaxAdjust" ; +static const string FLD_NAME = "Name" ; +static const string FLD_PARENT = "Parent" ; +static const string FLD_GEO = "Geo" ; +static const string FLD_AUX = "Aux" ; +static const string FLD_TYPE = "Type" ; +static const string FLD_REF1 = "Ref1" ; +static const string FLD_POS = "Pos" ; +static const string FLD_DIR = "Dir" ; +static const string FLD_STROKE = "Stroke" ; +static const string FLD_HOME = "Home" ; +static const string FLD_HSET = "HSet" ; +static const string FLD_TDIR = "TDir" ; +static const string FLD_ADIR = "ADir" ; +static const string FLD_ROT1W = "Rot1W" ; +static const string FLD_ROT2STROKE = "Rot2Stroke" ; +static const string FLD_SOLCH = "SolCh" ; + //---------------------------------------------------------------------------- Machine* Machine::m_pMchLua = nullptr ; @@ -57,6 +81,13 @@ Machine::LuaInit( const string& sMachineName) // registro le funzioni di modifica macchina per lua m_LuaMgr.RegisterFunction( "EmtModifyAxisStroke", Machine::LuaEmtModifyAxisStroke) ; m_LuaMgr.RegisterFunction( "EmtModifyAxisHome", Machine::LuaEmtModifyAxisHome) ; + m_LuaMgr.RegisterFunction( "EmtLinkRawPartToGroup", Machine::LuaEmtLinkRawPartToGroup) ; + m_LuaMgr.RegisterFunction( "EmtUnlinkRawPartFromGroup", Machine::LuaEmtUnlinkRawPartFromGroup) ; + m_LuaMgr.RegisterFunction( "EmtUnlinkAllRawPartsFromGroups", Machine::LuaEmtUnlinkAllRawPartsFromGroups) ; + // registro le funzioni di definizione entità CL per lua + m_LuaMgr.RegisterFunction( "EmtAddRapidStart", Machine::LuaEmtAddRapidStart) ; + m_LuaMgr.RegisterFunction( "EmtAddRapidMove", Machine::LuaEmtAddRapidMove) ; + m_LuaMgr.RegisterFunction( "EmtAddLinearMove", Machine::LuaEmtAddLinearMove) ; // registro le funzioni di scrittura part program per lua m_LuaMgr.RegisterFunction( "EmtWrite", Machine::LuaEmtWrite) ; @@ -187,23 +218,28 @@ Machine::LuaEmtGeneral( lua_State* L) return luaL_error( L, " Invalid Parameter, required a table") ; // lettura campo 'File' dalla tabella string sFile ; - LuaCheckTabFieldParam( L, 1, "File", sFile) + LuaCheckTabFieldParam( L, 1, FLD_FILE, sFile) // lettura eventuale campo 'Offset' dalla tabella (default 0,0,0) Vector3d vtOffset ; - LuaGetTabFieldParam( L, 1, "Offset", vtOffset) ; + LuaGetTabFieldParam( L, 1, FLD_OFFSET, vtOffset) ; + // lettura eventuale campo 'Special' dalla tabella + string sSpecial ; + LuaGetTabFieldParam( L, 1, FLD_SPECIAL, sSpecial) ; // lettura eventuale campo 'Processor' dalla tabella string sProcessor ; - LuaGetTabFieldParam( L, 1, "Processor", sProcessor) ; + LuaGetTabFieldParam( L, 1, FLD_PROCESSOR, sProcessor) ; // lettura eventuale campo 'AxisMaxAdjust' dalla tabella (default EPS_SMALL) double dAxisMaxAdjust = EPS_SMALL ; - LuaGetTabFieldParam( L, 1, "AxisMaxAdjust", dAxisMaxAdjust) ; + LuaGetTabFieldParam( L, 1, FLD_AXISMAXADJUST, dAxisMaxAdjust) ; // lettura eventuale campo 'ExitMaxAdjust' dalla tabella (default EPS_SMALL) double dExitMaxAdjust = EPS_SMALL ; - LuaGetTabFieldParam( L, 1, "ExitMaxAdjust", dExitMaxAdjust) ; + LuaGetTabFieldParam( L, 1, FLD_EXITMAXADJUST, dExitMaxAdjust) ; LuaClearStack( L) ; // info string sOut = "LuaEmtGeneral : " + sFile ; + if ( ! sSpecial.empty()) + sOut += ", " + sSpecial ; if ( ! sProcessor.empty()) sOut += ", " + sProcessor ; LOG_INFO( GetEMkLogger(), sOut.c_str()) @@ -216,6 +252,17 @@ Machine::LuaEmtGeneral( lua_State* L) if ( ! m_pMchLua->LoadMachineGeometry( sFile, vtOffset)) return luaL_error( L, " Load Machine failed") ; + // carico il gestore delle azioni speciali della macchina + if ( ! sSpecial.empty()) { + // carico il file lua dello special + string sSpecPath = m_pMchLua->m_sMachineDir + "\\" + sSpecial ; + if ( ! m_pMchLua->m_LuaMgr.ExecFile( sSpecPath)) + return luaL_error( L, " Load Special failed") ; + } + else { + LOG_INFO( GetEMkLogger(), " Special file not specified") + } + // carico il processore della macchina if ( ! sProcessor.empty()) { // carico il file lua del processore @@ -243,10 +290,13 @@ Machine::LuaEmtBase( lua_State* L) return luaL_error( L, " Invalid Parameter, required a table") ; // lettura campo 'Name' dalla tabella string sName ; - LuaCheckTabFieldParam( L, 1, "Name", sName) + LuaCheckTabFieldParam( L, 1, FLD_NAME, sName) // lettura campo 'Geo' dalla tabella string sGeo ; - LuaCheckTabFieldParam( L, 1, "Geo", sGeo) + LuaCheckTabFieldParam( L, 1, FLD_GEO, sGeo) + // lettura eventuale campo 'Aux' dalla tabella + STRVECTOR vsAux ; + LuaGetTabFieldParam( L, 1, FLD_AUX, vsAux) ; LuaClearStack( L) ; // info @@ -258,7 +308,7 @@ Machine::LuaEmtBase( lua_State* L) return luaL_error( L, " Unknown Machine") ; // carico i dati della base - if ( ! m_pMchLua->LoadMachineBase( sName, sGeo)) + if ( ! m_pMchLua->LoadMachineBase( sName, sGeo, vsAux)) return luaL_error( L, " Load Machine Base failed") ; return 0 ; @@ -273,19 +323,22 @@ Machine::LuaEmtTable( lua_State* L) return luaL_error( L, " Invalid Parameter, required a table") ; // lettura campo 'Name' dalla tabella string sName ; - LuaCheckTabFieldParam( L, 1, "Name", sName) + LuaCheckTabFieldParam( L, 1, FLD_NAME, sName) // lettura campo 'Parent' dalla tabella string sParent ; - LuaCheckTabFieldParam( L, 1, "Parent", sParent) + LuaCheckTabFieldParam( L, 1, FLD_PARENT, sParent) // lettura campo 'Type' dalla tabella int nType ; - LuaCheckTabFieldParam( L, 1, "Type", nType) + LuaCheckTabFieldParam( L, 1, FLD_TYPE, nType) // lettura campo 'Ref1' dalla tabella Point3d Ref1 ; - LuaCheckTabFieldParam( L, 1, "Ref1", Ref1) + LuaCheckTabFieldParam( L, 1, FLD_REF1, Ref1) // lettura campo 'Geo' dalla tabella string sGeo ; - LuaCheckTabFieldParam( L, 1, "Geo", sGeo) + LuaCheckTabFieldParam( L, 1, FLD_GEO, sGeo) + // lettura eventuale campo 'Aux' dalla tabella + STRVECTOR vsAux ; + LuaGetTabFieldParam( L, 1, FLD_AUX, vsAux) ; LuaClearStack( L) ; // info @@ -297,7 +350,7 @@ Machine::LuaEmtTable( lua_State* L) return luaL_error( L, " Unknown Machine") ; // carico i dati della tavola - if ( ! m_pMchLua->LoadMachineTable( sName, sParent, nType, Ref1, sGeo)) + if ( ! m_pMchLua->LoadMachineTable( sName, sParent, nType, Ref1, sGeo, vsAux)) return luaL_error( L, " Load Machine Table failed") ; return 0 ; @@ -312,28 +365,31 @@ Machine::LuaEmtAxis( lua_State* L) return luaL_error( L, " Invalid Parameter, required a table") ; // lettura campo 'Name' dalla tabella string sName ; - LuaCheckTabFieldParam( L, 1, "Name", sName) + LuaCheckTabFieldParam( L, 1, FLD_NAME, sName) // lettura campo 'Parent' dalla tabella string sParent ; - LuaCheckTabFieldParam( L, 1, "Parent", sParent) + LuaCheckTabFieldParam( L, 1, FLD_PARENT, sParent) // lettura campo 'Type' dalla tabella int nType ; - LuaCheckTabFieldParam( L, 1, "Type", nType) + LuaCheckTabFieldParam( L, 1, FLD_TYPE, nType) // lettura campo 'Pos' dalla tabella Point3d ptPos ; - LuaCheckTabFieldParam( L, 1, "Pos", ptPos) + LuaCheckTabFieldParam( L, 1, FLD_POS, ptPos) // lettura campo 'Dir' dalla tabella Vector3d vtDir ; - LuaCheckTabFieldParam( L, 1, "Dir", vtDir) + LuaCheckTabFieldParam( L, 1, FLD_DIR, vtDir) // lettura campo 'Stroke' dalla tabella STROKE Stroke ; - LuaCheckTabFieldParam( L, 1, "Stroke", Stroke.v) - // lettura campo 'Geo' dalla tabella - string sGeo ; - LuaCheckTabFieldParam( L, 1, "Geo", sGeo) + LuaCheckTabFieldParam( L, 1, FLD_STROKE, Stroke.v) // lettura eventuale campo 'Home' dalla tabella (default 0) double dHome = 0 ; - LuaGetTabFieldParam( L, 1, "Home", dHome) ; + LuaGetTabFieldParam( L, 1, FLD_HOME, dHome) ; + // lettura campo 'Geo' dalla tabella + string sGeo ; + LuaCheckTabFieldParam( L, 1, FLD_GEO, sGeo) + // lettura eventuale campo 'Aux' dalla tabella + STRVECTOR vsAux ; + LuaGetTabFieldParam( L, 1, FLD_AUX, vsAux) ; LuaClearStack( L) ; // info @@ -345,7 +401,7 @@ Machine::LuaEmtAxis( lua_State* L) return luaL_error( L, " Unknown Machine") ; // carico i dati dell'asse - if ( ! m_pMchLua->LoadMachineAxis( sName, sParent, nType, ptPos, vtDir, Stroke, sGeo, dHome)) + if ( ! m_pMchLua->LoadMachineAxis( sName, sParent, nType, ptPos, vtDir, Stroke, dHome, sGeo, vsAux)) return luaL_error( L, " Load Machine Axis failed") ; return 0 ; @@ -360,15 +416,19 @@ Machine::LuaEmtHead( lua_State* L) return luaL_error( L, " Invalid Parameter, required a table") ; // lettura campo 'Type' dalla tabella int nType ; - LuaCheckTabFieldParam( L, 1, "Type", nType) + LuaCheckTabFieldParam( L, 1, FLD_TYPE, nType) // Procedo alla lettura a seconda del tipo - if ( nType == MCH_HT_STD) + switch ( nType) { + case MCH_HT_STD : return LuaEmtStdHead( L) ; - else if ( nType == MCH_HT_MULTI) + case MCH_HT_MULTI : return LuaEmtMultiHead( L) ; - else + case MCH_HT_SPECIAL : + return LuaEmtSpecialHead( L) ; + default : return luaL_error( L, " Head type unknown") ; + } } //---------------------------------------------------------------------------- @@ -380,34 +440,37 @@ Machine::LuaEmtStdHead( lua_State* L) return luaL_error( L, " Invalid Parameter, required a table") ; // lettura campo 'Name' dalla tabella string sName ; - LuaCheckTabFieldParam( L, 1, "Name", sName) + LuaCheckTabFieldParam( L, 1, FLD_NAME, sName) // lettura campo 'Parent' dalla tabella string sParent ; - LuaCheckTabFieldParam( L, 1, "Parent", sParent) + LuaCheckTabFieldParam( L, 1, FLD_PARENT, sParent) // lettura campo 'HSet' dalla tabella string sHSet ; - LuaCheckTabFieldParam( L, 1, "HSet", sHSet) + LuaCheckTabFieldParam( L, 1, FLD_HSET, sHSet) // lettura campo 'Pos' dalla tabella Point3d ptPos ; - LuaCheckTabFieldParam( L, 1, "Pos", ptPos) + LuaCheckTabFieldParam( L, 1, FLD_POS, ptPos) // lettura campo 'TDir' dalla tabella Vector3d vtTDir ; - LuaCheckTabFieldParam( L, 1, "TDir", vtTDir) + LuaCheckTabFieldParam( L, 1, FLD_TDIR, vtTDir) // lettura eventuale campo 'ADir' dalla tabella Vector3d vtADir ; - LuaGetTabFieldParam( L, 1, "ADir", vtADir) ; + LuaGetTabFieldParam( L, 1, FLD_ADIR, vtADir) ; // lettura eventuale campo 'Rot1W' dalla tabella (default 1) double dRot1W = 1 ; - LuaGetTabFieldParam( L, 1, "Rot1W", dRot1W) ; + LuaGetTabFieldParam( L, 1, FLD_ROT1W, dRot1W) ; // lettura eventuale campo 'Rot2Stroke' dalla tabella STROKE Rot2Stroke = { - INFINITO, INFINITO} ; - LuaGetTabFieldParam( L, 1, "Rot2Stroke", Rot2Stroke.v) ; + LuaGetTabFieldParam( L, 1, FLD_ROT2STROKE, Rot2Stroke.v) ; // lettura eventuale campo 'SolCh' dalla tabella int nSolCh = MCH_SCC_NONE ; - LuaGetTabFieldParam( L, 1, "SolCh", nSolCh) ; + LuaGetTabFieldParam( L, 1, FLD_SOLCH, nSolCh) ; // lettura campo 'Geo' dalla tabella string sGeo ; - LuaCheckTabFieldParam( L, 1, "Geo", sGeo) + LuaCheckTabFieldParam( L, 1, FLD_GEO, sGeo) + // lettura eventuale campo 'Aux' dalla tabella + STRVECTOR vsAux ; + LuaGetTabFieldParam( L, 1, FLD_AUX, vsAux) ; LuaClearStack( L) ; // info @@ -420,7 +483,7 @@ Machine::LuaEmtStdHead( lua_State* L) // carico i dati della testa standard if ( ! m_pMchLua->LoadMachineStdHead( sName, sParent, sHSet, ptPos, vtTDir, vtADir, - dRot1W, Rot2Stroke, nSolCh, sGeo)) + dRot1W, Rot2Stroke, nSolCh, sGeo, vsAux)) return luaL_error( L, " Load Machine Standard Head failed") ; return 0 ; @@ -435,13 +498,13 @@ Machine::LuaEmtMultiHead( lua_State* L) return luaL_error( L, " Invalid Parameter, required a table") ; // lettura campo 'Name' dalla tabella string sName ; - LuaCheckTabFieldParam( L, 1, "Name", sName) + LuaCheckTabFieldParam( L, 1, FLD_NAME, sName) // lettura campo 'Parent' dalla tabella string sParent ; - LuaCheckTabFieldParam( L, 1, "Parent", sParent) + LuaCheckTabFieldParam( L, 1, FLD_PARENT, sParent) // lettura campo 'HSet' dalla tabella string sHSet ; - LuaCheckTabFieldParam( L, 1, "HSet", sHSet) + LuaCheckTabFieldParam( L, 1, FLD_HSET, sHSet) // lettura campo 'ExitNbr' dalla tabella int nExitNbr ; LuaCheckTabFieldParam( L, 1, "ExitNbr", nExitNbr) @@ -450,10 +513,10 @@ Machine::LuaEmtMultiHead( lua_State* L) vMuExit.reserve( nExitNbr) ; for ( int i = 0 ; i < nExitNbr ; ++ i) { // lettura - string sPos = "Pos" + ToString( i + 1) ; + string sPos = FLD_POS + ToString( i + 1) ; Point3d ptPos ; LuaCheckTabFieldParam( L, 1, sPos.c_str(), ptPos) - string sTDir = "TDir" + ToString( i + 1) ; + string sTDir = FLD_TDIR + ToString( i + 1) ; Vector3d vtTDir ; LuaCheckTabFieldParam( L, 1, sTDir.c_str(), vtTDir) // inserimento nell'array @@ -461,19 +524,22 @@ Machine::LuaEmtMultiHead( lua_State* L) } // lettura campo 'ADir' dalla tabella Vector3d vtADir ; - LuaGetTabFieldParam( L, 1, "ADir", vtADir) ; + LuaGetTabFieldParam( L, 1, FLD_ADIR, vtADir) ; // lettura eventuale campo 'Rot1W' dalla tabella (default 1) double dRot1W = 1 ; - LuaGetTabFieldParam( L, 1, "Rot1W", dRot1W) ; + LuaGetTabFieldParam( L, 1, FLD_ROT1W, dRot1W) ; // lettura eventuale campo 'Rot2Stroke' dalla tabella STROKE Rot2Stroke = { - INFINITO, INFINITO} ; - LuaGetTabFieldParam( L, 1, "Rot2Stroke", Rot2Stroke.v) ; + LuaGetTabFieldParam( L, 1, FLD_ROT2STROKE, Rot2Stroke.v) ; // lettura eventuale campo 'SolCh' dalla tabella int nSolCh = MCH_SCC_NONE ; - LuaGetTabFieldParam( L, 1, "SolCh", nSolCh) ; + LuaGetTabFieldParam( L, 1, FLD_SOLCH, nSolCh) ; // lettura campo 'Geo' dalla tabella string sGeo ; - LuaCheckTabFieldParam( L, 1, "Geo", sGeo) + LuaCheckTabFieldParam( L, 1, FLD_GEO, sGeo) + // lettura eventuale campo 'Aux' dalla tabella + STRVECTOR vsAux ; + LuaGetTabFieldParam( L, 1, FLD_AUX, vsAux) ; LuaClearStack( L) ; // info @@ -486,12 +552,70 @@ Machine::LuaEmtMultiHead( lua_State* L) // carico i dati della testa multipla if ( ! m_pMchLua->LoadMachineMultiHead( sName, sParent, sHSet, vMuExit, vtADir, - dRot1W, Rot2Stroke, nSolCh, sGeo)) + dRot1W, Rot2Stroke, nSolCh, sGeo, vsAux)) return luaL_error( L, " Load Machine Standard Head failed") ; return 0 ; } +//---------------------------------------------------------------------------- +int +Machine::LuaEmtSpecialHead( lua_State* L) +{ + // Il parametro 1 deve essere una tabella + if ( ! lua_istable( L, 1)) + return luaL_error( L, " Invalid Parameter, required a table") ; + // lettura campo 'Name' dalla tabella + string sName ; + LuaCheckTabFieldParam( L, 1, FLD_NAME, sName) + // lettura campo 'Parent' dalla tabella + string sParent ; + LuaCheckTabFieldParam( L, 1, FLD_PARENT, sParent) + // lettura campo 'HSet' dalla tabella + string sHSet ; + LuaCheckTabFieldParam( L, 1, FLD_HSET, sHSet) + // lettura campo 'Pos' dalla tabella + Point3d ptPos ; + LuaCheckTabFieldParam( L, 1, FLD_POS, ptPos) + // lettura campo 'TDir' dalla tabella + Vector3d vtTDir ; + LuaCheckTabFieldParam( L, 1, FLD_TDIR, vtTDir) + // lettura eventuale campo 'ADir' dalla tabella + Vector3d vtADir ; + LuaGetTabFieldParam( L, 1, FLD_ADIR, vtADir) ; + // lettura eventuale campo 'Rot1W' dalla tabella (default 1) + double dRot1W = 1 ; + LuaGetTabFieldParam( L, 1, FLD_ROT1W, dRot1W) ; + // lettura eventuale campo 'Rot2Stroke' dalla tabella + STROKE Rot2Stroke = { - INFINITO, INFINITO} ; + LuaGetTabFieldParam( L, 1, FLD_ROT2STROKE, Rot2Stroke.v) ; + // lettura eventuale campo 'SolCh' dalla tabella + int nSolCh = MCH_SCC_NONE ; + LuaGetTabFieldParam( L, 1, FLD_SOLCH, nSolCh) ; + // lettura campo 'Geo' dalla tabella + string sGeo ; + LuaCheckTabFieldParam( L, 1, FLD_GEO, sGeo) + // lettura eventuale campo 'Aux' dalla tabella + STRVECTOR vsAux ; + LuaGetTabFieldParam( L, 1, FLD_AUX, vsAux) ; + LuaClearStack( L) ; + + // info + string sOut = "LuaEmtSpecialHead : " + sName ; + LOG_INFO( GetEMkLogger(), sOut.c_str()) + + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + + // carico i dati della testa standard + if ( ! m_pMchLua->LoadMachineSpecialHead( sName, sParent, sHSet, ptPos, vtTDir, vtADir, + dRot1W, Rot2Stroke, nSolCh, sGeo, vsAux)) + return luaL_error( L, " Load Machine Special Head failed") ; + + return 0 ; +} + //---------------------------------------------------------------------------- int Machine::LuaEmtModifyAxisStroke( lua_State* L) @@ -532,6 +656,60 @@ Machine::LuaEmtModifyAxisHome( lua_State* L) return 1 ; } +//---------------------------------------------------------------------------- +int +Machine::LuaEmtLinkRawPartToGroup( lua_State* L) +{ + // 2 parametri : nRawId, sGroupName + int nRawId ; + LuaCheckParam( L, 1, nRawId) + string sGroupName ; + LuaCheckParam( L, 2, sGroupName) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // aggancio il grezzo al gruppo + bool bOk = m_pMchLua->LinkRawPartToGroup( nRawId, sGroupName) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtUnlinkRawPartFromGroup( lua_State* L) +{ + // 1 parametro : nRawId + int nRawId ; + LuaCheckParam( L, 1, nRawId) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // riporto il grezzo nel gruppo dei grezzi + bool bOk = m_pMchLua->UnlinkRawPartFromGroup( nRawId) ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtUnlinkAllRawPartsFromGroups( lua_State* L) +{ + // nessun parametro + LuaClearStack( L) ; + // verifico ci sia una macchina attiva + if ( m_pMchLua == nullptr) + return luaL_error( L, " Unknown Machine") ; + // riporto tutti i grezzi linkati nel gruppo dei grezzi + bool bOk = m_pMchLua->UnlinkAllRawPartsFromGroups() ; + // assegno risultato + LuaSetParam( L, bOk) ; + return 1 ; +} + //---------------------------------------------------------------------------- int Machine::LuaEmtWrite( lua_State* L) diff --git a/MachineLuaCL.cpp b/MachineLuaCL.cpp new file mode 100644 index 0000000..f24097b --- /dev/null +++ b/MachineLuaCL.cpp @@ -0,0 +1,192 @@ +//---------------------------------------------------------------------------- +// EgalTech 2016-2016 +//---------------------------------------------------------------------------- +// File : MachineLuaCL.cpp Data : 26.04.16 Versione : 1.6p4 +// Contenuto : Implementazione gestione macchina : funzioni Lua per CL. +// +// +// +// Modifiche : 26.04.16 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "MachMgr.h" +#include "DllMain.h" +#include "/EgtDev/Include/EXeExecutor.h" +#include "/EgtDev/Include/EGkGeoPoint3d.h" +#include "/EgtDev/Include/EGkCurveLine.h" +#include "/EgtDev/Include/EGkGeomDB.h" +#include "/EgtDev/Include/EGkLuaAux.h" +#include "/EgtDev/Include/EGnStringUtils.h" +#include "/EgtDev/Include/EGnFileUtils.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtAddRapidStart( lua_State* L) +{ + // 6 parametri : nPathId, ptP, vtTool, vtCorr, vtAux, nFlag + int nPathId ; + LuaCheckParam( L, 1, nPathId) + Point3d ptP ; + LuaCheckParam( L, 2, ptP) + Vector3d vtTool ; + LuaCheckParam( L, 3, vtTool) + Vector3d vtCorr ; + LuaCheckParam( L, 4, vtCorr) + Vector3d vtAux ; + LuaCheckParam( L, 5, vtAux) + int nFlag ; + LuaCheckParam( L, 6, nFlag) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva valida + if ( m_pMchLua == nullptr || + m_pMchLua->m_pMchMgr == nullptr || m_pMchLua->m_pGeomDB == nullptr) + return luaL_error( L, " Unknown Machine") ; + // creo oggetto punto per DB geometrico + PtrOwner pGP( CreateGeoPoint3d()) ; + bool bOk = ! IsNull( pGP) ; + // assegno le coordinate del punto + bOk = bOk && pGP->Set( ptP) ; + // inserisco l'oggetto nel DB geometrico + int nId = ( bOk ? m_pMchLua->m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, Release( pGP)) : GDB_ID_NULL) ; + bOk = bOk && ( nId != GDB_ID_NULL) ; + // creo oggetto dati Cam + PtrOwner pCam( new( nothrow) CamData) ; + bOk = bOk && ! IsNull( pCam) ; + if ( bOk) { + // assegno valori + pCam->SetMoveType( 0) ; + pCam->SetToolDir( vtTool) ; + pCam->SetCorrDir( vtCorr) ; + pCam->SetAuxDir( vtAux) ; + pCam->SetEndPoint( ptP) ; + pCam->SetFeed( 0) ; + pCam->SetFlag( nFlag) ; + // associo questo oggetto a quello geometrico + m_pMchLua->m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + } + // assegno risultato + if ( bOk) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtAddRapidMove( lua_State* L) +{ + // 7 parametri : nPathId, ptIni, ptFin, vtTool, vtCorr, vtAux, nFlag + int nPathId ; + LuaCheckParam( L, 1, nPathId) + Point3d ptIni ; + LuaCheckParam( L, 2, ptIni) + Point3d ptFin ; + LuaCheckParam( L, 3, ptFin) + Vector3d vtTool ; + LuaCheckParam( L, 4, vtTool) + Vector3d vtCorr ; + LuaCheckParam( L, 5, vtCorr) + Vector3d vtAux ; + LuaCheckParam( L, 6, vtAux) + int nFlag ; + LuaCheckParam( L, 7, nFlag) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva valida + if ( m_pMchLua == nullptr || + m_pMchLua->m_pMchMgr == nullptr || m_pMchLua->m_pGeomDB == nullptr) + return luaL_error( L, " Unknown Machine") ; + // creo oggetto linea per DB geometrico + PtrOwner pLine( CreateCurveLine()) ; + bool bOk = ! IsNull( pLine) ; + // assegno gli estremi della linea + bOk = bOk && pLine->Set( ptIni, ptFin) ; + // inserisco l'oggetto nel DB geometrico + int nId = ( bOk ? m_pMchLua->m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, Release( pLine)) : GDB_ID_NULL) ; + bOk = bOk && ( nId != GDB_ID_NULL) ; + // creo oggetto dati Cam + PtrOwner pCam( new( nothrow) CamData) ; + bOk = bOk && ! IsNull( pCam) ; + if ( bOk) { + // assegno valori + pCam->SetMoveType( 0) ; + pCam->SetToolDir( vtTool) ; + pCam->SetCorrDir( vtCorr) ; + pCam->SetAuxDir( vtAux) ; + pCam->SetEndPoint( ptFin) ; + pCam->SetFeed( 0) ; + pCam->SetFlag( nFlag) ; + // associo questo oggetto a quello geometrico + m_pMchLua->m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + } + // assegno risultato + if ( bOk) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} + +//---------------------------------------------------------------------------- +int +Machine::LuaEmtAddLinearMove( lua_State* L) +{ + // 8 parametri : nPathId, ptIni, ptFin, vtTool, vtCorr, vtAux, dFeed, nFlag + int nPathId ; + LuaCheckParam( L, 1, nPathId) + Point3d ptIni ; + LuaCheckParam( L, 2, ptIni) + Point3d ptFin ; + LuaCheckParam( L, 3, ptFin) + Vector3d vtTool ; + LuaCheckParam( L, 4, vtTool) + Vector3d vtCorr ; + LuaCheckParam( L, 5, vtCorr) + Vector3d vtAux ; + LuaCheckParam( L, 6, vtAux) + double dFeed ; + LuaCheckParam( L, 7, dFeed) + int nFlag ; + LuaCheckParam( L, 8, nFlag) + LuaClearStack( L) ; + // verifico ci sia una macchina attiva valida + if ( m_pMchLua == nullptr || + m_pMchLua->m_pMchMgr == nullptr || m_pMchLua->m_pGeomDB == nullptr) + return luaL_error( L, " Unknown Machine") ; + // creo oggetto linea per DB geometrico + PtrOwner pLine( CreateCurveLine()) ; + bool bOk = ! IsNull( pLine) ; + // assegno gli estremi della linea + bOk = bOk && pLine->Set( ptIni, ptFin) ; + // inserisco l'oggetto nel DB geometrico + int nId = ( bOk ? m_pMchLua->m_pGeomDB->AddGeoObj( GDB_ID_NULL, nPathId, Release( pLine)) : GDB_ID_NULL) ; + bOk = bOk && ( nId != GDB_ID_NULL) ; + // creo oggetto dati Cam + PtrOwner pCam( new( nothrow) CamData) ; + bOk = bOk && ! IsNull( pCam) ; + if ( bOk) { + // assegno valori + pCam->SetMoveType( 1) ; + pCam->SetToolDir( vtTool) ; + pCam->SetCorrDir( vtCorr) ; + pCam->SetAuxDir( vtAux) ; + pCam->SetEndPoint( ptFin) ; + pCam->SetFeed( dFeed) ; + pCam->SetFlag( nFlag) ; + // associo questo oggetto a quello geometrico + m_pMchLua->m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + } + // assegno risultato + if ( bOk) + LuaSetParam( L, nId) ; + else + LuaSetParam( L) ; + return 1 ; +} diff --git a/MachineStruConst.h b/MachineStruConst.h index c9db8b8..0f19460 100644 --- a/MachineStruConst.h +++ b/MachineStruConst.h @@ -64,7 +64,8 @@ enum MchAxisType { MCH_AT_NONE = 0, // Tipo di testa della macchina enum MchHeadType { MCH_HT_NONE = 0, MCH_HT_STD = 1, - MCH_HT_MULTI = 2} ; + MCH_HT_MULTI = 2, + MCH_HT_SPECIAL = 3} ; //---------------------------------------------------------------------------- // Identificativo iniziale riferimenti di tavola diff --git a/Machining.cpp b/Machining.cpp index 8accd5a..392d46e 100644 --- a/Machining.cpp +++ b/Machining.cpp @@ -30,1285 +30,36 @@ using namespace std ; -//---------------------------------------------------------------------------- -bool -Machining::SetOwner( int nId, IGeomDB* pGDB) -{ - m_nOwnerId = nId ; - m_pGeomDB = pGDB ; - return ( m_nOwnerId != GDB_ID_NULL && m_pGeomDB != nullptr) ; -} - -//---------------------------------------------------------------------------- -int -Machining::GetOwner( void) const -{ - return m_nOwnerId ; -} - -//---------------------------------------------------------------------------- -IGeomDB* -Machining::GetGeomDB( void) const -{ - return m_pGeomDB ; -} - -//---------------------------------------------------------------------------- -bool -Machining::Init( MachMgr* pMchMgr) -{ - m_pMchMgr = pMchMgr ; - if ( m_pMchMgr == nullptr) - return false ; - if ( m_pMchMgr->GetGeomDB() != m_pGeomDB) - return false ; - return true ; -} - //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- Machining::Machining( void) - : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr), m_pMchMgr( nullptr), m_nPhase( 1), - m_nPathId( GDB_ID_NULL), m_bCurr( false), m_ptCurr(), - m_vtTool(), m_vtCorr(), m_vtAux(), m_dFeed( 0), m_nFlag( 0) { } //---------------------------------------------------------------------------- -//---------------------------------------------------------------------------- -bool -Machining::GetElevation( int nPhase, const Point3d& ptP, - const Vector3d& vtDir, double& dElev) +const string& +Machining::GetToolName( void) const { - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // inizializzo elevazione - dElev = INFINITO ; - // ciclo sui grezzi - bool bFound = false ; - int nRawId = m_pMchMgr->GetFirstRawPart() ; - while ( nRawId != GDB_ID_NULL) { - // verifico che il grezzo compaia nella fase - if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { - // intersezione del raggio dal punto alla trimesh del grezzo - const double RAY_LEN = 10000 ; - int nStmId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; - ISurfTriMesh* pStm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nStmId)) ; - if ( pStm != nullptr) { - bFound = true ; - // recupero il riferimento della trimesh - Frame3d frStm ; - m_pGeomDB->GetGlobFrame( nStmId, frStm) ; - // porto il raggio in questo riferimento - Point3d ptPL = ptP ; - ptPL.ToLoc( frStm) ; - Vector3d vtDirL = vtDir ; - vtDirL.ToLoc( frStm) ; - ILSIVECTOR vInfo ; - if ( IntersLineSurfTm( ptPL, vtDirL, RAY_LEN, *pStm, vInfo)) { - for ( const auto& Info : vInfo) { - // se tratto di intersezione coincidente, considero la posizione più lontana, ovvero 2 - if ( Info.nILTT == ILTT_SEGM || Info.nILTT == ILTT_SEGM_ON_EDGE) { - // se prosegue un tratto precedente, non devo controllare sia minimo - if ( fabs( dElev - Info.dU) < EPS_SMALL) - dElev = Info.dU2 ; - else - dElev = min( dElev, Info.dU2) ; - } - // altrimenti intersezione puntuale, verifico che esca (coseno >= 0) - else if ( Info.dCosDN > - COS_ORTO_ANG_ZERO) { - dElev = min( dElev, Info.dU) ; - } - } - } - } - } - // passo al grezzo successivo - nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; - } - // se non trovate intersezioni, elevazione nulla - if ( dElev > INFINITO - 1) - dElev = 0 ; - return bFound ; + return GetToolData().m_sName ; } //---------------------------------------------------------------------------- -bool -Machining::GetElevation( int nPhase, const Point3d& ptP1, const Point3d& ptP2, - const Vector3d& vtDir, double& dElev) +const string& +Machining::GetHeadName( void) const { - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // inizializzo elevazione - dElev = INFINITO ; - // ciclo sui grezzi - bool bFound = false ; - int nRawId = m_pMchMgr->GetFirstRawPart() ; - while ( nRawId != GDB_ID_NULL) { - // verifico che il grezzo compaia nella fase - if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { - // intersezione del raggio dal punto alla trimesh del grezzo - const double RAY_LEN = 10000 ; - int nStmId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; - ISurfTriMesh* pStm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nStmId)) ; - if ( pStm != nullptr) { - bFound = true ; - // recupero il riferimento della trimesh - Frame3d frStm ; - m_pGeomDB->GetGlobFrame( nStmId, frStm) ; - // porto il segmento e la direzione in questo riferimento - Point3d ptP1L = ptP1 ; - ptP1L.ToLoc( frStm) ; - Point3d ptP2L = ptP2 ; - ptP2L.ToLoc( frStm) ; - Vector3d vtDirL = vtDir ; - vtDirL.ToLoc( frStm) ; - ILSIVECTOR vInfo ; - // inizializzo elevazione della superficie - double dElevS = 0 ; - // faccio test con un insieme di punti ( !!! sostituire con intersezione tra rettangolo e trimesh !!!) - const double STEP = 50 ; - int nStep = max( (int) ceil( ApproxDist( ptP1L, ptP2L) / STEP), 3) ; - for ( int i = 0 ; i <= nStep ; ++ i) { - // calcolo punto di test - double dFraz = i / (double) nStep ; - Point3d ptPL = Media( ptP1L, ptP2L, dFraz) ; - // inizializzo elevazione del punto - double dElevP = INFINITO ; - // calcolo elevazione sul punto - if ( IntersLineSurfTm( ptPL, vtDirL, RAY_LEN, *pStm, vInfo)) { - for ( const auto& Info : vInfo) { - // se tratto di intersezione coincidente, considero la posizione più lontana, ovvero 2 - if ( Info.nILTT == ILTT_SEGM || Info.nILTT == ILTT_SEGM_ON_EDGE) { - // se prosegue un tratto precedente, non devo controllare sia minimo - if ( fabs( dElevP - Info.dU) < EPS_SMALL) - dElevP = Info.dU2 ; - else - dElevP = min( dElevP, Info.dU2) ; - } - // altrimenti intersezione puntuale, verifico che esca (coseno >= 0) - else if ( Info.dCosDN > - COS_ORTO_ANG_ZERO) { - dElevP = min( dElevP, Info.dU) ; - } - } - } - // se elevazione calcolata, aggiorno quella della superficie - if ( dElevP < INFINITO - 1) - dElevS = max( dElevS, dElevP) ; - } - // aggiorno elevazione complessiva - if ( dElevS > 0) - dElev = min( dElev, dElevS) ; - } - } - // passo al grezzo successivo - nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; - } - // se non trovate intersezioni, elevazione nulla - if ( dElev > INFINITO - 1) - dElev = 0 ; - return bFound ; -} - -//---------------------------------------------------------------------------- -bool -Machining::GetElevation( int nPhase, const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptP3, - const Vector3d& vtDir, double& dElev) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // approssimo l'arco con due linee - double dElev1, dElev2 ; - if ( ! GetElevation( nPhase, ptP1, ptP2, vtDir, dElev1)) - return false ; - if ( ! GetElevation( nPhase, ptP2, ptP3, vtDir, dElev2)) - return false ; - dElev = max( dElev1, dElev2) ; - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::GetDistanceFromRawSide( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero il grezzo in cui è incluso il punto - BBox3d b3Pnt( ptP) ; - b3Pnt.Expand( 10, 10, 0) ; - int nRawId = m_pMchMgr->GetFirstRawPart() ; - while ( nRawId != GDB_ID_NULL) { - // verifico che il grezzo compaia nella fase - if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { - // pre-filtro con il box - BBox3d b3Raw ; - int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; - if ( m_pGeomDB->GetGlobalBBox( nRawSolidId, b3Raw) && b3Pnt.OverlapsXY( b3Raw)) { - // porto il punto nel riferimento del grezzo - Frame3d frRaw ; - m_pGeomDB->GetGroupGlobFrame( nRawId, frRaw) ; - Point3d ptPL = ptP ; - ptPL.ToLoc( frRaw) ; - // verifica con il contorno - int nOutCrvId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_OUTLINE) ; - ICurve* pCurve = GetCurve( m_pGeomDB->GetGeoObj( nOutCrvId)) ; - if ( pCurve != nullptr) { - int nSide ; - double dDist ; - DistPointCurve distPC( ptPL, *pCurve) ; - if ( distPC.GetDist( dDist) && dDist < 100 * EPS_SMALL || - (distPC.GetSideAtMinDistPoint( 0, Z_AX, nSide) && nSide != MDS_RIGHT)) - break ; - } - } - } - // passo al grezzo successivo - nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; - } - // se il punto non è interno ad alcun grezzo, distanza nulla - if ( nRawId == GDB_ID_NULL) { - dDist = 0 ; - return true ; - } - // recupero il contorno del grezzo - int nOutId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_OUTLINE) ; - ICurve* pOut = ::GetCurve( m_pGeomDB->GetGeoObj( nOutId)) ; - if ( pOut == nullptr) - return false ; - // recupero il riferimento del contorno e verifico che abbia Z verticale - Frame3d frStm ; - if ( ! m_pGeomDB->GetGlobFrame( nOutId, frStm) || - ( frStm.GetZType() != Frame3d::TOP && frStm.GetZType() != Frame3d::BOTTOM)) - return false ; - // interseco il raggio di test (portato nel riferimento del contorno) con il contorno del grezzo - const double RAY_LEN = 10000 ; - PtrOwner pRay( CreateCurveLine()) ; - if ( IsNull( pRay) || ! pRay->SetPVL( ptP, vtDir, RAY_LEN)) - return false ; - pRay->ToLoc( frStm) ; - IntersCurveCurve intCC( *pRay, *pOut) ; - IntCrvCrvInfo aInfo ; - if ( intCC.GetIntCrvCrvInfo( 0, aInfo)) - dDist = aInfo.IciA[0].dU * RAY_LEN ; - else - dDist = 0 ; - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::GetDistanceFromRawBottom( int nPhase, int nPathId, double dToler, double& dRbDist) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero distanza da fondo dei grezzi interessati dal percorso - dRbDist = 0 ; - BBox3d b3Compo ; - if ( ! m_pGeomDB->GetGlobalBBox( nPathId, b3Compo)) - return false ; - b3Compo.Expand( dToler, dToler, 0) ; - int nRawId = m_pMchMgr->GetFirstRawPart() ; - while ( nRawId != GDB_ID_NULL) { - // verifico che il grezzo compaia nella fase - if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { - BBox3d b3Raw ; - int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; - if ( m_pGeomDB->GetGlobalBBox( nRawSolidId, b3Raw) && b3Compo.OverlapsXY( b3Raw)) { - double dDist = b3Compo.GetMax().z - b3Raw.GetMin().z ; - if ( dDist > dRbDist) - dRbDist = dDist ; - } - } - // passo al grezzo successivo - nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; - } - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::GetRawGlobBox( int nPhase, int nPathId, BBox3d& b3Raw) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // inizializzo box - b3Raw.Reset() ; - // ricerco grezzi interessati dal percorso - BBox3d b3Compo ; - if ( ! m_pGeomDB->GetGlobalBBox( nPathId, b3Compo)) - return false ; - b3Compo.Expand( 10 * EPS_SMALL, 10 * EPS_SMALL, 0) ; - int nRawId = m_pMchMgr->GetFirstRawPart() ; - while ( nRawId != GDB_ID_NULL) { - // verifico che il grezzo compaia nella fase - if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { - BBox3d b3OneRaw ; - int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; - if ( m_pGeomDB->GetGlobalBBox( nRawSolidId, b3OneRaw) && b3Compo.OverlapsXY( b3OneRaw)) { - b3Raw.Add( b3OneRaw) ; - } - } - // passo al grezzo successivo - nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; - } - return true ; -} - -//---------------------------------------------------------------------------- -//---------------------------------------------------------------------------- -bool -Machining::SetPathId( int nPathId) -{ - m_nPathId = nPathId ; - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::SetToolDir( const Vector3d& vtDir) -{ - m_vtTool = vtDir ; - return ( m_vtTool.Normalize()) ; -} - -//---------------------------------------------------------------------------- -bool -Machining::SetCorrDir( const Vector3d& vtDir) -{ - m_vtCorr = vtDir ; - return ( ! m_vtCorr.IsSmall()) ; -} - -//---------------------------------------------------------------------------- -bool -Machining::SetAuxDir( const Vector3d& vtDir) -{ - m_vtAux = vtDir ; - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::SetFeed( double dFeed) -{ - m_dFeed = dFeed ; - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::SetFlag( int nFlag) -{ - m_nFlag = nFlag ; - return true ; + return GetToolData().m_sHead ; } //---------------------------------------------------------------------------- int -Machining::AddRapidStart( const Point3d& ptP) +Machining::GetExitNbr( void) const { - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return GDB_ID_NULL ; - // verifico di essere in uno stato valido per inizio - if ( m_vtTool.IsSmall()) - return GDB_ID_NULL ; - // creo oggetto punto per DB geometrico - PtrOwner pGP( CreateGeoPoint3d()) ; - if ( IsNull( pGP)) - return GDB_ID_NULL ; - // assegno le coordinate del punto - pGP->Set( ptP) ; - // inserisco l'oggetto nel DB geometrico - int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, m_nPathId, Release( pGP)) ; - if ( nId == GDB_ID_NULL) - return GDB_ID_NULL ; - // creo oggetto dati Cam - PtrOwner pCam( new( nothrow) CamData) ; - if ( IsNull( pCam)) - return GDB_ID_NULL ; - // assegno valori - pCam->SetMoveType( 0) ; - pCam->SetToolDir( m_vtTool) ; - pCam->SetCorrDir( m_vtCorr) ; - pCam->SetAuxDir( m_vtAux) ; - pCam->SetEndPoint( ptP) ; - pCam->SetFeed( 0) ; - pCam->SetFlag( m_nFlag) ; - // associo questo oggetto a quello geometrico - m_pGeomDB->SetUserObj( nId, Release( pCam)) ; - // salvo la posizione corrente - m_bCurr = true ; - m_ptCurr = ptP ; - return nId ; + return GetToolData().m_nExit ; } //---------------------------------------------------------------------------- -int -Machining::AddRapidMove( const Point3d& ptP) +const string& +Machining::GetToolTcPos( void) const { - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return GDB_ID_NULL ; - // verifico di essere in uno stato valido per un movimento in rapido - if ( ! m_bCurr || m_vtTool.IsSmall()) - return GDB_ID_NULL ; - // creo oggetto linea per DB geometrico - PtrOwner pLine( CreateCurveLine()) ; - if ( IsNull( pLine)) - return GDB_ID_NULL ; - // assegno le coordinate degli estremi - if ( ! pLine->Set( m_ptCurr, ptP)) - return GDB_ID_NULL ; - // inserisco l'oggetto nel DB geometrico - int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, m_nPathId, Release( pLine)) ; - if ( nId == GDB_ID_NULL) - return GDB_ID_NULL ; - // creo oggetto dati Cam - PtrOwner pCam( new( nothrow) CamData) ; - if ( IsNull( pCam)) - return GDB_ID_NULL ; - // assegno valori - pCam->SetMoveType( 0) ; - pCam->SetToolDir( m_vtTool) ; - pCam->SetCorrDir( m_vtCorr) ; - pCam->SetAuxDir( m_vtAux) ; - pCam->SetEndPoint( ptP) ; - pCam->SetFeed( 0) ; - pCam->SetFlag( m_nFlag) ; - // associo questo oggetto a quello geometrico - m_pGeomDB->SetUserObj( nId, Release( pCam)) ; - // salvo la posizione corrente - m_ptCurr = ptP ; - return nId ; + return GetToolData().m_sTcPos ; } - -//---------------------------------------------------------------------------- -int -Machining::AddLinearMove( const Point3d& ptP) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return GDB_ID_NULL ; - // verifico di essere in uno stato valido per un movimento lineare - if ( ! m_bCurr || m_vtTool.IsSmall()) { - LOG_INFO( GetEMkLogger(), "Error on LinearMove : Curr or ToolDir") - return GDB_ID_NULL ; - } - // se feed nulla, assegno il minimo e lo segnalo - if ( m_dFeed < FEED_MIN) { - m_dFeed = FEED_MIN ; - LOG_INFO( GetEMkLogger(), "Error on LinearMove : Min Feed") - } - // creo oggetto linea per DB geometrico - PtrOwner pLine( CreateCurveLine()) ; - if ( IsNull( pLine)) - return GDB_ID_NULL ; - // assegno le coordinate degli estremi - if ( ! pLine->Set( m_ptCurr, ptP)) - return GDB_ID_NULL ; - // inserisco l'oggetto nel DB geometrico - int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, m_nPathId, Release( pLine)) ; - if ( nId == GDB_ID_NULL) - return GDB_ID_NULL ; - // creo oggetto dati Cam - PtrOwner pCam( new( nothrow) CamData) ; - if ( IsNull( pCam)) - return GDB_ID_NULL ; - // assegno valori - pCam->SetMoveType( 1) ; - pCam->SetToolDir( m_vtTool) ; - pCam->SetCorrDir( m_vtCorr) ; - pCam->SetAuxDir( m_vtAux) ; - pCam->SetEndPoint( ptP) ; - pCam->SetFeed( m_dFeed) ; - pCam->SetFlag( m_nFlag) ; - // associo questo oggetto a quello geometrico - m_pGeomDB->SetUserObj( nId, Release( pCam)) ; - // salvo la posizione corrente - m_ptCurr = ptP ; - return nId ; -} - -//---------------------------------------------------------------------------- -int -Machining::AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, double dDeltaZ) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return GDB_ID_NULL ; - // verifico di essere in uno stato valido per un movimento arco - if ( ! m_bCurr || m_vtTool.IsSmall()) { - LOG_INFO( GetEMkLogger(), "Error on ArcMove : Curr or ToolDir") - return GDB_ID_NULL ; - } - // se feed nulla, assegno il minimo e lo segnalo - if ( m_dFeed < FEED_MIN) { - m_dFeed = FEED_MIN ; - LOG_INFO( GetEMkLogger(), "Error on ArcMove : Min Feed") - } - // creo oggetto arco per DB geometrico - PtrOwner pArc( CreateCurveArc()) ; - if ( IsNull( pArc)) - return GDB_ID_NULL ; - // assegno i dati dell'arco - if ( ! pArc->SetCPA( ptCen, m_ptCurr, dAngCen, dDeltaZ)) - return GDB_ID_NULL ; - Point3d ptFin ; - if ( ! pArc->GetEndPoint( ptFin) || ! AreSamePointApprox( ptFin, ptP)) - return GDB_ID_NULL ; - int nMove = ( dAngCen > 0 ? 3 : 2) ; - // inserisco l'oggetto nel DB geometrico - int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, m_nPathId, Release( pArc)) ; - if ( nId == GDB_ID_NULL) - return GDB_ID_NULL ; - // creo oggetto dati Cam - PtrOwner pCam( new( nothrow) CamData) ; - if ( IsNull( pCam)) - return GDB_ID_NULL ; - // assegno valori - pCam->SetMoveType( nMove) ; - pCam->SetToolDir( m_vtTool) ; - pCam->SetCorrDir( m_vtCorr) ; - pCam->SetAuxDir( m_vtAux) ; - pCam->SetEndPoint( ptP) ; - pCam->SetCenter( ptCen) ; - pCam->SetAngCen( dAngCen) ; - pCam->SetFeed( m_dFeed) ; - pCam->SetFlag( m_nFlag) ; - // associo questo oggetto a quello geometrico - m_pGeomDB->SetUserObj( nId, Release( pCam)) ; - // salvo la posizione corrente - m_ptCurr = ptP ; - return nId ; -} - -//---------------------------------------------------------------------------- -bool -Machining::ResetMoveData( void) -{ - m_bCurr = false ; - m_ptCurr = ORIG ; - m_vtTool = V_NULL ; - m_vtCorr = V_NULL ; - m_vtAux = V_NULL ; - m_dFeed = 0 ; - m_nFlag = 0 ; - return true ; -} - -//---------------------------------------------------------------------------- -//---------------------------------------------------------------------------- -bool -Machining::GetInitialAxesValues( DBLVECTOR& vAxVal) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero gruppo per geometria di lavorazione (Cutter Location) - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; - if ( nClId == GDB_ID_NULL) - return false ; - // recupero il primo percorso CL - int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; - // restituisco i valori iniziali degli assi di questo percorso di lavorazione - return GetClPathInitialAxesValues( nClPathId, vAxVal) ; -} - -//---------------------------------------------------------------------------- -bool -Machining::GetClPathInitialAxesValues( int nClPathId, DBLVECTOR& vAxVal) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero la prima entità di questo percorso - int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; - // recupero i dati Cam dell'entità - CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; - if ( pCamData == nullptr) - return false ; - // assegno i valori degli assi - vAxVal = pCamData->GetAxesVal() ; - return ( vAxVal.size() > 0) ; -} - -//---------------------------------------------------------------------------- -bool -Machining::GetFinalAxesValues( DBLVECTOR& vAxVal) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero gruppo per geometria di lavorazione (Cutter Location) - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; - if ( nClId == GDB_ID_NULL) - return false ; - // recupero l'ultimo percorso CL - int nClPathId = m_pGeomDB->GetLastGroupInGroup( nClId) ; - // restituisco i valori finali degli assi di questo percorso di lavorazione - return GetClPathFinalAxesValues( nClPathId, vAxVal) ; -} - -//---------------------------------------------------------------------------- -bool -Machining::GetClPathFinalAxesValues( int nClPathId, DBLVECTOR& vAxVal) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero l'ultima entità di questo percorso - int nEntId = m_pGeomDB->GetLastInGroup( nClPathId) ; - // recupero i dati Cam dell'entità - CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; - if ( pCamData == nullptr) - return false ; - // assegno i valori degli assi - vAxVal = pCamData->GetAxesVal() ; - return ( vAxVal.size() > 0) ; -} - -//---------------------------------------------------------------------------- -bool -Machining::CalculateAxesValues( void) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero la lavorazione precedente non vuota - int nPrevOpId = m_pMchMgr->GetPrevActiveOperation( m_nOwnerId) ; - Machining* pPrevMch = GetMachining( m_pGeomDB->GetUserObj( nPrevOpId)) ; - while ( pPrevMch != nullptr) { - if ( ! pPrevMch->IsEmpty()) - break ; - else { - nPrevOpId = m_pMchMgr->GetPrevActiveOperation( nPrevOpId) ; - pPrevMch = GetMachining( m_pGeomDB->GetUserObj( nPrevOpId)) ; - } - } - // recupero l'utensile precedente - string sPrevTool ; - if ( pPrevMch != nullptr) - pPrevMch->GetParam( MPA_TOOL, sPrevTool) ; - - // imposto l'utensile per i calcoli macchina - if ( ! m_pMchMgr->SetCalcTool( GetToolData().m_sName, GetToolData().m_sHead, GetToolData().m_nExit)) - return false ; - - // rimuovo posizionamento home da lavorazione precedente (non può più essere l'ultima) - if ( pPrevMch != nullptr) - pPrevMch->RemoveHome() ; - - // recupero il numero di assi lineari e rotanti attivi - int nLinAxes = m_pMchMgr->GetCurrLinAxes() ; - int nRotAxes = m_pMchMgr->GetCurrRotAxes() ; - - // assegno gli angoli iniziali - double dAngAprec = 0 ; - double dAngBprec = 0 ; - DBLVECTOR vAxVal ; - // se utensile non cambiato, uso gli angoli finali della lavorazione precedente - if ( ! sPrevTool.empty() && GetToolData().m_sName == sPrevTool && - pPrevMch->GetFinalAxesValues( vAxVal)) { - if ( nRotAxes >= 1) - dAngAprec = vAxVal[nLinAxes - 1 + 1] ; - if ( nRotAxes >= 2) - dAngBprec = vAxVal[nLinAxes - 1 + 2] ; - } - // altrimenti uso gli angoli home - else { - m_pMchMgr->GetAllCalcAxesHomePos( vAxVal) ; - if ( nRotAxes >= 1) - dAngAprec = vAxVal[nLinAxes - 1 + 1] ; - if ( nRotAxes >= 2) - dAngBprec = vAxVal[nLinAxes - 1 + 2] ; - } - - // recupero peso primo asse rotante di testa - double dRot1W = m_pMchMgr->GetCalcRot1W() ; - - // recupero gruppo della geometria di lavorazione (Cutter Location) - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; - if ( nClId == GDB_ID_NULL) - return false ; - - // calcolo il valore degli assi macchina di tutti i movimenti - bool bOk = true ; - int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; - while ( nClPathId != GDB_ID_NULL) { - double dAngAprecOri = dAngAprec ; - double dAngBprecOri = dAngBprec ; - int nOutStrC = 0 ; - if ( ! CalculateClPathAxesValues( nClPathId, nLinAxes, nRotAxes, dRot1W, dAngAprec, dAngBprec, nOutStrC)) { - // se extracorsa dell'asse C, provo a precaricarlo al contrario - if ( nOutStrC != 0) { - dAngAprec = dAngAprecOri + ( nOutStrC > 0 ? - ANG_FULL : ANG_FULL) ; - dAngBprec = dAngBprecOri ; - if ( ! CalculateClPathAxesValues( nClPathId, nLinAxes, nRotAxes, dRot1W, dAngAprec, dAngBprec, nOutStrC)) - bOk = false ; - } - else - bOk = false ; - } - nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ; - } - - return bOk ; -} - -//---------------------------------------------------------------------------- -bool -Machining::CalculateClPathAxesValues( int nClPathId, int nLinAxes, int nRotAxes, double dRot1W, - double& dAngAprec, double& dAngBprec, int& nOutStrC) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero il numero degli assi lineari e rotanti - // predispongo variabile per valori assi - DBLVECTOR vAxVal ; - vAxVal.reserve( 8) ; - // variabili per coordinate lineari precedenti - double dXprec, dYprec, dZprec ; - // ciclo su tutte le entità del percorso CL - nOutStrC = 0 ; - bool bOk = true ; - bool bFirst = true ; - for ( int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; - nEntId != GDB_ID_NULL ; - nEntId = m_pGeomDB->GetNext( nEntId)) { - // recupero i dati Cam dell'entità - CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; - if ( pCamData == nullptr) - continue ; - // verifico che il primo movimento non sia un arco - if ( bFirst && pCamData->IsArc()) { - pCamData->ResetAxes() ; - LOG_INFO( GetEMkLogger(), "Error : first move in ClPath is an arc") - return false ; - } - // calcolo degli assi rotanti della macchina - int nRStat ; - double dAngA1, dAngB1, dAngA2, dAngB2 ; - bool bROk = m_pMchMgr->GetCalcAngles( pCamData->GetToolDir(), pCamData->GetCorrDir(), nRStat, dAngA1, dAngB1, dAngA2, dAngB2) ; - if ( ! bROk || nRStat == 0) { - bOk = false ; - pCamData->SetAxes( CamData::AS_DIR_ERR, vAxVal) ; - continue ; - } - if ( nRStat == 1) { - // se primo movimento - if ( bFirst) { - // porto gli angoli ai valori più vicini ai precedenti con offset di uno o più giri - m_pMchMgr->GetNearestAngleInStroke( 1, dAngAprec, dAngA1) ; - m_pMchMgr->GetNearestAngleInStroke( 2, dAngBprec, dAngB1) ; - } - // per movimenti successivi - else { - // scelgo gli angoli più vicini, per continuità non applico offset per stare nelle corse - dAngA1 = AngleNearAngle( dAngA1, dAngAprec) ; - dAngB1 = AngleNearAngle( dAngB1, dAngBprec) ; - } - } - if ( nRStat == 2) { - // se primo movimento - if ( bFirst) { - // porto gli angoli ai valori più vicini ai precedenti con offset di uno o più giri - m_pMchMgr->GetNearestAngleInStroke( 1, dAngAprec, dAngA1) ; - m_pMchMgr->GetNearestAngleInStroke( 2, dAngBprec, dAngB1) ; - m_pMchMgr->GetNearestAngleInStroke( 1, dAngAprec, dAngA2) ; - m_pMchMgr->GetNearestAngleInStroke( 2, dAngBprec, dAngB2) ; - } - else { - // scelgo gli angoli più vicini, per continuità non applico offset per stare nelle corse - dAngA1 = AngleNearAngle( dAngA1, dAngAprec) ; - dAngB1 = AngleNearAngle( dAngB1, dAngBprec) ; - dAngA2 = AngleNearAngle( dAngA2, dAngAprec) ; - dAngB2 = AngleNearAngle( dAngB2, dAngBprec) ; - } - // scelgo la soluzione più vicina ai precedenti - double dDeltaA1 = dRot1W * fabs( dAngA1 - dAngAprec) ; - double dDeltaB1 = fabs( dAngB1 - dAngBprec) ; - double dDeltaA2 = dRot1W * fabs( dAngA2 - dAngAprec) ; - double dDeltaB2 = fabs( dAngB2 - dAngBprec) ; - if ( dDeltaA2 + dDeltaB2 < dDeltaA1 + dDeltaB1 - 1.) { - dAngA1 = dAngA2 ; - dAngB1 = dAngB2 ; - } - } - // ricavo posizione con eventuali modifiche dipendenti dalla lavorazione - Point3d ptP = pCamData->GetEndPoint() ; - AdjustEndPointForAxesCalc( pCamData, ptP) ; - // calcolo gli assi lineari della macchina - int nLStat ; - double dX, dY, dZ ; - bool bLOk = m_pMchMgr->GetCalcPositions( ptP, dAngA1, dAngB1, nLStat, dX, dY, dZ) ; - if ( ! bLOk || nLStat != 0) { - bOk = false ; - pCamData->SetAxes( CamData::AS_ERR, vAxVal) ; - continue ; - } - // assegno valori assi - vAxVal.clear() ; - vAxVal.emplace_back( dX) ; - vAxVal.emplace_back( dY) ; - vAxVal.emplace_back( dZ) ; - vAxVal.emplace_back( dAngA1) ; - vAxVal.emplace_back( dAngB1) ; - // verifico i limiti di corsa degli assi - int nStat ; - bool bOsOk = m_pMchMgr->VerifyOutstroke( dX, dY, dZ, dAngA1, dAngB1, nStat) ; - if ( ! bOsOk || nStat != 0) { - bOk = false ; - pCamData->SetAxes( CamData::AS_OUTSTROKE, vAxVal) ; - if ( nOutStrC == 0) { - if ( (nStat & 64) != 0) - nOutStrC = - 1 ; - else if ( (nStat & 128) != 0) - nOutStrC = 1 ; - } - string sInfo = "Outstroke : " + m_pMchMgr->GetOutstrokeInfo() ; - LOG_INFO( GetEMkLogger(), sInfo.c_str()) - continue ; - } - // salvo i valori degli assi - pCamData->SetAxes( CamData::AS_OK, vAxVal) ; - // se arco (per ora solo nel piano XY) devo calcolarne il centro in assi macchina - if ( pCamData->IsArc()) { - // ricavo punto medio - Point3d ptCen = pCamData->GetCenter() ; - double dAngCen = pCamData->GetAngCen() ; - Point3d ptMid = ptP ; - ptMid.Rotate( ptCen, Z_AX, - dAngCen / 2) ; - // determino i valori degli assi al punto medio - double dAngAmid = ( dAngAprec + dAngA1) / 2 ; - double dAngBmid = ( dAngBprec + dAngB1) / 2 ; - int nLmidStat ; - double dXmid, dYmid, dZmid ; - bool bLmidOk = m_pMchMgr->GetCalcPositions( ptMid, dAngAmid, dAngBmid, nLmidStat, dXmid, dYmid, dZmid) ; - if ( ! bLmidOk || nLmidStat != 0) { - bOk = false ; - pCamData->SetAxes( CamData::AS_ERR, vAxVal) ; - continue ; - } - // punti espressi in assi macchina - Point3d ptP1M( dXprec, dYprec, dZprec) ; - Point3d ptP2M( dXmid, dYmid, dZmid) ; - Point3d ptP3M( dX, dY, dZ) ; - // se coincidono - if ( AreSamePointApprox( ptP1M, ptP2M) && AreSamePointApprox( ptP1M, ptP3M)) { - // lo considero un arco di raggio nullo - pCamData->SetAxesCen( ptP2M) ; - pCamData->SetAxesRad( 0) ; - pCamData->SetAxesAngCen( 0) ; - // il movimento diventa lineare - pCamData->SetMoveType( 1) ; - // non è necessario verificare i limiti di corsa degli assi - } - // altrimenti calcolo l'arco cui appartengono - else { - // calcolo arco per i tre punti espressi in assi macchina - PtrOwner pArc( CreateCurveArc()) ; - if ( IsNull( pArc) || ! pArc->Set3P( ptP1M, ptP2M, ptP3M, false)) { - bOk = false ; - continue ; - } - // verifico il piano - if ( pArc->GetNormVersor().z < 0) - pArc->InvertN() ; - // assegno il centro e il raggio di questo arco ai dati cam - pCamData->SetAxesCen( pArc->GetCenter()) ; - pCamData->SetAxesRad( pArc->GetRadius()) ; - pCamData->SetAxesAngCen( pArc->GetAngCenter()) ; - // aggiorno il tipo di arco - pCamData->SetMoveType( pArc->GetAngCenter() > 0 ? 3 : 2) ; - // verifico i limiti di corsa dei punti lungo l'arco - const int NUM_VERIF_STEP = 16 ; - Point3d ptCen = pCamData->GetAxesCen() ; - double dAngCenStep = pCamData->GetAxesAngCen() / NUM_VERIF_STEP ; - Vector3d vtCurr = Point3d( dXprec, dYprec, dZprec) - ptCen ; - for ( int i = 1 ; i < NUM_VERIF_STEP ; ++ i) { - vtCurr.Rotate( Z_AX, dAngCenStep) ; - Point3d ptCurr = ptCen + vtCurr ; - double dCoeff = i / NUM_VERIF_STEP ; - double dAngA = dAngAprec * ( 1 - dCoeff) + dAngA1 * dCoeff ; - double dAngB = dAngBprec * ( 1 - dCoeff) + dAngB1 * dCoeff ; - int nStat ; - bool bOsOk = m_pMchMgr->VerifyOutstroke( ptCurr.x, ptCurr.y, ptCurr.z, dAngA, dAngB, nStat) ; - if ( ! bOsOk || nStat != 0) { - bOk = false ; - pCamData->SetAxes( CamData::AS_OUTSTROKE, vAxVal) ; - string sInfo = "Outstroke : " + m_pMchMgr->GetOutstrokeInfo() ; - LOG_INFO( GetEMkLogger(), sInfo.c_str()) - continue ; - } - } - } - } - bFirst = false ; - // memorizzo i valori degli assi lineari come nuovi precedenti - dXprec = dX ; - dYprec = dY ; - dZprec = dZ ; - // memorizzo i valori degli angoli come nuovi precedenti - dAngAprec = dAngA1 ; - dAngBprec = dAngB1 ; - } - - return bOk ; -} - -//---------------------------------------------------------------------------- -bool -Machining::AdjustStartEndMovements(void) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero gruppo della geometria di lavorazione (Cutter Location) - int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ; - if ( nClId == GDB_ID_NULL) - return false ; - - // recupero la lavorazione precedente non vuota - int nPrevOpId = m_pMchMgr->GetPrevActiveOperation( m_nOwnerId) ; - Machining* pPrevMch = GetMachining( m_pGeomDB->GetUserObj( nPrevOpId)) ; - while ( pPrevMch != nullptr) { - if ( ! pPrevMch->IsEmpty()) - break ; - else { - nPrevOpId = m_pMchMgr->GetPrevActiveOperation( nPrevOpId) ; - pPrevMch = GetMachining( m_pGeomDB->GetUserObj( nPrevOpId)) ; - } - } - // recupero l'utensile precedente e i dati della sua testa - string sPrevTool ; - if ( pPrevMch != nullptr) - pPrevMch->GetParam( MPA_TOOL, sPrevTool) ; - - // imposto l'utensile per i calcoli macchina - if ( ! m_pMchMgr->SetCalcTool( GetToolData().m_sName, GetToolData().m_sHead, GetToolData().m_nExit)) - return false ; - - // determino posizione precedente assi - DBLVECTOR vAxVal ; - // se primo utensile, uso la posizione home - if ( sPrevTool.empty()) { - if ( ! m_pMchMgr->GetAllCalcAxesHomePos( vAxVal)) - return false ; - } - // se utensile non cambiato o su diversa uscita della stessa testa, uso posizione finale della lavorazione precedente - else if ( ! ToolChangeNeeded( pPrevMch->GetToolData(), GetToolData())) { - pPrevMch->RemoveRise() ; - DBLVECTOR vAxIni ; - if ( ! pPrevMch->GetFinalAxesValues( vAxVal) || ! GetInitialAxesValues( vAxIni)) - return false ; - // determino delta Z rispetto a posizione finale - if ( vAxVal.size() >= 4 && vAxIni.size() >= 4) { - double dDelta = 0 ; - if ( ! CalcDeltaZForHeadRotation( vAxVal, vAxIni, dDelta)) - return false ; - if ( dDelta > EPS_SMALL) { - if ( ! pPrevMch->AddRise( vAxVal, dDelta)) - return false ; - } - } - } - // altrimenti aggiungo uscita per cambio utensile alla lavorazione precedente e parto da questa - else { - pPrevMch->RemoveRise() ; - if ( ! pPrevMch->AddRise( vAxVal)) - return false ; - } - - // aggiusto l'inizio di ogni percorso di lavoro - bool bOk = true ; - int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; - while ( bOk && nClPathId != GDB_ID_NULL) { - // sistemo inizio - if ( ! AdjustOneStartMovement( nClPathId, vAxVal)) - bOk = false ; - // recupero nuovi finali - if ( ! GetClPathFinalAxesValues( nClPathId, vAxVal)) - bOk = false ; - // passo al successivo - nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ; - } - - // aggiungo risalita finale - bOk = bOk && AddRise( vAxVal) ; - bOk = bOk && AddHome() ; - - return bOk ; -} - -//---------------------------------------------------------------------------- -bool -Machining::AdjustOneStartMovement( int nClPathId, const DBLVECTOR& vAxPrev) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero la prima entità di questo percorso - int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; - // recupero i dati Cam dell'entità - CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; - if ( pCamData == nullptr) - return false ; - // recupero i valori degli assi - DBLVECTOR vAxCurr ; - vAxCurr = pCamData->GetAxesVal() ; - // se Z pressochè uguali non devo fare alcunché - if ( fabs( vAxCurr[2] - vAxPrev[2]) < 10 * EPS_SMALL) - return true ; - // se Z corrente maggiore della precedente - else if ( vAxCurr[2] > vAxPrev[2]) { - // copio l'entità - if ( m_pGeomDB->Copy( nEntId, GDB_ID_NULL, nEntId, GDB_AFTER) == GDB_ID_NULL) - return false ; - // modifico quella originale (è la prima del percorso) - DBLVECTOR vAxNew = vAxPrev ; - vAxNew[2] = vAxCurr[2] ; - pCamData->SetAxes( CamData::AS_OK, vAxNew) ; - pCamData->ChangeAxesMask( CamData::MSK_L3) ; - pCamData->SetFlag( 0) ; - } - // altrimenti Z corrente minore della precedente - else { - // copio l'entità - if ( m_pGeomDB->Copy( nEntId, GDB_ID_NULL, nEntId, GDB_AFTER) == GDB_ID_NULL) - return false ; - // modifico quella originale (è la prima del percorso) - DBLVECTOR vAxNew = vAxCurr ; - vAxNew[2] = vAxPrev[2] ; - pCamData->SetAxes( CamData::AS_OK, vAxNew) ; - pCamData->ChangeAxesMask( CamData::MSK_L1 | CamData::MSK_L2 | CamData::MSK_R1 | CamData::MSK_R2) ; - pCamData->SetFlag( 2) ; - } - - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::ToolChangeNeeded( const ToolData& T1, const ToolData& T2) -{ - // se non cambia l'utensile, non cambia la testa fisica - if ( EqualNoCase( T1.m_sName, T2.m_sName)) - return false ; - // se non hanno TcPos e stanno sulla stessa testa con uscita diversa, non cambia la testa fisica - if ( T1.m_sTcPos.empty() && T2.m_sTcPos.empty() && - EqualNoCase( T1.m_sHead, T2.m_sHead) && T1.m_nExit != T2.m_nExit) - return false ; - // se hanno lo stesso TcPos e stanno sulla stessa testa con uscita diversa, non cambia la testa fisica - if ( EqualNoCase( T1.m_sTcPos, T2.m_sTcPos) && - EqualNoCase( T1.m_sHead, T2.m_sHead) && T1.m_nExit != T2.m_nExit) - return false ; - // altrimenti necessario un cambio - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::AddRise( DBLVECTOR& vAxVal, double dDelta) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero gruppo per geometria di lavorazione (Cutter Location) - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; - if ( nClId == GDB_ID_NULL) - return false ; - // recupero l'ultimo percorso - int nLastPxClId = m_pGeomDB->GetLastGroupInGroup( nClId) ; - // recupero l'ultima entità del percorso - int nEntId = m_pGeomDB->GetLastInGroup( nLastPxClId) ; - if ( nEntId == GDB_ID_NULL) - return false ; - // ne recupero i dati Cam - CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; - if ( pCamData == nullptr) - return false ; - // creo oggetto punto per DB geometrico - PtrOwner pGP( CreateGeoPoint3d()) ; - if ( IsNull( pGP)) - return false ; - // assegno le coordinate del punto - pGP->Set( pCamData->GetEndPoint()) ; - // inserisco l'oggetto nel DB geometrico - int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLastPxClId, Release( pGP)) ; - if ( nId == GDB_ID_NULL) - return false ; - m_pGeomDB->SetName( nId, MCH_RISE) ; - // creo oggetto dati Cam - PtrOwner pCam( pCamData->Clone()) ; - if ( IsNull( pCam)) - return false ; - // recupero i valori degli assi - vAxVal = pCam->GetAxesVal() ; - // flag per tipo di movimento in rapido - int nFlag = 0 ; - // se delta positivo lo uso come incremento di Z - if ( dDelta > 0) { - vAxVal[2] += dDelta ; - nFlag = 0 ; // movimento standard - } - // altrimenti uso la Z home - else { - DBLVECTOR vAxHome ; - m_pMchMgr->GetAllCalcAxesHomePos( vAxHome) ; - vAxVal[2] = vAxHome[2] ; - nFlag = 3 ; // movimento a Zmax - } - // verifico extra-corsa dell'asse Z - double dL1 = vAxVal[0] ; - double dL2 = vAxVal[1] ; - double dL3 = vAxVal[2] ; - double dR1 = ( vAxVal.size() >= 4 ? vAxVal[3] : 0) ; - double dR2 = ( vAxVal.size() >= 5 ? vAxVal[4] : 0) ; - int nStat ; - bool bOk = ( m_pMchMgr->VerifyOutstroke( dL1, dL2, dL3, dR1, dR2, nStat) && nStat == 0) ; - // assegno i dati - pCam->SetAxes( (bOk ? CamData::AS_OK : CamData::AS_OUTSTROKE), vAxVal) ; - pCam->SetMoveType( 0) ; - pCam->SetFeed( 0) ; - pCam->SetFlag( nFlag) ; - // associo questo oggetto a quello geometrico - m_pGeomDB->SetUserObj( nId, Release( pCam)) ; - - return bOk ; -} - -//---------------------------------------------------------------------------- -bool -Machining::RemoveRise( void) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero gruppo per geometria di lavorazione (Cutter Location) - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; - if ( nClId == GDB_ID_NULL) - return false ; - // recupero l'ultimo percorso CL - int nClPathId = m_pGeomDB->GetLastGroupInGroup( nClId) ; - // elimino tutte le entità RISE alla fine del percorso - int nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_RISE) ; - while ( nId != GDB_ID_NULL) { - m_pGeomDB->Erase( nId) ; - nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_RISE) ; - } - // elimino a maggior ragione le entità HOME - nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_HOME) ; - while ( nId != GDB_ID_NULL) { - m_pGeomDB->Erase( nId) ; - nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_HOME) ; - } - - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::AddHome( void) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero gruppo per geometria di lavorazione (Cutter Location) - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; - if ( nClId == GDB_ID_NULL) - return false ; - // recupero l'ultimo percorso - int nLastPxClId = m_pGeomDB->GetLastGroupInGroup( nClId) ; - // recupero l'ultima entità del percorso di nome RISE - int nEntId = m_pGeomDB->GetLastNameInGroup( nLastPxClId, MCH_RISE) ; - if ( nEntId == GDB_ID_NULL) - return false ; - // ne recupero i dati Cam - CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; - if ( pCamData == nullptr) - return false ; - // creo oggetto punto per DB geometrico - PtrOwner pGP( CreateGeoPoint3d()) ; - if ( IsNull( pGP)) - return false ; - // assegno le coordinate del punto - pGP->Set( pCamData->GetEndPoint()) ; - // inserisco l'oggetto nel DB geometrico - int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLastPxClId, Release( pGP)) ; - if ( nId == GDB_ID_NULL) - return false ; - m_pGeomDB->SetName( nId, MCH_HOME) ; - // creo oggetto dati Cam - PtrOwner pCam( pCamData->Clone()) ; - if ( IsNull( pCam)) - return false ; - // flag per tipo di movimento in rapido (rapido a Home) - int nFlag = 4 ; - // recupero coordinate home - DBLVECTOR vAxHome ; - m_pMchMgr->GetAllCalcAxesHomePos( vAxHome) ; - // assegno i dati - pCam->SetAxes( CamData::AS_OK, vAxHome) ; - pCam->SetMoveType( 0) ; - pCam->SetFeed( 0) ; - pCam->SetFlag( nFlag) ; - // associo questo oggetto a quello geometrico - m_pGeomDB->SetUserObj( nId, Release( pCam)) ; - - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::RemoveHome( void) -{ - if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) - return false ; - // recupero gruppo per geometria di lavorazione (Cutter Location) - int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; - if ( nClId == GDB_ID_NULL) - return false ; - // recupero l'ultimo percorso CL - int nClPathId = m_pGeomDB->GetLastGroupInGroup( nClId) ; - // elimino tutte le entità HOME alla fine del percorso - int nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_HOME) ; - while ( nId != GDB_ID_NULL) { - m_pGeomDB->Erase( nId) ; - nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_HOME) ; - } - - return true ; -} - -//---------------------------------------------------------------------------- -bool -Machining::CalcDeltaZForHeadRotation( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, double& dDeltaZ) -{ - // il numero di assi deve essere costante - if ( vAxStart.size() != vAxEnd.size()) - return false ; - // se ci sono solo assi lineari, non delta Z nullo - if ( vAxStart.size() <= 3) { - dDeltaZ = 0 ; - return true ; - } - // determino gli estremi del movimento rotatorio - double dR1Start = ( vAxStart.size() >= 4 ? vAxStart[3] : 0) ; - double dR2Start = ( vAxStart.size() >= 5 ? vAxStart[4] : 0) ; - double dR1End = ( vAxEnd.size() >= 4 ? vAxEnd[3] : 0) ; - double dR2End = ( vAxEnd.size() >= 5 ? vAxEnd[4] : 0) ; - // determino le variazioni di ciascun asse - double dR1Delta = dR1End - dR1Start ; - double dR2Delta = dR2End - dR2Start ; - // divido il movimento in step di massimo 15 gradi - int nStep = int( max( abs( dR1Delta), abs( dR2Delta)) / 15.0) + 1 ; - double dR1Step = dR1Delta / nStep ; - double dR2Step = dR2Delta / nStep ; - // calcolo - double dL1 = vAxStart[0] ; - double dL2 = vAxStart[1] ; - double dL3 = vAxStart[2] ; - double dZStart, dZmin ; - for ( int i = 0 ; i <= nStep ; ++ i) { - double dR1 = dR1Start + i * dR1Step ; - double dR2 = dR2Start + i * dR2Step ; - Point3d ptTip ; - if ( ! m_pMchMgr->GetCalcTipFromPositions( dL1, dL2, dL3, dR1, dR2, true, ptTip)) - return false ; - if ( i == 0) { - dZStart = ptTip.z ; - dZmin = dZStart ; - } - else if ( ptTip.z < dZmin) - dZmin = ptTip.z ; - } - dDeltaZ = dZStart - dZmin ; - return true ; -} \ No newline at end of file diff --git a/Machining.h b/Machining.h index d009dfa..4681e65 100644 --- a/Machining.h +++ b/Machining.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2015-2015 +// EgalTech 2015-2016 //---------------------------------------------------------------------------- -// File : Machining.h Data : 07.06.15 Versione : 1.6f2 +// File : Machining.h Data : 29.04.16 Versione : 1.6p4 // Contenuto : Dichiarazione della classe Machining da cui derivano // tutti i gestori delle lavorazioni. // @@ -14,27 +14,16 @@ #pragma once -#include "/EgtDev/Include/EGkPoint3d.h" -#include "/EgtDev/Include/EGkUserObj.h" -#include "/EgtDev/Include/EGkSelection.h" -#include "/EgtDev/Include/EgtNumCollection.h" - -class MachMgr ; +#include "Operation.h" //---------------------------------------------------------------------------- -class Machining : public IUserObj +class Machining : public Operation { - public : // IUserObj - bool SetOwner( int nId, IGeomDB* pGDB) override ; - int GetOwner( void) const override ; - IGeomDB* GetGeomDB( void) const override ; - - public : - virtual bool Init( MachMgr* pMchMgr) ; - virtual bool SetPhase( int nPhase) - { m_nPhase = nPhase ; return true ; } - virtual int GetPhase( void) const - { return m_nPhase ; } + protected : // Operation + const std::string& GetToolName( void) const ; + const std::string& GetHeadName( void) const ; + int GetExitNbr( void) const ; + const std::string& GetToolTcPos( void) const ; public : virtual bool Prepare( const std::string& sMchName) = 0 ; @@ -51,66 +40,9 @@ class Machining : public IUserObj virtual bool GetParam( int nType, std::string& sVal) const = 0 ; virtual const ToolData& GetToolData( void) const = 0 ; virtual bool GetGeometry( SELVECTOR& vIds) const = 0 ; - virtual bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) = 0 ; - virtual bool IsEmpty( void) const = 0 ; protected : Machining( void) ; - - protected : - bool GetElevation( int nPhase, const Point3d& ptP, - const Vector3d& vtDir, double& dElev) ; - bool GetElevation( int nPhase, const Point3d& ptP1, const Point3d& ptP2, - const Vector3d& vtDir, double& dElev) ; - bool GetElevation( int nPhase, const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptP3, - const Vector3d& vtDir, double& dElev) ; - bool GetDistanceFromRawSide( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist) ; - bool GetDistanceFromRawBottom( int nPhase, int nPathId, double dToler, double& dRbDist) ; - bool GetRawGlobBox( int nPhase, int nPathId, BBox3d& b3Raw) ; - bool GetInitialAxesValues( DBLVECTOR& vAxVal) ; - bool GetClPathInitialAxesValues( int nClPathId, DBLVECTOR& vAxVal) ; - bool GetFinalAxesValues( DBLVECTOR& vAxVal) ; - bool GetClPathFinalAxesValues( int nClPathId, DBLVECTOR& vAxVal) ; - bool CalculateAxesValues( void) ; - bool CalculateClPathAxesValues( int nClPathId, int nLinAxes, int nRotAxes, double dRot1W, - double& dAngAprec, double& dAngBprec, int& nOutStrC) ; - bool AdjustStartEndMovements( void) ; - bool AdjustOneStartMovement( int nClPathId, const DBLVECTOR& vAxPrev) ; - bool ToolChangeNeeded( const ToolData& T1, const ToolData& T2) ; - bool AddRise( DBLVECTOR& vAxVal, double dDelta = - 1) ; - bool RemoveRise( void) ; - bool AddHome( void) ; - bool RemoveHome( void) ; - bool CalcDeltaZForHeadRotation( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, double& dDeltaZ) ; - - protected : - bool SetPathId( int nPathId) ; - bool SetToolDir( const Vector3d& vtDir) ; - bool SetCorrDir( const Vector3d& vtDir) ; - bool SetAuxDir( const Vector3d& vtDir) ; - bool SetFeed( double dFeed) ; - bool SetFlag( int nFlag) ; - bool GetCurrPos( Point3d& ptCurr) - { if ( ! m_bCurr) return false ; ptCurr = m_ptCurr ; return true ; } - int AddRapidStart( const Point3d& ptP) ; - int AddRapidMove( const Point3d& ptP) ; - int AddLinearMove( const Point3d& ptP) ; - int AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, double dDeltaZ = 0) ; - bool ResetMoveData( void) ; - - protected : - int m_nOwnerId ; // identificativo dell'oggetto geometrico possessore - IGeomDB* m_pGeomDB ; // puntatore al DB geometrico - MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni - int m_nPhase ; // indice della fase di appartenenza (da 1 in su) - int m_nPathId ; // identificativo del gruppo corrente di inserimento dati - bool m_bCurr ; // punto corrente valido - Point3d m_ptCurr ; // posizione corrente - Vector3d m_vtTool ; // direzione fresa corrente - Vector3d m_vtCorr ; // direzione correzione corrente - Vector3d m_vtAux ; // direzione ausiliaria corrente - double m_dFeed ; // feed corrente - int m_nFlag ; // flag corrente } ; //---------------------------------------------------------------------------- diff --git a/Milling.h b/Milling.h index 3f512be..3569e4d 100644 --- a/Milling.h +++ b/Milling.h @@ -31,6 +31,13 @@ class Milling : public Machining bool Save( STRVECTOR& vString) const override ; bool Load( const STRVECTOR& vString) override ; + public : // Operation + bool IsEmpty( void) const override + { return ( m_nMills == 0) ; } + + protected : // Operation + bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; + public : // Machining bool Prepare( const std::string& sMillName) override ; bool SetParam( int nType, bool bVal) override ; @@ -46,9 +53,6 @@ class Milling : public Machining bool GetParam( int nType, std::string& sVal) const override ; const ToolData& GetToolData( void) const ; bool GetGeometry( SELVECTOR& vIds) const override ; - bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; - bool IsEmpty( void) const override - { return ( m_nMills == 0) ; } public : Milling( void) ; diff --git a/Operation.cpp b/Operation.cpp new file mode 100644 index 0000000..dfeb917 --- /dev/null +++ b/Operation.cpp @@ -0,0 +1,1321 @@ +//---------------------------------------------------------------------------- +// EgalTech 2016-2016 +//---------------------------------------------------------------------------- +// File : Operation.cpp Data : 29.04.16 Versione : 1.6p4 +// Contenuto : Implementazione gestione base operazioni. +// +// +// +// Modifiche : 29.04.16 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "DllMain.h" +#include "Operation.h" +#include "MachMgr.h" +#include "/EgtDev/Include/EGkAngle.h" +#include "/EgtDev/Include/EGkGeoPoint3d.h" +#include "/EgtDev/Include/EGkCurveLine.h" +#include "/EgtDev/Include/EGkCurveArc.h" +#include "/EgtDev/Include/EgkDistPointCurve.h" +#include "/EgtDev/Include/EgkIntersCurves.h" +#include "/EgtDev/Include/EGkIntersLineSurfTm.h" +#include "/EgtDev/Include/EGkGeomDB.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +Operation::SetOwner( int nId, IGeomDB* pGDB) +{ + m_nOwnerId = nId ; + m_pGeomDB = pGDB ; + return ( m_nOwnerId != GDB_ID_NULL && m_pGeomDB != nullptr) ; +} + +//---------------------------------------------------------------------------- +int +Operation::GetOwner( void) const +{ + return m_nOwnerId ; +} + +//---------------------------------------------------------------------------- +IGeomDB* +Operation::GetGeomDB( void) const +{ + return m_pGeomDB ; +} + +//---------------------------------------------------------------------------- +bool +Operation::Init( MachMgr* pMchMgr) +{ + m_pMchMgr = pMchMgr ; + if ( m_pMchMgr == nullptr) + return false ; + if ( m_pMchMgr->GetGeomDB() != m_pGeomDB) + return false ; + return true ; +} + +//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +Operation::Operation( void) + : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr), m_pMchMgr( nullptr), m_nPhase( 1), + m_nPathId( GDB_ID_NULL), m_bCurr( false), m_ptCurr(), + m_vtTool(), m_vtCorr(), m_vtAux(), m_dFeed( 0), m_nFlag( 0) +{ +} + +//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +bool +Operation::GetElevation( int nPhase, const Point3d& ptP, + const Vector3d& vtDir, double& dElev) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // inizializzo elevazione + dElev = INFINITO ; + // ciclo sui grezzi + bool bFound = false ; + int nRawId = m_pMchMgr->GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // verifico che il grezzo compaia nella fase + if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { + // intersezione del raggio dal punto alla trimesh del grezzo + const double RAY_LEN = 10000 ; + int nStmId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + ISurfTriMesh* pStm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nStmId)) ; + if ( pStm != nullptr) { + bFound = true ; + // recupero il riferimento della trimesh + Frame3d frStm ; + m_pGeomDB->GetGlobFrame( nStmId, frStm) ; + // porto il raggio in questo riferimento + Point3d ptPL = ptP ; + ptPL.ToLoc( frStm) ; + Vector3d vtDirL = vtDir ; + vtDirL.ToLoc( frStm) ; + ILSIVECTOR vInfo ; + if ( IntersLineSurfTm( ptPL, vtDirL, RAY_LEN, *pStm, vInfo)) { + for ( const auto& Info : vInfo) { + // se tratto di intersezione coincidente, considero la posizione più lontana, ovvero 2 + if ( Info.nILTT == ILTT_SEGM || Info.nILTT == ILTT_SEGM_ON_EDGE) { + // se prosegue un tratto precedente, non devo controllare sia minimo + if ( fabs( dElev - Info.dU) < EPS_SMALL) + dElev = Info.dU2 ; + else + dElev = min( dElev, Info.dU2) ; + } + // altrimenti intersezione puntuale, verifico che esca (coseno >= 0) + else if ( Info.dCosDN > - COS_ORTO_ANG_ZERO) { + dElev = min( dElev, Info.dU) ; + } + } + } + } + } + // passo al grezzo successivo + nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; + } + // se non trovate intersezioni, elevazione nulla + if ( dElev > INFINITO - 1) + dElev = 0 ; + return bFound ; +} + +//---------------------------------------------------------------------------- +bool +Operation::GetElevation( int nPhase, const Point3d& ptP1, const Point3d& ptP2, + const Vector3d& vtDir, double& dElev) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // inizializzo elevazione + dElev = INFINITO ; + // ciclo sui grezzi + bool bFound = false ; + int nRawId = m_pMchMgr->GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // verifico che il grezzo compaia nella fase + if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { + // intersezione del raggio dal punto alla trimesh del grezzo + const double RAY_LEN = 10000 ; + int nStmId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + ISurfTriMesh* pStm = GetSurfTriMesh( m_pGeomDB->GetGeoObj( nStmId)) ; + if ( pStm != nullptr) { + bFound = true ; + // recupero il riferimento della trimesh + Frame3d frStm ; + m_pGeomDB->GetGlobFrame( nStmId, frStm) ; + // porto il segmento e la direzione in questo riferimento + Point3d ptP1L = ptP1 ; + ptP1L.ToLoc( frStm) ; + Point3d ptP2L = ptP2 ; + ptP2L.ToLoc( frStm) ; + Vector3d vtDirL = vtDir ; + vtDirL.ToLoc( frStm) ; + ILSIVECTOR vInfo ; + // inizializzo elevazione della superficie + double dElevS = 0 ; + // faccio test con un insieme di punti ( !!! sostituire con intersezione tra rettangolo e trimesh !!!) + const double STEP = 50 ; + int nStep = max( (int) ceil( ApproxDist( ptP1L, ptP2L) / STEP), 3) ; + for ( int i = 0 ; i <= nStep ; ++ i) { + // calcolo punto di test + double dFraz = i / (double) nStep ; + Point3d ptPL = Media( ptP1L, ptP2L, dFraz) ; + // inizializzo elevazione del punto + double dElevP = INFINITO ; + // calcolo elevazione sul punto + if ( IntersLineSurfTm( ptPL, vtDirL, RAY_LEN, *pStm, vInfo)) { + for ( const auto& Info : vInfo) { + // se tratto di intersezione coincidente, considero la posizione più lontana, ovvero 2 + if ( Info.nILTT == ILTT_SEGM || Info.nILTT == ILTT_SEGM_ON_EDGE) { + // se prosegue un tratto precedente, non devo controllare sia minimo + if ( fabs( dElevP - Info.dU) < EPS_SMALL) + dElevP = Info.dU2 ; + else + dElevP = min( dElevP, Info.dU2) ; + } + // altrimenti intersezione puntuale, verifico che esca (coseno >= 0) + else if ( Info.dCosDN > - COS_ORTO_ANG_ZERO) { + dElevP = min( dElevP, Info.dU) ; + } + } + } + // se elevazione calcolata, aggiorno quella della superficie + if ( dElevP < INFINITO - 1) + dElevS = max( dElevS, dElevP) ; + } + // aggiorno elevazione complessiva + if ( dElevS > 0) + dElev = min( dElev, dElevS) ; + } + } + // passo al grezzo successivo + nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; + } + // se non trovate intersezioni, elevazione nulla + if ( dElev > INFINITO - 1) + dElev = 0 ; + return bFound ; +} + +//---------------------------------------------------------------------------- +bool +Operation::GetElevation( int nPhase, const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptP3, + const Vector3d& vtDir, double& dElev) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // approssimo l'arco con due linee + double dElev1, dElev2 ; + if ( ! GetElevation( nPhase, ptP1, ptP2, vtDir, dElev1)) + return false ; + if ( ! GetElevation( nPhase, ptP2, ptP3, vtDir, dElev2)) + return false ; + dElev = max( dElev1, dElev2) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::GetDistanceFromRawSide( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero il grezzo in cui è incluso il punto + BBox3d b3Pnt( ptP) ; + b3Pnt.Expand( 10, 10, 0) ; + int nRawId = m_pMchMgr->GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // verifico che il grezzo compaia nella fase + if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { + // pre-filtro con il box + BBox3d b3Raw ; + int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + if ( m_pGeomDB->GetGlobalBBox( nRawSolidId, b3Raw) && b3Pnt.OverlapsXY( b3Raw)) { + // porto il punto nel riferimento del grezzo + Frame3d frRaw ; + m_pGeomDB->GetGroupGlobFrame( nRawId, frRaw) ; + Point3d ptPL = ptP ; + ptPL.ToLoc( frRaw) ; + // verifica con il contorno + int nOutCrvId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_OUTLINE) ; + ICurve* pCurve = GetCurve( m_pGeomDB->GetGeoObj( nOutCrvId)) ; + if ( pCurve != nullptr) { + int nSide ; + double dDist ; + DistPointCurve distPC( ptPL, *pCurve) ; + if ( distPC.GetDist( dDist) && dDist < 100 * EPS_SMALL || + (distPC.GetSideAtMinDistPoint( 0, Z_AX, nSide) && nSide != MDS_RIGHT)) + break ; + } + } + } + // passo al grezzo successivo + nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; + } + // se il punto non è interno ad alcun grezzo, distanza nulla + if ( nRawId == GDB_ID_NULL) { + dDist = 0 ; + return true ; + } + // recupero il contorno del grezzo + int nOutId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_OUTLINE) ; + ICurve* pOut = ::GetCurve( m_pGeomDB->GetGeoObj( nOutId)) ; + if ( pOut == nullptr) + return false ; + // recupero il riferimento del contorno e verifico che abbia Z verticale + Frame3d frStm ; + if ( ! m_pGeomDB->GetGlobFrame( nOutId, frStm) || + ( frStm.GetZType() != Frame3d::TOP && frStm.GetZType() != Frame3d::BOTTOM)) + return false ; + // interseco il raggio di test (portato nel riferimento del contorno) con il contorno del grezzo + const double RAY_LEN = 10000 ; + PtrOwner pRay( CreateCurveLine()) ; + if ( IsNull( pRay) || ! pRay->SetPVL( ptP, vtDir, RAY_LEN)) + return false ; + pRay->ToLoc( frStm) ; + IntersCurveCurve intCC( *pRay, *pOut) ; + IntCrvCrvInfo aInfo ; + if ( intCC.GetIntCrvCrvInfo( 0, aInfo)) + dDist = aInfo.IciA[0].dU * RAY_LEN ; + else + dDist = 0 ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::GetDistanceFromRawBottom( int nPhase, int nPathId, double dToler, double& dRbDist) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero distanza da fondo dei grezzi interessati dal percorso + dRbDist = 0 ; + BBox3d b3Compo ; + if ( ! m_pGeomDB->GetGlobalBBox( nPathId, b3Compo)) + return false ; + b3Compo.Expand( dToler, dToler, 0) ; + int nRawId = m_pMchMgr->GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // verifico che il grezzo compaia nella fase + if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { + BBox3d b3Raw ; + int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + if ( m_pGeomDB->GetGlobalBBox( nRawSolidId, b3Raw) && b3Compo.OverlapsXY( b3Raw)) { + double dDist = b3Compo.GetMax().z - b3Raw.GetMin().z ; + if ( dDist > dRbDist) + dRbDist = dDist ; + } + } + // passo al grezzo successivo + nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::GetRawGlobBox( int nPhase, int nPathId, BBox3d& b3Raw) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // inizializzo box + b3Raw.Reset() ; + // ricerco grezzi interessati dal percorso + BBox3d b3Compo ; + if ( ! m_pGeomDB->GetGlobalBBox( nPathId, b3Compo)) + return false ; + b3Compo.Expand( 10 * EPS_SMALL, 10 * EPS_SMALL, 0) ; + int nRawId = m_pMchMgr->GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // verifico che il grezzo compaia nella fase + if ( m_pMchMgr->VerifyRawPartPhase( nRawId, nPhase)) { + BBox3d b3OneRaw ; + int nRawSolidId = m_pGeomDB->GetFirstNameInGroup( nRawId, MACH_RAW_SOLID) ; + if ( m_pGeomDB->GetGlobalBBox( nRawSolidId, b3OneRaw) && b3Compo.OverlapsXY( b3OneRaw)) { + b3Raw.Add( b3OneRaw) ; + } + } + // passo al grezzo successivo + nRawId = m_pMchMgr->GetNextRawPart( nRawId) ; + } + return true ; +} + +//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +bool +Operation::GetInitialAxesValues( DBLVECTOR& vAxVal) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero gruppo per geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + // recupero il primo percorso CL + int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + // restituisco i valori iniziali degli assi di questo percorso di lavorazione + return GetClPathInitialAxesValues( nClPathId, vAxVal) ; +} + +//---------------------------------------------------------------------------- +bool +Operation::GetClPathInitialAxesValues( int nClPathId, DBLVECTOR& vAxVal) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero la prima entità di questo percorso + int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; + // recupero i dati Cam dell'entità + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; + if ( pCamData == nullptr) + return false ; + // assegno i valori degli assi + vAxVal = pCamData->GetAxesVal() ; + return ( vAxVal.size() > 0) ; +} + +//---------------------------------------------------------------------------- +bool +Operation::GetFinalAxesValues( DBLVECTOR& vAxVal) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero gruppo per geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + // recupero l'ultimo percorso CL + int nClPathId = m_pGeomDB->GetLastGroupInGroup( nClId) ; + // restituisco i valori finali degli assi di questo percorso di lavorazione + return GetClPathFinalAxesValues( nClPathId, vAxVal) ; +} + +//---------------------------------------------------------------------------- +bool +Operation::GetClPathFinalAxesValues( int nClPathId, DBLVECTOR& vAxVal) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero l'ultima entità di questo percorso + int nEntId = m_pGeomDB->GetLastInGroup( nClPathId) ; + // recupero i dati Cam dell'entità + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; + if ( pCamData == nullptr) + return false ; + // assegno i valori degli assi + vAxVal = pCamData->GetAxesVal() ; + return ( vAxVal.size() > 0) ; +} + +//---------------------------------------------------------------------------- +bool +Operation::CalculateAxesValues( void) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero l'operazione precedente non vuota + int nPrevOpId = m_pMchMgr->GetPrevActiveOperation( m_nOwnerId) ; + Operation* pPrevOp = GetOperation( m_pGeomDB->GetUserObj( nPrevOpId)) ; + while ( pPrevOp != nullptr) { + if ( ! pPrevOp->IsEmpty()) + break ; + else { + nPrevOpId = m_pMchMgr->GetPrevActiveOperation( nPrevOpId) ; + pPrevOp = GetOperation( m_pGeomDB->GetUserObj( nPrevOpId)) ; + } + } + // recupero l'utensile precedente + string sPrevTool ; + if ( pPrevOp != nullptr) + sPrevTool = pPrevOp->GetToolName() ; + + // imposto l'utensile per i calcoli macchina + if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + + // rimuovo posizionamento home da lavorazione precedente (non può più essere l'ultima) + if ( pPrevOp != nullptr) + pPrevOp->RemoveHome() ; + + // recupero il numero di assi lineari e rotanti attivi + int nLinAxes = m_pMchMgr->GetCurrLinAxes() ; + int nRotAxes = m_pMchMgr->GetCurrRotAxes() ; + + // assegno gli angoli iniziali + double dAngAprec = 0 ; + double dAngBprec = 0 ; + DBLVECTOR vAxVal ; + // se utensile non cambiato, uso gli angoli finali della lavorazione precedente + if ( ! sPrevTool.empty() && GetToolName() == sPrevTool && + pPrevOp->GetFinalAxesValues( vAxVal)) { + if ( nRotAxes >= 1) + dAngAprec = vAxVal[nLinAxes - 1 + 1] ; + if ( nRotAxes >= 2) + dAngBprec = vAxVal[nLinAxes - 1 + 2] ; + } + // altrimenti uso gli angoli home + else { + m_pMchMgr->GetAllCalcAxesHomePos( vAxVal) ; + if ( nRotAxes >= 1) + dAngAprec = vAxVal[nLinAxes - 1 + 1] ; + if ( nRotAxes >= 2) + dAngBprec = vAxVal[nLinAxes - 1 + 2] ; + } + + // recupero peso primo asse rotante di testa + double dRot1W = m_pMchMgr->GetCalcRot1W() ; + + // recupero gruppo della geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + + // calcolo il valore degli assi macchina di tutti i movimenti + bool bOk = true ; + int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + while ( nClPathId != GDB_ID_NULL) { + double dAngAprecOri = dAngAprec ; + double dAngBprecOri = dAngBprec ; + int nOutStrC = 0 ; + if ( ! CalculateClPathAxesValues( nClPathId, nLinAxes, nRotAxes, dRot1W, dAngAprec, dAngBprec, nOutStrC)) { + // se extracorsa dell'asse C, provo a precaricarlo al contrario + if ( nOutStrC != 0) { + dAngAprec = dAngAprecOri + ( nOutStrC > 0 ? - ANG_FULL : ANG_FULL) ; + dAngBprec = dAngBprecOri ; + if ( ! CalculateClPathAxesValues( nClPathId, nLinAxes, nRotAxes, dRot1W, dAngAprec, dAngBprec, nOutStrC)) + bOk = false ; + } + else + bOk = false ; + } + nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ; + } + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Operation::CalculateClPathAxesValues( int nClPathId, int nLinAxes, int nRotAxes, double dRot1W, + double& dAngAprec, double& dAngBprec, int& nOutStrC) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero il numero degli assi lineari e rotanti + // predispongo variabile per valori assi + DBLVECTOR vAxVal ; + vAxVal.reserve( 8) ; + // variabili per coordinate lineari precedenti + double dXprec, dYprec, dZprec ; + // ciclo su tutte le entità del percorso CL + nOutStrC = 0 ; + bool bOk = true ; + bool bFirst = true ; + for ( int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; + nEntId != GDB_ID_NULL ; + nEntId = m_pGeomDB->GetNext( nEntId)) { + // recupero i dati Cam dell'entità + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; + if ( pCamData == nullptr) + continue ; + // verifico che il primo movimento non sia un arco + if ( bFirst && pCamData->IsArc()) { + pCamData->ResetAxes() ; + LOG_INFO( GetEMkLogger(), "Error : first move in ClPath is an arc") + return false ; + } + // calcolo degli assi rotanti della macchina + int nRStat ; + double dAngA1, dAngB1, dAngA2, dAngB2 ; + bool bROk = m_pMchMgr->GetCalcAngles( pCamData->GetToolDir(), pCamData->GetAuxDir(), nRStat, dAngA1, dAngB1, dAngA2, dAngB2) ; + if ( ! bROk || nRStat == 0) { + bOk = false ; + pCamData->SetAxes( CamData::AS_DIR_ERR, vAxVal) ; + continue ; + } + if ( nRStat == 1) { + // se primo movimento + if ( bFirst) { + // porto gli angoli ai valori più vicini ai precedenti con offset di uno o più giri + m_pMchMgr->GetNearestAngleInStroke( 1, dAngAprec, dAngA1) ; + m_pMchMgr->GetNearestAngleInStroke( 2, dAngBprec, dAngB1) ; + } + // per movimenti successivi + else { + // scelgo gli angoli più vicini, per continuità non applico offset per stare nelle corse + dAngA1 = AngleNearAngle( dAngA1, dAngAprec) ; + dAngB1 = AngleNearAngle( dAngB1, dAngBprec) ; + } + } + if ( nRStat == 2) { + // se primo movimento + if ( bFirst) { + // porto gli angoli ai valori più vicini ai precedenti con offset di uno o più giri + m_pMchMgr->GetNearestAngleInStroke( 1, dAngAprec, dAngA1) ; + m_pMchMgr->GetNearestAngleInStroke( 2, dAngBprec, dAngB1) ; + m_pMchMgr->GetNearestAngleInStroke( 1, dAngAprec, dAngA2) ; + m_pMchMgr->GetNearestAngleInStroke( 2, dAngBprec, dAngB2) ; + } + else { + // scelgo gli angoli più vicini, per continuità non applico offset per stare nelle corse + dAngA1 = AngleNearAngle( dAngA1, dAngAprec) ; + dAngB1 = AngleNearAngle( dAngB1, dAngBprec) ; + dAngA2 = AngleNearAngle( dAngA2, dAngAprec) ; + dAngB2 = AngleNearAngle( dAngB2, dAngBprec) ; + } + // scelgo la soluzione più vicina ai precedenti + double dDeltaA1 = dRot1W * fabs( dAngA1 - dAngAprec) ; + double dDeltaB1 = fabs( dAngB1 - dAngBprec) ; + double dDeltaA2 = dRot1W * fabs( dAngA2 - dAngAprec) ; + double dDeltaB2 = fabs( dAngB2 - dAngBprec) ; + if ( dDeltaA2 + dDeltaB2 < dDeltaA1 + dDeltaB1 - 1.) { + dAngA1 = dAngA2 ; + dAngB1 = dAngB2 ; + } + } + // ricavo posizione con eventuali modifiche dipendenti dalla lavorazione + Point3d ptP = pCamData->GetEndPoint() ; + AdjustEndPointForAxesCalc( pCamData, ptP) ; + // calcolo gli assi lineari della macchina + int nLStat ; + double dX, dY, dZ ; + bool bLOk = m_pMchMgr->GetCalcPositions( ptP, dAngA1, dAngB1, nLStat, dX, dY, dZ) ; + if ( ! bLOk || nLStat != 0) { + bOk = false ; + pCamData->SetAxes( CamData::AS_ERR, vAxVal) ; + continue ; + } + // assegno valori assi + vAxVal.clear() ; + vAxVal.emplace_back( dX) ; + vAxVal.emplace_back( dY) ; + vAxVal.emplace_back( dZ) ; + vAxVal.emplace_back( dAngA1) ; + vAxVal.emplace_back( dAngB1) ; + // verifico i limiti di corsa degli assi + int nStat ; + bool bOsOk = m_pMchMgr->VerifyOutstroke( dX, dY, dZ, dAngA1, dAngB1, nStat) ; + if ( ! bOsOk || nStat != 0) { + bOk = false ; + pCamData->SetAxes( CamData::AS_OUTSTROKE, vAxVal) ; + if ( nOutStrC == 0) { + if ( (nStat & 64) != 0) + nOutStrC = - 1 ; + else if ( (nStat & 128) != 0) + nOutStrC = 1 ; + } + string sInfo = "Outstroke : " + m_pMchMgr->GetOutstrokeInfo() ; + LOG_INFO( GetEMkLogger(), sInfo.c_str()) + continue ; + } + // salvo i valori degli assi + pCamData->SetAxes( CamData::AS_OK, vAxVal) ; + // se arco (per ora solo nel piano XY) devo calcolarne il centro in assi macchina + if ( pCamData->IsArc()) { + // ricavo punto medio + Point3d ptCen = pCamData->GetCenter() ; + double dAngCen = pCamData->GetAngCen() ; + Point3d ptMid = ptP ; + ptMid.Rotate( ptCen, Z_AX, - dAngCen / 2) ; + // determino i valori degli assi al punto medio + double dAngAmid = ( dAngAprec + dAngA1) / 2 ; + double dAngBmid = ( dAngBprec + dAngB1) / 2 ; + int nLmidStat ; + double dXmid, dYmid, dZmid ; + bool bLmidOk = m_pMchMgr->GetCalcPositions( ptMid, dAngAmid, dAngBmid, nLmidStat, dXmid, dYmid, dZmid) ; + if ( ! bLmidOk || nLmidStat != 0) { + bOk = false ; + pCamData->SetAxes( CamData::AS_ERR, vAxVal) ; + continue ; + } + // punti espressi in assi macchina + Point3d ptP1M( dXprec, dYprec, dZprec) ; + Point3d ptP2M( dXmid, dYmid, dZmid) ; + Point3d ptP3M( dX, dY, dZ) ; + // se coincidono + if ( AreSamePointApprox( ptP1M, ptP2M) && AreSamePointApprox( ptP1M, ptP3M)) { + // lo considero un arco di raggio nullo + pCamData->SetAxesCen( ptP2M) ; + pCamData->SetAxesRad( 0) ; + pCamData->SetAxesAngCen( 0) ; + // il movimento diventa lineare + pCamData->SetMoveType( 1) ; + // non è necessario verificare i limiti di corsa degli assi + } + // altrimenti calcolo l'arco cui appartengono + else { + // calcolo arco per i tre punti espressi in assi macchina + PtrOwner pArc( CreateCurveArc()) ; + if ( IsNull( pArc) || ! pArc->Set3P( ptP1M, ptP2M, ptP3M, false)) { + bOk = false ; + continue ; + } + // verifico il piano + if ( pArc->GetNormVersor().z < 0) + pArc->InvertN() ; + // assegno il centro e il raggio di questo arco ai dati cam + pCamData->SetAxesCen( pArc->GetCenter()) ; + pCamData->SetAxesRad( pArc->GetRadius()) ; + pCamData->SetAxesAngCen( pArc->GetAngCenter()) ; + // aggiorno il tipo di arco + pCamData->SetMoveType( pArc->GetAngCenter() > 0 ? 3 : 2) ; + // verifico i limiti di corsa dei punti lungo l'arco + const int NUM_VERIF_STEP = 16 ; + Point3d ptCen = pCamData->GetAxesCen() ; + double dAngCenStep = pCamData->GetAxesAngCen() / NUM_VERIF_STEP ; + Vector3d vtCurr = Point3d( dXprec, dYprec, dZprec) - ptCen ; + for ( int i = 1 ; i < NUM_VERIF_STEP ; ++ i) { + vtCurr.Rotate( Z_AX, dAngCenStep) ; + Point3d ptCurr = ptCen + vtCurr ; + double dCoeff = i / NUM_VERIF_STEP ; + double dAngA = dAngAprec * ( 1 - dCoeff) + dAngA1 * dCoeff ; + double dAngB = dAngBprec * ( 1 - dCoeff) + dAngB1 * dCoeff ; + int nStat ; + bool bOsOk = m_pMchMgr->VerifyOutstroke( ptCurr.x, ptCurr.y, ptCurr.z, dAngA, dAngB, nStat) ; + if ( ! bOsOk || nStat != 0) { + bOk = false ; + pCamData->SetAxes( CamData::AS_OUTSTROKE, vAxVal) ; + string sInfo = "Outstroke : " + m_pMchMgr->GetOutstrokeInfo() ; + LOG_INFO( GetEMkLogger(), sInfo.c_str()) + continue ; + } + } + } + } + bFirst = false ; + // memorizzo i valori degli assi lineari come nuovi precedenti + dXprec = dX ; + dYprec = dY ; + dZprec = dZ ; + // memorizzo i valori degli angoli come nuovi precedenti + dAngAprec = dAngA1 ; + dAngBprec = dAngB1 ; + } + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Operation::AdjustStartEndMovements(void) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero gruppo della geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOwnerId, MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + + // recupero la lavorazione precedente non vuota + int nPrevOpId = m_pMchMgr->GetPrevActiveOperation( m_nOwnerId) ; + Operation* pPrevOp = GetOperation( m_pGeomDB->GetUserObj( nPrevOpId)) ; + while ( pPrevOp != nullptr) { + if ( ! pPrevOp->IsEmpty()) + break ; + else { + nPrevOpId = m_pMchMgr->GetPrevActiveOperation( nPrevOpId) ; + pPrevOp = GetOperation( m_pGeomDB->GetUserObj( nPrevOpId)) ; + } + } + // recupero l'utensile precedente e i dati della sua testa + string sPrevTool ; + if ( pPrevOp != nullptr) + sPrevTool = pPrevOp->GetToolName() ; + + // imposto l'utensile per i calcoli macchina + if ( ! m_pMchMgr->SetCalcTool( GetToolName(), GetHeadName(), GetExitNbr())) + return false ; + + // determino posizione precedente assi + DBLVECTOR vAxVal ; + // se primo utensile, uso la posizione home + if ( sPrevTool.empty()) { + if ( ! m_pMchMgr->GetAllCalcAxesHomePos( vAxVal)) + return false ; + } + // se utensile non cambiato o su diversa uscita della stessa testa, uso posizione finale della lavorazione precedente + else if ( ! ToolChangeNeeded( *pPrevOp, *this)) { + pPrevOp->RemoveRise() ; + DBLVECTOR vAxIni ; + if ( ! pPrevOp->GetFinalAxesValues( vAxVal) || ! GetInitialAxesValues( vAxIni)) + return false ; + // determino delta Z rispetto a posizione finale + if ( vAxVal.size() >= 4 && vAxIni.size() >= 4) { + double dDelta = 0 ; + if ( ! CalcDeltaZForHeadRotation( vAxVal, vAxIni, dDelta)) + return false ; + if ( dDelta > EPS_SMALL) { + if ( ! pPrevOp->AddRise( vAxVal, dDelta)) + return false ; + } + } + } + // altrimenti aggiungo uscita per cambio utensile alla lavorazione precedente e parto da questa + else { + pPrevOp->RemoveRise() ; + if ( ! pPrevOp->AddRise( vAxVal)) + return false ; + } + + // aggiusto l'inizio di ogni percorso di lavoro + bool bOk = true ; + int nClPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + while ( bOk && nClPathId != GDB_ID_NULL) { + // sistemo inizio + if ( ! AdjustOneStartMovement( nClPathId, vAxVal)) + bOk = false ; + // recupero nuovi finali + if ( ! GetClPathFinalAxesValues( nClPathId, vAxVal)) + bOk = false ; + // passo al successivo + nClPathId = m_pGeomDB->GetNextGroup( nClPathId) ; + } + + // aggiungo risalita finale + bOk = bOk && AddRise( vAxVal) ; + bOk = bOk && AddHome() ; + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Operation::AdjustOneStartMovement( int nClPathId, const DBLVECTOR& vAxPrev) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero la prima entità di questo percorso + int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; + // recupero i dati Cam dell'entità + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; + if ( pCamData == nullptr) + return false ; + // recupero i valori degli assi + DBLVECTOR vAxCurr ; + vAxCurr = pCamData->GetAxesVal() ; + // se Z pressochè uguali non devo fare alcunché + if ( fabs( vAxCurr[2] - vAxPrev[2]) < 10 * EPS_SMALL) + return true ; + // se Z corrente maggiore della precedente + else if ( vAxCurr[2] > vAxPrev[2]) { + // copio l'entità + if ( m_pGeomDB->Copy( nEntId, GDB_ID_NULL, nEntId, GDB_AFTER) == GDB_ID_NULL) + return false ; + // modifico quella originale (è la prima del percorso) + DBLVECTOR vAxNew = vAxPrev ; + vAxNew[2] = vAxCurr[2] ; + pCamData->SetAxes( CamData::AS_OK, vAxNew) ; + pCamData->ChangeAxesMask( CamData::MSK_L3) ; + pCamData->SetFlag( 0) ; + } + // altrimenti Z corrente minore della precedente + else { + // copio l'entità + if ( m_pGeomDB->Copy( nEntId, GDB_ID_NULL, nEntId, GDB_AFTER) == GDB_ID_NULL) + return false ; + // modifico quella originale (è la prima del percorso) + DBLVECTOR vAxNew = vAxCurr ; + vAxNew[2] = vAxPrev[2] ; + pCamData->SetAxes( CamData::AS_OK, vAxNew) ; + pCamData->ChangeAxesMask( CamData::MSK_L1 | CamData::MSK_L2 | CamData::MSK_R1 | CamData::MSK_R2) ; + pCamData->SetFlag( 2) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::ToolChangeNeeded( const Operation& Op1, const Operation& Op2) +{ + // se non cambia l'utensile, non cambia la testa fisica + if ( EqualNoCase( Op1.GetToolName(), Op2.GetToolName())) + return false ; + // se non hanno TcPos e stanno sulla stessa testa con uscita diversa, non cambia la testa fisica + if ( Op1.GetToolTcPos().empty() && Op2.GetToolTcPos().empty() && + EqualNoCase( Op1.GetHeadName(), Op2.GetHeadName()) && Op1.GetExitNbr() != Op2.GetExitNbr()) + return false ; + // se hanno lo stesso TcPos e stanno sulla stessa testa con uscita diversa, non cambia la testa fisica + if ( EqualNoCase( Op1.GetToolTcPos(), Op2.GetToolTcPos()) && + EqualNoCase( Op1.GetHeadName(), Op2.GetHeadName()) && Op1.GetExitNbr() != Op2.GetExitNbr()) + return false ; + // altrimenti necessario un cambio + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::AddRise( DBLVECTOR& vAxVal, double dDelta) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero gruppo per geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + // recupero l'ultimo percorso + int nLastPxClId = m_pGeomDB->GetLastGroupInGroup( nClId) ; + // recupero l'ultima entità del percorso + int nEntId = m_pGeomDB->GetLastInGroup( nLastPxClId) ; + if ( nEntId == GDB_ID_NULL) + return false ; + // ne recupero i dati Cam + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; + if ( pCamData == nullptr) + return false ; + // creo oggetto punto per DB geometrico + PtrOwner pGP( CreateGeoPoint3d()) ; + if ( IsNull( pGP)) + return false ; + // assegno le coordinate del punto + pGP->Set( pCamData->GetEndPoint()) ; + // inserisco l'oggetto nel DB geometrico + int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLastPxClId, Release( pGP)) ; + if ( nId == GDB_ID_NULL) + return false ; + m_pGeomDB->SetName( nId, MCH_RISE) ; + // creo oggetto dati Cam + PtrOwner pCam( pCamData->Clone()) ; + if ( IsNull( pCam)) + return false ; + // recupero i valori degli assi + vAxVal = pCam->GetAxesVal() ; + // flag per tipo di movimento in rapido + int nFlag = 0 ; + // se delta positivo lo uso come incremento di Z + if ( dDelta > 0) { + vAxVal[2] += dDelta ; + nFlag = 0 ; // movimento standard + } + // altrimenti uso la Z home + else { + DBLVECTOR vAxHome ; + m_pMchMgr->GetAllCalcAxesHomePos( vAxHome) ; + vAxVal[2] = vAxHome[2] ; + nFlag = 3 ; // movimento a Zmax + } + // verifico extra-corsa dell'asse Z + double dL1 = vAxVal[0] ; + double dL2 = vAxVal[1] ; + double dL3 = vAxVal[2] ; + double dR1 = ( vAxVal.size() >= 4 ? vAxVal[3] : 0) ; + double dR2 = ( vAxVal.size() >= 5 ? vAxVal[4] : 0) ; + int nStat ; + bool bOk = ( m_pMchMgr->VerifyOutstroke( dL1, dL2, dL3, dR1, dR2, nStat) && nStat == 0) ; + // assegno i dati + pCam->SetAxes( (bOk ? CamData::AS_OK : CamData::AS_OUTSTROKE), vAxVal) ; + pCam->SetMoveType( 0) ; + pCam->SetFeed( 0) ; + pCam->SetFlag( nFlag) ; + // associo questo oggetto a quello geometrico + m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Operation::RemoveRise( void) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero gruppo per geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + // recupero l'ultimo percorso CL + int nClPathId = m_pGeomDB->GetLastGroupInGroup( nClId) ; + // elimino tutte le entità RISE alla fine del percorso + int nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_RISE) ; + while ( nId != GDB_ID_NULL) { + m_pGeomDB->Erase( nId) ; + nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_RISE) ; + } + // elimino a maggior ragione le entità HOME + nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_HOME) ; + while ( nId != GDB_ID_NULL) { + m_pGeomDB->Erase( nId) ; + nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_HOME) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::AddHome( void) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero gruppo per geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + // recupero l'ultimo percorso + int nLastPxClId = m_pGeomDB->GetLastGroupInGroup( nClId) ; + // recupero l'ultima entità del percorso di nome RISE + int nEntId = m_pGeomDB->GetLastNameInGroup( nLastPxClId, MCH_RISE) ; + if ( nEntId == GDB_ID_NULL) + return false ; + // ne recupero i dati Cam + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; + if ( pCamData == nullptr) + return false ; + // creo oggetto punto per DB geometrico + PtrOwner pGP( CreateGeoPoint3d()) ; + if ( IsNull( pGP)) + return false ; + // assegno le coordinate del punto + pGP->Set( pCamData->GetEndPoint()) ; + // inserisco l'oggetto nel DB geometrico + int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, nLastPxClId, Release( pGP)) ; + if ( nId == GDB_ID_NULL) + return false ; + m_pGeomDB->SetName( nId, MCH_HOME) ; + // creo oggetto dati Cam + PtrOwner pCam( pCamData->Clone()) ; + if ( IsNull( pCam)) + return false ; + // flag per tipo di movimento in rapido (rapido a Home) + int nFlag = 4 ; + // recupero coordinate home + DBLVECTOR vAxHome ; + m_pMchMgr->GetAllCalcAxesHomePos( vAxHome) ; + // assegno i dati + pCam->SetAxes( CamData::AS_OK, vAxHome) ; + pCam->SetMoveType( 0) ; + pCam->SetFeed( 0) ; + pCam->SetFlag( nFlag) ; + // associo questo oggetto a quello geometrico + m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::RemoveHome( void) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return false ; + // recupero gruppo per geometria di lavorazione (Cutter Location) + int nClId = m_pGeomDB->GetFirstNameInGroup( GetOwner(), MCH_CL) ; + if ( nClId == GDB_ID_NULL) + return false ; + // recupero l'ultimo percorso CL + int nClPathId = m_pGeomDB->GetLastGroupInGroup( nClId) ; + // elimino tutte le entità HOME alla fine del percorso + int nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_HOME) ; + while ( nId != GDB_ID_NULL) { + m_pGeomDB->Erase( nId) ; + nId = m_pGeomDB->GetFirstNameInGroup( nClPathId, MCH_HOME) ; + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::CalcDeltaZForHeadRotation( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, double& dDeltaZ) +{ + // il numero di assi deve essere costante + if ( vAxStart.size() != vAxEnd.size()) + return false ; + // se ci sono solo assi lineari, non delta Z nullo + if ( vAxStart.size() <= 3) { + dDeltaZ = 0 ; + return true ; + } + // determino gli estremi del movimento rotatorio + double dR1Start = ( vAxStart.size() >= 4 ? vAxStart[3] : 0) ; + double dR2Start = ( vAxStart.size() >= 5 ? vAxStart[4] : 0) ; + double dR1End = ( vAxEnd.size() >= 4 ? vAxEnd[3] : 0) ; + double dR2End = ( vAxEnd.size() >= 5 ? vAxEnd[4] : 0) ; + // determino le variazioni di ciascun asse + double dR1Delta = dR1End - dR1Start ; + double dR2Delta = dR2End - dR2Start ; + // divido il movimento in step di massimo 15 gradi + int nStep = int( max( abs( dR1Delta), abs( dR2Delta)) / 15.0) + 1 ; + double dR1Step = dR1Delta / nStep ; + double dR2Step = dR2Delta / nStep ; + // calcolo + double dL1 = vAxStart[0] ; + double dL2 = vAxStart[1] ; + double dL3 = vAxStart[2] ; + double dZStart, dZmin ; + for ( int i = 0 ; i <= nStep ; ++ i) { + double dR1 = dR1Start + i * dR1Step ; + double dR2 = dR2Start + i * dR2Step ; + Point3d ptTip ; + if ( ! m_pMchMgr->GetCalcTipFromPositions( dL1, dL2, dL3, dR1, dR2, true, ptTip)) + return false ; + if ( i == 0) { + dZStart = ptTip.z ; + dZmin = dZStart ; + } + else if ( ptTip.z < dZmin) + dZmin = ptTip.z ; + } + dDeltaZ = dZStart - dZmin ; + return true ; +} + +//---------------------------------------------------------------------------- +//---------------------------------------------------------------------------- +bool +Operation::SetPathId( int nPathId) +{ + m_nPathId = nPathId ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::SetToolDir( const Vector3d& vtDir) +{ + m_vtTool = vtDir ; + return ( m_vtTool.Normalize()) ; +} + +//---------------------------------------------------------------------------- +bool +Operation::SetCorrDir( const Vector3d& vtDir) +{ + m_vtCorr = vtDir ; + return ( ! m_vtCorr.IsSmall()) ; +} + +//---------------------------------------------------------------------------- +bool +Operation::SetAuxDir( const Vector3d& vtDir) +{ + m_vtAux = vtDir ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::SetCorrAuxDir( const Vector3d& vtDir) +{ + m_vtCorr = vtDir ; + m_vtAux = vtDir ; + return ( ! m_vtCorr.IsSmall()) ; +} + +//---------------------------------------------------------------------------- +bool +Operation::SetFeed( double dFeed) +{ + m_dFeed = dFeed ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Operation::SetFlag( int nFlag) +{ + m_nFlag = nFlag ; + return true ; +} + +//---------------------------------------------------------------------------- +int +Operation::AddRapidStart( const Point3d& ptP) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return GDB_ID_NULL ; + // verifico di essere in uno stato valido per inizio + if ( m_vtTool.IsSmall()) + return GDB_ID_NULL ; + // creo oggetto punto per DB geometrico + PtrOwner pGP( CreateGeoPoint3d()) ; + if ( IsNull( pGP)) + return GDB_ID_NULL ; + // assegno le coordinate del punto + pGP->Set( ptP) ; + // inserisco l'oggetto nel DB geometrico + int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, m_nPathId, Release( pGP)) ; + if ( nId == GDB_ID_NULL) + return GDB_ID_NULL ; + // creo oggetto dati Cam + PtrOwner pCam( new( nothrow) CamData) ; + if ( IsNull( pCam)) + return GDB_ID_NULL ; + // assegno valori + pCam->SetMoveType( 0) ; + pCam->SetToolDir( m_vtTool) ; + pCam->SetCorrDir( m_vtCorr) ; + pCam->SetAuxDir( m_vtAux) ; + pCam->SetEndPoint( ptP) ; + pCam->SetFeed( 0) ; + pCam->SetFlag( m_nFlag) ; + // associo questo oggetto a quello geometrico + m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + // salvo la posizione corrente + m_bCurr = true ; + m_ptCurr = ptP ; + return nId ; +} + +//---------------------------------------------------------------------------- +int +Operation::AddRapidMove( const Point3d& ptP) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return GDB_ID_NULL ; + // verifico di essere in uno stato valido per un movimento in rapido + if ( ! m_bCurr || m_vtTool.IsSmall()) + return GDB_ID_NULL ; + // creo oggetto linea per DB geometrico + PtrOwner pLine( CreateCurveLine()) ; + if ( IsNull( pLine)) + return GDB_ID_NULL ; + // assegno le coordinate degli estremi + if ( ! pLine->Set( m_ptCurr, ptP)) + return GDB_ID_NULL ; + // inserisco l'oggetto nel DB geometrico + int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, m_nPathId, Release( pLine)) ; + if ( nId == GDB_ID_NULL) + return GDB_ID_NULL ; + // creo oggetto dati Cam + PtrOwner pCam( new( nothrow) CamData) ; + if ( IsNull( pCam)) + return GDB_ID_NULL ; + // assegno valori + pCam->SetMoveType( 0) ; + pCam->SetToolDir( m_vtTool) ; + pCam->SetCorrDir( m_vtCorr) ; + pCam->SetAuxDir( m_vtAux) ; + pCam->SetEndPoint( ptP) ; + pCam->SetFeed( 0) ; + pCam->SetFlag( m_nFlag) ; + // associo questo oggetto a quello geometrico + m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + // salvo la posizione corrente + m_ptCurr = ptP ; + return nId ; +} + +//---------------------------------------------------------------------------- +int +Operation::AddLinearMove( const Point3d& ptP) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return GDB_ID_NULL ; + // verifico di essere in uno stato valido per un movimento lineare + if ( ! m_bCurr || m_vtTool.IsSmall()) { + LOG_INFO( GetEMkLogger(), "Error on LinearMove : Curr or ToolDir") + return GDB_ID_NULL ; + } + // se feed nulla, assegno il minimo e lo segnalo + if ( m_dFeed < FEED_MIN) { + m_dFeed = FEED_MIN ; + LOG_INFO( GetEMkLogger(), "Error on LinearMove : Min Feed") + } + // creo oggetto linea per DB geometrico + PtrOwner pLine( CreateCurveLine()) ; + if ( IsNull( pLine)) + return GDB_ID_NULL ; + // assegno le coordinate degli estremi + if ( ! pLine->Set( m_ptCurr, ptP)) + return GDB_ID_NULL ; + // inserisco l'oggetto nel DB geometrico + int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, m_nPathId, Release( pLine)) ; + if ( nId == GDB_ID_NULL) + return GDB_ID_NULL ; + // creo oggetto dati Cam + PtrOwner pCam( new( nothrow) CamData) ; + if ( IsNull( pCam)) + return GDB_ID_NULL ; + // assegno valori + pCam->SetMoveType( 1) ; + pCam->SetToolDir( m_vtTool) ; + pCam->SetCorrDir( m_vtCorr) ; + pCam->SetAuxDir( m_vtAux) ; + pCam->SetEndPoint( ptP) ; + pCam->SetFeed( m_dFeed) ; + pCam->SetFlag( m_nFlag) ; + // associo questo oggetto a quello geometrico + m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + // salvo la posizione corrente + m_ptCurr = ptP ; + return nId ; +} + +//---------------------------------------------------------------------------- +int +Operation::AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, double dDeltaZ) +{ + if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) + return GDB_ID_NULL ; + // verifico di essere in uno stato valido per un movimento arco + if ( ! m_bCurr || m_vtTool.IsSmall()) { + LOG_INFO( GetEMkLogger(), "Error on ArcMove : Curr or ToolDir") + return GDB_ID_NULL ; + } + // se feed nulla, assegno il minimo e lo segnalo + if ( m_dFeed < FEED_MIN) { + m_dFeed = FEED_MIN ; + LOG_INFO( GetEMkLogger(), "Error on ArcMove : Min Feed") + } + // creo oggetto arco per DB geometrico + PtrOwner pArc( CreateCurveArc()) ; + if ( IsNull( pArc)) + return GDB_ID_NULL ; + // assegno i dati dell'arco + if ( ! pArc->SetCPA( ptCen, m_ptCurr, dAngCen, dDeltaZ)) + return GDB_ID_NULL ; + Point3d ptFin ; + if ( ! pArc->GetEndPoint( ptFin) || ! AreSamePointApprox( ptFin, ptP)) + return GDB_ID_NULL ; + int nMove = ( dAngCen > 0 ? 3 : 2) ; + // inserisco l'oggetto nel DB geometrico + int nId = m_pGeomDB->AddGeoObj( GDB_ID_NULL, m_nPathId, Release( pArc)) ; + if ( nId == GDB_ID_NULL) + return GDB_ID_NULL ; + // creo oggetto dati Cam + PtrOwner pCam( new( nothrow) CamData) ; + if ( IsNull( pCam)) + return GDB_ID_NULL ; + // assegno valori + pCam->SetMoveType( nMove) ; + pCam->SetToolDir( m_vtTool) ; + pCam->SetCorrDir( m_vtCorr) ; + pCam->SetAuxDir( m_vtAux) ; + pCam->SetEndPoint( ptP) ; + pCam->SetCenter( ptCen) ; + pCam->SetAngCen( dAngCen) ; + pCam->SetFeed( m_dFeed) ; + pCam->SetFlag( m_nFlag) ; + // associo questo oggetto a quello geometrico + m_pGeomDB->SetUserObj( nId, Release( pCam)) ; + // salvo la posizione corrente + m_ptCurr = ptP ; + return nId ; +} + +//---------------------------------------------------------------------------- +bool +Operation::ResetMoveData( void) +{ + m_bCurr = false ; + m_ptCurr = ORIG ; + m_vtTool = V_NULL ; + m_vtCorr = V_NULL ; + m_vtAux = V_NULL ; + m_dFeed = 0 ; + m_nFlag = 0 ; + return true ; +} diff --git a/Operation.h b/Operation.h new file mode 100644 index 0000000..685ee98 --- /dev/null +++ b/Operation.h @@ -0,0 +1,117 @@ +//---------------------------------------------------------------------------- +// EgalTech 2016-2016 +//---------------------------------------------------------------------------- +// File : Operation.h Data : 29.04.16 Versione : 1.6p4 +// Contenuto : Dichiarazione della classe Operation da cui derivano +// Disposition e Machining. +// +// +// +// Modifiche : 29.04.16 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkPoint3d.h" +#include "/EgtDev/Include/EGkUserObj.h" +#include "/EgtDev/Include/EGkSelection.h" +#include "/EgtDev/Include/EgtNumCollection.h" + +class MachMgr ; +class CamData ; + +//---------------------------------------------------------------------------- +class Operation : public IUserObj +{ + public : // IUserObj + bool SetOwner( int nId, IGeomDB* pGDB) override ; + int GetOwner( void) const override ; + IGeomDB* GetGeomDB( void) const override ; + + public : + virtual bool Init( MachMgr* pMchMgr) ; + virtual bool SetPhase( int nPhase) + { m_nPhase = nPhase ; return true ; } + virtual int GetPhase( void) const + { return m_nPhase ; } + + public : + virtual bool IsEmpty( void) const = 0 ; + + protected : + virtual const std::string& GetToolName( void) const = 0 ; + virtual const std::string& GetHeadName( void) const = 0 ; + virtual int GetExitNbr( void) const = 0 ; + virtual const std::string& GetToolTcPos( void) const = 0 ; + virtual bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) = 0 ; + + protected : + Operation( void) ; + + protected : + bool GetElevation( int nPhase, const Point3d& ptP, + const Vector3d& vtDir, double& dElev) ; + bool GetElevation( int nPhase, const Point3d& ptP1, const Point3d& ptP2, + const Vector3d& vtDir, double& dElev) ; + bool GetElevation( int nPhase, const Point3d& ptP1, const Point3d& ptP2, const Point3d& ptP3, + const Vector3d& vtDir, double& dElev) ; + bool GetDistanceFromRawSide( int nPhase, const Point3d& ptP, const Vector3d& vtDir, double& dDist) ; + bool GetDistanceFromRawBottom( int nPhase, int nPathId, double dToler, double& dRbDist) ; + bool GetRawGlobBox( int nPhase, int nPathId, BBox3d& b3Raw) ; + + bool GetInitialAxesValues( DBLVECTOR& vAxVal) ; + bool GetClPathInitialAxesValues( int nClPathId, DBLVECTOR& vAxVal) ; + bool GetFinalAxesValues( DBLVECTOR& vAxVal) ; + bool GetClPathFinalAxesValues( int nClPathId, DBLVECTOR& vAxVal) ; + bool CalculateAxesValues( void) ; + bool CalculateClPathAxesValues( int nClPathId, int nLinAxes, int nRotAxes, double dRot1W, + double& dAngAprec, double& dAngBprec, int& nOutStrC) ; + bool AdjustStartEndMovements( void) ; + bool AdjustOneStartMovement( int nClPathId, const DBLVECTOR& vAxPrev) ; + bool ToolChangeNeeded( const Operation& Op1, const Operation& Op2) ; + bool AddRise( DBLVECTOR& vAxVal, double dDelta = - 1) ; + bool RemoveRise( void) ; + bool AddHome( void) ; + bool RemoveHome( void) ; + bool CalcDeltaZForHeadRotation( const DBLVECTOR& vAxStart, const DBLVECTOR& vAxEnd, double& dDeltaZ) ; + + protected : + int m_nOwnerId ; // identificativo dell'oggetto geometrico possessore + IGeomDB* m_pGeomDB ; // puntatore al DB geometrico + MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni + int m_nPhase ; // indice della fase di appartenenza (da 1 in su) + + protected : + bool SetPathId( int nPathId) ; + bool SetToolDir( const Vector3d& vtDir) ; + bool SetCorrDir( const Vector3d& vtDir) ; + bool SetAuxDir( const Vector3d& vtDir) ; + bool SetCorrAuxDir( const Vector3d& vtDir) ; + bool SetFeed( double dFeed) ; + bool SetFlag( int nFlag) ; + bool GetCurrPos( Point3d& ptCurr) const + { if ( ! m_bCurr) return false ; ptCurr = m_ptCurr ; return true ; } + int AddRapidStart( const Point3d& ptP) ; + int AddRapidMove( const Point3d& ptP) ; + int AddLinearMove( const Point3d& ptP) ; + int AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, double dDeltaZ = 0) ; + bool ResetMoveData( void) ; + + protected : + int m_nPathId ; // identificativo del gruppo corrente di inserimento dati + bool m_bCurr ; // punto corrente valido + Point3d m_ptCurr ; // posizione corrente + Vector3d m_vtTool ; // direzione fresa corrente + Vector3d m_vtCorr ; // direzione correzione corrente + Vector3d m_vtAux ; // direzione ausiliaria corrente + double m_dFeed ; // feed corrente + int m_nFlag ; // flag corrente +} ; + +//---------------------------------------------------------------------------- +inline const Operation* GetOperation( const IUserObj* pUserObj) + { return dynamic_cast( pUserObj) ; } +inline Operation* GetOperation( IUserObj* pUserObj) + { return dynamic_cast< Operation*>( pUserObj) ; } diff --git a/OutputConst.h b/OutputConst.h new file mode 100644 index 0000000..8bf948b --- /dev/null +++ b/OutputConst.h @@ -0,0 +1,113 @@ +//---------------------------------------------------------------------------- +// EgalTech 2016-2016 +//---------------------------------------------------------------------------- +// File : OutputConst.h Data : 30.04.16 Versione : 1.6p4 +// Contenuto : Dichiarazione nomi variabili e funzioni per output Lua. +// +// +// +// Modifiche : 30.04.16 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include + +//---------------------------------------------------------------------------- +// Variabili +static const std::string GLOB_VAR = "EMT" ; // tavola variabili globali +static const std::string GVAR_USETO1 = ".USETO1" ; // (bool) flag per utilizzo origine tavola +static const std::string GVAR_MODAL = ".MODAL" ; // (bool) flag per emissione modale dei valori +static const std::string GVAR_NUM = ".NUM" ; // (bool) flag numerazione +static const std::string GVAR_NUMTOK = ".Nt" ; // (string) token per numerazione +static const std::string GVAR_LINENBR = ".LINENBR" ; // (int) numero progressivo di linea +static const std::string GVAR_LINEINC = ".LINEINC" ; // (int) incremento per numero di linea +static const std::string GVAR_F = ".F" ; // (num) valore della feed +static const std::string GVAR_FT = ".Ft" ; // (string) token per feed +static const std::string GVAR_S = ".S" ; // (num) valore della speed +static const std::string GVAR_ST = ".St" ; // (string) token per speed +static const std::string GVAR_FILE = ".FILE" ; // (string) path file di output +static const std::string GVAR_INFO = ".INFO" ; // (string) informazioni iniziali +static const std::string GVAR_DISPID = ".DISPID" ; // (int) identificativo disposizione +static const std::string GVAR_DISPIND = ".DISPIND" ; // (int) indice disposizione +static const std::string GVAR_PHASE = ".PHASE" ; // (int) indice fase +static const std::string GVAR_EMPTY = ".EMPTY" ; // (bool) flag disposizione passiva +static const std::string GVAR_TABNAME = ".TABNAME" ; // (string) nome tavola +static const std::string GVAR_TABORI1 = ".TABORI1" ; // (Point3d) prima origine di tavola +static const std::string GVAR_FIXID = ".FIXID" ; // (int) identificativo bloccaggio (fixture) +static const std::string GVAR_FIXIND = ".FIXIND" ; // (int) indice bloccaggio +static const std::string GVAR_FIXNAME = ".FIXNAME" ; // (string) nome bloccaggio +static const std::string GVAR_FIXPOS = ".FIXPOS" ; // (Point3d) posizione bloccaggio +static const std::string GVAR_FIXANG = ".FIXANG" ; // (num) angolo di rotazione bloccaggio +static const std::string GVAR_RAWID = ".RAWID" ; // (int) identificativo grezzo +static const std::string GVAR_RAWIND = ".RAWIND" ; // (int) indice movimento del grezzo +static const std::string GVAR_RAWTYPE = ".RAWTYPE" ; // (int) tipo di movimento del grezzo +static const std::string GVAR_RAWPOS = ".RAWPOS" ; // (Point3d) posizione di movimento del grezzo +static const std::string GVAR_RAWFLAG = ".RAWFLAG" ; // (int) flag per movimento del grezzo +static const std::string GVAR_MCHID = ".MCHID" ; // (int) identificativo lavorazione +static const std::string GVAR_MCHIND = ".MCHIND" ; // (int) indice lavorazione +static const std::string GVAR_PATHID = ".PATHID" ; // (int) identificativo percorso di lavorazione +static const std::string GVAR_PATHIND = ".PATHIND" ; // (int) indice percorso di lavorazione +static const std::string GVAR_MOVEID = ".MOVEID" ; // (int) identificativo movimento +static const std::string GVAR_MOVEIND = ".MOVEIND" ; // (int) indice movimento +static const std::string GVAR_MOVE = ".MOVE" ; // (int) tipo di movimento (0,1,2,3) +static const std::string GVAR_L1 = ".L1" ; // (num) valore del primo asse lineare +static const std::string GVAR_L2 = ".L2" ; // (num) valore del secondo asse lineare +static const std::string GVAR_L3 = ".L3" ; // (num) valore del terzo asse lineare +static const std::string GVAR_R1 = ".R1" ; // (num) valore del primo asse rotante +static const std::string GVAR_R2 = ".R2" ; // (num) valore del secondo asse rotante +static const std::string GVAR_C1 = ".C1" ; // (num) valore del primo asse lineare per centro arco +static const std::string GVAR_C2 = ".C2" ; // (num) valore del secondo asse lineare per centro arco +static const std::string GVAR_C3 = ".C3" ; // (num) valore del terzo asse lineare per centro arco +static const std::string GVAR_RR = ".RR" ; // (num) valore raggio per arco +static const std::string GVAR_AC = ".AC" ; // (num) valore angolo al centro per arco +static const std::string GVAR_L1P = ".L1p" ; // (num) valore precedente del primo asse lineare +static const std::string GVAR_L2P = ".L2p" ; // (num) valore precedente del secondo asse lineare +static const std::string GVAR_L3P = ".L3p" ; // (num) valore precedente del terzo asse lineare +static const std::string GVAR_R1P = ".R1p" ; // (num) valore precedente del primo asse rotante +static const std::string GVAR_R2P = ".R2p" ; // (num) valore precedente del secondo asse rotante +static const std::string GVAR_L1T = ".L1t" ; // (num) token del primo asse lineare +static const std::string GVAR_L2T = ".L2t" ; // (num) token del secondo asse lineare +static const std::string GVAR_L3T = ".L3t" ; // (num) token del terzo asse lineare +static const std::string GVAR_R1T = ".R1t" ; // (num) token del primo asse rotante +static const std::string GVAR_R2T = ".R2t" ; // (num) token del secondo asse rotante +static const std::string GVAR_C1T = ".C1t" ; // (num) token del primo asse lineare per centro arco +static const std::string GVAR_C2T = ".C2t" ; // (num) token del secondo asse lineare per centro arco +static const std::string GVAR_C3T = ".C3t" ; // (num) token del terzo asse lineare per centro arco +static const std::string GVAR_RRT = ".RRt" ; // (num) token del raggio per arco +static const std::string GVAR_MASK = ".MASK" ; // (int) mask associato ai movimenti in rapido +static const std::string GVAR_FLAG = ".FLAG" ; // (int) flag associato ad ogni movimento +// Funzioni generazione +static const std::string ON_START = "OnStart" ; +static const std::string ON_END = "OnEnd" ; +static const std::string ON_PROGRAM_START = "OnProgramStart" ; +static const std::string ON_PROGRAM_END = "OnProgramEnd" ; +static const std::string ON_TOOL_SELECT = "OnToolSelect" ; +static const std::string ON_TOOL_DESELECT = "OnToolDeselect" ; +static const std::string ON_DISPOSITION_START = "OnDispositionStart" ; +static const std::string ON_DISPOSITION_END = "OnDispositionEnd" ; +static const std::string ON_TABLE_DATA = "OnTableData" ; +static const std::string ON_FIXTURE_DATA = "OnFixtureData" ; +static const std::string ON_RAWMOVE_DATA = "OnRawMoveData" ; +static const std::string ON_MACHINING_START = "OnMachiningStart" ; +static const std::string ON_MACHINING_END = "OnMachiningEnd" ; +static const std::string ON_PATH_START = "OnPathStart" ; +static const std::string ON_PATH_END = "OnPathEnd" ; +static const std::string ON_RAPID = "OnRapid" ; +static const std::string ON_LINEAR = "OnLinear" ; +static const std::string ON_ARC = "OnArc" ; +// Funzioni simulazione +static const std::string ON_SIMUL_DISPOSITION_START = "OnSimulDispositionStart" ; +static const std::string ON_SIMUL_DISPOSITION_END = "OnSimulDispositionEnd" ; +static const std::string ON_SIMUL_MACHINING_START = "OnSimulMachiningStart" ; +static const std::string ON_SIMUL_MACHINING_END = "OnSimulMachiningEnd" ; +static const std::string ON_SIMUL_PATH_START = "OnSimulPathStart" ; +static const std::string ON_SIMUL_PATH_END = "OnSimulPathEnd" ; +static const std::string ON_SIMUL_MOVE_START = "OnSimulMoveStart" ; +static const std::string ON_SIMUL_MOVE_END = "OnSimulMoveEnd" ; +// Funzioni macchina +static const std::string ON_RESET_MACHINE = "OnResetMachine" ; +// Valore minimo flag per chiamata funzione di movimento in simulazione +static const int MIN_CALL_SIMUL_MOVE = 1000 ; \ No newline at end of file diff --git a/SawFinishing.cpp b/SawFinishing.cpp index 4964f7a..f70b450 100644 --- a/SawFinishing.cpp +++ b/SawFinishing.cpp @@ -810,7 +810,7 @@ SawFinishing::CalculateAlongToolPath( int nAuxId, int nClId) // Imposto dati comuni SetPathId( nPxId) ; SetToolDir( vtTool) ; - SetCorrDir( vtCorr) ; + SetCorrAuxDir( vtCorr) ; // Classifico i tratti a seconda della pendenza (salita, discesa, verticale, orizzontale) INTVECTOR vnClass ; @@ -994,7 +994,7 @@ SawFinishing::CalculateAcrossToolPath( int nAuxId, int nClId) // Imposto dati comuni SetPathId( nPxId) ; SetToolDir( vtTool) ; - SetCorrDir( vtCorr) ; + SetCorrAuxDir( vtCorr) ; // Inizializzo contatore tagli m_nCuts = 0 ; diff --git a/SawFinishing.h b/SawFinishing.h index 88f0a12..05483ea 100644 --- a/SawFinishing.h +++ b/SawFinishing.h @@ -35,6 +35,13 @@ class SawFinishing : public Machining bool Save( STRVECTOR& vString) const override ; bool Load( const STRVECTOR& vString) override ; + public : // Operation + bool IsEmpty( void) const override + { return ( m_nCuts == 0) ; } + + protected : // Operation + bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; + public : // Machining bool Prepare( const std::string& sSawName) override ; bool SetParam( int nType, bool bVal) override ; @@ -50,9 +57,6 @@ class SawFinishing : public Machining bool GetParam( int nType, std::string& sVal) const override ; const ToolData& GetToolData( void) const override ; bool GetGeometry( SELVECTOR& vIds) const override ; - bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; - bool IsEmpty( void) const override - { return ( m_nCuts == 0) ; } public : SawFinishing( void) ; diff --git a/SawRoughing.cpp b/SawRoughing.cpp index e591b70..dac9d8c 100644 --- a/SawRoughing.cpp +++ b/SawRoughing.cpp @@ -889,7 +889,7 @@ SawRoughing::CalculateToolPath( int nAuxId, int nClId) // Imposto dati comuni SetPathId( nPxId) ; SetToolDir( vtTool) ; - SetCorrDir( vtCorr) ; + SetCorrAuxDir( vtCorr) ; // Determino eventuali pareti verticali (sono in senso decrescente di X) DBLVECTOR vdVr ; diff --git a/SawRoughing.h b/SawRoughing.h index 3779489..8e47c87 100644 --- a/SawRoughing.h +++ b/SawRoughing.h @@ -35,6 +35,13 @@ class SawRoughing : public Machining bool Save( STRVECTOR& vString) const override ; bool Load( const STRVECTOR& vString) override ; + public : // Operation + bool IsEmpty( void) const override + { return ( m_nCuts == 0) ; } + + protected : // Operation + bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; + public : // Machining bool Prepare( const std::string& sSawName) override ; bool SetParam( int nType, bool bVal) override ; @@ -50,9 +57,6 @@ class SawRoughing : public Machining bool GetParam( int nType, std::string& sVal) const override ; const ToolData& GetToolData( void) const override ; bool GetGeometry( SELVECTOR& vIds) const override ; - bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; - bool IsEmpty( void) const override - { return ( m_nCuts == 0) ; } public : SawRoughing( void) ; diff --git a/Sawing.cpp b/Sawing.cpp index 23c655b..7856cd6 100644 --- a/Sawing.cpp +++ b/Sawing.cpp @@ -1373,7 +1373,7 @@ Sawing::GenerateLineCl( const ICurveLine* pLine, const Vector3d& vtTool, const V // Imposto dati comuni SetPathId( nPxId) ; SetToolDir( vtTool) ; - SetCorrDir( vtCorr) ; + SetCorrAuxDir( vtCorr) ; // recupero distanza di sicurezza double dSafeZ = m_pMchMgr->GetCurrMachiningsMgr()->GetSafeZ() ; // lunghezza di approccio/retrazione @@ -1886,7 +1886,7 @@ Sawing::GenerateExtArcCl( const ICurveArc* pArc, const Vector3d& vtStaTool, cons m_pGeomDB->SetMaterial( nPxId, BLUE) ; // Imposto dati comuni SetPathId( nPxId) ; - SetCorrDir( vtCorr) ; + SetCorrAuxDir( vtCorr) ; // recupero distanza di sicurezza double dSafeZ = m_pMchMgr->GetCurrMachiningsMgr()->GetSafeZ() ; // lunghezza di approccio/retrazione @@ -2526,7 +2526,7 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, if ( m_Params.m_dStepIntArc < EPS_SMALL || ( dElev - dExtraCut) <= m_Params.m_dStepIntArc) { // 1 -> approccio SetToolDir( vtStaTool) ; - SetCorrDir( vtStaCorr) ; + SetCorrAuxDir( vtStaCorr) ; Point3d ptP1 ; pArc->GetStartPoint( ptP1) ; if ( ! AddApproach( ptP1, Z_AX, dSafeZ, dElev, dAppr)) @@ -2547,7 +2547,7 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, // se angolo al centro minore del limite, un solo arco if ( abs( pArc->GetAngCenter()) < MAX_ANG_CEN) { SetToolDir( vtEndTool) ; - SetCorrDir( vtEndCorr) ; + SetCorrAuxDir( vtEndCorr) ; if ( AddArcMove( ptP3, ptCen, dAngCen) == GDB_ID_NULL) return false ; } @@ -2557,12 +2557,12 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, pArc->GetMidPoint( ptMid) ; // prima metà arco SetToolDir( vtMidTool) ; - SetCorrDir( vtMidCorr) ; + SetCorrAuxDir( vtMidCorr) ; if ( AddArcMove( ptMid, ptCen, dAngCen / 2) == GDB_ID_NULL) return false ; // seconda metà arco SetToolDir( vtEndTool) ; - SetCorrDir( vtEndCorr) ; + SetCorrAuxDir( vtEndCorr) ; if ( AddArcMove( ptP3, ptCen, dAngCen / 2) == GDB_ID_NULL) return false ; } @@ -2577,7 +2577,7 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, else if ( m_Params.m_nStepType == SAW_ST_ZIGZAG || m_Params.m_nStepType == SAW_ST_TOANDFROM) { // 1 -> approccio SetToolDir( vtStaTool) ; - SetCorrDir( vtStaCorr) ; + SetCorrAuxDir( vtStaCorr) ; Point3d ptP1 ; pArc->GetStartPoint( ptP1) ; if ( ! AddApproach( ptP1, Z_AX, dSafeZ, dElev, dAppr)) @@ -2607,7 +2607,7 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, swap( ptP2, ptP3) ; // movimento in affondo SetToolDir( ( ( i % 2) == 0) ? vtEndTool : vtStaTool) ; - SetCorrDir( ( ( i % 2) == 0) ? vtEndCorr : vtStaCorr) ; + SetCorrAuxDir( ( ( i % 2) == 0) ? vtEndCorr : vtStaCorr) ; SetFlag( 0) ; SetFeed( GetTipFeed()) ; if ( AddLinearMove( ptP2) == GDB_ID_NULL) @@ -2620,7 +2620,7 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, if ( abs( dAngCen) < MAX_ANG_CEN) { double dCurrAngCen = dAngCen * ((( i % 2) == 0) ? -1 : 1) ; SetToolDir( ( ( i % 2) == 0) ? vtStaTool : vtEndTool) ; - SetCorrDir( ( ( i % 2) == 0) ? vtStaCorr : vtEndCorr) ; + SetCorrAuxDir( ( ( i % 2) == 0) ? vtStaCorr : vtEndCorr) ; if ( AddArcMove( ptP3, ptCen, dCurrAngCen) == GDB_ID_NULL) return false ; } @@ -2632,19 +2632,19 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, double dCurrAngCen = dAngCen / 2 * ((( i % 2) == 0) ? -1 : 1) ; // prima metà arco SetToolDir( vtMidTool) ; - SetCorrDir( vtMidCorr) ; + SetCorrAuxDir( vtMidCorr) ; if ( AddArcMove( ptMid, ptCen, dCurrAngCen) == GDB_ID_NULL) return false ; // seconda metà arco SetToolDir( ( ( i % 2) == 0) ? vtStaTool : vtEndTool) ; - SetCorrDir( ( ( i % 2) == 0) ? vtStaCorr : vtEndCorr) ; + SetCorrAuxDir( ( ( i % 2) == 0) ? vtStaCorr : vtEndCorr) ; if ( AddArcMove( ptP3, ptCen, dCurrAngCen) == GDB_ID_NULL) return false ; } } // 4 -> retrazione SetToolDir( vtStaTool) ; - SetCorrDir( vtStaCorr) ; + SetCorrAuxDir( vtStaCorr) ; Point3d ptP4 ; pArc->GetStartPoint( ptP4) ; if ( ! AddRetract( ptP4, Z_AX, dSafeZ, dElev, dAppr)) @@ -2655,7 +2655,7 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, else { // 1 -> approccio SetToolDir( vtStaTool) ; - SetCorrDir( vtStaCorr) ; + SetCorrAuxDir( vtStaCorr) ; Point3d ptP1 ; pArc->GetStartPoint( ptP1) ; if ( ! AddApproach( ptP1, Z_AX, dSafeZ, dElev, dAppr)) @@ -2671,7 +2671,7 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, double dDelta = ( ( i != 0) ? dExtraCut + i * dStep : 0) ; // movimento in affondo al punto iniziale SetToolDir( vtStaTool) ; - SetCorrDir( vtStaCorr) ; + SetCorrAuxDir( vtStaCorr) ; SetFlag( 0) ; SetFeed( GetTipFeed()) ; Point3d ptP2 ; @@ -2689,7 +2689,7 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, // se angolo al centro minore del limite, un solo arco if ( abs( dAngCen) < MAX_ANG_CEN) { SetToolDir( vtEndTool) ; - SetCorrDir( vtEndCorr) ; + SetCorrAuxDir( vtEndCorr) ; if ( AddArcMove( ptP3, ptCen, dAngCen) == GDB_ID_NULL) return false ; } @@ -2700,12 +2700,12 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, ptMid += Z_AX * dDelta ; // prima metà arco SetToolDir( vtMidTool) ; - SetCorrDir( vtMidCorr) ; + SetCorrAuxDir( vtMidCorr) ; if ( AddArcMove( ptMid, ptCen, dAngCen / 2) == GDB_ID_NULL) return false ; // seconda metà arco SetToolDir( vtEndTool) ; - SetCorrDir( vtEndCorr) ; + SetCorrAuxDir( vtEndCorr) ; if ( AddArcMove( ptP3, ptCen, dAngCen / 2) == GDB_ID_NULL) return false ; } @@ -2720,7 +2720,7 @@ Sawing::GenerateIntArcCl( const ICurveArc* pArc, return false ; // movimento di ritorno sopra il punto iniziale SetToolDir( vtStaTool) ; - SetCorrDir( vtStaCorr) ; + SetCorrAuxDir( vtStaCorr) ; SetFeed( GetEndFeed()) ; Point3d ptP5 ; pArc->GetStartPoint( ptP5) ; diff --git a/Sawing.h b/Sawing.h index dd80ee4..35fcd2a 100644 --- a/Sawing.h +++ b/Sawing.h @@ -35,6 +35,13 @@ class Sawing : public Machining bool Save( STRVECTOR& vString) const override ; bool Load( const STRVECTOR& vString) override ; + public : // Operation + bool IsEmpty( void) const override + { return ( m_nCuts == 0) ; } + + protected : // Operation + bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; + public : // Machining bool Prepare( const std::string& sSawName) override ; bool SetParam( int nType, bool bVal) override ; @@ -50,9 +57,6 @@ class Sawing : public Machining bool GetParam( int nType, std::string& sVal) const override ; const ToolData& GetToolData( void) const override ; bool GetGeometry( SELVECTOR& vIds) const override ; - bool AdjustEndPointForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; - bool IsEmpty( void) const override - { return ( m_nCuts == 0) ; } public : Sawing( void) ; diff --git a/Simulator.cpp b/Simulator.cpp index f745c78..0b39780 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -18,6 +18,7 @@ #include "Disposition.h" #include "Machining.h" #include "MachiningConst.h" +#include "OutputConst.h" #include "/EgtDev/Include/EMkToolConst.h" #include "/EgtDev/Include/EMkOperationConst.h" @@ -28,10 +29,14 @@ Simulator::Simulator( void) { m_pMchMgr = nullptr ; m_pGeomDB = nullptr ; + m_pMachine = nullptr ; m_dStep = 5.0 ; m_nOpId = GDB_ID_NULL ; + m_nOpInd = 0 ; m_nCLPathId = GDB_ID_NULL ; + m_nCLPathInd = 0 ; m_nEntId = GDB_ID_NULL ; + m_nEntInd = 0 ; m_dCoeff = 0 ; m_AxesName.reserve( 8) ; m_AxesVal.reserve( 8) ; @@ -48,10 +53,12 @@ bool Simulator::Init( MachMgr* pMchMgr) { // verifico ambiente - if ( pMchMgr == nullptr || pMchMgr->GetContextId() == 0 || pMchMgr->GetGeomDB() == nullptr) + if ( pMchMgr == nullptr || pMchMgr->GetContextId() == 0 || + pMchMgr->GetGeomDB() == nullptr || pMchMgr->GetCurrMachine() == nullptr) return false ; m_pMchMgr = pMchMgr ; m_pGeomDB = m_pMchMgr->GetGeomDB() ; + m_pMachine = m_pMchMgr->GetCurrMachine() ; return true ; } @@ -68,22 +75,28 @@ Simulator::Start( void) // imposto fase iniziale m_pMchMgr->SetCurrPhase( 1) ; // verifico la disposizione iniziale della macchinata - int nOpId = m_pMchMgr->GetFirstActiveOperation() ; - if ( m_pMchMgr->GetOperationType( nOpId) != OPER_DISP) + m_nOpId = m_pMchMgr->GetFirstActiveOperation() ; + m_nOpInd = 1 ; + if ( m_pMchMgr->GetOperationType( m_nOpId) != OPER_DISP) + return false ; + // definisco tavola variabili globali + bool bOk = m_pMachine->LuaCreateGlobTable( GLOB_VAR) ; + // richiamo gestione evento inizio e fine disposizione + if ( ! OnDispositionStart( m_nOpId, m_nOpInd, 1, true) || + ! OnDispositionEnd()) return false ; // cerco la prima lavorazione valida - nOpId = m_pMchMgr->GetNextActiveOperation( nOpId) ; - Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nOpId)) ; - while ( nOpId != GDB_ID_NULL) { - if ( IsValidMachiningType( m_pMchMgr->GetOperationType( nOpId)) && + m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; + while ( m_nOpId != GDB_ID_NULL) { + if ( IsValidMachiningType( m_pMchMgr->GetOperationType( m_nOpId)) && pMch != nullptr && ! pMch->IsEmpty()) break ; - nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; - pMch = GetMachining( m_pGeomDB->GetUserObj( nOpId)) ; + m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; + pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; } - if ( nOpId == GDB_ID_NULL) + if ( m_nOpId == GDB_ID_NULL) return false ; - m_nOpId = nOpId ; // aggiornamenti legati al cambio di lavorazione (utensile e assi conseguenti) if ( ! UpdateTool( true) || ! UpdateAxes()) @@ -93,11 +106,22 @@ Simulator::Start( void) if ( ! GoHome()) return false ; + // richiamo gestione evento inizio lavorazione + ++ m_nOpInd ; + if ( ! OnMachiningStart( m_nOpId, m_nOpInd)) + return false ; + // determino il primo percorso di lavoro int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOpId, MCH_CL) ; m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + m_nCLPathInd = 0 ; m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ; + m_nEntInd = 0 ; m_dCoeff = 0 ; + // richiamo gestione evento inizio percorso di lavoro + ++ m_nCLPathInd ; + if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd)) + return false ; return true ; } @@ -111,53 +135,131 @@ Simulator::Move( int& nStatus) nStatus = MCH_SIM_ERR ; return false ; } - // Se arrivato alla fine dell'interpolazione, recupero una nuova entità + // Se arrivato alla fine dell'interpolazione if ( m_dCoeff > 0.999) { + // recupero una nuova entità m_nEntId = m_pGeomDB->GetNext( m_nEntId) ; m_dCoeff = 0 ; } - // Se arrivato alla fine di un percorso di lavoro, recupero un nuovo CLpath - while ( m_nEntId == GDB_ID_NULL) { - m_nCLPathId = m_pGeomDB->GetNextGroup( m_nCLPathId) ; - // se non ce ne sono altri, devo passare a una nuova lavorazione - if ( m_nCLPathId == GDB_ID_NULL) - break ; - m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ; - m_dCoeff = 0 ; + // Se arrivato alla fine di un percorso di lavoro + if ( m_nEntId == GDB_ID_NULL) { + // richiamo gestione evento fine percorso di lavoro + if ( ! OnPathEnd()) { + nStatus = MCH_SIM_ERR ; + return false ; + } + // recupero un nuovo CLpath + while ( m_nEntId == GDB_ID_NULL) { + m_nCLPathId = m_pGeomDB->GetNextGroup( m_nCLPathId) ; + // se non ce ne sono altri, devo passare a una nuova lavorazione + if ( m_nCLPathId == GDB_ID_NULL) + break ; + m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ; + m_dCoeff = 0 ; + } + // se trovato nuovo CLpath + if ( m_nEntId != GDB_ID_NULL) { + // richiamo gestione evento inizio percorso di lavoro + ++ m_nCLPathInd ; + if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd)) { + nStatus = MCH_SIM_ERR ; + return false ; + } + m_nEntInd = 0 ; + } } - // Se arrivato alla fine di una lavorazione, recupero la successiva valida - while ( m_nCLPathId == GDB_ID_NULL) { - m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; - while ( m_nOpId != GDB_ID_NULL) { - Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; - // se non è una lavorazione, verifico se disposizione con cambio di fase - if ( pMch == nullptr) { + // Se arrivato alla fine di una operazione + if ( m_nCLPathId == GDB_ID_NULL) { + // richiamo gestione evento fine operazione + if ( ! OnOperationEnd()) { + nStatus = MCH_SIM_ERR ; + return false ; + } + // recupero la successiva valida + while ( m_nCLPathId == GDB_ID_NULL) { + m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; + while ( m_nOpId != GDB_ID_NULL) { + // se lavorazione valida + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; + if ( pMch != nullptr && ! pMch->IsEmpty()) { + // aggiorno utensile e assi conseguenti + if ( ! UpdateTool() || ! UpdateAxes()) { + nStatus = MCH_SIM_ERR ; + return false ; + } + ++ m_nOpInd ; + // richiamo gestione evento inizio lavorazione + if ( ! OnMachiningStart( m_nOpId, m_nOpInd)) { + nStatus = MCH_SIM_ERR ; + return false ; + } + break ; + } + // se disposizione con cambio di fase Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ; if ( pDisp != nullptr) { // cambio fase m_pMchMgr->SetCurrPhase( pDisp->GetPhase()) ; - // aggiorno visualizzazione e breve pausa (200 ms) - ExeDraw() ; - Sleep( 200) ; - } + // se con movimenti autonomi + if ( ! pDisp->IsEmpty()) { + // aggiorno utensile e assi conseguenti + if ( ! UpdateTool() || ! UpdateAxes()) { + nStatus = MCH_SIM_ERR ; + return false ; + } + ++ m_nOpInd ; + // richiamo gestione evento inizio disposizione + if ( ! OnDispositionStart( m_nOpId, m_nOpInd, pDisp->GetPhase(), false)) { + nStatus = MCH_SIM_ERR ; + return false ; + } + break ; + } + // altrimenti disposizione passiva + else { + ++ m_nOpInd ; + // richiamo gestione evento inizio e fine disposizione + if ( ! OnDispositionStart( m_nOpId, m_nOpInd, pDisp->GetPhase(), true) || + ! OnDispositionEnd()) { + nStatus = MCH_SIM_ERR ; + return false ; + } + // aggiorno visualizzazione e breve pausa (200 ms) + ExeDraw() ; + Sleep( 200) ; + } + } + // passo alla operazione successiva + m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; + } + // se non ce ne sono altre, sono alla fine + if ( m_nOpId == GDB_ID_NULL) { + nStatus = MCH_SIM_END ; + return false ; + } + // aggiorno gli altri dati + int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOpId, MCH_CL) ; + m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; + m_nCLPathInd = 0 ; + m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ; + m_nEntInd = 0 ; + m_dCoeff = 0 ; + // richiamo gestione evento inizio percorso di lavoro + if ( m_nEntId != GDB_ID_NULL) { + ++ m_nCLPathInd ; + if ( ! OnPathStart( m_nCLPathId, m_nCLPathInd)) { + nStatus = MCH_SIM_ERR ; + return false ; + } } - // lavorazione valida - else if ( ! pMch->IsEmpty()) - break ; - m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; } - // se non ce ne sono altre, sono alla fine - if ( m_nOpId == GDB_ID_NULL) { - nStatus = MCH_SIM_END ; - return false ; - } - // aggiorno gli altri dati - int nClId = m_pGeomDB->GetFirstNameInGroup( m_nOpId, MCH_CL) ; - m_nCLPathId = m_pGeomDB->GetFirstGroupInGroup( nClId) ; - m_nEntId = m_pGeomDB->GetFirstInGroup( m_nCLPathId) ; - m_dCoeff = 0 ; - // aggiorno utensile e assi conseguenti - if ( ! UpdateTool() || ! UpdateAxes()) { + } + + // Se inizio di nuova entità + if ( m_nEntId != GDB_ID_NULL && m_dCoeff < EPS_ZERO) { + ++ m_nEntInd ; + // richiamo gestione evento inizio entità + if ( ! OnMoveStart()) { nStatus = MCH_SIM_ERR ; return false ; } @@ -226,10 +328,16 @@ Simulator::Move( int& nStatus) // Se arrivato a fine interpolazione movimento, salvo posizioni e segnalo if ( m_dCoeff > 0.999) { - m_AxesVal = AxesEnd ; + for ( size_t i = 0 ; i < m_AxesName.size() ; ++ i) + m_AxesVal[i] = AxesEnd[i] ; nStatus = MCH_SIM_END_STEP ; + // richiamo gestione evento fine entità + if ( ! OnMoveEnd()) { + nStatus = MCH_SIM_ERR ; + return false ; + } } - // Altrimenti sto muovendomi in uno step + // Altrimenti sto muovendomi all'interno dello step else nStatus = MCH_SIM_OK ; return true ; @@ -257,9 +365,11 @@ Simulator::GetToolInfo( string& sName, double& dSpeed) if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; // Assegno il nome dell'utensile - if ( m_sTool.empty()) - return false ; sName = m_sTool ; + if ( sName.empty()) { + dSpeed = 0 ; + return true ; + } // Recupero speed Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; return ( pMch != nullptr && pMch->GetParam( MPA_SPEED, dSpeed)) ; @@ -305,6 +415,11 @@ Simulator::SetStep( double dStep) bool Simulator::Stop( void) { + // reset stato macchina + OnResetMachine() ; + // rimuovo tavola variabili globali + m_pMachine->LuaResetGlobVar( GLOB_VAR) ; + // reset dello stato m_nOpId = GDB_ID_NULL ; m_nCLPathId = GDB_ID_NULL ; m_nEntId = GDB_ID_NULL ; @@ -317,25 +432,40 @@ bool Simulator::UpdateTool( bool bForced) { // Recupero l'utensile della lavorazione corrente - string sTool ; Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; - if ( pMch == nullptr || ! pMch->GetParam( MPA_TOOL, sTool)) - return false ; - if ( ! m_pMchMgr->TdbSetCurrTool( sTool)) - return false ; - // se cambiato oppure forzato, attivo l'utensile della lavorazione - if ( sTool != m_sTool || bForced) { - string sHead ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; - int nExit ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ; - // se forzato, pulisco la testa - if ( bForced) - m_pMchMgr->ResetHeadSet( sHead) ; + if ( pMch != nullptr) { + string sTool ; + if ( ! pMch->GetParam( MPA_TOOL, sTool)) + return false ; + if ( ! m_pMchMgr->TdbSetCurrTool( sTool)) + return false ; + // se cambiato oppure forzato, attivo l'utensile della lavorazione + if ( sTool != m_sTool || bForced) { + string sHead ; m_pMchMgr->TdbGetCurrToolParam( TPA_HEAD, sHead) ; + int nExit ; m_pMchMgr->TdbGetCurrToolParam( TPA_EXIT, nExit) ; + // se forzato, pulisco la testa + if ( bForced) + m_pMchMgr->ResetHeadSet( sHead) ; + // carico l'utensile + if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) + return false ; + m_sTool = sTool ; + } + return true ; + } + // Provo con una disposizione + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ; + if ( pDisp != nullptr) { + // recupero i dati + string sTool ; string sHead ; int nExit ; + pDisp->GetToolData( sTool, sHead, nExit) ; // carico l'utensile if ( ! m_pMchMgr->SetCalcTool( sTool, sHead, nExit)) return false ; m_sTool = sTool ; + return true ; } - return true ; + return false ; } //---------------------------------------------------------------------------- @@ -354,8 +484,171 @@ Simulator::UpdateAxes( void) bool Simulator::GoHome( void) { + // reset stato macchina + OnResetMachine() ; // porto la macchina in home m_pMchMgr->ResetAllAxesPos() ; // assegno valori home degli assi macchina attivi return m_pMchMgr->GetAllCalcAxesHomePos( m_AxesVal) ; } + + + +//---------------------------------------------------------------------------- +bool +Simulator::OnOperationEnd( void) +{ + // se è una lavorazione + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; + if ( pMch != nullptr) { + // richiamo gestione evento fine lavorazione + return OnMachiningEnd() ; + } + // se è una disposizione + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ; + if ( pDisp != nullptr) { + // richiamo gestione evento fine disposizione + return OnDispositionEnd() ; + } + // errore + return false ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnDispositionStart( int nOpId, int nOpInd, int nPhase, bool bEmpty) +{ + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_DISPOSITION_START)) + return true ; + // assegno identificativo e indice disposizione + bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_DISPID, nOpId) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_DISPIND, nOpInd) ; + // assegno nuovo indice di fase + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PHASE, nPhase) ; + // assegno flag disposizione passiva + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_EMPTY, bEmpty) ; + // chiamo la funzione di inizio disposizione + bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_DISPOSITION_START) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnDispositionEnd( void) +{ + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_DISPOSITION_END)) + return true ; + // chiamo la funzione di fine disposizione + bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_DISPOSITION_END) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnMachiningStart( int nOpId, int nOpInd) +{ + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MACHINING_START)) + return true ; + // assegno identificativo e indice disposizione + bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHID, nOpId) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MCHIND, nOpInd) ; + // chiamo la funzione di inizio disposizione + bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_MACHINING_START) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnMachiningEnd( void) +{ + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MACHINING_END)) + return true ; + // chiamo la funzione di fine disposizione + bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_MACHINING_END) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnPathStart( int nClPathId, int nClPathInd) +{ + // assegno identificativo e indice percorso di lavorazione + bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PATHID, nClPathId) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_PATHIND, nClPathInd) ; + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_START)) + return bOk ; + // chiamo la funzione di inizio percorso di lavorazione + bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_PATH_START) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnPathEnd( void) +{ + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_PATH_END)) + return true ; + // chiamo la funzione di fine percorso di lavorazione + bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_PATH_END) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnMoveStart( void) +{ + // verifico richiesta chiamata funzione + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( m_nEntId)) ; + if ( pCamData == nullptr) + return false ; + int nFlag = pCamData->GetFlag() ; + if ( nFlag < MIN_CALL_SIMUL_MOVE) + return true ; + // assegno dati + bool bOk = m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MOVEID, m_nEntId) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_MOVEIND, m_nEntInd) ; + bOk = bOk && m_pMachine->LuaSetGlobVar( GLOB_VAR + GVAR_FLAG, nFlag) ; + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_START)) + return true ; + // chiamo la funzione + bOk = bOk && m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_START) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnMoveEnd( void) +{ + // verifico richiesta chiamata funzione + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( m_nEntId)) ; + if ( pCamData == nullptr) + return false ; + int nFlag = pCamData->GetFlag() ; + if ( nFlag < MIN_CALL_SIMUL_MOVE) + return true ; + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_SIMUL_MOVE_END)) + return true ; + // chiamo la funzione + bool bOk = m_pMachine->LuaCallFunction( ON_SIMUL_MOVE_END) ; + return bOk ; +} + +//---------------------------------------------------------------------------- +bool +Simulator::OnResetMachine( void) +{ + // verifico esistenza funzione + if ( ! m_pMachine->LuaExistsFunction( ON_RESET_MACHINE)) + return true ; + // eseguo reset macchina + bool bOk = m_pMachine->LuaCallFunction( ON_RESET_MACHINE) ; + return bOk ; +} diff --git a/Simulator.h b/Simulator.h index dd74532..fa1d7a4 100644 --- a/Simulator.h +++ b/Simulator.h @@ -18,6 +18,7 @@ class MachMgr ; class IGeomDB ; +class Machine ; //---------------------------------------------------------------------------- class Simulator @@ -32,20 +33,36 @@ class Simulator bool GetToolInfo( std::string& sName, double& dSpeed) ; bool GetMoveInfo( int& nGmove, double& dFeed) ; bool SetStep( double dStep) ; + bool GoHome( void) ; bool Stop( void) ; private : bool UpdateTool( bool bForced = false) ; bool UpdateAxes( void) ; - bool GoHome( void) ; + + private : + bool OnOperationEnd( void) ; + bool OnDispositionStart( int nOpId, int nOpInd, int nPhase, bool bEmpty) ; + bool OnDispositionEnd( void) ; + bool OnMachiningStart( int nOpId, int nOpInd) ; + bool OnMachiningEnd( void) ; + bool OnPathStart( int nClPathId, int nClPathInd) ; + bool OnPathEnd( void) ; + bool OnMoveStart( void) ; + bool OnMoveEnd( void) ; + bool OnResetMachine( void) ; private : MachMgr* m_pMchMgr ; // puntatore al gestore di tutte le lavorazioni IGeomDB* m_pGeomDB ; // puntatore al DB geometrico + Machine* m_pMachine ; // puntatore alla macchina double m_dStep ; // lunghezza di riferimento per la velocità di simulazione int m_nOpId ; // identificativo della operazione (lavoraz.) corrente + int m_nOpInd ; // contatore della operazione (lavoraz.) corrente int m_nCLPathId ; // identificativo del percorso di lavoro corrente + int m_nCLPathInd ; // contatore del percorso di lavoro corrente nell'operazione int m_nEntId ; // identificativo dell'entità corrente + int m_nEntInd ; // contatore dell'entità corrente nel percorso di lavoro double m_dCoeff ; // coefficiente di movimento corrente std::string m_sTool ; // nome dell'utensile corrente STRVECTOR m_AxesName ; // nomi degli assi macchina attivi diff --git a/Table.cpp b/Table.cpp index d0c7549..7c3df65 100644 --- a/Table.cpp +++ b/Table.cpp @@ -37,22 +37,22 @@ Table* Table::Clone( void) const { // alloco oggetto - Table* pAx = new(nothrow) Table ; + Table* pTab = new(nothrow) Table ; // eseguo copia dei dati - if ( pAx != nullptr) { - try { pAx->m_nOwnerId = GDB_ID_NULL ; - pAx->m_pGeomDB = nullptr ; - pAx->m_sName = m_sName ; - pAx->m_nType = m_nType ; - pAx->m_ptRef1 = m_ptRef1 ; + if ( pTab != nullptr) { + try { pTab->m_nOwnerId = GDB_ID_NULL ; + pTab->m_pGeomDB = nullptr ; + pTab->m_sName = m_sName ; + pTab->m_nType = m_nType ; + pTab->m_ptRef1 = m_ptRef1 ; } catch( ...) { - delete pAx ; + delete pTab ; return nullptr ; } } // ritorno l'oggetto - return pAx ; + return pTab ; } //----------------------------------------------------------------------------