diff --git a/AIStudio.Wpf.DiagramApp/ViewModels/LogicalViewModel.cs b/AIStudio.Wpf.DiagramApp/ViewModels/LogicalViewModel.cs index 83581e2..3514f1f 100644 --- a/AIStudio.Wpf.DiagramApp/ViewModels/LogicalViewModel.cs +++ b/AIStudio.Wpf.DiagramApp/ViewModels/LogicalViewModel.cs @@ -206,7 +206,7 @@ namespace AIStudio.Wpf.Logical if (connector.SourceConnectorInfo.DataItem is LogicalGateItemViewModelBase) { - input.Value.ConnectorValue = connector.SourceConnectorInfo.ConnectorValue; + input.Value.ConnectorValue = (connector.SourceConnectorInfo as LogicalConnectorInfo).ConnectorValue; input.Value.ColorViewModel.FillColor.Color = connector.SourceConnectorInfo.ColorViewModel.FillColor.Color; connector.ColorViewModel.LineColor.Color = connector.SourceConnectorInfo.ColorViewModel.FillColor.Color; diff --git a/AIStudio.Wpf.DiagramDesigner.Additionals/Controls/WPFRuler.cs b/AIStudio.Wpf.DiagramDesigner.Additionals/Controls/WPFRuler.cs index 8b31857..c88b406 100644 --- a/AIStudio.Wpf.DiagramDesigner.Additionals/Controls/WPFRuler.cs +++ b/AIStudio.Wpf.DiagramDesigner.Additionals/Controls/WPFRuler.cs @@ -59,7 +59,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls { if (this.AutoSize) { - return (double)(Unit == Unit.Cm ? DipHelper.DipToCm(this.ActualWidth) : DipHelper.DipToInch(this.ActualWidth)) / this.Zoom; + return (double)(Unit == Unit.Cm ? ScreenHelper.WidthToCm(this.ActualWidth) : ScreenHelper.WidthToInch(this.ActualWidth)) / this.Zoom; } else { @@ -255,9 +255,9 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls var rect = new Rect(0, 0, RenderSize.Width, RenderSize.Height); drawingContext.DrawRectangle(Background, null, rect); - double xDest = (Unit == Unit.Cm ? DipHelper.CmToDip(Length) : DipHelper.InchToDip(Length)) * this.Zoom; + double xDest = (Unit == Unit.Cm ? ScreenHelper.CmToWidth(Length) : ScreenHelper.InchToWidth(Length)) * this.Zoom; drawingContext.DrawRectangle(null, BorderPen, new Rect(new Point(0.0, 0.0), new Point(xDest, Height))); - double chip = Unit == Unit.Cm ? DipHelper.CmToDip(Chip) : DipHelper.InchToDip(Chip); + double chip = Unit == Unit.Cm ? ScreenHelper.CmToWidth(Chip) : ScreenHelper.InchToWidth(Chip); drawingContext.DrawLine(RedPen, new Point(chip, 0), new Point(chip, Height)); //画偏移位置之前的 @@ -268,21 +268,21 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls double d; if (Unit == Unit.Cm) { - d = DipHelper.CmToDip(dUnit) * this.Zoom; + d = ScreenHelper.CmToWidth(dUnit) * this.Zoom; if (dUnit < Length) { for (int i = 1; i <= 9; i++) { if (i != 5) { - double dMm = DipHelper.CmToDip(dUnit + 0.1 * i) * this.Zoom; + double dMm = ScreenHelper.CmToWidth(dUnit + 0.1 * i) * this.Zoom; if (Marks == MarksLocation.Up) drawingContext.DrawLine(ThinPen, new Point(dMm, 0), new Point(dMm, SegmentHeight / 3.0)); else drawingContext.DrawLine(ThinPen, new Point(dMm, Height), new Point(dMm, Height - SegmentHeight / 3.0)); } } - double dMiddle = DipHelper.CmToDip(dUnit + 0.5) * this.Zoom; + double dMiddle = ScreenHelper.CmToWidth(dUnit + 0.5) * this.Zoom; if (Marks == MarksLocation.Up) drawingContext.DrawLine(p, new Point(dMiddle, 0), new Point(dMiddle, SegmentHeight * 2.0 / 3.0)); else @@ -291,30 +291,30 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls } else { - d = DipHelper.InchToDip(dUnit) * this.Zoom; + d = ScreenHelper.InchToWidth(dUnit) * this.Zoom; if (dUnit < Length) { if (Marks == MarksLocation.Up) { - double dQuarter = DipHelper.InchToDip(dUnit + 0.25) * this.Zoom; + double dQuarter = ScreenHelper.InchToWidth(dUnit + 0.25) * this.Zoom; drawingContext.DrawLine(ThinPen, new Point(dQuarter, 0), new Point(dQuarter, SegmentHeight / 3.0)); - double dMiddle = DipHelper.InchToDip(dUnit + 0.5) * this.Zoom; + double dMiddle = ScreenHelper.InchToWidth(dUnit + 0.5) * this.Zoom; drawingContext.DrawLine(p, new Point(dMiddle, 0), new Point(dMiddle, SegmentHeight * 2D / 3D)); - double d3Quarter = DipHelper.InchToDip(dUnit + 0.75) * this.Zoom; + double d3Quarter = ScreenHelper.InchToWidth(dUnit + 0.75) * this.Zoom; drawingContext.DrawLine(ThinPen, new Point(d3Quarter, 0), new Point(d3Quarter, SegmentHeight / 3.0)); } else { - double dQuarter = DipHelper.InchToDip(dUnit + 0.25) * this.Zoom; + double dQuarter = ScreenHelper.InchToWidth(dUnit + 0.25) * this.Zoom; drawingContext.DrawLine(ThinPen, new Point(dQuarter, Height), new Point(dQuarter, Height - SegmentHeight / 3.0)); - double dMiddle = DipHelper.InchToDip(dUnit + 0.5) * this.Zoom; + double dMiddle = ScreenHelper.InchToWidth(dUnit + 0.5) * this.Zoom; drawingContext.DrawLine(p, new Point(dMiddle, Height), new Point(dMiddle, Height - SegmentHeight * 2D / 3D)); - double d3Quarter = DipHelper.InchToDip(dUnit + 0.75) * this.Zoom; + double d3Quarter = ScreenHelper.InchToWidth(dUnit + 0.75) * this.Zoom; drawingContext.DrawLine(ThinPen, new Point(d3Quarter, Height), new Point(d3Quarter, Height - SegmentHeight / 3.0)); } @@ -333,7 +333,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), - DipHelper.PtToDip(6), + 9, Brushes.DimGray); ft.SetFontWeight(FontWeights.Regular); ft.TextAlignment = TextAlignment.Center; @@ -353,21 +353,21 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls double d; if (Unit == Unit.Cm) { - d = DipHelper.CmToDip(dUnit) * this.Zoom; + d = ScreenHelper.CmToWidth(dUnit) * this.Zoom; if (dUnit < Length) { for (int i = 1; i <= 9; i++) { if (i != 5) { - double dMm = DipHelper.CmToDip(dUnit + 0.1 * i) * this.Zoom; + double dMm = ScreenHelper.CmToWidth(dUnit + 0.1 * i) * this.Zoom; if (Marks == MarksLocation.Up) drawingContext.DrawLine(ThinPen, new Point(dMm, 0), new Point(dMm, SegmentHeight / 3.0)); else drawingContext.DrawLine(ThinPen, new Point(dMm, Height), new Point(dMm, Height - SegmentHeight / 3.0)); } } - double dMiddle = DipHelper.CmToDip(dUnit + 0.5) * this.Zoom; + double dMiddle = ScreenHelper.CmToWidth(dUnit + 0.5) * this.Zoom; if (Marks == MarksLocation.Up) drawingContext.DrawLine(p, new Point(dMiddle, 0), new Point(dMiddle, SegmentHeight * 2.0 / 3.0)); else @@ -376,30 +376,30 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls } else { - d = DipHelper.InchToDip(dUnit) * this.Zoom; + d = ScreenHelper.InchToWidth(dUnit) * this.Zoom; if (dUnit < Length) { if (Marks == MarksLocation.Up) { - double dQuarter = DipHelper.InchToDip(dUnit + 0.25) * this.Zoom; + double dQuarter = ScreenHelper.InchToWidth(dUnit + 0.25) * this.Zoom; drawingContext.DrawLine(ThinPen, new Point(dQuarter, 0), new Point(dQuarter, SegmentHeight / 3.0)); - double dMiddle = DipHelper.InchToDip(dUnit + 0.5) * this.Zoom; + double dMiddle = ScreenHelper.InchToWidth(dUnit + 0.5) * this.Zoom; drawingContext.DrawLine(p, new Point(dMiddle, 0), new Point(dMiddle, SegmentHeight * 2D / 3D)); - double d3Quarter = DipHelper.InchToDip(dUnit + 0.75) * this.Zoom; + double d3Quarter = ScreenHelper.InchToWidth(dUnit + 0.75) * this.Zoom; drawingContext.DrawLine(ThinPen, new Point(d3Quarter, 0), new Point(d3Quarter, SegmentHeight / 3.0)); } else { - double dQuarter = DipHelper.InchToDip(dUnit + 0.25) * this.Zoom; + double dQuarter = ScreenHelper.InchToWidth(dUnit + 0.25) * this.Zoom; drawingContext.DrawLine(ThinPen, new Point(dQuarter, Height), new Point(dQuarter, Height - SegmentHeight / 3.0)); - double dMiddle = DipHelper.InchToDip(dUnit + 0.5) * this.Zoom; + double dMiddle = ScreenHelper.InchToWidth(dUnit + 0.5) * this.Zoom; drawingContext.DrawLine(p, new Point(dMiddle, Height), new Point(dMiddle, Height - SegmentHeight * 2D / 3D)); - double d3Quarter = DipHelper.InchToDip(dUnit + 0.75) * this.Zoom; + double d3Quarter = ScreenHelper.InchToWidth(dUnit + 0.75) * this.Zoom; drawingContext.DrawLine(ThinPen, new Point(d3Quarter, Height), new Point(d3Quarter, Height - SegmentHeight / 3.0)); } @@ -418,7 +418,7 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Arial"), - DipHelper.PtToDip(6), + 9, Brushes.DimGray); ft.SetFontWeight(FontWeights.Regular); ft.TextAlignment = TextAlignment.Center; @@ -442,11 +442,11 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls //Size desiredSize; //if (Unit == Unit.Cm) //{ - // desiredSize = new Size(DipHelper.CmToDip(Length), Height); + // desiredSize = new Size(ScreenHelper.CmToWidth(Length), Height); //} //else //{ - // desiredSize = new Size(DipHelper.InchToDip(Length), Height); + // desiredSize = new Size(ScreenHelper.InchToWidth(Length), Height); //} //return desiredSize; } @@ -474,145 +474,145 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Controls Up, Down } - /// - /// A helper class for DIP (Device Independent Pixels) conversion and scaling operations. - /// - public static class DipHelper - { - /// - /// Converts millimeters to DIP (Device Independant Pixels). - /// - /// A millimeter value. - /// A DIP value. - public static double MmToDip(double mm) - { - return CmToDip(mm / 10.0); - } + ///// + ///// A helper class for DIP (Device Independent Pixels) conversion and scaling operations. + ///// + //public static class DipHelper + //{ + // /// + // /// Converts millimeters to DIP (Device Independant Pixels). + // /// + // /// A millimeter value. + // /// A DIP value. + // public static double MmToDip(double mm) + // { + // return CmToDip(mm / 10.0); + // } - /// - /// Converts centimeters to DIP (Device Independant Pixels). - /// - /// A centimeter value. - /// A DIP value. - public static double CmToDip(double cm) - { - return (cm * 96.0 / 2.54); - } + // /// + // /// Converts centimeters to DIP (Device Independant Pixels). + // /// + // /// A centimeter value. + // /// A DIP value. + // public static double CmToDip(double cm) + // { + // return (cm * 96.0 / 2.54); + // } - /// - /// Converts inches to DIP (Device Independant Pixels). - /// - /// An inch value. - /// A DIP value. - public static double InchToDip(double inch) - { - return (inch * 96.0); - } - public static double DipToInch(double dip) - { - return dip / 96D; - } + // /// + // /// Converts inches to DIP (Device Independant Pixels). + // /// + // /// An inch value. + // /// A DIP value. + // public static double InchToDip(double inch) + // { + // return (inch * 96.0); + // } + // public static double DipToInch(double dip) + // { + // return dip / 96D; + // } - /// - /// Converts font points to DIP (Device Independant Pixels). - /// - /// A font point value. - /// A DIP value. - public static double PtToDip(double pt) - { - return (pt * 96.0 / 72.0); - } + // /// + // /// Converts font points to DIP (Device Independant Pixels). + // /// + // /// A font point value. + // /// A DIP value. + // public static double PtToDip(double pt) + // { + // return (pt * 96.0 / 72.0); + // } - /// - /// Converts DIP (Device Independant Pixels) to centimeters. - /// - /// A DIP value. - /// A centimeter value. - public static double DipToCm(double dip) - { - return (dip * 2.54 / 96.0); - } + // /// + // /// Converts DIP (Device Independant Pixels) to centimeters. + // /// + // /// A DIP value. + // /// A centimeter value. + // public static double DipToCm(double dip) + // { + // return (dip * 2.54 / 96.0); + // } - /// - /// Converts DIP (Device Independant Pixels) to millimeters. - /// - /// A DIP value. - /// A millimeter value. - public static double DipToMm(double dip) - { - return DipToCm(dip) * 10.0; - } + // /// + // /// Converts DIP (Device Independant Pixels) to millimeters. + // /// + // /// A DIP value. + // /// A millimeter value. + // public static double DipToMm(double dip) + // { + // return DipToCm(dip) * 10.0; + // } - /// - /// Gets the system DPI scale factor (compared to 96 dpi). - /// From http://blogs.msdn.com/jaimer/archive/2007/03/07/getting-system-dpi-in-wpf-app.aspx - /// Should not be called before the Loaded event (else XamlException mat throw) - /// - /// A Point object containing the X- and Y- scale factor. - private static Point GetSystemDpiFactor() - { - PresentationSource source = PresentationSource.FromVisual(Application.Current.MainWindow); - Matrix m = source.CompositionTarget.TransformToDevice; - return new Point(m.M11, m.M22); - } + // /// + // /// Gets the system DPI scale factor (compared to 96 dpi). + // /// From http://blogs.msdn.com/jaimer/archive/2007/03/07/getting-system-dpi-in-wpf-app.aspx + // /// Should not be called before the Loaded event (else XamlException mat throw) + // /// + // /// A Point object containing the X- and Y- scale factor. + // private static Point GetSystemDpiFactor() + // { + // PresentationSource source = PresentationSource.FromVisual(Application.Current.MainWindow); + // Matrix m = source.CompositionTarget.TransformToDevice; + // return new Point(m.M11, m.M22); + // } - private const double DpiBase = 96.0; + // private const double DpiBase = 96.0; - /// - /// Gets the system configured DPI. - /// - /// A Point object containing the X- and Y- DPI. - public static Point GetSystemDpi() - { - Point sysDpiFactor = GetSystemDpiFactor(); - return new Point( - sysDpiFactor.X * DpiBase, - sysDpiFactor.Y * DpiBase); - } + // /// + // /// Gets the system configured DPI. + // /// + // /// A Point object containing the X- and Y- DPI. + // public static Point GetSystemDpi() + // { + // Point sysDpiFactor = GetSystemDpiFactor(); + // return new Point( + // sysDpiFactor.X * DpiBase, + // sysDpiFactor.Y * DpiBase); + // } - /// - /// Gets the physical pixel density (DPI) of the screen. - /// - /// Size - in inch - of the diagonal of the screen. - /// A Point object containing the X- and Y- DPI. - public static Point GetPhysicalDpi(double diagonalScreenSize) - { - Point sysDpiFactor = GetSystemDpiFactor(); - double pixelScreenWidth = SystemParameters.PrimaryScreenWidth * sysDpiFactor.X; - double pixelScreenHeight = SystemParameters.PrimaryScreenHeight * sysDpiFactor.Y; - double formatRate = pixelScreenWidth / pixelScreenHeight; + // /// + // /// Gets the physical pixel density (DPI) of the screen. + // /// + // /// Size - in inch - of the diagonal of the screen. + // /// A Point object containing the X- and Y- DPI. + // public static Point GetPhysicalDpi(double diagonalScreenSize) + // { + // Point sysDpiFactor = GetSystemDpiFactor(); + // double pixelScreenWidth = SystemParameters.PrimaryScreenWidth * sysDpiFactor.X; + // double pixelScreenHeight = SystemParameters.PrimaryScreenHeight * sysDpiFactor.Y; + // double formatRate = pixelScreenWidth / pixelScreenHeight; - double inchHeight = diagonalScreenSize / Math.Sqrt(formatRate * formatRate + 1.0); - double inchWidth = formatRate * inchHeight; + // double inchHeight = diagonalScreenSize / Math.Sqrt(formatRate * formatRate + 1.0); + // double inchWidth = formatRate * inchHeight; - double xDpi = Math.Round(pixelScreenWidth / inchWidth); - double yDpi = Math.Round(pixelScreenHeight / inchHeight); + // double xDpi = Math.Round(pixelScreenWidth / inchWidth); + // double yDpi = Math.Round(pixelScreenHeight / inchHeight); - return new Point(xDpi, yDpi); - } + // return new Point(xDpi, yDpi); + // } - /// - /// Converts a DPI into a scale factor (compared to system DPI). - /// - /// A Point object containing the X- and Y- DPI to convert. - /// A Point object containing the X- and Y- scale factor. - public static Point DpiToScaleFactor(Point dpi) - { - Point sysDpi = GetSystemDpi(); - return new Point( - dpi.X / sysDpi.X, - dpi.Y / sysDpi.Y); - } + // /// + // /// Converts a DPI into a scale factor (compared to system DPI). + // /// + // /// A Point object containing the X- and Y- DPI to convert. + // /// A Point object containing the X- and Y- scale factor. + // public static Point DpiToScaleFactor(Point dpi) + // { + // Point sysDpi = GetSystemDpi(); + // return new Point( + // dpi.X / sysDpi.X, + // dpi.Y / sysDpi.Y); + // } - /// - /// Gets the scale factor to apply to a WPF application - /// so that 96 DIP always equals 1 inch on the screen (whatever the system DPI). - /// - /// Size - in inch - of the diagonal of the screen - /// A Point object containing the X- and Y- scale factor. - public static Point GetScreenIndependentScaleFactor(double diagonalScreenSize) - { - return DpiToScaleFactor(GetPhysicalDpi(diagonalScreenSize)); - } - } + // /// + // /// Gets the scale factor to apply to a WPF application + // /// so that 96 DIP always equals 1 inch on the screen (whatever the system DPI). + // /// + // /// Size - in inch - of the diagonal of the screen + // /// A Point object containing the X- and Y- scale factor. + // public static Point GetScreenIndependentScaleFactor(double diagonalScreenSize) + // { + // return DpiToScaleFactor(GetPhysicalDpi(diagonalScreenSize)); + // } + //} } diff --git a/AIStudio.Wpf.DiagramDesigner.Additionals/Converters/CountShiftConverter.cs b/AIStudio.Wpf.DiagramDesigner.Additionals/Converters/CountShiftConverter.cs index 232efa5..b797885 100644 --- a/AIStudio.Wpf.DiagramDesigner.Additionals/Converters/CountShiftConverter.cs +++ b/AIStudio.Wpf.DiagramDesigner.Additionals/Converters/CountShiftConverter.cs @@ -25,12 +25,12 @@ namespace AIStudio.Wpf.DiagramDesigner.Additionals.Converters if (parameter?.ToString() == "Y") { - var value = 0 - (unit == Unit.Cm? DipHelper.DipToCm(vector.Y - 20) : DipHelper.DipToInch(vector.Y - 20))/ zoomValue; + var value = 0 - (unit == Unit.Cm? ScreenHelper.WidthToCm(vector.Y - 20) : ScreenHelper.WidthToInch(vector.Y - 20))/ zoomValue; return value; } else { - var value = 0 - (unit == Unit.Cm ? DipHelper.DipToCm(vector.X - 20) : DipHelper.DipToInch(vector.X - 20)) / zoomValue; + var value = 0 - (unit == Unit.Cm ? ScreenHelper.WidthToCm(vector.X - 20) : ScreenHelper.WidthToInch(vector.X - 20)) / zoomValue; return value; } } diff --git a/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner.csproj b/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner.csproj index 045d357..4db0d82 100644 --- a/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner.csproj +++ b/AIStudio.Wpf.DiagramDesigner/AIStudio.Wpf.DiagramDesigner.csproj @@ -25,6 +25,7 @@ + diff --git a/AIStudio.Wpf.DiagramDesigner/Enums/PageSizeType.cs b/AIStudio.Wpf.DiagramDesigner/Enums/PageSizeType.cs index 6c880bd..2712fe9 100644 --- a/AIStudio.Wpf.DiagramDesigner/Enums/PageSizeType.cs +++ b/AIStudio.Wpf.DiagramDesigner/Enums/PageSizeType.cs @@ -6,32 +6,7 @@ using System.Text; namespace AIStudio.Wpf.DiagramDesigner { public enum PageSizeType - { - - [Description("Letter,8.5英寸*11英寸")]//612*792 - Letter, - [Description("Folio,8.5英寸*13英寸")]//612*936 - Folio, - [Description("Folio,8.5英寸*14英寸")]//612*1008 - Legal, - [Description("Folio,7.25英寸*10.5英寸")]//522*756 - Executive, - [Description("Folio,5.5英寸*8.5英寸")]//396*612 - Statement, - [Description("#10 Envelope,4.125英寸*9.5英寸")]//297*684 - Envelope, - [Description("Monarch Envelope,3.875英寸*7.5英寸")]//279*540 - MonarchEnvelope, - [Description("Tabloid,11英寸*17英寸")]//792*1224 - Tabloid, - [Description("Letter Small,8 1/2英寸*11英寸")]//612*792 - LetterSmall, - [Description("C Sheet,17英寸*22英寸")]//1224*1584 - CSheet, - [Description("D Sheet,22英寸*34英寸")]//1584*2448 - DSheet, - [Description("E Sheet,34英寸*44英寸")]//2448*3168 - ESheet, + { [Description("A3 sheet,297毫米*420毫米")]//842*1191 A3, [Description("A4 sheet,210毫米*297毫米")]//595*842 @@ -68,6 +43,30 @@ namespace AIStudio.Wpf.DiagramDesigner //JapanesePostcard, //[Description("Double Japanese Postcard")]//420*566 //DoubleJapanesePostcard, + [Description("Letter,8.5英寸*11英寸")]//612*792 + Letter, + [Description("Folio,8.5英寸*13英寸")]//612*936 + Folio, + [Description("Folio,8.5英寸*14英寸")]//612*1008 + Legal, + [Description("Folio,7.25英寸*10.5英寸")]//522*756 + Executive, + [Description("Folio,5.5英寸*8.5英寸")]//396*612 + Statement, + [Description("#10 Envelope,4.125英寸*9.5英寸")]//297*684 + Envelope, + [Description("Monarch Envelope,3.875英寸*7.5英寸")]//279*540 + MonarchEnvelope, + [Description("Tabloid,11英寸*17英寸")]//792*1224 + Tabloid, + [Description("Letter Small,8 1/2英寸*11英寸")]//612*792 + LetterSmall, + [Description("C Sheet,17英寸*22英寸")]//1224*1584 + CSheet, + [Description("D Sheet,22英寸*34英寸")]//1584*2448 + DSheet, + [Description("E Sheet,34英寸*44英寸")]//2448*3168 + ESheet, [Description("自定义")] Custom, } diff --git a/AIStudio.Wpf.DiagramDesigner/Helpers/ScreenHelper.cs b/AIStudio.Wpf.DiagramDesigner/Helpers/ScreenHelper.cs index 7d49930..839345c 100644 --- a/AIStudio.Wpf.DiagramDesigner/Helpers/ScreenHelper.cs +++ b/AIStudio.Wpf.DiagramDesigner/Helpers/ScreenHelper.cs @@ -1,11 +1,23 @@ -using System; -using System.Drawing; +using Microsoft.Win32; +using System.Collections.Generic; +using System; +using System.Management; using System.Runtime.InteropServices; +using System.Drawing; namespace AIStudio.Wpf.DiagramDesigner { public static class ScreenHelper { + public static double ScreenScale; + public static double MmToPixelsWidth; + static ScreenHelper() + { + ScreenScale = ResetScreenScale(); + MmToPixelsWidth = MillimetersToPixelsWidth(1); + } + + [DllImport("user32.dll", EntryPoint = "ReleaseDC")] public static extern IntPtr ReleaseDC( IntPtr hWnd, @@ -44,5 +56,94 @@ namespace AIStudio.Wpf.DiagramDesigner return physicalScreenWidth * 1.0000 / System.Windows.SystemParameters.PrimaryScreenWidth; } } + + //public static List GetMonitorPnpDeviceId() + //{ + // List rt = new List(); + + // using (ManagementClass mc = new ManagementClass("Win32_DesktopMonitor")) + // { + // using (ManagementObjectCollection moc = mc.GetInstances()) + // { + // foreach (var o in moc) + // { + // var each = (ManagementObject)o; + // object obj = each.Properties["PNPDeviceID"].Value; + // if (obj == null) + // continue; + + // rt.Add(each.Properties["PNPDeviceID"].Value.ToString()); + // } + // } + // } + + // return rt; + //} + + //public static byte[] GetMonitorEdid(string monitorPnpDevId) + //{ + // return (byte[])Registry.GetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Enum\" + monitorPnpDevId + @"\Device Parameters", "EDID", new byte[] { }); + //} + + ////获取显示器物理尺寸(cm) + //public static SizeF GetMonitorPhysicalSize(string monitorPnpDevId) + //{ + // byte[] edid = GetMonitorEdid(monitorPnpDevId); + // if (edid.Length < 23) + // return SizeF.Empty; + + // return new SizeF(edid[21], edid[22]); + //} + + //通过屏显示器理尺寸转换为显示器大小(inch) + public static float MonitorScaler(SizeF moniPhySize) + { + double mDSize = Math.Sqrt(Math.Pow(moniPhySize.Width, 2) + Math.Pow(moniPhySize.Height, 2)) / 2.54d; + return (float)Math.Round(mDSize, 1); + } + + public static double MillimetersToPixelsWidth(double length) //length是毫米,1厘米=10毫米 + { + //System.Windows.Forms.Panel p = new System.Windows.Forms.Panel(); + System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(IntPtr.Zero); + IntPtr hdc = g.GetHdc(); + int width = GetDeviceCaps(hdc, 4); // HORZRES + int pixels = GetDeviceCaps(hdc, 8); // BITSPIXEL + g.ReleaseHdc(hdc); + return (((double)pixels / (double)width) * (double)length); + } + + + + public static double MmToWidth(double length) //length是毫米,1厘米=10毫米 + { + return MmToPixelsWidth * length / ScreenScale; + } + + public static double WidthToMm(double length) + { + return ScreenScale * length / MmToPixelsWidth; + } + + public static double CmToWidth(double length) //length是毫米,1厘米=10毫米 + { + return MmToPixelsWidth * length * 10d/ ScreenScale; + } + + public static double WidthToCm(double length) + { + return ScreenScale * length / (MmToPixelsWidth * 10d); + } + + public static double InchToWidth(double length) //length是英寸,1英寸=2.54cm + { + return MmToPixelsWidth * length * 10d * 2.54d / ScreenScale; + } + + public static double WidthToInch(double length) //length是英寸,1英寸=2.54cm + { + return ScreenScale * length / (MmToPixelsWidth * 10d * 2.54d); + } + } } diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Connector/ConnectorInfoItemBase.cs b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Connector/ConnectorInfoItemBase.cs index 828ce18..bfc5b05 100644 --- a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Connector/ConnectorInfoItemBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Connector/ConnectorInfoItemBase.cs @@ -22,21 +22,20 @@ namespace AIStudio.Wpf.DiagramDesigner public ConnectorInfoItemBase(ConnectorInfoBase viewmodel) : base(viewmodel) { - ConnectorWidth = viewmodel.ConnectorWidth; - ConnectorHeight = viewmodel.ConnectorHeight; + PhysicalConnectorWidth = viewmodel.PhysicalConnectorWidth; + PhysicalConnectorHeight = viewmodel.PhysicalConnectorHeight; Orientation = viewmodel.Orientation; - ConnectorValue = viewmodel.ConnectorValue; } [XmlAttribute] - public double ConnectorWidth + public double PhysicalConnectorWidth { get; set; } [XmlAttribute] - public double ConnectorHeight + public double PhysicalConnectorHeight { get; set; } @@ -47,11 +46,7 @@ namespace AIStudio.Wpf.DiagramDesigner get; set; } - [XmlAttribute] - public double ConnectorValue - { - get; set; - } + } diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Connector/LogicalConnectorInfoItem.cs b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Connector/LogicalConnectorInfoItem.cs index c74a61b..267667a 100644 --- a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Connector/LogicalConnectorInfoItem.cs +++ b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/Connector/LogicalConnectorInfoItem.cs @@ -21,6 +21,7 @@ namespace AIStudio.Wpf.DiagramDesigner public LogicalConnectorInfoItem(LogicalConnectorInfo viewmodel) : base(viewmodel) { ValueTypePoint = viewmodel.ValueTypePoint; + ConnectorValue = viewmodel.ConnectorValue; } [XmlAttribute] @@ -28,6 +29,12 @@ namespace AIStudio.Wpf.DiagramDesigner { get; set; } + + [XmlAttribute] + public double ConnectorValue + { + get; set; + } } diff --git a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/DesignerItemBase.cs b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/DesignerItemBase.cs index a3dd684..10879bc 100644 --- a/AIStudio.Wpf.DiagramDesigner/Models/Serializables/DesignerItemBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/Models/Serializables/DesignerItemBase.cs @@ -20,13 +20,13 @@ namespace AIStudio.Wpf.DiagramDesigner public DesignerItemBase(DesignerItemViewModelBase viewmodel, string reserve = null) : base(viewmodel) { - this.Left = viewmodel.Left; - this.Top = viewmodel.Top; + this.PhysicalLeft = viewmodel.PhysicalLeft; + this.PhysicalTop = viewmodel.PhysicalTop; this.Angle = viewmodel.Angle; this.ScaleX = viewmodel.ScaleX; this.ScaleY = viewmodel.ScaleY; - this.ItemWidth = viewmodel.ItemWidth; - this.ItemHeight = viewmodel.ItemHeight; + this.PhysicalItemWidth = viewmodel.PhysicalItemWidth; + this.PhysicalItemHeight = viewmodel.PhysicalItemHeight; this.Icon = viewmodel.Icon; this.ItemTypeName = viewmodel.GetType().FullName; this.Margin = viewmodel.Margin; @@ -34,37 +34,70 @@ namespace AIStudio.Wpf.DiagramDesigner } [XmlAttribute] - public double Left { get; set; } + public double PhysicalLeft + { + get; set; + } [XmlAttribute] - public double Top { get; set; } + public double PhysicalTop + { + get; set; + } [XmlAttribute] - public double Angle { get; set; } + public double Angle + { + get; set; + } [XmlAttribute] - public double ScaleX { get; set; } + public double ScaleX + { + get; set; + } [XmlAttribute] - public double ScaleY { get; set; } + public double ScaleY + { + get; set; + } [XmlAttribute] - public double Margin { get; set; } + public double Margin + { + get; set; + } [XmlAttribute] - public double ItemWidth { get; set; } + public double PhysicalItemWidth + { + get; set; + } [XmlAttribute] - public double ItemHeight { get; set; } + public double PhysicalItemHeight + { + get; set; + } [XmlAttribute] - public string Icon { get; set; } + public string Icon + { + get; set; + } [XmlAttribute] - public string Reserve { get; set; } + public string Reserve + { + get; set; + } [XmlAttribute] - public string ItemTypeName { get; set; } + public string ItemTypeName + { + get; set; + } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorInfoBase.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorInfoBase.cs index e029c4c..88ebef0 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorInfoBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/ConnectorInfoBase.cs @@ -53,10 +53,9 @@ namespace AIStudio.Wpf.DiagramDesigner if (designerbase is ConnectorInfoItemBase designer) { - ConnectorWidth = designer.ConnectorWidth; - ConnectorHeight = designer.ConnectorHeight; + PhysicalConnectorWidth = designer.PhysicalConnectorWidth; + PhysicalConnectorHeight = designer.PhysicalConnectorHeight; Orientation = designer.Orientation; - ConnectorValue = designer.ConnectorValue; } } @@ -87,44 +86,61 @@ namespace AIStudio.Wpf.DiagramDesigner } } - private double connectorWidth = 8; + private double _connectorWidth = 8; public double ConnectorWidth { get { - return connectorWidth; + return _connectorWidth; } set { - connectorWidth = value; + if (SetProperty(ref _connectorWidth, value)) + { + RaisePropertyChanged(nameof(PhysicalConnectorWidth)); + } } } - private double connectorHeight = 8; + private double _connectorHeight = 8; public double ConnectorHeight { get { - return connectorHeight; + return _connectorHeight; } set { - connectorHeight = value; + if (SetProperty(ref _connectorHeight, value)) + { + RaisePropertyChanged(nameof(PhysicalConnectorHeight)); + } } } - public double _connectorValue; - public double ConnectorValue + public double PhysicalConnectorWidth { get { - return _connectorValue; + return ConnectorWidth * (Root?.ScreenScale ?? 1d); } set { - SetProperty(ref _connectorValue, value); + ConnectorWidth = value / (Root?.ScreenScale ?? 1d); } } + + public double PhysicalConnectorHeight + { + get + { + return ConnectorHeight * (Root?.ScreenScale ?? 1d); + } + set + { + ConnectorHeight = value / (Root?.ScreenScale ?? 1d); + } + } #endregion } } diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/LogicalConnectorInfo.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/LogicalConnectorInfo.cs index 9faacdc..f5a15a3 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/LogicalConnectorInfo.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/Connector/LogicalConnectorInfo.cs @@ -36,10 +36,24 @@ namespace AIStudio.Wpf.DiagramDesigner if (designerbase is LogicalConnectorInfoItem designer) { + ConnectorValue = designer.ConnectorValue; ValueTypePoint = designer.ValueTypePoint; } } + public double _connectorValue; + public double ConnectorValue + { + get + { + return _connectorValue; + } + set + { + SetProperty(ref _connectorValue, value); + } + } + public ValueTypePoint _valueTypePoint; public ValueTypePoint ValueTypePoint { diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DesignerItemViewModelBase.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DesignerItemViewModelBase.cs index 9c29184..9989d3c 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DesignerItemViewModelBase.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DesignerItemViewModelBase.cs @@ -51,13 +51,13 @@ namespace AIStudio.Wpf.DiagramDesigner if (designerbase is DesignerItemBase designer) { - this.Left = designer.Left; - this.Top = designer.Top; + this.PhysicalLeft = designer.PhysicalLeft; + this.PhysicalTop = designer.PhysicalTop; this.Angle = designer.Angle; this.ScaleX = designer.ScaleX; this.ScaleY = designer.ScaleY; - this.ItemWidth = designer.ItemWidth; - this.ItemHeight = designer.ItemHeight; + this.PhysicalItemWidth = designer.PhysicalItemWidth; + this.PhysicalItemHeight = designer.PhysicalItemHeight; this.Icon = designer.Icon; } } @@ -191,12 +191,10 @@ namespace AIStudio.Wpf.DiagramDesigner set { if (value <= 0) return; - - if (this is GroupDesignerItemViewModel && value < 70) + if (SetProperty(ref _itemWidth, value)) { - + RaisePropertyChanged(nameof(PhysicalItemWidth)); } - SetProperty(ref _itemWidth, value); } } @@ -212,7 +210,36 @@ namespace AIStudio.Wpf.DiagramDesigner set { if (value <= 0) return; - SetProperty(ref _itemHeight, value); + if (SetProperty(ref _itemHeight, value)) + { + RaisePropertyChanged(nameof(PhysicalItemHeight)); + } + } + } + + [Browsable(true)] + public double PhysicalItemWidth + { + get + { + return ItemWidth * (Root?.ScreenScale ?? 1d); + } + set + { + ItemWidth = value / (Root?.ScreenScale ?? 1d); + } + } + + [Browsable(true)] + public double PhysicalItemHeight + { + get + { + return ItemHeight * (Root?.ScreenScale ?? 1d); + } + set + { + ItemHeight = value / (Root?.ScreenScale ?? 1d); } } @@ -310,6 +337,32 @@ namespace AIStudio.Wpf.DiagramDesigner } } + [Browsable(true)] + public double PhysicalLeft + { + get + { + return Left * (Root?.ScreenScale ?? 1d); + } + set + { + Left = value / (Root?.ScreenScale ?? 1d); + } + } + + [Browsable(true)] + public double PhysicalTop + { + get + { + return Top * (Root?.ScreenScale ?? 1d); + } + set + { + Top = value / (Root?.ScreenScale ?? 1d); + } + } + public PointBase Position { get diff --git a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs index 18265fe..0075887 100644 --- a/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs +++ b/AIStudio.Wpf.DiagramDesigner/ViewModels/BaseViewModel/DiagramViewModel.cs @@ -112,38 +112,40 @@ namespace AIStudio.Wpf.DiagramDesigner public Size GetPageSize() { + Size size = _pageSize; switch (PageSizeType) - { - case PageSizeType.Letter: return new Size(612, 792); - case PageSizeType.Folio: return new Size(612, 936); - case PageSizeType.Legal: return new Size(612, 1008); - case PageSizeType.Executive: return new Size(522, 756); - case PageSizeType.Statement: return new Size(396, 612); - case PageSizeType.Envelope: return new Size(297, 684); - case PageSizeType.MonarchEnvelope: return new Size(279, 540); - case PageSizeType.Tabloid: return new Size(792, 1224); - case PageSizeType.LetterSmall: return new Size(612, 792); - case PageSizeType.CSheet: return new Size(1224, 1584); - case PageSizeType.DSheet: return new Size(1584, 2448); - case PageSizeType.ESheet: return new Size(2448, 3168); - case PageSizeType.A3: return new Size(842, 1191); - case PageSizeType.A4: return new Size(595, 842); - case PageSizeType.A5: return new Size(420, 595); - case PageSizeType.B4: return new Size(709, 1003); - case PageSizeType.B5: return new Size(516, 729); - case PageSizeType.DLEnvelope: return new Size(312, 624); - case PageSizeType.C5Envelope: return new Size(459, 649); - case PageSizeType.Quarto: return new Size(609, 780); - case PageSizeType.C6Quarto: return new Size(323, 459); - case PageSizeType.B5Quarto: return new Size(499, 709); - case PageSizeType.ItalyQuarto: return new Size(312, 652); - case PageSizeType.A4small: return new Size(595, 842); - case PageSizeType.GermanStdFanfold: return new Size(612, 864); - case PageSizeType.GermanLegalFanfold: return new Size(576, 936); - case PageSizeType.PRC16K: return new Size(414, 609); - case PageSizeType.PRC32K: return new Size(275, 428); - default: return _pageSize; + { + case PageSizeType.A3: size = new Size(297, 420); break; + case PageSizeType.A4: size = new Size(210, 297); break; + case PageSizeType.A5: size = new Size(148, 210); break; + case PageSizeType.B4: size = new Size(257, 364); break; + case PageSizeType.B5: size = new Size(176, 250); break; + case PageSizeType.DLEnvelope: size = new Size(110, 220); break; + case PageSizeType.C5Envelope: size = new Size(162, 229); break; + case PageSizeType.Quarto: size = new Size(215, 275); break; + case PageSizeType.C6Quarto: size = new Size(114, 162); break; + case PageSizeType.B5Quarto: size = new Size(176, 250); break; + case PageSizeType.ItalyQuarto: size = new Size(110, 230); break; + case PageSizeType.A4small: size = new Size(210, 297); break; + case PageSizeType.GermanStdFanfold: size = new Size(215.9, 304.8); break; + case PageSizeType.GermanLegalFanfold: size = new Size(203.2, 330.2); break; + case PageSizeType.PRC16K: size = new Size(146, 215); break; + case PageSizeType.PRC32K: size = new Size(97, 151); break; + case PageSizeType.Letter: size = new Size(215.9, 279.4); break; + case PageSizeType.Folio: size = new Size(215.9, 330.2); break; + case PageSizeType.Legal: size = new Size(215.9, 355.6); break; + case PageSizeType.Executive: size = new Size(184.15, 266.7); break; + case PageSizeType.Statement: size = new Size(139.7, 215.9); break; + case PageSizeType.Envelope: size = new Size(104.77, 241.3); break; + case PageSizeType.MonarchEnvelope: size = new Size(98.425, 190.5); break; + case PageSizeType.Tabloid: size = new Size(279.4, 431.8); break; + case PageSizeType.LetterSmall: size = new Size(215.9, 279.4); break; + case PageSizeType.CSheet: size = new Size(431.8, 558.8); break; + case PageSizeType.DSheet: size = new Size(558.8, 863.6); break; + case PageSizeType.ESheet: size = new Size(863.6, 1117.6); break; } + + return new Size(ScreenHelper.MmToWidth(size.Width), ScreenHelper.MmToWidth(size.Height)); } private PageSizeOrientation _pageSizeOrientation; @@ -599,6 +601,8 @@ namespace AIStudio.Wpf.DiagramDesigner private DoCommandManager DoCommandManager = new DoCommandManager(); public DiagramViewModel() { + SetScreenScale(); + CreateNewDiagramCommand = new SimpleCommand(ExecuteEnable, ExecuteCreateNewDiagramCommand); AddItemCommand = new SimpleCommand(ExecuteEnable, ExecuteAddItemCommand); DirectAddItemCommand = new SimpleCommand(ExecuteEnable, ExecuteDirectAddItemCommand); @@ -1464,7 +1468,7 @@ namespace AIStudio.Wpf.DiagramDesigner } } - + OffsetX += 10; OffsetY += 10; @@ -1511,7 +1515,7 @@ namespace AIStudio.Wpf.DiagramDesigner System.Windows.MessageBox.Show(e.StackTrace, e.Message, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error); } } - } + } private bool ItemsToDeleteHasConnector(List itemsToRemove, ConnectorInfoBase connector) { diff --git a/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml.cs b/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml.cs index 556eb80..0dc5286 100644 --- a/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml.cs +++ b/AIStudio.Wpf.Flowchart/Controls/FlowchartEditor.xaml.cs @@ -32,7 +32,6 @@ namespace AIStudio.Wpf.Flowchart.Controls public FlowchartEditor() { _diagramViewModel = new DiagramViewModel(); - _diagramViewModel.SetScreenScale(); _diagramViewModel.ShowGrid = true; _diagramViewModel.GridCellSize = new SizeBase(125 / _diagramViewModel.ScreenScale, 125 / _diagramViewModel.ScreenScale); _diagramViewModel.GridMarginSize = new Size(0, 0);