Skip to content

Commit

Permalink
ticket:5537 Handle multiple parameter values in a TextAnnotation
Browse files Browse the repository at this point in the history
Display the unit of the parameter if available. The unit is only shown if parameter has some value.
  • Loading branch information
adeas31 committed Jul 17, 2019
1 parent e0b417b commit 3ea3db0
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 78 deletions.
24 changes: 17 additions & 7 deletions OMEdit/OMEdit/OMEditGUI/Annotations/TextAnnotation.cpp
Expand Up @@ -538,21 +538,31 @@ void TextAnnotation::updateTextStringHelper(QRegExp regExp)
/* Ticket:4204
* If we have extend component then call Component::getParameterDisplayString from root component.
*/
if (mpComponent->getComponentType() == Component::Extend) {
textValue = mpComponent->getRootParentComponent()->getParameterDisplayString(variable);
} else {
textValue = mpComponent->getRootParentComponent()->getParameterDisplayString(variable);
}
textValue = mpComponent->getRootParentComponent()->getParameterDisplayString(variable);
if (!textValue.isEmpty()) {
mTextString.replace(pos, regExp.matchedLength(), textValue);
QString unit = "";
QString displaytUnit = "";
Component *pComponent = mpComponent->getRootParentComponent()->getComponentByName(variable);
if (pComponent) {
displaytUnit = pComponent->getDerivedClassModifierValue("displaytUnit");
if (displaytUnit.isEmpty()) {
unit = pComponent->getDerivedClassModifierValue("unit");
displaytUnit = unit;
}
}
if (displaytUnit.isEmpty()) {
mTextString.replace(pos, regExp.matchedLength(), textValue);
} else {
mTextString.replace(pos, regExp.matchedLength(), QString("%1 %2").arg(textValue, displaytUnit));
}
} else { /* if the value of %\\W* is empty then remove the % sign. */
mTextString.replace(pos, 1, "");
}
} else { /* if there is just alone % then remove it. Because if you want to print % then use %%. */
mTextString.replace(pos, 1, "");
}
}
pos += regExp.matchedLength();
pos = 0;
}
}

Expand Down
97 changes: 97 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -1297,6 +1297,78 @@ QString Component::getParameterDisplayString(QString parameterName)
return displayString;
}

/*!
* \brief Component::getDerivedClassModifierValue
* Used to fetch the values of unit and displayUnit.
* \param modifierName
* \return
*/
QString Component::getDerivedClassModifierValue(QString modifierName)
{
/* Get unit value
* First check if unit is defined with in the component modifier.
* If no unit is found then check it in the derived class modifier value.
* A derived class can be inherited, so look recursively.
*/
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
QString className = mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QString modifierValue = mpComponentInfo->getModifiersMap(pOMCProxy, className, this).value(modifierName);
if (modifierValue.isEmpty()) {
if (!pOMCProxy->isBuiltinType(mpComponentInfo->getClassName())) {
if (mpLibraryTreeItem) {
if (!mpLibraryTreeItem->getModelWidget()) {
MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(mpLibraryTreeItem, false);
}
modifierValue = mpLibraryTreeItem->getModelWidget()->getDerivedClassModifiersMap().value(modifierName);
}
if (modifierValue.isEmpty()) {
modifierValue = getInheritedDerivedClassModifierValue(this, modifierName);
}
}
}
return StringHandler::removeFirstLastQuotes(modifierValue);
}

/*!
* \brief Component::getInheritedDerivedClassModifierValue
* Helper function for Component::getDerivedClassModifierValue()
* \param pComponent
* \param modifierName
* \return
*/
QString Component::getInheritedDerivedClassModifierValue(Component *pComponent, QString modifierName)
{
MainWindow *pMainWindow = MainWindow::instance();
OMCProxy *pOMCProxy = pMainWindow->getOMCProxy();
QString modifierValue = "";
if (!pComponent->getLibraryTreeItem()->getModelWidget()) {
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(pComponent->getLibraryTreeItem(), false);
}
foreach (Component *pInheritedComponent, pComponent->getInheritedComponentsList()) {
/* Ticket #4031
* Since we use the parent ComponentInfo for inherited classes so we should not use
* pInheritedComponent->getComponentInfo()->getClassName() to get the name instead we should use
* pInheritedComponent->getLibraryTreeItem()->getNameStructure() to get the correct name of inherited class.
* Also don't just return after reading from first inherited class. Check recursively.
*/
if (!pOMCProxy->isBuiltinType(pInheritedComponent->getLibraryTreeItem()->getNameStructure())) {
if (pInheritedComponent->getLibraryTreeItem()) {
if (!pInheritedComponent->getLibraryTreeItem()->getModelWidget()) {
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(pInheritedComponent->getLibraryTreeItem(), false);
}
modifierValue = pInheritedComponent->getLibraryTreeItem()->getModelWidget()->getDerivedClassModifiersMap().value(modifierName);
}
if (modifierValue.isEmpty()) {
modifierValue = getInheritedDerivedClassModifierValue(pInheritedComponent, modifierName);
}
if (!modifierValue.isEmpty()) {
return StringHandler::removeFirstLastQuotes(modifierValue);
}
}
}
return "";
}

/*!
* \brief Component::shapeAdded
* Called when a reference shape is added in its actual class.
Expand Down Expand Up @@ -1478,6 +1550,31 @@ void Component::setBusComponent(Component *pBusComponent)
setVisible(!isInBus());
}

/*!
* \brief Component::getComponentByName
* Finds the component by name.
* \param componentName
* \return
*/
Component *Component::getComponentByName(const QString &componentName)
{
Component *pComponentFound = 0;
foreach (Component *pComponent, getComponentsList()) {
if (pComponent->getComponentInfo() && pComponent->getName().compare(componentName) == 0) {
pComponentFound = pComponent;
return pComponentFound;
}
}
/* if is not found in components list then look into the inherited components list. */
foreach (Component *pInheritedComponent, getInheritedComponentsList()) {
pComponentFound = pInheritedComponent->getComponentByName(componentName);
if (pComponentFound) {
return pComponentFound;
}
}
return pComponentFound;
}

/*!
* \brief Component::createNonExistingComponent
* Creates a non-existing component.
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -239,6 +239,8 @@ class Component : public QObject, public QGraphicsItem
void emitDeleted();
void componentParameterHasChanged();
QString getParameterDisplayString(QString parameterName);
QString getDerivedClassModifierValue(QString modifierName);
QString getInheritedDerivedClassModifierValue(Component *pComponent, QString modifierName);
void shapeAdded();
void shapeUpdated();
void shapeDeleted();
Expand All @@ -251,6 +253,7 @@ class Component : public QObject, public QGraphicsItem
bool isInBus() {return mpBusComponent != 0;}
void setBusComponent(Component *pBusComponent);
Component* getBusComponent() {return mpBusComponent;}
Component* getComponentByName(const QString &componentName);

Transformation mTransformation;
Transformation mOldTransformation;
Expand Down
72 changes: 5 additions & 67 deletions OMEdit/OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -95,36 +95,11 @@ Parameter::Parameter(Component *pComponent, bool showStartAttribute, QString tab
setSaveSelectorFilter("-");
setSaveSelectorCaption("-");
createValueWidget();
/* Get unit value
* First check if unit is defined with in the component modifier.
* If no unit is found then check it in the derived class modifier value.
* A derived class can be inherited, so look recursively.
*/
QString className = mpComponent->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QString unit = mpComponent->getComponentInfo()->getModifiersMap(pOMCProxy, className, mpComponent).value("unit");
if (unit.isEmpty()) {
if (!pOMCProxy->isBuiltinType(mpComponent->getComponentInfo()->getClassName())) {
unit = pOMCProxy->getDerivedClassModifierValue(mpComponent->getComponentInfo()->getClassName(), "unit");
if (unit.isEmpty()) {
unit = getModifierValueFromDerivedClass(mpComponent, "unit");
}
}
}
mUnit = StringHandler::removeFirstLastQuotes(unit);
/* Get displayUnit value
* First check if displayUnit is defined with in the component modifier.
* If no displayUnit is found then check it in the derived class modifier value.
* A derived class can be inherited, so look recursively.
*/
QString displayUnit = mpComponent->getComponentInfo()->getModifiersMap(pOMCProxy, className, mpComponent).value("displayUnit");
if (displayUnit.isEmpty()) {
if (!pOMCProxy->isBuiltinType(mpComponent->getComponentInfo()->getClassName())) {
displayUnit = pOMCProxy->getDerivedClassModifierValue(mpComponent->getComponentInfo()->getClassName(), "displayUnit");
if (displayUnit.isEmpty()) {
displayUnit = getModifierValueFromDerivedClass(mpComponent, "displayUnit");
}
}
}
// Get unit value
QString unit = mpComponent->getDerivedClassModifierValue("unit");
mUnit = unit;
// Get displayUnit value
QString displayUnit = mpComponent->getDerivedClassModifierValue("displayUnit");
if (displayUnit.isEmpty()) {
displayUnit = unit;
}
Expand Down Expand Up @@ -293,43 +268,6 @@ QString Parameter::getFixedState()
return mpFixedCheckBox->tickStateString();
}

/*!
* \brief Parameter::getModifierValueFromDerivedClass
* Returns the modifier value by reading the derived classes.
* \param pComponent
* \param modifierName
* \return the modifier value.
*/
QString Parameter::getModifierValueFromDerivedClass(Component *pComponent, QString modifierName)
{
MainWindow *pMainWindow = MainWindow::instance();
OMCProxy *pOMCProxy = pMainWindow->getOMCProxy();
QString modifierValue = "";
if (!pComponent->getLibraryTreeItem()->getModelWidget()) {
pMainWindow->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(pComponent->getLibraryTreeItem(), false);
}
foreach (Component *pInheritedComponent, pComponent->getInheritedComponentsList()) {
/* Ticket #4031
* Since we use the parent ComponentInfo for inherited classes so we should not use
* pInheritedComponent->getComponentInfo()->getClassName() to get the name instead we should use
* pInheritedComponent->getLibraryTreeItem()->getNameStructure() to get the correct name of inherited class.
* Also don't just return after reading from first inherited class. Check recursively.
*/
if (pInheritedComponent->getLibraryTreeItem() &&
!pOMCProxy->isBuiltinType(pInheritedComponent->getLibraryTreeItem()->getNameStructure())) {
modifierValue = pOMCProxy->getDerivedClassModifierValue(pInheritedComponent->getLibraryTreeItem()->getNameStructure(),
modifierName);
if (modifierValue.isEmpty()) {
modifierValue = getModifierValueFromDerivedClass(pInheritedComponent, modifierName);
}
if (!modifierValue.isEmpty()) {
return modifierValue;
}
}
}
return "";
}

/*!
Sets the input field of the parameter enable/disable.
\param enable
Expand Down
1 change: 0 additions & 1 deletion OMEdit/OMEdit/OMEditGUI/Component/ComponentProperties.h
Expand Up @@ -84,7 +84,6 @@ class Parameter : public QObject
Label* getCommentLabel() {return mpCommentLabel;}
void setFixedState(QString fixed, bool defaultValue);
QString getFixedState();
QString getModifierValueFromDerivedClass(Component *pComponent, QString modifierName);
void setEnabled(bool enable);
private:
Component *mpComponent;
Expand Down
35 changes: 32 additions & 3 deletions OMEdit/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -1778,7 +1778,11 @@ bool GraphicsView::isParameterConnectorSizing(Component *pComponent, QString par
}
// Look in class inherited components
foreach (Component *pInheritedComponent, pComponent->getInheritedComponentsList()) {
if (pInheritedComponent->getComponentInfo() && pInheritedComponent->getName().compare(parameter) == 0) {
/* Since we use the parent ComponentInfo for inherited classes so we should not use
* pInheritedComponent->getComponentInfo()->getClassName() to get the name instead we should use
* pInheritedComponent->getLibraryTreeItem()->getNameStructure() to get the correct name of inherited class.
*/
if (pInheritedComponent->getLibraryTreeItem() && pInheritedComponent->getLibraryTreeItem()->getName().compare(parameter) == 0) {
return (pInheritedComponent->getDialogAnnotation().size() > 10) && (pInheritedComponent->getDialogAnnotation().at(10).compare("true") == 0);
}
result = isParameterConnectorSizing(pInheritedComponent, parameter);
Expand Down Expand Up @@ -3532,9 +3536,8 @@ void UndoStack::push(UndoCommand *cmd)
ModelWidget::ModelWidget(LibraryTreeItem* pLibraryTreeItem, ModelWidgetContainer *pModelWidgetContainer)
: QWidget(pModelWidgetContainer), mpModelWidgetContainer(pModelWidgetContainer), mpLibraryTreeItem(pLibraryTreeItem),
mComponentsLoaded(false), mDiagramViewLoaded(false), mConnectionsLoaded(false), mCreateModelWidgetComponents(false),
mExtendsModifiersLoaded(false)
mExtendsModifiersLoaded(false), mDerivedClassModifiersLoaded(false)
{
mExtendsModifiersMap.clear();
// create widgets based on library type
if (mpLibraryTreeItem->getLibraryType() == LibraryTreeItem::Modelica) {
// icon graphics framework
Expand Down Expand Up @@ -3641,13 +3644,38 @@ QMap<QString, QString> ModelWidget::getExtendsModifiersMap(QString extendsClass)
return mExtendsModifiersMap.value(extendsClass);
}

/*!
* \brief ModelWidget::getDerivedClassModifiersMap
* Returns a derived class modifiers map
* \param derivedClass
* \return
*/
QMap<QString, QString> ModelWidget::getDerivedClassModifiersMap()
{
if (!mDerivedClassModifiersLoaded) {
mDerivedClassModifiersMap.clear();
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
QStringList derivedClassModifierNames = pOMCProxy->getDerivedClassModifierNames(mpLibraryTreeItem->getNameStructure());
foreach (QString derivedClassModifierName, derivedClassModifierNames) {
// if we have already read the record modifier then continue
if (mDerivedClassModifiersMap.contains(derivedClassModifierName)) {
continue;
}
mDerivedClassModifiersMap.insert(derivedClassModifierName, pOMCProxy->getDerivedClassModifierValue(mpLibraryTreeItem->getNameStructure(), derivedClassModifierName));
}
mDerivedClassModifiersLoaded = true;
}
return mDerivedClassModifiersMap;
}

/*!
* \brief ModelWidget::fetchExtendsModifiers
* Gets the extends modifiers and their values.
* \param extendsClass
*/
void ModelWidget::fetchExtendsModifiers(QString extendsClass)
{
mExtendsModifiersMap.clear();
OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy();
QStringList extendsModifiersList = pOMCProxy->getExtendsModifierNames(mpLibraryTreeItem->getNameStructure(), extendsClass);
QMap<QString, QString> extendsModifiersMap;
Expand Down Expand Up @@ -4401,6 +4429,7 @@ void ModelWidget::reDrawModelWidget()
} else {
// Draw icon view
mExtendsModifiersLoaded = false;
mDerivedClassModifiersLoaded = false;
// remove saved inherited classes
clearInheritedClasses();
// get inherited classes
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.h
Expand Up @@ -429,6 +429,7 @@ class ModelWidget : public QWidget
QList<LibraryTreeItem*> getInheritedClassesList() {return mInheritedClassesList;}
const QList<ComponentInfo*> &getComponentsList() {return mComponentsList;}
QMap<QString, QString> getExtendsModifiersMap(QString extendsClass);
QMap<QString, QString> getDerivedClassModifiersMap();
void fetchExtendsModifiers(QString extendsClass);
void reDrawModelWidgetInheritedClasses();
void drawBaseCoOrdinateSystem(ModelWidget *pModelWidget, GraphicsView *pGraphicsView);
Expand Down Expand Up @@ -490,6 +491,8 @@ class ModelWidget : public QWidget
bool mCreateModelWidgetComponents;
bool mExtendsModifiersLoaded;
QMap<QString, QMap<QString, QString> > mExtendsModifiersMap;
bool mDerivedClassModifiersLoaded;
QMap<QString, QString> mDerivedClassModifiersMap;
QList<LibraryTreeItem*> mInheritedClassesList;
QList<ComponentInfo*> mComponentsList;
QStringList mComponentsAnnotationsList;
Expand Down
11 changes: 11 additions & 0 deletions OMEdit/OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -2648,6 +2648,17 @@ QStringList OMCProxy::getAvailableLibraries()
return mpOMCInterface->getAvailableLibraries();
}

/*!
* \brief OMCProxy::getDerivedClassModifierNames
* Gets the derived class modifier names.
* \param className
* \return
*/
QStringList OMCProxy::getDerivedClassModifierNames(QString className)
{
return mpOMCInterface->getDerivedClassModifierNames(className);
}

/*!
* \brief OMCProxy::getDerivedClassModifierValue
* Gets the derived class modifier value.
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -226,6 +226,7 @@ class OMCProxy : public QObject
QString uriToFilename(QString uri);
QString getModelicaPath();
QStringList getAvailableLibraries();
QStringList getDerivedClassModifierNames(QString className);
QString getDerivedClassModifierValue(QString className, QString modifierName);
OMCInterface::convertUnits_res convertUnits(QString from, QString to);
QList<QString> getDerivedUnits(QString baseUnit);
Expand Down

0 comments on commit 3ea3db0

Please sign in to comment.