diff --git a/AutoNester.cpp b/AutoNester.cpp new file mode 100644 index 0000000..2e11a44 --- /dev/null +++ b/AutoNester.cpp @@ -0,0 +1,235 @@ +//---------------------------------------------------------------------------- +// EgalTech 2019-2019 +//---------------------------------------------------------------------------- +// File : AutoNester.cpp Data : 28.11.19 Versione : 2.1k6 +// Contenuto : Implementazione della classe AutoNester. +// +// +// +// Modifiche : 28.11.19 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "AutoNester.h" +#include "DllMain.h" +#include "/EgtDev/Include/ENsDllMain.h" +#include "/EgtDev/Include/EGkPolyArc.h" +#include "/EgtDev/Extern/Optalog/Include/cns.h" +#include "/EgtDev/Extern/Optalog/Include/cns_egaltech.h" +#include "/EgtDev/Include/SELkLockId.h" + +using namespace std ; + +//---------------------------------------------------------------------------- +IAutoNester* +CreateAutoNester( void) +{ + // verifico la chiave e le opzioni + if ( ! TestKeyForENs( GetENsKey(), 0, GetENsLogger())) + return false ; + // creo il NestMgr + return static_cast ( new(nothrow) AutoNester) ; +} + +//---------------------------------------------------------------------------- +// AutoNester +//---------------------------------------------------------------------------- +AutoNester::AutoNester( void) + : m_pOrder( nullptr), m_pComp( nullptr) +{ +} + +//---------------------------------------------------------------------------- +AutoNester::~AutoNester( void) +{ + Clear() ; +} + +//---------------------------------------------------------------------------- +bool +AutoNester::Clear( void) +{ + if ( m_pOrder != nullptr) { + CNS_DeleteLaunchingOrder( m_pOrder) ; + m_pOrder = nullptr ; + m_pComp = nullptr ; + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +AutoNester::Start( void) +{ + Clear() ; + m_pOrder = CNS_NewLaunchingOrder() ; + return ( m_pOrder != nullptr) ; +} + +//---------------------------------------------------------------------------- +bool +AutoNester::AddSheet( int nSheetId, const PolyArc& Outline, int nPriority, int nCount) +{ + if ( m_pOrder == nullptr) + return false ; + if ( ! Outline.IsClosed()) + return false ; + // contorno nel formato Optalog + const int nElem = Outline.GetPointNbr() - 1 ; + vector vElem ; vElem.reserve( nElem) ; + Point3d ptIni, ptFin ; double dBulge ; + bool bNext = Outline.GetFirstArc( ptIni, ptFin, dBulge) ; + while ( bNext) { + double dLeftDeflection = - dBulge * DistXY( ptIni, ptFin) / 2 ; + vElem.push_back( { ptFin.x, ptFin.y, dLeftDeflection}) ; + bNext = Outline.GetNextArc( ptIni, ptFin, dBulge) ; + } + // aggiungo + CNS_SheetPtr pSheet = CNS_AddNonRectangularSheet( m_pOrder, nCount, int( vElem.size()), vElem.data()) ; + if ( pSheet == nullptr) + return false ; + CNS_SetSheetUserString( pSheet, ToString( nSheetId).c_str()) ; + CNS_SetSheetPriority( pSheet, nPriority) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +AutoNester::AddPart( int nPartId, const PolyArc& Outline, int nCount) +{ + if ( m_pOrder == nullptr) + return false ; + if ( ! Outline.IsClosed()) + return false ; + // contorno nel formato Optalog + const int nElem = Outline.GetPointNbr() - 1 ; + vector vElem ; vElem.reserve( nElem) ; + Point3d ptIni, ptFin ; double dBulge ; + bool bNext = Outline.GetFirstArc( ptIni, ptFin, dBulge) ; + while ( bNext) { + double dLeftDeflection = - dBulge * DistXY( ptIni, ptFin) / 2 ; + vElem.push_back( { ptFin.x, ptFin.y, dLeftDeflection}) ; + bNext = Outline.GetNextArc( ptIni, ptFin, dBulge) ; + } + // aggiungo + CNS_PartPtr pPart = CNS_AddPart( m_pOrder, nCount, int( vElem.size()), vElem.data()) ; + if ( pPart == nullptr) + return false ; + CNS_SetPartUserString( pPart, ToString( nPartId).c_str()) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +AutoNester::SetInterpartGap( double dGap) +{ + if ( m_pOrder == nullptr) + return false ; + CNS_SetInterpartGap( m_pOrder, dGap) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +AutoNester::Compute( int nMaxTime) +{ + if ( m_pOrder == nullptr) + return false ; + // recupero i codici di sblocco del nesting + string sKeyId, sKeySign ; + SplitFirst( GetENsKey2(), "-", sKeyId, sKeySign) ; + // verifico si riferiscano alla chiave di protezione in uso + int nKeySN, nKeyId ; + if ( ! GetLockSN( nKeySN) || ! FromString( sKeyId, nKeyId) || nKeySN != nKeyId) + return false ; + // passo i codici al nester + CNS_UnLockLaunchingOrderOxy( m_pOrder, sKeyId.c_str(), sKeySign.c_str()) ; + // lancio l'esecuzione + m_pComp = CNS_LaunchLocalComputation( m_pOrder, nMaxTime / 1000.) ; + return ( m_pComp != nullptr) ; +} + +//---------------------------------------------------------------------------- +bool +AutoNester::GetComputationStatus( int& nStatus) +{ + if ( m_pOrder == nullptr || m_pComp == nullptr) + return false ; + CNS_ComputationStatus status = CNS_GetComputationStatus( m_pComp) ; + if ( status == CNS_PendingComputation) + nStatus = 0 ; + else if ( status == CNS_IntermediateResult) + nStatus = 1 ; + else if ( status == CNS_Ok) + nStatus = 2 ; + else + nStatus = - 1 ; + return ( nStatus >= 0) ; +} + +//---------------------------------------------------------------------------- +bool +AutoNester::GetResults( double& dTotFillRatio, ANIVECT& vANI) +{ + // verifico validità calcolo + if ( m_pComp == nullptr) + return false ; + // recupero la soluzione + CNS_SolutionPtr pSol = CNS_GetSolution( m_pComp) ; + if ( pSol == nullptr) + return false ; + // percentuale di riempimento complessivo + dTotFillRatio = CNS_GetFillRatio( pSol) ; + // recupero i dati di nesting + vANI.clear() ; + int nNestCount = CNS_GetNumberOfNestings( pSol) ; + for ( int i = 0 ; i < nNestCount ; ++ i) { + // riferimento allo i-esimo nesting + CNS_NestingPtr pNest = CNS_GetNesting( pSol, i) ; + // dati dello sheet + CNS_SheetPtr pSheet = CNS_GetSheet( pNest) ; + const char* szSheetId = CNS_GetSheetUserString( pSheet) ; + int nSheetId = 999 ; + if ( szSheetId != nullptr) + FromString( szSheetId, nSheetId) ; + int nMult = CNS_GetMultiplicity( pNest) ; + int nPartCount = CNS_GetNumberOfNestedParts( pNest) ; + double dFillRatio = CNS_GetNestingFillRatio( pNest) ; + vANI.push_back( { nMult, nSheetId, nPartCount, dFillRatio, 0, 0}) ; + // ciclo sui pezzi nestati + for ( int j = 0; j < nPartCount ; ++ j) { + // dati del pezzo + CNS_PartPtr pPart ; + double dX, dY, dAngRot ; + int nFlip ; + CNS_GetNestedPart( pNest, j, &pPart, &dX, &dY, &nFlip, &dAngRot) ; + const char* szPartId = CNS_GetPartUserString( pPart) ; + int nPartId = 999 ; + if ( szPartId != nullptr) + FromString( szPartId, nPartId) ; + vANI.push_back( { 0, nPartId, nFlip, dX, dY, dAngRot}) ; + } + } + return true ; +} + +//---------------------------------------------------------------------------- +bool +AutoNester::PrintResults( const string& sHtmlFile) +{ + // verifico validità calcolo + if ( m_pComp == nullptr) + return false ; + // recupero la soluzione + CNS_SolutionPtr pSol = CNS_GetSolution( m_pComp) ; + if ( pSol == nullptr) + return false ; + // se richiesto risultato in html + if ( ! IsEmptyOrSpaces( sHtmlFile)) + CNS_GenerateHtmlSolutionReport( pSol, sHtmlFile.c_str()) ; + return true ; +} + \ No newline at end of file diff --git a/AutoNester.h b/AutoNester.h new file mode 100644 index 0000000..f43436c --- /dev/null +++ b/AutoNester.h @@ -0,0 +1,44 @@ +//---------------------------------------------------------------------------- +// EgalTech 2019-2019 +//---------------------------------------------------------------------------- +// File : AutoNester.h Data : 28.11.19 Versione : 2.1k6 +// Contenuto : Dichiarazione della classe AutoNester. +// +// +// +// Modifiche : 28.11.19 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/ENsAutoNester.h" + +struct CNS_LaunchingOrder ; +struct CNS_Computation ; + +//---------------------------------------------------------------------------- +class AutoNester : public IAutoNester +{ + public : + ~AutoNester( void) override ; + bool Start( void) override ; + bool AddSheet( int nSheetId, const PolyArc& Outline, int nPriority, int nCount) override ; + bool AddPart( int nPartId, const PolyArc& Outline, int nCount) override ; + bool SetInterpartGap( double dGap) override ; + bool Compute( int nMaxTime) override ; + bool GetComputationStatus( int& nStatus) override ; + bool GetResults( double& dTotFillRatio, ANIVECT& vANI) override ; + bool PrintResults( const std::string& sHtmlFile) override ; + + public : + AutoNester( void) ; + + private : + bool Clear( void) ; + + private : + CNS_LaunchingOrder* m_pOrder ; // ordine di esecuzione per OptaLog + CNS_Computation* m_pComp ; // calcolo di ottimizzazione +} ; diff --git a/DllMain.h b/DllMain.h new file mode 100644 index 0000000..47bb10b --- /dev/null +++ b/DllMain.h @@ -0,0 +1,22 @@ +//---------------------------------------------------------------------------- +// EgalTech 2019-2019 +//---------------------------------------------------------------------------- +// File : DllMain.h Data : 28.11.19 Versione : 2.1k5 +// Contenuto : Prototipi funzioni per uso locale della DLL. +// +// +// +// Modifiche : 28.11.19 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EgtILogger.h" +#include + +//----------------------------------------------------------------------------- +ILogger* GetENsLogger( void) ; +const std::string& GetENsKey( void) ; +const std::string& GetENsKey2( void) ; diff --git a/ENsDllMain.cpp b/ENsDllMain.cpp new file mode 100644 index 0000000..0710bc8 --- /dev/null +++ b/ENsDllMain.cpp @@ -0,0 +1,122 @@ +//---------------------------------------------------------------------------- +// EgalTech 2019-2019 +//---------------------------------------------------------------------------- +// File : ENsDllMain.cpp Data : 28.11.19 Versione : 2.1k6 +// Contenuto : Inizializzazione della DLL. +// +// +// +// Modifiche : 28.11.19 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "DllMain.h" +#include "/EgtDev/Include/ENsDllMain.h" +#include "/EgtDev/Include/EGnGetModuleVer.h" +#include "/EgtDev/Include/EgtTrace.h" + +//--------------------------- Costanti ---------------------------------------- +#if defined( _WIN64) && defined( _DEBUG) + const char* ENS_STR = "EgtNestingD64.dll ver. " ; +#elif defined( _WIN64) + const char* ENS_STR = "EgtNestingR64.dll ver. " ; +#elif defined( _WIN32) && defined( _DEBUG) + const char* ENS_STR = "EgtNestingD32.dll ver. " ; +#else + const char* ENS_STR = "EgtNestingR32.dll ver. " ; +#endif +const int STR_DIM = 40 ; + +//----------------------------------------------------------------------------- +static HINSTANCE s_hModule = NULL ; +static char s_szENsNameVer[STR_DIM] ; + +//----------------------------------------------------------------------------- +BOOL APIENTRY +DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpReserved) +{ + + if ( dwReason == DLL_PROCESS_ATTACH) { + // 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( "EgtNesting.dll Initializing!\n") ; + } + else if ( dwReason == DLL_PROCESS_DETACH) { + s_hModule = NULL ; + EGT_TRACE( "EgtNesting.dll Terminating!\n") ; + } + + return 1 ; +} + +//----------------------------------------------------------------------------- +const char* +GetENsVersion( void) +{ + std::string sVer ; + + GetModuleVersion( s_hModule, sVer) ; + sprintf_s( s_szENsNameVer, STR_DIM, "%s%s", ENS_STR, sVer.c_str()) ; + + return s_szENsNameVer ; +} + +//----------------------------------------------------------------------------- +static ILogger* s_pLogger = nullptr ; + +//----------------------------------------------------------------------------- +void +SetENsLogger( ILogger* pLogger) +{ + s_pLogger = pLogger ; +} + +//----------------------------------------------------------------------------- +ILogger* +GetENsLogger( void) +{ + return s_pLogger ; +} + +//----------------------------------------------------------------------------- +static std::string s_sKey ; + +//----------------------------------------------------------------------------- +void +SetENsKey( const std::string& sKey) +{ + s_sKey = sKey ; +} + +//----------------------------------------------------------------------------- +const std::string& +GetENsKey( void) +{ + return s_sKey ; +} + +//----------------------------------------------------------------------------- +static std::string s_sKey2 ; + +//----------------------------------------------------------------------------- +void +SetENsKey2( const std::string& sKey2) +{ + s_sKey2 = sKey2 ; +} + +//----------------------------------------------------------------------------- +const std::string& +GetENsKey2( void) +{ + return s_sKey2 ; +} diff --git a/EgtNesting.rc b/EgtNesting.rc new file mode 100644 index 0000000..03c834f Binary files /dev/null and b/EgtNesting.rc differ diff --git a/EgtNesting.sln b/EgtNesting.sln new file mode 100644 index 0000000..19cd820 --- /dev/null +++ b/EgtNesting.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.645 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{CF90B215-ED21-47DF-A021-77928EE19115}") = "EgtNesting", "EgtNesting.vcxproj", "{29956D5C-1F3C-4AF4-81C6-53E144808B78}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {29956D5C-1F3C-4AF4-81C6-53E144808B78}.Debug|Win32.ActiveCfg = Debug|Win32 + {29956D5C-1F3C-4AF4-81C6-53E144808B78}.Debug|Win32.Build.0 = Debug|Win32 + {29956D5C-1F3C-4AF4-81C6-53E144808B78}.Debug|x64.ActiveCfg = Debug|x64 + {29956D5C-1F3C-4AF4-81C6-53E144808B78}.Debug|x64.Build.0 = Debug|x64 + {29956D5C-1F3C-4AF4-81C6-53E144808B78}.Release|Win32.ActiveCfg = Release|Win32 + {29956D5C-1F3C-4AF4-81C6-53E144808B78}.Release|Win32.Build.0 = Release|Win32 + {29956D5C-1F3C-4AF4-81C6-53E144808B78}.Release|x64.ActiveCfg = Release|x64 + {29956D5C-1F3C-4AF4-81C6-53E144808B78}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EC9972D8-833B-4D2E-9FC8-B628641D1429} + EndGlobalSection +EndGlobal diff --git a/EgtNesting.vcxproj b/EgtNesting.vcxproj new file mode 100644 index 0000000..8bd71f4 --- /dev/null +++ b/EgtNesting.vcxproj @@ -0,0 +1,242 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {29956D5C-1F3C-4AF4-81C6-53E144808B78} + Win32Proj + EgtNesting + 10.0.17763.0 + + + + DynamicLibrary + true + Unicode + v120_xp + + + DynamicLibrary + true + Unicode + v141 + + + DynamicLibrary + false + true + Unicode + v120_xp + + + DynamicLibrary + false + true + Unicode + v141 + + + + + + + + + + + + + + + + + + + true + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)D$(PlatformArchitecture) + C:\;$(IncludePath) + + + true + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)D$(PlatformArchitecture) + C:\;$(IncludePath) + + + false + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)R$(PlatformArchitecture) + C:\;$(IncludePath) + + + false + $(SolutionDir)$(Configuration)$(PlatformArchitecture)\ + $(Configuration)$(PlatformArchitecture)\ + $(ProjectName)R$(PlatformArchitecture) + C:\;$(IncludePath) + + + + Use + Level3 + Disabled + WIN32;I_AM_ENS;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + ProgramDatabase + + + Windows + true + C:\EgtDev\Extern\OxySec\Lib\x32\xnodus32.obj;%(AdditionalDependencies) + + + copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\ +copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\DllD32 + + + _UNICODE;UNICODE;_DEB32;%(PreprocessorDefinitions) + + + + + Use + Level3 + Disabled + WIN32;I_AM_ENS;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + C:\EgtDev\Extern\OxySec\Lib\x64\xnodus.obj;%(AdditionalDependencies) + + + copy $(TargetDir)$(TargetName).pdb \EgtDev\Lib\ +copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\DllD64 + + + _UNICODE;UNICODE;_DEB64;%(PreprocessorDefinitions) + + + + + Level3 + Use + Full + true + true + WIN32;I_AM_ENS;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + AnySuitable + Speed + false + StreamingSIMDExtensions2 + true + true + true + false + + + Windows + false + true + C:\EgtDev\Extern\OxySec\Lib\x32\xnodus32.obj;%(AdditionalDependencies) + Default + + + copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\Dll32 + + + _UNICODE;UNICODE;NDEB32;%(PreprocessorDefinitions) + + + + + Level3 + Use + Full + true + true + WIN32;I_AM_ENS;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + AnySuitable + Speed + false + AdvancedVectorExtensions2 + true + true + true + false + + + Windows + false + true + C:\EgtDev\Extern\OxySec\Lib\x64\xnodus.obj;%(AdditionalDependencies) + Default + + + copy $(TargetDir)$(TargetName).lib \EgtDev\Lib\ +copy $(TargetPath) \EgtProg\Dll64 + + + _UNICODE;UNICODE;NDEB64;%(PreprocessorDefinitions) + + + + + + + + + + + false + false + + + + + false + false + + + + + + + + Create + Create + Create + Create + + + + + + + + + \ No newline at end of file diff --git a/EgtNesting.vcxproj.filters b/EgtNesting.vcxproj.filters new file mode 100644 index 0000000..7364b86 --- /dev/null +++ b/EgtNesting.vcxproj.filters @@ -0,0 +1,44 @@ + + + + + File di origine + + + File di origine + + + File di origine + + + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + + + {d4961058-c982-4caa-a1d4-28a09d7a009e} + + + {83c46d29-aefb-4901-b937-52d7a2067330} + + + {795e593c-b797-4a00-b2eb-0036381b09ad} + + + + + File di risorse + + + \ No newline at end of file diff --git a/resource.h b/resource.h new file mode 100644 index 0000000..78f50d2 Binary files /dev/null and b/resource.h differ diff --git a/stdafx.cpp b/stdafx.cpp new file mode 100644 index 0000000..ee870bb --- /dev/null +++ b/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : file di origine che include solo le inclusioni standard +// EgtExchange.pch sarà l'intestazione precompilata +// stdafx.obj conterrà le informazioni sui tipi precompilati + +#include "stdafx.h" + +// TODO: fare riferimento alle intestazioni aggiuntive necessarie in STDAFX.H +// e non in questo file diff --git a/stdafx.h b/stdafx.h new file mode 100644 index 0000000..c0608ab --- /dev/null +++ b/stdafx.h @@ -0,0 +1,38 @@ +// stdafx.h : file di inclusione per file di inclusione di sistema standard +// o file di inclusione specifici del progetto utilizzati di frequente, ma +// modificati raramente +// + +#pragma once + +#include "/EgtDev/Include/EgtTargetVer.h" + +#include +#include +#include +#include + +// in Debug riconoscimento memory leakage +#if defined( _DEBUG) + #define _CRTDBG_MAP_ALLOC + #include + #include +#endif + +// in Debug controllo iteratori +#if defined( _DEBUG) + #define _SECURE_SCL 1 +#else + #define _SECURE_SCL 0 +#endif + +#include "/EgtDev/Include/EgtLibVer.h" + +#pragma comment(lib, EGTLIBDIR "EgtGeneral" EGTLIBVER ".lib") +#pragma comment(lib, EGTLIBDIR "EgtGeomKernel" EGTLIBVER ".lib") +#pragma comment(lib, EGTLIBDIR "SEgtLock" EGTLIBVER ".lib") +#if defined( _WIN64) + #pragma comment(lib, EGTEXTDIR "Optalog/Lib/x64/liblcnsR64.lib") +#elif defined( _WIN32) + #pragma comment(lib, EGTEXTDIR "Optalog/Lib/x32/liblcnsR32.lib") +#endif \ No newline at end of file