Skip to content

Commit

Permalink
Merge pull request #3 from betato/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
betato authored Sep 17, 2020
2 parents fee0fea + f2e7c66 commit ca26c9f
Show file tree
Hide file tree
Showing 20 changed files with 403 additions and 191 deletions.
34 changes: 16 additions & 18 deletions RocketcadManager/CadComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,28 @@ public TreeNode GetNode()
thisNode.Text = ComponentFileInfo.Name;
if (!NameOk())
{
if (!HasInfo || MissingComponentError)
{
thisNode.ImageKey = "WarningErrorFile";
thisNode.SelectedImageKey = "WarningErrorFile";
}
if (MissingComponentError || LoadingError)
SetImageKey(thisNode, "WarningErrorFile");
else if (!HasInfo)
SetImageKey(thisNode, "WarningQuestionFile");
else
{
thisNode.ImageKey = "WarningFile";
thisNode.SelectedImageKey = "WarningFile";
}
}
else if (!HasInfo || MissingComponentError)
{
thisNode.ImageKey = "ErrorFile";
thisNode.SelectedImageKey = "ErrorFile";
SetImageKey(thisNode, "WarningFile");
}
else if (MissingComponentError || LoadingError)
SetImageKey(thisNode, "ErrorFile");
else if (!HasInfo)
SetImageKey(thisNode, "QuestionFile");
else
{
thisNode.ImageKey = "File";
thisNode.SelectedImageKey = "File";
}
SetImageKey(thisNode, "File");
return thisNode;
}

private void SetImageKey(TreeNode node, string imageKey)
{
node.ImageKey = imageKey;
node.SelectedImageKey = imageKey;
}

public virtual bool NameOk()
{
return Regex.IsMatch(ComponentFileInfo.Name, @"^([0-9]{2}-)+[0-9]{2}(\s.*)*\.(?i)(SLDASM|SLDPRT)(?-i)$");
Expand Down
25 changes: 11 additions & 14 deletions RocketcadManager/Folder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,28 @@ public TreeNode DirectoryTree()
thisNode.Text = Path.Name;

if (NameOk())
{
thisNode.ImageKey = "Folder";
thisNode.SelectedImageKey = "Folder";
}
SetImageKey(thisNode, "Folder");
else
{
thisNode.ImageKey = "WarningFolder";
thisNode.SelectedImageKey = "WarningFolder";
}
SetImageKey(thisNode, "WarningFolder");

foreach (Folder folder in subFolders)
{
thisNode.Nodes.Add(folder.DirectoryTree());
}

foreach (Assembly assembly in assemblies)
{
thisNode.Nodes.Add(assembly.GetNode());
}

foreach (Part part in parts)
{
thisNode.Nodes.Add(part.GetNode());
}

return thisNode;
}

private void SetImageKey(TreeNode node, string imageKey)
{
node.ImageKey = imageKey;
node.SelectedImageKey = imageKey;
}

public bool IsEmpty()
{
// Contains no parts or assemblies
Expand Down
40 changes: 40 additions & 0 deletions RocketcadManager/Icons.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions RocketcadManager/Icons.resx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@
<data name="OpenFolder" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\OpenFolder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="QuestionFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\QuestionFile16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="QuestionFolder" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\QuestionFolder16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Refresh" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\Refresh21.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand All @@ -154,6 +160,12 @@
<data name="WarningFolder" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\WarningFolder.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="WarningQuestionFile" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\WarningQuestionFile16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="WarningQuestionFolder" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\WarningQuestionFolder16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="Warnings" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\Warning20.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
54 changes: 26 additions & 28 deletions RocketcadManager/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ public MainForm()
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception ex = (Exception)e.ExceptionObject;
string logFile = LogWriter.Write("crash", new string[] { ex.StackTrace });
string logFile = LogWriter.Write(LogType.ManagerCrash, ex.StackTrace);
MessageBox.Show(ex.Message + (e.IsTerminating ? " The program will now close." : "") +
"\n\nStack trace written to: " + logFile, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

private Config config;
private ImageList iconList = new ImageList();

private Dictionary<string, Part> parts = new Dictionary<string, Part>();
private Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
Expand All @@ -41,19 +42,22 @@ private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionE

private void Form1_Load(object sender, EventArgs e)
{
ConfigLoader.Open(out config);
Config.Open(out config);

ImageList imageList = new ImageList();
imageList.ColorDepth = ColorDepth.Depth32Bit;
imageList.Images.Add("File", Icons.File);
imageList.Images.Add("Folder", Icons.Folder);
imageList.Images.Add("WarningFile", Icons.WarningFile);
imageList.Images.Add("WarningFolder", Icons.WarningFolder);
imageList.Images.Add("ErrorFile", Icons.ErrorFile);
imageList.Images.Add("ErrorFolder", Icons.ErrorFolder);
imageList.Images.Add("WarningErrorFile", Icons.WarningErrorFile);
imageList.Images.Add("WarningErrorFolder", Icons.WarningErrorFolder);
fileView.ImageList = imageList;
iconList.ColorDepth = ColorDepth.Depth32Bit;
iconList.Images.Add("File", Icons.File);
iconList.Images.Add("Folder", Icons.Folder);
iconList.Images.Add("WarningFile", Icons.WarningFile);
iconList.Images.Add("WarningFolder", Icons.WarningFolder);
iconList.Images.Add("ErrorFile", Icons.ErrorFile);
iconList.Images.Add("ErrorFolder", Icons.ErrorFolder);
iconList.Images.Add("WarningErrorFile", Icons.WarningErrorFile);
iconList.Images.Add("WarningErrorFolder", Icons.WarningErrorFolder);
iconList.Images.Add("QuestionFile", Icons.QuestionFile);
iconList.Images.Add("QuestionFolder", Icons.QuestionFolder);
iconList.Images.Add("WarningQuestionFile", Icons.WarningQuestionFile);
iconList.Images.Add("WarningQuestionFolder", Icons.WarningQuestionFolder);
fileView.ImageList = iconList;

LoadFiles();
}
Expand Down Expand Up @@ -85,11 +89,8 @@ private void LoadFiles()
{
fileView.Nodes.Add(cadFolder.DirectoryTree());
}
// Expand top-level nodes
foreach (TreeNode node in fileView.Nodes)
{
node.Expand();
}
// Expand nodes
config.LoadTreeViewExpansion(fileView.Nodes);

toolStripStatusLabel1.Text = "Ready";
}
Expand Down Expand Up @@ -309,14 +310,6 @@ private void fileView_AfterSelect(object sender, TreeViewEventArgs e)
SelectComponent((CadComponent)component);
}

private void textBoxStock_KeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar))
{
e.Handled = true;
}
}

private void SaveSelected()
{
// TODO: Add text checking
Expand All @@ -336,20 +329,25 @@ private void SaveSelected()
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
SaveSelected();
config.SaveTreeViewExpansion(fileView.Nodes);

Config.Save(config);
}

private void toolStripSettings_Click(object sender, EventArgs e)
{
SettingsForm settingsWindow = new SettingsForm(config);
if (settingsWindow.ShowDialog(this) == DialogResult.OK)
{
ConfigLoader.Save(config);
config.SaveTreeViewExpansion(fileView.Nodes);
Config.Save(config);
LoadFiles();
}
}

private void toolStripRefresh_Click(object sender, EventArgs e)
{
config.SaveTreeViewExpansion(fileView.Nodes);
LoadFiles();
}

Expand Down Expand Up @@ -440,7 +438,7 @@ private void toolStripWarnings_Click(object sender, EventArgs e)
List<CadComponent> cadComponents = new List<CadComponent>();
cadComponents.AddRange(parts.Values.ToList());
cadComponents.AddRange(assemblies.Values.ToList());
WarningsListForm warningsList = new WarningsListForm(cadComponents);
WarningsListForm warningsList = new WarningsListForm(cadComponents, iconList);
warningsList.ShowDialog(this);
}
}
Expand Down
Binary file added RocketcadManager/Resources/QuestionFile16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RocketcadManager/Resources/QuestionFolder16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RocketcadManager/Resources/WarningErrorFile16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RocketcadManager/Resources/WarningErrorFolder16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added RocketcadManager/Resources/WarningQuestionFile16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions RocketcadManager/RocketcadManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
</ItemGroup>
<ItemGroup>
<Content Include="largeicon.ico" />
<None Include="Resources\WarningQuestionFolder16.png" />
<None Include="Resources\WarningQuestionFile16.png" />
<None Include="Resources\WarningErrorFolder16.png" />
<None Include="Resources\WarningErrorFile16.png" />
<None Include="Resources\QuestionFolder16.png" />
<None Include="Resources\QuestionFile16.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
2 changes: 1 addition & 1 deletion RocketcadManager/WarningsListForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 38 additions & 19 deletions RocketcadManager/WarningsListForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,44 +14,63 @@ partial class WarningsListForm : Form
{
private List<CadComponent> cadComponents;

public WarningsListForm(List<CadComponent> cadComponents)
public WarningsListForm(List<CadComponent> cadComponents, ImageList imageList)
{
this.cadComponents = cadComponents;
InitializeComponent();
listViewWarnings.SmallImageList = imageList;
}

private void WarningsListForm_Load(object sender, EventArgs e)
{
foreach (CadComponent cadComponent in cadComponents)
{
string name = cadComponent.ComponentFileInfo.Name;
string file = cadComponent.ComponentFileInfo.FullName;
string[] entry = { name, null, file };
// Create error string
StringBuilder errorStrBuilder = new StringBuilder();
if (!cadComponent.NameOk())
errorStrBuilder.Append("Naming violation, ");
if (!cadComponent.HasInfo)
{
entry[1] = "Missing info file";
listViewWarnings.Items.Add(new ListViewItem(entry));
}
errorStrBuilder.Append("Missing info file, ");
if (cadComponent.MissingComponentError)
errorStrBuilder.Append("Referenced components not found, ");
if (cadComponent.LoadingError)
{
entry[1] = "Error loading info file";
listViewWarnings.Items.Add(new ListViewItem(entry));
}
errorStrBuilder.Append("Error loading info file, ");
if (errorStrBuilder.Length <= 0)
continue; // No errors
errorStrBuilder.Length -= 2; // Trim trailing comma and space
string errorStr = errorStrBuilder.ToString();

// Set error icons
// TODO: Combine this with the similar CadComponent method
if (!cadComponent.NameOk())
{
entry[1] = "Naming violation";
listViewWarnings.Items.Add(new ListViewItem(entry));
}
if (cadComponent.MissingComponentError)
{
entry[1] = "Referenced components not found";
listViewWarnings.Items.Add(new ListViewItem(entry));
if (cadComponent.MissingComponentError || cadComponent.LoadingError)
AddWarning(cadComponent, errorStr, "WarningErrorFile");
else if (!cadComponent.HasInfo)
AddWarning(cadComponent, errorStr, "WarningQuestionFile");
else
AddWarning(cadComponent, errorStr, "WarningFile");
}
else if (cadComponent.MissingComponentError || cadComponent.LoadingError)
AddWarning(cadComponent, errorStr, "ErrorFile");
else if (!cadComponent.HasInfo)
AddWarning(cadComponent, errorStr, "QuestionFile");
}
foreach (ColumnHeader column in listViewWarnings.Columns)
{
column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
}
}

private void AddWarning(CadComponent cadComponent, string message, string imageKey)
{
string name = cadComponent.ComponentFileInfo.Name;
string file = cadComponent.ComponentFileInfo.FullName;
string[] entry = { name, message, file };

ListViewItem listItem = new ListViewItem(entry);
listItem.ImageKey = imageKey;
listViewWarnings.Items.Add(listItem);
}
}
}
Loading

0 comments on commit ca26c9f

Please sign in to comment.