Skip to content

Commit

Permalink
Read $error in the instance api (#9828)
Browse files Browse the repository at this point in the history
* Read $error in the instance api

Made PlacementAnnotation dynamic

* Return instead of trying to deserialize Absyn expression
  • Loading branch information
adeas31 committed Dec 1, 2022
1 parent f7e224c commit ae0256f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
14 changes: 14 additions & 0 deletions OMEdit/OMEditLIB/Annotations/DynamicAnnotation.cpp
Expand Up @@ -57,9 +57,23 @@ bool DynamicAnnotation::parse(const QString &str)
return true;
}

/*!
* \brief DynamicAnnotation::deserialize
* Deserialize an annotation expression json and stores the expression, then either
* calls reset or clear based on whether the deserializing succeeded or not.
* \param value
* \return
*/
bool DynamicAnnotation::deserialize(const QJsonValue &value)
{
try {
if (value.isObject()) {
QJsonObject valueObject = value.toObject();
if (valueObject.contains("$error")) {
MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, valueObject.value("$error").toString(), Helper::scriptingKind, Helper::errorLevel));
return false;
}
}
mExp.deserialize(value);
mState = mExp.isCall("DynamicSelect") ? State::Static : State::None;
reset();
Expand Down
8 changes: 8 additions & 0 deletions OMEdit/OMEditLIB/Element/Transformation.cpp
Expand Up @@ -157,16 +157,24 @@ void Transformation::parseTransformation(const ModelInstance::PlacementAnnotatio

// transformation
mVisible = placementAnnotation.getVisible();
mVisible.evaluate(placementAnnotation.getParentModel());
ModelInstance::Transformation transformation = placementAnnotation.getTransformation();
mOriginDiagram = transformation.getOrigin();
mOriginDiagram.evaluate(placementAnnotation.getParentModel());
mExtentDiagram = transformation.getExtent();
mExtentDiagram.evaluate(placementAnnotation.getParentModel());
mRotateAngleDiagram = transformation.getRotation();
mRotateAngleDiagram.evaluate(placementAnnotation.getParentModel());
// icon transformation
mVisibleIcon = placementAnnotation.getIconVisible();
mVisibleIcon.evaluate(placementAnnotation.getParentModel());
ModelInstance::Transformation iconTransformation = placementAnnotation.getIconTransformation();
mOriginIcon = iconTransformation.getOrigin();
mOriginIcon.evaluate(placementAnnotation.getParentModel());
mExtentIcon = iconTransformation.getExtent();
mExtentIcon.evaluate(placementAnnotation.getParentModel());
mRotateAngleIcon = iconTransformation.getRotation();
mRotateAngleIcon.evaluate(placementAnnotation.getParentModel());
}

void Transformation::updateTransformation(const Transformation &transformation)
Expand Down
30 changes: 16 additions & 14 deletions OMEdit/OMEditLIB/Modeling/Model.cpp
Expand Up @@ -692,39 +692,39 @@ namespace ModelInstance
}

if (annotation.contains("DocumentationClass")) {
mDocumentationClass = annotation.value("DocumentationClass").toBool();
mDocumentationClass.deserialize(annotation.value("DocumentationClass"));
}

if (annotation.contains("version")) {
mVersion = annotation.value("version").toString();
mVersion.deserialize(annotation.value("version"));
}

if (annotation.contains("versionDate")) {
mVersionDate = annotation.value("versionDate").toString();
mVersionDate.deserialize(annotation.value("versionDate"));
}

if (annotation.contains("versionBuild")) {
mVersionDate = QString::number(annotation.value("versionBuild").toInt());
mVersionBuild.deserialize(annotation.value("versionBuild"));
}

if (annotation.contains("dateModified")) {
mDateModified = annotation.value("dateModified").toString();
mDateModified.deserialize(annotation.value("dateModified"));
}

if (annotation.contains("preferredView")) {
mPreferredView = annotation.value("preferredView").toString();
mPreferredView.deserialize(annotation.value("preferredView"));
}

if (annotation.contains("__Dymola_state")) {
mState = annotation.value("__Dymola_state").toBool();
mState.deserialize(annotation.value("__Dymola_state"));
}

if (annotation.contains("Protection")) {
QJsonObject protection = annotation.value("Protection").toObject();
if (protection.contains("access")) {
QJsonObject access = protection.value("access").toObject();
if (access.contains("name")) {
mAccess = access.value("name").toString();
mAccess.deserialize(access.value("name"));
}
}
}
Expand Down Expand Up @@ -973,7 +973,7 @@ namespace ModelInstance
mDocumentationClass = false;
mVersion = "";
mVersionDate = "";
mVersionBuild = "";
mVersionBuild = 0;
mDateModified = "";
mPreferredView = "";
mState = false;
Expand Down Expand Up @@ -1011,8 +1011,9 @@ namespace ModelInstance
}
}

PlacementAnnotation::PlacementAnnotation()
PlacementAnnotation::PlacementAnnotation(Model *pParentModel)
{
mpParentModel = pParentModel;
// set the visible to false. Otherwise we get elements in the center of the view.
mVisible = false;
mIconVisible = false;
Expand Down Expand Up @@ -1124,15 +1125,16 @@ namespace ModelInstance
void Choices::deserialize(const QJsonObject &jsonObject)
{
if (jsonObject.contains("checkBox")) {
mCheckBox = jsonObject.value("checkBox").toBool();
mCheckBox.deserialize(jsonObject.value("checkBox"));
}

if (jsonObject.contains("__Dymola_checkBox")) {
mDymolaCheckBox = jsonObject.value("__Dymola_checkBox").toBool();
mDymolaCheckBox.deserialize(jsonObject.value("__Dymola_checkBox"));
}
}

Element::Element(Model *pParentModel)
: mPlacementAnnotation(pParentModel)
{
mpParentModel = pParentModel;
mpModel = 0;
Expand Down Expand Up @@ -1281,7 +1283,7 @@ namespace ModelInstance
QJsonObject annotation = jsonObject.value("annotation").toObject();

if (annotation.contains("choicesAllMatching")) {
mChoicesAllMatching = annotation.value("choicesAllMatching").toBool();
mChoicesAllMatching.deserialize(annotation.value("choicesAllMatching"));
}

if (annotation.contains("Placement")) {
Expand All @@ -1294,7 +1296,7 @@ namespace ModelInstance
}

if (annotation.contains("Evaluate")) {
mEvaluate = annotation.value("Evaluate").toBool();
mEvaluate.deserialize(annotation.value("Evaluate"));
}

if (annotation.contains("choices")) {
Expand Down
29 changes: 15 additions & 14 deletions OMEdit/OMEditLIB/Modeling/Model.h
Expand Up @@ -339,7 +339,6 @@ namespace ModelInstance
bool isDocumentationClass() const {return mDocumentationClass;}
QString getVersion() const {return mVersion;}
QString getVersionDate() const {return mVersionDate;}
QString getVersionBuild() const {return mVersionBuild;}
QString getDateModified() const {return mDateModified;}
QString getPreferredView() const {return mPreferredView;}
bool isState() const {return mState;}
Expand Down Expand Up @@ -381,14 +380,14 @@ namespace ModelInstance
QString mComment;
IconDiagramAnnotation *mpIconAnnotation;
IconDiagramAnnotation *mpDiagramAnnotation;
bool mDocumentationClass;
QString mVersion;
QString mVersionDate;
QString mVersionBuild;
QString mDateModified;
QString mPreferredView;
bool mState;
QString mAccess;
BooleanAnnotation mDocumentationClass;
StringAnnotation mVersion;
StringAnnotation mVersionDate;
RealAnnotation mVersionBuild;
StringAnnotation mDateModified;
StringAnnotation mPreferredView;
BooleanAnnotation mState;
StringAnnotation mAccess;
QList<Element*> mElements;
QString mFileName;
int mLineStart;
Expand Down Expand Up @@ -418,13 +417,15 @@ namespace ModelInstance
class PlacementAnnotation
{
public:
PlacementAnnotation();
PlacementAnnotation(Model *pParentModel);
void deserialize(const QJsonObject &jsonObject);
Model *getParentModel() const {return mpParentModel;}
BooleanAnnotation getVisible() const {return mVisible;}
Transformation getTransformation() const {return mTransformation;}
BooleanAnnotation getIconVisible() const {return mIconVisible;}
Transformation getIconTransformation() const {return mIconTransformation;}
private:
Model *mpParentModel;
BooleanAnnotation mVisible;
Transformation mTransformation;
BooleanAnnotation mIconVisible;
Expand Down Expand Up @@ -479,8 +480,8 @@ namespace ModelInstance
bool isCheckBox() const {return mCheckBox;}
bool isDymolaCheckBox() const {return mDymolaCheckBox;}
private:
bool mCheckBox;
bool mDymolaCheckBox;
BooleanAnnotation mCheckBox;
BooleanAnnotation mDymolaCheckBox;
};

class Element
Expand Down Expand Up @@ -541,11 +542,11 @@ namespace ModelInstance
QString mVariability;
QString mDirection;
QString mComment;
bool mChoicesAllMatching;
BooleanAnnotation mChoicesAllMatching;
PlacementAnnotation mPlacementAnnotation;
bool mHasDialogAnnotation;
DialogAnnotation mDialogAnnotation;
bool mEvaluate;
BooleanAnnotation mEvaluate;
Choices mChoices;

static QString getModifierValueFromInheritedType(Model *pModel, QStringList modifierName);
Expand Down

0 comments on commit ae0256f

Please sign in to comment.