def inject(self, data_dict, brd): """Inject plot settings from data_dict into a KiCad BOARD object.""" # Get all plot settings from the data dict. data_plot_settings = data_dict.get(self.dict_key, {}) # Get the plot settings from the board. brd_plot_settings = brd.GetPlotOptions() # Update existing plot settings in the board with new values from data. for key, value in list(data_plot_settings.items()): self.key_method_map[key.lower()].set(brd_plot_settings, value) # Enable specified layers for plotting. try: # Create an LSET where the bit is set for each enabled plot layer. lset = LSET() for l in data_plot_settings["layers"]: lset.AddLayer(l) except KeyError: # No layers element found in data dict. pass else: # Enable the specified layers while disabling the rest. brd_plot_settings.SetLayerSelection(lset) # Load the modified plot settings into the board. brd.SetPlotOptions(brd_plot_settings)
def remove_paste_and_glue(self, board, comps_hash): """ Remove from solder paste layers the filtered components. """ exclude = LSET() fpaste = board.GetLayerID('F.Paste') bpaste = board.GetLayerID('B.Paste') exclude.addLayer(fpaste) exclude.addLayer(bpaste) old_layers = [] fadhes = board.GetLayerID('F.Adhes') badhes = board.GetLayerID('B.Adhes') old_fadhes = [] old_badhes = [] rescue = board.GetLayerID('Rescue') fmask = board.GetLayerID('F.Mask') bmask = board.GetLayerID('B.Mask') for m in board.GetModules(): ref = m.GetReference() c = comps_hash.get(ref, None) if c and c.included and not c.fitted: # Remove all pads from *.Paste old_c_layers = [] for p in m.Pads(): pad_layers = p.GetLayerSet() is_front = fpaste in pad_layers.Seq() old_c_layers.append(pad_layers.FmtHex()) pad_layers.removeLayerSet(exclude) if len(pad_layers.Seq()) == 0: # No layers at all. Ridiculous, but happends. # At least add an F.Mask pad_layers.addLayer(fmask if is_front else bmask) logger.warning( W_WRONGPASTE + 'Pad with solder paste, but no copper or solder mask aperture in ' + ref) p.SetLayerSet(pad_layers) old_layers.append(old_c_layers) # Remove any graphical item in the *.Adhes layers for gi in m.GraphicalItems(): l_gi = gi.GetLayer() if l_gi == fadhes: gi.SetLayer(rescue) old_fadhes.append(gi) if l_gi == badhes: gi.SetLayer(rescue) old_badhes.append(gi) # Store the data to undo the above actions self.old_layers = old_layers self.old_fadhes = old_fadhes self.old_badhes = old_badhes self.fadhes = fadhes self.badhes = badhes return exclude
def remove_paste_and_glue(self, board, comps_hash): """ Remove from solder paste layers the filtered components. """ exclude = LSET() exclude.addLayer(board.GetLayerID('F.Paste')) exclude.addLayer(board.GetLayerID('B.Paste')) old_layers = [] fadhes = board.GetLayerID('F.Adhes') badhes = board.GetLayerID('B.Adhes') old_fadhes = [] old_badhes = [] rescue = board.GetLayerID('Rescue') for m in board.GetModules(): ref = m.GetReference() c = comps_hash.get(ref, None) if c and c.included and not c.fitted: # Remove all pads from *.Paste old_c_layers = [] for p in m.Pads(): pad_layers = p.GetLayerSet() old_c_layers.append(pad_layers.FmtHex()) pad_layers.removeLayerSet(exclude) p.SetLayerSet(pad_layers) old_layers.append(old_c_layers) # Remove any graphical item in the *.Adhes layers for gi in m.GraphicalItems(): l_gi = gi.GetLayer() if l_gi == fadhes: gi.SetLayer(rescue) old_fadhes.append(gi) if l_gi == badhes: gi.SetLayer(rescue) old_badhes.append(gi) # Store the data to undo the above actions self.old_layers = old_layers self.old_fadhes = old_fadhes self.old_badhes = old_badhes self.fadhes = fadhes self.badhes = badhes return exclude
def inject(self, data_dict, brd): """Inject enabled/visible layers from data_dict into a KiCad BOARD object.""" # Get the design rule settings from the data dict. data_drs = data_dict.get(self.dict_key, {}) # Get the design rules from the board. brd_drs = brd.GetDesignSettings() try: brd_drs.SetBoardThickness(data_drs["board thickness"]) except KeyError: pass try: brd_drs.SetCopperLayerCount(data_drs["# copper layers"]) except KeyError: pass try: # Create an LSET where the bit is set for each enabled layer. lset = LSET() for l in data_drs["enabled"]: lset.AddLayer(l) # Enable the specified layers while disabling the rest. brd_drs.SetEnabledLayers(lset) brd.SetEnabledLayers(lset) except KeyError: pass try: # Create an LSET where the bit is set for each visible layer. lset = LSET() for l in data_drs["visible"]: lset.AddLayer(l) # Make the specified layers visible while hiiding the rest. brd_drs.SetVisibleLayers(lset) brd.SetVisibleLayers(lset) except KeyError: pass # Load the updated layer settings back into the board. brd.SetDesignSettings(brd_drs) Refresh() # Refresh the board with the new data.