wxMaxima
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 
30 class MatrCell final : public Cell
31 {
32 public:
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  int GetInnerCellCount() const override { return m_cells.size(); }
39  Cell *GetInnerCell(int index) const override { return m_cells[index].get(); }
40 
41  void Recalculate(AFontSize fontsize) override;
42 
43  void Draw(wxPoint point) override;
44 
45  void AddNewCell(std::unique_ptr<Cell> &&cell);
46 
47  void NewRow() { m_matHeight++; m_dropCenters.emplace_back(-1, -1);}
48  void NewColumn() { m_matWidth++; m_widths.emplace_back(-1);}
49 
50  void SetDimension();
51 
52  wxString ToMathML() const override;
53  wxString ToMatlab() const override;
54  wxString ToOMML() const override;
55  wxString ToString() const override;
56  wxString ToTeX() const override;
57  wxString ToXML() const override;
58 
59  void SetSpecialFlag(bool special) { m_specialMatrix = special; }
60 
61  void SetInferenceFlag(bool inference) { m_inferenceMatrix = inference; }
62 
63  void RowNames(bool rn) { m_rowNames = rn; }
64 
65  void ColNames(bool cn) { m_colNames = cn; }
66 
67  void RoundedParens() { m_parenType = paren_rounded;}
68  void BracketParens() { m_parenType = paren_brackets;}
69  void StraightParens() { m_parenType = paren_straight;}
70  void AngledParens() { m_parenType = paren_angled;}
71 
72 private:
73  struct DropCenter
74  {
75  int drop = {}, center = {};
76  constexpr int Sum() const { return drop + center; }
77  constexpr DropCenter() = default;
78  constexpr DropCenter(int drop, int center) : drop(drop), center(center) {}
79  };
80 
82  std::vector<std::unique_ptr<Cell>> m_cells;
83 
84  std::vector<int> m_widths;
85  std::vector<DropCenter> m_dropCenters;
86 
87  unsigned int m_matWidth = 0;
88  unsigned int m_matHeight = 0;
89 
90  enum parenType : int8_t
91  {
92  paren_rounded = 0,
93  paren_brackets = 1,
94  paren_angled = 2,
95  paren_straight = 3
96  };
97 //** Bitfield objects (1 bytes)
98 //**
99  void InitBitFields()
100  { // Keep the initialization order below same as the order
101  // of bit fields in this class!
102  m_parenType = paren_rounded;
103  m_specialMatrix = false;
104  m_inferenceMatrix = false;
105  m_rowNames = false;
106  m_colNames = false;
107  }
108  uint8_t m_parenType : 2 /* InitBitFields */;
109  bool m_specialMatrix : 1 /* InitBitFields */;
110  bool m_inferenceMatrix : 1 /* InitBitFields */;
111  bool m_rowNames : 1 /* InitBitFields */;
112  bool m_colNames : 1 /* InitBitFields */;
113 };
114 
115 #endif // MATRCELL_H
MatrCell::GetInfo
const CellTypeInfo & GetInfo() override
Returns the information about this cell's type.
MatrCell::ToString
wxString ToString() const override
Returns the cell's representation as a string.
Definition: MatrCell.cpp:300
Cell.h
MatrCell::ToMatlab
wxString ToMatlab() const override
Convert this cell to its Matlab representation.
Definition: MatrCell.cpp:321
MatrCell::ToOMML
wxString ToOMML() const override
Definition: MatrCell.cpp:420
MatrCell::Copy
std::unique_ptr< Cell > Copy(GroupCell *group) const override
MatrCell::GetInnerCell
Cell * GetInnerCell(int index) const override
Definition: MatrCell.h:39
MatrCell
Definition: MatrCell.h:30
MatrCell::ToMathML
wxString ToMathML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: MatrCell.cpp:400
MatrCell::ToXML
wxString ToXML() const override
Convert this cell to a representation fit for saving in a .wxmx file.
Definition: MatrCell.cpp:458
Cell
Definition: Cell.h:139
AFontSize
Definition: FontAttribs.h:97
Configuration
Definition: Configuration.h:83
MatrCell::Recalculate
void Recalculate(AFontSize fontsize) override
Definition: MatrCell.cpp:63
GroupCell
Definition: GroupCell.h:68
CellTypeInfo
A class that carries information about the type of a cell.
Definition: Cell.h:90
MatrCell::GetInnerCellCount
int GetInnerCellCount() const override
The number of inner cells - for use by the iterators.
Definition: MatrCell.h:38
MatrCell::ToTeX
wxString ToTeX() const override
Convert this cell to its LaTeX representation.
Definition: MatrCell.cpp:344