From 1a1c8e71fcd14858f595029f089b2d4a00202b32 Mon Sep 17 00:00:00 2001
From: ogi <Administrator@S-OGI-PC>
Date: Fri, 05 Dec 2025 09:24:16 +0900
Subject: [PATCH] プロジェクトファイルを追加。

---
 HotelPms.SourceFactory/FormGdi.cs |  351 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 351 insertions(+), 0 deletions(-)

diff --git a/HotelPms.SourceFactory/FormGdi.cs b/HotelPms.SourceFactory/FormGdi.cs
new file mode 100644
index 0000000..989977a
--- /dev/null
+++ b/HotelPms.SourceFactory/FormGdi.cs
@@ -0,0 +1,351 @@
+using HotelPms.Share.Windows.GraphicsApi;
+using HotelPms.Share.Windows.Util;
+//using NetTopologySuite.Operation.Buffer;
+using Org.BouncyCastle.Bcpg;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Drawing.Drawing2D;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+//using Topology = NetTopologySuite.Geometries;
+
+namespace HotelPms.SourceFactory
+{
+    public partial class FormGdi : Form
+    {
+        // 存储当鼠标在PictureBox中左键按下的位置,相对于PictureBox左上角坐标点的位置来讲。
+        private Point mouseDownPoint = new Point();
+        private bool isDown = false;
+
+        Region r = new System.Drawing.Region();
+        PointF start = PointF.Empty;
+        PointF continues = PointF.Empty;
+        PointF end = PointF.Empty;
+        int isDrawing = 0;
+        List<List<PointF>> drawpaths = new List<List<PointF>>();
+        List<PointF> drawpathtemp = new List<PointF>();
+
+
+        public FormGdi()
+        {
+            InitializeComponent();
+        }
+
+        private void button1_Click(object sender, EventArgs e)
+        {
+            Rectangle r1 = new Rectangle(panel1.Location, panel1.Size);
+            Rectangle r2 = new Rectangle(panel2.Location, panel2.Size);
+            textBox2.Text = $"({r1.Left}, {r1.Top})-({r1.Right},{r1.Bottom})";
+            textBox3.Text = $"({r2.Left}, {r2.Top})-({r2.Right},{r2.Bottom})";
+            textBox1.Text = Overlap.RectRect(r1, r2) ? "相交" : "分离";
+
+            textBox5.Text = $"!({r1.Right} < {r2.Left} || {r1.Bottom} < {r2.Top} || {r2.Right} < {r1.Left} || {r2.Bottom} < {r1.Top})";
+        }
+
+        private void button2_Click(object sender, EventArgs e)
+        {
+            Rectangle r1 = new Rectangle(panel1.Location, panel1.Size);
+            Rectangle r2 = new Rectangle(panel2.Location, panel2.Size);
+            textBox2.Text = $"({r1.Left}, {r1.Top})-({r1.Right},{r1.Bottom})";
+            textBox3.Text = $"({r2.Left}, {r2.Top})-({r2.Right},{r2.Bottom})";
+            textBox1.Text = Overlap.RectRect2(r1, r2) ? "相交" : "分离";
+            textBox5.Text = string.Empty;
+        }
+
+        private void panel2_MouseDown(object sender, MouseEventArgs e)
+        {
+            isDown = true;
+            if (e.Button == System.Windows.Forms.MouseButtons.Left)
+            {
+                mouseDownPoint = e.Location;
+            }
+        }
+
+        private void panel2_MouseMove(object sender, MouseEventArgs e)
+        {
+            if (isDown)
+            {
+                Panel obj = sender as Panel;
+
+                //PointToClient 将指定屏幕点的位置计算成工作区坐标(控件内)。坐标原点为黄色区域(控件)左上角,X轴方向从左到右,Y轴方向从上到下,坐标单位为像素;
+
+                //PointToScreen 将指定工作区点的位置计算成屏幕坐标。坐标原点在屏幕左上角,X轴方向从左到右,Y轴方向从上到下,坐标单位为像素。
+
+                //1、PointToClient(Point p)
+                //这里的p,坐标原点为Screen左上角,即(0, 0)。
+                //它计算以当前Control的位置在Screen位置为坐标原点,返回p相对于坐标原点的值。
+                //如上图例,btn在screen中位置为(328, 188),那么,screen上点(10, 10)相对于(320, 188)即为结果(-318, -178),同理screen上点(0, 0)相对于pnl来说,是(-183, -185)。
+                //Control在Screen上点计算方式为:窗体Location加上其各级Parent的Location。
+
+                //2、PointToScreen(Point p)
+                //这里的p,坐标原点相对于Control的Location。
+                //这是求p于Control的Locaton在Screen上点迭加结果。
+                //如上例,pnl相对于窗体位置为(80, 60),其加上窗体Location(200, 100),再加上边框宽度3、标题栏高度25,即得185。
+                //btn.PointToScreen(new Point(30, 20)): { X = 358,Y = 208}
+                //此值即为:btn在Screen上位置(328, 188)加上(30, 20)所得。
+
+                // 先获取到当前鼠标所在位置,并减去鼠标左键按下时相对PictureBox左上角的坐标点,就是当前坐标要停留的坐标点位置。
+                Point point = this.PointToClient(obj.PointToScreen(new Point(e.X - mouseDownPoint.X, e.Y - mouseDownPoint.Y)));
+                obj.Location = point;
+            }
+        }
+
+        private void panel2_MouseUp(object sender, MouseEventArgs e)
+        {
+            if (isDown)
+            { 
+            }
+
+            isDown = false;
+        }
+
+        private void Form1_Paint(object sender, PaintEventArgs e)
+        {
+            System.Drawing.Pen pen = new Pen(Color.Red);
+            if (isDrawing == 1)
+            {
+                if (drawpaths.Count >= 1)
+                {
+                    foreach (List<PointF> drawpath in drawpaths)
+                    {
+                        if (drawpath.Count >= 2)
+                        {
+                            e.Graphics.DrawLines(pen, drawpath.ToArray());
+                            if (continues.Equals(PointF.Empty) == false)
+                            {
+                                e.Graphics.DrawLine(pen, start, continues);
+                            }
+                        }
+                        else
+                        {
+                            if (continues.Equals(PointF.Empty) == false)
+                            {
+                                e.Graphics.DrawLine(pen, start, continues);
+                            }
+                        }
+                    }
+                }
+                if (drawpathtemp.Count >= 2)
+                {
+                    e.Graphics.DrawLines(pen, drawpathtemp.ToArray());
+                    if (continues.Equals(PointF.Empty) == false)
+                    {
+                        e.Graphics.DrawLine(pen, start, continues);
+                    }
+                }
+                else
+                {
+                    if (continues.Equals(PointF.Empty) == false)
+                    {
+                        e.Graphics.DrawLine(pen, start, continues);
+                    }
+                }
+            }
+            else if (isDrawing == 0)
+            {
+                foreach (List<PointF> drawpath in drawpaths)
+                {
+                    if (drawpath.Count >= 2)
+                    {
+                        e.Graphics.DrawLines(pen, drawpath.ToArray());
+                    }
+                }
+            }
+
+        }
+
+        private void Form1_MouseClick(object sender, MouseEventArgs e)
+        {
+            if (e.Button == MouseButtons.Left)
+            {
+                if (isDrawing == 0)
+                {
+                    start = e.Location;
+                    isDrawing = 1;
+                    drawpathtemp.Add(start);
+                }
+                else if (isDrawing == 1)
+                {
+                    start = e.Location;
+                    drawpathtemp.Add(start);
+                }
+                else if (isDrawing == 2)
+                {
+
+                }
+                this.Refresh();
+            }
+            if (e.Button == MouseButtons.Right)
+            {
+                if (r.IsVisible(e.Location))
+                {
+                    MessageBox.Show("在选中区域内");
+                }
+                else
+                {
+                    MessageBox.Show("不在选中区域内");
+                }
+            }
+        }
+
+        private void Form1_MouseMove(object sender, MouseEventArgs e)
+        {
+            if (isDrawing == 1)
+            {
+                continues = e.Location;
+                this.Refresh();
+            }
+
+        }
+
+        private void FormGdi_KeyDown(object sender, KeyEventArgs e)
+        {
+            switch (e.KeyCode)
+            {
+                case Keys.Escape:
+                    drawpathtemp.Add(drawpathtemp.ElementAt(0));
+                    List<PointF> temp = new List<PointF>();
+                    if (drawpathtemp.Count > 2)
+                    {
+                        temp = drawpathtemp.GetRange(0, drawpathtemp.Count);
+                        drawpaths.Add(temp);
+                    }
+                    drawpathtemp.Clear();
+                    start = PointF.Empty;
+                    end = PointF.Empty;
+                    continues = PointF.Empty;
+                    isDrawing = 0;
+                    GraphicsPath gp = new GraphicsPath();
+                    gp.Reset();
+                    foreach (List<PointF> item in drawpaths)
+                    {
+                        gp.AddPolygon(item.ToArray());
+                        r.MakeEmpty();
+                        r.Union(gp);
+                    }
+                    this.Refresh();
+                    break;
+                default:
+                    break;
+            }
+        }
+
+#if false
+        private PointF[] ToPointF(Topology.Coordinate[] coordinates)
+        {
+            PointF[] pointFs = new PointF[coordinates.Length];
+            int i = 0;
+            foreach (Topology.Coordinate item in coordinates)
+            {
+
+                pointFs[i] = new PointF((float)item.X, (float)item.Y);
+                i++;
+            }
+            return pointFs;
+        }
+
+        private List<PointD> ToPointD(Topology.Coordinate[] coordinates)
+        {
+            List<PointD> pointFs = new List<PointD>();
+            int i = 0;
+            foreach (Topology.Coordinate item in coordinates)
+            {
+
+                pointFs.Add(new PointD(item.X, item.Y));
+                i++;
+            }
+            return pointFs;
+        }
+#endif
+
+        private void panel2_DoubleClick(object sender, EventArgs e)
+        {
+            (sender as Panel).BringToFront();
+        }
+
+#if false
+        private void panel3_Paint(object sender, PaintEventArgs e)
+        {
+            e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;  //使绘图质量最高,即消除锯齿
+                                                                 //g.InterpolationMode = InterpolationMode.HighQualityBicubic; //要らない!!!
+                                                                 //g.CompositingQuality = CompositingQuality.HighQuality; //要らない!!!            
+
+            //32.923023515806,130.70006035416
+            //32.933253514755,130.69430969802
+            //32.936999415636,130.7124199733
+            //32.929507455233,130.73954247087
+
+            //double rate = 1D;
+            Topology.LineString ls = new Topology.LineString(
+                new Topology.Coordinate[] {
+                    //new Topology.Coordinate { X = 32.923023515806 * rate, Y = 130.70006035416* rate },
+                    //new Topology.Coordinate { X = 32.933253514755 * rate, Y = 130.69430969802* rate },
+                    //new Topology.Coordinate { X = 32.936999415636 * rate, Y = 130.7124199733* rate },
+                    //new Topology.Coordinate { X = 32.929507455233 * rate , Y = 130.73954247087* rate }
+                    new Topology.Coordinate { X = 32.923023515806, Y = 130.70006035416 },
+                    new Topology.Coordinate { X = 32.933253514755, Y = 130.69430969802 },
+                    new Topology.Coordinate { X = 32.936999415636, Y = 130.7124199733 },
+                    new Topology.Coordinate { X = 32.929507455233 , Y = 130.73954247087 }
+                    //new Topology.Coordinate { X = 25, Y = 28 }, 
+                    //new Topology.Coordinate { X = 200, Y = 32 }, 
+                    //new Topology.Coordinate { X = 250, Y = 326 },
+                    //new Topology.Coordinate { X = 350, Y = 326 },
+                    //new Topology.Coordinate { X = 350, Y = 426 },
+                    //new Topology.Coordinate { X = 150, Y = 476 }
+                });
+            //Topology.Polygon result = ls.Buffer(10, NetTopologySuite.Operation.Buffer.EndCapStyle.Flat) as Topology.Polygon;
+
+            PointF[] pointFs = ToPointF(ls.Coordinates);
+            e.Graphics.DrawLines(new Pen(Color.Red, 3), pointFs);
+            //pointFs = ToPointF(result.Coordinates);
+            //e.Graphics.DrawPolygon(new Pen(Color.Blue, 3), pointFs);
+
+            List<PointD> pointDs = ToPointD(ls.Coordinates);
+            List<PointD> r1 = Geometry.OffsetCoords(pointDs, 0.0005) as List<PointD>;
+            StringBuilder text = new StringBuilder();
+            foreach (PointD item in r1)
+            {
+                text.AppendLine("{" + $" lat: {item.X}, lng: {item.Y} " + "},");
+            }
+            System.Diagnostics.Debug.WriteLine(text.ToString());
+
+            e.Graphics.DrawLines(new Pen(Color.Green, 3), PointD.ToPointF(r1).ToArray());
+
+            List<PointD> r2 = Geometry.OffsetCoords(pointDs, -0.0005) as List<PointD>;
+            StringBuilder text1 = new StringBuilder();
+            foreach (PointD item in r2)
+            {
+                text1.AppendLine("{" + $" lat: {item.X}, lng: {item.Y} " + "},");
+            }
+            System.Diagnostics.Debug.WriteLine(text1.ToString());
+            e.Graphics.DrawLines(new Pen(Color.Green, 3), PointD.ToPointF(r2).ToArray());
+
+            r2.Reverse();
+            r1.AddRange(r2);
+
+            StringBuilder text2 = new StringBuilder();
+            foreach (PointD item in r1)
+            {
+                text2.AppendLine("{" + $" lat: {item.X}, lng: {item.Y} " + "},");
+            }
+            System.Diagnostics.Debug.WriteLine(text2.ToString());
+
+            StringBuilder text3 = new StringBuilder();
+            foreach (PointD item in r1)
+            {
+                text3.AppendLine($"{item.X},{item.Y}");
+            }
+            System.Diagnostics.Debug.WriteLine(text3.ToString());
+
+            e.Graphics.DrawPolygon(new Pen(Color.Blue, 3), PointD.ToPointF(r1).ToArray());
+
+            e.Graphics.SmoothingMode = SmoothingMode.Default;
+        }
+#endif
+    }
+}

--
Gitblit v1.10.0