using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Msagl.Core.DataStructures;
using Microsoft.Msagl.Core.Geometry;
using Microsoft.Msagl.Core.Geometry.Curves;
using Microsoft.Msagl.Core.Layout;
using Microsoft.Msagl.Core.Routing;
namespace Microsoft.Msagl.Layout.LargeGraphLayout
{
///
/// layout settings to handle a large graph
///
public class LgLayoutSettings : LayoutAlgorithmSettings
{
public int maximumNumOfLayers;
public double mainGeometryGraphWidth;
public double mainGeometryGraphHeight;
public GeometryGraph lgGeometryGraph;
public bool hugeGraph;
public bool flow;
public int delta;
internal readonly Func TransformFromGraphToScreen;
internal readonly double DpiX;
internal readonly double DpiY;
///
/// size of drawn node
///
//public double NodeDotWidthInInches = 0.1;
public double NodeDotWidthInInches = 0.08; //jyoti made it small
public double NodeDotWidthInInchesMinInImage = 0.06;
//public double NodeLabelHeightInInches = 0.22;
public double NodeLabelHeightInInches = 0.14; //jyoti made it small
///
/// Func giving the maximal arrowhead length for the current viewport
///
public readonly Func MaximalArrowheadLength;
///
/// delegate to be called by LgInteractor on a graph change
///
public delegate void LgLayoutEvent();
///
/// event handler to be raised when the graph and its transform change
///
public event LgLayoutEvent ViewerChangeTransformAndInvalidateGraph;
///
///
///
public void OnViewerChangeTransformAndInvalidateGraph()
{
if (ViewerChangeTransformAndInvalidateGraph != null)
ViewerChangeTransformAndInvalidateGraph();
}
///
/// this graph is shown in the viewer
///
public RailGraph RailGraph
{
get { return Interactor != null ? Interactor.RailGraph : null; }
}
///
/// clones the object
///
///
public override LayoutAlgorithmSettings Clone()
{
return (LayoutAlgorithmSettings)MemberwiseClone();
}
///
/// the algorithm object
///
public LgInteractor Interactor { get; set; }
///
/// a delegate returning the current viewport of the viewer
///
internal Func ClientViewportFunc { get; set; }
///
/// constructor
///
///
///
///
///
/// the dynamic length of the arrowhead
public LgLayoutSettings(Func clientViewportFunc,
Func transformFromGraphToScreen,
double dpiX, double dpiY,
Func maximalArrowheadLength
)
{
ClientViewportFunc = clientViewportFunc;
TransformFromGraphToScreen = transformFromGraphToScreen;
DpiX = dpiX;
DpiY = dpiY;
MaximalArrowheadLength = maximalArrowheadLength;
EdgeRoutingSettings.Padding = NodeSeparation / 4;
EdgeRoutingSettings.PolylinePadding = NodeSeparation / 6;
InitDefaultRailColors();
InitDefaultSelectionColors();
}
public Func ClientViewportMappedToGraph { get; set; }
Dictionary geometryNodesToLgNodeInfos = new Dictionary();
///
/// the mapping from Geometry nodes to LgNodes
///
public Dictionary GeometryNodesToLgNodeInfos
{
get { return geometryNodesToLgNodeInfos; }
set { geometryNodesToLgNodeInfos = value; }
}
///
///
///
public IDictionary GeometryEdgesToLgEdgeInfos
{
get { return Interactor.GeometryEdgesToLgEdgeInfos; }
}
///
///
///
Interval _scaleInterval = new Interval(0.00001, 100000000.0);
bool needToLayout = true;
int maxNumberOfNodesPerTile = 20;
///
/// used for debugging mostly
///
public bool ExitAfterInit;
///
/// the range of scale
///
public Interval ScaleInterval
{
get { return _scaleInterval; }
set { _scaleInterval = value; }
}
///
/// set this property to true if the graph comes with a given layout
///
public bool NeedToLayout
{
get { return needToLayout; }
set { needToLayout = value; }
}
///
/// the node quota per tile
///
public int MaxNumberOfNodesPerTile
{
get { return maxNumberOfNodesPerTile; }
set { maxNumberOfNodesPerTile = value; }
}
private double increaseNodeQuota;
public double IncreaseNodeQuota
{
get { return increaseNodeQuota; }
set { increaseNodeQuota = value; }
}
int maxNumberOfRailsPerTile = 300;
public int MaxNumberOfRailsPerTile
{
get { return maxNumberOfRailsPerTile; }
set { maxNumberOfRailsPerTile = value; }
}
///
///
///
///
public double GetMaximalZoomLevel()
{
return Interactor.GetMaximalZoomLevel();
}
bool _simplifyRoutes = true;
private int _numberOfNodeShapeSegs = 12; //16;
public bool SimplifyRoutes
{
get { return _simplifyRoutes; }
set { _simplifyRoutes = value; }
}
public int NumberOfNodeShapeSegs
{
get { return _numberOfNodeShapeSegs; }
set { _numberOfNodeShapeSegs = value; }
}
public bool GenerateTiles
{
get { return _generateTiles; }
set { _generateTiles = value; }
}
bool _generateTiles = true;
private String[] _railColors;
public String[] RailColors
{
get { return _railColors; }
set { _railColors = value; }
}
private String[] _selectionColors;
public string[] SelectionColors
{
get { return _selectionColors; }
set { _selectionColors = value; }
}
private void InitDefaultRailColors()
{
_railColors = new String[3];
_railColors[0] = "#87CEFA";
_railColors[1] = "#FAFAD2";
_railColors[2] = "#FAFAD2";
//jyoti changed colors
//_railColors[0] = "#87CEFA";
//_railColors[1] = "#FAFAD2";
//_railColors[2] = "#F5F5F5";
}
private void InitDefaultSelectionColors()
{
// init red selection
_selectionColors = new String[3];
_selectionColors[0] = "#E60000";
_selectionColors[1] = "#E60000";
_selectionColors[2] = "#E60000";
//jyoti changed colors
//_selectionColors[0] = "#FF0000";
//_selectionColors[1] = "#EB3044";
//_selectionColors[2] = "#E55C7F";
//orange: #FF6A00,#FF9047,FFB07F
}
public String GetColorForZoomLevel(double zoomLevel)
{
int logZoomLevel = (int)Math.Log(zoomLevel, 2.0);
logZoomLevel = Math.Min(logZoomLevel, RailColors.Count() - 1);
logZoomLevel = Math.Max(logZoomLevel, 0);
return RailColors[logZoomLevel];
}
public String GetSelColorForZoomLevel(double zoomLevel)
{
int logZoomLevel = (int)Math.Log(zoomLevel, 2.0);
logZoomLevel = Math.Min(logZoomLevel, SelectionColors.Count() - 1);
logZoomLevel = Math.Max(logZoomLevel, 0);
return SelectionColors[logZoomLevel];
}
public String GetNodeSelColor()
{
return SelectionColors[0];
}
}
}