]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Use AttributeSelection for Extrusion operation
authorvsv <vitaly.smetannikov@opencascade.com>
Thu, 9 Oct 2014 12:59:02 +0000 (16:59 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Thu, 9 Oct 2014 12:59:02 +0000 (16:59 +0400)
src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp
src/FeaturesPlugin/extrusion_widget.xml
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/ModelAPI_Data.h
src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp
src/ModuleBase/ModuleBase_WidgetShapeSelector.h
src/XGUI/XGUI_ModuleConnector.cpp

index 295fb1c9de489e55cd14f0df7190b7c341e05625..60ee2b6898bd0f8d6b5e89f9beb9f7de43b227d3 100644 (file)
@@ -9,7 +9,7 @@
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_AttributeDouble.h>
-#include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
 #include <ModelAPI_AttributeBoolean.h>
 
 #include <GeomAlgoAPI_Extrusion.h>
@@ -22,36 +22,24 @@ FeaturesPlugin_Extrusion::FeaturesPlugin_Extrusion()
 
 void FeaturesPlugin_Extrusion::initAttributes()
 {
-  data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeReference::type());
+  data()->addAttribute(FeaturesPlugin_Extrusion::FACE_ID(), ModelAPI_AttributeSelection::type());
   data()->addAttribute(FeaturesPlugin_Extrusion::SIZE_ID(), ModelAPI_AttributeDouble::type());
   data()->addAttribute(FeaturesPlugin_Extrusion::REVERSE_ID(), ModelAPI_AttributeBoolean::type());
 }
 
 void FeaturesPlugin_Extrusion::execute()
 {
-  boost::shared_ptr<ModelAPI_AttributeReference> aFaceRef = boost::dynamic_pointer_cast<
-      ModelAPI_AttributeReference>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
+  boost::shared_ptr<ModelAPI_AttributeSelection> aFaceRef = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID()));
   if (!aFaceRef)
     return;
-  boost::shared_ptr<GeomAPI_Shape> aFace;
-  boost::shared_ptr<ModelAPI_ResultConstruction> aConstr = boost::dynamic_pointer_cast<
-      ModelAPI_ResultConstruction>(aFaceRef->value());
-  if (aConstr) {
-    aFace = aConstr->shape();
-  }
-  if (!aFace) {
-    // Check for body
-    boost::shared_ptr<ModelAPI_ResultBody> aBody = boost::dynamic_pointer_cast<
-        ModelAPI_ResultBody>(aFaceRef->value());
-    if (aBody) 
-      aFace = aBody->shape();
-  }
-  if (!aFace) 
-    return;
+  boost::shared_ptr<GeomAPI_Shape> aFace = 
+    boost::dynamic_pointer_cast<GeomAPI_Shape>(aFaceRef->value());
 
   double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value();
   if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value())
     aSize = -aSize;
+
   boost::shared_ptr<ModelAPI_ResultBody> aResult = document()->createBody(data());
   aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize));
   setResult(aResult);
index 426bb3fd592e17d2af551090f2da9f80a9f7655e..fee9e00dfb54a701d10cba2ef05713e189c03842 100644 (file)
@@ -4,7 +4,7 @@
     icon=":icons/sketch.png" 
     tooltip="Select a face for extrusion"
     activate="true"
-    shape_types="face wire"
+    shape_types="face wire edge"
     use_subshapes="true"
   />
   <doublevalue id="extrusion_size" label="Size" min="0" step="1.0" default="0" icon=":icons/dimension_v.png" tooltip="Set size of extrusion">
index 495bd04bc539c6ffdf1102dc2449e3e5102d1017..b9bb03a3117b05e16a633f530df938c84c2919a3 100644 (file)
@@ -11,6 +11,7 @@
 #include <Model_AttributeRefList.h>
 #include <Model_AttributeBoolean.h>
 #include <Model_AttributeString.h>
+#include <ModelAPI_AttributeSelection.h>
 #include <Model_Events.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_Result.h>
@@ -183,6 +184,21 @@ boost::shared_ptr<ModelAPI_AttributeReference> Model_Data::reference(const std::
   return aRes;
 }
 
+boost::shared_ptr<ModelAPI_AttributeSelection> Model_Data::selection(const std::string& theID)
+{
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  if (aFound == myAttrs.end()) {
+    // TODO: generate error on unknown attribute request and/or add mechanism for customization
+    return boost::shared_ptr<ModelAPI_AttributeSelection>();
+  }
+  boost::shared_ptr<ModelAPI_AttributeSelection> aRes = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aFound->second);
+  if (!aRes) {
+    // TODO: generate error on invalid attribute type request
+  }
+  return aRes;
+}
+
 boost::shared_ptr<ModelAPI_AttributeRefAttr> Model_Data::refattr(const std::string& theID)
 {
   std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
index 559fc12adb3444e4a31cc8e30fca673dd00db810..45360d1a8e23b5253b3f2bee56f56e9a183575a0 100644 (file)
@@ -72,6 +72,9 @@ class Model_Data : public ModelAPI_Data
   /// Returns the attribute that contains reference to a feature
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeReference>
     reference(const std::string& theID);
+  /// Returns the attribute that contains selection to a shape
+  MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeSelection>
+    selection(const std::string& theID);
   /// Returns the attribute that contains reference to an attribute of a feature
   MODEL_EXPORT virtual boost::shared_ptr<ModelAPI_AttributeRefAttr>
     refattr(const std::string& theID);
index 1265a51bd2a08738bfa1c14a1559d9d18c585873..1bd01c5b3692d1ab9fa97bcbe0edc21c0277b9c7 100644 (file)
@@ -21,6 +21,7 @@ class ModelAPI_AttributeString;
 class ModelAPI_Document;
 class ModelAPI_Attribute;
 class ModelAPI_Feature;
+class ModelAPI_AttributeSelection;
 class GeomAPI_Shape;
 
 /**\class ModelAPI_Data
@@ -47,6 +48,8 @@ class MODELAPI_EXPORT ModelAPI_Data
   virtual boost::shared_ptr<ModelAPI_AttributeInteger> integer(const std::string& theID) = 0;
   /// Returns the attribute that contains reference to a feature
   virtual boost::shared_ptr<ModelAPI_AttributeReference> reference(const std::string& theID) = 0;
+  /// Returns the attribute that contains selection to a shape
+  virtual boost::shared_ptr<ModelAPI_AttributeSelection> selection(const std::string& theID) = 0;
   /// Returns the attribute that contains reference to an attribute of a feature
   virtual boost::shared_ptr<ModelAPI_AttributeRefAttr> refattr(const std::string& theID) = 0;
   /// Returns the attribute that contains list of references to features
index 29443bf5d3f12fd85cad14cab528e58a1f082cb8..e70e5dc08b011513a8ce6d8b549ea9cce6909de7 100644 (file)
@@ -18,6 +18,7 @@
 #include <ModelAPI_Object.h>
 #include <ModelAPI_Result.h>
 #include <ModelAPI_AttributeReference.h>
+#include <ModelAPI_AttributeSelection.h>
 #include <Config_WidgetAPI.h>
 
 #include <GeomAPI_Shape.h>
@@ -99,6 +100,7 @@ ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParen
 //********************************************************************
 ModuleBase_WidgetShapeSelector::~ModuleBase_WidgetShapeSelector()
 {
+  activateSelection(false);
 }
 
 //********************************************************************
@@ -109,13 +111,22 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const
     return false;
 
   DataPtr aData = myFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeReference> aRef = boost::dynamic_pointer_cast<
-      ModelAPI_AttributeReference>(aData->attribute(attributeID()));
+  if (myUseSubShapes) {
+    boost::shared_ptr<ModelAPI_AttributeSelection> aSelect = 
+      boost::dynamic_pointer_cast<ModelAPI_AttributeSelection>(aData->attribute(attributeID()));
+
+    ResultBodyPtr aBody = boost::dynamic_pointer_cast<ModelAPI_ResultBody>(mySelectedObject);
+    if (aBody)
+      aSelect->setValue(aBody, myShape);
+  } else {
+    boost::shared_ptr<ModelAPI_AttributeReference> aRef = 
+      boost::dynamic_pointer_cast<ModelAPI_AttributeReference>(aData->attribute(attributeID()));
 
-  ObjectPtr aObject = aRef->value();
-  if (!(aObject && aObject->isSame(mySelectedObject))) {
-    aRef->setValue(mySelectedObject);
-    updateObject(myFeature);
+    ObjectPtr aObject = aRef->value();
+    if (!(aObject && aObject->isSame(mySelectedObject))) {
+      aRef->setValue(mySelectedObject);
+      updateObject(myFeature);
+    }
   }
   return true;
 }
@@ -124,10 +135,17 @@ bool ModuleBase_WidgetShapeSelector::storeValue() const
 bool ModuleBase_WidgetShapeSelector::restoreValue()
 {
   DataPtr aData = myFeature->data();
-  boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
-
   bool isBlocked = this->blockSignals(true);
-  mySelectedObject = aRef->value();
+  if (myUseSubShapes) {
+    boost::shared_ptr<ModelAPI_AttributeSelection> aSelect = aData->selection(attributeID());
+    if (aSelect) {
+      mySelectedObject = aSelect->context();
+      myShape = aSelect->value();
+    }
+  } else {
+    boost::shared_ptr<ModelAPI_AttributeReference> aRef = aData->reference(attributeID());
+    mySelectedObject = aRef->value();
+  }
   updateSelectionName();
 
   this->blockSignals(isBlocked);
index 75863884304d906e8bcb6174f875575ef005bac0..760e371a82ce489cccab6889e26694252e5f87c7 100644 (file)
@@ -9,6 +9,7 @@
 #include "ModuleBase_ModelWidget.h"
 
 #include <ModelAPI_Object.h>
+#include <GeomAPI_Shape.h>
 
 #include <TopAbs_ShapeEnum.hxx>
 
@@ -89,6 +90,8 @@ private:
   ModuleBase_IWorkshop* myWorkshop;
 
   ObjectPtr mySelectedObject;
+  boost::shared_ptr<GeomAPI_Shape> myShape;
+
   QStringList myShapeTypes;
 
   /// If true then local selector has to be activated in context
index aecada78b636372148cee115f97b7caae6ce0f53..8ebed4c15f5b33b88fb2da4a3bb2131e481a3915 100644 (file)
@@ -54,8 +54,9 @@ void XGUI_ModuleConnector::activateSubShapesSelection(const QIntList& theTypes)
   Handle(AIS_InteractiveContext) aAIS = myWorkshop->viewer()->AISContext();
   if (!aAIS->HasOpenedContext())
     aAIS->OpenLocalContext();
-  foreach(int aType, theTypes)
+  foreach(int aType, theTypes) {
     aAIS->ActivateStandardMode((TopAbs_ShapeEnum)aType);
+  }
 }
 
 void XGUI_ModuleConnector::deactivateSubShapesSelection()