Skip to content
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
29 changes: 2 additions & 27 deletions InitGui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import ksu_locator
from kicadStepUpCMD import *

from utils import make_string as mk_str, make_unicode as mk_uni


ksuWBpath = os.path.dirname(ksu_locator.__file__)
#sys.path.append(ksuWB + '/Gui')
Expand Down Expand Up @@ -275,33 +277,6 @@ def Activated(self):
prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui")
if prefs.IsEmpty():
#if prefs.GetContents() is None:
def mk_str(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.encode('utf-8')
return input
else: #py2
if type(input) == unicode:
input = input.encode('utf-8')
return input
else:
return input
def mk_uni(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.decode('utf-8')
return input
else: #py2
if type(input) != unicode:
input = input.decode('utf-8')
return input
else:
return input
##
FreeCAD.Console.PrintError('Creating first time ksu preferences\n')
#prefs.SetString('prefix3d_1',make_string(default_prefix3d))
prefs.SetInt('pcb_color',0)
Expand Down
31 changes: 3 additions & 28 deletions fps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import math
from math import radians

from utils import crc_gen, make_string, make_unicode

consolePrint = FreeCAD.Console.PrintMessage
consolePrint('fp loader v'+fps_version+'\n')

Expand Down Expand Up @@ -98,32 +100,6 @@ def makeAnno (name,bp,txt,afs):
return anno
#

def crc_gen_t(data):
import binascii
import re

#data=u'Würfel'
content=re.sub(r'[^\x00-\x7F]+','_', data)
#make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:])
#hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:].encode('utf-8')
#print(data +u'_'+ hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:])
return u'_'+ make_unicode_t(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:])
##

def make_unicode_t(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.decode('utf-8')
return input
else: #py2
if type(input) != unicode:
input = input.decode('utf-8')
return input
else:
return input

def mkColor(*color):
if len(color)==1:
if isinstance(color[0],basestring):
Expand Down Expand Up @@ -270,7 +246,6 @@ def simple_cpy (obj,lbl):
#

from kicadStepUptools import removesubtree, cfg_read_all
from kicadStepUptools import make_unicode, make_string
import fcad_parser
from fcad_parser import KicadPCB,SexpList

Expand Down Expand Up @@ -355,7 +330,7 @@ def addfootprint(fname = None):
last_pcb_path=os.path.dirname(fname)
path, ftname = os.path.split(fname)
ftname=os.path.splitext(ftname)[0]
ftname_sfx=crc_gen_t(make_unicode_t(ftname))
ftname_sfx=crc_gen(make_unicode(ftname))
pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUp")
pg.SetString("last_pcb_path", make_string(last_pcb_path)) # py3 .decode("utf-8")
prefs = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui")
Expand Down
109 changes: 7 additions & 102 deletions kicadStepUpCMD.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import constrainator
from constrainator import add_constraints, sanitizeSkBsp

from utils import make_string as mk_str, make_string

ksuCMD_version__='2.5.7'

global invisible_objs
Expand Down Expand Up @@ -2815,19 +2817,6 @@ def Activated(self):
# do something here...
if FreeCADGui.Selection.getSelection():
sel=FreeCADGui.Selection.getSelection()
def mk_str(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.encode('utf-8')
return input
else: #py2
if type(input) == unicode:
input = input.encode('utf-8')
return input
else:
return input
if len(sel) != 1:
msg="Select one object with Shape to be colored Cloned!\n"
reply = QtGui.QMessageBox.information(None,"Warning", msg)
Expand Down Expand Up @@ -2884,19 +2873,6 @@ def Activated(self):
# do something here...
if FreeCADGui.Selection.getSelection():
sel=FreeCADGui.Selection.getSelection()
def mk_str(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.encode('utf-8')
return input
else: #py2
if type(input) == unicode:
input = input.encode('utf-8')
return input
else:
return input
if len(sel) != 1:
msg="Select one object with Shape to generate a colored Binder!\n"
reply = QtGui.QMessageBox.information(None,"Warning", msg)
Expand Down Expand Up @@ -2963,19 +2939,6 @@ def Activated(self):
# do something here...
if FreeCADGui.Selection.getSelection():
sel=FreeCADGui.Selection.getSelection()
def mk_str(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.encode('utf-8')
return input
else: #py2
if type(input) == unicode:
input = input.encode('utf-8')
return input
else:
return input
if len(sel) != 2:
msg="Select the Binder and one object with Shape to ReLink the Binder!\n"
reply = QtGui.QMessageBox.information(None,"Warning", msg)
Expand Down Expand Up @@ -3019,20 +2982,6 @@ def Activated(self):
if FreeCADGui.Selection.getSelection():
sel=FreeCADGui.Selection.getSelection()
doc=FreeCAD.activeDocument()
def mk_str(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.encode('utf-8')
return input
else: #py2
if type(input) == unicode:
input = input.encode('utf-8')
return input
else:
return input
##
doc.openTransaction('union')
if len(sel)<1:
msg="Select one or two objects with Shape to be copied!\n"
Expand Down Expand Up @@ -3098,20 +3047,6 @@ def Activated(self):
# do something here...
if FreeCADGui.Selection.getSelection():
sel=FreeCADGui.Selection.getSelection()
def mk_str(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.encode('utf-8')
return input
else: #py2
if type(input) == unicode:
input = input.encode('utf-8')
return input
else:
return input
##
if len(sel)<1:
msg="Select at least one object with Shape to be copied!\n"
reply = QtGui.QMessageBox.information(None,"Warning", msg)
Expand Down Expand Up @@ -3219,21 +3154,7 @@ def Activated(self):
FreeCAD.Console.PrintWarning("Select ONE Part Design Next object\nor one or more objects to be copied!\n")

FreeCADGui.addCommand('ksuToolsDeepCopy',ksuToolsDeepCopy())
#####
def mk_str_u(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.encode('utf-8')
return input
else: #py2
if type(input) == unicode:
input = input.encode('utf-8')
return input
else:
return input
###

make_compound = False

# import FreeCAD as app,FreeCADGui as gui
Expand Down Expand Up @@ -3275,7 +3196,7 @@ def deep_copy_part(doc, part, compound='flat',suffix='(copy)'):
pName= 'None'

if make_compound=='compound':
compound = doc.addObject('Part::Compound', mk_str_u(part.Label)+suffix)
compound = doc.addObject('Part::Compound', mk_str(part.Label)+suffix)
compound.Links = copied_subobjects
if 0:
o=copied_subobjects[0]
Expand All @@ -3286,7 +3207,7 @@ def deep_copy_part(doc, part, compound='flat',suffix='(copy)'):
compound.ViewObject.ShapeAppearance = oo.ViewObject.ShapeAppearance
pName = doc.ActiveObject.Name
elif make_compound=='part':
doc.addObject('App::Part',mk_str_u(part.Label)+'_')
doc.addObject('App::Part',mk_str(part.Label)+'_')
#FreeCAD.Console.PrintMessage(doc.ActiveObject.Label)
actobj=doc.ActiveObject
for uplvlobj in actobj.InListRecursive:
Expand Down Expand Up @@ -3352,9 +3273,9 @@ def copy_subobject(doc, o,suffix='(copy)'):
copy.Shape = o.Shape
#copy.Label = 'Copy of ' + o.Label
if suffix=='_':
copy.Label = mk_str_u(o.Label)+suffix
copy.Label = mk_str(o.Label)+suffix
else:
copy.Label = mk_str_u(o.Label)+'.'+suffix
copy.Label = mk_str(o.Label)+'.'+suffix
#copy.Placement = get_recursive_inverse_placement(o).inverse()
copy.Placement = o.getGlobalPlacement()

Expand Down Expand Up @@ -3759,19 +3680,6 @@ def Activated(self):
# do something here...
if FreeCADGui.Selection.getSelection():
sel=FreeCADGui.Selection.getSelection()
def mk_str(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.encode('utf-8')
return input
else: #py2
if type(input) == unicode:
input = input.encode('utf-8')
return input
else:
return input
def i_say(msg):
FreeCAD.Console.PrintMessage(msg)
FreeCAD.Console.PrintMessage('\n')
Expand Down Expand Up @@ -4076,7 +3984,6 @@ def Activated(self):

import _DXF_Import
import os
from kicadStepUptools import make_unicode, make_string
# _DXF_Import.open('D:/Temp/t4k3-DWG.DXF')
prefs_ = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui")
last_pcb_path = prefs_.GetString("last_pcb_path")
Expand Down Expand Up @@ -4123,7 +4030,6 @@ def Activated(self):
try:
import ezdxf
import os
from kicadStepUptools import make_unicode, make_string
# _DXF_Import.open('D:/Temp/t4k3-DWG.DXF')
prefs_ = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui")
last_pcb_path = prefs_.GetString("last_pcb_path")
Expand Down Expand Up @@ -4171,7 +4077,6 @@ def Activated(self):
import _DXF_Import
from dxf_parser import _importDXF
import os
from kicadStepUptools import make_unicode, make_string
prefs_ = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/kicadStepUpGui")
last_pcb_path = prefs_.GetString("last_pcb_path")
if not(prefs_.GetBool('not_native_dlg')):
Expand Down
40 changes: 1 addition & 39 deletions kicadStepUptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@
import re
import time

from utils import crc_gen, make_string, make_unicode

max_recursion_limit=5000 # kSU issue#198
sys.setrecursionlimit(max_recursion_limit)
Expand Down Expand Up @@ -1787,34 +1788,6 @@ def open(filename,insert=None):
# onLoadFootprint(filename)


def make_unicode(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.decode('utf-8')
return input
else: #py2
if type(input) != unicode:
input = input.decode('utf-8')
return input
else:
return input

def make_string(input):
if (sys.version_info > (3, 0)): #py3
if isinstance(input, str):
return input
else:
input = input.encode('utf-8')
return input
else: #py2
if type(input) == unicode:
input = input.encode('utf-8')
return input
else:
return input

def PLine(prm1,prm2):
if hasattr(Part,"LineSegment"):
return Part.LineSegment(prm1, prm2)
Expand Down Expand Up @@ -6692,17 +6665,6 @@ def PullPCB(file_name=None):
# print('Cancel')
##

def crc_gen(data):
import binascii
import re

#data=u'Würfel'
content=re.sub(r'[^\x00-\x7F]+','_', data)
#make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:])
#hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:].encode('utf-8')
#print(data +u'_'+ hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:])
return u'_'+ make_unicode(hex(binascii.crc_hqx(content.encode('utf-8'), 0x0000))[2:])
##
def check_lightDir(set_default=False):

pg=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
Expand Down
Loading