Skip to content

Commit

Permalink
Merge pull request #5 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 ca26c9f + 76c8a6c commit 6f170f8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 40 deletions.
3 changes: 1 addition & 2 deletions RocketcadManager/Assembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public TreeNode SubComponentTree()

public override bool NameOk()
{
// Assembly names must end with 00
return Regex.IsMatch(ComponentFileInfo.Name, @"^([0-9]{2}-)+00(\s.*)*\.(?i)SLDASM(?-i)$");
return Regex.IsMatch(ComponentFileInfo.Name, ConstantPaths.ValidAssemblyRegex);
}
}
}
48 changes: 29 additions & 19 deletions RocketcadManager/CadComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,36 @@ public CadComponent(FileInfo fileInfo, Folder parentFolder)
return cadInfo;
}

public TreeNode GetNode()
public string GetImageKey()
{
TreeNode thisNode = new TreeNode();
thisNode.Tag = this;
thisNode.Text = ComponentFileInfo.Name;
if (!NameOk())
if (!NameOk() || !LocationOk())
{
if (MissingComponentError || LoadingError)
SetImageKey(thisNode, "WarningErrorFile");
return "WarningErrorFile";
else if (!HasInfo)
SetImageKey(thisNode, "WarningQuestionFile");
return "WarningQuestionFile";
else
SetImageKey(thisNode, "WarningFile");
return "WarningFile";
}
else if (MissingComponentError || LoadingError)
SetImageKey(thisNode, "ErrorFile");
return "ErrorFile";
else if (!HasInfo)
SetImageKey(thisNode, "QuestionFile");
return "QuestionFile";
else
SetImageKey(thisNode, "File");
return thisNode;
return "File";
}

private void SetImageKey(TreeNode node, string imageKey)
public TreeNode GetNode()
{
node.ImageKey = imageKey;
node.SelectedImageKey = imageKey;
}
TreeNode thisNode = new TreeNode();
string imageKey = GetImageKey();

public virtual bool NameOk()
{
return Regex.IsMatch(ComponentFileInfo.Name, @"^([0-9]{2}-)+[0-9]{2}(\s.*)*\.(?i)(SLDASM|SLDPRT)(?-i)$");
thisNode.Tag = this;
thisNode.Text = ComponentFileInfo.Name;
thisNode.ImageKey = imageKey;
thisNode.SelectedImageKey = imageKey;

return thisNode;
}

public int UsageCount()
Expand All @@ -104,5 +102,17 @@ public TreeNode DependancyTree()
}

public abstract void Save();

public abstract bool NameOk();

public bool LocationOk()
{
if (ParentFolder == null)
return true;
if (ConstantPaths.IgnoreTopLevelFolders && ParentFolder.ParentFolder == null)
return true;
return Regex.Match(ParentFolder.Path.Name, ConstantPaths.ParentFolderRegex).Groups[1].Value
== Regex.Match(ComponentFileInfo.Name, ConstantPaths.ChildFileRegex).Groups[1].Value;
}
}
}
21 changes: 18 additions & 3 deletions RocketcadManager/Folder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using RocketcadManagerLib;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
Expand Down Expand Up @@ -30,7 +31,7 @@ public TreeNode DirectoryTree()
thisNode.Tag = this;
thisNode.Text = Path.Name;

if (NameOk())
if (NameOk() && LocationOk())
SetImageKey(thisNode, "Folder");
else
SetImageKey(thisNode, "WarningFolder");
Expand Down Expand Up @@ -61,7 +62,21 @@ public bool IsEmpty()

public bool NameOk()
{
return Regex.IsMatch(Path.Name, @"^([0-9]{2}-)+[0-9]{2}($|\s)");
// Ignore top level folders
if (ConstantPaths.IgnoreTopLevelFolders && ParentFolder == null)
return true;
return Regex.IsMatch(Path.Name, ConstantPaths.ValidFolderRegex);
}

public bool LocationOk()
{
if (ParentFolder == null)
return true;
// Ignore top level folders
if (ConstantPaths.IgnoreTopLevelFolders && ParentFolder.ParentFolder == null)
return true;
return Regex.Match(ParentFolder.Path.Name, ConstantPaths.ParentFolderRegex).Groups[1].Value
== Regex.Match(Path.Name, ConstantPaths.ChildFolderRegex).Groups[1].Value;
}
}
}
3 changes: 1 addition & 2 deletions RocketcadManager/Part.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ public override void Save()

public override bool NameOk()
{
// Part names cannot end with 00
return base.NameOk() && !Regex.IsMatch(ComponentFileInfo.Name, @"^([0-9]{2}-)+00(\s.*)*\.(?i)SLDASM(?-i)$");
return Regex.IsMatch(ComponentFileInfo.Name, ConstantPaths.ValidPartRegex);
}
}
}
17 changes: 3 additions & 14 deletions RocketcadManager/WarningsListForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ private void WarningsListForm_Load(object sender, EventArgs e)
StringBuilder errorStrBuilder = new StringBuilder();
if (!cadComponent.NameOk())
errorStrBuilder.Append("Naming violation, ");
if (!cadComponent.LocationOk())
errorStrBuilder.Append("Name does not match parent folder, ");
if (!cadComponent.HasInfo)
errorStrBuilder.Append("Missing info file, ");
if (cadComponent.MissingComponentError)
Expand All @@ -41,20 +43,7 @@ private void WarningsListForm_Load(object sender, EventArgs e)
string errorStr = errorStrBuilder.ToString();

// Set error icons
// TODO: Combine this with the similar CadComponent method
if (!cadComponent.NameOk())
{
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");
AddWarning(cadComponent, errorStr, cadComponent.GetImageKey());
}
foreach (ColumnHeader column in listViewWarnings.Columns)
{
Expand Down
9 changes: 9 additions & 0 deletions RocketcadManagerLib/ConstantPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,14 @@ public static class ConstantPaths

public static DirectoryInfo LogDir { get { return new DirectoryInfo(dataFolder + @"\logs"); } }
public static FileInfo ConfigFile { get { return new FileInfo(dataFolder + @"\config.json"); } }

public static readonly string ValidPartRegex = @"^([0-9]{2}-)+(0[1-9]|[1-9][0-9])(\s.*)?\.(?i)SLDPRT(?-i)$";
public static readonly string ValidAssemblyRegex = @"^([0-9]{2}-)+00(\s.*)?\.(?i)SLDASM(?-i)$";
public static readonly string ValidFolderRegex = @"^([0-9]{2}-)+[0-9]{2}($|\s)";

public static readonly string ParentFolderRegex = @"^(([0-9]{2}-)+[0-9]{2})";
public static readonly string ChildFolderRegex = @"^([0-9]{2}(-[0-9]{2})*)-[0-9]{2}($|\s)";
public static readonly string ChildFileRegex = @"^([0-9]{2}(-[0-9]{2})*)-[0-9]{2}(\s.*)?\.(?i)(SLDASM|SLDPRT)(?-i)$";
public static readonly bool IgnoreTopLevelFolders = true;
}
}

0 comments on commit 6f170f8

Please sign in to comment.