From: vsv Date: Thu, 9 Oct 2014 12:59:02 +0000 (+0400) Subject: Use AttributeSelection for Extrusion operation X-Git-Tag: V_0.5~106^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=9ebd551ac78366b4a21e97e4d6a3b911f717ff9a;p=modules%2Fshaper.git Use AttributeSelection for Extrusion operation --- diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 295fb1c9d..60ee2b689 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include #include #include @@ -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 aFaceRef = boost::dynamic_pointer_cast< - ModelAPI_AttributeReference>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID())); + boost::shared_ptr aFaceRef = boost::dynamic_pointer_cast< + ModelAPI_AttributeSelection>(data()->attribute(FeaturesPlugin_Extrusion::FACE_ID())); if (!aFaceRef) return; - boost::shared_ptr aFace; - boost::shared_ptr aConstr = boost::dynamic_pointer_cast< - ModelAPI_ResultConstruction>(aFaceRef->value()); - if (aConstr) { - aFace = aConstr->shape(); - } - if (!aFace) { - // Check for body - boost::shared_ptr aBody = boost::dynamic_pointer_cast< - ModelAPI_ResultBody>(aFaceRef->value()); - if (aBody) - aFace = aBody->shape(); - } - if (!aFace) - return; + boost::shared_ptr aFace = + boost::dynamic_pointer_cast(aFaceRef->value()); double aSize = data()->real(FeaturesPlugin_Extrusion::SIZE_ID())->value(); if (data()->boolean(FeaturesPlugin_Extrusion::REVERSE_ID())->value()) aSize = -aSize; + boost::shared_ptr aResult = document()->createBody(data()); aResult->store(GeomAlgoAPI_Extrusion::makeExtrusion(aFace, aSize)); setResult(aResult); diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 426bb3fd5..fee9e00df 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -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" /> diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 495bd04bc..b9bb03a31 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -183,6 +184,21 @@ boost::shared_ptr Model_Data::reference(const std:: return aRes; } +boost::shared_ptr Model_Data::selection(const std::string& theID) +{ + std::map >::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(); + } + boost::shared_ptr aRes = + boost::dynamic_pointer_cast(aFound->second); + if (!aRes) { + // TODO: generate error on invalid attribute type request + } + return aRes; +} + boost::shared_ptr Model_Data::refattr(const std::string& theID) { std::map >::iterator aFound = myAttrs.find(theID); diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 559fc12ad..45360d1a8 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -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 reference(const std::string& theID); + /// Returns the attribute that contains selection to a shape + MODEL_EXPORT virtual boost::shared_ptr + selection(const std::string& theID); /// Returns the attribute that contains reference to an attribute of a feature MODEL_EXPORT virtual boost::shared_ptr refattr(const std::string& theID); diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index 1265a51bd..1bd01c5b3 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -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 integer(const std::string& theID) = 0; /// Returns the attribute that contains reference to a feature virtual boost::shared_ptr reference(const std::string& theID) = 0; + /// Returns the attribute that contains selection to a shape + virtual boost::shared_ptr selection(const std::string& theID) = 0; /// Returns the attribute that contains reference to an attribute of a feature virtual boost::shared_ptr refattr(const std::string& theID) = 0; /// Returns the attribute that contains list of references to features diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index 29443bf5d..e70e5dc08 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -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 aRef = boost::dynamic_pointer_cast< - ModelAPI_AttributeReference>(aData->attribute(attributeID())); + if (myUseSubShapes) { + boost::shared_ptr aSelect = + boost::dynamic_pointer_cast(aData->attribute(attributeID())); + + ResultBodyPtr aBody = boost::dynamic_pointer_cast(mySelectedObject); + if (aBody) + aSelect->setValue(aBody, myShape); + } else { + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(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 aRef = aData->reference(attributeID()); - bool isBlocked = this->blockSignals(true); - mySelectedObject = aRef->value(); + if (myUseSubShapes) { + boost::shared_ptr aSelect = aData->selection(attributeID()); + if (aSelect) { + mySelectedObject = aSelect->context(); + myShape = aSelect->value(); + } + } else { + boost::shared_ptr aRef = aData->reference(attributeID()); + mySelectedObject = aRef->value(); + } updateSelectionName(); this->blockSignals(isBlocked); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 758638843..760e371a8 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -9,6 +9,7 @@ #include "ModuleBase_ModelWidget.h" #include +#include #include @@ -89,6 +90,8 @@ private: ModuleBase_IWorkshop* myWorkshop; ObjectPtr mySelectedObject; + boost::shared_ptr myShape; + QStringList myShapeTypes; /// If true then local selector has to be activated in context diff --git a/src/XGUI/XGUI_ModuleConnector.cpp b/src/XGUI/XGUI_ModuleConnector.cpp index aecada78b..8ebed4c15 100644 --- a/src/XGUI/XGUI_ModuleConnector.cpp +++ b/src/XGUI/XGUI_ModuleConnector.cpp @@ -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()