Refactor Equation to be treated as a model and update Key Graph Features (#791)
* refactor code * update KGF * Rename some functions * Undo comment out of proj file * Pr feedback
This commit is contained in:
@@ -63,7 +63,7 @@ void EquationInputArea::AddEquationButton_Click(Object ^ sender, RoutedEventArgs
|
||||
|
||||
void EquationInputArea::AddNewEquation()
|
||||
{
|
||||
auto eq = ref new EquationViewModel();
|
||||
auto eq = ref new EquationViewModel(ref new Equation());
|
||||
|
||||
m_lastLineColorIndex = (m_lastLineColorIndex + 1) % AvailableColors->Size;
|
||||
|
||||
@@ -111,7 +111,7 @@ void EquationInputArea::EquationTextBox_KeyGraphFeaturesButtonClicked(Object ^ s
|
||||
auto tb = static_cast<EquationTextBox ^>(sender);
|
||||
auto eq = static_cast<EquationViewModel ^>(tb->DataContext);
|
||||
EquationVM = eq;
|
||||
KeyGraphFeaturesVisibilityChanged(this, ref new RoutedEventArgs());
|
||||
KeyGraphFeaturesRequested(EquationVM, ref new RoutedEventArgs());
|
||||
}
|
||||
|
||||
void EquationInputArea::EquationTextBox_EquationButtonClicked(Object ^ sender, RoutedEventArgs ^ e)
|
||||
|
@@ -23,7 +23,7 @@ namespace CalculatorApp
|
||||
OBSERVABLE_PROPERTY_RW_ALWAYS_NOTIFY(ViewModel::EquationViewModel ^, EquationVM);
|
||||
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IObservableVector<Windows::UI::Xaml::Media::SolidColorBrush ^> ^, AvailableColors);
|
||||
|
||||
event Windows::UI::Xaml::RoutedEventHandler ^ KeyGraphFeaturesVisibilityChanged;
|
||||
event Windows::UI::Xaml::RoutedEventHandler ^ KeyGraphFeaturesRequested;
|
||||
|
||||
private:
|
||||
void OnPropertyChanged(Platform::String^ propertyName);
|
||||
|
@@ -182,7 +182,6 @@
|
||||
Grid.Column="0">
|
||||
<Grid Grid.Row="0" Margin="0,4,0,0">
|
||||
<graphControl:Grapher Name="GraphingControl"
|
||||
EquationsSource="{x:Bind ViewModel.Equations, Mode=OneWay}"
|
||||
ForceProportionalAxes="True"
|
||||
LosingFocus="GraphingControl_LosingFocus"
|
||||
LostFocus="GraphingControl_LostFocus"
|
||||
@@ -191,30 +190,6 @@
|
||||
<graphControl:Grapher.Background>
|
||||
<SolidColorBrush Color="White"/>
|
||||
</graphControl:Grapher.Background>
|
||||
<graphControl:Grapher.EquationTemplate>
|
||||
<DataTemplate x:DataType="vm:EquationViewModel">
|
||||
<graphControl:Equation AnalysisError="{x:Bind AnalysisError, Mode=TwoWay}"
|
||||
Domain="{x:Bind Domain, Mode=TwoWay}"
|
||||
Expression="{x:Bind Expression, Mode=OneWay}"
|
||||
HorizontalAsymptotes="{x:Bind HorizontalAsymptotes, Mode=TwoWay}"
|
||||
InflectionPoints="{x:Bind InflectionPoints, Mode=TwoWay}"
|
||||
IsAnalysisUpdated="{x:Bind IsAnalysisUpdated, Mode=TwoWay}"
|
||||
LineColor="{x:Bind LineColor, Mode=OneWay}"
|
||||
Maxima="{x:Bind Maxima, Mode=TwoWay}"
|
||||
Minima="{x:Bind Minima, Mode=TwoWay}"
|
||||
Monotonicity="{x:Bind Monotonicity, Mode=TwoWay}"
|
||||
ObliqueAsymptotes="{x:Bind ObliqueAsymptotes, Mode=TwoWay}"
|
||||
Parity="{x:Bind Parity, Mode=TwoWay}"
|
||||
PeriodicityDirection="{x:Bind PeriodicityDirection, Mode=TwoWay}"
|
||||
PeriodicityExpression="{x:Bind PeriodicityExpression, Mode=TwoWay}"
|
||||
Range="{x:Bind Range, Mode=TwoWay}"
|
||||
TooComplexFeatures="{x:Bind TooComplexFeatures, Mode=TwoWay}"
|
||||
VerticalAsymptotes="{x:Bind VerticalAsymptotes, Mode=TwoWay}"
|
||||
XIntercept="{x:Bind XIntercept, Mode=TwoWay}"
|
||||
YIntercept="{x:Bind YIntercept, Mode=TwoWay}"/>
|
||||
</DataTemplate>
|
||||
</graphControl:Grapher.EquationTemplate>
|
||||
|
||||
</graphControl:Grapher>
|
||||
|
||||
<StackPanel Grid.Row="0"
|
||||
@@ -525,7 +500,7 @@
|
||||
Margin="0,4,0,0"
|
||||
Visibility="{x:Bind IsKeyGraphFeaturesVisible, Converter={StaticResource BooleanToVisibilityNegationConverter}, Mode=OneWay}"
|
||||
Equations="{x:Bind ViewModel.Equations}"
|
||||
KeyGraphFeaturesVisibilityChanged="OnEquationKeyGraphFeaturesVisibilityChanged"/>
|
||||
KeyGraphFeaturesRequested="OnEquationKeyGraphFeaturesRequested"/>
|
||||
|
||||
<Grid x:Name="ButtonContainerGrid"
|
||||
Grid.Row="1"
|
||||
|
@@ -77,9 +77,43 @@ void GraphingCalculator::OnShowTracePopupChanged(bool newValue)
|
||||
|
||||
void GraphingCalculator::GraphingCalculator_DataContextChanged(FrameworkElement ^ sender, DataContextChangedEventArgs ^ args)
|
||||
{
|
||||
if (ViewModel != nullptr)
|
||||
{
|
||||
if (m_vectorChangedToken.Value != 0)
|
||||
{
|
||||
ViewModel->Equations->VectorChanged -= m_vectorChangedToken;
|
||||
m_vectorChangedToken.Value = 0;
|
||||
}
|
||||
|
||||
if (m_variableUpdatedToken.Value != 0)
|
||||
{
|
||||
ViewModel->VariableUpdated -= m_variableUpdatedToken;
|
||||
m_variableUpdatedToken.Value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ViewModel = dynamic_cast<GraphingCalculatorViewModel ^>(args->NewValue);
|
||||
|
||||
ViewModel->VariableUpdated += ref new EventHandler<VariableChangedEventArgs>(this, &CalculatorApp::GraphingCalculator::OnVariableChanged);
|
||||
m_vectorChangedToken = ViewModel->Equations->VectorChanged +=
|
||||
ref new VectorChangedEventHandler<EquationViewModel ^>(this, &GraphingCalculator::OnEquationsVectorChanged);
|
||||
|
||||
m_variableUpdatedToken = ViewModel->VariableUpdated +=
|
||||
ref new EventHandler<VariableChangedEventArgs>(this, &CalculatorApp::GraphingCalculator::OnVariableChanged);
|
||||
}
|
||||
|
||||
void GraphingCalculator::OnEquationsVectorChanged(IObservableVector<EquationViewModel ^> ^ sender, IVectorChangedEventArgs ^ event)
|
||||
{
|
||||
if (event->CollectionChange != ::CollectionChange::ItemChanged)
|
||||
{
|
||||
GraphingControl->Equations->Clear();
|
||||
|
||||
for (auto equationViewModel : ViewModel->Equations)
|
||||
{
|
||||
GraphingControl->Equations->Append(equationViewModel->GraphEquation);
|
||||
}
|
||||
|
||||
GraphingControl->PlotGraph();
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingCalculator::OnTracePointChanged(Windows::Foundation::Point newPoint)
|
||||
@@ -331,8 +365,11 @@ void GraphingCalculator::GraphingControl_LosingFocus(UIElement ^ sender, LosingF
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingCalculator::OnEquationKeyGraphFeaturesVisibilityChanged(Object ^ sender, RoutedEventArgs ^ e)
|
||||
void GraphingCalculator::OnEquationKeyGraphFeaturesRequested(Object ^ sender, RoutedEventArgs ^ e)
|
||||
{
|
||||
auto equationViewModel = static_cast<EquationViewModel ^>(sender);
|
||||
GraphingControl->AnalyzeEquation(equationViewModel->GraphEquation);
|
||||
equationViewModel->PopulateKeyGraphFeatures();
|
||||
IsKeyGraphFeaturesVisible = true;
|
||||
}
|
||||
|
||||
|
@@ -34,6 +34,9 @@ namespace CalculatorApp
|
||||
void GraphingCalculator_DataContextChanged(Windows::UI::Xaml::FrameworkElement^ sender, Windows::UI::Xaml::DataContextChangedEventArgs^ args);
|
||||
|
||||
void OnVariableChanged(Platform::Object^ sender, CalculatorApp::ViewModel::VariableChangedEventArgs args);
|
||||
void OnEquationsVectorChanged(
|
||||
Windows::Foundation::Collections::IObservableVector<CalculatorApp::ViewModel::EquationViewModel ^> ^ sender,
|
||||
Windows::Foundation::Collections::IVectorChangedEventArgs ^ event);
|
||||
|
||||
void TextBoxLosingFocus(Windows::UI::Xaml::Controls::TextBox^ textbox, Windows::UI::Xaml::Input::LosingFocusEventArgs^ args);
|
||||
void TextBoxKeyDown(Windows::UI::Xaml::Controls::TextBox^ textbox, Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e);
|
||||
@@ -55,6 +58,8 @@ namespace CalculatorApp
|
||||
|
||||
private:
|
||||
Windows::Foundation::EventRegistrationToken m_dataRequestedToken;
|
||||
Windows::Foundation::EventRegistrationToken m_vectorChangedToken;
|
||||
Windows::Foundation::EventRegistrationToken m_variableUpdatedToken;
|
||||
void OnDataRequested(Windows::ApplicationModel::DataTransfer::DataTransferManager^ sender, Windows::ApplicationModel::DataTransfer::DataRequestedEventArgs^ e);
|
||||
|
||||
void TextBoxGotFocus(Windows::UI::Xaml::Controls::TextBox^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
@@ -62,7 +67,7 @@ namespace CalculatorApp
|
||||
void GraphingControl_LostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void GraphingControl_LosingFocus(Windows::UI::Xaml::UIElement ^ sender, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args);
|
||||
void GraphingControl_VariablesUpdated(Platform::Object ^ sender, Object ^ args);
|
||||
void OnEquationKeyGraphFeaturesVisibilityChanged(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void OnEquationKeyGraphFeaturesRequested(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void OnKeyGraphFeaturesClosed(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
bool ActiveTracingOn;
|
||||
};
|
||||
|
Reference in New Issue
Block a user