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
 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 build(self):
		if (self.__ready_to_build__):
			self.__ready_to_build__ = False
			self.buildCurve()
		return self.shape
class BDY_GEOM_CIRCLE(BDY_GEOM):
	def __init__(self):
		super(BDY_GEOM_CIRCLE, self).__init__('circle')
		self.curve      = None
		self.twist      = (None, None)
		self.parameters = (MIN_0, MAX_2PI)
		self.sense      = 'forward'
	def buildCurve(self):
		if (not self.curve is None):
			u = self.parameters[0]
			v = self.parameters[1]
			self.shape = self.curve.build(u, v)
class BDY_GEOM_DEG(BDY_GEOM):
	def __init__(self):
		super(BDY_GEOM_DEG, self).__init__('deg')
		self.location = VEC(0.0, 0.0, 0.0)
		self.normal1  = VEC(1.0, 0.0, 0.0)
		self.normal2  = VEC(0.0, 1.0, 0.0)
	def buildCurve(self):
		self.shape = Part.Point(self.location).toShape()
class BDY_GEOM_PCURVE(BDY_GEOM):
	def __init__(self):
		super(BDY_GEOM_PCURVE, self).__init__('pcurve')
		self.surface      = None
		self.pcurve       = None
		self.sense        = 'forward'
		self.fittolerance = 0.0
	def buildCurve(self):
		self.shape = createBSplinesPCurve(self.pcurve, self.surface, self.sense)
class BDY_GEOM_PLANE(BDY_GEOM):
	def __init__(self):
		super(BDY_GEOM_PLANE, self).__init__('plane')
		self.normal     = VEC(0.0, 0.0, 1.0)
		self.parameters = (MIN_0, 1.0)
		self.curve      = None
	def buildCurve(self):
		if (not self.curve is None):
			u = self.parameters[0]
			v = self.parameters[1]
			self.shape = self.curve.build(u, v)
class LoftData(object):
	def __init__(self):
		self.surface = None
		self.bs2cur  = None
		self.e1      = TAG_FALSE
		self.type    = 213
		self.n       = 1
		self.m       = 1
		self.v       = []
		self.e2      = TAG_FALSE
class Skin(object):
	def __init__(self):
		self.a1   = [-1, -1, -1, -1]
		self.f    = MIN_0
		self.loft = []
		self.a2   = [0.0, 0.0, 0.0]
		self.surf = None
		self.n    = 0
		self.law  = 'null_law'
		self.pcur = None
class BS3_Curve(object):
	def __init__(self, rational, periodic, degree):
		self.poles     = []       # sequence of VEC
		self.uMults    = ()       # tuple of int, e.g.  (3, 1,  3)
		self.uKnots    = ()       # tuple of float, eg. (0, 0.5, 1)
		self.uPeriodic = periodic # boolean
		self.uDegree   = degree   # int
		self.weights   = []       # sequence of float, e.g. (1, 0.8, 0.2), must have the same length as poles
		self.rational  = rational # boolean: False for nubs, True for nurbs
	def readPoints3DList(self, count, chunks, index):
		self.uKnots, self.uMults, i = readKnotsMults(count, chunks, index)
		us = sum(self.uMults) - (self.uDegree - 1)
		self.poles   = [None for r in range(0, us)]
		self.weights = [1 for r in range(0, us)] if (self.rational) else None

		for u in range(0, us):
			self.poles[u], i = getLocation(chunks, i)
			if (self.rational): self.weights[u], i = getFloat(chunks, i)

		self.uKnots, self.uMults, self.uPeriodic = adjustMultsKnots(self.uKnots, self.uMults, self.uPeriodic, self.uDegree)
		return i
class BS3_Surface(BS3_Curve):
	def __init__(self, rational, uPeriodic, vPeriodic, uDegree, vDegree):
		super(BS3_Surface, self).__init__(rational, uPeriodic, uDegree)
		self.poles     = [[]]      # sequence of sequence ofVEC
		self.weights   = [[]]      # sequence of sequence float
		self.vMults    = ()        # tuple of int, ref. umults
		self.vKnots    = ()        # tuple of float
		self.vPeriodic = vPeriodic # boolean
		self.vDegree   = vDegree          # int
	def readPoints3DMap(self, countU, countV, chunks, index):
		# row definitions
		self.uKnots, self.uMults, i = readKnotsMults(countU, chunks, index)
		# column definitions
		self.vKnots, self.vMults, i = readKnotsMults(countV, chunks, i)

		us = sum(self.uMults) - (self.uDegree - 1)
		vs = sum(self.vMults) - (self.vDegree - 1)

		self.poles   = [[None for c in range(0, vs)] for r in range(0, us)]
		self.weights = [[1 for c in range(0, vs)] for r in range(0, us)] if (self.rational) else None
		for v in range(0, vs):
			for u in range(0, us):
				self.poles[u][v], i  = getLocation(chunks, i)
				if (self.rational): self.weights[u][v], i = getFloat(chunks, i)

		self.uKnots, self.uMults, self.uPeriodic = adjustMultsKnots(self.uKnots, self.uMults, self.uPeriodic, self.uDegree)
		self.vKnots, self.vMults, self.vPeriodic = adjustMultsKnots(self.vKnots, self.vMults, self.vPeriodic, self.vDegree)

		return i
class Helix(object):
	def __init__(self):
		self.radAngles = Interval(Range('I', 1.0), Range('I', 1.0))
		self.posCenter = CENTER
		self.dirMajor  = DIR_X

		self.dirMinor  = DIR_Y
