Пример #1
0
        public static void ExportTTImages(OIDProject oIDProject, Scene scene, TTToolSettings set, bool highquality, bool canvasImage, bool maskimage, EnumNeutralOid enumNeutral)
        {
            if (scene == null || scene.TTImages == null || scene.TTImages.Count == 0)
            {
                return;
            }

            string destDir = Path.Combine(oIDProject.ProjectPath, "Scenes");

            if (!Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }

            if (canvasImage)
            {
                ExportCanvasImage(scene, destDir);
            }

            string workdir = Path.Combine(oIDProject.ProjectPath, "temp");

            if (!Directory.Exists(workdir))
            {
                Directory.CreateDirectory(workdir);
            }
            if (maskimage)
            {
                CreateMaskPicture(oIDProject, scene, set, highquality, destDir, workdir, enumNeutral);
            }
        }
Пример #2
0
        private static void CreateMaskPicture(OIDProject oIDProject, Scene scene, TTToolSettings set, bool highquality, string destDir, string workdir, EnumNeutralOid enumNeutral)
        {
            using (var maskPicture = new Bitmap(scene.PixelSize.Width, scene.PixelSize.Height))
            {
                using (Graphics graphic = Graphics.FromImage(maskPicture))
                {
                    graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                    if (enumNeutral == EnumNeutralOid.mask)
                    {
                        CreateNeutralMask(maskPicture, scene, set, workdir);
                    }

                    DrawAllOids(oIDProject, scene, set, workdir, maskPicture, graphic, highquality);
                }
                maskPicture.Save(Path.Combine(destDir, $"{scene.Name}_mask.png"), ImageFormat.Png);
            }

            if (enumNeutral == EnumNeutralOid.separate)
            {
                using (var maskPicture = new Bitmap(scene.PixelSize.Width, scene.PixelSize.Height))
                {
                    using (Graphics graphic = Graphics.FromImage(maskPicture))
                    {
                        graphic.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                        CreateNeutralMask(maskPicture, scene, set, workdir);
                    }
                    maskPicture.Save(Path.Combine(destDir, $"{scene.Name}_neutral.png"), ImageFormat.Png);
                }
            }
        }
Пример #3
0
 private static void DrawStartOids(OIDProject oIDProject, Scene scene, TTToolSettings set, string workdir, Bitmap maskPicture, Graphics graphic, bool highquality)
 {
     if (scene.StartOid != null && scene.StartOid.Polygons != null && scene.StartOid.Polygons.Count > 0)
     {
         set.CodeDim = new Size(1, 1);
         var res       = TTTool.CreateOidCodes(set, oIDProject.ProductID, workdir);
         var MaskImage = Bitmap.FromFile(res);
         DrawPolygons(maskPicture, graphic, scene.StartOid, MaskImage, highquality);
     }
 }
Пример #4
0
 private static void DrawSeceneOids(OIDProject oIDProject, Scene scene, TTToolSettings set, string workdir, Bitmap maskPicture, Graphics graphic, bool highquality)
 {
     foreach (SceneOid sc in scene.SceneOids)
     {
         var ns = oIDProject.nodeSetups.Where(x => x.Name == sc.SetupName).FirstOrDefault();
         set.CodeDim = new Size(1, 1);
         var res       = TTTool.CreateOidCodes(set, (short)ns.OID, workdir);
         var MaskImage = Bitmap.FromFile(res);
         DrawPolygons(maskPicture, graphic, sc, MaskImage, highquality);
     }
 }
Пример #5
0
        public static void CreateImage(OIDProject oIDProject, Scene scene, TTToolSettings set, bool highquality)
        {
            if (scene == null || scene.TTImages == null || scene.TTImages.Count == 0)
            {
                return;
            }

            string destDir = Path.Combine(oIDProject.ProjectPath, "Scenes");

            if (!Directory.Exists(destDir))
            {
                Directory.CreateDirectory(destDir);
            }

            using (var scenePicture = new Bitmap(scene.PixelSize.Width, scene.PixelSize.Height))
            {
                using (Graphics graphic = Graphics.FromImage(scenePicture))
                {
                    foreach (var img in scene.TTImages)
                    {
                        img.Draw(graphic, 1);
                    }
                }
                scenePicture.Save(Path.Combine(destDir, $"{scene.Name}.png"), ImageFormat.Png);
            }

            string workdir = Path.Combine(oIDProject.ProjectPath, "temp");

            if (!Directory.Exists(workdir))
            {
                Directory.CreateDirectory(workdir);
            }

            using (var maskPicture = new Bitmap(scene.PixelSize.Width, scene.PixelSize.Height))
            {
                using (Graphics graphic = Graphics.FromImage(maskPicture))
                {
                    DrawSeceneOids(oIDProject, scene, set, workdir, maskPicture, graphic, highquality);
                    DrawStartOids(oIDProject, scene, set, workdir, maskPicture, graphic, highquality);
                }


                maskPicture.Save(Path.Combine(destDir, $"{scene.Name}_mask.png"), ImageFormat.Png);
            }
        }
Пример #6
0
        private void loadProjectToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = FILTERPROJECT;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    Project = OIDProject.Load(ofd.FileName);
                    RefreshNodes();
                    RefreshOid();

                    if (lbOidCodes.Items != null && lbOidCodes.Items.Count > 0)
                    {
                        lbOidCodes.SelectedIndex = 0;
                    }
                }
            }
        }
Пример #7
0
        private static void DrawAllOids(OIDProject oIDProject, Scene scene, TTToolSettings set, string workdir, Bitmap maskPicture, Graphics graphic, bool highquality)
        {
            var allOids = new List <SceneOid>();

            allOids.AddRange(scene.SceneOids);
            if (scene.StartOid != null && scene.StartOid.Polygons != null && scene.StartOid.Polygons.Count > 0)
            {
                allOids.Add(scene.StartOid);
            }

            foreach (SceneOid sc in allOids)
            {
                var ns = oIDProject.nodeSetups.Where(x => x.Name == sc.SetupName).FirstOrDefault();
                set.CodeDim = new Size(1, 1);
                var res       = TTTool.CreateOidCodes(set, (ushort)(ns != null ? ns.OID: oIDProject.ProductID), workdir);
                var MaskImage = Bitmap.FromFile(res);
                DrawPolygons(maskPicture, graphic, sc, MaskImage, highquality);
            }
        }
Пример #8
0
        private void RefreshRecentItems()
        {
            MenuRecent.DropDownItems.Clear();
            foreach (var item in TTGRegistry.GetRecentProjectPath())
            {
                var mi = new ToolStripMenuItem(item);
                mi.Click += (_, __) =>
                {
                    Project = OIDProject.Load(item);
                    RefreshNodes();
                    RefreshOid();

                    if (lbOidCodes.Items != null && lbOidCodes.Items.Count > 0)
                    {
                        lbOidCodes.SelectedIndex = 0;
                    }
                };
                MenuRecent.DropDownItems.Add(mi);
            }
        }
Пример #9
0
        public static MediaFile ImportNewFile(OIDProject oIDProject)
        {
            MediaFile newMediaFile = new MediaFile();
            var       existing     = oIDProject.MediaFiles;

            if (oIDProject == null || existing == null)
            {
                return(null);
            }
            using (var ofd = new OpenFileDialog())
            {
                ofd.Filter = FILTERMEDIA;
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    using (var fs = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read))
                    {
                        var    fn  = GetHashSha1(fs);
                        var    nfn = $"{fn}{Path.GetExtension(ofd.FileName)}";
                        string pf  = Path.Combine(oIDProject.ProjectPath, oIDProject.MediaPath, $"m_{nfn}");


                        var alreadyexisting = existing.Where(x => x.HashValue == fn).FirstOrDefault();
                        if (alreadyexisting != null)
                        {
                            MessageBox.Show($"File already imported {alreadyexisting.EditorEditorName}");
                            return(null);
                        }

                        File.Copy(ofd.FileName, pf, true);

                        newMediaFile.FileName         = $"m_{nfn}";
                        newMediaFile.EditorEditorName = Regex.Replace(Path.GetFileNameWithoutExtension(ofd.FileName), "[^A-Za-z0-9_]", "");
                        newMediaFile.HashValue        = fn;
                    }
                    return(newMediaFile);
                }
            }
            return(null);
        }