Skip to content

Commit

Permalink
Fetch the component modifiers only once.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Nov 28, 2015
1 parent 44801e5 commit 9f0aa25
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 68 deletions.
69 changes: 40 additions & 29 deletions OMEdit/OMEditGUI/Component/Component.cpp
Expand Up @@ -72,6 +72,7 @@ ComponentInfo::ComponentInfo(QObject *pParent)
mCasuality = "";
mArrayIndex = "";
mIsArray = false;
mModifiersMap.clear();
}

/*!
Expand Down Expand Up @@ -108,6 +109,8 @@ void ComponentInfo::updateComponentInfo(const ComponentInfo *pComponentInfo)
mCasuality = pComponentInfo->getCausality();
mArrayIndex = pComponentInfo->getArrayIndex();
mIsArray = pComponentInfo->isArray();
mModifiersMap.clear();
mModifiersMap = pComponentInfo->getModifiersMap();
}

/*!
Expand Down Expand Up @@ -202,6 +205,34 @@ void ComponentInfo::parseComponentInfoString(QString value)
}
}

/*!
* \brief ComponentInfo::fetchModifiers
* Fetches the Component modifiers if any.
* \param pOMCProxy
* \param className
*/
void ComponentInfo::fetchModifiers(OMCProxy *pOMCProxy, QString className)
{
mModifiersMap.clear();
QStringList componentModifiersList = pOMCProxy->getComponentModifierNames(className, mName);
foreach (QString componentModifier, componentModifiersList) {
QString originalModifierName = QString(mName).append(".").append(componentModifier);
QString componentModifierValue = pOMCProxy->getComponentModifierValue(className, originalModifierName);
mModifiersMap.insert(componentModifier, componentModifierValue);
}
}

/*!
* \brief ComponentInfo::fetchParameterValue
* Fetches the Component parameter value if any.
* \param pOMCProxy
* \param className
*/
void ComponentInfo::fetchParameterValue(OMCProxy *pOMCProxy, QString className)
{
mParameterValue = pOMCProxy->getParameterValue(className, mName);
}

/*!
* \brief ComponentInfo::setArrayIndex
* Sets the array index
Expand Down Expand Up @@ -231,7 +262,8 @@ bool ComponentInfo::operator==(const ComponentInfo &componentInfo) const
(componentInfo.getStream() == this->getStream()) && (componentInfo.getReplaceable() == this->getReplaceable()) &&
(componentInfo.getVariablity() == this->getVariablity()) && (componentInfo.getInner() == this->getInner()) &&
(componentInfo.getOuter() == this->getOuter()) && (componentInfo.getCausality() == this->getCausality()) &&
(componentInfo.getArrayIndex() == this->getArrayIndex());
(componentInfo.getArrayIndex() == this->getArrayIndex()) && (componentInfo.getModifiersMap() == this->getModifiersMap()) &&
(componentInfo.getParameterValue() == this->getParameterValue());
}

/*!
Expand Down Expand Up @@ -293,11 +325,6 @@ Component::Component(QString name, LibraryTreeItem *pLibraryTreeItem, QString tr
}
setTransform(mTransformation.getTransformationMatrix());
setDialogAnnotation(dialogAnnotation);
// get the component modifier if any
getComponentModifiers();
MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow();
QString className = mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure();
mParameterValue = pMainWindow->getOMCProxy()->getParameterValue(className, getName());
// create actions
createActions();
mpOriginItem = new OriginItem(this);
Expand Down Expand Up @@ -327,8 +354,6 @@ Component::Component(LibraryTreeItem *pLibraryTreeItem, Component *pParentCompon
mpDefaultComponentText = 0;
drawComponent();
setDialogAnnotation(QStringList());
mModifiersMap.clear();
mParameterValue = "";
mpOriginItem = 0;
if (mpLibraryTreeItem) {
connect(mpLibraryTreeItem, SIGNAL(loaded(LibraryTreeItem*)), SLOT(handleLoaded()));
Expand All @@ -350,8 +375,6 @@ Component::Component(Component *pComponent, Component *pParentComponent)
mpDefaultComponentRectangle = 0;
mpDefaultComponentText = 0;
drawComponent();
mModifiersMap.clear();
mParameterValue = "";
mTransformation = Transformation(mpReferenceComponent->mTransformation);
setTransform(mTransformation.getTransformationMatrix());
mpOriginItem = 0;
Expand Down Expand Up @@ -392,8 +415,6 @@ Component::Component(Component *pComponent, GraphicsView *pGraphicsView)
createNonExistingComponent();
createDefaultComponent();
drawComponent();
mModifiersMap.clear();
mParameterValue = "";
mTransformation = Transformation(mpReferenceComponent->mTransformation);
setTransform(mTransformation.getTransformationMatrix());
createActions();
Expand Down Expand Up @@ -762,19 +783,6 @@ void Component::componentParameterHasChanged()
update();
}

void Component::getComponentModifiers()
{
mModifiersMap.clear();
MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow();
QString className = mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getNameStructure();
QStringList componentModifiersList = pMainWindow->getOMCProxy()->getComponentModifierNames(className, getName());
foreach (QString componentModifier, componentModifiersList) {
QString originalModifierName = QString(getName()).append(".").append(componentModifier);
QString componentModifierValue = pMainWindow->getOMCProxy()->getComponentModifierValue(className, originalModifierName);
mModifiersMap.insert(componentModifier, componentModifierValue);
}
}

/*!
* \brief Component::getParameterDisplayString
* Reads the parameters of the component.\n
Expand All @@ -792,13 +800,13 @@ QString Component::getParameterDisplayString(QString parameterName)
*/
QString displayString = "";
/* case 1 */
displayString = mModifiersMap.value(parameterName, "");
displayString = mpComponentInfo->getModifiersMap().value(parameterName, "");
/* case 2 */
if (displayString.isEmpty()) {
if (mpLibraryTreeItem) {
foreach (Component *pComponent, mpLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->getComponentsList()) {
if (pComponent->getComponentInfo()->getName().compare(parameterName) == 0) {
displayString = pComponent->getParameterValue();
displayString = pComponent->getComponentInfo()->getParameterValue();
break;
}
}
Expand Down Expand Up @@ -1323,7 +1331,7 @@ QString Component::getParameterDisplayStringFromExtendsParameters(QString parame
if (pInheritedComponent->getLibraryTreeItem()) {
foreach (Component *pComponent, pInheritedComponent->getLibraryTreeItem()->getModelWidget()->getDiagramGraphicsView()->getComponentsList()) {
if (pComponent->getComponentInfo()->getName().compare(parameterName) == 0) {
displayString = pComponent->getParameterValue();
displayString = pComponent->getComponentInfo()->getParameterValue();
if (!displayString.isEmpty()) {
return displayString;
}
Expand Down Expand Up @@ -1668,7 +1676,7 @@ void Component::duplicate()
newDiagramComponentInfo.setName(oldDiagramComponentInfo.getName());
UpdateComponentAttributesCommand *pUpdateDiagramComponentAttributesCommand;
pUpdateDiagramComponentAttributesCommand = new UpdateComponentAttributesCommand(pDiagramComponent, oldDiagramComponentInfo,
newDiagramComponentInfo, true, mModifiersMap);
newDiagramComponentInfo, true);
mpGraphicsView->getModelWidget()->getUndoStack()->push(pUpdateDiagramComponentAttributesCommand);
setSelected(false);
if (mpGraphicsView->getViewType() == StringHandler::Diagram) {
Expand Down Expand Up @@ -1912,6 +1920,9 @@ void Component::moveCtrlRight()
void Component::showParameters()
{
MainWindow *pMainWindow = mpGraphicsView->getModelWidget()->getModelWidgetContainer()->getMainWindow();
if (pMainWindow->getOMCProxy()->isBuiltinType(mpComponentInfo->getClassName())) {
return;
}
if (!mpLibraryTreeItem || mpLibraryTreeItem->isNonExisting()) {
QMessageBox::critical(pMainWindow, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::error),
tr("Cannot show parameters window for component <b>%1</b>. Did not find type <b>%2</b>.").arg(getName())
Expand Down
12 changes: 8 additions & 4 deletions OMEdit/OMEditGUI/Component/Component.h
Expand Up @@ -70,6 +70,8 @@ class ComponentInfo : public QObject
ComponentInfo(ComponentInfo *pComponentInfo, QObject *pParent = 0);
void updateComponentInfo(const ComponentInfo *pComponentInfo);
void parseComponentInfoString(QString value);
void fetchModifiers(OMCProxy *pOMCProxy, QString className);
void fetchParameterValue(OMCProxy *pOMCProxy, QString className);
void setClassName(QString className) {mClassName = className;}
QString getClassName() const {return mClassName;}
void setName(QString name) {mName = name;}
Expand Down Expand Up @@ -97,6 +99,10 @@ class ComponentInfo : public QObject
void setArrayIndex(QString arrayIndex);
QString getArrayIndex() const {return mArrayIndex;}
bool isArray() const {return mIsArray;}
void setModifiersMap(QMap<QString, QString> modifiersMap) {mModifiersMap = modifiersMap;}
QMap<QString, QString> getModifiersMap() const {return mModifiersMap;}
void setParameterValue(QString parameterValue) {mParameterValue = parameterValue;}
QString getParameterValue() const {return mParameterValue;}
bool operator==(const ComponentInfo &componentInfo) const;
bool operator!=(const ComponentInfo &componentInfo) const;
private:
Expand All @@ -116,6 +122,8 @@ class ComponentInfo : public QObject
QString mCasuality;
QString mArrayIndex;
bool mIsArray;
QMap<QString, QString> mModifiersMap;
QString mParameterValue;
};

class Component : public QObject, public QGraphicsItem
Expand Down Expand Up @@ -148,8 +156,6 @@ 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 @@ -182,7 +188,6 @@ class Component : public QObject, public QGraphicsItem
void emitChanged();
void emitDeleted();
void componentParameterHasChanged();
void getComponentModifiers();
QString getParameterDisplayString(QString parameterName);
void shapeAdded();
void shapeUpdated();
Expand All @@ -203,7 +208,6 @@ class Component : public QObject, public QGraphicsItem
ComponentType mComponentType;
QString mTransformationString;
QStringList mDialogAnnotation;
QMap<QString, QString> mModifiersMap;
QString mParameterValue;
QGraphicsRectItem *mpResizerRectangle;
LineAnnotation *mpNonExistingComponentLine;
Expand Down
18 changes: 10 additions & 8 deletions OMEdit/OMEditGUI/Component/ComponentProperties.cpp
Expand Up @@ -79,7 +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 = mpComponent->getModifiersMap().value("unit");
QString unit = mpComponent->getComponentInfo()->getModifiersMap().value("unit");
if (unit.isEmpty()) {
if (!pOMCProxy->isBuiltinType(mpComponent->getComponentInfo()->getClassName())) {
unit = getUnitFromDerivedClass(mpComponent);
Expand Down Expand Up @@ -613,6 +613,7 @@ void ComponentParameters::createTabsGroupBoxesAndParametersHelper(LibraryTreeIte
}
}
int insertIndex = 0;
pLibraryTreeItem->getModelWidget()->loadDiagramView();
foreach (Component *pComponent, pLibraryTreeItem->getModelWidget()->getDiagramGraphicsView()->getComponentsList()) {
/* Ticket #2531
* Do not show the protected & final parameters.
Expand All @@ -633,7 +634,7 @@ 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) {
QMap<QString, QString> modifiers = pComponent->getModifiersMap();
QMap<QString, QString> modifiers = pComponent->getComponentInfo()->getModifiersMap();
QMap<QString, QString>::iterator modifiersIterator;
for (modifiersIterator = modifiers.begin(); modifiersIterator != modifiers.end(); ++modifiersIterator) {
if (modifiersIterator.key().compare("start") == 0) {
Expand Down Expand Up @@ -717,7 +718,7 @@ void ComponentParameters::fetchComponentModifiers()
if (mpComponent->getReferenceComponent()) {
pComponent = mpComponent->getReferenceComponent();
}
QMap<QString, QString> modifiers = pComponent->getModifiersMap();
QMap<QString, QString> modifiers = pComponent->getComponentInfo()->getModifiersMap();
QMap<QString, QString>::iterator modifiersIterator;
for (modifiersIterator = modifiers.begin(); modifiersIterator != modifiers.end(); ++modifiersIterator) {
QString parameterName = StringHandler::getFirstWordBeforeDot(modifiersIterator.key());
Expand Down Expand Up @@ -826,11 +827,14 @@ Parameter* ComponentParameters::findParameter(const QString &parameter, Qt::Case
void ComponentParameters::updateComponentParameters()
{
bool valueChanged = false;
QMap<QString, QString> newComponentModifiersMap;
// save the Component modifiers
QMap<QString, QString> oldComponentModifiersMap = mpComponent->getComponentInfo()->getModifiersMap();
// new Component modifiers
QMap<QString, QString> newComponentModifiersMap = mpComponent->getComponentInfo()->getModifiersMap();
QMap<QString, QString> newComponentExtendsModifiersMap;
// any parameter changed
foreach (Parameter *pParameter, mParametersList) {
QString componentModifierKey = QString(mpComponent->getName()).append(".").append(pParameter->getNameLabel()->text());
QString componentModifierKey = pParameter->getNameLabel()->text();
QString componentModifierValue = pParameter->getValue();
if (pParameter->isValueModified()) {
valueChanged = true;
Expand Down Expand Up @@ -862,7 +866,7 @@ void ComponentParameters::updateComponentParameters()
modifier = modifier.trimmed();
if (modifierRegExp.exactMatch(modifier)) {
valueChanged = true;
QString componentModifierKey = QString(mpComponent->getName()).append(".").append(modifier.mid(0, modifier.indexOf("(")));
QString componentModifierKey = modifier.mid(0, modifier.indexOf("("));
QString componentModifierValue = modifier.mid(modifier.indexOf("("));
newComponentModifiersMap.insert(componentModifierKey, componentModifierValue);
} else {
Expand All @@ -874,8 +878,6 @@ void ComponentParameters::updateComponentParameters()
}
// if valueChanged is true then put the change in the undo stack.
if (valueChanged) {
// save the Component modifiers
QMap<QString, QString> oldComponentModifiersMap = mpComponent->getModifiersMap();
// save the Component extends modifiers
QMap<QString, QString> oldComponentExtendsModifiersMap;
if (mpComponent->getReferenceComponent()) {
Expand Down

0 comments on commit 9f0aa25

Please sign in to comment.