From aff96290a7d04d8756fce5fac13602018872a0b8 Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 25 Jun 2020 16:36:28 +0300 Subject: [PATCH] Issue #3236: Add buttons for shape type choice to Extrusion/Revolution objects --- .../FeaturesPlugin_Extrusion.cpp | 3 - src/FeaturesPlugin/FeaturesPlugin_Extrusion.h | 7 -- src/FeaturesPlugin/extrusion_widget.xml | 19 ++-- src/FeaturesPlugin/extrusionfuse_widget.xml | 8 +- src/FeaturesPlugin/revolution_widget.xml | 8 +- src/FeaturesPlugin/revolutionfuse_widget.xml | 8 +- .../ModuleBase_WidgetMultiSelector.cpp | 22 ++++- src/PartSet/PartSet_WidgetSketchCreator.cpp | 97 +++++++++++++++++-- src/PartSet/PartSet_WidgetSketchCreator.h | 10 ++ 9 files changed, 144 insertions(+), 38 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 6ae36c31a..57b1ba874 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -58,8 +57,6 @@ void FeaturesPlugin_Extrusion::initAttributes() data()->addAttribute(DIRECTION_OBJECT_ID(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(USE_SHAPES_ID(), ModelAPI_AttributeInteger::typeId()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), TO_OBJECT_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), FROM_OBJECT_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), DIRECTION_OBJECT_ID()); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h index 91a30f16d..1f657b30a 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.h @@ -123,13 +123,6 @@ public: return MY_FROM_OFFSET_ID; } - /// Attribute name of using shape types. - inline static const std::string& USE_SHAPES_ID() - { - static const std::string MY_USE_SHAPEST_ID("use_sapes"); - return MY_USE_SHAPEST_ID; - } - /// \return the kind of a feature. FEATURESPLUGIN_EXPORT virtual const std::string& getKind() { diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 7d833c095..138b4dca3 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -5,24 +5,19 @@ 1. Planar face of non-sketch object or a plane. Sketch creation will be started.<br /> 2. An existing sketch face or contour. Extrusion will be filled by it.<br /> 3. An existing result shape of kind: wires/edge/vertices. Extrusion will be filled by it." - shape_types="vertices edges wires faces shells solids compsolids compounds"> + shape_types="Vertices Edges Faces" + default_type = "2" + use_choice="true"> - - - + + shape_types="Vertices Edges Faces" + default_type = "2" + use_choice="true"> diff --git a/src/FeaturesPlugin/revolution_widget.xml b/src/FeaturesPlugin/revolution_widget.xml index f69065d75..d8ec39801 100644 --- a/src/FeaturesPlugin/revolution_widget.xml +++ b/src/FeaturesPlugin/revolution_widget.xml @@ -5,13 +5,17 @@ 1. Planar face of non-sketch object or a plane. Sketch creation will be started.<br /> 2. An existing sketch face or contour. Extrusion will be filled by it.<br /> 3. An existing result shape of kind: wires/edge/vertices. Extrusion will be filled by it." - shape_types="vertices edges wires faces shells compounds"> + shape_types="Vertices Edges Faces" + default_type = "2" + use_choice="true"> diff --git a/src/FeaturesPlugin/revolutionfuse_widget.xml b/src/FeaturesPlugin/revolutionfuse_widget.xml index 4f571406e..bcde5490f 100644 --- a/src/FeaturesPlugin/revolutionfuse_widget.xml +++ b/src/FeaturesPlugin/revolutionfuse_widget.xml @@ -6,14 +6,18 @@ 1. Planar face of non-sketch object or a plane. Sketch creation will be started.<br /> 2. An existing sketch face or contour. Extrusion will be filled by it.<br /> 3. An existing result shape of kind: wires/edge/vertices. Extrusion will be filled by it." - shape_types="vertices edges wires faces shells compounds"> + shape_types="Vertices Edges Faces" + default_type = "2" + use_choice="true"> diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index bab6ca002..9c4f6f9ef 100644 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -132,8 +132,19 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList); myTypeCtrl->setLabel(tr("Type")); if (!myShapeTypes.empty()) { - myTypeCtrl->setValue(0); - myDefMode = myShapeTypes.first().toStdString(); + std::string aDefType = theData->getProperty("default_type"); + if (aDefType.size() > 0) { + bool aOk = false; + int aId = QString(aDefType.c_str()).toInt(&aOk); + if (aOk) { + myTypeCtrl->setValue(aId); + myDefMode = myShapeTypes.at(aId).toStdString(); + } + } + if (myDefMode.size() == 0) { + myTypeCtrl->setValue(0); + myDefMode = myShapeTypes.first().toStdString(); + } } myMainLayout->addWidget(myTypeCtrl); @@ -570,6 +581,8 @@ bool ModuleBase_WidgetMultiSelector::processDelete() QList ModuleBase_WidgetMultiSelector::getControls() const { QList result; + if (myTypeCtrl->isVisible()) + result << myTypeCtrl; result << myListView->getControl(); return result; } @@ -618,8 +631,9 @@ void ModuleBase_WidgetMultiSelector::onSelectionTypeChanged() restoreValue(); myWorkshop->setSelected(getAttributeSelection()); // may be the feature's result is not displayed, but attributes should be - myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments, - true); /// hope that something is redisplayed by object updated + // hope that something is redisplayed by object updated + myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments, false); + myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeResults, true); // clear history should follow after set selected to do not increase history by setSelected clearSelectedHistory(); diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 9d6d90cf2..49d94f227 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -53,6 +53,9 @@ #include #include #include +#include +#include +#include #include @@ -68,6 +71,25 @@ #define DEBUG_UNDO_INVALID_SKETCH + + +QStringList getIconsList(const QStringList& theNames) +{ + QStringList aIcons; + foreach(QString aName, theNames) { + QString aUName = aName.toUpper(); + if ((aUName == "VERTICES") || (aUName == "VERTEX")) + aIcons << ":pictures/vertex32.png"; + else if ((aUName == "EDGES") || (aUName == "EDGE")) + aIcons << ":pictures/edge32.png"; + else if ((aUName == "FACES") || (aUName == "FACE")) + aIcons << ":pictures/face32.png"; + } + return aIcons; +} + + + PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule, const Config_WidgetAPI* theData) @@ -102,11 +124,37 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, aLayout->addWidget(mySizeOfViewWidget); aLayout->addWidget(myLabel); - aLayout->addStretch(1); std::string aTypes = theData->getProperty("shape_types"); myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts); + myIsUseChoice = theData->getBooleanAttribute("use_choice", false); + QStringList aIconsList = getIconsList(myShapeTypes); + myTypeCtrl = new ModuleBase_ChoiceCtrl(this, myShapeTypes, aIconsList); + myTypeCtrl->setLabel(tr("Type")); + if (!myShapeTypes.empty()) { + std::string aDefType = theData->getProperty("default_type"); + if (aDefType.size() > 0) { + bool aOk = false; + int aId = QString(aDefType.c_str()).toInt(&aOk); + if (aOk) { + myTypeCtrl->setValue(aId); + myDefMode = myShapeTypes.at(aId).toStdString(); + } + } + if (myDefMode.size() == 0) { + myTypeCtrl->setValue(0); + myDefMode = myShapeTypes.first().toStdString(); + } + } + aLayout->addWidget(myTypeCtrl); + // There is no sense to parameterize list of types while we can not parameterize selection mode + // if the xml definition contains one type, the controls to select a type should not be shown + if (myShapeTypes.size() <= 1 || !myIsUseChoice) { + myTypeCtrl->setVisible(false); + } + connect(myTypeCtrl, SIGNAL(valueChanged(int)), this, SLOT(onSelectionTypeChanged())); + aLayout->addStretch(1); myPreviewPlanes = new PartSet_PreviewPlanes(); } @@ -212,9 +260,6 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel(); const QList& aWidgets = aPanel->modelWidgets(); foreach(ModuleBase_ModelWidget* aWidget, aWidgets) { - QString aType(aWidget->metaObject()->className()); - if (aType == "ModuleBase_WidgetChoice") - continue; if (theSelectionControl) { // hide other controls if (aWidget != this) aWidget->setVisible(false); @@ -253,8 +298,13 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec QIntList PartSet_WidgetSketchCreator::shapeTypes() const { QIntList aShapeTypes; - foreach(QString aType, myShapeTypes) { - aShapeTypes.append(ModuleBase_Tools::shapeType(aType)); + if (myShapeTypes.length() > 1 && myIsUseChoice) { + aShapeTypes.append(ModuleBase_Tools::shapeType(myTypeCtrl->textValue())); + } + else { + foreach(QString aType, myShapeTypes) { + aShapeTypes.append(ModuleBase_Tools::shapeType(aType)); + } } return aShapeTypes; } @@ -592,3 +642,38 @@ void PartSet_WidgetSketchCreator::setEnabledModelWidget(ModuleBase_ModelWidget* eachControl->setEnabled(theEnabled); } } + +void PartSet_WidgetSketchCreator::onSelectionTypeChanged() +{ + // Clear current selection in order to avoid updating of object browser with obsolete indexes + // which can appear because of results deletetion after changing a type of selection + QString aSelectionType = myTypeCtrl->textValue(); + QList aEmptyList; + myWorkshop->setSelected(aEmptyList); + + updateSelectionModesAndFilters(true); + myWorkshop->selectionActivate()->updateSelectionModes(); + + if (!myFeature) + return; + + if (aSelectionType != "Faces") { + setVisibleSelectionControl(false); + myWorkshop->propertyPanel()->activateNextWidget(); + } + + /// store the selected type + AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID); + anAttrList->setSelectionType(aSelectionType.toStdString()); + anAttrList->clear(); + + // update object is necessary to flush update signal. It leads to objects references map update + // and the operation presentation will not contain deleted items visualized as parameters of + // the feature. + updateObject(myFeature); + myWorkshop->propertyPanel()->activeWidget()->restoreValue(); + myWorkshop->setSelected(getAttributeSelection()); + // may be the feature's result is not displayed, but attributes should be + // hope that something is redisplayed by object updated + myWorkshop->module()->customizeFeature(myFeature, ModuleBase_IModule::CustomizeArguments, true); +} \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index 0e32b0285..dd8bfa23a 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -30,6 +30,7 @@ class PartSet_Module; class ModuleBase_Operation; class ModuleBase_IWorkshop; class PartSet_PreviewPlanes; +class ModuleBase_ChoiceCtrl; /** * \ingroup Modules @@ -140,6 +141,9 @@ private: private slots: void onResumed(ModuleBase_Operation* theOp); + /// Slot is called on selection type changed + void onSelectionTypeChanged(); + private: /// Append new Sketch, set the selected plane for the sketch and start Edit operation. /// \param theValues a selection list @@ -179,6 +183,12 @@ private: /// class to show/hide preview planes PartSet_PreviewPlanes* myPreviewPlanes; + + bool myIsUseChoice; ///< A flag to store use_choice parameter state + + /// Control for types + ModuleBase_ChoiceCtrl* myTypeCtrl; + std::string myDefMode; }; #endif \ No newline at end of file -- 2.39.2