Skip to content

Commit

Permalink
ticket:3488
Browse files Browse the repository at this point in the history
Write the __OpenModelica_simulationFlags annotation based on the settings used in SimulationDialog
Read the __OpenModelica_simulationFlags and apply it them to simulation.
  • Loading branch information
adeas31 committed Jun 3, 2016
1 parent b85235d commit 06da538
Show file tree
Hide file tree
Showing 9 changed files with 414 additions and 130 deletions.
31 changes: 31 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.cpp
Expand Up @@ -1081,6 +1081,37 @@ void UpdateClassExperimentAnnotationCommand::undo()
mpMainWindow->getOMCProxy()->addClassAnnotation(mpLibraryTreeItem->getNameStructure(), mOldExperimentAnnotation);
}

UpdateClassSimulationFlagsAnnotationCommand::UpdateClassSimulationFlagsAnnotationCommand(MainWindow *pMainWindow,
LibraryTreeItem *pLibraryTreeItem,
QString oldSimulationFlags,
QString newSimulationFlags, QUndoCommand *pParent)
: QUndoCommand(pParent)
{
mpMainWindow = pMainWindow;
mpLibraryTreeItem = pLibraryTreeItem;
mOldSimulationFlags = oldSimulationFlags;
mNewSimulationFlags = newSimulationFlags;
setText(QString("Update %1 simulation flags annotation").arg(mpLibraryTreeItem->getNameStructure()));
}

/*!
* \brief UpdateClassSimulationFlagsAnnotationCommand::redo
* Redo the UpdateClassSimulationFlagsAnnotationCommand.
*/
void UpdateClassSimulationFlagsAnnotationCommand::redo()
{
mpMainWindow->getOMCProxy()->addClassAnnotation(mpLibraryTreeItem->getNameStructure(), mNewSimulationFlags);
}

/*!
* \brief UpdateClassSimulationFlagsAnnotationCommand::undo
* Undo the UpdateClassSimulationFlagsAnnotationCommand.
*/
void UpdateClassSimulationFlagsAnnotationCommand::undo()
{
mpMainWindow->getOMCProxy()->addClassAnnotation(mpLibraryTreeItem->getNameStructure(), mOldSimulationFlags);
}

UpdateSubModelAttributesCommand::UpdateSubModelAttributesCommand(Component *pComponent, const ComponentInfo &oldComponentInfo,
const ComponentInfo &newComponentInfo, QUndoCommand *pParent)
: QUndoCommand(pParent)
Expand Down
14 changes: 14 additions & 0 deletions OMEdit/OMEditGUI/Modeling/Commands.h
Expand Up @@ -229,6 +229,20 @@ class UpdateClassExperimentAnnotationCommand : public QUndoCommand
QString mNewExperimentAnnotation;
};

class UpdateClassSimulationFlagsAnnotationCommand : public QUndoCommand
{
public:
UpdateClassSimulationFlagsAnnotationCommand(MainWindow *pMainWindow, LibraryTreeItem *pLibraryTreeItem, QString oldSimulationFlags,
QString newSimulationFlags, QUndoCommand *pParent = 0);
void redo();
void undo();
private:
MainWindow *mpMainWindow;
LibraryTreeItem *mpLibraryTreeItem;
QString mOldSimulationFlags;
QString mNewSimulationFlags;
};

class UpdateSubModelAttributesCommand : public QUndoCommand
{
public:
Expand Down
10 changes: 4 additions & 6 deletions OMEdit/OMEditGUI/Modeling/ModelWidgetContainer.cpp
Expand Up @@ -3878,9 +3878,8 @@ bool ModelWidget::metaModelEditorTextChanged()
*/
void ModelWidget::handleCanUndoChanged(bool canUndo)
{
if (isVisible()) {
mpModelWidgetContainer->getMainWindow()->getUndoAction()->setEnabled(canUndo);
}
Q_UNUSED(canUndo);
updateUndoRedoActions();
}

/*!
Expand All @@ -3890,9 +3889,8 @@ void ModelWidget::handleCanUndoChanged(bool canUndo)
*/
void ModelWidget::handleCanRedoChanged(bool canRedo)
{
if (isVisible()) {
mpModelWidgetContainer->getMainWindow()->getRedoAction()->setEnabled(canRedo);
}
Q_UNUSED(canRedo);
updateUndoRedoActions();
}

void ModelWidget::closeEvent(QCloseEvent *event)
Expand Down
58 changes: 54 additions & 4 deletions OMEdit/OMEditGUI/OMC/OMCProxy.cpp
Expand Up @@ -1042,9 +1042,11 @@ bool OMCProxy::setExtendsModifierValue(QString className, QString extendsClassNa
if (modifierValue.isEmpty()) {
expression = QString("setExtendsModifierValue(%1, %2, %3, $Code(()))").arg(className).arg(extendsClassName).arg(modifierName);
} else if (modifierValue.startsWith("(")) {
expression = QString("setExtendsModifierValue(%1, %2, %3, $Code(%4))").arg(className).arg(extendsClassName).arg(modifierName).arg(modifierValue);
expression = QString("setExtendsModifierValue(%1, %2, %3, $Code(%4))").arg(className).arg(extendsClassName).arg(modifierName)
.arg(modifierValue);
} else {
expression = QString("setExtendsModifierValue(%1, %2, %3, $Code(=%4))").arg(className).arg(extendsClassName).arg(modifierName).arg(modifierValue);
expression = QString("setExtendsModifierValue(%1, %2, %3, $Code(=%4))").arg(className).arg(extendsClassName).arg(modifierName)
.arg(modifierValue);
}
sendCommand(expression);
if (getResult().toLower().contains("ok")) {
Expand Down Expand Up @@ -1426,7 +1428,8 @@ bool OMCProxy::createClass(QString type, QString className, LibraryTreeItem *pEx
if (!pExtendsLibraryTreeItem) {
expression = QString("%1 %2 end %3;").arg(type).arg(className).arg(className);
} else {
expression = QString("%1 %2 extends %3; end %4;").arg(type).arg(className).arg(pExtendsLibraryTreeItem->getNameStructure()).arg(className);
expression = QString("%1 %2 extends %3; end %4;").arg(type).arg(className).arg(pExtendsLibraryTreeItem->getNameStructure())
.arg(className);
}
return loadString(expression, className, Helper::utf8, false, false);
}
Expand Down Expand Up @@ -2088,7 +2091,8 @@ QString OMCProxy::importFMU(QString fmuName, QString outputDirectory, int logLev
bool generateOutputConnectors)
{
outputDirectory = outputDirectory.isEmpty() ? "<default>" : outputDirectory;
QString fmuFileName = mpOMCInterface->importFMU(fmuName, outputDirectory, logLevel, true, debugLogging, generateInputConnectors, generateOutputConnectors);
QString fmuFileName = mpOMCInterface->importFMU(fmuName, outputDirectory, logLevel, true, debugLogging, generateInputConnectors,
generateOutputConnectors);
printMessagesStringInternal();
return fmuFileName;
}
Expand Down Expand Up @@ -2364,6 +2368,52 @@ QString OMCProxy::getCommandLineOptionsAnnotation(QString className)
return StringHandler::unparse(StringHandler::removeFirstLastCurlBrackets(getResult()));
}

/*!
* \brief OMCProxy::getAnnotationNamedModifiers
* Returns the list of modifiers of the named annotation.
* \param className
* \param annotation
* \return
*/
QList<QString> OMCProxy::getAnnotationNamedModifiers(QString className, QString annotation)
{
QList<QString> result = mpOMCInterface->getAnnotationNamedModifiers(className, annotation);
if (result.isEmpty()) {
printMessagesStringInternal();
}
return result;
}

/*!
* \brief OMCProxy::getAnnotationModifierValue
* Returns the value of the named annotation modifier.
* \param className
* \param annotation
* \param modifier
* \return
*/
QString OMCProxy::getAnnotationModifierValue(QString className, QString annotation, QString modifier)
{
return mpOMCInterface->getAnnotationModifierValue(className, annotation, modifier);
}

/*!
* \brief OMCProxy::getSimulationFlagsAnnotation
* Returns the __OpenModelica_simulationFlags annotation as string.
* \param className
* \return
*/
QString OMCProxy::getSimulationFlagsAnnotation(QString className)
{
QStringList modifiers;
QList<QString> simulationFlags = getAnnotationNamedModifiers(className, "__OpenModelica_simulationFlags");
foreach (QString simulationFlag, simulationFlags) {
modifiers.append(QString("%1=\"%2\"").arg(simulationFlag)
.arg(getAnnotationModifierValue(className, "__OpenModelica_simulationFlags", simulationFlag)));
}
return QString("__OpenModelica_simulationFlags(%1)").arg(modifiers.join(","));
}

/*!
* \brief OMCProxy::numProcessors
* Gets the number of processors.
Expand Down
3 changes: 3 additions & 0 deletions OMEdit/OMEditGUI/OMC/OMCProxy.h
Expand Up @@ -217,6 +217,9 @@ class OMCProxy : public QObject
QList<QString> getDerivedUnits(QString baseUnit);
bool getDocumentationClassAnnotation(QString className);
QString getCommandLineOptionsAnnotation(QString className);
QList<QString> getAnnotationNamedModifiers(QString className, QString annotation);
QString getAnnotationModifierValue(QString className, QString annotation, QString modifier);
QString getSimulationFlagsAnnotation(QString className);
int numProcessors();
QString help(QString topic);
OMCInterface::getConfigFlagValidOptions_res getConfigFlagValidOptions(QString topic);
Expand Down

0 comments on commit 06da538

Please sign in to comment.