Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artwork + DRC #105

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions inkscape/svg2shenzhen/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,15 @@ def add_arguments(self, pars):
pars.add_argument("--threshold", type=float, default=128.0)
pars.add_argument("--openfactory", type=inkex.Boolean, default="true")
pars.add_argument("--openkicad", type=inkex.Boolean, default="true")
pars.add_argument("--centermodule", type=inkex.Boolean, default=True)
pars.add_argument("--createpads", type=inkex.Boolean, default=False)
pars.add_argument("--autoflatten", type=inkex.Boolean, default="true")
pars.add_argument("--debug", type=inkex.Boolean, default=False)

def coordToKicad(self,XYCoord):
return [
(XYCoord[0]-self.bb_width_center)/self.bb_scaling_w,
(XYCoord[1]-self.bb_height_center)/self.bb_scaling_h,
(XYCoord[0]-(self.bb_width_center if self.options.centermodule else 0))/self.bb_scaling_w,
(XYCoord[1]-(self.bb_height_center if self.options.centermodule else 0))/self.bb_scaling_h,
]

def setInkscapeScaling(self):
Expand Down Expand Up @@ -390,7 +392,9 @@ def processExportLayer(self):
'path': options.path,
'crop': options.crop,
'filetype': options.filetype,
'threshold': options.threshold
'threshold': options.threshold,
'centermodule': options.centermodule,
'createpads': options.createpads
}

if os.path.exists(options_path):
Expand Down Expand Up @@ -454,11 +458,13 @@ def processExportLayer(self):
os.remove(layer_dest_svg_path)

if options.filetype == "kicad_pcb" or options.filetype == "kicad_module":
center = "true" if self.options.centermodule else "false"
createPads = "true" if self.options.createpads else "false"
for i in range(0, len(layer_arguments), EXPORT_KICAD_MAX_PROCESSES):
processes = []
for _, layer_dest_png_path, layer_dest_kicad_path, layer_label, invert in layer_arguments[i:i+EXPORT_KICAD_MAX_PROCESSES]:
#export layer png to kicad
p = self.exportToKicad(layer_dest_png_path, layer_dest_kicad_path, layer_label, invert)
p = self.exportToKicad(layer_dest_png_path, layer_dest_kicad_path, layer_label, invert, center, createPads)
processes.append(p)
for p in processes:
p.communicate()
Expand Down Expand Up @@ -579,7 +585,7 @@ def openKicad(self, kicad_file_path):



def exportToKicad(self, png_path, output_path, layer_type, invert = "true"):
def exportToKicad(self, png_path, output_path, layer_type, invert = "true", center = "true", createPads = "false"):
plugin_path = os.path.dirname(os.path.abspath(__file__))

platform_system = platform.system()
Expand All @@ -592,7 +598,7 @@ def exportToKicad(self, png_path, output_path, layer_type, invert = "true"):
bitmap2component_exe = os.path.join(plugin_path, 'bitmap2component.exe')

layer_name = self.layer_map[layer_type]
command = "\"%s\" \"%s\" \"%s\" %s %s %s %s" % (bitmap2component_exe, png_path, output_path, layer_name, invert , str(int(self.options.dpi)) , str(int(self.options.threshold)))
command = "\"%s\" \"%s\" \"%s\" %s %s %s %s %s %s" % (bitmap2component_exe, png_path, output_path, layer_name, invert , str(int(self.options.dpi)) , str(int(self.options.threshold)), center, createPads )
if (self.options.debug):
inkex.utils.debug(command)
return subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Expand Down
3 changes: 3 additions & 0 deletions inkscape/svg2shenzhen_export.inx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<param name="threshold" type="int" min="0" max="255" _gui-text="Threshold (!)" _gui-description="Default: 5 - Define the threshold the black and white will have.">5</param>
<param name="dpi" type="int" min="0" max="10000" _gui-text="Export DPI (!)" _gui-description="Default: 1200 - Define the Dots Per Inch to Export the Layers at, recommended is 1,200, max is 10,000. Below 1,200 you may see artifacts due to the low resolution.">1200</param>
<separator />
<param name="centermodule" type="boolean" _gui-text="Center Module (!)" _gui-description="Select this option if you would like the origin of module(s) to be centered instead of the top left corner.">true</param>
<param name="createpads" type="boolean" _gui-text="Create Metal Pads (!)" _gui-description="Select this option if you want all copper layers to be converted to pads.">false</param>
<param name="autoflatten" type="boolean" _gui-text="Flatten Bezier (!)" _gui-description="Select this option if you have not flattened the Bezier Curves on your Edge.Cut layer. If this is not the first time you have exported this drawing do not check this option.">false</param>
<separator />
<param name="openfactory" type="boolean" gui-text="Open PCBWay (!)" _gui-description="Opens the PCBWay website with an affiliate link for you to submit an order.">false</param>
<param name="openkicad" type="boolean" gui-text="Open KiCad (!)" _gui-description="Opens the KiCad for you.">false</param>
<param name="debug" type="boolean" _gui-text="Debug Mode" _gui-description="Only necessary for troubleshooting.">false</param>
Expand Down
67 changes: 55 additions & 12 deletions src/bitmap2component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class BITMAPCONV_INFO
potrace_path_t* m_Paths; // the list of paths, from potrace (list of lines and bezier curves)
FILE* m_Outfile; // File to create
const char * m_CmpName; // The string used as cmp/footprint name
bool m_CenterOrigin;
bool m_CreatePads;

public:
BITMAPCONV_INFO();
Expand Down Expand Up @@ -134,7 +136,8 @@ BITMAPCONV_INFO::BITMAPCONV_INFO()

int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE* aOutfile,
OUTPUT_FMT_ID aFormat, int aDpi_X, int aDpi_Y,
BMP2CMP_MOD_LAYER aModLayer, const char * aLayerName = NULL )
BMP2CMP_MOD_LAYER aModLayer, const char * aLayerName = NULL,
bool center = true, bool createPad = false)
{
potrace_param_t* param;
potrace_state_t* st;
Expand Down Expand Up @@ -168,6 +171,8 @@ int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE* aOutfile,
BITMAPCONV_INFO info;
info.m_PixmapWidth = aPotrace_bitmap->w;
info.m_PixmapHeight = aPotrace_bitmap->h; // the bitmap size in pixels
info.m_CreatePads = createPad;
info.m_CenterOrigin = center;
info.m_Paths = st->plist;
info.m_Outfile = aOutfile;

Expand Down Expand Up @@ -343,8 +348,14 @@ void BITMAPCONV_INFO::OuputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char*
int ii, jj;
VECTOR2I currpoint;

int offsetX = (int)( m_PixmapWidth / 2 * m_ScaleX );
int offsetY = (int)( m_PixmapHeight / 2 * m_ScaleY );
int offsetX = 0;
int offsetY = 0;

if(m_CenterOrigin)
{
offsetX = (int)( m_PixmapWidth / 2 * m_ScaleX );
offsetY = (int)( m_PixmapHeight / 2 * m_ScaleY );
}

const VECTOR2I startpoint = aPolygon.CPoint( 0 );

Expand Down Expand Up @@ -374,27 +385,59 @@ void BITMAPCONV_INFO::OuputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char*
case PCBNEW_KICAD_MOD:
{
double width = 0.01; // outline thickness in mm
fprintf( m_Outfile, " (fp_poly (pts" );

const char* copper = "Cu";
const char* indent = " ";
bool createPad = false;

if(m_CreatePads && strstr(aBrdLayerName, copper) != nullptr)
{
fprintf( m_Outfile, " (pad 1 smd custom (at " );
indent = " ";
createPad = true;
}
else
{
fprintf( m_Outfile, " (fp_poly (pts" );
}

jj = 0;
double originX = 0;
double originY = 0;
for( ii = 0; ii < aPolygon.PointCount(); ii++ )
{
currpoint = aPolygon.CPoint( ii );
if( createPad && ii == 0)
{
originX = ( currpoint.x - offsetX ) / 1e6;
originY = ( currpoint.y - offsetY ) / 1e6;
fprintf( m_Outfile, "%f %f) (size %f %f) (layers %s)\n (zone_connect 0)\n (options (clearance outline) (anchor circle))\n (primitives\n (gr_poly (pts\n ",
originX, originY, width, width, aBrdLayerName );
}
fprintf( m_Outfile, " (xy %f %f)",
( currpoint.x - offsetX ) / 1e6,
( currpoint.y - offsetY ) / 1e6 );

( ( currpoint.x - offsetX ) / 1e6 ) - originX,
( ( currpoint.y - offsetY ) / 1e6 ) - originY );
if( jj++ > 6 )
{
jj = 0;
fprintf( m_Outfile, ("\n ") );
fprintf( m_Outfile, " \n%s", indent );
}
}
// Close polygon
fprintf( m_Outfile, " (xy %f %f) )",
( startpoint.x - offsetX ) / 1e6, ( startpoint.y - offsetY ) / 1e6 );

fprintf( m_Outfile, "(layer %s) (width %f)\n )\n", aBrdLayerName, width );
if( createPad )
{
fprintf( m_Outfile, " (xy %f %f) )",
( ( startpoint.x - offsetX ) / 1e6 ) - originX, ( ( startpoint.y - offsetY ) / 1e6 ) - originY );

fprintf( m_Outfile, "(width %f) )\n ))\n", width );
}
else
{
fprintf( m_Outfile, " (xy %f %f) )",
( startpoint.x - offsetX ) / 1e6, ( startpoint.y - offsetY ) / 1e6 );

fprintf( m_Outfile, "(layer %s) (width %f)\n )\n", aBrdLayerName, width );
}

}
break;
Expand Down
27 changes: 23 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ using namespace std;

extern int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE* aOutfile,
OUTPUT_FMT_ID aFormat, int aDpi_X, int aDpi_Y,
BMP2CMP_MOD_LAYER aModLayer, const char * layer_name = NULL );
BMP2CMP_MOD_LAYER aModLayer, const char * layer_name = NULL,
bool center = true, bool createPad = false );


string pcb_header = "(kicad_pcb (version 4) (host pcbnew 4.0.7)"
Expand Down Expand Up @@ -125,7 +126,7 @@ void showUsage()
cout<<" bitmap2component-cli "<<endl;
cout<<"" << endl;
cout<<" Usage"<<endl;
cout<<" ./bitmap2component <filename.png> <output filename> <layer> <negative|true/false> <dpi> <threshold|0-255>"<<endl;
cout<<" ./bitmap2component <filename.png> <output filename> <layer> <negative|true/false> <dpi> <threshold|0-255> <center|true/false> <create pads|true/false>"<<endl;
cout<<"\n\n\n" << endl;
}

Expand All @@ -137,6 +138,8 @@ int main(int argc, char* argv[])
int dpi = 600;
string image_filename;
string output_filename;
bool center = true;
bool createPad = false;


BMP2CMP_MOD_LAYER kicad_output_layer = MOD_LYR_FCU;
Expand Down Expand Up @@ -170,6 +173,22 @@ int main(int argc, char* argv[])
threshold = stoi(string(argv[6]));
}

if (argc > 7){
if (string(argv[7]) == "true"){
center = true;
}else{
center = false;
}
}

if (argc > 8){
if (string(argv[8]) == "true"){
createPad = true;
}else{
createPad = false;
}
}

printf("[bitmap2component] Filename %s\n", image_filename.c_str());

FILE * pFile;
Expand Down Expand Up @@ -233,12 +252,12 @@ int main(int argc, char* argv[])
printf("[bitmap2component] Trace image\n");

// fprintf(pFile, pcb_header.c_str());
bitmap2component( potrace_bitmap, pFile, PCBNEW_KICAD_MOD, dpi, dpi, kicad_output_layer, layer_name );
bitmap2component( potrace_bitmap, pFile, PCBNEW_KICAD_MOD, dpi, dpi, kicad_output_layer, layer_name, center, createPad);
// fprintf(pFile, pcb_footer.c_str());


fclose( pFile );

printf("[bitmap2component] Done\n");

}
}