From: vsv Date: Thu, 16 Apr 2015 14:45:28 +0000 (+0300) Subject: Issue #459: Check pre-selection for group operation X-Git-Tag: V_1.1.0~21^2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6a7e53a3d3b52f1f798b7e3aa3c48de9c870d92b;p=modules%2Fshaper.git Issue #459: Check pre-selection for group operation --- diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index fb7c6925d..3b82ea108 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -402,28 +402,29 @@ void Model_AttributeSelection::selectBody( { // perform the selection TNaming_Selector aSel(selectionLabel()); - TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl() : TopoDS_Shape(); TopoDS_Shape aContext; ResultBodyPtr aBody = std::dynamic_pointer_cast(myRef.value()); if (aBody) { aContext = aBody->shape()->impl(); } else { - ResultConstructionPtr aConstr = - std::dynamic_pointer_cast(myRef.value()); - if (aConstr) { - aContext = aConstr->shape()->impl(); + ResultPtr aResult = + std::dynamic_pointer_cast(myRef.value()); + if (aResult) { + aContext = aResult->shape()->impl(); } else { Events_Error::send("A result with shape is expected"); return; } } + TopoDS_Shape aNewShape = theSubShape ? theSubShape->impl() : aContext; /// fix for issue 411: result modified shapes must not participate in this selection mechanism FeaturePtr aFeatureOwner = std::dynamic_pointer_cast(owner()); if (aFeatureOwner.get()) aFeatureOwner->eraseResults(); - - aSel.Select(aNewShape, aContext); + if (!aContext.IsNull()) { + aSel.Select(aNewShape, aContext); + } } /// registers the name of the shape in the label (theID == 0) of sub label (theID is a tag) diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 03569839c..1d87b4ae2 100644 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -154,6 +155,31 @@ QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo) return aFeatureStr; } +typedef QMap ShapeTypes; +static ShapeTypes MyShapeTypes; + +TopAbs_ShapeEnum shapeType(const QString& theType) +{ + if (MyShapeTypes.count() == 0) { + MyShapeTypes["face"] = TopAbs_FACE; + MyShapeTypes["faces"] = TopAbs_FACE; + MyShapeTypes["vertex"] = TopAbs_VERTEX; + MyShapeTypes["vertices"] = TopAbs_VERTEX; + MyShapeTypes["wire"] = TopAbs_WIRE; + MyShapeTypes["edge"] = TopAbs_EDGE; + MyShapeTypes["edges"] = TopAbs_EDGE; + MyShapeTypes["shell"] = TopAbs_SHELL; + MyShapeTypes["solid"] = TopAbs_SOLID; + MyShapeTypes["solids"] = TopAbs_SOLID; + } + QString aType = theType.toLower(); + if (MyShapeTypes.contains(aType)) + return MyShapeTypes[aType]; + Events_Error::send("Shape type defined in XML is not implemented!"); + return TopAbs_SHAPE; +} + + } diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 3c9006d9a..75c6b95fe 100644 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -10,6 +10,7 @@ #include "ModuleBase.h" #include +#include #include @@ -65,6 +66,11 @@ MODULEBASE_EXPORT void setSpinValue(QDoubleSpinBox* theSpin, double theValue); /// \return a string MODULEBASE_EXPORT QString objectInfo(const ObjectPtr& theObj, const bool isUseAttributesInfo = false); +/// Converts string value (name of shape type) to shape enum value +/// \param theType - string with shape type name +/// \return TopAbs_ShapeEnum value +MODULEBASE_EXPORT TopAbs_ShapeEnum shapeType(const QString& theType); + } #endif diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index c74b323b8..57e2ce949 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -131,7 +131,7 @@ bool ModuleBase_WidgetMultiSelector::storeValueCustom() const if (aSelectionListAttr) { // Store shapes type TopAbs_ShapeEnum aCurrentType = - ModuleBase_WidgetShapeSelector::shapeType(myTypeCombo->currentText()); + ModuleBase_Tools::shapeType(myTypeCombo->currentText()); aSelectionListAttr->setSelectionType(myTypeCombo->currentText().toStdString()); } return true; @@ -149,8 +149,7 @@ bool ModuleBase_WidgetMultiSelector::restoreValue() if (aSelectionListAttr) { // Restore shape type - setCurrentShapeType( - ModuleBase_WidgetShapeSelector::shapeType(aSelectionListAttr->selectionType().c_str())); + setCurrentShapeType(ModuleBase_Tools::shapeType(aSelectionListAttr->selectionType().c_str())); updateSelectionList(aSelectionListAttr); return true; } @@ -198,6 +197,12 @@ void ModuleBase_WidgetMultiSelector::restoreAttributeValue(bool/* theValid*/) //******************************************************************** bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerPrs& thePrs) { + TopoDS_Shape aShape = thePrs.shape(); + if ((myTypeCombo->count() > 1) && (!aShape.IsNull())) { + TopAbs_ShapeEnum aType = ModuleBase_Tools::shapeType(myTypeCombo->currentText()); + if (aShape.ShapeType() != aType) + return false; + } ResultPtr aResult; if (!thePrs.owner().IsNull()) { ObjectPtr anObject = myWorkshop->selection()->getSelectableObject(thePrs.owner()); @@ -235,7 +240,7 @@ bool ModuleBase_WidgetMultiSelector::setSelectionCustom(const ModuleBase_ViewerP aSelectionListAttr->append(aResult, GeomShapePtr()); } else { - GeomShapePtr aShape = std::shared_ptr(new GeomAPI_Shape()); + GeomShapePtr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aTDSShape)); // We can not select a result of our feature if (aShape->isEqual(aResult->shape())) @@ -303,7 +308,7 @@ void ModuleBase_WidgetMultiSelector::setCurrentShapeType(const TopAbs_ShapeEnum for (int idx = 0; idx < myTypeCombo->count(); ++idx) { aShapeTypeName = myTypeCombo->itemText(idx); - TopAbs_ShapeEnum aRefType = ModuleBase_WidgetShapeSelector::shapeType(aShapeTypeName); + TopAbs_ShapeEnum aRefType = ModuleBase_Tools::shapeType(aShapeTypeName); if(aRefType == theShapeType && idx != myTypeCombo->currentIndex()) { myIsActive = false; activateShapeSelection(); @@ -324,7 +329,7 @@ void ModuleBase_WidgetMultiSelector::activateShapeSelection() if (myIsActive) { QString aNewType = myTypeCombo->currentText(); QIntList aList; - aList.append(ModuleBase_WidgetShapeSelector::shapeType(aNewType)); + aList.append(ModuleBase_Tools::shapeType(aNewType)); myWorkshop->activateSubShapesSelection(aList); } else { myWorkshop->deactivateSubShapesSelection(); diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp index a88479bc5..1f5d011ea 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.cpp @@ -65,29 +65,6 @@ #include #include -typedef QMap ShapeTypes; -static ShapeTypes MyShapeTypes; - -TopAbs_ShapeEnum ModuleBase_WidgetShapeSelector::shapeType(const QString& theType) -{ - if (MyShapeTypes.count() == 0) { - MyShapeTypes["face"] = TopAbs_FACE; - MyShapeTypes["faces"] = TopAbs_FACE; - MyShapeTypes["vertex"] = TopAbs_VERTEX; - MyShapeTypes["vertices"] = TopAbs_VERTEX; - MyShapeTypes["wire"] = TopAbs_WIRE; - MyShapeTypes["edge"] = TopAbs_EDGE; - MyShapeTypes["edges"] = TopAbs_EDGE; - MyShapeTypes["shell"] = TopAbs_SHELL; - MyShapeTypes["solid"] = TopAbs_SOLID; - MyShapeTypes["solids"] = TopAbs_SOLID; - } - QString aType = theType.toLower(); - if (MyShapeTypes.contains(aType)) - return MyShapeTypes[aType]; - Events_Error::send("Shape type defined in XML is not implemented!"); - return TopAbs_SHAPE; -} ModuleBase_WidgetShapeSelector::ModuleBase_WidgetShapeSelector(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, @@ -269,7 +246,7 @@ bool ModuleBase_WidgetShapeSelector::acceptSubShape(std::shared_ptrimpl(); foreach (QString aType, myShapeTypes) { - if (aShape.ShapeType() == shapeType(aType)) + if (aShape.ShapeType() == ModuleBase_Tools::shapeType(aType)) return true; } return false; @@ -338,7 +315,7 @@ void ModuleBase_WidgetShapeSelector::activateSelection(bool toActivate) if (myIsActive) { QIntList aList; foreach (QString aType, myShapeTypes) { - aList.append(shapeType(aType)); + aList.append(ModuleBase_Tools::shapeType(aType)); } myWorkshop->activateSubShapesSelection(aList); } else { diff --git a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h index 8890912da..bf0fb6800 100644 --- a/src/ModuleBase/ModuleBase_WidgetShapeSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetShapeSelector.h @@ -58,11 +58,6 @@ class MODULEBASE_EXPORT ModuleBase_WidgetShapeSelector : public ModuleBase_Widge Q_OBJECT public: - /// Converts string value (name of shape type) to shape enum value - /// \param theType - string with shape type name - /// \return TopAbs_ShapeEnum value - static TopAbs_ShapeEnum shapeType(const QString& theType); - /// Constructor /// \param theParent the parent object /// \param theWorkshop instance of workshop interface