public DIQ(byte[] asduBytes, int offset) { byte b = asduBytes[offset]; this.dpi = (DpiState)(b & 0x03);//2 bytes //skip 2 bytes this.qd = new QualityDescriptorNibble(asduBytes, offset); }
public void Initialize([NotNull] IDiagram diagram, DpiState dpiState) { _dpiState = dpiState; _diagram = diagram; Document = CreateDocument(); }
public void SetDiagram([NotNull] IDiagram diagram) { _loading = true; _diagram = diagram; _properties.Item = diagram; if (_diagram.Model != null) { _diagram.Model.ChildCreated += OnModelChildCreated; _diagram.Model.ChildRemoved += OnModelChildRemoved; var groups = _diagram.Groups?.ToArray(); var entities = _diagram.Entities?.ToArray(); _dpiState = CalculateDpiActions(diagram); _graph.Initialize(diagram, _dpiState); var doc = _graph.Doc; if (doc != null) { try { doc.StartTransaction(); if (groups?.Any() ?? false) { AddShapes(groups); } if (entities?.Any() ?? false) { var npEntities = AddShapes(entities)?.ToArray(); if (npEntities?.Any() ?? false) { // We have at least an unprocessed shape! foreach (var entity in npEntities) { GraphOnCreateIdentity(entity.AssociatedId, entity.Position); AddShape(entity); } } var links = _diagram.Links?.ToArray(); if (links != null) { foreach (var link in links) { AddLink(link); } } } if (groups?.Any() ?? false) { foreach (var group in groups) { if (group.Identity is IGroup groupIdentity) { var groupNode = GetGroup(groupIdentity); groupNode.RefreshBorder(); } } } if (_links?.Any() ?? false) { var links = _links.Values.ToArray(); foreach (var link in links) { link.UpdateRoute(); } } _graph.DocPosition = _graph.DocumentTopLeft; } finally { _loading = false; doc.FinishTransaction($"Set Diagram {diagram.Name}"); } } } else { throw new ArgumentException(Properties.Resources.DiagramNoModelError); } }
private DpiState CalculateDpiActions(IDiagram diagram) { DpiState result = DpiState.Ok; var schemaManager = new DiagramPropertySchemaManager(diagram.Model); var dpiFactor = schemaManager.GetDpiFactor(diagram); if (dpiFactor > 0f) { if (dpiFactor > Dpi.Factor.Height + 0.25) { result = DpiState.TooBig; } else if (dpiFactor < Dpi.Factor.Height - 0.25) { result = DpiState.TooSmall; } } else { schemaManager.SetDpiFactor(diagram); var links = diagram.Links?.ToArray(); if (links?.Any() ?? false) { var propertyType = schemaManager.GetLinksSchema()?.GetPropertyType("Points"); if (propertyType != null) { var totalDistanceFactor = 0.0; var count = 0; foreach (var link in links) { var property = link.GetProperty(propertyType); if (property is IPropertyArray array) { var points = array.Value?.Select(x => float.Parse(x, NumberFormatInfo.InvariantInfo)) .ToArray(); if (points?.Any() ?? false) { var source = link.DataFlow.Source; var sourceShape = diagram.Entities.FirstOrDefault(x => x.AssociatedId == source.Id); if (sourceShape != null) { var position = sourceShape.Position; var x = points[0]; var y = points[1]; var distance = Math.Sqrt(Math.Pow(position.X - x, 2) + Math.Pow(position.Y - y, 2)); totalDistanceFactor += distance / Dpi.Factor.Width; count++; } } } } if (count > 0) { var distanceFactor = totalDistanceFactor / count; if (distanceFactor < 13f) { result = DpiState.TooSmall; } else if (distanceFactor > 26f) { result = DpiState.TooBig; } } } } } return(result); }
public GraphEntity([NotNull] IEntityShape shape, DpiState dpiState) : base() { _shape = shape; _dpiState = dpiState; var identity = shape.Identity; if (identity is IEntity entity) { Initialize(Icons.Resources.ResourceManager, GetIconName(entity), entity.Name); if (_imageSize == ImageSize.Big) { if (entity.BigImage != null && Icon is GoImage icon) { icon.Image = entity.BigImage; } Icon.Size = new SizeF(64.0f, 64.0f); } else { if (entity.Image != null && Icon is GoImage icon) { icon.Image = entity.Image; } Icon.Size = new SizeF(32.0f, 32.0f); } entity.ImageChanged += OnEntityImageChanged; //InPort.ToSpot = GoObject.NoSpot; //InPort.IsValidSelfNode = false; //InPort.IsValidDuplicateLinks = false; //OutPort.FromSpot = GoObject.NoSpot; //OutPort.IsValidSelfNode = false; //OutPort.IsValidDuplicateLinks = false; Port.Size = new SizeF(15f, 15f); Icon.Resizable = false; Reshapable = false; _threatsMarker = new AssociatedThreatsMarker(entity) { Position = new PointF(Icon.Size.Width / 2.0f, Icon.Size.Height / 2.0f), }; _threatsMarker.ThreatEventClicked += OnThreatEventClicked; Add(_threatsMarker); _diagramMarker = new AssociatedDiagramMarker(entity) { Position = new PointF(16.0f * Dpi.Factor.Width, 0), }; _diagramMarker.DiagramClicked += OnDiagramClicked; Add(_diagramMarker); _warningMarker = new WarningMarker() { Position = new PointF(0.0f, 16.0f * Dpi.Factor.Height), }; Add(_warningMarker); switch (_dpiState) { case DpiState.TooSmall: Location = new PointF(_shape.Position.X * 2, _shape.Position.Y * 2); break; case DpiState.TooBig: Location = new PointF(_shape.Position.X / 2, _shape.Position.Y / 2); break; default: Location = _shape.Position; break; } Copyable = false; AddObserver(this); // ReSharper disable once SuspiciousTypeConversion.Global ((INotifyPropertyChanged)identity).PropertyChanged += OnPropertyChanged; } else { throw new ArgumentException(Properties.Resources.ShapeNotEntityError); } }
public GraphLink([NotNull] ILink link, DpiState dpiState) : this() { _dpiState = dpiState; Link = link; }