diff --git a/AuxTools.h b/AuxTools.h index 5e3d27d..2db645f 100644 --- a/AuxTools.h +++ b/AuxTools.h @@ -11,6 +11,8 @@ // //---------------------------------------------------------------------------- +#pragma once + #include "/EgtDev/Include/EgtNumCollection.h" #include diff --git a/EgtExecutor.rc b/EgtExecutor.rc index 41e9da2..212ff31 100644 Binary files a/EgtExecutor.rc and b/EgtExecutor.rc differ diff --git a/EgtExecutor.vcxproj b/EgtExecutor.vcxproj index 7ac12ff..a68fd03 100644 --- a/EgtExecutor.vcxproj +++ b/EgtExecutor.vcxproj @@ -264,6 +264,7 @@ copy $(TargetPath) \EgtProg\Dll64 + diff --git a/EgtExecutor.vcxproj.filters b/EgtExecutor.vcxproj.filters index 87d3002..1021607 100644 --- a/EgtExecutor.vcxproj.filters +++ b/EgtExecutor.vcxproj.filters @@ -290,6 +290,9 @@ File di origine\LUA + + File di origine\Global + diff --git a/GenTools.cpp b/GenTools.cpp new file mode 100644 index 0000000..9046844 --- /dev/null +++ b/GenTools.cpp @@ -0,0 +1,55 @@ +//---------------------------------------------------------------------------- +// EgalTech 2017-2017 +//---------------------------------------------------------------------------- +// File : GenTools.cpp Data : 08.01.17 Versione : 1.6x5 +// Contenuto : Funzioni generalie. +// +// +// +// Modifiche : 08.01.17 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#include "stdafx.h" +#include "GenTools.h" +#include + +using namespace std ; + +//---------------------------------------------------------------------------- +HWND +FindTopWindow( void) +{ + // Recupero l'Id del processo corrente + DWORD pid = GetCurrentProcessId() ; + + pair params = { 0, pid} ; + + // Enumerate the windows using a lambda to process each window + BOOL bResult = EnumWindows( []( HWND hWnd, LPARAM lParam) -> BOOL + { + auto pParams = ( pair*)(lParam) ; + + DWORD processId ; + if ( GetWindowThreadProcessId( hWnd, &processId) && + processId == pParams->second && + GetWindow( hWnd, GW_OWNER) == (HWND) nullptr && + IsWindowVisible( hWnd)) { + // Stop enumerating + SetLastError( -1) ; + pParams->first = hWnd ; + return FALSE ; + } + + // Continue enumerating + return TRUE ; + }, (LPARAM) ¶ms) ; + + + if ( ! bResult && GetLastError() == -1 && params.first != nullptr) { + return params.first ; + } + + return nullptr ; +} \ No newline at end of file diff --git a/GenTools.h b/GenTools.h new file mode 100644 index 0000000..851371d --- /dev/null +++ b/GenTools.h @@ -0,0 +1,22 @@ +//---------------------------------------------------------------------------- +// EgalTech 2017-2017 +//---------------------------------------------------------------------------- +// File : GenTools.h Data : 08.01.17 Versione : 1.6x5 +// Contenuto : Prototipi funzioni generiche. +// +// +// +// Modifiche : 08.01.17 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#define NOMINMAX +#include + +//---------------------------------------------------------------------------- +// Recupero l'handle della finestra principale dell'eseguibile +HWND FindTopWindow( void) ; + diff --git a/GeoTools.h b/GeoTools.h index 6c6dfb6..6feaa01 100644 --- a/GeoTools.h +++ b/GeoTools.h @@ -11,6 +11,8 @@ // //---------------------------------------------------------------------------- +#pragma once + #include "/EgtDev/Include/EGkPoint3d.h" #include "/EgtDev/Include/EgtNumCollection.h" diff --git a/LUA_General.cpp b/LUA_General.cpp index 05b7f4c..291a40d 100644 --- a/LUA_General.cpp +++ b/LUA_General.cpp @@ -15,6 +15,7 @@ #include "stdafx.h" #include "EXE.h" #include "LUA.h" +#include "GenTools.h" #include "/EgtDev/Include/ExeExecutor.h" #include "/EgtDev/Include/EGkLuaAux.h" #include "/EgtDev/Include/EGnStringUtils.h" @@ -216,7 +217,7 @@ LuaOutLog( lua_State* L) static int LuaOutBox( lua_State* L) { - // 3 o 4 parametri : stringa, titolo, icona [bModal] + // 3 o 4 parametri : stringa, titolo, icona [, bModal] string sOut ; LuaCheckParam( L, 1, sOut) string sTitle ; @@ -233,7 +234,7 @@ LuaOutBox( lua_State* L) LuaGetParam( L, 4, bModal) ; LuaClearStack( L) ; // emetto la finestra di dialogo - int nRes = MessageBox( nullptr, stringtoW( sOut), stringtoW( sTitle), + int nRes = MessageBox( FindTopWindow(), stringtoW( sOut), stringtoW( sTitle), MB_OKCANCEL | nIcon | ( bModal ? MB_TASKMODAL : MB_SYSTEMMODAL)) ; // risultato (Ok->true, Cancel->false) LuaSetParam( L, ( nRes == IDOK)) ; @@ -272,6 +273,52 @@ LuaOutText( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaFileDialog( lua_State* L) +{ + // 3 parametri : bOpenVsSave, sFile, sFilter + bool bOpenVsSave ; + LuaCheckParam( L, 1, bOpenVsSave) + string sFile ; + LuaCheckParam( L, 2, sFile) + string sFilter ; + LuaCheckParam( L, 3, sFilter) + LuaClearStack( L) ; + // Converto i parametri nel formato wide e cambio L'|' in L'\0' nel filtro + AtoWEX wsFileName( sFile.c_str()) ; + AtoW wsFilter( sFilter.c_str()) ; + for ( wchar_t* pC = wsFilter.m_psz ; *pC != L'\0' ; ++ pC) { + if ( *pC == L'|') + *pC = L'\0' ; + } + // Riempio la struttura dati per il dialogo + OPENFILENAME ofn ; + ZeroMemory( &ofn, sizeof( ofn)) ; + ofn.lStructSize = sizeof( ofn) ; + ofn.hwndOwner = FindTopWindow() ; + ofn.lpstrFilter = LPWSTR( wsFilter) ; + ofn.lpstrFile = LPWSTR( wsFileName) ; + ofn.nMaxFile = MAX_PATH ; + ofn.Flags = OFN_DONTADDTORECENT | OFN_PATHMUSTEXIST ; + // Visualizzo il dialogo + if ( bOpenVsSave) { + ofn.Flags |= OFN_FILEMUSTEXIST ; + if ( GetOpenFileName( &ofn) != FALSE) + LuaSetParam( L, wstrztoA( wsFileName)) ; + else + LuaSetParam( L) ; + } + else { + ofn.Flags |= OFN_OVERWRITEPROMPT ; + if ( GetSaveFileName( &ofn) != FALSE) + LuaSetParam( L, wstrztoA( wsFileName)) ; + else + LuaSetParam( L) ; + } + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaExistsFile( lua_State* L) @@ -490,6 +537,7 @@ LuaInstallGeneral( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtOutBox", LuaOutBox) ; bOk = bOk && luaMgr.RegisterFunction( "EgtProcessEvents", LuaProcessEvents) ; bOk = bOk && luaMgr.RegisterFunction( "EgtOutText", LuaOutText) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtFileDialog", LuaFileDialog) ; bOk = bOk && luaMgr.RegisterFunction( "EgtExistsFile", LuaExistsFile) ; bOk = bOk && luaMgr.RegisterFunction( "EgtCopyFile", LuaCopyFile) ; bOk = bOk && luaMgr.RegisterFunction( "EgtRenameFile", LuaRenameFile) ; diff --git a/LUA_MachMgr.cpp b/LUA_MachMgr.cpp index 784d887..0b955d8 100644 --- a/LUA_MachMgr.cpp +++ b/LUA_MachMgr.cpp @@ -2586,6 +2586,27 @@ LuaGetCalcTipFromPositions( lua_State* L) return 1 ; } +//------------------------------------------------------------------------------- +static int +LuaGetCalcToolDirFromAngles( lua_State* L) +{ + // 2 parametri : dAngA, dAngB + double dAngA ; + LuaCheckParam( L, 1, dAngA) + double dAngB ; + LuaCheckParam( L, 2, dAngB) + LuaClearStack( L) ; + // Calcolo la direzione utensile dagli angoli macchina + Vector3d vtDir ; + bool bOk = ExeGetCalcToolDirFromAngles( dAngA, dAngB, vtDir) ; + // restituisco il risultato + if ( bOk) + LuaSetParam( L, vtDir) ; + else + LuaSetParam( L) ; + return 1 ; +} + //------------------------------------------------------------------------------- static int LuaVerifyOutstroke( lua_State* L) @@ -3032,6 +3053,7 @@ LuaInstallMachMgr( LuaMgr& luaMgr) bOk = bOk && luaMgr.RegisterFunction( "EgtGetCalcAngles", LuaGetCalcAngles) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetCalcPositions", LuaGetCalcPositions) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetCalcTipFromPositions", LuaGetCalcTipFromPositions) ; + bOk = bOk && luaMgr.RegisterFunction( "EgtGetCalcToolDirFromAngles", LuaGetCalcToolDirFromAngles) ; bOk = bOk && luaMgr.RegisterFunction( "EgtVerifyOutstroke", LuaVerifyOutstroke) ; bOk = bOk && luaMgr.RegisterFunction( "EgtGetOutstrokeInfo", LuaGetOutstrokeInfo) ; // Machine Move