//---------------------------------------------------------------------------- // EgalTech 2016-2016 //---------------------------------------------------------------------------- // File : Operation.cpp Data : 29.05.16 Versione : 1.6r7 // Contenuto : Implementazione gestione operazioni per CL. // // // // Modifiche : 29.05.16 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "DllMain.h" #include "Operation.h" #include "MachMgr.h" #include "/EgtDev/Include/EGkGeoPoint3d.h" #include "/EgtDev/Include/EGkCurveLine.h" #include "/EgtDev/Include/EGkCurveArc.h" #include "/EgtDev/Include/EGkCurveComposite.h" #include "/EgtDev/Include/EGkGeomDB.h" #include "/EgtDev/Include/EgtPointerOwner.h" using namespace std ; //---------------------------------------------------------------------------- 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 ; } //---------------------------------------------------------------------------- bool Operation::SetFlagOnLastMove( int nFlag) { int nLastEntId = m_pGeomDB->GetLastInGroup( m_nPathId) ; CamData* pCamData = GetCamData( m_pGeomDB->GetUserObj( nLastEntId)) ; if ( pCamData == nullptr) return false ; pCamData->SetFlag( nFlag) ; return true ; } //---------------------------------------------------------------------------- bool Operation::SetFlag2( int nFlag2) { m_nFlag2 = nFlag2 ; return true ; } //---------------------------------------------------------------------------- bool Operation::SetIndex( int nIndex) { m_nIndex = nIndex ; 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) ; pCam->SetFlag2( m_nFlag2) ; pCam->SetIndex( m_nIndex) ; // 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::AddRapidStart( const Point3d& ptP, const string& sName) { int nId = AddRapidStart( ptP) ; if ( nId != GDB_ID_NULL) m_pGeomDB->SetName( nId, sName) ; 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) ; pCam->SetFlag2( m_nFlag2) ; pCam->SetIndex( m_nIndex) ; // associo questo oggetto a quello geometrico m_pGeomDB->SetUserObj( nId, Release( pCam)) ; // salvo la posizione corrente m_ptCurr = ptP ; return nId ; } //---------------------------------------------------------------------------- int Operation::AddRapidMove( const Point3d& ptP, const string& sName) { int nId = AddRapidMove( ptP) ; if ( nId != GDB_ID_NULL) m_pGeomDB->SetName( nId, sName) ; return nId ; } //---------------------------------------------------------------------------- int Operation::AddRapidMove( const Point3d& ptP, bool bSplit) { // se non richiesta spezzatura con massima lunghezza, emissione normale if ( ! NeedSplit( bSplit)) return AddRapidMove( ptP) ; // altrimenti opportuna spezzatura Point3d ptS ; if ( ! GetCurrPos( ptS)) return GDB_ID_NULL ; double dLen = Dist( ptS, ptP) ; double dStep = GetMaxSplitLen( true, false) ; int nStep = int( dLen / dStep + 0.999) ; int nFirstId = GDB_ID_NULL ; for ( int i = 1 ; i <= nStep ; ++ i) { int nId = AddRapidMove( Media( ptS, ptP, i * 1.0 / nStep)) ; if ( nId == GDB_ID_NULL) return GDB_ID_NULL ; if ( nFirstId == GDB_ID_NULL) nFirstId = nId ; SetFlag( 0) ; SetFlag2( 0) ; } return nFirstId ; } //---------------------------------------------------------------------------- int Operation::AddRapidMove( const Point3d& ptP, bool bSplit, const string& sName) { int nFirstId = AddRapidMove( ptP, bSplit) ; int nId = nFirstId ; while ( nId != GDB_ID_NULL) { m_pGeomDB->SetName( nId, sName) ; nId = m_pGeomDB->GetNext( nId) ; } return nFirstId ; } //---------------------------------------------------------------------------- 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_ERROR( 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_WARN( GetEMkLogger(), "Warning 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) ; pCam->SetFlag2( m_nFlag2) ; pCam->SetIndex( m_nIndex) ; // 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, const string& sName) { int nId = AddLinearMove( ptP) ; if ( nId != GDB_ID_NULL) m_pGeomDB->SetName( nId, sName) ; return nId ; } //---------------------------------------------------------------------------- int Operation::AddLinearMove( const Point3d& ptP, bool bSplit) { // se non richiesta spezzatura con massima lunghezza, emissione normale if ( ! NeedSplit( bSplit)) return AddLinearMove( ptP) ; // altrimenti opportuna spezzatura Point3d ptS ; if ( ! GetCurrPos( ptS)) return GDB_ID_NULL ; double dLen = Dist( ptS, ptP) ; double dStep = GetMaxSplitLen( true, true) ; int nStep = int( ceil( ( dLen - EPS_ZERO) / dStep)) ; int nFirstId = GDB_ID_NULL ; for ( int i = 1 ; i <= nStep ; ++ i) { int nId = AddLinearMove( Media( ptS, ptP, i * 1.0 / nStep)) ; if ( nId == GDB_ID_NULL) return GDB_ID_NULL ; if ( nFirstId == GDB_ID_NULL) nFirstId = nId ; } return nFirstId ; } //---------------------------------------------------------------------------- int Operation::AddLinearMove( const Point3d& ptP, bool bSplit, const string& sName) { int nFirstId = AddLinearMove( ptP, bSplit) ; int nId = nFirstId ; while ( nId != GDB_ID_NULL) { m_pGeomDB->SetName( nId, sName) ; nId = m_pGeomDB->GetNext( nId) ; } return nFirstId ; } //---------------------------------------------------------------------------- int Operation::AddArcMove( const Point3d& ptP, const Point3d& ptCen, double dAngCen, const Vector3d& vtN) { 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_ERROR( 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_WARN( GetEMkLogger(), "Warning on ArcMove : Min Feed") } // creo oggetto arco per DB geometrico PtrOwner pArc( CreateCurveArc()) ; if ( IsNull( pArc)) return GDB_ID_NULL ; // verifico normale arco rispetto a versore utensile, ed eventualmente modifico opportunamente Vector3d vtMyN = vtN ; double dMyAngCen = dAngCen ; if ( vtMyN * m_vtTool < - EPS_ZERO) { vtMyN = - vtMyN ; dMyAngCen = - dMyAngCen ; } // assegno i dati dell'arco double dDeltaZ = ( ptP - m_ptCurr) * vtMyN ; if ( ! pArc->SetCPAN( ptCen, m_ptCurr, dMyAngCen, dDeltaZ, vtMyN)) return GDB_ID_NULL ; Point3d ptFin ; if ( ! pArc->GetEndPoint( ptFin) || ! AreSamePointApprox( ptFin, ptP)) return GDB_ID_NULL ; int nMove = ( dMyAngCen > 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( dMyAngCen) ; pCam->SetDeltaN( dDeltaZ) ; pCam->SetNormDir( vtMyN) ; pCam->SetFeed( m_dFeed) ; pCam->SetFlag( m_nFlag) ; pCam->SetFlag2( m_nFlag2) ; pCam->SetIndex( m_nIndex) ; // 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, const Vector3d& vtN, const string& sName) { int nId = AddArcMove( ptP, ptCen, dAngCen, vtN) ; if ( nId != GDB_ID_NULL) m_pGeomDB->SetName( nId, sName) ; return nId ; } //---------------------------------------------------------------------------- int Operation::AddCurveMove( const ICurve* pCrv) { // verifico che la curva esista if ( pCrv == nullptr) return GDB_ID_NULL ; // se linea if ( pCrv->GetType() == CRV_LINE) { const ICurveLine* pLine = GetCurveLine( pCrv) ; Point3d ptP3 = pLine->GetEnd() ; return AddLinearMove( ptP3) ; } // se arco semplice else if ( pCrv->GetType() == CRV_ARC && abs( GetCurveArc( pCrv)->GetAngCenter()) < MAX_ANG_CEN) { const ICurveArc* pArc = GetCurveArc( pCrv) ; Point3d ptCen = pArc->GetCenter() ; double dAngCen = pArc->GetAngCenter() ; Vector3d vtN = pArc->GetNormVersor() ; Point3d ptP3 ; pArc->GetEndPoint( ptP3) ; return AddArcMove( ptP3, ptCen, dAngCen, vtN) ; } // se arco o curva composita else if ( pCrv->GetType() == CRV_ARC || pCrv->GetType() == CRV_COMPO) { // in ogni caso, converto in archi e rette PtrOwner pCompo( CreateCurveComposite()) ; if ( ! pCompo->AddCurve( *pCrv)) return GDB_ID_NULL ; // verifico archi VerifyArcs( pCompo) ; // emetto curve componenti int nFirstId = GDB_ID_NULL ; const ICurve* pCrv = pCompo->GetFirstCurve() ; while ( pCrv != nullptr) { if ( pCrv->GetType() == CRV_LINE) { const ICurveLine* pLine = GetCurveLine( pCrv) ; Point3d ptP3 = pLine->GetEnd() ; int nId = AddLinearMove( ptP3) ; if ( nId == GDB_ID_NULL) return GDB_ID_NULL ; if ( nFirstId == GDB_ID_NULL) nFirstId = nId ; } else if ( pCrv->GetType() == CRV_ARC) { const ICurveArc* pArc = GetCurveArc( pCrv) ; Point3d ptCen = pArc->GetCenter() ; double dAngCen = pArc->GetAngCenter() ; Vector3d vtN = pArc->GetNormVersor() ; Point3d ptP3 ; pArc->GetEndPoint( ptP3) ; int nId = AddArcMove( ptP3, ptCen, dAngCen, vtN) ; if ( nId == GDB_ID_NULL) return GDB_ID_NULL ; if ( nFirstId == GDB_ID_NULL) nFirstId = nId ; } else return GDB_ID_NULL ; pCrv = pCompo->GetNextCurve() ; } return nFirstId ; } // altre curve non ammesse else return GDB_ID_NULL ; } //---------------------------------------------------------------------------- int Operation::AddCurveMove( const ICurve* pCrv, const string& sName) { int nFirstId = AddCurveMove( pCrv) ; int nId = nFirstId ; while ( nId != GDB_ID_NULL) { m_pGeomDB->SetName( nId, sName) ; nId = m_pGeomDB->GetNext( nId) ; } return nFirstId ; } //---------------------------------------------------------------------------- int Operation::AddCurveMove( const ICurve* pCrv, bool bSplit) { // se non richiesta spezzatura, emissione normale if ( ! bSplit) return AddCurveMove( pCrv) ; // altrimenti opportuna spezzatura PtrOwner pCompo ; if ( ! pCompo.Set( ConvertCurveToComposite( pCrv->Clone())) || ! ApproxWithLines( pCompo)) return false ; return AddCurveMove( pCompo) ; } //---------------------------------------------------------------------------- int Operation::AddCurveMove( const ICurve* pCrv, bool bSplit, const string& sName) { int nFirstId = AddCurveMove( pCrv, bSplit) ; int nId = nFirstId ; while ( nId != GDB_ID_NULL) { m_pGeomDB->SetName( nId, sName) ; nId = m_pGeomDB->GetNext( nId) ; } return nFirstId ; } //---------------------------------------------------------------------------- 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 ; m_nFlag2 = 0 ; m_nIndex = 0 ; return true ; }