From: nds Date: Tue, 22 Mar 2016 11:28:44 +0000 (+0300) Subject: Issue #1343 Improvement of Extrusion and Revolution operations: sketcher start or... X-Git-Tag: V_2.3.0~334 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=514bc3ce714fa4b398b94f3293aa279b31725467;p=modules%2Fshaper.git Issue #1343 Improvement of Extrusion and Revolution operations: sketcher start or extrusion filling by selection. --- diff --git a/src/ExchangePlugin/plugin-Exchange.xml b/src/ExchangePlugin/plugin-Exchange.xml index d8bb8a0c7..1dfef175e 100644 --- a/src/ExchangePlugin/plugin-Exchange.xml +++ b/src/ExchangePlugin/plugin-Exchange.xml @@ -12,7 +12,8 @@ - + diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 8a1001b85..86530f164 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -26,6 +26,7 @@ SET(PROJECT_HEADERS FeaturesPlugin_RevolutionBoolean.h FeaturesPlugin_RevolutionCut.h FeaturesPlugin_RevolutionFuse.h + FeaturesPlugin_ValidatorExtrusionBase.h FeaturesPlugin_ValidatorTransform.h FeaturesPlugin_Validators.h ) @@ -52,6 +53,7 @@ SET(PROJECT_SOURCES FeaturesPlugin_RevolutionBoolean.cpp FeaturesPlugin_RevolutionCut.cpp FeaturesPlugin_RevolutionFuse.cpp + FeaturesPlugin_ValidatorExtrusionBase.cpp FeaturesPlugin_ValidatorTransform.cpp FeaturesPlugin_Validators.cpp ) @@ -80,6 +82,7 @@ INCLUDE_DIRECTORIES( ../ModelAPI ../GeomAPI ../GeomAlgoAPI + ../GeomValidators ../Events ) @@ -88,6 +91,7 @@ SET(PROJECT_LIBRARIES ModelAPI GeomAPI GeomAlgoAPI + GeomValidators ) ADD_DEFINITIONS(-DFEATURESPLUGIN_EXPORTS) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp index 432e38850..0fd2ba3b4 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Plugin.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -38,6 +39,8 @@ FeaturesPlugin_Plugin::FeaturesPlugin_Plugin() ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); aFactory->registerValidator("FeaturesPlugin_ValidatorTransform", new FeaturesPlugin_ValidatorTransform); + aFactory->registerValidator("FeaturesPlugin_ValidatorExtrusionBase", + new FeaturesPlugin_ValidatorExtrusionBase); aFactory->registerValidator("FeaturesPlugin_PipeLocationsValidator", new FeaturesPlugin_PipeLocationsValidator); diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.cpp b/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.cpp new file mode 100755 index 000000000..7f16df44e --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.cpp @@ -0,0 +1,31 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +#include "FeaturesPlugin_ValidatorExtrusionBase.h" + +#include "GeomValidators_FeatureKind.h" +#include "GeomValidators_ShapeType.h" + +#include "ModelAPI_AttributeSelectionList.h" +#include "ModelAPI_ResultPart.h" +#include "ModelAPI_ResultBody.h" +#include "ModelAPI_ResultCompSolid.h" +#include "ModelAPI_Session.h" + +bool FeaturesPlugin_ValidatorExtrusionBase::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + bool aValid = true; + + GeomValidators_FeatureKind* aValidator = new GeomValidators_FeatureKind(); + // check whether the selection is on the sketch + bool aFeatureKindValid = aValidator->isValid(theAttribute, theArguments, theError); + if (!aFeatureKindValid) { + // check if selection has Face selected + GeomValidators_ShapeType* aShapeType = new GeomValidators_ShapeType(); + std::list anArguments; + anArguments.push_back("face"); + aValid = aShapeType->isValid(theAttribute, anArguments, theError); + } + return aValid; +} diff --git a/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.h b/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.h new file mode 100755 index 000000000..240718b21 --- /dev/null +++ b/src/FeaturesPlugin/FeaturesPlugin_ValidatorExtrusionBase.h @@ -0,0 +1,29 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: FeaturesPlugin_ValidatorExtrusionBase.h +// Created: 16 Sep 2015 +// Author: Natalia ERMOLAEVA + +#ifndef FeaturesPlugin_ValidatorExtrusionBase_H +#define FeaturesPlugin_ValidatorExtrusionBase_H + +#include "ModelAPI_AttributeValidator.h" + +/** \class FeaturesPlugin_ValidatorExtrusionBase + * \ingroup Validators + * \brief A validator of selection + */ +class FeaturesPlugin_ValidatorExtrusionBase : public ModelAPI_AttributeValidator +{ + public: + /** \return true if attribute is valid + * \param theAttribute the checked attribute + * \param theArguments arguments of the attribute + * \param theError error message + */ + virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + +#endif diff --git a/src/FeaturesPlugin/extrusion_widget.xml b/src/FeaturesPlugin/extrusion_widget.xml index 09462cf8e..6f0faf610 100644 --- a/src/FeaturesPlugin/extrusion_widget.xml +++ b/src/FeaturesPlugin/extrusion_widget.xml @@ -9,17 +9,17 @@ Extrusion will be filled with them" icon=":icons/sketch.png" use_body="false" tooltip="Create or edit a sketch" - shape_types="vertex edge face wire objects"> + shape_types="face objects"> + + + - - - - - - + type_choice="Vertices Edges Faces Solids" + use_choice="true"> \ No newline at end of file diff --git a/src/FeaturesPlugin/revolution_widget.xml b/src/FeaturesPlugin/revolution_widget.xml index 80ad354cd..187317bc0 100644 --- a/src/FeaturesPlugin/revolution_widget.xml +++ b/src/FeaturesPlugin/revolution_widget.xml @@ -8,7 +8,7 @@ icon=":icons/sketch.png" tooltip="Select a sketch face" type_choice="Faces"> - + - + +#include +#include +#include + +bool GeomValidators_FeatureKind::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const +{ + bool isSketchEntities = true; + std::set anEntityKinds; + std::string anEntityKindsStr; + std::list::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); + for (; anIt != aLast; anIt++) { + anEntityKinds.insert(*anIt); + if (!anEntityKindsStr.empty()) + anEntityKindsStr += ", "; + anEntityKindsStr += *anIt; + } + + std::string anAttributeType = theAttribute->attributeType(); + if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { + AttributeSelectionListPtr aSelectionListAttr = + std::dynamic_pointer_cast(theAttribute); + // all context objects should be sketch entities + for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize && isSketchEntities; i++) { + AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); + ObjectPtr anObject = aSelectAttr->context(); + // a context of the selection attribute is a feature result. It can be a case when the result + // of the feature is null, e.g. the feature is modified and has not been executed yet. + // The validator returns an invalid result here. The case is an extrusion built on a sketch + // feature. A new sketch element creation leads to an empty result. + if (!anObject.get()) + isSketchEntities = false; + else { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } + } + if (anAttributeType == ModelAPI_AttributeSelection::typeId()) { + AttributeSelectionPtr aSelectAttr = + std::dynamic_pointer_cast(theAttribute); + ObjectPtr anObject = aSelectAttr->context(); + // a context of the selection attribute is a feature result. It can be a case when the result + // of the feature is null, e.g. the feature is modified and has not been executed yet. + // The validator returns an invalid result here. The case is an extrusion built on a sketch + // feature. A new sketch element creation leads to an empty result. + if (!anObject.get()) + isSketchEntities = false; + else { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } + if (anAttributeType == ModelAPI_AttributeRefList::typeId()) { + AttributeRefListPtr aRefListAttr = + std::dynamic_pointer_cast(theAttribute); + // all context objects should be sketch entities + for (int i = 0, aSize = aRefListAttr->size(); i < aSize && isSketchEntities; i++) { + ObjectPtr anObject = aRefListAttr->object(i); + // a context of the selection attribute is a feature result. It can be a case when the result + // of the feature is null, e.g. the feature is modified and has not been executed yet. + // The validator returns an invalid result here. The case is an extrusion built on a sketch + // feature. A new sketch element creation leads to an empty result. + if (!anObject.get()) + isSketchEntities = false; + else { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } + } + if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) { + std::shared_ptr aRef = + std::dynamic_pointer_cast(theAttribute); + isSketchEntities = false; + if (aRef->isObject()) { + ObjectPtr anObject = aRef->object(); + if (anObject.get() != NULL) { + FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); + if (aFeature.get() != NULL) + isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); + } + } + } + if (!isSketchEntities) { + theError = "It refers to feature, which kind is not in the list: " + anEntityKindsStr; + } + + return isSketchEntities; +} diff --git a/src/GeomValidators/GeomValidators_FeatureKind.h b/src/GeomValidators/GeomValidators_FeatureKind.h new file mode 100755 index 000000000..894992753 --- /dev/null +++ b/src/GeomValidators/GeomValidators_FeatureKind.h @@ -0,0 +1,31 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: GeomValidators_FeatureKind.h +// Created: 22 March 2015 +// Author: Natalia Ermolaeva + +#ifndef GeomValidators_FeatureKind_H +#define GeomValidators_FeatureKind_H + +#include + +#include +#include + +/** + * Generic validator for any attribute of a feature. + */ +class GeomValidators_FeatureKind : public ModelAPI_AttributeValidator +{ +public: + /// \return True if the attribute is valid. It checks whether the shape is a + /// body subshape. Does not allow select construction shapes. + /// \param[in] theAttribute an attribute to check + /// \param[in] theArguments a filter parameters + /// \param[out] theError error message. + GEOMVALIDATORS_EXPORT virtual bool isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const; +}; + +#endif diff --git a/src/GeomValidators/GeomValidators_Plugin.cpp b/src/GeomValidators/GeomValidators_Plugin.cpp index 824206f63..831ad0dc9 100644 --- a/src/GeomValidators/GeomValidators_Plugin.cpp +++ b/src/GeomValidators/GeomValidators_Plugin.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -39,6 +40,7 @@ GeomValidators_Plugin::GeomValidators_Plugin() aFactory->registerValidator("GeomValidators_ZeroOffset", new GeomValidators_ZeroOffset); aFactory->registerValidator("GeomValidators_BooleanSelection", new GeomValidators_BooleanSelection); aFactory->registerValidator("GeomValidators_IntersectionSelection", new GeomValidators_IntersectionSelection); + aFactory->registerValidator("GeomValidators_FeatureKind", new GeomValidators_FeatureKind); // register this plugin ModelAPI_Session::get()->registerPlugin(this); diff --git a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp index 43a879c57..81a5194b5 100755 --- a/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp +++ b/src/ModuleBase/ModuleBase_WidgetMultiSelector.cpp @@ -101,7 +101,7 @@ ModuleBase_WidgetMultiSelector::ModuleBase_WidgetMultiSelector(QWidget* theParen QString aTypesStr = aPropertyTypes.c_str(); QStringList aShapeTypes = aTypesStr.split(' ', QString::SkipEmptyParts); - myIsUseChoice = theData->getBooleanAttribute("use_choice", true); + myIsUseChoice = theData->getBooleanAttribute("use_choice", false); if (!aShapeTypes.empty()) myTypeCombo->addItems(aShapeTypes); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 53ae4b098..8a43baadc 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -222,7 +222,6 @@ void PartSet_Module::registerValidators() aFactory->registerValidator("PartSet_MiddlePointSelection", new PartSet_MiddlePointSelection); aFactory->registerValidator("PartSet_DifferentObjects", new PartSet_DifferentObjectsValidator); aFactory->registerValidator("PartSet_CoincidentAttr", new PartSet_CoincidentAttr); - aFactory->registerValidator("PartSet_SketchEntityValidator", new PartSet_SketchEntityValidator); } void PartSet_Module::registerFilters() diff --git a/src/PartSet/PartSet_Validators.cpp b/src/PartSet/PartSet_Validators.cpp index 6baf8589d..4bf822bfd 100755 --- a/src/PartSet/PartSet_Validators.cpp +++ b/src/PartSet/PartSet_Validators.cpp @@ -523,94 +523,6 @@ bool PartSet_DifferentObjectsValidator::isValid(const AttributePtr& theAttribute return true; } -bool PartSet_SketchEntityValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const -{ - bool isSketchEntities = true; - std::set anEntityKinds; - std::string anEntityKindsStr; - std::list::const_iterator anIt = theArguments.begin(), aLast = theArguments.end(); - for (; anIt != aLast; anIt++) { - anEntityKinds.insert(*anIt); - if (!anEntityKindsStr.empty()) - anEntityKindsStr += ", "; - anEntityKindsStr += *anIt; - } - - std::string anAttributeType = theAttribute->attributeType(); - if (anAttributeType == ModelAPI_AttributeSelectionList::typeId()) { - AttributeSelectionListPtr aSelectionListAttr = - std::dynamic_pointer_cast(theAttribute); - // all context objects should be sketch entities - for (int i = 0, aSize = aSelectionListAttr->size(); i < aSize && isSketchEntities; i++) { - AttributeSelectionPtr aSelectAttr = aSelectionListAttr->value(i); - ObjectPtr anObject = aSelectAttr->context(); - // a context of the selection attribute is a feature result. It can be a case when the result - // of the feature is null, e.g. the feature is modified and has not been executed yet. - // The validator returns an invalid result here. The case is an extrusion built on a sketch - // feature. A new sketch element creation leads to an empty result. - if (!anObject.get()) - isSketchEntities = false; - else { - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); - } - } - } - if (anAttributeType == ModelAPI_AttributeSelection::typeId()) { - AttributeSelectionPtr aSelectAttr = - std::dynamic_pointer_cast(theAttribute); - ObjectPtr anObject = aSelectAttr->context(); - // a context of the selection attribute is a feature result. It can be a case when the result - // of the feature is null, e.g. the feature is modified and has not been executed yet. - // The validator returns an invalid result here. The case is an extrusion built on a sketch - // feature. A new sketch element creation leads to an empty result. - if (!anObject.get()) - isSketchEntities = false; - else { - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); - } - } - if (anAttributeType == ModelAPI_AttributeRefList::typeId()) { - AttributeRefListPtr aRefListAttr = - std::dynamic_pointer_cast(theAttribute); - // all context objects should be sketch entities - for (int i = 0, aSize = aRefListAttr->size(); i < aSize && isSketchEntities; i++) { - ObjectPtr anObject = aRefListAttr->object(i); - // a context of the selection attribute is a feature result. It can be a case when the result - // of the feature is null, e.g. the feature is modified and has not been executed yet. - // The validator returns an invalid result here. The case is an extrusion built on a sketch - // feature. A new sketch element creation leads to an empty result. - if (!anObject.get()) - isSketchEntities = false; - else { - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); - } - } - } - if (anAttributeType == ModelAPI_AttributeRefAttr::typeId()) { - std::shared_ptr aRef = - std::dynamic_pointer_cast(theAttribute); - isSketchEntities = false; - if (aRef->isObject()) { - ObjectPtr anObject = aRef->object(); - if (anObject.get() != NULL) { - FeaturePtr aFeature = ModelAPI_Feature::feature(anObject); - if (aFeature.get() != NULL) - isSketchEntities = anEntityKinds.find(aFeature->getKind()) != anEntityKinds.end(); - } - } - } - if (!isSketchEntities) { - theError = "It refers to feature, which kind is not in the list: " + anEntityKindsStr; - } - - return isSketchEntities; -} - bool PartSet_CoincidentAttr::isValid(const AttributePtr& theAttribute, const std::list& theArguments, std::string& theError) const diff --git a/src/PartSet/PartSet_Validators.h b/src/PartSet/PartSet_Validators.h index aaf3c88c9..2111ef63d 100644 --- a/src/PartSet/PartSet_Validators.h +++ b/src/PartSet/PartSet_Validators.h @@ -165,22 +165,6 @@ private: }; -/** -* \ingroup Validators -* A validator which checks that objects selected for feature attributes are different (not the same) -*/ -class PartSet_SketchEntityValidator : public ModelAPI_AttributeValidator -{ - public: - //! Returns true if the attribute is good for the feature attribute - //! \param theAttribute an attribute - //! \param theArguments a list of arguments (names of attributes to check) - //! \param theError an output error string - virtual bool isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const; -}; - /**\class PartSet_CoincidentAttr * \ingroup Validators * \brief Validator to check whether there is a coincident constraint between diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 4e9ccb983..cecf69f4d 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -114,20 +114,6 @@ bool PartSet_WidgetSketchCreator::storeValueCustom() const return true; } -void PartSet_WidgetSketchCreator::activateCustom() -{ - //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 @@ -157,12 +143,6 @@ QIntList PartSet_WidgetSketchCreator::getShapeTypes() const return aShapeTypes; } -void PartSet_WidgetSketchCreator::deactivate() -{ - if (isSelectionMode()) - ModuleBase_WidgetSelector::deactivate(); -} - void PartSet_WidgetSketchCreator::setEditingMode(bool isEditing) { ModuleBase_ModelWidget::setEditingMode(isEditing); @@ -172,24 +152,17 @@ void PartSet_WidgetSketchCreator::setEditingMode(bool isEditing) 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; + return !aHasValueInList; } void PartSet_WidgetSketchCreator::onSelectionChanged() { QList aSelected = getFilteredSelected(); - if (startSketchOperation(aSelected)) { - - } - else {// if (aSelected.size() > 1) { + if (!startSketchOperation(aSelected)) { QList::const_iterator anIt = aSelected.begin(), aLast = aSelected.end(); bool aProcessed = false; for (; anIt != aLast; anIt++) { @@ -201,6 +174,8 @@ void PartSet_WidgetSketchCreator::onSelectionChanged() emit valuesChanged(); updateObject(myFeature); setVisibleSelectionControl(false); + // manually deactivation because the widget was not activated as has no focus acceptin controls + deactivate(); emit focusOutWidget(this); } } @@ -223,10 +198,6 @@ void PartSet_WidgetSketchCreator::setObject(ObjectPtr theSelectedObject, } } } -//void PartSet_WidgetSketchCreator::onStarted() -//{ -// disconnect(myModule, SIGNAL(operationLaunched()), this, SLOT(onStarted())); -//} bool PartSet_WidgetSketchCreator::startSketchOperation(const QList& theValues) { @@ -240,57 +211,33 @@ bool PartSet_WidgetSketchCreator::startSketchOperation(const QList(myModule->workshop()); - XGUI_Workshop* aWorkshop = aConnector->workshop(); - XGUI_Displayer* aDisp = aWorkshop->displayer(); - QObjectPtrList aObjList = aDisp->displayedObjects(); - bool aHasBody = !myUseBody; - ResultBodyPtr aBody; - if(!aHasBody) { - foreach(ObjectPtr aObj, aObjList) { - aBody = std::dynamic_pointer_cast(aObj); - if (aBody.get() != NULL) { - aHasBody = true; - break; - } - } - }*/ - //if (aHasBody) { - // Launch Sketch operation - CompositeFeaturePtr aCompFeature = - std::dynamic_pointer_cast(myFeature); + // manually deactivation because the widget was not activated as has no focus acceptin controls + deactivate(); + + // Launch Sketch operation + CompositeFeaturePtr aCompFeature = + std::dynamic_pointer_cast(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); + myModule->sendOperation(aFOperation); - /// 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); - myModule->sendOperation(aFOperation); - //connect(anOperation, SIGNAL(aborted()), aWorkshop->operationMgr(), SLOT(abortAllOperations())); - //} - /* else { - // Break current operation - std::string anOperationName = feature()->getKind(); - QString aTitle = tr( anOperationName.c_str() ); - QMessageBox::warning(this, aTitle, - tr("There are no bodies found. Operation aborted."), QMessageBox::Ok); - ModuleBase_Operation* aOp = myModule->workshop()->currentOperation(); - aOp->abort(); - }*/ return aSketchStarted; } @@ -299,14 +246,9 @@ bool PartSet_WidgetSketchCreator::focusTo() if (isSelectionMode()) { setVisibleSelectionControl(true); - //CompositeFeaturePtr aCompFeature = - // std::dynamic_pointer_cast(myFeature); - // if (aCompFeature->numberOfSubs() == 0) - // return ModuleBase_ModelWidget::focusTo(); - //connect(myModule, SIGNAL(operationLaunched()), SLOT(onStarted())); // 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() - ModuleBase_WidgetSelector::activateCustom(); + activateCustom(); return true; } else { diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index f6f56f8a2..aa25800bd 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -47,9 +47,6 @@ public: /// \return the state whether the widget can accept the focus virtual bool focusTo(); - /// The methiod called when widget is deactivated - virtual void deactivate(); - /// Editing mode depends on mode of current operation. This value is defined by it. virtual void setEditingMode(bool isEditing); @@ -60,9 +57,6 @@ protected: virtual bool restoreValueCustom(); - /// 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); @@ -90,8 +84,6 @@ protected slots: virtual void onSelectionChanged(); private slots: - //void onStarted(); - void onResumed(ModuleBase_Operation* theOp); private: diff --git a/src/XGUI/XGUI_OperationMgr.cpp b/src/XGUI/XGUI_OperationMgr.cpp index ad8596ab3..d54e6925d 100644 --- a/src/XGUI/XGUI_OperationMgr.cpp +++ b/src/XGUI/XGUI_OperationMgr.cpp @@ -596,8 +596,9 @@ bool XGUI_OperationMgr::onProcessEnter(QObject* theObject) { bool isAccepted = false; ModuleBase_Operation* aOperation = currentOperation(); + // to avoid enter processing when operation has not been started yet if (!aOperation) - return false; + return isAccepted; ModuleBase_IPropertyPanel* aPanel = aOperation->propertyPanel(); // only property panel enter is processed in order to do not process enter in application dialogs bool isPPChild = isChildObject(theObject, aPanel);