From 4af82842098757e6e7f4f28e2eb744d184bb2b3e Mon Sep 17 00:00:00 2001 From: mpv Date: Mon, 29 Jun 2015 10:57:14 +0300 Subject: [PATCH] Parts results and activation/deactivation management (show/hide also) --- src/Model/Model_AttributeReference.cpp | 2 - src/Model/Model_AttributeSelection.cpp | 27 +++++++ src/Model/Model_AttributeSelection.h | 4 ++ src/Model/Model_Data.cpp | 4 +- src/Model/Model_Document.h | 1 + src/Model/Model_Objects.cpp | 8 ++- src/Model/Model_ResultPart.cpp | 97 ++++++++++++++++++++------ src/Model/Model_ResultPart.h | 7 ++ src/ModelAPI/ModelAPI_ResultPart.h | 5 ++ 9 files changed, 127 insertions(+), 28 deletions(-) diff --git a/src/Model/Model_AttributeReference.cpp b/src/Model/Model_AttributeReference.cpp index 700e2f7d3..beb04549c 100644 --- a/src/Model/Model_AttributeReference.cpp +++ b/src/Model/Model_AttributeReference.cpp @@ -36,8 +36,6 @@ void Model_AttributeReference::setValue(ObjectPtr theObject) // same document, use reference attribute if (anObjLab.IsNull() || owner()->document() == theObject->document()) { - std::shared_ptr aDoc = - std::dynamic_pointer_cast(owner()->document()); if (anObjLab.IsNull()) { myRef->Set(myRef->Label()); } else { diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 852bba227..df8ea041b 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -61,7 +62,10 @@ using namespace std; static const int kSTART_VERTEX_DELTA = 1000000; // identifier that there is simple reference: selection equals to context Standard_GUID kSIMPLE_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb29"); +// simple reference in the construction Standard_GUID kCONSTUCTION_SIMPLE_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb28"); +// reference to Part sub-object +Standard_GUID kPART_REF_ID("635eacb2-a1d6-4dec-8348-471fae17cb27"); // on this label is stored: // TNaming_NamedShape - selected shape @@ -120,6 +124,10 @@ void Model_AttributeSelection::setValue(const ResultPtr& theContext, } else { selectConstruction(theContext, theSubShape); } + } else if (theContext->groupName() == ModelAPI_ResultPart::group()) { + aSelLab.ForgetAllAttributes(true); + TDataStd_UAttribute::Set(aSelLab, kPART_REF_ID); + selectPart(theContext, theSubShape); } //the attribute initialized state should be changed by sendAttributeUpdated only //myIsInitialized = true; @@ -606,6 +614,25 @@ void Model_AttributeSelection::selectConstruction( registerSubShape(selectionLabel(), aSubShape, 0, aContextFeature, aMyDoc, "", aRefs); } +void Model_AttributeSelection::selectPart( + const ResultPtr& theContext, const std::shared_ptr& theSubShape) +{ + // store the shape (in case part is not loaded it should be usefull + TopoDS_Shape aShape; + std::string aName = theContext->data()->name(); + if (theSubShape->isNull()) {// the whole part shape is selected + aShape = theContext->shape()->impl(); + } else { + aShape = theSubShape->impl(); + ResultPartPtr aPart = std::dynamic_pointer_cast(theContext); + aName += "/" + aPart->nameInPart(theSubShape); + } + TNaming_Builder aBuilder(selectionLabel()); + aBuilder.Select(aShape, aShape); + // identify by name in the part + TDataStd_Name::Set(selectionLabel(), aName.c_str()); +} + TDF_Label Model_AttributeSelection::selectionLabel() { return myRef.myRef->Label().FindChild(1); diff --git a/src/Model/Model_AttributeSelection.h b/src/Model/Model_AttributeSelection.h index 1b2f82601..9e9213f87 100644 --- a/src/Model/Model_AttributeSelection.h +++ b/src/Model/Model_AttributeSelection.h @@ -68,6 +68,10 @@ protected: virtual void selectConstruction( const ResultPtr& theContext, const std::shared_ptr& theSubShape); + /// Performs the selection for the part result (selection by name of body result inside of part) + virtual void selectPart( + const ResultPtr& theContext, const std::shared_ptr& theSubShape); + /// Returns the label where TNaming_Selection results are stored /// Note: there must be no attributes stored at the same label because Selector clears this lab TDF_Label selectionLabel(); diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index fa379d723..9228db8ab 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -400,7 +400,9 @@ void Model_Data::setIsInHistory(const bool theFlag) bool Model_Data::isDisplayed() { - return myObject.get() && myObject->document().get() && myObject->document()->isActive() && + return myObject.get() && myObject->document().get() && + (myObject->document()->isActive() || + myObject->document() == ModelAPI_Session::get()->moduleDocument()) && // root is accessible allways myFlags->Value(kFlagDisplayed) == Standard_True; } diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 5446bcd3c..bc414a156 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -229,6 +229,7 @@ class Model_Document : public ModelAPI_Document friend class Model_AttributeReference; friend class Model_AttributeRefAttr; friend class Model_AttributeRefList; + friend class Model_ResultPart; friend class DFBrowser; private: diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index 1b8e3253b..5d27392b9 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -341,7 +341,7 @@ ObjectPtr Model_Objects::object(const std::string& theGroupID, const int theInde { createHistory(theGroupID); //TODO: mpv stabilization hotfix - if (myHistory[theGroupID].size() <= theIndex) + if (myHistory[theGroupID].size() <= (const unsigned int)theIndex) return ObjectPtr(); return myHistory[theGroupID][theIndex]; } @@ -816,8 +816,10 @@ void Model_Objects::updateResults(FeaturePtr theFeature) if (aGroup->Get() == ModelAPI_ResultBody::group().c_str()) { aNewBody = createBody(theFeature->data(), aResIndex); } else if (aGroup->Get() == ModelAPI_ResultPart::group().c_str()) { - //aNewBody = createPart(theFeature->data(), aResIndex); - theFeature->execute(); // create the part result + std::shared_ptr aNewP = createPart(theFeature->data(), aResIndex); + theFeature->setResult(aNewP, aResIndex); + if (!aNewP->partDoc().get()) + theFeature->execute(); // create the part result: it is better to restore the previous result if it is possible break; } else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) { theFeature->execute(); // construction shapes are needed for sketch solver diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index 10e884ff3..e49604794 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -74,12 +74,15 @@ bool Model_ResultPart::setDisabled(std::shared_ptr theThis, if (ModelAPI_ResultPart::setDisabled(theThis, theFlag)) { DocumentPtr aDoc = Model_ResultPart::partDoc(); if (aDoc.get()) { + // make the current feature the last in any case: to update shapes defore deactivation too + FeaturePtr aLastFeature = std::dynamic_pointer_cast(aDoc->object( + ModelAPI_Feature::group(), aDoc->size(ModelAPI_Feature::group()) - 1)); + aDoc->setCurrentFeature(aLastFeature, false); if (theFlag) { // disable, so make all features disabled too + // update the shape just before the deactivation: it will be used outside of part + myShape.Nullify(); + shape(); aDoc->setCurrentFeature(FeaturePtr(), false); - } else { // enabled, so make the current feature the last inside of this document - FeaturePtr aLastFeature = std::dynamic_pointer_cast(aDoc->object( - ModelAPI_Feature::group(), aDoc->size(ModelAPI_Feature::group()) - 1)); - aDoc->setCurrentFeature(aLastFeature, false); } } return true; @@ -89,29 +92,79 @@ bool Model_ResultPart::setDisabled(std::shared_ptr theThis, std::shared_ptr Model_ResultPart::shape() { - DocumentPtr aDoc = Model_ResultPart::partDoc(); - if (aDoc.get()) { - const std::string& aBodyGroup = ModelAPI_ResultBody::group(); - TopoDS_Compound aResultComp; - BRep_Builder aBuilder; - aBuilder.MakeCompound(aResultComp); - int aNumSubs = 0; - for(int a = aDoc->size(aBodyGroup) - 1; a >= 0; a--) { - ResultPtr aBody = std::dynamic_pointer_cast(aDoc->object(aBodyGroup, a)); - if (aBody.get() && aBody->shape().get()) { - TopoDS_Shape aShape = *(aBody->shape()->implPtr()); - if (!aShape.IsNull()) { - aBuilder.Add(aResultComp, aShape); - aNumSubs++; + if (myShape.IsNull()) { + DocumentPtr aDoc = Model_ResultPart::partDoc(); + if (aDoc.get()) { + const std::string& aBodyGroup = ModelAPI_ResultBody::group(); + TopoDS_Compound aResultComp; + BRep_Builder aBuilder; + aBuilder.MakeCompound(aResultComp); + int aNumSubs = 0; + for(int a = aDoc->size(aBodyGroup) - 1; a >= 0; a--) { + ResultPtr aBody = std::dynamic_pointer_cast(aDoc->object(aBodyGroup, a)); + if (aBody.get() && aBody->shape().get() && !aBody->isDisabled()) { + TopoDS_Shape aShape = *(aBody->shape()->implPtr()); + if (!aShape.IsNull()) { + aBuilder.Add(aResultComp, aShape); + aNumSubs++; + } } } + if (aNumSubs) { + myShape = aResultComp; + } } - if (aNumSubs) { - std::shared_ptr aResult(new GeomAPI_Shape); - aResult->setImpl(new TopoDS_Shape(aResultComp)); - return aResult; + } + if (myShape.IsNull()) + return std::shared_ptr(); + std::shared_ptr aResult(new GeomAPI_Shape); + aResult->setImpl(new TopoDS_Shape(myShape)); + return aResult; +} + +#include +#include +#include +#include +#include + +std::string Model_ResultPart::nameInPart(const std::shared_ptr& theShape) +{ + TopoDS_Shape aShape = theShape->impl(); + // getting an access to the document of part + std::shared_ptr aDoc = std::dynamic_pointer_cast(partDoc()); + if (!aDoc.get()) // the part document is not presented for the moment + return ""; + TDF_Label anAccessLabel = aDoc->generalLabel(); + + std::string aName; + // check if the subShape is already in DF + Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, anAccessLabel); + Handle(TDataStd_Name) anAttr; + if(!aNS.IsNull() && !aNS->IsEmpty()) { // in the document + if(aNS->Label().FindAttribute(TDataStd_Name::GetID(), anAttr)) { + aName = TCollection_AsciiString(anAttr->Get()).ToCString(); + if(!aName.empty()) { + const TDF_Label& aLabel = aDoc->findNamingName(aName); + + static const std::string aPostFix("_"); + TNaming_Iterator anItL(aNS); + for(int i = 1; anItL.More(); anItL.Next(), i++) { + if(anItL.NewShape() == aShape) { + aName += aPostFix; + aName += TCollection_AsciiString (i).ToCString(); + break; + } + } + } } } + return aName; +} + +std::shared_ptr Model_ResultPart::shapeInPart(const std::string& theName) +{ + /// TODO: not implemented yet return std::shared_ptr(); } diff --git a/src/Model/Model_ResultPart.h b/src/Model/Model_ResultPart.h index 57e130239..fe00a84bd 100644 --- a/src/Model/Model_ResultPart.h +++ b/src/Model/Model_ResultPart.h @@ -9,6 +9,7 @@ #include "Model.h" #include +#include /**\class Model_ResultPart * \ingroup DataModel @@ -19,6 +20,7 @@ */ class Model_ResultPart : public ModelAPI_ResultPart { + TopoDS_Shape myShape; ///< shape of this part created from bodies (updated only of Part deactivation) public: /// Returns the part-document of this result MODEL_EXPORT virtual std::shared_ptr partDoc(); @@ -35,6 +37,11 @@ class Model_ResultPart : public ModelAPI_ResultPart /// Result shape of part document is compound of bodies inside of this part MODEL_EXPORT virtual std::shared_ptr shape(); + /// Returns the name of the shape inside of the part + MODEL_EXPORT virtual std::string nameInPart(const std::shared_ptr& theShape); + /// Returns the shape by the name in the part + MODEL_EXPORT virtual std::shared_ptr shapeInPart(const std::string& theName); + /// Returns the parameters of color definition in the resources config manager MODEL_EXPORT virtual void colorConfigInfo(std::string& theSection, std::string& theName, std::string& theDefault); diff --git a/src/ModelAPI/ModelAPI_ResultPart.h b/src/ModelAPI/ModelAPI_ResultPart.h index 131af613f..fec934216 100644 --- a/src/ModelAPI/ModelAPI_ResultPart.h +++ b/src/ModelAPI/ModelAPI_ResultPart.h @@ -53,6 +53,11 @@ class ModelAPI_ResultPart : public ModelAPI_Result /// Returns true if document is activated (loaded into the memory) virtual bool isActivated() = 0; + + /// Returns the name of the shape inside of the part + virtual std::string nameInPart(const std::shared_ptr& theShape) = 0; + /// Returns the shape by the name in the part + virtual std::shared_ptr shapeInPart(const std::string& theName) = 0; }; //! Pointer on feature object -- 2.39.2