}
-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());
/*
* 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;
}
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;
}
}
-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);
}
+ }
}
#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()
{
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");
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_ */
#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(
ModelAPI_Session::get()->validators()->registerNotObligatory(
getKind(), ExchangePlugin_ImportFeature::FILE_PATH_ID());
}
-
/*
* Computes or recomputes the results
*/
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;
}
// 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);
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") {
aGeomShape = IGESImport(theFileName, anExtension, anError);
} else if (anExtension == "STL") {
aGeomShape = STLImport(theFileName, anError);
- } else {
+ } else {
anError = "Unsupported format: " + anExtension;
}
}
// Pass the results into the model
-
+
loadNamingDS(aGeomShape, aResult);
// create color group
}
//============================================================================
-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);
}
// LCOV_EXCL_START
-void ExchangePlugin_ImportFeature::removeFeature(
+void ExchangePlugin_ImportFeatureBase::removeFeature(
std::shared_ptr<ModelAPI_Feature> theFeature)
{
if (!data()->isValid())
}
// 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);
}
// 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()));
}
// 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);
}
//============================================================================
-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);
+}
*
* 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; }
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);
};
+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_ */
{
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);
} 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();
<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" />
GeomAlgoAPI_STEPExport.h
GeomAlgoAPI_STLExport.h
GeomAlgoAPI_STLImport.h
+ GeomAlgoAPI_ImageImport.h
GeomAlgoAPI_IGESExport.h
GeomAlgoAPI_Transform.h
GeomAlgoAPI_ShapeTools.h
GeomAlgoAPI_STEPExport.cpp
GeomAlgoAPI_STLExport.cpp
GeomAlgoAPI_STLImport.cpp
+ GeomAlgoAPI_ImageImport.cpp
GeomAlgoAPI_IGESExport.cpp
GeomAlgoAPI_Transform.cpp
GeomAlgoAPI_ShapeTools.cpp
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
--- /dev/null
+// 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;
+}
--- /dev/null
+// 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_ */
{
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
/// 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
#include <GeomDataAPI_Dir.h>
#include <SelectMgr_ListIteratorOfListOfFilter.hxx>
+#include <Graphic3d_Texture2Dmanual.hxx>
+#include <OCCViewer_Utilities.h>
+
#define FEATURE_ITEM_COLOR "0,0,225"
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()) {
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"),
}
}
+//******************************************************
+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()
{
/// Import shape from a file
void onImportShape();
+ /// Import image from a file
+ void onImportImage();
+
/// Export features to a file
void onExportPart();