def text(p, text): pcb = pcbnew.GetBoard() t = pcbnew.TEXTE_PCB(pcb) pcb.Add(t) t.SetPosition(p) t.SetText(text) return t
def generate_text_hint(board, text, width, height, thickness, x, y): txt = pcbnew.TEXTE_PCB(board) txt.SetText(text) txt.SetPosition(pcbnew.wxPoint(int(x), int(y))) txt.SetHorizJustify(pcbnew.GR_TEXT_HJUSTIFY_CENTER) txt.SetTextSize(pcbnew.wxSize(int(width), int(height))) txt.SetThickness(int(thickness)) return txt
def create_Text(pcb, txt, p, w, lyr): mytxt = pcbnew.TEXTE_PCB(pcb) mytxt.SetText(txt) mytxt.SetLayer(lyr) mytxt.SetPosition(p) mytxt.SetHorizJustify(pcbnew.GR_TEXT_HJUSTIFY_CENTER) mytxt.SetTextSize(pcbnew.wxSize(w,w)) mytxt.SetThickness(int(w/4)) pcb.Add(mytxt)
def draw_text(board, text, x, y): txtmod = pcbnew.TEXTE_PCB(board) txtmod.SetText(text) txtmod.SetPosition(pcbnew.wxPoint(int(x), int(y))) txtmod.SetHorizJustify(pcbnew.GR_TEXT_HJUSTIFY_CENTER) txtmod.SetTextSize(pcbnew.wxSize(0.75 * MM_TO_KC, 1 * MM_TO_KC)) txtmod.SetThickness(int(0.1 * MM_TO_KC)) txtmod.SetLayer(pcbnew.F_SilkS) board.Add(txtmod)
def write_text(): board = pcbnew.GetBoard() layertable = get_layertable() x = 0 for y in range(0, 100 * SCALE, SCALE * 10): text = pcbnew.TEXTE_PCB(board) text.SetText("HOLA: %d, %d" % (x, y)) text.SetPosition(pcbnew.wxPoint(x, y)) text.SetTextSize(pcbnew.wxSize(SCALE * 8, SCALE * 8)) text.SetThickness(SCALE * 1) text.SetLayer(layertable["F.SilkS"]) board.Add(text) pcbnew.Refresh()
def setup_text(self, pcb): texts = { TriadPiece.LEFT: [ Text( text="Left", position=Position(130.9875, 28.702, 0), size=TextSize(2.0, 2.0, 0.3), ) ], TriadPiece.CENTER: [], TriadPiece.RIGHT: [ Text( text="Right", position=Position(61.9125, 28.702, 0), size=TextSize(2.0, 2.0, 0.3), ) ], } for d in pcb.GetDrawings(): if type(d) == pcbnew.TEXTE_PCB: pcb.Remove(d) for text in texts[self.piece]: # The ordering of these operations is very important. Properties # like angle/justifcation affect the behavhior of the flip # operation. Always set position and flip before adjusting text. t = pcbnew.TEXTE_PCB(pcb) pos = t.GetPosition() pos.x = int(text.position.x * POSITION_SCALE) pos.y = int(text.position.y * POSITION_SCALE) t.SetPosition(pos) t.SetLayer(pcbnew.F_SilkS) if text.layer == pcbnew.B_SilkS: if self.local_build: t.Flip(pos, False) else: t.Flip(pos) t.SetText(text.text) t.SetTextAngle(text.position.r * ROTATION_SCALE) if self.local_build: t.SetTextThickness(int(text.size.t * POSITION_SCALE)) else: t.SetThickness(int(text.size.t * POSITION_SCALE)) t.SetTextWidth(int(text.size.w * POSITION_SCALE)) t.SetTextHeight(int(text.size.h * POSITION_SCALE)) t.SetHorizJustify(text.justify) pcb.Add(t)
def create_text_element(text, justification = None): te = pcbnew.TEXTE_PCB(pcb) #te.SetPosition (pcbnew.wxPoint(x,y)) #te.SetLayer (pcbnew.F_SilkS) te.SetVisible (True) te.SetThickness (mm_to_nm(.1524)) te.SetText (text) if justification <> None: if justification.lower() == 'left': justification = pcbnew.GR_TEXT_HJUSTIFY_LEFT elif justification.lower() == 'right': justification = pcbnew.GR_TEXT_HJUSTIFY_RIGHT elif justification.lower() == 'center': justification = pcbnew.GR_TEXT_HJUSTIFY_CENTER te.SetHorizJustify(justification) return te
def _renderVCutH(self, layer=Layer.Cmts_User): """ return list of DRAWSEGMENT V-Cuts """ bBox = self.boardSubstrate.boundingBox() minX, maxX = bBox.GetX() - fromMm(3), bBox.GetX() + bBox.GetWidth() + fromMm(3) segments = [] for cut in self.hVCuts: segment = pcbnew.DRAWSEGMENT() self._setVCutSegmentStyle(segment, layer) segment.SetStart(pcbnew.wxPoint(minX, cut)) segment.SetEnd(pcbnew.wxPoint(maxX, cut)) segments.append(segment) label = pcbnew.TEXTE_PCB(segment) self._setVCutLabelStyle(label, layer) label.SetPosition(wxPoint(maxX + fromMm(3), cut)) segments.append(label) return segments
def setup_text(self, pcb): texts = [ Text( text="v3.0", position=Position(155.446, 53.34, 0), size=TextSize(2.0, 2.0, 0.3), layer=pcbnew.F_SilkS, ), Text( text="v3.0", position=Position(155.446, 53.34, 0), size=TextSize(2.0, 2.0, 0.3), layer=pcbnew.B_SilkS, ), ] for d in pcb.GetDrawings(): if type(d) == pcbnew.TEXTE_PCB: pcb.Remove(d) for text in texts: # The ordering of these operations is very important. Properties # like angle/justifcation affect the behavhior of the flip # operation. Always set position and flip before adjusting text. t = pcbnew.TEXTE_PCB(pcb) pos = t.GetPosition() pos.x = int(text.position.x * POSITION_SCALE) pos.y = int(text.position.y * POSITION_SCALE) t.SetPosition(pos) t.SetLayer(pcbnew.F_SilkS) if text.layer == pcbnew.B_SilkS: if self.local_build: t.Flip(pos, False) else: t.Flip(pos) t.SetText(text.text) t.SetTextAngle(text.position.r * ROTATION_SCALE) if self.local_build: t.SetTextThickness(int(text.size.t * POSITION_SCALE)) else: t.SetThickness(int(text.size.t * POSITION_SCALE)) t.SetTextWidth(int(text.size.w * POSITION_SCALE)) t.SetTextHeight(int(text.size.h * POSITION_SCALE)) t.SetHorizJustify(text.justify) pcb.Add(t)
def _renderVCutV(self, layer=Layer.Cmts_User): """ return list of DRAWSEGMENT V-Cuts """ bBox = self.boardSubstrate.boundingBox() minY, maxY = bBox.GetY() - fromMm(3), bBox.GetY() + bBox.GetHeight() + fromMm(3) segments = [] for cut in self.vVCuts: segment = pcbnew.DRAWSEGMENT() self._setVCutSegmentStyle(segment, layer) segment.SetStart(pcbnew.wxPoint(cut, minY)) segment.SetEnd(pcbnew.wxPoint(cut, maxY)) segments.append(segment) label = pcbnew.TEXTE_PCB(segment) self._setVCutLabelStyle(label, layer) label.SetPosition(wxPoint(cut, minY - fromMm(3))) label.SetTextAngle(900) segments.append(label) return segments
def add_text(pos, angle, string, layer='F.SilkS', size=(1, 1), thick=5, hjustify=None, vjustify=None): text = pcbnew.TEXTE_PCB(pcb) text.SetPosition(pnt.to_unit(vec2.round(pos, PointDigits), UnitMM)) text.SetTextAngle(angle * 10) text.SetText(string) text.SetLayer(pcb.GetLayerID(layer)) text.SetTextSize(pcbnew.wxSizeMM(size[0], size[1])) text.SetThickness(scalar_to_unit(thick, UnitMM)) text.SetMirrored(layer[0] == 'B') if hjustify != None: text.SetHorizJustify(hjustify) if vjustify != None: text.SetVertJustify(vjustify) pcb.Add(text) return text
def DrawText(board, text_str, layer, pos, size=int(1.5 * pcbnew.IU_PER_MM), thickness=None, h_align=pcbnew.GR_TEXT_HJUSTIFY_CENTER): if thickness == None: thickness = int(size / 7.5) text = pcbnew.TEXTE_PCB(board) text.SetText(text_str) text.SetPosition(pcbnew.wxPoint(*pos)) try: # this fails in version 4.0.x text.SetTextSize(pcbnew.wxSize(size, size)) except AttributeError: # this fails in nightly 20171105 version text.SetSize(pcbnew.wxSize(size, size)) text.SetThickness(thickness) text.SetHorizJustify(h_align) text.SetLayer(layer) board.Add(text)
if pos[0] not in cp: cp.append(pos[0]) if pos[1] not in rp: rp.append(pos[1]) cp.sort() rp.sort() height = abs(max(rp) - min(rp)) height += height / len(rp) row_height = height / len(rp) top = min(rp) - row_height / 2 if column_width == None: #Compute width t = pcbnew.TEXTE_PCB(pcb) for p in pads: if p.GetNetname() not in tracknames: continue else: t.SetText(p.GetNetname()) column_width = max(column_width, t.GetBoundingBox().GetWidth()) #We'll build the list to the right the width of one column away. The expectation is the user will place it where they want it. for p in pads: #continue pos = p.GetPosition() column_number = cp.index(pos[0]) x = offset_left + cp[0] + column_width + column_width * column_number pos[0] = x text = pcbnew.TEXTE_PCB(pcb)
vscore_top = panelCenter.y - panelHeight / 2 - V_SCORE_LINE_LENGTH_BEYOND_BOARD * SCALE vscore_bottom = panelCenter.y + panelHeight / 2 + V_SCORE_LINE_LENGTH_BEYOND_BOARD * SCALE vscore_right = panelCenter.x + panelWidth / 2 + V_SCORE_LINE_LENGTH_BEYOND_BOARD * SCALE vscore_left = panelCenter.x - panelWidth / 2 - V_SCORE_LINE_LENGTH_BEYOND_BOARD * SCALE v_scores = [] # vertical v-scores for x in range(1, NUM_X): x_loc = panelCenter.x - panelWidth / 2 + HORIZONTAL_EDGE_RAIL_WIDTH * SCALE + boardWidth * x v_score_line = pcbnew.DRAWSEGMENT(board) v_scores.append(v_score_line) v_score_line.SetStart(pcbnew.wxPoint(x_loc, vscore_top)) v_score_line.SetEnd(pcbnew.wxPoint(x_loc, vscore_bottom)) v_score_line.SetLayer(layertable[V_SCORE_LAYER]) v_score_text = pcbnew.TEXTE_PCB(board) v_score_text.SetText(V_SCORE_TEXT) v_score_text.SetPosition( wxPoint(x_loc, vscore_top - V_SCORE_TEXT_CENTER_TO_LINE_LENGTH * SCALE)) v_score_text.SetTextSize( pcbnew.wxSize(SCALE * V_SCORE_TEXT_SIZE, SCALE * V_SCORE_TEXT_SIZE)) #v_score_text.SetThickness(SCALE*1) v_score_text.SetLayer(layertable[V_SCORE_LAYER]) v_score_text.SetTextAngle(900) board.Add(v_score_text) if args.verbose: print("Vertical v-scores created.") # horizontal v-scores for y in range(0, NUM_Y + 1):
# vertical v-scores if HORIZONTAL_EDGE_RAIL_WIDTH >0: rangeStart = 0 rangeEnd = NUM_X+1 else: rangeStart = 1 rangeEnd = NUM_X for x in range(rangeStart, rangeEnd): x_loc = panelCenter.x - panelWidth/2 + HORIZONTAL_EDGE_RAIL_WIDTH*SCALE + boardWidth*x v_score_line = pcbnew.DRAWSEGMENT(board) v_scores.append(v_score_line) v_score_line.SetStart(pcbnew.wxPoint(x_loc, vscore_top)) v_score_line.SetEnd(pcbnew.wxPoint(x_loc, vscore_bottom)) v_score_line.SetLayer(layertable[V_SCORE_LAYER]) v_score_text = pcbnew.TEXTE_PCB(board) v_score_text.SetText(V_SCORE_TEXT) v_score_text.SetHorizJustify(GR_TEXT_HJUSTIFY_LEFT) v_score_text.SetPosition(wxPoint(x_loc, vscore_top - V_SCORE_TEXT_SIZE*SCALE)) v_score_text.SetTextSize(pcbnew.wxSize(SCALE*V_SCORE_TEXT_SIZE,SCALE*V_SCORE_TEXT_SIZE)) v_score_text.SetLayer(layertable[V_SCORE_TEXT_LAYER]) v_score_text.SetTextAngle(900) board.Add(v_score_text) # horizontal v-scores if VERTICAL_EDGE_RAIL_WIDTH >0: rangeStart = 0 rangeEnd = NUM_Y+1 else: rangeStart = 1 rangeEnd = NUM_Y