23 |
# fix for people using python2.1 |
# fix for people using python2.1 |
24 |
from __future__ import nested_scopes |
from __future__ import nested_scopes |
25 |
|
|
26 |
import copy |
import copy, operator |
27 |
|
|
28 |
from Thuban import _ |
from Thuban import _ |
29 |
|
|
30 |
from types import * |
import types |
31 |
|
|
32 |
from messages import \ |
from messages import \ |
33 |
LAYER_PROJECTION_CHANGED, \ |
LAYER_PROJECTION_CHANGED, \ |
35 |
LAYER_VISIBILITY_CHANGED |
LAYER_VISIBILITY_CHANGED |
36 |
|
|
37 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
38 |
|
from Thuban.Model.range import Range |
39 |
|
|
40 |
import Thuban.Model.layer |
import Thuban.Model.layer |
41 |
|
|
197 |
|
|
198 |
fill -- a Color object. |
fill -- a Color object. |
199 |
""" |
""" |
|
assert isinstance(fill, Color) |
|
200 |
self.GetDefaultGroup().GetProperties().SetFill(fill) |
self.GetDefaultGroup().GetProperties().SetFill(fill) |
201 |
self.__SendNotification() |
self.__SendNotification() |
202 |
|
|
209 |
|
|
210 |
color -- a Color object. |
color -- a Color object. |
211 |
""" |
""" |
|
assert isinstance(color, Color) |
|
212 |
self.GetDefaultGroup().GetProperties().SetLineColor(color) |
self.GetDefaultGroup().GetProperties().SetLineColor(color) |
213 |
self.__SendNotification() |
self.__SendNotification() |
214 |
|
|
221 |
|
|
222 |
lineWidth -- an integer > 0. |
lineWidth -- an integer > 0. |
223 |
""" |
""" |
224 |
assert isinstance(lineWidth, IntType) |
assert isinstance(lineWidth, types.IntType) |
225 |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
226 |
self.__SendNotification() |
self.__SendNotification() |
227 |
|
|
456 |
color -- the color of the line. This must be a Color object. |
color -- the color of the line. This must be a Color object. |
457 |
""" |
""" |
458 |
|
|
|
assert isinstance(color, Color) |
|
459 |
self.__stroke = color |
self.__stroke = color |
460 |
|
|
461 |
def GetLineWidth(self): |
def GetLineWidth(self): |
467 |
|
|
468 |
lineWidth -- the new line width. This must be > 0. |
lineWidth -- the new line width. This must be > 0. |
469 |
""" |
""" |
470 |
assert isinstance(lineWidth, IntType) |
assert isinstance(lineWidth, types.IntType) |
471 |
if (lineWidth < 1): |
if (lineWidth < 1): |
472 |
raise ValueError(_("lineWidth < 1")) |
raise ValueError(_("lineWidth < 1")) |
473 |
|
|
483 |
fill -- the color of the fill. This must be a Color object. |
fill -- the color of the fill. This must be a Color object. |
484 |
""" |
""" |
485 |
|
|
|
assert isinstance(fill, Color) |
|
486 |
self.__fill = fill |
self.__fill = fill |
487 |
|
|
488 |
def __eq__(self, other): |
def __eq__(self, other): |
539 |
label -- a string representing the Group's label. This must |
label -- a string representing the Group's label. This must |
540 |
not be None. |
not be None. |
541 |
""" |
""" |
542 |
assert isinstance(label, StringTypes) |
assert isinstance(label, types.StringTypes) |
543 |
self.label = label |
self.label = label |
544 |
|
|
545 |
def GetDisplayText(self): |
def GetDisplayText(self): |
585 |
return not self.__eq__(other) |
return not self.__eq__(other) |
586 |
|
|
587 |
def __repr__(self): |
def __repr__(self): |
588 |
return "'" + self.label + "', " + repr(self.GetProperties()) |
return repr(self.label) + ", " + repr(self.GetProperties()) |
589 |
|
|
590 |
class ClassGroupSingleton(ClassGroup): |
class ClassGroupSingleton(ClassGroup): |
591 |
"""A Group that is associated with a single value.""" |
"""A Group that is associated with a single value.""" |
640 |
and self.__value == other.__value |
and self.__value == other.__value |
641 |
|
|
642 |
def __repr__(self): |
def __repr__(self): |
643 |
return "(" + self.__value + ", " + ClassGroup.__repr__(self) + ")" |
return "(" + repr(self.__value) + ", " + ClassGroup.__repr__(self) + ")" |
644 |
|
|
645 |
class ClassGroupDefault(ClassGroup): |
class ClassGroupDefault(ClassGroup): |
646 |
"""The default Group. When values do not match any other |
"""The default Group. When values do not match any other |
703 |
|
|
704 |
ClassGroup.__init__(self, label, props, group) |
ClassGroup.__init__(self, label, props, group) |
705 |
|
|
706 |
self.__min = self.__max = 0 |
#self.__min = self.__max = 0 |
707 |
|
#self.__range = Range("[" + repr(float(min)) + ";" + |
708 |
|
#repr(float(max)) + "[") |
709 |
self.SetRange(min, max) |
self.SetRange(min, max) |
710 |
|
|
711 |
def __copy__(self): |
def __copy__(self): |
712 |
return ClassGroupRange(self.GetMin(), |
return ClassGroupRange(min = self.__range, |
713 |
self.GetMax(), |
max = None, |
714 |
self.GetProperties(), |
props = self.GetProperties(), |
715 |
self.GetLabel()) |
label = self.GetLabel()) |
716 |
|
|
717 |
def __deepcopy__(self, memo): |
def __deepcopy__(self, memo): |
718 |
return ClassGroupRange(copy.copy(self.GetMin()), |
return ClassGroupRange(min = copy.copy(self.__range), |
719 |
copy.copy(self.GetMax()), |
max = copy.copy(self.GetMax()), |
720 |
group = self) |
group = self) |
721 |
|
|
722 |
def GetMin(self): |
def GetMin(self): |
723 |
"""Return the range's minimum value.""" |
"""Return the range's minimum value.""" |
724 |
return self.__min |
return self.__range.GetRange()[1] |
725 |
|
|
726 |
def SetMin(self, min): |
def SetMin(self, min): |
727 |
"""Set the range's minimum value. |
"""Set the range's minimum value. |
730 |
maximum value. Use SetRange() to change both min and max values. |
maximum value. Use SetRange() to change both min and max values. |
731 |
""" |
""" |
732 |
|
|
733 |
self.SetRange(min, self.__max) |
self.SetRange(min, self.__range.GetRange()[2]) |
734 |
|
|
735 |
def GetMax(self): |
def GetMax(self): |
736 |
"""Return the range's maximum value.""" |
"""Return the range's maximum value.""" |
737 |
return self.__max |
return self.__range.GetRange()[2] |
738 |
|
|
739 |
def SetMax(self, max): |
def SetMax(self, max): |
740 |
"""Set the range's maximum value. |
"""Set the range's maximum value. |
742 |
max -- the new maximum. Note that this must be greater than the current |
max -- the new maximum. Note that this must be greater than the current |
743 |
minimum value. Use SetRange() to change both min and max values. |
minimum value. Use SetRange() to change both min and max values. |
744 |
""" |
""" |
745 |
self.SetRange(self.__min, max) |
self.SetRange(self.__range.GetRange()[1], max) |
746 |
|
|
747 |
def SetRange(self, min, max): |
def SetRange(self, min, max = None): |
748 |
"""Set a new range. |
"""Set a new range. |
749 |
|
|
750 |
Note that min must be strictly less than max. |
Note that min must be strictly less than max. |
753 |
min -- the new maximum value |
min -- the new maximum value |
754 |
""" |
""" |
755 |
|
|
756 |
if min >= max: |
if isinstance(min, Range): |
757 |
raise ValueError(_("ClassGroupRange: %i(min) >= %i(max)!") % |
self.__range = min |
758 |
(min, max)) |
else: |
759 |
self.__min = min |
if max is None: |
760 |
self.__max = max |
raise ValueError() |
761 |
|
|
762 |
|
self.__range = Range(("[", min, max, "[")) |
763 |
|
|
764 |
def GetRange(self): |
def GetRange(self): |
765 |
"""Return the range as a tuple (min, max)""" |
"""Return the range as a string""" |
766 |
return (self.__min, self.__max) |
#return (self.__min, self.__max) |
767 |
|
return self.__range.string(self.__range.GetRange()) |
768 |
|
|
769 |
def Matches(self, value): |
def Matches(self, value): |
770 |
"""Determine if the given value lies with the current range. |
"""Determine if the given value lies with the current range. |
772 |
The following check is used: min <= value < max. |
The following check is used: min <= value < max. |
773 |
""" |
""" |
774 |
|
|
775 |
return self.__min <= value < self.__max |
return operator.contains(self.__range, value) |
776 |
|
#return self.__min <= value < self.__max |
777 |
|
|
778 |
def GetDisplayText(self): |
def GetDisplayText(self): |
779 |
label = self.GetLabel() |
label = self.GetLabel() |
780 |
|
|
781 |
if label != "": return label |
if label != "": return label |
782 |
|
|
783 |
return _("%s - %s") % (self.GetMin(), self.GetMax()) |
#return _("%s - %s") % (self.GetMin(), self.GetMax()) |
784 |
|
#return repr(self.__range) |
785 |
|
return self.__range.string(self.__range.GetRange()) |
786 |
|
|
787 |
def __eq__(self, other): |
def __eq__(self, other): |
788 |
return ClassGroup.__eq__(self, other) \ |
return ClassGroup.__eq__(self, other) \ |
789 |
and isinstance(other, ClassGroupRange) \ |
and isinstance(other, ClassGroupRange) \ |
790 |
and self.__min == other.__min \ |
and self.__range == other.__range |
791 |
and self.__max == other.__max |
#and self.__min == other.__min \ |
792 |
|
#and self.__max == other.__max |
793 |
|
|
794 |
def __repr__(self): |
def __repr__(self): |
795 |
return "(" + str(self.__min) + ", " + str(self.__max) + ", " + \ |
return "(" + str(self.__range) + ClassGroup.__repr__(self) + ")" |
796 |
ClassGroup.__repr__(self) + ")" |
#return "(" + repr(self.__min) + ", " + repr(self.__max) + ", " + \ |
797 |
|
#ClassGroup.__repr__(self) + ")" |
798 |
|
|
799 |
class ClassGroupMap(ClassGroup): |
class ClassGroupMap(ClassGroup): |
800 |
"""Currently, this class is not used.""" |
"""Currently, this class is not used.""" |