Skip to content

Commit

Permalink
OMEdit fixes for 1.23 (#12317)
Browse files Browse the repository at this point in the history
* Attempt to fix the random crashes in Element::updateDynamicSelect (#12264)

Call deleteLater instead of directly deleting the item.
This will cause the event loop to delete the item after all pending events have been delivered to it.

* Remove OMShellLib. (#12281)

- The issue started with OMShell reporting
    `qt.svg: Cannot open file ':/Resources/omshell-large.svg', because: No such file or directory`
    at startup on Linux.

    The qrc file was added in the lib sources instead of the executable
    sources. This works fine on Windows but not on Linux.

    As it turns out there is no need to have OMShellLib anyway. It is now
    removed and the sources for it are moved to OMShell.

* Fix crash when creating a transition (#12283)

* Trim whitespace instead of removing spaces from the variables name (#12284)

* Trim whitespace instead of removing spaces from the variables name

#12235

* Run the test

* Remove leading and trailing whitespace

* Create a connection without calling getModelInstance (#12312)

#11920

* Assume visible=true when the expression evaluation fails (#12314)

---------

Co-authored-by: Mahder Gebremedhin <mahge@users.noreply.github.com>
  • Loading branch information
adeas31 and mahge committed Apr 25, 2024
1 parent eb2a157 commit 0bbd735
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 226 deletions.
36 changes: 23 additions & 13 deletions OMCompiler/SimulationRuntime/c/util/read_matlab4.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,27 @@ void omc_free_matlab4_reader(ModelicaMatReader *reader)
}
}

void remSpaces(char *ch){
char *ch2 = ch;
unsigned int ui = 0;
unsigned int uj = 0;

for(ui=0;ui<=strlen(ch);ui++){
if(ch[ui]!=' '){
ch2[uj] = ch[ui];
uj++;
}
}
void trimWhitespace(char *str)
{
char *start = str;
char *end;
size_t len = strlen(str);
if (len > 0 && (isspace(*start) || isspace(str[len-1]))) {
/* find first non-whitespace */
while (isspace(*start)) {
++start;
}
/* find last non-whitespace */
end = start + strlen(start) - 1;
while (end > str && isspace(*end)) {
--end;
}
len = end - start + 1;
/* shift the string to remove leading whitespace */
if (start != str) memmove(str, start, len);
/* terminate the string to remove trailing whitespace */
*(str+len) = '\0';
}
}

/* Read n elements into str; convert from double if necessary, etc */
Expand Down Expand Up @@ -311,7 +321,7 @@ const char* omc_new_matlab4_reader(const char *filename, ModelicaMatReader *read
reader->allInfo[k].name[hdr.mrows] = '\0';
reader->allInfo[k].isParam = -1;
reader->allInfo[k].index = -1;
remSpaces(reader->allInfo[k].name);
trimWhitespace(reader->allInfo[k].name);
/* fprintf(stderr, " Adding variable '%s'\n", reader->allInfo[k].name); */
}
}
Expand All @@ -329,7 +339,7 @@ const char* omc_new_matlab4_reader(const char *filename, ModelicaMatReader *read
reader->allInfo[k].name[hdr.ncols] = '\0';
reader->allInfo[k].isParam = -1;
reader->allInfo[k].index = -1;
remSpaces(reader->allInfo[k].name);
trimWhitespace(reader->allInfo[k].name);
/* fprintf(stderr, " Adding variable '%s'\n", reader->allInfo[k].name); */
}
free(tmp);
Expand Down
52 changes: 11 additions & 41 deletions OMEdit/OMEditLIB/Annotations/LineAnnotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1573,10 +1573,6 @@ void LineAnnotation::updateConnectionAnnotation()
CompositeModelEditor *pCompositeModelEditor = dynamic_cast<CompositeModelEditor*>(mpGraphicsView->getModelWidget()->getEditor());
pCompositeModelEditor->updateConnection(this);
} else {
// update the ModelInstance::Line with new annotation
if (mpGraphicsView->getModelWidget()->isNewApi()) {
updateLine();
}
// get the connection line annotation.
QString annotationString = QString("annotate=$annotation(%1)").arg(getShapeAnnotation());
// update the connection
Expand Down Expand Up @@ -2108,8 +2104,8 @@ ExpandableConnectorTreeView::ExpandableConnectorTreeView(CreateConnectionDialog
* \param pConnectionLineAnnotation
* \param pParent
*/
CreateConnectionDialog::CreateConnectionDialog(GraphicsView *pGraphicsView, LineAnnotation *pConnectionLineAnnotation, QWidget *pParent)
: QDialog(pParent), mpGraphicsView(pGraphicsView), mpConnectionLineAnnotation(pConnectionLineAnnotation)
CreateConnectionDialog::CreateConnectionDialog(GraphicsView *pGraphicsView, LineAnnotation *pConnectionLineAnnotation, bool createConnector, QWidget *pParent)
: QDialog(pParent), mpGraphicsView(pGraphicsView), mpConnectionLineAnnotation(pConnectionLineAnnotation), mCreateConnector(createConnector)
{
setWindowTitle(QString(Helper::applicationName).append(" - ").append(Helper::createConnection));
setAttribute(Qt::WA_DeleteOnClose);
Expand Down Expand Up @@ -2598,16 +2594,17 @@ void CreateConnectionDialog::createConnection()
mpConnectionLineAnnotation->setStartElementName(startElementName);
mpConnectionLineAnnotation->setEndElementName(endElementName);
if (mpGraphicsView->getModelWidget()->isNewApi()) {
if (mpGraphicsView->getModelWidget()->getModelInstance()->isValidConnection(startElementName, endElementName)) {
mpConnectionLineAnnotation->setLine(new ModelInstance::Line(mpGraphicsView->getModelWidget()->getModelInstance()));
mpConnectionLineAnnotation->updateLine();
/* Issue #12163. Do not check connection validity when called from GraphicsView::createConnector
* GraphicsView::createConnector creates an incomplete connector. We do this for performance reasons. Avoid calling getModelInstance API.
* We know for sure that both connectors are compatible in this case so its okay not to check for validity.
*/
if (mCreateConnector) {
mpConnectionLineAnnotation->drawCornerItems();
mpConnectionLineAnnotation->setCornerItemsActiveOrPassive();
ModelInfo oldModelInfo = mpGraphicsView->getModelWidget()->createModelInfo();
mpGraphicsView->addConnectionToView(mpConnectionLineAnnotation, false);
mpGraphicsView->addConnectionToClass(mpConnectionLineAnnotation);
ModelInfo newModelInfo = mpGraphicsView->getModelWidget()->createModelInfo();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new OMCUndoCommand(mpGraphicsView->getModelWidget()->getLibraryTreeItem(), oldModelInfo, newModelInfo, "Add Connection"));
} else if (mpGraphicsView->getModelWidget()->getModelInstance()->isValidConnection(startElementName, endElementName)) {
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddConnectionCommand(mpConnectionLineAnnotation, true));
mpGraphicsView->getModelWidget()->updateModelText();
} else {
QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName, Helper::error),
Expand Down Expand Up @@ -2735,20 +2732,8 @@ void CreateOrEditTransitionDialog::createOrEditTransition()
mpPrioritySpinBox->value(),
mpTransitionLineAnnotation->getOMCShapeAnnotation()));
} else {
if (mpGraphicsView->getModelWidget()->isNewApi()) {
mpTransitionLineAnnotation->setLine(new ModelInstance::Line(mpGraphicsView->getModelWidget()->getModelInstance()));
mpTransitionLineAnnotation->updateLine();
mpTransitionLineAnnotation->drawCornerItems();
mpTransitionLineAnnotation->setCornerItemsActiveOrPassive();
ModelInfo oldModelInfo = mpGraphicsView->getModelWidget()->createModelInfo();
mpGraphicsView->addTransitionToView(mpTransitionLineAnnotation, false);
mpGraphicsView->addTransitionToClass(mpTransitionLineAnnotation);
ModelInfo newModelInfo = mpGraphicsView->getModelWidget()->createModelInfo();
mpGraphicsView->getModelWidget()->getUndoStack()->push(new OMCUndoCommand(mpGraphicsView->getModelWidget()->getLibraryTreeItem(), oldModelInfo, newModelInfo, "Add Transition"));
} else {
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddTransitionCommand(mpTransitionLineAnnotation, true));
//mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitConnectionAdded(mpTransitionLineAnnotation);
}
mpGraphicsView->getModelWidget()->getUndoStack()->push(new AddTransitionCommand(mpTransitionLineAnnotation, true));
//mpGraphicsView->getModelWidget()->getLibraryTreeItem()->emitConnectionAdded(mpTransitionLineAnnotation);
}
mpGraphicsView->getModelWidget()->updateModelText();
accept();
Expand All @@ -2764,21 +2749,6 @@ void LineAnnotation::setProperties(const QString& condition, const bool immediat
getTextAnnotation()->setTextString("%condition");
}

/*!
* \brief LineAnnotation::updateLine
* Updates the Line object with the annotation.
*/
void LineAnnotation::updateLine()
{
mpLine->setPoints(mPoints);
mpLine->setColor(mLineColor);
mpLine->setPattern(mLinePattern);
mpLine->setThickness(mLineThickness);
mpLine->setArrow(mArrow);
mpLine->setArrowSize(mArrowSize);
mpLine->setSmooth(mSmooth);
}

void LineAnnotation::updateTransistion(const QString& condition, const bool immediate, const bool rest, const bool synchronize, const int priority)
{
getTextAnnotation()->updateTextString();
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/Annotations/LineAnnotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class LineAnnotation : public ShapeAnnotation
void showOMSConnection();
void updateTransistion(const QString& condition, const bool immediate, const bool rest, const bool synchronize, const int priority);
void setProperties(const QString& condition, const bool immediate, const bool rest, const bool synchronize, const int priority);
void updateLine();

static QColor findLineColorForConnection(Element *pComponent);
void clearCollidingConnections();
Expand Down Expand Up @@ -285,10 +284,11 @@ class CreateConnectionDialog : public QDialog
{
Q_OBJECT
public:
CreateConnectionDialog(GraphicsView *pGraphicsView, LineAnnotation *pConnectionLineAnnotation, QWidget *pParent = 0);
CreateConnectionDialog(GraphicsView *pGraphicsView, LineAnnotation *pConnectionLineAnnotation, bool createConnector, QWidget *pParent = 0);
private:
GraphicsView *mpGraphicsView;
LineAnnotation *mpConnectionLineAnnotation;
bool mCreateConnector;
Element *mpStartElement;
Element *mpStartRootElement;
Element *mpEndElement;
Expand Down
4 changes: 2 additions & 2 deletions OMEdit/OMEditLIB/Annotations/TextAnnotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ TextAnnotation::TextAnnotation(QString annotation, LineAnnotation *pLineAnnotati
*/
if (pLineAnnotation->getPoints().size() > 0) {
if (pLineAnnotation->getImmediate()) {
setPos(pLineAnnotation->getPoints().at(mPoints.size() - 1));
setPos(pLineAnnotation->getPoints().at(pLineAnnotation->getPoints().size() - 1));
} else {
setPos(pLineAnnotation->getPoints().at(0));
}
Expand All @@ -175,7 +175,7 @@ TextAnnotation::TextAnnotation(ModelInstance::Text *pText, LineAnnotation *pLine
*/
if (pLineAnnotation->getPoints().size() > 0) {
if (pLineAnnotation->getImmediate()) {
setPos(pLineAnnotation->getPoints().at(mPoints.size() - 1));
setPos(pLineAnnotation->getPoints().at(pLineAnnotation->getPoints().size() - 1));
} else {
setPos(pLineAnnotation->getPoints().at(0));
}
Expand Down

0 comments on commit 0bbd735

Please sign in to comment.