From: mpv Date: Thu, 3 Apr 2014 08:10:00 +0000 (+0400) Subject: Implementation of Point feature (without computation of result yet) plus some debug... X-Git-Tag: V_0.1~41^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=69fae9d94ffa0fd9c37a756bf8d4736522f06214;p=modules%2Fshaper.git Implementation of Point feature (without computation of result yet) plus some debug and API extension dedicated to this development. --- diff --git a/src/Config/Config_FeatureMessage.h b/src/Config/Config_FeatureMessage.h index ba0c64c7b..848e12325 100644 --- a/src/Config/Config_FeatureMessage.h +++ b/src/Config/Config_FeatureMessage.h @@ -9,7 +9,7 @@ /* * Class to pass a feature entry extracted from xml file. * Example of the feature entry: - * + * */ class CONFIG_EXPORT Config_FeatureMessage: public Event_Message { diff --git a/src/Config/plugin-PartSet.xml b/src/Config/plugin-PartSet.xml index 2785659ef..2b4e76e22 100644 --- a/src/Config/plugin-PartSet.xml +++ b/src/Config/plugin-PartSet.xml @@ -1,20 +1,20 @@ - + - + - - + + - \ No newline at end of file + diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index ae05dd926..c6dfa0f7e 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -10,6 +10,7 @@ SET(PROJECT_HEADERS Model_PluginManager.h Model_Object.h Model_Iterator.h + Model_AttributeDouble.h Model_AttributeDocRef.h ) @@ -19,6 +20,7 @@ SET(PROJECT_SOURCES Model_PluginManager.cxx Model_Object.cxx Model_Iterator.cxx + Model_AttributeDouble.cxx Model_AttributeDocRef.cxx ) diff --git a/src/Model/Model_AttributeDouble.cxx b/src/Model/Model_AttributeDouble.cxx new file mode 100644 index 000000000..7e2ed83e1 --- /dev/null +++ b/src/Model/Model_AttributeDouble.cxx @@ -0,0 +1,27 @@ +// File: ModelAPI_AttributeDouble.cxx +// Created: 2 Apr 2014 +// Author: Mikhail PONIKAROV + +#include "Model_AttributeDouble.h" + +using namespace std; + +void Model_AttributeDouble::setValue(const double theValue) +{ + myReal->Set(theValue); +} + +double Model_AttributeDouble::value() +{ + return myReal->Get(); +} + +Model_AttributeDouble::Model_AttributeDouble(TDF_Label& theLabel) +{ + // check the attribute could be already presented in this doc (after load document) + if (!theLabel.FindAttribute(TDataStd_Real::GetID(), myReal)) { + // create attribute: not initialized by value yet, just zero + myReal = TDataStd_Real::Set(theLabel, 0.); + } +} + diff --git a/src/Model/Model_AttributeDouble.h b/src/Model/Model_AttributeDouble.h new file mode 100644 index 000000000..d498bc42b --- /dev/null +++ b/src/Model/Model_AttributeDouble.h @@ -0,0 +1,35 @@ +// File: Model_AttributeDouble.h +// Created: 2 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef Model_AttributeDouble_HeaderFile +#define Model_AttributeDouble_HeaderFile + +#include "Model.h" +#include "ModelAPI_AttributeDouble.h" +#include +#include + +/**\class Model_AttributeDouble + * \ingroup DataModel + * \brief Attribute that contains real value with double precision. + */ + +class MODEL_EXPORT Model_AttributeDouble : public ModelAPI_AttributeDouble +{ + Handle_TDataStd_Real myReal; ///< double is Real attribute +public: + /// Defines the double value + virtual void setValue(const double theValue); + + /// Returns the double value + virtual double value(); + +protected: + /// Initializes attibutes + Model_AttributeDouble(TDF_Label& theLabel); + + friend class Model_Object; +}; + +#endif diff --git a/src/Model/Model_Document.cxx b/src/Model/Model_Document.cxx index 6555a22db..8a3f0bf45 100644 --- a/src/Model/Model_Document.cxx +++ b/src/Model/Model_Document.cxx @@ -212,8 +212,8 @@ void Model_Document::setUniqueName( // first count all objects of such kind to start with index = count + 1 int aNumObjects = 0; shared_ptr anIter = featuresIterator(theGroupID); - for(; anIter->More(); anIter->Next()) { - if (anIter->CurrentKind() == theFeature->getKind()) + for(; anIter->more(); anIter->next()) { + if (anIter->currentKind() == theFeature->getKind()) aNumObjects++; } // generate candidate name @@ -221,14 +221,14 @@ void Model_Document::setUniqueName( aNameStream<getKind()<<"_"<More();) { - if (anIter->CurrentName() == aName) { + for(anIter = featuresIterator(theGroupID); anIter->more();) { + if (anIter->currentName() == aName) { aNumObjects++; stringstream aNameStream; aNameStream<getKind()<<"_"<Next(); + } else anIter->next(); } theFeature->data()->setName(aName); diff --git a/src/Model/Model_Iterator.cxx b/src/Model/Model_Iterator.cxx index 917d89288..ae62fa928 100644 --- a/src/Model/Model_Iterator.cxx +++ b/src/Model/Model_Iterator.cxx @@ -9,29 +9,29 @@ using namespace std; -void Model_Iterator::Next() +void Model_Iterator::next() { return myIter.Next(); } -bool Model_Iterator::More() +bool Model_Iterator::more() { return myIter.More(); } -shared_ptr Model_Iterator::Current() +shared_ptr Model_Iterator::current() { TDF_Label aLab = myIter.Value()->Label(); return myDoc->feature(aLab); } -string Model_Iterator::CurrentKind() +string Model_Iterator::currentKind() { return string(TCollection_AsciiString( Handle(TDataStd_Comment)::DownCast(myIter.Value())->Get()).ToCString()); } -string Model_Iterator::CurrentName() +string Model_Iterator::currentName() { TDF_Label aLab = myIter.Value()->Label(); Handle(TDataStd_Name) aName; @@ -40,6 +40,15 @@ string Model_Iterator::CurrentName() return ""; // name is not found } +int Model_Iterator::numIterationsLeft() +{ + int aResult = 0; + TDF_ChildIDIterator aTempIter(myIter); + for(; aTempIter.More(); aTempIter.Next()) + aResult++; + return aResult; +} + Model_Iterator::Model_Iterator(std::shared_ptr theDoc, TDF_Label theLab) : myDoc(theDoc), myIter(theLab, TDataStd_Comment::GetID(), Standard_False) {} diff --git a/src/Model/Model_Iterator.h b/src/Model/Model_Iterator.h index 2ec50ab3a..4da78e267 100644 --- a/src/Model/Model_Iterator.h +++ b/src/Model/Model_Iterator.h @@ -24,15 +24,18 @@ class MODEL_EXPORT Model_Iterator : public ModelAPI_Iterator TDF_ChildIDIterator myIter; ///< iterator of the features-labels public: /// Iterates to the next feature - virtual void Next(); + virtual void next(); /// Returns true if the current iteration is valid and next iteration is possible - virtual bool More(); + virtual bool more(); /// Returns the currently iterated feature - virtual std::shared_ptr Current(); + virtual std::shared_ptr current(); /// Returns the kind of the current feature (faster than Current()->getKind()) - virtual std::string CurrentKind(); + virtual std::string currentKind(); /// Returns the name of the current feature (faster than Current()->getName()) - virtual std::string CurrentName(); + virtual std::string currentName(); + /// Don't changes the current position of iterator. Not fast: iterates the left items. + /// \returns number of left iterations + virtual int numIterationsLeft(); protected: /// Initializes iterator diff --git a/src/Model/Model_Object.cxx b/src/Model/Model_Object.cxx index 735080954..0312a0c12 100644 --- a/src/Model/Model_Object.cxx +++ b/src/Model/Model_Object.cxx @@ -4,6 +4,7 @@ #include #include +#include #include using namespace std; @@ -36,6 +37,9 @@ void Model_Object::addAttribute(string theID, string theAttrType) ModelAPI_Attribute* anAttr = 0; if (theAttrType == ModelAPI_AttributeDocRef::type()) anAttr = new Model_AttributeDocRef(anAttrLab); + else if (theAttrType == ModelAPI_AttributeDouble::type()) + anAttr = new Model_AttributeDouble(anAttrLab); + if (anAttr) myAttrs[theID] = std::shared_ptr(anAttr); else @@ -56,3 +60,18 @@ shared_ptr Model_Object::docRef(const string theID) } return aRes; } + +shared_ptr Model_Object::real(const string theID) +{ + map >::iterator aFound = myAttrs.find(theID); + if (aFound == myAttrs.end()) { + // TODO: generate error on unknown attribute request and/or add mechanism for customization + return std::shared_ptr(); + } + shared_ptr aRes = + dynamic_pointer_cast(aFound->second); + if (!aRes) { + // TODO: generate error on invalid attribute type request + } + return aRes; +} diff --git a/src/Model/Model_Object.h b/src/Model/Model_Object.h index d96f90b18..ecaca8920 100644 --- a/src/Model/Model_Object.h +++ b/src/Model/Model_Object.h @@ -35,7 +35,9 @@ public: /// Defines the name of the feature visible by the user in the object browser virtual void setName(std::string theName); /// Returns the attribute that references to another document - std::shared_ptr docRef(const std::string theID); + virtual std::shared_ptr docRef(const std::string theID); + /// Returns the attribute that contains real value with double precision + virtual std::shared_ptr real(const std::string theID); /// Initializes object by the attributes: must be called just after the object is created /// for each attribute of the object diff --git a/src/Model/Model_PluginManager.cxx b/src/Model/Model_PluginManager.cxx index f2b7a5594..15b85a9b1 100644 --- a/src/Model/Model_PluginManager.cxx +++ b/src/Model/Model_PluginManager.cxx @@ -43,6 +43,17 @@ std::shared_ptr Model_PluginManager::rootDocument() Model_Application::getApplication()->getDocument("root")); } +shared_ptr Model_PluginManager::currentDocument() +{ + if (!myCurrentDoc) + myCurrentDoc = rootDocument(); + return myCurrentDoc; +} + +void Model_PluginManager::setCurrentDocument(shared_ptr theDoc) +{ + myCurrentDoc = theDoc; +} Model_PluginManager::Model_PluginManager() { diff --git a/src/Model/Model_PluginManager.h b/src/Model/Model_PluginManager.h index 196ebd6ca..c0cc31e5f 100644 --- a/src/Model/Model_PluginManager.h +++ b/src/Model/Model_PluginManager.h @@ -25,17 +25,24 @@ class Model_PluginManager : public ModelAPI_PluginManager, public Event_Listener std::map myPlugins; std::map myPluginObjs; ///< instances of the already plugins std::string myCurrentPluginName; ///< name of the plugin that must be loaded currently + std::shared_ptr myCurrentDoc; ///< current working document public: /// Creates the feature object using plugins functionality MODEL_EXPORT virtual std::shared_ptr createFeature(std::string theFeatureID); /// Returns the root document of the application (that may contains sub-documents) - virtual std::shared_ptr rootDocument(); + MODEL_EXPORT virtual std::shared_ptr rootDocument(); + + /// Returns the current document that used for current work in the application + MODEL_EXPORT virtual std::shared_ptr currentDocument(); + + /// Defines the current document that used for current work in the application + MODEL_EXPORT virtual void setCurrentDocument(std::shared_ptr theDoc); /// Registers the plugin that creates features. /// It is obligatory for each plugin to call this function on loading to be found by /// the plugin manager on call of the feature) - virtual void registerPlugin(ModelAPI_Plugin* thePlugin); + MODEL_EXPORT virtual void registerPlugin(ModelAPI_Plugin* thePlugin); /// Processes the configuration file reading MODEL_EXPORT virtual void processEvent(const Event_Message* theMessage); diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 950cbc530..c81c020af 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -16,6 +16,7 @@ SET(PROJECT_HEADERS ModelAPI_Object.h ModelAPI_Document.h ModelAPI_Attribute.h + ModelAPI_AttributeDouble.h ModelAPI_AttributeDocRef.h ) diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 7490fc636..ad58d4228 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -6,6 +6,9 @@ #include "ModelAPI_PluginManager.h" #include "ModelAPI_Feature.h" #include "ModelAPI_Object.h" + #include "ModelAPI_Attribute.h" + #include "ModelAPI_AttributeDocRef.h" + #include "ModelAPI_AttributeDouble.h" %} // to avoid error on this @@ -22,9 +25,15 @@ %shared_ptr(ModelAPI_PluginManager) %shared_ptr(ModelAPI_Feature) %shared_ptr(ModelAPI_Object) +%shared_ptr(ModelAPI_Attribute) +%shared_ptr(ModelAPI_AttributeDocRef) +%shared_ptr(ModelAPI_AttributeDouble) // all supported interfaces %include "ModelAPI_Document.h" %include "ModelAPI_PluginManager.h" %include "ModelAPI_Feature.h" %include "ModelAPI_Object.h" +%include "ModelAPI_Attribute.h" +%include "ModelAPI_AttributeDocRef.h" +%include "ModelAPI_AttributeDouble.h" diff --git a/src/ModelAPI/ModelAPI_AttributeDouble.h b/src/ModelAPI/ModelAPI_AttributeDouble.h new file mode 100644 index 000000000..7dfb882c3 --- /dev/null +++ b/src/ModelAPI/ModelAPI_AttributeDouble.h @@ -0,0 +1,36 @@ +// File: ModelAPI_AttributeDouble.h +// Created: 2 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef ModelAPI_AttributeDouble_HeaderFile +#define ModelAPI_AttributeDouble_HeaderFile + +#include "ModelAPI_Attribute.h" + +/**\class ModelAPI_AttributeDouble + * \ingroup DataModel + * \brief Attribute that contains real value with double precision. + */ + +class MODELAPI_EXPORT ModelAPI_AttributeDouble : public ModelAPI_Attribute +{ +public: + /// Defines the double value + virtual void setValue(double theValue) = 0; + + /// Returns the double value + virtual double value() = 0; + + /// Returns the type of this class of attributes + static std::string type() {return "Double";} + + /// Returns the type of this class of attributes, not static method + virtual std::string attributeType() {return type();} + +protected: + /// Objects are created for features automatically + ModelAPI_AttributeDouble() + {} +}; + +#endif diff --git a/src/ModelAPI/ModelAPI_Iterator.h b/src/ModelAPI/ModelAPI_Iterator.h index 84afc7381..22d2066b3 100644 --- a/src/ModelAPI/ModelAPI_Iterator.h +++ b/src/ModelAPI/ModelAPI_Iterator.h @@ -22,15 +22,18 @@ class MODELAPI_EXPORT ModelAPI_Iterator { public: /// Iterates to the next feature - virtual void Next() = 0; + virtual void next() = 0; /// Returns true if the current iteration is valid and next iteration is possible - virtual bool More() = 0; + virtual bool more() = 0; /// Returns the currently iterated feature - virtual std::shared_ptr Current() = 0; + virtual std::shared_ptr current() = 0; /// Returns the kind of the current feature (faster than Current()->getKind()) - virtual std::string CurrentKind() = 0; + virtual std::string currentKind() = 0; /// Returns the name of the current feature (faster than Current()->getName()) - virtual std::string CurrentName() = 0; + virtual std::string currentName() = 0; + /// Don't changes the current position of iterator. Not fast: iterates the left items. + /// \returns number of left iterations + virtual int numIterationsLeft() = 0; protected: /// Use plugin manager for features creation: this method is diff --git a/src/ModelAPI/ModelAPI_Object.h b/src/ModelAPI/ModelAPI_Object.h index 490e5617a..7f78a35ce 100644 --- a/src/ModelAPI/ModelAPI_Object.h +++ b/src/ModelAPI/ModelAPI_Object.h @@ -10,6 +10,7 @@ #include class ModelAPI_AttributeDocRef; +class ModelAPI_AttributeDouble; /**\class ModelAPI_Object * \ingroup DataModel @@ -29,6 +30,8 @@ public: /// Returns the attribute that references to another document virtual std::shared_ptr docRef(const std::string theID) = 0; + /// Returns the attribute that contains real value with double precision + virtual std::shared_ptr real(const std::string theID) = 0; /// Initializes object by the attributes: must be called just after the object is created /// for each attribute of the object diff --git a/src/ModelAPI/ModelAPI_PluginManager.cxx b/src/ModelAPI/ModelAPI_PluginManager.cxx index 4e9406a9a..6f9834f6a 100644 --- a/src/ModelAPI/ModelAPI_PluginManager.cxx +++ b/src/ModelAPI/ModelAPI_PluginManager.cxx @@ -15,10 +15,9 @@ #include // to avoid unresolved ModelAPI_Iterator() #include -// to avoid unresolved ModelAPI_Attribute() #include -// to avoid unresolved ModelAPI_AttributeDocRef() #include +#include #ifdef WIN32 #include diff --git a/src/ModelAPI/ModelAPI_PluginManager.h b/src/ModelAPI/ModelAPI_PluginManager.h index b53a66336..34e5cca94 100644 --- a/src/ModelAPI/ModelAPI_PluginManager.h +++ b/src/ModelAPI/ModelAPI_PluginManager.h @@ -37,6 +37,12 @@ public: /// Returns the root document of the application (that may contains sub-documents) virtual std::shared_ptr rootDocument() = 0; + /// Returns the current document that used for current work in the application + virtual std::shared_ptr currentDocument() = 0; + + /// Defines the current document that used for current work in the application + virtual void setCurrentDocument(std::shared_ptr theDoc) = 0; + /// loads the library with specific name, appends "lib*.dll" or "*.so" depending on the platform static void ModelAPI_PluginManager::loadLibrary(const std::string theLibName); diff --git a/src/PartSetPlugin/CMakeLists.txt b/src/PartSetPlugin/CMakeLists.txt index 10d71fce7..ab420ebe9 100644 --- a/src/PartSetPlugin/CMakeLists.txt +++ b/src/PartSetPlugin/CMakeLists.txt @@ -5,12 +5,14 @@ INCLUDE(Common) SET(PROJECT_HEADERS PartSetPlugin.h PartSetPlugin_Plugin.h - PartSetPlugin_NewPart.h + PartSetPlugin_Part.h + PartSetPlugin_Point.h ) SET(PROJECT_SOURCES PartSetPlugin_Plugin.cxx - PartSetPlugin_NewPart.cxx + PartSetPlugin_Part.cxx + PartSetPlugin_Point.cxx ) ADD_DEFINITIONS(-DPARTSETPLUGIN_EXPORTS ${BOOST_DEFINITIONS}) diff --git a/src/PartSetPlugin/PartSetPlugin_NewPart.cxx b/src/PartSetPlugin/PartSetPlugin_NewPart.cxx deleted file mode 100644 index 2b2c59bc3..000000000 --- a/src/PartSetPlugin/PartSetPlugin_NewPart.cxx +++ /dev/null @@ -1,27 +0,0 @@ -// File: PartSetPlugin_NewPart.cxx -// Created: 27 Mar 2014 -// Author: Mikhail PONIKAROV - -#include "PartSetPlugin_NewPart.h" -#include "ModelAPI_PluginManager.h" -#include "ModelAPI_Document.h" -#include "ModelAPI_Object.h" -#include "ModelAPI_AttributeDocRef.h" - -using namespace std; - -PartSetPlugin_NewPart::PartSetPlugin_NewPart() -{ -} - -void PartSetPlugin_NewPart::initAttributes() -{ - data()->addAttribute(ModelAPI_AttributeDocRef::type(), PART_DOC_REF); -} - -void PartSetPlugin_NewPart::execute() -{ - shared_ptr aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument(); - data()->setName(string("Part_") + "1"); - aPartSetDoc->subDocument(string("Part_") + "1"); -} diff --git a/src/PartSetPlugin/PartSetPlugin_NewPart.h b/src/PartSetPlugin/PartSetPlugin_NewPart.h deleted file mode 100644 index 1294d4ddb..000000000 --- a/src/PartSetPlugin/PartSetPlugin_NewPart.h +++ /dev/null @@ -1,34 +0,0 @@ -// File: PartSetPlugin_NewPart.hxx -// Created: 27 Mar 2014 -// Author: Mikhail PONIKAROV - -#ifndef PartSetPlugin_NewPart_HeaderFile -#define PartSetPlugin_NewPart_HeaderFile - -#include "PartSetPlugin.h" -#include - -/// part reference attribute -const std::string PART_DOC_REF = "PartDocument"; - -/**\class PartSetPlugin_NewPart - * \ingroup DataModel - * \brief Feature for creation of the new part in PartSet. - */ -class PartSetPlugin_NewPart: public ModelAPI_Feature -{ -public: - /// Returns the kind of a feature - PARTSETPLUGIN_EXPORT virtual std::string getKind() {return "new_part";} - - /// Creates a new part document if needed - PARTSETPLUGIN_EXPORT virtual void execute(); - - /// Request for initialization of data model of the feature: adding all attributes - PARTSETPLUGIN_EXPORT virtual void initAttributes(); - - /// Use plugin manager for features creation - PartSetPlugin_NewPart(); -}; - -#endif diff --git a/src/PartSetPlugin/PartSetPlugin_NewPart.hxx b/src/PartSetPlugin/PartSetPlugin_NewPart.hxx deleted file mode 100644 index 9b824c0ee..000000000 --- a/src/PartSetPlugin/PartSetPlugin_NewPart.hxx +++ /dev/null @@ -1,26 +0,0 @@ -// File: PartSetPlugin_NewPart.hxx -// Created: 27 Mar 2014 -// Author: Mikhail PONIKAROV - -#ifndef PartSetPlugin_NewPart_HeaderFile -#define PartSetPlugin_NewPart_HeaderFile - -#include "PartSetPlugin.h" -#include - -/**\class PartSetPlugin_NewPart - * \ingroup DataModel - * \brief Feature for creation of the new part in PartSet. - */ - -class PartSetPlugin_NewPart: public ModelAPI_Feature -{ -public: - /// Returns the kind of a feature - PARTSETPLUGIN_EXPORT virtual std::string GetKind() {return "new_part";} - - /// Use plugin manager for features creation - PartSetPlugin_NewPart(); -}; - -#endif diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cxx b/src/PartSetPlugin/PartSetPlugin_Part.cxx new file mode 100644 index 000000000..fd9d69d87 --- /dev/null +++ b/src/PartSetPlugin/PartSetPlugin_Part.cxx @@ -0,0 +1,30 @@ +// File: PartSetPlugin_Part.cxx +// Created: 27 Mar 2014 +// Author: Mikhail PONIKAROV + +#include "PartSetPlugin_Part.h" +#include "ModelAPI_PluginManager.h" +#include "ModelAPI_Document.h" +#include "ModelAPI_Object.h" +#include "ModelAPI_Iterator.h" +#include "ModelAPI_AttributeDocRef.h" + +using namespace std; + +PartSetPlugin_Part::PartSetPlugin_Part() +{ +} + +void PartSetPlugin_Part::initAttributes() +{ + data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type()); +} + +void PartSetPlugin_Part::execute() +{ + shared_ptr aDocRef = data()->docRef(PART_ATTR_DOC_REF); + if (!aDocRef->value()) { // create a document if not yet created + shared_ptr aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument(); + aDocRef->setValue(aPartSetDoc->subDocument(data()->getName())); + } +} diff --git a/src/PartSetPlugin/PartSetPlugin_Part.h b/src/PartSetPlugin/PartSetPlugin_Part.h new file mode 100644 index 000000000..c40f1633d --- /dev/null +++ b/src/PartSetPlugin/PartSetPlugin_Part.h @@ -0,0 +1,34 @@ +// File: PartSetPlugin_Part.h +// Created: 27 Mar 2014 +// Author: Mikhail PONIKAROV + +#ifndef PartSetPlugin_Part_HeaderFile +#define PartSetPlugin_Part_HeaderFile + +#include "PartSetPlugin.h" +#include + +/// part reference attribute +const std::string PART_ATTR_DOC_REF = "PartDocument"; + +/**\class PartSetPlugin_Part + * \ingroup DataModel + * \brief Feature for creation of the new part in PartSet. + */ +class PartSetPlugin_Part: public ModelAPI_Feature +{ +public: + /// Returns the kind of a feature + PARTSETPLUGIN_EXPORT virtual std::string getKind() {return "Part";} + + /// Creates a new part document if needed + PARTSETPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + PARTSETPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation + PartSetPlugin_Part(); +}; + +#endif diff --git a/src/PartSetPlugin/PartSetPlugin_Plugin.cxx b/src/PartSetPlugin/PartSetPlugin_Plugin.cxx index 61fbc5a0b..c1998aefa 100644 --- a/src/PartSetPlugin/PartSetPlugin_Plugin.cxx +++ b/src/PartSetPlugin/PartSetPlugin_Plugin.cxx @@ -1,5 +1,6 @@ #include "PartSetPlugin_Plugin.h" -#include "PartSetPlugin_NewPart.h" +#include "PartSetPlugin_Part.h" +#include "PartSetPlugin_Point.h" #include #include @@ -17,12 +18,21 @@ PartSetPlugin_Plugin::PartSetPlugin_Plugin() std::shared_ptr PartSetPlugin_Plugin::createFeature(string theFeatureID) { std::shared_ptr aCreated; - if (theFeatureID == "new_part") { - aCreated = std::shared_ptr(new PartSetPlugin_NewPart); + bool isCurrent = true; // to create a feature in the current document + if (theFeatureID == "Part") { + aCreated = std::shared_ptr(new PartSetPlugin_Part); + isCurrent = false; // allways create in the root document + } else if (theFeatureID == "Point") { + aCreated = std::shared_ptr(new PartSetPlugin_Point); } + // add to a root document for the current moment - if (aCreated) - ModelAPI_PluginManager::get()->rootDocument()->addFeature(aCreated, PARTS_GROUP); + if (aCreated) { + shared_ptr aDoc = isCurrent ? + ModelAPI_PluginManager::get()->currentDocument() : + ModelAPI_PluginManager::get()->rootDocument(); + aDoc->addFeature(aCreated, PARTS_GROUP); + } // feature of such kind is not found return aCreated; } diff --git a/src/PartSetPlugin/PartSetPlugin_Point.cxx b/src/PartSetPlugin/PartSetPlugin_Point.cxx new file mode 100644 index 000000000..be95256c0 --- /dev/null +++ b/src/PartSetPlugin/PartSetPlugin_Point.cxx @@ -0,0 +1,31 @@ +// File: PartSetPlugin_Point.cxx +// Created: 27 Mar 2014 +// Author: Mikhail PONIKAROV + +#include "PartSetPlugin_Point.h" +#include "ModelAPI_PluginManager.h" +#include "ModelAPI_Document.h" +#include "ModelAPI_Object.h" +#include "ModelAPI_AttributeDouble.h" + +using namespace std; + +PartSetPlugin_Point::PartSetPlugin_Point() +{ +} + +void PartSetPlugin_Point::initAttributes() +{ + data()->addAttribute(POINT_ATTR_X, ModelAPI_AttributeDouble::type()); + data()->addAttribute(POINT_ATTR_Y, ModelAPI_AttributeDouble::type()); + data()->addAttribute(POINT_ATTR_Z, ModelAPI_AttributeDouble::type()); +} + +// this is for debug only +#include +void PartSetPlugin_Point::execute() +{ + // TODO: create a real shape for the point using OCC layer + cout<<"X="<real(POINT_ATTR_X)->value()<<" Y="<real(POINT_ATTR_Y)->value() + <<" Z="<real(POINT_ATTR_Z)->value()< + +/// attribute name for X coordinate +const std::string POINT_ATTR_X = "x"; +/// attribute name for Y coordinate +const std::string POINT_ATTR_Y = "y"; +/// attribute name for Z coordinate +const std::string POINT_ATTR_Z = "z"; + +/**\class PartSetPlugin_Point + * \ingroup DataModel + * \brief Feature for creation of the new part in PartSet. + */ +class PartSetPlugin_Point: public ModelAPI_Feature +{ +public: + /// Returns the kind of a feature + PARTSETPLUGIN_EXPORT virtual std::string getKind() {return "Point";} + + /// Creates a new part document if needed + PARTSETPLUGIN_EXPORT virtual void execute(); + + /// Request for initialization of data model of the feature: adding all attributes + PARTSETPLUGIN_EXPORT virtual void initAttributes(); + + /// Use plugin manager for features creation + PartSetPlugin_Point(); +}; + +#endif