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
30class MatrCell final : public Cell
31{
32public:
33 MatrCell(GroupCell *group, Configuration *config);
34 MatrCell(GroupCell *group, const MatrCell &cell);
35 std::unique_ptr<Cell> Copy(GroupCell *group) const override;
36 const CellTypeInfo &GetInfo() override;
37
38 size_t GetInnerCellCount() const override { return m_cells.size(); }
39 Cell *GetInnerCell(size_t index) const override { return m_cells[index].get(); }
40 Cell *GetInnerCell(long x, long y) const {
41 return m_cells[static_cast<size_t>(x) * m_matWidth + y].get(); }
42
43 void Recalculate(AFontSize fontsize) override;
44
45 void Draw(wxPoint point, wxDC *dc, wxDC *antialiassingDC) override;
46
47 void AddNewCell(std::unique_ptr<Cell> &&cell);
48
49 void NewRow() { m_matHeight++; m_dropCenters.emplace_back(-1, -1);}
50 void NewColumn() { m_matWidth++; m_widths.emplace_back(-1);}
51
52 void SetDimension();
53
54 wxString ToMathML() const override;
55 wxString ToMatlab() const override;
56 wxString ToOMML() const override;
57 wxString ToString() const override;
58 wxString ToTeX() const override;
59 wxString ToXML() const override;
60
61 void SetSpecialFlag(bool special) { m_specialMatrix = special; }
62
63 void SetInferenceFlag(bool inference) { m_inferenceMatrix = inference; }
64
65 void RowNames(bool rn) { m_rowNames = rn; }
66
67 void ColNames(bool cn) { m_colNames = cn; }
68
69 void RoundedParens() { m_parenType = paren_rounded;}
70 void BracketParens() { m_parenType = paren_brackets;}
71 void StraightParens() { m_parenType = paren_straight;}
72 void AngledParens() { m_parenType = paren_angled;}
73 void NoParens() { m_parenType = paren_none;}
74
75private:
76 struct DropCenter
77 {
78 int drop = {}, center = {};
79 constexpr int Sum() const { return drop + center; }
80 constexpr DropCenter() = default;
81 constexpr DropCenter(int drop, int center) : drop(drop), center(center) {}
82 };
83
85 std::vector<std::unique_ptr<Cell>> m_cells;
86
87 std::vector<wxCoord> m_widths;
88 std::vector<DropCenter> m_dropCenters;
89
90 size_t m_matWidth = 0;
91 size_t m_matHeight = 0;
92
93 enum parenType : int8_t
94 {
95 paren_rounded = 0,
96 paren_brackets = 1,
97 paren_angled = 2,
98 paren_straight = 3,
99 paren_none = 4
100 };
101//** Bitfield objects (1 bytes)
102//**
103 void InitBitFields_MatrCell()
104 { // Keep the initialization order below same as the order
105 // of bit fields in this class!
106 m_parenType = paren_rounded;
107 m_specialMatrix = false;
108 m_inferenceMatrix = false;
109 m_rowNames = false;
110 m_colNames = false;
111 }
112 uint8_t m_parenType : 3 /* InitBitFields_MatrCell */;
113 bool m_specialMatrix : 1 /* InitBitFields_MatrCell */;
114 bool m_inferenceMatrix : 1 /* InitBitFields_MatrCell */;
115 bool m_rowNames : 1 /* InitBitFields_MatrCell */;
116 bool m_colNames : 1 /* InitBitFields_MatrCell */;
117};
118
119#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:98
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
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: MatrCell.h:31
void Draw(wxPoint point, wxDC *dc, wxDC *antialiassingDC) override
Draw this cell.
Definition: MatrCell.cpp:101
wxString ToString() const override
Returns the cell's representation as a string.
Definition: MatrCell.cpp:245
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:38
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: MatrCell.cpp:393
wxString ToOMML() const override
Returns the cell's representation as OMML.
Definition: MatrCell.cpp:350
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: MatrCell.cpp:331
Cell * GetInnerCell(size_t index) const override
Retrieve an inner cell with given index which must be less than GetInnerCellCount.
Definition: MatrCell.h:39
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: MatrCell.cpp:283
void Recalculate(AFontSize fontsize) override
Recalculate the size of the cell and the difference between top and center.
Definition: MatrCell.cpp:62
std::unique_ptr< Cell > Copy(GroupCell *group) const override
Create a copy of this cell.
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: MatrCell.cpp:263