Improvement: modification of the value in the property panel should make enabled the Apply button in the panel. The value is not applyed to the model yet, but click on Apply leads to the values apply. The button becomes disabled if the result is invalid feature.
return theResult->shape();
}
+std::string getFeatureError(const FeaturePtr& theFeature)
+{
+ std::string anError;
+ if (!theFeature.get() || !theFeature->data()->isValid() || theFeature->isAction())
+ return anError;
+
+ // to be removed later, this error should be got from the feature
+ if (theFeature->data()->execState() == ModelAPI_StateDone ||
+ theFeature->data()->execState() == ModelAPI_StateMustBeUpdated)
+ return anError;
+
+ // set error indication
+ anError = theFeature->error();
+ if (anError.empty()) {
+ bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone
+ || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
+ if (!isDone)
+ anError = theFeature->data()->execState();
+ }
+
+ return anError;
+}
+
ObjectPtr objectByName(const DocumentPtr& theDocument, const std::string& theGroup, const std::string& theName)
{
for (int anIndex = 0; anIndex < theDocument->size(theGroup); ++anIndex) {
/// Returns shape from the given Result object
MODELAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape(const ResultPtr& theResult);
+/*! Returns the feature error generated according to feature error and exec state
+ * \param theFeature a feature
+ * \return error value or empty string
+ */
+MODELAPI_EXPORT std::string getFeatureError(const FeaturePtr& theFeature);
+
/*!
* Searches for variable with name \param theName in \param theDocument.
* If found, set it value in the \param outValue and returns true.
#include "ModuleBase_ISelection.h"
#include "ModuleBase_OperationDescription.h"
#include "ModuleBase_OperationFeature.h"
-#include <ModuleBase_ModelWidget.h>
+#include "ModuleBase_ModelWidget.h"
#include <Events_Loop.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_CompositeFeature.h>
#include <ModelAPI_Session.h>
+#include "ModelAPI_Tools.h"
#include <Config_PointerMessage.h>
#include <Config_WidgetReader.h>
QString ModuleBase_IModule::getFeatureError(const FeaturePtr& theFeature)
{
- QString anError;
- if (!theFeature.get() || !theFeature->data()->isValid() || theFeature->isAction())
- return anError;
-
- // to be removed later, this error should be got from the feature
- if (theFeature->data()->execState() == ModelAPI_StateDone ||
- theFeature->data()->execState() == ModelAPI_StateMustBeUpdated)
- return anError;
-
- // set error indication
- anError = QString::fromStdString(theFeature->error());
- if (anError.isEmpty()) {
- bool isDone = ( theFeature->data()->execState() == ModelAPI_StateDone
- || theFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
- if (!isDone)
- anError = toString(theFeature->data()->execState());
- }
-
- return anError;
+ return ModelAPI_Tools::getFeatureError(theFeature).c_str();
}
QString ModuleBase_IModule::getWidgetError(ModuleBase_ModelWidget* theWidget)
if (anAttr.get()) {
QString anAttributeName = anAttr->id().c_str();
switch (aState) {
- case ModuleBase_ModelWidget::ModifiedInPP:
- anError = "Attribute \"" + anAttributeName +
- "\" modification is not applyed. Please click \"Enter\" or \"Tab\".";
- break;
case ModuleBase_ModelWidget::ModifiedInViewer:
anError = "Attribute \"" + anAttributeName +
"\" is locked by modification value in the viewer.";
case ModuleBase_ModelWidget::Reset:
anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
break;
+ case ModuleBase_ModelWidget::ModifiedInPP: // Apply should be enabled in this mode
+ default:
+ break;
}
}
}
#include <memory>
+class ModuleBase_OperationFeature;
class Config_WidgetAPI;
class ModuleBase_IWorkshop;
class QKeyEvent;
bool myUseReset;
/// blocked flag of modification of the value state
bool myIsValueStateBlocked;
+
+ friend ModuleBase_OperationFeature; // to call storeValue() by commit if value state is ModifiedInPP
};
#endif
return true; // rename operation
if (myFeature->isAction())
return true;
- //Get validators for the Id
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- bool aValid = aFactory->validate(myFeature);
-
- // the feature exec state should be checked in order to do not apply features, which result can not
- // be built. E.g. extrusion on sketch, where the "to" is a perpendicular plane to the sketch
- bool isDone = ( myFeature->data()->execState() == ModelAPI_StateDone
- || myFeature->data()->execState() == ModelAPI_StateMustBeUpdated );
- return aValid && isDone;
+ std::string anError = ModelAPI_Tools::getFeatureError(myFeature);
+ return anError.empty();
}
void ModuleBase_OperationFeature::startOperation()
bool ModuleBase_OperationFeature::commit()
{
+ ModuleBase_IPropertyPanel* aPanel = propertyPanel();
+ if (aPanel) {
+ ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
+ if (anActiveWidget && anActiveWidget->getValueState() == ModuleBase_ModelWidget::ModifiedInPP) {
+ anActiveWidget->storeValue();
+ }
+ }
if (canBeCommitted()) {
emit beforeCommitted();
// the widgets of property panel should not process any events come from data mode
(workshop()->operationMgr()->currentOperation());
if (aFOperation && aFOperation->feature() == theFeature) {
QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
- QString anError = myWorkshop->module()->getFeatureError(theFeature);
-
+
ModuleBase_ModelWidget* anActiveWidget = activeWidget();
- QString aWidgetError = myWorkshop->module()->getWidgetError(anActiveWidget);
- if (anError.isEmpty())
- anError = aWidgetError;
-
+ bool isApplyEnabledByActiveWidget = false;
+ if (anActiveWidget)
+ isApplyEnabledByActiveWidget = anActiveWidget->getValueState() ==
+ ModuleBase_ModelWidget::ModifiedInPP;
+ QString anError = "";
+ QString aWidgetError = "";
+ if (!isApplyEnabledByActiveWidget) {
+ anError = myWorkshop->module()->getFeatureError(theFeature);
+ aWidgetError = myWorkshop->module()->getWidgetError(anActiveWidget);
+ if (anError.isEmpty())
+ anError = aWidgetError;
+ }
updateActionState(anOkAction, anError);
updateToolTip(anActiveWidget, aWidgetError);
}
}
}
+bool XGUI_ErrorMgr::isApplyEnabled() const
+{
+ bool isEnabled = false;
+ XGUI_ActionsMgr* anActionsMgr = workshop()->actionsMgr();
+ ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
+ (workshop()->operationMgr()->currentOperation());
+ if (aFOperation) {
+ QAction* anOkAction = anActionsMgr->operationStateAction(XGUI_ActionsMgr::Accept);
+ isEnabled = anOkAction && anOkAction->isEnabled();
+ }
+ return isEnabled;
+}
+
void XGUI_ErrorMgr::updateActionState(QAction* theAction, const QString& theError)
{
bool anEnabled = theError.isEmpty();
/// \param theFeature a feature
void updateAcceptAllAction(const FeaturePtr& theFeature);
+ /// Returns true if the apply is enabled for the current feature
+ bool isApplyEnabled() const;
+
protected slots:
/// Reimplemented from ModuleBase_ErrorMgr::onWidgetChanged().
virtual void onWidgetChanged();
XGUI_OperationMgr::XGUI_OperationMgr(QObject* theParent,
ModuleBase_IWorkshop* theWorkshop)
-: QObject(theParent), myIsApplyEnabled(false), myWorkshop(theWorkshop)
+: QObject(theParent), myWorkshop(theWorkshop)
{
}
bool isCompositeCommitted = false;
while (hasOperation()) {
ModuleBase_Operation* anOperation = currentOperation();
- if (isApplyEnabled()) {
+ if (workshop()->errorMgr()->isApplyEnabled()) {
onCommitOperation();
} else {
abortOperation(anOperation);
return;
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
(currentOperation());
- if(aFOperation && aFOperation->feature().get()) {
- QString anError = myWorkshop->module()->getFeatureError(aFOperation->feature());
- if (anError.isEmpty()) {
- ModuleBase_IPropertyPanel* aPanel = aFOperation->propertyPanel();
- if (aPanel) {
- ModuleBase_ModelWidget* anActiveWidget = aPanel->activeWidget();
- if (anActiveWidget)
- anError = myWorkshop->module()->getWidgetError(anActiveWidget);
- }
- }
- setApplyEnabled(anError.isEmpty());
- }
-}
-
-void XGUI_OperationMgr::setApplyEnabled(const bool theEnabled)
-{
- myIsApplyEnabled = theEnabled;
- ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>
- (currentOperation());
- if (aFOperation) {
+ if(aFOperation && aFOperation->feature().get())
workshop()->errorMgr()->updateActions(aFOperation->feature());
- }
}
void XGUI_OperationMgr::updateApplyOfOperations(ModuleBase_Operation* theOperation)
ModuleBase_OperationFeature* aFOperation = dynamic_cast<ModuleBase_OperationFeature*>(theOperation);
if (aFOperation)
anErrorMgr->updateAcceptAllAction(aFOperation->feature());
- //emit nestedStateChanged(theOperation->getDescription()->operationId().toStdString(),
- // theOperation->isValid());
}
else {
foreach(ModuleBase_Operation* anOperation, myOperations) {
if (anOperation)
updateApplyOfOperations(anOperation);
- //emit nestedStateChanged(anOperation->getDescription()->operationId().toStdString(),
- // anOperation->isValid());
- }
- }
-}
-
-bool XGUI_OperationMgr::isApplyEnabled() const
-{
- return myIsApplyEnabled;
-}
-
-bool XGUI_OperationMgr::isParentOperationValid() const
-{
- bool isValid = false;
- // the enable state of the parent operation of the nested one is defined by the rules that
- // firstly there are nested operations and secondly the parent operation is valid
- ModuleBase_Operation* aPrevOp = 0;
- Operations::const_iterator anIt = myOperations.end();
- if (anIt != myOperations.begin()) { // there are items in the operations list
- --anIt;
- aPrevOp = *anIt; // the last top operation, the operation which is started
- if (anIt != myOperations.begin()) { // find the operation where the started operation is nested
- --anIt;
- aPrevOp = *anIt;
}
}
- return aPrevOp && aPrevOp->isValid();
}
bool XGUI_OperationMgr::canStopOperation(ModuleBase_Operation* theOperation)
else if (canStopOperation(aCurrentOp)) {
// the started operation is granted in the parrent operation,
// e.g. current - Line in Sketch, started Circle
- if (myIsApplyEnabled && aCurrentOp->isModified())
+ if (workshop()->errorMgr()->isApplyEnabled() && aCurrentOp->isModified())
aCurrentOp->commit();
else
abortOperation(aCurrentOp);
/// \param theOperation an aborted operation
void abortOperation(ModuleBase_Operation* theOperation);
- /// Returns enable apply state
- /// \return theEnabled a boolean value
- bool isApplyEnabled() const;
-
- /// Returns valid state of the parent operation. If the current operation is the last one
- /// it returns the valid state of the operation
- /// \return boolean value
- bool isParentOperationValid() const;
-
public slots:
/// Slot that commits the current operation.
void onCommitOperation();
/// Signal is emitted after the key released click.
void keyEnterReleased();
- protected:
- /// Sets apply state to the value and emit signal about this state is changed
- /// \param theEnabled the state value
- void setApplyEnabled(const bool theEnabled);
-
public: // TEMPORARY, it should be protected and be performed automatically
/// Emits nestedStateChange for operations with an information about validity of the operation
/// \param theOperation the sent operation. If it is NULL, all operations in the stack are sent.
/// Current workshop
ModuleBase_IWorkshop* myWorkshop;
-
- /// Lock/Unlock access to Ok button in property panel
- bool myIsApplyEnabled;
};
#endif
myUpdatePrefs(false)
{
XGUI_OperationMgr* anOperationMgr = workshop()->operationMgr();
- //connect(anOperationMgr, SIGNAL(nestedStateChanged(const std::string&, const bool)),
- // this, SLOT(onNestedStateChanged(const std::string&, const bool)));
}
//******************************************************
//}
}
-/*void XGUI_WorkshopListener::onNestedStateChanged(const std::string& theFeatureId, const bool theState)
-{
- XGUI_Workshop* aWorkshop = workshop();
-
- //one button is used for all features, which can have nested actions, so it is obtained from
- // the action manager
- //bool aActionToBeUpdated = aWorkshop->isFeatureOfNested(theFeatureId);
- if (aWorkshop->isSalomeMode()) {
- XGUI_SalomeConnector* aSalomeConnector = aWorkshop->salomeConnector();
- XGUI_ActionsMgr* anActionsMgr = aWorkshop->actionsMgr();
- if (aSalomeConnector->isFeatureOfNested(anActionsMgr->action(theFeatureId.c_str())))
- aActionToBeUpdated = true;
- } else {
- AppElements_MainMenu* aMenuBar = aWorkshop->mainWindow()->menuObject();
- AppElements_Command* aCommand = aMenuBar->feature(theFeatureId.c_str());
- if (aCommand && aCommand->button()->additionalButtonWidget())
- aActionToBeUpdated = true;
- }
- if (aActionToBeUpdated) {
- QAction* anAcceptAllAction = aWorkshop->actionsMgr()->operationStateAction(XGUI_ActionsMgr::AcceptAll, NULL);
- anAcceptAllAction->setEnabled(theState);
- }
-}*/
-
bool XGUI_WorkshopListener::event(QEvent * theEvent)
{
PostponeMessageQtEvent* aPostponedEv = dynamic_cast<PostponeMessageQtEvent*>(theEvent);