From f4b66a0744e13778ab35f7e165d968c868dd6d9f Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 6 Apr 2016 16:35:43 +0300 Subject: [PATCH] Issue #1343. Improvement of Extrusion and Revolution operations: transaction correction: sketch creation is sketch transaction(was: sketch in extrusion, edit sketch transaction), disable/enable selection control in widget sketch creator. --- src/FeaturesPlugin/extrusion_widget.xml | 4 +- src/FeaturesPlugin/extrusioncut_widget.xml | 4 +- src/FeaturesPlugin/extrusionfuse_widget.xml | 4 +- src/FeaturesPlugin/revolution_widget.xml | 4 +- src/FeaturesPlugin/revolutioncut_widget.xml | 4 +- src/FeaturesPlugin/revolutionfuse_widget.xml | 4 +- .../ModuleBase_OperationFeature.cpp | 10 +- src/ModuleBase/ModuleBase_OperationFeature.h | 4 + src/PartSet/CMakeLists.txt | 2 - src/PartSet/PartSet_Module.cpp | 5 - .../PartSet_WidgetMultiSelectorComposite.cpp | 60 ----------- .../PartSet_WidgetMultiSelectorComposite.h | 51 ---------- src/PartSet/PartSet_WidgetSketchCreator.cpp | 99 +++++++++++-------- src/PartSet/PartSet_WidgetSketchCreator.h | 14 ++- 14 files changed, 89 insertions(+), 180 deletions(-) delete mode 100755 src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp delete mode 100755 src/PartSet/PartSet_WidgetMultiSelectorComposite.h diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 4c94677a1..ebe912f3b 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -10,12 +10,12 @@ shape_types="faces objects"> - - + - - + - - + - - + - - + - - + aPreSelected; // Check that the selected result are not results of operation feature FeaturePtr aFeature = feature(); @@ -433,7 +431,13 @@ void ModuleBase_OperationFeature::initSelection(ModuleBase_ISelection* theSelect } else aPreSelected = theSelection->getSelected(ModuleBase_ISelection::AllControls); - myPreSelection = aPreSelected; + setPreselection(aPreSelected); +} + +void ModuleBase_OperationFeature::setPreselection(const QList& theValues) +{ + clearPreselection(); + myPreSelection = theValues; } void ModuleBase_OperationFeature::clearPreselection() diff --git a/src/ModuleBase/ModuleBase_OperationFeature.h b/src/ModuleBase/ModuleBase_OperationFeature.h index 2d1844d13..b6f5c95fd 100755 --- a/src/ModuleBase/ModuleBase_OperationFeature.h +++ b/src/ModuleBase/ModuleBase_OperationFeature.h @@ -98,6 +98,10 @@ Q_OBJECT virtual void initSelection(ModuleBase_ISelection* theSelection, ModuleBase_IViewer* theViewer); + /// Fill internal map by preselection + /// \param theValues a list of preselection + void setPreselection(const QList& theValues); + /// \brief Set property pane to the operation /// \param theProp a property panel instance virtual void setPropertyPanel(ModuleBase_IPropertyPanel* theProp); diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index bb032d0d7..e0d363f52 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -19,7 +19,6 @@ SET(PROJECT_HEADERS PartSet_WidgetPoint2d.h PartSet_WidgetEditor.h PartSet_WidgetMultiSelector.h - PartSet_WidgetMultiSelectorComposite.h PartSet_WidgetPoint2dDistance.h PartSet_WidgetPoint2DFlyout.h PartSet_WidgetShapeSelector.h @@ -47,7 +46,6 @@ SET(PROJECT_SOURCES PartSet_Validators.cpp PartSet_WidgetEditor.cpp PartSet_WidgetMultiSelector.cpp - PartSet_WidgetMultiSelectorComposite.cpp PartSet_WidgetPoint2d.cpp PartSet_WidgetPoint2dDistance.cpp PartSet_WidgetPoint2DFlyout.cpp diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index f4984ca05..a55a66c48 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -10,7 +10,6 @@ #include "PartSet_WidgetPoint2DFlyout.h" #include "PartSet_WidgetShapeSelector.h" #include "PartSet_WidgetMultiSelector.h" -#include "PartSet_WidgetMultiSelectorComposite.h" #include "PartSet_WidgetEditor.h" #include "PartSet_WidgetFileSelector.h" #include "PartSet_WidgetSketchCreator.h" @@ -680,10 +679,6 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th new PartSet_WidgetMultiSelector(theParent, aWorkshop, theWidgetApi); aShapeSelectorWgt->setSketcher(mySketchMgr->activeSketch()); aWgt = aShapeSelectorWgt; - } else if (theType == "composite_multi_selector") { - PartSet_WidgetMultiSelectorComposite* aShapeSelectorWgt = - new PartSet_WidgetMultiSelectorComposite(theParent, aWorkshop, theWidgetApi); - aWgt = aShapeSelectorWgt; } else if (theType == WDG_DOUBLEVALUE_EDITOR) { aWgt = new PartSet_WidgetEditor(theParent, aWorkshop, theWidgetApi); diff --git a/src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp b/src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp deleted file mode 100755 index 2c34e5c2a..000000000 --- a/src/PartSet/PartSet_WidgetMultiSelectorComposite.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_WidgetMultiSelectorComposite.cpp -// Created: 17 Mar 2016 -// Author: Natalia Ermolaeva - -#include "PartSet_WidgetMultiSelectorComposite.h" - -PartSet_WidgetMultiSelectorComposite::PartSet_WidgetMultiSelectorComposite(QWidget* theParent, - ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData) -: ModuleBase_WidgetMultiSelector(theParent, theWorkshop, theData) -{ -} - -PartSet_WidgetMultiSelectorComposite::~PartSet_WidgetMultiSelectorComposite() -{ -} - -bool PartSet_WidgetMultiSelectorComposite::focusTo() -{ - bool aCanHaveFocus = true; - - if (hasSubObjects()) { - // disable widget controls - disableControls(); - aCanHaveFocus = false; - } - else - aCanHaveFocus = ModuleBase_WidgetMultiSelector::focusTo(); - return aCanHaveFocus; -} - -void PartSet_WidgetMultiSelectorComposite::setEditingMode(bool isEditing) -{ - ModuleBase_ModelWidget::setEditingMode(isEditing); - bool aHasSubObjects = hasSubObjects(); - if (aHasSubObjects) - disableControls(); -} - -bool PartSet_WidgetMultiSelectorComposite::hasSubObjects() const -{ - bool aHasSubObjects = false; - - bool aCanSetFocus = true; - CompositeFeaturePtr aComposite = std::dynamic_pointer_cast(myFeature); - if (aComposite.get()) - aHasSubObjects = aComposite->numberOfSubs() > 0; - return aHasSubObjects; -} - -void PartSet_WidgetMultiSelectorComposite::disableControls() -{ - QList aMyControls = getControls(); - foreach(QWidget* eachControl, aMyControls) { - eachControl->setFocusPolicy(Qt::NoFocus); - eachControl->setEnabled(false); - } -} diff --git a/src/PartSet/PartSet_WidgetMultiSelectorComposite.h b/src/PartSet/PartSet_WidgetMultiSelectorComposite.h deleted file mode 100755 index 4cfd940a0..000000000 --- a/src/PartSet/PartSet_WidgetMultiSelectorComposite.h +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_WidgetMultiSelectorComposite.h -// Created: 17 Mar 2016 -// Author: Natalia Ermolaeva - -#ifndef PartSet_WidgetMultiSelectorComposite_H -#define PartSet_WidgetMultiSelectorComposite_H - -#include "PartSet.h" - -#include - -#include - -/** -* \ingroup Modules -* Customosation of ModuleBase_WidgetMultiSelector in order to provide -* working with sketch specific objects and creation of external objects. -*/ -class PARTSET_EXPORT PartSet_WidgetMultiSelectorComposite: public ModuleBase_WidgetMultiSelector -{ -Q_OBJECT - public: - /// Constructor - /// \param theParent the parent object - /// \param theWorkshop instance of workshop interface - /// \param theData the widget configuation. The attribute of the model widget is obtained from - PartSet_WidgetMultiSelectorComposite(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData); - - virtual ~PartSet_WidgetMultiSelectorComposite(); - - /// Set focus to the first control of the current widget. The focus policy of the control is checked. - /// If the widget has the NonFocus focus policy, it is skipped. - /// \return the state whether the widget can accept the focus - virtual bool focusTo(); - - /// Editing mode depends on mode of current operation. This value is defined by it. - virtual void setEditingMode(bool isEditing); - -private: - /// Returns true if the current composite feature contains at least one sub-object - /// \return boolean value - bool hasSubObjects() const; - - /// Disable controls by setting them focus policy NoFocus and disabling them - void disableControls(); -}; - -#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index cc3f93362..1f00cc5a1 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -48,7 +48,7 @@ #include #include -//#define DEBUG_UNDO_INVALID_SKETCH +#define DEBUG_UNDO_INVALID_SKETCH PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule, @@ -71,19 +71,6 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, myLabel->setWordWrap(true); aLayout->addWidget(myLabel); aLayout->addStretch(1); - /*if (!aLabelIcon.isEmpty()) - myLabel->setPixmap(QPixmap(aLabelIcon)); - - - QString aToolTip = QString::fromStdString(theData->widgetTooltip()); - myTextLine = new QLineEdit(this); - myTextLine->setReadOnly(true); - myTextLine->setToolTip(aToolTip); - myTextLine->installEventFilter(this); - - myLabel->setToolTip(aToolTip); - - aLayout->addRow(myLabel, myTextLine);*/ std::string aTypes = theData->getProperty("shape_types"); myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts); @@ -93,6 +80,9 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator() { + // we need to deactivate here in order to hide preview planes if the selection mode is + // active + deactivate(); } QList PartSet_WidgetSketchCreator::getControls() const @@ -104,12 +94,6 @@ QList PartSet_WidgetSketchCreator::getControls() const bool PartSet_WidgetSketchCreator::restoreValueCustom() { - /*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; } @@ -178,8 +162,6 @@ bool PartSet_WidgetSketchCreator::isValidSelectionCustom(const ModuleBase_Viewer void PartSet_WidgetSketchCreator::activateSelectionControl() { - setVisibleSelectionControl(true); - // we need to call activate here as the widget has no focus accepted controls // if these controls are added here, activate will happens automatically after focusIn() XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); @@ -201,8 +183,11 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec else { // hide current control if (aWidget == this) aWidget->setVisible(false); - else + else { aWidget->setVisible(true); + if (aWidget->attributeID() == myAttributeListID) + setEnabledModelWidget(aWidget, !hasSubObjects()); + } } } @@ -232,8 +217,22 @@ QIntList PartSet_WidgetSketchCreator::getShapeTypes() const void PartSet_WidgetSketchCreator::setEditingMode(bool isEditing) { ModuleBase_ModelWidget::setEditingMode(isEditing); - if (isEditing) + if (isEditing) { setVisibleSelectionControl(false); + + ModuleBase_ModelWidget* anAttributeListWidget = 0; + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); + XGUI_PropertyPanel* aPanel = aWorkshop->propertyPanel(); + const QList& aWidgets = aPanel->modelWidgets(); + foreach(ModuleBase_ModelWidget* aWidget, aWidgets) { + if (aWidget->attributeID() == myAttributeListID) { + anAttributeListWidget = aWidget; + break; + } + } + if (anAttributeListWidget) + setEnabledModelWidget(anAttributeListWidget, !hasSubObjects()); + } } bool PartSet_WidgetSketchCreator::isSelectionMode() const @@ -244,6 +243,17 @@ bool PartSet_WidgetSketchCreator::isSelectionMode() const return !aHasValueInList; } +bool PartSet_WidgetSketchCreator::hasSubObjects() const +{ + bool aHasSubObjects = false; + + bool aCanSetFocus = true; + CompositeFeaturePtr aComposite = std::dynamic_pointer_cast(myFeature); + if (aComposite.get()) + aHasSubObjects = aComposite->numberOfSubs() > 0; + return aHasSubObjects; +} + bool PartSet_WidgetSketchCreator::setSelection(QList& theValues, const bool theToValidate) { @@ -305,23 +315,13 @@ bool PartSet_WidgetSketchCreator::startSketchOperation(const QList(myFeature); - /// add sketch feature without current feature change. - /// it is important to do not change the current feature in order to - /// after sketch edition, the extrusion cut feature becomes current - SessionPtr aMgr = ModelAPI_Session::get(); - DocumentPtr aDoc = aMgr->activeDocument(); - FeaturePtr aPreviousCurrentFeature = aDoc->currentFeature(false); - FeaturePtr aSketch = aCompFeature->addFeature("Sketch"); - - PartSet_WidgetSketchLabel::fillSketchPlaneBySelection(aSketch, aValue); - - aDoc->setCurrentFeature(aPreviousCurrentFeature, false); - // start edit operation for the sketch ModuleBase_OperationFeature* aFOperation = dynamic_cast (myModule->createOperation("Sketch")); - if (aFOperation) - aFOperation->setFeature(aSketch); + QList aValues; + aValues.push_back(aValue); + aFOperation->setPreselection(aValues); + myModule->sendOperation(aFOperation); return aSketchStarted; @@ -330,16 +330,16 @@ bool PartSet_WidgetSketchCreator::startSketchOperation(const QList