wxMaxima
Loading...
Searching...
No Matches
ImgCell.h
1// -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2//
3// Copyright (C) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4// (C) 2014-2015 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
23#ifndef IMGCELL_H
24#define IMGCELL_H
25
26#include "Cell.h"
27#include <wx/image.h>
28#include "Image.h"
29#include "ImgCellBase.h"
30#include <memory>
31
32#include <wx/fs_arc.h>
33
34class ImgCell final : public ImgCellBase
35{
36public:
37 ImgCell(GroupCell *group, Configuration *config);
38 ImgCell(GroupCell *group, Configuration *config, const wxMemoryBuffer &image, const wxString &type);
39 ImgCell(GroupCell *group, Configuration *config, const wxString &image, const wxString &wxmFile, bool remove = true);
40
41 ImgCell(GroupCell *group, Configuration *config, const wxBitmap &bitmap);
42 ImgCell(GroupCell *group, const ImgCell &cell);
43 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
44 const CellTypeInfo &GetInfo() override;
45 virtual ~ImgCell() override;
46
48 ImgCell &operator=(const ImgCell&) = delete;
49
51 void GnuplotSource(wxString sourcefile, wxString datafile, const wxString &wxmFile)
52 { if (m_image) m_image->GnuplotSource(std::move(sourcefile),
53 std::move(datafile),
54 wxmFile); }
55 void CompressedGnuplotSource(wxString sourcefile, wxString datafile,
56 const wxString &wxmFile)
57 { if (m_image) m_image->CompressedGnuplotSource(std::move(sourcefile),
58 std::move(datafile),
59 wxmFile); }
60
62 wxString GnuplotSource() const override
63 { return m_image ? m_image->GnuplotSource() : wxString(); }
64
65 void LoadImage(wxString image, bool remove = true);
66
68 void SetPPI(int ppi) override {m_image->SetPPI(ppi);}
69 int GetPPI() const override {return m_image->GetPPI();}
70 size_t GetOriginalWidth() const override {return m_image->GetOriginalWidth();}
71 size_t GetOriginalHeight() const override {return m_image->GetOriginalHeight();}
72 void TallyImageLoadFailures(int &dataUnavailable, int &decodeFailed) const override {
73 if (!m_image) return;
74 switch (m_image->GetLoadFailureKind()) {
75 case Image::LoadFailureKind::DataUnavailable: dataUnavailable++; break;
76 case Image::LoadFailureKind::DecodeFailed: decodeFailed++; break;
77 default: break;
78 }
79 }
80
81 void ReloadImage(const wxString &image, const wxString &wxmFile);
82
84 bool CanExportSVG() const override {return (m_image != NULL) && m_image->CanExportSVG();}
85
86 friend class AnimationCell;
87
96 wxSize ToImageFile(wxString filename) override;
97
103 void ClearCache() override { if (m_image) m_image->ClearCache(); }
104
105 const wxString GetToolTip(wxPoint point) const override;
106
108 void SetBitmap(const wxBitmap &bitmap);
109
111 bool CopyToClipboard() const override;
112
113 void DrawRectangle(bool draw) { m_drawRectangle = draw; }
114
116 wxString GetExtension() const override
117 { if (m_image)return m_image->GetExtension(); else return wxEmptyString; }
118
120 wxString GetOrigImageFile() const
121 { return m_origImageFile; }
122
124 void SetOrigImageFile(const wxString &file)
125 { m_origImageFile = file; }
126
133 wxMemoryBuffer GetCompressedImage() const { return m_image->GetCompressedImage(); }
134
135 wxCoord GetMaxWidth() const override { return m_image ? m_image->GetMaxWidth() : -1; }
136 wxCoord GetHeightList() const override { return m_height; }
137 void SetMaxWidth(wxCoord width) override { if (m_image) m_image->SetMaxWidth(width); }
138 void SetMaxHeight(wxCoord height) override { if (m_image) m_image->SetMaxHeight(height); }
139
140 void Recalculate(const AFontSize fontsize) const override;
141
143 void SetCurrentPoint(wxPoint point) const override;
144 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
145
146 wxString ToMatlab() const override;
147 wxString ToMathML() const override;
148 wxString ToRTF() const override;
149 wxString ToString() const override;
150 wxString ToTeX() const override;
151 wxString ToXML() const override;
152
153 bool CanPopOut() const override { return m_image && m_image->HasGnuplotSource(); }
154
155private:
156 void SetConfiguration(Configuration *config) override;
157 void DrawBoundingBox(wxDC &WXUNUSED(dc), bool WXUNUSED(all) = false) override;
158 int GetImageBorderWidth() const override { return m_imageBorderWidth; }
159
160 std::shared_ptr<Image> m_image;
161
162 ViewCellPointers *const m_viewCellPointers = GetViewCellPointers();
163
164 mutable int m_imageBorderWidth = 0;
165
166//** Bitfield objects (1 bytes)
167//**
168 bool m_drawRectangle : 1 = true;
169 bool m_drawBoundingBox : 1 = false;
170
171 static int s_counter;
172
173 wxString m_origImageFile;
174};
175
176#endif // IMGCELL_H
The definition of the base class of all cells the worksheet consists of.
This file declares the class Image.
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:99
Definition: AnimationCell.h:46
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:1151
virtual void SetCurrentPoint(wxPoint point) const
Pass 2: Arrangement.
Definition: Cell.cpp:514
ViewCellPointers * GetViewCellPointers() const
The transient view-state half of the cell-pointer registry this cell uses.
Definition: Cell.cpp:75
The configuration storage for the current worksheet.
Definition: Configuration.h:98
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:42
Definition: ImgCell.h:35
void SetOrigImageFile(const wxString &file)
Sets the name of the file the image was originally created from.
Definition: ImgCell.h:124
wxString ToString() const override
Returns the cell's representation as a string.
Definition: ImgCell.cpp:212
wxString GetExtension() const override
Returns the file name extension that matches the image type.
Definition: ImgCell.h:116
bool CanPopOut() const override
Can this cell be popped out interactively in gnuplot?
Definition: ImgCell.h:153
void SetCurrentPoint(wxPoint point) const override
Pass 2: Arrangement.
Definition: ImgCell.cpp:155
void GnuplotSource(wxString sourcefile, wxString datafile, const wxString &wxmFile)
Tell the image which gnuplot files it was made from.
Definition: ImgCell.h:51
void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: ImgCell.cpp:136
void SetPPI(int ppi) override
Set the image's resolution.
Definition: ImgCell.h:68
void SetBitmap(const wxBitmap &bitmap)
Sets the bitmap that is shown.
Definition: ImgCell.cpp:109
wxMemoryBuffer GetCompressedImage() const
Returns the original compressed version of the image. Goes through Image::GetCompressedImage() (rathe...
Definition: ImgCell.h:133
void Draw(wxDC *dc, wxDC *antialiassingDC) override
Pass 3 (Paint): Renders the cell using pre-calculated coordinates.
Definition: ImgCell.cpp:159
wxSize ToImageFile(wxString filename) override
Writes the image to a file.
Definition: ImgCell.cpp:218
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: ImgCell.cpp:216
wxCoord GetHeightList() const override
Returns the total height of this line.
Definition: ImgCell.h:136
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: ImgCell.cpp:287
void ClearCache() override
Removes the cached scaled image from memory.
Definition: ImgCell.h:103
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
wxString GetOrigImageFile() const
Returns the name of the file the image was originally created from.
Definition: ImgCell.h:120
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
bool CopyToClipboard() const override
Copies the cell to the system's clipboard.
Definition: ImgCell.cpp:351
wxString ToRTF() const override
Returns the cell's representation as RTF.
Definition: ImgCell.cpp:239
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: ImgCell.cpp:283
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: ImgCell.cpp:214
wxString GnuplotSource() const override
The name of the file with gnuplot commands that created this file.
Definition: ImgCell.h:62
ImgCell & operator=(const ImgCell &)=delete
This class can be derived from wxAccessible which has no copy constructor.
const wxString GetToolTip(wxPoint point) const override
Returns the ToolTip this cell provides at a given point.
Definition: ImgCell.cpp:127
bool CanExportSVG() const override
Can this image be exported in SVG format?
Definition: ImgCell.h:84
The view/interaction half of the cell-pointer registry.
Definition: CellPointers.h:187