summaryrefslogtreecommitdiff
path: root/cad/src/foundation/LeafLikeGroup.py
blob: 6ad849c3e0e542f664761e86b8efa20206d768d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# Copyright 2007-2008 Nanorex, Inc.  See LICENSE file for details.
"""
LeafLikeGroup.py - abstract superclass for groups that appear as leaves
in the MT, e.g. DnaStrandOrSegment, NanotubeSegment, PeptideSegment.

@author: Bruce
@version: $Id$
@copyright: 2007-2008 Nanorex, Inc.  See LICENSE file for details.

History:

most methods written by Bruce as part of DnaStrandOrSegment,
and subsequently copied into NanotubeSegment and PeptideSegment
by Ninad and/or Mark and/or Piotr.

bruce 081217 made this class to contain common code for those
classes which originated in DnaStrandOrSegment (which was
svn copied to initiate this file).

TODO:

notice and pull in other common code subsequently
added to some of our subclasses.

"""

from foundation.Group import Group

from utilities.debug_prefs import debug_pref, Choice_boolean_False

class LeafLikeGroup(Group):
    """
    Abstract superclass for Groups that appear as leaves in the Model Tree.

    Internally, this is just a specialized Group containing subclass-
    specific subobjects and attributes, and overriding some Node or Group API
    methods to change Model Tree behavior (and perhaps other behavior).
    """

    def permit_addnode_inside(self): #bruce 080626
        """
        [overrides superclass method]
        """
        return False

    def permits_ungrouping(self):
        """
        Should the user interface permit users to dissolve this Group
        using self.ungroup?

        [overrides superclass method]
        """
        #bruce 080207 in deprecated class Block, copied to DnaStrandOrSegment 080318
        return self._show_all_kids_for_debug() # normally False

    def _show_all_kids_for_debug(self):
        #bruce 080207 in deprecated class Block, copied to DnaStrandOrSegment 080318
        #bruce 081217: revised to use same debug_pref for all node classes
        debug_pref_name = "Model Tree: show content of leaf-like Groups?"
        return debug_pref( debug_pref_name, Choice_boolean_False )

    def _f_wants_to_be_killed(self, pre_updaters = True, **opts): # in LeafLikeGroup
        """
        [friend method for enforce_permitted_members_in_groups and subroutines]

        Does self want to be killed due to members that got ejected
        by _f_move_nonpermitted_members (or due to completely invalid structure
        from before then, and no value in keeping self even temporarily)?

        @rtype: boolean

        [overrides superclass method]
        """
        #bruce 080319
        del opts, pre_updaters
        return not self.members

    def MT_DND_can_drop_inside(self): #bruce 080317, revised 080318
        """
        Are ModelTree Drag and Drop operations permitted to drop nodes
        inside self?

        [overrides superclass method]
        """
        return self._show_all_kids_for_debug() # normally False

    def openable(self):
        """
        whether tree widgets should permit the user to open/close
        their view of this node

        [overrides superclass method]
        """
        # if we decide this depends on the tree widget or on somet for thing about it,
        # we'll have to pass in some args... don't do that unless/until we need to.

        #If there are no MT_kids (subnodes visible in MT under this group) then
        #don't make this node 'openable'. This makes sure that expand/ collapse
        #pixmap next to the node is not shown for this type of Group with 0
        #MT_kids
        #Examples of such groups include empty groups, DnaStrand Groups,
        #DnaSegments etc -- Ninad 2008-03-15
        return len(self.MT_kids()) != 0

    def MT_kids(self, display_prefs = {}):
        """
        [overrides superclass method]
        """
        if self._show_all_kids_for_debug(): # normally False
            # bruce 080318
            return self.members
        return ()

    def get_all_content_chunks(self): # by Ninad; moved & docstring revised by bruce 081217
        """
        Return all the chunks which should be considered logical contents
        of self.

        The default implementation returns direct members of self
        which are chunks.

        Some subclasses must override this.
        """
        # TODO: refactor this and its callers to use a more general definition
        # of what to return, and to use related submethods such as one to
        # iterate over logical contents (perhaps adding that to API).
        # The different calls might need splitting into different API methods.
        # REVIEW: I suspect there are bugs at present from not including jigs,
        # when this is used for dragging.
        # [bruce 081217 comments]
        all_content_chunk_list = []

        for member in self.members:
            if isinstance(member, self.assy.Chunk):
                all_content_chunk_list.append(member)

        return all_content_chunk_list

    pass # end of class DnaStrandOrSegment

# end