# -*- coding: iso-8859-1 -*-

###
### This file is generated automatically by SALOME v6.4.0 with dump python functionality
###

import sys
import salome
import GEOM
import geompy
import salome
import math
#from Numeric import *
import SALOMEDS
gg = salome.ImportComponentGUI("GEOM")


salome.salome_init()
theStudy = salome.myStudy

geompy.init_geom(theStudy)
####################################################
##       Begin of variables section      ##
####################################################

# factor corectie

f=.1
raza_cil_mare=2.0*f
raza_cil_mic= 1.7*f
inalt_cil_mare= 15.0*f
inalt_cil_mic= 7.0*f
dim_cutie_mare= 1*f
dim_cutie_mica= 1*f
angle = math.radians(60)
dim_plan_mare= 30.0*f
dim_plan_mic= inalt_cil_mic*2.0
locatie_cil_mic= 3.0*f
locatie_cil_mic_z= -raza_cil_mare
locatie_cutie = dim_cutie_mare/2.0
transl_cutie= -locatie_cutie


# Origine si vectori
O = geompy.MakeVertex(0, 0, 0)

OX = geompy.MakeVectorDXDYDZ(1, 0, 0)

OY = geompy.MakeVectorDXDYDZ(0, 1, 0)

OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)

id_O = geompy.addToStudy(O,"O")
gg.createAndDisplayGO(id_O)
id_OX = geompy.addToStudy(OX,"OX")
gg.createAndDisplayGO(id_OX)
id_OY = geompy.addToStudy(OY,"OY")
gg.createAndDisplayGO(id_OY)
id_OZ = geompy.addToStudy(OZ,"OZ")
gg.createAndDisplayGO(id_OZ)

Translation_OZ = geompy.MakeTranslation(OZ, locatie_cil_mic, 0, 0)
geompy.addToStudy(Translation_OZ,'Translation_OZ')
# Plane origine

Plan_OXY = geompy.MakePlaneLCS(None, 30, 1)
Plan_OYZ = geompy.MakePlaneLCS(None, 30, 2)
Plan_OXZ = geompy.MakePlaneLCS(None, 30, 3)

id_Plan_OXY = geompy.addToStudy(Plan_OXY,"Plan_OXY")
gg.createAndDisplayGO(id_Plan_OXY)
id_Plan_OYZ = geompy.addToStudy(Plan_OYZ,"Plan_OYZ")
gg.createAndDisplayGO(id_Plan_OYZ)
id_Plan_OXZ = geompy.addToStudy(Plan_OXZ,"Plan_OXZ")
gg.createAndDisplayGO(id_Plan_OXZ)


# Cilindru 

def CYLINDER(radius,height):

	Cylinder = geompy.MakeCylinder(O, OX, radius, height)
	id_Cylinder = geompy.addToStudy(Cylinder,"Cylinder")
	gg.createAndDisplayGO(id_Cylinder)
	return Cylinder 
# Puncte hexagon

def BOX (dim_box,height):
	Points = []
	for i in range (0,6,1):
		y = dim_box*math.cos(angle*i)
		z = dim_box*math.sin(angle*i)
		point = geompy.MakeVertex (0.0,y,z)
		Points.append(point)
		compound = geompy.MakeCompound(Points)
#	id_Point = geompy.addToStudy(Points[i],"Point"+i)
#	gg.createAndDisplayGO(id_point)

#id_compound = geompy.addToStudy(compound,"Compound")
#gg.createAndDisplayGO(id_compound)


	Line_1 = geompy.MakeLineTwoPnt(Points[0], Points[1])
	Line_2 = geompy.MakeLineTwoPnt(Points[1], Points[2])
	Line_3 = geompy.MakeLineTwoPnt(Points[2], Points[3])
	Line_4 = geompy.MakeLineTwoPnt(Points[3], Points[4])
	Line_5 = geompy.MakeLineTwoPnt(Points[4], Points[5])
	Line_6 = geompy.MakeLineTwoPnt(Points[5], Points[0])
	Wire_1 = geompy.MakeWire([Line_1, Line_2, Line_3, Line_4, Line_5, Line_6], 1e-07)
	Face_1 = geompy.MakeFaceWires([Wire_1], 1)
#geompy.addToStudy( Line_1, 'Line_1' )
#geompy.addToStudy( Line_2, 'Line_2' )
#geompy.addToStudy( Line_3, 'Line_3' )
#geompy.addToStudy( Line_4, 'Line_4' )
#geompy.addToStudy( Line_5, 'Line_5' )
#geompy.addToStudy( Line_6, 'Line_6' )
#geompy.addToStudy( Wire_1, 'Wire_1' )
#geompy.addToStudy( Face_1, 'Face_1' )

	Punct_capat_Cylinder = geompy.MakeVertex(height,0.0,0.0)
	Linie_inalt_cilindru = geompy.MakeLineTwoPnt(O,Punct_capat_Cylinder)
#geompy.addToStudy(Linie_inalt_cilindru,'Linie_inalt_cilindru')

	Box = geompy.MakePipe(Face_1, Linie_inalt_cilindru)
#geompy.addToStudy(Box,'Box_Cylinder')

	return Box

Cil_Mare = CYLINDER (raza_cil_mare,inalt_cil_mare)
geompy.addToStudy( Cil_Mare, 'Cil_Mare' )
Cil_Mic = CYLINDER (raza_cil_mic,inalt_cil_mic)
geompy.addToStudy( Cil_Mic, 'Cil_Mic' )

Box_Mare = BOX(dim_cutie_mare,inalt_cil_mare)
geompy.addToStudy(Box_Mare,'Box_Mare')
Box_Mic = BOX(dim_cutie_mica,inalt_cil_mic)
geompy.addToStudy(Box_Mic,'Box_Mic')


Cut_Cil_Mare = geompy.MakeCut(Cil_Mare,Box_Mare)
Cut_Cil_Mic = geompy.MakeCut(Cil_Mic,Box_Mic)
Multi_Rotation_OXY = geompy.MultiRotate1D(Plan_OXY, OX, 3)
geompy.addToStudy( Multi_Rotation_OXY, 'Multi-Rotation_OXY')

Cut_Plane_Cil_Mare=geompy.MakeCommon(Cut_Cil_Mare,Multi_Rotation_OXY)
geompy.addToStudy(Cut_Plane_Cil_Mare,'Cut_Plane_Cil_Mare')

Cut_Plane_Cil_Mic=geompy.MakeCommon(Cut_Cil_Mic,Multi_Rotation_OXY)
geompy.addToStudy(Cut_Plane_Cil_Mic,'Cut_Plane_Cil_Mic')

Partition_1 = geompy.MakePartition([Cil_Mare], [Plan_OXY, Box_Mare, Cut_Plane_Cil_Mare], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
BlocksCompound_1 = geompy.CheckAndImprove(Partition_1)

Partition_2 = geompy.MakePartition([Cil_Mic], [Plan_OXY, Box_Mic, Cut_Plane_Cil_Mic], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
BlocksCompound_2 = geompy.CheckAndImprove(Partition_2)


geompy.addToStudy( Partition_1, 'Partition_1' )
geompy.addToStudy( BlocksCompound_1, 'BlocksCompound_1' )

geompy.addToStudy( Partition_2, 'Partition_2' )
geompy.addToStudy( BlocksCompound_2, 'BlocksCompound_2' )

Rotation_Cil_Mic = geompy.MakeRotation(Cil_Mic, OY, -90*math.pi/180.0)
Rotation_Box_Mic = geompy.MakeRotation(Box_Mic, OY, -90*math.pi/180.0)
Rotation_Plane_Cil_Mic = geompy.MakeRotation(Cut_Plane_Cil_Mic, OY, -90*math.pi/180.0)
Cil_Mic_Sus = geompy.MakeTranslation(Rotation_Cil_Mic, locatie_cil_mic, 0, 0)
geompy.addToStudy( Cil_Mic_Sus, 'Cil_Mic_Sus' )
Box_Mic_Sus = geompy.MakeTranslation(Rotation_Box_Mic, locatie_cil_mic, 0, 0)
geompy.addToStudy( Box_Mic_Sus, 'Box_Mic_Sus' )
Plane_Cil_Mic_Sus = geompy.MakeTranslation(Rotation_Plane_Cil_Mic, locatie_cil_mic, 0, 0)
geompy.addToStudy( Plane_Cil_Mic_Sus, 'Plane_Cil_Mic_Sus' )
Tpipe=geompy.MakeFuse(Cil_Mare,Cil_Mic_Sus)
geompy.addToStudy( Tpipe, 'Tpipe' )


# Puncte Pana
Plane1_P1=geompy.MakeVertex(locatie_cil_mic,raza_cil_mare,0)
Plane1_P2=geompy.MakeVertex(locatie_cil_mic-raza_cil_mic,0,raza_cil_mare)
Plane1_P3=geompy.MakeVertex(locatie_cil_mic,-raza_cil_mare,0)

Plane2_P1=geompy.MakeVertex(locatie_cil_mic,raza_cil_mare,0)
Plane2_P2=geompy.MakeVertex(locatie_cil_mic+raza_cil_mic,0,raza_cil_mare)
Plane2_P3=geompy.MakeVertex(locatie_cil_mic,-raza_cil_mare,0)

Plane1= geompy.MakePlaneThreePnt(Plane1_P1,Plane1_P2,Plane1_P3,7.0*raza_cil_mic)
Plane2= geompy.MakePlaneThreePnt(Plane2_P1,Plane2_P2,Plane2_P3,7.0*raza_cil_mic)
geompy.addToStudy( Plane1, 'Plane1' )
geompy.addToStudy( Plane2, 'Plane2' )
Partition_Cil_Mare = geompy.MakePartition([Cil_Mare], [Plan_OXY], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
[Solid_1,Solid_2] = geompy.ExtractShapes(Partition_Cil_Mare, geompy.ShapeType["SOLID"], True)
geompy.addToStudy(Solid_1,'Solid_1')
Fuse_Plane_Pana = geompy.MakeFuse(Plane1, Plane2)
Plane_Pana = geompy.MakeCommon(Solid_2, Fuse_Plane_Pana)
geompy.addToStudy( Plane_Pana, 'Plane_Pana' )


Partition_3 = geompy.MakePartition([Cil_Mic_Sus], [Plane_Pana], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
[Solid_1,Cil_Mic_Pana,Solid_3] = geompy.ExtractShapes(Partition_3, geompy.ShapeType["SOLID"], True)
geompy.addToStudy(Cil_Mic_Pana,'Cil_Mic_Pana')
Plane_Taiere_Cil_Mic_Sus=geompy.MakeCommon(Cil_Mic_Pana,Plane_Cil_Mic_Sus)
Box_Taiere_Cil_Mic_Sus=geompy.MakeCommon(Cil_Mic_Pana, Box_Mic_Sus)
geompy.addToStudy( Plane_Taiere_Cil_Mic_Sus, 'Plane_Taiere_Cil_Mic_Sus' )
geompy.addToStudy( Box_Taiere_Cil_Mic_Sus, 'Box_Taiere_Cil_Mic_Sus' )
Plane_Taiere_Cil_Mare_Pana=geompy.MakeCut(Cut_Plane_Cil_Mare,Cil_Mic_Pana)
Box_Taiere_Cil_Mare_Pana=geompy.MakeCut(Box_Mare,Cil_Mic_Pana)
geompy.addToStudy( Plane_Taiere_Cil_Mare_Pana, 'Plane_Taiere_Cil_Mare_Pana' )
geompy.addToStudy( Box_Taiere_Cil_Mare_Pana, 'Box_Taiere_Cil_Mare_Pana' )



Translation_Plan_OYZ=geompy.MakeTranslation(Plan_OYZ,locatie_cil_mic,0,0)
geompy.addToStudy(Translation_Plan_OYZ,'Translation_Plan_OYZ')

Partition_3 = geompy.MakePartition([Tpipe], [Plan_OXY, Plane_Pana, Plane_Taiere_Cil_Mic_Sus, Box_Taiere_Cil_Mic_Sus, Plane_Taiere_Cil_Mare_Pana, Box_Taiere_Cil_Mare_Pana, Translation_Plan_OYZ, Plan_OXZ], [], [], geompy.ShapeType["SOLID"], 0, [], 0)
BlocksCompound_3 = geompy.CheckAndImprove(Partition_3)
Plan_Mic_Taiere_Cil_Mic_Sus=geompy.MakeCommon(Box_Taiere_Cil_Mic_Sus,Translation_Plan_OYZ)
geompy.addToStudy(Plan_Mic_Taiere_Cil_Mic_Sus,'Plan_Mic_Taiere_Cil_Mic_Sus')
geompy.addToStudy( Partition_3, 'Partition_3' )
geompy.addToStudy( BlocksCompound_3, 'BlocksCompound_3' )

Partition_Cil_Mic_Sus=geompy.MakePartition([Cil_Mic_Pana],[Plan_Mic_Taiere_Cil_Mic_Sus, Box_Taiere_Cil_Mic_Sus, Plane_Taiere_Cil_Mic_Sus],[],[],geompy.ShapeType["SOLID"], 0, [], 0)
geompy.addToStudy(Partition_Cil_Mic_Sus,'Partition_Cil_Mic_Sus')
BlocksCompound_4 = geompy.CheckAndImprove(Partition_Cil_Mic_Sus)
geompy.addToStudy( BlocksCompound_4, 'BlocksCompound_4' )


##################################################
### Mesh Part 	##################################
##################################################
#
import smesh, SMESH, SALOMEDS
#
smesh.SetCurrentStudy(theStudy)
import StdMeshers
#
# # Mesh Cilindru Mare
# Mesh_1 = smesh.Mesh(BlocksCompound_CilMarePartition)
#
# Regular_1D = Mesh_1.Segment()
# Nb_Segments_1 = Regular_1D.NumberOfSegments(15)
# Nb_Segments_1.SetDistrType( 0 )
# Quadrangle_2D = Mesh_1.Quadrangle()
# Hexa_3D = smesh.CreateHypothesis('Hexa_3D')
# status = Mesh_1.AddHypothesis(Hexa_3D)
# isDone = Mesh_1.Compute()
#
# ## set object names
# smesh.SetName(Mesh_1.GetMesh(), 'Mesh_1')
# smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
# smesh.SetName(Nb_Segments_1, 'Nb. Segments_1')
# smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
# smesh.SetName(Hexa_3D, 'Hexa_3D')
#
# # Mesh Cilindru Mic
# Mesh_2 = smesh.Mesh(BlocksCompound_CilMicPartition)
# Regular_1D = Mesh_2.Segment()
# Nb_Segments_1 = Regular_1D.NumberOfSegments(15)
# Nb_Segments_1.SetDistrType( 0 )
# Quadrangle_2D = Mesh_2.Quadrangle()
# Hexa_3D = smesh.CreateHypothesis('Hexa_3D')
# status = Mesh_2.AddHypothesis(Hexa_3D)
# isDone = Mesh_2.Compute()
#
# smesh.SetName(Mesh_2.GetMesh(), 'Mesh_2')
# smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
# smesh.SetName(Nb_Segments_1, 'Nb. Segments_1')
# smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
# smesh.SetName(Hexa_3D, 'Hexa_3D')
#
# # Mesh TshapePipe
# Mesh_3 = smesh.Mesh(BlocksCompound_TshapePipe)
# Regular_1D = Mesh_3.Segment()
# Nb_Segments_1 = Regular_1D.NumberOfSegments(15)
# Nb_Segments_1.SetDistrType( 0 )
# Quadrangle_2D = Mesh_3.Quadrangle()
# Hexa_3D = smesh.CreateHypothesis('Hexa_3D')
# status = Mesh_3.AddHypothesis(Hexa_3D)
# isDone = Mesh_3.Compute()
#
# smesh.SetName(Mesh_3.GetMesh(), 'Mesh_3')
# smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
# smesh.SetName(Nb_Segments_1, 'Nb. Segments_1')
# smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
# smesh.SetName(Hexa_3D, 'Hexa_3D')
#
# # Mesh Partition 3
Mesh_4 = smesh.Mesh(Partition_3)
Regular_1D = Mesh_4.Segment()
Nb_Segments_1 = Regular_1D.NumberOfSegments(15)
Nb_Segments_1.SetDistrType( 0 )
Quadrangle_2D = Mesh_4.Quadrangle()
Hexa_3D = smesh.CreateHypothesis('Hexa_3D')
status = Mesh_4.AddHypothesis(Hexa_3D)
isDone = Mesh_4.Compute()

smesh.SetName(Mesh_4.GetMesh(), 'Mesh_4')
smesh.SetName(Regular_1D.GetAlgorithm(), 'Regular_1D')
smesh.SetName(Nb_Segments_1, 'Nb. Segments_1')
smesh.SetName(Quadrangle_2D.GetAlgorithm(), 'Quadrangle_2D')
smesh.SetName(Hexa_3D, 'Hexa_3D')
#
#
#

if salome.sg.hasDesktop():
  salome.sg.updateObjBrowser(1)
