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

Fix DIP Parts to run with FreeCAD 0.18 and Python 3 #372

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*.[pP][yY][cC]
*.DS_Store
*.bak
.vscode/
8 changes: 4 additions & 4 deletions cadquery/FCAD_script_generator/DIP_parts/cq_base_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf8 -*-
#!/usr/bin/python
# -*- coding: utf8 -*-
#

#****************************************************************************
Expand Down Expand Up @@ -57,8 +57,8 @@ def __init__(self, plane, origin=(0.0, 0.0)):
self.commands = []
self.plane = plane
self.origin = origin
self.x = 0
self.y = 0
self.x = 0.0
self.y = 0.0
self.addMoveTo(origin[0], origin[1])

def getCurrentPosition(self):
Expand Down Expand Up @@ -409,7 +409,7 @@ def _union_all(self, objects):
def _mirror(self, obj, pins=None, pitch=None):

if pins is None:
pins = self.num_pins / 2
pins = self.num_pins // 2

if pitch is None:
pitch = self.pin_pitch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf8 -*-
#!/usr/bin/python
# -*- coding: utf8 -*-
#

#****************************************************************************
Expand Down Expand Up @@ -156,7 +156,7 @@ def getAllModels(self, model_classes):

# instantiate generator classes in order to make a dictionary of all model names
for i in range(0, len(model_classes)):
for variant in self.base_params.keys():
for variant in list(self.base_params.keys()):
params = self.base_params[variant]
model = model_classes[i](params)
if model.make_me:
Expand Down Expand Up @@ -211,7 +211,7 @@ def getModel(self, model_class, variant):
:rtype: ```tuple````
"""

model = self.base_params.has_key(variant)
model = variant in self.base_params

# instantiate generator class in order to make a dictionary entry for a single variant
if model:
Expand Down
19 changes: 10 additions & 9 deletions cadquery/FCAD_script_generator/DIP_parts/cq_model_generator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf8 -*-
#!/usr/bin/python
# -*- coding: utf8 -*-
#
# This is derived from a cadquery script for generating PDIP models in X3D format
#
Expand Down Expand Up @@ -54,6 +54,7 @@
#

import sys, os
import importlib

import exportPartToVRML as expVRML
import shaderColors
Expand All @@ -74,7 +75,7 @@
# Import cad_tools
import cq_cad_tools
# Reload tools
reload(cq_cad_tools)
importlib.reload(cq_cad_tools)
# Explicitly load all needed functions
from cq_cad_tools import FuseObjs_wColors, GetListOfObjects, restore_Main_Tools, \
exportSTEP, close_CQ_Example, saveFCdoc, z_RotateObject, Color_Objects, \
Expand Down Expand Up @@ -117,7 +118,7 @@
try:
close_CQ_Example(FreeCAD, Gui)
except: # catch *all* exceptions
print "CQ 030 doesn't open example file"
print("CQ 030 doesn't open example file")

global All
All = None
Expand Down Expand Up @@ -350,7 +351,7 @@ def makeModel(self, models_dir, genericName, model, keepDocument=True, verbose=F

if not self.kicadStepUptools == False:
kicadStepUptools.KSUWidget.close()
reload(kicadStepUptools)
importlib.reload(kicadStepUptools)
kicadStepUptools.KSUWidget.close()
#kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized)
#kicadStepUptools.KSUWidget.destroy()
Expand Down Expand Up @@ -432,7 +433,7 @@ class my_part_params (PartParametersBase)

models_made = 0

if len(options) > 0 and not params.base_params.has_key(options[0]):
if len(options) > 0 and not options[0] in params.base_params:

models = params.getAllModels(series)

Expand All @@ -444,7 +445,7 @@ class my_part_params (PartParametersBase)
buildAllSMD = options[0] == "allsmd"
qfilter = '*' if options[0] == "all" or options[0] == "allsmd" else options[0]
qfilter = re.compile(fnmatch.translate(qfilter))
for variant in models.keys():
for variant in list(models.keys()):
if qfilter.match(variant):
params = models[variant].params
model = models[variant].model(params)
Expand All @@ -457,7 +458,7 @@ class my_part_params (PartParametersBase)

models = params.getSampleModels(series)

for variant in models.keys():
for variant in list(models.keys()):
params = models[variant].params
model = models[variant].model(params)
if model.make_me:
Expand All @@ -481,9 +482,9 @@ class my_part_params (PartParametersBase)
FreeCAD.Console.PrintMessage('\r\n' + variant + ' - not made')

if models_made == 0:
FreeCAD.Console.PrintMessage('\r\nDone - no models matched the provided filter!')
FreeCAD.Console.PrintMessage('\r\nDone - no models matched the provided filter!\r\n')
else:
FreeCAD.Console.PrintMessage('\r\nDone - models made: ' + str(models_made))
FreeCAD.Console.PrintMessage('\r\nDone - models made: ' + str(models_made) + '\r\n')

sys.argv = [] # clear, running kicadStepUptools changes values

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf8 -*-
#!/usr/bin/python
# -*- coding: utf8 -*-
#

#****************************************************************************
Expand Down Expand Up @@ -48,7 +48,7 @@ class dip_switch_piano (PartBase):
def __init__(self, params):
PartBase.__init__(self, params)
# self.make_me = params.type == CaseType.THT and params.num_pins >= 2 and params.num_pins <= 24 and params.pin_rows_distance == 7.62
self.make_me = self.num_pins / 2 in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
self.make_me = self.num_pins // 2 in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
# if self.make_me:
self.licAuthor = "Terje Io"
self.licEmail = "https://github.com/terjeio"
Expand Down Expand Up @@ -83,9 +83,9 @@ def __init__(self, params):

def makeModelName(self, genericName):
if self.num_pins == 2 or self.num_pins == 12 or self.num_pins == 22:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Piano_10.8x' + '{:.1f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Piano_10.8x' + '{:.1f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
else:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Piano_10.8x' + '{:.2f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Piano_10.8x' + '{:.2f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'


def _make_switchpockets(self):
Expand Down Expand Up @@ -184,7 +184,7 @@ class dip_switch_piano_cts (dip_switch_piano):
def __init__(self, params):
dip_switch_piano.__init__(self, params)

self.make_me = self.num_pins / 2 in [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
self.make_me = self.num_pins // 2 in [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

self.pin_width = 0.48
self.pin_length = 3.81
Expand Down Expand Up @@ -214,7 +214,7 @@ def make_body(self):


def makeModelName(self, genericName):
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Piano_CTS_Series194-' + '{:d}'.format(self.num_pins / 2) + 'MSTN_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Piano_CTS_Series194-' + '{:d}'.format(self.num_pins // 2) + 'MSTN_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'


### EOF ###
18 changes: 9 additions & 9 deletions cadquery/FCAD_script_generator/DIP_parts/cq_model_pin_switch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf8 -*-
#!/usr/bin/python
# -*- coding: utf8 -*-
#

#****************************************************************************
Expand Down Expand Up @@ -47,7 +47,7 @@ class dip_switch (PartBase):

def __init__(self, params):
PartBase.__init__(self, params)
self.make_me = self.num_pins / 2 in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
self.make_me = self.num_pins // 2 in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
# if self.make_me:
self.licAuthor = "Terje Io"
self.licEmail = "https://github.com/terjeio"
Expand Down Expand Up @@ -84,9 +84,9 @@ def __init__(self, params):

def makeModelName(self, genericName):
if self.num_pins == 6 or self.num_pins == 16:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_9.78x' + '{:.1f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_9.78x' + '{:.1f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
else:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_9.78x' + '{:.2f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_9.78x' + '{:.2f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'

def _make_switchpockets(self):

Expand Down Expand Up @@ -176,8 +176,8 @@ class dip_switch_low_profile (dip_switch):
def __init__(self, params):
dip_switch.__init__(self, params)

self.make_me = self.num_pins / 2 in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
self.make_me = self.num_pins // 2 in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

self.rotation = 180
self.pin_rows_distance = 7.62
self.pin_pitch = 2.54
Expand All @@ -194,7 +194,7 @@ def __init__(self, params):
self.color_keys[0] = "black body" #body
self.color_keys.append("white body") #buttons
self.color_keys.append("white body") #buttons

# self.first_pin_pos = (self.pin_pitch * (self.num_pins / 4.0 - 0.5), (self.pin_rows_distance / 2.0) - self.pin_thickness)
# self.offsets = ((self.first_pin_pos[1], -self.first_pin_pos[0], self.body_board_distance))
self.first_pin_pos = (self.pin_pitch * (self.num_pins / 4.0 - 0.5), (self.pin_rows_distance / 2.0) - self.pin_thickness)
Expand Down Expand Up @@ -228,8 +228,8 @@ def make_pins(self):

def makeModelName(self, genericName):
if self.num_pins == 2 or self.num_pins == 12 or self.num_pins == 22:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_6.7x' + '{:.1f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_6.7x' + '{:.1f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile'
else:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_6.7x' + '{:.2f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_6.7x' + '{:.2f}'.format(self.body_length) + 'mm_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile'

### EOF ###
12 changes: 6 additions & 6 deletions cadquery/FCAD_script_generator/DIP_parts/cq_model_smd_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def makeModelName(self, genericName):
# can not be changed
#
if self.num_pins == 2 or self.num_pins == 12 or self.num_pins == 22:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_' + '{:.1f}'.format(self.body_width) + 'x' + '{:.1f}'.format(self.body_length) + 'mm_W8.61mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_' + '{:.1f}'.format(self.body_width) + 'x' + '{:.1f}'.format(self.body_length) + 'mm_W8.61mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile'
else:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_' + '{:.1f}'.format(self.body_width) + 'x' + '{:.2f}'.format(self.body_length) + 'mm_W8.61mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_' + '{:.1f}'.format(self.body_width) + 'x' + '{:.2f}'.format(self.body_length) + 'mm_W8.61mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile'

def _make_switchpockets(self):

Expand Down Expand Up @@ -185,9 +185,9 @@ def makeModelName(self, genericName):
# can not be changed
#
if self.num_pins == 2 or self.num_pins == 12 or self.num_pins == 22:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_' + '{:.1f}'.format(self.body_width) + 'x' + '{:.1f}'.format(self.body_length) + 'mm_W6.73mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile_JPin'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_' + '{:.1f}'.format(self.body_width) + 'x' + '{:.1f}'.format(self.body_length) + 'mm_W6.73mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile_JPin'
else:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_' + '{:.1f}'.format(self.body_width) + 'x' + '{:.2f}'.format(self.body_length) + 'mm_W6.73mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile_JPin'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_' + '{:.1f}'.format(self.body_width) + 'x' + '{:.2f}'.format(self.body_length) + 'mm_W6.73mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_LowProfile_JPin'

class dip_smd_switch (dip_smd_switch_lowprofile):

Expand Down Expand Up @@ -232,9 +232,9 @@ def makeModelName(self, genericName):
# can not be changed
#
if self.num_pins == 6 or self.num_pins == 16:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_' + '{:.2f}'.format(self.body_width) + 'x' + '{:.1f}'.format(self.body_length) + 'mm_W8.61mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_' + '{:.2f}'.format(self.body_width) + 'x' + '{:.1f}'.format(self.body_length) + 'mm_W8.61mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
else:
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_' + '{:.2f}'.format(self.body_width) + 'x' + '{:.2f}'.format(self.body_length) + 'mm_W8.61mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_' + '{:.2f}'.format(self.body_width) + 'x' + '{:.2f}'.format(self.body_length) + 'mm_W8.61mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'

def _make_switchpockets(self):

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf8 -*-
#!/usr/bin/python
# -*- coding: utf8 -*-
#

#****************************************************************************
Expand Down Expand Up @@ -43,7 +43,7 @@ class dip_switch_copal_CHS_B (dip_smd_switch_lowprofile):

def __init__(self, params):
dip_smd_switch_lowprofile.__init__(self, params)
self.make_me = self.make_me and self.num_pins / 2 in [1, 2, 4, 6, 8, 10]
self.make_me = self.make_me and self.num_pins // 2 in [1, 2, 4, 6, 8, 10]
self.rotation = 90

self.pin_pitch = 1.27
Expand All @@ -67,7 +67,7 @@ def __init__(self, params):
self.first_pin_pos = (self.pin_pitch * (self.num_pins / 4.0 - 0.5), self.pin_rows_distance / 2.0)

def makeModelName(self, genericName):
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_Copal_CHS-' + '{:02d}'.format(self.num_pins / 2) + 'B_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_Copal_CHS-' + '{:02d}'.format(self.num_pins // 2) + 'B_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'

def _make_switchpockets(self):

Expand Down Expand Up @@ -125,7 +125,7 @@ def __init__(self, params):
self.first_pin_pos = (self.pin_pitch * (self.num_pins / 4.0 - 0.5), self.body_width / 2.0)

def makeModelName(self, genericName):
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_Copal_CHS-' + '{:02d}'.format(self.num_pins / 2) + 'A_W5.08mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_JPin'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_Copal_CHS-' + '{:02d}'.format(self.num_pins // 2) + 'A_W5.08mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_JPin'

def make_pins(self):

Expand All @@ -144,7 +144,7 @@ class dip_switch_copal_CVS (dip_switch_copal_CHS_B):
def __init__(self, params):
dip_switch_copal_CHS_B.__init__(self, params)

self.make_me = self.num_pins / 2 in [1, 2, 3, 4, 8]
self.make_me = self.num_pins // 2 in [1, 2, 3, 4, 8]
self.pin_pitch = 1.00
self.pin_length = 1.0
self.pin_thickness = 0.15
Expand All @@ -170,7 +170,7 @@ def __init__(self, params):
self.first_pin_pos = (self.pin_pitch * (self.num_pins / 4.0 - 0.5), self.body_width / 2.0)

def makeModelName(self, genericName):
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_Copal_CVS-' + '{:02d}'.format(self.num_pins / 2) + 'xB_W5.9mm_P1mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_Copal_CVS-' + '{:02d}'.format(self.num_pins // 2) + 'xB_W5.9mm_P1mm'

# create other side of the pins
return pins.union(pins.rotate((0,0,0), (0,0,1), 180))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf8 -*-
#!/usr/bin/python
# -*- coding: utf8 -*-
#

#****************************************************************************
Expand Down Expand Up @@ -43,7 +43,7 @@ class dip_switch_kingtek_dshp04tj (dip_smd_switch_lowprofile):

def __init__(self, params):
dip_smd_switch_lowprofile.__init__(self, params)
self.make_me = self.make_me and self.num_pins / 2 in [2, 3, 4, 5, 6, 7, 8, 9, 10]
self.make_me = self.make_me and self.num_pins // 2 in [2, 3, 4, 5, 6, 7, 8, 9, 10]
self.rotation = 90

self.pin_pitch = 1.27
Expand All @@ -67,7 +67,7 @@ def __init__(self, params):
self.first_pin_pos = (self.pin_pitch * (self.num_pins / 4.0 - 0.5), self.pin_rows_distance / 2.0)

def makeModelName(self, genericName):
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_KingTek_DSHP' + '{:02d}'.format(self.num_pins / 2) + 'TJ_W5.25mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_JPin'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_KingTek_DSHP' + '{:02d}'.format(self.num_pins // 2) + 'TJ_W5.25mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm_JPin'


def _make_switchpockets(self):
Expand Down Expand Up @@ -126,7 +126,7 @@ def __init__(self, params):
self.offsets = (0.0, 0.0, self.body_board_distance)

def makeModelName(self, genericName):
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins / 2) + '_Slide_KingTek_DSHP' + '{:02d}'.format(self.num_pins / 2) + 'TS_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'
return 'SW_DIP_SPSTx' + '{:02d}'.format(self.num_pins // 2) + '_Slide_KingTek_DSHP' + '{:02d}'.format(self.num_pins // 2) + 'TS_W7.62mm_P' + '{:.2f}'.format(self.pin_pitch) + 'mm'

def make_pins(self):

Expand Down
Loading