wxMaxima
Loading...
Searching...
No Matches
SumCell.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) 2004-2015 Andrej Vodopivec <andrej.vodopivec@gmail.com>
4// (C) 2014-2018 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
31#ifndef SUMCELL_H
32#define SUMCELL_H
33
34#include "precomp.h"
35#include "Cell.h"
36#include "ParenCell.h"
37
38class TextCell;
39
40//cppcheck-suppress ctuOneDefinitionRuleViolation
41class SumCell : public Cell
42{
43public:
47 std::unique_ptr<Cell> &&under, std::unique_ptr<Cell> &&over,
48 std::unique_ptr<Cell> &&base);
49 SumCell(GroupCell *group, const SumCell &cell);
50 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
51 const CellTypeInfo &GetInfo() override;
52
53 size_t GetInnerCellCount() const override { return 10; }
54 Cell *GetInnerCell(size_t index) const override {
55 switch (index) {
56 case 0:
57 return m_open.get();
58 case 1:
59 return m_paren.get();
60 case 2:
61 return m_comma1.get();
62 case 3:
63 return m_var.get();
64 case 4:
65 return m_comma2.get();
66 case 5:
67 return m_start.get();
68 case 6:
69 return m_comma3.get();
70 case 7:
71 return m_close.get();
72 case 8:
73 return m_over.get();
74 case 9:
75 return m_under.get();
76 default:
77 return nullptr;
78 }
79 }
80
81 void Recalculate(const AFontSize fontsize) const override;
82
84 void SetCurrentPoint(wxPoint point) const override;
85 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
86
87 wxString ToMathML() const override;
88 wxString ToMatlab() const override;
89 wxString ToOMML() const override;
90 wxString ToString() const override;
91 wxString ToTeX() const override;
92 wxString ToXML() const override;
93
94 void SetAltCopyText(const wxString &text) override { m_altCopyText = text; }
95
103 void NeedsParen(bool needsParen) {
104 m_baseNeedsParen = needsParen;
105 m_displayParen = needsParen;
106 }
107 const wxString &GetAltCopyText() const override { return m_altCopyText; }
108
109 bool BreakUp() const override;
110
121 size_t GetBrokenCellCount() const override {
122 return m_over->ToString().IsEmpty() ? 7 : 9;
123 }
124 Cell *GetBrokenCell(size_t index) const override {
125 const bool hasOver = !m_over->ToString().IsEmpty();
126 switch (index) {
127 case 0:
128 return m_open.get();
129 case 1:
130 return Base();
131 case 2:
132 return m_comma1.get();
133 case 3:
134 return m_var.get();
135 case 4:
136 return m_comma2.get();
137 case 5:
138 return m_start.get();
139 case 6:
140 return hasOver ? m_comma3.get() : m_close.get();
141 case 7:
142 return hasOver ? m_over.get() : nullptr;
143 case 8:
144 return hasOver ? m_close.get() : nullptr;
145 default:
146 return nullptr;
147 }
148 }
149
150 void Unbreak() const override final;
151
152protected:
163 void RefreshBreakUpCommandName() const;
165 virtual const wxString GetMaximaCommandName() const;
167 virtual const wxString GetMatlabCommandName() const;
169 virtual const wxString GetLaTeXCommandName() const;
171 virtual const wxString GetUnicodeSymbol() const;
173 virtual const wxString GetSvgSymbolData() const;
175 virtual const wxString GetXMLType() const;
177 virtual const wxSize GetSymbolSize() const;
179 Cell *Base() const;
180 Cell *Over() const {return m_over.get();}
181 Cell *Under() const {return m_under.get();}
182
183private:
184 std::unique_ptr<Cell> MakeStart(Cell *under) const;
185 void MakeBreakUpCells();
186 const static wxString m_svgSumSign;
187
188 ParenCell *Paren() const;
190 Cell *DisplayedBase() const;
191
193 wxString m_altCopyText;
194 // The pointers below point to inner cells and must be kept contiguous.
195 // ** This is the partial draw list order. All pointers must be the same:
196 // ** either Cell * or std::unique_ptr<Cell>. NO OTHER TYPES are allowed.
197 std::unique_ptr<Cell> m_open;
198 std::unique_ptr<Cell> m_paren;
199 std::unique_ptr<Cell> m_comma1;
200 std::unique_ptr<Cell> m_var;
201 std::unique_ptr<Cell> m_comma2;
202 std::unique_ptr<Cell> m_start;
203 std::unique_ptr<Cell> m_comma3;
204 std::unique_ptr<Cell> m_close;
205 std::unique_ptr<Cell> m_over;
206 std::unique_ptr<Cell> m_under;
207 // The pointers above point to inner cells and must be kept contiguous.
208
209 mutable wxSize m_signSize;
210
211//** Bitfield objects (1 bytes)
212//**
221 mutable bool m_displayParen : 1 = true;
226 bool m_baseNeedsParen : 1 = true;
227};
228
229#endif // SUMCELL_H
The definition of the base class of all cells the worksheet consists of.
This file declares the class ParenCell.
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 class that carries information about the type of a cell.
Definition: Cell.h:93
The base class all cell types the worksheet can consist of are derived from.
Definition: Cell.h:148
virtual void SetCurrentPoint(wxPoint point) const
Pass 2: Arrangement.
Definition: Cell.cpp:526
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
The class that represents parenthesis that are wrapped around text.
Definition: ParenCell.h:46
Definition: SumCell.h:42
size_t GetInnerCellCount() const override
The number of inner cells - for use by the iterators.
Definition: SumCell.h:53
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: SumCell.cpp:336
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: SumCell.cpp:270
virtual const wxString GetMaximaCommandName() const
What maxima command name corresponds to this cell?
Definition: SumCell.cpp:122
bool BreakUp() const override
Try to split this command into lines to make it fit on the screen.
Definition: SumCell.cpp:367
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
virtual const wxString GetXMLType() const
Returns the type our cell has when saving it to .wxmx.
Definition: SumCell.cpp:151
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
size_t GetBrokenCellCount() const override
ORDER MATTERS, and this is NOT the same set as GetInnerCellCount()/ GetInnerCell() above: index 1 the...
Definition: SumCell.h:121
virtual const wxString GetMatlabCommandName() const
What matlab command name corresponds to this cell?
Definition: SumCell.cpp:136
void NeedsParen(bool needsParen)
Whether the summand genuinely needs the disambiguating parentheses around it (GH #1536),...
Definition: SumCell.h:103
wxString ToString() const override
Returns the cell's representation as a string.
Definition: SumCell.cpp:244
virtual const wxSize GetSymbolSize() const
How big do we want our svg symbol to be?
Definition: SumCell.cpp:112
const wxString & GetAltCopyText() const override
Get the text set using SetAltCopyText - may be empty.
Definition: SumCell.h:107
virtual const wxString GetLaTeXCommandName() const
What LaTeX command name corresponds to this cell?
Definition: SumCell.cpp:141
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: SumCell.cpp:292
void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: SumCell.cpp:159
void RefreshBreakUpCommandName() const
Re-applies GetMaximaCommandName() to the already-created m_open cell.
Definition: SumCell.cpp:77
Cell * GetBrokenCell(size_t index) const override
Retrieve a piece of this cell's broken (linear/1D) display; see GetBrokenCellCount().
Definition: SumCell.h:124
void SetAltCopyText(const wxString &text) override
What should end up if placing this cell on the clipboard?
Definition: SumCell.h:94
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: SumCell.cpp:325
void SetCurrentPoint(wxPoint point) const override
Pass 2: Arrangement.
Definition: SumCell.cpp:200
void Unbreak() const override final
Undo breaking this cell into multiple lines.
Definition: SumCell.cpp:362
void Draw(wxDC *dc, wxDC *antialiassingDC) override
Pass 3 (Paint): Renders the cell using pre-calculated coordinates.
Definition: SumCell.cpp:222
Cell * GetInnerCell(size_t index) const override
Retrieve an inner cell with given index which must be less than GetInnerCellCount.
Definition: SumCell.h:54
virtual const wxString GetUnicodeSymbol() const
What unicode symbol name corresponds to this cell?
Definition: SumCell.cpp:146
virtual const wxString GetSvgSymbolData() const
Returns the data that creates our SVG symbol.
Definition: SumCell.cpp:130
Cell * Base() const
The base cell owned by the paren (it's without the paren)
Definition: SumCell.cpp:85
wxString ToOMML() const override
Returns the cell's representation as OMML.
Definition: SumCell.cpp:305
A Text cell.
Definition: TextCell.h:40