Skip to content

Commit

Permalink
[NewAPI] Show replaceable short type definitions in parameters window (
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 22, 2023
1 parent 3347ee4 commit 7d1e442
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 205 deletions.
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/Annotations/ShapeAnnotation.cpp
Expand Up @@ -609,10 +609,10 @@ QList<QPointF> ShapeAnnotation::getExtentsForInheritedShapeFromIconDiagramMap(Gr
ModelInstance::Extend *pExtend = dynamic_cast<ModelInstance::Extend*>(getExtend());
if (pExtend) {
if (pGraphicsView->getViewType() == StringHandler::Icon) {
extent = pExtend->getExtendsAnnotation()->getIconMap().getExtent();
extent = pExtend->getAnnotation()->getIconMap().getExtent();
preserveAspectRatio = pExtend->getModel()->getAnnotation()->getIconAnnotation()->mMergedCoOrdinateSystem.getPreserveAspectRatio();
} else {
extent = pExtend->getExtendsAnnotation()->getDiagramMap().getExtent();
extent = pExtend->getAnnotation()->getDiagramMap().getExtent();
preserveAspectRatio = pExtend->getModel()->getAnnotation()->getDiagramAnnotation()->mMergedCoOrdinateSystem.getPreserveAspectRatio();
}
}
Expand Down
147 changes: 78 additions & 69 deletions OMEdit/OMEditLIB/Element/ElementProperties.cpp

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions OMEdit/OMEditLIB/Element/ElementProperties.h
Expand Up @@ -56,9 +56,9 @@ class Parameter : public QObject
ChoicesAllMatching
};
Parameter(Element *pElement, bool showStartAttribute, QString tab, QString groupBox);
Parameter(ModelInstance::Component *pComponent, ElementParameters *pElementParameters);
Parameter(ModelInstance::Element *pElement, ElementParameters *pElementParameters);
Element* getElement() {return mpElement;}
ModelInstance::Component* getModelInstanceComponent() {return mpModelInstanceComponent;}
ModelInstance::Element* getModelInstanceElement() {return mpModelInstanceElement;}
bool isParameter() const;
void setTab(QString tab) {mTab = tab;}
StringAnnotation getTab() {return mTab;}
Expand Down Expand Up @@ -102,7 +102,7 @@ class Parameter : public QObject
void update();
private:
Element *mpElement;
ModelInstance::Component *mpModelInstanceComponent;
ModelInstance::Element *mpModelInstanceElement;
ElementParameters *mpElementParameters = 0;
StringAnnotation mTab;
StringAnnotation mGroup;
Expand Down Expand Up @@ -185,15 +185,15 @@ class ElementParameters : public QDialog
{
Q_OBJECT
public:
ElementParameters(ModelInstance::Component *pComponent, GraphicsView *pGraphicsView, bool inherited, bool nested, QWidget *pParent = 0);
ElementParameters(ModelInstance::Element *pElement, GraphicsView *pGraphicsView, bool inherited, bool nested, QWidget *pParent = 0);
~ElementParameters();
GraphicsView *getGraphicsView() const {return mpGraphicsView;}
bool isInherited() const {return mInherited;}
QString getModification() const {return mModification;}
static void applyStartFixedAndDisplayUnitModifiers(Parameter *pParameter, const ModelInstance::Modifier &modifier, bool defaultValue);
void updateParameters();
private:
ModelInstance::Component *mpElement;
ModelInstance::Element *mpElement;
GraphicsView *mpGraphicsView;
bool mInherited;
bool mNested;
Expand Down
24 changes: 24 additions & 0 deletions OMEdit/OMEditLIB/FlatModelica/Parser.cpp
Expand Up @@ -72,6 +72,9 @@ QString FlatModelica::Parser::getModelicaComment(QString element)
/*!
* \brief FlatModelica::Parser::getTypeFromElementRedeclaration
* \param elmentRedeclaration
* Parses the code like,
* redeclare ClassA classA "A"
* and returns ClassA, the type of the component.
* \return
*/
QString FlatModelica::Parser::getTypeFromElementRedeclaration(const QString &elmentRedeclaration)
Expand All @@ -86,3 +89,24 @@ QString FlatModelica::Parser::getTypeFromElementRedeclaration(const QString &elm
}
return "";
}

/*!
* \brief FlatModelica::Parser::getShortClassTypeFromElementRedeclaration
* \param elmentRedeclaration
* Parses the code like,
* redeclare model M = C
* and returns M, the type of the short class specifier.
* \return
*/
QString FlatModelica::Parser::getShortClassTypeFromElementRedeclaration(const QString &elmentRedeclaration)
{
antlr4::ANTLRInputStream input(elmentRedeclaration.toStdString());
openmodelica::modelicaLexer lexer(&input);
antlr4::CommonTokenStream tokens(&lexer);
openmodelica::modelicaParser parser(&tokens);
openmodelica::modelicaParser::Element_redeclarationContext *pElement_redeclarationContext = parser.element_redeclaration();
if (pElement_redeclarationContext && pElement_redeclarationContext->short_class_definition()) {
return QString::fromStdString(pElement_redeclarationContext->short_class_definition()->short_class_specifier()->type_specifier()->getText());
}
return "";
}
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/FlatModelica/Parser.h
Expand Up @@ -40,6 +40,7 @@ namespace FlatModelica
namespace Parser {
QString getModelicaComment(QString element);
QString getTypeFromElementRedeclaration(const QString &elmentRedeclaration);
QString getShortClassTypeFromElementRedeclaration(const QString &elmentRedeclaration);
} // namespace Utilities
} // namespace FlatModelica

Expand Down
174 changes: 79 additions & 95 deletions OMEdit/OMEditLIB/Modeling/Model.cpp
Expand Up @@ -1159,7 +1159,7 @@ namespace ModelInstance
foreach (auto pElement, mElements) {
if (pElement->isExtend()) {
auto pExtend = dynamic_cast<Extend*>(pElement);
value = pExtend->getExtendsModifier().getModifierValue(QStringList() << parameter);
value = pExtend->getModifier().getModifierValue(QStringList() << parameter);
if (!value.isEmpty()) {
return value;
} else {
Expand Down Expand Up @@ -1394,6 +1394,9 @@ namespace ModelInstance
Element::Element(Model *pParentModel)
{
mpParentModel = pParentModel;
mpPrefixes = std::make_unique<Prefixes>(pParentModel);
mComment = "";
mpAnnotation = std::make_unique<Annotation>(pParentModel);
}

Element::~Element()
Expand All @@ -1403,22 +1406,86 @@ namespace ModelInstance
}
}

QString Element::getModifierValueFromType(QStringList modifierNames)
{
/* 1. First check if unit is defined with in the component modifier.
* 2. If no unit is found then check it in the derived class modifier value.
* 3. A derived class can be inherited, so look recursively.
*/
// Case 1
QString modifierValue = mModifier.getModifierValue(modifierNames);
if (modifierValue.isEmpty() && mpModel) {
// Case 2
modifierValue = mpModel->getModifier().getModifierValue(modifierNames);
// Case 3
if (modifierValue.isEmpty()) {
modifierValue = Element::getModifierValueFromInheritedType(mpModel, modifierNames);
}
}
return modifierValue;
}

/*!
* \brief Component::getComment
* Returns the Component comment.
* Prefer the comment given in replaceable part.
* \return
*/
QString Element::getComment() const
{
if (mpPrefixes->getReplaceable() && !mpPrefixes->getReplaceable()->getComment().isEmpty()) {
return mpPrefixes->getReplaceable()->getComment();
} else {
return mComment;
}
}

/*!
* \brief Element::getAnnotation
* Returns the Element Annotation.
* Prefer the annotation given in replaceable part.
* \return
*/
Annotation *Element::getAnnotation() const
{
if (mpPrefixes->getReplaceable() && mpPrefixes->getReplaceable()->getAnnotation()) {
return mpPrefixes->getReplaceable()->getAnnotation();
} else {
return mpAnnotation.get();
}
}

QString Element::getModifierValueFromInheritedType(Model *pModel, QStringList modifierNames)
{
QString modifierValue = "";
foreach (auto pElement, pModel->getElements()) {
if (pElement->isExtend() && pElement->getModel()) {
auto pExtend = dynamic_cast<Extend*>(pElement);
modifierValue = pExtend->getModel()->getModifier().getModifierValue(modifierNames);
if (modifierValue.isEmpty()) {
modifierValue = Element::getModifierValueFromInheritedType(pExtend->getModel(), modifierNames);
} else {
return modifierValue;
}
}
}
return modifierValue;
}

Extend::Extend(Model *pParentModel, const QJsonObject &jsonObject)
: Element(pParentModel)
{
mpExtendsAnnotation = std::make_unique<Annotation>(pParentModel);
mBaseClass = "";
deserialize(jsonObject);
}

void Extend::deserialize(const QJsonObject &jsonObject)
{
if (jsonObject.contains("modifiers")) {
mExtendsModifier.deserialize(jsonObject.value("modifiers"));
mModifier.deserialize(jsonObject.value("modifiers"));
}

if (jsonObject.contains("annotation")) {
mpExtendsAnnotation->deserialize(jsonObject.value("annotation").toObject());
mpAnnotation->deserialize(jsonObject.value("annotation").toObject());
}

if (jsonObject.contains("baseClass")) {
Expand Down Expand Up @@ -1456,30 +1523,15 @@ namespace ModelInstance
Component::Component(Model *pParentModel)
: Element(pParentModel)
{
initialize();

}

Component::Component(Model *pParentModel, const QJsonObject &jsonObject)
: Element(pParentModel)
{
initialize();
deserialize(jsonObject);
}

void Component::initialize()
{
mName = "";
mCondition = true;
mType = "";
if (mpModel) {
delete mpModel;
}
mpModel = 0;
mpPrefixes = std::make_unique<Prefixes>(mpParentModel);
mComment = "";
mpAnnotation = std::make_unique<Annotation>(mpParentModel);
}

void Component::deserialize(const QJsonObject &jsonObject)
{
if (jsonObject.contains("name")) {
Expand Down Expand Up @@ -1542,72 +1594,6 @@ namespace ModelInstance
}
}

QString Component::getModifierValueFromType(QStringList modifierNames)
{
/* 1. First check if unit is defined with in the component modifier.
* 2. If no unit is found then check it in the derived class modifier value.
* 3. A derived class can be inherited, so look recursively.
*/
// Case 1
QString modifierValue = mModifier.getModifierValue(modifierNames);
if (modifierValue.isEmpty() && mpModel) {
// Case 2
modifierValue = mpModel->getModifier().getModifierValue(modifierNames);
// Case 3
if (modifierValue.isEmpty()) {
modifierValue = Component::getModifierValueFromInheritedType(mpModel, modifierNames);
}
}
return modifierValue;
}

/*!
* \brief Component::getComment
* Returns the Component comment.
* Prefer the comment given in replaceable part.
* \return
*/
QString Component::getComment() const
{
if (mpPrefixes->getReplaceable() && !mpPrefixes->getReplaceable()->getComment().isEmpty()) {
return mpPrefixes->getReplaceable()->getComment();
} else {
return mComment;
}
}

/*!
* \brief Component::getAnnotation
* Returns the Component Annotation.
* Prefer the annotation given in replaceable part.
* \return
*/
Annotation *Component::getAnnotation() const
{
if (mpPrefixes->getReplaceable() && mpPrefixes->getReplaceable()->getAnnotation()) {
return mpPrefixes->getReplaceable()->getAnnotation();
} else {
return mpAnnotation.get();
}
}

QString Component::getModifierValueFromInheritedType(Model *pModel, QStringList modifierNames)
{
QString modifierValue = "";
foreach (auto pElement, pModel->getElements()) {
if (pElement->isExtend() && pElement->getModel()) {
auto pExtend = dynamic_cast<Extend*>(pElement);
modifierValue = pExtend->getModel()->getModifier().getModifierValue(modifierNames);
if (modifierValue.isEmpty()) {
modifierValue = Component::getModifierValueFromInheritedType(pExtend->getModel(), modifierNames);
} else {
return modifierValue;
}
}
}
return modifierValue;
}

/*!
* \brief Component::getQualifiedName
* Returns the qualified name of the component.
Expand All @@ -1634,9 +1620,7 @@ namespace ModelInstance
: Element(pParentModel)
{
mpParentModel = pParentModel;
mName = "";
mpPrefixes = std::make_unique<Prefixes>(mpParentModel);
mBaseClass = "";
mIsShortClassDefinition = false;
deserialize(jsonObject);
}

Expand All @@ -1651,6 +1635,7 @@ namespace ModelInstance
}

if (jsonObject.contains("baseClass")) {
mIsShortClassDefinition = true;
mBaseClass = jsonObject.value("baseClass").toString();
}

Expand All @@ -1662,6 +1647,10 @@ namespace ModelInstance
mModifier.deserialize(jsonObject.value("modifiers"));
}

if (jsonObject.contains("annotation")) {
mpAnnotation->deserialize(jsonObject.value("annotation").toObject());
}

if (jsonObject.contains("source")) {
mSource.deserialize(jsonObject.value("source").toObject());
}
Expand All @@ -1676,11 +1665,6 @@ namespace ModelInstance
}
}

QString ReplaceableClass::getRootType() const
{
return mName;
}

Part::Part()
{
mName = "";
Expand Down

0 comments on commit 7d1e442

Please sign in to comment.