summaryrefslogtreecommitdiff
path: root/cad/src/dna/commands/MakeCrossovers/ListWidgetItems_Command_Mixin.py
blob: 67e6b411ea6c9e0af786ee08295865798d2754d9 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Copyright 2008 Nanorex, Inc.  See LICENSE file for details.
"""
ListWidgetItems_Command_Mixin.py

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

History:
2008-05-27 -2008-05-29 Created and modified.

TODO as of 2008-06-01:
- Rename this class and others like ListWidgetItems_*_Mixin to a better name
- At the moment used only by MakeCrossOvers_* classes, need refactoring of
MultipleDnaSegmentResize classes so that they also implement this API
OR refactor these classes so that they are wrap the functionality and are used
as an object in the classes such as MakeCrossovers_*.
- Move this and other related classes to possibly dna.command_support
- These classes refer to MultipleDnaSegmentResize classes because this was
originally implemented there (see also dna.command_support.DnaSegmentList)

@see: MakeCrossovers_Command
      ListWidgetItems_GraphicsMode_Mixin
      ListWidgetItems_PM_Mixin
"""

class ListWidgetItems_Command_Mixin:

    #A list of all dnasegments that will be scanned for potential
    #crossover sites.
    _structList = []

    def command_entered(self):
        """
        @see baseCommand.command_entered() for documentation
        @see MakeCrossovers_Command.command_entered()
        """
        self._structList = []


    def itemLimitForSegmentListWidget(self):
        """
        Maximum number of items allowed in the segment list widet.(For
        performance reasons)
        """
        return 30


    def ensureSegmentListItemsWithinLimit(self, segments):
        """
        Subclasses should override this method.
        """
        pass


    def logMessage(self, type = ''):
        """
        Subclasses should override this
        """
        pass


    def activateAddSegmentsTool(self, enableFlag = True):
        """
        """
        if self.propMgr is None:
            return False

        return self.propMgr.activateAddSegmentsTool(enableFlag)

    def isAddSegmentsToolActive(self):
        """
        Returns True if the Add segments tool in the PM, that allows adding
        dna segments from the segment list,  is active.
        @see: MultipleDnaSegmentResize_GraphicsMode.chunkLeftUp()
        @see: MultipleDnaSegmentResize_GraphicsMode.end_selection_from_GLPane()
        @see: self.isRemoveSegmentsToolActive()
        @see: self.addSegmentToResizeSegmentList()
        """
        if self.propMgr is None:
            return False

        return self.propMgr.isAddSegmentsToolActive()


    def activateRemoveSegmentsTool(self, enableFlag = True):
        if self.propMgr is None:
            return
        self.propMgr.activateRemoveSegmentsTool(enableFlag)

    def isRemoveSegmentsToolActive(self):
        """
        Returns True if the Remove Segments tool in the PM, that allows removing
        dna segments from the segment list, is active.
        @see: MultipleDnaSegmentResize_GraphicsMode.chunkLeftUp()
        @see: MultipleDnaSegmentResize_GraphicsMode.end_selection_from_GLPane()
        @see: self.isAddSegmentsToolActive()
        @see: self.removeSegmentFromResizeSegmentList()
        """
        if self.propMgr is None:
            return False

        return self.propMgr.isRemoveSegmentsToolActive()

    def addSegmentToSegmentList(self, segment):
        """
        Adds the given segment to the segment list
        @param segment: The DnaSegment to be added to the segment list.
        Also does other things such as updating handles etc.
        @type sement: B{DnaSegment}
        @see: self.isAddSegmentsToolActive()
        @TODO: This allows ONLY PAM3 DNA segments to be added to the
        segment list. NEEDS REVISION
        """
        if segment.is_PAM3_DnaSegment() and segment not in self._structList:
            self._structList.append(segment)

    def removeSegmentFromSegmentList(self, segment):
        """
        Removes the given segment from the segment list
        @param segment: The DnaSegment to be removed from the segment
        list. Also does other things such as updating handles etc.
        @type sement: B{DnaSegment}
        @see: self.isRemoveSegmentsToolActive()
        """
        if segment in self._structList:
            self._structList.remove(segment)

    def getSegmentList(self):
        return self._structList

    def updateSegmentList(self):
        """
        Update the structure list, removing the invalid items in the structure
        @see:MultipleDnaSegmentResize_PropertyManager.model_changed()
        @see: self.getstructList()
        """
        #@TODO: Should this always be called in self.getStructList()??? But that
        #could be SLOW because that method gets called too often by
        #the edit command's graphics mode.
        def func(struct):
            if struct is not None and not struct.killed():
                if not struct.isEmpty():
                    return True

            return False

        new_list = filter( lambda struct:
                           func(struct) ,
                           self._structList )

        if len(new_list) != len(self._structList):
            self._structList = new_list

    def setSegmentList(self, structList):
        """
        Replaces the list of segments with the
        given segmentList. Calls the related method of self.struct.
        @param structList: New list of segments.
        @type  structList: list
        @see: DnaSegmentList.setResizeStructList()
        """
        self._structList = structList