示例#1
0
        private bool CheckProfileExistance(LogicalMotionComponent MotionComponent, string FileName)
        {
            // the full file path where we should find the preset profiles
            var fullFilePath = PRESET_FOLDER + "\\" + MotionComponent.HashString + "\\" + FileName + ".json";

            return(File.Exists(fullFilePath));
        }
示例#2
0
        /// <summary>
        /// Load the preset position file of the specified logical motion controller by the file name
        /// </summary>
        /// <param name="LogicalMotionController"></param>
        /// <param name="FileName"></param>
        public MassMoveArgs LoadProfile(LogicalMotionComponent MotionComponent, string FileName)
        {
            // the full file path where we should find the preset profiles
            var fullFilePath = PRESET_FOLDER + "\\" + MotionComponent.HashString + "\\" + FileName + ".json";

            if (File.Exists(fullFilePath) == true)
            {
                var json = File.ReadAllText(fullFilePath, new UTF8Encoding());

                var arg = MassMoveArgs.FromJsonString(json);

                if (arg.LogicalMotionComponent != MotionComponent.HashString)
                {
                    // if the logical motion component of the loaded preset profile does not
                    // match the one selected on the window.
                    throw new FormatException("it does not match with the selected motion component.");
                }
                else
                {
                    return(arg);
                }
            }
            else
            {
                // the folder does not exist
                throw new FileNotFoundException($"the preset profile {FileName} is not found.");
            }
        }
示例#3
0
        /// <summary>
        /// Load the preset position file of the specified logical motion controller by the file name
        /// </summary>
        /// <param name="LogicalMotionController"></param>
        /// <param name="FileName"></param>
        public MassMoveArgs LoadProfile(LogicalMotionComponent MotionComponent, string FileName)
        {
            // the full file path where we should find the preset profiles
            var fullFilePath = PRESET_FOLDER + "\\" + MotionComponent.GetHashString() + "\\" + FileName + ".json";

            if (File.Exists(fullFilePath) == true)
            {
                var json = File.ReadAllText(fullFilePath, new UTF8Encoding());

                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.Converters.Add(new MassMoveArgsConverter());
                var args = JsonConvert.DeserializeObject <MassMoveArgs>(json, new MassMoveArgsConverter());

                if (args.LogicalMotionComponent != MotionComponent.GetHashString())
                {
                    throw new FormatException("it does not match with the selected motion component.");
                }
                else if (args.HashString != args.GetHashString())
                {
                    throw new FormatException("it might be modified unexpectedly.");
                }
                else
                {
                    return(args);
                }
            }
            else
            {
                // the folder does not exist
                throw new FileNotFoundException($"{fullFilePath} does not exist.");
            }
        }
示例#4
0
        /// <summary>
        /// load the current positions of the specified logical motion component
        /// </summary>
        /// <param name="MotionComponent"></param>
        /// <returns></returns>
        private MassMoveArgs LoadRealtimePosition(LogicalMotionComponent MotionComponent)
        {
            // generate the mass move argument as the binding source of the preset window.
            MassMoveArgs arg = new MassMoveArgs();

            foreach (var laxis in MotionComponent)
            {
                var a = laxis.MoveArgs.Clone() as AxisMoveArgs;
                a.Distance   = laxis.PhysicalAxisInst.UnitHelper.RelPosition;
                a.IsMoveable = true;
                a.MoveOrder  = 1;
                arg.Add(a);
            }

            arg.LogicalMotionComponent = MotionComponent.HashString;

            return(arg);
        }
示例#5
0
        /// <summary>
        /// load the current positions of the specified logical motion component
        /// </summary>
        /// <param name="MotionComponent"></param>
        /// <returns></returns>
        private MassMoveArgs LoadCurrentPositions(LogicalMotionComponent MotionComponent)
        {
            // generate the move args list to bind to the window
            MassMoveArgs arg = new MassMoveArgs()
            {
            };

            foreach (var laxis in MotionComponent)
            {
                var a = laxis.MoveArgs.Clone() as AxisMoveArgs;
                a.Distance   = laxis.PhysicalAxisInst.UnitHelper.RelPosition;
                a.IsMoveable = true;
                a.MoveOrder  = 1;
                arg.Add(a);
            }

            arg.LogicalMotionComponent = MotionComponent.GetHashString();

            return(arg);
        }
示例#6
0
        /// <summary>
        /// Save the preset position profile
        /// </summary>
        /// <param name="Arg"></param>
        /// <param name="FileName"></param>
        private void SaveProfile(LogicalMotionComponent MotionComponent, MassMoveArgs Arg, string FileName)
        {
            if (MotionComponent == null)
            {
                throw new InvalidDataException("the logical motion controller is empty.");
            }

            if (FileName == null || FileName == "")
            {
                throw new ArgumentException("the name of profile can not be empty.");
            }

            if (FileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                throw new InvalidDataException("the name of profile contains invalid chars.");
            }

            // if the directory does not exist, create it.
            var dir = PRESET_FOLDER + "\\" + MotionComponent.HashString;

            if (Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }

            // the full file path where we should find the preset profiles
            //var fullFilePath = PRESET_FOLDER + "\\" + MotionComponent.HashString + "\\" + FileName + ".json";

            var jsonstr = MassMoveArgs.ToJsonString(Arg);


            File.WriteAllText($"{dir}\\{FileName}.json", jsonstr, new UTF8Encoding());

            // reload the position preset profile list
            LoadProfilesList(MotionComponent);
        }
示例#7
0
        /// <summary>
        /// Load the profiles which belong to the selected logical motion component
        /// </summary>
        /// <returns></returns>
        private void LoadProfilesList(LogicalMotionComponent MotionComponent)
        {
            var dir = PRESET_FOLDER + "\\" + MotionComponent.HashString;

            if (Directory.Exists(dir))
            {
                List <string> profiles = new List <string>();

                DirectoryInfo info = new DirectoryInfo(dir);
                foreach (var file in info.GetFiles())
                {
                    if (file.Extension == ".json")
                    {
                        profiles.Add(Path.GetFileNameWithoutExtension(file.FullName));
                    }
                }

                ProfileList = profiles.ToArray();
            }
            else
            {
                ProfileList = null;
            }
        }
示例#8
0
        /// <summary>
        /// Save the preset position profile
        /// </summary>
        /// <param name="Args"></param>
        /// <param name="FileName"></param>
        private void SaveProfile(LogicalMotionComponent MotionComponent, MassMoveArgs Args, string FileName)
        {
            if (MotionComponent == null)
            {
                throw new InvalidDataException("the logical motion controller is empty.");
            }

            if (FileName.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)
            {
                throw new InvalidDataException("the name of profile contains invalid chars.");
            }

            // if the directory does not exist, create it.
            var dir = PRESET_FOLDER + "\\" + MotionComponent.GetHashString();

            if (Directory.Exists(dir) == false)
            {
                Directory.CreateDirectory(dir);
            }

            // the full file path where we should find the preset profiles
            var fullFilePath = PRESET_FOLDER + "\\" + MotionComponent.GetHashString() + "\\" + FileName + ".json";

            // calculate the hash string which is used to check whether the profile is modified
            Args.HashString = Args.GetHashString();

            JsonSerializerSettings settings = new JsonSerializerSettings();

            settings.Converters.Add(new MassMoveArgsConverter());
            var json = JsonConvert.SerializeObject(Args, settings);

            File.WriteAllText(fullFilePath, json, new UTF8Encoding());

            // reload the position preset profile list
            LoadProfilesList(MotionComponent);
        }