GraphControl: refactoring and optimizations (#831)
* GraphControl cleaning * replace textbox value after submission * rebase * rebase * rebase * Add filters * rebase! * rebase
This commit is contained in:
@@ -1,447 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "Equation.h"
|
||||
using namespace winrt::Windows::Foundation::Collections;
|
||||
|
||||
using namespace Platform;
|
||||
using namespace std;
|
||||
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:";
|
||||
|
||||
DependencyProperty ^ Equation::s_expressionProperty;
|
||||
static constexpr auto s_propertyName_Expression = L"Expression";
|
||||
|
||||
DependencyProperty ^ Equation::s_lineColorProperty;
|
||||
static constexpr auto s_propertyName_LineColor = L"LineColor";
|
||||
|
||||
DependencyProperty ^ Equation::s_isLineEnabledProperty;
|
||||
static constexpr auto s_propertyName_IsLineEnabled = L"IsLineEnabled";
|
||||
|
||||
DependencyProperty ^ Equation::s_hasGraphErrorProperty;
|
||||
static constexpr auto s_propertyName_HasGraphError = L"HasGraphError";
|
||||
|
||||
DependencyProperty ^ Equation::s_isValidatedProperty;
|
||||
static constexpr auto s_propertyName_IsValidated = L"IsValidated";
|
||||
|
||||
DependencyProperty ^ Equation::s_xInterceptProperty;
|
||||
static constexpr auto s_propertyName_XIntercept = L"XIntercept";
|
||||
|
||||
DependencyProperty ^ Equation::s_yInterceptProperty;
|
||||
static constexpr auto s_propertyName_YIntercept = L"YIntercept";
|
||||
|
||||
DependencyProperty ^ Equation::s_parityProperty;
|
||||
static constexpr auto s_propertyName_Parity = L"Parity";
|
||||
|
||||
DependencyProperty ^ Equation::s_periodicityDirectionProperty;
|
||||
static constexpr auto s_propertyName_PeriodicityDirection = L"PeriodicityDirection";
|
||||
|
||||
DependencyProperty ^ Equation::s_periodicityExpressionProperty;
|
||||
static constexpr auto s_propertyName_PeriodicityExpression = L"PeriodicityExpression";
|
||||
|
||||
DependencyProperty ^ Equation::s_minimaProperty;
|
||||
static constexpr auto s_propertyName_Minima = L"Minima";
|
||||
|
||||
DependencyProperty ^ Equation::s_maximaProperty;
|
||||
static constexpr auto s_propertyName_Maxima = L"Maxima";
|
||||
|
||||
DependencyProperty ^ Equation::s_domainProperty;
|
||||
static constexpr auto s_propertyName_Domain = L"Domain";
|
||||
|
||||
DependencyProperty ^ Equation::s_rangeProperty;
|
||||
static constexpr auto s_propertyName_Range = L"Range";
|
||||
|
||||
DependencyProperty ^ Equation::s_inflectionPointsProperty;
|
||||
static constexpr auto s_propertyName_InflectionPoints = L"InflectionPoints";
|
||||
|
||||
DependencyProperty ^ Equation::s_monotonicityProperty;
|
||||
static constexpr auto s_propertyName_Monotonicity = L"Monotonicity";
|
||||
|
||||
DependencyProperty ^ Equation::s_verticalAsymptotesProperty;
|
||||
static constexpr auto s_propertyName_VerticalAsymptotes = L"VerticalAsymptotes";
|
||||
|
||||
DependencyProperty ^ Equation::s_horizontalAsymptotesProperty;
|
||||
static constexpr auto s_propertyName_HorizontalAsymptotes = L"HorizontalAsymptotes";
|
||||
|
||||
DependencyProperty ^ Equation::s_obliqueAsymptotesProperty;
|
||||
static constexpr auto s_propertyName_ObliqueAsymptotes = L"ObliqueAsymptotes";
|
||||
|
||||
DependencyProperty ^ Equation::s_tooComplexFeaturesProperty;
|
||||
static constexpr auto s_propertyName_TooComplexFeatures = L"TooComplexFeatures";
|
||||
|
||||
DependencyProperty ^ Equation::s_analysisErrorProperty;
|
||||
static constexpr auto s_propertyName_AnalysisError = L"AnalysisError";
|
||||
|
||||
namespace EquationProperties
|
||||
{
|
||||
String ^ Expression = StringReference(s_propertyName_Expression);
|
||||
String ^ LineColor = StringReference(s_propertyName_LineColor);
|
||||
String ^ IsLineEnabled = StringReference(s_propertyName_IsLineEnabled);
|
||||
String ^ HasGraphError = StringReference(s_propertyName_HasGraphError);
|
||||
String ^ IsValidated = StringReference(s_propertyName_IsValidated);
|
||||
String ^ XIntercept = StringReference(s_propertyName_XIntercept);
|
||||
String ^ YIntercept = StringReference(s_propertyName_YIntercept);
|
||||
String ^ Parity = StringReference(s_propertyName_Parity);
|
||||
String ^ PeriodicityDirection = StringReference(s_propertyName_PeriodicityDirection);
|
||||
String ^ PeriodicityExpression = StringReference(s_propertyName_PeriodicityExpression);
|
||||
String ^ Minima = StringReference(s_propertyName_Minima);
|
||||
String ^ Maxima = StringReference(s_propertyName_Maxima);
|
||||
String ^ Domain = StringReference(s_propertyName_Domain);
|
||||
String ^ Range = StringReference(s_propertyName_Range);
|
||||
String ^ InflectionPoints = StringReference(s_propertyName_InflectionPoints);
|
||||
String ^ Monotonicity = StringReference(s_propertyName_Monotonicity);
|
||||
String ^ VerticalAsymptotes = StringReference(s_propertyName_VerticalAsymptotes);
|
||||
String ^ HorizontalAsymptotes = StringReference(s_propertyName_HorizontalAsymptotes);
|
||||
String ^ ObliqueAsymptotes = StringReference(s_propertyName_ObliqueAsymptotes);
|
||||
String ^ TooComplexFeatures = StringReference(s_propertyName_TooComplexFeatures);
|
||||
String ^ AnalysisError = StringReference(s_propertyName_AnalysisError);
|
||||
}
|
||||
|
||||
void Equation::RegisterDependencyProperties()
|
||||
{
|
||||
if (!s_expressionProperty)
|
||||
{
|
||||
s_expressionProperty = DependencyProperty::Register(
|
||||
EquationProperties::Expression,
|
||||
String::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_lineColorProperty)
|
||||
{
|
||||
// Default line color should be the user's accent color
|
||||
auto uiSettings = ref new UISettings();
|
||||
|
||||
s_lineColorProperty = DependencyProperty::Register(
|
||||
EquationProperties::LineColor,
|
||||
SolidColorBrush::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_isLineEnabledProperty)
|
||||
{
|
||||
s_isLineEnabledProperty = DependencyProperty::Register(
|
||||
EquationProperties::IsLineEnabled,
|
||||
bool ::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_hasGraphErrorProperty)
|
||||
{
|
||||
s_hasGraphErrorProperty = DependencyProperty::Register(
|
||||
EquationProperties::HasGraphError,
|
||||
bool ::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(false, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_isValidatedProperty)
|
||||
{
|
||||
s_isValidatedProperty = DependencyProperty::Register(
|
||||
EquationProperties::IsValidated,
|
||||
bool ::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(false, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_xInterceptProperty)
|
||||
{
|
||||
s_xInterceptProperty = DependencyProperty::Register(
|
||||
EquationProperties::XIntercept,
|
||||
String::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_yInterceptProperty)
|
||||
{
|
||||
s_yInterceptProperty = DependencyProperty::Register(
|
||||
EquationProperties::YIntercept,
|
||||
String::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_parityProperty)
|
||||
{
|
||||
s_parityProperty = DependencyProperty::Register(
|
||||
EquationProperties::Parity,
|
||||
int ::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_periodicityDirectionProperty)
|
||||
{
|
||||
s_periodicityDirectionProperty = DependencyProperty::Register(
|
||||
EquationProperties::PeriodicityDirection,
|
||||
int ::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_periodicityExpressionProperty)
|
||||
{
|
||||
s_periodicityExpressionProperty = DependencyProperty::Register(
|
||||
EquationProperties::PeriodicityExpression,
|
||||
String::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_minimaProperty)
|
||||
{
|
||||
s_minimaProperty = DependencyProperty::Register(
|
||||
EquationProperties::Minima,
|
||||
IObservableVector<String ^>::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_maximaProperty)
|
||||
{
|
||||
s_maximaProperty = DependencyProperty::Register(
|
||||
EquationProperties::Maxima,
|
||||
IObservableVector<String ^>::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_domainProperty)
|
||||
{
|
||||
s_domainProperty = DependencyProperty::Register(
|
||||
EquationProperties::Domain,
|
||||
String::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_rangeProperty)
|
||||
{
|
||||
s_rangeProperty = DependencyProperty::Register(
|
||||
EquationProperties::Range,
|
||||
String::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_inflectionPointsProperty)
|
||||
{
|
||||
s_inflectionPointsProperty = DependencyProperty::Register(
|
||||
EquationProperties::InflectionPoints,
|
||||
IObservableVector<String ^>::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_monotonicityProperty)
|
||||
{
|
||||
s_monotonicityProperty = DependencyProperty::Register(
|
||||
EquationProperties::Monotonicity,
|
||||
IObservableMap<String ^, String ^>::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_verticalAsymptotesProperty)
|
||||
{
|
||||
s_verticalAsymptotesProperty = DependencyProperty::Register(
|
||||
EquationProperties::VerticalAsymptotes,
|
||||
IObservableVector<String ^>::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_horizontalAsymptotesProperty)
|
||||
{
|
||||
s_horizontalAsymptotesProperty = DependencyProperty::Register(
|
||||
EquationProperties::HorizontalAsymptotes,
|
||||
IObservableVector<String ^>::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_obliqueAsymptotesProperty)
|
||||
{
|
||||
s_obliqueAsymptotesProperty = DependencyProperty::Register(
|
||||
EquationProperties::ObliqueAsymptotes,
|
||||
IObservableVector<String ^>::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
if (!s_tooComplexFeaturesProperty)
|
||||
{
|
||||
s_tooComplexFeaturesProperty = DependencyProperty::Register(
|
||||
EquationProperties::TooComplexFeatures,
|
||||
int ::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_analysisErrorProperty)
|
||||
{
|
||||
s_analysisErrorProperty = DependencyProperty::Register(
|
||||
EquationProperties::AnalysisError,
|
||||
int ::typeid,
|
||||
Equation::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Equation::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
}
|
||||
|
||||
void Equation::OnCustomDependencyPropertyChanged(DependencyObject ^ obj, DependencyPropertyChangedEventArgs ^ args)
|
||||
{
|
||||
if (auto eq = static_cast<Equation ^>(obj))
|
||||
{
|
||||
String ^ propertyName = nullptr;
|
||||
if (args->Property == s_expressionProperty)
|
||||
{
|
||||
propertyName = EquationProperties::Expression;
|
||||
}
|
||||
else if (args->Property == s_lineColorProperty)
|
||||
{
|
||||
propertyName = EquationProperties::LineColor;
|
||||
}
|
||||
else if (args->Property == s_isLineEnabledProperty)
|
||||
{
|
||||
propertyName = EquationProperties::IsLineEnabled;
|
||||
}
|
||||
else if (args->Property == s_xInterceptProperty)
|
||||
{
|
||||
propertyName = EquationProperties::XIntercept;
|
||||
}
|
||||
else if (args->Property == s_yInterceptProperty)
|
||||
{
|
||||
propertyName = EquationProperties::YIntercept;
|
||||
}
|
||||
else if (args->Property == s_parityProperty)
|
||||
{
|
||||
propertyName = EquationProperties::Parity;
|
||||
}
|
||||
else if (args->Property == s_periodicityDirectionProperty)
|
||||
{
|
||||
propertyName = EquationProperties::PeriodicityDirection;
|
||||
}
|
||||
else if (args->Property == s_periodicityExpressionProperty)
|
||||
{
|
||||
propertyName = EquationProperties::PeriodicityExpression;
|
||||
}
|
||||
else if (args->Property == s_minimaProperty)
|
||||
{
|
||||
propertyName = EquationProperties::Minima;
|
||||
}
|
||||
else if (args->Property == s_maximaProperty)
|
||||
{
|
||||
propertyName = EquationProperties::Maxima;
|
||||
}
|
||||
else if (args->Property == s_domainProperty)
|
||||
{
|
||||
propertyName = EquationProperties::Domain;
|
||||
}
|
||||
else if (args->Property == s_rangeProperty)
|
||||
{
|
||||
propertyName = EquationProperties::Range;
|
||||
}
|
||||
else if (args->Property == s_inflectionPointsProperty)
|
||||
{
|
||||
propertyName = EquationProperties::InflectionPoints;
|
||||
}
|
||||
else if (args->Property == s_monotonicityProperty)
|
||||
{
|
||||
propertyName = EquationProperties::Monotonicity;
|
||||
}
|
||||
else if (args->Property == s_verticalAsymptotesProperty)
|
||||
{
|
||||
propertyName = EquationProperties::VerticalAsymptotes;
|
||||
}
|
||||
else if (args->Property == s_horizontalAsymptotesProperty)
|
||||
{
|
||||
propertyName = EquationProperties::HorizontalAsymptotes;
|
||||
}
|
||||
else if (args->Property == s_obliqueAsymptotesProperty)
|
||||
{
|
||||
propertyName = EquationProperties::ObliqueAsymptotes;
|
||||
}
|
||||
else if (args->Property == s_tooComplexFeaturesProperty)
|
||||
{
|
||||
propertyName = EquationProperties::TooComplexFeatures;
|
||||
}
|
||||
else if (args->Property == s_analysisErrorProperty)
|
||||
{
|
||||
propertyName = EquationProperties::AnalysisError;
|
||||
}
|
||||
else if (args->Property == s_hasGraphErrorProperty)
|
||||
{
|
||||
propertyName = EquationProperties::HasGraphError;
|
||||
}
|
||||
else if (args->Property == s_isValidatedProperty)
|
||||
{
|
||||
propertyName = EquationProperties::IsValidated;
|
||||
}
|
||||
|
||||
eq->PropertyChanged(eq, propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
wstring Equation::GetRequest()
|
||||
{
|
||||
wstringstream ss{};
|
||||
ss << GetRequestHeader() << GetExpression() << GetLineColor() << L"</mfenced></mrow>";
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
wstring Equation::GetRequestHeader()
|
||||
{
|
||||
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)
|
||||
{
|
||||
return L"<mrow><mi>plotIneq2D</mi><mfenced separators=\"\">"s;
|
||||
}
|
||||
else if (expr.find(L">=<") != wstring::npos)
|
||||
{
|
||||
return L"<mrow><mi>plotEq2d</mi><mfenced separators=\"\">"s;
|
||||
}
|
||||
else
|
||||
{
|
||||
return L"<mrow><mi>plot2d</mi><mfenced separators=\"\">"s;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
wstring Equation::GetLineColor()
|
||||
{
|
||||
return L""s;
|
||||
}
|
||||
|
||||
bool Equation::IsGraphableEquation()
|
||||
{
|
||||
return !Expression->IsEmpty() && IsLineEnabled && !HasGraphError;
|
||||
}
|
||||
}
|
@@ -1,507 +0,0 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace GraphControl
|
||||
{
|
||||
namespace EquationProperties
|
||||
{
|
||||
extern Platform::String ^ Expression;
|
||||
extern Platform::String ^ LineColor;
|
||||
extern Platform::String ^ IsLineEnabled;
|
||||
}
|
||||
|
||||
ref class Equation;
|
||||
delegate void PropertyChangedEventHandler(Equation ^ sender, Platform::String ^ propertyName);
|
||||
|
||||
[Windows::UI::Xaml::Data::Bindable] public ref class Equation sealed : public Windows::UI::Xaml::DependencyObject
|
||||
{
|
||||
public:
|
||||
|
||||
Equation()
|
||||
{
|
||||
}
|
||||
|
||||
static void RegisterDependencyProperties();
|
||||
|
||||
#pragma region Platform::String ^ Expression DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ ExpressionProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_expressionProperty;
|
||||
}
|
||||
}
|
||||
property Platform::String^ Expression
|
||||
{
|
||||
Platform::String^ get()
|
||||
{
|
||||
return static_cast<Platform::String^>(GetValue(s_expressionProperty));
|
||||
}
|
||||
void set(Platform::String^ value)
|
||||
{
|
||||
SetValue(s_expressionProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::UI::Xaml::Media::SolidColorBrush ^ LineColor DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ LineColorProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_lineColorProperty;
|
||||
}
|
||||
}
|
||||
property Windows::UI::Xaml::Media::SolidColorBrush^ LineColor
|
||||
{
|
||||
Windows::UI::Xaml::Media::SolidColorBrush^ get()
|
||||
{
|
||||
return static_cast<Windows::UI::Xaml::Media::SolidColorBrush^>(GetValue(s_lineColorProperty));
|
||||
}
|
||||
void set(Windows::UI::Xaml::Media::SolidColorBrush^ value)
|
||||
{
|
||||
if (value == nullptr || LineColor == nullptr || (value->Color.A != LineColor->Color.A) || (value->Color.R != LineColor->Color.R)
|
||||
|| (value->Color.G != LineColor->Color.G) || (value->Color.B != LineColor->Color.B))
|
||||
SetValue(s_lineColorProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region bool IsLineEnabled DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ IsLineEnabledProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty ^ get()
|
||||
{
|
||||
return s_isLineEnabledProperty;
|
||||
}
|
||||
}
|
||||
property bool IsLineEnabled
|
||||
{
|
||||
bool get()
|
||||
{
|
||||
return static_cast<bool>(GetValue(s_isLineEnabledProperty));
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
SetValue(s_isLineEnabledProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region bool HasGraphError DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ HasGraphErrorProperty { Windows::UI::Xaml::DependencyProperty ^ get() { return s_hasGraphErrorProperty; } }
|
||||
|
||||
property bool HasGraphError
|
||||
{
|
||||
bool get()
|
||||
{
|
||||
return static_cast<bool>(GetValue(s_hasGraphErrorProperty));
|
||||
}
|
||||
|
||||
internal:
|
||||
void set(bool value)
|
||||
{
|
||||
SetValue(s_hasGraphErrorProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region bool IsValidated DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ IsValidatedProperty { Windows::UI::Xaml::DependencyProperty ^ get() { return s_isValidatedProperty; } }
|
||||
|
||||
property bool IsValidated
|
||||
{
|
||||
bool get()
|
||||
{
|
||||
return static_cast<bool>(GetValue(s_isValidatedProperty));
|
||||
}
|
||||
|
||||
internal:
|
||||
void set(bool value)
|
||||
{
|
||||
SetValue(s_isValidatedProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Key Graph Features
|
||||
|
||||
|
||||
#pragma region Platform::String ^ XIntercept DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ XInterceptProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_xInterceptProperty;
|
||||
}
|
||||
}
|
||||
property Platform::String^ XIntercept
|
||||
{
|
||||
Platform::String^ get()
|
||||
{
|
||||
return static_cast<Platform::String^>(GetValue(s_xInterceptProperty));
|
||||
}
|
||||
internal: void set(Platform::String^ value)
|
||||
{
|
||||
SetValue(s_xInterceptProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Platform::String ^ YIntercept DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ YInterceptProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_yInterceptProperty;
|
||||
}
|
||||
}
|
||||
property Platform::String^ YIntercept
|
||||
{
|
||||
Platform::String^ get()
|
||||
{
|
||||
return static_cast<Platform::String^>(GetValue(s_yInterceptProperty));
|
||||
}
|
||||
internal: void set(Platform::String^ value)
|
||||
{
|
||||
SetValue(s_yInterceptProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region int Parity DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ ParityProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_parityProperty;
|
||||
}
|
||||
}
|
||||
property int Parity
|
||||
{
|
||||
int get()
|
||||
{
|
||||
return static_cast<int>(GetValue(s_parityProperty));
|
||||
}
|
||||
internal: void set(int value)
|
||||
{
|
||||
SetValue(s_parityProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region int Periodicity DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ PeriodicityDirectionProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_periodicityDirectionProperty;
|
||||
}
|
||||
}
|
||||
property int PeriodicityDirection
|
||||
{
|
||||
int get()
|
||||
{
|
||||
return static_cast<int>(GetValue(s_periodicityDirectionProperty));
|
||||
}
|
||||
internal: void set(int value)
|
||||
{
|
||||
SetValue(s_periodicityDirectionProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Platform::String ^ PeriodicityExpression DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ PeriodicityExpressionProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_periodicityExpressionProperty;
|
||||
}
|
||||
}
|
||||
property Platform::String ^ PeriodicityExpression
|
||||
{
|
||||
Platform::String ^ get()
|
||||
{
|
||||
return static_cast<Platform::String ^>(GetValue(s_periodicityExpressionProperty));
|
||||
}
|
||||
internal: void set(Platform::String ^ value)
|
||||
{
|
||||
SetValue(s_periodicityExpressionProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::Foundation::Collections::IVector < Platform::String ^ > ^ Minima DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ MinimaProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_minimaProperty;
|
||||
}
|
||||
}
|
||||
property Windows::Foundation::Collections::IVector<Platform::String^> ^ Minima
|
||||
{
|
||||
Windows::Foundation::Collections::IVector<Platform::String^> ^ get()
|
||||
{
|
||||
return static_cast<Windows::Foundation::Collections::IVector<Platform::String^> ^>(GetValue(s_minimaProperty));
|
||||
}
|
||||
internal: void set(Windows::Foundation::Collections::IVector<Platform::String^> ^ value)
|
||||
{
|
||||
SetValue(s_minimaProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::Foundation::Collections::IVector < Platform::String ^ > ^ Maxima DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ MaximaProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_maximaProperty;
|
||||
}
|
||||
}
|
||||
property Windows::Foundation::Collections::IVector<Platform::String^> ^ Maxima
|
||||
{
|
||||
Windows::Foundation::Collections::IVector<Platform::String^> ^ get()
|
||||
{
|
||||
return static_cast<Windows::Foundation::Collections::IVector<Platform::String^> ^>(GetValue(s_maximaProperty));
|
||||
}
|
||||
internal: void set(Windows::Foundation::Collections::IVector<Platform::String^> ^ value)
|
||||
{
|
||||
SetValue(s_maximaProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Platform::String ^ Domain DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ DomainProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_domainProperty;
|
||||
}
|
||||
}
|
||||
property Platform::String^ Domain
|
||||
{
|
||||
Platform::String^ get()
|
||||
{
|
||||
return static_cast<Platform::String^>(GetValue(s_domainProperty));
|
||||
}
|
||||
internal: void set(Platform::String^ value)
|
||||
{
|
||||
SetValue(s_domainProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Platform::String ^ Range DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ RangeProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_rangeProperty;
|
||||
}
|
||||
}
|
||||
property Platform::String^ Range
|
||||
{
|
||||
Platform::String^ get()
|
||||
{
|
||||
return static_cast<Platform::String^>(GetValue(s_rangeProperty));
|
||||
}
|
||||
internal: void set(Platform::String^ value)
|
||||
{
|
||||
SetValue(s_rangeProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::Foundation::Collections::IVector < Platform::String ^ > ^ InflectionPoints DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ InflectionPointsProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_inflectionPointsProperty;
|
||||
}
|
||||
}
|
||||
property Windows::Foundation::Collections::IVector<Platform::String^> ^ InflectionPoints
|
||||
{
|
||||
Windows::Foundation::Collections::IVector<Platform::String^> ^ get()
|
||||
{
|
||||
return static_cast<Windows::Foundation::Collections::IVector<Platform::String^> ^>(GetValue(s_inflectionPointsProperty));
|
||||
}
|
||||
internal: void set(Windows::Foundation::Collections::IVector<Platform::String^> ^ value)
|
||||
{
|
||||
SetValue(s_inflectionPointsProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::Foundation::Collections::IObservableMap < Platform::String ^, Platform::String ^ > ^ Monotonicity DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ MonotonicityProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_monotonicityProperty;
|
||||
}
|
||||
}
|
||||
property Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::String ^> ^ Monotonicity
|
||||
{
|
||||
Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::String ^> ^ get()
|
||||
{
|
||||
return static_cast<Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::String ^> ^>(GetValue(s_monotonicityProperty));
|
||||
}
|
||||
internal: void set(Windows::Foundation::Collections::IObservableMap<Platform::String^, Platform::String ^> ^ value)
|
||||
{
|
||||
SetValue(s_monotonicityProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::Foundation::Collections::IVector < Platform::String ^ > ^ VerticalAsymptotes DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ VerticalAsymptotesProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_verticalAsymptotesProperty;
|
||||
}
|
||||
}
|
||||
property Windows::Foundation::Collections::IVector<Platform::String^> ^ VerticalAsymptotes
|
||||
{
|
||||
Windows::Foundation::Collections::IVector<Platform::String^> ^ get()
|
||||
{
|
||||
return static_cast<Windows::Foundation::Collections::IVector<Platform::String^> ^>(GetValue(s_verticalAsymptotesProperty));
|
||||
}
|
||||
internal: void set(Windows::Foundation::Collections::IVector<Platform::String^> ^ value)
|
||||
{
|
||||
SetValue(s_verticalAsymptotesProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::Foundation::Collections::IVector < Platform::String ^ > ^ HorizontalAsymptotes DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ HorizontalAsymptotesProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_horizontalAsymptotesProperty;
|
||||
}
|
||||
}
|
||||
property Windows::Foundation::Collections::IVector<Platform::String^> ^ HorizontalAsymptotes
|
||||
{
|
||||
Windows::Foundation::Collections::IVector<Platform::String^> ^ get()
|
||||
{
|
||||
return static_cast<Windows::Foundation::Collections::IVector<Platform::String^> ^>(GetValue(s_horizontalAsymptotesProperty));
|
||||
}
|
||||
internal: void set(Windows::Foundation::Collections::IVector<Platform::String^> ^ value)
|
||||
{
|
||||
SetValue(s_horizontalAsymptotesProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::Foundation::Collections::IVector < Platform::String ^ > ^ ObliqueAsymptotes DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ ObliqueAsymptotesProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_obliqueAsymptotesProperty;
|
||||
}
|
||||
}
|
||||
property Windows::Foundation::Collections::IVector<Platform::String^> ^ ObliqueAsymptotes
|
||||
{
|
||||
Windows::Foundation::Collections::IVector<Platform::String^> ^ get()
|
||||
{
|
||||
return static_cast<Windows::Foundation::Collections::IVector<Platform::String^> ^>(GetValue(s_obliqueAsymptotesProperty));
|
||||
}
|
||||
internal: void set(Windows::Foundation::Collections::IVector<Platform::String^> ^ value)
|
||||
{
|
||||
SetValue(s_obliqueAsymptotesProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region int TooComplexFeatures DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ TooComplexFeaturesProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_tooComplexFeaturesProperty;
|
||||
}
|
||||
}
|
||||
property int TooComplexFeatures
|
||||
{
|
||||
int get()
|
||||
{
|
||||
return static_cast<int>(GetValue(s_tooComplexFeaturesProperty));
|
||||
}
|
||||
internal: void set(int value)
|
||||
{
|
||||
SetValue(s_tooComplexFeaturesProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region int AnalysisError DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ AnalysisErrorProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty ^ get()
|
||||
{
|
||||
return s_analysisErrorProperty;
|
||||
}
|
||||
}
|
||||
property int AnalysisError
|
||||
{
|
||||
int get()
|
||||
{
|
||||
return static_cast<int>(GetValue(s_analysisErrorProperty));
|
||||
}
|
||||
internal: void set(int value)
|
||||
{
|
||||
SetValue(s_analysisErrorProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
internal : event PropertyChangedEventHandler ^ PropertyChanged;
|
||||
|
||||
std::wstring GetRequest();
|
||||
bool IsGraphableEquation();
|
||||
|
||||
private:
|
||||
static void OnCustomDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject ^ obj, Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args);
|
||||
|
||||
std::wstring GetRequestHeader();
|
||||
std::wstring GetExpression();
|
||||
std::wstring GetLineColor();
|
||||
|
||||
private:
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_expressionProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_lineColorProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_isLineEnabledProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_hasGraphErrorProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_isValidatedProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_xInterceptProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_yInterceptProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_parityProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_periodicityDirectionProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_periodicityExpressionProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_minimaProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_maximaProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_domainProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_rangeProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_inflectionPointsProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_monotonicityProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_verticalAsymptotesProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_horizontalAsymptotesProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_obliqueAsymptotesProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_tooComplexFeaturesProperty;
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_analysisErrorProperty;
|
||||
};
|
||||
}
|
@@ -24,16 +24,17 @@ using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Controls;
|
||||
using namespace Windows::UI::Xaml::Input;
|
||||
using namespace Windows::UI::Xaml::Media;
|
||||
using namespace GraphControl;
|
||||
|
||||
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, ForceProportionalAxes);
|
||||
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Variables);
|
||||
DEPENDENCY_PROPERTY_INITIALIZATION(Grapher, Equations);
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr auto s_defaultStyleKey = L"GraphControl.Grapher";
|
||||
constexpr auto s_templateKey_SwapChainPanel = L"GraphSurface";
|
||||
|
||||
constexpr auto s_propertyName_Equations = L"Equations";
|
||||
constexpr auto s_propertyName_Variables = L"Variables";
|
||||
constexpr auto s_propertyName_ForceProportionalAxes = L"ForceProportionalAxes";
|
||||
|
||||
constexpr auto s_X = L"x";
|
||||
constexpr auto s_Y = L"y";
|
||||
constexpr auto s_defaultFormatType = FormatType::MathML;
|
||||
@@ -52,24 +53,19 @@ namespace
|
||||
|
||||
namespace GraphControl
|
||||
{
|
||||
DependencyProperty ^ Grapher::s_equationsProperty;
|
||||
DependencyProperty ^ Grapher::s_variablesProperty;
|
||||
DependencyProperty ^ Grapher::s_forceProportionalAxesTemplateProperty;
|
||||
|
||||
Grapher::Grapher()
|
||||
: m_solver{ IMathSolver::CreateMathSolver() }
|
||||
, m_graph{ m_solver->CreateGrapher() }
|
||||
, m_Moving{ false }
|
||||
{
|
||||
Equations = ref new EquationCollection();
|
||||
|
||||
m_solver->ParsingOptions().SetFormatType(s_defaultFormatType);
|
||||
m_solver->FormatOptions().SetFormatType(s_defaultFormatType);
|
||||
m_solver->FormatOptions().SetMathMLPrefix(wstring(L"mml"));
|
||||
|
||||
DefaultStyleKey = StringReference(s_defaultStyleKey);
|
||||
|
||||
this->SetValue(EquationsProperty, ref new EquationCollection());
|
||||
this->SetValue(VariablesProperty, ref new Map<String ^, double>());
|
||||
|
||||
this->Loaded += ref new RoutedEventHandler(this, &Grapher::OnLoaded);
|
||||
this->Unloaded += ref new RoutedEventHandler(this, &Grapher::OnUnloaded);
|
||||
|
||||
@@ -147,52 +143,6 @@ namespace GraphControl
|
||||
TryUpdateGraph();
|
||||
}
|
||||
|
||||
void Grapher::RegisterDependencyProperties()
|
||||
{
|
||||
if (!s_equationsProperty)
|
||||
{
|
||||
s_equationsProperty = DependencyProperty::Register(
|
||||
StringReference(s_propertyName_Equations),
|
||||
EquationCollection::typeid,
|
||||
Grapher::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_variablesProperty)
|
||||
{
|
||||
s_variablesProperty = DependencyProperty::Register(
|
||||
StringReference(s_propertyName_Variables),
|
||||
IObservableMap<String ^, double>::typeid,
|
||||
Grapher::typeid,
|
||||
ref new PropertyMetadata(nullptr, ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
|
||||
if (!s_forceProportionalAxesTemplateProperty)
|
||||
{
|
||||
s_forceProportionalAxesTemplateProperty = DependencyProperty::Register(
|
||||
StringReference(s_propertyName_ForceProportionalAxes),
|
||||
bool ::typeid,
|
||||
Grapher::typeid,
|
||||
ref new PropertyMetadata(true, ref new PropertyChangedCallback(&Grapher::OnCustomDependencyPropertyChanged)));
|
||||
}
|
||||
}
|
||||
|
||||
void Grapher::OnCustomDependencyPropertyChanged(DependencyObject ^ obj, DependencyPropertyChangedEventArgs ^ args)
|
||||
{
|
||||
auto self = static_cast<Grapher ^>(obj);
|
||||
if (self)
|
||||
{
|
||||
if (args->Property == EquationsProperty)
|
||||
{
|
||||
self->OnEquationsChanged(args);
|
||||
}
|
||||
else if (args->Property == ForceProportionalAxesTemplateProperty)
|
||||
{
|
||||
self->OnForceProportionalAxesChanged(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Grapher::OnDependencyPropertyChanged(DependencyObject ^ obj, DependencyProperty ^ p)
|
||||
{
|
||||
if (p == SolidColorBrush::ColorProperty)
|
||||
@@ -202,30 +152,36 @@ namespace GraphControl
|
||||
}
|
||||
}
|
||||
|
||||
void Grapher::OnEquationsChanged(DependencyPropertyChangedEventArgs ^ args)
|
||||
void Grapher::OnEquationsPropertyChanged(EquationCollection ^ oldValue, EquationCollection ^ newValue)
|
||||
{
|
||||
if (auto older = static_cast<EquationCollection ^>(args->OldValue))
|
||||
if (oldValue != nullptr)
|
||||
{
|
||||
if (m_tokenEquationChanged.Value != 0)
|
||||
{
|
||||
older->EquationChanged -= m_tokenEquationChanged;
|
||||
oldValue->EquationChanged -= m_tokenEquationChanged;
|
||||
m_tokenEquationChanged.Value = 0;
|
||||
}
|
||||
|
||||
if (m_tokenEquationStyleChanged.Value != 0)
|
||||
{
|
||||
older->EquationStyleChanged -= m_tokenEquationStyleChanged;
|
||||
oldValue->EquationStyleChanged -= m_tokenEquationStyleChanged;
|
||||
m_tokenEquationStyleChanged.Value = 0;
|
||||
}
|
||||
|
||||
if (m_tokenEquationLineEnabledChanged.Value != 0)
|
||||
{
|
||||
oldValue->EquationLineEnabledChanged -= m_tokenEquationLineEnabledChanged;
|
||||
m_tokenEquationLineEnabledChanged.Value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (auto newer = static_cast<EquationCollection ^>(args->NewValue))
|
||||
if (newValue != nullptr)
|
||||
{
|
||||
m_tokenEquationChanged = newer->EquationChanged += ref new EquationChangedEventHandler(this, &Grapher::OnEquationChanged);
|
||||
m_tokenEquationChanged = newValue->EquationChanged += ref new EquationChangedEventHandler(this, &Grapher::OnEquationChanged);
|
||||
|
||||
m_tokenEquationStyleChanged = newer->EquationStyleChanged += ref new EquationChangedEventHandler(this, &Grapher::OnEquationStyleChanged);
|
||||
m_tokenEquationStyleChanged = newValue->EquationStyleChanged += ref new EquationChangedEventHandler(this, &Grapher::OnEquationStyleChanged);
|
||||
|
||||
m_tokenEquationLineEnabledChanged = newer->EquationLineEnabledChanged +=
|
||||
m_tokenEquationLineEnabledChanged = newValue->EquationLineEnabledChanged +=
|
||||
ref new EquationChangedEventHandler(this, &Grapher::OnEquationLineEnabledChanged);
|
||||
}
|
||||
|
||||
@@ -268,8 +224,9 @@ namespace GraphControl
|
||||
PlotGraph();
|
||||
}
|
||||
|
||||
void Grapher::AnalyzeEquation(Equation ^ equation)
|
||||
KeyGraphFeaturesInfo ^ Grapher::AnalyzeEquation(Equation ^ equation)
|
||||
{
|
||||
auto result = ref new KeyGraphFeaturesInfo();
|
||||
if (auto graph = GetGraph(equation))
|
||||
{
|
||||
if (auto analyzer = graph->GetAnalyzer())
|
||||
@@ -281,38 +238,17 @@ namespace GraphControl
|
||||
(Graphing::Analyzer::NativeAnalysisType)Graphing::Analyzer::PerformAnalysisType::PerformAnalysisType_All))
|
||||
{
|
||||
Graphing::IGraphFunctionAnalysisData functionAnalysisData = m_solver->Analyze(analyzer.get());
|
||||
{
|
||||
equation->XIntercept = ref new String(functionAnalysisData.Zeros.c_str());
|
||||
equation->YIntercept = ref new String(functionAnalysisData.YIntercept.c_str());
|
||||
equation->Domain = ref new String(functionAnalysisData.Domain.c_str());
|
||||
equation->Range = ref new String(functionAnalysisData.Range.c_str());
|
||||
equation->Parity = functionAnalysisData.Parity;
|
||||
equation->PeriodicityDirection = functionAnalysisData.PeriodicityDirection;
|
||||
equation->PeriodicityExpression = ref new String(functionAnalysisData.PeriodicityExpression.c_str());
|
||||
equation->Minima = ConvertWStringVector(functionAnalysisData.Minima);
|
||||
equation->Maxima = ConvertWStringVector(functionAnalysisData.Maxima);
|
||||
equation->InflectionPoints = ConvertWStringVector(functionAnalysisData.InflectionPoints);
|
||||
equation->Monotonicity = ConvertWStringIntMap(functionAnalysisData.MonotoneIntervals);
|
||||
equation->VerticalAsymptotes = ConvertWStringVector(functionAnalysisData.VerticalAsymptotes);
|
||||
equation->HorizontalAsymptotes = ConvertWStringVector(functionAnalysisData.HorizontalAsymptotes);
|
||||
equation->ObliqueAsymptotes = ConvertWStringVector(functionAnalysisData.ObliqueAsymptotes);
|
||||
equation->TooComplexFeatures = functionAnalysisData.TooComplexFeatures;
|
||||
equation->AnalysisError = CalculatorApp::AnalysisErrorType::NoError;
|
||||
|
||||
return;
|
||||
}
|
||||
return KeyGraphFeaturesInfo::Create(functionAnalysisData);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
equation->AnalysisError = CalculatorApp::AnalysisErrorType::AnalysisNotSupported;
|
||||
|
||||
return;
|
||||
return KeyGraphFeaturesInfo::Create(CalculatorApp::AnalysisErrorType::AnalysisNotSupported);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
equation->AnalysisError = CalculatorApp::AnalysisErrorType::AnalysisCouldNotBePerformed;
|
||||
return KeyGraphFeaturesInfo::Create(CalculatorApp::AnalysisErrorType::AnalysisCouldNotBePerformed);
|
||||
}
|
||||
|
||||
void Grapher::PlotGraph()
|
||||
@@ -371,7 +307,7 @@ namespace GraphControl
|
||||
ss << L"<mo>,</mo>";
|
||||
}
|
||||
|
||||
ss << eq->GetRequest();
|
||||
ss << eq->GetRequest()->Data();
|
||||
}
|
||||
|
||||
ss << s_getGraphClosingTags;
|
||||
@@ -463,13 +399,13 @@ namespace GraphControl
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr<IGraph> Grapher::GetGraph(GraphControl::Equation ^ equation)
|
||||
shared_ptr<IGraph> Grapher::GetGraph(Equation ^ equation)
|
||||
{
|
||||
std::shared_ptr<Graphing::IGraph> graph = m_solver->CreateGrapher();
|
||||
|
||||
wstringstream ss{};
|
||||
ss << s_getGraphOpeningTags;
|
||||
ss << equation->GetRequest();
|
||||
ss << equation->GetRequest()->Data();
|
||||
ss << s_getGraphClosingTags;
|
||||
|
||||
wstring request = ss.str();
|
||||
@@ -485,30 +421,6 @@ namespace GraphControl
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
IObservableVector<String ^> ^ Grapher::ConvertWStringVector(vector<wstring> inVector)
|
||||
{
|
||||
Vector<String ^> ^ outVector = ref new Vector<String ^>();
|
||||
|
||||
for (auto v : inVector)
|
||||
{
|
||||
outVector->Append(ref new String(v.c_str()));
|
||||
}
|
||||
|
||||
return outVector;
|
||||
}
|
||||
|
||||
IObservableMap<String ^, String ^> ^ Grapher::ConvertWStringIntMap(map<wstring, int> inMap)
|
||||
{
|
||||
Map<String ^, String ^> ^ outMap = ref new Map<String ^, String ^>();
|
||||
;
|
||||
for (auto m : inMap)
|
||||
{
|
||||
outMap->Insert(ref new String(m.first.c_str()), m.second.ToString());
|
||||
}
|
||||
|
||||
return outMap;
|
||||
}
|
||||
|
||||
void Grapher::UpdateVariables()
|
||||
{
|
||||
auto updatedVariables = ref new Map<String ^, double>();
|
||||
@@ -573,7 +485,7 @@ namespace GraphControl
|
||||
graphColors.reserve(validEqs.size());
|
||||
for (Equation ^ eq : validEqs)
|
||||
{
|
||||
auto lineColor = eq->LineColor->Color;
|
||||
auto lineColor = eq->LineColor;
|
||||
graphColors.emplace_back(lineColor.R, lineColor.G, lineColor.B, lineColor.A);
|
||||
}
|
||||
options.SetGraphColors(graphColors);
|
||||
@@ -595,7 +507,7 @@ namespace GraphControl
|
||||
return validEqs;
|
||||
}
|
||||
|
||||
void Grapher::OnForceProportionalAxesChanged(DependencyPropertyChangedEventArgs ^ args)
|
||||
void Grapher::OnForceProportionalAxesPropertyChanged(bool /*oldValue*/, bool /*newValue*/)
|
||||
{
|
||||
TryUpdateGraph();
|
||||
}
|
||||
|
@@ -4,11 +4,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "DirectX/RenderMain.h"
|
||||
#include "Equation.h"
|
||||
#include "EquationCollection.h"
|
||||
#include "../Models/Equation.h"
|
||||
#include "../Models/EquationCollection.h"
|
||||
#include "../Utils.h"
|
||||
#include "IGraphAnalyzer.h"
|
||||
#include "IMathSolver.h"
|
||||
#include "Common.h"
|
||||
#include "Models/KeyGraphFeaturesInfo.h"
|
||||
#include <ppltasks.h>
|
||||
|
||||
namespace GraphControl
|
||||
{
|
||||
@@ -28,71 +31,13 @@ public
|
||||
public:
|
||||
Grapher();
|
||||
|
||||
static void RegisterDependencyProperties();
|
||||
|
||||
#pragma region GraphControl::EquationCollection ^ Equations DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ EquationsProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_equationsProperty;
|
||||
}
|
||||
}
|
||||
|
||||
property GraphControl::EquationCollection^ Equations
|
||||
{
|
||||
GraphControl::EquationCollection^ get()
|
||||
{
|
||||
return static_cast< GraphControl::EquationCollection^ >(GetValue(s_equationsProperty));
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::Foundation::Collections::IObservableMap < Platform::String ^, double> ^ Variables DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ VariablesProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_variablesProperty;
|
||||
}
|
||||
}
|
||||
|
||||
property Windows::Foundation::Collections::IObservableMap<Platform::String^, double>^ Variables
|
||||
{
|
||||
Windows::Foundation::Collections::IObservableMap<Platform::String^, double>^ get()
|
||||
{
|
||||
return static_cast<Windows::Foundation::Collections::IObservableMap<Platform::String^, double>^>(GetValue(s_variablesProperty));
|
||||
}
|
||||
|
||||
void set(Windows::Foundation::Collections::IObservableMap<Platform::String^, double>^ value)
|
||||
{
|
||||
SetValue(s_variablesProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Windows::UI::Xaml::DataTemplate ^ ForceProportionalAxes DependencyProperty
|
||||
static property Windows::UI::Xaml::DependencyProperty^ ForceProportionalAxesTemplateProperty
|
||||
{
|
||||
Windows::UI::Xaml::DependencyProperty^ get()
|
||||
{
|
||||
return s_forceProportionalAxesTemplateProperty;
|
||||
}
|
||||
}
|
||||
|
||||
property bool ForceProportionalAxes
|
||||
{
|
||||
bool get()
|
||||
{
|
||||
return static_cast<bool>(GetValue(s_forceProportionalAxesTemplateProperty));
|
||||
}
|
||||
void set(bool value)
|
||||
{
|
||||
SetValue(s_forceProportionalAxesTemplateProperty, value);
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
DEPENDENCY_PROPERTY_OWNER(Grapher);
|
||||
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(bool, ForceProportionalAxes, true);
|
||||
DEPENDENCY_PROPERTY_WITH_DEFAULT(
|
||||
SINGLE_ARG(Windows::Foundation::Collections::IObservableMap<Platform::String ^, double> ^),
|
||||
Variables,
|
||||
SINGLE_ARG(ref new Platform::Collections::Map<Platform::String ^, double>()));
|
||||
DEPENDENCY_PROPERTY_R_WITH_DEFAULT_AND_CALLBACK(GraphControl::EquationCollection ^, Equations, nullptr);
|
||||
// Pass active tracing turned on or off down to the renderer
|
||||
|
||||
property bool ActiveTracing
|
||||
@@ -153,7 +98,7 @@ public
|
||||
void SetVariable(Platform::String ^ variableName, double newValue);
|
||||
Platform::String ^ ConvertToLinear(Platform::String ^ mmlString);
|
||||
void PlotGraph();
|
||||
void AnalyzeEquation(GraphControl::Equation ^ equation);
|
||||
GraphControl::KeyGraphFeaturesInfo ^ AnalyzeEquation(GraphControl::Equation ^ equation);
|
||||
|
||||
protected:
|
||||
#pragma region Control Overrides
|
||||
@@ -173,13 +118,13 @@ public
|
||||
void OnLoaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ args);
|
||||
void OnUnloaded(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ args);
|
||||
|
||||
static void OnCustomDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject ^ obj, Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args);
|
||||
void OnForceProportionalAxesPropertyChanged(bool oldValue, bool newValue);
|
||||
void OnEquationsPropertyChanged(EquationCollection ^ oldValue, EquationCollection ^ newValue);
|
||||
void OnDependencyPropertyChanged(Windows::UI::Xaml::DependencyObject ^ obj, Windows::UI::Xaml::DependencyProperty ^ p);
|
||||
|
||||
void OnEquationsChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args);
|
||||
void OnEquationChanged(GraphControl::Equation ^ equation);
|
||||
void OnEquationStyleChanged(GraphControl::Equation ^ equation);
|
||||
void OnEquationLineEnabledChanged(GraphControl::Equation ^ equation);
|
||||
void OnEquationChanged(Equation ^ equation);
|
||||
void OnEquationStyleChanged(Equation ^ equation);
|
||||
void OnEquationLineEnabledChanged(Equation ^ equation);
|
||||
bool TryUpdateGraph();
|
||||
void TryPlotGraph(bool shouldRetry);
|
||||
void UpdateGraphOptions(Graphing::IGraphingOptions& options, const std::vector<Equation ^>& validEqs);
|
||||
@@ -188,8 +133,6 @@ public
|
||||
std::shared_ptr<Graphing::IGraph> GetGraph(GraphControl::Equation ^ equation);
|
||||
void UpdateVariables();
|
||||
|
||||
void OnForceProportionalAxesChanged(Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args);
|
||||
|
||||
void OnBackgroundColorChanged(const Windows::UI::Color& color);
|
||||
|
||||
void ScaleRange(double centerX, double centerY, double scale);
|
||||
@@ -222,8 +165,6 @@ public
|
||||
Windows::Foundation::EventRegistrationToken m_tokenEquationChanged;
|
||||
Windows::Foundation::EventRegistrationToken m_tokenEquationLineEnabledChanged;
|
||||
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_forceProportionalAxesTemplateProperty;
|
||||
|
||||
Windows::Foundation::EventRegistrationToken m_tokenBackgroundColorChanged;
|
||||
|
||||
const std::unique_ptr<Graphing::IMathSolver> m_solver;
|
||||
|
@@ -284,24 +284,27 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Control\Equation.h" />
|
||||
<ClInclude Include="Control\EquationCollection.h" />
|
||||
<ClInclude Include="Control\Grapher.h" />
|
||||
<ClInclude Include="DirectX\ActiveTracingPointRenderer.h" />
|
||||
<ClInclude Include="DirectX\DeviceResources.h" />
|
||||
<ClInclude Include="DirectX\DirectXHelper.h" />
|
||||
<ClInclude Include="DirectX\NearestPointRenderer.h" />
|
||||
<ClInclude Include="DirectX\RenderMain.h" />
|
||||
<ClInclude Include="Models\Equation.h" />
|
||||
<ClInclude Include="Models\EquationCollection.h" />
|
||||
<ClInclude Include="Models\KeyGraphFeaturesInfo.h" />
|
||||
<ClInclude Include="pch.h" />
|
||||
<ClInclude Include="Utils.h" />
|
||||
<ClInclude Include="winrtHeaders.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Control\Equation.cpp" />
|
||||
<ClCompile Include="Control\Grapher.cpp" />
|
||||
<ClCompile Include="DirectX\ActiveTracingPointRenderer.cpp" />
|
||||
<ClCompile Include="DirectX\DeviceResources.cpp" />
|
||||
<ClCompile Include="DirectX\NearestPointRenderer.cpp" />
|
||||
<ClCompile Include="DirectX\RenderMain.cpp" />
|
||||
<ClCompile Include="Models\Equation.cpp" />
|
||||
<ClCompile Include="Models\KeyGraphFeaturesInfo.cpp" />
|
||||
<ClCompile Include="pch.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
|
@@ -10,6 +10,9 @@
|
||||
<Filter Include="Control">
|
||||
<UniqueIdentifier>{e8d91a71-6933-4fd8-b333-421085d13896}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Models">
|
||||
<UniqueIdentifier>{0f768477-7ceb-42c4-a32a-cb024320dbc3}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="pch.cpp" />
|
||||
@@ -19,9 +22,6 @@
|
||||
<ClCompile Include="DirectX\RenderMain.cpp">
|
||||
<Filter>DirectX</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Control\Equation.cpp">
|
||||
<Filter>Control</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Control\Grapher.cpp">
|
||||
<Filter>Control</Filter>
|
||||
</ClCompile>
|
||||
@@ -31,6 +31,10 @@
|
||||
<ClCompile Include="DirectX\ActiveTracingPointRenderer.cpp">
|
||||
<Filter>DirectX</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Models\KeyGraphFeaturesInfo.cpp" />
|
||||
<ClCompile Include="Models\Equation.cpp">
|
||||
<Filter>Models</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="pch.h" />
|
||||
@@ -44,12 +48,6 @@
|
||||
<Filter>DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="winrtHeaders.h" />
|
||||
<ClInclude Include="Control\Equation.h">
|
||||
<Filter>Control</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Control\EquationCollection.h">
|
||||
<Filter>Control</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Control\Grapher.h">
|
||||
<Filter>Control</Filter>
|
||||
</ClInclude>
|
||||
@@ -59,6 +57,14 @@
|
||||
<ClInclude Include="DirectX\ActiveTracingPointRenderer.h">
|
||||
<Filter>DirectX</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Utils.h" />
|
||||
<ClInclude Include="Models\KeyGraphFeaturesInfo.h" />
|
||||
<ClInclude Include="Models\Equation.h">
|
||||
<Filter>Models</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Models\EquationCollection.h">
|
||||
<Filter>Models</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Page Include="Themes\generic.xaml">
|
||||
@@ -71,5 +77,7 @@
|
||||
<ItemGroup>
|
||||
<CopyFileToFolders Include="$(GraphingImplDll)" />
|
||||
<CopyFileToFolders Include="$(GraphingEngineDll)" />
|
||||
<CopyFileToFolders Include="$(GraphingImplDll)" />
|
||||
<CopyFileToFolders Include="$(GraphingEngineDll)" />
|
||||
</ItemGroup>
|
||||
</Project>
|
85
src/GraphControl/Models/Equation.cpp
Normal file
85
src/GraphControl/Models/Equation.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
// 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;
|
||||
}
|
||||
}
|
41
src/GraphControl/Models/Equation.h
Normal file
41
src/GraphControl/Models/Equation.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
#include "Utils.h"
|
||||
#include <string>
|
||||
|
||||
namespace GraphControl
|
||||
{
|
||||
[Windows::UI::Xaml::Data::Bindable] public ref class Equation sealed : public Windows::UI::Xaml::Data::INotifyPropertyChanged
|
||||
{
|
||||
public:
|
||||
Equation();
|
||||
|
||||
OBSERVABLE_OBJECT();
|
||||
OBSERVABLE_NAMED_PROPERTY_RW(Platform::String ^, Expression);
|
||||
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsLineEnabled);
|
||||
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsValidated);
|
||||
OBSERVABLE_NAMED_PROPERTY_RW(bool, HasGraphError);
|
||||
|
||||
property Windows::UI::Color LineColor
|
||||
{
|
||||
Windows::UI::Color get();
|
||||
void set(Windows::UI::Color value);
|
||||
}
|
||||
|
||||
static property Platform::String
|
||||
^ LineColorPropertyName { Platform::String ^ get(); }
|
||||
|
||||
public : Platform::String
|
||||
^ GetRequest();
|
||||
|
||||
bool IsGraphableEquation();
|
||||
|
||||
private:
|
||||
std::wstring GetExpression();
|
||||
|
||||
private:
|
||||
Windows::UI::Color m_LineColor;
|
||||
};
|
||||
}
|
@@ -38,7 +38,7 @@ public
|
||||
{
|
||||
m_vector->Append(value);
|
||||
m_tokens.emplace_back(
|
||||
value->PropertyChanged += ref new GraphControl::PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged));
|
||||
value->PropertyChanged += ref new Windows::UI::Xaml::Data::PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged));
|
||||
}
|
||||
|
||||
virtual void Clear()
|
||||
@@ -75,7 +75,8 @@ public
|
||||
{
|
||||
m_vector->InsertAt(index, value);
|
||||
m_tokens.insert(
|
||||
m_tokens.begin() + index, value->PropertyChanged += ref new PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged));
|
||||
m_tokens.begin() + index,
|
||||
value->PropertyChanged += ref new Windows::UI::Xaml::Data::PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged));
|
||||
}
|
||||
|
||||
virtual void RemoveAt(unsigned int index)
|
||||
@@ -110,7 +111,8 @@ public
|
||||
m_tokens.resize(size);
|
||||
for (auto i = 0u; i < size; i++)
|
||||
{
|
||||
m_tokens[i] = items[i]->PropertyChanged += ref new PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged);
|
||||
m_tokens[i] = items[i]->PropertyChanged +=
|
||||
ref new Windows::UI::Xaml::Data::PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged);
|
||||
}
|
||||
|
||||
m_vector->ReplaceAll(items);
|
||||
@@ -121,7 +123,8 @@ public
|
||||
m_vector->GetAt(index)->PropertyChanged -= m_tokens[index];
|
||||
|
||||
m_vector->SetAt(index, value);
|
||||
m_tokens[index] = value->PropertyChanged += ref new PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged);
|
||||
m_tokens[index] = value->PropertyChanged +=
|
||||
ref new Windows::UI::Xaml::Data::PropertyChangedEventHandler(this, &EquationCollection::OnEquationPropertyChanged);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
@@ -151,19 +154,21 @@ public
|
||||
event EquationChangedEventHandler ^ EquationLineEnabledChanged;
|
||||
|
||||
private:
|
||||
void OnEquationPropertyChanged(GraphControl::Equation ^ sender, Platform::String ^ propertyName)
|
||||
void OnEquationPropertyChanged(Object^ sender, Windows::UI::Xaml::Data::PropertyChangedEventArgs ^ args)
|
||||
{
|
||||
if (propertyName == EquationProperties::LineColor)
|
||||
auto equation = static_cast<Equation ^>(sender);
|
||||
auto propertyName = args->PropertyName;
|
||||
if (propertyName == GraphControl::Equation::LineColorPropertyName)
|
||||
{
|
||||
EquationStyleChanged(sender);
|
||||
EquationStyleChanged(equation);
|
||||
}
|
||||
else if (propertyName == EquationProperties::Expression)
|
||||
else if (propertyName == GraphControl::Equation::ExpressionPropertyName)
|
||||
{
|
||||
EquationChanged(sender);
|
||||
EquationChanged(equation);
|
||||
}
|
||||
else if (propertyName == EquationProperties::IsLineEnabled)
|
||||
else if (propertyName == GraphControl::Equation::IsLineEnabledPropertyName)
|
||||
{
|
||||
EquationLineEnabledChanged(sender);
|
||||
EquationLineEnabledChanged(equation);
|
||||
}
|
||||
}
|
||||
|
70
src/GraphControl/Models/KeyGraphFeaturesInfo.cpp
Normal file
70
src/GraphControl/Models/KeyGraphFeaturesInfo.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "KeyGraphFeaturesInfo.h"
|
||||
#include "../../CalcViewModel/GraphingCalculatorEnums.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;
|
||||
using namespace GraphControl;
|
||||
using namespace Graphing;
|
||||
|
||||
IObservableVector<String ^> ^ KeyGraphFeaturesInfo::ConvertWStringVector(vector<wstring> inVector)
|
||||
{
|
||||
auto outVector = ref new Vector<String ^>();
|
||||
|
||||
for (auto v : inVector)
|
||||
{
|
||||
outVector->Append(ref new String(v.c_str()));
|
||||
}
|
||||
|
||||
return outVector;
|
||||
}
|
||||
|
||||
IObservableMap<String ^, String ^> ^ KeyGraphFeaturesInfo::ConvertWStringIntMap(map<wstring, int> inMap)
|
||||
{
|
||||
Map<String ^, String ^> ^ outMap = ref new Map<String ^, String ^>();
|
||||
;
|
||||
for (auto m : inMap)
|
||||
{
|
||||
outMap->Insert(ref new String(m.first.c_str()), m.second.ToString());
|
||||
}
|
||||
|
||||
return outMap;
|
||||
}
|
||||
|
||||
KeyGraphFeaturesInfo ^ KeyGraphFeaturesInfo::Create(IGraphFunctionAnalysisData data)
|
||||
{
|
||||
auto res = ref new KeyGraphFeaturesInfo();
|
||||
res->XIntercept = ref new String(data.Zeros.c_str());
|
||||
res->YIntercept = ref new String(data.YIntercept.c_str());
|
||||
res->Domain = ref new String(data.Domain.c_str());
|
||||
res->Range = ref new String(data.Range.c_str());
|
||||
res->Parity = data.Parity;
|
||||
res->PeriodicityDirection = data.PeriodicityDirection;
|
||||
res->PeriodicityExpression = ref new String(data.PeriodicityExpression.c_str());
|
||||
res->Minima = ConvertWStringVector(data.Minima);
|
||||
res->Maxima = ConvertWStringVector(data.Maxima);
|
||||
res->InflectionPoints = ConvertWStringVector(data.InflectionPoints);
|
||||
res->Monotonicity = ConvertWStringIntMap(data.MonotoneIntervals);
|
||||
res->VerticalAsymptotes = ConvertWStringVector(data.VerticalAsymptotes);
|
||||
res->HorizontalAsymptotes = ConvertWStringVector(data.HorizontalAsymptotes);
|
||||
res->ObliqueAsymptotes = ConvertWStringVector(data.ObliqueAsymptotes);
|
||||
res->TooComplexFeatures = data.TooComplexFeatures;
|
||||
res->AnalysisError = CalculatorApp::AnalysisErrorType::NoError;
|
||||
return res;
|
||||
}
|
||||
|
||||
KeyGraphFeaturesInfo ^ KeyGraphFeaturesInfo::Create(CalculatorApp::AnalysisErrorType type)
|
||||
{
|
||||
auto res = ref new KeyGraphFeaturesInfo();
|
||||
res->AnalysisError = type;
|
||||
return res;
|
||||
}
|
51
src/GraphControl/Models/KeyGraphFeaturesInfo.h
Normal file
51
src/GraphControl/Models/KeyGraphFeaturesInfo.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
#include "Utils.h"
|
||||
|
||||
|
||||
namespace Graphing
|
||||
{
|
||||
struct IGraphFunctionAnalysisData;
|
||||
}
|
||||
|
||||
namespace CalculatorApp
|
||||
{
|
||||
enum AnalysisErrorType;
|
||||
}
|
||||
|
||||
namespace GraphControl
|
||||
{
|
||||
|
||||
public
|
||||
ref class KeyGraphFeaturesInfo sealed
|
||||
{
|
||||
public:
|
||||
PROPERTY_R(Platform::String ^, XIntercept);
|
||||
PROPERTY_R(Platform::String ^, YIntercept);
|
||||
PROPERTY_R(int, Parity);
|
||||
PROPERTY_R(int, PeriodicityDirection);
|
||||
PROPERTY_R(Platform::String ^, PeriodicityExpression);
|
||||
PROPERTY_R(Windows::Foundation::Collections::IVector<Platform::String ^> ^, Minima);
|
||||
PROPERTY_R(Windows::Foundation::Collections::IVector<Platform::String ^> ^, Maxima);
|
||||
PROPERTY_R(Platform::String ^, Domain);
|
||||
PROPERTY_R(Platform::String ^, Range);
|
||||
PROPERTY_R(Windows::Foundation::Collections::IVector<Platform::String ^> ^, InflectionPoints);
|
||||
PROPERTY_R(SINGLE_ARG(Windows::Foundation::Collections::IObservableMap<Platform::String ^, Platform::String ^> ^), Monotonicity);
|
||||
PROPERTY_R(Windows::Foundation::Collections::IVector<Platform::String ^> ^, VerticalAsymptotes);
|
||||
PROPERTY_R(Windows::Foundation::Collections::IVector<Platform::String ^> ^, HorizontalAsymptotes);
|
||||
PROPERTY_R(Windows::Foundation::Collections::IVector<Platform::String ^> ^, ObliqueAsymptotes);
|
||||
PROPERTY_R(int, TooComplexFeatures);
|
||||
PROPERTY_R(int, AnalysisError);
|
||||
|
||||
internal:
|
||||
static KeyGraphFeaturesInfo ^ Create(Graphing::IGraphFunctionAnalysisData data);
|
||||
static KeyGraphFeaturesInfo ^ Create(CalculatorApp::AnalysisErrorType type);
|
||||
|
||||
private:
|
||||
static Windows::Foundation::Collections::IObservableVector<Platform::String ^> ^ ConvertWStringVector(std::vector<std::wstring> inVector);
|
||||
static Windows::Foundation::Collections::
|
||||
IObservableMap<Platform::String ^, Platform::String ^> ^ ConvertWStringIntMap(std::map<std::wstring, int> inMap);
|
||||
};
|
||||
}
|
588
src/GraphControl/Utils.h
Normal file
588
src/GraphControl/Utils.h
Normal file
@@ -0,0 +1,588 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#pragma once
|
||||
|
||||
// Utility macros to make Models easier to write
|
||||
// generates a member variable called m_<n>
|
||||
|
||||
#define SINGLE_ARG(...) __VA_ARGS__
|
||||
|
||||
#define PROPERTY_R(t, n) \
|
||||
property t n \
|
||||
{ \
|
||||
t get() \
|
||||
{ \
|
||||
return m_##n; \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
void set(t value) \
|
||||
{ \
|
||||
m_##n = value; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
t m_##n; \
|
||||
\
|
||||
public:
|
||||
|
||||
#define PROPERTY_RW(t, n) \
|
||||
property t n \
|
||||
{ \
|
||||
t get() \
|
||||
{ \
|
||||
return m_##n; \
|
||||
} \
|
||||
void set(t value) \
|
||||
{ \
|
||||
m_##n = value; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
t m_##n; \
|
||||
\
|
||||
public:
|
||||
|
||||
#define OBSERVABLE_PROPERTY_R(t, n) \
|
||||
property t n \
|
||||
{ \
|
||||
t get() \
|
||||
{ \
|
||||
return m_##n; \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
void set(t value) \
|
||||
{ \
|
||||
if (m_##n != value) \
|
||||
{ \
|
||||
m_##n = value; \
|
||||
RaisePropertyChanged(L#n); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
t m_##n; \
|
||||
\
|
||||
public:
|
||||
|
||||
#define OBSERVABLE_PROPERTY_RW(t, n) \
|
||||
property t n \
|
||||
{ \
|
||||
t get() \
|
||||
{ \
|
||||
return m_##n; \
|
||||
} \
|
||||
void set(t value) \
|
||||
{ \
|
||||
if (m_##n != value) \
|
||||
{ \
|
||||
m_##n = value; \
|
||||
RaisePropertyChanged(L#n); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
t m_##n; \
|
||||
\
|
||||
public:
|
||||
|
||||
#define OBSERVABLE_NAMED_PROPERTY_R(t, n) \
|
||||
OBSERVABLE_PROPERTY_R(t, n) \
|
||||
internal: \
|
||||
static property Platform::String ^ n##PropertyName \
|
||||
{ \
|
||||
Platform::String ^ get() { return Platform::StringReference(L#n); } \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
|
||||
#define OBSERVABLE_NAMED_PROPERTY_RW(t, n) \
|
||||
OBSERVABLE_PROPERTY_RW(t, n) \
|
||||
internal: \
|
||||
static property Platform::String ^ n##PropertyName \
|
||||
{ \
|
||||
Platform::String ^ get() { return Platform::StringReference(L#n); } \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
|
||||
#define OBSERVABLE_PROPERTY_FIELD(n) m_##n
|
||||
|
||||
// This variant of the observable object is for objects that don't want to react to property changes
|
||||
#ifndef UNIT_TESTS
|
||||
#define OBSERVABLE_OBJECT() \
|
||||
virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler ^ PropertyChanged; \
|
||||
internal: \
|
||||
void RaisePropertyChanged(Platform::String ^ p) \
|
||||
{ \
|
||||
PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p)); \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
#else
|
||||
#define OBSERVABLE_OBJECT() \
|
||||
virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler ^ PropertyChanged; \
|
||||
internal: \
|
||||
void RaisePropertyChanged(Platform::String ^ p) \
|
||||
{ \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
#endif
|
||||
|
||||
// The callback specified in the macro is a method in the class that will be called every time the object changes
|
||||
// the callback is supposed to be have a single parameter of type Platform::String^
|
||||
#ifndef UNIT_TESTS
|
||||
#define OBSERVABLE_OBJECT_CALLBACK(c) \
|
||||
virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler ^ PropertyChanged; \
|
||||
internal: \
|
||||
void RaisePropertyChanged(Platform::String ^ p) \
|
||||
{ \
|
||||
PropertyChanged(this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs(p)); \
|
||||
c(p); \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
#else
|
||||
#define OBSERVABLE_OBJECT_CALLBACK(c) \
|
||||
virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler ^ PropertyChanged; \
|
||||
internal: \
|
||||
void RaisePropertyChanged(Platform::String ^ p) \
|
||||
{ \
|
||||
c(p); \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
#endif
|
||||
|
||||
// The variable member generated by this macro should not be used in the class code, use the
|
||||
// property getter instead.
|
||||
#define COMMAND_FOR_METHOD(p, m) \
|
||||
property Windows::UI::Xaml::Input::ICommand^ p {\
|
||||
Windows::UI::Xaml::Input::ICommand^ get() {\
|
||||
if (!donotuse_##p) {\
|
||||
donotuse_##p = CalculatorApp::Common::MakeDelegate(this, &m);\
|
||||
} return donotuse_##p; }} private: Windows::UI::Xaml::Input::ICommand^ donotuse_##p; \
|
||||
\
|
||||
public:
|
||||
|
||||
// Utilities for DependencyProperties
|
||||
namespace Utils
|
||||
{
|
||||
namespace Details
|
||||
{
|
||||
template <typename T>
|
||||
struct IsRefClass
|
||||
{
|
||||
static const bool value = __is_ref_class(T);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct RemoveHat
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct RemoveHat<T ^>
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<IsRefClass<T>::value, T ^>::type MakeDefault()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
typename std::enable_if<!IsRefClass<T>::value, T>::type MakeDefault()
|
||||
{
|
||||
return T();
|
||||
}
|
||||
|
||||
// There's a bug in Xaml in which custom enums are not recognized by the property system/binding
|
||||
// therefore this template will determine that for enums the type to use to register the
|
||||
// DependencyProperty is to be Object, for everything else it will use the type
|
||||
// NOTE: If we are to find more types in which this is broken this template
|
||||
// will be specialized for those types to return Object
|
||||
template <typename T>
|
||||
struct TypeToUseForDependencyProperty
|
||||
{
|
||||
typedef typename std::conditional<std::is_enum<T>::value, Platform::Object, T>::type type;
|
||||
};
|
||||
}
|
||||
|
||||
const wchar_t LRE = 0x202a; // Left-to-Right Embedding
|
||||
const wchar_t PDF = 0x202c; // Pop Directional Formatting
|
||||
const wchar_t LRO = 0x202d; // Left-to-Right Override
|
||||
|
||||
// Regular DependencyProperty
|
||||
template <typename TOwner, typename TType>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyProperty(
|
||||
_In_ const wchar_t* const name,
|
||||
_In_ Windows::UI::Xaml::PropertyMetadata^ metadata)
|
||||
{
|
||||
typedef typename Details::RemoveHat<TOwner>::type OwnerType;
|
||||
typedef typename Details::RemoveHat<TType>::type ThisPropertyType;
|
||||
typedef typename Details::TypeToUseForDependencyProperty<ThisPropertyType>::type ThisDependencyPropertyType;
|
||||
|
||||
static_assert(Details::IsRefClass<OwnerType>::value, "The owner of a DependencyProperty must be a ref class");
|
||||
|
||||
return Windows::UI::Xaml::DependencyProperty::Register(
|
||||
Platform::StringReference(name),
|
||||
ThisDependencyPropertyType::typeid, // Work around bugs in Xaml by using the filtered type
|
||||
OwnerType::typeid,
|
||||
metadata);
|
||||
}
|
||||
|
||||
template <typename TOwner, typename TType>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyProperty(_In_ const wchar_t* const name)
|
||||
{
|
||||
typedef typename Details::RemoveHat<TType>::type ThisPropertyType;
|
||||
|
||||
return RegisterDependencyProperty<TOwner, TType>(
|
||||
name,
|
||||
ref new Windows::UI::Xaml::PropertyMetadata(Details::MakeDefault<ThisPropertyType>()));
|
||||
}
|
||||
|
||||
template <typename TOwner, typename TType>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyProperty(_In_ const wchar_t* const name, TType defaultValue)
|
||||
{
|
||||
return RegisterDependencyProperty<TOwner, TType>(
|
||||
name,
|
||||
ref new Windows::UI::Xaml::PropertyMetadata(defaultValue));
|
||||
}
|
||||
|
||||
template <typename TOwner, typename TType, typename TCallback>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyPropertyWithCallback(
|
||||
_In_ wchar_t const * const name,
|
||||
TCallback callback)
|
||||
{
|
||||
typedef typename Details::RemoveHat<TType>::type ThisPropertyType;
|
||||
return RegisterDependencyProperty<TOwner, TType>(
|
||||
name,
|
||||
ref new Windows::UI::Xaml::PropertyMetadata(
|
||||
Details::MakeDefault<ThisPropertyType>(),
|
||||
ref new Windows::UI::Xaml::PropertyChangedCallback(callback)));
|
||||
}
|
||||
|
||||
template <typename TOwner, typename TType, typename TCallback>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyPropertyWithCallback(
|
||||
_In_ wchar_t const * const name,
|
||||
TType defaultValue,
|
||||
TCallback callback)
|
||||
{
|
||||
typedef typename Details::RemoveHat<TType>::type ThisPropertyType;
|
||||
return RegisterDependencyProperty<TOwner, TType>(
|
||||
name,
|
||||
ref new Windows::UI::Xaml::PropertyMetadata(
|
||||
defaultValue,
|
||||
ref new Windows::UI::Xaml::PropertyChangedCallback(callback)));
|
||||
}
|
||||
|
||||
// Attached DependencyProperty
|
||||
template <typename TOwner, typename TType>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyPropertyAttached(
|
||||
_In_ const wchar_t* const name,
|
||||
_In_ Windows::UI::Xaml::PropertyMetadata^ metadata)
|
||||
{
|
||||
typedef typename Details::RemoveHat<TOwner>::type OwnerType;
|
||||
typedef typename Details::RemoveHat<TType>::type ThisPropertyType;
|
||||
typedef typename Details::TypeToUseForDependencyProperty<ThisPropertyType>::type ThisDependencyPropertyType;
|
||||
|
||||
static_assert(Details::IsRefClass<OwnerType>::value, "The owner of a DependencyProperty must be a ref class");
|
||||
|
||||
return Windows::UI::Xaml::DependencyProperty::RegisterAttached(
|
||||
Platform::StringReference(name),
|
||||
ThisDependencyPropertyType::typeid, // Work around bugs in Xaml by using the filtered type
|
||||
OwnerType::typeid,
|
||||
metadata);
|
||||
}
|
||||
|
||||
template <typename TOwner, typename TType>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyPropertyAttached(_In_ const wchar_t* const name)
|
||||
{
|
||||
typedef typename Details::RemoveHat<TType>::type ThisPropertyType;
|
||||
return RegisterDependencyPropertyAttached<TOwner, TType>(
|
||||
name,
|
||||
ref new Windows::UI::Xaml::PropertyMetadata(Details::MakeDefault<ThisPropertyType>()));
|
||||
}
|
||||
|
||||
template <typename TOwner, typename TType>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyPropertyAttached(_In_ const wchar_t* const name, TType defaultValue)
|
||||
{
|
||||
return RegisterDependencyPropertyAttached<TOwner, TType>(
|
||||
name,
|
||||
ref new Windows::UI::Xaml::PropertyMetadata(defaultValue));
|
||||
}
|
||||
|
||||
template <typename TOwner, typename TType, typename TCallback>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyPropertyAttachedWithCallback(
|
||||
_In_ wchar_t const * const name,
|
||||
TCallback callback)
|
||||
{
|
||||
typedef typename Details::RemoveHat<TType>::type ThisPropertyType;
|
||||
return RegisterDependencyPropertyAttached<TOwner, TType>(
|
||||
name,
|
||||
ref new Windows::UI::Xaml::PropertyMetadata(
|
||||
Details::MakeDefault<ThisPropertyType>(),
|
||||
ref new Windows::UI::Xaml::PropertyChangedCallback(callback)));
|
||||
}
|
||||
|
||||
template <typename TOwner, typename TType, typename TCallback>
|
||||
Windows::UI::Xaml::DependencyProperty^ RegisterDependencyPropertyAttachedWithCallback(
|
||||
_In_ wchar_t const * const name,
|
||||
TType defaultValue,
|
||||
TCallback callback)
|
||||
{
|
||||
typedef typename Details::RemoveHat<TType>::type ThisPropertyType;
|
||||
return RegisterDependencyPropertyAttached<TOwner, TType>(
|
||||
name,
|
||||
ref new Windows::UI::Xaml::PropertyMetadata(
|
||||
defaultValue,
|
||||
ref new Windows::UI::Xaml::PropertyChangedCallback(callback)));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Swap(T *ref1, T *ref2)
|
||||
{
|
||||
T temp = *ref1;
|
||||
*ref1 = *ref2;
|
||||
*ref2 = temp;
|
||||
}
|
||||
}
|
||||
|
||||
// This goes into the header to define the property, in the public: section of the class
|
||||
#define DEPENDENCY_PROPERTY_OWNER(owner) \
|
||||
private: \
|
||||
typedef owner DependencyPropertiesOwner; \
|
||||
\
|
||||
public:
|
||||
|
||||
// Normal DependencyProperty
|
||||
#define DEPENDENCY_PROPERTY(type, name) \
|
||||
property type name \
|
||||
{ \
|
||||
type get() \
|
||||
{ \
|
||||
return safe_cast<type>(GetValue(s_##name##Property)); \
|
||||
} \
|
||||
void set(type value) \
|
||||
{ \
|
||||
SetValue(s_##name##Property, value); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||
\
|
||||
public: \
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ name##Property \
|
||||
{ \
|
||||
Windows::UI::Xaml::DependencyProperty ^ get() { \
|
||||
assert(s_##name##Property); \
|
||||
return s_##name##Property; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ Initialize##name##Property() \
|
||||
{ \
|
||||
return Utils::RegisterDependencyProperty<DependencyPropertiesOwner, type>(L#name); \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
|
||||
#define DEPENDENCY_PROPERTY_WITH_CALLBACK(type, name) \
|
||||
property type name \
|
||||
{ \
|
||||
type get() \
|
||||
{ \
|
||||
return safe_cast<type>(GetValue(s_##name##Property)); \
|
||||
} \
|
||||
void set(type value) \
|
||||
{ \
|
||||
SetValue(s_##name##Property, value); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||
\
|
||||
public: \
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ name##Property \
|
||||
{ \
|
||||
Windows::UI::Xaml::DependencyProperty ^ get() { \
|
||||
assert(s_##name##Property); \
|
||||
return s_##name##Property; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ Initialize##name##Property() \
|
||||
{ \
|
||||
return Utils::RegisterDependencyPropertyWithCallback<DependencyPropertiesOwner, type>(L#name, &On##name##PropertyChangedImpl); \
|
||||
} \
|
||||
static void On##name##PropertyChangedImpl(Windows::UI::Xaml::DependencyObject ^ sender, Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args) \
|
||||
{ \
|
||||
auto self = safe_cast<DependencyPropertiesOwner ^>(sender); \
|
||||
self->On##name##PropertyChanged(safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
#define DEPENDENCY_PROPERTY_WITH_DEFAULT(type, name, defaultValue) \
|
||||
property type name \
|
||||
{ \
|
||||
type get() \
|
||||
{ \
|
||||
return safe_cast<type>(GetValue(s_##name##Property)); \
|
||||
} \
|
||||
void set(type value) \
|
||||
{ \
|
||||
SetValue(s_##name##Property, value); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||
\
|
||||
public: \
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ name##Property \
|
||||
{ \
|
||||
Windows::UI::Xaml::DependencyProperty ^ get() { \
|
||||
assert(s_##name##Property); \
|
||||
return s_##name##Property; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ Initialize##name##Property() \
|
||||
{ \
|
||||
return Utils::RegisterDependencyProperty<DependencyPropertiesOwner, type>(L#name, defaultValue); \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
|
||||
#define DEPENDENCY_PROPERTY_WITH_CALLBACK(type, name) \
|
||||
property type name \
|
||||
{ \
|
||||
type get() \
|
||||
{ \
|
||||
return safe_cast<type>(GetValue(s_##name##Property)); \
|
||||
} \
|
||||
void set(type value) \
|
||||
{ \
|
||||
SetValue(s_##name##Property, value); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||
\
|
||||
public: \
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ name##Property \
|
||||
{ \
|
||||
Windows::UI::Xaml::DependencyProperty ^ get() { \
|
||||
assert(s_##name##Property); \
|
||||
return s_##name##Property; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ Initialize##name##Property() \
|
||||
{ \
|
||||
return Utils::RegisterDependencyPropertyWithCallback<DependencyPropertiesOwner, type>(L#name, &On##name##PropertyChangedImpl); \
|
||||
} \
|
||||
static void On##name##PropertyChangedImpl(Windows::UI::Xaml::DependencyObject ^ sender, Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args) \
|
||||
{ \
|
||||
auto self = safe_cast<DependencyPropertiesOwner ^>(sender); \
|
||||
self->On##name##PropertyChanged(safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
|
||||
#define DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(type, name, defaultValue) \
|
||||
property type name \
|
||||
{ \
|
||||
type get() \
|
||||
{ \
|
||||
return safe_cast<type>(GetValue(s_##name##Property)); \
|
||||
} \
|
||||
void set(type value) \
|
||||
{ \
|
||||
SetValue(s_##name##Property, value); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||
\
|
||||
public: \
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ name##Property \
|
||||
{ \
|
||||
Windows::UI::Xaml::DependencyProperty ^ get() { \
|
||||
assert(s_##name##Property); \
|
||||
return s_##name##Property; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ Initialize##name##Property() \
|
||||
{ \
|
||||
return Utils::RegisterDependencyPropertyWithCallback<DependencyPropertiesOwner, type>(L#name, defaultValue, &On##name##PropertyChangedImpl); \
|
||||
} \
|
||||
static void On##name##PropertyChangedImpl(Windows::UI::Xaml::DependencyObject ^ sender, Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args) \
|
||||
{ \
|
||||
auto self = safe_cast<DependencyPropertiesOwner ^>(sender); \
|
||||
self->On##name##PropertyChanged(safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
|
||||
#define DEPENDENCY_PROPERTY_R_WITH_DEFAULT_AND_CALLBACK(type, name, defaultValue) \
|
||||
property type name \
|
||||
{ \
|
||||
type get() \
|
||||
{ \
|
||||
return safe_cast<type>(GetValue(s_##name##Property)); \
|
||||
} \
|
||||
private: void set(type value) \
|
||||
{ \
|
||||
SetValue(s_##name##Property, value); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ s_##name##Property; \
|
||||
\
|
||||
public: \
|
||||
static property Windows::UI::Xaml::DependencyProperty ^ name##Property \
|
||||
{ \
|
||||
Windows::UI::Xaml::DependencyProperty ^ get() { \
|
||||
assert(s_##name##Property); \
|
||||
return s_##name##Property; \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
private: \
|
||||
static Windows::UI::Xaml::DependencyProperty ^ Initialize##name##Property() \
|
||||
{ \
|
||||
return Utils::RegisterDependencyPropertyWithCallback<DependencyPropertiesOwner, type>(L#name, defaultValue, &On##name##PropertyChangedImpl); \
|
||||
} \
|
||||
static void On##name##PropertyChangedImpl(Windows::UI::Xaml::DependencyObject ^ sender, Windows::UI::Xaml::DependencyPropertyChangedEventArgs ^ args) \
|
||||
{ \
|
||||
auto self = safe_cast<DependencyPropertiesOwner ^>(sender); \
|
||||
self->On##name##PropertyChanged(safe_cast<type>(args->OldValue), safe_cast<type>(args->NewValue)); \
|
||||
} \
|
||||
\
|
||||
public:
|
||||
|
||||
// This goes into the cpp to initialize the static variable
|
||||
#define DEPENDENCY_PROPERTY_INITIALIZATION(owner, name) Windows::UI::Xaml::DependencyProperty ^ owner::s_##name##Property = owner::Initialize##name##Property();
|
@@ -18,6 +18,10 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <type_traits>
|
||||
|
||||
|
||||
// DirectX headers
|
||||
#include <d2d1_3.h>
|
||||
|
Reference in New Issue
Block a user