Skip to content

Commit

Permalink
GUI: Add 'container' box to EventDialog
Browse files Browse the repository at this point in the history
This is the destination container for event definitions.
Currently, only gates are defined within fault trees.
Other event types are defined in the Model directly.

The container section can be expanded in future
to choose the destination files as well upon working with multi-files.

The current new-gate definitions
are constrained to define a fault-tree as well,
so that only single-top fault tree are allowed.

Issue #204
Issue #209
  • Loading branch information
rakhimov committed Jul 22, 2017
1 parent 4eb8360 commit 3e7b3f9
Show file tree
Hide file tree
Showing 2 changed files with 149 additions and 73 deletions.
33 changes: 32 additions & 1 deletion gui/eventdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "src/expression/constant.h"
#include "src/expression/exponential.h"
#include "src/ext/bits.h"
#include "src/ext/find_iterator.h"
#include "src/ext/variant.h"

#include "guiassert.h"
Expand Down Expand Up @@ -62,6 +63,7 @@ EventDialog::EventDialog(mef::Model *model, QWidget *parent)
constantValue->setValidator(&probabilityValidator);
exponentialRate->setValidator(&nonNegativeValidator);
addArgLine->setValidator(&nameValidator);
containerFaultTreeName->setValidator(&nameValidator);

connect(typeBox, OVERLOAD(QComboBox, currentIndexChanged, int),
[this](int index) {
Expand All @@ -81,12 +83,22 @@ EventDialog::EventDialog(mef::Model *model, QWidget *parent)
default:
GUI_ASSERT(false, );
}
if (index == ext::one_bit_index(EventType::Gate)) {
containerFaultTree->setEnabled(true);
containerFaultTree->setChecked(true);
containerModel->setEnabled(false);
} else {
containerFaultTree->setEnabled(false);
containerModel->setEnabled(true);
containerModel->setChecked(true);
}
validate();
});
connect(expressionType, OVERLOAD(QComboBox, currentIndexChanged, int), this,
&EventDialog::validate);
connect(expressionBox, &QGroupBox::toggled, this, &EventDialog::validate);
connectLineEdits({nameLine, constantValue, exponentialRate});
connectLineEdits(
{nameLine, constantValue, exponentialRate, containerFaultTreeName});
connect(connectiveBox, OVERLOAD(QComboBox, currentIndexChanged, int),
[this](int index) {
voteNumberBox->setEnabled(index == mef::kVote);
Expand Down Expand Up @@ -146,6 +158,9 @@ EventDialog::EventDialog(mef::Model *model, QWidget *parent)
}
});

/// @todo Enable fault-tree as a container for events.
containerFaultTree->setEnabled(false);

// Ensure proper defaults.
GUI_ASSERT(typeBox->currentIndex() == 0, );
GUI_ASSERT(stackedWidgetType->currentIndex() == 0, );
Expand Down Expand Up @@ -351,6 +366,22 @@ void EventDialog::validate()
}
}

if (containerFaultTreeName->isEnabled()) {
if (containerFaultTreeName->hasAcceptableInput() == false)
return;
GUI_ASSERT(typeBox->currentIndex() == ext::one_bit_index(Gate), );
QString faultTreeName = containerFaultTreeName->text();
if (auto it
= ext::find(m_model->fault_trees(), faultTreeName.toStdString())) {
if ((*it)->top_events().empty() == false) {
m_errorBar->showMessage(
tr("Fault tree '%1' is already defined with a top gate.")
.arg(faultTreeName));
containerFaultTreeName->setStyleSheet(yellowBackground);
}
return;
}
}
emit validated(true);
}

Expand Down
189 changes: 117 additions & 72 deletions gui/eventdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>545</width>
<height>472</height>
<width>630</width>
<height>478</height>
</rect>
</property>
<property name="sizePolicy">
Expand Down Expand Up @@ -86,18 +86,61 @@
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
<item row="0" column="0">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLine"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="typeLabel">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="typeBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>House event</string>
</property>
</item>
<item>
<property name="text">
<string>Basic event</string>
</property>
</item>
<item>
<property name="text">
<string>Undeveloped</string>
</property>
</item>
<item>
<property name="text">
<string>Conditional</string>
</property>
</item>
<item>
<property name="text">
<string>Gate</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" rowspan="2">
<widget class="QStackedWidget" name="stackedWidgetType">
Expand Down Expand Up @@ -343,7 +386,8 @@
<string>Add Argument</string>
</property>
<property name="icon">
<iconset theme="list-add"/>
<iconset theme="list-add">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -353,7 +397,8 @@
<string>Remove Argument</string>
</property>
<property name="icon">
<iconset theme="list-remove"/>
<iconset theme="list-remove">
<normaloff>.</normaloff>.</iconset>
</property>
</widget>
</item>
Expand All @@ -363,63 +408,44 @@
</widget>
</widget>
</item>
<item row="0" column="0">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="nameLine"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="typeLabel">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="typeBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>House event</string>
</property>
</item>
<item>
<property name="text">
<string>Basic event</string>
</property>
</item>
<item>
<property name="text">
<string>Undeveloped</string>
</property>
</item>
<item>
<property name="text">
<string>Conditional</string>
</property>
</item>
<item>
<property name="text">
<string>Gate</string>
</property>
</item>
</widget>
</item>
</layout>
<item row="3" column="1">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Container</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QFormLayout" name="formLayout_6">
<item row="1" column="0">
<widget class="QRadioButton" name="containerFaultTree">
<property name="text">
<string>Fault tree:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="containerFaultTreeName">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="containerModel">
<property name="text">
<string>Model</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="0" column="2">
<item row="0" column="2" rowspan="4">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand Down Expand Up @@ -449,6 +475,9 @@
<tabstop>addArgButton</tabstop>
<tabstop>argsList</tabstop>
<tabstop>removeArgButton</tabstop>
<tabstop>containerModel</tabstop>
<tabstop>containerFaultTree</tabstop>
<tabstop>containerFaultTreeName</tabstop>
</tabstops>
<resources/>
<connections>
Expand Down Expand Up @@ -500,5 +529,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>containerFaultTree</sender>
<signal>toggled(bool)</signal>
<receiver>containerFaultTreeName</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>402</x>
<y>174</y>
</hint>
<hint type="destinationlabel">
<x>531</x>
<y>177</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 3e7b3f9

Please sign in to comment.