From 5decc02f4892227b0df11422e67d8b0d23272f6e Mon Sep 17 00:00:00 2001 From: spo Date: Tue, 21 Jun 2016 13:55:59 +0300 Subject: [PATCH] Make ExchangePlugin_ImportFeature a CompositeFeature --- .../ExchangePlugin_ImportFeature.cpp | 39 +++++++++---------- .../ExchangePlugin_ImportFeature.h | 35 +++++++++++++---- src/ExchangePlugin/ExchangePlugin_Tools.cpp | 2 + 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp index 73a35fd22..f1592b5b5 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.cpp @@ -2,16 +2,12 @@ // File: ExchangePlugin_ImportFeature.cpp // Created: Aug 28, 2014 -// Author: Sergey BELASH +// Authors: Sergey BELASH, Sergey POKHODENKO #include #include #include -#ifdef _DEBUG -#include -#include -#endif #include #include @@ -57,9 +53,10 @@ ExchangePlugin_ImportFeature::~ExchangePlugin_ImportFeature() void ExchangePlugin_ImportFeature::initAttributes() { data()->addAttribute(ExchangePlugin_ImportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(ExchangePlugin_ImportFeature::GROUP_LIST_ID(), ModelAPI_AttributeRefList::typeId()); + data()->addAttribute(ExchangePlugin_ImportFeature::FEATURES_ID(), ModelAPI_AttributeRefList::typeId()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ExchangePlugin_ImportFeature::GROUP_LIST_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory( + getKind(), ExchangePlugin_ImportFeature::FEATURES_ID()); } /* @@ -138,23 +135,23 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName) XAO::Geometry* aXaoGeometry = aXao.getGeometry(); // use the geometry name or the file name for the feature - std::string aBodyName = aXaoGeometry->getName().empty() - ? GeomAlgoAPI_Tools::File_Tools::name(theFileName) - : aXaoGeometry->getName(); + std::string aBodyName = aXaoGeometry->getName(); + if (aBodyName.empty()) + aBodyName = GeomAlgoAPI_Tools::File_Tools::name(theFileName); data()->setName(aBodyName); ResultBodyPtr aResultBody = createResultBody(aGeomShape); setResult(aResultBody); // Process groups - AttributeRefListPtr aRefListOfGroups = reflist(ExchangePlugin_ImportFeature::GROUP_LIST_ID()); + std::shared_ptr aRefListOfGroups = + std::dynamic_pointer_cast(data()->attribute(FEATURES_ID())); // Remove previous groups stored in RefList std::list anGroupList = aRefListOfGroups->list(); std::list::iterator anGroupIt = anGroupList.begin(); for (; anGroupIt != anGroupList.end(); ++anGroupIt) { - std::shared_ptr aFeature = - std::dynamic_pointer_cast(*anGroupIt); + std::shared_ptr aFeature = ModelAPI_Feature::feature(*anGroupIt); if (aFeature) document()->removeFeature(aFeature); } @@ -163,7 +160,7 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName) for (int aGroupIndex = 0; aGroupIndex < aXao.countGroups(); ++aGroupIndex) { XAO::Group* aXaoGroup = aXao.getGroup(aGroupIndex); - std::shared_ptr aGroupFeature = document()->addFeature("Group", false); + std::shared_ptr aGroupFeature = addFeature("Group"); // group name if (!aXaoGroup->getName().empty()) @@ -188,13 +185,13 @@ void ExchangePlugin_ImportFeature::importXAO(const std::string& theFileName) aSelectionList->value(anElementIndex)->setId(aReferenceID); } - - aRefListOfGroups->append(aGroupFeature); - - // hide the group in the history - document()->setCurrentFeature(aGroupFeature, false); - // groups features is internal part of the import - aGroupFeature->setInHistory(aGroupFeature, false); +// +// aRefListOfGroups->append(aGroupFeature); +// +// // hide the group in the history +// document()->setCurrentFeature(aGroupFeature, false); +// // groups features is internal part of the import +// aGroupFeature->setInHistory(aGroupFeature, false); } } catch (XAO::XAO_Exception& e) { diff --git a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h index 566a7b9e5..d882bc759 100644 --- a/src/ExchangePlugin/ExchangePlugin_ImportFeature.h +++ b/src/ExchangePlugin/ExchangePlugin_ImportFeature.h @@ -2,13 +2,14 @@ // File: ExchangePlugin_ImportFeature.h // Created: Aug 28, 2014 -// Author: Sergey BELASH +// Authors: Sergey BELASH, Sergey POKHODENKO #ifndef EXCHANGEPLUGIN_IMPORTFEATURE_H_ #define EXCHANGEPLUGIN_IMPORTFEATURE_H_ -#include -#include +#include "ExchangePlugin.h" + +#include #include #include @@ -20,7 +21,7 @@ * * The list of supported formats is defined in the configuration file. */ -class ExchangePlugin_ImportFeature : public ModelAPI_Feature +class ExchangePlugin_ImportFeature : public ModelAPI_CompositeFeature { public: /// Feature kind @@ -35,11 +36,11 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature static const std::string MY_FILE_PATH_ID("file_path"); return MY_FILE_PATH_ID; } - /// attribute name of group list - inline static const std::string& GROUP_LIST_ID() + /// All features (list of references) + inline static const std::string& FEATURES_ID() { - static const std::string MY_GROUP_LIST_ID("group_list"); - return MY_GROUP_LIST_ID; + static const std::string MY_FEATURES_ID("Features"); + return MY_FEATURES_ID; } /// Default constructor EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature(); @@ -61,6 +62,24 @@ class ExchangePlugin_ImportFeature : public ModelAPI_Feature /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false. EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; } + /// Reimplemented from ModelAPI_CompositeFeature::addFeature() + virtual std::shared_ptr addFeature(std::string theID); + + /// Reimplemented from ModelAPI_CompositeFeature::numberOfSubs() + virtual int numberOfSubs(bool forTree = false) const; + + /// Reimplemented from ModelAPI_CompositeFeature::subFeature() + virtual std::shared_ptr subFeature(const int theIndex, bool forTree = false); + + /// Reimplemented from ModelAPI_CompositeFeature::subFeatureId() + virtual int subFeatureId(const int theIndex) const; + + /// Reimplemented from ModelAPI_CompositeFeature::isSub() + virtual bool isSub(ObjectPtr theObject) const; + + /// Reimplemented from ModelAPI_CompositeFeature::removeFeature() + virtual void removeFeature(std::shared_ptr theFeature); + protected: /// Performs the import of the file EXCHANGEPLUGIN_EXPORT void importFile(const std::string& theFileName); diff --git a/src/ExchangePlugin/ExchangePlugin_Tools.cpp b/src/ExchangePlugin/ExchangePlugin_Tools.cpp index 51f22b82b..5a65fc1da 100644 --- a/src/ExchangePlugin/ExchangePlugin_Tools.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Tools.cpp @@ -34,6 +34,8 @@ std::string ExchangePlugin_Tools::selectionType2xaoDimension(const std::string& std::string ExchangePlugin_Tools::xaoDimension2selectionType(const std::string& theDimension) { +// return theDimension; + if (theDimension == "vertex") return "Vertices"; else if (theDimension == "edge") -- 2.39.2