Changeset 9770cc8 in OpenModelica


Ignore:
Timestamp:
2021-06-08T14:07:16+02:00 (3 years ago)
Author:
GitHub <noreply@…>
Branches:
Added-citation-metadata, maintenance/v1.18, maintenance/v1.19, maintenance/v1.20, maintenance/v1.21, maintenance/v1.22, maintenance/v1.23, master, omlib-staging
Children:
5dd217b, c162e1ab
Parents:
41f9a35e
git-author:
Adeel Asghar <adeel.asghar@…> (06/08/21 14:07:16)
git-committer:
GitHub <noreply@…> (06/08/21 14:07:16)
Message:

Replaced assert with size checks (#7530)

Location:
OMEdit/OMEditLIB/Annotations
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp

    r16b10d40 r9770cc8  
    962962    if (mPoints.size() == 2 && mpEndComponent) {
    963963      // just check if additional points are really needed or not.
    964       if ((mGeometries[secondLastIndex] == ShapeAnnotation::HorizontalLine && mPoints[lastIndex].y() != point.y()) ||
    965           (mGeometries[secondLastIndex] == ShapeAnnotation::VerticalLine && mPoints[lastIndex].x() != point.x())) {
     964      if (secondLastIndex < mGeometries.size() && ((mGeometries.at(secondLastIndex) == ShapeAnnotation::HorizontalLine && mPoints.at(lastIndex).y() != point.y()) ||
     965                                                   (mGeometries.at(secondLastIndex) == ShapeAnnotation::VerticalLine && mPoints.at(lastIndex).x() != point.x()))) {
    966966        insertPointsGeometriesAndCornerItems(lastIndex);
    967967        setCornerItemsActiveOrPassive();
     
    975975      updateCornerItem(lastIndex);
    976976      /* update the 2nd point */
    977       assert(secondLastIndex < mGeometries.size());
    978       if (mGeometries[secondLastIndex] == ShapeAnnotation::HorizontalLine) {
    979         mPoints[secondLastIndex] = QPointF(mPoints[secondLastIndex].x(), mPoints[secondLastIndex].y() + dy);
    980       } else if (mGeometries[secondLastIndex] == ShapeAnnotation::VerticalLine) {
    981         mPoints[secondLastIndex] = QPointF(mPoints[secondLastIndex].x() + dx, mPoints[secondLastIndex].y());
    982       }
    983       updateCornerItem(secondLastIndex);
     977      if (secondLastIndex < mGeometries.size()) {
     978        if (mGeometries.at(secondLastIndex) == ShapeAnnotation::HorizontalLine) {
     979          mPoints[secondLastIndex] = QPointF(mPoints.at(secondLastIndex).x(), mPoints.at(secondLastIndex).y() + dy);
     980        } else if (mGeometries.at(secondLastIndex) == ShapeAnnotation::VerticalLine) {
     981          mPoints[secondLastIndex] = QPointF(mPoints.at(secondLastIndex).x() + dx, mPoints.at(secondLastIndex).y());
     982        }
     983        updateCornerItem(secondLastIndex);
     984      }
    984985    }
    985986    if (!mpGraphicsView->isCreatingConnection() && !mpGraphicsView->isCreatingTransition()) {
     
    12821283    updateOMSConnection();
    12831284  } else {
    1284     assert(!mOldAnnotation.isEmpty());
    1285     if (mLineType == LineAnnotation::ConnectionType) {
    1286       mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateConnectionCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
    1287     } else if (mLineType == LineAnnotation::TransitionType) {
    1288       mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateTransitionCommand(this, mCondition, mImmediate, mReset,
    1289                                                                                          mSynchronize, mPriority, mOldAnnotation,
    1290                                                                                          mCondition, mImmediate, mReset, mSynchronize,
    1291                                                                                          mPriority, getOMCShapeAnnotation()));
    1292     } else if (mLineType == LineAnnotation::InitialStateType) {
    1293       mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateInitialStateCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
     1285    if (!mOldAnnotation.isEmpty()) {
     1286      if (mLineType == LineAnnotation::ConnectionType) {
     1287        mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateConnectionCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
     1288      } else if (mLineType == LineAnnotation::TransitionType) {
     1289        mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateTransitionCommand(this, mCondition, mImmediate, mReset,
     1290                                                                                           mSynchronize, mPriority, mOldAnnotation,
     1291                                                                                           mCondition, mImmediate, mReset, mSynchronize,
     1292                                                                                           mPriority, getOMCShapeAnnotation()));
     1293      } else if (mLineType == LineAnnotation::InitialStateType) {
     1294        mpGraphicsView->getModelWidget()->getUndoStack()->push(new UpdateInitialStateCommand(this, mOldAnnotation, getOMCShapeAnnotation()));
     1295      }
    12941296    }
    12951297  }
  • OMEdit/OMEditLIB/Annotations/ShapeAnnotation.cpp

    r8e569a04 r9770cc8  
    770770  if (dynamic_cast<LineAnnotation*>(this) || dynamic_cast<PolygonAnnotation*>(this)) {
    771771    for (int i = 0 ; i < mCornerItemsList.size() ; i++) {
    772       assert(mPoints.size() > i);
    773       mCornerItemsList.at(i)->setPos(QPointF(mPoints.at(i).x(), mPoints.at(i).y()));
     772      if (mPoints.size() > i) {
     773        mCornerItemsList.at(i)->setPos(QPointF(mPoints.at(i).x(), mPoints.at(i).y()));
     774      }
    774775    }
    775776  } else {
    776     assert(mExtents.size() > 1);
    777     QPointF extent1 = QPointF(qMin(mExtents.at(0).x(), mExtents.at(1).x()), qMin(mExtents.at(0).y(), mExtents.at(1).y()));
    778     QPointF extent2 = QPointF(qMax(mExtents.at(0).x(), mExtents.at(1).x()), qMax(mExtents.at(0).y(), mExtents.at(1).y()));
    779     if (mCornerItemsList.size() > 1) {
    780       mCornerItemsList.at(0)->setPos(QPointF(extent1.x(), extent1.y()));
    781       mCornerItemsList.at(1)->setPos(QPointF(extent2.x(), extent2.y()));
     777    if (mExtents.size() > 1) {
     778      QPointF extent1 = QPointF(qMin(mExtents.at(0).x(), mExtents.at(1).x()), qMin(mExtents.at(0).y(), mExtents.at(1).y()));
     779      QPointF extent2 = QPointF(qMax(mExtents.at(0).x(), mExtents.at(1).x()), qMax(mExtents.at(0).y(), mExtents.at(1).y()));
     780      if (mCornerItemsList.size() > 1) {
     781        mCornerItemsList.at(0)->setPos(QPointF(extent1.x(), extent1.y()));
     782        mCornerItemsList.at(1)->setPos(QPointF(extent2.x(), extent2.y()));
     783      }
    782784    }
    783785  }
     
    804806void ShapeAnnotation::replaceExtent(const int index, const QPointF point)
    805807{
    806   assert(mExtents.size() > 1);
    807   assert(index >= 0 && index <= 1);
    808 
    809   prepareGeometryChange();
    810   mExtents.replace(index, point);
     808  if (mExtents.size() > 1 && index >= 0 && index <= 1) {
     809    prepareGeometryChange();
     810    mExtents.replace(index, point);
     811  }
    811812}
    812813
     
    819820void ShapeAnnotation::updateExtent(const int index, const QPointF point)
    820821{
    821   assert(mExtents.size() > 1);
    822   assert(index >= 0 && index <= 1);
    823 
    824   prepareGeometryChange();
    825   mExtents.replace(index, point);
    826 
     822  if (mExtents.size() > 1 && index >= 0 && index <= 1) {
     823    prepareGeometryChange();
     824    mExtents.replace(index, point);
     825  }
    827826  applyTransformation();
    828827}
     
    15501549void ShapeAnnotation::cornerItemReleased(const bool changed)
    15511550{
    1552   assert(!mOldAnnotation.isEmpty());
    1553 
    1554   if (changed) {
    1555     ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
    1556     LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(this);
    1557 
    1558     if (pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
    1559       if (pLineAnnotation) {
    1560         pLineAnnotation->updateOMSConnection();
    1561         pModelWidget->createOMSimulatorUndoCommand(QString("Update OMS Connection connect(%1, %2)").arg(pLineAnnotation->getStartComponentName(), pLineAnnotation->getEndComponentName()));
     1551  if (!mOldAnnotation.isEmpty()) {
     1552    if (changed) {
     1553      ModelWidget *pModelWidget = mpGraphicsView->getModelWidget();
     1554      LineAnnotation *pLineAnnotation = dynamic_cast<LineAnnotation*>(this);
     1555
     1556      if (pModelWidget->getLibraryTreeItem()->getLibraryType() == LibraryTreeItem::OMS) {
     1557        if (pLineAnnotation) {
     1558          pLineAnnotation->updateOMSConnection();
     1559          pModelWidget->createOMSimulatorUndoCommand(QString("Update OMS Connection connect(%1, %2)").arg(pLineAnnotation->getStartComponentName(), pLineAnnotation->getEndComponentName()));
     1560          pModelWidget->updateModelText();
     1561          return;
     1562        }
     1563      } else {
     1564        if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) {
     1565          manhattanizeShape(false);
     1566          removeRedundantPointsGeometriesAndCornerItems();
     1567          // Call getOMCShapeAnnotation() after manhattanizeShape() and removeRedundantPointsGeometriesAndCornerItems() to get a correct new annotation
     1568          QString newAnnotation = getOMCShapeAnnotation();
     1569          pModelWidget->getUndoStack()->push(new UpdateConnectionCommand(pLineAnnotation, mOldAnnotation, newAnnotation));
     1570        } else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::TransitionType) {
     1571          manhattanizeShape(false);
     1572          removeRedundantPointsGeometriesAndCornerItems();
     1573          QString newAnnotation = getOMCShapeAnnotation();
     1574          pModelWidget->getUndoStack()->push(new UpdateTransitionCommand(pLineAnnotation, pLineAnnotation->getCondition(), pLineAnnotation->getImmediate(),
     1575                                                                         pLineAnnotation->getReset(), pLineAnnotation->getSynchronize(), pLineAnnotation->getPriority(),
     1576                                                                         mOldAnnotation, pLineAnnotation->getCondition(), pLineAnnotation->getImmediate(),
     1577                                                                         pLineAnnotation->getReset(), pLineAnnotation->getSynchronize(), pLineAnnotation->getPriority(), newAnnotation));
     1578        } else {
     1579          QString newAnnotation = getOMCShapeAnnotation();
     1580          pModelWidget->getUndoStack()->push(new UpdateShapeCommand(this, mOldAnnotation, newAnnotation));
     1581          pModelWidget->updateClassAnnotationIfNeeded();
     1582        }
    15621583        pModelWidget->updateModelText();
    1563         return;
    15641584      }
    15651585    } else {
    1566       if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::ConnectionType) {
    1567         manhattanizeShape(false);
    1568         removeRedundantPointsGeometriesAndCornerItems();
    1569         // Call getOMCShapeAnnotation() after manhattanizeShape() and removeRedundantPointsGeometriesAndCornerItems() to get a correct new annotation
    1570         QString newAnnotation = getOMCShapeAnnotation();
    1571         pModelWidget->getUndoStack()->push(new UpdateConnectionCommand(pLineAnnotation, mOldAnnotation, newAnnotation));
    1572       } else if (pLineAnnotation && pLineAnnotation->getLineType() == LineAnnotation::TransitionType) {
    1573         manhattanizeShape(false);
    1574         removeRedundantPointsGeometriesAndCornerItems();
    1575         QString newAnnotation = getOMCShapeAnnotation();
    1576         pModelWidget->getUndoStack()->push(new UpdateTransitionCommand(pLineAnnotation, pLineAnnotation->getCondition(), pLineAnnotation->getImmediate(),
    1577                                                                        pLineAnnotation->getReset(), pLineAnnotation->getSynchronize(), pLineAnnotation->getPriority(),
    1578                                                                        mOldAnnotation, pLineAnnotation->getCondition(), pLineAnnotation->getImmediate(),
    1579                                                                        pLineAnnotation->getReset(), pLineAnnotation->getSynchronize(), pLineAnnotation->getPriority(), newAnnotation));
    1580       } else {
    1581         QString newAnnotation = getOMCShapeAnnotation();
    1582         pModelWidget->getUndoStack()->push(new UpdateShapeCommand(this, mOldAnnotation, newAnnotation));
    1583         pModelWidget->updateClassAnnotationIfNeeded();
    1584       }
    1585       pModelWidget->updateModelText();
    1586     }
    1587   } else {
    1588     parseShapeAnnotation(mOldAnnotation);
    1589     applyTransformation();
     1586      parseShapeAnnotation(mOldAnnotation);
     1587      applyTransformation();
     1588    }
    15901589  }
    15911590
Note: See TracChangeset for help on using the changeset viewer.