+bool ModuleBase_ModelWidget::isValueEnabled() const
+{
+ bool anEnabled = true;
+ if (myIsValueEnabled == DefinedInPreferences) {
+#ifdef DEBUG_ENABLE_SKETCH_INPUT_FIELDS
+ bool aCanDisable = false;
+#else
+ //Config_PropManager::boolean(SKETCH_TAB_NAME, "disable_input_fields", "true");
+ bool aCanDisable = true;
+#endif
+ if (aCanDisable)
+ anEnabled = false;
+ }
+ else if (myIsValueEnabled == Off)
+ anEnabled = false;
+ return anEnabled;
+}
+
+void ModuleBase_ModelWidget::processValueState()
+{
+ if (myState == ModifiedInPP || myState == ModifiedInViewer)
+ storeValue();
+}
+
+Events_InfoMessage ModuleBase_ModelWidget::getValueStateError() const
+{
+ Events_InfoMessage aMessage;
+
+ ModuleBase_ModelWidget::ValueState aState = getValueState();
+ if (aState != ModuleBase_ModelWidget::Stored) {
+ AttributePtr anAttr = feature()->attribute(attributeID());
+ if (anAttr.get()) {
+ const std::string& anAttributeName = anAttr->id();
+ switch (aState) {
+ case ModuleBase_ModelWidget::ModifiedInViewer:
+ aMessage = "Attribute \"%1\" is locked by modification value in the viewer.";
+ aMessage.addParameter(anAttributeName);
+ break;
+ case ModuleBase_ModelWidget::Reset:
+ aMessage = "Attribute \"%1\" is not initialized.";
+ aMessage.addParameter(anAttributeName);
+ break;
+ case ModuleBase_ModelWidget::ModifiedInPP: // Apply should be enabled in this mode
+ default:
+ break;
+ }
+ }
+ }
+ return aMessage;
+}
+
+QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const
+{
+ QString anError;
+
+ if (!feature().get())
+ return anError;
+
+ std::string aFeatureID = feature()->getKind();
+ std::string anAttributeID = attributeID();
+ AttributePtr anAttribute = feature()->attribute(anAttributeID);
+ if (!anAttribute.get())
+ return anError;
+
+ std::string aValidatorID;
+ Events_InfoMessage anErrorMsg;
+
+ static ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+ if (!aValidators->validate(anAttribute, aValidatorID, anErrorMsg)) {
+ if (anErrorMsg.empty())
+ anErrorMsg = "Unknown error.";
+
+ if (anErrorMsg.context().empty()) {
+ anErrorMsg.setContext(aFeatureID + ":" + anAttributeID + ":" + aValidatorID);
+ }
+ }
+
+ if (anErrorMsg.empty() && theValueStateChecked) {
+ anErrorMsg = getValueStateError();
+ }
+
+ if (!anErrorMsg.empty()) {
+ anError = ModuleBase_Tools::translate(anErrorMsg);
+ }
+
+ return anError;
+}
+