Fixed om emission

This commit is contained in:
2026-07-20 18:17:45 +02:00
parent d368b36b8c
commit 4cfe7c3a0e
6 changed files with 301 additions and 21 deletions

View File

@@ -86,7 +86,7 @@ def emit_model(
del id_list # Kept in the public API for compiler extensions and inspection. del id_list # Kept in the public API for compiler extensions and inspection.
indentation = "\t" * indent indentation = "\t" * indent
body_indent = "\t" * (indent + 1) body_indent = "\t" * (indent + 1)
model_name = identifier(graph["id"]) model_name = model_name_for(graph)
lines = [f"{indentation}model {model_name}"] lines = [f"{indentation}model {model_name}"]
implementation = graph.get("implementation", {}) implementation = graph.get("implementation", {})
implementation_kind = implementation.get("kind") implementation_kind = implementation.get("kind")
@@ -123,7 +123,7 @@ def emit_model(
if implementation_kind == "graph": if implementation_kind == "graph":
for block in nested_graph.get("blocks", []): for block in nested_graph.get("blocks", []):
block_type = identifier(block["id"]) block_type = model_name_for(block)
block_name = identifier(block["name"]) block_name = identifier(block["name"])
lines.append(f"{body_indent}{block_type} {block_name};") lines.append(f"{body_indent}{block_type} {block_name};")
for junction in nested_graph.get("junctions", []): for junction in nested_graph.get("junctions", []):
@@ -322,5 +322,11 @@ def identifier(value: str) -> str:
return normalized return normalized
def model_name_for(component: dict[str, Any]) -> str:
"""Return the generated Modelica type name for a component."""
return identifier(f"m_{component['name']}")
def _junction_name(junction_id: str) -> str: def _junction_name(junction_id: str) -> str:
return identifier(f"junction_{junction_id}") return identifier(f"junction_{junction_id}")

View File

@@ -24,3 +24,4 @@ class Simulation:
self.id_list = result.objects_by_id self.id_list = result.objects_by_id
self.last_compilation_output = result.modelica self.last_compilation_output = result.modelica
log.info("Generated Modelica model:\n%s", self.last_compilation_output) log.info("Generated Modelica model:\n%s", self.last_compilation_output)
log.info("Simulation settings:\n%s", self.last_compilation_input['implementation']['graph']['simulation'])

View File

@@ -1,6 +1,6 @@
from copy import deepcopy from copy import deepcopy
from PySide6.QtWidgets import QDialog from PySide6.QtWidgets import QButtonGroup, QDialog
from bedit.gui.generated.ui_simulation_settings_dialog import Ui_SimulationSettingsDialog from bedit.gui.generated.ui_simulation_settings_dialog import Ui_SimulationSettingsDialog
@@ -11,12 +11,50 @@ class SimulationSettingsDialog(QDialog):
self.ui = Ui_SimulationSettingsDialog() self.ui = Ui_SimulationSettingsDialog()
self.ui.setupUi(self) self.ui.setupUi(self)
self._settings = deepcopy(settings) self._settings = deepcopy(settings)
self.ui.placeholderCheckBox.setChecked(
bool(self._settings.get("enabled", False)) self.interval_mode_group = QButtonGroup(self)
self.interval_mode_group.setExclusive(True)
self.interval_mode_group.addButton(self.ui.numberOfIntervalsRadioButton)
self.interval_mode_group.addButton(self.ui.intervalTimeRadioButton)
self.ui.startTimeSpinBox.setValue(float(settings.get("startTime", 0.0)))
self.ui.stopTimeSpinBox.setValue(float(settings.get("stopTime", 1.0)))
self.ui.numberOfIntervalsSpinBox.setValue(
int(settings.get("numberOfIntervals", 500))
) )
self.ui.intervalTimeSpinBox.setValue(float(settings.get("intervalTime", 0.002)))
interval_mode = settings.get("intervalMode", "numberOfIntervals")
if interval_mode == "intervalTime":
self.ui.intervalTimeRadioButton.setChecked(True)
else:
self.ui.numberOfIntervalsRadioButton.setChecked(True)
self.ui.numberOfIntervalsRadioButton.toggled.connect(
self._update_interval_fields
)
self.ui.intervalTimeRadioButton.toggled.connect(self._update_interval_fields)
self._update_interval_fields()
def _update_interval_fields(self) -> None:
use_number = self.ui.numberOfIntervalsRadioButton.isChecked()
self.ui.numberOfIntervalsSpinBox.setEnabled(use_number)
self.ui.intervalTimeSpinBox.setEnabled(not use_number)
@property @property
def settings(self) -> dict: def settings(self) -> dict:
values = deepcopy(self._settings) values = deepcopy(self._settings)
values["enabled"] = self.ui.placeholderCheckBox.isChecked() values.update(
{
"startTime": self.ui.startTimeSpinBox.value(),
"stopTime": self.ui.stopTimeSpinBox.value(),
"intervalMode": (
"numberOfIntervals"
if self.ui.numberOfIntervalsRadioButton.isChecked()
else "intervalTime"
),
"numberOfIntervals": self.ui.numberOfIntervalsSpinBox.value(),
"intervalTime": self.ui.intervalTimeSpinBox.value(),
}
)
return values return values

View File

@@ -15,25 +15,76 @@ from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon, QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter, QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform) QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QAbstractButton, QApplication, QCheckBox, QDialog, from PySide6.QtWidgets import (QAbstractButton, QAbstractSpinBox, QApplication, QDialog,
QDialogButtonBox, QGroupBox, QSizePolicy, QSpacerItem, QDialogButtonBox, QDoubleSpinBox, QFormLayout, QGroupBox,
QVBoxLayout, QWidget) QLabel, QRadioButton, QSizePolicy, QSpacerItem,
QSpinBox, QVBoxLayout, QWidget)
class Ui_SimulationSettingsDialog(object): class Ui_SimulationSettingsDialog(object):
def setupUi(self, SimulationSettingsDialog): def setupUi(self, SimulationSettingsDialog):
if not SimulationSettingsDialog.objectName(): if not SimulationSettingsDialog.objectName():
SimulationSettingsDialog.setObjectName(u"SimulationSettingsDialog") SimulationSettingsDialog.setObjectName(u"SimulationSettingsDialog")
SimulationSettingsDialog.resize(420, 180) SimulationSettingsDialog.resize(420, 384)
self.dialogLayout = QVBoxLayout(SimulationSettingsDialog) self.dialogLayout = QVBoxLayout(SimulationSettingsDialog)
self.dialogLayout.setObjectName(u"dialogLayout") self.dialogLayout.setObjectName(u"dialogLayout")
self.settingsGroup = QGroupBox(SimulationSettingsDialog) self.settingsGroup = QGroupBox(SimulationSettingsDialog)
self.settingsGroup.setObjectName(u"settingsGroup") self.settingsGroup.setObjectName(u"settingsGroup")
self.settingsLayout = QVBoxLayout(self.settingsGroup) self.settingsLayout = QVBoxLayout(self.settingsGroup)
self.settingsLayout.setObjectName(u"settingsLayout") self.settingsLayout.setObjectName(u"settingsLayout")
self.placeholderCheckBox = QCheckBox(self.settingsGroup) self.simulationInterval = QGroupBox(self.settingsGroup)
self.placeholderCheckBox.setObjectName(u"placeholderCheckBox") self.simulationInterval.setObjectName(u"simulationInterval")
self.simulationInterval.setEnabled(True)
self.formLayout = QFormLayout(self.simulationInterval)
self.formLayout.setObjectName(u"formLayout")
self.label = QLabel(self.simulationInterval)
self.label.setObjectName(u"label")
self.settingsLayout.addWidget(self.placeholderCheckBox) self.formLayout.setWidget(0, QFormLayout.ItemRole.LabelRole, self.label)
self.startTimeSpinBox = QDoubleSpinBox(self.simulationInterval)
self.startTimeSpinBox.setObjectName(u"startTimeSpinBox")
self.startTimeSpinBox.setEnabled(True)
self.formLayout.setWidget(0, QFormLayout.ItemRole.FieldRole, self.startTimeSpinBox)
self.label_2 = QLabel(self.simulationInterval)
self.label_2.setObjectName(u"label_2")
self.formLayout.setWidget(1, QFormLayout.ItemRole.LabelRole, self.label_2)
self.stopTimeSpinBox = QDoubleSpinBox(self.simulationInterval)
self.stopTimeSpinBox.setObjectName(u"stopTimeSpinBox")
self.stopTimeSpinBox.setValue(1.000000000000000)
self.formLayout.setWidget(1, QFormLayout.ItemRole.FieldRole, self.stopTimeSpinBox)
self.numberOfIntervalsRadioButton = QRadioButton(self.simulationInterval)
self.numberOfIntervalsRadioButton.setObjectName(u"numberOfIntervalsRadioButton")
self.formLayout.setWidget(2, QFormLayout.ItemRole.LabelRole, self.numberOfIntervalsRadioButton)
self.intervalTimeRadioButton = QRadioButton(self.simulationInterval)
self.intervalTimeRadioButton.setObjectName(u"intervalTimeRadioButton")
self.formLayout.setWidget(3, QFormLayout.ItemRole.LabelRole, self.intervalTimeRadioButton)
self.numberOfIntervalsSpinBox = QSpinBox(self.simulationInterval)
self.numberOfIntervalsSpinBox.setObjectName(u"numberOfIntervalsSpinBox")
self.numberOfIntervalsSpinBox.setMaximum(999999999)
self.numberOfIntervalsSpinBox.setValue(500)
self.formLayout.setWidget(2, QFormLayout.ItemRole.FieldRole, self.numberOfIntervalsSpinBox)
self.intervalTimeSpinBox = QDoubleSpinBox(self.simulationInterval)
self.intervalTimeSpinBox.setObjectName(u"intervalTimeSpinBox")
self.intervalTimeSpinBox.setDecimals(5)
self.intervalTimeSpinBox.setStepType(QAbstractSpinBox.StepType.AdaptiveDecimalStepType)
self.intervalTimeSpinBox.setValue(0.002000000000000)
self.formLayout.setWidget(3, QFormLayout.ItemRole.FieldRole, self.intervalTimeSpinBox)
self.settingsLayout.addWidget(self.simulationInterval)
self.settingsSpacer = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding) self.settingsSpacer = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
@@ -59,6 +110,14 @@ class Ui_SimulationSettingsDialog(object):
def retranslateUi(self, SimulationSettingsDialog): def retranslateUi(self, SimulationSettingsDialog):
SimulationSettingsDialog.setWindowTitle(QCoreApplication.translate("SimulationSettingsDialog", u"Simulation Settings", None)) SimulationSettingsDialog.setWindowTitle(QCoreApplication.translate("SimulationSettingsDialog", u"Simulation Settings", None))
self.settingsGroup.setTitle(QCoreApplication.translate("SimulationSettingsDialog", u"Settings", None)) self.settingsGroup.setTitle(QCoreApplication.translate("SimulationSettingsDialog", u"Settings", None))
self.placeholderCheckBox.setText(QCoreApplication.translate("SimulationSettingsDialog", u"Enable simulation option", None)) self.simulationInterval.setTitle(QCoreApplication.translate("SimulationSettingsDialog", u"Simulation Interval", None))
self.label.setText(QCoreApplication.translate("SimulationSettingsDialog", u"Start time:", None))
self.startTimeSpinBox.setPrefix("")
self.startTimeSpinBox.setSuffix(QCoreApplication.translate("SimulationSettingsDialog", u"s", None))
self.label_2.setText(QCoreApplication.translate("SimulationSettingsDialog", u"Stop time:", None))
self.stopTimeSpinBox.setSuffix(QCoreApplication.translate("SimulationSettingsDialog", u"s", None))
self.numberOfIntervalsRadioButton.setText(QCoreApplication.translate("SimulationSettingsDialog", u"Number of intervals:", None))
self.intervalTimeRadioButton.setText(QCoreApplication.translate("SimulationSettingsDialog", u"Interval:", None))
self.intervalTimeSpinBox.setSuffix(QCoreApplication.translate("SimulationSettingsDialog", u"s", None))
# retranslateUi # retranslateUi

View File

@@ -2,16 +2,185 @@
<ui version="4.0"> <ui version="4.0">
<class>SimulationSettingsDialog</class> <class>SimulationSettingsDialog</class>
<widget class="QDialog" name="SimulationSettingsDialog"> <widget class="QDialog" name="SimulationSettingsDialog">
<property name="geometry"><rect><x>0</x><y>0</y><width>420</width><height>180</height></rect></property> <property name="geometry">
<property name="windowTitle"><string>Simulation Settings</string></property> <rect>
<x>0</x>
<y>0</y>
<width>420</width>
<height>311</height>
</rect>
</property>
<property name="windowTitle">
<string>Simulation Settings</string>
</property>
<layout class="QVBoxLayout" name="dialogLayout"> <layout class="QVBoxLayout" name="dialogLayout">
<item><widget class="QGroupBox" name="settingsGroup"><property name="title"><string>Settings</string></property><layout class="QVBoxLayout" name="settingsLayout"><item><widget class="QCheckBox" name="placeholderCheckBox"><property name="text"><string>Enable simulation option</string></property></widget></item><item><spacer name="settingsSpacer"><property name="orientation"><enum>Qt::Orientation::Vertical</enum></property><property name="sizeHint" stdset="0"><size><width>20</width><height>40</height></size></property></spacer></item></layout></widget></item> <item>
<item><widget class="QDialogButtonBox" name="buttonBox"><property name="standardButtons"><set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set></property></widget></item> <widget class="QTabWidget" name="settingsGroup">
<widget class="QWidget" name="generalPage" native="true">
<attribute name="title">
<string>General</string>
</attribute>
<layout class="QVBoxLayout" name="settingsLayout">
<item>
<widget class="QGroupBox" name="simulationInterval">
<property name="enabled">
<bool>true</bool>
</property>
<property name="title">
<string>Simulation Interval</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Start time:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::DoubleSpinBox" name="startTime">
<property name="enabled">
<bool>true</bool>
</property>
<property name="prefix">
<string/>
</property>
<property name="suffix">
<string>s</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Stop time:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="Gui::DoubleSpinBox" name="stopTime">
<property name="suffix">
<string>s</string>
</property>
<property name="value">
<double>1.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QRadioButton" name="interval_number">
<property name="text">
<string>Number of intervals:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QRadioButton" name="interval_time">
<property name="text">
<string>Interval:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="Gui::IntSpinBox" name="numberOfIntervals">
<property name="maximum">
<number>999999999</number>
</property>
<property name="value">
<number>500</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="Gui::DoubleSpinBox" name="intervalTime">
<property name="suffix">
<string>s</string>
</property>
<property name="decimals">
<number>5</number>
</property>
<property name="stepType">
<enum>QAbstractSpinBox::StepType::AdaptiveDecimalStepType</enum>
</property>
<property name="value">
<double>0.002000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="settingsSpacer">
<property name="orientation">
<enum>Qt::Orientation::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>Gui::IntSpinBox</class>
<extends>QSpinBox</extends>
<header>Gui/SpinBox.h</header>
</customwidget>
<customwidget>
<class>Gui::DoubleSpinBox</class>
<extends>QDoubleSpinBox</extends>
<header>Gui/SpinBox.h</header>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections> <connections>
<connection><sender>buttonBox</sender><signal>accepted()</signal><receiver>SimulationSettingsDialog</receiver><slot>accept()</slot><hints/></connection> <connection>
<connection><sender>buttonBox</sender><signal>rejected()</signal><receiver>SimulationSettingsDialog</receiver><slot>reject()</slot><hints/></connection> <sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>SimulationSettingsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>SimulationSettingsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>20</x>
<y>20</y>
</hint>
<hint type="destinationlabel">
<x>20</x>
<y>20</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>

View File

@@ -648,7 +648,14 @@
], ],
"annotations": [], "annotations": [],
"junctions": [], "junctions": [],
"simulation": {} "simulation": {
"enabled": false,
"startTime": 0.0,
"stopTime": 10.0,
"intervalMode": "numberOfIntervals",
"numberOfIntervals": 5000,
"intervalTime": 0.002
}
} }
} }
} }