protected override void SaveToolsCommandImplementation()
        {
            var dlg = ViewModels.Ioc.SimpleIoc <IFileDialog> .GetInstance("SaveFile");

            dlg.AddExtension = true;
            dlg.DefaultExt   = "jTools";
            dlg.Filter       = "Tools (JSON) |*.jTools";

            var b = dlg.ShowDialog();

            if (b.HasValue && b.Value)
            {
                Messenger.Send(new SaveToolsMessage()
                {
                    GetTools = (tools) =>
                    {
                        if ((tools != null) && (tools.Count() > 0))
                        {
                            var name    = Path.GetFileNameWithoutExtension(dlg.FileName);
                            var toolset = new MDTools.ToolSet()
                            {
                                Name = name
                            };

                            foreach (var tool in tools)
                            {
                                toolset.Tools.Add(tool as MDTools.Tool);
                            }

                            SaveTools(dlg.FileName, toolset);
                        }
                    }
                });
            }
        }
        public static MDT.ToolSet ToToolsData(this MMT.ToolSet toolset)
        {
            var ts = new MDT.ToolSet();

            foreach (var item in toolset.Tools)
            {
                ts.Tools.Add(item.ToData());
            }

            return(ts);
        }
        internal static void SaveTools(MDTools.ToolSet toolSet, Func <StreamWriter> getStreamWriter)
        {
            JsonSerializer serializer = new JsonSerializer();

            serializer.NullValueHandling = NullValueHandling.Ignore;

            using (StreamWriter sw = getStreamWriter())
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, toolSet);
                }
        }
Example #4
0
        private void SetTooling(MDTooling.Tooling tooling, MDTools.ToolSet toolset)
        {
            foreach (var item in tooling.Units)
            {
                var t = toolset.Tools.FirstOrDefault(e => string.Compare(e.Name, item.ToolName) == 0);

                if (t != null)
                {
                    if (t is MDTools.AngularTransmission at)
                    {
                        Messenger.Send(new AngularTransmissionLoadMessage()
                        {
                            ToolHolder          = item.ToolHolderId,
                            AngularTransmission = at,
                            AppendSubSpindle    = (addSubSpindle) =>
                            {
                                foreach (var item in at.Subspindles)
                                {
                                    var tool = ((item is MDTools.SubspindleEx sse) && (sse.Tool != null)) ? sse.Tool : null;
                                    addSubSpindle(item.Position, item.Direction, tool);
                                }
                            }
                        });
 internal static void SaveTools(string fileName, MDTools.ToolSet toolSet) => SaveTools(toolSet, () => new StreamWriter(fileName));