From 1d7f1751b169b50450ebceae6a700708d5bfe7d5 Mon Sep 17 00:00:00 2001 From: nds Date: Fri, 18 Mar 2016 11:05:31 +0300 Subject: [PATCH] Issue #1343 Improvement of Extrusion and Revolution operations: first extrusion widget is a selection widget child to process different types of selection in the viewer. --- src/FeaturesPlugin/extrusion_widget.xml | 7 +- src/ModuleBase/ModuleBase_WidgetSelector.cpp | 6 + src/ModuleBase/ModuleBase_WidgetSelector.h | 8 +- src/PartSet/PartSet_WidgetSketchCreator.cpp | 128 +++++++++++++++---- src/PartSet/PartSet_WidgetSketchCreator.h | 28 +++- 5 files changed, 141 insertions(+), 36 deletions(-) diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 82414a999..ac410cf69 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -2,10 +2,13 @@ + tooltip="Create or edit a sketch" + shape_types="vertex edge face"> diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.cpp b/src/ModuleBase/ModuleBase_WidgetSelector.cpp index d2d36e446..454ed88de 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetSelector.cpp @@ -62,6 +62,12 @@ void ModuleBase_WidgetSelector::onSelectionChanged() updateFocus(); } +//******************************************************************** +QList ModuleBase_WidgetSelector::getAttributeSelection() const +{ + return QList(); +} + //******************************************************************** bool ModuleBase_WidgetSelector::acceptSubShape(const GeomShapePtr& theShape, const ResultPtr& theResult) const diff --git a/src/ModuleBase/ModuleBase_WidgetSelector.h b/src/ModuleBase/ModuleBase_WidgetSelector.h index 2a41f7114..d2fbdeb08 100755 --- a/src/ModuleBase/ModuleBase_WidgetSelector.h +++ b/src/ModuleBase/ModuleBase_WidgetSelector.h @@ -64,26 +64,26 @@ Q_OBJECT protected: /// Update focus after the attribute value change - virtual void updateFocus() = 0; + virtual void updateFocus() {}; /// Return the attribute values wrapped in a list of viewer presentations /// \return a list of viewer presentations, which contains an attribute result and /// a shape. If the attribute do not uses the shape, it is empty - virtual QList getAttributeSelection() const = 0; + virtual QList getAttributeSelection() const; /// Retunrs a list of possible shape types /// \return a list of shapes virtual QIntList getShapeTypes() const = 0; /// Computes and updates name of selected object in the widget - virtual void updateSelectionName() = 0; + virtual void updateSelectionName() {}; /// Store the values to the model attribute of the widget. It casts this attribute to /// the specific type and set the given values /// \param theSelectedObject an object /// \param theShape a selected shape, which is used in the selection attribute /// \return true if it is succeed - virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) = 0; + virtual void setObject(ObjectPtr theSelectedObject, GeomShapePtr theShape) {}; /// The methiod called when widget is activated virtual void activateCustom(); diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index b965f4348..22e839ce5 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include @@ -37,21 +38,31 @@ #include #include -#include +//#include +#include #include PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule, const Config_WidgetAPI* theData) -: ModuleBase_ModelWidget(theParent, theData), myModule(theModule), myUseBody(true) +: ModuleBase_WidgetSelector(theParent, theModule->workshop(), theData), + myModule(theModule), myUseBody(true) { - QFormLayout* aLayout = new QFormLayout(this); + myAttributeListID = theData->getProperty("attribute_list_id"); + + //QFormLayout* aLayout = new QFormLayout(this); + QVBoxLayout* aLayout = new QVBoxLayout(this); + ModuleBase_Tools::zeroMargins(aLayout); + ModuleBase_Tools::adjustMargins(aLayout); QString aLabelText = QString::fromStdString(theData->widgetLabel()); QString aLabelIcon = QString::fromStdString(theData->widgetIcon()); + myLabel = new QLabel(aLabelText, this); - if (!aLabelIcon.isEmpty()) + myLabel->setWordWrap(true); + aLayout->addWidget(myLabel); + /*if (!aLabelIcon.isEmpty()) myLabel->setPixmap(QPixmap(aLabelIcon)); @@ -68,7 +79,10 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, myUseBody = QVariant(aUseBody).toBool(); } - aLayout->addRow(myLabel, myTextLine); + aLayout->addRow(myLabel, myTextLine);*/ + + std::string aTypes = theData->getProperty("shape_types"); + myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts); } PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator() @@ -78,18 +92,18 @@ PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator() QList PartSet_WidgetSketchCreator::getControls() const { QList aControls; - aControls.append(myTextLine); + aControls.append(myLabel); return aControls; } bool PartSet_WidgetSketchCreator::restoreValueCustom() { - CompositeFeaturePtr aCompFeature = + /*CompositeFeaturePtr aCompFeature = std::dynamic_pointer_cast(myFeature); if (aCompFeature->numberOfSubs() > 0) { FeaturePtr aSubFeature = aCompFeature->subFeature(0); myTextLine->setText(QString::fromStdString(aSubFeature->data()->name())); - } + }*/ return true; } @@ -100,16 +114,72 @@ bool PartSet_WidgetSketchCreator::storeValueCustom() const void PartSet_WidgetSketchCreator::activateCustom() { - CompositeFeaturePtr aCompFeature = - std::dynamic_pointer_cast(myFeature); - if (aCompFeature->numberOfSubs() == 0) - connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted())); + if (isSelectionMode()) { + ModuleBase_WidgetSelector::activateCustom(); + //connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted())); + + //setVisibleSelectionControl(true); + } + else { + setVisibleSelectionControl(false); + emit focusOutWidget(this); + } +} + +void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelectionControl) +{ + // hide current widget, activate the next widget + XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel(); + const QList& aWidgets = aPanel->modelWidgets(); + foreach(ModuleBase_ModelWidget* aWidget, aWidgets) { + if (theSelectionControl) { // hide other controls + if (aWidget != this) + aWidget->setVisible(false); + } + else { // hide current control + if (aWidget == this) + aWidget->setVisible(false); + } + } +} + +QIntList PartSet_WidgetSketchCreator::getShapeTypes() const +{ + QIntList aShapeTypes; + foreach(QString aType, myShapeTypes) { + aShapeTypes.append(ModuleBase_Tools::shapeType(aType)); + } + return aShapeTypes; +} + +void PartSet_WidgetSketchCreator::deactivate() +{ + if (isSelectionMode()) { + ModuleBase_WidgetSelector::activateCustom(); + } +} + +bool PartSet_WidgetSketchCreator::isSelectionMode() const +{ + //CompositeFeaturePtr aCompFeature = + // std::dynamic_pointer_cast(myFeature); + //bool aHasSub = aCompFeature->numberOfSubs() > 0; + + AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID); + bool aHasValueInList = anAttrList.get() && anAttrList->size() > 0; + + return !aHasValueInList;//aHasSub || aHasValueInList; } void PartSet_WidgetSketchCreator::onStarted() { disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted())); + setVisibleSelectionControl(true); + + /* // Check that model already has bodies XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); XGUI_Workshop* aWorkshop = aConnector->workshop(); @@ -156,26 +226,30 @@ void PartSet_WidgetSketchCreator::onStarted() tr("There are no bodies found. Operation aborted."), QMessageBox::Ok); ModuleBase_Operation* aOp = myModule->workshop()->currentOperation(); aOp->abort(); - } + }*/ } bool PartSet_WidgetSketchCreator::focusTo() { - CompositeFeaturePtr aCompFeature = - std::dynamic_pointer_cast(myFeature); - if (aCompFeature->numberOfSubs() == 0) - return ModuleBase_ModelWidget::focusTo(); - - connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*))); - SessionPtr aMgr = ModelAPI_Session::get(); - // Open transaction that is general for the previous nested one: it will be closed on nested commit - bool aIsOp = aMgr->isOperation(); - if (!aIsOp) { - const static std::string aNestedOpID("Parameters modification"); - aMgr->startOperation(aNestedOpID, true); + if (isSelectionMode()) { + //CompositeFeaturePtr aCompFeature = + // std::dynamic_pointer_cast(myFeature); + // if (aCompFeature->numberOfSubs() == 0) + // return ModuleBase_ModelWidget::focusTo(); + connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted())); + return true; + } + else { + connect(myModule, SIGNAL(resumed(ModuleBase_Operation*)), SLOT(onResumed(ModuleBase_Operation*))); + SessionPtr aMgr = ModelAPI_Session::get(); + // Open transaction that is general for the previous nested one: it will be closed on nested commit + bool aIsOp = aMgr->isOperation(); + if (!aIsOp) { + const static std::string aNestedOpID("Parameters modification"); + aMgr->startOperation(aNestedOpID, true); + } + restoreValue(); } - - restoreValue(); return false; } diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index 4bb31fe94..f52a0f1fa 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -9,7 +9,7 @@ #include "PartSet.h" -#include +#include class QLabel; class QLineEdit; @@ -24,10 +24,11 @@ class ModuleBase_Operation; * it will transfer a focus to next widget. It is supposed that the widget will be placed as * a first widget in property panel */ -class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_ModelWidget +class PARTSET_EXPORT PartSet_WidgetSketchCreator : public ModuleBase_WidgetSelector { Q_OBJECT - public: + +public: /// Constructor /// \param theParent the parent object /// \param theModule a reference to a module object @@ -46,6 +47,9 @@ Q_OBJECT /// \return the state whether the widget can accept the focus virtual bool focusTo(); + /// The methiod called when widget is deactivated + virtual void deactivate(); + protected: /// Saves the internal parameters to the given feature /// \return True in success @@ -56,12 +60,27 @@ protected: /// The methiod called when widget is activated virtual void activateCustom(); + /// Visualization of the current control or others in PP + /// \param theSelectionControl state whether the control should be shown/hidden + void setVisibleSelectionControl(const bool theSelectionControl); + + /// Retunrs a list of possible shape types + /// \return a list of shapes + virtual QIntList getShapeTypes() const; + +private: + /// Returns true if the selection mode is active. This is when composition feature has no + /// a sub-object and the attribute list is empty + /// \return boolean value + bool isSelectionMode() const; + private slots: void onStarted(); void onResumed(ModuleBase_Operation* theOp); private: + std::string myAttributeListID; PartSet_Module* myModule; @@ -71,6 +90,9 @@ private: /// Input control of the widget QLineEdit* myTextLine; + /// List of accepting shapes types + QStringList myShapeTypes; + /// To check if we need to use body for composite feature or not bool myUseBody; -- 2.39.2