5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "logicalswitchdata.h"
23 #include "radiodata.h"
24 #include "radiodataconversionstate.h"
25 #include "rawsource.h"
26 #include "rawswitch.h"
28 bool LogicalSwitchData::isEmpty() const
33 CSFunctionFamily
LogicalSwitchData::getFunctionFamily() const
35 if (func
== LS_FN_EDGE
)
36 return LS_FAMILY_EDGE
;
37 else if (func
== LS_FN_TIMER
)
38 return LS_FAMILY_TIMER
;
39 else if (func
== LS_FN_STICKY
)
40 return LS_FAMILY_STICKY
;
41 else if (func
< LS_FN_AND
|| func
> LS_FN_ELESS
)
42 return LS_FAMILY_VOFS
;
43 else if (func
< LS_FN_EQUAL
)
44 return LS_FAMILY_VBOOL
;
46 return LS_FAMILY_VCOMP
;
49 unsigned int LogicalSwitchData::getRangeFlags() const
53 if (func
== LS_FN_DPOS
|| func
== LS_FN_DAPOS
)
54 f
|= RANGE_DELTA_FUNCTION
;
56 if (func
== LS_FN_DAPOS
|| func
== LS_FN_APOS
|| func
== LS_FN_ANEG
)
57 f
|= RANGE_ABS_FUNCTION
;
62 QString
LogicalSwitchData::funcToString() const
99 case LS_FN_VALMOSTEQUAL
:
108 return tr("Unknown");
112 QString
LogicalSwitchData::nameToString(int index
) const
114 return RadioData::getElementName(tr("L"), index
+ 1, NULL
, true);
117 void LogicalSwitchData::convert(RadioDataConversionState
& cstate
)
119 cstate
.setComponent(tr("LSW"), 7);
120 cstate
.setSubComp(RawSwitch(SWITCH_TYPE_VIRTUAL
, cstate
.subCompIdx
+ 1).toString(cstate
.fromType
, cstate
.fromGS(), cstate
.fromModel()));
121 CSFunctionFamily family
= getFunctionFamily();
124 val1
= RawSource(val1
).convert(cstate
.withComponentField("V1")).toValue();
126 case LS_FAMILY_STICKY
:
127 case LS_FAMILY_VBOOL
:
128 val1
= RawSwitch(val1
).convert(cstate
.withComponentField("V1")).toValue();
129 val2
= RawSwitch(val2
).convert(cstate
.withComponentField("V2")).toValue();
132 val1
= RawSwitch(val1
).convert(cstate
.withComponentField("V1")).toValue();
134 case LS_FAMILY_VCOMP
:
135 val1
= RawSource(val1
).convert(cstate
.withComponentField("V1")).toValue();
136 val2
= RawSource(val2
).convert(cstate
.withComponentField("V2")).toValue();
142 andsw
= RawSwitch(andsw
).convert(cstate
.withComponentField("AND")).toValue();