wxMaxima
Loading...
Searching...
No Matches
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 <memory>
36#include <wx/image.h>
37#include <wx/timer.h>
38
39#include <wx/fs_arc.h>
40#include <wx/mstream.h>
41#include <wx/wfstream.h>
42
43#include <vector>
44
45class AnimationCell final : public ImgCellBase
46{
47public:
61 const AttachmentSource &attachments, double framerate = -1);
62 AnimationCell(GroupCell *group, Configuration *config, double framerate = -1);
65 AnimationCell(GroupCell *group, Configuration *config, const wxMemoryBuffer &image, const wxString &type);
66 AnimationCell(GroupCell *group, Configuration *config, const wxString &image, bool remove);
67 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
68 void operator=(const AnimationCell&) = delete;
69 AnimationCell(const AnimationCell&) = delete;
70
71 void SetConfiguration(Configuration *config) override;
72 int GetPPI() const override {if(IsOk()) return m_images.at(m_displayed)->GetPPI(); else return 0;}
73 size_t GetOriginalWidth() const override {
74 if(IsOk())return m_images.at(m_displayed)->GetOriginalWidth(); else return 0;}
75 size_t GetOriginalHeight() const override {
76 if(IsOk())return m_images.at(m_displayed)->GetOriginalHeight(); else return 0;}
79 void TallyImageLoadFailures(int &dataUnavailable, int &decodeFailed) const override {
80 for (const auto &image : m_images) {
81 if (!image) continue;
82 switch (image->GetLoadFailureKind()) {
83 case Image::LoadFailureKind::DataUnavailable: dataUnavailable++; break;
84 case Image::LoadFailureKind::DecodeFailed: decodeFailed++; break;
85 default: break;
86 }
87 }
88 }
89 wxString GetExtension() const override
90 { if (IsOk())return m_images.at(m_displayed)->GetExtension(); else return wxEmptyString; }
91
92 const CellTypeInfo &GetInfo() override;
93 ~AnimationCell() override;
94 int Length() const {return m_images.size();}
95 void LoadImages(const wxMemoryBuffer& imageData);
96 void LoadImages(const wxString& imageFile);
98 void SetPPI(int ppi) override;
100 static wxDataFormat m_gifFormat;
101
103 bool CanExportSVG() const override {return (m_images.at(m_displayed) != nullptr) && m_images.at(m_displayed)->CanExportSVG();}
104
106 class GifDataObject : public wxCustomDataObject
107 {
108 public:
109 explicit GifDataObject(const wxMemoryOutputStream &str);
110
112
113 private:
114 wxCharBuffer m_databuf;
115 };
116
117 bool IsOk() const;
118
119 const wxString GetToolTip(wxPoint point) const override;
120
126 void ClearCache() override;
127
128 void LoadImages(wxArrayString images, bool deleteRead);
129
130 int GetDisplayedIndex() const { return m_displayed; }
131
132 wxImage GetBitmap(int n) const
133 { return m_images.at(n)->GetUnscaledBitmap().ConvertToImage(); }
134
135 void SetDisplayedIndex(int ind);
136
138 wxSize ToImageFile(wxString file) override;
139
141 wxSize ToGif(const wxString& file);
142
143 bool CopyToClipboard() const override;
144
147
153 double GetFrameRate() const;
154
159 void ReloadTimer();
160
165 void StopTimer();
166
172 double SetFrameRate(double Freq);
173
174 bool AnimationRunning() const { return m_animationRunning; }
175 void AnimationRunning(bool run);
176 void ToggleAnimationRunning(){AnimationRunning(!AnimationRunning());}
177 bool CanPopOut() const override
178 { return m_images.at(m_displayed) && (m_images.at(m_displayed)->HasGnuplotSource()); }
179
180 void GnuplotSource(int image, wxString gnuplotFilename, wxString dataFilename,
181 const AttachmentSource &attachments)
182 { m_images.at(image)->GnuplotSource(std::move(gnuplotFilename),
183 std::move(dataFilename), attachments); }
184 void CompressedGnuplotSource(int image, wxString gnuplotFilename, wxString dataFilename,
185 const AttachmentSource &attachments)
186 { m_images.at(image)->CompressedGnuplotSource(std::move(gnuplotFilename),
187 std::move(dataFilename),
188 attachments); }
189
190 wxString GnuplotSource() const override
191 {
192 if (!m_images.at(m_displayed))
193 return wxEmptyString;
194 else
195 return m_images.at(m_displayed)->GnuplotSource();
196 }
197
198private:
199 ViewCellPointers *const m_viewCellPointers = GetViewCellPointers(); // must come before m_timer (!)
200 std::unique_ptr<wxTimer> m_timer;
201 std::vector<std::shared_ptr<Image>> m_images;
202
209 double m_framerate = -1;
210 int m_displayed = 0;
211 int m_imageBorderWidth = 0;
212
213//** Bitfield objects (1 bytes)
214//**
215 bool m_animationRunning : 1 = true;
216 bool m_drawBoundingBox : 1 = false;
218 AttachmentSource m_attachments;
219
220 int GetImageBorderWidth() const override { return m_imageBorderWidth; }
221
222 void Recalculate(const AFontSize fontsize) const override;
223
225 void SetCurrentPoint(wxPoint point) const override;
226 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
227
228 wxString ToMatlab() const override;
229 wxString ToMathML() const override;
230 wxString ToRTF() const override;
231 wxString ToString() const override;
232 wxString ToTeX() const override;
233 wxString ToXML() const override;
234
235 wxCoord GetMaxWidth() const override;
236 wxCoord GetHeightList() const override { return m_height; }
237 void SetMaxWidth(wxCoord width) override;
238 double GetUserScale() const override;
239 void SetUserScale(double scale) override;
240 bool GetFitToWindow() const override;
241 void SetFitToWindow(bool fit) override;
242 void SetMaxHeight(wxCoord height) override;
243
244 void DrawBoundingBox(wxDC &WXUNUSED(dc), bool WXUNUSED(all) = false) override
245 { m_drawBoundingBox = true; }
246};
247
248#endif // ANIMATIONCELL_H
The definition of the base class of all cells the worksheet consists of.
This file declares the class Image.
int group
Neighbouring sections of the same group aren't separated.
Definition: ToolBarSections.cpp:45
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:99
A Gif object for the clipboard.
Definition: AnimationCell.h:107
Definition: AnimationCell.h:46
wxString GetExtension() const override
Returns the file name extension that matches the image type.
Definition: AnimationCell.h:89
bool CopyToClipboard() const override
Copies the cell to the system's clipboard.
Definition: AnimationCell.cpp:524
void ClearCache() override
Remove all cached scaled images from memory.
Definition: AnimationCell.cpp:512
AnimationCell(GroupCell *group, Configuration *config, const wxMemoryBuffer &image, const wxString &type)
A constructor that loads the compressed file from a wxMemoryBuffer.
bool CanPopOut() const override
Can this cell be popped out interactively in gnuplot?
Definition: AnimationCell.h:177
double SetFrameRate(double Freq)
Set the frame rate of this AnimationCell [in Hz].
Definition: AnimationCell.cpp:155
void SetPPI(int ppi) override
Set the animation's resolution.
Definition: AnimationCell.cpp:437
wxSize ToImageFile(wxString file) override
Exports the image the animation currently displays.
Definition: AnimationCell.cpp:442
wxString GnuplotSource() const override
The name of the file with gnuplot commands that created this file.
Definition: AnimationCell.h:190
void StopTimer()
Stops the timer.
Definition: AnimationCell.cpp:140
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
void ReloadTimer()
Reload the animation timer starting and instantiating and registering it if necessary.
Definition: AnimationCell.cpp:129
bool CopyAnimationToClipboard()
Put the animation on the clipboard.
Definition: AnimationCell.cpp:550
double GetFrameRate() const
Get the frame rate of this AnimationCell [in Hz].
Definition: AnimationCell.cpp:111
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
void SetConfiguration(Configuration *config) override
Tell this cell to use the configuration object config.
Definition: AnimationCell.cpp:98
void TallyImageLoadFailures(int &dataUnavailable, int &decodeFailed) const override
Unlike GetOriginalWidth()/Height(), this tallies EVERY frame, not just the one currently displayed.
Definition: AnimationCell.h:79
const wxString GetToolTip(wxPoint point) const override
Returns the ToolTip this cell provides at a given point.
Definition: AnimationCell.cpp:463
static wxDataFormat m_gifFormat
A class that publishes wxm data to the clipboard.
Definition: AnimationCell.h:100
bool CanExportSVG() const override
Can the current image be exported in SVG format?
Definition: AnimationCell.h:103
wxSize ToGif(const wxString &file)
Exports the whole animation as animated gif.
Definition: AnimationCell.cpp:474
The files a worksheet's XML refers to by name.
Definition: AttachmentSource.h:49
A class that carries information about the type of a cell.
Definition: Cell.h:93
CachedInteger< wxCoord > m_height
The height of this cell.
Definition: Cell.h:1262
virtual void SetCurrentPoint(wxPoint point) const
Pass 2: Arrangement.
Definition: Cell.cpp:532
ViewCellPointers * GetViewCellPointers() const
The transient view-state half of the cell-pointer registry this cell uses.
Definition: Cell.cpp:74
The configuration storage for the current worksheet.
Definition: Configuration.h:102
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:88
@ DecodeFailed
Data was read fine and a decoder exists for the format (or it's an SVG, parsed by our own vendored co...
@ DataUnavailable
Raw data could never be obtained at all (file not found, empty wxmx entry, ...). Always a real failur...
Definition: ImgCellBase.h:44
The view/interaction half of the cell-pointer registry.
Definition: CellPointers.h:341