From ef735191febeda718b07736db7abdd728a81c17b Mon Sep 17 00:00:00 2001 From: nds Date: Wed, 6 Apr 2016 13:17:46 +0300 Subject: [PATCH] Issue #1343. Improvement of Extrusion and Revolution operations: filling extrusion list by the sub-feature in Widget sketch creator. --- .../FeaturesPlugin_Validators.cpp | 2 +- src/PartSet/PartSet_Module.cpp | 2 +- src/PartSet/PartSet_WidgetSketchCreator.cpp | 298 ++++++++---------- src/PartSet/PartSet_WidgetSketchCreator.h | 21 +- src/XGUI/XGUI_OperationMgr.cpp | 2 +- 5 files changed, 149 insertions(+), 176 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp index 2230d9eb2..9e5a3a3b9 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Validators.cpp @@ -155,7 +155,7 @@ bool FeaturesPlugin_ValidatorBaseForGeneration::isValidAttribute(const Attribute GeomValidators_ShapeType aShapeTypeValidator; if(!aShapeTypeValidator.isValid(anAttr, theArguments, theError)) { theError = "Selected shape has unacceptable type. Acceptable types are: faces or wires on sketch, \ - whole sketch(if it has at least one face), and whole objects with shape types: "; +whole sketch(if it has at least one face), and whole objects with shape types: "; std::list::const_iterator anIt = theArguments.cbegin(); theError += *anIt; for(++anIt; anIt != theArguments.cend(); ++anIt) { diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 079340337..f4984ca05 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -808,7 +808,7 @@ void PartSet_Module::editFeature(FeaturePtr theFeature) bool PartSet_Module::canCommitOperation() const { - return PartSet_WidgetSketchCreator::canCommitCurrentSketch(myWorkshop); + return true; } void PartSet_Module::launchOperation(const QString& theCmdId) diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index 26b748157..cc3f93362 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -48,6 +48,8 @@ #include #include +//#define DEBUG_UNDO_INVALID_SKETCH + PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, PartSet_Module* theModule, const Config_WidgetAPI* theData) @@ -68,6 +70,7 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent, myLabel = new QLabel(aLabelText, this); myLabel->setWordWrap(true); aLayout->addWidget(myLabel); + aLayout->addStretch(1); /*if (!aLabelIcon.isEmpty()) myLabel->setPixmap(QPixmap(aLabelIcon)); @@ -127,7 +130,7 @@ AttributePtr PartSet_WidgetSketchCreator::attribute() const } //******************************************************************** -void PartSet_WidgetSketchCreator::openTransaction() +void PartSet_WidgetSketchCreator::openExtrusionTransaction() { SessionPtr aMgr = ModelAPI_Session::get(); bool aIsOp = aMgr->isOperation(); @@ -233,96 +236,6 @@ void PartSet_WidgetSketchCreator::setEditingMode(bool isEditing) setVisibleSelectionControl(false); } -bool PartSet_WidgetSketchCreator::canCommitCurrentSketch(ModuleBase_IWorkshop* theWorkshop) -{ - bool aCanCommit = true; - ModuleBase_Operation* anOperation = theWorkshop->currentOperation(); - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop); - XGUI_OperationMgr* anOpMgr = aWorkshop->operationMgr(); - // check if the operation is nested - if (anOperation && anOpMgr->operationsCount() > 1) { - ModuleBase_OperationFeature* aFOperation = dynamic_cast(anOperation); - FeaturePtr aCurrentFeature = aFOperation ? aFOperation->feature() : FeaturePtr(); - - ModuleBase_Operation* aPOperation = anOpMgr->previousOperation(anOperation); - ModuleBase_OperationFeature* aFPOperation = dynamic_cast(aPOperation); - FeaturePtr aParentFeature = aFPOperation ? aFPOperation->feature() : FeaturePtr(); - - CompositeFeaturePtr aCompositeFeature = - std::dynamic_pointer_cast(aCurrentFeature); - CompositeFeaturePtr aPCompositeFeature = - std::dynamic_pointer_cast(aParentFeature); - // check if both features are composite: extrusion and sketch - if (aCompositeFeature.get() && aPCompositeFeature.get()) { - // selection attribute list is currently filled in execute(), so we need to call it - // if there is no opened transaction, it should be started and finished - SessionPtr aMgr = ModelAPI_Session::get(); - bool aIsOp = aMgr->isOperation(); - if (!aIsOp) - aMgr->startOperation(); - - 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(); - std::string aValidatorID, anError; - bool isValidPComposite = aFactory->validate(aFirstAttribute, aValidatorID, anError); - if (!isValidPComposite) { - int anAnswer = QMessageBox::question( - aWorkshop->desktop(), tr("Apply current feature"), - tr("The current feature can not be used as an argument of the parent feature.\n\ - After apply it will be deleted. Would you like to continue?"), - QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel); - if (anAnswer == QMessageBox::Ok) - aCanCommit = true; - else - aCanCommit = false; - } - } - if (!aIsOp) { - if (aCanCommit) - aMgr->finishOperation(); - else - aMgr->abortOperation(); - } - } - } - 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); @@ -416,18 +329,16 @@ bool PartSet_WidgetSketchCreator::startSketchOperation(const QList