import salome
import geompy

def MakeMiddleSpline(spline1='Edge_1',spline2='Edge_2',nbPoints=100,add=True):
	
	# Get the splines
	
	if isinstance(spline1,str):
		
		spline1Name=spline1
		
		spline1=salome.myStudy.FindObjectByName(spline1Name,"GEOM")[0].GetObject()
		
	
	if isinstance(spline2,str):
		
		spline2Name=spline2
		
		spline2=salome.myStudy.FindObjectByName(spline2Name,"GEOM")[0].GetObject()
		
	
	#-
	
	# Get the parameters to use
	
	parameters=[float(i)/(nbPoints-1) for i in range(nbPoints)]
	
	#-
	
	# Create the points
	
	spline1Vertexes=[]
	spline2Vertexes=[]
	
	for parameter in parameters:
		
		spline1Vertexes.append(geompy.MakeVertexOnCurve(spline1,parameter))
		spline2Vertexes.append(geompy.MakeVertexOnCurve(spline2,parameter))
	
	#-
	
	# Get the middle spline vertexes
	
	nbVertexes=len(spline1Vertexes)
	
	middleVertexes=[]
	
	for i in range(nbVertexes):
		
		vertex1=spline1Vertexes[i]
		vertex2=spline2Vertexes[i]
		
		
		spline=geompy.MakeEdge(vertex1,vertex2)
		
		middleVertexes.append(geompy.MakeVertexOnCurve(spline,0.5))
		
	
	#-
	
	# Create the middle spline
	
	middleSpline=geompy.MakeInterpol(middleVertexes)
	
	#-
	
	# Add the resulting spline
	
	if add==True:
		
		gg=salome.ImportComponentGUI("GEOM")
		
		id=geompy.addToStudy(middleSpline,"middleSpline")
		
		gg.createAndDisplayGO(id)
		
	
	#-
	
	# Return the resulting spline
	
	return middleSpline
	
	#-
	

