Esempio n. 1
0
    def _create_bottom_mask(self):
        print("Drawing bottom mask from {0}".format(self.layers.bottommask))
        bottom_mask_sketch = self._create_sketch_on_face(
            'Bottom_Mask_Sketch',
            self._output_file.PCB_Body,
            self._get_bottom_face(self._output_file.PCB_Body)
        )
        ctx = GerberFreecadContext()
        ctx.sketch = bottom_mask_sketch
        ctx.scale_y *= -1
        ctx.thin_draw = True
        ctx.verbose = self.verbose

        gerberfile = read(self.layers.outline)
        gerberfile.render(ctx, pbar=True)

        self._output_file.recompute()

        self._output_file.addObject("PartDesign::Pad", "Bottom_Mask_Body")
        self._output_file.Bottom_Mask_Body.Sketch = \
            self._output_file.Bottom_Mask_Sketch
        self._output_file.Bottom_Mask_Body.Length = \
            self._mask_thickness + self._outer_copper_thickness
        self._output_file.recompute()

        if not self._nox:
            bottom_mask_sketch.ViewObject.hide()

        ctx = GerberFreecadContext()
        ctx.sketch = bottom_mask_sketch
        ctx.thin_draw = False
        ctx.thickness = self._mask_thickness + self._outer_copper_thickness
        ctx.scale_y *= -1
        ctx.verbose = self.verbose
        ctx.pcb_ctx = self
        ctx.prefix = 'BME_'
        ctx.invert = True
        ctx.base_body = self._output_file.Bottom_Mask_Body

        gerberfile = read(self.layers.bottommask)
        gerberfile.render(ctx, pbar=True)

        ctx.fuse('Bottom_Mask', simplify=False)
        self._colorize_object(
            self._output_file.Bottom_Mask_cut,
            self._mask_color, self._mask_alpha
        )
        if not self.nox:
            self._output_file.Bottom_Mask_cut.ViewObject.Selectable = False
        self._output_file.recompute()
Esempio n. 2
0
    def render_devel_view(self, output_filename=None,
                          quick=False, nox=False):
        output_filename = '{0}.devel.png'.format(output_filename)
        ctx = GerberCairoContext()

        ctx.color = theme.COLORS['fr-4']
        ctx.alpha = 1.0
        outline = read(self.layers.outline)
        outline.render(ctx)

        ctx.color = self.copper_color
        bottompaste = read(self.layers.bottompaste)
        bottompaste.render(ctx)

        ctx.alpha = 0.9
        ctx.color = self.silk_color
        bottomsilk = read(self.layers.bottomsilk)
        bottomsilk.render(ctx)

        num_copper_layers = len(self.layers.internal)
        if self.layers.top is not None:
            num_copper_layers += 1
        if self.layers.bottom is not None:
            num_copper_layers += 1

        ctx.color = self.layer_colors[num_copper_layers - 1]
        bottom = read(self.layers.bottom)
        bottom.render(ctx)

        ctx.alpha = 0.5
        for idx, l in enumerate(self.layers.internal):
            layer = read(l)
            ctx.color = self.layer_colors[num_copper_layers - 2 - idx]
            layer.render(ctx)

        ctx.alpha = 0.9
        ctx.color = self.layer_colors[0]
        top = read(self.layers.top)
        top.render(ctx)

        ctx.color = self.silk_color
        topsilk = read(self.layers.topsilk)
        topsilk.render(ctx)

        ctx.color = self.copper_color
        toppaste = read(self.layers.toppaste)
        toppaste.render(ctx)

        ctx.color = theme.COLORS['black']
        ctx.alpha = 1.0
        drill = read(self.layers.drill)
        drill.render(ctx)

        ctx.dump(output_filename)
Esempio n. 3
0
    def render_devel_view(self, output_filename=None, quick=False, nox=False):
        output_filename = '{0}.devel.png'.format(output_filename)
        ctx = GerberCairoContext()

        ctx.color = theme.COLORS['fr-4']
        ctx.alpha = 1.0
        outline = read(self.layers.outline)
        outline.render(ctx)

        ctx.color = self.copper_color
        bottompaste = read(self.layers.bottompaste)
        bottompaste.render(ctx)

        ctx.alpha = 0.9
        ctx.color = self.silk_color
        bottomsilk = read(self.layers.bottomsilk)
        bottomsilk.render(ctx)

        num_copper_layers = len(self.layers.internal)
        if self.layers.top is not None:
            num_copper_layers += 1
        if self.layers.bottom is not None:
            num_copper_layers += 1

        ctx.color = self.layer_colors[num_copper_layers - 1]
        bottom = read(self.layers.bottom)
        bottom.render(ctx)

        ctx.alpha = 0.5
        for idx, l in enumerate(self.layers.internal):
            layer = read(l)
            ctx.color = self.layer_colors[num_copper_layers - 2 - idx]
            layer.render(ctx)

        ctx.alpha = 0.9
        ctx.color = self.layer_colors[0]
        top = read(self.layers.top)
        top.render(ctx)

        ctx.color = self.silk_color
        topsilk = read(self.layers.topsilk)
        topsilk.render(ctx)

        ctx.color = self.copper_color
        toppaste = read(self.layers.toppaste)
        toppaste.render(ctx)

        ctx.color = theme.COLORS['black']
        ctx.alpha = 1.0
        drill = read(self.layers.drill)
        drill.render(ctx)

        ctx.dump(output_filename)
Esempio n. 4
0
    def _create_bottom_copper(self):
        print("Drawing bottom copper from {0}".format(self.layers.bottom))
        bottom_copper_sketch = self._create_sketch_on_face(
            'Bottom_Copper_Sketch',
            self._output_file.PCB_Body,
            self._get_bottom_face(self._output_file.PCB_Body)
        )
        ctx = GerberFreecadContext()
        ctx.sketch = bottom_copper_sketch
        ctx.scale_y *= -1
        ctx.thin_draw = False
        ctx.thickness = self._outer_copper_thickness
        ctx.verbose = self.verbose
        ctx.pcb_ctx = self
        ctx.prefix = 'BCE_'
        ctx.simplify_cad_elements = True

        gerberfile = read(self.layers.bottom)
        gerberfile.render(ctx, pbar=True)

        ctx.render_deferred()

        ctx.fuse('Bottom_Copper')
        self._bottom_copper_obj = getattr(self._output_file, 'Bottom_Copper_fused')

        self._colorize_object(self._bottom_copper_obj, self._copper_color)
        self._output_file.recompute()
Esempio n. 5
0
    def _create_top_silk(self):
        print("Drawing top silk from {0}".format(self.layers.topsilk))
        top_silk_sketch = self._create_sketch_on_face(
            'Top_Silk_Sketch',
            self._output_file.Top_Mask_cut,
            self._get_top_face(self._output_file.Top_Mask_cut)
        )
        ctx = GerberFreecadContext()
        ctx.sketch = top_silk_sketch
        ctx.thin_draw = False
        ctx.thickness = 2 * self._silk_thickness
        ctx.verbose = self.verbose
        ctx.pcb_ctx = self
        ctx.prefix = 'TSE_'
        ctx.simplify_cad_elements = True

        gerberfile = read(self.layers.topsilk)
        gerberfile.render(ctx, pbar=True)

        ctx.render_deferred()

        if self._quick is True:
            for element in ctx.elements:
                obj = getattr(self._output_file, element)
                self._colorize_object(obj, self._silk_color)
        else:
            ctx.fuse('Top_Silk')
            obj = getattr(self._output_file, 'Top_Silk_fused')
            self._colorize_object(obj, self._silk_color)

        self._output_file.recompute()
Esempio n. 6
0
    def render_top_view(self, output_filename=None,
                        quick=False, nox=False):
        output_filename = '{0}.top.png'.format(output_filename)
        ctx = GerberCairoContext()

        if self.outline_color is not None:
            ctx.color = self.outline_color
        if self.outline_alpha is not None:
            ctx.alpha = self.outline_alpha
        outline = read(self.layers.outline)
        outline.render(ctx)

        if self.copper_color is not None:
            ctx.color = self.copper_color
        if self.copper_alpha is not None:
            ctx.alpha = self.copper_alpha
        copper = read(self.layers.top)
        copper.render(ctx)

        if self.mask_color is not None:
            ctx.color = self.mask_color
        if self.mask_alpha is not None:
            ctx.alpha = self.mask_alpha
        mask = read(self.layers.topmask)
        mask.render(ctx, invert=True)

        if self.silk_color is not None:
            ctx.color = self.silk_color
        if self.silk_alpha is not None:
            ctx.alpha = self.silk_alpha
        silk = read(self.layers.topsilk)
        silk.render(ctx)

        if self.drill_color is not None:
            ctx.color = self.drill_color
        if self.drill_alpha is not None:
            ctx.alpha = self.drill_alpha
        drill = read(self.layers.drill)
        drill.render(ctx)

        ctx.dump(output_filename)
Esempio n. 7
0
    def render_top_view(self, output_filename=None, quick=False, nox=False):
        output_filename = '{0}.top.png'.format(output_filename)
        ctx = GerberCairoContext()

        if self.outline_color is not None:
            ctx.color = self.outline_color
        if self.outline_alpha is not None:
            ctx.alpha = self.outline_alpha
        outline = read(self.layers.outline)
        outline.render(ctx)

        if self.copper_color is not None:
            ctx.color = self.copper_color
        if self.copper_alpha is not None:
            ctx.alpha = self.copper_alpha
        copper = read(self.layers.top)
        copper.render(ctx)

        if self.mask_color is not None:
            ctx.color = self.mask_color
        if self.mask_alpha is not None:
            ctx.alpha = self.mask_alpha
        mask = read(self.layers.topmask)
        mask.render(ctx, invert=True)

        if self.silk_color is not None:
            ctx.color = self.silk_color
        if self.silk_alpha is not None:
            ctx.alpha = self.silk_alpha
        silk = read(self.layers.topsilk)
        silk.render(ctx)

        if self.drill_color is not None:
            ctx.color = self.drill_color
        if self.drill_alpha is not None:
            ctx.alpha = self.drill_alpha
        drill = read(self.layers.drill)
        drill.render(ctx)

        ctx.dump(output_filename)
Esempio n. 8
0
 def render(self, output_filename=None, quick=False, nox=False):
     if self.dialect:
         self.layers = self.dialect(self.filenames)
     ctx = GerberCairoContext()
     ctx.alpha = 0.95
     for filename in self.filenames:
         print("parsing %s" % filename)
         if filename in self.layers.outer_copper_layers:
             ctx.color = (1, 1, 1)
             ctx.alpha = 0.8
         elif filename in self.layers.silk_layers:
             ctx.color = (0.2, 0.2, 0.75)
             ctx.alpha = 0.8
         gerberfile = read(filename)
         gerberfile.render(ctx)
     if not output_filename:
         output_filename = self.layers.pcbname
     if os.path.splitext(output_filename)[1].upper() != 'SVG':
         output_filename += '.svg'
     print('Saving image to {0}'.format(output_filename))
     ctx.dump(output_filename)
Esempio n. 9
0
    def _create_body(self):
        print("Thin drawing outline from {0}".format(self.layers.outline))
        olsketch = self._output_file.addObject(
            "Sketcher::SketchObject", "Outline Sketch"
        )
        ctx = GerberFreecadContext()
        ctx.sketch = olsketch
        ctx.thin_draw = True
        ctx.verbose = self.verbose

        gerberfile = read(self.layers.outline)
        gerberfile.render(ctx)

        self._output_file.recompute()

        self._output_file.addObject("PartDesign::Pad", "PCB_Body")
        self._output_file.PCB_Body.Sketch = self._output_file.Outline_Sketch
        self._output_file.PCB_Body.Length = self._pcb_thickness
        self._output_file.recompute()

        self._colorize_object(self._output_file.PCB_Body, self._pcb_color)
        if not self._nox:
            olsketch.ViewObject.hide()
def get_gerber_primitives_from_gerber_file(gerber_file):
    print('reading gerber files begin')
    parsed_gerber = read(gerber_file)
    print('reading gerber file ends')
    return parsed_gerber.primitives
Esempio n. 11
0
    def _create_drills(self):
        print("Drawing drills from {0}".format(self.layers.drill))
        print("Drilling on Top Copper")
        drill_sketch_tc = self._create_sketch_on_face(
            'Drill_Sketch_TC',
            self._output_file.PCB_Body,
            self._get_top_face(self._output_file.PCB_Body)
        )

        ctx = GerberFreecadContext()
        ctx.sketch = drill_sketch_tc
        ctx.thin_draw = False
        ctx.verbose = self.verbose
        ctx.pcb_ctx = self

        ctx.prefix = 'DRL_TC'
        ctx.thickness = self._outer_copper_thickness
        ctx.invert = True
        ctx.base_body = self._top_copper_obj

        gerberfile = read(self.layers.drill)
        gerberfile.render(ctx, pbar=True)

        ctx.fuse('Top_Copper_DRL', simplify=False)
        self._colorize_object(
            self._output_file.Top_Copper_DRL, self._copper_color
        )
        self._colorize_object(
            self._output_file.Top_Copper_DRL_cut, self._copper_color
        )
        self._output_file.recompute()

        print("Drilling on Bottom Copper")
        drill_sketch_bc = self._create_sketch_on_face(
            'Drill_Sketch_BC',
            self._output_file.PCB_Body,
            self._get_bottom_face(self._output_file.PCB_Body)
        )

        ctx = GerberFreecadContext()
        ctx.sketch = drill_sketch_bc
        ctx.scale_y *= -1
        ctx.thin_draw = False
        ctx.verbose = self.verbose
        ctx.pcb_ctx = self

        ctx.prefix = 'DRL_BC'
        ctx.thickness = self._outer_copper_thickness
        ctx.invert = True
        ctx.base_body = self._bottom_copper_obj

        gerberfile = read(self.layers.drill)
        gerberfile.render(ctx, pbar=True)

        ctx.fuse('Bottom_Copper_DRL', simplify=False)
        self._colorize_object(
            self._output_file.Bottom_Copper_DRL, self._copper_color
        )
        self._colorize_object(
            self._output_file.Bottom_Copper_DRL_cut, self._copper_color
        )
        self._output_file.recompute()

        print("Drilling on PCB Body")
        drill_sketch_body = self._output_file.addObject(
            'Sketcher::SketchObject', 'Drill_Sketch_PCB'
        )

        ctx = GerberFreecadContext()
        ctx.sketch = drill_sketch_body
        ctx.thin_draw = False
        ctx.verbose = self.verbose
        ctx.pcb_ctx = self

        ctx.prefix = 'DRL_BODY'
        ctx.thickness = self._pcb_thickness
        ctx.invert = True
        ctx.base_body = self._output_file.PCB_Body

        gerberfile = read(self.layers.drill)
        gerberfile.render(ctx, pbar=True)

        ctx.fuse('PCB_Body_DRL', simplify=False)
        self._colorize_object(
            self._output_file.PCB_Body_DRL, self._pcb_color
        )
        self._colorize_object(
            self._output_file.PCB_Body_DRL_cut, self._pcb_color
        )
        self._output_file.recompute()
Esempio n. 12
0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

if __name__ == '__main__':
    from gerber.common import read
    from gerber.render import GerberSvgContext
    import sys

    if len(sys.argv) < 2:
        sys.stderr.write("Usage: python -m gerber <filename> <filename>...\n")
        sys.exit(1)

    ctx = GerberSvgContext()
    ctx.alpha = 0.95
    for filename in sys.argv[1:]:
        print("parsing %s" % filename)
        if 'GTO' in filename or 'GBO' in filename:
            ctx.color = (1, 1, 1)
            ctx.alpha = 0.8
        elif 'GTS' in filename or 'GBS' in filename:
            ctx.color = (0.2, 0.2, 0.75)
            ctx.alpha = 0.8
        gerberfile = read(filename)
        gerberfile.render(ctx)

    print('Saving image to test.svg')
    ctx.dump('test.svg')