public bool Save(string fileName) { try { if (string.IsNullOrEmpty(fileName)) { return(false); } if (CircleDiagramModel == null || !CircleDiagramModel.IsCorrect()) { return(false); } if (Path.GetExtension(fileName) != ".xml") { fileName = string.Format("{0}.xml", fileName); } var xmlModel = GetXmlModel(); if (xmlModel == null) { return(false); } using (var fs = new FileStream(fileName, FileMode.Create)) { XmlProvider.WriteXmlToStream(xmlModel, fs); } return(true); } catch (Exception) { return(false); } }
public CircleDiagramRelationship GetSelectedCircleDiagramRelationship() { if (CircleDiagramModel == null || !CircleDiagramModel.IsCorrect()) { return(null); } var lvSelItem = SelectedItems.Count > 0 ? SelectedItems[0] : null; return(lvSelItem != null ? CircleDiagramModel.FindRelationshipByName(lvSelItem.Name) : null); }
public void UpdateGroups() { if (CircleDiagramModel == null || !CircleDiagramModel.IsCorrect()) { return; } Groups.Clear(); Groups.Add(Consts.NoneGroup, Consts.NoneGroupText); for (var groupKey = 0; groupKey < CircleDiagramModel.CountLevels; groupKey++) { Groups.Add(groupKey.ToString(), string.Format(Consts.GroupTextFormat, groupKey)); } foreach (ListViewItem curItem in Items) { var curModelNode = CircleDiagramModel.FindNodeByName(curItem.Name); if (curModelNode == null) { continue; } curItem.Group = Groups[curModelNode.StartCircleNumber.ToString()] ?? Groups[Consts.NoneGroup]; } }
public static void SetMainPropertiesToCircleDiagramModel( this CircleDiagramMainProperies mainPropeties, CircleDiagramModel model) { if (model == null || !model.IsCorrect() || mainPropeties == null) { return; } model.ChangeParametersValues(mainPropeties.CountLevels, new SolidBrush(mainPropeties.MainBackgroundColor), new SolidBrush(mainPropeties.RingBackgroundColor), new SolidBrush(mainPropeties.IntervalBackgroundColor), new Pen(mainPropeties.NodeBorderColor, mainPropeties.NodeBorderThickness), new Pen(mainPropeties.RingBorderColor, mainPropeties.RingBorderThickness), new Pen(mainPropeties.RelationshipPenColor, mainPropeties.RelationshipPenThickness), new SolidBrush(mainPropeties.NumerationColor), mainPropeties.NumerationFont, mainPropeties.NumerationBeginNumber, mainPropeties.NumerationIsInverted); }
public static void GetMainPropertiesFromCircleDiagramModel( this CircleDiagramMainProperies mainProperties, CircleDiagramModel model) { if (model == null || !model.IsCorrect() || mainProperties == null) { return; } mainProperties.CountLevels = model.CountLevels; mainProperties.MainBackgroundColor = SerializeUtils.BrushToColor(model.MainBackground); mainProperties.RingBackgroundColor = SerializeUtils.BrushToColor(model.RingBackground); mainProperties.IntervalBackgroundColor = SerializeUtils.BrushToColor(model.IntervalBackground); mainProperties.NodeBorderColor = model.NodeBorder.Color; mainProperties.NodeBorderThickness = model.NodeBorder.Width; mainProperties.RingBorderColor = model.RingBorder.Color; mainProperties.RingBorderThickness = model.RingBorder.Width; mainProperties.RelationshipPenColor = model.RelationshipPen.Color; mainProperties.RelationshipPenThickness = model.RelationshipPen.Width; mainProperties.NumerationColor = SerializeUtils.BrushToColor(model.NumerationBrush); mainProperties.NumerationFont = model.NumerationFont; mainProperties.NumerationBeginNumber = model.NumerationBeginNumber; mainProperties.NumerationIsInverted = model.NumerationIsInverted; }
private void UpdateNodeAfterEditing() { if (CircleDiagramModel == null || !CircleDiagramModel.IsCorrect()) { return; } var targetNode = CircleDiagramModel.FindNodeByName(NodePropeties.Name); if (targetNode == null) { return; } NodePropeties.SetNodePropertiesToCircleDiagramNode(targetNode); var targetItem = lvNodes.Items[targetNode.Name]; if (targetItem == null) { return; } targetItem.Text = targetNode.Text.Replace("\r\n", " "); var group = lvNodes.Groups[targetNode.StartCircleNumber.ToString()]; if (group != null) { targetItem.Group = group; } else { var noneGroup = lvNodes.Groups[Consts.NoneGroup]; if (noneGroup != null) { targetItem.Group = noneGroup; } } RedrawDiagramOnControl(); }
public CircleDiagramInputOutputMachine(CircleDiagramModel circleDiagramModel) { CircleDiagramModel = circleDiagramModel != null && circleDiagramModel.IsCorrect() ? circleDiagramModel : null; }
public void RedrawDiagram(Graphics graphics, Color emptyAreasColor) { if (graphics == null || CircleDiagramModel == null || !CircleDiagramModel.IsCorrect()) { return; } var width = graphics.VisibleClipBounds.Width; var height = graphics.VisibleClipBounds.Height; if (width == 0 || height == 0) { return; } SquareCanvasLength = width <= height ? width : height; DiagramAreaLength = SquareCanvasLength - SquareIndent; PercentageScale = DiagramAreaLength / DefaultSquareCanvasLength; if (PercentageScale <= 0) { PercentageScale = 1; } MapLayer = new Bitmap( (int)(DiagramAreaLength + SquareIndent), (int)(DiagramAreaLength + SquareIndent)); UpdateMap(); NodesLayer = new Bitmap( (int)(DiagramAreaLength + SquareIndent), (int)(DiagramAreaLength + SquareIndent)); UpdateNodes(); RelationshipsLayer = new Bitmap( (int)(DiagramAreaLength + SquareIndent), (int)(DiagramAreaLength + SquareIndent)); UpdateRelationships(); MainLayer = new Bitmap((int)SquareCanvasLength, (int)SquareCanvasLength); var mainGraphics = Graphics.FromImage(MainLayer); mainGraphics.DrawImage(MapLayer, new PointF(0, 0)); mainGraphics.DrawImage(NodesLayer, new PointF(0, 0)); mainGraphics.DrawImage(RelationshipsLayer, new PointF(0, 0)); graphics.Clear(emptyAreasColor); var dX = width / 2; var dY = height / 2; graphics.TranslateTransform(dX, dY); graphics.DrawImage(MainLayer, new PointF(-SquareCanvasLength / 2, -SquareCanvasLength / 2)); //var grPath = new GraphicsPath(); //grPath.AddLine(new PointF(-250, -250), new PointF(-250, -50)); //grPath.AddLine(new PointF(-250, -50), new PointF(-50, -50)); //grPath.AddLine(new PointF(-50, -50), new PointF(-250, -250)); //var grBrush = new PathGradientBrush(grPath); //grBrush.CenterColor = Color.Black; //grBrush.SurroundColors = new [] { Color.Empty }; //graphics.FillPath(grBrush, grPath); }