diff --git a/EExDllMain.cpp b/EExDllMain.cpp
index ecd8f91..3be0128 100644
--- a/EExDllMain.cpp
+++ b/EExDllMain.cpp
@@ -44,12 +44,13 @@ DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
if ( dwReason == DLL_PROCESS_ATTACH) {
- #if defined( NDEBUG)
- BOOL IsDbgPresent = FALSE ;
- CheckRemoteDebuggerPresent( GetCurrentProcess(), &IsDbgPresent) ;
- if ( IsDbgPresent)
- return 0 ;
- #endif
+ // Controllo commentato per problemi con VB.NET
+ //#if defined( NDEBUG)
+ // BOOL IsDbgPresent = FALSE ;
+ // CheckRemoteDebuggerPresent( GetCurrentProcess(), &IsDbgPresent) ;
+ // if ( IsDbgPresent)
+ // return 0 ;
+ //#endif
s_hModule = hModule ;
EGT_TRACE( "EgtExchange.dll Initializing!\n") ;
}
diff --git a/EgtExchange.rc b/EgtExchange.rc
index ab5a064..bdf077a 100644
Binary files a/EgtExchange.rc and b/EgtExchange.rc differ
diff --git a/EgtExchange.vcxproj b/EgtExchange.vcxproj
index 72f7fdd..2aeb522 100644
--- a/EgtExchange.vcxproj
+++ b/EgtExchange.vcxproj
@@ -188,6 +188,7 @@ copy $(TargetPath) \EgtProg\Dll64
+
@@ -197,6 +198,7 @@ copy $(TargetPath) \EgtProg\Dll64
+
@@ -220,6 +222,7 @@ copy $(TargetPath) \EgtProg\Dll64
+
diff --git a/EgtExchange.vcxproj.filters b/EgtExchange.vcxproj.filters
index 2bed90f..0a0e197 100644
--- a/EgtExchange.vcxproj.filters
+++ b/EgtExchange.vcxproj.filters
@@ -63,6 +63,12 @@
File di intestazione
+
+ File di intestazione
+
+
+ File di intestazione
+
@@ -98,6 +104,9 @@
File di origine
+
+ File di origine
+
diff --git a/ExcExecutor.cpp b/ExcExecutor.cpp
index 5d8fa22..129e318 100644
--- a/ExcExecutor.cpp
+++ b/ExcExecutor.cpp
@@ -17,10 +17,11 @@
#include "DllMain.h"
#include "/EgtDev/Include/EgnStringUtils.h"
#include "/EgtDev/Include/EgnCmdParser.h"
-#include "/EgtDev/Include/EExExportStl.h"
#include "/EgtDev/Include/EExExportDxf.h"
-#include "/EgtDev/Include/EExImportStl.h"
+#include "/EgtDev/Include/EExExportStl.h"
+#include "/EgtDev/Include/EExImportCnc.h"
#include "/EgtDev/Include/EExImportDxf.h"
+#include "/EgtDev/Include/EExImportStl.h"
using namespace std ;
@@ -37,10 +38,11 @@ ExcExecutor::ExcExecutor( void)
{
// assegno chiavi a funzioni di esecuzione
m_ExecMgr.Init( 8) ;
- m_ExecMgr.Insert( "EXPORTSTL", &ExcExecutor::ExecuteExportStl) ;
m_ExecMgr.Insert( "EXPORTDXF", &ExcExecutor::ExecuteExportDxf) ;
- m_ExecMgr.Insert( "IMPORTSTL", &ExcExecutor::ExecuteImportStl) ;
+ m_ExecMgr.Insert( "EXPORTSTL", &ExcExecutor::ExecuteExportStl) ;
+ m_ExecMgr.Insert( "IMPORTCNC", &ExcExecutor::ExecuteImportCnc) ;
m_ExecMgr.Insert( "IMPORTDXF", &ExcExecutor::ExecuteImportDxf) ;
+ m_ExecMgr.Insert( "IMPORTSTL", &ExcExecutor::ExecuteImportStl) ;
}
//----------------------------------------------------------------------------
@@ -82,34 +84,6 @@ ExcExecutor::SetGeomDB( IGeomDB* pGdb)
return ( m_pGDB != nullptr) ;
}
-//----------------------------------------------------------------------------
-bool
-ExcExecutor::ExecuteExportStl( const string& sCmd2, const STRVECTOR& vsParams)
-{
- // 2 parametri : Id del gruppo, nome del file
- if ( vsParams.size() != 2)
- return false ;
- // recupero l'Id
- int nId = m_pParser->GetIdParam( vsParams[0]) ;
- if ( nId == CMD_ID_ERROR)
- return false ;
- // eventuale conversione di token nel nome file
- string sFile = vsParams[1] ;
- m_pParser->DirReplace( sFile) ;
- // preparo l'esportatore
- IExportStl* pExpStl = CreateExportStl() ;
- if ( pExpStl == nullptr) {
- LOG_ERROR( GetEExLogger(), "Error : CreateExportStl")
- return false ;
- }
- // eseguo l'esportazione
- bool bOk = pExpStl->Export( m_pGDB, nId, sFile) ;
- // cancello l'esportatore
- delete pExpStl ;
-
- return bOk ;
-}
-
//----------------------------------------------------------------------------
bool
ExcExecutor::ExecuteExportDxf( const string& sCmd2, const STRVECTOR& vsParams)
@@ -140,10 +114,38 @@ ExcExecutor::ExecuteExportDxf( const string& sCmd2, const STRVECTOR& vsParams)
//----------------------------------------------------------------------------
bool
-ExcExecutor::ExecuteImportStl( const string& sCmd2, const STRVECTOR& vsParams)
+ExcExecutor::ExecuteExportStl( const string& sCmd2, const STRVECTOR& vsParams)
{
- // 2 o 3 parametri : nome del file, Id del gruppo[, ScaleFactor]
- if ( vsParams.size() != 2 && vsParams.size() != 3)
+ // 2 parametri : Id del gruppo, nome del file
+ if ( vsParams.size() != 2)
+ return false ;
+ // recupero l'Id
+ int nId = m_pParser->GetIdParam( vsParams[0]) ;
+ if ( nId == CMD_ID_ERROR)
+ return false ;
+ // eventuale conversione di token nel nome file
+ string sFile = vsParams[1] ;
+ m_pParser->DirReplace( sFile) ;
+ // preparo l'esportatore
+ IExportStl* pExpStl = CreateExportStl() ;
+ if ( pExpStl == nullptr) {
+ LOG_ERROR( GetEExLogger(), "Error : CreateExportStl")
+ return false ;
+ }
+ // eseguo l'esportazione
+ bool bOk = pExpStl->Export( m_pGDB, nId, sFile) ;
+ // cancello l'esportatore
+ delete pExpStl ;
+
+ return bOk ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ExcExecutor::ExecuteImportCnc( const string& sCmd2, const STRVECTOR& vsParams)
+{
+ // 2 : nome del file, Id del gruppo
+ if ( vsParams.size() != 2)
return false ;
// eventuale conversione di token nel nome file
string sFile = vsParams[0] ;
@@ -152,21 +154,17 @@ ExcExecutor::ExecuteImportStl( const string& sCmd2, const STRVECTOR& vsParams)
int nId = m_pParser->GetIdParam( vsParams[1]) ;
if ( nId == CMD_ID_ERROR)
return false ;
- // gestisco ScaleFactor
- double dScaleFactor = 1 ;
- if ( vsParams.size() >= 3)
- FromString( vsParams[2], dScaleFactor) ;
// preparo l'importatore
- IImportStl* pImpStl = CreateImportStl() ;
- if ( pImpStl == nullptr) {
- LOG_ERROR( GetEExLogger(), "Error : CreateImportStl")
+ IImportCnc* pImpCnc = CreateImportCnc() ;
+ if ( pImpCnc == nullptr) {
+ LOG_ERROR( GetEExLogger(), "Error : CreateImportCnc")
return false ;
}
// eseguo l'importazione
- bool bOk = pImpStl->Import( sFile, m_pGDB, nId, dScaleFactor) ;
+ bool bOk = pImpCnc->Import( sFile, m_pGDB, nId) ;
// cancello l'importatore
- delete pImpStl ;
+ delete pImpCnc ;
return bOk ;
}
@@ -203,3 +201,36 @@ ExcExecutor::ExecuteImportDxf( const string& sCmd2, const STRVECTOR& vsParams)
return bOk ;
}
+
+//----------------------------------------------------------------------------
+bool
+ExcExecutor::ExecuteImportStl( const string& sCmd2, const STRVECTOR& vsParams)
+{
+ // 2 o 3 parametri : nome del file, Id del gruppo[, ScaleFactor]
+ if ( vsParams.size() != 2 && vsParams.size() != 3)
+ return false ;
+ // eventuale conversione di token nel nome file
+ string sFile = vsParams[0] ;
+ m_pParser->DirReplace( sFile) ;
+ // recupero l'Id
+ int nId = m_pParser->GetIdParam( vsParams[1]) ;
+ if ( nId == CMD_ID_ERROR)
+ return false ;
+ // gestisco ScaleFactor
+ double dScaleFactor = 1 ;
+ if ( vsParams.size() >= 3)
+ FromString( vsParams[2], dScaleFactor) ;
+
+ // preparo l'importatore
+ IImportStl* pImpStl = CreateImportStl() ;
+ if ( pImpStl == nullptr) {
+ LOG_ERROR( GetEExLogger(), "Error : CreateImportStl")
+ return false ;
+ }
+ // eseguo l'importazione
+ bool bOk = pImpStl->Import( sFile, m_pGDB, nId, dScaleFactor) ;
+ // cancello l'importatore
+ delete pImpStl ;
+
+ return bOk ;
+}
diff --git a/ExcExecutor.h b/ExcExecutor.h
index df1d310..4c405e1 100644
--- a/ExcExecutor.h
+++ b/ExcExecutor.h
@@ -35,10 +35,11 @@ class ExcExecutor : public IExcExecutor
ExcExecutor( void) ;
private :
- bool ExecuteExportStl( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteExportDxf( const std::string& sCmd2, const STRVECTOR& vsParams) ;
- bool ExecuteImportStl( const std::string& sCmd2, const STRVECTOR& vsParams) ;
+ bool ExecuteExportStl( const std::string& sCmd2, const STRVECTOR& vsParams) ;
bool ExecuteImportDxf( const std::string& sCmd2, const STRVECTOR& vsParams) ;
+ bool ExecuteImportCnc( const std::string& sCmd2, const STRVECTOR& vsParams) ;
+ bool ExecuteImportStl( const std::string& sCmd2, const STRVECTOR& vsParams) ;
private :
IGeomDB* m_pGDB ;
diff --git a/ImportCnc.cpp b/ImportCnc.cpp
new file mode 100644
index 0000000..f5fea6c
--- /dev/null
+++ b/ImportCnc.cpp
@@ -0,0 +1,703 @@
+//----------------------------------------------------------------------------
+// EgalTech 2014-2014
+//----------------------------------------------------------------------------
+// File : ImportCnc.cpp Data : 15.09.14 Versione : 1.5i3
+// Contenuto : Implementazione della classe per l'importazione di CNC.
+//
+//
+//
+// Modifiche : 15.09.14 DS Creazione modulo.
+//
+//
+//----------------------------------------------------------------------------
+
+//--------------------------- Include ----------------------------------------
+#include "stdafx.h"
+#include "ImportCnc.h"
+#include "DllMain.h"
+#include "/EgtDev/Include/EGkGeomDB.h"
+#include "/EgtDev/Include/EGkGdbIterator.h"
+#include "/EgtDev/Include/EGkStringUtils3d.h"
+#include "/EgtDev/Include/EgkCurveLine.h"
+#include "/EgtDev/Include/EgkCurveArc.h"
+#include "/EgtDEv/Include/EGnScan.h"
+#include "/EgtDev/Include/EgnStringConverter.h"
+#include "/EgtDev/Include/EgtPointerOwner.h"
+
+using namespace std ;
+
+//----------------------------------------------------------------------------
+IImportCnc*
+CreateImportCnc( void)
+{
+ return static_cast ( new(nothrow) ImportCnc) ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::Import( const string& sFile, IGeomDB* pGDB, int nIdGroup)
+{
+ // verifico il DB geometrico
+ if ( pGDB == nullptr) {
+ LOG_ERROR( GetEExLogger(), "ImportCnc : Error on GeomDB")
+ return false ;
+ }
+ m_pGDB = pGDB ;
+
+ // verifico l'Id di gruppo
+ if ( ! m_pGDB->ExistsObj( nIdGroup)) {
+ LOG_ERROR( GetEExLogger(), "ImportCnc : Error on IdGroup")
+ return false ;
+ }
+ m_nIdGroup = nIdGroup ;
+ // ricavo il riferimento del gruppo
+ if ( ! m_pGDB->GetGroupGlobFrame( m_nIdGroup, m_frGroup)) {
+ LOG_ERROR( GetEExLogger(), "ImportCnc : Error on Group Frame3d")
+ return false ;
+ }
+
+ // inizializzo lo scanner
+ Scanner TheScanner ;
+ if ( ! TheScanner.Init( sFile, "")) {
+ LOG_ERROR( GetEExLogger(), "ImportCnc : Error on Init")
+ return false ;
+ }
+
+ // inizializzo lo stato
+ m_bToMove = false ;
+ m_nTool = 0 ;
+ m_nNextTool = 0 ;
+ m_nMoveType = RAPID ;
+ m_nCharsOn = 0 ;
+ m_bAbsCoord = true ;
+ m_nInterpPl = XY ;
+ m_nArcType = NONE ;
+ m_ptLast = ORIG ;
+ m_ptNext = ORIG ;
+ m_ptCen = ORIG ;
+ m_vtOffs = V_NULL ;
+ m_dRadius = 0 ;
+ m_colCurr = BLACK ;
+
+ // ciclo di lettura delle linee
+ bool bOk = true ;
+ string sLine ;
+ while ( TheScanner.GetLine( sLine)) {
+ if ( ! ProcessLine( sLine)) {
+ bOk = false ;
+ string sErr = "ImportCnc : Error on line " + ToString( TheScanner.GetCurrLineNbr()) ;
+ LOG_ERROR( GetEExLogger(), sErr.c_str())
+ }
+ }
+
+ return bOk ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ProcessLine( const string& sLine)
+{
+ // eventuale gestione linea di commento
+ if ( sLine[0] == '(' || sLine[0] == ';')
+ return ParseRemark( sLine) ;
+
+ // altre linee da saltare
+ if ( sLine[0] == '$')
+ return true ;
+
+ // divido la linea in parti
+ STRVECTOR vsTokens ;
+ Tokenize( sLine, "NGXYZIJKRUVWABCFTMH", vsTokens) ;
+
+ // analizzo ogni singola parte
+ for ( size_t i = 0 ; i < vsTokens.size() ; ++ i) {
+ // analizzo per categorie determinate dal primo carattere del token
+ switch ( vsTokens[i][0]) {
+ case 'G' :
+ ParseG( vsTokens[i]) ;
+ break ;
+ case 'X' :
+ ParseX( vsTokens[i]) ;
+ break ;
+ case 'Y' :
+ ParseY( vsTokens[i]) ;
+ break ;
+ case 'Z' :
+ ParseZ( vsTokens[i]) ;
+ break ;
+ case 'I' :
+ ParseI( vsTokens[i]) ;
+ break ;
+ case 'J' :
+ ParseJ( vsTokens[i]) ;
+ break ;
+ case 'K' :
+ ParseK( vsTokens[i]) ;
+ break ;
+ case 'R' :
+ ParseR( vsTokens[i]) ;
+ break ;
+ case 'C' :
+ ParseC( vsTokens[i]) ;
+ break ;
+ case 'T' :
+ ParseT( vsTokens[i]) ;
+ break ;
+ case 'M' :
+ ParseM( vsTokens[i]) ;
+ break ;
+ }
+ }
+
+ // se comando di movimento o riconosciuto movimento, lo eseguo
+ if ( m_nCommand == MOVE || m_bToMove)
+ return ExecMovement() ;
+ // se comando di impostazione piano di interpolazione
+ else if ( m_nCommand == IPL)
+ return ExecSetIPL() ;
+
+ // reset stato comandi
+ m_nCommand = NO_CMD ;
+ m_nCharsOn = 0 ;
+ m_bToMove = false ;
+ m_nArcType = NONE ;
+
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::Tokenize( const string& sString, const string& sHeaders, STRVECTOR& vsTokens)
+{
+ string::size_type iPosStart ;
+ string::size_type iPosEnd ;
+
+
+ // pulisco il risultato
+ vsTokens.clear() ;
+ // parto dall'inizio
+ iPosStart = ( sString.empty() ? string::npos : sString.find_first_of( sHeaders, 0)) ;
+ // mentre esiste un nuovo inizio di token
+ while ( iPosStart != string::npos) {
+ // cerco il successivo carattere di intestazione
+ iPosEnd = sString.find_first_of( sHeaders, iPosStart + 1) ;
+ // aggiungo il token al vettore
+ vsTokens.push_back( sString.substr( iPosStart, iPosEnd - iPosStart)) ;
+ // cerco l'inizio di un nuovo token
+ iPosStart = iPosEnd ;
+ }
+
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseRemark( const string& sLine)
+{
+ // cerco indicazione di posizione Home
+ string::size_type iFrom = sLine.find( "FROM/") ;
+ if ( iFrom != string::npos) {
+ Point3d ptHome ;
+ if ( FromString( sLine.substr( iFrom + 5), ptHome)) {
+ m_ptLast = ptHome ;
+ m_ptNext = m_ptLast ;
+ }
+ return true ;
+ }
+ // cerco indicazione di colore
+ string::size_type iCol = sLine.find( "COLOR/") ;
+ if ( iCol != string::npos) {
+ int vnVal[3] ;
+ if ( FromString( sLine.substr( iCol + 6), vnVal)) {
+ m_colCurr.Set( vnVal[0], vnVal[1], vnVal[2]) ;
+ }
+ return true ;
+ }
+
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseG( const string& sToken)
+{
+ int nVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), nVal))
+ nVal = 0 ;
+ switch ( nVal) {
+ case 0 :
+ m_nCommand = MOVE ;
+ m_nMoveType = RAPID ;
+ break ;
+ case 1 :
+ m_nCommand = MOVE ;
+ m_nMoveType = LINE ;
+ break ;
+ case 2 :
+ m_nCommand = MOVE ;
+ m_nMoveType = ARC_CW ;
+ break ;
+ case 3 :
+ m_nCommand = MOVE ;
+ m_nMoveType = ARC_CCW ;
+ break ;
+ case 16 :
+ m_nCommand = IPL ;
+ break ;
+ case 17 :
+ m_nInterpPl = XY ;
+ break ;
+ case 18 :
+ m_nInterpPl = ZX ;
+ break ;
+ case 19 :
+ m_nInterpPl = YZ ;
+ break ;
+ case 54 :
+ case 55 :
+ case 56 :
+ case 57 :
+ m_vtOffs = V_NULL ;
+ break ;
+ case 58 :
+ case 59 :
+ m_nCommand = OFFS ;
+ m_vtOffs = V_NULL ;
+ break ;
+ case 90 :
+ m_bAbsCoord = true ;
+ break ;
+ case 91 :
+ m_bAbsCoord = false ;
+ break ;
+ }
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseX( const string& sToken)
+{
+ double dVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), dVal))
+ dVal = 0 ;
+ switch ( m_nCommand) {
+ case IPL :
+ break ;
+ case OFFS :
+ m_vtOffs.x = dVal ;
+ break ;
+ default :
+ m_ptNext.x = ( m_bAbsCoord ? m_vtOffs.x + dVal : m_ptLast.x + dVal) ;
+ m_bToMove = true ;
+ break ;
+ }
+ m_nCharsOn |= X_ON ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseY( const string& sToken)
+{
+ double dVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), dVal))
+ dVal = 0 ;
+ switch ( m_nCommand) {
+ case IPL :
+ break ;
+ case OFFS :
+ m_vtOffs.y = dVal ;
+ break ;
+ default :
+ m_ptNext.y = ( m_bAbsCoord ? m_vtOffs.y + dVal : m_ptLast.y + dVal) ;
+ m_bToMove = true ;
+ break ;
+ }
+ m_nCharsOn |= Y_ON ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseZ( const string& sToken)
+{
+ double dVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), dVal))
+ dVal = 0 ;
+ switch ( m_nCommand) {
+ case IPL :
+ break ;
+ case OFFS :
+ m_vtOffs.z = dVal ;
+ break ;
+ default :
+ m_ptNext.z = ( m_bAbsCoord ? m_vtOffs.z + dVal : m_ptLast.z + dVal) ;
+ m_bToMove = true ;
+ break ;
+ }
+ m_nCharsOn |= Z_ON ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseI( const string& sToken)
+{
+ double dVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), dVal))
+ dVal = 0 ;
+ m_ptCen.x = dVal ;
+ m_nArcType = CENTER ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseJ( const string& sToken)
+{
+ double dVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), dVal))
+ dVal = 0 ;
+ m_ptCen.y = dVal ;
+ m_nArcType = CENTER ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseK( const string& sToken)
+{
+ double dVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), dVal))
+ dVal = 0 ;
+ m_ptCen.z = dVal ;
+ m_nArcType = CENTER ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseR( const string& sToken)
+{
+ double dVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), dVal))
+ dVal = 0 ;
+ m_dRadius = dVal ;
+ m_nArcType = RADIUS ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseC( const string& sToken)
+{
+ // cerco l'impostazione del raggio con CR= (Siemens)
+ if ( sToken.find( "CR=") != 0)
+ return true ;
+ double dVal ;
+ int nStart = 3 ;
+ if ( ! FromString( sToken.substr( nStart), dVal))
+ dVal = 0 ;
+ m_dRadius = dVal ;
+ m_nArcType = RADIUS ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseT( const string& sToken)
+{
+ int nVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), nVal))
+ nVal = 0 ;
+ m_nNextTool = nVal ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ParseM( const string& sToken)
+{
+ int nVal ;
+ int nStart = ( sToken[1] == '=' ? 2 : 1) ;
+ if ( ! FromString( sToken.substr( nStart), nVal))
+ nVal = 0 ;
+ if ( nVal == 6)
+ m_nTool = m_nNextTool ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ExecSetIPL( void)
+{
+ if ( ( m_nCharsOn & X_ON) != 0 && ( m_nCharsOn & Y_ON)) {
+ m_nInterpPl = XY ;
+ return true ;
+ }
+ else if ( ( m_nCharsOn & Y_ON) != 0 && ( m_nCharsOn & Z_ON)) {
+ m_nInterpPl = YZ ;
+ return true ;
+ }
+ else if ( ( m_nCharsOn & Z_ON) != 0 && ( m_nCharsOn & X_ON)) {
+ m_nInterpPl = ZX ;
+ return true ;
+ }
+
+ return false ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::ExecMovement( void)
+{
+ switch ( m_nMoveType) {
+ case RAPID :
+ return AddLine( L_RAPID) ;
+ case LINE :
+ return AddLine( L_LINE) ;
+ case ARC_CW :
+ case ARC_CCW :
+ if ( AddArc( m_nMoveType == ARC_CCW))
+ return true ;
+ AddLine( L_ERROR) ;
+ return false ;
+ }
+
+ return false ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::AddLine( int nLineType)
+{
+ // se la linea è nulla, non la inserisco ma proseguo senza errore
+ if ( AreSamePointApprox( m_ptLast, m_ptNext))
+ return true ;
+
+ // creo la linea
+ PtrOwner pCrvLine( CreateCurveLine()) ;
+ if ( IsNull( pCrvLine))
+ return false ;
+ // setto la linea
+ if ( ! pCrvLine->Set( m_ptLast, m_ptNext))
+ return false ;
+ // porto la linea nel riferimento del gruppo
+ pCrvLine->ToLoc( m_frGroup) ;
+ // inserisco la linea nel DB
+ int nId = m_pGDB->AddGeoObj( GDB_ID_NULL, GetToolGroup( m_nTool), Release( pCrvLine)) ;
+ if ( nId == GDB_ID_NULL)
+ return false ;
+ // attributi
+ switch ( nLineType) {
+ case L_RAPID :
+ m_pGDB->SetMaterial( nId, Color( 0, 192, 192)) ;
+ break ;
+ case L_LINE :
+ m_pGDB->SetMaterial( nId, m_colCurr) ;
+ break ;
+ case L_ERROR :
+ m_pGDB->SetMaterial( nId, RED) ;
+ m_pGDB->SetName( nId, "Error") ;
+ break ;
+ }
+ // movimento effettuato
+ m_ptLast = m_ptNext ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::AddArc( bool bCCW)
+{
+ // creo l'arco
+ PtrOwner pCrvArc( CreateCurveArc()) ;
+ if ( IsNull( pCrvArc))
+ return false ;
+ // determino la normale al piano di interpolazione
+ Vector3d vtN = Z_AX ;
+ if ( m_nInterpPl == ZX)
+ vtN = Y_AX ;
+ else if ( m_nInterpPl == YZ)
+ vtN = X_AX ;
+ // se arco definito con raggio
+ if ( m_nArcType == RADIUS) {
+ // punti estremi, raggio e senso di rotazione
+ if ( ! pCrvArc->Set2PNRS( m_ptLast, m_ptNext, vtN, fabs( m_dRadius), bCCW))
+ return false ;
+ // se raggio negativo, si deve prendere la soluzione con AngCen > 180deg
+ if ( m_dRadius < 0) {
+ if ( ! pCrvArc->Flip() || ! pCrvArc->ToAdditional())
+ return false ;
+ }
+ }
+ // se arco definito con centro
+ else if ( m_nArcType == CENTER) {
+ // determino se valido
+ switch ( VerifyArcCenter( vtN)) {
+ case A_ARC :
+ // punti estremi e centro
+ if ( ! pCrvArc->SetC2PN( m_ptCen, m_ptLast, m_ptNext, vtN))
+ return false ;
+ break ;
+ case A_CIRC :
+ // calcolo standard
+ if ( ! SetCircC2PN( m_ptCen, m_ptLast, m_ptNext, vtN, Get( pCrvArc)))
+ return false ;
+ break ;
+ default :
+ return false ;
+ }
+ // verifico senso di rotazione
+ if ( ( bCCW && pCrvArc->GetAngCenter() < 0) ||
+ ( ! bCCW && pCrvArc->GetAngCenter() > 0)) {
+ if ( ! pCrvArc->ToAdditional())
+ return false ;
+ }
+ }
+ // altrimenti errore
+ else
+ return false ;
+ // porto l'arco nel riferimento del gruppo
+ pCrvArc->ToLoc( m_frGroup) ;
+ // inserisco l'arco nel DB
+ int nId = m_pGDB->AddGeoObj( GDB_ID_NULL, GetToolGroup( m_nTool), Release( pCrvArc)) ;
+ if ( nId == GDB_ID_NULL)
+ return false ;
+ // assegnazione del colore
+ if ( ! m_pGDB->SetMaterial( nId, m_colCurr))
+ return false ;
+ // movimento effettuato
+ m_ptLast = m_ptNext ;
+ return true ;
+}
+
+//----------------------------------------------------------------------------
+int
+ImportCnc::VerifyArcCenter( const Vector3d& vtN)
+{
+ // calcolo il riferimento OCS derivato da vtN
+ Frame3d frOcs ;
+ if ( ! frOcs.Set( ORIG, vtN))
+ return A_ERROR ;
+ // porto i punti in questo riferimento
+ Point3d ptLloc = m_ptLast ;
+ ptLloc.ToLoc( frOcs) ;
+ Point3d ptNloc = m_ptNext ;
+ ptNloc.ToLoc( frOcs) ;
+ Point3d ptCloc = m_ptCen ;
+ ptCloc.ToLoc( frOcs) ;
+ Vector3d vtOloc = m_vtOffs ;
+ vtOloc.ToLoc( frOcs) ;
+ // verifico se circonferenza
+ int nRet = ( SqDistXY( ptLloc, ptNloc) > EPS_SMALL * EPS_SMALL) ? A_ARC : A_CIRC ;
+ // se coordinate in assoluto prima verifico in assoluto
+ if ( m_bAbsCoord) {
+ // centro in assoluto
+ Point3d ptCas = ptCloc + vtOloc ;
+ double dRadLast = DistXY( ptLloc, ptCas) ;
+ double dRadNext = DistXY( ptNloc, ptCas) ;
+ if ( fabs ( dRadNext - dRadLast) < 10 * EPS_SMALL) {
+ m_ptCen += m_vtOffs ;
+ return nRet ;
+ }
+ // centro in relativo
+ Point3d ptCrl = ptCloc + ptLloc ;
+ dRadLast = DistXY( ptLloc, ptCrl) ;
+ dRadNext = DistXY( ptNloc, ptCrl) ;
+ if ( fabs ( dRadNext - dRadLast) < 10 * EPS_SMALL) {
+ m_ptCen = ptCrl ;
+ m_ptCen.ToGlob( frOcs) ;
+ return nRet ;
+ }
+ }
+ // altrimenti coordinate in relativo e prima provo queste
+ else {
+ // centro in relativo
+ Point3d ptCrl = ptCloc + ptLloc ;
+ double dRadLast = DistXY( ptLloc, ptCrl) ;
+ double dRadNext = DistXY( ptNloc, ptCrl) ;
+ if ( fabs ( dRadNext - dRadLast) < 10 * EPS_SMALL) {
+ m_ptCen = ptCrl ;
+ m_ptCen.ToGlob( frOcs) ;
+ return nRet ;
+ }
+ // centro in assoluto
+ Point3d ptCas = ptCloc + vtOloc ;
+ dRadLast = DistXY( ptLloc, ptCas) ;
+ dRadNext = DistXY( ptNloc, ptCas) ;
+ if ( fabs ( dRadNext - dRadLast) < 10 * EPS_SMALL) {
+ m_ptCen += m_vtOffs ;
+ return nRet ;
+ }
+ }
+
+ return A_ERROR ;
+}
+
+//----------------------------------------------------------------------------
+bool
+ImportCnc::SetCircC2PN( const Point3d& ptCen, const Point3d& ptStart, const Point3d& ptNearEnd, const Vector3d& vtN,
+ ICurveArc* pCrvArc)
+{
+ // calcolo il riferimento OCS derivato da vtN
+ Frame3d frOcs ;
+ if ( ! frOcs.Set( ORIG, vtN))
+ return false ;
+ // porto i punti in questo riferimento
+ Point3d ptCloc = ptCen ;
+ ptCloc.ToLoc( frOcs) ;
+ Point3d ptSloc = ptStart ;
+ ptSloc.ToLoc( frOcs) ;
+ Point3d ptNEloc = ptNearEnd ;
+ ptNEloc.ToLoc( frOcs) ;
+ // calcolo il cerchio in questo piano
+ double dRad = 0.5 * ( DistXY( ptCloc, ptSloc) + DistXY( ptCloc, ptNEloc)) ;
+ ptCloc.z = ptSloc.z ;
+ Vector3d vtS = ptSloc - ptCloc ;
+ if ( ! pCrvArc->Set( ptCloc, Z_AX, dRad, vtS, ANG_FULL, ptNEloc.z - ptSloc.z))
+ return false ;
+ // riporto l'arco nel riferimento naturale
+ return pCrvArc->ToGlob( frOcs) ;
+}
+
+//----------------------------------------------------------------------------
+int
+ImportCnc::GetToolGroup( int nTool)
+{
+ // assegno il nome dell'utensile
+ string sTool = "T" + ToString( nTool, 2) ;
+
+ // se trovo un gruppo con il nome dell'utensile, ne restituisco l'Id
+ PtrOwner pIter( CreateGdbIterator( m_pGDB)) ;
+ if ( IsNull( pIter))
+ return false ;
+ for ( bool bNext = pIter->GoToFirstInGroup( m_nIdGroup) ;
+ bNext ;
+ bNext = pIter->GoToNext()) {
+ string sName ;
+ if ( pIter->GetName( sName) && sName == sTool)
+ return pIter->GetId() ;
+ }
+
+ // inserisco un nuovo layer nel DB geometrico
+ int nId = m_pGDB->AddGroup( GDB_ID_NULL, m_nIdGroup, GLOB_FRM) ;
+ if ( nId == GDB_ID_NULL)
+ return GDB_ID_NULL ;
+ // assegnazione nome
+ if ( ! m_pGDB->SetName( nId, sTool))
+ return GDB_ID_NULL ;
+
+ return nId ;
+}
+
diff --git a/ImportCnc.h b/ImportCnc.h
new file mode 100644
index 0000000..8379455
--- /dev/null
+++ b/ImportCnc.h
@@ -0,0 +1,79 @@
+//----------------------------------------------------------------------------
+// EgalTech 2014-2014
+//----------------------------------------------------------------------------
+// File : ImportCnc.h Data : 15.09.14 Versione : 1.5i3
+// Contenuto : Dichiarazione della classe ImportCnc.
+//
+//
+//
+// Modifiche : 15.09.14 DS Creazione modulo.
+//
+//
+//----------------------------------------------------------------------------
+
+#pragma once
+
+#include "/EgtDev/Include/EExImportCnc.h"
+#include "/EgtDev/Include/EGnStringBase.h"
+
+class ICurveArc ;
+
+//----------------------------------------------------------------------------
+class ImportCnc : public IImportCnc
+{
+ public :
+ virtual bool Import( const std::string& sFile, IGeomDB* pGDB, int nIdGroup) ;
+
+ private :
+ bool ProcessLine( const std::string& sLine) ;
+ bool Tokenize( const std::string& sString, const std::string& sHeaders, STRVECTOR& vsTokens) ;
+ bool ParseRemark( const std::string& sLine) ;
+ bool ParseG( const std::string& sToken) ;
+ bool ParseX( const std::string& sToken) ;
+ bool ParseY( const std::string& sToken) ;
+ bool ParseZ( const std::string& sToken) ;
+ bool ParseI( const std::string& sToken) ;
+ bool ParseJ( const std::string& sToken) ;
+ bool ParseK( const std::string& sToken) ;
+ bool ParseR( const std::string& sToken) ;
+ bool ParseC( const std::string& sToken) ;
+ bool ParseT( const std::string& sToken) ;
+ bool ParseM( const std::string& sToken) ;
+ bool ExecSetIPL( void) ;
+ bool ExecMovement( void) ;
+ bool AddLine( int nLineType) ;
+ bool AddArc( bool bCCW) ;
+ int VerifyArcCenter( const Vector3d& vtN) ;
+ bool SetCircC2PN( const Point3d& ptCen, const Point3d& ptStart, const Point3d& ptNearEnd, const Vector3d& vtN,
+ ICurveArc* pCrvArc) ;
+ int GetToolGroup( int nTool) ;
+
+ private :
+ enum InterpPl { XY = 1, YZ = 2, ZX = 3} ;
+ enum Command { NO_CMD = 0, MOVE = 1, IPL = 2, OFFS = 3} ;
+ enum MoveType { RAPID = 0, LINE = 1, ARC_CW = 2, ARC_CCW = 3} ;
+ enum LineType { L_RAPID = 0, L_LINE = 1, L_ERROR = 2} ;
+ enum ArcType { NONE = 0, RADIUS = 1, CENTER = 2} ;
+ enum ArcCtType { A_ARC = 0, A_CIRC =1, A_ERROR = 2} ;
+ enum CharOn { X_ON = 1, Y_ON = 2, Z_ON = 4 } ;
+
+ private :
+ IGeomDB* m_pGDB ;
+ int m_nIdGroup ;
+ Frame3d m_frGroup ;
+ bool m_bToMove ;
+ int m_nTool ;
+ int m_nNextTool ;
+ int m_nCommand ;
+ int m_nCharsOn ;
+ int m_nMoveType ;
+ bool m_bAbsCoord ;
+ int m_nInterpPl ;
+ int m_nArcType ;
+ Point3d m_ptLast ;
+ Point3d m_ptNext ;
+ Point3d m_ptCen ;
+ Vector3d m_vtOffs ;
+ double m_dRadius ;
+ Color m_colCurr ;
+} ;