# Path: geosolver/matfunc.py
# class Vec(Table):
#     def dot( self, otherVec ):  return reduce(operator.add, map(operator.mul, self, otherVec), 0.0)
#     def norm( self ):  return math.sqrt(abs( self.dot(self.conjugate()) ))
#     def normSquared( self ):  return abs( self.dot(self.conjugate()) )
#     def normalize( self ):  return self / self.norm()
#     def outer( self, otherVec ):  return Mat([otherVec*x for x in self])
#     def cross( self, otherVec ):
#         'Compute a Vector or Cross Product with another vector'
#         assert len(self) == len(otherVec) == 3, 'Cross product only defined for 3-D vectors'
#         u, v = self, otherVec
#         return Vec([ u[1]*v[2]-u[2]*v[1], u[2]*v[0]-u[0]*v[2], u[0]*v[1]-u[1]*v[0] ])
#     def house( self, index ):
#         'Compute a Householder vector which zeroes all but the index element after a reflection'
#         v = Vec( Table([0]*index).concat(self[index:]) ).normalize()
#         t = v[index]
#         sigma = 1.0 - t**2
#         if sigma != 0.0:
#             t = v[index] = t<=0 and t-1.0 or -sigma / (t + 1.0)
#             v /= t
#         return v, 2.0 * t**2 / (sigma + t**2)
#     def polyval( self, x ):
#         'Vec([6,3,4]).polyval(5) evaluates to 6*x**2 + 3*x + 4 at x=5'
#         return reduce( lambda cum,c: cum*x+c, self, 0.0 )
#     def ratval( self, x ):
#         'Vec([10,20,30,40,50]).ratfit(5) evaluates to (10*x**2 + 20*x + 30) / (40*x**2 + 50*x + 1) at x=5.'
#         degree = len(self) / 2
#         num, den = self[:degree+1], self[degree+1:] + [1]
#         return num.polyval(x) / den.polyval(x)


from includes import *
from geosolver.matfunc import Vec
from LinearAlgebra import *
from camera import CameraType
from prototypeObjects import PrototypeManager

class Command:
	""" Commands that are general to the whole scene can be subclassed from this class. """
	def __init__(self):
		""" initialize """
		pass
		
	def execute(self):
		""" execute the command """
		raise NotImplementedError(caller + ' must be implemented in subclass')

class UpdateTaskbarCommand(Command):
	""" Update the taskbar whena mouse move event occurs in on of the many views/viewports. """
	def __init__(self, glViewport, mainWindow):
		Command.__init__(self)
		self.mainWindow = mainWindow
		self.glViewport = glViewport

	def execute(self, mouseEvent):
		""" Process the mouse move event and update the text in the taskbar 
		
		Parameters:
			mouseEvent: new position of the mouse in 2D
		"""
		camera = self.glViewport.getCamera()
		""" convert the 2D viewport coordinates into 3D projected on a Y-plane in 3D and
		for the other viewports to the orthogonal plane. """

# Path: geosolver/matfunc.py
# class Vec(Table):
#     def dot( self, otherVec ):  return reduce(operator.add, map(operator.mul, self, otherVec), 0.0)
#     def norm( self ):  return math.sqrt(abs( self.dot(self.conjugate()) ))
#     def normSquared( self ):  return abs( self.dot(self.conjugate()) )
#     def normalize( self ):  return self / self.norm()
#     def outer( self, otherVec ):  return Mat([otherVec*x for x in self])
#     def cross( self, otherVec ):
#         'Compute a Vector or Cross Product with another vector'
#         assert len(self) == len(otherVec) == 3, 'Cross product only defined for 3-D vectors'
#         u, v = self, otherVec
#         return Vec([ u[1]*v[2]-u[2]*v[1], u[2]*v[0]-u[0]*v[2], u[0]*v[1]-u[1]*v[0] ])
#     def house( self, index ):
#         'Compute a Householder vector which zeroes all but the index element after a reflection'
#         v = Vec( Table([0]*index).concat(self[index:]) ).normalize()
#         t = v[index]
#         sigma = 1.0 - t**2
#         if sigma != 0.0:
#             t = v[index] = t<=0 and t-1.0 or -sigma / (t + 1.0)
#             v /= t
#         return v, 2.0 * t**2 / (sigma + t**2)
#     def polyval( self, x ):
#         'Vec([6,3,4]).polyval(5) evaluates to 6*x**2 + 3*x + 4 at x=5'
#         return reduce( lambda cum,c: cum*x+c, self, 0.0 )
#     def ratval( self, x ):
#         'Vec([10,20,30,40,50]).ratfit(5) evaluates to (10*x**2 + 20*x + 30) / (40*x**2 + 50*x + 1) at x=5.'
#         degree = len(self) / 2
#         num, den = self[:degree+1], self[degree+1:] + [1]
#         return num.polyval(x) / den.polyval(x)


# Path: workbench/commands.py
from includes import *
from geosolver.matfunc import Vec
from LinearAlgebra import *
from camera import CameraType
from prototypeObjects import PrototypeManager


class Command:
	""" Commands that are general to the whole scene can be subclassed from this class. """
	def __init__(self):
		""" initialize """
		pass
		
	def execute(self):
		""" execute the command """
		raise NotImplementedError(caller + ' must be implemented in subclass')

class UpdateTaskbarCommand(Command):
	""" Update the taskbar whena mouse move event occurs in on of the many views/viewports. """
	def __init__(self, glViewport, mainWindow):
		Command.__init__(self)
		self.mainWindow = mainWindow
		self.glViewport = glViewport

	def execute(self, mouseEvent):
		""" Process the mouse move event and update the text in the taskbar 
		
		Parameters:
			mouseEvent: new position of the mouse in 2D
		"""
		camera = self.glViewport.getCamera()
		""" convert the 2D viewport coordinates into 3D projected on a Y-plane in 3D and
		for the other viewports to the orthogonal plane. """

		translation = Vec(camera.unprojectedCoordinatesOf([mouseEvent.x(), mouseEvent.y(), 1.0]))