From: mpv Date: Wed, 11 Nov 2015 09:21:52 +0000 (+0300) Subject: Fix for the problem where group is moved to the end, after the operation it was not... X-Git-Tag: V_2.0.0_alfa2~40 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=cc171413e851e053de99dee13870d2c1cab0327e;p=modules%2Fshaper.git Fix for the problem where group is moved to the end, after the operation it was not created on and then export to old GEOM: now the context and the sub-shape is detected correctly. --- diff --git a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py index 924130843..30844b674 100644 --- a/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py +++ b/src/ConnectorPlugin/ConnectorPlugin_ExportFeature.py @@ -114,13 +114,15 @@ class ExportFeature(ModelAPI.ModelAPI_Feature): else: groupType = "SOLID" - # iterate on exported objects and check if the current - # group refers to this object - for obj in self.geomObjects: - if aSelectionContext.shape().isEqual(obj[0]): - aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType]) - self.geompy.UnionIDs(aGroup,Ids) - self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName) + aContextBody = ModelAPI.modelAPI_ResultBody(aSelectionContext) + if aContextBody is not None: + # iterate on exported objects and check if the current + # group refers to this object + for obj in self.geomObjects: + if aContextBody.isLatestEqual(obj[0]): + aGroup = self.geompy.CreateGroup(obj[1], self.geompy.ShapeType[groupType]) + self.geompy.UnionIDs(aGroup,Ids) + self.geompy.addToStudyInFather(obj[1], aGroup, theGroupName) ## Exports all shapes and groups into the GEOM module. def execute(self): diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 232ff61b5..bdc924e27 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -327,11 +327,14 @@ TDF_LabelMap& Model_AttributeSelection::scope() aCompositeOwnerOwner = ModelAPI_Tools::compositeOwner(aCompositeOwner); } } + // for group Scope is not limitet: this is always up to date objects + bool isGroup = aFeature.get() && aFeature->getKind() == "Group"; for(; aFIter != allFeatures.end(); aFIter++) { if (*aFIter == owner()) { // the left features are created later (except subs of composite) aMePassed = true; continue; } + if (isGroup) aMePassed = false; bool isInScope = !aMePassed; if (!isInScope && aComposite.get()) { // try to add sub-elements of composite if this is composite if (aComposite->isSub(*aFIter)) @@ -903,14 +906,24 @@ void Model_AttributeSelection::selectSubShape( int Model_AttributeSelection::Id() { + int anID = 0; std::shared_ptr aSelection = value(); std::shared_ptr aContext = context()->shape(); - const TopoDS_Shape& aMainShape = aContext->impl(); + TopoDS_Shape aMainShape = aContext->impl(); const TopoDS_Shape& aSubShape = aSelection->impl(); - int anID = 0; + // searching for the latest main shape if (aSelection && !aSelection->isNull() && aContext && !aContext->isNull()) { + std::shared_ptr aDoc = + std::dynamic_pointer_cast(context()->document()); + if (aDoc.get()) { + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aMainShape, aDoc->generalLabel()); + if (!aNS.IsNull()) { + aMainShape = TNaming_Tool::CurrentShape(aNS); + } + } + TopTools_IndexedMapOfShape aSubShapesMap; TopExp::MapShapes(aMainShape, aSubShapesMap); anID = aSubShapesMap.FindIndex(aSubShape); diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index bacee75eb..ee6ba1b79 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -759,3 +760,21 @@ std::shared_ptr Model_BodyBuilder::shape() } return std::shared_ptr(); } + +bool Model_BodyBuilder::isLatestEqual(const std::shared_ptr& theShape) +{ + if (theShape.get()) { + TopoDS_Shape aShape = theShape->impl(); + std::shared_ptr aData = std::dynamic_pointer_cast(data()); + if (aData) { + TDF_Label& aShapeLab = aData->shapeLab(); + Handle(TNaming_NamedShape) aName; + if (aShapeLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) { + TopoDS_Shape aLatest = TNaming_Tool::CurrentShape(aName); + if (aLatest.IsEqual(aShape)) + return true; + } + } + } + return false; +} diff --git a/src/Model/Model_BodyBuilder.h b/src/Model/Model_BodyBuilder.h index 85032d4f8..3785d2164 100755 --- a/src/Model/Model_BodyBuilder.h +++ b/src/Model/Model_BodyBuilder.h @@ -109,6 +109,10 @@ public: /// (theFlag = true) and back (theFlag = false) MODEL_EXPORT virtual void evolutionToSelection(const bool theFlag); + /// Returns true if the latest modification of this body in the naming history + // is equal to the given shape + MODEL_EXPORT virtual bool isLatestEqual(const std::shared_ptr& theShape); + protected: /// Default constructor accessible only by Model_Objects Model_BodyBuilder(ModelAPI_Object* theOwner); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 1c7645b0c..b3bdb63b7 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -265,6 +265,7 @@ class Model_Document : public ModelAPI_Document friend class Model_AttributeReference; friend class Model_AttributeRefAttr; friend class Model_AttributeRefList; + friend class Model_AttributeSelection; friend class Model_ResultPart; friend class Model_ResultCompSolid; friend class DFBrowser; diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index d7e3f46c9..8418ba22f 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -41,3 +41,8 @@ bool Model_ResultBody::setDisabled(std::shared_ptr theThis, con } return aChanged; } + +bool Model_ResultBody::isLatestEqual(const std::shared_ptr& theShape) +{ + return myBuilder->isLatestEqual(theShape); +} diff --git a/src/Model/Model_ResultBody.h b/src/Model/Model_ResultBody.h index 1300be1c5..3c4b0f9ca 100644 --- a/src/Model/Model_ResultBody.h +++ b/src/Model/Model_ResultBody.h @@ -40,6 +40,11 @@ public: /// naming data structure if theFlag if false. Or restores everything on theFlag is true. MODEL_EXPORT virtual bool setDisabled(std::shared_ptr theThis, const bool theFlag); + + /// Returns true if the latest modification of this body in the naming history + // is equal to the given shape + MODEL_EXPORT virtual bool isLatestEqual(const std::shared_ptr& theShape); + /// Removes the stored builders MODEL_EXPORT virtual ~Model_ResultBody() {}; diff --git a/src/Model/Model_ResultCompSolid.cpp b/src/Model/Model_ResultCompSolid.cpp index b731fdcef..4b83d3d59 100755 --- a/src/Model/Model_ResultCompSolid.cpp +++ b/src/Model/Model_ResultCompSolid.cpp @@ -188,3 +188,8 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr& the aECreator->sendUpdated(data()->owner(), EVENT_DISP); } } + +bool Model_ResultCompSolid::isLatestEqual(const std::shared_ptr& theShape) +{ + return myBuilder->isLatestEqual(theShape); +} diff --git a/src/Model/Model_ResultCompSolid.h b/src/Model/Model_ResultCompSolid.h index 21fb163b9..ba92674e8 100755 --- a/src/Model/Model_ResultCompSolid.h +++ b/src/Model/Model_ResultCompSolid.h @@ -70,6 +70,10 @@ public: /// Sets all subs as concealed in the data tree (referenced by other objects) MODEL_EXPORT virtual void setIsConcealed(const bool theValue); + /// Returns true if the latest modification of this body in the naming history + // is equal to the given shape + MODEL_EXPORT virtual bool isLatestEqual(const std::shared_ptr& theShape); + protected: /// Makes a body on the given feature Model_ResultCompSolid(); diff --git a/src/ModelAPI/ModelAPI_BodyBuilder.h b/src/ModelAPI/ModelAPI_BodyBuilder.h index 3d945b47c..38f2868a9 100755 --- a/src/ModelAPI/ModelAPI_BodyBuilder.h +++ b/src/ModelAPI/ModelAPI_BodyBuilder.h @@ -101,6 +101,10 @@ public: /// (theFlag = true) and back (theFlag = false) virtual void evolutionToSelection(const bool theFlag) = 0; + /// Returns true if the latest modification of this body in the naming history + // is equal to the given shape + virtual bool isLatestEqual(const std::shared_ptr& theShape) = 0; + protected: /// Returns the data manager of this object: attributes MODELAPI_EXPORT virtual std::shared_ptr data() const; diff --git a/src/ModelAPI/ModelAPI_ResultBody.h b/src/ModelAPI/ModelAPI_ResultBody.h index 54df9a2c6..272d94e3e 100644 --- a/src/ModelAPI/ModelAPI_ResultBody.h +++ b/src/ModelAPI/ModelAPI_ResultBody.h @@ -111,6 +111,10 @@ public: MODELAPI_EXPORT virtual void loadDisconnectedVertexes(std::shared_ptr theShape, const std::string& theName,int& theTag); + /// Returns true if the latest modification of this body in the naming history + // is equal to the given shape + MODELAPI_EXPORT virtual bool isLatestEqual(const std::shared_ptr& theShape) = 0; + protected: /// Default constructor accessible only from Model_Objects MODELAPI_EXPORT ModelAPI_ResultBody();