From f1adf8e96ca2fd04ea386a9f01da566c3a2c61c1 Mon Sep 17 00:00:00 2001 From: rraphael Date: Tue, 12 Jan 2021 22:23:48 +0100 Subject: [PATCH] import image: add python dump --- src/ExchangeAPI/ExchangeAPI.i | 1 + src/ExchangeAPI/ExchangeAPI_Import.cpp | 48 ++++++++++++++++++++++++ src/ExchangeAPI/ExchangeAPI_Import.h | 43 +++++++++++++++++++++ src/PythonAPI/model/exchange/__init__.py | 2 +- 4 files changed, 93 insertions(+), 1 deletion(-) diff --git a/src/ExchangeAPI/ExchangeAPI.i b/src/ExchangeAPI/ExchangeAPI.i index 173e1a6d2..160d4f8f1 100644 --- a/src/ExchangeAPI/ExchangeAPI.i +++ b/src/ExchangeAPI/ExchangeAPI.i @@ -41,6 +41,7 @@ // shared pointers %shared_ptr(ExchangeAPI_Export) %shared_ptr(ExchangeAPI_Import) +%shared_ptr(ExchangeAPI_Import_Image) // all supported interfaces %include "ExchangeAPI_Export.h" diff --git a/src/ExchangeAPI/ExchangeAPI_Import.cpp b/src/ExchangeAPI/ExchangeAPI_Import.cpp index f12ea5dc6..d17f3bfa8 100644 --- a/src/ExchangeAPI/ExchangeAPI_Import.cpp +++ b/src/ExchangeAPI/ExchangeAPI_Import.cpp @@ -205,3 +205,51 @@ void importPart(const std::shared_ptr & thePart, if (aCurrentFeature) thePart->setCurrentFeature(aCurrentFeature, THE_VISIBLE_FEATURE); } + +//------------------------------------------------------------------------------------------------- +//------------------------------------------------------------------------------------------------- + +ExchangeAPI_Import_Image::ExchangeAPI_Import_Image( + const std::shared_ptr & theFeature) +: ModelHighAPI_Interface(theFeature) +{ + initialize(); +} + +ExchangeAPI_Import_Image::ExchangeAPI_Import_Image( + const std::shared_ptr & theFeature, + const std::string & theFilePath) +: ModelHighAPI_Interface(theFeature) +{ + if (initialize()) + setFilePath(theFilePath); +} + +void ExchangeAPI_Import_Image::setFilePath(const std::string & theFilePath) +{ + fillAttribute(theFilePath, myfilePath); + execute(); +} + +ImportImagePtr addImportImage( + const std::shared_ptr & thePart, + const std::string & theFilePath) +{ + std::shared_ptr aFeature = thePart->addFeature(ExchangeAPI_Import_Image::ID()); + return ImportImagePtr(new ExchangeAPI_Import_Image(aFeature, theFilePath)); +} + +void ExchangeAPI_Import_Image::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + std::string aPartName = theDumper.name(aBase->document()); + + std::string aFilePath = aBase->string(ExchangePlugin_Import_ImageFeature::FILE_PATH_ID())->value(); + + theDumper << aBase << " = model.addImportImage(" << aPartName << ", \"" + << aFilePath << "\")" << std::endl; + + // to make import have results + theDumper << "model.do()" << std::endl; +} + diff --git a/src/ExchangeAPI/ExchangeAPI_Import.h b/src/ExchangeAPI/ExchangeAPI_Import.h index d3403e544..61f4c7bb9 100644 --- a/src/ExchangeAPI/ExchangeAPI_Import.h +++ b/src/ExchangeAPI/ExchangeAPI_Import.h @@ -118,5 +118,48 @@ EXCHANGEAPI_EXPORT void importPart( const ModelHighAPI_Reference & theAfterThis = ModelHighAPI_Reference()); //-------------------------------------------------------------------------------------- +//-------------------------------------------------------------------------------------- +/**\class ExchangeAPI_Import_Image + * \ingroup CPPHighAPI + * \brief Interface for Import feature + */ +class ExchangeAPI_Import_Image : public ModelHighAPI_Interface +{ +public: + /// Constructor without values + EXCHANGEAPI_EXPORT + explicit ExchangeAPI_Import_Image(const std::shared_ptr & theFeature); + /// Constructor with values + EXCHANGEAPI_EXPORT + ExchangeAPI_Import_Image(const std::shared_ptr & theFeature, + const std::string & theFilePath); + + /// Destructor + EXCHANGEAPI_EXPORT + virtual ~ExchangeAPI_Import_Image() = default; + + INTERFACE_1(ExchangePlugin_Import_ImageFeature::ID(), + filePath, ExchangePlugin_Import_ImageFeature::FILE_PATH_ID(), + ModelAPI_AttributeString, /** File path */ + ) + + /// Set point values + EXCHANGEAPI_EXPORT + void setFilePath(const std::string & theFilePath); + + /// Dump wrapped feature + EXCHANGEAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; + +}; + +//! Pointer on Import object +typedef std::shared_ptr ImportImagePtr; + + +EXCHANGEAPI_EXPORT +ImportImagePtr addImportImage(const std::shared_ptr & thePart, + const std::string & theFilePath); + //-------------------------------------------------------------------------------------- #endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_IMPORT_H_ */ diff --git a/src/PythonAPI/model/exchange/__init__.py b/src/PythonAPI/model/exchange/__init__.py index 800ab45f9..c8ca2ad4c 100644 --- a/src/PythonAPI/model/exchange/__init__.py +++ b/src/PythonAPI/model/exchange/__init__.py @@ -20,6 +20,6 @@ """ from ExchangeAPI import addImport, addImportSTEP, exportToFile, exportToXAO, exportToSTL -from ExchangeAPI import exportPart, importPart +from ExchangeAPI import exportPart, importPart, addImportImage from .tools import * -- 2.39.2