import geompy, smesh, math

f=.1

radius_Cyl=20.0*f

radius_cyl=3.0*f
height_cyl=100.0*f
position_cyl=9.0*f
length_box=2.0*position_cyl+3.0*radius_cyl
width_box=7.0*f
depth_box=1.0*f

height_Cyl=2.0*position_cyl+height_cyl

#  small_element

radius_small=0.2*f
scufundare_small=0.05*f
depth_small=(position_cyl-2.0*radius_cyl)/2.0+scufundare_small
length_rectangle=0.5*f


# Points, Vectors and Planes
O = geompy.MakeVertex(0, 0, 0)
loc_cyl_start=geompy.MakeVertex(position_cyl,0,position_cyl)
loc_cyl_end=geompy.MakeVertex(position_cyl,0,position_cyl+height_cyl)
OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
Vector_cyl = geompy.MakeVector(loc_cyl_start, loc_cyl_end)


Plane_OXY = geompy.MakePlaneLCS(None, 5.0, 1)
Plane_OYZ = geompy.MakePlaneLCS(None, 20.0, 2)
Plane_OXZ = geompy.MakePlaneLCS(None, 20.0, 3)


disk_Cyl=geompy.MakeDiskR(radius_Cyl,1)
Cyl=geompy.MakePrismVecH(disk_Cyl,OZ,height_Cyl)
#Cyl = geompy.MakeCylinder(O, OZ, radius_Cyl, height_Cyl)
cyl = geompy.MakeCylinder(loc_cyl_start, Vector_cyl, radius_cyl,height_cyl)

cylinders = geompy.MultiRotate1D(cyl, OZ, 4)
Face_1 = geompy.MakeFaceHW( length_box, width_box,1)
Rotation_1 = geompy.MakeRotation(Face_1, OZ, 90*math.pi/180.0)
Fuse_1 = geompy.MakeFuse(Rotation_1, Face_1)
Translation_1 = geompy.MakeTranslation(Fuse_1, 0, 0, position_cyl-depth_box)
Xshape1 = geompy.MakePrismVecH(Translation_1, OZ, depth_box)
Xshape2 = geompy.MakeTranslation(Xshape1, 0, 0, height_cyl+depth_box)


# small pieces


Face_1 = geompy.MakeFaceHW(length_rectangle, radius_small*2.0, 2)
#geompy.addToStudy( Face_1, 'Face_1' )
Disk_1 = geompy.MakeDiskR(radius_small, 2)
Partition_2 = geompy.MakePartition([Disk_1], [Plane_OXY], [], [], geompy.ShapeType["FACE"], 0, [], 0)
[Face_2,Face_3] = geompy.ExtractShapes(Partition_2, geompy.ShapeType["FACE"], True)
Translation_3 = geompy.MakeTranslation(Face_2, 0, 0, -length_rectangle/2.0)
Translation_4 = geompy.MakeTranslation(Face_3, 0, 0, length_rectangle/2.0)
Fuse_1 = geompy.MakeFuse(Face_1, Translation_3)
Fuse_2 = geompy.MakeFuse(Fuse_1, Translation_4)
Small = geompy.MakePrismVecH(Fuse_2, OX, depth_small)
small_x=position_cyl+radius_cyl-scufundare_small
small_z=position_cyl+height_cyl/2.0
Rotation_small=geompy.MakeRotation(Small, OX, 20*math.pi/180.0)
Small_position=geompy.MakeTranslation(Rotation_small,small_x,0,small_z)
Small_around_cyl=geompy.MultiRotate1D(Small_position,Vector_cyl,4)
Smalls=geompy.MultiRotate1D(Small_around_cyl,OZ,4)

#Fuse_2 = geompy.MakeFuse(cylinders, Xshape1)
#Fuse_3 = geompy.MakeFuse(Fuse_2, Xshape2)
Compound_1 = geompy.MakeCompound([Xshape1, Xshape2,cylinders,Smalls])

# Plane partitionare

Translation_Plane_OXY_1=geompy.MakeTranslation(Plane_OXY, 0, 0, position_cyl-depth_box)
Translation_Plane_OXY_2=geompy.MakeTranslation(Plane_OXY, 0, 0, position_cyl+1*f)
Translation_Plane_OXY_3=geompy.MakeTranslation(Plane_OXY, 0, 0, position_cyl+height_cyl/2.0-(length_rectangle+2.0*radius_small))
Translation_Plane_OXY_4=geompy.MakeTranslation(Plane_OXY, 0, 0, position_cyl+height_cyl/2.0+(length_rectangle+2.0*radius_small))
Translation_Plane_OXY_5=geompy.MakeTranslation(Plane_OXY, 0, 0, position_cyl+height_cyl)
Translation_Plane_OXY_6=geompy.MakeTranslation(Plane_OXY, 0, 0, position_cyl+height_cyl+depth_box)




Cut_1 = geompy.MakeCut(Cyl, Compound_1)
#Partition_1 = geompy.MakePartition([Cut_1], [Translation_Plane_OXY_1, Translation_Plane_OXY_2, Translation_Plane_OXY_3, Translation_Plane_OXY_4, Translation_Plane_OXY_5, Translation_Plane_OXY_6,Plane_OXZ,Plane_OYZ], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
Partition_1 = geompy.MakePartition([Cut_1], [Translation_Plane_OXY_1, Translation_Plane_OXY_2, Translation_Plane_OXY_3, Translation_Plane_OXY_4, Translation_Plane_OXY_5, Translation_Plane_OXY_6], [], [],geompy.ShapeType["SOLID"], 0, [], 0)
# Add to study


[Solid_1,Solid_2,Solid_3,Solid_4,Solid_5,Solid_6,Solid_7,Solid_8,Solid_9,Solid_10] = geompy.ExtractShapes(Partition_1, geompy.ShapeType["SOLID"], True)

#[geomObj_65] = geompy.GetSharedShapesMulti([Shared_Face_1, Solid_3, Solid_4], geompy.ShapeType["FACE"])

Wall_int = geompy.CreateGroup(Solid_5, geompy.ShapeType["FACE"])
geompy.UnionIDs(Wall_int, [44, 41, 38, 47])
Wall_ext = geompy.CreateGroup(Solid_5, geompy.ShapeType["FACE"])
geompy.UnionIDs(Wall_ext, [3])
Shared = geompy.CreateGroup(Solid_5, geompy.ShapeType["FACE"])
geompy.UnionIDs(Shared, [24])


geompy.addToStudy(O,"O")
geompy.addToStudy(loc_cyl_start,"loc_cyl_start")
geompy.addToStudy(loc_cyl_end,"loc_cyl_end")

geompy.addToStudy(OX,"OX")
geompy.addToStudy(OY,"OY")
geompy.addToStudy(OZ,"OZ")
geompy.addToStudy( Vector_cyl, 'Vector_cyl' )


geompy.addToStudy(Plane_OXY,"Plane_OXY")
geompy.addToStudy(Plane_OYZ,"Plane_OYZ")
geompy.addToStudy(Plane_OXZ,"Plane_OXZ")
geompy.addToStudy( Cyl, 'Cyl' )
geompy.addToStudy( cyl, 'cyl' )
geompy.addToStudy( cylinders, 'cylinders' )
geompy.addToStudy( Fuse_1, 'Fuse_1' )
geompy.addToStudy( Xshape1, 'Xshape1' )
geompy.addToStudy( Xshape2, 'Xshape2' )


# geompy.addToStudy( Face_1, 'Face_1' )
# geompy.addToStudy( Disk_1, 'Disk_1' )
# geompy.addToStudy( Partition_2, 'Partition_2' )
# geompy.addToStudyInFather( Partition_2, Face_2, 'Face_2' )
# geompy.addToStudyInFather( Partition_2, Face_3, 'Face_3' )
# geompy.addToStudy( Translation_3, 'Translation_3' )
# geompy.addToStudy( Translation_4, 'Translation_4' )
# geompy.addToStudy( Fuse_1, 'Fuse_1' )
# geompy.addToStudy( Fuse_2, 'Fuse_2' )
geompy.addToStudy(Small,'Small')
geompy.addToStudy(Small_position,'Small_position')
geompy.addToStudy(Small_around_cyl,'Small_around_cyl')
geompy.addToStudy(Smalls,'Smalls')
#geompy.addToStudy( Fuse_3, 'Fuse_3' )
geompy.addToStudy( Compound_1, 'Compound_1' )


geompy.addToStudy(Translation_Plane_OXY_1,'Translation_Plane_OXY_1')
geompy.addToStudy(Translation_Plane_OXY_2,'Translation_Plane_OXY_2')
geompy.addToStudy(Translation_Plane_OXY_3,'Translation_Plane_OXY_3')
geompy.addToStudy(Translation_Plane_OXY_4,'Translation_Plane_OXY_4')
geompy.addToStudy(Translation_Plane_OXY_5,'Translation_Plane_OXY_5')
geompy.addToStudy(Translation_Plane_OXY_6,'Translation_Plane_OXY_6')

geompy.addToStudy( Cut_1, 'Cut_1' )
geompy.addToStudy( Partition_1, 'Partition_1' )

geompy.addToStudyInFather( Partition_1, Solid_1, 'Solid_1' )
geompy.addToStudyInFather( Partition_1, Solid_2, 'Solid_2' )
geompy.addToStudyInFather( Partition_1, Solid_3, 'Solid_3' )
geompy.addToStudyInFather( Partition_1, Solid_4, 'Solid_4' )
geompy.addToStudyInFather( Partition_1, Solid_5, 'Solid_5' )
geompy.addToStudyInFather( Partition_1, Solid_6, 'Solid_6' )
geompy.addToStudyInFather( Partition_1, Solid_7, 'Solid_7' )
geompy.addToStudyInFather( Partition_1, Solid_8, 'Solid_8' )
geompy.addToStudyInFather( Partition_1, Solid_9, 'Solid_9' )
geompy.addToStudyInFather( Partition_1, Solid_10, 'Solid_10' )

geompy.addToStudyInFather( Solid_5, Wall_int, 'Wall_int' )
geompy.addToStudyInFather( Solid_5, Wall_ext, 'Wall_ext' )
geompy.addToStudyInFather( Solid_5, Shared, 'Shared' )


#geompy.addToStudyInFather( Solid_4, Shared_Face_1, 'Shared_Face_1' )
#geompy.addToStudyInFather( Solid_4, Shared_Face_2, 'Shared_Face_2' )
