Skip to content

Commit

Permalink
Store the extends modifiers and component modifiers.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 25, 2015
1 parent eb5d903 commit 734e3df
Show file tree
Hide file tree
Showing 10 changed files with 524 additions and 450 deletions.
22 changes: 10 additions & 12 deletions OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -443,18 +443,16 @@ void TextAnnotation::updateTextStringHelper(QRegExp regExp)
*/
void TextAnnotation::updateTextString()
{
/*
From Modelica Spec 32revision2,
There are a number of common macros that can be used in the text, and they should be replaced when displaying
the text as follows:
- %par replaced by the value of the parameter par. The intent is that the text is easily readable, thus if par is
of an enumeration type, replace %par by the item name, not by the full name.
[Example: if par="Modelica.Blocks.Types.Enumeration.Periodic", then %par should be displayed as
"Periodic"]
- %% replaced by %
- %name replaced by the name of the component (i.e. the identifier for it in in the enclosing class).
- %class replaced by the name of the class.
*/
/* From Modelica Spec 32revision2,
* There are a number of common macros that can be used in the text, and they should be replaced when displaying
* the text as follows:
* - %par replaced by the value of the parameter par. The intent is that the text is easily readable, thus if par is
* of an enumeration type, replace %par by the item name, not by the full name.
* [Example: if par="Modelica.Blocks.Types.Enumeration.Periodic", then %par should be displayed as "Periodic"]
* - %% replaced by %
* - %name replaced by the name of the component (i.e. the identifier for it in in the enclosing class).
* - %class replaced by the name of the class.
*/
mTextString = mOriginalTextString;
if (!mTextString.contains("%")) {
return;
Expand Down
169 changes: 119 additions & 50 deletions OMEdit/OMEditGUI/Component/Component.cpp

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -148,6 +148,8 @@ class Component : public QObject, public QGraphicsItem
QString getTransformationString() {return mTransformationString;}
void setDialogAnnotation(QStringList dialogAnnotation) {mDialogAnnotation = dialogAnnotation;}
QStringList getDialogAnnotation() {return mDialogAnnotation;}
QMap<QString, QString> getModifiersMap() {return mModifiersMap;}
QString getParameterValue() {return mParameterValue;}
CoOrdinateSystem getCoOrdinateSystem() const;
OriginItem* getOriginItem() {return mpOriginItem;}
QAction* getParametersAction() {return mpParametersAction;}
Expand Down Expand Up @@ -180,6 +182,7 @@ class Component : public QObject, public QGraphicsItem
void emitChanged();
void emitDeleted();
void componentParameterHasChanged();
void getComponentModifiers();
QString getParameterDisplayString(QString parameterName);
void shapeAdded();
void shapeUpdated();
Expand All @@ -200,6 +203,8 @@ class Component : public QObject, public QGraphicsItem
ComponentType mComponentType;
QString mTransformationString;
QStringList mDialogAnnotation;
QMap<QString, QString> mModifiersMap;
QString mParameterValue;
QGraphicsRectItem *mpResizerRectangle;
LineAnnotation *mpNonExistingComponentLine;
RectangleAnnotation *mpDefaultComponentRectangle;
Expand Down Expand Up @@ -244,6 +249,8 @@ class Component : public QObject, public QGraphicsItem
void setOriginAndExtents();
void reloadComponent(bool loaded);
void updateConnections();
QString getParameterDisplayStringFromExtendsModifiers(QString parameterName);
QString getParameterDisplayStringFromExtendsParameters(QString parameterName);
signals:
void added();
void transformChange();
Expand Down
159 changes: 104 additions & 55 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -79,8 +79,7 @@ Parameter::Parameter(Component *pComponent, bool showStartAttribute, QString tab
* If no unit is found then check it in the derived class modifier value.
* A derived class can be inherited, so look recursively.
*/
QString unit = pOMCProxy->getComponentModifierValue(mpComponent->getComponentInfo()->getClassName(),
QString(mpComponent->getName()).append(".unit"));
QString unit = mpComponent->getModifiersMap().value("unit");
if (unit.isEmpty()) {
if (!pOMCProxy->isBuiltinType(mpComponent->getComponentInfo()->getClassName())) {
unit = getUnitFromDerivedClass(mpComponent);
Expand Down Expand Up @@ -485,7 +484,13 @@ void ComponentParameters::setUpDialog()
mTabsMap.insert("General", mpParametersTabWidget->addTab(pParametersScrollArea, "General"));
// create parameters tabs and groupboxes
createTabsGroupBoxesAndParameters(mpComponent->getLibraryTreeItem());
/* We append the actual Components parameters first so that they appear first on the list.
* For that we use QList insert instead of append in ComponentParameters::createTabsGroupBoxesAndParametersHelper() function.
* Modelica.Electrical.Analog.Basic.Resistor order is wrong if we don't use insert.
*/
createTabsGroupBoxesAndParametersHelper(mpComponent->getLibraryTreeItem(), true);
fetchComponentModifiers();
fetchExtendsModifiers();
foreach (Parameter *pParameter, mParametersList) {
ParametersScrollArea *pParametersScrollArea;
pParametersScrollArea = qobject_cast<ParametersScrollArea*>(mpParametersTabWidget->widget(mTabsMap.value(pParameter->getTab())));
Expand Down Expand Up @@ -551,14 +556,10 @@ void ComponentParameters::setUpDialog()
*/
void ComponentParameters::createTabsGroupBoxesAndParameters(LibraryTreeItem *pLibraryTreeItem)
{
foreach (ModelWidget::InheritedClass *pInheritedClass, pLibraryTreeItem->getModelWidget()->getInheritedClassesList()) {
createTabsGroupBoxesAndParametersHelper(pInheritedClass->mpLibraryTreeItem);
foreach (LibraryTreeItem *pInheritedLibraryTreeItem, pLibraryTreeItem->getModelWidget()->getInheritedClassesList()) {
createTabsGroupBoxesAndParameters(pInheritedLibraryTreeItem);
createTabsGroupBoxesAndParametersHelper(pInheritedLibraryTreeItem);
}
/* We append the actual Components parameters first so that they appear first on the list.
* For that we use QList insert instead of append in ComponentParameters::createTabsGroupBoxesAndParametersHelper() function.
* Modelica.Electrical.Analog.Basic.Resistor order is wrong if we don't use insert.
*/
createTabsGroupBoxesAndParametersHelper(pLibraryTreeItem, true);
}

/*!
Expand All @@ -573,10 +574,10 @@ void ComponentParameters::createTabsGroupBoxesAndParametersHelper(LibraryTreeIte
{
OMCProxy *pOMCProxy = mpMainWindow->getOMCProxy();
foreach (LibraryTreeItem *pInheritedLibraryTreeItem, pLibraryTreeItem->getInheritedClasses()) {
QStringList extendsModifiers = pOMCProxy->getExtendsModifierNames(pLibraryTreeItem->getNameStructure(),
pInheritedLibraryTreeItem->getNameStructure());
foreach (QString extendsModifier, extendsModifiers) {
QString parameterName = StringHandler::getFirstWordBeforeDot(extendsModifier);
QMap<QString, QString> extendsModifiers = pLibraryTreeItem->getModelWidget()->getExtendsModifiersMap(pInheritedLibraryTreeItem->getNameStructure());
QMap<QString, QString>::iterator extendsModifiersIterator;
for (extendsModifiersIterator = extendsModifiers.begin(); extendsModifiersIterator != extendsModifiers.end(); ++extendsModifiersIterator) {
QString parameterName = StringHandler::getFirstWordBeforeDot(extendsModifiersIterator.key());
/* Ticket #2531
* Check if parameter is marked final in the extends modifier.
*/
Expand All @@ -589,19 +590,23 @@ void ComponentParameters::createTabsGroupBoxesAndParametersHelper(LibraryTreeIte
} else {
Parameter *pParameter = findParameter(parameterName);
if (pParameter) {
QString start = pOMCProxy->getExtendsModifierValue(pLibraryTreeItem->getNameStructure(),
pInheritedLibraryTreeItem->getNameStructure(), parameterName + ".start");
QString fixed = pOMCProxy->getExtendsModifierValue(pLibraryTreeItem->getNameStructure(),
pInheritedLibraryTreeItem->getNameStructure(), parameterName + ".fixed");
if (!start.isEmpty() || !fixed.isEmpty()) {
pParameter->setGroupBox("Initialization");
pParameter->setShowStartAttribute(true);
pParameter->setValueWidget(start, true);
pParameter->setFixedState(fixed, true);
if (extendsModifiersIterator.key().compare(parameterName + ".start") == 0) {
QString start = extendsModifiersIterator.value();
if (!start.isEmpty()) {
pParameter->setGroupBox("Initialization");
pParameter->setShowStartAttribute(true);
pParameter->setValueWidget(start, false);
}
}
else if (extendsModifiersIterator.key().compare(parameterName + ".fixed") == 0) {
QString fixed = extendsModifiersIterator.value();
if (!fixed.isEmpty()) {
pParameter->setGroupBox("Initialization");
pParameter->setShowStartAttribute(true);
pParameter->setFixedState(fixed, false);
}
} else {
QString value = pOMCProxy->getExtendsModifierValue(pLibraryTreeItem->getNameStructure(),
pInheritedLibraryTreeItem->getNameStructure(), extendsModifier);
pParameter->setValueWidget(value, true);
pParameter->setValueWidget(extendsModifiersIterator.value(), true);
}
}
}
Expand All @@ -628,8 +633,16 @@ void ComponentParameters::createTabsGroupBoxesAndParametersHelper(LibraryTreeIte
bool isParameter = (pComponent->getComponentInfo()->getVariablity().compare("parameter") == 0);
// If not a parameter then check for start and fixed bindings. See Modelica.Electrical.Analog.Basic.Resistor parameter R.
if (!isParameter) {
start = pOMCProxy->getComponentModifierValue(pLibraryTreeItem->getNameStructure(), pComponent->getName() + ".start");
fixed = pOMCProxy->getComponentModifierValue(pLibraryTreeItem->getNameStructure(), pComponent->getName() + ".fixed");
QMap<QString, QString> modifiers = pComponent->getModifiersMap();
QMap<QString, QString>::iterator modifiersIterator;
for (modifiersIterator = modifiers.begin(); modifiersIterator != modifiers.end(); ++modifiersIterator) {
if (modifiersIterator.key().compare("start") == 0) {
start = modifiersIterator.value();
}
else if (modifiersIterator.key().compare("fixed") == 0) {
fixed = modifiersIterator.value();
}
}
showStartAttribute = (!start.isEmpty() || !fixed.isEmpty()) ? true : false;
}
/* get the dialog annotation */
Expand Down Expand Up @@ -700,23 +713,69 @@ void ComponentParameters::createTabsGroupBoxesAndParametersHelper(LibraryTreeIte
*/
void ComponentParameters::fetchComponentModifiers()
{
OMCProxy *pOMCProxy = mpMainWindow->getOMCProxy();
QString className = mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QStringList modifiers = pOMCProxy->getComponentModifierNames(className, mpComponent->getName());
foreach (QString modifier, modifiers) {
QString parameterName = StringHandler::getFirstWordBeforeDot(modifier);
Component *pComponent = mpComponent;
if (mpComponent->getReferenceComponent()) {
pComponent = mpComponent->getReferenceComponent();
}
QMap<QString, QString> modifiers = pComponent->getModifiersMap();
QMap<QString, QString>::iterator modifiersIterator;
for (modifiersIterator = modifiers.begin(); modifiersIterator != modifiers.end(); ++modifiersIterator) {
QString parameterName = StringHandler::getFirstWordBeforeDot(modifiersIterator.key());
Parameter *pParameter = findParameter(parameterName);
if (pParameter) {
QString start = pOMCProxy->getComponentModifierValue(className, mpComponent->getName() + "." + parameterName + ".start");
QString fixed = pOMCProxy->getComponentModifierValue(className, mpComponent->getName() + "." + parameterName + ".fixed");
if (!start.isEmpty() || !fixed.isEmpty()) {
pParameter->setGroupBox("Initialization");
pParameter->setShowStartAttribute(true);
pParameter->setValueWidget(start, false);
pParameter->setFixedState(fixed, false);
if (modifiersIterator.key().compare(parameterName + ".start") == 0) {
QString start = modifiersIterator.value();
if (!start.isEmpty()) {
pParameter->setGroupBox("Initialization");
pParameter->setShowStartAttribute(true);
pParameter->setValueWidget(start, mpComponent->getReferenceComponent() ? true : false);
}
}
else if (modifiersIterator.key().compare(parameterName + ".fixed") == 0) {
QString fixed = modifiersIterator.value();
if (!fixed.isEmpty()) {
pParameter->setGroupBox("Initialization");
pParameter->setShowStartAttribute(true);
pParameter->setFixedState(fixed, mpComponent->getReferenceComponent() ? true : false);
}
} else {
QString value = pOMCProxy->getComponentModifierValue(className, mpComponent->getName() + "." + modifier);
pParameter->setValueWidget(value, false);
pParameter->setValueWidget(modifiersIterator.value(), mpComponent->getReferenceComponent() ? true : false);
}
}
}
}

void ComponentParameters::fetchExtendsModifiers()
{
if (mpComponent->getReferenceComponent()) {
QString inheritedClassName;
inheritedClassName = mpComponent->getReferenceComponent()->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QMap<QString, QString> extendsModifiersMap = mpComponent->getGraphicsView()->getModelWidget()->getExtendsModifiersMap(inheritedClassName);
QMap<QString, QString>::iterator extendsModifiersIterator;
for (extendsModifiersIterator = extendsModifiersMap.begin(); extendsModifiersIterator != extendsModifiersMap.end(); ++extendsModifiersIterator) {
// since first word is component name so we remove it.
QString parameterName = StringHandler::removeFirstWordAfterDot(extendsModifiersIterator.key());
parameterName = StringHandler::getFirstWordBeforeDot(parameterName);
Parameter *pParameter = findParameter(parameterName);
if (pParameter) {
if (extendsModifiersIterator.key().compare(parameterName + ".start") == 0) {
QString start = extendsModifiersIterator.value();
if (!start.isEmpty()) {
pParameter->setGroupBox("Initialization");
pParameter->setShowStartAttribute(true);
pParameter->setValueWidget(start, false);
}
}
else if (extendsModifiersIterator.key().compare(parameterName + ".fixed") == 0) {
QString fixed = extendsModifiersIterator.value();
if (!fixed.isEmpty()) {
pParameter->setGroupBox("Initialization");
pParameter->setShowStartAttribute(true);
pParameter->setFixedState(fixed, false);
}
} else {
pParameter->setValueWidget(extendsModifiersIterator.value(), false);
}
}
}
}
Expand Down Expand Up @@ -816,23 +875,13 @@ void ComponentParameters::updateComponentParameters()
// if valueChanged is true then put the change in the undo stack.
if (valueChanged) {
// save the Component modifiers
QString className = mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QMap<QString, QString> oldComponentModifiersMap;
QStringList componentModifiersList = mpMainWindow->getOMCProxy()->getComponentModifierNames(className, mpComponent->getName());
foreach (QString componentModifier, componentModifiersList) {
QString originalModifierName = QString(mpComponent->getName()).append(".").append(componentModifier);
QString componentModifierValue = mpMainWindow->getOMCProxy()->getComponentModifierValue(className, originalModifierName);
oldComponentModifiersMap.insert(componentModifier, componentModifierValue);
}
QMap<QString, QString> oldComponentModifiersMap = mpComponent->getModifiersMap();
// save the Component extends modifiers
QMap<QString, QString> oldComponentExtendsModifiersMap;
if (mpComponent->getReferenceComponent()) {
QString inheritedClassName = mpComponent->getReferenceComponent()->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QStringList extendsModifiersList = mpMainWindow->getOMCProxy()->getExtendsModifierNames(className, inheritedClassName);
foreach (QString extendsModifier, extendsModifiersList) {
QString componentModifierValue = mpMainWindow->getOMCProxy()->getExtendsModifierValue(className, inheritedClassName, extendsModifier);
oldComponentExtendsModifiersMap.insert(extendsModifier, componentModifierValue);
}
QString inheritedClassName;
inheritedClassName = mpComponent->getReferenceComponent()->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
oldComponentExtendsModifiersMap = mpComponent->getGraphicsView()->getModelWidget()->getExtendsModifiersMap(inheritedClassName);
}
// create UpdateComponentParametersCommand
UpdateComponentParametersCommand *pUpdateComponentParametersCommand;
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditGUI/Component/ComponentProperties.h
Expand Up @@ -155,6 +155,7 @@ class ComponentParameters : public QDialog
void createTabsGroupBoxesAndParameters(LibraryTreeItem *pLibraryTreeItem);
void createTabsGroupBoxesAndParametersHelper(LibraryTreeItem *pLibraryTreeItem, bool useInsert = false);
void fetchComponentModifiers();
void fetchExtendsModifiers();
Parameter* findParameter(LibraryTreeItem *pLibraryTreeItem, const QString &parameter,
Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) const;
Parameter* findParameter(const QString &parameter, Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive) const;
Expand Down
7 changes: 6 additions & 1 deletion OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -579,13 +579,16 @@ void UpdateComponentParametersCommand::redo()
}
// apply the new Component extends modifiers if any
if (mpComponent->getReferenceComponent()) {
QString inheritedClassName = mpComponent->getReferenceComponent()->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QString inheritedClassName;
inheritedClassName = mpComponent->getReferenceComponent()->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QMap<QString, QString>::iterator componentExtendsModifier;
for (componentExtendsModifier = mNewComponentExtendsModifiersMap.begin(); componentExtendsModifier != mNewComponentExtendsModifiersMap.end(); ++componentExtendsModifier) {
QString modifierValue = componentExtendsModifier.value();
pOMCProxy->setExtendsModifierValue(className, inheritedClassName, componentExtendsModifier.key(), modifierValue.prepend("="));
}
mpComponent->getGraphicsView()->getModelWidget()->updateExtendsModifiersMap(inheritedClassName);
}
mpComponent->getComponentModifiers();
mpComponent->componentParameterHasChanged();
}

Expand Down Expand Up @@ -615,7 +618,9 @@ void UpdateComponentParametersCommand::undo()
QString modifierValue = componentExtendsModifier.value();
pOMCProxy->setExtendsModifierValue(className, inheritedClassName, componentExtendsModifier.key(), modifierValue.prepend("="));
}
mpComponent->getGraphicsView()->getModelWidget()->updateExtendsModifiersMap(inheritedClassName);
}
mpComponent->getComponentModifiers();
mpComponent->componentParameterHasChanged();
}

Expand Down

0 comments on commit 734e3df

Please sign in to comment.