internal static void SaveTooling(MDTooling.Tooling tooling, Func <StreamWriter> getStreamWriter)
        {
            JsonSerializer serializer = new JsonSerializer()
            {
                NullValueHandling = NullValueHandling.Ignore
            };

            using (StreamWriter sw = getStreamWriter())
                using (JsonWriter writer = new JsonTextWriter(sw))
                {
                    serializer.Serialize(writer, tooling);
                }
        }
Example #2
0
        public static MDT.Tooling ToToolsData(this MMT.Tooling tooling)
        {
            var t = new MDT.Tooling()
            {
                Machine = Path.GetFileNameWithoutExtension(tooling.MachineFile),
                Tools   = Path.GetFileNameWithoutExtension(tooling.ToolsFile)
            };

            foreach (var item in tooling.Units)
            {
                t.Units.Add(item.ToData());
            }

            return(t);
        }
Example #3
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);
                                }
                            }
                        });
        protected override void SaveToolingCommandImplementation()
        {
            var dlg = ViewModels.Ioc.SimpleIoc <IFileDialog> .GetInstance("SaveFile");

            dlg.AddExtension = true;
            dlg.DefaultExt   = "jTooling";
            dlg.Filter       = "Tooling (JSON) |*.jTooling";

            var b = dlg.ShowDialog();

            if (b.HasValue && b.Value)
            {
                var id     = 0;
                var toolig = new MDTooling.Tooling()
                {
                    Machine = _lastMachineFile,
                    Tools   = _lastToolsFile
                };

                Messenger.Send(new SaveToolingMessage()
                {
                    AddToolUnit = (thId, tool) =>
                    {
                        toolig.Units.Add(new MDTooling.ToolingUnit()
                        {
                            ToolingUnitID = id++,
                            ToolHolderId  = thId,
                            ToolName      = tool
                        });
                    }
                });

                SaveTooling(dlg.FileName, toolig);

                _lastToolingFile = dlg.FileName;
            }
        }
 internal static void SaveTooling(string fileName, MDTooling.Tooling tooling) => SaveTooling(tooling, () => new StreamWriter(fileName));