import Part
import math
from FreeCAD import Base
######################## SET THESE PARAMETERS ####################
#box size (inside)
L=350
#wood thickness
e=3.1
#box depth (=height in sowing machine)
h=40
#tolerance for glued parts
tol=0
#tolerance for moving parts
space=0.1
#holes diameter to drain water
holeDiam=5
#number of holes on one row
nbHoles=10
##################################################################

#face
lenght=float(L+2*e+2*space)
face = Part.makeBox(lenght,h+e,e)
cutterH = Part.makeBox(lenght/5+2*tol,e+tol,e)
cutterV = Part.makeBox(e+tol,float(h)/4+2*tol,e)

cutterH.translate(Base.Vector(-tol,0,0))
face = face.cut(cutterH)
cutterH.translate(Base.Vector(2*lenght/5,0,0))
face = face.cut(cutterH)
cutterH.translate(Base.Vector(2*lenght/5,0,0))
face = face.cut(cutterH)

cutterV.translate(Base.Vector(0,e,0))
face = face.cut(cutterV)
cutterV.translate(Base.Vector(0,2*float(h)/4,0))
face = face.cut(cutterV)
cutterV.translate(Base.Vector(lenght-e-tol,float(h)/4,0))
face = face.cut(cutterV)
cutterV.translate(Base.Vector(0,-2*float(h)/4,0))
face = face.cut(cutterV)

face.translate(Base.Vector(0,-2*h,0))

#bottom
bottom = Part.makeBox(lenght,lenght,e)

#repositioning at origin
cutterH = Part.makeBox(lenght/5+2*tol,e+tol,e)
cutterH.translate(Base.Vector(-tol+lenght/5,0,0))
bottom = bottom.cut(cutterH)
cutterH.translate(Base.Vector(2*lenght/5,0,0))
bottom = bottom.cut(cutterH)

bottom.rotate(Base.Vector(lenght/2,lenght/2,0),Base.Vector(0,0,1),90)

##repositioning at origin
cutterH = Part.makeBox(lenght/5+2*tol,e+tol,e)
cutterH.translate(Base.Vector(-tol+lenght/5,0,0))
bottom = bottom.cut(cutterH)
cutterH.translate(Base.Vector(2*lenght/5,0,0))
bottom = bottom.cut(cutterH)

bottom.rotate(Base.Vector(lenght/2,lenght/2,0),Base.Vector(0,0,1),90)

#repositioning at origin
cutterH = Part.makeBox(lenght/5+2*tol,e+tol,e)
cutterH.translate(Base.Vector(-tol+lenght/5,0,0))
bottom = bottom.cut(cutterH)
cutterH.translate(Base.Vector(2*lenght/5,0,0))
bottom = bottom.cut(cutterH)

bottom.rotate(Base.Vector(lenght/2,lenght/2,0),Base.Vector(0,0,1),90)

#repositioning at origin
cutterH = Part.makeBox(lenght/5+2*tol,e+tol,e)
cutterH.translate(Base.Vector(-tol+lenght/5,0,0))
bottom = bottom.cut(cutterH)
cutterH.translate(Base.Vector(2*lenght/5,0,0))
bottom = bottom.cut(cutterH)

hole = Part.makeCylinder(5,e)
hole.translate(Base.Vector(2*e+holeDiam,2*e+holeDiam,0))

i=e+(lenght-2*e)/(2*nbHoles)
for x in range(1,nbHoles+1):
	j=e+(lenght-2*e)/(2*nbHoles)
	for y in range(1,nbHoles+1):
		hole = Part.makeCylinder(float(holeDiam)/2,e,Base.Vector(i,j,0))
		bottom = bottom.cut(hole)
		j=j+(lenght-2*e)/(nbHoles)
	i=i+(lenght-2*e)/(nbHoles)


Part.show(bottom)
Part.show(face)
Gui.SendMsgToActiveView("ViewFit")