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

dial indicator version for newer kicad #1

Open
EeliK opened this issue Jan 2, 2018 · 1 comment
Open

dial indicator version for newer kicad #1

EeliK opened this issue Jan 2, 2018 · 1 comment

Comments

@EeliK
Copy link

EeliK commented Jan 2, 2018

#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#
from __future__ import division

import sys
import math

import pcbnew
import FootprintWizardBase
import PadArray as PA

def rotate_about(center, p, theta):
    dx = p.x-center.x
    dy = p.y-center.y
    theta = math.radians(theta)
    x2 = dx * math.cos(theta) + dy * math.sin(theta)
    y2 = dx * math.sin(theta) + dy * math.cos(theta)

    return pcbnew.wxPoint(center.x+x2, center.y+y2)

class dial_indicator_wizard(FootprintWizardBase.FootprintWizard):

    def GetName(self):
        return "Dial indicator"

    def GetDescription(self):
        return "Indicator for rotary control"

    def GenerateParameterList(self):

        self.AddParam("Dial", "angle", self.uInteger, 270, min_value=1, max_value=360)
        self.AddParam("Dial", "radius", self.uMM, 6)

        self.AddParam("Ticks", "show ticks", self.uBool, 1)
        self.AddParam("Ticks", "number of divisions", self.uInteger, 10)
        self.AddParam("Ticks", "tick length", self.uMM, 1)

        self.AddParam("Labels", "show labels", self.uBool, 1)
        self.AddParam("Labels", "min", self.uInteger, 0)
        self.AddParam("Labels", "step", self.uInteger, 1)
        

    def CheckParameters(self):
        pass

    def GetValue(self):
        
        return "indicator"

    
    def BuildThisFootprint(self):

        dial_params = self.parameters['Dial']
        dial_angle = dial_params['angle']
        dial_radius = dial_params['radius']
        
        tick_params = self.parameters ['Ticks']
        tick_show = tick_params['show ticks']
        tick_num_divisions = tick_params['number of divisions']
        tick_length = tick_params['tick length']

        label_params = self.parameters ['Labels']
        label_show = label_params['show labels']
        label_min = label_params['min']
        label_step = label_params['step']

        text_size = self.GetTextSize()  # IPC nominal
        thickness = self.GetTextThickness()
        # self.draw.GetLineTickness())
        textposy = self.GetTextSize()
         
        self.draw.Value( 0, textposy, text_size )
        self.draw.Reference( 0, -textposy, text_size )

        layer = pcbnew.F_SilkS
        center_mm = pcbnew.wxPoint(0,0)

        start = pcbnew.wxPoint (center_mm.x, center_mm.y - dial_radius)
        center = pcbnew.wxPoint (center_mm.x, center_mm.y)
        start = rotate_about (center, start, dial_angle/2.0)

        self.draw.SetLayer(layer)
        self.draw.SetLineTickness(pcbnew.FromMM (0.15))
        self.draw.Arc (center.x, center.y, start.x, start.y, dial_angle*10)

        for j in range (0, tick_num_divisions+1):
            ang = j * dial_angle/(tick_num_divisions) - dial_angle/2.0
            ang = -ang

            center = pcbnew.wxPoint (center_mm.x, center_mm.y)
            start = pcbnew.wxPoint (center_mm.x, center_mm.y - dial_radius)
            end = pcbnew.wxPoint (center_mm.x, center_mm.y - dial_radius - tick_length)

            start = rotate_about (center, start, ang)
            end = rotate_about (center, end, ang)

            #
            if tick_show:
                self.draw.SetLayer(layer)
                self.draw.SetLineTickness(pcbnew.FromMM (0.15))
                self.draw.Line (start.x, start.y, end.x, end.y)

            if label_show:
                text_pos = pcbnew.wxPoint (center_mm.x, center_mm.y - dial_radius - tick_length - text_size*1.25)
                text_pos = rotate_about (center, text_pos, ang)

                #
                text = pcbnew.TEXTE_MODULE(self.module)

                text.SetPosition (text_pos)
                #text.SetOrientation (ang*10.0)
                text.SetThickness (pcbnew.FromMM (0.15))
                text.SetLayer(layer)
                text.SetText (str(label_min + j*label_step))

                self.module.Add (text)


dial_indicator_wizard().register()

@bobc
Copy link
Owner

bobc commented Jan 2, 2018

Thanks. I think I have incorporated all the changes and pushed them to a new branch "v5". I didn't have a chance to test them yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants