diff --git a/TestEGr.rc b/TestEGr.rc index c2a7308..db2a9cb 100644 Binary files a/TestEGr.rc and b/TestEGr.rc differ diff --git a/TestEGrDlg.cpp b/TestEGrDlg.cpp index 9728e57..1922d5c 100644 --- a/TestEGrDlg.cpp +++ b/TestEGrDlg.cpp @@ -29,6 +29,8 @@ #include "/EgtDev/Include/EGrSceExecutor.h" #include "/EgtDev/Include/EExImportStl.h" #include "/EgtDev/Include/EExImportDxf.h" +#include "/EgtDev/Include/EExExportStl.h" +#include "/EgtDev/Include/EExExportDxf.h" using namespace std ; @@ -142,6 +144,7 @@ BEGIN_MESSAGE_MAP( CTestEGrDlg, CDialog) ON_BN_CLICKED( IDC_OPEN, OnFileOpen) ON_BN_CLICKED( IDC_SAVE, OnFileSave) ON_BN_CLICKED( IDC_IMPORT, OnFileImport) + ON_BN_CLICKED( IDC_EXPORT, OnFileExport) ON_BN_CLICKED( IDC_EXEC, OnFileExec) ON_CONTROL_RANGE( BN_CLICKED, IDC_WIREFRAME, IDC_SHADING, OnShowMode) ON_BN_CLICKED( IDC_SHOWCURVEDIR, OnShowCurveDir) @@ -477,6 +480,7 @@ CTestEGrDlg::OnSize( UINT nType, int cx, int cy) MoveDlgItem( IDC_NEW, IP_TR, cx, cy) ; MoveDlgItem( IDC_OPEN, IP_TR, cx, cy) ; MoveDlgItem( IDC_SAVE, IP_TR, cx, cy) ; + MoveDlgItem( IDC_EXPORT, IP_TR, cx, cy) ; MoveDlgItem( IDC_IMPORT, IP_TR, cx, cy) ; MoveDlgItem( IDC_EXEC, IP_TR, cx, cy) ; MoveDlgItem( IDC_SEPAR, IP_TR, cx, cy) ; @@ -807,6 +811,47 @@ CTestEGrDlg::OnFileImport( void) AfxMessageBox( L"Error importing file (look at Log file)", MB_ICONSTOP|MB_OK) ; } +//---------------------------------------------------------------------------- +void +CTestEGrDlg::OnFileExport( void) +{ + // visualizzo il dialogo di scelta file + CFileDialog dlg( FALSE, L"*.*", NULL, + OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR, + L"All Files (*.*)|*.*|" + L"AutoCAD Drawing Exchange (*.dxf) |*.dxf|" + L"Stereolithography (*.stl) |*.stl||", + NULL, 0, FALSE) ; + + // imposto il direttorio iniziale + wstring wsDir = stringtoW( GetPrivateProfileStringUtf8( "General", "LastExpDir", "", AfxGetApp()->m_pszProfileName)) ; + if ( ! wsDir.empty()) + dlg.m_ofn.lpstrInitialDir = wsDir.c_str() ; + + // lancio il dialogo di scelta file + if ( dlg.DoModal() != IDOK) + return ; + + // recupero la path del file + string sFilePath = WtoA( dlg.GetPathName()) ; + if ( sFilePath.empty()) + return ; + + // imposto cursore attesa + CWaitCursor wait ; + + // divido in nome e direttorio e salvo quest'ultimo + string sFileDir ; + string sFileName ; + SplitLast( sFilePath, "\\", sFileDir, sFileName) ; + if ( ! sFileDir.empty()) + WritePrivateProfileStringUtf8( "General", "LastExpDir", sFileDir.c_str(), AfxGetApp()->m_pszProfileName) ; + + // salvo il file + if ( ! FileExport( sFilePath)) + AfxMessageBox( L"Error exporting file (look at Log file)", MB_ICONSTOP|MB_OK) ; +} + //---------------------------------------------------------------------------- void CTestEGrDlg::OnFileExec( void) @@ -1238,6 +1283,67 @@ CTestEGrDlg::FileImport( const string& sFilePath) return true ; } +//---------------------------------------------------------------------------- +bool +CTestEGrDlg::FileExport( const string& sFilePath) +{ + // divido in nome e direttorio + string sFileDir ; + string sFileName ; + SplitLast( sFilePath, "\\", sFileDir, sFileName) ; + + // recupero l'estensione + string sFileTitle ; + string sFileExt ; + SplitLast( sFileName, ".", sFileTitle, sFileExt) ; + ToUpper( sFileExt) ; + + // verifico che l'estensione sia supportata + if ( sFileExt != "DXF" && sFileExt != "STL") { + // emetto info + string sInfo = "File type (" + sFileExt + ") not recognized" ; + LOG_INFO( m_pLogGen, sInfo.c_str()) + return false ; + } + + // emetto info + string sInfo = "Export File = " + sFilePath ; + LOG_INFO( m_pLogGen, sInfo.c_str()) + + // esporto il file DXF + if ( sFileExt == "DXF") { + // preparo l'esportatore + PtrOwner pExpDxf( CreateExportDxf()) ; + if ( ! IsValid( pExpDxf)) { + LOG_ERROR( m_pLogGen, "Error : CreateExportDxf") + return false ; + } + // eseguo l'esportazione + if ( ! pExpDxf->Export( m_pGeomDB, GDB_ID_ROOT, sFilePath)) { + return false ; + } + // log dei comandi + LOG_INFO( m_pLogCmd, ( "EXPORTDXF( 0, " + sFilePath + ")").c_str()) + } + // esporto il file STL + else if ( sFileExt == "STL") { + // preparo l'esportatore + PtrOwner pExpStl( CreateExportStl()) ; + if ( ! IsValid( pExpStl)) { + LOG_ERROR( m_pLogGen, "Error : CreateExportStl") + return false ; + } + // eseguo l'esportazione + if ( ! pExpStl->Export( m_pGeomDB, GDB_ID_ROOT, sFilePath)) { + return false ; + } + // log dei comandi + LOG_INFO( m_pLogCmd, ( "EXPORTSTL( 0, " + sFilePath + ")").c_str()) + } + + return true ; +} + //---------------------------------------------------------------------------- bool CTestEGrDlg::FileExec( const string& sFilePath) diff --git a/TestEGrDlg.h b/TestEGrDlg.h index eb7e58e..1fabdfc 100644 --- a/TestEGrDlg.h +++ b/TestEGrDlg.h @@ -51,6 +51,7 @@ class CTestEGrDlg : public CDialog afx_msg void OnFileOpen( void) ; afx_msg void OnFileSave( void) ; afx_msg void OnFileImport( void) ; + afx_msg void OnFileExport( void) ; afx_msg void OnFileExec( void) ; afx_msg void OnShowMode( UINT nID) ; afx_msg void OnShowCurveDir( void) ; @@ -83,6 +84,7 @@ class CTestEGrDlg : public CDialog bool FileOpen( const std::string& sFilePath) ; bool FileSave( const std::string& sFilePath) ; bool FileImport( const std::string& sFilePath) ; + bool FileExport( const std::string& sFilePath) ; bool FileExec( const std::string& sFilePath) ; void EmitTitle( void) ; // GeomDBTree diff --git a/resource.h b/resource.h index cc020d4..ccfac1c 100644 Binary files a/resource.h and b/resource.h differ