]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
add Picture import
authorrraphael <raphael.raphael@c-s.fr>
Sat, 5 Dec 2020 16:51:22 +0000 (17:51 +0100)
committerrraphael <raphael.raphael@c-s.fr>
Fri, 15 Jan 2021 11:10:10 +0000 (12:10 +0100)
13 files changed:
src/ExchangePlugin/ExchangePlugin_Import.cpp
src/ExchangePlugin/ExchangePlugin_Import.h
src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp
src/ExchangePlugin/ExchangePlugin_ImportFeature.h
src/ExchangePlugin/ExchangePlugin_Plugin.cpp
src/ExchangePlugin/plugin-Exchange.xml
src/GeomAlgoAPI/CMakeLists.txt
src/GeomAlgoAPI/GeomAlgoAPI_ImageImport.cpp [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_ImageImport.h [new file with mode: 0644]
src/ModelAPI/ModelAPI_Object.h
src/PartSet/PartSet_Module.cpp
src/XGUI/XGUI_Workshop.cpp
src/XGUI/XGUI_Workshop.h

index e9b0415827ae27f4c6dfef6a464029779936ed89..6157782b1a739c7b8dfc6e51b3ceb5ad6ad7fbd6 100644 (file)
@@ -67,25 +67,22 @@ DocumentPtr findDocument(DocumentPtr thePartSetDoc, const std::wstring& thePartN
 }
 
 
-ExchangePlugin_Import::ExchangePlugin_Import()
-{
-}
-
-ExchangePlugin_Import::~ExchangePlugin_Import()
-{
-  // TODO Auto-generated destructor stub
-}
-
 /*
  * Request for initialization of data model of the feature: adding all attributes
  */
-void ExchangePlugin_Import::initAttributes()
+void ExchangePlugin_ImportBase::initAttributes()
 {
   data()->addAttribute(FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(STEP_FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
-  data()->addAttribute(IMPORT_TYPE_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(TARGET_PART_ID(), ModelAPI_AttributeInteger::typeId());
-  data()->addAttribute(TARGET_PARTS_LIST_ID(), ModelAPI_AttributeStringArray::typeId());
+  data()->addAttribute(TARGET_PARTS_LIST_ID(), ModelAPI_AttributeStringArray::typeId()); 
+}
+
+void ExchangePlugin_Import::initAttributes()
+{
+  ExchangePlugin_ImportBase::initAttributes();
+
+  data()->addAttribute(STEP_FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
+  data()->addAttribute(IMPORT_TYPE_ID(), ModelAPI_AttributeString::typeId()); 
   data()->addAttribute(STEP_TARGET_PART_ID(), ModelAPI_AttributeInteger::typeId());
   data()->addAttribute(STEP_TARGET_PARTS_LIST_ID(), ModelAPI_AttributeStringArray::typeId());
   data()->addAttribute(STEP_MATERIALS_ID(), ModelAPI_AttributeBoolean::typeId());
@@ -96,12 +93,12 @@ void ExchangePlugin_Import::initAttributes()
 /*
  * Computes or recomputes the results
  */
+
 void ExchangePlugin_Import::execute()
 {
   AttributeStringPtr aFormatAttr =
       this->string(ExchangePlugin_Import::IMPORT_TYPE_ID());
   std::string aFormat = aFormatAttr->value();
-
   AttributeStringPtr aFilePathAttr;
   std::string aFilePath;
   AttributeStringArrayPtr aPartsAttr;
@@ -142,23 +139,45 @@ void ExchangePlugin_Import::execute()
     }
 
     AttributeStringPtr aImportTypeAttr =
-                        aData->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID());
+        aData->string(ExchangePlugin_ImportFeature::IMPORT_TYPE_ID());
 
     aData->boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())
-         ->setValue(boolean(ExchangePlugin_Import::STEP_MATERIALS_ID())->value());
+        ->setValue(boolean(ExchangePlugin_Import::STEP_MATERIALS_ID())->value());
     aData->boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())
-         ->setValue(boolean(ExchangePlugin_Import::STEP_COLORS_ID())->value());
+        ->setValue(boolean(ExchangePlugin_Import::STEP_COLORS_ID())->value());
     aData->boolean(ExchangePlugin_ImportFeature::STEP_SCALE_INTER_UNITS_ID())
-         ->setValue(boolean(ExchangePlugin_Import::STEP_SCALE_INTER_UNITS_ID())->value());
+        ->setValue(boolean(ExchangePlugin_Import::STEP_SCALE_INTER_UNITS_ID())->value());
 
     aPathAttr->setValue(aFilePathAttr->value());
     aImportTypeAttr->setValue(aFormat);
-
     aImportFeature->execute();
   }
 }
 
+void ExchangePlugin_Import_Image::execute()
+{
+ AttributeStringPtr aFilePathAttr = string(ExchangePlugin_ImportBase::FILE_PATH_ID());
+  std::string aFilePath = aFilePathAttr->value();
+  if (aFilePath.empty()) {
+    setError("File path is empty.");
+    return;
+  }
+
+  // get the document where to import
+  AttributeStringArrayPtr aPartsAttr = stringArray(TARGET_PARTS_LIST_ID());
+  AttributeIntegerPtr aTargetAttr = integer(TARGET_PART_ID());
+  SessionPtr aSession = ModelAPI_Session::get();
+  DocumentPtr aDoc = findDocument(aSession->moduleDocument(),
+      Locale::Convert::toWString(aPartsAttr->value(aTargetAttr->value())));
 
+  if (aDoc.get()) {
+    FeaturePtr aImportFeature = aDoc->addFeature(ExchangePlugin_Import_ImageFeature::ID());
+    DataPtr aData = aImportFeature->data();
+    AttributeStringPtr aPathAttr = aData->string(ExchangePlugin_Import_ImageFeature::FILE_PATH_ID());
+    aPathAttr->setValue(aFilePathAttr->value());
+    aImportFeature->execute();
+  }
+}
 void ExchangePlugin_Import::attributeChanged(const std::string& theID)
 {
   AttributeStringPtr aFilePathAttr;
@@ -184,41 +203,55 @@ void ExchangePlugin_Import::attributeChanged(const std::string& theID)
    }
 }
 
-void ExchangePlugin_Import::updatePart(AttributeStringArrayPtr& thePartsAttr,
-                                       AttributeIntegerPtr& theTargetAttr)
+void ExchangePlugin_Import_Image::attributeChanged(const std::string& theID)
 {
-    // update the list of target parts
-    SessionPtr aSession = ModelAPI_Session::get();
-    DocumentPtr aDoc = document();
-    bool isPartSet = aDoc == aSession->moduleDocument();
-    if (isPartSet) {
-      std::list<std::wstring> anAcceptedValues;
-      anAcceptedValues.push_back(THE_NEW_PART_STR);
-
-      // append names of all parts
-      std::list<FeaturePtr> aSubFeatures = aDoc->allFeatures();
-      for (std::list<FeaturePtr>::iterator aFIt = aSubFeatures.begin();
-        aFIt != aSubFeatures.end(); ++aFIt) {
-        if ((*aFIt)->getKind() == PartSetPlugin_Part::ID())
-          anAcceptedValues.push_back((*aFIt)->name());
-      }
+  if (theID == FILE_PATH_ID()) {
+    AttributeStringPtr aFilePathAttr = string(FILE_PATH_ID());
+    if (aFilePathAttr->value().empty())
+      return;
 
-      if ((size_t)thePartsAttr->size() != anAcceptedValues.size())
-        theTargetAttr->setValue(0);
+    AttributeStringArrayPtr aPartsAttr = stringArray(TARGET_PARTS_LIST_ID());
+    AttributeIntegerPtr aTargetAttr = integer(TARGET_PART_ID());
+    updatePart(aPartsAttr, aTargetAttr);
+  }
+}
 
-      thePartsAttr->setSize((int)anAcceptedValues.size());
-      std::list<std::wstring>::iterator anIt = anAcceptedValues.begin();
-      for (int anInd = 0; anIt != anAcceptedValues.end(); ++anIt, ++anInd)
-        thePartsAttr->setValue(anInd, Locale::Convert::toString(*anIt));
+void ExchangePlugin_ImportBase::updatePart(AttributeStringArrayPtr& aPartsAttr,
+                                       AttributeIntegerPtr& aTargetAttr)
+{
+
+  // update the list of target parts
+  SessionPtr aSession = ModelAPI_Session::get();
+  DocumentPtr aDoc = document();
+  bool isPartSet = aDoc == aSession->moduleDocument();
+  if (isPartSet) {
+    std::list<std::wstring> anAcceptedValues;
+    anAcceptedValues.push_back(THE_NEW_PART_STR);
+
+    // append names of all parts
+    std::list<FeaturePtr> aSubFeatures = aDoc->allFeatures();
+    for (std::list<FeaturePtr>::iterator aFIt = aSubFeatures.begin();
+         aFIt != aSubFeatures.end(); ++aFIt) {
+      if ((*aFIt)->getKind() == PartSetPlugin_Part::ID())
+        anAcceptedValues.push_back((*aFIt)->name());
     }
-    else {
-      // keep only the name of the current part
-      if (thePartsAttr->size() == 0) {
-        FeaturePtr aPartFeature = ModelAPI_Tools::findPartFeature(aSession->moduleDocument(), aDoc);
-
-        thePartsAttr->setSize(1);
-        thePartsAttr->setValue(0, Locale::Convert::toString(aPartFeature->name()));
-        theTargetAttr->setValue(0);
-      }
+
+    if ((size_t)aPartsAttr->size() != anAcceptedValues.size())
+      aTargetAttr->setValue(0);
+
+    aPartsAttr->setSize((int)anAcceptedValues.size());
+    std::list<std::wstring>::iterator anIt = anAcceptedValues.begin();
+    for (int anInd = 0; anIt != anAcceptedValues.end(); ++anIt, ++anInd)
+      aPartsAttr->setValue(anInd, Locale::Convert::toString(*anIt));
+  }
+  else {
+    // keep only the name of the current part
+    if (aPartsAttr->size() == 0) {
+      FeaturePtr aPartFeature = ModelAPI_Tools::findPartFeature(aSession->moduleDocument(), aDoc);
+
+      aPartsAttr->setSize(1);
+      aPartsAttr->setValue(0, Locale::Convert::toString(aPartFeature->name()));
+      aTargetAttr->setValue(0);
     }
+  }
 }
index eeac517943217320b69804add40fb0a5a0e5726e..7bb2928947979096adba1cc7948db9dbcb751246 100644 (file)
@@ -26,9 +26,9 @@
 #include <ModelAPI_Result.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_AttributeStringArray.h>
-
 #include <map>
 
+
 /**
  * \class ExchangePlugin_ImportFeature
  * \ingroup Plugins
  *
  * The list of supported formats is defined in the configuration file.
  */
-class ExchangePlugin_Import : public ModelAPI_Feature
+class ExchangePlugin_ImportBase : public ModelAPI_Feature
 {
- public:
-  /// Feature kind
-  inline static const std::string& ID()
-  {
-    static const std::string MY_IMPORT_ID("ImportMacro");
-    return MY_IMPORT_ID;
-  }
-  /// Feature kind
-  inline static const std::string& IMPORT_TYPE_ID()
-  {
-    static const std::string MY_IMPORT_TYPE_ID("ImportType");
-    return MY_IMPORT_TYPE_ID;
-  }
+ public:  
   /// attribute name of file path
   inline static const std::string& FILE_PATH_ID()
   {
@@ -69,7 +57,50 @@ class ExchangePlugin_Import : public ModelAPI_Feature
     static const std::string MY_TARGET_PARTS_LIST_ID("target_parts_list");
     return MY_TARGET_PARTS_LIST_ID;
   }
-  /// attribute name of step file path
+  /// Default constructor
+  EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportBase()= default;
+  /// Default destructor
+  EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ImportBase()= default;
+
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
+
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  EXCHANGEPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID) = 0;
+
+  /// Computes or recomputes the results
+  EXCHANGEPLUGIN_EXPORT virtual void execute() = 0;
+
+  /// Returns true if this feature is used as macro: creates other features and then removed.
+  EXCHANGEPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+
+  /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
+  EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
+
+ protected:
+
+  EXCHANGEPLUGIN_EXPORT void  updatePart(AttributeStringArrayPtr& aPartsAttr,
+                                         AttributeIntegerPtr& aTargetAttr);
+};
+
+EXCHANGEPLUGIN_EXPORT class ExchangePlugin_Import : public ExchangePlugin_ImportBase
+{
+ public:
+  /// Feature kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_IMPORT_ID("ImportMacro");
+    return MY_IMPORT_ID;
+  }
+ /// Feature kind
+  inline static const std::string& IMPORT_TYPE_ID()
+  {
+    static const std::string MY_IMPORT_TYPE_ID("ImportType");
+    return MY_IMPORT_TYPE_ID;
+  }
+ /// attribute name of step file path
   inline static const std::string& STEP_FILE_PATH_ID()
   {
     static const std::string MY_STEP_FILE_PATH_ID("step_file_path");
@@ -106,36 +137,55 @@ class ExchangePlugin_Import : public ModelAPI_Feature
     return MY_STEP_COLORS_ID;
   }
   /// Default constructor
-  EXCHANGEPLUGIN_EXPORT ExchangePlugin_Import();
+  EXCHANGEPLUGIN_EXPORT ExchangePlugin_Import() = default;
   /// Default destructor
-  EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_Import();
+  EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_Import() = default;
 
   /// Returns the unique kind of a feature
-  EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind()
+  EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind() override
   {
     return ExchangePlugin_Import::ID();
   }
+  /// Computes or recomputes the results
+  EXCHANGEPLUGIN_EXPORT virtual void execute() override;
 
   /// Request for initialization of data model of the feature: adding all attributes
   EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
 
-  /// Called on change of any argument-attribute of this object
-  /// \param theID identifier of changed attribute
-  EXCHANGEPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+  // Called on change of any argument-attribute of this object
+    /// \param theID identifier of changed attribute
+  EXCHANGEPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID) override;
 
-  /// Computes or recomputes the results
-  EXCHANGEPLUGIN_EXPORT virtual void execute();
+};
 
-  /// Returns true if this feature is used as macro: creates other features and then removed.
-  EXCHANGEPLUGIN_EXPORT virtual bool isMacro() const { return true; }
+EXCHANGEPLUGIN_EXPORT class ExchangePlugin_Import_Image : public ExchangePlugin_ImportBase
+{
+ public:
+  /// Feature kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_IMPORT_ID("ImportImageMacro");
+    return MY_IMPORT_ID;
+  }
 
-  /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
-  EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
+  /// Default constructor
+  EXCHANGEPLUGIN_EXPORT ExchangePlugin_Import_Image() = default;
+  /// Default destructor
+  EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_Import_Image() = default;
+
+  /// Returns the unique kind of a feature
+  EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind() override
+  {
+    return ExchangePlugin_Import_Image::ID();
+  }
+
+  /// Computes or recomputes the results
+  EXCHANGEPLUGIN_EXPORT virtual void execute() override;
+
+  // Called on change of any argument-attribute of this object
+    /// \param theID identifier of changed attribute
+  EXCHANGEPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID) override;
 
- private:
-  /// Called to update part
-  EXCHANGEPLUGIN_EXPORT
-  void updatePart(AttributeStringArrayPtr& thePartsAttr, AttributeIntegerPtr& theTargetAttr);
 };
 
 #endif /* IMPORT_IMPORTFEATURE_H_ */
index ee9e7a79893a365a2a25e5bd3a8affb7c959969d..dd87d800cfd9f01ee6ce5ca6e6ae929bbe712dd5 100644 (file)
@@ -31,6 +31,7 @@
 #include <GeomAlgoAPI_Tools.h>
 #include <GeomAlgoAPI_XAOImport.h>
 #include <GeomAlgoAPI_STLImport.h>
+#include <GeomAlgoAPI_ImageImport.h>
 
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_Face.h>
 #include <ExchangePlugin_Tools.h>
 
 
-
-ExchangePlugin_ImportFeature::ExchangePlugin_ImportFeature()
-{
-}
-
-ExchangePlugin_ImportFeature::~ExchangePlugin_ImportFeature()
-{
-  // TODO Auto-generated destructor stub
-}
-
 /*
  * Request for initialization of data model of the feature: adding all attributes
  */
-void ExchangePlugin_ImportFeature::initAttributes()
+void ExchangePlugin_ImportFeatureBase::initAttributes()
 {
-  data()->addAttribute(ExchangePlugin_ImportFeature::FILE_PATH_ID(),
+  data()->addAttribute(ExchangePlugin_ImportFeatureBase::FILE_PATH_ID(),
                        ModelAPI_AttributeString::typeId());
   AttributePtr aFeaturesAttribute =
-  data()->addAttribute(ExchangePlugin_ImportFeature::FEATURES_ID(),
+    data()->addAttribute(ExchangePlugin_ImportFeatureBase::FEATURES_ID(),
                          ModelAPI_AttributeRefList::typeId());
+  aFeaturesAttribute->setIsArgument(false);
+
+  ModelAPI_Session::get()->validators()->registerNotObligatory(
+      getKind(), ExchangePlugin_ImportFeatureBase::FEATURES_ID());
+}
+
+void ExchangePlugin_ImportFeature::initAttributes()
+{
+  ExchangePlugin_ImportFeatureBase::initAttributes();
+   
   data()->addAttribute(STEP_FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(IMPORT_TYPE_ID(), ModelAPI_AttributeString::typeId());
   data()->addAttribute(STEP_MATERIALS_ID(), ModelAPI_AttributeBoolean::typeId());
   data()->addAttribute(STEP_COLORS_ID(), ModelAPI_AttributeBoolean::typeId());
   data()->addAttribute(STEP_SCALE_INTER_UNITS_ID(), ModelAPI_AttributeBoolean::typeId());
-
-  aFeaturesAttribute->setIsArgument(false);
-
-  ModelAPI_Session::get()->validators()->registerNotObligatory(
-      getKind(), ExchangePlugin_ImportFeature::FEATURES_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(
       getKind(), ExchangePlugin_ImportFeature::STEP_COLORS_ID());
   ModelAPI_Session::get()->validators()->registerNotObligatory(
@@ -106,7 +103,6 @@ void ExchangePlugin_ImportFeature::initAttributes()
   ModelAPI_Session::get()->validators()->registerNotObligatory(
       getKind(), ExchangePlugin_ImportFeature::FILE_PATH_ID());
 }
-
 /*
  * Computes or recomputes the results
  */
@@ -130,12 +126,23 @@ void ExchangePlugin_ImportFeature::execute()
   importFile(aFilePath);
 }
 
-std::shared_ptr<ModelAPI_ResultBody> ExchangePlugin_ImportFeature::createResultBody(
-                        std::shared_ptr<GeomAPI_Shape> theGeomShape)
+void ExchangePlugin_Import_ImageFeature::execute()
+{
+  AttributeStringPtr aFilePathAttr = string(ExchangePlugin_Import_ImageFeature::FILE_PATH_ID());
+  std::string aFilePath = aFilePathAttr->value();
+  if (aFilePath.empty()) {
+    setError("File path is empty.");
+    return;
+  }
+  importFile(aFilePath);
+}
+
+std::shared_ptr<ModelAPI_ResultBody> ExchangePlugin_ImportFeatureBase::createResultBody(
+    std::shared_ptr<GeomAPI_Shape> aGeomShape)
 {
   std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
   //LoadNamingDS of the imported shape
-  loadNamingDS(theGeomShape, aResultBody);
+  loadNamingDS(aGeomShape, aResultBody);
   return aResultBody;
 }
 
@@ -152,7 +159,6 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
   // Perform the import
   std::string anError;
   std::shared_ptr<GeomAPI_Shape> aGeomShape;
-
   std::map<std::wstring, std::list<std::wstring>> theMaterialShape;
 
   std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
@@ -163,7 +169,6 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
   bool anColorGroupSelected = boolean(ExchangePlugin_ImportFeature::STEP_COLORS_ID())->value();
   bool anMaterialsGroupSelected =
                         boolean(ExchangePlugin_ImportFeature::STEP_MATERIALS_ID())->value();
-
   if (anExtension == "BREP" || anExtension == "BRP") {
     aGeomShape = BREPImport(theFileName, anExtension, anError);
   } else if (anExtension == "STEP" || anExtension == "STP") {
@@ -190,7 +195,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
     aGeomShape = IGESImport(theFileName, anExtension, anError);
   } else if (anExtension == "STL") {
     aGeomShape = STLImport(theFileName, anError);
-  } else {
+  }  else {
     anError = "Unsupported format: " + anExtension;
   }
 
@@ -201,7 +206,7 @@ void ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
   }
 
   // Pass the results into the model
-
   loadNamingDS(aGeomShape, aResult);
 
   // create color group
@@ -536,7 +541,7 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName)
 }
 
 //============================================================================
-std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::addFeature(
+std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeatureBase::addFeature(
     std::string theID)
 {
   std::shared_ptr<ModelAPI_Feature> aNew = document()->addFeature(theID, false);
@@ -548,7 +553,7 @@ std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::addFeature(
 }
 
 // LCOV_EXCL_START
-void ExchangePlugin_ImportFeature::removeFeature(
+void ExchangePlugin_ImportFeatureBase::removeFeature(
     std::shared_ptr<ModelAPI_Feature> theFeature)
 {
   if (!data()->isValid())
@@ -558,12 +563,12 @@ void ExchangePlugin_ImportFeature::removeFeature(
 }
 // LCOV_EXCL_STOP
 
-int ExchangePlugin_ImportFeature::numberOfSubs(bool /*forTree*/) const
+int ExchangePlugin_ImportFeatureBase::numberOfSubs(bool /*forTree*/) const
 {
   return data()->reflist(FEATURES_ID())->size(true);
 }
 
-std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::subFeature(
+std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeatureBase::subFeature(
     const int theIndex, bool /*forTree*/)
 {
   ObjectPtr anObj = data()->reflist(FEATURES_ID())->object(theIndex, false);
@@ -572,7 +577,7 @@ std::shared_ptr<ModelAPI_Feature> ExchangePlugin_ImportFeature::subFeature(
 }
 
 // LCOV_EXCL_START
-int ExchangePlugin_ImportFeature::subFeatureId(const int theIndex) const
+int ExchangePlugin_ImportFeatureBase::subFeatureId(const int theIndex) const
 {
   std::shared_ptr<ModelAPI_AttributeRefList> aRefList = std::dynamic_pointer_cast<
       ModelAPI_AttributeRefList>(data()->attribute(FEATURES_ID()));
@@ -591,7 +596,7 @@ int ExchangePlugin_ImportFeature::subFeatureId(const int theIndex) const
 }
 // LCOV_EXCL_STOP
 
-bool ExchangePlugin_ImportFeature::isSub(ObjectPtr theObject) const
+bool ExchangePlugin_ImportFeatureBase::isSub(ObjectPtr theObject) const
 {
   // check is this feature of result
   FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
@@ -601,12 +606,48 @@ bool ExchangePlugin_ImportFeature::isSub(ObjectPtr theObject) const
 }
 
 //============================================================================
-void ExchangePlugin_ImportFeature::loadNamingDS(
+void ExchangePlugin_ImportFeatureBase::loadNamingDS(
     std::shared_ptr<GeomAPI_Shape> theGeomShape,
     std::shared_ptr<ModelAPI_ResultBody> theResultBody)
 {
   //load result
   theResultBody->store(theGeomShape);
+
   std::string aNameMS = "Shape";
   theResultBody->loadFirstLevel(theGeomShape, aNameMS);
 }
+
+void ExchangePlugin_Import_ImageFeature::importFile(const std::string& theFileName)
+{
+
+  std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
+  std::string theTextureFileName = "";
+  // Perform the import
+  std::string anError;
+  std::shared_ptr<GeomAPI_Shape> aGeomShape;
+   if (anExtension == "PNG" || anExtension == "GIF" ||
+             anExtension == "TIFF" || anExtension == "JPE" ||
+             anExtension == "JPG" || anExtension == "JPEG" ||
+             anExtension == "BMP"|| anExtension == "PPM"
+             ) {
+     aGeomShape = ImageImport(theFileName, anError);
+     if(anError == "")
+       theTextureFileName = theFileName;
+    } else {
+    anError = "Unsupported format: " + anExtension;
+  }
+
+  // Check if shape is valid
+  if (!anError.empty()) {
+    setError("An error occurred while importing " + theFileName + ": " + anError);
+    return;
+  }
+
+  // Pass the results into the model
+  std::string anObjectName = GeomAlgoAPI_Tools::File_Tools::name(theFileName);
+  data()->setName(Locale::Convert::toWString(anObjectName));
+
+  auto resultBody = createResultBody(aGeomShape);
+  resultBody->setTextureFile(theTextureFileName);
+  setResult(resultBody);
+}
index 3c34eced69f111e0765f59055042f75fc71811cb..fa4ac0f7fcff915b1ad6dc57b73e0a1ff5923516 100644 (file)
  *
  * The list of supported formats is defined in the configuration file.
  */
-class ExchangePlugin_ImportFeature : public ModelAPI_CompositeFeature
+class ExchangePlugin_ImportFeatureBase : public ModelAPI_CompositeFeature
 {
- public:
-  /// Feature kind
-  inline static const std::string& ID()
-  {
-    static const std::string MY_IMPORT_ID("Import");
-    return MY_IMPORT_ID;
-  }
-  /// Feature kind
-  inline static const std::string& IMPORT_TYPE_ID()
-  {
-    static const std::string MY_IMPORT_TYPE_ID("ImportType");
-    return MY_IMPORT_TYPE_ID;
-  }
+ public:  
   /// attribute name of file path
   inline static const std::string& FILE_PATH_ID()
   {
     static const std::string MY_FILE_PATH_ID("file_path");
     return MY_FILE_PATH_ID;
   }
-  /// attribute name of file path
-  inline static const std::string& STEP_FILE_PATH_ID()
-  {
-    static const std::string MY_STEP_FILE_PATH_ID("step_file_path");
-    return MY_STEP_FILE_PATH_ID;
-  }
   /// All features (list of references)
   inline static const std::string& FEATURES_ID()
   {
     static const std::string MY_FEATURES_ID("Features");
     return MY_FEATURES_ID;
   }
-  /// attribute name of step Scale to International System Units
-  inline static const std::string& STEP_SCALE_INTER_UNITS_ID()
+  /// attribute name of target part
+  inline static const std::string& TARGET_PART_ID()
   {
-    static const std::string MY_STEP_SCALE_INTER_UNITS_ID("step_scale_inter_units");
-    return MY_STEP_SCALE_INTER_UNITS_ID;
-  }
-  /// attribute name of step materiels
-  inline static const std::string& STEP_MATERIALS_ID()
-  {
-    static const std::string MY_STEP_MATERIALS_ID("step_materials");
-    return MY_STEP_MATERIALS_ID;
-  }
-  /// attribute name of step colors
-  inline static const std::string& STEP_COLORS_ID()
-  {
-    static const std::string MY_STEP_COLORS_ID("step_colors");
-    return MY_STEP_COLORS_ID;
+    static const std::string MY_TARGET_PART_ID("target_part");
+    return MY_TARGET_PART_ID;
   }
   /// Default constructor
-  EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature();
+  EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeatureBase() = default;
   /// Default destructor
-  EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ImportFeature();
+  EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ImportFeatureBase() = default;
 
   /// Returns the unique kind of a feature
-  EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind()
-  {
-    return ExchangePlugin_ImportFeature::ID();
-  }
+  EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind() = 0;
 
   /// Request for initialization of data model of the feature: adding all attributes
   EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
 
   /// Computes or recomputes the results
-  EXCHANGEPLUGIN_EXPORT virtual void execute();
+  EXCHANGEPLUGIN_EXPORT virtual void execute() = 0;
 
   /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
   EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
@@ -126,19 +93,82 @@ class ExchangePlugin_ImportFeature : public ModelAPI_CompositeFeature
 
  protected:
   /// Performs the import of the file
-  EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName);
-
-  /// Performs the import of XAO file
-  EXCHANGEPLUGIN_EXPORT void importXAO(const std::string& theFileName);
+  EXCHANGEPLUGIN_EXPORT virtual void importFile(const std::string& theFileName) = 0;
 
   /// Creates and prepares a result body from the shape
   std::shared_ptr<ModelAPI_ResultBody> createResultBody(
       std::shared_ptr<GeomAPI_Shape> aGeomShape);
 
-private:
   /// Loads Naming data structure to the document
   void loadNamingDS(std::shared_ptr<GeomAPI_Shape> theGeomShape,
                     std::shared_ptr<ModelAPI_ResultBody> theResultBody);
+};
+
+class ExchangePlugin_ImportFeature : public ExchangePlugin_ImportFeatureBase
+{
+public:
+  /// Feature kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_IMPORT_ID("Import");
+    return MY_IMPORT_ID;
+  }
+  /// Feature kind
+  inline static const std::string& IMPORT_TYPE_ID()
+  {
+    static const std::string MY_IMPORT_TYPE_ID("ImportType");
+    return MY_IMPORT_TYPE_ID;
+  }
+  /// attribute name of file path
+  inline static const std::string& STEP_FILE_PATH_ID()
+  {
+    static const std::string MY_STEP_FILE_PATH_ID("step_file_path");
+    return MY_STEP_FILE_PATH_ID;
+  }
+
+  /// Default constructor
+  EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature() = default;
+  /// Default destructor
+  EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ImportFeature() = default;
+
+  /// attribute name of step Scale to International System Units
+  inline static const std::string& STEP_SCALE_INTER_UNITS_ID()
+  {
+    static const std::string MY_STEP_SCALE_INTER_UNITS_ID("step_scale_inter_units");
+    return MY_STEP_SCALE_INTER_UNITS_ID;
+  }
+  /// attribute name of step materiels
+  inline static const std::string& STEP_MATERIALS_ID()
+  {
+    static const std::string MY_STEP_MATERIALS_ID("step_materials");
+    return MY_STEP_MATERIALS_ID;
+  }
+  /// attribute name of step colors
+  inline static const std::string& STEP_COLORS_ID()
+  {
+    static const std::string MY_STEP_COLORS_ID("step_colors");
+    return MY_STEP_COLORS_ID;
+  }
+  /// Returns the unique kind of a feature
+  EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind() override
+  {
+    return ExchangePlugin_ImportFeature::ID();
+  }
+
+  /// Computes or recomputes the results
+  EXCHANGEPLUGIN_EXPORT virtual void execute() override;
+
+  /// Request for initialization of data model of the feature: adding all attributes
+  EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
+
+protected:
+  /// Performs the import of the file
+  EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName) override;
+
+  /// Performs the import of XAO file
+  EXCHANGEPLUGIN_EXPORT void importXAO(const std::string& theFileName);
+
+private:                   
   /// Set groups of color
   void setColorGroups(std::shared_ptr<ModelAPI_ResultBody> theResultBody);
 
@@ -153,4 +183,33 @@ private:
 
 };
 
+class ExchangePlugin_Import_ImageFeature : public ExchangePlugin_ImportFeatureBase
+{
+ public:
+  /// Feature kind
+  inline static const std::string& ID()
+  {
+    static const std::string MY_IMPORT_ID("ImportImage");
+    return MY_IMPORT_ID;
+  }
+
+  /// Default constructor
+  EXCHANGEPLUGIN_EXPORT ExchangePlugin_Import_ImageFeature() = default;
+  /// Default destructor
+  EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_Import_ImageFeature() = default;
+
+  /// Returns the unique kind of a feature
+  EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind() override
+  {
+    return ExchangePlugin_Import_ImageFeature::ID();
+  }
+
+   /// Computes or recomputes the results
+  EXCHANGEPLUGIN_EXPORT virtual void execute() override;
+
+protected:
+  /// Performs the import of the file
+  EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName) override;
+
+};
 #endif /* IMPORT_IMPORTFEATURE_H_ */
index 235ddd17fc9243ea24328b249d45e69ab568c535..1436dcf032765a3871988e4e548296cc3e2af26b 100644 (file)
@@ -54,6 +54,9 @@ FeaturePtr ExchangePlugin_Plugin::createFeature(std::string theFeatureID)
 {
   if (theFeatureID == ExchangePlugin_ImportFeature::ID()) {
     return FeaturePtr(new ExchangePlugin_ImportFeature);
+  }  else
+  if (theFeatureID == ExchangePlugin_Import_ImageFeature::ID()) {
+      return FeaturePtr(new ExchangePlugin_Import_ImageFeature);
   } else
   if (theFeatureID == ExchangePlugin_ExportFeature::ID()) {
     return FeaturePtr(new ExchangePlugin_ExportFeature);
@@ -69,6 +72,9 @@ FeaturePtr ExchangePlugin_Plugin::createFeature(std::string theFeatureID)
   } else
   if (theFeatureID == ExchangePlugin_Import::ID()) {
     return FeaturePtr(new ExchangePlugin_Import);
+  } else
+  if (theFeatureID == ExchangePlugin_Import_Image::ID()) {
+     return FeaturePtr(new ExchangePlugin_Import_Image);
   }
   // feature of such kind is not found
   return FeaturePtr();
index c6f58a196aa9842bbace3d4d88e2a2fa2f78deb6..b553ded1872a5f8b16cc8ca332a7f3a32c3b6090 100644 (file)
@@ -1,7 +1,7 @@
 <plugin>
   <workbench id="Part">
     <group id="Exchange">
-      <feature id="ImportMacro" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
+      <feature id="Import" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
                helpfile="importFeature.html"
                internal="1">
       <switch id="ImportType">
                 label="Import to"
                 tooltip="Select the image to import the document" />
       </feature>
-      <feature id="Import" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
+      <feature id="ImportImage" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
+               helpfile="importFeature.html"
+               internal="1">
+        <file_selector id="file_path" title="Import image file" path="">
+          <validator id="ExchangePlugin_ImportFormat" parameters="GIF|TIFF|PNG|JPG|JPEG|BMP|PPM|JPE:Image" />
+        </file_selector>
+        <choice id="target_part"
+                string_list_attribute="target_parts_list"
+                label="Import to"
+                tooltip="Select the image to import the document" />
+      </feature>
+      <feature id="ImportFeature" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
                helpfile="importFeature.html" internal="1">
         <switch id="ImportType">
           <case id="Regular" title="BREP, XAO, IGES, STL">
           <validator id="ExchangePlugin_ImportFormat" parameters="GIF|TIFF|PNG|JPG|JPEG|BMP|PPM|JPE:Image" />
         </file_selector>
       </feature>
+      <feature id="ImportImageFeature" title="Import" tooltip="Import a file" icon="icons/Exchange/import.png"
+               helpfile="importFeature.html"
+               internal="1">
+        <file_selector id="file_path" title="Import image file" path="">
+          <validator id="ExchangePlugin_ImportFormat" parameters="GIF|TIFF|PNG|JPG|JPEG|BMP|PPM|JPE:Image" />
+        </file_selector>
+      </feature>
       <feature id="Export" title="Export" tooltip="Export to file" icon="icons/Exchange/export.png"
                helpfile="exportFeature.html" internal="1">
         <source path="export_widget.xml" />
index 1948f8161f143b3d25486ae76a5ca5941b6e0d17..7f5752e09d253e8db37fd37368af8f334c48bbc2 100644 (file)
@@ -51,6 +51,7 @@ SET(PROJECT_HEADERS
     GeomAlgoAPI_STEPExport.h
     GeomAlgoAPI_STLExport.h
     GeomAlgoAPI_STLImport.h
+    GeomAlgoAPI_ImageImport.h
     GeomAlgoAPI_IGESExport.h
     GeomAlgoAPI_Transform.h
     GeomAlgoAPI_ShapeTools.h
@@ -119,6 +120,7 @@ SET(PROJECT_SOURCES
     GeomAlgoAPI_STEPExport.cpp
     GeomAlgoAPI_STLExport.cpp
     GeomAlgoAPI_STLImport.cpp
+    GeomAlgoAPI_ImageImport.cpp
     GeomAlgoAPI_IGESExport.cpp
     GeomAlgoAPI_Transform.cpp
     GeomAlgoAPI_ShapeTools.cpp
@@ -177,6 +179,10 @@ SET(CMAKE_SWIG_FLAGS -w325,321,362,383,302)
 SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES CPLUSPLUS ON)
 SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow")
 
+INCLUDE(UseQtExt)
+# additional include directories
+INCLUDE_DIRECTORIES(${QT_INCLUDES})
+
 INCLUDE_DIRECTORIES(
   ../GeomAPI
   ../GeomAlgoImpl
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ImageImport.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ImageImport.cpp
new file mode 100644 (file)
index 0000000..a95bf2b
--- /dev/null
@@ -0,0 +1,99 @@
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include <GeomAlgoAPI_ImageImport.h>
+
+#include <QPixmap>
+#include <BRep_Builder.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+#include <BRepBuilderAPI_MakePolygon.hxx>
+#include <BRepBuilderAPI_MakeVertex.hxx>
+#include <BRepBuilderAPI_Sewing.hxx>
+#include <gp_Pnt.hxx>
+#include <OSD_Path.hxx>
+#include <RWStl.hxx>
+#include <TopoDS_Compound.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Shell.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <TopoDS_Wire.hxx>
+
+std::shared_ptr<GeomAPI_Shape> ImageImport(const std::string& theFileName,
+                                         std::string& theError)
+{
+  TopoDS_Shape aResShape;
+  try
+  {
+    QPixmap* pixmap = new QPixmap(theFileName.c_str());
+    int height            =  pixmap->height();
+    int width             =  pixmap->width();
+
+    delete pixmap;
+
+    TopoDS_Vertex aTriVertexes[4];
+    gp_Pnt aPnt1( -0.5*width, -0.5*height, 0);
+    gp_Pnt aPnt2( 0.5*width, -0.5*height, 0);
+    gp_Pnt aPnt3(  0.5*width,  0.5*height, 0 );;
+    gp_Pnt aPnt4( -0.5*width,  0.5*height, 0 );
+    TopoDS_Face aFace;
+    TopoDS_Wire aWire;
+
+    aTriVertexes[0] = BRepBuilderAPI_MakeVertex (aPnt1);
+    aTriVertexes[1] = BRepBuilderAPI_MakeVertex (aPnt2);
+    aTriVertexes[2] = BRepBuilderAPI_MakeVertex (aPnt3);
+    aTriVertexes[3] = BRepBuilderAPI_MakeVertex (aPnt4);
+
+    aWire = BRepBuilderAPI_MakePolygon (aTriVertexes[0], aTriVertexes[1], aTriVertexes[2], aTriVertexes[3], Standard_True);
+
+    BRepBuilderAPI_Sewing aSewingTool;
+    aSewingTool.Init (1.0e-06, Standard_True);
+
+    TopoDS_Compound aComp;
+    BRep_Builder BuildTool;
+    BuildTool.MakeCompound(aComp);
+
+    if(!aWire.IsNull())
+    {
+      aFace = BRepBuilderAPI_MakeFace (aWire);
+      if (!aFace.IsNull())
+      {
+        BuildTool.Add (aComp, aFace);
+      }
+    }
+
+    aSewingTool.Load (aComp);
+    aSewingTool.Perform();
+    aResShape = aSewingTool.SewedShape();
+    if (aResShape.IsNull())
+    {
+      aResShape = aComp;
+    }
+  }
+  catch (Standard_Failure const& anException) {
+    theError = anException.GetMessageString();
+    aResShape.Nullify();
+  }
+
+  std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
+  aGeomShape->setImpl(new TopoDS_Shape(aResShape));  
+
+  return aGeomShape;
+}
diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ImageImport.h b/src/GeomAlgoAPI/GeomAlgoAPI_ImageImport.h
new file mode 100644 (file)
index 0000000..d9798b5
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright (C) 2014-2020  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+
+#ifndef GEOMALGOAPI_IMAGEIMPORT_H_
+#define GEOMALGOAPI_IMAGEIMPORT_H_
+
+#include <GeomAlgoAPI.h>
+#include <GeomAPI_Shape.h>
+
+#include <string>
+
+/// Implementation of the import STL files algorithms
+GEOMALGOAPI_EXPORT
+std::shared_ptr<GeomAPI_Shape>  ImageImport(const std::string& theFileName,
+                                          std::string& theError);
+
+#endif /* GEOMALGOAPI_IMAGEIMPORT_H_ */
index a905e6d2978f30e71519e9b6e40961f8ff005e5f..a8b08adc6020fcb80fe61d24be15e6b42b935f85 100644 (file)
@@ -45,6 +45,7 @@ class ModelAPI_Object: public ModelAPI_Entity
 {
   std::shared_ptr<ModelAPI_Data> myData;  ///< manager of the data model of a feature
   std::shared_ptr<ModelAPI_Document> myDoc;  ///< document this object belongs to
+  std::string textureFile = "";
  public:
 #ifdef DEBUG_NAMES
   std::wstring myName; // name of this object
@@ -100,6 +101,21 @@ class ModelAPI_Object: public ModelAPI_Entity
   /// signal.
   MODELAPI_EXPORT virtual void setDisplayed(const bool theDisplay);
 
+  MODELAPI_EXPORT bool hasTextureFile()
+  {
+    return (textureFile != "");
+  }
+
+  MODELAPI_EXPORT void setTextureFile(const std::string & theTextureFile)
+  {
+    textureFile = theTextureFile;
+  }
+
+  MODELAPI_EXPORT const std::string & getTextureFile()
+  {
+    return  textureFile;
+  }
+
  protected:
   /// This method is called just after creation of the object: it must initialize
   /// all fields, normally initialized in the constructor
index d9648b56e5c585b514c19a3813ed039fcaf2b2fa..64b63156be7cad4c15df08ccbea2c19cf2b807b1 100644 (file)
 #include <GeomDataAPI_Dir.h>
 
 #include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <OCCViewer_Utilities.h>
+
 
 #define FEATURE_ITEM_COLOR "0,0,225"
 
@@ -1445,6 +1448,41 @@ void PartSet_Module::customizePresentation(const ObjectPtr& theObject,
       thePrs->setDeflection(getResultDeflection(aResult));
 
       thePrs->setTransparency(getResultTransparency(aResult));
+
+      /// set texture  parameters
+      if(aResult->hasTextureFile())
+      {
+        Handle(AIS_InteractiveObject) anAIS = thePrs->impl<Handle(AIS_InteractiveObject)>();
+        if (!anAIS.IsNull())
+        {
+          std::vector<int> aColor = {167, 167, 167 };
+          thePrs->setColor(aColor[0], aColor[1], aColor[2]);
+          Quantity_Color myShadingColor(NCollection_Vec3<float>(aColor[0]/255.,  aColor[1]/255., aColor[2]/255.));
+
+          Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(anAIS);
+          if (!anAISShape.IsNull())
+          {
+            auto myDrawer = new Prs3d_ShadingAspect();
+            if (!anAISShape->Attributes()->HasOwnShadingAspect())
+            {
+              anAISShape->Attributes()->SetShadingAspect (myDrawer);
+            }
+
+            myDrawer->SetColor(myShadingColor);
+
+            Handle(Image_PixMap) aPixmap;
+            QPixmap px(aResult->getTextureFile().c_str());
+            if (!px.isNull() )
+              aPixmap = OCCViewer_Utilities::imageToPixmap( px.toImage() );
+
+            anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMap
+                (new Graphic3d_Texture2Dmanual(aPixmap));
+            anAISShape->Attributes()->ShadingAspect()->Aspect()->SetTextureMapOn();
+
+            anAISShape->SetDisplayMode(AIS_Shaded);
+          }
+        }
+      }
     }
     FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
     if (aFeature.get()) {
index 5bc03f55e400376054edb046022690c7cc4d7941..b78a019bccde374fcd12c43ef7c647f5f00449fa 100644 (file)
@@ -490,6 +490,12 @@ void XGUI_Workshop::initMenu()
     QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10);
   connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportShape()));
 
+  aAction = salomeConnector()->addDesktopCommand("IMPORT_IMAGE_CMD", tr("Picture..."),
+    tr("Import a picture from an image file"),
+    QIcon(),
+    QKeySequence(), false, "MEN_DESK_FILE", tr("Import"), 10, 10);
+  connect(aAction, SIGNAL(triggered(bool)), this, SLOT(onImportImage()));
+
   // Export sub-menu
   aAction = salomeConnector()->addDesktopCommand("SAVEAS_CMD", tr("Part set..."),
                                              tr("Export the current document into a native file"),
@@ -1340,6 +1346,19 @@ void XGUI_Workshop::onImportShape()
   }
 }
 
+//******************************************************
+void XGUI_Workshop::onImportImage()
+{
+  if (abortAllOperations()) {
+    ModuleBase_OperationFeature* anImportOp = dynamic_cast<ModuleBase_OperationFeature*>(
+        module()->createOperation(ExchangePlugin_Import_Image::ID()));
+    anImportOp->setHelpFileName(QString("ExchangePlugin") + QDir::separator() +
+      "importFeature.html");
+    myPropertyPanel->updateApplyPlusButton(anImportOp->feature());
+    operationMgr()->startOperation(anImportOp);
+  }
+}
+
 //******************************************************
 void XGUI_Workshop::onExportShape()
 {
index c503990f9671babb5fb79093e419705d31d0d3f5..cc243b62a8b36b408538eef68768ba57c1d9931b 100644 (file)
@@ -410,6 +410,9 @@ signals:
   /// Import shape from a file
   void onImportShape();
 
+  /// Import  image from a file
+  void onImportImage();
+
   /// Export features to a file
   void onExportPart();