# Path: importerConstants.py
# MIN_0   = 0.0
# 
# MIN_PI  = -pi
# 
# MIN_PI2 = -pi / 2
# 
# MIN_INF = float('-inf')
# 
# MAX_2PI = 2 * pi
# 
# MAX_PI  = pi
# 
# MAX_PI2 = pi / 2
# 
# MAX_INF = float('inf')
# 
# MAX_LEN = 2e+100
# 
# Path: importerConstants.py
# CENTER = VEC(0, 0, 0)
# 
# DIR_X  = VEC(1, 0, 0)
# 
# DIR_Y  = VEC(0, 1, 0)
# 
# DIR_Z  = VEC(0, 0, 1)
# 
# ENCODING_FS      = 'utf8'


import traceback, Part, Draft, os, FreeCAD, re
from importerUtils              import *
from FreeCAD                    import Vector as VEC, Rotation as ROT, Placement as PLC, Matrix as MAT, Base
from math                       import pi, fabs, degrees, asin, sin, cos, tan, atan2, ceil, e, cosh, sinh, tanh, acos, acosh, asin, asinh, atan, atanh, log, sqrt, exp, log10
from importerConstants          import MIN_0, MIN_PI, MIN_PI2, MIN_INF, MAX_2PI, MAX_PI, MAX_PI2, MAX_INF, MAX_LEN
from importerConstants          import CENTER, DIR_X, DIR_Y, DIR_Z, ENCODING_FS


def readBS3Surface(chunks, index):
	nbs, degreeU, degreeV, i = getDimensionSurface(chunks, index)
	if (nbs == 'nullbs'):
		return None, i
	if (nbs in ('nubs', 'nurbs')):
		closureU, closureV, singularityU, singularityV, countU, countV, i = getClosureSurface(chunks, i)
		spline = BS3_Surface(nbs == 'nurbs', closureU == 'periodic', closureV == 'periodic', degreeU, degreeV)
		i = spline.readPoints3DMap(countU, countV, chunks, i)
		return spline, i
	if (nbs == 'summary'):
		x, i            = getFloat(chunks, i)
		arr, i          = getFloatArray(chunks, i)
		tol, i          = getLength(chunks, i)
		closureU, i     = getEnumByValue(chunks, i, CLOSURE)
		closureV, i     = getEnumByValue(chunks, i, CLOSURE)
		singularityU, i = getSingularity(chunks, i)
		singularityV, i = getSingularity(chunks, i)
		# FIXME: create a surface from these values! -> ../tutorials/2012/Tube and Pipe/Example_iparts/45Elbow.ipt
	return None, i

def readSplineSurface(chunks, index, tolerance):
	singularity, i = getSingularity(chunks, index)
	if (singularity == 'full'):
		spline, i = readBS3Surface(chunks, i)
		if ((spline is not None) and tolerance):
			tol, i = getLength(chunks, i)
			return spline, tol, i
		return spline, None, i
	if ((singularity == 'none') or (singularity == 4)):

# Path: importerConstants.py
# MIN_0   = 0.0
# 
# MIN_PI  = -pi
# 
# MIN_PI2 = -pi / 2
# 
# MIN_INF = float('-inf')
# 
# MAX_2PI = 2 * pi
# 
# MAX_PI  = pi
# 
# MAX_PI2 = pi / 2
# 
# MAX_INF = float('inf')
# 
# MAX_LEN = 2e+100
# 
# Path: importerConstants.py
# CENTER = VEC(0, 0, 0)
# 
# DIR_X  = VEC(1, 0, 0)
# 
# DIR_Y  = VEC(0, 1, 0)
# 
# DIR_Z  = VEC(0, 0, 1)
# 
# ENCODING_FS      = 'utf8'


# Path: Acis.py
import traceback, Part, Draft, os, FreeCAD, re
from importerUtils              import *
from FreeCAD                    import Vector as VEC, Rotation as ROT, Placement as PLC, Matrix as MAT, Base
from math                       import pi, fabs, degrees, asin, sin, cos, tan, atan2, ceil, e, cosh, sinh, tanh, acos, acosh, asin, asinh, atan, atanh, log, sqrt, exp, log10
from importerConstants          import MIN_0, MIN_PI, MIN_PI2, MIN_INF, MAX_2PI, MAX_PI, MAX_PI2, MAX_INF, MAX_LEN
from importerConstants          import CENTER, DIR_X, DIR_Y, DIR_Z, ENCODING_FS


def readBS3Surface(chunks, index):
	nbs, degreeU, degreeV, i = getDimensionSurface(chunks, index)
	if (nbs == 'nullbs'):
		return None, i
	if (nbs in ('nubs', 'nurbs')):
		closureU, closureV, singularityU, singularityV, countU, countV, i = getClosureSurface(chunks, i)
		spline = BS3_Surface(nbs == 'nurbs', closureU == 'periodic', closureV == 'periodic', degreeU, degreeV)
		i = spline.readPoints3DMap(countU, countV, chunks, i)
		return spline, i
	if (nbs == 'summary'):
		x, i            = getFloat(chunks, i)
		arr, i          = getFloatArray(chunks, i)
		tol, i          = getLength(chunks, i)
		closureU, i     = getEnumByValue(chunks, i, CLOSURE)
		closureV, i     = getEnumByValue(chunks, i, CLOSURE)
		singularityU, i = getSingularity(chunks, i)
		singularityV, i = getSingularity(chunks, i)
		# FIXME: create a surface from these values! -> ../tutorials/2012/Tube and Pipe/Example_iparts/45Elbow.ipt
	return None, i

def readSplineSurface(chunks, index, tolerance):
	singularity, i = getSingularity(chunks, index)
	if (singularity == 'full'):
		spline, i = readBS3Surface(chunks, i)
		if ((spline is not None) and tolerance):
			tol, i = getLength(chunks, i)
			return spline, tol, i
		return spline, None, i
	if ((singularity == 'none') or (singularity == 4)):

		rngU, i = getInterval(chunks, i, MIN_INF, MAX_INF, 1.0)
