Skip to content

Commit

Permalink
Handle the inheritance when animating using DynamicSelect annotation (#…
Browse files Browse the repository at this point in the history
…8623)

Fixes #8607
  • Loading branch information
adeas31 committed Mar 1, 2022
1 parent 76e1b92 commit f425a43
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 194 deletions.
12 changes: 12 additions & 0 deletions OMEdit/OMEditLIB/Annotations/DynamicAnnotation.cpp
Expand Up @@ -82,6 +82,18 @@ void DynamicAnnotation::reset()
}
}

/*!
* \brief DynamicAnnotation::resetDynamicToStatic
* Resets from dynamic to static.
*/
void DynamicAnnotation::resetDynamicToStatic()
{
if (mState == State::Dynamic) {
mState = State::Static;
reset();
}
}

/*!
* \brief DynamicAnnotation::isDynamicSelectExpression
* Returns true if state is not none. DynamicSelect doesn't have state none.
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Annotations/DynamicAnnotation.h
Expand Up @@ -43,6 +43,7 @@ class DynamicAnnotation
void parse(const QString &str);
bool update(double time, Element *parent);
void reset();
void resetDynamicToStatic();
virtual void clear() = 0;
virtual FlatModelica::Expression toExp() const = 0;
bool isDynamicSelectExpression() const;
Expand Down
12 changes: 6 additions & 6 deletions OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp
Expand Up @@ -1000,12 +1000,12 @@ void LineAnnotation::setShapeFlags(bool enable)
if ((mLineType == LineAnnotation::ConnectionType || mLineType == LineAnnotation::TransitionType
|| mLineType == LineAnnotation::InitialStateType || mLineType == LineAnnotation::ShapeType)
&& mpGraphicsView) {
/*
Only set the ItemIsMovable & ItemSendsGeometryChanges flags on Line if the class is not a system library class
AND Line is not an inherited Line AND Line type is not ConnectionType.
*/
/* Only set the ItemIsMovable & ItemSendsGeometryChanges flags on Line if the class is not a system library class
* AND not a visualization view
* AND Line is not an inherited Line AND Line type is not ConnectionType.
*/
bool isSystemLibrary = mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary();
if (!isSystemLibrary && !isInheritedShape() && mLineType != LineAnnotation::ConnectionType &&
if (!isSystemLibrary && !mpGraphicsView->isVisualizationView() && !isInheritedShape() && mLineType != LineAnnotation::ConnectionType &&
mLineType != LineAnnotation::TransitionType && mLineType != LineAnnotation::InitialStateType) {
setFlag(QGraphicsItem::ItemIsMovable, enable);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, enable);
Expand Down Expand Up @@ -2164,7 +2164,7 @@ CreateOrEditTransitionDialog::CreateOrEditTransitionDialog(GraphicsView *pGraphi
// Create the buttons
mpOkButton = new QPushButton(Helper::ok);
mpOkButton->setAutoDefault(true);
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() || mpGraphicsView->isVisualizationView()) {
if (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary()) {
mpOkButton->setDisabled(true);
}
connect(mpOkButton, SIGNAL(clicked()), SLOT(createOrEditTransition()));
Expand Down
75 changes: 52 additions & 23 deletions OMEdit/OMEditLIB/Annotations/ShapeAnnotation.cpp
Expand Up @@ -299,6 +299,8 @@ ShapeAnnotation::ShapeAnnotation(bool inheritedShape, GraphicsView *pGraphicsVie
connect(pShapeAnnotation, SIGNAL(changed()), this, SLOT(referenceShapeChanged()));
connect(pShapeAnnotation, SIGNAL(deleted()), this, SLOT(referenceShapeDeleted()));
}
connect(mpGraphicsView, SIGNAL(updateDynamicSelect(double)), this, SLOT(updateDynamicSelect(double)));
connect(mpGraphicsView, SIGNAL(resetDynamicSelect()), this, SLOT(resetDynamicSelect()));
}

int ShapeAnnotation::maxTextLengthToShowOnLibraryIcon = 2;
Expand Down Expand Up @@ -1041,10 +1043,11 @@ void ShapeAnnotation::moveShape(const qreal dx, const qreal dy)
void ShapeAnnotation::setShapeFlags(bool enable)
{
/* Only set the ItemIsMovable & ItemSendsGeometryChanges flags on shape if the class is not a system library class
* AND not a visualization view.
* AND shape is not an inherited shape.
* AND shape is not a OMS connector i.e., input/output signals of fmu.
*/
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !mpGraphicsView->isVisualizationView() && !isInheritedShape()
&& !(mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS
&& (mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSConnector()
|| mpGraphicsView->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()
Expand All @@ -1062,27 +1065,53 @@ void ShapeAnnotation::setShapeFlags(bool enable)
*/
void ShapeAnnotation::updateDynamicSelect(double time)
{
bool updated = false;

updated |= mVisible.update(time, mpParentComponent);
updated |= mOrigin.update(time, mpParentComponent);
updated |= mRotation.update(time, mpParentComponent);
updated |= mLineColor.update(time, mpParentComponent);
updated |= mFillColor.update(time, mpParentComponent);
updated |= mLineThickness.update(time, mpParentComponent);
updated |= mArrowSize.update(time, mpParentComponent);
updated |= mExtents.update(time, mpParentComponent);
updated |= mRadius.update(time, mpParentComponent);
updated |= mStartAngle.update(time, mpParentComponent);
updated |= mEndAngle.update(time, mpParentComponent);
updated |= mFontSize.update(time, mpParentComponent);
updated |= mTextString.update(time, mpParentComponent);

if (updated) {
update();
if ((mpGraphicsView && mpGraphicsView->isVisualizationView())
|| (mpParentComponent && mpParentComponent->getGraphicsView() && mpParentComponent->getGraphicsView()->isVisualizationView())) {
bool updated = false;

updated |= mVisible.update(time, mpParentComponent);
updated |= mOrigin.update(time, mpParentComponent);
updated |= mRotation.update(time, mpParentComponent);
updated |= mLineColor.update(time, mpParentComponent);
updated |= mFillColor.update(time, mpParentComponent);
updated |= mLineThickness.update(time, mpParentComponent);
updated |= mArrowSize.update(time, mpParentComponent);
updated |= mExtents.update(time, mpParentComponent);
updated |= mRadius.update(time, mpParentComponent);
updated |= mStartAngle.update(time, mpParentComponent);
updated |= mEndAngle.update(time, mpParentComponent);
updated |= mFontSize.update(time, mpParentComponent);
updated |= mTextString.update(time, mpParentComponent);

if (updated) {
update();
}
}
}

/*!
* \brief ShapeAnnotation::resetDynamicSelect
* Resets the DynamicSelect back to static.
*/
void ShapeAnnotation::resetDynamicSelect()
{
mVisible.resetDynamicToStatic();
mOrigin.resetDynamicToStatic();
mRotation.resetDynamicToStatic();
mLineColor.resetDynamicToStatic();
mFillColor.resetDynamicToStatic();
mLineThickness.resetDynamicToStatic();
mArrowSize.resetDynamicToStatic();
mExtents.resetDynamicToStatic();
mRadius.resetDynamicToStatic();
mStartAngle.resetDynamicToStatic();
mEndAngle.resetDynamicToStatic();
mFontSize.resetDynamicToStatic();
mTextString.resetDynamicToStatic();

update();
}

/*!
* \brief ShapeAnnotation::manhattanizeShape
* Slot activated when mpManhattanizeShapeAction triggered signal is raised.\n
Expand Down Expand Up @@ -1785,8 +1814,8 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant &
if (isSelected()) {
setCornerItemsActiveOrPassive();
setCursor(Qt::SizeAllCursor);
/* Only allow manipulations on shapes if the class is not a system library class OR shape is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()) {
/* Only allow manipulations on shapes if the class is not a system library class OR not a visualization view OR shape is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !mpGraphicsView->isVisualizationView() && !isInheritedShape()) {
if (pLineAnnotation) {
connect(mpGraphicsView, SIGNAL(manhattanize()), this, SLOT(manhattanizeShape()), Qt::UniqueConnection);
}
Expand Down Expand Up @@ -1819,8 +1848,8 @@ QVariant ShapeAnnotation::itemChange(GraphicsItemChange change, const QVariant &
} else if (!mIsCornerItemClicked) {
setCornerItemsActiveOrPassive();
unsetCursor();
/* Only allow manipulations on shapes if the class is not a system library class OR shape is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedShape()) {
/* Only allow manipulations on shapes if the class is not a system library class OR not a visualization view OR shape is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !mpGraphicsView->isVisualizationView() && !isInheritedShape()) {
if (pLineAnnotation) {
disconnect(mpGraphicsView, SIGNAL(manhattanize()), this, SLOT(manhattanizeShape()));
}
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Annotations/ShapeAnnotation.h
Expand Up @@ -261,6 +261,7 @@ public slots:
void referenceShapeChanged();
void referenceShapeDeleted();
void updateDynamicSelect(double time);
void resetDynamicSelect();
protected:
GraphicsView *mpGraphicsView;
Element *mpParentComponent;
Expand Down
10 changes: 5 additions & 5 deletions OMEdit/OMEditLIB/Element/CornerItem.cpp
Expand Up @@ -119,7 +119,7 @@ void CornerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option
*/
void CornerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
if (event->button() == Qt::LeftButton && !mpShapeAnnotation->getGraphicsView()->isVisualizationView()) {
if (!signalsBlocked()) {
emit cornerItemPress(mConnectedPointIndex);
}
Expand All @@ -136,7 +136,7 @@ void CornerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
*/
void CornerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (mpShapeAnnotation->isInheritedShape()
if (mpShapeAnnotation->isInheritedShape() && mpShapeAnnotation->getGraphicsView()->isVisualizationView()
|| (mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS
&& (mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSConnector()
|| mpShapeAnnotation->getGraphicsView()->getModelWidget()->getLibraryTreeItem()->getOMSBusConnector()
Expand Down Expand Up @@ -179,7 +179,7 @@ void CornerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void CornerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
if (event->button() == Qt::LeftButton) {
if (event->button() == Qt::LeftButton && !mpShapeAnnotation->getGraphicsView()->isVisualizationView()) {
if (!signalsBlocked()) {
emit cornerItemRelease(mOldScenePosition != scenePos());
}
Expand Down Expand Up @@ -300,7 +300,7 @@ bool ResizerItem::isPressed()
*/
void ResizerItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if (event->button() == Qt::LeftButton) {
if (event->button() == Qt::LeftButton && !mpComponent->getGraphicsView()->isVisualizationView()) {
emit resizerItemPressed(this);
mIsPressed = true;
mResizerItemOldPosition = event->scenePos();
Expand Down Expand Up @@ -331,7 +331,7 @@ void ResizerItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
void ResizerItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
if (event->button() == Qt::LeftButton) {
if (event->button() == Qt::LeftButton && !mpComponent->getGraphicsView()->isVisualizationView()) {
mIsPressed = false;
emit resizerItemReleased();
if (mResizerItemOldPosition != mpComponent->getGraphicsView()->snapPointToGrid(event->scenePos())) {
Expand Down
28 changes: 23 additions & 5 deletions OMEdit/OMEditLIB/Element/Element.cpp
Expand Up @@ -685,6 +685,8 @@ Element::Element(QString name, LibraryTreeItem *pLibraryTreeItem, QString annota
connect(this, SIGNAL(transformHasChanged()), SLOT(updatePlacementAnnotation()));
connect(this, SIGNAL(transformChange(bool)), SLOT(updateOriginItem()));
connect(this, SIGNAL(transformHasChanged()), SLOT(updateOriginItem()));
connect(mpGraphicsView, SIGNAL(updateDynamicSelect(double)), this, SLOT(updateDynamicSelect(double)));
connect(mpGraphicsView, SIGNAL(resetDynamicSelect()), this, SLOT(resetDynamicSelect()));
/* Ticket:4204
* If the child class use text annotation from base class then we need to call this
* since when the base class is created the child class doesn't exist.
Expand Down Expand Up @@ -732,6 +734,8 @@ Element::Element(LibraryTreeItem *pLibraryTreeItem, Element *pParentElement)
connect(mpLibraryTreeItem, SIGNAL(shapeAddedForComponent()), SLOT(handleShapeAdded()));
connect(mpLibraryTreeItem, SIGNAL(componentAddedForComponent()), SLOT(handleElementAdded()));
}
connect(mpGraphicsView, SIGNAL(updateDynamicSelect(double)), this, SLOT(updateDynamicSelect(double)));
connect(mpGraphicsView, SIGNAL(resetDynamicSelect()), this, SLOT(resetDynamicSelect()));
}

Element::Element(Element *pElement, Element *pParentElement, Element *pRootParentElement)
Expand Down Expand Up @@ -775,6 +779,8 @@ Element::Element(Element *pElement, Element *pParentElement, Element *pRootParen
connect(mpReferenceComponent, SIGNAL(transformHasChanged()), SLOT(referenceElementTransformHasChanged()));
connect(mpReferenceComponent, SIGNAL(displayTextChanged()), SLOT(componentNameHasChanged()));
connect(mpReferenceComponent, SIGNAL(deleted()), SLOT(referenceElementDeleted()));
connect(mpGraphicsView, SIGNAL(updateDynamicSelect(double)), this, SLOT(updateDynamicSelect(double)));
connect(mpGraphicsView, SIGNAL(resetDynamicSelect()), this, SLOT(resetDynamicSelect()));
}

Element::Element(Element *pElement, GraphicsView *pGraphicsView)
Expand Down Expand Up @@ -1046,9 +1052,10 @@ CoOrdinateSystem Element::getCoOrdinateSystem() const
void Element::setElementFlags(bool enable)
{
/* Only set the ItemIsMovable & ItemSendsGeometryChanges flags on component if the class is not a system library class
* AND not a visualization view.
* AND component is not an inherited shape.
*/
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedElement()) {
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !mpGraphicsView->isVisualizationView() && !isInheritedElement()) {
setFlag(QGraphicsItem::ItemIsMovable, enable);
setFlag(QGraphicsItem::ItemSendsGeometryChanges, enable);
}
Expand Down Expand Up @@ -3339,15 +3346,26 @@ void Element::updateDynamicSelect(double time)
}
}

void Element::resetDynamicSelect()
{
if (mpLibraryTreeItem && mpLibraryTreeItem->isState()) {
// no need to do anything for state machines case.
} else { // DynamicSelect
foreach (ShapeAnnotation *pShapeAnnotation, mShapesList) {
pShapeAnnotation->resetDynamicSelect();
}
}
}

QVariant Element::itemChange(GraphicsItemChange change, const QVariant &value)
{
QGraphicsItem::itemChange(change, value);
if (change == QGraphicsItem::ItemSelectedHasChanged) {
if (isSelected()) {
showResizerItems();
setCursor(Qt::SizeAllCursor);
// Only allow manipulations on component if the class is not a system library class OR component is not an inherited component.
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedElement()) {
// Only allow manipulations on component if the class is not a system library class OR not a visualization view OR component is not an inherited component.
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !mpGraphicsView->isVisualizationView() && !isInheritedElement()) {
connect(mpGraphicsView, SIGNAL(deleteSignal()), this, SLOT(deleteMe()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseDuplicate()), this, SLOT(duplicate()), Qt::UniqueConnection);
connect(mpGraphicsView, SIGNAL(mouseRotateClockwise()), this, SLOT(rotateClockwise()), Qt::UniqueConnection);
Expand Down Expand Up @@ -3382,8 +3400,8 @@ QVariant Element::itemChange(GraphicsItemChange change, const QVariant &value)
hideResizerItems();
}
unsetCursor();
/* Only allow manipulations on component if the class is not a system library class OR component is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !isInheritedElement()) {
/* Only allow manipulations on component if the class is not a system library class OR not a visualization view OR component is not an inherited component. */
if (!mpGraphicsView->getModelWidget()->getLibraryTreeItem()->isSystemLibrary() && !mpGraphicsView->isVisualizationView() && !isInheritedElement()) {
disconnect(mpGraphicsView, SIGNAL(deleteSignal()), this, SLOT(deleteMe()));
disconnect(mpGraphicsView, SIGNAL(mouseDuplicate()), this, SLOT(duplicate()));
disconnect(mpGraphicsView, SIGNAL(mouseRotateClockwise()), this, SLOT(rotateClockwise()));
Expand Down
1 change: 1 addition & 0 deletions OMEdit/OMEditLIB/Element/Element.h
Expand Up @@ -415,6 +415,7 @@ public slots:
void showSubModelAttributes();
void showElementPropertiesDialog();
void updateDynamicSelect(double time);
void resetDynamicSelect();
protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
};
Expand Down

0 comments on commit f425a43

Please sign in to comment.