From 3ca643374136cf3848656fa532d1a12178b067c1 Mon Sep 17 00:00:00 2001 From: Yury Rodzikau Date: Fri, 13 Jun 2025 08:47:58 +0200 Subject: [PATCH 1/3] Scanlab SMC Driver: Refactored CSMCJobInstance::ReadSimulationFile to Support Parser Selection Based on SMC Version * Implements logic to select the appropriate SimulationData parser dynamically based on the detected SCANmotionControl version. * Restored the previous SMCJob interface to ensure backward compatibility with existing code. Signed-off-by: Yury Rodzikau --- .../ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml | 10 +-- .../libmcdriver_scanlabsmc_dynamic.h | 20 ------ .../libmcdriver_scanlabsmc_dynamic.hpp | 52 +--------------- .../libmcdriver_scanlabsmc_types.hpp | 2 + ...mcdriver_scanlabsmc_smccontextinstance.cpp | 8 ++- ...mcdriver_scanlabsmc_smccontextinstance.hpp | 2 + .../libmcdriver_scanlabsmc_smcjob.cpp | 10 --- .../libmcdriver_scanlabsmc_smcjob.hpp | 4 -- .../libmcdriver_scanlabsmc_smcjobinstance.cpp | 33 +++++++++- .../libmcdriver_scanlabsmc_smcjobinstance.hpp | 14 +++-- .../Interfaces/libmcdriver_scanlabsmc_abi.hpp | 18 ------ .../libmcdriver_scanlabsmc_interfaces.hpp | 12 ---- ...ibmcdriver_scanlabsmc_interfacewrapper.cpp | 62 ------------------- .../libmcdriver_scanlabsmc_types.hpp | 2 + 14 files changed, 53 insertions(+), 196 deletions(-) diff --git a/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml b/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml index 5693c607..b7944cc2 100644 --- a/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml +++ b/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml @@ -103,7 +103,7 @@ - + @@ -326,14 +326,6 @@ Custom implementation - - - - - - - - diff --git a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.h b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.h index e11190ed..33754374 100644 --- a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.h +++ b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.h @@ -252,24 +252,6 @@ typedef LibMCDriver_ScanLabSMCResult (*PLibMCDriver_ScanLabSMCSMCJob_StopExecuti */ typedef LibMCDriver_ScanLabSMCResult (*PLibMCDriver_ScanLabSMCSMCJob_LoadSimulationDataPtr) (LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pSimulationDataTable); -/** -* Reads the SMC Simulation data into a data table. -* -* @param[in] pSMCJob - SMCJob instance. -* @param[in] pSimulationDataTable - Data table object to read the simulation into. -* @return error code or 0 (success) -*/ -typedef LibMCDriver_ScanLabSMCResult (*PLibMCDriver_ScanLabSMCSMCJob_LoadSimulationData_SMC_v1Ptr) (LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pSimulationDataTable); - -/** -* Reads the SMC Log Record data into a data table. -* -* @param[in] pSMCJob - SMCJob instance. -* @param[in] pLogRecordDataTable - Data table object to read the simulation into. -* @return error code or 0 (success) -*/ -typedef LibMCDriver_ScanLabSMCResult (*PLibMCDriver_ScanLabSMCSMCJob_LoadLogRecordDataPtr) (LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pLogRecordDataTable); - /** * Returns a characteristic value of a job. * @@ -874,8 +856,6 @@ typedef struct { PLibMCDriver_ScanLabSMCSMCJob_WaitForExecutionPtr m_SMCJob_WaitForExecution; PLibMCDriver_ScanLabSMCSMCJob_StopExecutionPtr m_SMCJob_StopExecution; PLibMCDriver_ScanLabSMCSMCJob_LoadSimulationDataPtr m_SMCJob_LoadSimulationData; - PLibMCDriver_ScanLabSMCSMCJob_LoadSimulationData_SMC_v1Ptr m_SMCJob_LoadSimulationData_SMC_v1; - PLibMCDriver_ScanLabSMCSMCJob_LoadLogRecordDataPtr m_SMCJob_LoadLogRecordData; PLibMCDriver_ScanLabSMCSMCJob_GetJobCharacteristicPtr m_SMCJob_GetJobCharacteristic; PLibMCDriver_ScanLabSMCSMCJob_GetJobDurationPtr m_SMCJob_GetJobDuration; PLibMCDriver_ScanLabSMCSMCConfiguration_SetDynamicViolationReactionPtr m_SMCConfiguration_SetDynamicViolationReaction; diff --git a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp index c57f169f..06755123 100644 --- a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp +++ b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp @@ -239,6 +239,7 @@ class ELibMCDriver_ScanLabSMCException : public std::exception { case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCENAME: return "EMPTYRTCSERVICEDLLRESOURCENAME"; case LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND: return "RTCSERVICERESOURCENOTFOUND"; case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA: return "EMPTYRTCSERVICEDLLRESOURCEDATA"; + case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED: return "SIMULATIONDATALOADINGISNOTSUPPORTED"; } return "UNKNOWN"; } @@ -308,6 +309,7 @@ class ELibMCDriver_ScanLabSMCException : public std::exception { case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCENAME: return "Empty RTC Service DLL Resource Name."; case LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND: return "RTC Service Resource not found."; case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA: return "Empty RTC Service DLL Resource Data."; + case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED: return "Simulation data loading is not supported for this version."; } return "unknown error"; } @@ -544,8 +546,6 @@ class CSMCJob : public CBase { inline void WaitForExecution(const LibMCDriver_ScanLabSMC_uint32 nTimeOutInMilliseconds); inline void StopExecution(); inline void LoadSimulationData(classParam pSimulationDataTable); - inline void LoadSimulationData_SMC_v1(classParam pSimulationDataTable); - inline void LoadLogRecordData(classParam pLogRecordDataTable); inline LibMCDriver_ScanLabSMC_double GetJobCharacteristic(const eJobCharacteristic eValueType); inline LibMCDriver_ScanLabSMC_double GetJobDuration(); }; @@ -788,8 +788,6 @@ class CDriver_ScanLabSMC : public CDriver { pWrapperTable->m_SMCJob_WaitForExecution = nullptr; pWrapperTable->m_SMCJob_StopExecution = nullptr; pWrapperTable->m_SMCJob_LoadSimulationData = nullptr; - pWrapperTable->m_SMCJob_LoadSimulationData_SMC_v1 = nullptr; - pWrapperTable->m_SMCJob_LoadLogRecordData = nullptr; pWrapperTable->m_SMCJob_GetJobCharacteristic = nullptr; pWrapperTable->m_SMCJob_GetJobDuration = nullptr; pWrapperTable->m_SMCConfiguration_SetDynamicViolationReaction = nullptr; @@ -1069,24 +1067,6 @@ class CDriver_ScanLabSMC : public CDriver { if (pWrapperTable->m_SMCJob_LoadSimulationData == nullptr) return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; - #ifdef _WIN32 - pWrapperTable->m_SMCJob_LoadSimulationData_SMC_v1 = (PLibMCDriver_ScanLabSMCSMCJob_LoadSimulationData_SMC_v1Ptr) GetProcAddress(hLibrary, "libmcdriver_scanlabsmc_smcjob_loadsimulationdata_smc_v1"); - #else // _WIN32 - pWrapperTable->m_SMCJob_LoadSimulationData_SMC_v1 = (PLibMCDriver_ScanLabSMCSMCJob_LoadSimulationData_SMC_v1Ptr) dlsym(hLibrary, "libmcdriver_scanlabsmc_smcjob_loadsimulationdata_smc_v1"); - dlerror(); - #endif // _WIN32 - if (pWrapperTable->m_SMCJob_LoadSimulationData_SMC_v1 == nullptr) - return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; - - #ifdef _WIN32 - pWrapperTable->m_SMCJob_LoadLogRecordData = (PLibMCDriver_ScanLabSMCSMCJob_LoadLogRecordDataPtr) GetProcAddress(hLibrary, "libmcdriver_scanlabsmc_smcjob_loadlogrecorddata"); - #else // _WIN32 - pWrapperTable->m_SMCJob_LoadLogRecordData = (PLibMCDriver_ScanLabSMCSMCJob_LoadLogRecordDataPtr) dlsym(hLibrary, "libmcdriver_scanlabsmc_smcjob_loadlogrecorddata"); - dlerror(); - #endif // _WIN32 - if (pWrapperTable->m_SMCJob_LoadLogRecordData == nullptr) - return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; - #ifdef _WIN32 pWrapperTable->m_SMCJob_GetJobCharacteristic = (PLibMCDriver_ScanLabSMCSMCJob_GetJobCharacteristicPtr) GetProcAddress(hLibrary, "libmcdriver_scanlabsmc_smcjob_getjobcharacteristic"); #else // _WIN32 @@ -1701,14 +1681,6 @@ class CDriver_ScanLabSMC : public CDriver { if ( (eLookupError != 0) || (pWrapperTable->m_SMCJob_LoadSimulationData == nullptr) ) return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; - eLookupError = (*pLookup)("libmcdriver_scanlabsmc_smcjob_loadsimulationdata_smc_v1", (void**)&(pWrapperTable->m_SMCJob_LoadSimulationData_SMC_v1)); - if ( (eLookupError != 0) || (pWrapperTable->m_SMCJob_LoadSimulationData_SMC_v1 == nullptr) ) - return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; - - eLookupError = (*pLookup)("libmcdriver_scanlabsmc_smcjob_loadlogrecorddata", (void**)&(pWrapperTable->m_SMCJob_LoadLogRecordData)); - if ( (eLookupError != 0) || (pWrapperTable->m_SMCJob_LoadLogRecordData == nullptr) ) - return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; - eLookupError = (*pLookup)("libmcdriver_scanlabsmc_smcjob_getjobcharacteristic", (void**)&(pWrapperTable->m_SMCJob_GetJobCharacteristic)); if ( (eLookupError != 0) || (pWrapperTable->m_SMCJob_GetJobCharacteristic == nullptr) ) return LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTFINDLIBRARYEXPORT; @@ -2177,26 +2149,6 @@ class CDriver_ScanLabSMC : public CDriver { CheckError(m_pWrapper->m_WrapperTable.m_SMCJob_LoadSimulationData(m_pHandle, hSimulationDataTable)); } - /** - * CSMCJob::LoadSimulationData_SMC_v1 - Reads the SMC Simulation data into a data table. - * @param[in] pSimulationDataTable - Data table object to read the simulation into. - */ - void CSMCJob::LoadSimulationData_SMC_v1(classParam pSimulationDataTable) - { - LibMCEnvHandle hSimulationDataTable = pSimulationDataTable.GetHandle(); - CheckError(m_pWrapper->m_WrapperTable.m_SMCJob_LoadSimulationData_SMC_v1(m_pHandle, hSimulationDataTable)); - } - - /** - * CSMCJob::LoadLogRecordData - Reads the SMC Log Record data into a data table. - * @param[in] pLogRecordDataTable - Data table object to read the simulation into. - */ - void CSMCJob::LoadLogRecordData(classParam pLogRecordDataTable) - { - LibMCEnvHandle hLogRecordDataTable = pLogRecordDataTable.GetHandle(); - CheckError(m_pWrapper->m_WrapperTable.m_SMCJob_LoadLogRecordData(m_pHandle, hLogRecordDataTable)); - } - /** * CSMCJob::GetJobCharacteristic - Returns a characteristic value of a job. * @param[in] eValueType - Type of job diff --git a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp index 182f1139..e0c0566a 100644 --- a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp +++ b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp @@ -157,6 +157,7 @@ typedef void * LibMCDriver_ScanLabSMC_pvoid; #define LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCENAME 1049 /** Empty RTC Service DLL Resource Name. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND 1050 /** RTC Service Resource not found. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA 1051 /** Empty RTC Service DLL Resource Data. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED 1052 /** Simulation data loading is not supported for this version. */ /************************************************************************************************************************* Error strings for LibMCDriver_ScanLabSMC @@ -226,6 +227,7 @@ inline const char * LIBMCDRIVER_SCANLABSMC_GETERRORSTRING (LibMCDriver_ScanLabSM case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCENAME: return "Empty RTC Service DLL Resource Name."; case LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND: return "RTC Service Resource not found."; case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA: return "Empty RTC Service DLL Resource Data."; + case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED: return "Simulation data loading is not supported for this version."; default: return "unknown error"; } } diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.cpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.cpp index 2e67f2a5..d5b2f915 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.cpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.cpp @@ -91,8 +91,8 @@ CSMCContextInstance::CSMCContextInstance(const std::string& sContextName, ISMCCo : m_pSDK (pSDK), m_pDriverEnvironment (pDriverEnvironment), m_sContextName (sContextName), - m_nSerialNumber (0) - + m_nSerialNumber (0), + m_bSendToHardware (false) { if (pSDK.get() == nullptr) throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM); @@ -115,6 +115,8 @@ CSMCContextInstance::CSMCContextInstance(const std::string& sContextName, ISMCCo m_sIPAddress = pSMCConfiguration->GetIPAddress(); + m_bSendToHardware = pSMCConfiguration->GetSendToHardware(); + auto pCorrectionFile = m_pWorkingDirectory->StoreCustomStringInTempFile("ct5", ""); eSMCConfigVersion configVersion = eSMCConfigVersion::Unknown; @@ -220,7 +222,7 @@ std::string CSMCContextInstance::GetSimulationSubDirectory() PSMCJobInstance CSMCContextInstance::BeginJob(const double dStartPositionX, const double dStartPositionY) { - return std::make_shared (m_pContextHandle, dStartPositionX, dStartPositionY, m_pWorkingDirectory, m_sSimulationSubDirectory); + return std::make_shared (m_pContextHandle, dStartPositionX, dStartPositionY, m_pWorkingDirectory, m_sSimulationSubDirectory, m_bSendToHardware); } PSMCJobInstance CSMCContextInstance::GetUnfinishedJob() diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.hpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.hpp index 1fbb7585..177ce143 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.hpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccontextinstance.hpp @@ -63,6 +63,8 @@ class CSMCContextInstance { uint32_t m_nSerialNumber; + bool m_bSendToHardware; + public: CSMCContextInstance(const std::string & sContextName, ISMCConfiguration* pSMCConfiguration, PScanLabSMCSDK pSDK, LibMCEnv::PDriverEnvironment pDriverEnvironment, const std::string & sRTCDLLDirectory); diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.cpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.cpp index e8a16804..1295c8b1 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.cpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.cpp @@ -132,16 +132,6 @@ void CSMCJob::LoadSimulationData(LibMCEnv::PDataTable pSimulationDataTable) m_pJobInstance->ReadSimulationFile(pSimulationDataTable); } -void CSMCJob::LoadSimulationData_SMC_v1(LibMCEnv::PDataTable pSimulationDataTable) -{ - m_pJobInstance->ReadSimulationFile_SMC_v1(pSimulationDataTable); -} - -void CSMCJob::LoadLogRecordData(LibMCEnv::PDataTable pLogRecordDataTable) -{ - m_pJobInstance->ReadLogRecordFile(pLogRecordDataTable); -} - LibMCDriver_ScanLabSMC_double CSMCJob::GetJobCharacteristic(const LibMCDriver_ScanLabSMC::eJobCharacteristic eValueType) { return m_pJobInstance->GetJobCharacteristic (eValueType); diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.hpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.hpp index 849edd0e..acc75d6b 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.hpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjob.hpp @@ -96,10 +96,6 @@ class CSMCJob : public virtual ISMCJob, public virtual CBase { void LoadSimulationData(LibMCEnv::PDataTable pSimulationDataTable) override; - void LoadSimulationData_SMC_v1(LibMCEnv::PDataTable pSimulationDataTable) override; - - void LoadLogRecordData(LibMCEnv::PDataTable pLogRecordDataTable) override; - LibMCDriver_ScanLabSMC_double GetJobCharacteristic(const LibMCDriver_ScanLabSMC::eJobCharacteristic eValueType) override; LibMCDriver_ScanLabSMC_double GetJobDuration() override; diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp index 0f2ca2cb..36dae119 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp @@ -51,14 +51,15 @@ using namespace LibMCDriver_ScanLabSMC::Impl; Class definition of CSMCJob **************************************************************************************************************************/ -CSMCJobInstance::CSMCJobInstance(PSMCContextHandle pContextHandle, double dStartPositionX, double dStartPositionY, LibMCEnv::PWorkingDirectory pWorkingDirectory, std::string sSimulationSubDirectory) +CSMCJobInstance::CSMCJobInstance(PSMCContextHandle pContextHandle, double dStartPositionX, double dStartPositionY, LibMCEnv::PWorkingDirectory pWorkingDirectory, std::string sSimulationSubDirectory, bool bSendToHardware) : m_pContextHandle(pContextHandle), m_JobID(0), m_bIsFinalized(false), m_pWorkingDirectory (pWorkingDirectory), m_sSimulationSubDirectory (sSimulationSubDirectory), m_bHasJobDuration (false), - m_dJobDuration (0.0) + m_dJobDuration (0.0), + m_bSendToHardware (bSendToHardware) { if (m_pWorkingDirectory.get() == nullptr) @@ -660,6 +661,32 @@ double CSMCJobInstance::GetJobDuration() } void CSMCJobInstance::ReadSimulationFile(LibMCEnv::PDataTable pDataTable) +{ + slsc_VersionInfo version = m_pSDK->slsc_cfg_get_scanmotioncontrol_version(); + + if (version.m_nMajor == 0) { + if (version.m_nMinor == 8 || version.m_nMinor == 9) { + ReadSimulationFile_SMC_v0_8(pDataTable); + } + else { + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED); + } + } + else if (version.m_nMajor == 1) { + if (version.m_nMinor == 0) + { + if (m_bSendToHardware) + ReadLogRecordFile(pDataTable); + else + ReadSimulationFile_SMC_v1_0(pDataTable); + } + else { + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED); + } + } +} + +void CSMCJobInstance::ReadSimulationFile_SMC_v0_8(LibMCEnv::PDataTable pDataTable) { if (pDataTable.get() == nullptr) throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM); @@ -706,7 +733,7 @@ void CSMCJobInstance::ReadSimulationFile(LibMCEnv::PDataTable pDataTable) m_bHasJobDuration = true; } -void CSMCJobInstance::ReadSimulationFile_SMC_v1(LibMCEnv::PDataTable pDataTable) +void CSMCJobInstance::ReadSimulationFile_SMC_v1_0(LibMCEnv::PDataTable pDataTable) { if (pDataTable.get() == nullptr) throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM); diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.hpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.hpp index 9b7348aa..92e69545 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.hpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.hpp @@ -62,6 +62,8 @@ class CSMCJobInstance { bool m_bHasJobDuration; double m_dJobDuration; + bool m_bSendToHardware; + void drawPolylineEx(slscHandle contextHandle, const uint64_t nPointsBufferSize, const LibMCDriver_ScanLabSMC::sPoint2D* pPointsBuffer, bool bIsClosed); void drawHatchesEx(const LibMCDriver_ScanLabSMC_uint64 nHatchesBufferSize, const LibMCDriver_ScanLabSMC::sHatch2D* pHatchesBuffer, const LibMCDriver_ScanLabSMC_double dMarkSpeed, const LibMCDriver_ScanLabSMC_double dJumpSpeed, const LibMCDriver_ScanLabSMC_double dPower, const LibMCDriver_ScanLabSMC_double dZValue); void drawHatchesExLinearPower(const LibMCDriver_ScanLabSMC_uint64 nHatchesBufferSize, const LibMCDriver_ScanLabSMC::sHatch2D* pHatchesBuffer, const LibMCDriver_ScanLabSMC_double dMarkSpeed, const LibMCDriver_ScanLabSMC_double dJumpSpeed, const LibMCDriver_ScanLabSMC_double dPower, const LibMCDriver_ScanLabSMC_double dZValue, std::vector& PowerValues1, std::vector& PowerValues2, double dMaxPower); @@ -69,7 +71,7 @@ class CSMCJobInstance { public: - CSMCJobInstance(PSMCContextHandle pContextHandle, double dStartPositionX, double dStartPositionY, LibMCEnv::PWorkingDirectory pWorkingDirectory, std::string sSimulationSubDirectory); + CSMCJobInstance(PSMCContextHandle pContextHandle, double dStartPositionX, double dStartPositionY, LibMCEnv::PWorkingDirectory pWorkingDirectory, std::string sSimulationSubDirectory, bool bSendToHardware); virtual ~CSMCJobInstance(); @@ -99,16 +101,18 @@ class CSMCJobInstance { void AddLayerToList(LibMCEnv::PToolpathLayer pLayer); void ReadSimulationFile(LibMCEnv::PDataTable pDataTable); - - void ReadSimulationFile_SMC_v1(LibMCEnv::PDataTable pDataTable); - - void ReadLogRecordFile(LibMCEnv::PDataTable pDataTable); double GetJobCharacteristic(const LibMCDriver_ScanLabSMC::eJobCharacteristic eValueType); double GetJobDuration(); +private: + + void ReadSimulationFile_SMC_v0_8(LibMCEnv::PDataTable pDataTable); + + void ReadSimulationFile_SMC_v1_0(LibMCEnv::PDataTable pDataTable); + void ReadLogRecordFile(LibMCEnv::PDataTable pDataTable); }; typedef std::shared_ptr PSMCJobInstance; diff --git a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_abi.hpp b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_abi.hpp index b0cb9176..5c551adb 100644 --- a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_abi.hpp +++ b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_abi.hpp @@ -265,24 +265,6 @@ LIBMCDRIVER_SCANLABSMC_DECLSPEC LibMCDriver_ScanLabSMCResult libmcdriver_scanlab */ LIBMCDRIVER_SCANLABSMC_DECLSPEC LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadsimulationdata(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pSimulationDataTable); -/** -* Reads the SMC Simulation data into a data table. -* -* @param[in] pSMCJob - SMCJob instance. -* @param[in] pSimulationDataTable - Data table object to read the simulation into. -* @return error code or 0 (success) -*/ -LIBMCDRIVER_SCANLABSMC_DECLSPEC LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadsimulationdata_smc_v1(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pSimulationDataTable); - -/** -* Reads the SMC Log Record data into a data table. -* -* @param[in] pSMCJob - SMCJob instance. -* @param[in] pLogRecordDataTable - Data table object to read the simulation into. -* @return error code or 0 (success) -*/ -LIBMCDRIVER_SCANLABSMC_DECLSPEC LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadlogrecorddata(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pLogRecordDataTable); - /** * Returns a characteristic value of a job. * diff --git a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfaces.hpp b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfaces.hpp index fd0301a9..0da4bb34 100644 --- a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfaces.hpp +++ b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfaces.hpp @@ -435,18 +435,6 @@ class ISMCJob : public virtual IBase { */ virtual void LoadSimulationData(LibMCEnv::PDataTable pSimulationDataTable) = 0; - /** - * ISMCJob::LoadSimulationData_SMC_v1 - Reads the SMC Simulation data into a data table. - * @param[in] pSimulationDataTable - Data table object to read the simulation into. - */ - virtual void LoadSimulationData_SMC_v1(LibMCEnv::PDataTable pSimulationDataTable) = 0; - - /** - * ISMCJob::LoadLogRecordData - Reads the SMC Log Record data into a data table. - * @param[in] pLogRecordDataTable - Data table object to read the simulation into. - */ - virtual void LoadLogRecordData(LibMCEnv::PDataTable pLogRecordDataTable) = 0; - /** * ISMCJob::GetJobCharacteristic - Returns a characteristic value of a job. * @param[in] eValueType - Type of job diff --git a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfacewrapper.cpp b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfacewrapper.cpp index 5db66160..4a287526 100644 --- a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfacewrapper.cpp +++ b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_interfacewrapper.cpp @@ -653,64 +653,6 @@ LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadsimulationdata(Li } } -LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadsimulationdata_smc_v1(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pSimulationDataTable) -{ - IBase* pIBaseClass = (IBase *)pSMCJob; - - try { - LibMCEnv::PDataTable pISimulationDataTable = std::make_shared(CWrapper::sPLibMCEnvWrapper.get(), pSimulationDataTable); - CWrapper::sPLibMCEnvWrapper->AcquireInstance(pISimulationDataTable.get()); - if (!pISimulationDataTable) - throw ELibMCDriver_ScanLabSMCInterfaceException (LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDCAST); - - ISMCJob* pISMCJob = dynamic_cast(pIBaseClass); - if (!pISMCJob) - throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDCAST); - - pISMCJob->LoadSimulationData_SMC_v1(pISimulationDataTable); - - return LIBMCDRIVER_SCANLABSMC_SUCCESS; - } - catch (ELibMCDriver_ScanLabSMCInterfaceException & Exception) { - return handleLibMCDriver_ScanLabSMCException(pIBaseClass, Exception); - } - catch (std::exception & StdException) { - return handleStdException(pIBaseClass, StdException); - } - catch (...) { - return handleUnhandledException(pIBaseClass); - } -} - -LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_loadlogrecorddata(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, LibMCEnv_DataTable pLogRecordDataTable) -{ - IBase* pIBaseClass = (IBase *)pSMCJob; - - try { - LibMCEnv::PDataTable pILogRecordDataTable = std::make_shared(CWrapper::sPLibMCEnvWrapper.get(), pLogRecordDataTable); - CWrapper::sPLibMCEnvWrapper->AcquireInstance(pILogRecordDataTable.get()); - if (!pILogRecordDataTable) - throw ELibMCDriver_ScanLabSMCInterfaceException (LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDCAST); - - ISMCJob* pISMCJob = dynamic_cast(pIBaseClass); - if (!pISMCJob) - throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDCAST); - - pISMCJob->LoadLogRecordData(pILogRecordDataTable); - - return LIBMCDRIVER_SCANLABSMC_SUCCESS; - } - catch (ELibMCDriver_ScanLabSMCInterfaceException & Exception) { - return handleLibMCDriver_ScanLabSMCException(pIBaseClass, Exception); - } - catch (std::exception & StdException) { - return handleStdException(pIBaseClass, StdException); - } - catch (...) { - return handleUnhandledException(pIBaseClass); - } -} - LibMCDriver_ScanLabSMCResult libmcdriver_scanlabsmc_smcjob_getjobcharacteristic(LibMCDriver_ScanLabSMC_SMCJob pSMCJob, eLibMCDriver_ScanLabSMCJobCharacteristic eValueType, LibMCDriver_ScanLabSMC_double * pValue) { IBase* pIBaseClass = (IBase *)pSMCJob; @@ -2255,10 +2197,6 @@ LibMCDriver_ScanLabSMCResult LibMCDriver_ScanLabSMC::Impl::LibMCDriver_ScanLabSM *ppProcAddress = (void*) &libmcdriver_scanlabsmc_smcjob_stopexecution; if (sProcName == "libmcdriver_scanlabsmc_smcjob_loadsimulationdata") *ppProcAddress = (void*) &libmcdriver_scanlabsmc_smcjob_loadsimulationdata; - if (sProcName == "libmcdriver_scanlabsmc_smcjob_loadsimulationdata_smc_v1") - *ppProcAddress = (void*) &libmcdriver_scanlabsmc_smcjob_loadsimulationdata_smc_v1; - if (sProcName == "libmcdriver_scanlabsmc_smcjob_loadlogrecorddata") - *ppProcAddress = (void*) &libmcdriver_scanlabsmc_smcjob_loadlogrecorddata; if (sProcName == "libmcdriver_scanlabsmc_smcjob_getjobcharacteristic") *ppProcAddress = (void*) &libmcdriver_scanlabsmc_smcjob_getjobcharacteristic; if (sProcName == "libmcdriver_scanlabsmc_smcjob_getjobduration") diff --git a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp index 182f1139..e0c0566a 100644 --- a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp +++ b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp @@ -157,6 +157,7 @@ typedef void * LibMCDriver_ScanLabSMC_pvoid; #define LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCENAME 1049 /** Empty RTC Service DLL Resource Name. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND 1050 /** RTC Service Resource not found. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA 1051 /** Empty RTC Service DLL Resource Data. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED 1052 /** Simulation data loading is not supported for this version. */ /************************************************************************************************************************* Error strings for LibMCDriver_ScanLabSMC @@ -226,6 +227,7 @@ inline const char * LIBMCDRIVER_SCANLABSMC_GETERRORSTRING (LibMCDriver_ScanLabSM case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCENAME: return "Empty RTC Service DLL Resource Name."; case LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND: return "RTC Service Resource not found."; case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA: return "Empty RTC Service DLL Resource Data."; + case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED: return "Simulation data loading is not supported for this version."; default: return "unknown error"; } } From 25bd119694db4fb60dc6a3ce43db813f1edf1d1d Mon Sep 17 00:00:00 2001 From: Yury Rodzikau Date: Fri, 13 Jun 2025 10:14:14 +0200 Subject: [PATCH 2/3] Scanlab SMC Driver: Implemented UTF-8 file path support for Windows in simulation file loading * Added platform-specific handling to support long UTF-8 file paths on Windows using MultiByteToWideChar. * Implemented exception generation in AMCF style. Signed-off-by: Yury Rodzikau --- .../ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml | 7 +- .../libmcdriver_scanlabsmc_dynamic.hpp | 6 ++ .../libmcdriver_scanlabsmc_types.hpp | 6 ++ .../libmcdriver_scanlabsmc_smccsvparser.cpp | 72 +++++++++++++++---- .../libmcdriver_scanlabsmc_smccsvparser.hpp | 37 +++++++++- .../libmcdriver_scanlabsmc_types.hpp | 6 ++ 6 files changed, 119 insertions(+), 15 deletions(-) diff --git a/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml b/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml index b7944cc2..6d6aefa4 100644 --- a/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml +++ b/Drivers/ScanLabSMC/ACT/LibMCDriver_ScanLabSMC.xml @@ -102,8 +102,11 @@ - - + + + + + diff --git a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp index 06755123..b626ab5d 100644 --- a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp +++ b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_dynamic.hpp @@ -240,6 +240,9 @@ class ELibMCDriver_ScanLabSMCException : public std::exception { case LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND: return "RTCSERVICERESOURCENOTFOUND"; case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA: return "EMPTYRTCSERVICEDLLRESOURCEDATA"; case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED: return "SIMULATIONDATALOADINGISNOTSUPPORTED"; + case LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTREADSIMULATIONFILE: return "COULDNOTREADSIMULATIONFILE"; + case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE: return "CSVPARSERUNKNOWNFIELDPARSERTYPE"; + case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE: return "CSVPARSERINTERPOLATEINDEXOUTOFRANGE"; } return "UNKNOWN"; } @@ -310,6 +313,9 @@ class ELibMCDriver_ScanLabSMCException : public std::exception { case LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND: return "RTC Service Resource not found."; case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA: return "Empty RTC Service DLL Resource Data."; case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED: return "Simulation data loading is not supported for this version."; + case LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTREADSIMULATIONFILE: return "Could not read simulation file."; + case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE: return "Unknown Field Parser Type."; + case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE: return "Index out of range in Interpolate."; } return "unknown error"; } diff --git a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp index e0c0566a..ed63d8b5 100644 --- a/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp +++ b/Drivers/ScanLabSMC/Headers/CppDynamic/libmcdriver_scanlabsmc_types.hpp @@ -158,6 +158,9 @@ typedef void * LibMCDriver_ScanLabSMC_pvoid; #define LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND 1050 /** RTC Service Resource not found. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA 1051 /** Empty RTC Service DLL Resource Data. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED 1052 /** Simulation data loading is not supported for this version. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTREADSIMULATIONFILE 1053 /** Could not read simulation file. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE 1054 /** Unknown Field Parser Type. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE 1055 /** Index out of range in Interpolate. */ /************************************************************************************************************************* Error strings for LibMCDriver_ScanLabSMC @@ -228,6 +231,9 @@ inline const char * LIBMCDRIVER_SCANLABSMC_GETERRORSTRING (LibMCDriver_ScanLabSM case LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND: return "RTC Service Resource not found."; case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA: return "Empty RTC Service DLL Resource Data."; case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED: return "Simulation data loading is not supported for this version."; + case LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTREADSIMULATIONFILE: return "Could not read simulation file."; + case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE: return "Unknown Field Parser Type."; + case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE: return "Index out of range in Interpolate."; default: return "unknown error"; } } diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.cpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.cpp index 4336eb71..4762e4b3 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.cpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.cpp @@ -1,4 +1,38 @@ +/*++ + +Copyright (C) 2023 Autodesk Inc. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Autodesk Inc. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL AUTODESK INC. BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Abstract: This is the class definition of CSMCCSVParser + +*/ + #include "libmcdriver_scanlabsmc_smccsvparser.hpp" +#include "libmcdriver_scanlabsmc_interfaceexception.hpp" #include #include @@ -9,13 +43,28 @@ using namespace LibMCDriver_ScanLabSMC::Impl; -CSMCCSVParser::CSMCCSVParser(const std::string& filename, char delimiter) +CSMCCSVParser::CSMCCSVParser(const std::string& sAbsoluteFileNameUTF8, char delimiter) : m_delimiter(delimiter) { - std::ifstream file(filename, std::ios::binary); - if (!file) { - throw std::runtime_error("Failed to open file: " + filename); - } + +#ifdef _WIN32 + if (sAbsoluteFileNameUTF8.length() > 65536) + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDPARAM); + + int nLength = (int)sAbsoluteFileNameUTF8.length(); + int nBufferSize = nLength * 2 + 2; + std::vector wsLibraryFileName(nBufferSize); + int nResult = MultiByteToWideChar(CP_UTF8, 0, sAbsoluteFileNameUTF8.c_str(), nLength, &wsLibraryFileName[0], nBufferSize); + if (nResult == 0) + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_INVALIDSIMULATIONFILENAME); + + std::ifstream file(wsLibraryFileName.data(), std::ios::binary); +#else + std::ifstream file(sAbsoluteFileNameUTF8, std::ios::binary); +#endif + + if (!file.is_open()) + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTOOPENSIMULATIONFILE); file.seekg(0, std::ios::end); std::streamsize size = file.tellg(); @@ -23,7 +72,7 @@ CSMCCSVParser::CSMCCSVParser(const std::string& filename, char delimiter) m_fileBuff.resize(static_cast(size)); if (!file.read(m_fileBuff.data(), size)) { - throw std::runtime_error("Failed to read file content"); + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTREADSIMULATIONFILE); } } @@ -217,7 +266,7 @@ void CSMCCSVParser::ParseValue(const char* data, size_t length, void* target, vo } else { - throw std::runtime_error("ParseValue: Unsupported type"); + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE); } } @@ -246,7 +295,7 @@ void CSMCCSVParser::InterpolateVector(size_t idx_from, size_t idx_to, void* targ if (idx_from >= timestamp->size() || idx_to >= timestamp->size() || idx_from >= position->size() || idx_to >= position->size()) { - throw std::out_of_range("Index out of range in Interpolate."); + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE); } double t0 = timestamp->at(idx_from); @@ -299,7 +348,6 @@ void CSMCCSVParser::ParseString(const char* data, size_t length, void* target, v void CSMCCSVParser::ParseLaserSignal(const char* data, size_t length, void* target, void* ts_target) { - auto* vec = static_cast*>(target); std::vector sub_cycles; @@ -349,7 +397,7 @@ CSMCCSVParser::ParserFunc CSMCCSVParser::GetParser(FieldParserType type) case FieldParserType::LaserSignal: return &CSMCCSVParser::ParseLaserSignal; default: - throw std::invalid_argument("CSMCCSVParser::GetParser - unknown FieldParserType"); + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE); } } @@ -372,7 +420,7 @@ CSMCCSVParser::ExtenderFunc CSMCCSVParser::GetExtender(FieldParserType type) { case FieldParserType::LaserSignal: return nullptr; default: - throw std::invalid_argument("CSMCCSVParser::GetParser - unknown FieldParserType"); + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE); } } @@ -396,7 +444,7 @@ CSMCCSVParser::InterpolatorFunc CSMCCSVParser::GetInterpolator(FieldParserType t case FieldParserType::LaserSignal: return nullptr; default: - throw std::invalid_argument("CSMCCSVParser::GetParser - unknown FieldParserType"); + throw ELibMCDriver_ScanLabSMCInterfaceException(LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE); } } diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.hpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.hpp index 8cc0debb..65330869 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.hpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.hpp @@ -1,6 +1,41 @@ +/*++ + +Copyright (C) 2023 Autodesk Inc. + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the Autodesk Inc. nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL AUTODESK INC. BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + +Abstract: This is the class declaration of CSMCCSVParser + +*/ + #ifndef __LIBMCDRIVER_SCANLABSMC_SMCCSVPARSER #define __LIBMCDRIVER_SCANLABSMC_SMCCSVPARSER +#include "libmcdriver_scanlabsmc_interfaces.hpp" + #include #include #include @@ -175,7 +210,7 @@ namespace Impl { * @param filename Path to the CSV file. * @param delimiter Delimiter character used in the CSV (e.g. ',', ';'). */ - CSMCCSVParser(const std::string& filename, char delimiter); + CSMCCSVParser(const std::string& sAbsoluteFileNameUTF8, char delimiter); /** * @brief Starts parsing the CSV file using user-provided parsers and target vectors. diff --git a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp index e0c0566a..ed63d8b5 100644 --- a/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp +++ b/Drivers/ScanLabSMC/Interfaces/libmcdriver_scanlabsmc_types.hpp @@ -158,6 +158,9 @@ typedef void * LibMCDriver_ScanLabSMC_pvoid; #define LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND 1050 /** RTC Service Resource not found. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA 1051 /** Empty RTC Service DLL Resource Data. */ #define LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED 1052 /** Simulation data loading is not supported for this version. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTREADSIMULATIONFILE 1053 /** Could not read simulation file. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE 1054 /** Unknown Field Parser Type. */ +#define LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE 1055 /** Index out of range in Interpolate. */ /************************************************************************************************************************* Error strings for LibMCDriver_ScanLabSMC @@ -228,6 +231,9 @@ inline const char * LIBMCDRIVER_SCANLABSMC_GETERRORSTRING (LibMCDriver_ScanLabSM case LIBMCDRIVER_SCANLABSMC_ERROR_RTCSERVICERESOURCENOTFOUND: return "RTC Service Resource not found."; case LIBMCDRIVER_SCANLABSMC_ERROR_EMPTYRTCSERVICEDLLRESOURCEDATA: return "Empty RTC Service DLL Resource Data."; case LIBMCDRIVER_SCANLABSMC_ERROR_SIMULATIONDATALOADINGISNOTSUPPORTED: return "Simulation data loading is not supported for this version."; + case LIBMCDRIVER_SCANLABSMC_ERROR_COULDNOTREADSIMULATIONFILE: return "Could not read simulation file."; + case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERUNKNOWNFIELDPARSERTYPE: return "Unknown Field Parser Type."; + case LIBMCDRIVER_SCANLABSMC_ERROR_CSVPARSERINTERPOLATEINDEXOUTOFRANGE: return "Index out of range in Interpolate."; default: return "unknown error"; } } From 01decf1d9657a80bce73e60dc841fddc50301db8 Mon Sep 17 00:00:00 2001 From: Yury Rodzikau Date: Wed, 18 Jun 2025 11:22:35 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Scanlab=20SMC=20Driver:=20Implements=20pars?= =?UTF-8?q?ing=20and=20storing=20the=20=E2=80=9Claseron=E2=80=9D=20signal?= =?UTF-8?q?=20as=20uint32=5Ft=20instead=20of=20bool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Implements parsing and storing the “laseron” signal as uint32_t instead of bool Signed-off-by: Yury Rodzikau --- .../libmcdriver_scanlabsmc_smccsvparser.cpp | 2 +- .../libmcdriver_scanlabsmc_smcjobinstance.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.cpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.cpp index 4762e4b3..3e904b5c 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.cpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smccsvparser.cpp @@ -348,7 +348,7 @@ void CSMCCSVParser::ParseString(const char* data, size_t length, void* target, v void CSMCCSVParser::ParseLaserSignal(const char* data, size_t length, void* target, void* ts_target) { - auto* vec = static_cast*>(target); + auto* vec = static_cast*>(target); std::vector sub_cycles; diff --git a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp index 36dae119..eedddc8d 100644 --- a/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp +++ b/Drivers/ScanLabSMC/Implementation/libmcdriver_scanlabsmc_smcjobinstance.cpp @@ -755,8 +755,8 @@ void CSMCJobInstance::ReadSimulationFile_SMC_v1_0(LibMCEnv::PDataTable pDataTabl std::vector scanheadX; // DisplacedX_Galvo_1 std::vector scanheadY; // DisplacedY_Galvo_1 - std::vector laserSignal; // LaserSignal - std::vector laserToggle; // LaserToggle + std::vector laserSignal; // LaserSignal + std::vector laserToggle; // LaserToggle std::vector activeChannel0; // ActiveChannel0 std::vector activeChannel1; // ActiveChannel1 std::vector cmdCount; // CommandCount @@ -768,7 +768,7 @@ void CSMCJobInstance::ReadSimulationFile_SMC_v1_0(LibMCEnv::PDataTable pDataTabl {{CSMCCSVParser::FieldParserType::Double, CSMCCSVParser::FieldProcessingStep::Extend | CSMCCSVParser::FieldProcessingStep::Interpolate }, &scanheadX}, {{CSMCCSVParser::FieldParserType::Double, CSMCCSVParser::FieldProcessingStep::Extend | CSMCCSVParser::FieldProcessingStep::Interpolate }, &scanheadY}, {{CSMCCSVParser::FieldParserType::LaserSignal,CSMCCSVParser::FieldProcessingStep::Nop}, &laserSignal}, - {{CSMCCSVParser::FieldParserType::Bool,CSMCCSVParser::FieldProcessingStep::Nop}, &laserToggle}, + {{CSMCCSVParser::FieldParserType::UInt32,CSMCCSVParser::FieldProcessingStep::Nop}, &laserToggle}, {{CSMCCSVParser::FieldParserType::None,CSMCCSVParser::FieldProcessingStep::Nop}, nullptr}, {{CSMCCSVParser::FieldParserType::None,CSMCCSVParser::FieldProcessingStep::Nop}, nullptr}, {{CSMCCSVParser::FieldParserType::Int,CSMCCSVParser::FieldProcessingStep::Nop}, &cmdCount}, @@ -788,7 +788,7 @@ void CSMCJobInstance::ReadSimulationFile_SMC_v1_0(LibMCEnv::PDataTable pDataTabl pDataTable->AddColumn("timestamp", "Timestamp", LibMCEnv::eDataTableColumnType::DoubleColumn); pDataTable->AddColumn("x", "X", LibMCEnv::eDataTableColumnType::DoubleColumn); pDataTable->AddColumn("y", "Y", LibMCEnv::eDataTableColumnType::DoubleColumn); - pDataTable->AddColumn("laseron", "LaserOn", LibMCEnv::eDataTableColumnType::Int32Column); + pDataTable->AddColumn("laseron", "LaserOn", LibMCEnv::eDataTableColumnType::Uint32Column); pDataTable->AddColumn("active1", "Active Channel 1", LibMCEnv::eDataTableColumnType::DoubleColumn); pDataTable->AddColumn("active2", "Active Channel 2", LibMCEnv::eDataTableColumnType::DoubleColumn); pDataTable->AddColumn("cmdindex", "Command Index", LibMCEnv::eDataTableColumnType::Int32Column); @@ -804,6 +804,9 @@ void CSMCJobInstance::ReadSimulationFile_SMC_v1_0(LibMCEnv::PDataTable pDataTabl pDataTable->SetDoubleColumnValues("y", scanheadY); scanheadY.resize(0); + + pDataTable->SetUint32ColumnValues("laseron", laserSignal); + laserSignal.resize(0); } void CSMCJobInstance::ReadLogRecordFile(LibMCEnv::PDataTable pDataTable) @@ -832,7 +835,7 @@ void CSMCJobInstance::ReadLogRecordFile(LibMCEnv::PDataTable pDataTable) std::vector timestampValues; std::vector scanheadX; std::vector scanheadY; - std::vector laserSignal; + std::vector laserSignal; std::vector bindings = { {{CSMCCSVParser::FieldParserType::Double, CSMCCSVParser::FieldProcessingStep::Extend | CSMCCSVParser::FieldProcessingStep::Interpolate }, &scanheadX}, @@ -854,7 +857,7 @@ void CSMCJobInstance::ReadLogRecordFile(LibMCEnv::PDataTable pDataTable) pDataTable->AddColumn("timestamp", "Timestamp", LibMCEnv::eDataTableColumnType::DoubleColumn); pDataTable->AddColumn("x", "X", LibMCEnv::eDataTableColumnType::DoubleColumn); pDataTable->AddColumn("y", "Y", LibMCEnv::eDataTableColumnType::DoubleColumn); - pDataTable->AddColumn("laseron", "LaserOn", LibMCEnv::eDataTableColumnType::Int32Column); + pDataTable->AddColumn("laseron", "LaserOn", LibMCEnv::eDataTableColumnType::Uint32Column); pDataTable->AddColumn("active1", "Active Channel 1", LibMCEnv::eDataTableColumnType::DoubleColumn); pDataTable->AddColumn("active2", "Active Channel 2", LibMCEnv::eDataTableColumnType::DoubleColumn); pDataTable->AddColumn("cmdindex", "Command Index", LibMCEnv::eDataTableColumnType::Int32Column); @@ -870,6 +873,9 @@ void CSMCJobInstance::ReadLogRecordFile(LibMCEnv::PDataTable pDataTable) pDataTable->SetDoubleColumnValues("y", scanheadY); scanheadY.resize(0); + + pDataTable->SetUint32ColumnValues("laseron", laserSignal); + laserSignal.resize(0); } void CSMCJobInstance::AddLayerToList(LibMCEnv::PToolpathLayer pLayer)