Salome HOME
Parts results and activation/deactivation management (show/hide also)
authormpv <mpv@opencascade.com>
Mon, 29 Jun 2015 07:57:14 +0000 (10:57 +0300)
committermpv <mpv@opencascade.com>
Mon, 29 Jun 2015 07:57:14 +0000 (10:57 +0300)
src/Model/Model_AttributeReference.cpp
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/Model/Model_Data.cpp
src/Model/Model_Document.h
src/Model/Model_Objects.cpp
src/Model/Model_ResultPart.cpp
src/Model/Model_ResultPart.h
src/ModelAPI/ModelAPI_ResultPart.h

index 700e2f7d3d387f3e1d902d34a7de0e02692f14a8..beb04549cffe4a51c359d83158e386613ddb07e8 100644 (file)
@@ -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<Model_Document> aDoc =
-        std::dynamic_pointer_cast<Model_Document>(owner()->document());
       if (anObjLab.IsNull()) {
         myRef->Set(myRef->Label());
       } else {
index 852bba22736a200a04c2c042783a8d150a887270..df8ea041beeb781f618c5ce0de32a12f1105e2d4 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
+#include <ModelAPI_ResultPart.h>
 #include <ModelAPI_CompositeFeature.h>
 #include <GeomAPI_Shape.h>
 #include <GeomAPI_PlanarEdges.h>
@@ -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<GeomAPI_Shape>& 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<TopoDS_Shape>();
+  } else {
+    aShape = theSubShape->impl<TopoDS_Shape>();
+    ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(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);
index 1b2f8260155efefa267bca2be85d5bb01b9c2fcf..9e9213f8785a6838689f5bad8a4ddb181e2b0049 100644 (file)
@@ -68,6 +68,10 @@ protected:
   virtual void selectConstruction(
     const ResultPtr& theContext, const std::shared_ptr<GeomAPI_Shape>& 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<GeomAPI_Shape>& 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();
index fa379d7239490d890e3d727a2b08a2f619942601..9228db8ab97e075d1edde3db920058adbee0eec2 100644 (file)
@@ -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;
 }
 
index 5446bcd3cd99c582300b7e216686598fbff62df9..bc414a15672e9d41f7cf7c7c3c4d4916bd8d829b 100644 (file)
@@ -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:
index 1b8e3253b9eda85fc235449e940f623707305434..5d27392b94eee04a3880e2398d97907f43a33870 100644 (file)
@@ -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<ModelAPI_ResultPart> 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
index 10e884ff3c4ed4ff939d1b650b2fef54c0dbf481..e49604794c6e2e4149106645dc762c744b582832 100644 (file)
@@ -74,12 +74,15 @@ bool Model_ResultPart::setDisabled(std::shared_ptr<ModelAPI_Result> 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<ModelAPI_Feature>(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<ModelAPI_Feature>(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<ModelAPI_Result> theThis,
 
 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 (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<ModelAPI_Result>(aDoc->object(aBodyGroup, a));
+        if (aBody.get() && aBody->shape().get() && !aBody->isDisabled()) {
+          TopoDS_Shape aShape = *(aBody->shape()->implPtr<TopoDS_Shape>());
+          if (!aShape.IsNull()) {
+            aBuilder.Add(aResultComp, aShape);
+            aNumSubs++;
+          }
         }
       }
+      if (aNumSubs) {
+        myShape = aResultComp;
+      }
     }
-    if (aNumSubs) {
-      std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
-      aResult->setImpl(new TopoDS_Shape(aResultComp));
-      return aResult;
+  }
+  if (myShape.IsNull())
+    return std::shared_ptr<GeomAPI_Shape>();
+  std::shared_ptr<GeomAPI_Shape> aResult(new GeomAPI_Shape);
+  aResult->setImpl(new TopoDS_Shape(myShape));
+  return aResult;
+}
+
+#include <Model_Document.h>
+#include <TNaming_Tool.hxx>
+#include <TNaming_NamedShape.hxx>
+#include <TNaming_Iterator.hxx>
+#include <TDataStd_Name.hxx>
+
+std::string Model_ResultPart::nameInPart(const std::shared_ptr<GeomAPI_Shape>& theShape)
+{
+  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+  // getting an access to the document of part
+  std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(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<GeomAPI_Shape> Model_ResultPart::shapeInPart(const std::string& theName)
+{
+  /// TODO: not implemented yet
   return std::shared_ptr<GeomAPI_Shape>();
 }
 
index 57e13023931b62e017e2379fac005567853e7868..fe00a84bd0654dbf6b2237b594911593be9a75cc 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "Model.h"
 #include <ModelAPI_ResultPart.h>
+#include <TopoDS_Shape.hxx>
 
 /**\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<ModelAPI_Document> 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<GeomAPI_Shape> shape();
 
+  /// Returns the name of the shape inside of the part
+  MODEL_EXPORT virtual std::string nameInPart(const std::shared_ptr<GeomAPI_Shape>& theShape);
+  /// Returns the shape by the name in the part
+  MODEL_EXPORT virtual std::shared_ptr<GeomAPI_Shape> 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);
index 131af613f772498b0398e2e3e88f215c0e659294..fec9342164ed8d5b26c4e0558f10bd6d2e8f900c 100644 (file)
@@ -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<GeomAPI_Shape>& theShape) = 0;
+  /// Returns the shape by the name in the part
+  virtual std::shared_ptr<GeomAPI_Shape> shapeInPart(const std::string& theName) = 0;
 };
 
 //! Pointer on feature object