diff --git a/inkscape/svg2shenzhen/export.py b/inkscape/svg2shenzhen/export.py index ec721ed..36101de 100644 --- a/inkscape/svg2shenzhen/export.py +++ b/inkscape/svg2shenzhen/export.py @@ -241,22 +241,33 @@ def __init__(self): self.bb_scaling_h = 0 self.layer_map = { - #'inkscape-name' : kicad-name, - 'F.Cu' : "F.Cu", - 'B.Cu' : "B.Cu", - # 'Adhes' : "{}.Adhes", - # 'Paste' : "{}.Paste", - 'F.Silk' : "F.Silk", - 'B.Silk' : "B.Silk", - 'F.Mask' : "F.Mask", - 'B.Mask' : "B.Mask", - # 'CrtYd' : "{}.CrtYd", - # 'Fab' : "{}.Fab", + #'inkscape-name' : 'kicad-name', + 'F.Cu' : 'F.Cu', + 'B.Cu' : 'B.Cu', + 'B.Adhes' : 'B.Adhes', + 'F.Adhes' : 'F.Adhes', + 'B.Paste' : 'B.Paste', + 'F.Paste' : 'F.Paste', + 'B.SilkS' : 'B.SilkS', + 'F.SilkS' : 'F.SilkS', + 'B.Mask' : 'B.Mask', + 'F.Mask' : 'F.Mask', + 'Dwgs.User' : 'Dwgs.User', + 'Cmts.User' : 'Cmts.User', + 'Eco1.User' : 'Eco1.User', + 'Eco2.User' : 'Eco2.User', + 'Margin' : 'Margin', + 'B.CrtYd' : 'B.CrtYd', + 'F.CrtYd' : 'F.CrtYd', + 'B.Fab' : 'B.Fab', + 'F.Fab' : 'F.Fab', + # The following layers are here for backward compatibility: + 'B.Silk' : 'B.SilkS', + 'F.Silk' : 'F.SilkS', # 'Edge.Cuts' : "Edge.Cuts" } - def coordToKicad(self,XYCoord): return [ (XYCoord[0]-self.bb_width_center)/self.bb_scaling_w, @@ -573,7 +584,8 @@ def exportToKicad(self, png_path, output_path, layer_type, invert = "true"): else: bitmap2component_exe = os.path.join(plugin_path, 'bitmap2component.exe') - command = "\"%s\" \"%s\" \"%s\" %s %s %s %s" % (bitmap2component_exe, png_path, output_path, layer_type, invert , str(int(self.options.dpi)) , str(int(self.options.threshold))) + 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))) if (self.options.debug): inkex.debug(command) return subprocess.Popen(command.encode("utf-8"), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) diff --git a/inkscape/svg2shenzhen/prepare.py b/inkscape/svg2shenzhen/prepare.py index fe94943..d7ea5b8 100644 --- a/inkscape/svg2shenzhen/prepare.py +++ b/inkscape/svg2shenzhen/prepare.py @@ -132,26 +132,65 @@ def prepareDocument(self): rect = self.createWhitebg() white_layer.append(rect) - if ("Edge.Cuts" not in layers): - self.createLayer("Edge.Cuts") + if ("F.Cu" not in layers and "F.Cu-disabled" not in layers): + self.createLayer("F.Cu") if ("B.Cu-disabled" not in layers and "B.Cu" not in layers): self.createLayer("B.Cu-disabled") - if ("B.Mask-disabled" not in layers and "B.Mask" not in layers): - self.createLayer("B.Mask-disabled") + if ("B.Adhes-disabled" not in layers and "B.Adhes" not in layers): + self.createLayer("B.Adhes-disabled") - if ("B.Silk-disabled" not in layers and "B.Silk" not in layers): - self.createLayer("B.Silk-disabled") + if ("F.Adhes-disabled" not in layers and "F.Adhes" not in layers): + self.createLayer("F.Adhes-disabled") - if ("F.Cu" not in layers and "F.Cu-disabled" not in layers): - self.createLayer("F.Cu") + if ("B.Paste-disabled" not in layers and "B.Paste" not in layers): + self.createLayer("B.Paste-disabled") + + if ("F.Paste-disabled" not in layers and "F.Paste" not in layers): + self.createLayer("F.Paste-disabled") + + if ("B.SilkS-disabled" not in layers and "B.SilkS" not in layers): + self.createLayer("B.SilkS-disabled") + + if ("F.SilkS-disabled" not in layers and "F.SilkS" not in layers): + self.createLayer("F.SilkS-disabled") + + if ("B.Mask-disabled" not in layers and "B.Mask" not in layers): + self.createLayer("B.Mask-disabled") if ("F.Mask-disabled" not in layers and "F.Mask" not in layers): self.createLayer("F.Mask-disabled") - if ("F.Silk-disabled" not in layers and "F.Silk" not in layers): - self.createLayer("F.Silk-disabled") + if ("Dwgs.User-disabled" not in layers and "Dwgs.User" not in layers): + self.createLayer("Dwgs.User-disabled") + + if ("Cmts.User-disabled" not in layers and "Cmts.User" not in layers): + self.createLayer("Cmts.User-disabled") + + if ("Eco1.User-disabled" not in layers and "Eco1.User" not in layers): + self.createLayer("Eco1.User-disabled") + + if ("Eco2.User-disabled" not in layers and "Eco2.User" not in layers): + self.createLayer("Eco2.User-disabled") + + if ("Edge.Cuts" not in layers): + self.createLayer("Edge.Cuts") + + if ("Margin-disabled" not in layers and "Margin" not in layers): + self.createLayer("Margin-disabled") + + if ("B.CrtYd-disabled" not in layers and "B.CrtYd" not in layers): + self.createLayer("B.CrtYd-disabled") + + if ("F.CrtYd-disabled" not in layers and "F.CrtYd" not in layers): + self.createLayer("F.CrtYd-disabled") + + if ("B.Fab-disabled" not in layers and "B.Fab" not in layers): + self.createLayer("B.Fab-disabled") + + if ("F.Fab-disabled" not in layers and "F.Fab" not in layers): + self.createLayer("F.Fab-disabled") if ("Drill" not in layers): self.createLayer("Drill") diff --git a/src/bitmap2component.cpp b/src/bitmap2component.cpp index b8ea758..bbdd6cf 100644 --- a/src/bitmap2component.cpp +++ b/src/bitmap2component.cpp @@ -80,7 +80,7 @@ class BITMAPCONV_INFO * Creates the output file specified by m_Outfile, * depending on file format given by m_Format */ - void CreateOutputFile( BMP2CMP_MOD_LAYER aModLayer = (BMP2CMP_MOD_LAYER) 0 ); + void CreateOutputFile( BMP2CMP_MOD_LAYER aModLayer = (BMP2CMP_MOD_LAYER) 0, const char * aLayerName = NULL ); private: @@ -134,7 +134,7 @@ 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 ) + BMP2CMP_MOD_LAYER aModLayer, const char * aLayerName = NULL ) { potrace_param_t* param; potrace_state_t* st; @@ -201,7 +201,7 @@ int bitmap2component( potrace_bitmap_t* aPotrace_bitmap, FILE* aOutfile, info.m_ScaleX = 1e6 * 25.4 / aDpi_X; // the conversion scale from PPI to UI info.m_ScaleY = 1e6 * 25.4 / aDpi_Y; // Y axis is top to bottom in modedit - info.CreateOutputFile( aModLayer ); + info.CreateOutputFile( aModLayer, aLayerName ); break; default: @@ -440,7 +440,7 @@ void BITMAPCONV_INFO::OuputOnePolygon( SHAPE_LINE_CHAIN & aPolygon, const char* } -void BITMAPCONV_INFO::CreateOutputFile( BMP2CMP_MOD_LAYER aModLayer ) +void BITMAPCONV_INFO::CreateOutputFile( BMP2CMP_MOD_LAYER aModLayer, const char * aLayerName ) { std::vector cornersBuffer; @@ -538,7 +538,7 @@ void BITMAPCONV_INFO::CreateOutputFile( BMP2CMP_MOD_LAYER aModLayer ) for( int ii = 0; ii < polyset_areas.OutlineCount(); ii++ ) { SHAPE_LINE_CHAIN& poly = polyset_areas.Outline( ii ); - OuputOnePolygon(poly, getBrdLayerName( aModLayer ) ); + OuputOnePolygon(poly, aLayerName != NULL ? aLayerName : getBrdLayerName( aModLayer ) ); } polyset_areas.RemoveAllContours(); diff --git a/src/main.cpp b/src/main.cpp index e4307c7..8aa231f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,7 +15,7 @@ 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 ); + BMP2CMP_MOD_LAYER aModLayer, const char * layer_name = NULL ); string pcb_header = "(kicad_pcb (version 4) (host pcbnew 4.0.7)" @@ -139,7 +139,8 @@ int main(int argc, char* argv[]) string output_filename; - BMP2CMP_MOD_LAYER kicad_output_layer; + BMP2CMP_MOD_LAYER kicad_output_layer = MOD_LYR_FCU; + const char * layer_name = NULL; showUsage(); @@ -149,21 +150,7 @@ int main(int argc, char* argv[]) output_filename = string(argv[2]); if (argc > 3){ - string layer_name = string(argv[3]); - if (layer_name == "F.Cu" ) - kicad_output_layer = MOD_LYR_FCU; - else if(layer_name == "B.Cu") - kicad_output_layer = MOD_LYR_BCU; - else if(layer_name == "F.Mask") - kicad_output_layer = MOD_LYR_FMASK; - else if(layer_name == "B.Mask") - kicad_output_layer = MOD_LYR_BMASK; - else if(layer_name == "F.Silk") - kicad_output_layer = MOD_LYR_FSILKS; - else if(layer_name == "B.Silk") - kicad_output_layer = MOD_LYR_BSILKS; - else - kicad_output_layer = MOD_LYR_FCU; + layer_name = argv[3]; } @@ -246,7 +233,7 @@ 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 ); + bitmap2component( potrace_bitmap, pFile, PCBNEW_KICAD_MOD, dpi, dpi, kicad_output_layer, layer_name ); // fprintf(pFile, pcb_footer.c_str());