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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
|
# Copyright 2008 Nanorex, Inc. See LICENSE file for details.
"""
MultipleDnaSegmentResize_GraphicsMode.py
Graphics mode for resizing multiple dna segments at once
@author: Ninad
@copyright: 2008 Nanorex, Inc. See LICENSE file for details.
@version:$Id$
History:
TODO:
see MultipleDnaSegmentResize_EditCommand
"""
from dna.commands.DnaSegment.DnaSegment_GraphicsMode import DnaSegment_GraphicsMode
from PyQt4.Qt import Qt
from graphics.drawing.drawDnaRibbons import drawDnaRibbons
import foundation.env as env
from utilities.prefs_constants import selectionColor_prefs_key
from utilities.prefs_constants import DarkBackgroundContrastColor_prefs_key
from utilities.prefs_constants import cursorTextColor_prefs_key
from utilities.constants import black, banana, silver, lighterblue, darkred
from graphics.drawing.CS_draw_primitives import drawcylinder
from graphics.drawing.CS_draw_primitives import drawsphere
SPHERE_RADIUS = 6.0
SPHERE_DRAWLEVEL = 2
SPHERE_OPACITY = 0.5
CYL_RADIUS = 13.0
CYL_OPACITY = 0.4
SPHERE_RADIUS_2 = 3.0
_superclass = DnaSegment_GraphicsMode
class MultipleDnaSegmentResize_GraphicsMode(DnaSegment_GraphicsMode):
"""
Graphics mode for resizing multiple dna segments at once
"""
def Enter_GraphicsMode(self):
_superclass.Enter_GraphicsMode(self)
#@TODO: Deselect everything. Is it Ok to do??
self.win.assy.unpickall_in_GLPane()
def update_cursor_for_no_MB(self):
"""
Update the cursor for no mouse button pressed
"""
if self.command:
if self.command.isAddSegmentsToolActive():
self.o.setCursor(self.win.addSegmentToResizeSegmentListCursor)
return
if self.command.isRemoveSegmentsToolActive():
self.o.setCursor(self.win.removeSegmentFromResizeSegmentListCursor)
return
_superclass.update_cursor_for_no_MB(self)
def chunkLeftUp(self, a_chunk, event):
"""
Overrides superclass method. If add or remove segmets tool is active,
upon leftUp , when this method gets called, it modifies the list
of segments being resized by self.command.
@see: self.update_cursor_for_no_MB()
@see: self.end_selection_from_GLPane()
"""
if self.command.isAddSegmentsToolActive() or \
self.command.isRemoveSegmentsToolActive():
if a_chunk.isAxisChunk():
segmentGroup = a_chunk.parent_node_of_class(
self.win.assy.DnaSegment)
if segmentGroup is not None:
if self.command.isAddSegmentsToolActive():
self.command.addSegmentToResizeSegmentList(segmentGroup)
if self.command.isRemoveSegmentsToolActive():
self.command.removeSegmentFromResizeSegmentList(segmentGroup)
self.end_selection_from_GLPane()
return
_superclass.chunkLeftUp(self, a_chunk, event)
def end_selection_from_GLPane(self):
"""
Overrides superclass method. In addition to selecting or deselecting
the chunk, if a tool that adds Dna segments to the segment list in
the property manager is active, this method also adds
the selected dna segments to that list. Example, if user selects
'Add Dna segments' tool and does a lasso selection , then this also
method adds the selected segments to the list. Opposite behavior if
the 'remove segments from segment list too, is active)
"""
_superclass.end_selection_from_GLPane(self)
selectedSegments = self.win.assy.getSelectedDnaSegments()
for segment in selectedSegments:
if self.command.isAddSegmentsToolActive():
self.command.addSegmentToResizeSegmentList(segment)
if self.command.isRemoveSegmentsToolActive():
self.command.removeSegmentFromResizeSegmentList(segment)
def keyPressEvent(self, event):
"""
Handles keyPressEvent. Overrides superclass method. If delete key
is pressed while the focus is inside the PM list widget, it deletes
that list widget item.
@see: MultipleDnaSegmentResize_PropertyManager.listWidgetHasFocus()
@TODO: alls self.command.propMgr object which is better to avoid...
"""
if event.key() == Qt.Key_Delete:
if self.command.propMgr and self.command.propMgr.listWidgetHasFocus():
self.command.propMgr.removeListWidgetItems()
return
_superclass.keyPressEvent(self, event)
def _drawSpecialIndicators(self):
"""
Overrides superclass method.
This draws a transparent cylinder around the segments being resized, to
easily distinguish them from other model.
@see: basicGraphicsmode._drawSpecialIndicators()
"""
if self.command:
segmentList = self.command.getResizeSegmentList()
for segment in segmentList:
end1, end2 = segment.getAxisEndPoints()
if end1 is not None and end2 is not None:
drawcylinder(banana,
end1,
end2,
CYL_RADIUS,
capped = True,
opacity = CYL_OPACITY )
def _drawTags(self):
"""
Overrides _superClass._drawTags()
for self._tagPositions.
@see: self.drawTag()
@see: GraphicsMode._drawTags()
@see: class PM_SelectionWidget
"""
if 0:
#see method for details. Used for debugging only
self._DEBUG_Flag_EndPoint1_ofDnaSegments()
if self._tagPositions:
for point in self._tagPositions:
drawsphere(silver,
point,
SPHERE_RADIUS,
SPHERE_DRAWLEVEL,
opacity = SPHERE_OPACITY)
def _DEBUG_Flag_EndPoint1_ofDnaSegments(self):
"""
Temporary method that draws a sphere to indicate the endPoint1
of each segment being resized. Used for debugging a bug in
computing average end points for the resize handles.
"""
if not self.command:
return
endPoints_1 = []
for segment in self.command.getResizeSegmentList():
e1, e2 = segment.getAxisEndPoints()
if e1 is not None:
endPoints_1.append(e1)
for end1 in endPoints_1:
drawsphere(lighterblue,
end1,
SPHERE_RADIUS,
SPHERE_DRAWLEVEL,
opacity = 1.0)
def _drawDnaRubberbandLine(self):
"""
Overrides superclass method. It loops through the segments being resized
and draws the rubberband lines for all. NOT this could be SLOW
@see: MultipleDnaSegmentResize_EditCommand.getDnaRibbonParams() for
comments.
@TODO: needs more cleanup
"""
handleType = ''
if self.command.grabbedHandle is not None:
if self.command.grabbedHandle in [self.command.rotationHandle1,
self.command.rotationHandle2]:
handleType = 'ROTATION_HANDLE'
else:
handleType = 'RESIZE_HANDLE'
if handleType and handleType == 'RESIZE_HANDLE':
# textColor is not used. I'm going to ask Ninad if this should
# stay in or should be removed. --Mark
#textColor = env.prefs[cursorTextColor_prefs_key] # Mark 2008-08-28
for segment in self.command.getResizeSegmentList():
self.command.currentStruct = segment
params_when_adding_bases, params_when_removing_bases = \
self.command.getDnaRibbonParams()
if params_when_adding_bases:
end1, \
end2, \
basesPerTurn,\
duplexRise, \
ribbon1_start_point, \
ribbon2_start_point, \
ribbon1_direction, \
ribbon2_direction, \
ribbon1Color, \
ribbon2Color = params_when_adding_bases
#Note: The displayStyle argument for the rubberband line should
#really be obtained from self.command.struct. But the struct
#is a DnaSegment (a Group) and doesn't have attr 'display'
#Should we then obtain this information from one of its strandChunks?
#but what if two strand chunks and axis chunk are rendered
#in different display styles? since situation may vary, lets
#use self.glpane.displayMode for rubberbandline displayMode
drawDnaRibbons(self.glpane,
end1,
end2,
basesPerTurn,
duplexRise,
self.glpane.scale,
self.glpane.lineOfSight,
self.glpane.displayMode,
ribbonThickness = 4.0,
ribbon1_start_point = ribbon1_start_point,
ribbon2_start_point = ribbon2_start_point,
ribbon1_direction = ribbon1_direction,
ribbon2_direction = ribbon2_direction,
ribbon1Color = ribbon1Color,
ribbon2Color = ribbon2Color,
)
#Draw a sphere that indicates the current position of
#the resize end of each segment .
drawsphere(env.prefs[selectionColor_prefs_key],
end2,
SPHERE_RADIUS_2,
SPHERE_DRAWLEVEL,
opacity = SPHERE_OPACITY)
#Draw the text next to the cursor that gives info about
#number of base pairs etc
self._drawCursorText(position = end2)
elif params_when_removing_bases:
end2 = params_when_removing_bases
#Draw a sphere that indicates the current position of
#the resize end of each segment.
drawsphere(darkred,
end2,
SPHERE_RADIUS_2,
SPHERE_DRAWLEVEL,
opacity = SPHERE_OPACITY)
#Draw the text next to the cursor that gives info about
#number of base pairs etc
self._drawCursorText(position = end2)
#Reset the command.currentStruct to None. (it is set to 'segment'
#at the beginning of the for loop.
self.command.currentStruct = None
|