+ Fixed GraphArea::DeserializeFromFile() logic and filestorage logic to properly restore internal data for loaded graphs

This commit is contained in:
Alexander Smirnov 2015-03-05 01:04:58 +03:00
Родитель 32b13b02e4
Коммит d982bc4857
7 изменённых файлов: 87 добавлений и 34 удалений

Просмотреть файл

@ -7,6 +7,7 @@
+ Fixed ZoomControl unresponsivness after startup (prev needed to change zoom/translation first to work fine) [WPF,METRO]
+ Fixed ZoomControl::Zoom property bug on empty content window resize [WPF, METRO]
+ Fixed dynamic graph showcase example first vertex auto zooming onto [WPF]
+ Fixed GraphArea::DeserializeFromFile() logic and filestorage logic to properly restore internal data for loaded graphs
+ Optimized showcase app media files
!Breaking changes

Просмотреть файл

@ -39,6 +39,7 @@ namespace ShowcaseApp.WPF.Pages
gg_Area.GenerateGraphFinished += gg_Area_GenerateGraphFinished;
ggLogic.DefaultEdgeRoutingAlgorithm = EdgeRoutingAlgorithmTypeEnum.SimpleER;
ggLogic.EdgeCurvingEnabled = true;
ZoomControl.SetViewFinderVisibility(gg_zoomctrl, Visibility.Visible);
@ -134,7 +135,7 @@ namespace ShowcaseApp.WPF.Pages
try
{
gg_Area.DeserializeFromFile(dlg.FileName);
gg_Area.SetVerticesDrag(true);
gg_Area.SetVerticesDrag(true, true);
gg_Area.UpdateAllEdges();
gg_zoomctrl.ZoomToFill();
}

Просмотреть файл

@ -25,13 +25,25 @@ namespace GraphX
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source",
typeof(VertexControl),
typeof(EdgeControl),
new UIPropertyMetadata(null));
new UIPropertyMetadata(null, OnSourceChanged));
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue == null) return;
((EdgeControl)d).ActivateSourceListener();
}
public static readonly DependencyProperty TargetProperty = DependencyProperty.Register("Target",
typeof(VertexControl),
typeof(EdgeControl),
new UIPropertyMetadata(null));
new UIPropertyMetadata(null, OnTargetChanged));
private static void OnTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue == null) return;
((EdgeControl)d).ActivateTargetListener();
}
public static readonly DependencyProperty EdgeProperty = DependencyProperty.Register("Edge", typeof(object),
typeof(EdgeControl),
@ -325,22 +337,9 @@ namespace GraphX
foreach (var item in Enum.GetValues(typeof (EventType)).Cast<EventType>())
UpdateEventhandling(item);
if (source != null)
{
_sourceTrace = source.EventOptions.PositionChangeNotification;
source.EventOptions.PositionChangeNotification = true;
source.PositionChanged += source_PositionChanged;
_sourceListener = new PropertyChangeNotifier(this, SourceProperty);
_sourceListener.ValueChanged += SourceChanged;
}
if (target != null)
{
_targetTrace = target.EventOptions.PositionChangeNotification;
target.EventOptions.PositionChangeNotification = true;
target.PositionChanged += source_PositionChanged;
_targetListener = new PropertyChangeNotifier(this, TargetProperty);
_targetListener.ValueChanged += TargetChanged;
}
ActivateSourceListener();
ActivateTargetListener();
}
/*var dpd = DependencyPropertyDescriptor.FromProperty(SourceProperty, typeof(EdgeControl));
if (dpd != null) dpd.AddValueChanged(this, SourceChanged);
@ -350,6 +349,35 @@ namespace GraphX
IsSelfLooped = _isSelfLooped;
}
private void ActivateSourceListener()
{
if (Source != null && !_posTracersActivatedS)
{
_sourceTrace = Source.EventOptions.PositionChangeNotification;
Source.EventOptions.PositionChangeNotification = true;
Source.PositionChanged += source_PositionChanged;
_sourceListener = new PropertyChangeNotifier(this, SourceProperty);
_sourceListener.ValueChanged += SourceChanged;
_posTracersActivatedS = true;
}
}
private void ActivateTargetListener()
{
if (Target != null && !_posTracersActivatedT)
{
_targetTrace = Target.EventOptions.PositionChangeNotification;
Target.EventOptions.PositionChangeNotification = true;
Target.PositionChanged += source_PositionChanged;
_targetListener = new PropertyChangeNotifier(this, TargetProperty);
_targetListener.ValueChanged += TargetChanged;
_posTracersActivatedT = true;
}
}
private bool _posTracersActivatedS;
private bool _posTracersActivatedT;
static EdgeControl()
{
//override the StyleKey

Просмотреть файл

@ -19,6 +19,7 @@ using System.Windows.Threading;
using Microsoft.Win32;
using System.Windows.Controls;
using GraphX.Controls.Enums;
using GraphX.Logic.Models;
using Point = System.Windows.Point;
using Size = System.Windows.Size;
@ -1367,6 +1368,7 @@ namespace GraphX
RemoveAllEdges();
RemoveAllVertices();
var data = LogicCore.FileServiceProvider.DeserializeDataFromFile(filename);
if (LogicCore.Graph == null) LogicCore.Graph = Activator.CreateInstance<TGraph>();
@ -1404,6 +1406,21 @@ namespace GraphX
UpdateLayout();
foreach (var item in EdgesList.Values)
item.OnApplyTemplate();
RestoreAlgorithmStorage();
}
private void RestoreAlgorithmStorage()
{
//if (LogicCore.AlgorithmStorage.Layout == null)
// {
var vPositions = GetVertexPositions();
var vSizeRectangles = GetVertexSizeRectangles();
var lay = LogicCore.GenerateLayoutAlgorithm(GetVertexSizes());
var or = LogicCore.GenerateOverlapRemovalAlgorithm(vSizeRectangles);
var er = LogicCore.GenerateEdgeRoutingAlgorithm(DesiredSize.ToGraphX(), vPositions, vSizeRectangles);
LogicCore.CreateNewAlgorithmStorage(lay, or, er);
// }
}
#endregion

Просмотреть файл

@ -1366,6 +1366,19 @@ namespace GraphX
//TODO
//foreach (var item in EdgesList.Values)
// item.OnApplyTemplate();
RestoreAlgorithmStorage();
}
private void RestoreAlgorithmStorage()
{
var vPositions = GetVertexPositions();
var vSizeRectangles = GetVertexSizeRectangles();
var lay = LogicCore.GenerateLayoutAlgorithm(GetVertexSizes());
var or = LogicCore.GenerateOverlapRemovalAlgorithm(vSizeRectangles);
var er = LogicCore.GenerateEdgeRoutingAlgorithm(DesiredSize.ToGraphX(), vPositions, vSizeRectangles);
LogicCore.CreateNewAlgorithmStorage(lay, or, er);
}
#endregion

Просмотреть файл

@ -49,7 +49,7 @@ namespace GraphX
bool AreOverlapNeeded();
IExternalLayout<TVertex> GenerateLayoutAlgorithm(Dictionary<TVertex, Size> vertexSizes);
IExternalOverlapRemoval<TVertex> GenerateOverlapRemovalAlgorithm(Dictionary<TVertex, Rect> rectangles = null);
IExternalEdgeRouting<TVertex, TEdge> GenerateEdgeRoutingAlgorithm(Size DesiredSize);
IExternalEdgeRouting<TVertex, TEdge> GenerateEdgeRoutingAlgorithm(Size desiredSize, IDictionary<TVertex, Point> positions = null, IDictionary<TVertex, Rect> rectangles = null);
}
}

Просмотреть файл

@ -41,26 +41,19 @@ namespace GraphX.Logic
public IExternalLayout<TVertex> GenerateLayoutAlgorithm(Dictionary<TVertex, Size> vertexSizes)
{
if (ExternalLayoutAlgorithm != null)
{
var alg = ExternalLayoutAlgorithm;
if (alg.NeedVertexSizes) alg.VertexSizes = vertexSizes;
return alg;
}
else return AlgorithmFactory.CreateLayoutAlgorithm(DefaultLayoutAlgorithm, Graph, null, vertexSizes, DefaultLayoutAlgorithmParams);
if (ExternalLayoutAlgorithm == null) return AlgorithmFactory.CreateLayoutAlgorithm(DefaultLayoutAlgorithm, Graph, null, vertexSizes, DefaultLayoutAlgorithmParams);
var alg = ExternalLayoutAlgorithm;
if (alg.NeedVertexSizes) alg.VertexSizes = vertexSizes;
return alg;
}
public IExternalEdgeRouting<TVertex, TEdge> GenerateEdgeRoutingAlgorithm(Size DesiredSize)
public IExternalEdgeRouting<TVertex, TEdge> GenerateEdgeRoutingAlgorithm(Size desiredSize, IDictionary<TVertex, Point> positions = null, IDictionary<TVertex, Rect> rectangles = null)
{
if (ExternalEdgeRoutingAlgorithm == null && DefaultEdgeRoutingAlgorithm != EdgeRoutingAlgorithmTypeEnum.None)
{
return AlgorithmFactory.CreateEdgeRoutingAlgorithm(DefaultEdgeRoutingAlgorithm, new Rect(DesiredSize), Graph, null, null, DefaultEdgeRoutingAlgorithmParams);
return AlgorithmFactory.CreateEdgeRoutingAlgorithm(DefaultEdgeRoutingAlgorithm, new Rect(desiredSize), Graph, positions, rectangles, DefaultEdgeRoutingAlgorithmParams);
}
else if (ExternalEdgeRoutingAlgorithm != null)
{
return ExternalEdgeRoutingAlgorithm;
}
else return null;
return ExternalEdgeRoutingAlgorithm;
}
}
}