From 48915b522a7277ba36d2af01acc9e89b72bd4c85 Mon Sep 17 00:00:00 2001 From: mpv Date: Fri, 26 Jun 2015 10:54:38 +0300 Subject: [PATCH] Initial part document shapes management implementation. --- src/Model/Model_Data.cpp | 3 ++- src/Model/Model_Document.cpp | 29 ++++++++++++++++++++++++- src/Model/Model_Document.h | 37 +++++++++++++++++++------------- src/Model/Model_ResultPart.cpp | 32 +++++++++++++++++++++++++++ src/Model/Model_ResultPart.h | 3 +++ src/Model/Model_Session.cpp | 5 +++++ src/ModelAPI/ModelAPI_Document.h | 25 ++++++++++++--------- src/XGUI/XGUI_Workshop.cpp | 8 +++++-- 8 files changed, 113 insertions(+), 29 deletions(-) diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index e3020d992..fa379d723 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -400,7 +400,8 @@ void Model_Data::setIsInHistory(const bool theFlag) bool Model_Data::isDisplayed() { - return myFlags->Value(kFlagDisplayed) == Standard_True; + return myObject.get() && myObject->document().get() && myObject->document()->isActive() && + myFlags->Value(kFlagDisplayed) == Standard_True; } void Model_Data::setDisplayed(const bool theDisplay) diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index 291307590..75cfb1de8 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -48,7 +48,7 @@ static const int TAG_GENERAL = 1; // general properties tag static const int TAG_CURRENT_FEATURE = 1; ///< where the reference to the current feature label is located (or no attribute if null feature) Model_Document::Model_Document(const std::string theID, const std::string theKind) - : myID(theID), myKind(theKind), + : myID(theID), myKind(theKind), myIsActive(false), myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format { myObjs = new Model_Objects(myDoc->Main()); @@ -835,3 +835,30 @@ std::list > Model_Document::allFeatures() { return myObjs->allFeatures(); } + +void Model_Document::setActive(const bool theFlag) +{ + if (theFlag != myIsActive) { + myIsActive = theFlag; + // redisplay all the objects of this part + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + + for(int a = size(ModelAPI_Feature::group()) - 1; a >= 0; a--) { + FeaturePtr aFeature = std::dynamic_pointer_cast( + object(ModelAPI_Feature::group(), a)); + if (aFeature.get() && aFeature->data()->isValid()) { + const std::list >& aResList = aFeature->results(); + std::list >::const_iterator aRes = aResList.begin(); + for(; aRes != aResList.end(); aRes++) { + ModelAPI_EventCreator::get()->sendUpdated(*aRes, aRedispEvent); + } + } + } + } +} + +bool Model_Document::isActive() const +{ + return myIsActive; +} diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index 20adb3d05..5446bcd3c 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -204,20 +204,25 @@ class Model_Document : public ModelAPI_Document //! Returns the list of Ids of the operations that can be redoed (called for the root document) std::list redoList() const; - /// Internally makes document know that feature was removed or added in history after creation + //! Internally makes document know that feature was removed or added in history after creation virtual void updateHistory(const std::shared_ptr theObject); - /// Internally makes document know that feature was removed or added in history after creation + //! Internally makes document know that feature was removed or added in history after creation virtual void updateHistory(const std::string theGroup); - /// Returns true if the document is root module document + //! Returns true if the document is root module document bool isRoot() const; - /// Sets shared pointer to this + //! Sets shared pointer to this void setThis(DocumentPtr theDoc); - /// Returns the objects manager + //! Returns the objects manager Model_Objects* objects() {return myObjs;} + ///! Informs the document that it becomes active and some actions must be performed + virtual void setActive(const bool theFlag); + //! Returns true if this document is currently active + virtual bool isActive() const; + friend class Model_Application; friend class Model_Session; friend class Model_Update; @@ -233,30 +238,32 @@ class Model_Document : public ModelAPI_Document Model_Objects *myObjs; ///< data manager of this document - /// counter value of transaction on the last "save" call, used for "IsModified" method + //! counter value of transaction on the last "save" call, used for "IsModified" method int myTransactionSave; - /// number of nested transactions performed (list becasue may be nested inside of nested) - /// the list is empty if not nested transaction is performed + //! number of nested transactions performed (list becasue may be nested inside of nested) + //! the list is empty if not nested transaction is performed std::list myNestedNum; - /// Information related to the every user-transaction + //! Information related to the every user-transaction struct Transaction { int myOCAFNum; ///< number of OCAF transactions related to each "this" transaction, may be 0 std::string myId; ///< user-identifier string of transaction - /// default constructor with default Id + //! default constructor with default Id Transaction(): myOCAFNum(0), myId("") {} }; - /// transaction indexes (related to myTransactionsAfterSave) and info about the real transactions - /// in myDocument connected to this operation (may be zero for empty transaction) + //! transaction indexes (related to myTransactionsAfterSave) and info about the real transactions + //! in myDocument connected to this operation (may be zero for empty transaction) std::list myTransactions; - /// list of info about transactions undone (first is oldest undone) + //! list of info about transactions undone (first is oldest undone) std::list myRedos; - /// Optimization for finding the shape-label by topological naming names + //! Optimization for finding the shape-label by topological naming names std::map myNamingNames; - /// If it is true, features are not executed on update (on abort, undo, redo) + //! If it is true, features are not executed on update (on abort, undo, redo) bool myExecuteFeatures; + + bool myIsActive; ///< flag that stores the active/not active state }; #endif diff --git a/src/Model/Model_ResultPart.cpp b/src/Model/Model_ResultPart.cpp index dfd8c8594..bdae260d6 100644 --- a/src/Model/Model_ResultPart.cpp +++ b/src/Model/Model_ResultPart.cpp @@ -9,6 +9,10 @@ #include #include #include +#include + +#include +#include std::shared_ptr Model_ResultPart::partDoc() { @@ -82,3 +86,31 @@ bool Model_ResultPart::setDisabled(std::shared_ptr theThis, } return false; } + +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 (aNumSubs) { + std::shared_ptr aResult(new GeomAPI_Shape); + aResult->setImpl(new TopoDS_Shape(aResultComp)); + return aResult; + } + } + return std::shared_ptr(); +} diff --git a/src/Model/Model_ResultPart.h b/src/Model/Model_ResultPart.h index c2c70d940..2afb017ee 100644 --- a/src/Model/Model_ResultPart.h +++ b/src/Model/Model_ResultPart.h @@ -32,6 +32,9 @@ class Model_ResultPart : public ModelAPI_ResultPart MODEL_EXPORT virtual bool setDisabled(std::shared_ptr theThis, const bool theFlag); + /// Result shape of part document is compound of bodies inside of this part + MODEL_EXPORT virtual std::shared_ptr shape(); + protected: /// makes a result on a temporary feature (an action) Model_ResultPart(); diff --git a/src/Model/Model_Session.cpp b/src/Model/Model_Session.cpp index 042ebe6f3..9d76861f6 100644 --- a/src/Model/Model_Session.cpp +++ b/src/Model/Model_Session.cpp @@ -219,6 +219,11 @@ void Model_Session::setActiveDocument( std::shared_ptr theDoc, bool theSendSignal) { if (myCurrentDoc != theDoc) { + if (myCurrentDoc.get()) + myCurrentDoc->setActive(false); + if (theDoc.get()) + theDoc->setActive(true); + std::shared_ptr aPrevious = myCurrentDoc; myCurrentDoc = theDoc; if (theDoc.get() && theSendSignal) { diff --git a/src/ModelAPI/ModelAPI_Document.h b/src/ModelAPI/ModelAPI_Document.h index 38f02b147..b1aa60c7b 100644 --- a/src/ModelAPI/ModelAPI_Document.h +++ b/src/ModelAPI/ModelAPI_Document.h @@ -102,19 +102,19 @@ public: //! Makes the current feature one feature upper virtual void setCurrentFeatureUp() = 0; - /// To virtually destroy the fields of successors + //! To virtually destroy the fields of successors MODELAPI_EXPORT virtual ~ModelAPI_Document(); - /// Creates a construction cresults + //! Creates a construction cresults virtual std::shared_ptr createConstruction( const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; - /// Creates a body results + //! Creates a body results virtual std::shared_ptr createBody( const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; - /// Creates a part results + //! Creates a part results virtual std::shared_ptr createPart( const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; - /// Creates a group results + //! Creates a group results virtual std::shared_ptr createGroup( const std::shared_ptr& theFeatureData, const int theIndex = 0) = 0; @@ -125,17 +125,22 @@ public: virtual std::shared_ptr feature( const std::shared_ptr& theResult) = 0; - ///! Returns all features of the document including the hidden features which are not in - ///! history. Not very fast method, for calling once, not in big cycles. + //! Returns all features of the document including the hidden features which are not in + //! history. Not very fast method, for calling once, not in big cycles. virtual std::list > allFeatures() = 0; + //! Informs the document that it becomes active and some actions must be performed + virtual void setActive(const bool theFlag) = 0; + //! Returns true if this document is currently active + virtual bool isActive() const = 0; + protected: - /// Only for SWIG wrapping it is here + //! Only for SWIG wrapping it is here MODELAPI_EXPORT ModelAPI_Document(); - /// Internally makes document know that feature was removed or added in history after creation + //! Internally makes document know that feature was removed or added in history after creation MODELAPI_EXPORT virtual void updateHistory(const std::shared_ptr theObject) = 0; - /// Internally makes document know that feature was removed or added in history after creation + //! Internally makes document know that feature was removed or added in history after creation MODELAPI_EXPORT virtual void updateHistory(const std::string theGroup) = 0; friend class ModelAPI_Object; // to add or remove from the history diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index eaebe0894..bbcef0e89 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -1634,6 +1634,7 @@ for (int i = 0; i < aDoc->size(aGroupName); i++) { \ void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible) { foreach (ObjectPtr aObj, theList) { + /* ResultPartPtr aPartRes = std::dynamic_pointer_cast(aObj); if (aPartRes) { DocumentPtr aDoc = aPartRes->partDoc(); @@ -1641,8 +1642,9 @@ void XGUI_Workshop::showObjects(const QObjectPtrList& theList, bool isVisible) SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), isVisible) SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), isVisible) } else { + */ aObj->setDisplayed(isVisible); - } + //} } Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); } @@ -1657,6 +1659,7 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList) // Show only objects from the list foreach (ObjectPtr aObj, theList) { + /* ResultPartPtr aPartRes = std::dynamic_pointer_cast(aObj); if (aPartRes) { DocumentPtr aDoc = aPartRes->partDoc(); @@ -1664,8 +1667,9 @@ void XGUI_Workshop::showOnlyObjects(const QObjectPtrList& theList) SET_DISPLAY_GROUP(ModelAPI_ResultConstruction::group(), true) SET_DISPLAY_GROUP(ModelAPI_ResultGroup::group(), true) } else { + */ aObj->setDisplayed(true); - } + //} } Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); -- 2.39.2