Exemple #1
0
        private void SetupDebugConsole()
        {
            if (UseConsole)
            {
                DOut.PrintF  = Console.Write;
                DOut.PrintLn = Console.WriteLine;

                DOut.pl("DOut's output setting is Console");

                //DClient = new DebugClient();

                ////if (DClient.IsValid)
                //{
                //    DOut.PrintFunc = DClient.Write;
                //    DOut.PrintLnFunc = DClient.WriteLine;

                //    DOut.pl("DOut's output setting is DebugServer");
                //}
            }
            else
            {
                MainWindow wnd = (MainWindow)MainWindow;
                DOut.PrintF  = wnd.GetBuiltinConsole().Print;
                DOut.PrintLn = wnd.GetBuiltinConsole().PrintLn;
            }
        }
Exemple #2
0
        public bool InsPointToLastSelectedSeg()
        {
            if (LastSelSegment == null)
            {
                return(false);
            }

            MarkSegment seg = LastSelSegment.Value;

            CadFigure fig = DB.GetFigure(seg.FigureID);

            if (fig == null)
            {
                return(false);
            }

            if (fig.Type != CadFigure.Types.POLY_LINES)
            {
                return(false);
            }

            bool handle = false;

            handle |= fig.GetPointAt(seg.PtIndexA).IsHandle;
            handle |= fig.GetPointAt(seg.PtIndexB).IsHandle;

            if (handle)
            {
                return(false);
            }

            int ins  = 0;
            int ins0 = Math.Min(seg.PtIndexA, seg.PtIndexB);
            int ins1 = Math.Max(seg.PtIndexA, seg.PtIndexB);

            if (ins0 == 0 && ins1 == fig.PointCount - 1)
            {
                ins = ins1 + 1;
            }
            else
            {
                ins = ins1;
            }

            DOut.pl($"ins={ins} pcnt={fig.PointCount}");

            fig.InsertPointAt(ins, (CadVertex)LastDownPoint);

            ClearSelection();

            fig.SelectPointAt(ins, true);

            return(true);
        }
Exemple #3
0
        public void PrintPage(PlotterController pc, Graphics printerGraphics, CadSize2D pageSize, CadSize2D deviceSize)
        {
            DOut.pl($"Dev Width:{deviceSize.Width} Height:{deviceSize.Height}");
#if PRINT_WITH_GL_ONLY
            Bitmap bmp = GetPrintableBmp(pc, pageSize, deviceSize);
            printerGraphics.DrawImage(bmp, 0, 0);
#elif PRINT_WITH_GDI_ONLY
            PrintPageGDI(printerGraphics, pageSize, deviceSize);
#else
            PrintPageSwitch(pc, printerGraphics, pageSize, deviceSize);
#endif
        }
Exemple #4
0
        public FlexArray <int> GetOuterEdge()
        {
            // Pairを持たないHalfEdgeのリストを作成
            List <HalfEdge> heList = new List <HalfEdge>();

            ForEachHalfEdge(he => {
                if (he.Pair == null)
                {
                    heList.Add(he);
                }
            });

            FlexArray <int> ret = new FlexArray <int>();

            if (heList.Count <= 1)
            {
                return(ret);
            }

            int s = FindMaxDistantHalfEdge(CadVertex.Zero, heList);

            if (s == -1)
            {
                DOut.pl("HeModel.GetOuterEdge not found start HalfEdge");
                return(ret);
            }


            int      t   = s;
            HalfEdge whe = heList[t];

            int vi = whe.Vertex;

            heList.RemoveAt(t);

            while (true)
            {
                ret.Add(vi);
                vi = whe.Next.Vertex;

                t = FindHalfEdge(vi, heList);

                if (t == -1)
                {
                    break;
                }

                whe = heList[t];
                heList.RemoveAt(t);
            }

            return(ret);
        }
Exemple #5
0
        private void testSvg()
        {
            List <CadFigure> figList = Controller.DB.GetSelectedFigList();

            SvgExporter svgExporter = new SvgExporter();

            XDocument doc = svgExporter.ToSvg(figList,
                                              Controller.DC,
                                              Controller.PageSize.Width,
                                              Controller.PageSize.Height);

            DOut.pl(doc.ToString());
            doc.Save(@"f:\work2\test.svg");
        }
Exemple #6
0
        public static CadData?Load(string fname)
        {
            FileStream fs = new FileStream(fname, FileMode.Open, FileAccess.Read);

            byte[] sign = new byte[Sign.Length];

            fs.Read(sign, 0, Sign.Length);

            if (!Sign.SequenceEqual <byte>(sign))
            {
                fs.Close();
                return(null);
            }

            byte[] version = new byte[Version.Length];

            fs.Read(version, 0, Version.Length);

            byte[] data = new byte[fs.Length - Sign.Length - Version.Length];

            fs.Read(data, 0, data.Length);

            fs.Close();

            DOut.pl($"MpCadFile.Load {fname} {VersionStr(version)}");

            if (IsVersion(version, 1, 0, 0, 0))
            {
                return(null);
            }
            else if (IsVersion(version, 1, 0, 0, 1))
            {
                MpCadData_v1001 mpdata = MessagePackSerializer.Deserialize <MpCadData_v1001>(data);
                return(MpUtil_v1001.CreateCadData_v1001(mpdata));
            }
            else if (IsVersion(version, 1, 0, 0, 2))
            {
                MpCadData_v1002 mpdata = MessagePackSerializer.Deserialize <MpCadData_v1002>(data);
                return(MpUtil_v1002.CreateCadData_v1002(mpdata));
            }

            return(null);
        }
Exemple #7
0
        private void test009()
        {
            DrawContext dc = Controller.DC;

            CadObjectDB db = Controller.DB;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            int i        = 0;
            int layerCnt = db.LayerList.Count;

            for (; i < layerCnt; i++)
            {
                CadLayer layer = db.LayerList[i];

                int j      = 0;
                int figCnt = layer.FigureList.Count;

                for (; j < figCnt; j++)
                {
                    CadFigure fig = layer.FigureList[j];

                    int k    = 0;
                    int pcnt = fig.PointList.Count;

                    for (; k < pcnt; k++)
                    {
                        CadVertex p  = fig.PointList[k];
                        CadVertex sp = dc.WorldPointToDevPoint(p);
                    }
                }
            }

            sw.Stop();
            DOut.pl(sw.ElapsedMilliseconds.ToString() + " milli sec");
        }
Exemple #8
0
        public void RemoveVertexs(List <int> idxList)
        {
            int[] indexMap = new int[VertexStore.Count];

            for (int i = 0; i < idxList.Count; i++)
            {
                indexMap[idxList[i]] = -1;
            }

            int r = 0;

            for (int i = 0; i < VertexStore.Count; i++)
            {
                if (indexMap[i] != -1)
                {
                    indexMap[i] = r;
                    r++;
                }
            }

            ForEachHalfEdge(he =>
            {
                he.Vertex = indexMap[he.Vertex];
                if (he.Vertex == -1)
                {
                    DOut.pl("HeModel.RemoveVertexs error. he.Vertex == -1");
                }
            });

            for (int i = VertexStore.Count - 1; i >= 0; i--)
            {
                if (indexMap[i] == -1)
                {
                    VertexStore.RemoveAt(i);
                }
            }
        }