Skip to content

Commit

Permalink
Adjust save button to save to a predefined location if specified. Fix…
Browse files Browse the repository at this point in the history
… java formatting to match spotless.
  • Loading branch information
BytingBulldogs3539 committed Feb 5, 2024
1 parent 5de3cdd commit f14a9b5
Show file tree
Hide file tree
Showing 9 changed files with 406 additions and 55 deletions.
57 changes: 57 additions & 0 deletions Motion-Profile-Mapper/Motion-Profile-Mapper/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,70 @@
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="MotionProfileMapper.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
<section name="VelocityMap.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false"/>
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
<userSettings>
<MotionProfileMapper.Properties.Settings>
<setting name="IpAddress" serializeAs="String">
<value>10.35.39.2</value>
</setting>
<setting name="Username" serializeAs="String">
<value>lvuser</value>
</setting>
<setting name="Password" serializeAs="String">
<value />
</setting>
<setting name="RioLocation" serializeAs="String">
<value>/home/lvuser/profiles/</value>
</setting>
<setting name="FrameWidth" serializeAs="String">
<value>0.711</value>
</setting>
<setting name="MaxVel" serializeAs="String">
<value>2</value>
</setting>
<setting name="MaxAcc" serializeAs="String">
<value>1</value>
</setting>
<setting name="MaxRotVel" serializeAs="String">
<value>0</value>
</setting>
<setting name="MaxRotAcc" serializeAs="String">
<value>0</value>
</setting>
<setting name="MaxJerk" serializeAs="String">
<value>12</value>
</setting>
<setting name="SnapNewPaths" serializeAs="String">
<value>True</value>
</setting>
<setting name="INILocation" serializeAs="String">
<value>/home/lvuser/</value>
</setting>
<setting name="MaxCen" serializeAs="String">
<value>2.5</value>
</setting>
<setting name="FrameLength" serializeAs="String">
<value>0.711</value>
</setting>
<setting name="defaultAllianceIsRed" serializeAs="String">
<value>False</value>
</setting>
<setting name="iniSavePath" serializeAs="String">
<value />
</setting>
<setting name="javaSavePath" serializeAs="String">
<value />
</setting>
<setting name="mpSavePath" serializeAs="String">
<value />
</setting>
</MotionProfileMapper.Properties.Settings>
<VelocityMap.Properties.Settings>
<setting name="IpAddress" serializeAs="String">
<value>10.35.39.2</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ private Boolean validateINIS()
private void saveAllLocalButton_Click(object sender, EventArgs e)
{
if (validateINIS()) return;

SaveFileDialog browser = new SaveFileDialog();
browser.RestoreDirectory = true;
String files = "";
Expand All @@ -304,19 +305,34 @@ private void saveAllLocalButton_Click(object sender, EventArgs e)
browser.FileName = files;
browser.OverwritePrompt = false;

if (browser.ShowDialog() != DialogResult.OK) return;
String iniBasePath = "";
String javaBasePath = "";

Cursor = Cursors.WaitCursor;
if (!Directory.Exists(Properties.Settings.Default.javaSavePath) || !Directory.Exists(Properties.Settings.Default.iniSavePath))
{
if (browser.ShowDialog() != DialogResult.OK) return;
iniBasePath = Path.GetDirectoryName(browser.FileName.Trim());
javaBasePath = iniBasePath;
}
else
{
iniBasePath = Properties.Settings.Default.iniSavePath;
javaBasePath = Properties.Settings.Default.javaSavePath;
}

Cursor = Cursors.WaitCursor;
setStatus("Saving profiles to file system...", Color.Black);

List<string> paths = new List<string>();
List<INI> iniList = new List<INI>();



foreach (INI ini in inis)
{
string iniPath = Path.Combine(Path.GetDirectoryName(browser.FileName.Trim()), Path.GetFileNameWithoutExtension(ini.fileName) + ".ini");
string javaPath = Path.Combine(Path.GetDirectoryName(browser.FileName.Trim()), Path.GetFileNameWithoutExtension(ini.fileName) + ".java");
string iniPath = Path.Combine(iniBasePath, Path.GetFileNameWithoutExtension(ini.fileName) + ".ini");
string javaPath = Path.Combine(javaBasePath, Path.GetFileNameWithoutExtension(ini.fileName) + ".java");

if (browser.FilterIndex == 2)
{
paths.Add(iniPath);
Expand All @@ -335,7 +351,6 @@ private void saveAllLocalButton_Click(object sender, EventArgs e)
iniList.Add(ini);
}
}

bool yesToAll = false;
for (int i = 0; i < paths.Count; i++)
{
Expand Down Expand Up @@ -394,18 +409,27 @@ private void saveLocalButton_Click(object sender, EventArgs e)
browser.Title = "Save initialization file locally";
browser.OverwritePrompt = false;

String iniBasePath = "";
String javaBasePath = "";


if (browser.ShowDialog() != DialogResult.OK) return;
if (!Directory.Exists(Properties.Settings.Default.javaSavePath) || !Directory.Exists(Properties.Settings.Default.iniSavePath))
{
if (browser.ShowDialog() != DialogResult.OK) return;
iniBasePath = Path.GetDirectoryName(browser.FileName.Trim());
javaBasePath = iniBasePath;
}
else
{
iniBasePath = Properties.Settings.Default.iniSavePath;
javaBasePath = Properties.Settings.Default.javaSavePath;
}

Cursor = Cursors.WaitCursor;
string iniPath = Path.Combine(
Path.GetDirectoryName(browser.FileName.Trim()),
string iniPath = Path.Combine(iniBasePath,
selectedIni.fileName + ".ini"
);

string javaPath = Path.Combine(
Path.GetDirectoryName(browser.FileName.Trim()),
string javaPath = Path.Combine(javaBasePath,
selectedIni.fileName + ".java"
);

Expand Down Expand Up @@ -653,6 +677,11 @@ private void loadLocalButton_Click(object sender, EventArgs e)
fileDialog.Title = "Select initialization files to load";
fileDialog.Multiselect = true;

if (Directory.Exists(Properties.Settings.Default.iniSavePath))
{
fileDialog.InitialDirectory = Properties.Settings.Default.iniSavePath;
}

if (fileDialog.ShowDialog() != DialogResult.OK) return;

Cursor = Cursors.WaitCursor;
Expand Down
56 changes: 39 additions & 17 deletions Motion-Profile-Mapper/Motion-Profile-Mapper/Forms/MotionProfiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,22 +573,33 @@ private void SaveAllProfiles(object sender, EventArgs e)
FolderBrowserDialog browser = new FolderBrowserDialog();
browser.Description = "Save all motion profiles to folder\n\nCAUTION: Existing profiles will be overridden!";

if (browser.ShowDialog() != DialogResult.OK) return;
String mpBasePath = "";

if (!Directory.Exists(Properties.Settings.Default.javaSavePath) || !Directory.Exists(Properties.Settings.Default.iniSavePath))
{
if (browser.ShowDialog() != DialogResult.OK) return;
mpBasePath = System.IO.Path.GetDirectoryName(browser.SelectedPath);
}
else
{
mpBasePath = Properties.Settings.Default.mpSavePath;
}


Cursor = Cursors.WaitCursor;
setStatus("Saving profiles to file system...", false);
foreach (Profile profile in profiles)
{
string mpPath = System.IO.Path.Combine(browser.SelectedPath, profile.Name.Replace(' ', '_') + ".mp");
string javaPath = System.IO.Path.Combine(browser.SelectedPath, profile.Name.Replace(' ', '_') + ".java");
string mpPath = System.IO.Path.Combine(mpBasePath, profile.Name.Replace(' ', '_') + ".mp");
//string javaPath = System.IO.Path.Combine(mpBasePath, profile.Name.Replace(' ', '_') + ".java");
using (var writer = new StreamWriter(mpPath))
{
writer.Write(profile.toJSON().ToString());
}
using (var writer = new StreamWriter(javaPath))
{
writer.Write(profile.toJava());
}
//using (var writer = new StreamWriter(javaPath))
//{
// writer.Write(profile.toJava());
//}
}
setStatus("Profiles saved to file system", false);
Cursor = Cursors.Default;
Expand All @@ -607,13 +618,24 @@ private void SaveSelectedProfile(object sender, EventArgs e)
browser.Filter = "Motion Profile|*.mp;";
browser.Title = "Save motion profile file";

if (browser.ShowDialog() != DialogResult.OK || browser.FileName.Trim().Length <= 3) return;

String mpBasePath = "";

if (!Directory.Exists(Properties.Settings.Default.javaSavePath) || !Directory.Exists(Properties.Settings.Default.iniSavePath))
{
if (browser.ShowDialog() != DialogResult.OK || browser.FileName.Trim().Length <= 3) return;
mpBasePath = System.IO.Path.GetDirectoryName(browser.FileName.Trim());
}
else
{
mpBasePath = Properties.Settings.Default.mpSavePath;
}

Cursor = Cursors.WaitCursor;
setStatus("Saving profile to file system...", false);
// Write mp file to load from
string filePath = System.IO.Path.Combine(
System.IO.Path.GetDirectoryName(browser.FileName.Trim()),
mpBasePath,
System.IO.Path.GetFileNameWithoutExtension(browser.FileName.Trim()) + ".mp"
);
using (var writer = new StreamWriter(filePath))
Expand All @@ -622,14 +644,14 @@ private void SaveSelectedProfile(object sender, EventArgs e)
}

// Write java file to pre-compile into robot
string pointPath = System.IO.Path.Combine(
System.IO.Path.GetDirectoryName(browser.FileName.Trim()),
System.IO.Path.GetFileNameWithoutExtension(browser.FileName.Trim()) + ".java"
);
using (var writer = new StreamWriter(pointPath))
{
writer.Write(selectedProfile.toJava());
}
//string pointPath = System.IO.Path.Combine(
// System.IO.Path.GetDirectoryName(browser.FileName.Trim()),
// System.IO.Path.GetFileNameWithoutExtension(browser.FileName.Trim()) + ".java"
//);
//using (var writer = new StreamWriter(pointPath))
//{
// writer.Write(selectedProfile.toJava());
//}

setStatus("Profile saved to file system", false);
Cursor = Cursors.Default;
Expand Down
Loading

0 comments on commit f14a9b5

Please sign in to comment.