Skip to content

Commit

Permalink
Added support for Gerber files
Browse files Browse the repository at this point in the history
  • Loading branch information
lagnajeet committed Jul 14, 2018
1 parent 57b4d6d commit 1515e97
Show file tree
Hide file tree
Showing 18 changed files with 551 additions and 15 deletions.
14 changes: 14 additions & 0 deletions LP.SolidWorks.ECADWorksAddin/LP.SolidWorks.ECADWorksAddin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="Emgu.CV.World">
<HintPath>..\References\emgucv\Emgu.CV.World.dll</HintPath>
</Reference>
<Reference Include="GerberLibrary">
<HintPath>..\References\GerberLibrary\GerberLibrary.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\References\JSON.net\Newtonsoft.Json.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -73,6 +77,12 @@
<Compile Include="message.Designer.cs">
<DependentUpon>message.cs</DependentUpon>
</Compile>
<Compile Include="Progress.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Progress.Designer.cs">
<DependentUpon>Progress.cs</DependentUpon>
</Compile>
<Compile Include="TaskpaneHostUI.cs">
<SubType>UserControl</SubType>
</Compile>
Expand All @@ -81,6 +91,7 @@
</Compile>
<Compile Include="TaskpaneIntegration.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UtilityClass.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="componentsForm.resx">
Expand All @@ -89,6 +100,9 @@
<EmbeddedResource Include="message.resx">
<DependentUpon>message.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Progress.resx">
<DependentUpon>Progress.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="TaskpaneHostUI.resx">
<DependentUpon>TaskpaneHostUI.cs</DependentUpon>
</EmbeddedResource>
Expand Down
82 changes: 82 additions & 0 deletions LP.SolidWorks.ECADWorksAddin/Progress.Designer.cs

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

155 changes: 155 additions & 0 deletions LP.SolidWorks.ECADWorksAddin/Progress.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace LP.SolidWorks.BlankAddin
{
public partial class Progress : Form, GerberLibrary.ProgressLog
{
private List<string> Files;
Color SolderMaskColor;
Color SilkScreenColor;
Color CopperColor;
Color TracesColor;
public Progress(string zippedGerber, Color _SolderMaskColor, Color _SilkScreenColor, Color _CopperColor, Color _tracescolor)
{
SolderMaskColor = _SolderMaskColor;
SilkScreenColor = _SilkScreenColor;
CopperColor = _CopperColor;
TracesColor = _tracescolor;

InitializeComponent();
progressBar1.Value = 0;
Files = new List<string>();
Files.Add(zippedGerber);
}
Thread T = null;
internal void StartThread()
{
T = new Thread(new ThreadStart(doStuff));
T.Start();
}

public void doStuff()
{
GerberLibrary.GerberImageCreator GIC = new GerberLibrary.GerberImageCreator();
GerberLibrary.BoardRenderColorSet Colors = new GerberLibrary.BoardRenderColorSet();
Colors.BoardRenderColor = SolderMaskColor;
Colors.BoardRenderSilkColor = SilkScreenColor;
Colors.BoardRenderPadColor = CopperColor;
Colors.BoardRenderTraceColor = TracesColor;
SetProgress("Image generation started", -1);
GIC.SetColors(Colors);

GerberLibrary.Gerber.SaveIntermediateImages = false;


bool fixgroup = true;
string ext1 = Path.GetExtension(Files[0]);
if (Files.Count == 1 && ext1 != ".zip") fixgroup = false;
GIC.AddBoardsToSet(Files, fixgroup, this);

if (GIC.Errors.Count > 0)
{
foreach (var a in GIC.Errors)
{
Errors.Add(String.Format("Error: {0}", a));
}
}
try
{
if (GIC.Count() > 1)
{

if (Files.Count() == 1)
{
string justthefilename = Path.Combine(Path.GetDirectoryName(Files[0]), Path.GetFileNameWithoutExtension(Files[0]));
//GIC.WriteImageFiles(justthefilename, 200, false, this);
GIC.WriteImageToMemory(justthefilename,ref UtilityClass.TopDecal,ref UtilityClass.BottomDecal, 1000, this);
}
}
}
catch(Exception E)
{
Errors.Add("Some errors:");
while(E!=null)
{
Errors.Add(E.Message);
E = E.InnerException;
}
}
SetProgress("Done!",100);
if (Errors.Count > 0)
{
SetProgress("Encountered some problems during image generation:", -1);
}
foreach (var a in Errors)
{
SetProgress(a, -1);
}

}
List<String> Errors = new List<string>();
private void timer1_Tick(object sender, EventArgs e)
{
if (T == null) return;
if (T.ThreadState == ThreadState.Stopped && Errors.Count == 0)
{
this.Close();

}
}

public void AddString(string text, float progress = -1F)
{
SetProgress(text, progress);

}

delegate void UpdateBar(string text, float progress);

private void SetProgress(string text, float progress)
{

if (this.progressBar1.InvokeRequired)
{
UpdateBar d = new UpdateBar(SetProgress);
this.Invoke(d, new object[] { text, progress });
}
else
{

if (progress >= 100)
{
progressBar1.Value = 100;
this.ControlBox = true;
}
else
{

int temp = progressBar1.Value;
temp += 2;
if (temp >= 100)
{
temp = 100;
this.ControlBox = true;
}
else
this.ControlBox = false;
progressBar1.Value = temp;
}
textBox1.Text = text + "\r\n" + textBox1.Text;
}
}


}
}
Loading

0 comments on commit 1515e97

Please sign in to comment.