#import geompy, smesh, math

import sys
import salome

salome.salome_init()
theStudy = salome.myStudy

import GEOM
import geompy
import math
import SALOMEDS


geompy.init_geom(theStudy)

f=.1

no_elemente=3
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

length_total=height_cyl+2.0*depth_box
height_Cyl=2.0*position_cyl+height_cyl

#  small_element

radius_small=0.2*f
scufundare_small=0.3*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)
geompy.addToStudy(disk_Cyl,'disk_Cyl')
Cyl=geompy.MakePrismVecH(disk_Cyl,OZ,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)
geompy.addToStudy(Fuse_1,'disk_Xshape1')
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

Vertex_1 = geompy.MakeVertex(0, radius_small, length_rectangle/2.0)
Vertex_2 = geompy.MakeVertex(0, 0, radius_small+length_rectangle/2.0)
Vertex_3 = geompy.MakeVertex(0, -radius_small, length_rectangle/2.0)

Vertex_4 = geompy.MakeVertex(0, radius_small, -length_rectangle/2.0)

Vertex_5 = geompy.MakeVertex(0, -radius_small, -length_rectangle/2.0)


Arc_1 = geompy.MakeArc(Vertex_1, Vertex_2, Vertex_3)
Arc_2 = geompy.MakeRotation(Arc_1, OY, 180*math.pi/180.0)

Line_1 = geompy.MakeLineTwoPnt(Vertex_1, Vertex_4)
Line_2 = geompy.MakeLineTwoPnt(Vertex_3, Vertex_5)
Wire_1 = geompy.MakeWire([Arc_1, Arc_2, Line_1, Line_2], 1e-07)
Face_4 = geompy.MakeFaceWires([Wire_1], 1)
Small = geompy.MakePrismVecH(Face_4, 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)

Compound_1 = geompy.MakeCompound([Xshape1, Xshape2,cylinders])

# 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.0*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-1.0*f)
Translation_Plane_OXY_6=geompy.MakeTranslation(Plane_OXY, 0, 0, position_cyl+height_cyl+depth_box)
Translation_Plane_OXY_7=geompy.MakeTranslation(Plane_OXY, 0, 0, height_Cyl)


Cut_1 = geompy.MakeCut(Cyl,cylinders)
Cut_2 = geompy.MakeCut(Cut_1,Smalls)
Cut_3 = geompy.MakeCut(Cut_2,Xshape1)
Cut_4 = geompy.MakeCut(Cut_3,Xshape2)

Punct_1 = geompy.MakeVertex(radius_Cyl, 0, 0)
Punct_2 = geompy.MakeVertex(radius_Cyl, 0, height_Cyl)
Compound_2 = geompy.MakeCompound([Punct_1, Cut_4, Punct_2])

Partition_1 = geompy.MakePartition([Cut_4], [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)
[Solid_1,Solid_2,Solid_3,Solid_4,Solid_5,Solid_6,Solid_7] = geompy.ExtractShapes(Partition_1, geompy.ShapeType["SOLID"], True)

# Add to study



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( Xshape1, 'Xshape1' )
geompy.addToStudy( Xshape2, 'Xshape2' )

geompy.addToStudy(Small,'Small')
geompy.addToStudy(Small_position,'Small_position')
geompy.addToStudy(Small_around_cyl,'Small_around_cyl')
geompy.addToStudy(Smalls,'Smalls')

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(Translation_Plane_OXY_7,'Translation_Plane_OXY_7')

geompy.addToStudy( Cut_4, 'Cut_4' )
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' )


# Update browser

salome.sg.updateObjBrowser(0)

