1 // -*- mode: c++; c-file-style: "linux"; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 //
3 // Copyright (C) 2014-2018 Gunter Königsmann <wxMaxima@physikbuch.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // SPDX-License-Identifier: GPL-2.0+
21
22 /*! \file
23 This file defines the class ConjugateCell
24
25 ConjugateCell is the Cell type that represents the field that represents the
26 conjugate() command.
27 */
28
29 #include "ConjugateCell.h"
30
ConjugateCell(Cell * parent,Configuration ** config,CellPointers * cellPointers)31 ConjugateCell::ConjugateCell(Cell *parent, Configuration **config, CellPointers *cellPointers) :
32 Cell(parent, config, cellPointers),
33 m_innerCell(new TextCell(parent, config, cellPointers, "")),
34 m_open(new TextCell(parent, config, cellPointers, "conjugate(")),
35 m_close(new TextCell(parent, config, cellPointers, ")"))
36 {
37 m_open->DontEscapeOpeningParenthesis();
38 m_last = NULL;
39 }
40
41 // Old cppcheck bugs:
42 // cppcheck-suppress uninitMemberVar symbolName=ConjugateCell::m_open
43 // cppcheck-suppress uninitMemberVar symbolName=ConjugateCell::m_close
ConjugateCell(const ConjugateCell & cell)44 ConjugateCell::ConjugateCell(const ConjugateCell &cell):
45 ConjugateCell(cell.m_group, cell.m_configuration, cell.m_cellPointers)
46 {
47 CopyCommonData(cell);
48 if(cell.m_innerCell)
49 SetInner(cell.m_innerCell->CopyList());
50 }
51
~ConjugateCell()52 ConjugateCell::~ConjugateCell()
53 {
54 if(this == m_cellPointers->m_selectionStart)
55 m_cellPointers->m_selectionStart = NULL;
56 if(this == m_cellPointers->m_selectionEnd)
57 m_cellPointers->m_selectionEnd = NULL;
58 MarkAsDeleted();
59 }
60
GetInnerCells()61 std::list<std::shared_ptr<Cell>> ConjugateCell::GetInnerCells()
62 {
63 std::list<std::shared_ptr<Cell>> innerCells;
64 if(m_innerCell)
65 innerCells.push_back(m_innerCell);
66 if(m_open)
67 innerCells.push_back(m_open);
68 if(m_close)
69 innerCells.push_back(m_close);
70 return innerCells;
71 }
72
SetInner(Cell * inner)73 void ConjugateCell::SetInner(Cell *inner)
74 {
75 if (inner == NULL)
76 return;
77 m_innerCell = std::shared_ptr<Cell>(inner);
78
79 m_last = m_innerCell.get();
80 if (m_last != NULL)
81 while (m_last->m_next != NULL)
82 m_last = m_last->m_next;
83 }
84
RecalculateWidths(int fontsize)85 void ConjugateCell::RecalculateWidths(int fontsize)
86 {
87 if(!NeedsRecalculation(fontsize))
88 return;
89
90 m_innerCell->RecalculateWidthsList(fontsize);
91 m_open->RecalculateWidthsList(fontsize);
92 m_close->RecalculateWidthsList(fontsize);
93 if(!m_isBrokenIntoLines)
94 m_width = m_innerCell->GetFullWidth() + Scale_Px(8);
95 else
96 m_width = 0;
97 Cell::RecalculateWidths(fontsize);
98 }
99
RecalculateHeight(int fontsize)100 void ConjugateCell::RecalculateHeight(int fontsize)
101 {
102 if(!NeedsRecalculation(fontsize))
103 return;
104
105 m_innerCell->RecalculateHeightList(fontsize);
106 m_open->RecalculateHeightList(fontsize);
107 m_close->RecalculateHeightList(fontsize);
108 if(!m_isBrokenIntoLines)
109 {
110 m_height = m_innerCell->GetHeightList() + Scale_Px(4);
111 m_center = m_innerCell->GetCenterList() + Scale_Px(2);
112 }
113 else
114 {
115 m_height = wxMax(m_innerCell->GetHeightList(), m_open->GetHeightList());
116 m_center = wxMax(m_innerCell->GetCenterList(), m_open->GetCenterList());
117 }
118 Cell::RecalculateHeight(fontsize);
119 }
120
Draw(wxPoint point)121 void ConjugateCell::Draw(wxPoint point)
122 {
123 Cell::Draw(point);
124 if (DrawThisCell(point))
125 {
126 Configuration *configuration = (*m_configuration);
127
128 wxDC *dc = configuration->GetDC();
129 SetPen();
130 wxPoint in;
131 in.x = point.x + Scale_Px(4);
132 in.y = point.y;
133 m_innerCell->DrawList(in);
134
135 dc->DrawLine(point.x + Scale_Px(2),
136 point.y - m_center + Scale_Px(2),
137 point.x + m_width - Scale_Px(2) - 1,
138 point.y - m_center + Scale_Px(2)
139 );
140 // point.y - m_center + m_height - Scale_Px(2));
141 UnsetPen();
142 }
143 }
144
ToString()145 wxString ConjugateCell::ToString()
146 {
147 if (m_isBrokenIntoLines)
148 return wxEmptyString;
149 else
150 return wxT("conjugate(") + m_innerCell->ListToString() + wxT(")");
151 }
152
ToMatlab()153 wxString ConjugateCell::ToMatlab()
154 {
155 if (m_isBrokenIntoLines)
156 return wxEmptyString;
157 else
158 return wxT("conjugate(") + m_innerCell->ListToMatlab() + wxT(")");
159 }
160
ToTeX()161 wxString ConjugateCell::ToTeX()
162 {
163 if (m_isBrokenIntoLines)
164 return wxEmptyString;
165 else
166 return wxT("\\overline{") + m_innerCell->ListToTeX() + wxT("}");
167 }
168
ToMathML()169 wxString ConjugateCell::ToMathML()
170 {
171 // return wxT("<apply><conjugate/><ci>") + m_innerCell->ListToMathML() + wxT("</ci></apply>");
172 return wxT("<mover accent=\"true\">") + m_innerCell->ListToMathML() +
173 wxT("<mo>¯</mo></mover>\n");
174 }
175
ToOMML()176 wxString ConjugateCell::ToOMML()
177 {
178 return wxT("<m:bar><m:barPr><m:pos m:val=\"top\"/> </m:barPr><m:e>") +
179 m_innerCell->ListToOMML() + wxT("</m:e></m:bar>");
180 }
181
ToXML()182 wxString ConjugateCell::ToXML()
183 {
184 wxString flags;
185 if (m_forceBreakLine)
186 flags += wxT(" breakline=\"true\"");
187
188 return wxT("<cj") + flags + wxT(">") + m_innerCell->ListToXML() + wxT("</cj>");
189 }
190
BreakUp()191 bool ConjugateCell::BreakUp()
192 {
193 if (!m_isBrokenIntoLines)
194 {
195 m_isBrokenIntoLines = true;
196 m_open->m_nextToDraw = m_innerCell.get();
197 wxASSERT_MSG(m_last != NULL, _("Bug: No last cell in a conjugateCell!"));
198 if (m_last != NULL)
199 m_last->m_nextToDraw = m_close.get();
200 m_close->m_nextToDraw = m_nextToDraw;
201 m_nextToDraw = m_open.get();
202 ResetData();
203 m_height = wxMax(m_innerCell->GetHeightList(), m_open->GetHeightList());
204 m_center = wxMax(m_innerCell->GetCenterList(), m_open->GetCenterList());
205 return true;
206 }
207 return false;
208 }
209