/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// #ifndef _EX_STEP_TUTOTRIALS_COMMON_H_ #define _EX_STEP_TUTOTRIALS_COMMON_H_ #include "OdAnsiString.h" #include "OdString.h" #include "ExPrintConsole.h" #include #include #include #include #ifndef _WIN32 #include #endif #ifdef __APPLE__ #include #endif #if defined(OD_USE_WMAIN) #define tut_main wmain #define tut_main_char wchar_t #define tut_main_char_to_string(char_buf) OdString(char_buf) #else #define tut_main main #define tut_main_char char #define tut_main_char_to_string(char_buf) OdAnsiString(char_buf) #endif #ifdef _DEBUG // uncomment for debug attach // #define MAKE_PAUSE_ON_START #endif class ExStepServices; namespace StepTutorial { const OdString applicationName = "ExStepTutorials"; } namespace StepTutorial { enum class ExecutionResult { eSucceed, eFailed, eWrongParams, eShowHelp, }; using TutorialExecutor = std::function&, std::ostream&)>; struct StepTutorialData { StepTutorialData(OdAnsiString name_, TutorialExecutor executor_) : name(name_) , executor(executor_) { } OdAnsiString name; TutorialExecutor executor; }; using StepTutorialDataPtr = std::shared_ptr; using StepTutorialDataCollection = std::vector; #define REGISTER_TUTORIAL(FunctionName) std::make_shared\ (\ OdAnsiString(#FunctionName).makeLower(),\ [](const ExStepServices& service, const std::vector& params, std::ostream& output) -> StepTutorial::ExecutionResult \ {\ return FunctionName(service, params, output);\ }\ ) inline void showTutorialHelp(const ExStepServices& svcs, StepTutorialDataCollection& tutorialCollection, std::ostream& executionStream) { executionStream << "\n\nList of available tutorials and its parameters descriptions: "; int tutorialNumber = 1; std::vector fakeArgs = { "-help" }; for (auto& tutorial : tutorialCollection) { executionStream << std::endl << tutorialNumber << ". Tutorial: " << tutorial->name << std::endl; tutorial->executor(svcs, fakeArgs, executionStream); ++tutorialNumber; } } class WorkDir { public: static const OdAnsiString& getPath() { return workDir; } static void setPath(const OdAnsiString& newWorkPath) { workDir = newWorkPath; } private: static OdAnsiString workDir; }; class ExecutionStreamWrapper { public: ~ExecutionStreamWrapper() { odPrintConsoleString(OdString(executionStream.str().c_str())); } operator std::ostream& () { return executionStream; } private: std::stringstream executionStream; }; inline OdString getExecutablePath() { #ifdef _WIN32 wchar_t path[MAX_PATH] = { 0 }; GetModuleFileNameW(NULL, path, MAX_PATH); return path; #elif __APPLE__ char result[PATH_MAX]; uint32_t count = PATH_MAX; if (!_NSGetExecutablePath(result, &count)) { return OdString(result, count); } return OdString(); #else char result[PATH_MAX]; ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); result[count] = 0; return OdString(result); #endif } } #endif