Salome HOME
import image: add python dump
authorrraphael <raphael.raphael@c-s.fr>
Tue, 12 Jan 2021 21:23:48 +0000 (22:23 +0100)
committerrraphael <raphael.raphael@c-s.fr>
Fri, 15 Jan 2021 11:14:02 +0000 (12:14 +0100)
src/ExchangeAPI/ExchangeAPI.i
src/ExchangeAPI/ExchangeAPI_Import.cpp
src/ExchangeAPI/ExchangeAPI_Import.h
src/PythonAPI/model/exchange/__init__.py

index 173e1a6d2af23fba5abc78e87f9219cba2b9d14e..160d4f8f1649a5e57851a41b236fc8affeb6d7d6 100644 (file)
@@ -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"
index f12ea5dc6d3059230ddd7bc9498c957b2ddb4fe9..d17f3bfa8e7a1bc6afad585f5543d911878ab083 100644 (file)
@@ -205,3 +205,51 @@ void importPart(const std::shared_ptr<ModelAPI_Document> & thePart,
   if (aCurrentFeature)
     thePart->setCurrentFeature(aCurrentFeature, THE_VISIBLE_FEATURE);
 }
+
+//-------------------------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
+
+ExchangeAPI_Import_Image::ExchangeAPI_Import_Image(
+    const std::shared_ptr<ModelAPI_Feature> & theFeature)
+: ModelHighAPI_Interface(theFeature)
+{
+  initialize();
+}
+
+ExchangeAPI_Import_Image::ExchangeAPI_Import_Image(
+    const std::shared_ptr<ModelAPI_Feature> & 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<ModelAPI_Document> & thePart,
+    const std::string & theFilePath)
+{
+  std::shared_ptr<ModelAPI_Feature> 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;
+}
+
index d3403e54416156d7184650ff226c7c543988c0d0..61f4c7bb905804d3c91e3e0bd43f57f03ce19e88 100644 (file)
@@ -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<ModelAPI_Feature> & theFeature);
+  /// Constructor with values
+  EXCHANGEAPI_EXPORT
+  ExchangeAPI_Import_Image(const std::shared_ptr<ModelAPI_Feature> & 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<ExchangeAPI_Import_Image> ImportImagePtr;
+
+
+EXCHANGEAPI_EXPORT
+ImportImagePtr addImportImage(const std::shared_ptr<ModelAPI_Document> & thePart,
+                    const std::string & theFilePath);
+
 //--------------------------------------------------------------------------------------
 #endif /* SRC_EXCHANGEAPI_EXCHANGEAPI_IMPORT_H_ */
index 800ab45f9e2f4366a234f0413a804a6c162d6755..c8ca2ad4c7849810162e98d3711e880b51b5bf44 100644 (file)
@@ -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 *