←
Documentation
ADS-IDAC Engine
5.0.0
ControlValue.cpp
Go to the documentation of this file.
1
// ControlValue.cpp: implementation of the ControlValue class.
2
//
4
5
#include "
ControlValue.h
"
6
#include "../Global/TermConversions.h"
7
#include "../Branch/BranchRecord.h"
8
#include <boost/serialization/export.hpp>
9
#include "../Global/SimulationContext.h"
10
#include <boost/archive/binary_oarchive.hpp>
11
#include <boost/archive/binary_iarchive.hpp>
12
BOOST_CLASS_EXPORT_IMPLEMENT(
ControlValue
)
13
using namespace
std;
14
15
17
// Construction/Destruction
19
20
ControlValue::ControlValue
()
21
{
22
SystemControl::setTypeOfControl
(
DisplayType::ControlValue
);
23
displayed_control_value
= -1.0;
24
displayed_control_value_when_fail
= -1.0;
25
}
26
27
ControlValue::~ControlValue
()
28
{
29
30
}
31
void
ControlValue::setDisplayedControlValue
(
double
x){
displayed_control_value
= x;}
32
void
ControlValue::setDisplayedControlValueWhenFail
(
double
x){
displayed_control_value_when_fail
= x;}
33
double
ControlValue::getDisplayedControlValue
(){
return
displayed_control_value
;}
34
double
ControlValue::getDisplayedControlValueWhenFail
(){
return
displayed_control_value_when_fail
;}
35
void
ControlValue::readInfoFromFile
(ifstream &fin){
36
SystemControl::readInfoFromFile
(fin);
37
fin >>
displayed_control_value_when_fail
;
38
}
39
void
ControlValue::updateDisplayedControlValue
(
SystemModule
&_th,
double
_control_value){
40
InteractiveVariable
*iv_ptr;
41
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
42
if
(iv_ptr == 0){
43
SystemControl::setPtrToCorrespondingInteractiveVariable
((
InteractiveVariable
*) _th.
getComponentFromSystemMap
(
SystemControl::getCorrespondingComponentNameOfControl
()));
44
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
45
}
46
if
(iv_ptr != 0){
47
if
(
SystemControl::getFunctionalState
() ==
sim::State::Succeed
){
48
iv_ptr->
setInputValue
(_control_value);
49
this->
setDisplayedControlValue
(_control_value);
50
}
51
else
{
//control fails
52
displayed_control_value
=
displayed_control_value_when_fail
;
53
}
54
}
55
else
{
56
ofstream fout(
"err messages.txt"
, ios::app);
57
cout <<
" ControlState::updateDisplayedControlValue Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
58
<<
" can not be located."
<< endl;
59
fout <<
r5pars_
.timesno <<
" ControlState::updateDisplayedControlValue Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
60
<<
" can not be located.\n"
;
61
fout.close();
62
r5pars_
.sim_err =
true
;
63
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlValue::updateDisplayedControlValue err."
);
64
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::AdsSimErr
);
65
}
66
}
67
void
ControlValue::performControl
(
SystemModule
&_th,
double
_control_value){
68
InteractiveVariable
*iv_ptr;
69
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
70
if
(iv_ptr == 0){
71
SystemControl::setPtrToCorrespondingInteractiveVariable
((
InteractiveVariable
*) _th.
getComponentFromSystemMap
(
SystemControl::getCorrespondingComponentNameOfControl
()));
72
iv_ptr =
SystemControl::getPtrToCorrespondingInteractiveVariable
();
73
}
74
if
(iv_ptr != 0){
75
iv_ptr->
setInputValue
(_control_value);
76
iv_ptr->
setNeedToInteract
(
true
);
77
this->
setDisplayedControlValue
(_control_value);
78
// update control value
79
this->
setControlValue
(_control_value);
80
//
81
}
82
else
{
83
ofstream fout(
"err messages.txt"
, ios::app);
84
cout <<
" ControlState::updateDisplayedControlValue Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
85
<<
" can not be located."
<< endl;
86
fout <<
r5pars_
.timesno <<
" ControlState::updateDisplayedControlValue Component "
<<
SystemControl::getCorrespondingComponentNameOfControl
()
87
<<
" can not be located.\n"
;
88
fout.close();
89
r5pars_
.sim_err =
true
;
90
g_sim
.
Branch_center
.
setTempESMessage
(
"ControlValue::performControl err."
);
91
g_sim
.
Branch_center
.
setTempTypeOfConsequence
(
Consequence::AdsSimErr
);
92
}
93
}
94
void
ControlValue::copyControlValue
(
ControlValue
&_cv){
95
displayed_control_value
= _cv.
getDisplayedControlValue
();
96
displayed_control_value_when_fail
= _cv.
getDisplayedControlValueWhenFail
();
97
this->
copySystemControl
(_cv);
98
}
99
void
ControlValue::saveControlValueToFile
(ofstream &fout){
100
this->
saveSystemControlToFile
(fout);
101
fout <<
displayed_control_value
<<
' '
<<
displayed_control_value_when_fail
<<
'\n'
;
102
}
103
void
ControlValue::retrieveControlValueFromFile
(ifstream &fin){
104
this->
retrieveSystemControlFromFile
(fin);
105
fin >>
displayed_control_value
>>
displayed_control_value_when_fail
;
106
}
ControlValue.h
DisplayType::ControlValue
@ ControlValue
Consequence::AdsSimErr
@ AdsSimErr
g_sim
SimulationContext g_sim
Global simulation context: the single instance, defined in SimulationContext.cpp.
Definition:
SimulationContext.cpp:7
BranchRecord::setTempTypeOfConsequence
void setTempTypeOfConsequence(Consequence)
Stores the consequence of the end state the running sequence will get.
Definition:
BranchRecord.cpp:1641
BranchRecord::setTempESMessage
void setTempESMessage(std::string)
Stores the description of the end state the running sequence will get if it is terminated (set by mod...
Definition:
BranchRecord.cpp:1640
ControlElement::setControlValue
void setControlValue(double)
Definition:
ControlElement.cpp:63
ControlElement::getCorrespondingComponentNameOfControl
std::string getCorrespondingComponentNameOfControl()
Definition:
ControlElement.cpp:41
ControlElement::readInfoFromFile
void readInfoFromFile(std::ifstream &)
Definition:
ControlElement.cpp:46
ControlValue
Definition:
ControlValue.h:21
ControlValue::displayed_control_value
double displayed_control_value
Definition:
ControlValue.h:37
ControlValue::getDisplayedControlValue
double getDisplayedControlValue()
Definition:
ControlValue.cpp:33
ControlValue::saveControlValueToFile
void saveControlValueToFile(std::ofstream &)
Definition:
ControlValue.cpp:99
ControlValue::retrieveControlValueFromFile
void retrieveControlValueFromFile(std::ifstream &)
Definition:
ControlValue.cpp:103
ControlValue::setDisplayedControlValue
void setDisplayedControlValue(double)
Definition:
ControlValue.cpp:31
ControlValue::readInfoFromFile
void readInfoFromFile(std::ifstream &)
Definition:
ControlValue.cpp:35
ControlValue::updateDisplayedControlValue
void updateDisplayedControlValue(SystemModule &, double)
Definition:
ControlValue.cpp:39
ControlValue::displayed_control_value_when_fail
double displayed_control_value_when_fail
Definition:
ControlValue.h:37
ControlValue::~ControlValue
virtual ~ControlValue()
Definition:
ControlValue.cpp:27
ControlValue::ControlValue
ControlValue()
Definition:
ControlValue.cpp:20
ControlValue::getDisplayedControlValueWhenFail
double getDisplayedControlValueWhenFail()
Definition:
ControlValue.cpp:34
ControlValue::copyControlValue
void copyControlValue(ControlValue &)
Definition:
ControlValue.cpp:94
ControlValue::performControl
void performControl(SystemModule &, double)
Definition:
ControlValue.cpp:67
ControlValue::setDisplayedControlValueWhenFail
void setDisplayedControlValueWhenFail(double)
Definition:
ControlValue.cpp:32
InteractiveVariable
Definition:
InteractiveVariable.h:16
InteractiveVariable::setInputValue
void setInputValue(double val)
Definition:
InteractiveVariable.cpp:29
InteractiveVariable::setNeedToInteract
void setNeedToInteract(bool flag)
Definition:
InteractiveVariable.cpp:36
SystemControl::getPtrToCorrespondingInteractiveVariable
InteractiveVariable * getPtrToCorrespondingInteractiveVariable()
Definition:
SystemControl.cpp:39
SystemControl::setPtrToCorrespondingInteractiveVariable
void setPtrToCorrespondingInteractiveVariable(InteractiveVariable *)
Definition:
SystemControl.cpp:36
SystemControl::setTypeOfControl
void setTypeOfControl(DisplayType)
Definition:
SystemControl.cpp:35
SystemControl::saveSystemControlToFile
void saveSystemControlToFile(std::ofstream &)
Definition:
SystemControl.cpp:48
SystemControl::getFunctionalState
int getFunctionalState()
Definition:
SystemControl.cpp:37
SystemControl::retrieveSystemControlFromFile
void retrieveSystemControlFromFile(std::ifstream &)
Definition:
SystemControl.cpp:55
SystemControl::copySystemControl
void copySystemControl(SystemControl &)
Definition:
SystemControl.cpp:41
SystemModule
Definition:
SystemModule.h:28
SystemModule::getComponentFromSystemMap
THElement * getComponentFromSystemMap(std::string)
Definition:
SystemModule.cpp:501
r5pars_
struct @0 r5pars_
sim::State::Succeed
constexpr int Succeed
Definition:
SimConstants.h:104
SimulationContext::Branch_center
BranchRecord Branch_center
Dynamic event tree state.
Definition:
SimulationContext.h:45
src
ADSIDAC
ControlPanel
ControlValue.cpp
Generated by
1.9.4