Salome HOME
Merge branch 'Dev_1.2.0' of newgeom:newgeom into Dev_1.2.0
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 21 May 2015 14:25:53 +0000 (17:25 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 21 May 2015 14:25:53 +0000 (17:25 +0300)
15 files changed:
src/FeaturesPlugin/extrusion_widget.xml
src/Model/Model_AttributeSelection.cpp
src/Model/Model_AttributeSelection.h
src/Model/Model_Document.cpp
src/Model/Model_Objects.cpp
src/Model/Model_Session.cpp
src/Model/Model_Session.h
src/ModelAPI/ModelAPI_AttributeSelection.h
src/ModelAPI/ModelAPI_Session.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/PartSet/PartSet_WidgetShapeSelector.cpp
src/PartSet/PartSet_WidgetShapeSelector.h
src/PartSetPlugin/PartSetPlugin_Part.cpp
src/XGUI/XGUI_Displayer.cpp

index d68dbe414245c643f29f4360236875664d0105dd..5783d542c91d650034452da3bccba393a648ea67 100644 (file)
@@ -13,7 +13,8 @@
                     icon=":icons/plane.png"
                     label="Plane face"
                     tooltip="Select a planar face"
-                    shape_types="face">
+                    shape_types="face"
+                    default="&lt;sketch&gt;">
       <validator id="GeomValidators_Face" parameters="plane"/>
     </shape_selector>
     <doublevalue
@@ -32,7 +33,8 @@
                     icon=":icons/plane_inverted.png"
                     label="Plane face"
                     tooltip="Select a planar face"
-                    shape_types="face">
+                    shape_types="face"
+                    default="&lt;sketch&gt;">
       <validator id="GeomValidators_Face" parameters="plane"/>
     </shape_selector>
     <doublevalue
index d6f9f869eb5fdf184b293bcd64e754a05bf03006..6ff60d02e363dde45d66a62466e116f72c006518 100644 (file)
@@ -649,10 +649,11 @@ bool isTrivial (const TopTools_ListOfShape& theAncestors, TopTools_IndexedMapOfS
   if(aNumber > 1) return false;
   return true;
 }
-std::string Model_AttributeSelection::namingName()
+std::string Model_AttributeSelection::namingName(const std::string& theDefaultName)
 {
   std::string aName("");
-  if(!this->isInitialized()) return aName;
+  if(!this->isInitialized())
+    return !theDefaultName.empty() ? theDefaultName : aName;
   Handle(TDataStd_Name) anAtt;
   if(selectionLabel().FindAttribute(TDataStd_Name::GetID(), anAtt)) {
     aName = TCollection_AsciiString(anAtt->Get()).ToCString();
@@ -663,7 +664,7 @@ std::string Model_AttributeSelection::namingName()
   ResultPtr aCont = context();
   aName = "Undefined name";
   if(!aCont.get() || aCont->shape()->isNull()) 
-    return aName;
+    return !theDefaultName.empty() ? theDefaultName : aName;
   if (!aSubSh.get() || aSubSh->isNull()) { // no subshape, so just the whole feature name
     return aCont->data()->name();
   }
index b900299de1b8f16fc8e3b22e3e64c68d89e222e8..19c1a151490126d014cc4931642f3d492bebbe08 100644 (file)
@@ -40,7 +40,8 @@ public:
   MODEL_EXPORT virtual bool update();
 
   /// Returns a textual string of the selection
-  MODEL_EXPORT virtual std::string namingName();
+  /// \param theDefaultValue a name, which is returned if the naming name can not be obtained
+  MODEL_EXPORT virtual std::string namingName(const std::string& theDefaultValue = "");
   
   /// Returns an Id of the selection
   /// NOTE: This method has been added for temporary export of groups towards old GEOM
index b1477e5c8f727c8d723ef6319533a0d2e7986a04..82ae16d6520b8e50cb5634d48785e26b7f9f8bc7 100644 (file)
@@ -569,8 +569,10 @@ void Model_Document::removeFeature(FeaturePtr theFeature)
   if (theFeature == currentFeature(false)) {
     int aCurrentIndex = index(theFeature);
     if (aCurrentIndex != -1) {
-      setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(
-        object(ModelAPI_Feature::group(), aCurrentIndex - 1)), false);
+      ObjectPtr aPrevObj;
+      if (aCurrentIndex != 0)
+        aPrevObj = object(ModelAPI_Feature::group(), aCurrentIndex - 1);
+      setCurrentFeature(std::dynamic_pointer_cast<ModelAPI_Feature>(aPrevObj), false);
     }
   }
   myObjs->removeFeature(theFeature);
@@ -654,6 +656,7 @@ void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurr
   const bool theVisible)
 {
   TDF_Label aRefLab = generalLabel().FindChild(TAG_CURRENT_FEATURE);
+  CompositeFeaturePtr aMain; // main feature that may nest the new current
   if (theCurrent.get()) {
     /*
     if (theVisible) { // make features below which are not in history also enabled: sketch subs
@@ -673,7 +676,8 @@ void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurr
       CompositeFeaturePtr aComposite = 
         std::dynamic_pointer_cast<ModelAPI_CompositeFeature>((*aRefToMe)->owner());
       if (aComposite.get() && aComposite->isSub(theCurrent)) {
-        theCurrent = aComposite;
+        aMain = aComposite;
+        break;
       }
     }
 
@@ -694,10 +698,6 @@ void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurr
   static Events_Loop* aLoop = Events_Loop::loop();
   static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
 
-  // if the current feature is composite features, all sub-features also must be enabled
-  CompositeFeaturePtr aCurComp = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theCurrent);
-
-
   bool aPassed = false; // flag that the current object is already passed in cycle
   FeaturePtr anIter = myObjs->lastFeature();
   for(; anIter.get(); anIter = myObjs->nextFeature(anIter, true)) {
@@ -705,7 +705,7 @@ void Model_Document::setCurrentFeature(std::shared_ptr<ModelAPI_Feature> theCurr
     if (anIter == theCurrent) aPassed = true;
 
     bool aDisabledFlag = !aPassed;
-    if (aCurComp.get() && aCurComp->isSub(anIter))
+    if (aMain.get() && aMain->isSub(anIter))
       aDisabledFlag = false;
     if (anIter->setDisabled(aDisabledFlag)) {
       // state of feature is changed => so feature become updated
index e87508864abad949886e2070b4001a5f18c5b833..2356a20537c7b0e12758f70dfcd11a50aeda74f5 100644 (file)
@@ -486,6 +486,7 @@ void Model_Objects::synchronizeFeatures(
       aNewFeatures.insert(aFeature);
       initData(aFeature, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
       updateHistory(aFeature);
+      aFeature->setDisabled(false); // by default created feature is enabled (this allows to recreate the results before "setCurrent" is called)
 
       // event: model is updated
       ModelAPI_EventCreator::get()->sendUpdated(aFeature, aCreateEvent);
@@ -600,6 +601,15 @@ void Model_Objects::synchronizeBackRefs()
             std::shared_ptr<Model_Data> aRefData = 
               std::dynamic_pointer_cast<Model_Data>((*aRefTo)->data());
             aRefData->addBackReference(aFeature, aRefsIter->first); // here the Concealed flag is updated
+            // update enable/disable status: the nested status must be equal to the composite
+            CompositeFeaturePtr aComp = 
+              std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aFeature);
+            if (aComp.get()) {
+              FeaturePtr aReferenced = std::dynamic_pointer_cast<ModelAPI_Feature>(*aRefTo);
+              if (aReferenced.get()) {
+                aReferenced->setDisabled(aComp->isDisabled());
+              }
+            }
           }
         }
       }
@@ -777,7 +787,9 @@ 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);
+          //aNewBody = createPart(theFeature->data(), aResIndex); 
+          theFeature->execute(); // create the part result
+          break;
         } else if (aGroup->Get() == ModelAPI_ResultConstruction::group().c_str()) {
           theFeature->execute(); // construction shapes are needed for sketch solver
           break;
index ea951c7962c13b8eb64508fcfffc6cf3f60d7e11..de3cddb282f2560b844528f3ae709c76da93c40a 100644 (file)
@@ -250,6 +250,11 @@ std::list<std::shared_ptr<ModelAPI_Document> > Model_Session::allOpenedDocuments
   return aResult;
 }
 
+bool Model_Session::isLoadByDemand(const std::string theDocID)
+{
+  return Model_Application::getApplication()->isLoadByDemand(theDocID);
+}
+
 std::shared_ptr<ModelAPI_Document> Model_Session::copy(
     std::shared_ptr<ModelAPI_Document> theSource, std::string theID)
 {
index ebfef43d0f943958ea15e15b935723e3fa6c77da..2584a2e201aa35a14012df0e8c79c6a08ea29d9c 100644 (file)
@@ -90,6 +90,9 @@ class Model_Session : public ModelAPI_Session, public Events_Listener
   /// Returns all the opened documents of the session (without postponed)
   MODEL_EXPORT virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments();
 
+  /// Returns true if document is not loaded yet
+  MODEL_EXPORT virtual bool isLoadByDemand(const std::string theDocID);
+
   /// Registers the plugin that creates features.
   /// It is obligatory for each plugin to call this function on loading to be found by 
   /// the plugin manager on call of the feature)
index 495da4180492d8eb36b9d62ba4d6e7978e6bd698..71c850e59830047483ded064f64885f76fd9bcd9 100644 (file)
@@ -42,7 +42,8 @@ class ModelAPI_AttributeSelection : public ModelAPI_Attribute
   MODELAPI_EXPORT virtual std::string attributeType();
 
   /// Returns a textual string of the selection
-  virtual std::string namingName() = 0;
+  /// \param theDefaultValue a value, which is used if the naming name can not be obtained
+  virtual std::string namingName(const std::string& theDefaultValue = "") = 0;
   
   /// Returns an id of the selection
   virtual int Id() = 0;
index 5c927e7d3eec56226d1b56c43e9e9cbe23acf550..47f6071810e4980069cec0671d47fde61f3e3bf1 100644 (file)
@@ -93,6 +93,9 @@ class MODELAPI_EXPORT ModelAPI_Session
   /// Returns all the opened documents of the session (without postponed)
   virtual std::list<std::shared_ptr<ModelAPI_Document> > allOpenedDocuments() = 0;
 
+  /// Returns true if document is not loaded yet
+  virtual bool isLoadByDemand(const std::string theDocID) = 0;
+
   /// Copies the document to the new one with the given id
   virtual std::shared_ptr<ModelAPI_Document> copy(std::shared_ptr<ModelAPI_Document> theSource,
                                                     std::string theID) = 0;
index cea370ba22459d542c78437cc3e13f7c637347af..785e98b4141f73de40e9fbe431f8e9ee1d31ca67 100644 (file)
@@ -263,7 +263,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
   bool isNameUpdated = false;
   AttributeSelectionPtr aSelect = aData->selection(attributeID());
   if (aSelect) {
-    myTextLine->setText(QString::fromStdString(aSelect->namingName()));
+    myTextLine->setText(QString::fromStdString(aSelect->namingName(getDefaultValue())));
     isNameUpdated = true;
   }
   if (!isNameUpdated) {
@@ -283,7 +283,7 @@ void ModuleBase_WidgetShapeSelector::updateSelectionName()
         }
       }
       else {
-        myTextLine->setText("");
+        myTextLine->setText(getDefaultValue().c_str());
       }
     }
   }
index e21d756fd7751ffb54c52b3130e7b7590f66f7e4..2dcd3662d1fa3457edf6be3d096680d4a8f34ea6 100644 (file)
@@ -122,10 +122,6 @@ Q_OBJECT
   /// \param theShape a shape
   virtual bool acceptSubShape(std::shared_ptr<GeomAPI_Shape> theShape) const;
 
-  // Get the shape from the attribute it the attribute contain a shape, e.g. selection attribute
-  /// \return a shape
-  GeomShapePtr getShape() const;
-
   /// Clear attribute
   void clearAttribute();
 
@@ -136,6 +132,10 @@ Q_OBJECT
   /// \return true if it is succeed
   virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
+  /// Get the shape from the attribute if the attribute contains a shape, e.g. selection attribute
+  /// \return a shape
+  virtual GeomShapePtr getShape() const;
+
   /// Return the attribute values wrapped in a list of viewer presentations
   /// \return a list of viewer presentations, which contains an attribute result and
   /// a shape. If the attribute do not uses the shape, it is empty
index cea864a6af9dcfe1aa1ac198b7ba02b723f7639c..a4dbf44f6f70884839b7e4e019812914989f153b 100644 (file)
 
 #include <XGUI_Workshop.h>
 
+#include <XGUI_ModuleConnector.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_SelectionMgr.h>
+#include <XGUI_Selection.h>
+#include <SelectMgr_IndexedMapOfOwner.hxx>
+#include <StdSelect_BRepOwner.hxx>
+
 PartSet_WidgetShapeSelector::PartSet_WidgetShapeSelector(QWidget* theParent,
                                                          ModuleBase_IWorkshop* theWorkshop,
                                                          const Config_WidgetAPI* theData,
@@ -63,6 +70,67 @@ bool PartSet_WidgetShapeSelector::setObject(ObjectPtr theSelectedObject, GeomSha
   return ModuleBase_WidgetShapeSelector::setObject(aSelectedObject, theShape);
 }
 
+//********************************************************************
+GeomShapePtr PartSet_WidgetShapeSelector::getShape() const
+{
+  // an empty shape by default
+  GeomShapePtr aShape;
+
+  // 1. find an attribute value in attribute reference attribute value
+  DataPtr aData = myFeature->data();
+  AttributePtr aAttr = aData->attribute(attributeID());
+  AttributeRefAttrPtr aRefAttr = 
+    std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+  if (aRefAttr) {
+    if (!aRefAttr->isObject()) {
+      AttributePtr anAttribute = aRefAttr->attr();
+      if (anAttribute.get()) {
+        XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+        XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer();
+
+        // 2. find visualized vertices of the attribute and if the attribute of the vertex is
+        // the same, return it
+        FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(anAttribute->owner());
+        // 2.1 get visualized results of the feature
+        const std::list<ResultPtr>& aResList = anAttributeFeature->results();
+        std::list<ResultPtr>::const_iterator anIt = aResList.begin(), aLast = aResList.end();
+        for (; anIt != aLast; anIt++) {
+          AISObjectPtr aAISObj = aDisplayer->getAISObject(*anIt);
+          if (aAISObj.get() != NULL) {
+            Handle(AIS_InteractiveObject) anAISIO = aAISObj->impl<Handle(AIS_InteractiveObject)>();
+            // 2.2 find selected owners of a visualizedd object
+            SelectMgr_IndexedMapOfOwner aSelectedOwners;  
+            aConnector->workshop()->selector()->selection()->entityOwners(anAISIO, aSelectedOwners);
+            for  (Standard_Integer i = 1, n = aSelectedOwners.Extent(); i <= n; i++) {
+              Handle(SelectMgr_EntityOwner) anOwner = aSelectedOwners(i);
+              if (!anOwner.IsNull()) {
+                Handle(StdSelect_BRepOwner) aBRepOwner = Handle(StdSelect_BRepOwner)::DownCast(anOwner);
+                if (!aBRepOwner.IsNull() && aBRepOwner->HasShape()) {
+                  const TopoDS_Shape& aBRepShape = aBRepOwner->Shape();
+                  if (aBRepShape.ShapeType() == TopAbs_VERTEX) {
+                    // 2.3 if the owner is vertex and an attribute of the vertex is equal to the initial
+                    // attribute, returns the shape
+                    AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(anAttributeFeature,
+                                                                                  aBRepShape, sketch());
+                    if (aPntAttr.get() != NULL && aPntAttr == anAttribute) {
+                      aShape = std::shared_ptr<GeomAPI_Shape>(new GeomAPI_Shape);
+                      aShape->setImpl(new TopoDS_Shape(aBRepShape));
+                      break;
+                    }
+                  }
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+  if (!aShape.get())
+    aShape = ModuleBase_WidgetShapeSelector::getShape();
+  return aShape;
+}
+
 //********************************************************************
 void PartSet_WidgetShapeSelector::restoreAttributeValue(const bool theValid)
 {
index f300db7e8d011fe85db6c010bc98c848f1bdadd3..050b64e271b479860c10a54c7952c24125d1482d 100644 (file)
@@ -49,6 +49,13 @@ protected:
   /// \param theShape a selected shape, which is used in the selection attribute
   virtual bool setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape);
 
+  /// Get the shape from the attribute if the attribute contain a shape
+  /// It processes the ref attr type of attributes. It obtains the referenced attribute,
+  /// results of the attribute feature. And it founds a vertes in the owners of the results
+  /// If the vertex is found, it creates a geom shape on it.
+  /// \return a shape
+  virtual GeomShapePtr getShape() const;
+
   /// Creates a backup of the current values of the attribute
   /// It should be realized in the specific widget because of different
   /// parameters of the current attribute
index 95fa5f06bee10875028b822faaf7c3e3bc11a62b..09a768acf8b9f2b19cc385c1d3bbf96ef8e70cc2 100644 (file)
@@ -27,7 +27,11 @@ void PartSetPlugin_Part::execute()
   if (!aResult) {
     aResult = document()->createPart(data());
     setResult(aResult);
-    aResult->activate();
+    // do not activate part by simple execution if it is not loaded yet: it must be explicitly
+    // activated for this
+    if (!ModelAPI_Session::get()->isLoadByDemand(aResult->data()->name())) {
+      aResult->activate();
+    }
   }
 }
 
index 5254c1ea6d40e10be803a613fa7ae93ba2217c14..83fa8010dd1dce83aedec88d74947ef59887dbd6 100644 (file)
@@ -426,19 +426,16 @@ void XGUI_Displayer::setSelected(const  QList<ModuleBase_ViewerPrs>& theValues,
     aContext->ClearSelected();
     //if (aSelected.size() > 0) {
     foreach (ModuleBase_ViewerPrs aPrs, theValues) {
-    //    if (isValidSelection(aPrs)) {
-    //foreach(ObjectPtr aResult, theResults) {
-      ObjectPtr anObject = aPrs.object();
-      ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
-      if (aResult.get() && isVisible(aResult)) {
-        AISObjectPtr anObj = myResult2AISObjectMap[aResult];
-        Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
-        if (!anAIS.IsNull()) {
-          const TopoDS_Shape& aShape = aPrs.shape();
-          if (!aShape.IsNull()) {
-            aContext->AddOrRemoveSelected(aShape, false);
-          }
-          else {
+      const TopoDS_Shape& aShape = aPrs.shape();
+      if (!aShape.IsNull()) {
+        aContext->AddOrRemoveSelected(aShape, false);
+      } else {
+        ObjectPtr anObject = aPrs.object();
+        ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
+        if (aResult.get() && isVisible(aResult)) {
+          AISObjectPtr anObj = myResult2AISObjectMap[aResult];
+          Handle(AIS_InteractiveObject) anAIS = anObj->impl<Handle(AIS_InteractiveObject)>();
+          if (!anAIS.IsNull()) {
             // The methods are replaced in order to provide multi-selection, e.g. restore selection
             // by activating multi selector widget. It also gives an advantage that the multi
             // selection in OB gives multi-selection in the viewer
@@ -452,7 +449,6 @@ void XGUI_Displayer::setSelected(const  QList<ModuleBase_ViewerPrs>& theValues,
   } else {
     aContext->UnhilightCurrents();
     aContext->ClearCurrents();
-    //foreach(ObjectPtr aResult, theResults) {
     foreach (ModuleBase_ViewerPrs aPrs, theValues) {
       ObjectPtr anObject = aPrs.object();
       ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);