* GraphControl cleaning * replace textbox value after submission * rebase * rebase * rebase * Add filters * rebase! * rebase
86 lines
2.5 KiB
C++
86 lines
2.5 KiB
C++
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
// Licensed under the MIT License.
|
|
|
|
#include "pch.h"
|
|
#include "Equation.h"
|
|
|
|
using namespace Platform;
|
|
using namespace Platform::Collections;
|
|
using namespace std;
|
|
using namespace Windows::Foundation::Collections;
|
|
using namespace Windows::UI;
|
|
using namespace Windows::UI::ViewManagement;
|
|
using namespace Windows::UI::Xaml;
|
|
using namespace Windows::UI::Xaml::Media;
|
|
|
|
namespace GraphControl
|
|
{
|
|
// Remove mml: formatting specific to RichEditBox control, which is not understood by the graph engine.
|
|
static constexpr wstring_view s_mathPrefix = L"mml:";
|
|
|
|
Equation::Equation()
|
|
{
|
|
}
|
|
|
|
String ^ Equation::GetRequest()
|
|
{
|
|
wstringstream ss;
|
|
wstring expr{ Expression->Data() };
|
|
|
|
// Check for unicode characters of less than, less than or equal to, greater than and greater than or equal to.
|
|
if (expr.find(L">><") != wstring::npos || expr.find(L"><<") != wstring::npos || expr.find(L">≥<") != wstring::npos
|
|
|| expr.find(L">≤<") != wstring::npos)
|
|
{
|
|
ss << L"<mrow><mi>plotIneq2D</mi><mfenced separators=\"\">"s;
|
|
}
|
|
else if (expr.find(L">=<") != wstring::npos)
|
|
{
|
|
ss << L"<mrow><mi>plotEq2d</mi><mfenced separators=\"\">";
|
|
}
|
|
else
|
|
{
|
|
ss << L"<mrow><mi>plot2d</mi><mfenced separators=\"\">";
|
|
}
|
|
ss << GetExpression() << L"</mfenced></mrow>";
|
|
|
|
return ref new String(ss.str().c_str());
|
|
}
|
|
|
|
wstring Equation::GetExpression()
|
|
{
|
|
wstring mathML = Expression->Data();
|
|
|
|
size_t mathPrefix = 0;
|
|
while ((mathPrefix = mathML.find(s_mathPrefix, mathPrefix)) != std::string::npos)
|
|
{
|
|
mathML.replace(mathPrefix, s_mathPrefix.length(), L"");
|
|
mathPrefix += s_mathPrefix.length();
|
|
}
|
|
|
|
return mathML;
|
|
}
|
|
|
|
Color Equation::LineColor::get()
|
|
{
|
|
return m_LineColor;
|
|
}
|
|
void Equation::LineColor::set(Color value)
|
|
{
|
|
if (m_LineColor.R != value.R || m_LineColor.G != value.G || m_LineColor.B != value.B || m_LineColor.A != value.A)
|
|
{
|
|
m_LineColor = value;
|
|
RaisePropertyChanged(L"LineColor");
|
|
}
|
|
}
|
|
|
|
Platform::String ^ Equation::LineColorPropertyName::get()
|
|
{
|
|
return Platform::StringReference(L"LineColor");
|
|
}
|
|
|
|
bool Equation::IsGraphableEquation()
|
|
{
|
|
return !Expression->IsEmpty() && IsLineEnabled && !HasGraphError;
|
|
}
|
|
}
|