File: SimulatorTab.h

package info (click to toggle)
dyssol 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,184 kB
  • sloc: cpp: 53,870; sh: 85; python: 59; makefile: 11
file content (86 lines) | stat: -rw-r--r-- 2,170 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Copyright (c) 2020, Dyssol Development Team.
 * Copyright (c) 2023, DyssolTEC GmbH.
 * All rights reserved. This file is part of Dyssol. See LICENSE file for license information. */

#pragma once

#include "ui_SimulatorTab.h"
#include "SimulationThread.h"
#include "Simulator.h"
#include "QtDialog.h"
#include <QTimer>
#include <QElapsedTimer>

class CSimulator;
class CFlowsheet;

class CSimulatorTab
	: public CQtDialog
{
	Q_OBJECT

	enum EStatTable : int
	{
		TIME_WIN_START = 0,
		TIME_WIN_END,
		TIME_WIN_LENGTH,
		ITERATION_NUMBER,
		WINDOW_NUMBER,
		UNIT_NAME,
		STARTED_TIME,
		ELAPSED_TIME
	};

	Ui::CSimulatorTabClass ui;

	CFlowsheet* m_pFlowsheet;			// Pointer to a current flowsheet.
	CSimulator* m_pSimulator;			// Pointer to a current simulator.

	CSimulationThread* m_simulationThread = new CSimulationThread([&]() {m_pSimulator->Simulate(); }, [&]() {m_pSimulator->Stop(); });	// Separate thread for simulator.

	QElapsedTimer m_simulationTimer;	// Timer to determine simulation time.
	QTimer m_logTimer;				    // Interrupt timer to update simulation log.

public:
	CSimulatorTab(CFlowsheet* _pFlowsheet, CSimulator* _pSimulator, QWidget* _parent = nullptr);
	CSimulatorTab(const CSimulatorTab&)            = delete;
	CSimulatorTab(CSimulatorTab&&)                 = delete;
	CSimulatorTab& operator=(const CSimulatorTab&) = delete;
	CSimulatorTab& operator=(CSimulatorTab&&)      = delete;
	~CSimulatorTab() override;

	void InitializeConnections() const;

public:
	void setVisible(bool _visible) override;

	void UpdateWholeView() const;
	void OnNewFlowsheet() const;

	void StartStopSimulation();

private slots:
	void SetSimulationTime();
	void SimulationFinished();

	void ClearSimulationResults();
	void ClearInitialRecycleStreams();
	void ClearAll();

	void UpdateLog() const;

private:
	void AbortSimulation();

	void ClearLog() const;
	void UpdateSimulationTime() const;
	void BlockUI(bool _block) const;

signals:
	void DataChanged();	// User has made some changes
	/**
	 * \brief Emitted when the state of the simulator changes to IDLE or RUNNING.
	 * \param _state New state.
	 */
	void SimulatorStateChanged(ESimulatorState _state);
};