From: nds Date: Thu, 10 Mar 2016 10:53:09 +0000 (+0300) Subject: Issue #1302 Restricting preselection to the first argument only: mirror feature has... X-Git-Tag: V_2.3.0~392 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=864ef42d70739c0b65efd691f0d101b5468eac55;p=modules%2Fshaper.git Issue #1302 Restricting preselection to the first argument only: mirror feature has the greed widget. --- diff --git a/src/Config/Config_Keywords.h b/src/Config/Config_Keywords.h index e26ba0aa4..daacdbf8b 100644 --- a/src/Config/Config_Keywords.h +++ b/src/Config/Config_Keywords.h @@ -71,6 +71,7 @@ const static char* ATTR_INTERNAL = "internal"; const static char* ATTR_OBLIGATORY = "obligatory"; const static char* ATTR_CONCEALMENT = "concealment"; const static char* ATTR_USE_RESET = "use_reset"; +const static char* ATTR_GREED = "greed"; // WDG_INFO properties const static char* INFO_WDG_TEXT = FEATURE_TEXT; diff --git a/src/ModuleBase/ModuleBase_OperationFeature.cpp b/src/ModuleBase/ModuleBase_OperationFeature.cpp index cee58efb0..294d0f037 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.cpp +++ b/src/ModuleBase/ModuleBase_OperationFeature.cpp @@ -15,6 +15,7 @@ #include "ModuleBase_IPropertyPanel.h" #include "ModuleBase_ISelection.h" #include "ModuleBase_IViewer.h" +#include "ModuleBase_Tools.h" #include #include @@ -330,33 +331,55 @@ bool ModuleBase_OperationFeature::commit() return false; } -void ModuleBase_OperationFeature::activateByPreselection() +void ModuleBase_OperationFeature::activateByPreselection(ModuleBase_IWorkshop* theWorkshop) { if (myPreSelection.empty()) return; ModuleBase_ISelection::filterSelectionOnEqualPoints(myPreSelection); - ModuleBase_ModelWidget* aFilledWgt = 0; + std::string aGreedAttributeId = ModuleBase_Tools::findGreedAttribute(theWorkshop, myFeature); + ModuleBase_IPropertyPanel* aPropertyPanel = propertyPanel(); + ModuleBase_ModelWidget* aFilledWgt = 0; if (aPropertyPanel) { const QList& aWidgets = aPropertyPanel->modelWidgets(); + QList::const_iterator aWIt; + ModuleBase_ModelWidget* aWgt = 0; if (!aWidgets.empty()) { - ModuleBase_ModelWidget* aWgt = 0; - QList::const_iterator aWIt; - bool isSet = false; - // 1. apply the selection to controls - for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) { - aWgt = (*aWIt); - if (!aWgt->canSetValue()) - continue; - aPropertyPanel->setPreselectionWidget(aWgt); - if (!aWgt->setSelection(myPreSelection, true)) { - isSet = false; - break; - } else { - isSet = true; - aFilledWgt = aWgt; + if (!aGreedAttributeId.empty()) { + // set preselection to greed widget + for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) { + aWgt = (*aWIt); + if (aWgt->attributeID() == aGreedAttributeId) { + aPropertyPanel->setPreselectionWidget(aWgt); + aWgt->setSelection(myPreSelection, true); + aPropertyPanel->setPreselectionWidget(NULL); + break; + } + } + // activate first not greed widget + std::string aFirstAttributeId = aWidgets.front()->attributeID(); + if (aFirstAttributeId == aGreedAttributeId) // activate next widget after greeded + aFilledWgt = aWidgets.front(); + else + aFilledWgt = NULL; // activate first widget of the panel + } + else { + bool isSet = false; + // 1. apply the selection to controls + for (aWIt = aWidgets.constBegin(); aWIt != aWidgets.constEnd(); ++aWIt) { + aWgt = (*aWIt); + if (!aWgt->canSetValue()) + continue; + aPropertyPanel->setPreselectionWidget(aWgt); + if (!aWgt->setSelection(myPreSelection, true)) { + isSet = false; + break; + } else { + isSet = true; + aFilledWgt = aWgt; + } } } aPropertyPanel->setPreselectionWidget(NULL); @@ -371,9 +394,9 @@ void ModuleBase_OperationFeature::activateByPreselection() if (aFilledWgt) emit activatedByPreselection(); } - // 4. activate the next obligatory widget - aPropertyPanel->activateNextWidget(aFilledWgt); } + // 4. activate the next obligatory widget + aPropertyPanel->activateNextWidget(aFilledWgt); clearPreselection(); } diff --git a/src/ModuleBase/ModuleBase_OperationFeature.h b/src/ModuleBase/ModuleBase_OperationFeature.h index 4f96cd56e..c2411b884 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.h +++ b/src/ModuleBase/ModuleBase_OperationFeature.h @@ -26,6 +26,7 @@ class ModuleBase_ModelWidget; class ModuleBase_ISelection; class ModuleBase_IViewer; +class ModuleBase_IWorkshop; class QKeyEvent; @@ -105,7 +106,7 @@ Q_OBJECT //ModuleBase_IPropertyPanel* propertyPanel() const { return myPropertyPanel; } /// Activates widgets by preselection if it is accepted. Emits signal if the activation is correct - virtual void activateByPreselection(); + virtual void activateByPreselection(ModuleBase_IWorkshop* theWorkshop); /// If the operation works with feature which is sub-feature of another one /// then this variable has to be initialised by parent feature diff --git a/src/ModuleBase/ModuleBase_Tools.cpp b/src/ModuleBase/ModuleBase_Tools.cpp index 5d921bdc8..02e774313 100755 --- a/src/ModuleBase/ModuleBase_Tools.cpp +++ b/src/ModuleBase/ModuleBase_Tools.cpp @@ -8,6 +8,9 @@ #include #include +#include +#include +#include #include #include @@ -407,6 +410,20 @@ void getParameters(QStringList& theParameters) } } +std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop, const FeaturePtr& theFeature) +{ + std::string anAttributeId; + + std::string aXmlCfg, aDescription; + theWorkshop->module()->getXMLRepresentation(theFeature->getKind(), aXmlCfg, aDescription); + + ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop); + std::string anAttributeTitle; + aFactory.getGreedAttribute(anAttributeId); + + return anAttributeId; +} + } // namespace ModuleBase_Tools diff --git a/src/ModuleBase/ModuleBase_Tools.h b/src/ModuleBase/ModuleBase_Tools.h index 9346e28ff..3e8f3b4d7 100755 --- a/src/ModuleBase/ModuleBase_Tools.h +++ b/src/ModuleBase/ModuleBase_Tools.h @@ -26,6 +26,7 @@ class QLayout; class QDoubleSpinBox; class ModuleBase_ParamIntSpinBox; class ModuleBase_ParamSpinBox; +class ModuleBase_IWorkshop; namespace ModuleBase_Tools { @@ -171,6 +172,10 @@ MODULEBASE_EXPORT TopAbs_ShapeEnum getCompoundSubType(const TopoDS_Shape& theSha /// \theParameters a list of parameter names MODULEBASE_EXPORT void getParameters(QStringList& theParameters); +/// Returns list of parameters accessible in the active part and partset +/// \theParameters a list of parameter names +MODULEBASE_EXPORT std::string findGreedAttribute(ModuleBase_IWorkshop* theWorkshop, + const FeaturePtr& theFeature); } #endif diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.cpp b/src/ModuleBase/ModuleBase_WidgetFactory.cpp index 45d6446ca..267ab17b5 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.cpp +++ b/src/ModuleBase/ModuleBase_WidgetFactory.cpp @@ -143,8 +143,7 @@ void ModuleBase_WidgetFactory::createWidget(ModuleBase_PageBase* thePage, thePage->alignToTop(); } -void ModuleBase_WidgetFactory::getAttributeTitle(const std::string& theFeatureKind, - const std::string& theAttributeId, +void ModuleBase_WidgetFactory::getAttributeTitle(const std::string& theAttributeId, std::string& theTitle) { bool aFound = false; @@ -156,6 +155,39 @@ void ModuleBase_WidgetFactory::getAttributeTitle(const std::string& theFeatureKi } } +void ModuleBase_WidgetFactory::getGreedAttribute(std::string& theAttributeId) +{ + if (!theAttributeId.empty()) + return; + + myParentId = myWidgetApi->widgetId(); + if (!myWidgetApi->toChildWidget()) + return; + + do { //Iterate over each node + std::string aWdgType = myWidgetApi->widgetType(); + // Find title under PageGroup + if (myWidgetApi->isGroupBoxWidget() || + ModuleBase_WidgetCreatorFactory::get()->hasPageWidget(aWdgType)) { + getGreedAttribute(theAttributeId); + } + else { + // Find title here + std::string anAttributeId = myWidgetApi->widgetId(); + if (myWidgetApi->getBooleanAttribute(ATTR_GREED, false)) + theAttributeId = anAttributeId; + if (theAttributeId.empty() && myWidgetApi->isPagedWidget()) { + //If current widget is toolbox or switch-casebox then fetch all + //it's pages recursively and setup into the widget. + myWidgetApi->toChildWidget(); + do { + getGreedAttribute(theAttributeId); + } while (theAttributeId.empty() && myWidgetApi->toNextWidget()); + } + } + } while (theAttributeId.empty() && myWidgetApi->toNextWidget()); +} + void ModuleBase_WidgetFactory::moveToWidgetId(const std::string& theWidgetId, bool& theFound) { if (theFound) diff --git a/src/ModuleBase/ModuleBase_WidgetFactory.h b/src/ModuleBase/ModuleBase_WidgetFactory.h index fd416271e..5e14ad4af 100644 --- a/src/ModuleBase/ModuleBase_WidgetFactory.h +++ b/src/ModuleBase/ModuleBase_WidgetFactory.h @@ -54,13 +54,15 @@ class MODULEBASE_EXPORT ModuleBase_WidgetFactory } /// Returns the value of the title key from XML definition of the attribute in the feature - /// \param theFeatureKind a value of a kind of a feature /// \param theAttributeId a value of a kind of the attribute under the feature /// \param theTitle the result title - void getAttributeTitle(const std::string& theFeatureKind, - const std::string& theAttributeId, + void getAttributeTitle(const std::string& theAttributeId, std::string& theTitle); + /// Returns the identifier of the first found attribute where greed field value is set and true + /// \param theAttributeId an outpup parameter with attribute + void getGreedAttribute(std::string& theAttributeId); + protected: /// check if ModuleBase_Widget has expandable widgets in getControls bool hasExpandingControls(QWidget* theParent); diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index e8c609343..9471f0b8d 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -190,7 +190,7 @@ std::string ModuleBase_WidgetSelector::generateName(const AttributePtr& theAttri ModuleBase_WidgetFactory aFactory(aXmlCfg, theWorkshop); std::string anAttributeTitle; - aFactory.getAttributeTitle(aFeature->getKind(), theAttribute->id(), anAttributeTitle); + aFactory.getAttributeTitle(theAttribute->id(), anAttributeTitle); std::stringstream aStreamName; aStreamName << theAttribute->owner()->data()->name() << "/"<< anAttributeTitle.c_str(); diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 323067442..2eb9cffe1 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -374,7 +374,8 @@ label="Segments:" tooltip="Select list of mirroring objects" type_choice="Edges" - use_external="true"> + use_external="true" + greed ="true"> diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index cb56c3879..e04181c6c 100755 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -451,7 +451,7 @@ void XGUI_Workshop::onOperationStarted(ModuleBase_Operation* theOperation) // if the operation can be committed after the controls filling, the method perform should // be stopped. Otherwise unnecessary presentations can be shown(e.g. operation prs in sketch) if (!aFOperation->isEditOperation()) { - aFOperation->activateByPreselection(); + aFOperation->activateByPreselection(moduleConnector()); if (operationMgr()->currentOperation() != aFOperation) return; }