wxMaxima
Loading...
Searching...
No Matches
MatrCell.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-2016 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 MATRCELL_H
24#define MATRCELL_H
25
26#include "Cell.h"
27
28#include <vector>
29
49class MatrCell final : public Cell
50{
51public:
52 MatrCell(GroupCell *group, Configuration *config);
53 MatrCell(GroupCell *group, const MatrCell &cell);
54 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
55 const CellTypeInfo &GetInfo() override;
56
57 size_t GetInnerCellCount() const override { return m_cells.size(); }
58 Cell *GetInnerCell(size_t index) const override { return m_cells.at(index).get(); }
59 Cell *GetInnerCell(int x, int y) const {
60 return m_cells.at(static_cast<size_t>(x) * m_matWidth + y).get(); }
61
62 void Recalculate(const AFontSize fontsize) const override;
63
65 void SetCurrentPoint(wxPoint point) override;
66 void Draw(wxDC *dc, wxDC *antialiassingDC) override;
67
68 void AddNewCell(std::unique_ptr<Cell> &&cell);
69
70 void NewRow() { m_matHeight++; m_dropCenters.emplace_back(-1, -1);}
71 void NewColumn() { m_matWidth++; m_widths.emplace_back(-1);}
72
73 void SetDimension();
74
75 wxString ToMathML() const override;
76 wxString ToMatlab() const override;
77 wxString ToOMML() const override;
78 wxString ToString() const override;
79 wxString ToTeX() const override;
80 wxString ToXML() const override;
81
82 void SetSpecialFlag(bool special) { m_specialMatrix = special; }
83
84 void SetInferenceFlag(bool inference) { m_inferenceMatrix = inference; }
85
86 void RowNames(bool rn) { m_rowNames = rn; }
87
88 void ColNames(bool cn) { m_colNames = cn; }
89
90 void RoundedParens() { m_parenType = paren_rounded;}
91 void BracketParens() { m_parenType = paren_brackets;}
92 void StraightParens() { m_parenType = paren_straight;}
93 void AngledParens() { m_parenType = paren_angled;}
94 void NoParens() { m_parenType = paren_none;}
95
96private:
97 struct DropCenter
98 {
99 int drop = {}, center = {};
100 constexpr int Sum() const { return drop + center; }
101 constexpr DropCenter() = default;
102 constexpr DropCenter(int drop, int center) : drop(drop), center(center) {}
103 };
104
106 std::vector<std::unique_ptr<Cell>> m_cells;
107
108 mutable std::vector<wxCoord> m_widths;
109 mutable std::vector<DropCenter> m_dropCenters;
110
111 size_t m_matWidth = 0;
112 size_t m_matHeight = 0;
113
114 enum parenType : int8_t
115 {
116 paren_rounded = 0,
117 paren_brackets = 1,
118 paren_angled = 2,
119 paren_straight = 3,
120 paren_none = 4
121 };
122//** Bitfield objects (1 bytes)
123//**
124 void InitBitFields_MatrCell()
125 { // Keep the initialization order below same as the order
126 // of bit fields in this class!
127 m_parenType = paren_rounded;
128 m_specialMatrix = false;
129 m_inferenceMatrix = false;
130 m_rowNames = false;
131 m_colNames = false;
132 }
133 uint8_t m_parenType : 3 /* InitBitFields_MatrCell */;
134 bool m_specialMatrix : 1 /* InitBitFields_MatrCell */;
135 bool m_inferenceMatrix : 1 /* InitBitFields_MatrCell */;
136 bool m_rowNames : 1 /* InitBitFields_MatrCell */;
137 bool m_colNames : 1 /* InitBitFields_MatrCell */;
138};
139
140#endif // MATRCELL_H
The definition of the base class of all cells the worksheet consists of.
A Type-Safe Fixed-Point Font Size.
Definition: FontAttribs.h:97
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:142
virtual void SetCurrentPoint(wxPoint point)
Pass 2: Arrangement.
Definition: Cell.cpp:466
The configuration storage for the current worksheet.
Definition: Configuration.h:86
A cell grouping input (and, if there is one, also the output) cell to a foldable item.
Definition: GroupCell.h:87
A Cell that displays a matrix.
Definition: MatrCell.h:50
wxString ToString() const override
Returns the cell's representation as a string.
Definition: MatrCell.cpp:254
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
size_t GetInnerCellCount() const override
The number of inner cells - for use by the iterators.
Definition: MatrCell.h:57
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: MatrCell.cpp:438
wxString ToOMML() const override
Returns the cell's representation as OMML.
Definition: MatrCell.cpp:395
void SetCurrentPoint(wxPoint point) override
Pass 2: Arrangement.
Definition: MatrCell.cpp:101
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: MatrCell.cpp:340
Cell * GetInnerCell(size_t index) const override
Retrieve an inner cell with given index which must be less than GetInnerCellCount.
Definition: MatrCell.h:58
void Recalculate(const AFontSize fontsize) const override
Recalculate the size of the cell and the difference between top and center.
Definition: MatrCell.cpp:62
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: MatrCell.cpp:292
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
void Draw(wxDC *dc, wxDC *antialiassingDC) override
Pass 3 (Paint): Renders the cell using pre-calculated coordinates.
Definition: MatrCell.cpp:120
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: MatrCell.cpp:272