// Copyright (C) Stichting Deltares 2016. All rights reserved.
//
// This file is part of Ringtoets.
//
// Ringtoets is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see .
//
// All names, logos, and references to "Deltares" are registered trademarks of
// Stichting Deltares and remain full property of Stichting Deltares at all times.
// All rights reserved.
using System.Collections.Generic;
using Core.Common.Gui;
using Core.Common.Gui.Forms;
using Core.Common.Gui.Forms.ViewManager;
using Core.Common.Gui.Plugin;
using Core.Components.Charting.Data;
using Core.Plugins.OxyPlot.Commands;
using Core.Plugins.OxyPlot.Forms;
using Core.Plugins.OxyPlot.Legend;
using Core.Plugins.OxyPlot.Properties;
namespace Core.Plugins.OxyPlot
{
///
/// This class ties all the components together to enable charting interaction.
///
public class OxyPlotGuiPlugin : GuiPlugin
{
private ChartingRibbon chartingRibbon;
private LegendController legendController;
private bool activated;
public override IRibbonCommandHandler RibbonCommandHandler
{
get
{
return chartingRibbon;
}
}
public override void Activate()
{
legendController = CreateLegendController(Gui);
chartingRibbon = CreateRibbon(legendController, Gui);
legendController.ToggleLegend();
Gui.ActiveViewChanged += GuiOnActiveViewChanged;
activated = true;
}
public override IEnumerable GetViewInfos()
{
yield return new ViewInfo
{
Image = Resources.ChartIcon,
GetViewName = (v, o) => "Diagram"
};
}
public override void Dispose()
{
if (activated)
{
Gui.ActiveViewChanged -= GuiOnActiveViewChanged;
}
base.Dispose();
}
///
/// Creates a new .
///
/// The to use for the controller
/// .
/// A new instance.
private LegendController CreateLegendController(IToolViewController toolViewController)
{
var controller = new LegendController(toolViewController);
controller.OnOpenLegend += (s,e) => UpdateComponentsForActiveView();
return controller;
}
///
/// Creates the and the commands that will be used when clicking on the buttons.
///
/// The to use for the
/// .
/// The controller for Document Views.
/// A new instance.
private static ChartingRibbon CreateRibbon(LegendController legendController, IDocumentViewController documentViewController)
{
return new ChartingRibbon
{
ToggleLegendViewCommand = new ToggleLegendViewCommand(legendController)
};
}
private void GuiOnActiveViewChanged(object sender, ActiveViewChangeEventArgs activeViewChangeEventArgs)
{
UpdateComponentsForActiveView();
}
///
/// Updates the components which the knows about so that it reflects
/// the currently active view.
///
private void UpdateComponentsForActiveView()
{
var chartView = Gui.ActiveView as IChartView;
if (chartView != null)
{
chartingRibbon.Chart = chartView.Chart;
legendController.Update(chartView.Chart.Data);
}
else
{
chartingRibbon.Chart = null;
legendController.Update(null);
}
}
}
}