private static PlanElement FromRectangleSimple(ElementBaseRectangle elem, bool mouseOver) { var rect = elem.GetRectangle(); var pt = new PointCollection { rect.TopLeft, rect.TopRight, rect.BottomRight, rect.BottomLeft }; var showHint = true; if (HasProperty(elem, "ShowTooltip")) { showHint = (bool)GetProperty(elem, "ShowTooltip"); } Guid zoneUID = Guid.Empty; if (HasProperty(elem, "ZoneUID")) { zoneUID = (Guid)GetProperty(elem, "ZoneUID"); } var backgroundImage = GetBackgroundContent(elem.BackgroundImageSource, elem.ImageType, elem.Width, elem.Height); var shape = new PlanElement { Path = InternalConverter.PointsToPath(pt.ToWindowsPointCollection(), PathKind.ClosedLine), Border = InternalConverter.ConvertColor(elem.BorderColor.ToWindowsColor()), BorderMouseOver = InternalConverter.ConvertColor(Colors.Orange), Name = elem.PresentationName, Id = zoneUID == Guid.Empty ? "pe" + elem.UID : "pe" + zoneUID, Image = backgroundImage, X = elem.Left, Y = elem.Top, Hint = showHint ? GetElementHint(elem) : null, GkObject = GetGkObject(elem), BorderThickness = elem.BorderThickness, Type = ShapeTypes.Path.ToString(), HasOverlay = mouseOver, Width = elem.Width, Height = elem.Height }; var asZone = elem as IElementZone; if (asZone == null) return shape; var zone = GKManager.Zones.FirstOrDefault(z => z.UID == asZone.ZoneUID); if (zone != null) { var background = GetGKZoneStateColor(zone.State.StateClass); shape.Fill = InternalConverter.ConvertColor(background); return shape; } var zoneSkd = GKManager.SKDZones.FirstOrDefault(z => z.UID == asZone.ZoneUID); if (zoneSkd != null) { var background = GetGKSKDZoneStateColor(zoneSkd.State.StateClass); shape.Fill = InternalConverter.ConvertColor(background); return shape; } var zoneSec = GKManager.GuardZones.FirstOrDefault(z => z.UID == asZone.ZoneUID); if (zoneSec != null) { var background = GetGKGuardZoneStateColor(zoneSec.State.StateClass); shape.Fill = InternalConverter.ConvertColor(background); } return shape; }
public static PlanElement FromEllipse(ElementEllipse item) { var result = Dispatcher.CurrentDispatcher.Invoke( () => { Debug.WriteLine( "App thread is {0}, with appartment = {1}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.GetApartmentState()); return item.GetRectangle(); }); var rect = result; var pt = new PointCollection { rect.TopLeft, rect.TopRight, rect.BottomRight, rect.BottomLeft }; var shape = new PlanElement { Path = InternalConverter.PointsToPath(pt.ToWindowsPointCollection(), PathKind.Ellipse), Border = InternalConverter.ConvertColor(item.BorderColor.ToWindowsColor()), Fill = InternalConverter.ConvertColor(item.BackgroundColor.ToWindowsColor()), BorderMouseOver = InternalConverter.ConvertColor(item.BorderColor.ToWindowsColor()), FillMouseOver = InternalConverter.ConvertColor(item.BackgroundColor.ToWindowsColor()), Name = item.PresentationName, Id = "pe" + item.UID, Hint = item.ShowTooltip ? GetElementHint(item) : null, BorderThickness = item.BorderThickness, Type = ShapeTypes.Path.ToString(), HasOverlay = false }; return shape; }
public static Rect GetRectangle(PointCollection points) { double minLeft = double.MaxValue; double minTop = double.MaxValue; double maxLeft = 0; double maxTop = 0; if (points == null) points = new PointCollection(); foreach (var point in points) { if (point.X < minLeft) minLeft = point.X; if (point.Y < minTop) minTop = point.Y; if (point.X > maxLeft) maxLeft = point.X; if (point.Y > maxTop) maxTop = point.Y; } if (maxTop < minTop) minTop = maxTop; if (maxLeft < minLeft) minLeft = maxLeft; return new Rect(minLeft, minTop, maxLeft - minLeft, maxTop - minTop); }