From: mpv Date: Thu, 8 May 2014 04:51:37 +0000 (+0400) Subject: Added history of features and removed Iterator (size and feature by index must be... X-Git-Tag: V_0.2~81 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d55b9b2a4aec1ad934bed2edda57d31ea33e34ae;p=modules%2Fshaper.git Added history of features and removed Iterator (size and feature by index must be used instead) --- diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index c0c67230e..142a02bb4 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -7,6 +7,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET(PROJECT_HEADERS GeomAPI.h GeomAPI_Interface.h + GeomAPI_XYZ.h GeomAPI_Pnt.h GeomAPI_Dir.h GeomAPI_Pln.h @@ -15,6 +16,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES GeomAPI_Interface.cpp + GeomAPI_XYZ.cpp GeomAPI_Pnt.cpp GeomAPI_Dir.cpp GeomAPI_Pln.cpp diff --git a/src/GeomAPI/GeomAPI_Dir.cpp b/src/GeomAPI/GeomAPI_Dir.cpp index bf0941c31..6e8ea2429 100644 --- a/src/GeomAPI/GeomAPI_Dir.cpp +++ b/src/GeomAPI/GeomAPI_Dir.cpp @@ -2,9 +2,10 @@ // Created: 23 Apr 2014 // Author: Mikhail PONIKAROV -#include +#include +#include -#include +#include #define MY_DIR static_cast(myImpl) @@ -26,3 +27,8 @@ double GeomAPI_Dir::z() const { return MY_DIR->Z(); } + +const boost::shared_ptr GeomAPI_Dir::xyz() +{ + return boost::shared_ptr(new GeomAPI_XYZ(MY_DIR->X(), MY_DIR->Y(), MY_DIR->Z())); +} diff --git a/src/GeomAPI/GeomAPI_Dir.h b/src/GeomAPI/GeomAPI_Dir.h index 7993a3d77..afdab1c09 100644 --- a/src/GeomAPI/GeomAPI_Dir.h +++ b/src/GeomAPI/GeomAPI_Dir.h @@ -6,6 +6,9 @@ #define GeomAPI_Dir_HeaderFile #include +#include + +class GeomAPI_XYZ; /**\class GeomAPI_Dir * \ingroup DataModel @@ -25,6 +28,8 @@ public: /// returns Z coordinate double z() const; + /// returns coordinates of the direction + const boost::shared_ptr xyz(); }; #endif diff --git a/src/GeomAPI/GeomAPI_Pnt.cpp b/src/GeomAPI/GeomAPI_Pnt.cpp index 6414a2dc3..83d1dddf9 100644 --- a/src/GeomAPI/GeomAPI_Pnt.cpp +++ b/src/GeomAPI/GeomAPI_Pnt.cpp @@ -3,6 +3,7 @@ // Author: Mikhail PONIKAROV #include +#include #include @@ -12,6 +13,10 @@ GeomAPI_Pnt::GeomAPI_Pnt(const double theX, const double theY, const double theZ : GeomAPI_Interface(new gp_Pnt(theX, theY, theZ)) {} +GeomAPI_Pnt::GeomAPI_Pnt(const boost::shared_ptr& theCoords) + : GeomAPI_Interface(new gp_Pnt(theCoords->x(), theCoords->y(), theCoords->z())) +{} + double GeomAPI_Pnt::x() const { return MY_PNT->X(); @@ -41,3 +46,8 @@ void GeomAPI_Pnt::setZ(const double theZ) { return MY_PNT->SetZ(theZ); } + +const boost::shared_ptr GeomAPI_Pnt::xyz() +{ + return boost::shared_ptr(new GeomAPI_XYZ(MY_PNT->X(), MY_PNT->Y(), MY_PNT->Z())); +} diff --git a/src/GeomAPI/GeomAPI_Pnt.h b/src/GeomAPI/GeomAPI_Pnt.h index 8f80bef18..a63974d98 100644 --- a/src/GeomAPI/GeomAPI_Pnt.h +++ b/src/GeomAPI/GeomAPI_Pnt.h @@ -6,6 +6,9 @@ #define GeomAPI_Pnt_HeaderFile #include +#include + +class GeomAPI_XYZ; /**\class GeomAPI_Pnt * \ingroup DataModel @@ -17,6 +20,8 @@ class GEOMAPI_EXPORT GeomAPI_Pnt: public GeomAPI_Interface public: /// Creation of point by coordinates GeomAPI_Pnt(const double theX, const double theY, const double theZ); + /// Creation of point by coordinates + GeomAPI_Pnt(const boost::shared_ptr& theCoords); /// returns X coordinate double x() const; @@ -31,6 +36,9 @@ public: void setY(const double theY); /// sets Z coordinate void setZ(const double theZ); + + /// returns coordinates of the point + const boost::shared_ptr xyz(); }; #endif diff --git a/src/GeomAPI/GeomAPI_XYZ.cpp b/src/GeomAPI/GeomAPI_XYZ.cpp new file mode 100644 index 000000000..30c246323 --- /dev/null +++ b/src/GeomAPI/GeomAPI_XYZ.cpp @@ -0,0 +1,58 @@ +// File: GeomAPI_XYZ.cpp +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#include + +#include + +#define MY_XYZ static_cast(myImpl) + +GeomAPI_XYZ::GeomAPI_XYZ(const double theX, const double theY, const double theZ) + : GeomAPI_Interface(new gp_XYZ(theX, theY, theZ)) +{} + +double GeomAPI_XYZ::x() const +{ + return MY_XYZ->X(); +} + +double GeomAPI_XYZ::y() const +{ + return MY_XYZ->Y(); +} + +double GeomAPI_XYZ::z() const +{ + return MY_XYZ->Z(); +} + +void GeomAPI_XYZ::setX(const double theX) +{ + return MY_XYZ->SetX(theX); +} + +void GeomAPI_XYZ::setY(const double theY) +{ + return MY_XYZ->SetY(theY); +} + +void GeomAPI_XYZ::setZ(const double theZ) +{ + return MY_XYZ->SetZ(theZ); +} + +const boost::shared_ptr GeomAPI_XYZ::added( + const boost::shared_ptr& theArg) +{ + boost::shared_ptr aResult(new GeomAPI_XYZ(MY_XYZ->X() + theArg->x(), + MY_XYZ->Y() + theArg->y(), MY_XYZ->Z() + theArg->z())); + return aResult; +} + +const boost::shared_ptr GeomAPI_XYZ::multiplied(const double theArg) +{ + boost::shared_ptr aResult(new GeomAPI_XYZ(MY_XYZ->X() * theArg, + MY_XYZ->Y() * theArg, MY_XYZ->Z() * theArg)); + return aResult; +} diff --git a/src/GeomAPI/GeomAPI_XYZ.h b/src/GeomAPI/GeomAPI_XYZ.h new file mode 100644 index 000000000..6042428e5 --- /dev/null +++ b/src/GeomAPI/GeomAPI_XYZ.h @@ -0,0 +1,43 @@ +// File: GeomAPI_XYZ.hxx +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAPI_XYZ_HeaderFile +#define GeomAPI_XYZ_HeaderFile + +#include +#include + +/**\class GeomAPI_XYZ + * \ingroup DataModel + * \brief 3 coordinates: they may represent vector or point or something else + */ + +class GEOMAPI_EXPORT GeomAPI_XYZ: public GeomAPI_Interface +{ +public: + /// Creation by coordinates + GeomAPI_XYZ(const double theX, const double theY, const double theZ); + + /// returns X coordinate + double x() const; + /// returns Y coordinate + double y() const; + /// returns Z coordinate + double z() const; + + /// sets X coordinate + void setX(const double theX); + /// sets Y coordinate + void setY(const double theY); + /// sets Z coordinate + void setZ(const double theZ); + + /// result is sum of coordinates of this and the given argument + const boost::shared_ptr added(const boost::shared_ptr& theArg); + /// result is coordinates multiplied by the argument + const boost::shared_ptr multiplied(const double theArg); +}; + +#endif + diff --git a/src/GeomData/GeomData_Dir.h b/src/GeomData/GeomData_Dir.h index 56a8b9d2a..a7c1a2497 100644 --- a/src/GeomData/GeomData_Dir.h +++ b/src/GeomData/GeomData_Dir.h @@ -31,7 +31,7 @@ public: /// Returns the Z double value GEOMDATA_EXPORT virtual double z() const; /// Returns the direction of this attribute - GEOMDATA_EXPORT boost::shared_ptr dir(); + GEOMDATA_EXPORT virtual boost::shared_ptr dir(); protected: /// Initializes attributes diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index b928f3695..faf24fe99 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -5,6 +5,7 @@ #include "GeomData_Point.h" #include "Model_Events.h" #include +#include using namespace std; @@ -35,6 +36,13 @@ double GeomData_Point::z() const return myCoords->Value(2); } +boost::shared_ptr GeomData_Point::pnt() +{ + boost::shared_ptr aResult(new GeomAPI_Pnt( + myCoords->Value(0), myCoords->Value(1), myCoords->Value(2))); + return aResult; +} + GeomData_Point::GeomData_Point(TDF_Label& theLabel) { // check the attribute could be already presented in this doc (after load document) diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h index 9886333c2..ee319e89e 100644 --- a/src/GeomData/GeomData_Point.h +++ b/src/GeomData/GeomData_Point.h @@ -28,6 +28,8 @@ public: GEOMDATA_EXPORT virtual double y() const; /// Returns the Z double value GEOMDATA_EXPORT virtual double z() const; + /// Returns the 3D point + GEOMDATA_EXPORT virtual boost::shared_ptr pnt(); protected: /// Initializes attributes diff --git a/src/GeomDataAPI/GeomDataAPI_Dir.h b/src/GeomDataAPI/GeomDataAPI_Dir.h index 92018306c..dbe8ef5e2 100644 --- a/src/GeomDataAPI/GeomDataAPI_Dir.h +++ b/src/GeomDataAPI/GeomDataAPI_Dir.h @@ -8,6 +8,8 @@ #include "GeomDataAPI.h" #include +class GeomAPI_Dir; + /**\class GeomDataAPI_Dir * \ingroup DataModel * \brief Attribute that contains 3D direction coordinates. @@ -25,6 +27,8 @@ public: virtual double y() const = 0; /// Returns the Z double value virtual double z() const = 0; + /// Returns the direction of this attribute + virtual boost::shared_ptr dir() = 0; /// Returns the type of this class of attributes static inline std::string type() {return std::string("Dir");} diff --git a/src/GeomDataAPI/GeomDataAPI_Point.h b/src/GeomDataAPI/GeomDataAPI_Point.h index 68f294e60..c9581b2be 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point.h +++ b/src/GeomDataAPI/GeomDataAPI_Point.h @@ -8,6 +8,8 @@ #include "GeomDataAPI.h" #include +class GeomAPI_Pnt; + /**\class GeomDataAPI_Point * \ingroup DataModel * \brief Attribute that contains 3D point coordinates. @@ -25,6 +27,8 @@ public: virtual double y() const = 0; /// Returns the Z double value virtual double z() const = 0; + /// Returns the 3D point + virtual boost::shared_ptr pnt() = 0; /// Returns the type of this class of attributes static inline std::string type() {return std::string("Point");} diff --git a/src/Model/CMakeLists.txt b/src/Model/CMakeLists.txt index 7b60ee48c..ea081fac1 100644 --- a/src/Model/CMakeLists.txt +++ b/src/Model/CMakeLists.txt @@ -7,7 +7,6 @@ SET(PROJECT_HEADERS Model_Document.h Model_PluginManager.h Model_Data.h - Model_Iterator.h Model_AttributeDouble.h Model_AttributeDocRef.h Model_Events.h @@ -18,7 +17,6 @@ SET(PROJECT_SOURCES Model_Document.cpp Model_PluginManager.cpp Model_Data.cpp - Model_Iterator.cpp Model_AttributeDouble.cpp Model_AttributeDocRef.cpp Model_Events.cpp diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 1548c709e..0cb633666 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -34,7 +34,6 @@ class Model_Data: public ModelAPI_Data TDF_Label label() {return myLab;} friend class Model_Document; - friend class Model_Iterator; public: /// Returns the name of the feature visible by the user in the object browser diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 304bef421..790bab22f 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -7,21 +7,22 @@ #include #include #include -#include #include #include #include #include #include +#include +#include #include static const int UNDO_LIMIT = 10; // number of possible undo operations static const int TAG_GENERAL = 1; // general properties tag -static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (Root for Model_DatasMgr) -static const int TAG_HISTORY = 3; // tag of the history sub-tree (Root for Model_History) +static const int TAG_OBJECTS = 2; // tag of the objects sub-tree (features) +static const int TAG_HISTORY = 3; // tag of the history sub-tree (python dump) using namespace std; @@ -208,7 +209,8 @@ void Model_Document::redo() boost::shared_ptr Model_Document::addFeature(string theID) { - boost::shared_ptr aFeature = ModelAPI_PluginManager::get()->createFeature(theID); + boost::shared_ptr aFeature = + ModelAPI_PluginManager::get()->createFeature(theID); if (aFeature) { boost::dynamic_pointer_cast(aFeature->documentToAdd())->addFeature(aFeature); } else { @@ -225,7 +227,8 @@ void Model_Document::addFeature(const boost::shared_ptr theFea boost::shared_ptr aData(new Model_Data); aData->setFeature(theFeature); aData->setLabel(anObjLab); - boost::shared_ptr aThis = Model_Application::getApplication()->getDocument(myID); + boost::shared_ptr aThis = + Model_Application::getApplication()->getDocument(myID); theFeature->setData(aData); theFeature->setDoc(aThis); setUniqueName(theFeature); @@ -235,6 +238,20 @@ void Model_Document::addFeature(const boost::shared_ptr theFea // put index of the feature in the group in the tree TDataStd_Integer::Set(anObjLab, myFeatures[aGroup].size()); myFeatures[aGroup].push_back(theFeature); + // store feature in the history of features array + Handle(TDataStd_ReferenceArray) aRefs; + if (!groupLabel(FEATURES_GROUP).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) { + aRefs = TDataStd_ReferenceArray::Set(groupLabel(FEATURES_GROUP), 0, 0); + aRefs->SetValue(0, anObjLab); + } else { // extend array by one more element + Handle(TDataStd_HLabelArray1) aNewArray = + new TDataStd_HLabelArray1(aRefs->Lower(), aRefs->Upper() + 1); + for(int a = aRefs->Lower(); a < aRefs->Upper(); a++) { + aNewArray->SetValue(a, aRefs->Value(a)); + } + aNewArray->SetValue(aRefs->Upper() + 1, anObjLab); + aRefs->SetInternalArray(aNewArray); + } // event: feature is added static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED); @@ -260,7 +277,8 @@ int Model_Document::featureIndex(boost::shared_ptr theFeature) if (theFeature->document().get() != this) { return theFeature->document()->featureIndex(theFeature); } - boost::shared_ptr aData = boost::dynamic_pointer_cast(theFeature->data()); + boost::shared_ptr aData = + boost::dynamic_pointer_cast(theFeature->data()); Handle(TDataStd_Integer) aFeatureIndex; if (aData->label().FindAttribute(TDataStd_Integer::GetID(), aFeatureIndex)) { return aFeatureIndex->Get(); @@ -276,22 +294,42 @@ boost::shared_ptr Model_Document::subDocument(string theDocID return Model_Application::getApplication()->getDocument(theDocID); } -boost::shared_ptr Model_Document::featuresIterator(const string theGroup) +boost::shared_ptr Model_Document::feature( + const string& theGroupID, const int theIndex) { - boost::shared_ptr aThis(Model_Application::getApplication()->getDocument(myID)); - // create an empty iterator for not existing group - // (to avoidance of attributes management outside the transaction) - if (myGroups.find(theGroup) == myGroups.end()) - return boost::shared_ptr(new Model_Iterator()); - return boost::shared_ptr(new Model_Iterator(aThis, groupLabel(theGroup))); + if (theGroupID == FEATURES_GROUP) { // history is just a references array + Handle(TDataStd_ReferenceArray) aRefs; + if (groupLabel(FEATURES_GROUP).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) { + if (aRefs->Lower() <= theIndex && aRefs->Upper() >= theIndex) { + TDF_Label aFeatureLab = aRefs->Value(theIndex); + return feature(aFeatureLab); + } + } + } else { // one of the group + map > >::iterator aGroup = + myFeatures.find(theGroupID); + if (aGroup != myFeatures.end() && (int)(aGroup->second.size()) > theIndex) { + return aGroup->second[theIndex]; + } + } + // not found + return boost::shared_ptr(); } -boost::shared_ptr Model_Document::feature(const string& theGroupID, const int theIndex) +int Model_Document::size(const string& theGroupID) { - // TODO: optimize this method - boost::shared_ptr anIter = featuresIterator(theGroupID); - for(int a = 0; a != theIndex && anIter->more(); anIter->next()) a++; - return anIter->more() ? anIter->current() : boost::shared_ptr(); + if (theGroupID == FEATURES_GROUP) { // history is just a references array + Handle(TDataStd_ReferenceArray) aRefs; + if (groupLabel(FEATURES_GROUP).FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) + return aRefs->Length(); + } else { // one of the group + map > >::iterator aGroup = + myFeatures.find(theGroupID); + if (aGroup != myFeatures.end()) + return aGroup->second.size(); + } + // group is not found + return 0; } const vector& Model_Document::getGroups() const @@ -304,11 +342,6 @@ Model_Document::Model_Document(const std::string theID) { myDoc->SetUndoLimit(UNDO_LIMIT); myTransactionsAfterSave = 0; - // to avoid creation of tag outside of the transaction (by iterator, for example) - /* - if (!myDoc->Main().FindChild(TAG_OBJECTS).IsAttribute(TDF_TagSource::GetID())) - TDataStd_Comment::Set(myDoc->Main().FindChild(TAG_OBJECTS).NewChild(), ""); - */ } TDF_Label Model_Document::groupLabel(const string theGroup) @@ -326,10 +359,10 @@ TDF_Label Model_Document::groupLabel(const string theGroup) void Model_Document::setUniqueName(boost::shared_ptr theFeature) { // first count all objects of such kind to start with index = count + 1 - int aNumObjects = 0; - boost::shared_ptr anIter = featuresIterator(theFeature->getGroup()); - for(; anIter->more(); anIter->next()) { - if (anIter->currentKind() == theFeature->getKind()) + int a, aNumObjects = 0; + int aSize = size(theFeature->getGroup()); + for(a = 0; a < aSize; a++) { + if (feature(theFeature->getGroup(), a)->getKind() == theFeature->getKind()) aNumObjects++; } // generate candidate name @@ -337,14 +370,14 @@ void Model_Document::setUniqueName(boost::shared_ptr theFeatur aNameStream<getKind()<<"_"<getGroup()); anIter->more();) { - if (anIter->currentName() == aName) { + for(a = 0; a < aSize;) { + if (feature(theFeature->getGroup(), a)->data()->getName() == aName) { aNumObjects++; stringstream aNameStream; aNameStream<getKind()<<"_"<getGroup()); - } else anIter->next(); + a = 0; + } else a++; } theFeature->data()->setName(aName); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index f98788c5e..0bf22b98e 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -70,16 +70,16 @@ public: //! Adds a new sub-document by the identifier, or returns existing one if it is already exist MODEL_EXPORT virtual boost::shared_ptr subDocument(std::string theDocID); - //! Creates an iterator of the features by the specific groups - MODEL_EXPORT virtual boost::shared_ptr featuresIterator( - const std::string theGroup); - + ///! Returns the id of hte document MODEL_EXPORT virtual const std::string& id() const {return myID;} //! Returns the feature in the group by the index (started from zero) MODEL_EXPORT virtual boost::shared_ptr feature(const std::string& theGroupID, const int theIndex); + //! Returns the number of features in the group + MODEL_EXPORT virtual int size(const std::string& theGroupID); + ///! Returns the vector of groups already added to the document MODEL_EXPORT virtual const std::vector& getGroups() const; diff --git a/src/Model/Model_Iterator.cpp b/src/Model/Model_Iterator.cpp deleted file mode 100644 index ba59cdf75..000000000 --- a/src/Model/Model_Iterator.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// File: Model_Iterator.hxx -// Created: 1 Apr 2014 -// Author: Mikhail PONIKAROV - -#include "Model_Iterator.h" -#include "Model_Document.h" -#include "ModelAPI_Feature.h" -#include "Model_Data.h" -#include -#include - -using namespace std; - -void Model_Iterator::next() -{ - return myIter.Next(); -} - -bool Model_Iterator::more() -{ - return myIter.More() == Standard_True; -} - -boost::shared_ptr Model_Iterator::current() -{ - TDF_Label aLab = myIter.Value()->Label(); - return myDoc->feature(aLab); -} - -string Model_Iterator::currentKind() -{ - return string(TCollection_AsciiString( - Handle(TDataStd_Comment)::DownCast(myIter.Value())->Get()).ToCString()); -} - -string Model_Iterator::currentName() -{ - TDF_Label aLab = myIter.Value()->Label(); - Handle(TDataStd_Name) aName; - if (aLab.FindAttribute(TDataStd_Name::GetID(), aName)) - return string(TCollection_AsciiString(aName->Get()).ToCString()); - return ""; // name is not found -} - -int Model_Iterator::numIterationsLeft() -{ - int aResult = 0; - TDF_ChildIDIterator aTempIter(myIter); - for(; aTempIter.More(); aTempIter.Next()) - aResult++; - return aResult; -} - -bool Model_Iterator::isEqual(boost::shared_ptr theFeature) -{ - return (myIter.Value()->Label() == - boost::dynamic_pointer_cast(theFeature->data())->label()) == Standard_True; - -} - -Model_Iterator::Model_Iterator() -{ -} - -Model_Iterator::Model_Iterator(boost::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 deleted file mode 100644 index ff116605d..000000000 --- a/src/Model/Model_Iterator.h +++ /dev/null @@ -1,55 +0,0 @@ -// File: Model_Iterator.h -// Created: 1 Apr 2014 -// Author: Mikhail PONIKAROV - -#ifndef Model_Iterator_HeaderFile -#define Model_Iterator_HeaderFile - -#include "Model.h" -#include "ModelAPI_Iterator.h" -#include -#include - -class Model_Document; - -/**\class Model_Iterator - * \ingroup DataModel - * \brief Allows to iterate features of the document. Is created by the document - * (see method featuresIterator). - */ - -class Model_Iterator : public ModelAPI_Iterator -{ - boost::shared_ptr myDoc; ///< the document of iterated objects - TDF_ChildIDIterator myIter; ///< iterator of the features-labels -public: - /// Iterates to the next feature - MODEL_EXPORT virtual void next(); - /// Returns true if the current iteration is valid and next iteration is possible - MODEL_EXPORT virtual bool more(); - /// Returns the currently iterated feature - MODEL_EXPORT virtual boost::shared_ptr current(); - /// Returns the kind of the current feature (faster than Current()->getKind()) - MODEL_EXPORT virtual std::string currentKind(); - /// Returns the name of the current feature (faster than Current()->getName()) - MODEL_EXPORT virtual std::string currentName(); - /// Don't changes the current position of iterator. Not fast: iterates the left items. - /// \returns number of left iterations - MODEL_EXPORT virtual int numIterationsLeft(); - - /// Compares the current feature with the given one - /// \returns true if given feature equals to the current one - MODEL_EXPORT virtual bool isEqual(boost::shared_ptr theFeature); - -protected: - /// Creates an empty iterator that alway returns More false - Model_Iterator(); - /// Initializes iterator - /// \param theDoc document where the iteration is performed - /// \param theLab label of the features group to iterate - Model_Iterator(boost::shared_ptr theDoc, TDF_Label theLab); - - friend class Model_Document; -}; - -#endif diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index b5a717b02..2fe5b5359 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -7,7 +7,6 @@ SET(PROJECT_HEADERS ModelAPI_PluginManager.h ModelAPI_Plugin.h ModelAPI_Feature.h - ModelAPI_Iterator.h ModelAPI_Data.h ModelAPI_Document.h ModelAPI_Attribute.h diff --git a/src/ModelAPI/ModelAPI.i b/src/ModelAPI/ModelAPI.i index 19be24d4d..119f73d16 100644 --- a/src/ModelAPI/ModelAPI.i +++ b/src/ModelAPI/ModelAPI.i @@ -9,7 +9,6 @@ #include "ModelAPI_Attribute.h" #include "ModelAPI_AttributeDocRef.h" #include "ModelAPI_AttributeDouble.h" - #include "ModelAPI_Iterator.h" %} // to avoid error on this @@ -29,7 +28,6 @@ %shared_ptr(ModelAPI_Attribute) %shared_ptr(ModelAPI_AttributeDocRef) %shared_ptr(ModelAPI_AttributeDouble) -%shared_ptr(ModelAPI_Iterator) // all supported interfaces %include "ModelAPI_Document.h" @@ -39,4 +37,3 @@ %include "ModelAPI_Attribute.h" %include "ModelAPI_AttributeDocRef.h" %include "ModelAPI_AttributeDouble.h" -%include "ModelAPI_Iterator.h" diff --git a/src/ModelAPI/ModelAPI_Attribute.h b/src/ModelAPI/ModelAPI_Attribute.h index 011430d72..d00bbc76a 100644 --- a/src/ModelAPI/ModelAPI_Attribute.h +++ b/src/ModelAPI/ModelAPI_Attribute.h @@ -27,9 +27,11 @@ public: /// To virtually destroy the fields of successors MODELAPI_EXPORT virtual ~ModelAPI_Attribute() {} + /// Sets the owner of this attribute MODELAPI_EXPORT void setFeature(const boost::shared_ptr& theFeature) {myFeature = theFeature;} + /// Returns the owner of this attribute MODELAPI_EXPORT const boost::shared_ptr& feature() {return myFeature;} protected: diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index efc85b275..4ae738022 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -11,7 +11,6 @@ #include class ModelAPI_Feature; -class ModelAPI_Iterator; /// Common groups identifiers /// Group of parameters @@ -20,8 +19,8 @@ static const std::string PARAMETERS_GROUP = "Parameters"; static const std::string CONSTRUCTIONS_GROUP = "Construction"; /// Group of parts static const std::string PARTS_GROUP = "Parts"; -/// Group of sketches -static const std::string SKETCHS_GROUP = "Sketchs"; +/// All created fetaures of the document (a history) +static const std::string FEATURES_GROUP = "Features"; /**\class Model_Document * \ingroup DataModel @@ -73,10 +72,6 @@ public: ///! Adds a new sub-document by the identifier, or returns existing one if it is already exist MODELAPI_EXPORT virtual boost::shared_ptr subDocument(std::string theDocID) = 0; - ///! Creates an iterator of the features by the specific groups - MODELAPI_EXPORT virtual boost::shared_ptr featuresIterator( - const std::string theGroup) = 0; - ///! Returns the id of hte document MODELAPI_EXPORT virtual const std::string& id() const = 0; @@ -84,6 +79,9 @@ public: MODELAPI_EXPORT virtual boost::shared_ptr feature(const std::string& theGroupID, const int theIndex) = 0; + //! Returns the number of features in the group + MODELAPI_EXPORT virtual int size(const std::string& theGroupID) = 0; + //! Returns the index of feature in the group (zero based) MODELAPI_EXPORT virtual int featureIndex(boost::shared_ptr theFeature) = 0; diff --git a/src/ModelAPI/ModelAPI_Iterator.h b/src/ModelAPI/ModelAPI_Iterator.h deleted file mode 100644 index db4a5d119..000000000 --- a/src/ModelAPI/ModelAPI_Iterator.h +++ /dev/null @@ -1,51 +0,0 @@ -// File: ModelAPI_Iterator.hxx -// Created: 1 Apr 2014 -// Author: Mikhail PONIKAROV - -#ifndef ModelAPI_Iterator_HeaderFile -#define ModelAPI_Iterator_HeaderFile - -#include "ModelAPI.h" -#include -#include - -class ModelAPI_Feature; -class ModelAPI_Document; - -/**\class ModelAPI_Iterator - * \ingroup DataModel - * \brief Allows to iterate features of the document. Is created by the document - * (see method featuresIterator). - */ - -class MODELAPI_EXPORT ModelAPI_Iterator -{ -public: - /// Iterates to the next feature - virtual void next() = 0; - /// Returns true if the current iteration is valid and next iteration is possible - virtual bool more() = 0; - /// Returns the currently iterated feature - virtual boost::shared_ptr current() = 0; - /// Returns the kind of the current feature (faster than Current()->getKind()) - virtual std::string currentKind() = 0; - /// Returns the name of the current feature (faster than Current()->getName()) - 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; - /// Compares the current feature with the given one - /// \returns true if given feature equals to the current one - virtual bool isEqual(boost::shared_ptr theFeature) = 0; - - /// To virtually destroy the fields of successors - virtual ~ModelAPI_Iterator() {} - -protected: - /// Use plugin manager for features creation: this method is - /// defined here only for SWIG-wrapping - ModelAPI_Iterator() - {} -}; - -#endif diff --git a/src/ModelAPI/ModelAPI_PluginManager.cpp b/src/ModelAPI/ModelAPI_PluginManager.cpp index 772ac8d98..285bb4031 100644 --- a/src/ModelAPI/ModelAPI_PluginManager.cpp +++ b/src/ModelAPI/ModelAPI_PluginManager.cpp @@ -11,10 +11,6 @@ #include // to avoid unresolved ModelAPI_Plugin() #include -// to avoid unresolved ModelAPI_Iterator() -#include -// to avoid unresolved ModelAPI_Iterator() -#include #include #include #include diff --git a/src/PartSetPlugin/PartSetPlugin_Part.cpp b/src/PartSetPlugin/PartSetPlugin_Part.cpp index 144411717..0fd91d969 100644 --- a/src/PartSetPlugin/PartSetPlugin_Part.cpp +++ b/src/PartSetPlugin/PartSetPlugin_Part.cpp @@ -6,7 +6,6 @@ #include "ModelAPI_PluginManager.h" #include "ModelAPI_Document.h" #include "ModelAPI_Data.h" -#include "ModelAPI_Iterator.h" #include "ModelAPI_AttributeDocRef.h" using namespace std; diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 6acb48d74..35d90ab5d 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -4,6 +4,7 @@ #include "SketchPlugin_Sketch.h" #include +#include #include #include #include @@ -70,8 +71,8 @@ boost::shared_ptr SketchPlugin_Sketch::to3D(const double theX, cons boost::shared_ptr aY = boost::dynamic_pointer_cast(data()->attribute(SKETCH_ATTR_DIRY)); - return boost::shared_ptr(new GeomAPI_Pnt( - aC->x() + aX->x() * theX + aY->x() * theY, - aC->y() + aX->y() * theX + aY->y() * theY, - aC->z() + aX->z() * theX + aY->z() * theY)); + boost::shared_ptr aSum = aC->pnt()->xyz()->added( + aX->dir()->xyz()->multiplied(theX))->added(aY->dir()->xyz()->multiplied(theY)); + + return boost::shared_ptr(new GeomAPI_Pnt(aSum)); } diff --git a/src/XGUI/XGUI_DocumentDataModel.cpp b/src/XGUI/XGUI_DocumentDataModel.cpp index a9bb8b61b..ebae53b82 100644 --- a/src/XGUI/XGUI_DocumentDataModel.cpp +++ b/src/XGUI/XGUI_DocumentDataModel.cpp @@ -2,7 +2,6 @@ #include "XGUI_PartDataModel.h" #include -#include #include #include #include @@ -125,7 +124,7 @@ void XGUI_DocumentDataModel::processEvent(const Events_Message* theMessage) // Reset whole tree ************************** } else { beginResetModel(); - int aNbParts = myDocument->featuresIterator(PARTS_GROUP)->numIterationsLeft(); + int aNbParts = myDocument->size(PARTS_GROUP); if (myPartModels.size() != aNbParts) { // resize internal models while (myPartModels.size() > aNbParts) { delete myPartModels.last(); @@ -341,4 +340,4 @@ QModelIndex XGUI_DocumentDataModel::partFolderNode() const { int aPos = myModel->rowCount(QModelIndex()); return createIndex(aPos, columnCount() - 1, 0); -} \ No newline at end of file +} diff --git a/src/XGUI/XGUI_PartDataModel.cpp b/src/XGUI/XGUI_PartDataModel.cpp index 3ca210d76..0e31dd7fd 100644 --- a/src/XGUI/XGUI_PartDataModel.cpp +++ b/src/XGUI/XGUI_PartDataModel.cpp @@ -1,7 +1,6 @@ #include "XGUI_PartDataModel.h" #include -#include #include #include #include @@ -74,10 +73,10 @@ int XGUI_TopDataModel::rowCount(const QModelIndex& theParent) const return 2; if (theParent.internalId() == ParamsFolder) - return myDocument->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft(); + return myDocument->size(PARAMETERS_GROUP); if (theParent.internalId() == ConstructFolder) - return myDocument->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft(); + return myDocument->size(CONSTRUCTIONS_GROUP); return 0; } @@ -246,9 +245,9 @@ int XGUI_PartDataModel::rowCount(const QModelIndex& parent) const case MyRoot: return 3; case ParamsFolder: - return featureDocument()->featuresIterator(PARAMETERS_GROUP)->numIterationsLeft(); + return featureDocument()->size(PARAMETERS_GROUP); case ConstructFolder: - return featureDocument()->featuresIterator(CONSTRUCTIONS_GROUP)->numIterationsLeft(); + return featureDocument()->size(CONSTRUCTIONS_GROUP); case BodiesFolder: return 0; }