+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();
+}
+
+QString ModuleBase_ModelWidget::getValueStateError() const
+{
+ QString anError = "";
+
+ ModuleBase_ModelWidget::ValueState aState = getValueState();
+ if (aState != ModuleBase_ModelWidget::Stored) {
+ AttributePtr anAttr = feature()->attribute(attributeID());
+ if (anAttr.get()) {
+ QString anAttributeName = anAttr->id().c_str();
+ switch (aState) {
+ case ModuleBase_ModelWidget::ModifiedInViewer:
+ anError = "Attribute \"" + anAttributeName +
+ "\" is locked by modification value in the viewer.";
+ break;
+ case ModuleBase_ModelWidget::Reset:
+ anError = "Attribute \"" + anAttributeName + "\" is not initialized.";
+ break;
+ case ModuleBase_ModelWidget::ModifiedInPP: // Apply should be enabled in this mode
+ default:
+ break;
+ }
+ }
+ }
+ return anError;
+}
+
+QString ModuleBase_ModelWidget::getError(const bool theValueStateChecked) const
+{
+ QString anError;
+
+ if (!feature().get())
+ return anError;
+
+ 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.";
+ anErrorMsg = anAttributeID + " - " + aValidatorID + ": " + anErrorMsg.messageString();
+ }
+
+ if (!anErrorMsg.empty()) {
+ std::string aStr = Config_Translator::translate(anErrorMsg);
+ std::string aCodec = Config_Translator::codec(anErrorMsg.context());
+ anError = QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
+ }
+
+ if (anError.isEmpty() && theValueStateChecked)
+ anError = getValueStateError();
+
+ anError = translateString(anError);
+ return anError;
+}
+
+
+QString ModuleBase_ModelWidget::translateString(const QString& theMsg) const
+{
+ if (!theMsg.isEmpty()) {
+ std::string aContext = feature()->getKind();
+ std::string aStr = Config_Translator::translate(aContext, theMsg.toStdString().c_str());
+ std::string aCodec = Config_Translator::codec(aContext);
+ return QTextCodec::codecForName(aCodec.c_str())->toUnicode(aStr.c_str());
+ }
+ return theMsg;
+}
+
+