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

Convert to Python3 #5

Open
wants to merge 1 commit 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
18 changes: 10 additions & 8 deletions bin/cnc25d_example_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

import os, re, sys
import subprocess
import six
from six.moves import input

##############################################################################
# Checking FreeCAD installation
Expand Down Expand Up @@ -76,11 +78,11 @@
freecad_verion_major = int(freecad_verion[0])
freecad_verion_minor = int(freecad_verion[1])
if((freecad_verion_major==0)and(freecad_verion_minor<13)):
print("ERR056: Error, Your FreeCAD version is too old! You have {:d}.{:d} and 0.13 or newer is needed.".format(freecad_verion_major, freecad_verion_minor))
six.print_(("ERR056: Error, Your FreeCAD version is too old! You have {:d}.{:d} and 0.13 or newer is needed.".format(freecad_verion_major, freecad_verion_minor)))
print("Please, install the latest FreeCAD version on your system and re-run this script.")
sys.exit(1)
#info
print("The FreeCAD version {:d}.{:d} is installed on your system.".format(freecad_verion_major, freecad_verion_minor))
six.print_(("The FreeCAD version {:d}.{:d} is installed on your system.".format(freecad_verion_major, freecad_verion_minor)))

### check if the FreeCAD Library can be imported

Expand Down Expand Up @@ -4014,8 +4016,8 @@ def sub_canvas_graphics(ai_rotation_direction, ai_angle_position):
ceg_example_list_sorted_keys = sorted(ceg_example_list.keys())
print("\nThis executable helps you to generate the following cnc25d script examples in the current directory:")
for l_example in ceg_example_list_sorted_keys:
print(" + {:s}".format(l_example))
user_choice=raw_input("Do you want to generate all these upper files in the current directory? [yes/No] ")
six.print_((" + {:s}".format(l_example)))
user_choice=input("Do you want to generate all these upper files in the current directory? [yes/No] ")
if((user_choice=='yes')or(user_choice=='y')):
for l_example in ceg_example_list_sorted_keys:
fh_output = open(l_example, 'w')
Expand All @@ -4025,14 +4027,14 @@ def sub_canvas_graphics(ai_rotation_direction, ai_angle_position):
else:
print("Choose which cnc25d script example you want to generate in the current directory:")
for l_example in ceg_example_list_sorted_keys:
print("cnc25d script example : {:s}".format(l_example))
user_choice=raw_input("Do you want to generate the file {:s} in the current directory? [yes/No] ".format(l_example))
six.print_(("cnc25d script example : {:s}".format(l_example)))
user_choice=input("Do you want to generate the file {:s} in the current directory? [yes/No] ".format(l_example))
if((user_choice=='yes')or(user_choice=='y')):
fh_output = open(l_example, 'w')
fh_output.write(ceg_example_list[l_example])
fh_output.close()
print(ceg_instructions.format(l_example, l_example, l_example))
six.print_((ceg_instructions.format(l_example, l_example, l_example)))
else:
print("The script example {:s} has not been created.".format(l_example))
six.print_(("The script example {:s} has not been created.".format(l_example)))


18 changes: 10 additions & 8 deletions bin/cnc25d_example_generator_src.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

import os, re, sys
import subprocess
import six
from six.moves import input

##############################################################################
# Checking FreeCAD installation
Expand Down Expand Up @@ -76,11 +78,11 @@
freecad_verion_major = int(freecad_verion[0])
freecad_verion_minor = int(freecad_verion[1])
if((freecad_verion_major==0)and(freecad_verion_minor<13)):
print("ERR056: Error, Your FreeCAD version is too old! You have {:d}.{:d} and 0.13 or newer is needed.".format(freecad_verion_major, freecad_verion_minor))
six.print_(("ERR056: Error, Your FreeCAD version is too old! You have {:d}.{:d} and 0.13 or newer is needed.".format(freecad_verion_major, freecad_verion_minor)))
print("Please, install the latest FreeCAD version on your system and re-run this script.")
sys.exit(1)
#info
print("The FreeCAD version {:d}.{:d} is installed on your system.".format(freecad_verion_major, freecad_verion_minor))
six.print_(("The FreeCAD version {:d}.{:d} is installed on your system.".format(freecad_verion_major, freecad_verion_minor)))

### check if the FreeCAD Library can be imported

Expand Down Expand Up @@ -317,8 +319,8 @@
ceg_example_list_sorted_keys = sorted(ceg_example_list.keys())
print("\nThis executable helps you to generate the following cnc25d script examples in the current directory:")
for l_example in ceg_example_list_sorted_keys:
print(" + {:s}".format(l_example))
user_choice=raw_input("Do you want to generate all these upper files in the current directory? [yes/No] ")
six.print_((" + {:s}".format(l_example)))
user_choice=input("Do you want to generate all these upper files in the current directory? [yes/No] ")
if((user_choice=='yes')or(user_choice=='y')):
for l_example in ceg_example_list_sorted_keys:
fh_output = open(l_example, 'w')
Expand All @@ -328,14 +330,14 @@
else:
print("Choose which cnc25d script example you want to generate in the current directory:")
for l_example in ceg_example_list_sorted_keys:
print("cnc25d script example : {:s}".format(l_example))
user_choice=raw_input("Do you want to generate the file {:s} in the current directory? [yes/No] ".format(l_example))
six.print_(("cnc25d script example : {:s}".format(l_example)))
user_choice=input("Do you want to generate the file {:s} in the current directory? [yes/No] ".format(l_example))
if((user_choice=='yes')or(user_choice=='y')):
fh_output = open(l_example, 'w')
fh_output.write(ceg_example_list[l_example])
fh_output.close()
print(ceg_instructions.format(l_example, l_example, l_example))
six.print_((ceg_instructions.format(l_example, l_example, l_example)))
else:
print("The script example {:s} has not been created.".format(l_example))
six.print_(("The script example {:s} has not been created.".format(l_example)))


3 changes: 2 additions & 1 deletion cnc25d/angles.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
################################################################

import math
import six

################################################################
# functions
Expand All @@ -53,7 +54,7 @@ def roll_pitch_to_pan_tilt(ai_a1, ai_a2):
if(abs(sin_A)<1+radian_epsilon):
sin_A = math.copysign(1, sin_A)
else:
print("ERR053: Internal Error, sin_A {:0.3f}".format(sin_A))
six.print_(("ERR053: Internal Error, sin_A {:0.3f}".format(sin_A)))
sys.exit(2)
A = math.asin(sin_A)
b1 = b1_sign*math.pi/2 - A
Expand Down
43 changes: 22 additions & 21 deletions cnc25d/axle_lid.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
# header for Python / FreeCAD compatibility
################################################################

import cnc25d_api
from . import cnc25d_api
import six
cnc25d_api.importing_freecad()

#print("FreeCAD.Version:", FreeCAD.Version())
Expand All @@ -52,7 +53,7 @@
#import svgwrite
#from dxfwrite import DXFEngine
# cnc25d
import gearring
from . import gearring

################################################################
# inheritance from gearring
Expand Down Expand Up @@ -225,19 +226,19 @@ def axle_lid_constraint_check(c):
# print("ERR141: Error, cnc_router_bit_radius {:0.3f} is bigger than axle_hole_radius {:0.3f}".format(c['cnc_router_bit_radius'], c['axle_hole_radius']))
# sys.exit(2)
if(c['axle_hole_radius']>c['central_radius']-radian_epsilon):
print("ERR144: Error, axle_hole_radius {:0.3f} is bigger than central_radius {:0.3f}".format(c['axle_hole_radius'], c['central_radius']))
six.print_(("ERR144: Error, axle_hole_radius {:0.3f} is bigger than central_radius {:0.3f}".format(c['axle_hole_radius'], c['central_radius'])))
sys.exit(2)
if(c['central_radius']>c['clearance_radius']-radian_epsilon):
print("ERR147: Error, central_radius {:0.3f} is bigger than clearance_radius {:0.3f}".format(c['central_radius'], c['clearance_radius']))
six.print_(("ERR147: Error, central_radius {:0.3f} is bigger than clearance_radius {:0.3f}".format(c['central_radius'], c['clearance_radius'])))
sys.exit(2)
if(c['clearance_radius']>c['holder_radius']-radian_epsilon):
print("ERR151: Error, clearance_radius {:0.3f} is bigger than the holder_radius {:0.3f}".format(c['clearance_radius'], c['holder_radius']))
six.print_(("ERR151: Error, clearance_radius {:0.3f} is bigger than the holder_radius {:0.3f}".format(c['clearance_radius'], c['holder_radius'])))
sys.exit(2)
if(c['annulus_holder_axle_hole_radius']>c['clearance_radius']):
print("ERR159: Error, annulus_holder_axle_hole_radius {:0.3f} is bigger than clearance_radius {:0.3f}".format(c['annulus_holder_axle_hole_radius'], c['clearance_radius']))
six.print_(("ERR159: Error, annulus_holder_axle_hole_radius {:0.3f} is bigger than clearance_radius {:0.3f}".format(c['annulus_holder_axle_hole_radius'], c['clearance_radius'])))
sys.exit(2)
if(c['holder_crenel_number']<4):
print("ERR154: Error, holder_crenel_number {:d} is smaller than 4".format(c['holder_crenel_number']))
six.print_(("ERR154: Error, holder_crenel_number {:d} is smaller than 4".format(c['holder_crenel_number'])))
sys.exit(2)
c['middle_crenel_1'] = 0
c['middle_crenel_2'] = int(c['holder_crenel_number']/2)
Expand Down Expand Up @@ -267,22 +268,22 @@ def axle_lid_constraint_check(c):
c['leg_hole_distance'] = 2*(2*c['leg_hole_radius'] + c['leg_hole_length'])
if(c['leg_type'] != 'none'):
if((c['leg_type'] != 'rear') and (c['leg_type'] != 'side')):
print("ERR536: Error, leg_type {:s} set to an unknow value. Possible values: 'none', 'rear' or 'side'".format(c['leg_type']))
six.print_(("ERR536: Error, leg_type {:s} set to an unknow value. Possible values: 'none', 'rear' or 'side'".format(c['leg_type'])))
sys.exit(2)
if(c['leg_length']<=0):
print("ERR539: Error, leg_length {:0.3f} must be strictly positive".format(c['leg_length']))
six.print_(("ERR539: Error, leg_length {:0.3f} must be strictly positive".format(c['leg_length'])))
sys.exit(2)
if(c['toe_length']<c['leg_hole_radius']):
print("ERR543: Error, toe_length {:0.3f} is smaller than leg_hole_radius {:0.3f}".format(c['toe_length'], c['leg_hole_radius']))
six.print_(("ERR543: Error, toe_length {:0.3f} is smaller than leg_hole_radius {:0.3f}".format(c['toe_length'], c['leg_hole_radius'])))
sys.exit(2)
#if(c['foot_length']<c['leg_hole_radius']):
# print("ERR543: Error, foot_length {:0.3f} is smaller than leg_hole_radius {:0.3f}".format(c['foot_length'], c['leg_hole_radius']))
# sys.exit(2)
if(c['leg_hole_distance']<2*c['leg_hole_radius']+c['leg_hole_length']):
print("ERR549: Error, leg_hole_distance {:0.3f} is too small compare to leg_hole_radius {:0.3f} and leg_hole_length {:0.3f}".format(c['leg_hole_distance'], c['leg_hole_radius'], c['leg_hole_length']))
six.print_(("ERR549: Error, leg_hole_distance {:0.3f} is too small compare to leg_hole_radius {:0.3f} and leg_hole_length {:0.3f}".format(c['leg_hole_distance'], c['leg_hole_radius'], c['leg_hole_length'])))
sys.exit(2)
if(c['leg_border_length']<c['leg_hole_radius']):
print("ERR552: Error, leg_border_length {:0.3f} is smaller than leg_hole_radius {:0.3f}".format(c['leg_border_length'], c['leg_hole_radius']))
six.print_(("ERR552: Error, leg_border_length {:0.3f} is smaller than leg_hole_radius {:0.3f}".format(c['leg_border_length'], c['leg_hole_radius'])))
sys.exit(2)
### axle_B
c['output_axle_B_internal_radius'] = c['output_axle_B_internal_diameter']/2.0
Expand Down Expand Up @@ -464,27 +465,27 @@ def axle_lid_2d_construction(c):
### axle_B
if(c['output_axle_B_place'] != 'none'):
if((c['output_axle_B_place'] != 'small')and(c['output_axle_B_place'] != 'large')):
print("ERR442: Error, output_axle_B_place {:s} is unknown. Possible values: 'none', 'small' or 'large'".format(c['output_axle_B_place']))
six.print_(("ERR442: Error, output_axle_B_place {:s} is unknown. Possible values: 'none', 'small' or 'large'".format(c['output_axle_B_place'])))
sys.exit(2)
if(c['output_axle_distance']<=0.0):
print("ERR445: Error, output_axle_distance {:0.3f} must be positive".format(c['output_axle_distance']))
six.print_(("ERR445: Error, output_axle_distance {:0.3f} must be positive".format(c['output_axle_distance'])))
sys.exit(2)
if(c['output_axle_B_external_radius'] == 0):
c['output_axle_B_external_radius'] = 2*c['output_axle_B_internal_radius']
if(c['output_axle_B_external_radius']<=c['output_axle_B_internal_radius']):
print("ERR452: Error, output_axle_B_external_radius {:0.3f} is null or smaller than output_axle_B_internal_radius {:0.3f}".format(c['output_axle_B_external_radius'], c['output_axle_B_internal_radius']))
six.print_(("ERR452: Error, output_axle_B_external_radius {:0.3f} is null or smaller than output_axle_B_internal_radius {:0.3f}".format(c['output_axle_B_external_radius'], c['output_axle_B_internal_radius'])))
sys.exit(2)
if(c['output_axle_B_crenel_number']>0):
if(c['output_axle_B_crenel_radius']<radian_epsilon):
print("ERR460: Error, output_axle_B_crenel_radius {:0.3f} is too small".format(c['output_axle_B_crenel_radius']))
six.print_(("ERR460: Error, output_axle_B_crenel_radius {:0.3f} is too small".format(c['output_axle_B_crenel_radius'])))
sys.exit(2)
if(c['output_axle_B_crenel_position_radius'] == 0):
c['output_axle_B_crenel_position_radius'] = (c['output_axle_B_internal_radius'] + c['output_axle_B_external_radius'])/2.0
if(c['output_axle_B_crenel_position_radius']<(c['output_axle_B_internal_radius']+c['output_axle_B_crenel_radius'])):
print("ERR460: Error, output_axle_B_crenel_position_radius {:0.3f} is too small compare to output_axle_B_internal_radius {:0.3f} and output_axle_B_crenel_radius {:0.3f}".format(c['output_axle_B_crenel_position_radius'], c['output_axle_B_internal_radius'], c['output_axle_B_crenel_radius']))
six.print_(("ERR460: Error, output_axle_B_crenel_position_radius {:0.3f} is too small compare to output_axle_B_internal_radius {:0.3f} and output_axle_B_crenel_radius {:0.3f}".format(c['output_axle_B_crenel_position_radius'], c['output_axle_B_internal_radius'], c['output_axle_B_crenel_radius'])))
sys.exit(2)
if(c['output_axle_B_crenel_position_radius']>(c['output_axle_B_external_radius']-c['output_axle_B_crenel_radius'])):
print("ERR463: Error, output_axle_B_crenel_position_radius {:0.3f} is too big compare to output_axle_B_external_radius {:0.3f} and output_axle_B_crenel_radius {:0.3f}".format(c['output_axle_B_crenel_position_radius'], c['output_axle_B_external_radius'], c['output_axle_B_crenel_radius']))
six.print_(("ERR463: Error, output_axle_B_crenel_position_radius {:0.3f} is too big compare to output_axle_B_external_radius {:0.3f} and output_axle_B_crenel_radius {:0.3f}".format(c['output_axle_B_crenel_position_radius'], c['output_axle_B_external_radius'], c['output_axle_B_crenel_radius'])))
sys.exit(2)
## calculation of the angle (DCE)
ABC = (c['middle_crenel_2'] - c['middle_crenel_1'] - 1) * c['crenel_portion_angle'] / 2.0 - c['holder_crenel_half_angle']
Expand All @@ -495,7 +496,7 @@ def axle_lid_2d_construction(c):
AC1 = math.sqrt(AB**2 + BC**2 - 2*AB*BC*math.cos(ABC1))
cos_ACB1 = ((AC1**2+BC**2-AB**2)/(2*AC1*BC))
if((cos_ACB1<radian_epsilon)or(cos_ACB1>1-radian_epsilon)):
print("ERR474: Error, cos_ACB1 {:0.3f} is out of the range 0..1".format(cos_ACB1))
six.print_(("ERR474: Error, cos_ACB1 {:0.3f} is out of the range 0..1".format(cos_ACB1)))
sys.exit(2)
ACB1 = math.acos(cos_ACB1)
DC = c['output_axle_B_external_radius']
Expand Down Expand Up @@ -539,10 +540,10 @@ def axle_lid_2d_construction(c):
# external_axle_B_half_angle
external_axle_B_half_angle = math.atan(float(input_axle_B_external_radius)/c['holder_radius'])
if(first_angle>c['output_axle_B_angle']-external_axle_B_half_angle):
print("ERR500: Error, first_angle {:0.3f} too big compare to output_axle_B_angle {:0.3f} and external_axle_B_half_angle {:0.3f}".format(first_angle, c['output_axle_B_angle'], external_axle_B_half_angle))
six.print_(("ERR500: Error, first_angle {:0.3f} too big compare to output_axle_B_angle {:0.3f} and external_axle_B_half_angle {:0.3f}".format(first_angle, c['output_axle_B_angle'], external_axle_B_half_angle)))
sys.exit(2)
if(last_angle<c['output_axle_B_angle']+external_axle_B_half_angle):
print("ERR503: Error, last_angle {:0.3f} too small compare to output_axle_B_angle {:0.3f} and external_axle_B_half_angle {:0.3f}".format(last_angle, c['output_axle_B_angle'], external_axle_B_half_angle))
six.print_(("ERR503: Error, last_angle {:0.3f} too small compare to output_axle_B_angle {:0.3f} and external_axle_B_half_angle {:0.3f}".format(last_angle, c['output_axle_B_angle'], external_axle_B_half_angle)))
sys.exit(2)
holder_A = []
# first point
Expand Down
Loading