2 @package nviz.animation
4 @brief Nviz (3D view) animation
9 (C) 2011 by the GRASS Development Team
11 This program is free software under the GNU General Public License
12 (>=v2). Read the file COPYING that comes with GRASS for details.
14 @author Anna Kratochvilova <kratochanna gmail.com>
21 from wx.lib.newevent
import NewEvent
23 wxAnimationFinished, EVT_ANIM_FIN = NewEvent()
24 wxAnimationUpdateIndex, EVT_ANIM_UPDATE_IDX = NewEvent()
27 """!Class represents animation as a sequence of states (views).
28 It enables to record, replay the sequence and finally generate
29 all image files. Recording and replaying is based on timer events.
30 There is no frame interpolation like in the Tcl/Tk based Nviz.
33 """!Animation constructor
35 @param mapWindow glWindow where rendering takes place
36 @param timer timer for recording and replaying
54 """!Start recording/playing"""
58 """!Pause recording/playing"""
62 """!Stop recording/playing"""
67 """!Record/play next view state (on timer event)"""
71 """!Record new view state"""
72 self.animationList.append({
'view' : copy.deepcopy(self.mapWindow.view),
73 'iview': copy.deepcopy(self.mapWindow.iview)})
79 """!Render next frame"""
97 """!Update view data in map window and render"""
98 toolWin = self.mapWindow.GetToolWin()
99 toolWin.UpdateState(view = params[
'view'], iview = params[
'iview'])
101 self.mapWindow.UpdateView()
103 self.mapWindow.render[
'quick'] =
True
104 self.mapWindow.Refresh(
False)
107 """!Test if timer is running"""
108 return self.timer.IsRunning()
111 """!Start animation mode
113 @param mode animation mode (record, play, save)
118 """!Get animation mode (record, play, save)"""
122 """!Test if animation is paused"""
129 """!Returns if an animation has been recorded"""
133 """!Return number of recorded frames"""
137 """!Clear all records"""
142 """!Render frame of given index"""
151 """!Animation ends"""
152 toolWin = self.mapWindow.GetToolWin()
153 event = wxAnimationFinished(mode = self.
mode)
154 wx.PostEvent(toolWin, event)
157 """!Frame index changed, update tool window"""
158 toolWin = self.mapWindow.GetToolWin()
159 event = wxAnimationUpdateIndex(index = index, mode = self.
mode)
160 wx.PostEvent(toolWin, event)
163 """!Abort image files generation"""
167 """"!Test if animation has been saved (to images)"""
171 """!Generate image files
173 @param path path to direcory
174 @param prefix file prefix
175 @param format index of image file format
177 w, h = self.mapWindow.GetClientSizeTuple()
178 toolWin = self.mapWindow.GetToolWin()
186 filepath = os.path.join(path, filename)
187 self.mapWindow.SaveToFile(FileName = filepath, FileType = self.
formats[format],
188 width = w, height = h)
192 toolWin.UpdateFrameIndex(index = self.
currentFrame, goToFrame =
False)
200 """!Set Frames Per Second value
201 @param fps frames per second
206 """!Return timer interval in ms"""
207 return 1000. / self.
fps
def PostFinishedEvent
Animation ends.
def GetInterval
Return timer interval in ms.
def StopSaving
Abort image files generation.
def Start
Start recording/playing.
def UpdateView
Update view data in map window and render.
def Pause
Pause recording/playing.
def Play
Render next frame.
Class represents animation as a sequence of states (views).
def PostUpdateIndexEvent
Frame index changed, update tool window.
def IsRunning
Test if timer is running.
def SetFPS
Set Frames Per Second value.
def Clear
Clear all records.
def GoToFrame
Render frame of given index.
def Record
Record new view state.
def SetMode
Start animation mode.
def __init__
Animation constructor.
def GetFrameCount
Return number of recorded frames.
def Update
Record/play next view state (on timer event)
def Exists
Returns if an animation has been recorded.
def Stop
Stop recording/playing.
def IsPaused
Test if animation is paused.
def GetMode
Get animation mode (record, play, save)
def SaveAnimationFile
Generate image files.