1945a5cff4
- aggiunto import di DXF e STL - aggiunto albero per materiali custom.
1273 lines
40 KiB
C++
1273 lines
40 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2013-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : TestEGrDlg.cpp Data : 29.01.14 Versione : 1.5a1
|
|
// Contenuto : Implementazione della classe gestione dialogo principale.
|
|
//
|
|
//
|
|
//
|
|
// Modifiche : 29.01.14 DS Creazione modulo.
|
|
//
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "TestEGr.h"
|
|
#include "TestEGrDlg.h"
|
|
#include "TestEGrUtils.h"
|
|
#include "resource.h"
|
|
#include "/EgtDev/Include/EgtIniFile.h"
|
|
#include "/EgtDev/Include/EgtILogger.h"
|
|
#include "/EgtDev/Include/EgtPerfCounter.h"
|
|
#include "/EgtDev/Include/EgtPointerOwner.h"
|
|
#include "/EgtDev/Include/EGnCmdParser.h"
|
|
#include "/EgtDev/Include/EGkGeomDB.h"
|
|
#include "/EgtDev/Include/EGkGdbExecutor.h"
|
|
#include "/EgtDev/Include/EExExcExecutor.h"
|
|
#include "/EgtDev/Include/EGrScene.h"
|
|
#include "/EgtDev/Include/EGrSceExecutor.h"
|
|
#include "/EgtDev/Include/EExImportStl.h"
|
|
#include "/EgtDev/Include/EExImportDxf.h"
|
|
|
|
using namespace std ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
#ifdef _DEBUG
|
|
#define new DEBUG_NEW
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[] = __FILE__;
|
|
#endif
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
// CAboutDlg dialog used for App About
|
|
//----------------------------------------------------------------------------
|
|
class CAboutDlg : public CDialog
|
|
{
|
|
public :
|
|
CAboutDlg( void) ;
|
|
|
|
protected :
|
|
BOOL OnInitDialog( void) ;
|
|
|
|
DECLARE_MESSAGE_MAP()
|
|
} ;
|
|
|
|
//----------------------------------------------------------------------------
|
|
CAboutDlg::CAboutDlg( void) : CDialog( IDD_ABOUTBOX)
|
|
{
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
CAboutDlg::OnInitDialog( void)
|
|
{
|
|
CDialog::OnInitDialog() ;
|
|
|
|
GetDlgItem( IDC_EXEVER)->SetWindowText( stringtoW( GetExeNameVer())) ;
|
|
|
|
string sInfo ;
|
|
GetSceneInfo( sInfo) ;
|
|
ReplaceString( sInfo, "\n", "\r\n") ;
|
|
sInfo += "\r\n" ;
|
|
GetDlgItem( IDC_EXEINFO)->SetWindowText( stringtoW( sInfo)) ;
|
|
|
|
return TRUE ;
|
|
}
|
|
|
|
BEGIN_MESSAGE_MAP( CAboutDlg, CDialog)
|
|
END_MESSAGE_MAP()
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
// CTestEGrDlg dialog
|
|
//----------------------------------------------------------------------------
|
|
CTestEGrDlg::CTestEGrDlg( const std::string& sFileToOpen, ILogger* pLogGen, ILogger* pLogCmd, CWnd* pParent)
|
|
:CDialog( IDD_TESTEGR_DIALOG, pParent)
|
|
{
|
|
m_hIcon = AfxGetApp()->LoadIcon( IDR_MAINFRAME) ;
|
|
// eventuale file da caricare all'avvio
|
|
m_sFileToOpen = sFileToOpen ;
|
|
// memorizzo i puntatori ai logger generale e dei comandi
|
|
m_pLogGen = pLogGen ;
|
|
m_pLogCmd = pLogCmd ;
|
|
// inizializzazioni varie
|
|
m_pGeomDB = nullptr ;
|
|
m_pGdbExec = nullptr ;
|
|
m_pExcExec = nullptr ;
|
|
m_pSceExec = nullptr ;
|
|
m_pCmdParser = nullptr ;
|
|
m_pImgList = nullptr ;
|
|
m_nOldIdTree = GDB_ID_NULL ;
|
|
m_bModified = false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
CTestEGrDlg::~CTestEGrDlg( void)
|
|
{
|
|
// ripristino ultima entità selezionata sull'albero delle entità
|
|
RevertOldIdInTree() ;
|
|
// cancello esecutori
|
|
if ( m_pGdbExec != nullptr)
|
|
delete m_pGdbExec ;
|
|
m_pGdbExec = nullptr ;
|
|
if ( m_pExcExec != nullptr)
|
|
delete m_pExcExec ;
|
|
m_pExcExec = nullptr ;
|
|
if ( m_pSceExec != nullptr)
|
|
delete m_pSceExec ;
|
|
m_pSceExec = nullptr ;
|
|
if ( m_pCmdParser != nullptr)
|
|
delete m_pCmdParser ;
|
|
m_pCmdParser = nullptr ;
|
|
// cancello GeomDB
|
|
if ( m_pGeomDB != nullptr)
|
|
delete m_pGeomDB ;
|
|
m_pGeomDB = nullptr ;
|
|
// cancello ImgList
|
|
if ( m_pImgList != nullptr)
|
|
delete m_pImgList ;
|
|
m_pImgList = nullptr ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BEGIN_MESSAGE_MAP( CTestEGrDlg, CDialog)
|
|
ON_WM_SYSCOMMAND()
|
|
ON_WM_PAINT()
|
|
ON_WM_QUERYDRAGICON()
|
|
ON_WM_SIZE()
|
|
ON_WM_CLOSE()
|
|
ON_BN_CLICKED( IDC_NEW, OnFileNew)
|
|
ON_BN_CLICKED( IDC_OPEN, OnFileOpen)
|
|
ON_BN_CLICKED( IDC_SAVE, OnFileSave)
|
|
ON_BN_CLICKED( IDC_IMPORT, OnFileImport)
|
|
ON_BN_CLICKED( IDC_EXEC, OnFileExec)
|
|
ON_CONTROL_RANGE( BN_CLICKED, IDC_WIREFRAME, IDC_SHADING, OnShowMode)
|
|
ON_CONTROL_RANGE( BN_CLICKED, IDC_ZOOM_ALL, IDC_ZOOM_OUT, OnZoom)
|
|
ON_CONTROL_RANGE( BN_CLICKED, IDC_VIEW_TOP, IDC_VIEW_ISO, OnView)
|
|
ON_BN_CLICKED( IDC_CLOSE, OnClose)
|
|
ON_NOTIFY( TVN_SELCHANGED, IDC_TREE, OnTreeSelChanged)
|
|
ON_NOTIFY( NM_DBLCLK, IDC_TREE, OnTreeDoubleClick)
|
|
END_MESSAGE_MAP()
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
CTestEGrDlg::OnInitDialog( void)
|
|
{
|
|
CDialog::OnInitDialog() ;
|
|
|
|
// Add "About..." menu item to system menu.
|
|
|
|
// IDM_ABOUTBOX must be in the system command range.
|
|
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX) ;
|
|
ASSERT(IDM_ABOUTBOX < 0xF000) ;
|
|
|
|
CMenu* pSysMenu = GetSystemMenu( FALSE) ;
|
|
if ( pSysMenu != NULL) {
|
|
BOOL bNameValid ;
|
|
CString strAboutMenu ;
|
|
bNameValid = strAboutMenu.LoadString( IDS_ABOUTBOX) ;
|
|
ASSERT( bNameValid) ;
|
|
if ( ! strAboutMenu.IsEmpty()) {
|
|
pSysMenu->AppendMenu( MF_SEPARATOR) ;
|
|
pSysMenu->AppendMenu( MF_STRING, IDM_ABOUTBOX, strAboutMenu) ;
|
|
}
|
|
}
|
|
|
|
// Set the icon for this dialog. The framework does this automatically
|
|
// when the application's main window is not a dialog
|
|
SetIcon( m_hIcon, TRUE) ; // Set big icon
|
|
SetIcon( m_hIcon, FALSE) ; // Set small icon
|
|
|
|
// salvo le dimensioni del client
|
|
CRect rectClient ;
|
|
GetClientRect( &rectClient) ;
|
|
m_nPrevCx = rectClient.right ;
|
|
m_nPrevCy = rectClient.bottom ;
|
|
|
|
// salvo le dimensioni della barra di destra e di quella in basso
|
|
CRect rectView ;
|
|
GetDlgItem( IDC_SCENE)->GetWindowRect( rectView) ;
|
|
ScreenToClient( &rectView) ;
|
|
m_nLeftBarW = rectView.left - rectClient.left ;
|
|
m_nRightBarW = rectClient.right - rectView.right ;
|
|
m_nBottomBarH = rectClient.bottom - rectView.bottom ;
|
|
|
|
// creo il DB geometrico
|
|
m_pGeomDB = CreateGeomDB() ;
|
|
if ( m_pGeomDB == nullptr)
|
|
LOG_ERROR( m_pLogGen, "Error in CreateGeomDB")
|
|
|
|
// inizializzo il DB geometrico
|
|
PrepareGeomDB() ;
|
|
|
|
// creo la vista per la scena
|
|
if ( ! m_View.Create( this, IDC_SCENE))
|
|
LOG_ERROR( m_pLogGen, "Error in CreateSceneView")
|
|
|
|
// recupero i parametri della scena
|
|
int nDriver = GetPrivateProfileInt( "OpenGL", "Driver", 2, AfxGetApp()->m_pszProfileName) ;
|
|
bool b2Buff = ( GetPrivateProfileInt( "OpenGL", "DoubleBuffer", 1, AfxGetApp()->m_pszProfileName) == 1) ;
|
|
int nColorBits = GetPrivateProfileInt( "OpenGL", "ColorBits", 16, AfxGetApp()->m_pszProfileName) ;
|
|
int nDepthBits = GetPrivateProfileInt( "OpenGL", "DepthBits", 16, AfxGetApp()->m_pszProfileName) ;
|
|
|
|
// creazione della scena
|
|
if ( ! m_View.StartScene( nDriver, b2Buff, nColorBits, nDepthBits))
|
|
LOG_ERROR( m_pLogGen, "Error in StartScene")
|
|
|
|
// recupero i colori dello sfondo e li imposto
|
|
if ( m_View.GetScene() != nullptr) {
|
|
Color ColorTop( 186, 203, 226) ;
|
|
GetIniColor( "Scene", "BackTop", ColorTop) ;
|
|
Color ColorBottom( 102, 102, 102) ;
|
|
GetIniColor( "Scene", "BackBottom", ColorBottom) ;
|
|
m_View.GetScene()->SetBackground( ColorTop, ColorBottom) ;
|
|
}
|
|
|
|
// recupero il tipo di visualizzazione e lo imposto
|
|
if ( m_View.GetScene() != nullptr) {
|
|
int nShMode = GetPrivateProfileInt( "Scene", "ShowMode", 0, AfxGetApp()->m_pszProfileName) ;
|
|
m_View.GetScene()->SetShowMode( nShMode) ;
|
|
UpdateShowModeButtons() ;
|
|
}
|
|
|
|
// recupero gli angoli di vista e li imposto
|
|
if ( m_View.GetScene() != nullptr) {
|
|
double dAngVdeg = 0, dAngOdeg = 0 ;
|
|
GetViewAngles( "Scene", "View", dAngVdeg, dAngOdeg) ;
|
|
m_View.GetScene()->SetCamera( dAngVdeg, dAngOdeg, 0) ;
|
|
UpdateViewButtons() ;
|
|
}
|
|
|
|
// recupero gli attributi del rettangolo per ZoomWin e li imposto
|
|
if ( m_View.GetScene() != nullptr) {
|
|
bool bOutline = true ;
|
|
Color colRect( 0, 0, 0) ;
|
|
GetIniZoomWinAttrib( "Scene", "ZoomWin", bOutline, colRect) ;
|
|
m_View.GetScene()->SetWinRectAttribs( bOutline, colRect) ;
|
|
}
|
|
|
|
// recupero il colore di marcatura e lo imposto
|
|
if ( m_View.GetScene() != nullptr) {
|
|
Color colMark( 192, 192, 0) ;
|
|
GetIniColor( "Scene", "Mark", colMark) ;
|
|
m_View.GetScene()->SetMark( colMark) ;
|
|
}
|
|
|
|
// imposto il DB geometrico
|
|
if ( m_View.GetScene() != nullptr)
|
|
m_View.GetScene()->Init( m_pGeomDB) ;
|
|
|
|
// log con info sulla scena
|
|
string sSceneInfo ;
|
|
m_View.GetSceneInfo( sSceneInfo) ;
|
|
LOG_INFO( m_pLogGen, sSceneInfo.c_str())
|
|
|
|
// recupero il posizionamento della finestra del dialogo
|
|
WINDOWPLACEMENT winPlace ;
|
|
if ( GetIniWinPlace( "General", "WinPlace", winPlace))
|
|
SetWindowPlacement( &winPlace) ;
|
|
|
|
// preparo l'esecutore
|
|
PrepareExecutor() ;
|
|
|
|
// collego l'oggetto al control
|
|
m_Cmd.SubclassDlgItem( IDC_COMMAND, this) ;
|
|
|
|
// preparo il Tree
|
|
PrepareTree() ;
|
|
|
|
// eventuale apertura o esecuzione di file all'avvio
|
|
if ( ! m_sFileToOpen.empty()) {
|
|
// ricavo l'estensione
|
|
string sDummy ;
|
|
string sEst ;
|
|
SplitLast( m_sFileToOpen, ".", sDummy, sEst) ;
|
|
ToUpper( sEst) ;
|
|
// apro il file
|
|
if ( sEst == "NGE") {
|
|
if ( ! FileOpen( m_sFileToOpen))
|
|
AfxMessageBox( L"Error loading file (look at Log file)", MB_ICONSTOP|MB_OK) ;
|
|
}
|
|
// eseguo lo script
|
|
else if ( sEst == "TSC") {
|
|
if ( ! FileExec( m_sFileToOpen))
|
|
AfxMessageBox( L"Error executing file (look at Log file)", MB_ICONSTOP|MB_OK) ;
|
|
}
|
|
// errore
|
|
else
|
|
AfxMessageBox( L"File extension not recognized", MB_ICONSTOP|MB_OK) ;
|
|
}
|
|
|
|
return TRUE ; // return TRUE unless you set the focus to a control
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::GetViewAngles( const char* szSection, const char* szKey, double& dAngVdeg, double& dAngOdeg)
|
|
{
|
|
string sTmp = GetPrivateProfileStringUtf8( szSection, szKey, "", AfxGetApp()->m_pszProfileName) ;
|
|
if ( ! sTmp.empty()) {
|
|
STRVECTOR vsParams ;
|
|
Tokenize( sTmp, ",", vsParams) ;
|
|
if ( vsParams.size() >= 2) {
|
|
FromString( vsParams[0], dAngVdeg) ;
|
|
FromString( vsParams[1], dAngOdeg) ;
|
|
return true ;
|
|
}
|
|
}
|
|
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::GetIniColor( const char* szSection, const char* szKey, Color& cCol)
|
|
{
|
|
string sTmp = GetPrivateProfileStringUtf8( szSection, szKey, "", AfxGetApp()->m_pszProfileName) ;
|
|
if ( ! sTmp.empty()) {
|
|
STRVECTOR vsParams ;
|
|
Tokenize( sTmp, ",", vsParams) ;
|
|
if ( vsParams.size() >= 3) {
|
|
int nRed ;
|
|
FromString( vsParams[0], nRed) ;
|
|
int nGreen ;
|
|
FromString( vsParams[1], nGreen) ;
|
|
int nBlue ;
|
|
FromString( vsParams[2], nBlue) ;
|
|
cCol.Set( nRed, nGreen, nBlue) ;
|
|
return true ;
|
|
}
|
|
}
|
|
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::GetIniZoomWinAttrib( const char* szSection, const char* szKey,
|
|
bool& bOutline, Color& colRect)
|
|
{
|
|
string sTmp = GetPrivateProfileStringUtf8( szSection, szKey, "", AfxGetApp()->m_pszProfileName) ;
|
|
if ( ! sTmp.empty()) {
|
|
STRVECTOR vsParams ;
|
|
Tokenize( sTmp, ",", vsParams) ;
|
|
if ( vsParams.size() >= 5) {
|
|
FromString( vsParams[0], bOutline) ;
|
|
int nRed ;
|
|
FromString( vsParams[1], nRed) ;
|
|
int nGreen ;
|
|
FromString( vsParams[2], nGreen) ;
|
|
int nBlue ;
|
|
FromString( vsParams[3], nBlue) ;
|
|
int nAlpha ;
|
|
FromString( vsParams[4], nAlpha) ;
|
|
colRect.Set( nRed, nGreen, nBlue, nAlpha) ;
|
|
return true ;
|
|
}
|
|
}
|
|
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::GetIniWinPlace( const char* szSection, const char* szKey, WINDOWPLACEMENT& winPlace)
|
|
{
|
|
string sTmp = GetPrivateProfileStringUtf8( szSection, szKey, "", AfxGetApp()->m_pszProfileName) ;
|
|
if ( ! sTmp.empty()) {
|
|
STRVECTOR vsParams ;
|
|
Tokenize( sTmp, ",", vsParams) ;
|
|
if ( vsParams.size() >= 5) {
|
|
int nVal ;
|
|
winPlace.length = sizeof( WINDOWPLACEMENT) ;
|
|
winPlace.flags = 0 ;
|
|
FromString( vsParams[0], nVal) ;
|
|
winPlace.showCmd = (( nVal != 1) ? SW_SHOW : SW_SHOWMAXIMIZED) ;
|
|
FromString( vsParams[1], nVal) ;
|
|
winPlace.rcNormalPosition.left = nVal ;
|
|
FromString( vsParams[2], nVal) ;
|
|
winPlace.rcNormalPosition.top = nVal ;
|
|
FromString( vsParams[3], nVal) ;
|
|
winPlace.rcNormalPosition.right = nVal ;
|
|
FromString( vsParams[4], nVal) ;
|
|
winPlace.rcNormalPosition.bottom = nVal ;
|
|
return true ;
|
|
}
|
|
}
|
|
|
|
return false ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnSysCommand( UINT nID, LPARAM lParam)
|
|
{
|
|
if ( (nID & 0xFFF0) == IDM_ABOUTBOX) {
|
|
CAboutDlg dlgAbout ;
|
|
dlgAbout.DoModal() ;
|
|
}
|
|
else {
|
|
CDialog::OnSysCommand( nID, lParam) ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnPaint( void)
|
|
{
|
|
if ( IsIconic()) {
|
|
CPaintDC dc( this) ; // device context for painting
|
|
|
|
SendMessage( WM_ICONERASEBKGND, reinterpret_cast<WPARAM>( dc.GetSafeHdc()), 0) ;
|
|
|
|
// Center icon in client rectangle
|
|
int cxIcon = GetSystemMetrics( SM_CXICON) ;
|
|
int cyIcon = GetSystemMetrics( SM_CYICON) ;
|
|
CRect rect ;
|
|
GetClientRect( &rect) ;
|
|
int x = ( rect.Width() - cxIcon + 1) / 2 ;
|
|
int y = ( rect.Height() - cyIcon + 1) / 2 ;
|
|
|
|
// Draw the icon
|
|
dc.DrawIcon( x, y, m_hIcon) ;
|
|
}
|
|
else {
|
|
// ridisegno dialogo
|
|
CDialog::OnPaint() ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
HCURSOR
|
|
CTestEGrDlg::OnQueryDragIcon( void)
|
|
{
|
|
return static_cast<HCURSOR>( m_hIcon) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnSize( UINT nType, int cx, int cy)
|
|
{
|
|
CDialog::OnSize( nType, cx, cy) ;
|
|
|
|
// se ridotta a icona non si fa alcunché
|
|
if ( cx <= 0 || cy <= 0 || nType == SIZE_MINIMIZED)
|
|
return ;
|
|
|
|
// se cambiata dimensione
|
|
if ( nType == SIZE_RESTORED || nType == SIZE_MAXIMIZED) {
|
|
// spostamento bottoni
|
|
MoveDlgItem( IDC_NEW, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_OPEN, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_SAVE, 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) ;
|
|
MoveDlgItem( IDC_WIREFRAME, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_HIDDENLINE, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_SHADING, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_ZOOM_ALL, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_ZOOM_IN, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_ZOOM_OUT, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_VIEW_TOP, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_VIEW_FRONT, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_VIEW_BACK, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_VIEW_LEFT, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_VIEW_RIGHT, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_VIEW_ISO, IP_TR, cx, cy) ;
|
|
MoveDlgItem( IDC_COMMAND, IP_BR, cx, cy) ;
|
|
MoveDlgItem( IDC_CLOSE, IP_BR, cx, cy) ;
|
|
// spostamento e adattamento tree e associati
|
|
MoveDlgItem( IDC_TREE, IP_TL, cx, cy) ;
|
|
MoveDlgItem( IDC_DATA, IP_TL, cx, cy) ;
|
|
CRect rectData ;
|
|
if ( GetWindowRect( GetDlgItem( IDC_DATA), rectData))
|
|
ReshapeDlgItem( IDC_DATA, IR_H, 0, cy - rectData.top - m_nBottomBarH) ;
|
|
// spostamento e adattamento barre sotto
|
|
MoveDlgItem( IDC_INFO, IP_BL, cx, cy) ;
|
|
ReshapeDlgItem( IDC_INFO, IR_W, cx - m_nLeftBarW - m_nRightBarW, 0) ;
|
|
MoveDlgItem( IDC_COORD, IP_BR, cx, cy) ;
|
|
// adattamento vista della scena
|
|
CRect rectView ;
|
|
if ( GetWindowRect( &m_View, rectView))
|
|
m_View.Reshape( m_nLeftBarW, rectView.top,
|
|
cx - m_nLeftBarW - m_nRightBarW, cy - m_nBottomBarH - rectView.top) ;
|
|
// salvo la nuova dimensione
|
|
m_nPrevCx = cx ;
|
|
m_nPrevCy = cy ;
|
|
// lancio ridisegno
|
|
RedrawWindow( NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW) ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::MoveDlgItem( int nID, int nPos, int cx, int cy)
|
|
{
|
|
CWnd* pBtn ;
|
|
if ( ( pBtn = GetDlgItem( nID)) == nullptr)
|
|
return false ;
|
|
|
|
CRect rect ;
|
|
pBtn->GetWindowRect( rect) ;
|
|
ScreenToClient( &rect) ;
|
|
|
|
int nX ;
|
|
int nY ;
|
|
switch ( nPos) {
|
|
case IP_TR :
|
|
nX = rect.left + cx - m_nPrevCx ;
|
|
nY = rect.top ;
|
|
break ;
|
|
default : // IP_TL
|
|
nX = rect.left ;
|
|
nY = rect.top ;
|
|
break ;
|
|
case IP_BR :
|
|
nX = rect.left + cx - m_nPrevCx ;
|
|
nY = rect.top + cy - m_nPrevCy ;
|
|
break ;
|
|
case IP_BL :
|
|
nX = rect.left ;
|
|
nY = rect.top + cy - m_nPrevCy ;
|
|
break ;
|
|
}
|
|
|
|
return ( pBtn->SetWindowPos( NULL, nX, nY, 0, 0, SWP_NOSIZE | SWP_NOZORDER) != 0) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::ReshapeDlgItem( int nID, int nFlag, int nW, int nH)
|
|
{
|
|
CWnd* pBtn ;
|
|
if ( ( pBtn = GetDlgItem( nID)) == nullptr)
|
|
return false ;
|
|
|
|
CRect rect ;
|
|
pBtn->GetWindowRect( rect) ;
|
|
ScreenToClient( &rect) ;
|
|
|
|
int nWu ;
|
|
int nHu ;
|
|
switch ( nFlag) {
|
|
case IR_W :
|
|
nWu = nW ;
|
|
nHu = rect.Height() ;
|
|
break ;
|
|
case IR_H :
|
|
nWu = rect.Width() ;
|
|
nHu = nH ;
|
|
break ;
|
|
default : // IR_WH
|
|
nWu = nW ;
|
|
nHu = nH ;
|
|
break ;
|
|
}
|
|
|
|
return ( pBtn->SetWindowPos( NULL, 0, 0, nWu, nHu, SWP_NOMOVE | SWP_NOZORDER) != 0) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::GetWindowRect( CWnd* pWnd, CRect& rect)
|
|
{
|
|
if ( pWnd == nullptr || ! ::IsWindow( pWnd->m_hWnd))
|
|
return false ;
|
|
|
|
pWnd->GetWindowRect( rect) ;
|
|
ScreenToClient( &rect) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OutInfo( const string& sOut, bool bLog)
|
|
{
|
|
CWnd* pWnd = GetDlgItem( IDC_INFO) ;
|
|
if ( pWnd != nullptr)
|
|
pWnd->SetWindowText( stringtoW( sOut)) ;
|
|
|
|
if ( bLog)
|
|
LOG_INFO( m_pLogGen, sOut.c_str())
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OutData( const string& sOut, bool bLog)
|
|
{
|
|
CWnd* pWnd = GetDlgItem( IDC_DATA) ;
|
|
if ( pWnd != nullptr)
|
|
pWnd->SetWindowText( stringtoW( sOut)) ;
|
|
|
|
if ( bLog)
|
|
LOG_INFO( m_pLogGen, sOut.c_str())
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnClose( void)
|
|
{
|
|
// gestisco eventuale file corrente modificato
|
|
if ( ! ManageModified())
|
|
return ;
|
|
|
|
// salvo il tipo di visualizzazione
|
|
int nShMode = m_View.GetScene()->GetShowMode() ;
|
|
WritePrivateProfileInt( "Scene", "ShowMode", nShMode, AfxGetApp()->m_pszProfileName) ;
|
|
|
|
// salvo gli angoli di vista
|
|
double dAngVdeg, dAngOdeg ;
|
|
m_View.GetScene()->GetCamera( &dAngVdeg, &dAngOdeg) ;
|
|
string sOut = ToString( dAngVdeg, 1) + "," + ToString( dAngOdeg, 1) ;
|
|
WritePrivateProfileStringUtf8( "Scene", "View", sOut.c_str(), AfxGetApp()->m_pszProfileName) ;
|
|
|
|
// salvo lo stato della finestra del dialogo
|
|
WINDOWPLACEMENT winPlace ;
|
|
if ( GetWindowPlacement( &winPlace)) {
|
|
string sOut ;
|
|
sOut = ToString( ( winPlace.showCmd == SW_SHOWMAXIMIZED ? 1 : 0)) + "," +
|
|
ToString( winPlace.rcNormalPosition.left) + "," +
|
|
ToString( winPlace.rcNormalPosition.top) + "," +
|
|
ToString( winPlace.rcNormalPosition.right) + "," +
|
|
ToString( winPlace.rcNormalPosition.bottom) ;
|
|
WritePrivateProfileStringUtf8( "General", "WinPlace", sOut.c_str(), AfxGetApp()->m_pszProfileName) ;
|
|
}
|
|
|
|
m_View.Destroy() ;
|
|
|
|
EndDialog( IDCLOSE) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnFileNew( void)
|
|
{
|
|
// gestisco eventuale file corrente modificato
|
|
if ( ! ManageModified())
|
|
return ;
|
|
// reinizializzo il progetto
|
|
if ( ! FileNew())
|
|
AfxMessageBox( L"Error on file new (look at Log file)", MB_ICONSTOP|MB_OK) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnFileOpen( void)
|
|
{
|
|
// gestisco eventuale file corrente modificato
|
|
if ( ! ManageModified())
|
|
return ;
|
|
|
|
// visualizzo il dialogo di scelta file
|
|
CFileDialog dlg( TRUE, L"*.Nge", NULL,
|
|
OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_NOCHANGEDIR,
|
|
L"New geometry EgalTech (*.Nge) |*.Nge||", NULL, 0, FALSE) ;
|
|
|
|
// imposto il direttorio iniziale
|
|
wstring wsDir = stringtoW( GetPrivateProfileStringUtf8( "General", "LastNgeDir", "", 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 ;
|
|
|
|
// divido in nome e direttorio e salvo quest'ultimo
|
|
string sFileDir ;
|
|
string sFileName ;
|
|
SplitLast( sFilePath, "\\", sFileDir, sFileName) ;
|
|
if ( ! sFileDir.empty())
|
|
WritePrivateProfileStringUtf8( "General", "LastNgeDir", sFileDir.c_str(), AfxGetApp()->m_pszProfileName) ;
|
|
|
|
// carico il file
|
|
if ( ! FileOpen( sFilePath))
|
|
AfxMessageBox( L"Error loading file (look at Log file)", MB_ICONSTOP|MB_OK) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnFileSave( void)
|
|
{
|
|
// visualizzo il dialogo di scelta file
|
|
CFileDialog dlg( FALSE, L"*.Nge", stringtoW( m_sFileName),
|
|
OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR,
|
|
L"New geometry EgalTech (*.Nge) |*.Nge||", NULL, 0, FALSE) ;
|
|
|
|
// imposto il direttorio iniziale
|
|
wstring wsDir = stringtoW( GetPrivateProfileStringUtf8( "General", "LastNgeDir", "", 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 ;
|
|
|
|
// divido in nome e direttorio e salvo quest'ultimo
|
|
string sFileDir ;
|
|
string sFileName ;
|
|
SplitLast( sFilePath, "\\", sFileDir, sFileName) ;
|
|
if ( ! sFileDir.empty())
|
|
WritePrivateProfileStringUtf8( "General", "LastNgeDir", sFileDir.c_str(), AfxGetApp()->m_pszProfileName) ;
|
|
|
|
// salvo il file
|
|
if ( ! FileSave( sFilePath))
|
|
AfxMessageBox( L"Error saving file (look at Log file)", MB_ICONSTOP|MB_OK) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnFileImport( void)
|
|
{
|
|
// gestisco eventuale file corrente modificato
|
|
if ( ! ManageModified())
|
|
return ;
|
|
|
|
// visualizzo il dialogo di scelta file
|
|
CFileDialog dlg( TRUE, L"*.*", NULL,
|
|
OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|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", "LastImpDir", "", 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 ;
|
|
|
|
// divido in nome e direttorio e salvo quest'ultimo
|
|
string sFileDir ;
|
|
string sFileName ;
|
|
SplitLast( sFilePath, "\\", sFileDir, sFileName) ;
|
|
if ( ! sFileDir.empty())
|
|
WritePrivateProfileStringUtf8( "General", "LastImpDir", sFileDir.c_str(), AfxGetApp()->m_pszProfileName) ;
|
|
|
|
// carico il file
|
|
if ( ! FileImport( sFilePath))
|
|
AfxMessageBox( L"Error importing file (look at Log file)", MB_ICONSTOP|MB_OK) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnFileExec( void)
|
|
{
|
|
// visualizzo il dialogo di scelta file
|
|
CFileDialog dlg( TRUE, L"*.Tsc", NULL,
|
|
OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY|OFN_NOCHANGEDIR,
|
|
L"Test script EgalTech (*.Tsc) |*.Tsc||", NULL, 0, FALSE) ;
|
|
|
|
// imposto il direttorio iniziale
|
|
wstring wsDir = stringtoW( GetPrivateProfileStringUtf8( "General", "LastTscDir", "", 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 e ne salvo il direttorio
|
|
string sFilePath = WtoA( dlg.GetPathName()) ;
|
|
if ( sFilePath.empty())
|
|
return ;
|
|
string sFileDir ;
|
|
string sFileName ;
|
|
SplitLast( sFilePath, "\\", sFileDir, sFileName) ;
|
|
if ( ! sFileDir.empty())
|
|
WritePrivateProfileStringUtf8( "General", "LastTscDir", sFileDir.c_str(), AfxGetApp()->m_pszProfileName) ;
|
|
|
|
// eseguo lo script
|
|
if ( ! FileExec( sFilePath))
|
|
AfxMessageBox( L"Error executing file (look at Log file)", MB_ICONSTOP|MB_OK) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnShowMode( UINT nID)
|
|
{
|
|
m_View.ShowMode( nID) ;
|
|
UpdateShowModeButtons() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::UpdateShowModeButtons( void)
|
|
{
|
|
int nSM = m_View.GetScene()->GetShowMode() ;
|
|
(( CButton*) GetDlgItem( IDC_WIREFRAME))->SetCheck( ( nSM == SM_WIREFRAME ? BST_CHECKED : BST_UNCHECKED)) ;
|
|
(( CButton*) GetDlgItem( IDC_HIDDENLINE))->SetCheck( ( nSM == SM_HIDDENLINE ? BST_CHECKED : BST_UNCHECKED)) ;
|
|
(( CButton*) GetDlgItem( IDC_SHADING))->SetCheck( ( nSM == SM_SHADING ? BST_CHECKED : BST_UNCHECKED)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnZoom( UINT nID)
|
|
{
|
|
m_View.Zoom( nID) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::OnView( UINT nID)
|
|
{
|
|
m_View.View( nID) ;
|
|
UpdateViewButtons() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::UpdateViewButtons( void)
|
|
{
|
|
int nVw = m_View.GetScene()->GetCameraDir() ;
|
|
(( CButton*) GetDlgItem( IDC_VIEW_TOP))->SetCheck( ( nVw == CT_TOP ? BST_CHECKED : BST_UNCHECKED)) ;
|
|
(( CButton*) GetDlgItem( IDC_VIEW_FRONT))->SetCheck( ( nVw == CT_FRONT ? BST_CHECKED : BST_UNCHECKED)) ;
|
|
(( CButton*) GetDlgItem( IDC_VIEW_BACK))->SetCheck( ( nVw == CT_BACK ? BST_CHECKED : BST_UNCHECKED)) ;
|
|
(( CButton*) GetDlgItem( IDC_VIEW_LEFT))->SetCheck( ( nVw == CT_LEFT ? BST_CHECKED : BST_UNCHECKED)) ;
|
|
(( CButton*) GetDlgItem( IDC_VIEW_RIGHT))->SetCheck( ( nVw == CT_RIGHT ? BST_CHECKED : BST_UNCHECKED)) ;
|
|
(( CButton*) GetDlgItem( IDC_VIEW_ISO))->SetCheck( ( nVw == CT_ISO_SW ? BST_CHECKED : BST_UNCHECKED)) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
BOOL
|
|
CTestEGrDlg::PreTranslateMessage( MSG* pMsg)
|
|
{
|
|
// se messaggio rotella mouse e non settata cattura
|
|
if ( pMsg->message == WM_MOUSEWHEEL && GetCapture() == nullptr) {
|
|
// invio il messaggio alla finestra del dialogo su cui si trova il mouse
|
|
CPoint ptClient = pMsg->pt ;
|
|
ScreenToClient( &ptClient) ;
|
|
pMsg->hwnd = ::ChildWindowFromPoint( m_hWnd, ptClient) ;
|
|
if ( pMsg->hwnd == nullptr)
|
|
return 1 ;
|
|
}
|
|
// passo al gestore di default
|
|
return CDialog::PreTranslateMessage( pMsg) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::PrepareGeomDB( void)
|
|
{
|
|
if ( m_pGeomDB == nullptr)
|
|
return false ;
|
|
// pulisco e reinizializzo
|
|
m_pGeomDB->Init() ;
|
|
// imposto il materiale di default tramite colore
|
|
Color colDef( 0, 0, 0) ;
|
|
GetIniColor( "GeomDB", "DefaultColor", colDef) ;
|
|
m_pGeomDB->SetDefaultMaterial( colDef) ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::PrepareExecutor( void)
|
|
{
|
|
// verifico validità DB geometrico
|
|
if ( m_pGeomDB == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "GeomDB invalid")
|
|
return false ;
|
|
}
|
|
|
|
// eventuale distruzione oggetti per esecuzione
|
|
if ( m_pGdbExec != nullptr)
|
|
delete m_pGdbExec ;
|
|
m_pGdbExec = nullptr ;
|
|
if ( m_pExcExec != nullptr)
|
|
delete m_pExcExec ;
|
|
m_pExcExec = nullptr ;
|
|
if ( m_pSceExec != nullptr)
|
|
delete m_pSceExec ;
|
|
m_pSceExec = nullptr ;
|
|
if ( m_pCmdParser == nullptr)
|
|
delete m_pCmdParser ;
|
|
m_pCmdParser = nullptr ;
|
|
|
|
// creo oggetti per esecuzione e ne verifico la validità
|
|
m_pGdbExec = CreateGdbExecutor() ;
|
|
if ( m_pGdbExec == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "Error in CreateGdbExecutor")
|
|
return false ;
|
|
}
|
|
m_pExcExec = CreateExcExecutor() ;
|
|
if ( m_pExcExec == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "Error in CreateExcExecutor")
|
|
return false ;
|
|
}
|
|
|
|
m_pSceExec = CreateSceExecutor() ;
|
|
if ( m_pSceExec == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "Error in CreateSceExecutor")
|
|
return false ;
|
|
}
|
|
m_pCmdParser = CreateCmdParser() ;
|
|
if ( m_pCmdParser == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "Error in CreateCmdParser")
|
|
return false ;
|
|
}
|
|
|
|
// inizializzazioni
|
|
m_pGdbExec->SetGeomDB( m_pGeomDB) ;
|
|
m_pExcExec->SetGeomDB( m_pGeomDB) ;
|
|
m_pSceExec->SetScene( m_View.GetScene()) ;
|
|
m_pCmdParser->SetExecutor( m_pGdbExec) ;
|
|
m_pCmdParser->AddExecutor( m_pExcExec) ;
|
|
m_pCmdParser->AddExecutor( m_pSceExec) ;
|
|
m_pCmdParser->Init() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::ManageModified( void)
|
|
{
|
|
// se non modificato, procedo normalmente
|
|
if ( ! m_bModified)
|
|
return true ;
|
|
|
|
// chiedo cosa fare
|
|
string sMsg ;
|
|
sMsg = "Salvare le modifiche" ;
|
|
if ( ! m_sFileName.empty())
|
|
sMsg += " a " + m_sFileName ;
|
|
sMsg += " ?" ;
|
|
switch ( AfxMessageBox( stringtoW( sMsg), MB_YESNOCANCEL)) {
|
|
case IDYES :
|
|
OnFileSave() ;
|
|
return ( ! m_bModified) ;
|
|
break ;
|
|
case IDNO :
|
|
return true ;
|
|
break ;
|
|
default :
|
|
return false ;
|
|
break ;
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::FileNew( void)
|
|
{
|
|
// verifico validità DB geometrico
|
|
if ( m_pGeomDB == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "GeomDB invalid")
|
|
return false ;
|
|
}
|
|
|
|
// pulisco l'albero delle entità
|
|
ClearTree() ;
|
|
// reinizializzazione (con pulizia) del DB geometrico
|
|
PrepareGeomDB() ;
|
|
// visualizzo con zoom all
|
|
m_View.Zoom( IDC_ZOOM_ALL) ;
|
|
// inserisco il nome del file nel titolo della finestra
|
|
m_sFileName.clear() ;
|
|
m_bModified = false ;
|
|
EmitTitle() ;
|
|
// log dei comandi
|
|
LOG_INFO( m_pLogCmd, "NEW")
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::FileOpen( const string& sFilePath)
|
|
{
|
|
// verifico validità DB geometrico
|
|
if ( m_pGeomDB == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "GeomDB invalid")
|
|
return false ;
|
|
}
|
|
|
|
// divido in nome e direttorio
|
|
string sFileDir ;
|
|
string sFileName ;
|
|
SplitLast( sFilePath, "\\", sFileDir, sFileName) ;
|
|
|
|
// inserisco il nome del file nel titolo della finestra
|
|
m_sFileName = sFileName ;
|
|
m_bModified = false ;
|
|
EmitTitle() ;
|
|
// emetto info
|
|
string sInfo = "Open File = " + sFilePath ;
|
|
LOG_INFO( m_pLogGen, sInfo.c_str())
|
|
|
|
// pulisco l'albero delle entità
|
|
ClearTree() ;
|
|
// reinizializzazione (con pulizia) del DB geometrico
|
|
PrepareGeomDB() ;
|
|
// carico il file
|
|
if ( ! m_pGeomDB->Load( sFilePath))
|
|
return false ;
|
|
// log dei comandi
|
|
LOG_INFO( m_pLogCmd, ( "LOAD( " + sFilePath + ")").c_str())
|
|
// visualizzo con zoom all
|
|
PerformanceCounter Counter ;
|
|
Counter.Start() ;
|
|
m_View.Zoom( IDC_ZOOM_ALL) ;
|
|
Counter.Stop() ;
|
|
string sOut = "First ZoomAll time = " + ToString( Counter.GetTime(), 2) + " ms" ;
|
|
// emetto info
|
|
::OutInfo( sOut) ;
|
|
// aggiorno l'albero delle entità
|
|
LoadTree() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::FileSave( const string& sFilePath)
|
|
{
|
|
// verifico validità DB geometrico
|
|
if ( m_pGeomDB == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "GeomDB invalid")
|
|
return false ;
|
|
}
|
|
|
|
// divido in nome e direttorio
|
|
string sFileDir ;
|
|
string sFileName ;
|
|
SplitLast( sFilePath, "\\", sFileDir, sFileName) ;
|
|
|
|
// inserisco il nome del file nel titolo della finestra
|
|
m_sFileName = sFileName ;
|
|
m_bModified = false ;
|
|
EmitTitle() ;
|
|
// emetto info
|
|
string sInfo = "Save File = " + sFilePath ;
|
|
LOG_INFO( m_pLogGen, sInfo.c_str())
|
|
|
|
// recupero flag per salvatggio binario
|
|
bool bBin = ( GetPrivateProfileInt( "GeomDB", "BinarySave", 0, AfxGetApp()->m_pszProfileName) == 1) ;
|
|
|
|
// salvo il file
|
|
if ( ! m_pGeomDB->Save( sFilePath, bBin))
|
|
return false ;
|
|
// log dei comandi
|
|
LOG_INFO( m_pLogCmd, ( "SAVE( " + sFilePath + ")").c_str())
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::FileImport( const string& sFilePath)
|
|
{
|
|
// verifico validità DB geometrico
|
|
if ( m_pGeomDB == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "GeomDB invalid")
|
|
return false ;
|
|
}
|
|
|
|
// 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 ;
|
|
}
|
|
|
|
// inserisco il nome del file nel titolo della finestra
|
|
m_sFileName = sFileTitle + ".Nge" ;
|
|
m_bModified = true ;
|
|
EmitTitle() ;
|
|
// emetto info
|
|
string sInfo = "Import File = " + sFilePath ;
|
|
LOG_INFO( m_pLogGen, sInfo.c_str())
|
|
|
|
// pulisco l'albero delle entità
|
|
ClearTree() ;
|
|
// reinizializzazione (con pulizia) del DB geometrico
|
|
PrepareGeomDB() ;
|
|
// importo il file DXF
|
|
if ( sFileExt == "DXF") {
|
|
// aggiungo un gruppo pezzo
|
|
int nPartId = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ;
|
|
// preparo l'importatore
|
|
PtrOwner<IImportDxf> pImpDxf( CreateImportDxf()) ;
|
|
if ( ! IsValid( pImpDxf)) {
|
|
LOG_ERROR( m_pLogGen, "Error : CreateImportDxf")
|
|
return false ;
|
|
}
|
|
// eseguo l'importazione
|
|
if ( ! pImpDxf->Import( sFilePath, m_pGeomDB, nPartId))
|
|
return false ;
|
|
// log dei comandi
|
|
LOG_INFO( m_pLogCmd, "RESET( $P1)")
|
|
LOG_INFO( m_pLogCmd, "GR.XY( $P1, $ROOT, ORIG)")
|
|
LOG_INFO( m_pLogCmd, ( "IMPORTDXF( " + sFilePath + ", $P1)").c_str())
|
|
}
|
|
// importo il file STL
|
|
else if ( sFileExt == "STL") {
|
|
// aggiungo un gruppo pezzo e un gruppo layer
|
|
int nPartId = m_pGeomDB->AddGroup( GDB_ID_NULL, GDB_ID_ROOT, Frame3d()) ;
|
|
int nLayerId = m_pGeomDB->AddGroup( GDB_ID_NULL, nPartId, Frame3d()) ;
|
|
// preparo l'importatore
|
|
PtrOwner<IImportStl> pImpStl( CreateImportStl()) ;
|
|
if ( ! IsValid( pImpStl)) {
|
|
LOG_ERROR( m_pLogGen, "Error : CreateImportStl")
|
|
return false ;
|
|
}
|
|
// eseguo l'importazione
|
|
if ( ! pImpStl->Import( sFilePath, m_pGeomDB, nLayerId))
|
|
return false ;
|
|
// log dei comandi
|
|
LOG_INFO( m_pLogCmd, "RESET( ($P1, $L1))")
|
|
LOG_INFO( m_pLogCmd, "GR.XY( $P1, $ROOT, ORIG)")
|
|
LOG_INFO( m_pLogCmd, "GR.XY( $L1, $P1, ORIG)")
|
|
LOG_INFO( m_pLogCmd, ( "IMPORTSTL( " + sFilePath + ", $L1)").c_str())
|
|
}
|
|
|
|
// visualizzo con zoom all
|
|
PerformanceCounter Counter ;
|
|
Counter.Start() ;
|
|
m_View.Zoom( IDC_ZOOM_ALL) ;
|
|
Counter.Stop() ;
|
|
string sOut = "First ZoomAll time = " + ToString( Counter.GetTime(), 2) + " ms" ;
|
|
// emetto info
|
|
::OutInfo( sOut) ;
|
|
// aggiorno l'albero delle entità
|
|
LoadTree() ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::FileExec( const string& sFilePath)
|
|
{
|
|
// verifico validità esecutore
|
|
if ( m_pCmdParser == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "CmdParser invalid")
|
|
return false ;
|
|
}
|
|
|
|
// divido in nome e direttorio
|
|
string sFileDir ;
|
|
string sFileName ;
|
|
SplitLast( sFilePath, "\\", sFileDir, sFileName) ;
|
|
|
|
// inserisco il nome del file nel titolo della finestra
|
|
m_sFileName = sFileName ;
|
|
m_bModified = true ;
|
|
EmitTitle() ;
|
|
// emetto info
|
|
string sInfo = "Exec File = " + sFilePath ;
|
|
LOG_INFO( m_pLogGen, sInfo.c_str())
|
|
|
|
// pulisco l'albero delle entità
|
|
ClearTree() ;
|
|
|
|
// esecuzione script
|
|
bool bOk = m_pCmdParser->Run( sFilePath) ;
|
|
|
|
// log dei comandi
|
|
LOG_INFO( m_pLogCmd, ( "RUN( " + sFilePath + ")").c_str())
|
|
|
|
// aggiorno visualizzazione
|
|
m_View.Redraw() ;
|
|
// aggiorno l'albero delle entità
|
|
LoadTree() ;
|
|
|
|
// aggiorno stato bottoni
|
|
UpdateShowModeButtons() ;
|
|
UpdateViewButtons() ;
|
|
|
|
return bOk ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
CTestEGrDlg::LineExec( const string& sLine)
|
|
{
|
|
// verifico validità esecutore
|
|
if ( m_pCmdParser == nullptr) {
|
|
LOG_ERROR( m_pLogGen, "CmdParser invalid")
|
|
return false ;
|
|
}
|
|
|
|
// ripristino stato oggetto marcato
|
|
int nIdOld = RevertOldIdInTree() ;
|
|
|
|
// eseguo il comando
|
|
bool bOk = m_pCmdParser->ExecLine( sLine) ;
|
|
|
|
// log dei comandi
|
|
if ( bOk)
|
|
LOG_INFO( m_pLogCmd, sLine.c_str())
|
|
else
|
|
LOG_INFO( m_pLogCmd, ( "// " + sLine).c_str())
|
|
|
|
// dichiaro file modificato
|
|
m_bModified = true ;
|
|
EmitTitle() ;
|
|
|
|
// aggiorno l'albero delle entità e tento di riselezionare l'oggetto prima marcato
|
|
LoadTree() ;
|
|
if ( ! m_pGeomDB->ExistsObj( nIdOld) ||
|
|
! SelectIdInTree( nIdOld))
|
|
m_View.Redraw() ;
|
|
|
|
// aggiorno stato bottoni
|
|
UpdateShowModeButtons() ;
|
|
UpdateViewButtons() ;
|
|
|
|
return bOk ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
CTestEGrDlg::EmitTitle( void)
|
|
{
|
|
string sTitle ;
|
|
|
|
// nome file
|
|
if ( m_sFileName.empty())
|
|
sTitle = "New" ;
|
|
else
|
|
sTitle = m_sFileName ;
|
|
// indicazione di modificato
|
|
if ( m_bModified)
|
|
sTitle += "*" ;
|
|
// dati del prodotto
|
|
sTitle += " - EgalTech TestEGr" ;
|
|
|
|
// emissione del titolo
|
|
SetWindowText( stringtoW( sTitle)) ;
|
|
} |