Adding CDPSM package.
[PyCIM.git] / CIM14 / IEC61970 / Meas / Discrete.py
bloba70ee379af693925af586c83aefc887047ab11e3
1 # Copyright (C) 2010 Richard Lincoln
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # Lesser General Public License for more details.
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA, USA
17 from CIM14.IEC61970.Meas.Measurement import Measurement
19 class Discrete(Measurement):
20 """Discrete represents a discrete Measurement, i.e. a Measurement reprsenting discrete values, e.g. a Breaker position.
21 """
23 def __init__(self, normalValue=0, minValue=0, maxValue=0, Command=None, DiscreteValues=None, ValueAliasSet=None, *args, **kw_args):
24 """Initialises a new 'Discrete' instance.
26 @param normalValue: Normal measurement value, e.g., used for percentage calculations.
27 @param minValue: Normal value range minimum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values
28 @param maxValue: Normal value range maximum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values.
29 @param Command: The Control variable associated with the Measurement.
30 @param DiscreteValues: The values connected to this measurement.
31 @param ValueAliasSet: The ValueAliasSet used for translation of a MeasurementValue.value to a name
32 """
33 #: Normal measurement value, e.g., used for percentage calculations.
34 self.normalValue = normalValue
36 #: Normal value range minimum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values
37 self.minValue = minValue
39 #: Normal value range maximum for any of the MeasurementValue.values. Used for scaling, e.g. in bar graphs or of telemetered raw values.
40 self.maxValue = maxValue
42 self._Command = None
43 self.Command = Command
45 self._DiscreteValues = []
46 self.DiscreteValues = [] if DiscreteValues is None else DiscreteValues
48 self._ValueAliasSet = None
49 self.ValueAliasSet = ValueAliasSet
51 super(Discrete, self).__init__(*args, **kw_args)
53 _attrs = ["normalValue", "minValue", "maxValue"]
54 _attr_types = {"normalValue": int, "minValue": int, "maxValue": int}
55 _defaults = {"normalValue": 0, "minValue": 0, "maxValue": 0}
56 _enums = {}
57 _refs = ["Command", "DiscreteValues", "ValueAliasSet"]
58 _many_refs = ["DiscreteValues"]
60 def getCommand(self):
61 """The Control variable associated with the Measurement.
62 """
63 return self._Command
65 def setCommand(self, value):
66 if self._Command is not None:
67 self._Command._Discrete = None
69 self._Command = value
70 if self._Command is not None:
71 self._Command.Discrete = None
72 self._Command._Discrete = self
74 Command = property(getCommand, setCommand)
76 def getDiscreteValues(self):
77 """The values connected to this measurement.
78 """
79 return self._DiscreteValues
81 def setDiscreteValues(self, value):
82 for x in self._DiscreteValues:
83 x.Discrete = None
84 for y in value:
85 y._Discrete = self
86 self._DiscreteValues = value
88 DiscreteValues = property(getDiscreteValues, setDiscreteValues)
90 def addDiscreteValues(self, *DiscreteValues):
91 for obj in DiscreteValues:
92 obj.Discrete = self
94 def removeDiscreteValues(self, *DiscreteValues):
95 for obj in DiscreteValues:
96 obj.Discrete = None
98 def getValueAliasSet(self):
99 """The ValueAliasSet used for translation of a MeasurementValue.value to a name
101 return self._ValueAliasSet
103 def setValueAliasSet(self, value):
104 if self._ValueAliasSet is not None:
105 filtered = [x for x in self.ValueAliasSet.Discretes if x != self]
106 self._ValueAliasSet._Discretes = filtered
108 self._ValueAliasSet = value
109 if self._ValueAliasSet is not None:
110 if self not in self._ValueAliasSet._Discretes:
111 self._ValueAliasSet._Discretes.append(self)
113 ValueAliasSet = property(getValueAliasSet, setValueAliasSet)