Skip to content

Commit

Permalink
[NewAPI] Handle connections with new instance based api (#9409)
Browse files Browse the repository at this point in the history
Support for,
- array connections including multi dimensional arrays
- expandable connectors
- connectorSizing
  • Loading branch information
adeas31 committed Sep 21, 2022
1 parent a51a08b commit be3b4e9
Show file tree
Hide file tree
Showing 13 changed files with 777 additions and 419 deletions.
426 changes: 284 additions & 142 deletions OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp

Large diffs are not rendered by default.

47 changes: 25 additions & 22 deletions OMEdit/OMEditLIB/Annotations/LineAnnotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class ExpandableConnectorTreeItem : public QObject
Q_OBJECT
public:
ExpandableConnectorTreeItem();
ExpandableConnectorTreeItem(QString name, bool array, QString arrayIndex, StringHandler::ModelicaClasses restriction, bool newVariable,
ExpandableConnectorTreeItem(QString name, bool array, QStringList arrayIndexes, StringHandler::ModelicaClasses restriction, bool newVariable,
ExpandableConnectorTreeItem *pParentExpandableConnectorTreeItem);
~ExpandableConnectorTreeItem();
bool isRootItem() {return mIsRootItem;}
Expand All @@ -199,8 +199,8 @@ class ExpandableConnectorTreeItem : public QObject
const QString& getName() const {return mName;}
void setArray(bool array) {mArray = array;}
bool isArray() {return mArray;}
void setArrayIndex(QString arrayIndex) {mArrayIndex = arrayIndex;}
const QString& getArrayIndex() const {return mArrayIndex;}
void setArrayIndexes(QStringList arrayIndexes) {mArrayIndexes = arrayIndexes;}
const QStringList& getArrayIndexes() const {return mArrayIndexes;}
void setRestriction(StringHandler::ModelicaClasses restriction) {mRestriction = restriction;}
StringHandler::ModelicaClasses getRestriction() {return mRestriction;}
void setNewVariable(bool newVariable) {mNewVariable = newVariable;}
Expand All @@ -216,7 +216,7 @@ class ExpandableConnectorTreeItem : public QObject
QList<ExpandableConnectorTreeItem*> mChildren;
QString mName;
bool mArray;
QString mArrayIndex;
QStringList mArrayIndexes;
StringHandler::ModelicaClasses mRestriction;
bool mNewVariable;
};
Expand Down Expand Up @@ -247,7 +247,8 @@ class ExpandableConnectorTreeModel : public QAbstractItemModel
Qt::ItemFlags flags(const QModelIndex &index) const override;
QModelIndex findFirstEnabledItem(ExpandableConnectorTreeItem *pExpandableConnectorTreeItem);
QModelIndex expandableConnectorTreeItemIndex(const ExpandableConnectorTreeItem *pExpandableConnectorTreeItem) const;
void createExpandableConnectorTreeItem(Element *pComponent, ExpandableConnectorTreeItem *pParentExpandableConnectorTreeItem);
void createExpandableConnectorTreeItem(ModelInstance::Element *pModelElement, ExpandableConnectorTreeItem *pParentExpandableConnectorTreeItem);
void createExpandableConnectorTreeItem(Element *pElement, ExpandableConnectorTreeItem *pParentExpandableConnectorTreeItem);
private:
CreateConnectionDialog *mpCreateConnectionDialog;
ExpandableConnectorTreeItem *mpRootExpandableConnectorTreeItem;
Expand All @@ -274,10 +275,10 @@ class CreateConnectionDialog : public QDialog
private:
GraphicsView *mpGraphicsView;
LineAnnotation *mpConnectionLineAnnotation;
Element *mpStartComponent;
Element *mpStartRootComponent;
Element *mpEndComponent;
Element *mpEndRootComponent;
Element *mpStartElement;
Element *mpStartRootElement;
Element *mpEndElement;
Element *mpEndRootElement;
Label *mpHeading;
QFrame *mpHorizontalLine;
ExpandableConnectorTreeModel *mpStartExpandableConnectorTreeModel;
Expand All @@ -289,26 +290,28 @@ class CreateConnectionDialog : public QDialog
ExpandableConnectorTreeView *mpEndExpandableConnectorTreeView;
QList<ExpandableConnectorTreeItem*> mEndConnectorsList;
Label *mpIndexesDescriptionLabel;
Label *mpStartRootComponentLabel;
QSpinBox *mpStartRootComponentSpinBox;
Label *mpStartComponentLabel;
QSpinBox *mpStartComponentSpinBox;
Label *mpEndRootComponentLabel;
QSpinBox *mpEndRootComponentSpinBox;
Label *mpEndComponentLabel;
QSpinBox *mpEndComponentSpinBox;
Label *mpStartRootElementLabel;
QList<QSpinBox*> mStartRootElementSpinBoxList;
Label *mpStartElementLabel;
QList<QSpinBox*> mStartElementSpinBoxList;
Label *mpEndRootElementLabel;
QList<QSpinBox*> mEndRootElementSpinBoxList;
Label *mpEndElementLabel;
QList<QSpinBox*> mEndElementSpinBoxList;
QPushButton *mpOkButton;
QPushButton *mpCancelButton;
QDialogButtonBox *mpButtonBox;
QGridLayout *mpMainLayout;
QHBoxLayout *mpConnectionStartHorizontalLayout;
QHBoxLayout *mpConnectionEndHorizontalLayout;

QSpinBox* createSpinBox(QString arrayIndex);
static QString createComponentNameFromLayout(QHBoxLayout *pLayout);
static QString getComponentConnectionName(GraphicsView *pGraphicsView, ExpandableConnectorTreeView *pExpandableConnectorTreeView, QHBoxLayout *pConnectionHorizontalLayout,
Element *pComponent1, Element *pRootComponent1, QSpinBox *pComponentSpinBox1, QSpinBox *pRootComponentSpinBox1,
Element *pComponent2, Element *pRootComponent2, QSpinBox *pComponentSpinBox2, QSpinBox *pRootComponentSpinBox2);
QList<QSpinBox*> createSpinBoxes(Element *pElement);
QList<QSpinBox*> createSpinBoxes(const QStringList &arrayIndexes);
QSpinBox* createSpinBox(QString arrayIndex, int position, int length);
static QString createElementNameFromLayout(QHBoxLayout *pLayout);
static QString getElementConnectionName(GraphicsView *pGraphicsView, ExpandableConnectorTreeView *pExpandableConnectorTreeView, QHBoxLayout *pConnectionHorizontalLayout,
Element *pElement1, Element *pRootElement1, QList<QSpinBox*> elementSpinBoxList1, QList<QSpinBox*> rootElementSpinBoxList1,
Element *pElement2, Element *pRootElement2, QList<QSpinBox*> elementSpinBoxList2, QList<QSpinBox*> rootElementSpinBoxList2);
public slots:
void startConnectorChanged(const QModelIndex &current, const QModelIndex &previous);
void endConnectorChanged(const QModelIndex &current, const QModelIndex &previous);
Expand Down
81 changes: 43 additions & 38 deletions OMEdit/OMEditLIB/Annotations/TextAnnotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
TextAnnotation::TextAnnotation(QString annotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(false, pGraphicsView, 0, 0)
{
mpComponent = 0;
mpElement = 0;
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
// set the default values
Expand All @@ -65,7 +65,7 @@ TextAnnotation::TextAnnotation(QString annotation, GraphicsView *pGraphicsView)
TextAnnotation::TextAnnotation(ModelInstance::Text *pText, bool inherited, GraphicsView *pGraphicsView)
: ShapeAnnotation(inherited, pGraphicsView, 0, 0)
{
mpComponent = 0;
mpElement = 0;
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
mpText = pText;
Expand All @@ -80,7 +80,7 @@ TextAnnotation::TextAnnotation(ModelInstance::Text *pText, bool inherited, Graph
}

TextAnnotation::TextAnnotation(ShapeAnnotation *pShapeAnnotation, Element *pParent)
: ShapeAnnotation(pShapeAnnotation, pParent), mpComponent(pParent)
: ShapeAnnotation(pShapeAnnotation, pParent), mpElement(pParent)
{
mpOriginItem = 0;
updateShape(pShapeAnnotation);
Expand All @@ -89,7 +89,7 @@ TextAnnotation::TextAnnotation(ShapeAnnotation *pShapeAnnotation, Element *pPare
}

TextAnnotation::TextAnnotation(ModelInstance::Text *pText, Element *pParent)
: ShapeAnnotation(pParent), mpComponent(pParent)
: ShapeAnnotation(pParent), mpElement(pParent)
{
mpOriginItem = 0;
mpText = pText;
Expand All @@ -106,7 +106,7 @@ TextAnnotation::TextAnnotation(ModelInstance::Text *pText, Element *pParent)
TextAnnotation::TextAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, pShapeAnnotation, 0)
{
mpComponent = 0;
mpElement = 0;
mpOriginItem = new OriginItem(this);
mpOriginItem->setPassive();
updateShape(pShapeAnnotation);
Expand All @@ -116,14 +116,14 @@ TextAnnotation::TextAnnotation(ShapeAnnotation *pShapeAnnotation, GraphicsView *
}

TextAnnotation::TextAnnotation(Element *pParent)
: ShapeAnnotation(0, pParent), mpComponent(pParent)
: ShapeAnnotation(0, pParent), mpElement(pParent)
{
mpOriginItem = 0;
// set the default values
GraphicItem::setDefaults();
FilledShape::setDefaults();
ShapeAnnotation::setDefaults();
// give a reasonable size to default component text
// give a reasonable size to default element text
mExtents.replace(0, QPointF(-100, -50));
mExtents.replace(1, QPointF(100, 50));
setTextString("%name");
Expand All @@ -135,7 +135,7 @@ TextAnnotation::TextAnnotation(Element *pParent)
TextAnnotation::TextAnnotation(QString annotation, LineAnnotation *pLineAnnotation)
: ShapeAnnotation(0, pLineAnnotation)
{
mpComponent = 0;
mpElement = 0;
mpOriginItem = 0;
// set the default values
GraphicItem::setDefaults();
Expand Down Expand Up @@ -165,7 +165,7 @@ TextAnnotation::TextAnnotation(QString annotation, LineAnnotation *pLineAnnotati
TextAnnotation::TextAnnotation(GraphicsView *pGraphicsView)
: ShapeAnnotation(true, pGraphicsView, 0, 0)
{
mpComponent = 0;
mpElement = 0;
mpOriginItem = 0;
// set the default values
GraphicItem::setDefaults();
Expand Down Expand Up @@ -314,15 +314,15 @@ void TextAnnotation::paint(QPainter *painter, const QStyleOptionGraphicsItem *op
if (mTextString.contains("%") || mTextString.length() > maxTextLengthToShowOnLibraryIcon) {
return;
}
} else if (mpComponent && mpComponent->getGraphicsView()->isRenderingLibraryPixmap()) {
} else if (mpElement && mpElement->getGraphicsView()->isRenderingLibraryPixmap()) {
return;
}
if (mVisible) {
// state machine visualization
// text annotation on a component
if (mpComponent && mpComponent->getLibraryTreeItem() && mpComponent->getLibraryTreeItem()->isState()
&& mpComponent->getGraphicsView()->isVisualizationView()) {
if (mpComponent->isActiveState()) {
// text annotation on a element
if (mpElement && mpElement->getLibraryTreeItem() && mpElement->getLibraryTreeItem()->isState()
&& mpElement->getGraphicsView()->isVisualizationView()) {
if (mpElement->isActiveState()) {
painter->setOpacity(1.0);
} else {
painter->setOpacity(0.2);
Expand Down Expand Up @@ -434,7 +434,7 @@ void TextAnnotation::drawTextAnnotation(QPainter *painter)
}
}
// draw the font
if (mpComponent || mappedBoundingRect.width() != 0 || mappedBoundingRect.height() != 0) {
if (mpElement || mappedBoundingRect.width() != 0 || mappedBoundingRect.height() != 0) {
painter->drawText(mappedBoundingRect, StringHandler::getTextAlignment(mHorizontalAlignment) | Qt::AlignVCenter | Qt::TextDontClip, textToDraw);
}
}
Expand Down Expand Up @@ -543,10 +543,10 @@ void TextAnnotation::updateShape(ShapeAnnotation *pShapeAnnotation)

void TextAnnotation::initUpdateTextString()
{
if (mpComponent) {
if (mpElement) {
if (mTextString.contains("%")) {
updateTextString();
connect(mpComponent, SIGNAL(displayTextChanged()), SLOT(updateTextString()), Qt::UniqueConnection);
connect(mpElement, SIGNAL(displayTextChanged()), SLOT(updateTextString()), Qt::UniqueConnection);
}
}
}
Expand All @@ -567,23 +567,28 @@ void TextAnnotation::updateTextStringHelper(QRegExp regExp)
if (!variable.isEmpty()) {
QString textValue;
/* Ticket:4204
* If we have extend component then call Element::getParameterDisplayString from root component.
* If we have extend element then call Element::getParameterDisplayString from root element.
*/
textValue = mpComponent->getRootParentElement()->getParameterDisplayString(variable);
textValue = mpElement->getRootParentElement()->getParameterDisplayString(variable);
if (!textValue.isEmpty()) {
QString unit = mpComponent->getRootParentElement()->getParameterModifierValue(variable, "unit");
QString displayUnit = mpComponent->getRootParentElement()->getParameterModifierValue(variable, "displayUnit");
Element *pElement = mpComponent->getRootParentElement()->getElementByName(variable);
if (pElement) {
if (displayUnit.isEmpty()) {
displayUnit = pElement->getDerivedClassModifierValue("displayUnit");
}
if (unit.isEmpty()) {
unit = pElement->getDerivedClassModifierValue("unit");
}
// if display unit is still empty then use unit
if (displayUnit.isEmpty()) {
displayUnit = unit;
QString unit = mpElement->getRootParentElement()->getParameterModifierValue(variable, "unit");
QString displayUnit = mpElement->getRootParentElement()->getParameterModifierValue(variable, "displayUnit");
if (MainWindow::instance()->isNewApi()) {
ModelInstance::Element* pModelElement = Element::getModelElementByName(mpElement->getRootParentElement()->getModel(), variable);
//! @todo Fix this once we actually have SI.Resistance as type of Element instead of Real. See issue #9374.
} else {
Element *pElement = mpElement->getRootParentElement()->getElementByName(variable);
if (pElement) {
if (displayUnit.isEmpty()) {
displayUnit = pElement->getDerivedClassModifierValue("displayUnit");
}
if (unit.isEmpty()) {
unit = pElement->getDerivedClassModifierValue("unit");
}
// if display unit is still empty then use unit
if (displayUnit.isEmpty()) {
displayUnit = unit;
}
}
}
// do not do any conversion if unit or displayUnit is empty of if both are 1!
Expand Down Expand Up @@ -631,7 +636,7 @@ void TextAnnotation::updateTextString()
* 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).
* - %name replaced by the name of the element (i.e. the identifier for it in in the enclosing class).
* - %class replaced by the name of the class.
*/
LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(parentItem());
Expand All @@ -644,23 +649,23 @@ void TextAnnotation::updateTextString()
mTextString.prepend(QString("%1: ").arg(pLineAnnotation->getPriority()));
}
}
} else if (mpComponent) {
} else if (mpElement) {
mTextString.reset();

if (!mTextString.contains("%")) {
return;
}
if (MainWindow::instance()->isNewApi()) {
if (mTextString.toLower().contains("%name")) {
mTextString.replace(QRegExp("%name"), mpComponent->getModelElement()->getName());
mTextString.replace(QRegExp("%name"), mpElement->getModelElement()->getName());
}
} else {
if (mTextString.toLower().contains("%name")) {
mTextString.replace(QRegExp("%name"), mpComponent->getName());
mTextString.replace(QRegExp("%name"), mpElement->getName());
}
}
if (mTextString.toLower().contains("%class") && mpComponent->getLibraryTreeItem()) {
mTextString.replace(QRegExp("%class"), mpComponent->getLibraryTreeItem()->getNameStructure());
if (mTextString.toLower().contains("%class") && mpElement->getLibraryTreeItem()) {
mTextString.replace(QRegExp("%class"), mpElement->getLibraryTreeItem()->getNameStructure());
}
if (!mTextString.contains("%")) {
return;
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditLIB/Annotations/TextAnnotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class TextAnnotation : public ShapeAnnotation
void updateShape(ShapeAnnotation *pShapeAnnotation) override;
void setText(ModelInstance::Text *pText) {mpText = pText;}
private:
Element *mpComponent;
Element *mpElement;
ModelInstance::Text *mpText;

void initUpdateTextString();
Expand Down
Loading

0 comments on commit be3b4e9

Please sign in to comment.