From dd31f5aedab7f3bb833b97fae5f82b32a92f927c Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 5 Apr 2016 17:42:59 +0300 Subject: [PATCH] Issue #1343. Improvement of Extrusion and Revolution operations: setSketchObjectToList is perfomed on the GUI level. Reason: if execute is started before, there is a crash if sketch contains only one not-closed contour. --- .../FeaturesPlugin_CompositeSketch.cpp | 30 ---------- .../FeaturesPlugin_CompositeSketch.h | 3 - .../FeaturesPlugin_Extrusion.cpp | 3 - .../FeaturesPlugin_Revolution.cpp | 3 - .../GeomValidators_ShapeType.cpp | 0 src/PartSet/PartSet_WidgetSketchCreator.cpp | 59 ++++++++++++++----- src/PartSet/PartSet_WidgetSketchCreator.h | 7 +++ 7 files changed, 52 insertions(+), 53 deletions(-) mode change 100644 => 100755 src/GeomValidators/GeomValidators_ShapeType.cpp diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp index 17f3158dd..b8bd1ee23 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp @@ -117,36 +117,6 @@ void FeaturesPlugin_CompositeSketch::erase() ModelAPI_CompositeFeature::erase(); } -//================================================================================================= -void FeaturesPlugin_CompositeSketch::setSketchObjectToList() -{ - AttributeSelectionListPtr aBaseObjectsSelectionList = selectionList(BASE_OBJECTS_ID()); - if(!aBaseObjectsSelectionList.get() || aBaseObjectsSelectionList->isInitialized()) { - return; - } - - AttributeReferencePtr aSketchLauncherRef = reference(SKETCH_ID()); - if(!aSketchLauncherRef.get() || !aSketchLauncherRef->isInitialized()) { - return; - } - - FeaturePtr aSketchFeature = std::dynamic_pointer_cast(aSketchLauncherRef->value()); - - if(!aSketchFeature.get() || aSketchFeature->results().empty()) { - return; - } - - ResultPtr aSketchRes = aSketchFeature->results().front(); - ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSketchRes); - if(!aConstruction.get()) { - return; - } - - if(aBaseObjectsSelectionList->size() == 0) { - aBaseObjectsSelectionList->append(aSketchRes, GeomShapePtr()); - } -} - //================================================================================================= void FeaturesPlugin_CompositeSketch::getBaseShapes(ListOfShape& theBaseShapesList, const bool theIsMakeShells) diff --git a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h index d2c7be54e..f83fe924b 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h +++ b/src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.h @@ -66,9 +66,6 @@ protected: /// Initializes composite sketch attributes. void initCompositeSketchAttribtues(const int theInitFlags); - /// Sets the sub-object to list of base. - void setSketchObjectToList(); - /// \brief Returns list of base shapes. /// \param[out] theBaseShapesList list of base shapes (warning: list not cleared). /// \param[in] theIsMakeShells if true make shells from faces with shared edges. diff --git a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp index 16333c306..225e3cf48 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Extrusion.cpp @@ -76,9 +76,6 @@ bool FeaturesPlugin_Extrusion::makeExtrusions(ListOfShape& theBaseShapes, { theMakeShapes.clear(); - /// Sub-feature of the composite should be set in the base list. - setSketchObjectToList(); - // Getting base shapes. getBaseShapes(theBaseShapes); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp index ae67aa67a..12e053e32 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Revolution.cpp @@ -74,9 +74,6 @@ bool FeaturesPlugin_Revolution::makeRevolutions(ListOfShape& theBaseShapes, { theMakeShapes.clear(); - /// Sub-feature of the composite should be set in the base list. - setSketchObjectToList(); - // Getting base shapes. getBaseShapes(theBaseShapes); diff --git a/src/GeomValidators/GeomValidators_ShapeType.cpp b/src/GeomValidators/GeomValidators_ShapeType.cpp old mode 100644 new mode 100755 diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 48de5bdbd..26b748157 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -125,6 +126,17 @@ AttributePtr PartSet_WidgetSketchCreator::attribute() const return anAttribute; } +//******************************************************************** +void PartSet_WidgetSketchCreator::openTransaction() +{ + SessionPtr aMgr = ModelAPI_Session::get(); + bool aIsOp = aMgr->isOperation(); + if (!aIsOp) { + const static std::string aNestedOpID("Parameters modification"); + aMgr->startOperation(aNestedOpID, true); + } +} + //******************************************************************** bool PartSet_WidgetSketchCreator::isValidSelection(const ModuleBase_ViewerPrs& theValue) { @@ -248,12 +260,13 @@ bool PartSet_WidgetSketchCreator::canCommitCurrentSketch(ModuleBase_IWorkshop* t bool aIsOp = aMgr->isOperation(); if (!aIsOp) aMgr->startOperation(); - aPCompositeFeature->execute(); // to fill attribute selection list std::list aSelListAttributes = aParentFeature->data()->attributes( ModelAPI_AttributeSelectionList::typeId()); if (aSelListAttributes.size() == 1) { AttributePtr aFirstAttribute = aSelListAttributes.front(); + /// Sub-feature of the composite should be set in the base list. + setSketchObjectToList(aPCompositeFeature, aFirstAttribute); SessionPtr aMgr = ModelAPI_Session::get(); ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); @@ -282,6 +295,34 @@ bool PartSet_WidgetSketchCreator::canCommitCurrentSketch(ModuleBase_IWorkshop* t return aCanCommit; } +void PartSet_WidgetSketchCreator::setSketchObjectToList(const CompositeFeaturePtr& theCompositeFeature, + const AttributePtr& theAttribute) +{ + if (!theCompositeFeature.get() || theCompositeFeature->numberOfSubs() != 1) + return; + + AttributeSelectionListPtr aBaseObjectsSelectionList = + std::dynamic_pointer_cast(theAttribute); + if(!aBaseObjectsSelectionList.get() || aBaseObjectsSelectionList->isInitialized()) { + return; + } + + FeaturePtr aSketchFeature = theCompositeFeature->subFeature(0); + if(!aSketchFeature.get() || aSketchFeature->results().empty()) { + return; + } + + ResultPtr aSketchRes = aSketchFeature->results().front(); + ResultConstructionPtr aConstruction = std::dynamic_pointer_cast(aSketchRes); + if(!aConstruction.get()) { + return; + } + + if(aBaseObjectsSelectionList->size() == 0) { + aBaseObjectsSelectionList->append(aSketchRes, GeomShapePtr()); + } +} + bool PartSet_WidgetSketchCreator::isSelectionMode() const { AttributeSelectionListPtr anAttrList = myFeature->data()->selectionList(myAttributeListID); @@ -377,24 +418,14 @@ bool PartSet_WidgetSketchCreator::focusTo() { if (isSelectionMode()) { activateSelectionControl(); - - SessionPtr aMgr = ModelAPI_Session::get(); - bool aIsOp = aMgr->isOperation(); - if (!aIsOp) - aMgr->startOperation(myFeature->getKind()); + // Open transaction that is general for the previous nested one: it will be closed on nested commit + openTransaction(); return true; } else { - //setVisibleSelectionControl(false); - 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); - } + openTransaction(); restoreValue(); } return false; diff --git a/src/PartSet/PartSet_WidgetSketchCreator.h b/src/PartSet/PartSet_WidgetSketchCreator.h index a53166444..1c24c1254 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.h +++ b/src/PartSet/PartSet_WidgetSketchCreator.h @@ -76,7 +76,14 @@ public: /// \return boolean value static bool canCommitCurrentSketch(ModuleBase_IWorkshop* theWorkshop); + /// Sets the sub-object to list of base. + static void setSketchObjectToList(const CompositeFeaturePtr& theFeature, + const AttributePtr& theAttribute); + protected: + /// If there is no operation in current session, start operation for modify parameters + void openTransaction(); + /// Checks whether the selection presentation contains preview planes /// \param theValue a selection information /// \return a boolean value -- 2.39.2