# Path: Interface/evaluator.py
# class Evaluator(object):
#     def __init__(self, printFunction):
#         self._print=printFunction
#         self._error='*error*'
#         self._ok='*Ok*'
#         self._cadApplication=PyCadApp
#         
#     def evaluate(self, value):
#         """
#             evaluate the string 
#         """
#         if len(value)<=0:
#             return None
#         for cmd in RESERVED_WORK:
#             if value.count(cmd):
#                 return self._error + "->Reserved word"
#         
#             
#         if value[0]=='>': # eval
#             return self._eval(value[1:])
#         if value[0]=='@':
#             return self._exec(value[1:])
#         else:
#             return value
#             
#     def _eval(self, value):
#         """
#             evaluate the evaluated value
#         """
#         try:
#             return eval(value)
#         except:
#             return self._error
#             
#     def _exec(self, value):
#         """
#             exec value
#         """
#         try:
#             value=str(value).replace('print', 'self._print')
#             value=str(value).replace('pyCad', 'self._cadApplication')
#             exec(value)
#             return self._ok
#         except:
#             return self._error
# 
# Path: Interface/Preview/factory.py
# def getPreviewObject(command):
#     if isinstance(command , SegmentCommand):
#         return QtSegmentItem(command)
#     elif isinstance(command , ArcCommand):
#         return QtArcItem(command)
#     elif isinstance(command , RectangleCommand):
#         return QtRectangleItem(command)
#     elif isinstance(command , EllipseCommand):
#         return QtEllipseItem(command)
#     elif isinstance(command , PolylineCommand):
#         return QtPolylineItem(command)
#     elif isinstance(command ,  PolygonCommand):
#         return QtPolygonItem(command)
#     else:
#         return None


from Kernel.GeoEntity.point     import Point
from Kernel.GeoUtil.geolib      import Vector
from Kernel.pycadevent          import PyCadEvent
from Kernel.unitparser          import decodePoint, convertLengh, convertAngle
from Interface.evaluator        import Evaluator
from Interface.Preview.factory  import getPreviewObject
#
#
# This  module Provide custom exception for the db module and kernel
#



class FunctionHandler(object):
    '''
        This object contains all known commands.
        Commands are registered by "registerCommand" before the are available.
        Evaluation of commands or expressions is done by "evaluate"
    '''
    def __init__(self, edit_ctrl, edit_output):
        '''
            Defines an dictionary containing all known commands.
            Member 'registerCommand' add's a command to the table.
            Member 'evaluate' execute a command by call its call-back or evaluates an expression.
        '''
        # Input control
        self.__edit_ctrl = edit_ctrl
        # Output Control
        self.__edit_output=edit_output
        # current value
        self._value = None
        # command table
        self._command_table = {}
        # Global inner command evaluation
        self.evaluateInner=None
        #Evaluator

# Path: Interface/evaluator.py
# class Evaluator(object):
#     def __init__(self, printFunction):
#         self._print=printFunction
#         self._error='*error*'
#         self._ok='*Ok*'
#         self._cadApplication=PyCadApp
#         
#     def evaluate(self, value):
#         """
#             evaluate the string 
#         """
#         if len(value)<=0:
#             return None
#         for cmd in RESERVED_WORK:
#             if value.count(cmd):
#                 return self._error + "->Reserved word"
#         
#             
#         if value[0]=='>': # eval
#             return self._eval(value[1:])
#         if value[0]=='@':
#             return self._exec(value[1:])
#         else:
#             return value
#             
#     def _eval(self, value):
#         """
#             evaluate the evaluated value
#         """
#         try:
#             return eval(value)
#         except:
#             return self._error
#             
#     def _exec(self, value):
#         """
#             exec value
#         """
#         try:
#             value=str(value).replace('print', 'self._print')
#             value=str(value).replace('pyCad', 'self._cadApplication')
#             exec(value)
#             return self._ok
#         except:
#             return self._error
# 
# Path: Interface/Preview/factory.py
# def getPreviewObject(command):
#     if isinstance(command , SegmentCommand):
#         return QtSegmentItem(command)
#     elif isinstance(command , ArcCommand):
#         return QtArcItem(command)
#     elif isinstance(command , RectangleCommand):
#         return QtRectangleItem(command)
#     elif isinstance(command , EllipseCommand):
#         return QtEllipseItem(command)
#     elif isinstance(command , PolylineCommand):
#         return QtPolylineItem(command)
#     elif isinstance(command ,  PolygonCommand):
#         return QtPolygonItem(command)
#     else:
#         return None


# Path: Interface/CmdIntf/functionhandler.py
from Kernel.GeoEntity.point     import Point
from Kernel.GeoUtil.geolib      import Vector
from Kernel.pycadevent          import PyCadEvent
from Kernel.unitparser          import decodePoint, convertLengh, convertAngle
from Interface.evaluator        import Evaluator
from Interface.Preview.factory  import getPreviewObject

#
#
# This  module Provide custom exception for the db module and kernel
#



class FunctionHandler(object):
    '''
        This object contains all known commands.
        Commands are registered by "registerCommand" before the are available.
        Evaluation of commands or expressions is done by "evaluate"
    '''
    def __init__(self, edit_ctrl, edit_output):
        '''
            Defines an dictionary containing all known commands.
            Member 'registerCommand' add's a command to the table.
            Member 'evaluate' execute a command by call its call-back or evaluates an expression.
        '''
        # Input control
        self.__edit_ctrl = edit_ctrl
        # Output Control
        self.__edit_output=edit_output
        # current value
        self._value = None
        # command table
        self._command_table = {}
        # Global inner command evaluation
        self.evaluateInner=None
        #Evaluator

        self._eval=Evaluator(self.printCommand)