Salome HOME
Initial part document shapes management implementation.
authormpv <mpv@opencascade.com>
Fri, 26 Jun 2015 07:54:38 +0000 (10:54 +0300)
committermpv <mpv@opencascade.com>
Fri, 26 Jun 2015 07:54:38 +0000 (10:54 +0300)
src/Model/Model_Data.cpp
src/Model/Model_Document.cpp
src/Model/Model_Document.h
src/Model/Model_ResultPart.cpp
src/Model/Model_ResultPart.h
src/Model/Model_Session.cpp
src/ModelAPI/ModelAPI_Document.h
src/XGUI/XGUI_Workshop.cpp

index e3020d992e929c8f6d9d7577cf804bedec53809f..fa379d7239490d890e3d727a2b08a2f619942601 100644 (file)
@@ -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)
index 2913075901a1c12bf6c05823643c786bb872ffa2..75cfb1de8b761910f7b3875a35add957da0a6834 100644 (file)
@@ -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<std::shared_ptr<ModelAPI_Feature> > 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<ModelAPI_Feature>(
+        object(ModelAPI_Feature::group(), a));
+      if (aFeature.get() && aFeature->data()->isValid()) {
+        const std::list<std::shared_ptr<ModelAPI_Result> >& aResList = aFeature->results();
+        std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResList.begin();
+        for(; aRes != aResList.end(); aRes++) {
+          ModelAPI_EventCreator::get()->sendUpdated(*aRes, aRedispEvent);
+        }
+      }
+    }
+  }
+}
+
+bool Model_Document::isActive() const
+{
+  return myIsActive;
+}
index 20adb3d05e8e2231417026378b04a97d1dbe5701..5446bcd3cd99c582300b7e216686598fbff62df9 100644 (file)
@@ -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<std::string> 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<ModelAPI_Object> 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<int> 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<Transaction> myTransactions;
-  /// list of info about transactions undone (first is oldest undone)
+  //! list of info about transactions undone (first is oldest undone)
   std::list<Transaction> myRedos;
 
-  /// Optimization for finding the shape-label by topological naming names
+  //! Optimization for finding the shape-label by topological naming names
   std::map<std::string, TDF_Label> 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
index dfd8c85949c0756870bc22422489135182774dd2..bdae260d67d2a865c8496a275504b7530f138609 100644 (file)
@@ -9,6 +9,10 @@
 #include <ModelAPI_AttributeDocRef.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Feature.h>
+#include <ModelAPI_ResultBody.h>
+
+#include <TopoDS_Compound.hxx>
+#include <BRep_Builder.hxx>
 
 std::shared_ptr<ModelAPI_Document> Model_ResultPart::partDoc()
 {
@@ -82,3 +86,31 @@ bool Model_ResultPart::setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
   }
   return false;
 }
+
+std::shared_ptr<GeomAPI_Shape> 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<ModelAPI_Result>(aDoc->object(aBodyGroup, a));
+      if (aBody.get() && aBody->shape().get()) {
+        TopoDS_Shape aShape = *(aBody->shape()->implPtr<TopoDS_Shape>());
+        if (!aShape.IsNull()) {
+          aBuilder.Add(aResultComp, aShape);
+          aNumSubs++;
+        }
+      }
+    }
+    if (aNumSubs) {
+      std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
+      aResult->setImpl(new TopoDS_Shape(aResultComp));
+      return aResult;
+    }
+  }
+  return std::shared_ptr<GeomAPI_Shape>();
+}
index c2c70d94081377e47d23c755112085abff0ba983..2afb017ee7f7a2869916de6ace0204a800604f4d 100644 (file)
@@ -32,6 +32,9 @@ class Model_ResultPart : public ModelAPI_ResultPart
   MODEL_EXPORT virtual bool setDisabled(std::shared_ptr<ModelAPI_Result> theThis,
     const bool theFlag);
 
+  /// Result shape of part document is compound of bodies inside of this part
+  MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> shape();
+
 protected:
   /// makes a result on a temporary feature (an action)
   Model_ResultPart();
index 042ebe6f3964ec88c3a1d6a44b544fe6f2f43651..9d76861f6411516a1cfae49ef2f6151b2937d1dc 100644 (file)
@@ -219,6 +219,11 @@ void Model_Session::setActiveDocument(
   std::shared_ptr<ModelAPI_Document> theDoc, bool theSendSignal)
 {
   if (myCurrentDoc != theDoc) {
+    if (myCurrentDoc.get())
+      myCurrentDoc->setActive(false);
+    if (theDoc.get())
+      theDoc->setActive(true);
+
     std::shared_ptr<ModelAPI_Document> aPrevious = myCurrentDoc;
     myCurrentDoc = theDoc;
     if (theDoc.get() && theSendSignal) {
index 38f02b147cd412e93f2347cdbd8b056572dfd47b..b1aa60c7b41840214668748b376e4479734580be 100644 (file)
@@ -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<ModelAPI_ResultConstruction> createConstruction(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
-  /// Creates a body results
+  //! Creates a body results
   virtual std::shared_ptr<ModelAPI_ResultBody> createBody(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
-  /// Creates a part results
+  //! Creates a part results
   virtual std::shared_ptr<ModelAPI_ResultPart> createPart(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
-  /// Creates a group results
+  //! Creates a group results
   virtual std::shared_ptr<ModelAPI_ResultGroup> createGroup(
       const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0) = 0;
 
@@ -125,17 +125,22 @@ public:
   virtual std::shared_ptr<ModelAPI_Feature> feature(
       const std::shared_ptr<ModelAPI_Result>& 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<std::shared_ptr<ModelAPI_Feature> > 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<ModelAPI_Object> 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
index eaebe08948c4f6814b3ec3ad241ce46ce409d889..bbcef0e89cf857a8122008490661e4f6fae4eca7 100644 (file)
@@ -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<ModelAPI_ResultPart>(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<ModelAPI_ResultPart>(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));