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:
38 ImgCell(GroupCell *group, Configuration *config, const wxMemoryBuffer &image, const wxString &type);
39 ImgCell(GroupCell *group, Configuration *config, const wxString &image, const AttachmentSource &attachments, 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,
52 const AttachmentSource &attachments)
53 { if (m_image) m_image->GnuplotSource(std::move(sourcefile),
54 std::move(datafile),
55 attachments); }
56 void CompressedGnuplotSource(wxString sourcefile, wxString datafile,
57 const AttachmentSource &attachments)
58 { if (m_image) m_image->CompressedGnuplotSource(std::move(sourcefile),
59 std::move(datafile),
60 attachments); }
61
63 wxString GnuplotSource() const override
64 { return m_image ? m_image->GnuplotSource() : wxString(); }
65
66 void LoadImage(wxString image, bool remove = true);
67
69 void SetPPI(int ppi) override {m_image->SetPPI(ppi);}
70 int GetPPI() const override {return m_image->GetPPI();}
71 size_t GetOriginalWidth() const override {return m_image->GetOriginalWidth();}
72 size_t GetOriginalHeight() const override {return m_image->GetOriginalHeight();}
73 void TallyImageLoadFailures(int &dataUnavailable, int &decodeFailed) const override {
74 if (!m_image) return;
75 switch (m_image->GetLoadFailureKind()) {
76 case Image::LoadFailureKind::DataUnavailable: dataUnavailable++; break;
77 case Image::LoadFailureKind::DecodeFailed: decodeFailed++; break;
78 default: break;
79 }
80 }
81
83 void ReloadImage(const wxString &image);
84
86 bool CanExportSVG() const override {return (m_image != nullptr) && m_image->CanExportSVG();}
87
88 friend class AnimationCell;
89
98 wxSize ToImageFile(wxString filename) override;
99
105 void ClearCache() override { if (m_image) m_image->ClearCache(); }
106
107 const wxString GetToolTip(wxPoint point) const override;
108
110 void SetBitmap(const wxBitmap &bitmap);
111
113 bool CopyToClipboard() const override;
114
115 void DrawRectangle(bool draw) { m_drawRectangle = draw; }
116
118 wxString GetExtension() const override
119 { if (m_image)return m_image->GetExtension(); else return wxEmptyString; }
120
122 wxString GetOrigImageFile() const
123 { return m_origImageFile; }
124
126 void SetOrigImageFile(const wxString &file)
127 { m_origImageFile = file; }
128
135 wxMemoryBuffer GetCompressedImage() const { return m_image->GetCompressedImage(); }
136
137 wxCoord GetMaxWidth() const override { return m_image ? m_image->GetMaxWidth() : -1; }
138 wxCoord GetHeightList() const override { return m_height; }
139 void SetMaxWidth(wxCoord width) override { if (m_image) m_image->SetMaxWidth(width); }
140 void SetMaxHeight(wxCoord height) override { if (m_image) m_image->SetMaxHeight(height); }
141
142 void Recalculate(const AFontSize fontsize) const override;
143
145 void SetCurrentPoint(wxPoint point) const override;
146 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
147
148 wxString ToMatlab() const override;
149 wxString ToMathML() const override;
150 wxString ToRTF() const override;
151 wxString ToString() const override;
152 wxString ToTeX() const override;
153 wxString ToXML() const override;
154
155 bool CanPopOut() const override { return m_image && m_image->HasGnuplotSource(); }
156
157private:
158 void SetConfiguration(Configuration *config) override;
159 void DrawBoundingBox(wxDC &WXUNUSED(dc), bool WXUNUSED(all) = false) override;
160 int GetImageBorderWidth() const override { return m_imageBorderWidth; }
161
162 std::shared_ptr<Image> m_image;
163
164 ViewCellPointers *const m_viewCellPointers = GetViewCellPointers();
165
166 mutable int m_imageBorderWidth = 0;
167
168//** Bitfield objects (1 bytes)
169//**
170 bool m_drawRectangle : 1 = true;
171 bool m_drawBoundingBox : 1 = false;
172
173 static int s_counter;
174
175 wxString m_origImageFile;
176};
177
178#endif // IMGCELL_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
Definition: AnimationCell.h:46
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:1212
virtual void SetCurrentPoint(wxPoint point) const
Pass 2: Arrangement.
Definition: Cell.cpp:526
ViewCellPointers * GetViewCellPointers() const
The transient view-state half of the cell-pointer registry this cell uses.
Definition: Cell.cpp:73
The configuration storage for the current worksheet.
Definition: Configuration.h:101
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:126
wxString ToString() const override
Returns the cell's representation as a string.
Definition: ImgCell.cpp:215
wxString GetExtension() const override
Returns the file name extension that matches the image type.
Definition: ImgCell.h:118
bool CanPopOut() const override
Can this cell be popped out interactively in gnuplot?
Definition: ImgCell.h:155
void SetCurrentPoint(wxPoint point) const override
Pass 2: Arrangement.
Definition: ImgCell.cpp:154
void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: ImgCell.cpp:135
void SetPPI(int ppi) override
Set the image's resolution.
Definition: ImgCell.h:69
void SetBitmap(const wxBitmap &bitmap)
Sets the bitmap that is shown.
Definition: ImgCell.cpp:108
wxMemoryBuffer GetCompressedImage() const
Returns the original compressed version of the image. Goes through Image::GetCompressedImage() (rathe...
Definition: ImgCell.h:135
void Draw(wxDC *dc, wxDC *antialiassingDC) override
Pass 3 (Paint): Renders the cell using pre-calculated coordinates.
Definition: ImgCell.cpp:158
wxSize ToImageFile(wxString filename) override
Writes the image to a file.
Definition: ImgCell.cpp:221
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: ImgCell.cpp:219
void ReloadImage(const wxString &image)
Loads the image again from this file in the file system.
Definition: ImgCell.cpp:91
void GnuplotSource(wxString sourcefile, wxString datafile, const AttachmentSource &attachments)
Tell the image which gnuplot files it was made from.
Definition: ImgCell.h:51
wxCoord GetHeightList() const override
Returns the total height of this line.
Definition: ImgCell.h:138
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: ImgCell.cpp:290
void ClearCache() override
Removes the cached scaled image from memory.
Definition: ImgCell.h:105
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:122
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:354
wxString ToRTF() const override
Returns the cell's representation as RTF.
Definition: ImgCell.cpp:242
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: ImgCell.cpp:286
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: ImgCell.cpp:217
wxString GnuplotSource() const override
The name of the file with gnuplot commands that created this file.
Definition: ImgCell.h:63
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:126
bool CanExportSVG() const override
Can this image be exported in SVG format?
Definition: ImgCell.h:86
The view/interaction half of the cell-pointer registry.
Definition: CellPointers.h:282