/// <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."); } }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Move a set of axes /// </summary> /// <returns></returns> public void MoveToPresetPosition(MassMoveArgs Args) { throw new NotImplementedException(); }