From b57548c7b4e1cf20cd5c1ed44d2d944614a35ff1 Mon Sep 17 00:00:00 2001 From: Andrea Cisternino Date: Sun, 10 May 2020 11:17:47 +0200 Subject: [PATCH 1/4] main_generator.py: fix whitespace issues --- .../DIP_packages/main_generator.py | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/cadquery/FCAD_script_generator/DIP_packages/main_generator.py b/cadquery/FCAD_script_generator/DIP_packages/main_generator.py index 58c61350..cb8ca20d 100644 --- a/cadquery/FCAD_script_generator/DIP_packages/main_generator.py +++ b/cadquery/FCAD_script_generator/DIP_packages/main_generator.py @@ -91,7 +91,7 @@ STR_licEmail = "ksu" STR_licOrgSys = "kicad StepUp" STR_licPreProc = "OCC" -STR_licOrg = "FreeCAD" +STR_licOrg = "FreeCAD" ################################################################################################# @@ -126,11 +126,11 @@ except: # catch *all* exceptions print "CQ 030 doesn't open example file" - + import cq_parameters # modules parameters from cq_parameters import * - + # case_color = (0.1, 0.1, 0.1) # pins_color = (0.9, 0.9, 0.9) #case_color = (50, 50, 50) @@ -162,7 +162,7 @@ def make_case(params, type, modelName): e = params.e # pin center to center distance (pitch) npins = params.npins # number of pins - + corner = params.corner excludepins = params.excludepins @@ -177,8 +177,8 @@ def make_case(params, type, modelName): ti_r = 0.75 # top indicator radius ti_d = 0.5 # top indicator depth - - + + the = 12.0 # body angle in degrees tb_s = 0.15 # top part of body is that much smaller @@ -243,7 +243,7 @@ def make_pins_tht(params, type, modelName): e = params.e # pin center to center distance (pitch) npins = params.npins # number of pins - + corner = params.corner excludepins = params.excludepins @@ -287,7 +287,7 @@ def chamfer_corner(pina): pinsL = [pin] pinsR = [pin.translate((0,0,0))] - + if npins/2>2: # draw the 2nd pin (regular pin shape) x = e*(npins/4.-0.5-1) # center x position of 2nd pin @@ -296,7 +296,7 @@ def chamfer_corner(pina): line(-b/4.,-b).line(-b/2.,0).line(-b/4.,b).line(0,L-b).\ line(-(b1-b)/2.,0).line(0,ty).\ close().extrude(c) - + # draw the top part of the pin pin2 = pin2.faces(">Z").workplane().center(0,-E/4.).rect(b1,-E/2.).extrude(-c) if (corner == CORNER_CHAMFER_TYPE): @@ -311,7 +311,7 @@ def chamfer_corner(pina): pin_i = pin2.translate((-e*(i-1),0,0)) pinsL.append(pin_i) pinsR.append(pin_i.translate((0,0,0))) - + # create last pin (mirrored 1st pin) x = -e*(npins/4.-0.5) pinl = cq.Workplane("XZ", (x, E/2., 0)).\ @@ -328,7 +328,7 @@ def chamfer_corner(pina): pinsL.append(pinl) pinsR.append(pinl.translate((0,0,0))) - + # FreeCAD.Console.PrintMessage("\r\n\r\n") # ttts = "pins = " + str(len(pins)) + "\r\n" # FreeCAD.Console.PrintMessage(ttts) @@ -352,8 +352,8 @@ def union_all(objects): tts = "len(pinsR) " + str(len(pinsR)) + "\r\n" FreeCAD.Console.PrintMessage(tts) for ei in excludepins: - tts = "excludepins " + str(ei) + "\r\n" - FreeCAD.Console.PrintMessage(tts) + tts = "excludepins " + str(ei) + "\r\n" + FreeCAD.Console.PrintMessage(tts) for i in range(0, npins/2): AddPinLeft = True for ei in excludepins: @@ -373,7 +373,7 @@ def union_all(objects): tts = "Adding to pinsRNew " + str(i - (npins/2)) + "\r\n" FreeCAD.Console.PrintMessage(tts) pinsRNew.append(pinsR[i - (npins/2)]) - + # union all pins pinsLT = union_all(pinsLNew) pinsRT = union_all(pinsRNew) @@ -385,7 +385,7 @@ def union_all(objects): #mvX = (npins*e/4+e/2) #mvY = (E-c)/2 #pins = pins.translate ((-mvX,-mvY,0)) - + return (pinsT) @@ -402,7 +402,7 @@ def make_pins_smd(params, type, modelName): e = params.e # pin center to center distance (pitch) npins = params.npins # number of pins - + corner = params.corner excludepins = params.excludepins @@ -425,11 +425,11 @@ def chamfer_corner(pina): edges(BS((1000, E/2.-c-0.001, ty-c-0.001), (-1000, E/2.-c+0.001, ty-c+0.001))).chamfer(c/0.18).\ edges(BS((1000, E/2.-0.001, ty-0.001), (-1000, E/2.+0.001, ty+0.001))).chamfer(6.*c) - + # draw 1st pin x = e*(npins/4.-0.5) # center x position of first pin ty = (A2+c)/2.+A1 # top point (max z) of pin - + # draw the side part of the pin pin = cq.Workplane("XZ", (x, E/2., 0)). \ moveTo(-b, 0). \ @@ -458,7 +458,7 @@ def chamfer_corner(pina): pinsR = [pin.translate((0,0,0))] # # -# +# if npins/2>2: # draw the 2nd pin (regular pin shape) x = e*(npins/4.-0.5-1) # center x position of 2nd pin @@ -468,7 +468,7 @@ def chamfer_corner(pina): lineTo(b, ty). \ lineTo(b, 0). \ close().extrude(c) - + # draw the top part of the pin pin2 = pin2.faces(">Z").workplane().center(0, -(4. * b) + c/2.).rect(2*b, 8 * b).extrude(-c) @@ -488,7 +488,7 @@ def chamfer_corner(pina): pinsL.append(pin_i) pinsR.append(pin_i.translate((0,0,0))) - + # create last pin (mirrored 1st pin) x = -e*(npins/4.-0.5) pinl = cq.Workplane("XZ", (x, E/2., 0)). \ @@ -510,7 +510,7 @@ def chamfer_corner(pina): pinsL.append(pinl) pinsR.append(pinl.translate((0,0,0))) - + def union_all(objects): o = objects[0] for i in range(1,len(objects)): @@ -528,8 +528,8 @@ def union_all(objects): tts = "len(pinsR) " + str(len(pinsR)) + "\r\n" FreeCAD.Console.PrintMessage(tts) for ei in excludepins: - tts = "excludepins " + str(ei) + "\r\n" - FreeCAD.Console.PrintMessage(tts) + tts = "excludepins " + str(ei) + "\r\n" + FreeCAD.Console.PrintMessage(tts) for i in range(0, npins/2): AddPinLeft = True for ei in excludepins: @@ -549,7 +549,7 @@ def union_all(objects): tts = "Adding to pinsRNew " + str(i - (npins/2)) + "\r\n" FreeCAD.Console.PrintMessage(tts) pinsRNew.append(pinsR[i - (npins/2)]) - + # union all pins pinsLT = union_all(pinsLNew) pinsRT = union_all(pinsRNew) @@ -576,19 +576,19 @@ def make_one(variant, filename, type): ## filename) print("Done generating DIL %s variant." % variant) - + def make_3D_model(models_dir, variant): - + LIST_license = ["",] modelName = all_params[variant].modelName - + CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedmodelName) App.setActiveDocument(CheckedmodelName) Gui.ActiveDocument=Gui.getDocument(CheckedmodelName) case = make_case(all_params[variant], type, modelName) - + if (all_params[variant].type == CASE_THT_TYPE): pins = make_pins_tht(all_params[variant], type, modelName) @@ -609,7 +609,7 @@ def make_3D_model(models_dir, variant): show(pins) #show(pinmark) #stop - + doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) @@ -703,7 +703,7 @@ def make_3D_model(models_dir, variant): #FreeCADGui.ActiveDocument.activeObject.BoundingBox = True - + def run(): ## # get variant names from command line @@ -768,29 +768,29 @@ def run(): #stop buildAllSMD = 0 - + if len(sys.argv) < 3: FreeCAD.Console.PrintMessage('No variant name is given! building DIP-8_W7.62mm') model_to_build='DIP-8_W7.62mm' else: model_to_build=sys.argv[2] - + if model_to_build == "all": variants = all_params.keys() - + if model_to_build == "allsmd": variants = all_params.keys() buildAllSMD = 1 else: variants = [model_to_build] - - + + if (buildAllSMD == 1): for variant in variants: if (all_params[variant].type == CASE_SMD_TYPE): FreeCAD.Console.PrintMessage('\r\n'+variant) make_3D_model(models_dir, variant) - + else: for variant in variants: FreeCAD.Console.PrintMessage('\r\n'+variant) From 3a9e391aa98f1359dc708cc4004bbb7ba0e1c02e Mon Sep 17 00:00:00 2001 From: Andrea Cisternino Date: Sun, 10 May 2020 11:24:53 +0200 Subject: [PATCH 2/4] main_generator.py: fix file issues and print functions --- cadquery/FCAD_script_generator/DIP_packages/main_generator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cadquery/FCAD_script_generator/DIP_packages/main_generator.py b/cadquery/FCAD_script_generator/DIP_packages/main_generator.py index cb8ca20d..9f166510 100644 --- a/cadquery/FCAD_script_generator/DIP_packages/main_generator.py +++ b/cadquery/FCAD_script_generator/DIP_packages/main_generator.py @@ -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 # @@ -124,7 +124,7 @@ try: close_CQ_Example(App, Gui) except: # catch *all* exceptions - print "CQ 030 doesn't open example file" + print("CQ 030 doesn't open example file") import cq_parameters # modules parameters From 884238a78100bba0dc0b96b7bf4b8890ea935666 Mon Sep 17 00:00:00 2001 From: Andrea Cisternino Date: Sun, 10 May 2020 11:49:10 +0200 Subject: [PATCH 3/4] main_generator.py: fix import issues --- .../DIP_packages/main_generator.py | 45 +++++++++++++++---- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/cadquery/FCAD_script_generator/DIP_packages/main_generator.py b/cadquery/FCAD_script_generator/DIP_packages/main_generator.py index 9f166510..056a04be 100644 --- a/cadquery/FCAD_script_generator/DIP_packages/main_generator.py +++ b/cadquery/FCAD_script_generator/DIP_packages/main_generator.py @@ -96,28 +96,55 @@ ################################################################################################# -# Import cad_tools -import cq_cad_tools -# Reload tools -reload(cq_cad_tools) # Explicitly load all needed functions from cq_cad_tools import FuseObjs_wColors, GetListOfObjects, restore_Main_Tools, \ exportSTEP, close_CQ_Example, exportVRML, saveFCdoc, z_RotateObject, Color_Objects, \ CutObjs_wColors, checkRequirements +# Sphinx workaround #1 +try: + QtGui +except NameError: + QtGui = None try: # Gui.SendMsgToActiveView("Run") - from Gui.Command import * Gui.activateWorkbench("CadQueryWorkbench") - import cadquery as cq + import cadquery + cq = cadquery from Helpers import show # CadQuery Gui except: # catch *all* exceptions - msg="missing CadQuery 0.3.0 or later Module!\r\n\r\n" - msg+="https://github.com/jmwright/cadquery-freecad-module/wiki\n" - reply = QtGui.QMessageBox.information(None,"Info ...",msg) + msg = "missing CadQuery 0.3.0 or later Module!\r\n\r\n" + msg += "https://github.com/jmwright/cadquery-freecad-module/wiki\n" + if QtGui is not None: + reply = QtGui.QMessageBox.information(None,"Info ...",msg) # maui end +# Sphinx workaround #2 +try: + cq + checkRequirements(cq) +except NameError: + cq = None +# + +def reload_lib(lib): + if (sys.version_info > (3, 0)): + import importlib + importlib.reload(lib) + else: + importlib.reload (lib) + + +# Import cad_tools +import cq_cad_tools +# Reload tools +reload_lib(cq_cad_tools) +# Explicitly load all needed functions +from cq_cad_tools import FuseObjs_wColors, GetListOfObjects, restore_Main_Tools, \ + exportSTEP, close_CQ_Example, exportVRML, saveFCdoc, z_RotateObject, Color_Objects, \ + CutObjs_wColors, checkRequirements, runGeometryCheck + #checking requirements checkRequirements(cq) From fcff0b7376df85380cbc4c58160d81239712d49f Mon Sep 17 00:00:00 2001 From: Andrea Cisternino Date: Sun, 10 May 2020 11:52:27 +0200 Subject: [PATCH 4/4] main_generator.py: fix float division issues --- .../DIP_packages/main_generator.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cadquery/FCAD_script_generator/DIP_packages/main_generator.py b/cadquery/FCAD_script_generator/DIP_packages/main_generator.py index 056a04be..e3290aa8 100644 --- a/cadquery/FCAD_script_generator/DIP_packages/main_generator.py +++ b/cadquery/FCAD_script_generator/DIP_packages/main_generator.py @@ -334,7 +334,7 @@ def chamfer_corner(pina): # create other pins (except last one) pinsL.append(pin2) pinsR.append(pin2.translate((0,0,0))) - for i in range(2,npins/2-1): + for i in range(2,npins//2-1): pin_i = pin2.translate((-e*(i-1),0,0)) pinsL.append(pin_i) pinsR.append(pin_i.translate((0,0,0))) @@ -381,7 +381,7 @@ def union_all(objects): for ei in excludepins: tts = "excludepins " + str(ei) + "\r\n" FreeCAD.Console.PrintMessage(tts) - for i in range(0, npins/2): + for i in range(0, npins//2): AddPinLeft = True for ei in excludepins: if ((i + 1) == ei): @@ -391,7 +391,7 @@ def union_all(objects): FreeCAD.Console.PrintMessage(tts) pinsLNew.append(pinsL[i]) - for i in range(npins/2, npins): + for i in range(npins//2, npins): AddPinRight = True for ei in excludepins: if ((i + 1) == ei): @@ -399,7 +399,7 @@ def union_all(objects): if (AddPinRight): tts = "Adding to pinsRNew " + str(i - (npins/2)) + "\r\n" FreeCAD.Console.PrintMessage(tts) - pinsRNew.append(pinsR[i - (npins/2)]) + pinsRNew.append(pinsR[i - (npins//2)]) # union all pins pinsLT = union_all(pinsLNew) @@ -510,7 +510,7 @@ def chamfer_corner(pina): # create other pins (except last one) pinsL.append(pin2) pinsR.append(pin2.translate((0,0,0))) - for i in range(2,npins/2-1): + for i in range(2,npins//2-1): pin_i = pin2.translate((-e*(i-1),0,0)) pinsL.append(pin_i) pinsR.append(pin_i.translate((0,0,0))) @@ -557,7 +557,7 @@ def union_all(objects): for ei in excludepins: tts = "excludepins " + str(ei) + "\r\n" FreeCAD.Console.PrintMessage(tts) - for i in range(0, npins/2): + for i in range(0, npins//2): AddPinLeft = True for ei in excludepins: if ((i + 1) == ei): @@ -567,7 +567,7 @@ def union_all(objects): FreeCAD.Console.PrintMessage(tts) pinsLNew.append(pinsL[i]) - for i in range(npins/2, npins): + for i in range(npins//2, npins): AddPinRight = True for ei in excludepins: if ((i + 1) == ei): @@ -575,7 +575,7 @@ def union_all(objects): if (AddPinRight): tts = "Adding to pinsRNew " + str(i - (npins/2)) + "\r\n" FreeCAD.Console.PrintMessage(tts) - pinsRNew.append(pinsR[i - (npins/2)]) + pinsRNew.append(pinsR[i - (npins//2)]) # union all pins pinsLT = union_all(pinsLNew)