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 IsPaused(self)
Test if animation is paused.
def Record(self)
Record new view state.
def GoToFrame(self, index)
Render frame of given index.
def SetMode(self, mode)
Start animation mode.
def IsRunning(self)
Test if timer is running.
def GetFrameCount(self)
Return number of recorded frames.
def Clear(self)
Clear all records.
Class represents animation as a sequence of states (views).
def Pause(self)
Pause recording/playing.
def Play(self)
Render next frame.
def Stop(self)
Stop recording/playing.
def SetFPS(self, fps)
Set Frames Per Second value.
def UpdateView(self, params)
Update view data in map window and render.
def Start(self)
Start recording/playing.
def SaveAnimationFile(self, path, prefix, format)
Generate image files.
def Update(self)
Record/play next view state (on timer event)
def Exists(self)
Returns if an animation has been recorded.
def PostUpdateIndexEvent(self, index)
Frame index changed, update tool window.
def GetMode(self)
Get animation mode (record, play, save)
def GetInterval(self)
Return timer interval in ms.
def __init__(self, mapWindow, timer)
Animation constructor.
def SetPause(self, pause)
def StopSaving(self)
Abort image files generation.
def PostFinishedEvent(self)
Animation ends.