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 |
|
|
223 |
|
|
224 |
lineWidth -- an integer > 0. |
lineWidth -- an integer > 0. |
225 |
""" |
""" |
226 |
assert isinstance(lineWidth, IntType) |
assert isinstance(lineWidth, types.IntType) |
227 |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
self.GetDefaultGroup().GetProperties().SetLineWidth(lineWidth) |
228 |
self.__SendNotification() |
self.__SendNotification() |
229 |
|
|
450 |
|
|
451 |
def GetLineColor(self): |
def GetLineColor(self): |
452 |
"""Return the line color as a Color object.""" |
"""Return the line color as a Color object.""" |
453 |
return self.stroke |
return self.__stroke |
454 |
|
|
455 |
def SetLineColor(self, color): |
def SetLineColor(self, color): |
456 |
"""Set the line color. |
"""Set the line color. |
459 |
""" |
""" |
460 |
|
|
461 |
assert isinstance(color, Color) |
assert isinstance(color, Color) |
462 |
self.stroke = color |
self.__stroke = color |
463 |
|
|
464 |
def GetLineWidth(self): |
def GetLineWidth(self): |
465 |
"""Return the line width.""" |
"""Return the line width.""" |
466 |
return self.strokeWidth |
return self.__strokeWidth |
467 |
|
|
468 |
def SetLineWidth(self, lineWidth): |
def SetLineWidth(self, lineWidth): |
469 |
"""Set the line width. |
"""Set the line width. |
470 |
|
|
471 |
lineWidth -- the new line width. This must be > 0. |
lineWidth -- the new line width. This must be > 0. |
472 |
""" |
""" |
473 |
assert isinstance(lineWidth, IntType) |
assert isinstance(lineWidth, types.IntType) |
474 |
if (lineWidth < 1): |
if (lineWidth < 1): |
475 |
raise ValueError(_("lineWidth < 1")) |
raise ValueError(_("lineWidth < 1")) |
476 |
|
|
477 |
self.strokeWidth = lineWidth |
self.__strokeWidth = lineWidth |
478 |
|
|
479 |
def GetFill(self): |
def GetFill(self): |
480 |
"""Return the fill color as a Color object.""" |
"""Return the fill color as a Color object.""" |
481 |
return self.fill |
return self.__fill |
482 |
|
|
483 |
def SetFill(self, fill): |
def SetFill(self, fill): |
484 |
"""Set the fill color. |
"""Set the fill color. |
487 |
""" |
""" |
488 |
|
|
489 |
assert isinstance(fill, Color) |
assert isinstance(fill, Color) |
490 |
self.fill = fill |
self.__fill = fill |
491 |
|
|
492 |
def __eq__(self, other): |
def __eq__(self, other): |
493 |
"""Return true if 'props' has the same attributes as this class""" |
"""Return true if 'props' has the same attributes as this class""" |
494 |
|
|
495 |
|
# |
496 |
|
# using 'is' over '==' results in a huge performance gain |
497 |
|
# in the renderer |
498 |
|
# |
499 |
return isinstance(other, ClassGroupProperties) \ |
return isinstance(other, ClassGroupProperties) \ |
500 |
and self.stroke == other.GetLineColor() \ |
and (self.__stroke is other.__stroke or \ |
501 |
and self.strokeWidth == other.GetLineWidth() \ |
self.__stroke == other.__stroke) \ |
502 |
and self.fill == other.GetFill() |
and (self.__fill is other.__fill or \ |
503 |
|
self.__fill == other.__fill) \ |
504 |
|
and self.__strokeWidth == other.__strokeWidth |
505 |
|
|
506 |
def __ne__(self, other): |
def __ne__(self, other): |
507 |
return not self.__eq__(other) |
return not self.__eq__(other) |
512 |
def __deepcopy__(self): |
def __deepcopy__(self): |
513 |
return ClassGroupProperties(self) |
return ClassGroupProperties(self) |
514 |
|
|
515 |
|
def __repr__(self): |
516 |
|
return repr((self.__stroke, self.__strokeWidth, self.__fill)) |
517 |
|
|
518 |
class ClassGroup: |
class ClassGroup: |
519 |
"""A base class for all Groups within a Classification""" |
"""A base class for all Groups within a Classification""" |
520 |
|
|
543 |
label -- a string representing the Group's label. This must |
label -- a string representing the Group's label. This must |
544 |
not be None. |
not be None. |
545 |
""" |
""" |
546 |
assert isinstance(label, StringType) |
assert isinstance(label, types.StringTypes) |
547 |
self.label = label |
self.label = label |
548 |
|
|
549 |
def GetDisplayText(self): |
def GetDisplayText(self): |
582 |
|
|
583 |
def __eq__(self, other): |
def __eq__(self, other): |
584 |
return isinstance(other, ClassGroup) \ |
return isinstance(other, ClassGroup) \ |
585 |
|
and self.label == other.label \ |
586 |
and self.GetProperties() == other.GetProperties() |
and self.GetProperties() == other.GetProperties() |
587 |
|
|
588 |
def __ne__(self, other): |
def __ne__(self, other): |
589 |
return not self.__eq__(other) |
return not self.__eq__(other) |
590 |
|
|
591 |
|
def __repr__(self): |
592 |
|
return repr(self.label) + ", " + repr(self.GetProperties()) |
593 |
|
|
594 |
class ClassGroupSingleton(ClassGroup): |
class ClassGroupSingleton(ClassGroup): |
595 |
"""A Group that is associated with a single value.""" |
"""A Group that is associated with a single value.""" |
618 |
|
|
619 |
def GetValue(self): |
def GetValue(self): |
620 |
"""Return the associated value.""" |
"""Return the associated value.""" |
621 |
return self.value |
return self.__value |
622 |
|
|
623 |
def SetValue(self, value): |
def SetValue(self, value): |
624 |
"""Associate this Group with the given value.""" |
"""Associate this Group with the given value.""" |
625 |
self.value = value |
self.__value = value |
626 |
|
|
627 |
def Matches(self, value): |
def Matches(self, value): |
628 |
"""Determine if the given value matches the associated Group value.""" |
"""Determine if the given value matches the associated Group value.""" |
629 |
|
|
630 |
"""Returns True if the value matches, False otherwise.""" |
"""Returns True if the value matches, False otherwise.""" |
631 |
|
|
632 |
return self.value == value |
return self.__value == value |
633 |
|
|
634 |
def GetDisplayText(self): |
def GetDisplayText(self): |
635 |
label = self.GetLabel() |
label = self.GetLabel() |
641 |
def __eq__(self, other): |
def __eq__(self, other): |
642 |
return ClassGroup.__eq__(self, other) \ |
return ClassGroup.__eq__(self, other) \ |
643 |
and isinstance(other, ClassGroupSingleton) \ |
and isinstance(other, ClassGroupSingleton) \ |
644 |
and self.GetValue() == other.GetValue() |
and self.__value == other.__value |
645 |
|
|
646 |
|
def __repr__(self): |
647 |
|
return "(" + repr(self.__value) + ", " + ClassGroup.__repr__(self) + ")" |
648 |
|
|
649 |
class ClassGroupDefault(ClassGroup): |
class ClassGroupDefault(ClassGroup): |
650 |
"""The default Group. When values do not match any other |
"""The default Group. When values do not match any other |
683 |
and isinstance(other, ClassGroupDefault) \ |
and isinstance(other, ClassGroupDefault) \ |
684 |
and self.GetProperties() == other.GetProperties() |
and self.GetProperties() == other.GetProperties() |
685 |
|
|
686 |
|
def __repr__(self): |
687 |
|
return "(" + ClassGroup.__repr__(self) + ")" |
688 |
|
|
689 |
class ClassGroupRange(ClassGroup): |
class ClassGroupRange(ClassGroup): |
690 |
"""A Group that represents a range of values that map to the same |
"""A Group that represents a range of values that map to the same |
691 |
set of properties.""" |
set of properties.""" |
705 |
label -- a label for this group. |
label -- a label for this group. |
706 |
""" |
""" |
707 |
|
|
708 |
ClassGroup.__init__(self, label, props, None) |
ClassGroup.__init__(self, label, props, group) |
|
|
|
|
self.min = self.max = 0 |
|
709 |
|
|
710 |
|
#self.__min = self.__max = 0 |
711 |
|
#self.__range = Range("[" + repr(float(min)) + ";" + |
712 |
|
#repr(float(max)) + "[") |
713 |
self.SetRange(min, max) |
self.SetRange(min, max) |
714 |
|
|
715 |
def __copy__(self): |
def __copy__(self): |
716 |
return ClassGroupRange(self.GetMin(), |
return ClassGroupRange(min = self.__range, |
717 |
self.GetMax(), |
max = None, |
718 |
self.GetProperties(), |
props = self.GetProperties(), |
719 |
self.GetLabel()) |
label = self.GetLabel()) |
720 |
|
|
721 |
def __deepcopy__(self, memo): |
def __deepcopy__(self, memo): |
722 |
return ClassGroupRange(copy.copy(self.GetMin()), |
return ClassGroupRange(min = copy.copy(self.__range), |
723 |
copy.copy(self.GetMax()), |
max = copy.copy(self.GetMax()), |
724 |
group = self) |
group = self) |
725 |
|
|
726 |
def GetMin(self): |
def GetMin(self): |
727 |
"""Return the range's minimum value.""" |
"""Return the range's minimum value.""" |
728 |
return self.min |
return self.__range.GetRange()[1] |
729 |
|
|
730 |
def SetMin(self, min): |
def SetMin(self, min): |
731 |
"""Set the range's minimum value. |
"""Set the range's minimum value. |
734 |
maximum value. Use SetRange() to change both min and max values. |
maximum value. Use SetRange() to change both min and max values. |
735 |
""" |
""" |
736 |
|
|
737 |
self.SetRange(min, self.max) |
self.SetRange(min, self.__range.GetRange()[2]) |
738 |
|
|
739 |
def GetMax(self): |
def GetMax(self): |
740 |
"""Return the range's maximum value.""" |
"""Return the range's maximum value.""" |
741 |
return self.max |
return self.__range.GetRange()[2] |
742 |
|
|
743 |
def SetMax(self, max): |
def SetMax(self, max): |
744 |
"""Set the range's maximum value. |
"""Set the range's maximum value. |
746 |
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 |
747 |
minimum value. Use SetRange() to change both min and max values. |
minimum value. Use SetRange() to change both min and max values. |
748 |
""" |
""" |
749 |
self.SetRange(self.min, max) |
self.SetRange(self.__range.GetRange()[1], max) |
750 |
|
|
751 |
def SetRange(self, min, max): |
def SetRange(self, min, max = None): |
752 |
"""Set a new range. |
"""Set a new range. |
753 |
|
|
754 |
Note that min must be strictly less than max. |
Note that min must be strictly less than max. |
757 |
min -- the new maximum value |
min -- the new maximum value |
758 |
""" |
""" |
759 |
|
|
760 |
if min >= max: |
if isinstance(min, Range): |
761 |
raise ValueError(_("ClassGroupRange: %i(min) >= %i(max)!") % |
self.__range = min |
762 |
(min, max)) |
else: |
763 |
self.min = min |
if max is None: |
764 |
self.max = max |
raise ValueError() |
765 |
|
|
766 |
|
self.__range = Range(("[", min, max, "[")) |
767 |
|
|
768 |
def GetRange(self): |
def GetRange(self): |
769 |
"""Return the range as a tuple (min, max)""" |
"""Return the range as a string""" |
770 |
return (self.min, self.max) |
#return (self.__min, self.__max) |
771 |
|
return self.__range.string(self.__range.GetRange()) |
772 |
|
|
773 |
def Matches(self, value): |
def Matches(self, value): |
774 |
"""Determine if the given value lies with the current range. |
"""Determine if the given value lies with the current range. |
776 |
The following check is used: min <= value < max. |
The following check is used: min <= value < max. |
777 |
""" |
""" |
778 |
|
|
779 |
return self.min <= value < self.max |
return operator.contains(self.__range, value) |
780 |
|
#return self.__min <= value < self.__max |
781 |
|
|
782 |
def GetDisplayText(self): |
def GetDisplayText(self): |
783 |
label = self.GetLabel() |
label = self.GetLabel() |
784 |
|
|
785 |
if label != "": return label |
if label != "": return label |
786 |
|
|
787 |
return _("%s - %s") % (self.GetMin(), self.GetMax()) |
#return _("%s - %s") % (self.GetMin(), self.GetMax()) |
788 |
|
#return repr(self.__range) |
789 |
|
return self.__range.string(self.__range.GetRange()) |
790 |
|
|
791 |
def __eq__(self, other): |
def __eq__(self, other): |
792 |
return ClassGroup.__eq__(self, other) \ |
return ClassGroup.__eq__(self, other) \ |
793 |
and isinstance(other, ClassGroupRange) \ |
and isinstance(other, ClassGroupRange) \ |
794 |
and self.GetRange() == other.GetRange() |
and self.__range == other.__range |
795 |
|
#and self.__min == other.__min \ |
796 |
|
#and self.__max == other.__max |
797 |
|
|
798 |
|
def __repr__(self): |
799 |
|
return "(" + str(self.__range) + ClassGroup.__repr__(self) + ")" |
800 |
|
#return "(" + repr(self.__min) + ", " + repr(self.__max) + ", " + \ |
801 |
|
#ClassGroup.__repr__(self) + ")" |
802 |
|
|
803 |
class ClassGroupMap(ClassGroup): |
class ClassGroupMap(ClassGroup): |
804 |
"""Currently, this class is not used.""" |
"""Currently, this class is not used.""" |