diff --git a/CamData.h b/CamData.h index 10c7547..cacb4c7 100644 --- a/CamData.h +++ b/CamData.h @@ -102,4 +102,11 @@ class CamData : public IUserObj int m_nAxesStatus ; // stato dei valori degli assi int m_nAxesMask ; // mask di emissione degli assi (bit a bit) DBLVECTOR m_vMachAxes ; // valori degli assi macchina -} ; \ No newline at end of file +} ; + + +//---------------------------------------------------------------------------- +inline const CamData* GetCamData( const IUserObj* pUserObj) + { return dynamic_cast( pUserObj) ; } +inline CamData* GetCamData( IUserObj* pUserObj) + { return dynamic_cast< CamData*>( pUserObj) ; } diff --git a/Disposition.cpp b/Disposition.cpp index 41e52bf..b51f742 100644 --- a/Disposition.cpp +++ b/Disposition.cpp @@ -27,6 +27,7 @@ using namespace std ; //---------------------------------------------------------------------------- static std::string DIS_TABLE = "Tab" ; +static std::string DIS_PHASE = "Ph" ; static std::string DIS_REF1 = "Ref1" ; static std::string DIS_AREA1 = "Area1" ; static std::string DIS_FXD_TOT = "FxT" ; @@ -80,6 +81,7 @@ Disposition::Dump( string& sOut, bool bMM, const char* szNewLine) const { sOut += GetClassName() + "[mm]" + szNewLine ; sOut += "Tab=" + m_sTabName + ( m_bTabOk ? " (ok)" : " (to verify)") + szNewLine ; + sOut += "Phase=" + ToString( m_nPhase) + szNewLine ; sOut += "Ref1=(" + ToString( m_ptRef1, 3) + ")" + szNewLine ; sOut += "Area1=(" + ToString( m_b3Area1, 3) + ")" + szNewLine ; for ( const auto& FixData : m_vFixData) { @@ -118,17 +120,20 @@ 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(), 3 + nFxdLines + nMvdLines, "") ; - // nome + vString.insert( vString.begin(), 4 + nFxdLines + nMvdLines, "") ; + // Nome if ( ! SetVal( DIS_TABLE, m_sTabName, vString[++k])) return false ; + // Fase + if ( ! SetVal( DIS_PHASE, m_nPhase, vString[++k])) + return false ; // Primo riferimento if ( ! SetVal( DIS_REF1, m_ptRef1, vString[++k])) return false ; // Prima area if ( ! SetVal( DIS_AREA1, m_b3Area1, vString[++k])) return false ; - // dati sottopezzi + // Dati sottopezzi if ( ! SetVal( DIS_FXD_TOT, nFxdTot, vString[++k])) return false ; for ( const auto& FixData : m_vFixData) { @@ -137,7 +142,7 @@ Disposition::Save( STRVECTOR& vString) const ! SetVal( DIS_FXD_ANG, FixData.dAng, vString[++k])) return false ; } - // dati posizionamento grezzi + // Dati posizionamento grezzi if ( ! SetVal( DIS_MVD_TOT, nMvdTot, vString[++k])) return false ; for ( const auto& MvrData : m_vMvrData) { @@ -159,9 +164,13 @@ Disposition::Load( const STRVECTOR& vString) if ( vString.size() < 5) return false ; int k = - 1 ; - // nome + // nome della tavola + m_bTabOk = false ; if ( ! GetVal( vString[++k], DIS_TABLE, m_sTabName)) return false ; + // fase opzionale + if ( ! GetVal( vString[++k], DIS_PHASE, m_nPhase)) + -- k ; // primo riferimento if ( ! GetVal( vString[++k], DIS_REF1, m_ptRef1)) return false ; @@ -231,6 +240,7 @@ Disposition::Disposition( void) m_pGeomDB = nullptr ; m_pMchMgr = nullptr ; m_bTabOk = false ; + m_nPhase = 1 ; } //---------------------------------------------------------------------------- diff --git a/Disposition.h b/Disposition.h index d9a295e..2fc2312 100644 --- a/Disposition.h +++ b/Disposition.h @@ -51,21 +51,28 @@ typedef std::vector MVRDATAVECTOR ; class Disposition : public IUserObj { public : // IUserObj - virtual Disposition* Clone( void) const ; - virtual const std::string& GetClassName( void) const ; - virtual bool Dump( std::string& sOut, bool bMM = true, const char* szNewLine = "\n") const ; - virtual bool ToSave( void) const { return true ; } - virtual bool Save( STRVECTOR& vString) const ; - virtual bool Load( const STRVECTOR& vString) ; - virtual bool SetOwner( int nId, IGeomDB* pGDB) ; - virtual int GetOwner( void) const ; - virtual IGeomDB* GetGeomDB( void) const ; + Disposition* Clone( void) const override ; + const std::string& GetClassName( void) const override ; + bool Dump( std::string& sOut, bool bMM = true, const char* szNewLine = "\n") const override ; + bool ToSave( void) const override + { 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 : Disposition( void) ; bool Init( MachMgr* pMchMgr) ; + bool SetPhase( int nPhase) + { m_nPhase = nPhase ; return true ; } + int GetPhase( void) const + { return m_nPhase ; } bool SetTable( const std::string& sTable) ; bool Apply( void) ; + bool IsSetTableName( void) const + { return ! m_sTabName.empty() ; } bool GetTable( std::string& sTable) const ; bool GetTableRef1( Point3d& ptRef1) const ; bool GetTableArea1( BBox3d& b3Area1) const ; @@ -94,6 +101,13 @@ class Disposition : public IUserObj 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 -} ; \ No newline at end of file +} ; + +//---------------------------------------------------------------------------- +inline const Disposition* GetDisposition( const IUserObj* pUserObj) + { return dynamic_cast( pUserObj) ; } +inline Disposition* GetDisposition( IUserObj* pUserObj) + { return dynamic_cast< Disposition*>( pUserObj) ; } diff --git a/Drilling.cpp b/Drilling.cpp index 52d31ac..f20ce43 100644 --- a/Drilling.cpp +++ b/Drilling.cpp @@ -80,6 +80,7 @@ bool Drilling::Dump( string& sOut, bool bMM, const char* szNewLine) const { sOut += GetClassName() + "[mm]" + szNewLine ; + sOut += KEY_PHASE + EQUAL + ToString( m_nPhase) + szNewLine ; sOut += KEY_IDS + EQUAL + ToString( m_vId) + szNewLine ; for ( int i = 0 ; i < m_Params.GetSize() ; ++ i) sOut += m_Params.ToString( i) + szNewLine ; @@ -95,7 +96,7 @@ bool Drilling::Save( STRVECTOR& vString) const { try { - int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() + 1 ; + int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() + 2 ; vString.insert( vString.begin(), nSize, "") ; int k = - 1 ; if ( ! SetVal( KEY_IDS, m_vId, vString[++k])) @@ -104,6 +105,8 @@ Drilling::Save( STRVECTOR& vString) const vString[++k] = m_Params.ToString( i) ; for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i) vString[++k] = m_TParams.ToString( i) ; + if ( ! SetVal( KEY_PHASE, m_nPhase, vString[++k])) + return false ; if ( ! SetVal( KEY_NUM, m_nDrillings, vString[++k])) return false ; } @@ -144,7 +147,11 @@ Drilling::Load( const STRVECTOR& vString) string sKey, sVal ; SplitFirst( vString[++k], "=", sKey, sVal) ; // leggo - if ( sKey == KEY_NUM) { + if ( sKey == KEY_PHASE){ + if ( ! FromString( sVal, m_nPhase)) + return false ; + } + else if ( sKey == KEY_NUM) { if ( ! FromString( sVal, m_nDrillings)) return false ; } diff --git a/DrillingData.cpp b/DrillingData.cpp index a48c139..28b6689 100644 --- a/DrillingData.cpp +++ b/DrillingData.cpp @@ -94,7 +94,7 @@ DrillingData::CopyFrom( const MachiningData* pMdata) if ( pMdata == this) return true ; // la sorgente deve essere dello stesso tipo - const DrillingData* pDdata = dynamic_cast( pMdata) ; + const DrillingData* pDdata = GetDrillingData( pMdata) ; if ( pDdata == nullptr) return false ; // eseguo copia @@ -128,7 +128,7 @@ DrillingData::SameAs(const MachiningData* pMdata) const if ( pMdata == this) return true ; // se sono di tipo diverso -> diversi - const DrillingData* pDdata = dynamic_cast( pMdata) ; + const DrillingData* pDdata = GetDrillingData( pMdata) ; if ( pDdata == nullptr) return false ; // confronto termine a termine diff --git a/DrillingData.h b/DrillingData.h index e35407f..2c24841 100644 --- a/DrillingData.h +++ b/DrillingData.h @@ -64,3 +64,5 @@ struct DrillingData : public MachiningData //---------------------------------------------------------------------------- inline const DrillingData* GetDrillingData( const MachiningData* pMdata) { return (dynamic_cast( pMdata)) ; } +inline DrillingData* GetDrillingData( MachiningData* pMdata) + { return (dynamic_cast( pMdata)) ; } diff --git a/EgtMachKernel.rc b/EgtMachKernel.rc index 10c7175..9c1eb38 100644 Binary files a/EgtMachKernel.rc and b/EgtMachKernel.rc differ diff --git a/EgtMachKernel.vcxproj b/EgtMachKernel.vcxproj index 64a2b9a..32f8c93 100644 --- a/EgtMachKernel.vcxproj +++ b/EgtMachKernel.vcxproj @@ -238,6 +238,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtMachKernel.vcxproj.filters b/EgtMachKernel.vcxproj.filters index 320e2fd..e98992c 100644 --- a/EgtMachKernel.vcxproj.filters +++ b/EgtMachKernel.vcxproj.filters @@ -153,6 +153,9 @@ Source Files\Output + + Source Files\MachMgr + diff --git a/Generator.cpp b/Generator.cpp index b21393c..f5344bf 100644 --- a/Generator.cpp +++ b/Generator.cpp @@ -44,6 +44,7 @@ static const string GVAR_FILE = ".FILE" ; // (string) path file di ou 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) @@ -220,12 +221,16 @@ bool Generator::ProcessDisposition( int nOpId, int nOpInd) { // Parametri della disposizione - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nOpId)) ; + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( nOpId)) ; if ( pDisp == nullptr) return false ; + // Imposto la fase + int nPhase = pDisp->GetPhase() ; + m_pMchMgr->SetCurrPhase( nPhase) ; + // Emetto inizio disposizione - if ( ! OnDispositionStart( nOpId, nOpInd)) + if ( ! OnDispositionStart( nOpId, nOpInd, nPhase)) return false ; // Emetto dati tavola @@ -359,7 +364,7 @@ bool Generator::ProcessClEnt( int nEntId, int nEntInd, int nClPathId, int nClPathInd, int nOpId, int nOpInd) { // Recupero i dati Cam - CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( nEntId)) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; if ( pCamData == nullptr || pCamData->GetAxesStatus() != CamData::AS_OK) return false ; const DBLVECTOR& AxesEnd = pCamData->GetAxisVal() ; @@ -481,13 +486,15 @@ Generator::OnProgramEnd( void) //---------------------------------------------------------------------------- bool -Generator::OnDispositionStart( int nOpId, int nOpInd) +Generator::OnDispositionStart( int nOpId, int nOpInd, int nPhase) { // definisco tavola variabili locali (temporanee) bool bOk = m_pMachine->LuaCreateGlobTable( TEMP_VAR) ; // assegno identificativo e indice disposizione bOk = 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) ; // chiamo la funzione di inizio disposizione bOk = bOk && m_pMachine->LuaCallFunction( ON_DISPOSITION_START) ; // cancello variabili locali diff --git a/Generator.h b/Generator.h index b8ea91b..1243802 100644 --- a/Generator.h +++ b/Generator.h @@ -41,7 +41,7 @@ class Generator bool OnProgramEnd( void) ; bool OnToolSelect( void) ; bool OnToolDeselect( void) ; - bool OnDispositionStart( int nOpId, int nOpInd) ; + bool OnDispositionStart( int nOpId, int nOpInd, int nPhase) ; 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/MachConst.h b/MachConst.h index 0b7f4f7..ecca193 100644 --- a/MachConst.h +++ b/MachConst.h @@ -33,6 +33,8 @@ const std::string MACH_RAW_GROUP = "Raws" ; const std::string MACH_OPER_GROUP = "Opers" ; // Nome del grezzo const std::string MACH_RAW_PART = "RawPart" ; +// Chiave per info fase di appartenenza del grezzo +const std::string MACH_RAW_PHASE = "Ph" ; // Nome del solido del grezzo const std::string MACH_RAW_SOLID = "RawSolid" ; // Nome del punto che rappresenta il centro del grezzo diff --git a/MachMgr.h b/MachMgr.h index 9b58f4b..6a1755f 100644 --- a/MachMgr.h +++ b/MachMgr.h @@ -72,6 +72,12 @@ class MachMgr : public IMachMgr bool SetCurrMachGroup( int nId) override ; bool ResetCurrMachGroup( void) override ; int GetCurrMachGroup( void) const override ; + // Phases + int AddPhase( void) override ; + bool SetCurrPhase( int nPhase) override ; + int GetCurrPhase( void) const override ; + bool RemoveLastPhase( void) override ; + int GetPhaseCount( void) const override ; // RawParts int GetRawPartCount( void) const override ; int GetFirstRawPart( void) const override ; @@ -81,6 +87,7 @@ class MachMgr : public IMachMgr bool ModifyRawPart( int nRawId, const Point3d& ptOrig, double dLen, double dWidth, double dHeight, Color cCol) override ; bool ModifyRawPartSize( int nRawId, double dLength, double dWidth, double dHeight) override ; bool ModifyRawPartHeight( int nRawId, double dHeight) override ; + bool KeepRawPart( int nRawId) override ; bool RemoveRawPart( int nRawId) override ; bool RotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg) override ; bool MoveToCornerRawPart( int nRawId, const Point3d& ptCorner, int nFlag) override ; @@ -275,6 +282,7 @@ class MachMgr : public IMachMgr bool VerifyMachAux( void) const ; bool CreateMachAux( void) ; // MachGroups + bool PrepareCurrMachGroup( int nId) ; bool VerifyMachGroup( int nId, MachGrp& mgData) const ; bool ExistsCurrMachGroup( void) const { return ( m_pGeomDB != nullptr && m_nCurrMGrpId != GDB_ID_NULL) ; } @@ -282,6 +290,9 @@ class MachMgr : public IMachMgr bool LoadMachine( const std::string& sMachineName) ; int GetMachine( const std::string& sMachineName) const ; int GetCurrMGeoId( void) const ; + // Phases + bool PrepareCurrPhase( int nPhase, bool bDoDisp) ; + int CalcPhaseCount( void) const ; // RawParts int AddRawPart( int nCrvId, double dOverMat, double dZmin, double dHeight, Color cCol) ; int AddRawPart( int nSurfId, Color cCol) ; @@ -292,6 +303,8 @@ class MachMgr : public IMachMgr bool SwapParts( bool bToRawPart) ; bool SwapRawPartParts( int nRawId, bool bToRawPart) ; bool ShowRootParts( bool bShow) ; + // Operations : dispositions + int AddDisposition( const std::string& sName, int nOperGrpId, int nPhase) ; private : typedef std::vector MCHDATAVECTOR ; @@ -308,6 +321,9 @@ class MachMgr : public IMachMgr MachGrp m_cCurrMGrp ; // dati principali macchinata corrente int m_nCurrMch ; // indice macchina corrente (0-based) MCHDATAVECTOR m_vMachines ; // elenco macchine caricate + int m_nPhasesCount ; // numero fasi di lavorazione della macchinata corrente + int m_nCurrPhase ; // indice fase corrente (1-based) + int m_nCurrDispId ; // identificativo della disposizione corrente int m_nCurrMachiningId ; // identificativo della lavorazione corrente Simulator* m_pSimul ; // puntatore al simulatore attivo } ; diff --git a/MachMgrBasic.cpp b/MachMgrBasic.cpp index f4f497c..4c1923b 100644 --- a/MachMgrBasic.cpp +++ b/MachMgrBasic.cpp @@ -47,6 +47,9 @@ MachMgr::MachMgr( void) m_nMachAuxId = GDB_ID_NULL ; m_nCurrMGrpId = GDB_ID_NULL ; m_nCurrMch = 0 ; + m_nPhasesCount = 0 ; + m_nCurrPhase = 0 ; + m_nCurrDispId = GDB_ID_NULL ; m_nCurrMachiningId = GDB_ID_NULL ; m_pSimul = nullptr ; } diff --git a/MachMgrFixtures.cpp b/MachMgrFixtures.cpp index 26872c3..0c7e49b 100644 --- a/MachMgrFixtures.cpp +++ b/MachMgrFixtures.cpp @@ -27,9 +27,8 @@ using namespace std ; bool MachMgr::SetTable( const string& sTable) { - // imposto la tavola per la disposizione ( e il calcolo) - int nDispId = GetFirstOperation() ; - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nDispId)) ; + // imposto la tavola per la prima disposizione ( e il calcolo) + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( GetFirstOperation())) ; return ( pDisp != nullptr && pDisp->SetTable( sTable)) ; } @@ -40,10 +39,8 @@ MachMgr::GetTableRef( int nInd, Point3d& ptPos) // attualmente previsto solo il riferimento 1 if ( nInd != 1) return false ; - // recupero la prima operazione, deve essere la disposizione - int nDispId = GetFirstOperation() ; - // recupero il primo oggetto disposizione - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nDispId)) ; + // recupero la prima operazione, deve essere la prima disposizione + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( GetFirstOperation())) ; if ( pDisp == nullptr) return false ; // recupero il punto @@ -57,10 +54,8 @@ MachMgr::GetTableArea( int nInd, BBox3d& b3Area1) // attualmente prevista solo l'area 1 if ( nInd != 1) return false ; - // recupero la prima operazione, deve essere la disposizione - int nDispId = GetFirstOperation() ; - // recupero il primo oggetto disposizione - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nDispId)) ; + // recupero la prima operazione, deve essere la prima disposizione + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( GetFirstOperation())) ; if ( pDisp == nullptr) return false ; // recupero il bounding box @@ -71,10 +66,8 @@ MachMgr::GetTableArea( int nInd, BBox3d& b3Area1) int MachMgr::AddFixture( const string& sName, const Point3d& ptPos, double dAngRotDeg) { - // recupero la prima operazione, deve essere la disposizione - int nDispId = GetFirstOperation() ; - // recupero l'oggetto disposizione - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nDispId)) ; + // recupero l'oggetto disposizione corrente + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione diff --git a/MachMgrMachGroups.cpp b/MachMgrMachGroups.cpp index b0ce4ea..a4fc3be 100644 --- a/MachMgrMachGroups.cpp +++ b/MachMgrMachGroups.cpp @@ -130,18 +130,16 @@ MachMgr::AddMachGroup( const string& sName, const string& sMachineName) // creo il sottogruppo per le operazioni int nOperGroupId = m_pGeomDB->AddGroup( GDB_ID_NULL, nNewId, GLOB_FRM) ; m_pGeomDB->SetName( nOperGroupId, MACH_OPER_GROUP) ; - // rendo corrente il gruppo - if ( ! SetCurrMachGroup( nNewId)) { + // predispongo e verifico impostazioni e aggiungo prima fase + if ( ! PrepareCurrMachGroup( nNewId) || AddPhase() == 0) { m_pGeomDB->Erase( nNewId) ; return GDB_ID_NULL ; } - // inserisco la prima operazione, sempre disposizione iniziale - if ( ! AddDisposition( "Disp")) { - m_pGeomDB->Erase( nNewId) ; - return GDB_ID_NULL ; - } - // reset lavorazione corrente - m_nCurrMachiningId = GDB_ID_NULL ; + // nascondo i pezzi rimasti sotto la radice + 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) ; // restituisco l'identificativo del gruppo return nNewId ; } @@ -269,6 +267,24 @@ MachMgr::GetMachGroupId( const string& sName) const //---------------------------------------------------------------------------- bool MachMgr::SetCurrMachGroup( int nId) +{ + // predispongo e verifico impostazioni + if ( ! PrepareCurrMachGroup( nId)) + return false ; + // imposto la prima fase come corrente + if ( ! SetCurrPhase( 1)) + return false ; + // nascondo i pezzi rimasti sotto la radice + 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) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::PrepareCurrMachGroup( int nId) { // verifica del gruppo base per le lavorazioni if ( ! VerifyMachBase()) @@ -297,22 +313,15 @@ MachMgr::SetCurrMachGroup( int nId) m_nCurrMGrpId = nId ; m_cCurrMGrp = mgData ; m_nCurrMch = GetMachine( m_cCurrMGrp.MGeoName) ; - // porto i pezzi dalla loro posizione standard nei grezzi nuovi - SwapParts( true) ; - // nascondo i pezzi rimasti sotto la radice - 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) ; - // eseguo la prima operazione di disposizione - int nDispId = GetFirstOperation() ; - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nDispId)) ; - if ( pDisp != nullptr) { - pDisp->Init( this) ; - return pDisp->Apply() ; + m_nPhasesCount = CalcPhaseCount() ; + m_nCurrPhase = 0 ; + m_nCurrDispId = GDB_ID_NULL ; + m_nCurrMachiningId = GDB_ID_NULL ; + if ( m_pSimul != nullptr) { + delete m_pSimul ; + m_pSimul = nullptr ; } - else - return true ; + return true ; } //---------------------------------------------------------------------------- diff --git a/MachMgrOperations.cpp b/MachMgrOperations.cpp index 6452390..d606624 100644 --- a/MachMgrOperations.cpp +++ b/MachMgrOperations.cpp @@ -371,18 +371,27 @@ MachMgr::AddDisposition( const string& sName) string sNewName = sName ; if ( ! GetOperationNewName( sNewName)) return GDB_ID_NULL ; + // eseguo + return AddDisposition( sNewName, nOperGrpId, m_nCurrPhase) ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::AddDisposition( const string& sName, int nOperGrpId, int nPhase) +{ // inserisco il gruppo int nId = m_pGeomDB->AddGroup( GDB_ID_NULL, nOperGrpId, GLOB_FRM) ; if ( nId == GDB_ID_NULL) return GDB_ID_NULL ; // assegno il nome - m_pGeomDB->SetName( nId, sNewName) ; + m_pGeomDB->SetName( nId, sName) ; // installo il gestore della disposizione Disposition* pDisp = new(nothrow) Disposition ; if ( pDisp == nullptr) return GDB_ID_NULL ; m_pGeomDB->SetUserObj( nId, pDisp) ; pDisp->Init( this) ; + pDisp->SetPhase( nPhase) ; return nId ; } @@ -400,7 +409,7 @@ MachMgr::SetCurrMachining( int nId) if ( m_pGeomDB->GetParentId( nId) != nOperGrpId) return false ; // verifico che questo gruppo sia realmente una lavorazione - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nId)) ; if ( pMch == nullptr) return false ; // gli imposto il manager generale delle lavorazioni @@ -472,7 +481,8 @@ MachMgr::AddMachining( const string& sName, const std::string& sMachining) case MT_MILLING : pMch = new( nothrow) Milling ; break ; } m_pGeomDB->SetUserObj( nId, pMch) ; - if ( pMch == nullptr || ! pMch->Init( this) || ! pMch->Prepare( sMachining)) { + if ( pMch == nullptr || ! pMch->Init( this) || + ! pMch->SetPhase( m_nCurrPhase) || ! pMch->Prepare( sMachining)) { string sOut = "AddMachining error : " + sMachining + " on " + sName ; LOG_INFO( GetEMkLogger(), sOut.c_str()) m_pGeomDB->Erase( nId) ; @@ -492,7 +502,7 @@ MachMgr::SetMachiningParam( int nType, bool bVal) if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // imposto il parametro @@ -508,7 +518,7 @@ MachMgr::SetMachiningParam( int nType, int nVal) if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // imposto il parametro @@ -524,7 +534,7 @@ MachMgr::SetMachiningParam( int nType, double dVal) if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // imposto il parametro @@ -540,7 +550,7 @@ MachMgr::SetMachiningParam( int nType, const string& sVal) if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // imposto il parametro @@ -556,7 +566,7 @@ MachMgr::SetMachiningGeometry( const SELVECTOR& vIds) if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // imposto la geometria @@ -572,7 +582,7 @@ MachMgr::MachiningPreview( bool bRecalc) if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // calcolo l'anteprima della lavorazione @@ -588,7 +598,7 @@ MachMgr::MachiningApply( bool bRecalc) if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // calcolo la lavorazione @@ -604,7 +614,7 @@ MachMgr::GetMachiningParam( int nType, bool& bVal) const if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // recupero il parametro @@ -620,7 +630,7 @@ MachMgr::GetMachiningParam( int nType, int& nVal) const if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // recupero il parametro @@ -636,7 +646,7 @@ MachMgr::GetMachiningParam( int nType, double& dVal) const if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // recupero il parametro @@ -652,7 +662,7 @@ MachMgr::GetMachiningParam( int nType, string& sVal) const if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // recupero il parametro @@ -668,7 +678,7 @@ MachMgr::GetMachiningToolData( void) const if ( nCurrMchId == GDB_ID_NULL) return nullptr ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return nullptr ; // recupero il parametro @@ -684,7 +694,7 @@ MachMgr::GetMachiningGeometry( SELVECTOR& vIds) const if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // restituisco la geometria originale @@ -700,7 +710,7 @@ MachMgr::IsEmpty( void) const if ( nCurrMchId == GDB_ID_NULL) return false ; // ne recupero il gestore - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nCurrMchId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nCurrMchId)) ; if ( pMch == nullptr) return false ; // restituisco lo stato diff --git a/MachMgrParts.cpp b/MachMgrParts.cpp index 4799cb1..f771b9e 100644 --- a/MachMgrParts.cpp +++ b/MachMgrParts.cpp @@ -1,8 +1,8 @@ //---------------------------------------------------------------------------- -// EgalTech 2015-2015 +// EgalTech 2015-2016 //---------------------------------------------------------------------------- -// File : MachMgr.cpp Data : 16.04.15 Versione : 1.6d3 -// Contenuto : Implementazione gestione grezzi e pezzi della classe MachMgr. +// File : MachMgrParts.cpp Data : 16.04.15 Versione : 1.6d3 +// Contenuto : Implementazione gestione pezzi della classe MachMgr. // // // diff --git a/MachMgrPhases.cpp b/MachMgrPhases.cpp new file mode 100644 index 0000000..cefb736 --- /dev/null +++ b/MachMgrPhases.cpp @@ -0,0 +1,197 @@ +//---------------------------------------------------------------------------- +// EgalTech 2016-2016 +//---------------------------------------------------------------------------- +// File : MachMgrPhases.cpp Data : 09.02.16 Versione : 1.6n3 +// Contenuto : Implementazione gestione fasi della classe MachMgr. +// +// +// +// Modifiche : 09.02.16 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "DllMain.h" +#include "MachMgr.h" +#include "Disposition.h" +#include "Machining.h" +#include "MachConst.h" +#include "/EgtDev/Include/EGkGdbIterator.h" +#include "/EgtDev/Include/EgtPointerOwner.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +int +MachMgr::AddPhase( void) +{ + // recupero la tavola della fase precedente + string sTable ; + int nDispId = GetFirstOperation() ; + while ( nDispId != GDB_ID_NULL) { + const Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( nDispId)) ; + if ( pDisp != nullptr) + pDisp->GetTable( sTable) ; + nDispId = GetNextOperation( nDispId) ; + } + // incremento il numero totale delle fasi + ++ m_nPhasesCount ; + // imposto la nuova fase corrente + PrepareCurrPhase( m_nPhasesCount, false) ; + // inserisco la prima operazione di fase, sempre una disposizione + string sName = "Disp" + ToString( m_nCurrPhase, 2) ; + m_nCurrDispId = AddDisposition( sName) ; + if ( m_nCurrDispId == GDB_ID_NULL) + return 0 ; + // assegno la tavola della disposizione precedente + if ( ! sTable.empty()) { + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; + pDisp->SetTable( sTable) ; + } + + return m_nCurrPhase ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::SetCurrPhase( int nPhase) +{ + return PrepareCurrPhase( nPhase, true) ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::PrepareCurrPhase( int nPhase, bool bDoDisp) +{ + // verifico esistenza fase + if ( nPhase <= 0 || nPhase > m_nPhasesCount) + return false ; + // se coincide con la vecchia fase, non devo fare alcunché + if ( nPhase == m_nCurrPhase) + return true ; + // se c'è lavorazione corrente e non appartiene a questa fase, reset + const Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( GetCurrMachining())) ; + if ( pMch != nullptr && pMch->GetPhase() != nPhase) + ResetCurrMachining() ; + // tolgo i pezzi dai grezzi che non appartengono alla fase + int nRawId = GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // recupero le fasi in cui è presente il grezzo (se manca è fase 1) + INTVECTOR vPhase ; + if ( ! m_pGeomDB->GetInfo( nRawId, MACH_RAW_PHASE, vPhase) || vPhase.empty()) + vPhase.emplace_back( 1) ; + // se non appartiene + if ( find( vPhase.begin(), vPhase.end(), nPhase) == vPhase.end()) + SwapRawPartParts( nRawId, false) ; + // passo al prossimo + nRawId = GetNextRawPart( nRawId) ; + } + // inserisco i pezzi nei grezzi che appartengono alla fase + nRawId = GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // recupero le fasi in cui è presente il grezzo (se manca è fase 1) + INTVECTOR vPhase ; + if ( ! m_pGeomDB->GetInfo( nRawId, MACH_RAW_PHASE, vPhase) || vPhase.empty()) + vPhase.emplace_back( 1) ; + // se appartiene + if ( find( vPhase.begin(), vPhase.end(), nPhase) != vPhase.end()) + SwapRawPartParts( nRawId, true) ; + // passo al prossimo + nRawId = GetNextRawPart( nRawId) ; + } + // aggiorno stato grezzi + nRawId = GetFirstRawPart() ; + while ( nRawId != GDB_ID_NULL) { + // recupero le fasi in cui è presente il grezzo + INTVECTOR vPhase ; + if ( ! m_pGeomDB->GetInfo( nRawId, MACH_RAW_PHASE, vPhase) || vPhase.empty()) + vPhase.emplace_back( 1) ; + // verifico + bool bOn = ( find( vPhase.begin(), vPhase.end(), nPhase) != vPhase.end()) ; + m_pGeomDB->SetStatus( nRawId, ( bOn ? GDB_ST_ON : GDB_ST_OFF)) ; + // passo al prossimo + nRawId = GetNextRawPart( nRawId) ; + } + // imposto disposizione corrente + int nDispId = GDB_ID_NULL ; + if ( bDoDisp) { + Disposition* pDisp = nullptr ; + nDispId = GetFirstOperation() ; + while ( nDispId != GDB_ID_NULL) { + pDisp = GetDisposition( m_pGeomDB->GetUserObj( nDispId)) ; + if ( pDisp != nullptr && pDisp->GetPhase() == nPhase) + break ; + else + pDisp = nullptr ; + nDispId = GetNextOperation( nDispId) ; + } + if ( pDisp != nullptr) { + pDisp->Init( this) ; + if ( pDisp->IsSetTableName() && ! pDisp->Apply()) + return false ; + } + else + return false ; + } + // aggiorno stato lavorazioni + int nMchId = GetFirstOperation() ; + while ( nMchId != GDB_ID_NULL) { + const Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nMchId)) ; + if ( pMch != nullptr) { + m_pGeomDB->SetStatus( nMchId, ( pMch->GetPhase() == nPhase ? GDB_ST_ON : GDB_ST_OFF)) ; + } + nMchId = GetNextOperation( nMchId) ; + } + // assegno l'indice della nuova fase corrente + m_nCurrPhase = nPhase ; + m_nCurrDispId = nDispId ; + return true ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetCurrPhase( void) const +{ + return m_nCurrPhase ; +} + +//---------------------------------------------------------------------------- +bool +MachMgr::RemoveLastPhase( void) +{ + // non è possibile rimuovere la prima e unica fase + if ( m_nPhasesCount <= 1) + return false ; + // imposto le relative lavorazioni come disattivate e senza fase + // elimino i grezzi appartenenti a questa sola fase e la relativa disposizione + // se era corrente, rendo corrente la precedente + if ( m_nCurrPhase == m_nPhasesCount) + SetCurrPhase( m_nCurrPhase - 1) ; + -- m_nPhasesCount ; + return true ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::GetPhaseCount( void) const +{ + return m_nPhasesCount ; +} + +//---------------------------------------------------------------------------- +int +MachMgr::CalcPhaseCount( void) const +{ + // ciclo sulle disposizioni + int nPhases = 0 ; + int nDispId = GetFirstOperation() ; + while ( nDispId != GDB_ID_NULL) { + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( nDispId)) ; + if ( pDisp != nullptr) + nPhases = max( nPhases, pDisp->GetPhase()) ; + nDispId = GetNextOperation( nDispId) ; + } + return nPhases ; +} diff --git a/MachMgrRawParts.cpp b/MachMgrRawParts.cpp index 9437409..4cfcd8a 100644 --- a/MachMgrRawParts.cpp +++ b/MachMgrRawParts.cpp @@ -88,6 +88,8 @@ MachMgr::AddRawPart( const Point3d& ptOrig, double dLen, double dWidth, double d return GDB_ID_NULL ; // assegno il nome al gruppo bool bOk = m_pGeomDB->SetName( nRawId, MACH_RAW_PART) ; + // assegno la fase al gruppo + m_pGeomDB->SetInfo( nRawId, MACH_RAW_PHASE, m_nCurrPhase) ; // creo solido e outline bOk = bOk && ModifyRawPart( nRawId, ptOrig, dLen, dWidth, dHeight, cCol) ; // se qualcosa è andato storto, cancello tutto @@ -475,6 +477,30 @@ MachMgr::ModifyRawPartHeight( int nRawId, double dHeight) return bOk ; } +//---------------------------------------------------------------------------- +bool +MachMgr::KeepRawPart( int nRawId) +{ + // verifica validità grezzo + if ( ! VerifyRawPart( nRawId)) + return false ; + // recupero le fasi in cui è presente il grezzo (se manca è fase 1) + INTVECTOR vPhase ; + if ( ! m_pGeomDB->GetInfo( nRawId, MACH_RAW_PHASE, vPhase) || vPhase.empty()) + vPhase.emplace_back( 1) ; + // se fase corrente già presente, non devo fare alcunché + if ( find( vPhase.begin(), vPhase.end(), m_nCurrPhase) != vPhase.end()) + return true ; + // aggiungo la fase corrente + vPhase.emplace_back( m_nCurrPhase) ; + if ( ! m_pGeomDB->SetInfo( nRawId, MACH_RAW_PHASE, vPhase)) + return false ; + // visualizzo il grezzo e ne attivo i pezzi + if ( ! m_pGeomDB->SetStatus( nRawId, GDB_ST_ON)) + return false ; + return SwapRawPartParts( nRawId, true) ; +} + //---------------------------------------------------------------------------- bool MachMgr::RemoveRawPart( int nRawId) @@ -507,10 +533,8 @@ MachMgr::VerifyRawPart( int nRawId) const bool MachMgr::RotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg) { - // recupero la prima operazione, deve essere la disposizione - int nDispId = GetFirstOperation() ; - // recupero l'oggetto disposizione - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nDispId)) ; + // recupero l'oggetto disposizione corrente + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione @@ -521,10 +545,8 @@ MachMgr::RotateRawPart( int nRawId, const Vector3d& vtAx, double dAngRotDeg) bool MachMgr::MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag) { - // recupero la prima operazione, deve essere la disposizione - int nDispId = GetFirstOperation() ; - // recupero l'oggetto disposizione - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nDispId)) ; + // recupero l'oggetto disposizione corrente + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione @@ -535,10 +557,8 @@ MachMgr::MoveToCornerRawPart( int nRawId, const Point3d& ptP, int nFlag) bool MachMgr::MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag) { - // recupero la prima operazione, deve essere la disposizione - int nDispId = GetFirstOperation() ; - // recupero l'oggetto disposizione - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nDispId)) ; + // recupero l'oggetto disposizione corrente + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione @@ -549,10 +569,8 @@ MachMgr::MoveToCenterRawPart( int nRawId, const Point3d& ptP, int nFlag) bool MachMgr::MoveRawPart( int nRawId, const Vector3d& vtMove) { - // recupero la prima operazione, deve essere la disposizione - int nDispId = GetFirstOperation() ; - // recupero l'oggetto disposizione - Disposition* pDisp = dynamic_cast( m_pGeomDB->GetUserObj( nDispId)) ; + // recupero l'oggetto disposizione corrente + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nCurrDispId)) ; if ( pDisp == nullptr) return false ; // eseguo l'operazione diff --git a/Machining.cpp b/Machining.cpp index febeb3e..ff34a89 100644 --- a/Machining.cpp +++ b/Machining.cpp @@ -65,7 +65,7 @@ Machining::Init( MachMgr* pMchMgr) //---------------------------------------------------------------------------- //---------------------------------------------------------------------------- Machining::Machining( void) - : m_nOwnerId( GDB_ID_NULL), m_pGeomDB( nullptr), m_pMchMgr( nullptr), + : 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) { @@ -483,7 +483,7 @@ Machining::GetClPathInitialAxesValues( int nClPathId, DBLVECTOR& vAxVal) // recupero la prima entità di questo percorso int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; // recupero i dati Cam dell'entità - CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( nEntId)) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; if ( pCamData == nullptr) return false ; // assegno i valori degli assi @@ -516,7 +516,7 @@ Machining::GetClPathFinalAxesValues( int nClPathId, DBLVECTOR& vAxVal) // recupero l'ultima entità di questo percorso int nEntId = m_pGeomDB->GetLastInGroup( nClPathId) ; // recupero i dati Cam dell'entità - CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( nEntId)) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; if ( pCamData == nullptr) return false ; // assegno i valori degli assi @@ -532,13 +532,13 @@ Machining::CalculateAxesValues( void) return false ; // recupero la lavorazione precedente non vuota int nPrevOpId = m_pMchMgr->GetPrevActiveOperation( m_nOwnerId) ; - Machining* pPrevMch = dynamic_cast( m_pGeomDB->GetUserObj( nPrevOpId)) ; + Machining* pPrevMch = GetMachining( m_pGeomDB->GetUserObj( nPrevOpId)) ; while ( pPrevMch != nullptr) { if ( ! pPrevMch->IsEmpty()) break ; else { nPrevOpId = m_pMchMgr->GetPrevActiveOperation( nPrevOpId) ; - pPrevMch = dynamic_cast( m_pGeomDB->GetUserObj( nPrevOpId)) ; + pPrevMch = GetMachining( m_pGeomDB->GetUserObj( nPrevOpId)) ; } } // recupero l'utensile precedente @@ -616,7 +616,7 @@ Machining::CalculateClPathAxesValues( int nClPathId, int nLinAxes, int nRotAxes, nEntId != GDB_ID_NULL ; nEntId = m_pGeomDB->GetNext( nEntId)) { // recupero i dati Cam dell'entità - CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( nEntId)) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; if ( pCamData == nullptr) continue ; // calcolo degli assi rotanti della macchina @@ -701,13 +701,13 @@ Machining::AdjustStartEndMovements(void) // recupero la lavorazione precedente non vuota int nPrevOpId = m_pMchMgr->GetPrevActiveOperation( m_nOwnerId) ; - Machining* pPrevMch = dynamic_cast( m_pGeomDB->GetUserObj( nPrevOpId)) ; + Machining* pPrevMch = GetMachining( m_pGeomDB->GetUserObj( nPrevOpId)) ; while ( pPrevMch != nullptr) { if ( ! pPrevMch->IsEmpty()) break ; else { nPrevOpId = m_pMchMgr->GetPrevActiveOperation( nPrevOpId) ; - pPrevMch = dynamic_cast( m_pGeomDB->GetUserObj( nPrevOpId)) ; + pPrevMch = GetMachining( m_pGeomDB->GetUserObj( nPrevOpId)) ; } } // recupero l'utensile precedente e i dati della sua testa @@ -780,7 +780,7 @@ Machining::AdjustOneStartMovement( int nClPathId, const DBLVECTOR& vAxPrev) // recupero la prima entità di questo percorso int nEntId = m_pGeomDB->GetFirstInGroup( nClPathId) ; // recupero i dati Cam dell'entità - CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( nEntId)) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; if ( pCamData == nullptr) return false ; // recupero i valori degli assi @@ -853,7 +853,7 @@ Machining::AddRise( DBLVECTOR& vAxVal, double dDelta) if ( nEntId == GDB_ID_NULL) return false ; // ne recupero i dati Cam - CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( nEntId)) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; if ( pCamData == nullptr) return false ; // creo oggetto punto per DB geometrico @@ -950,7 +950,7 @@ Machining::AddHome( void) if ( nEntId == GDB_ID_NULL) return false ; // ne recupero i dati Cam - CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( nEntId)) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nEntId)) ; if ( pCamData == nullptr) return false ; // creo oggetto punto per DB geometrico diff --git a/Machining.h b/Machining.h index 11f25b2..c4f41b8 100644 --- a/Machining.h +++ b/Machining.h @@ -25,12 +25,16 @@ class MachMgr ; class Machining : public IUserObj { public : // IUserObj - virtual bool SetOwner( int nId, IGeomDB* pGDB) ; - virtual int GetOwner( void) const ; - virtual IGeomDB* GetGeomDB( void) const ; + 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 Prepare( const std::string& sMchName) = 0 ; @@ -90,6 +94,7 @@ class Machining : public IUserObj 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 @@ -99,3 +104,10 @@ class Machining : public IUserObj double m_dFeed ; // feed corrente int m_nFlag ; // flag corrente } ; + +//---------------------------------------------------------------------------- +inline const Machining* GetMachining( const IUserObj* pUserObj) + { return dynamic_cast( pUserObj) ; } +inline Machining* GetMachining( IUserObj* pUserObj) + { return dynamic_cast< Machining*>( pUserObj) ; } + diff --git a/Milling.cpp b/Milling.cpp index af12a0c..efc0949 100644 --- a/Milling.cpp +++ b/Milling.cpp @@ -62,11 +62,13 @@ bool Milling::Dump( string& sOut, bool bMM, const char* szNewLine) const { sOut += GetClassName() + "[mm]" + szNewLine ; + sOut += KEY_PHASE + EQUAL + ToString( m_nPhase) + szNewLine ; sOut += KEY_IDS + EQUAL + ToString( m_vId) + szNewLine ; for ( int i = 0 ; i < m_Params.GetSize() ; ++ i) sOut += m_Params.ToString( i) + szNewLine ; for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i) sOut += m_TParams.ToString( i) + szNewLine ; + sOut += KEY_NUM + EQUAL + ToString( m_nMills) + szNewLine ; return true ; } @@ -76,7 +78,7 @@ bool Milling::Save( STRVECTOR& vString) const { try { - int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() ; + int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() + 2 ; vString.insert( vString.begin(), nSize, "") ; int k = - 1 ; if ( ! SetVal( KEY_IDS, m_vId, vString[++k])) @@ -85,6 +87,10 @@ Milling::Save( STRVECTOR& vString) const vString[++k] = m_Params.ToString( i) ; for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i) vString[++k] = m_TParams.ToString( i) ; + if ( ! SetVal( KEY_PHASE, m_nPhase, vString[++k])) + return false ; + if ( ! SetVal( KEY_NUM, m_nMills, vString[++k])) + return false ; } catch( ...) { return false ; @@ -118,7 +124,20 @@ Milling::Load( const STRVECTOR& vString) return false ; } // parametri di stato - // attualmente non presenti + while ( k < nSize - 1) { + // separo chiave da valore + string sKey, sVal ; + SplitFirst( vString[++k], "=", sKey, sVal) ; + // leggo + if ( sKey == KEY_PHASE){ + if ( ! FromString( sVal, m_nPhase)) + return false ; + } + else if ( sKey == KEY_NUM) { + if ( ! FromString( sVal, m_nMills)) + return false ; + } + } return true ; } @@ -130,6 +149,7 @@ Milling::Milling( void) m_Params.m_sToolName = "*" ; m_TParams.m_sName = "*" ; m_TParams.m_sHead = "*" ; + m_nMills = 0 ; } //---------------------------------------------------------------------------- @@ -218,6 +238,9 @@ Milling::SetGeometry( const SELVECTOR& vIds) bool Milling::Preview( bool bRecalc) { + // reset numero percorsi di lavoro generati + m_nMills = 0 ; + return false ; } @@ -225,6 +248,9 @@ Milling::Preview( bool bRecalc) bool Milling::Apply( bool bRecalc) { + // reset numero percorsi di lavoro generati + m_nMills = 0 ; + return false ; } diff --git a/Milling.h b/Milling.h index 947dccd..f65dc13 100644 --- a/Milling.h +++ b/Milling.h @@ -48,7 +48,7 @@ class Milling : public Machining bool GetGeometry( SELVECTOR& vIds) const override ; bool AdjustPositionForAxesCalc( const CamData* pCamData, Point3d& ptP) override ; bool IsEmpty( void) const override - { return true ; } + { return ( m_nMills == 0) ; } public : Milling( void) ; @@ -62,4 +62,5 @@ class Milling : public Machining SELVECTOR m_vId ; // identificativi entità geometriche da lavorare MillingData m_Params ; // parametri lavorazione ToolData m_TParams ; // parametri utensile + int m_nMills ; // numero di percorsi di lavoro generati } ; \ No newline at end of file diff --git a/MillingData.cpp b/MillingData.cpp index 981e30c..db2f601 100644 --- a/MillingData.cpp +++ b/MillingData.cpp @@ -114,7 +114,7 @@ MillingData::CopyFrom( const MachiningData* pMdata) if ( pMdata == this) return true ; // la sorgente deve essere dello stesso tipo - const MillingData* pSdata = dynamic_cast( pMdata) ; + const MillingData* pSdata = GetMillingData( pMdata) ; if ( pSdata == nullptr) return false ; // eseguo copia @@ -158,7 +158,7 @@ MillingData::SameAs(const MachiningData* pMdata) const if ( pMdata == this) return true ; // se sono di tipo diverso -> diversi - const MillingData* pSdata = dynamic_cast( pMdata) ; + const MillingData* pSdata = GetMillingData( pMdata) ; if ( pSdata == nullptr) return false ; // confronto termine a termine diff --git a/MillingData.h b/MillingData.h index 9065748..247d447 100644 --- a/MillingData.h +++ b/MillingData.h @@ -81,3 +81,5 @@ struct MillingData : public MachiningData //---------------------------------------------------------------------------- inline const MillingData* GetMillingData( const MachiningData* pMdata) { return (dynamic_cast( pMdata)) ; } +inline MillingData* GetMillingData( MachiningData* pMdata) + { return (dynamic_cast( pMdata)) ; } diff --git a/Sawing.cpp b/Sawing.cpp index 534d04b..7918fdd 100644 --- a/Sawing.cpp +++ b/Sawing.cpp @@ -67,6 +67,7 @@ bool Sawing::Dump( string& sOut, bool bMM, const char* szNewLine) const { sOut += GetClassName() + "[mm]" + szNewLine ; + sOut += KEY_PHASE + EQUAL + ToString( m_nPhase) + szNewLine ; sOut += KEY_IDS + EQUAL + ToString( m_vId) + szNewLine ; for ( int i = 0 ; i < m_Params.GetSize() ; ++ i) sOut += m_Params.ToString( i) + szNewLine ; @@ -82,7 +83,7 @@ bool Sawing::Save( STRVECTOR& vString) const { try { - int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() + 1 ; + int nSize = 1 + m_Params.GetSize() + m_TParams.GetSize() + 2 ; vString.insert( vString.begin(), nSize, "") ; int k = - 1 ; if ( ! SetVal( KEY_IDS, m_vId, vString[++k])) @@ -91,6 +92,8 @@ Sawing::Save( STRVECTOR& vString) const vString[++k] = m_Params.ToString( i) ; for ( int i = 0 ; i < m_TParams.GetSize() ; ++ i) vString[++k] = m_TParams.ToString( i) ; + if ( ! SetVal( KEY_PHASE, m_nPhase, vString[++k])) + return false ; if ( ! SetVal( KEY_NUM, m_nCuts, vString[++k])) return false ; } @@ -131,7 +134,11 @@ Sawing::Load( const STRVECTOR& vString) string sKey, sVal ; SplitFirst( vString[++k], "=", sKey, sVal) ; // leggo - if ( sKey == KEY_NUM) { + if ( sKey == KEY_PHASE){ + if ( ! FromString( sVal, m_nPhase)) + return false ; + } + else if ( sKey == KEY_NUM) { if ( ! FromString( sVal, m_nCuts)) return false ; } diff --git a/SawingData.cpp b/SawingData.cpp index 73df1af..6939e22 100644 --- a/SawingData.cpp +++ b/SawingData.cpp @@ -102,7 +102,7 @@ SawingData::CopyFrom( const MachiningData* pMdata) if ( pMdata == this) return true ; // la sorgente deve essere dello stesso tipo - const SawingData* pSdata = dynamic_cast( pMdata) ; + const SawingData* pSdata = GetSawingData( pMdata) ; if ( pSdata == nullptr) return false ; // eseguo copia @@ -140,7 +140,7 @@ SawingData::SameAs(const MachiningData* pMdata) const if ( pMdata == this) return true ; // se sono di tipo diverso -> diversi - const SawingData* pSdata = dynamic_cast( pMdata) ; + const SawingData* pSdata = GetSawingData( pMdata) ; if ( pSdata == nullptr) return false ; // confronto termine a termine diff --git a/SawingData.h b/SawingData.h index ac16f41..8676e27 100644 --- a/SawingData.h +++ b/SawingData.h @@ -76,3 +76,5 @@ struct SawingData : public MachiningData //---------------------------------------------------------------------------- inline const SawingData* GetSawingData( const MachiningData* pMdata) { return (dynamic_cast( pMdata)) ; } +inline SawingData* GetSawingData( MachiningData* pMdata) + { return (dynamic_cast( pMdata)) ; } diff --git a/Simulator.cpp b/Simulator.cpp index 2e556f7..258aa18 100644 --- a/Simulator.cpp +++ b/Simulator.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "Simulator.h" #include "MachMgr.h" +#include "Disposition.h" #include "Machining.h" #include "MachiningConst.h" #include "/EgtDev/Include/EMkToolConst.h" @@ -70,13 +71,13 @@ Simulator::Start( void) return false ; // cerco la prima lavorazione valida nOpId = m_pMchMgr->GetNextActiveOperation( nOpId) ; - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( nOpId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( nOpId)) ; while ( nOpId != GDB_ID_NULL) { if ( IsValidMachiningType( m_pMchMgr->GetOperationType( nOpId)) && pMch != nullptr && ! pMch->IsEmpty()) break ; nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; - pMch = dynamic_cast( m_pGeomDB->GetUserObj( nOpId)) ; + pMch = GetMachining( m_pGeomDB->GetUserObj( nOpId)) ; } if ( nOpId == GDB_ID_NULL) return false ; @@ -125,13 +126,18 @@ Simulator::Move( int& nStatus) // Se arrivato alla fine di una lavorazione, recupero la successiva valida while ( m_nCLPathId == GDB_ID_NULL) { m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( m_nOpId)) ; while ( m_nOpId != GDB_ID_NULL) { - if ( IsValidMachiningType( m_pMchMgr->GetOperationType( m_nOpId)) && - pMch != nullptr && ! pMch->IsEmpty()) + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; + // se non è una lavorazione, verifico se disposizione con cambio di fase + if ( pMch == nullptr) { + Disposition* pDisp = GetDisposition( m_pGeomDB->GetUserObj( m_nOpId)) ; + if ( pDisp != nullptr) + m_pMchMgr->SetCurrPhase( pDisp->GetPhase()) ; + } + // lavorazione valida + else if ( ! pMch->IsEmpty()) break ; m_nOpId = m_pMchMgr->GetNextActiveOperation( m_nOpId) ; - pMch = dynamic_cast( m_pGeomDB->GetUserObj( m_nOpId)) ; } // se non ce ne sono altre, sono alla fine if ( m_nOpId == GDB_ID_NULL) { @@ -151,7 +157,7 @@ Simulator::Move( int& nStatus) } // Cerco prossima posizione su interpolazione corrente - CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( m_nEntId)) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( m_nEntId)) ; if ( pCamData == nullptr) { nStatus = MCH_SIM_ERR ; return false ; @@ -231,7 +237,7 @@ Simulator::GetToolInfo( string& sName, double& dSpeed) return false ; sName = m_sTool ; // Recupero speed - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( m_nOpId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; return ( pMch != nullptr && pMch->GetParam( MPA_TOOLSPEED, dSpeed)) ; } @@ -243,7 +249,7 @@ Simulator::GetMoveInfo( int& nGmove, double& dFeed) if ( m_pMchMgr == nullptr || m_pGeomDB == nullptr) return false ; // Recupero il movimento corrente - CamData* pCamData = dynamic_cast( m_pGeomDB->GetUserObj( m_nEntId)) ; + CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( m_nEntId)) ; if ( pCamData == nullptr) return false ; // Assegno feed @@ -288,7 +294,7 @@ Simulator::UpdateTool( bool bForced) { // Recupero l'utensile della lavorazione corrente string sTool ; - Machining* pMch = dynamic_cast( m_pGeomDB->GetUserObj( m_nOpId)) ; + Machining* pMch = GetMachining( m_pGeomDB->GetUserObj( m_nOpId)) ; if ( pMch == nullptr || ! pMch->GetParam( MPA_TOOL, sTool)) return false ; if ( ! m_pMchMgr->TdbSetCurrTool( sTool))