#endif
ModuleBase_IOperation::ModuleBase_IOperation(const QString& theId, QObject* theParent)
- : QObject(theParent)
+ : QObject(theParent), myIsEditing(false), myIsModified(false)
{
myDescription = new ModuleBase_OperationDescription(theId);
}
//void setModelWidgets(const std::string& theXmlRepresentation,
// QList<ModuleBase_ModelWidget*> 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
/// Returns pointer to the root document.
boost::shared_ptr<ModelAPI_Document> document() const;
+ /// Editing feature flag
+ bool myIsEditing;
+
+ /// Modified feature flag
+ bool myIsModified;
+
private:
ModuleBase_OperationDescription* myDescription; /// the container to have the operation description
};
#endif
ModuleBase_Operation::ModuleBase_Operation(const QString& theId, QObject* theParent)
-: ModuleBase_IOperation(theId, theParent), myIsEditing(false)
+: ModuleBase_IOperation(theId, theParent)
{
}
boost::shared_ptr<ModelAPI_Document> 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<ModuleBase_ModelWidget*> aWidgets = getDescription()->modelWidgets();
/// 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
private:
FeaturePtr myFeature; /// the operation feature to be handled
-
- bool myIsEditing;
};
#endif
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);
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<PartSet_OperationFeatureEdit*>(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);
}
bool isApplyed = myActiveWidget->setValue(aValue);
delete aValue;
-
+ myIsModified = (myIsModified || isApplyed);
return isApplyed;
}
#include <AIS_DimensionSelectionMode.hxx>
#include <QKeyEvent>
+#include <QMessageBox>
+#include <QApplication>
#ifdef _DEBUG
#include <QDebug>
{
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:
<point_selector id="ArcStartPoint" title="Start point" tooltip="Start point of the arc"/>
<point_selector id="ArcEndPoint" title="End point" tooltip="End point of the arc"/>
</feature>
+ </group>
+
+ <group id="Constraints">
<feature id="SketchConstraintCoincidence" title="Coincident" tooltip="Create constraint for the coincidence of two points" internal="1"/>
<feature id="SketchConstraintDistance" title="Distance" tooltip="Create constraint for the distance from a point to an object">
<label title="Select point and another feature (point or point on line) between which to calculate distance" tooltip="Select point and another feature (point or point on line) between which to calculate distance"/>
setActionChecked(eachCommand, true);
}
}
+
+QStringList XGUI_ActionsMgr::nestedCommands(const QString& theId) const
+{
+ if (myNestedActions.contains(theId))
+ return myNestedActions[theId];
+ return QStringList();
+}
+
+bool XGUI_ActionsMgr::isNested(const QString& theId) const
+{
+ foreach(QString aId, myNestedActions.keys()) {
+ QStringList aList = myNestedActions[aId];
+ if (aList.contains(theId))
+ return true;
+ }
+ return false;
+}
\ No newline at end of file
//! Sets relation between the command (with given Id) and it's nested actions.
void addNestedCommands(const QString& theId, const QStringList& theCommands);
+ QStringList nestedCommands(const QString& theId) const;
+
+ bool isNested(const QString& theId) const;
+
public slots:
//! Update workbench actions according to OperationMgr state:
//! No active operations: all actions but nested are available
bool XGUI_OperationMgr::canStopOperation()
{
- int anAnswer = QMessageBox::question(0, tr("Operation launch"),
- tr("Previous operation is not finished and will be aborted"),
- QMessageBox::Ok, QMessageBox::Cancel);
- return anAnswer == QMessageBox::Ok;
+ ModuleBase_Operation* anOperation = currentOperation();
+ if (anOperation) {
+ if (anOperation->isModified()) {
+ int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Operation launch"),
+ tr("Previous operation is not finished and will be aborted"),
+ QMessageBox::Ok, QMessageBox::Cancel);
+ return anAnswer == QMessageBox::Ok;
+ }
+ }
+ return true;
}
void XGUI_OperationMgr::onCommitOperation()
void XGUI_OperationMgr::onAbortOperation()
{
ModuleBase_Operation* anOperation = currentOperation();
- if (anOperation)
+ if (anOperation && canAbortOperation())
anOperation->abort();
}
+bool XGUI_OperationMgr::canAbortOperation()
+{
+ ModuleBase_Operation* anOperation = currentOperation();
+ if (anOperation && anOperation->isModified()) {
+ int anAnswer = QMessageBox::question(qApp->activeWindow(), tr("Cancel operation"),
+ tr("Operation %1 will be cancelled. Continue?").arg(anOperation->id()),
+ QMessageBox::Yes, QMessageBox::No);
+ return anAnswer == QMessageBox::Yes;
+ }
+ return true;
+}
+
void XGUI_OperationMgr::onOperationStopped()
{
ModuleBase_Operation* aSenderOperation = dynamic_cast<ModuleBase_Operation*>(sender());
/// Returns whether the operation can be stopped.
bool canStopOperation();
+ /// Returns true if the operation can be aborted
+ bool canAbortOperation();
+
protected slots:
/// Slot that commits the current operation.
void onCommitOperation();