wxMaxima
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 
31 #include <wx/filesys.h>
32 #include <wx/fs_arc.h>
33 
34 class ImgCell final : public ImgCellBase
35 {
36 public:
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, std::shared_ptr<wxFileSystem> filesystem, 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  ~ImgCell() override;
46 
48  ImgCell &operator=(const ImgCell&) = delete;
49 
51  void GnuplotSource(wxString sourcefile, wxString datafile, std::shared_ptr<wxFileSystem> filesystem)
52  { if (m_image) m_image->GnuplotSource(sourcefile,datafile, filesystem); }
53 
55  wxString GnuplotSource() const override
56  { return m_image ? m_image->GnuplotSource() : wxString(); }
57 
58  void LoadImage(wxString image, bool remove = true);
59 
61  void SetPPI(int ppi) override {m_image->SetPPI(ppi);}
62  int GetPPI() const override {return m_image->GetPPI();}
63  size_t GetOriginalWidth() const override {return m_image->GetOriginalWidth();}
64  size_t GetOriginalHeight() const override {return m_image->GetOriginalHeight();}
65 
66  void ReloadImage(const wxString &image, std::shared_ptr<wxFileSystem> filesystem);
67 
69  bool CanExportSVG() const override {return (m_image != NULL) && m_image->CanExportSVG();}
70 
71  friend class AnimationCell;
72 
81  wxSize ToImageFile(wxString filename) override;
82 
88  void ClearCache() override { if (m_image) m_image->ClearCache(); }
89 
90  const wxString &GetToolTip(wxPoint point) const override;
91 
93  void SetBitmap(const wxBitmap &bitmap);
94 
96  bool CopyToClipboard() const override;
97 
98  void DrawRectangle(bool draw) { m_drawRectangle = draw; }
99 
101  wxString GetExtension() const override
102  { if (m_image)return m_image->GetExtension(); else return wxEmptyString; }
103 
105  wxString GetOrigImageFile() const
106  { return m_origImageFile; }
107 
109  void SetOrigImageFile(wxString file)
110  { m_origImageFile = file; }
111 
113  wxMemoryBuffer GetCompressedImage() const { return m_image->m_compressedImage; }
114 
115  double GetMaxWidth() const override { return m_image ? m_image->GetMaxWidth() : -1; }
116  double GetHeightList() const override { return m_image ? m_image->GetHeightList() : -1; }
117  void SetMaxWidth(double width) override { if (m_image) m_image->SetMaxWidth(width); }
118  void SetMaxHeight(double height) override { if (m_image) m_image->SetMaxHeight(height); }
119 
120  void Recalculate(AFontSize fontsize) override;
121 
122  void Draw(wxPoint point) override;
123 
124  wxString ToMatlab() const override;
125  wxString ToRTF() const override;
126  wxString ToString() const override;
127  wxString ToTeX() const override;
128  wxString ToXML() const override;
129 
130  bool CanPopOut() const override { return !m_image->GnuplotSource().empty(); }
131 
132 private:
133  void SetConfiguration(Configuration **config) override;
134  void DrawBoundingBox(wxDC &WXUNUSED(dc), bool WXUNUSED(all) = false) override;
135  int GetImageBorderWidth() const override { return m_imageBorderWidth; }
136 
137  std::shared_ptr<Image> m_image;
138 
139  CellPointers *const m_cellPointers = GetCellPointers();
140 
141  int m_imageBorderWidth = 0;
142 
143 //** Bitfield objects (1 bytes)
144 //**
145  void InitBitFields()
146  { // Keep the initialization order below same as the order
147  // of bit fields in this class!
148  m_drawRectangle = true;
149  m_drawBoundingBox = false;
150  }
151  bool m_drawRectangle : 1 /* InitBitFields */;
152  bool m_drawBoundingBox : 1 /* InitBitFields */;
153 
154  static int s_counter;
155 
156  wxString m_origImageFile;
157 };
158 
159 #endif // IMGCELL_H
ImgCell::ClearCache
void ClearCache() override
Definition: ImgCell.h:88
ImgCell::ToMatlab
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: ImgCell.cpp:246
ImgCell::SetOrigImageFile
void SetOrigImageFile(wxString file)
Sets the name of the file the image was originally created from.
Definition: ImgCell.h:109
ImgCell::Draw
void Draw(wxPoint point) override
Definition: ImgCell.cpp:188
Cell.h
ImgCell::SetBitmap
void SetBitmap(const wxBitmap &bitmap)
Sets the bitmap that is shown.
Definition: ImgCell.cpp:125
ImgCell::ToRTF
wxString ToRTF() const override
Definition: ImgCell.cpp:276
ImgCell::GetExtension
wxString GetExtension() const override
Returns the file name extension that matches the image type.
Definition: ImgCell.h:101
ImgCell::operator=
ImgCell & operator=(const ImgCell &)=delete
This class can be derived from wxAccessible which has no copy constructor.
ImgCell::GetToolTip
const wxString & GetToolTip(wxPoint point) const override
Definition: ImgCell.cpp:146
ImgCell::ToXML
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: ImgCell.cpp:325
CellPointers
Definition: CellPointers.h:44
Image.h
ImgCell::CanPopOut
bool CanPopOut() const override
Can this cell be popped out interactively in gnuplot?
Definition: ImgCell.h:130
ImgCell::GetCompressedImage
wxMemoryBuffer GetCompressedImage() const
Returns the original compressed version of the image.
Definition: ImgCell.h:113
AFontSize
Definition: FontAttribs.h:97
ImgCell::GetInfo
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
ImgCell
Definition: ImgCell.h:34
ImgCell::ToString
wxString ToString() const override
Returns the cell's representation as a string.
Definition: ImgCell.cpp:241
AnimationCell
Definition: AnimationCell.h:45
ImgCell::Recalculate
void Recalculate(AFontSize fontsize) override
Definition: ImgCell.cpp:158
ImgCell::CopyToClipboard
bool CopyToClipboard() const override
Copies the cell to the system's clipboard.
Definition: ImgCell.cpp:412
ImgCell::ToTeX
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: ImgCell.cpp:251
Configuration
Definition: Configuration.h:83
ImgCell::ToImageFile
wxSize ToImageFile(wxString filename) override
Definition: ImgCell.cpp:256
ImgCell::CanExportSVG
bool CanExportSVG() const override
Can this image be exported in SVG format?
Definition: ImgCell.h:69
ImgCellBase
Definition: ImgCellBase.h:40
ImgCell::GnuplotSource
wxString GnuplotSource() const override
The name of the file with gnuplot commands that created this file.
Definition: ImgCell.h:55
ImgCell::Copy
std::unique_ptr< Cell > Copy(GroupCell *group) const override
GroupCell
Definition: GroupCell.h:68
CellTypeInfo
A class that carries information about the type of a cell.
Definition: Cell.h:90
ImgCell::GetOrigImageFile
wxString GetOrigImageFile() const
Returns the name of the file the image was originally created from.
Definition: ImgCell.h:105
ImgCell::GnuplotSource
void GnuplotSource(wxString sourcefile, wxString datafile, std::shared_ptr< wxFileSystem > filesystem)
Tell the image which gnuplot files it was made from.
Definition: ImgCell.h:51
ImgCell::SetPPI
void SetPPI(int ppi) override
Set the image's resolution.
Definition: ImgCell.h:61