From: vsv Date: Tue, 1 Jul 2014 15:16:48 +0000 (+0400) Subject: Accessibility of constraint operations under editing of sketch elements X-Git-Tag: V_0.4.4~211^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=11496be069750941ff9cbcef21088a56bfd32cdf;p=modules%2Fshaper.git Accessibility of constraint operations under editing of sketch elements --- diff --git a/src/ModuleBase/ModuleBase_IOperation.cpp b/src/ModuleBase/ModuleBase_IOperation.cpp index bcc697dcb..cc398e5b0 100644 --- a/src/ModuleBase/ModuleBase_IOperation.cpp +++ b/src/ModuleBase/ModuleBase_IOperation.cpp @@ -17,7 +17,7 @@ #endif ModuleBase_IOperation::ModuleBase_IOperation(const QString& theId, QObject* theParent) - : QObject(theParent) + : QObject(theParent), myIsEditing(false), myIsModified(false) { myDescription = new ModuleBase_OperationDescription(theId); } diff --git a/src/ModuleBase/ModuleBase_IOperation.h b/src/ModuleBase/ModuleBase_IOperation.h index 77e01083c..0d304c0a2 100644 --- a/src/ModuleBase/ModuleBase_IOperation.h +++ b/src/ModuleBase/ModuleBase_IOperation.h @@ -76,6 +76,12 @@ public: //void setModelWidgets(const std::string& theXmlRepresentation, // QList theWidgets); + /// Returns True if data of its feature was modified during operation + virtual bool isModified() const { return myIsModified; } + + /// Returns True id the current operation is launched in editing mode + bool isEditOperation() const { return myIsEditing; } + signals: void started(); /// the operation is started void aborted(); /// the operation is aborted @@ -134,6 +140,12 @@ protected: /// Returns pointer to the root document. boost::shared_ptr document() const; + /// Editing feature flag + bool myIsEditing; + + /// Modified feature flag + bool myIsModified; + private: ModuleBase_OperationDescription* myDescription; /// the container to have the operation description }; diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index f94c918dd..c1ed4b0d0 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -24,7 +24,7 @@ #endif ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent) -: ModuleBase_IOperation(theId, theParent), myIsEditing(false) +: ModuleBase_IOperation(theId, theParent) { } @@ -106,6 +106,7 @@ FeaturePtr ModuleBase_Operation::createFeature(const bool theFlushMessage) boost::shared_ptr aDoc = document(); FeaturePtr aFeature = aDoc->addFeature(getDescription()->operationId().toStdString()); if (aFeature) { // TODO: generate an error if feature was not created + myIsModified = true; aFeature->execute(); // Init default values /*QList aWidgets = getDescription()->modelWidgets(); diff --git a/src/ModuleBase/ModuleBase_Operation.h b/src/ModuleBase/ModuleBase_Operation.h index a40d774e4..6a95f0085 100644 --- a/src/ModuleBase/ModuleBase_Operation.h +++ b/src/ModuleBase/ModuleBase_Operation.h @@ -72,8 +72,6 @@ public: /// Sets the operation feature void setEditingFeature(FeaturePtr theFeature); - bool isEditOperation() const { return myIsEditing; } - public slots: /// Slots which listen the mode widget activation /// \param theWidget the model widget @@ -113,8 +111,6 @@ private: private: FeaturePtr myFeature; /// the operation feature to be handled - - bool myIsEditing; }; #endif diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index dbbe9fd5d..1e00eb180 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -48,6 +48,7 @@ double editedValue(double theValue, bool& isDone) aLay->setContentsMargins(0,0,0,0); QLineEdit* aEditor = new QLineEdit(QString::number(theValue), &aDlg); + aEditor->setValidator(new QDoubleValidator(aEditor)); QObject::connect(aEditor, SIGNAL(returnPressed()), &aDlg, SLOT(accept())); aLay->addWidget(aEditor); diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index 50c0de49d..dd788f540 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -524,6 +524,20 @@ void PartSet_Module::onStorePoint2D(FeaturePtr theFeature, const std::string& th bool PartSet_Module::isFeatureEnabled(const QString& theCmdId) const { - //qDebug("### isFeatureEnabled %s", qPrintable(theCmdId)); - return true; + XGUI_OperationMgr* aOpMgr = myWorkshop->operationMgr(); + XGUI_ActionsMgr* aActMgr = myWorkshop->actionsMgr(); + + ModuleBase_Operation* aOperation = aOpMgr->currentOperation(); + if (!aOperation) + return !aActMgr->isNested(theCmdId); + + PartSet_OperationFeatureEdit* aSketchEdtOp = dynamic_cast(aOperation); + if (aSketchEdtOp) { + QStringList aConstraintList; + aConstraintList<<"SketchConstraintDistance"<<"SketchConstraintLength" + <<"SketchConstraintRadius"<<"SketchConstraintParallel"<<"SketchConstraintPerpendicular"; + return aConstraintList.contains(theCmdId); + } + QStringList aList = aActMgr->nestedCommands(aOperation->id()); + return aList.contains(theCmdId); } diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index 096f56f40..a1652fc48 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -286,6 +286,6 @@ bool PartSet_OperationFeatureCreate::setWidgetValue(FeaturePtr theFeature, doubl bool isApplyed = myActiveWidget->setValue(aValue); delete aValue; - + myIsModified = (myIsModified || isApplyed); return isApplyed; } diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index 117195468..dd6639321 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -11,6 +11,8 @@ #include #include +#include +#include #ifdef _DEBUG #include @@ -89,7 +91,15 @@ void PartSet_OperationSketchBase::keyReleased(const int theKey) { switch (theKey) { case Qt::Key_Escape: { - abort(); + bool toAbort = true; + if (isModified()) { + int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Cancel operation"), + tr("Operation %1 will be cancelled. Continue?").arg(id()), + QMessageBox::Yes, QMessageBox::No); + toAbort = (anAnswer == QMessageBox::Yes); + } + if (toAbort) + abort(); } break; default: diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 6c320ee71..365fb02c3 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -21,6 +21,9 @@ + + +