wxMaxima
AnimationCell.h
Go to the documentation of this file.
1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2007-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4 // (C) 2014-2016 Gunter Königsmann <wxMaxima@physikbuch.de>
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 // SPDX-License-Identifier: GPL-2.0+
22 
29 #ifndef ANIMATIONCELL_H
30 #define ANIMATIONCELL_H
31 
32 #include "Cell.h"
33 #include "Image.h"
34 #include "ImgCellBase.h"
35 #include <wx/image.h>
36 #include <wx/timer.h>
37 
38 #include <wx/filesys.h>
39 #include <wx/fs_arc.h>
40 #include <wx/mstream.h>
41 #include <wx/wfstream.h>
42 
43 #include <vector>
44 
45 class AnimationCell final : public ImgCellBase
46 {
47 public:
59  AnimationCell(GroupCell *group, Configuration **config, std::shared_ptr<wxFileSystem> filesystem, int framerate = -1);
60  AnimationCell(GroupCell *group, Configuration **config, int framerate = -1);
61  AnimationCell(GroupCell *group, const AnimationCell &cell);
63  AnimationCell(GroupCell *group, Configuration **config, const wxMemoryBuffer &image, const wxString &type);
64  AnimationCell(GroupCell *group, Configuration **config, const wxString &image, bool remove);
65  std::unique_ptr<Cell> Copy(GroupCell *group) const override;
66  void operator=(const AnimationCell&) = delete;
67  AnimationCell(const AnimationCell&) = delete;
68 
69  void SetConfiguration(Configuration **config) override;
70  int GetPPI() const override {if(IsOk()) return m_images[m_displayed]->GetPPI();else return 0;}
71  size_t GetOriginalWidth() const override {if(IsOk())return m_images[m_displayed]->GetOriginalWidth();else return 0;}
72  size_t GetOriginalHeight() const override {if(IsOk())return m_images[m_displayed]->GetOriginalHeight();else return 0;}
73  wxString GetExtension() const override
74  { if (IsOk())return m_images[m_displayed]->GetExtension(); else return wxEmptyString; }
75 
76  const CellTypeInfo &GetInfo() override;
77  ~AnimationCell();
78  int Length() const {return m_images.size();}
79  void LoadImages(wxMemoryBuffer imageData);
80  void LoadImages(wxString imageFile);
82  void SetPPI(int ppi) override;
84  static wxDataFormat m_gifFormat;
85 
87  bool CanExportSVG() const override {return (m_images[m_displayed] != NULL) && m_images[m_displayed]->CanExportSVG();}
88 
90  class GifDataObject : public wxCustomDataObject
91  {
92  public:
93  explicit GifDataObject(const wxMemoryOutputStream &str);
94 
95  GifDataObject();
96 
97  private:
98  wxCharBuffer m_databuf;
99  };
100 
101  bool IsOk() const;
102 
103  const wxString &GetToolTip(wxPoint point) const override;
104 
110  void ClearCache() override;
111 
112  void LoadImages(wxArrayString images, bool deleteRead);
113 
114  int GetDisplayedIndex() const { return m_displayed; }
115 
116  wxImage GetBitmap(int n) const
117  { return m_images[n]->GetUnscaledBitmap().ConvertToImage(); }
118 
119  void SetDisplayedIndex(int ind);
120 
122  wxSize ToImageFile(wxString file) override;
123 
125  wxSize ToGif(wxString file);
126 
127  bool CopyToClipboard() const override;
128 
131 
137  int GetFrameRate() const;
138 
143  void ReloadTimer();
144 
149  void StopTimer();
150 
156  int SetFrameRate(int Freq);
157 
158  bool AnimationRunning() const { return m_animationRunning; }
159  void AnimationRunning(bool run);
160  bool CanPopOut() const override
161  { return (!m_images[m_displayed]->GnuplotSource().empty()); }
162 
163  void GnuplotSource(int image, wxString gnuplotFilename, wxString dataFilename, std::shared_ptr<wxFileSystem> filesystem)
164  { m_images[image]->GnuplotSource(gnuplotFilename, dataFilename, filesystem); }
165 
166  wxString GnuplotSource() const override
167  {
168  if (!m_images[m_displayed])
169  return wxEmptyString;
170  else
171  return m_images[m_displayed]->GnuplotSource();
172  }
173 
174 private:
175  CellPointers *const m_cellPointers = GetCellPointers(); // must come before m_timer (!)
176  wxTimer m_timer;
177  std::vector<std::shared_ptr<Image>> m_images;
178  std::shared_ptr<wxFileSystem> m_fileSystem;
179 
184  int m_framerate = -1;
185  int m_displayed = 0;
186  int m_imageBorderWidth = 0;
187 
188 //** Bitfield objects (1 bytes)
189 //**
190  void InitBitFields()
191  { // Keep the initialization order below same as the order
192  // of bit fields in this class!
193  m_animationRunning = true;
194  m_drawBoundingBox = false;
195  }
196 
197  bool m_animationRunning : 1 /* InitBitFields */;
198  bool m_drawBoundingBox : 1 /* InitBitFields */;
199 
200 
201  int GetImageBorderWidth() const override { return m_imageBorderWidth; }
202 
203  void Recalculate(AFontSize fontsize) override;
204 
205  void Draw(wxPoint point) override;
206 
207  wxString ToMatlab() const override;
208  wxString ToRTF() const override;
209  wxString ToString() const override;
210  wxString ToTeX() const override;
211  wxString ToXML() const override;
212 
213  double GetMaxWidth() const override;
214  double GetHeightList() const override;
215  void SetMaxWidth(double width) override;
216  void SetMaxHeight(double height) override;
217 
218  void DrawBoundingBox(wxDC &WXUNUSED(dc), bool WXUNUSED(all) = false) override
219  { m_drawBoundingBox = true; }
220 };
221 
222 #endif // ANIMATIONCELL_H
AnimationCell::GetFrameRate
int GetFrameRate() const
Definition: AnimationCell.cpp:127
Cell.h
AnimationCell::GetToolTip
const wxString & GetToolTip(wxPoint point) const override
Definition: AnimationCell.cpp:542
AnimationCell::GnuplotSource
wxString GnuplotSource() const override
The name of the file with gnuplot commands that created this file.
Definition: AnimationCell.h:166
AnimationCell::CanExportSVG
bool CanExportSVG() const override
Can the current image be exported in SVG format?
Definition: AnimationCell.h:87
AnimationCell::CopyAnimationToClipboard
bool CopyAnimationToClipboard()
Put the animation on the clipboard.
Definition: AnimationCell.cpp:631
AnimationCell::CanPopOut
bool CanPopOut() const override
Can this cell be popped out interactively in gnuplot?
Definition: AnimationCell.h:160
AnimationCell::CopyToClipboard
bool CopyToClipboard() const override
Copies the cell to the system's clipboard.
Definition: AnimationCell.cpp:603
AnimationCell::GetInfo
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
AnimationCell::m_gifFormat
static wxDataFormat m_gifFormat
A class that publishes wxm data to the clipboard.
Definition: AnimationCell.h:84
AnimationCell::ToImageFile
wxSize ToImageFile(wxString file) override
Exports the image the animation currently displays.
Definition: AnimationCell.cpp:485
CellPointers
Definition: CellPointers.h:44
Image.h
AFontSize
Definition: FontAttribs.h:97
AnimationCell::ReloadTimer
void ReloadTimer()
Definition: AnimationCell.cpp:145
AnimationCell
Definition: AnimationCell.h:45
AnimationCell::ToGif
wxSize ToGif(wxString file)
Exports the whole animation as animated gif.
Definition: AnimationCell.cpp:554
AnimationCell::SetPPI
void SetPPI(int ppi) override
Set the animation's resolution.
Definition: AnimationCell.cpp:479
Configuration
Definition: Configuration.h:83
ImgCellBase
Definition: ImgCellBase.h:40
GroupCell
Definition: GroupCell.h:68
AnimationCell::GetExtension
wxString GetExtension() const override
Returns the file name extension that matches the image type.
Definition: AnimationCell.h:73
CellTypeInfo
A class that carries information about the type of a cell.
Definition: Cell.h:90
AnimationCell::Copy
std::unique_ptr< Cell > Copy(GroupCell *group) const override
AnimationCell::SetFrameRate
int SetFrameRate(int Freq)
Definition: AnimationCell.cpp:170
AnimationCell::ClearCache
void ClearCache() override
Definition: AnimationCell.cpp:590
AnimationCell::GifDataObject
A Gif object for the clipboard.
Definition: AnimationCell.h:90
AnimationCell::StopTimer
void StopTimer()
Definition: AnimationCell.cpp:155