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
73 void ReloadImage(const wxString &image, const wxString &wxmFile);
74
76 bool CanExportSVG() const override {return (m_image != NULL) && m_image->CanExportSVG();}
77
78 friend class AnimationCell;
79
88 wxSize ToImageFile(wxString filename) override;
89
95 void ClearCache() override { if (m_image) m_image->ClearCache(); }
96
97 const wxString GetToolTip(wxPoint point) const override;
98
100 void SetBitmap(const wxBitmap &bitmap);
101
103 bool CopyToClipboard() const override;
104
105 void DrawRectangle(bool draw) { m_drawRectangle = draw; }
106
108 wxString GetExtension() const override
109 { if (m_image)return m_image->GetExtension(); else return wxEmptyString; }
110
112 wxString GetOrigImageFile() const
113 { return m_origImageFile; }
114
116 void SetOrigImageFile(const wxString &file)
117 { m_origImageFile = file; }
118
120 wxMemoryBuffer GetCompressedImage() const { return m_image->m_compressedImage; }
121
122 wxCoord GetMaxWidth() const override { return m_image ? m_image->GetMaxWidth() : -1; }
123 wxCoord GetHeightList() const override { return m_image ? m_image->GetHeightList() : -1; }
124 void SetMaxWidth(wxCoord width) override { if (m_image) m_image->SetMaxWidth(width); }
125 void SetMaxHeight(wxCoord height) override { if (m_image) m_image->SetMaxHeight(height); }
126
127 void Recalculate(AFontSize fontsize) override;
128
129 void Draw(wxPoint point, wxDC *dc, wxDC *antialiassingDC) override;
130
131 wxString ToMatlab() const override;
132 wxString ToRTF() const override;
133 wxString ToString() const override;
134 wxString ToTeX() const override;
135 wxString ToXML() const override;
136
137 bool CanPopOut() const override { return m_image && m_image->HasGnuplotSource(); }
138
139private:
140 void SetConfiguration(Configuration *config) override;
141 void DrawBoundingBox(wxDC &WXUNUSED(dc), bool WXUNUSED(all) = false) override;
142 int GetImageBorderWidth() const override { return m_imageBorderWidth; }
143
144 std::shared_ptr<Image> m_image;
145
146 CellPointers *const m_cellPointers = GetCellPointers();
147
148 int m_imageBorderWidth = 0;
149
150//** Bitfield objects (1 bytes)
151//**
152 void InitBitFields_ImgCell()
153 { // Keep the initialization order below same as the order
154 // of bit fields in this class!
155 m_drawRectangle = true;
156 m_drawBoundingBox = false;
157 }
158 bool m_drawRectangle : 1 /* InitBitFields_ImgCell */;
159 bool m_drawBoundingBox : 1 /* InitBitFields_ImgCell */;
160
161 static int s_counter;
162
163 wxString m_origImageFile;
164};
165
166#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:98
Definition: AnimationCell.h:46
The storage for pointers to cells.
Definition: CellPointers.h:45
A class that carries information about the type of a cell.
Definition: Cell.h:93
The configuration storage for the current worksheet.
Definition: Configuration.h:85
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:74
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:116
wxString ToString() const override
Returns the cell's representation as a string.
Definition: ImgCell.cpp:214
wxString GetExtension() const override
Returns the file name extension that matches the image type.
Definition: ImgCell.h:108
bool CanPopOut() const override
Can this cell be popped out interactively in gnuplot?
Definition: ImgCell.h:137
void GnuplotSource(wxString sourcefile, wxString datafile, const wxString &wxmFile)
Tell the image which gnuplot files it was made from.
Definition: ImgCell.h:51
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:117
wxMemoryBuffer GetCompressedImage() const
Returns the original compressed version of the image.
Definition: ImgCell.h:120
wxSize ToImageFile(wxString filename) override
Writes the image to a file.
Definition: ImgCell.cpp:220
void Recalculate(AFontSize fontsize) override
Recalculate the size of the cell and the difference between top and center.
Definition: ImgCell.cpp:143
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: ImgCell.cpp:218
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: ImgCell.cpp:283
void ClearCache() override
Removes the cached scaled image from memory.
Definition: ImgCell.h:95
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:112
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
void Draw(wxPoint point, wxDC *dc, wxDC *antialiassingDC) override
Draw this cell.
Definition: ImgCell.cpp:162
bool CopyToClipboard() const override
Copies the cell to the system's clipboard.
Definition: ImgCell.cpp:349
wxString ToRTF() const override
Returns the cell's representation as RTF.
Definition: ImgCell.cpp:241
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: ImgCell.cpp:216
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:134
bool CanExportSVG() const override
Can this image be exported in SVG format?
Definition: ImgCell.h:76