
function TCanvasDraw(){
    var type = 'TCanvasDraw';
    TCanvasDraw.prototype.InitConstructor = function(){
        TDrawObject.prototype.InitConstructor.call(this);
        this.scaleTeX = 80;
        this.widthTeX = -1;
        this.scaleX = 1;
        this.scaleY = 1;
        this.correctScale = 1;
        this.SetType(type);
    };
    this.InitConstructor();

    TCanvasDraw.prototype.Init = function(_object){
        TDrawObject.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasDraw'))
        {
            if (typeof _object.scaleTeX !== 'undefined' && _object.scaleTeX !== null && IsNumeric(_object.scaleTeX))
                this.scaleTeX = _object.scaleTeX;
            if (typeof _object.widthTeX !== 'undefined' && _object.widthTeX !== null && IsNumeric(_object.widthTeX))
                this.widthTeX = _object.widthTeX;
            if (typeof _object.scaleX !== 'undefined' && _object.scaleX !== null && IsNumeric(_object.scaleX))
                this.scaleX = _object.scaleX;
            if (typeof _object.scaleY !== 'undefined' && _object.scaleY !== null && IsNumeric(_object.scaleY))
                this.scaleY = _object.scaleY;
            if (typeof _object.correctScale !== 'undefined' && _object.correctScale !== null && IsNumeric(_object.correctScale))
                this.correctScale = _object.correctScale;
        }
    };

    TCanvasDraw.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TDrawObject.prototype.IsType.call(this,_type);
    };
    
    TCanvasDraw.prototype.ReadXML = function(tag,fun){
        TDrawObject.prototype.ReadXML.call(this,tag,fun);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof tag !== 'undefined' && tag !== null)
        {
            var tmp,tmp2;
            var attr;
            var obj;
            this.ReadXMLData(tag);
            
            attr = tag.getAttribute('scaleTeX');
            if (typeof attr !== 'undefined' && attr !== null)
            {
                attr = parseFloat(attr);
                if (attr !== null && IsNumeric(attr))
                    this.scaleTeX = attr;
            }
            attr = tag.getAttribute('widthTeX');
            if (typeof attr !== 'undefined' && attr !== null)
            {
                attr = parseFloat(attr);
                if (attr !== null && IsInt(attr))
                {
                    this.widthTeX = attr;
                    tmp = this.GetWidth();
                    if (typeof tmp !== 'undefined' && tmp !== null)
                        this.correctScale = this.widthTeX/tmp;
                }
            }
            attr = tag.getAttribute('scaleX');
            if (typeof attr !== 'undefined' && attr !== null)
            {
                attr = parseFloat(attr);
                if (attr !== null && IsNumeric(attr))
                    this.scaleX = attr;
            }
            attr = tag.getAttribute('scaleY');
            if (typeof attr !== 'undefined' && attr !== null)
            {
                attr = parseFloat(attr);
                if (attr !== null && IsNumeric(attr))
                    this.scaleY = attr;
            }
            attr = tag.getAttribute('scale');
            if (typeof attr !== 'undefined' && attr !== null)
            {
                attr = parseFloat(attr);
                if (attr !== null && IsNumeric(attr))
                {
                    this.scaleX = attr;
                    this.scaleY = attr;
                }
            }            
            var block = this.GetFigure(0);
            if (block === null)
                block = objM.newObject('TCanvasBlock');
            if (block !== null)
            {
                this.SetFigure(0, block);
                block.SetVariables(this.GetVariables());
                block.ReadXML(tag);
            }
        }
    };


    TCanvasDraw.prototype.Draw = function(_object){
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TGenerateObject'))
        {
            var tmp2 = [],id = this.GetId(),controls = [];
            if (id !== null)
            {
                
                tmp2[0] = this.GetWidth();
                tmp2[1] = this.GetHeight();
                tmp2[2] = this.GetFigures();
                tmp2[3] = this.GetXMax()-this.GetXMin();
                tmp2[4] = this.GetYMax()-this.GetYMin();
                tmp2[5] = this.GetZMax()-this.GetZMin();
                tmp2[6] = this.GetXMin();
                tmp2[7] = this.GetYMin();
                tmp2[8] = this.GetZMin();
                tmp2[9] = this.GetAlignX();
                tmp2[10] = this.GetColourBackground();
                tmp2[11] = this.scaleTeX;
                tmp2[12] = this.widthTeX;
                tmp2[13] = this.scaleX;
                tmp2[14] = this.scaleY;
                tmp2[15] = this.correctScale;
                tmp2[16] = this.GetClassStyle();
                _object.Add('GenerateCanvas',id,tmp2);
            }
        }
    };

};

TCanvasDraw.prototype = new TDrawObject();


function TCanvasBlock(){
    var type = 'TCanvasBlock';
    TCanvasBlock.prototype.InitConstructor = function(){
        TObjectFigure.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.colourFill = null;
        this.colourLine = null;
        this.colourText = null;
        this.colourSideText = null;
        this.arrowParameters = null;
        this.fontParameters = null;
        this.figures = [];
        this.variables = null;
        this.lineWidth = 1;
    };
    this.InitConstructor();

    TCanvasBlock.prototype.Init = function(_object){
        TObjectFigure.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasBlock'))
        {
            var i;
            if (typeof _object.colourFill !== 'undefined' && _object.colourFill !== null && _object.colourFill.IsType('TColourTXT'))
                this.colourFill = objM.copy(_object.colourFill);
            if (typeof _object.colourLine !== 'undefined' && _object.colourLine !== null && _object.colourLine.IsType('TColourTXT'))
                this.colourLine = objM.copy(_object.colourLine);
            if (typeof _object.colourText !== 'undefined' && _object.colourText !== null && _object.colourText.IsType('TColourTXT'))
                this.colourText = objM.copy(_object.colourText);
            if (typeof _object.colourSideText !== 'undefined' && _object.colourSideText !== null && _object.colourSideText.IsType('TColourTXT'))
                this.colourSideText = objM.copy(_object.colourSideText);
            if (typeof _object.arrowParameters !== 'undefined' && _object.arrowParameters !== null && _object.arrowParameters.IsType('TArrowParameters'))
                this.arrowParameters = objM.copy(_object.arrowParameters);
            if (typeof _object.fontParameters !== 'undefined' && _object.fontParameters !== null && _object.fontParameters.IsType('TFontParameters'))
                this.fontParameters = objM.copy(_object.fontParameters);
            if (typeof _object.figures !== 'undefined' && _object.figures !== null)
            {
                for (i = 0;i < _object.figures.length;i++)
                    if (typeof _object.figures[i] !== 'undefined' && _object.figures[i] !== null && _object.figures[i].IsType('TObjectFigure'))
                        this.figures[i] = objM.copy(_object.figures[i]);
            }
            if (typeof _object.variables !== 'undefined' && _object.variables !== null && _object.variables.IsType('TVariables'))
                this.variables = objM.copy(_object.variables);
            if (typeof _object.lineWidth !== 'undefined' && _object.lineWidth !== null && IsNumeric(_object.lineWidth))
                this.lineWidth = _object.lineWidth;
        }
    };

    TCanvasBlock.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TObjectFigure.prototype.IsType.call(this,_type);
    };
    
    TCanvasBlock.prototype.ReadXML = function(tag){
        TObjectFigure.prototype.ReadXML.call(this,tag);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof tag !== 'undefined' && tag !== null)
        {
            var x = tag.childNodes,i,k,fig,attr;
            for (i = 0,k = 0;i < x.length;i++)
            {
                if (x[i].nodeType === 1)
                {
                    fig = this.GetFigure(k);
                    if (x[i].nodeName === 'F')
                    {
                        if (fig === null)
                        {
                            var attr = x[i].getAttribute('type');
                            if (attr !== null)
                            {
                                switch(attr)
                                {
                                    case 'triangle':
                                        this.SetFigure(k, objM.newObject('TCanvasTriangle_'));
                                        break;
                                    case 'polygon':
                                        this.SetFigure(k, objM.newObject('TCanvasPolygon_'));
                                        break;
                                    case 'line':
                                        this.SetFigure(k, objM.newObject('TCanvasLine_'));
                                        break;
                                    case 'circle':
                                        this.SetFigure(k, objM.newObject('TCanvasCircle_'));
                                        break;
                                    case 'TableShow':
                                        this.SetFigure(k, objM.newObject('TCanvasTableShow_'));
                                        break;
                                }
                                fig = this.GetFigure(k);
                            }
                        }
                        if (fig !== null)
                        {
                            fig.SetVariables(this.GetVariables());

                            if (this.colourFill !== null)
                                fig.SetColourRGBA(this.colourFill.GetColour(this.GetObjectVariables()));
                            if (this.colourLine !== null)
                                fig.SetColourLineRGBA(this.colourLine.GetColour(this.GetObjectVariables()));

                            if (fig.IsType('TCanvasCircle_'))
			    {
				fig.SetLineWidth(this.GetLineWidth());
			    }
                            if (fig.IsType('TCanvasLine_'))
                            {
                                if (this.arrowParameters !== null)
                                {
                                    fig.SetBeginArrowWidth(this.arrowParameters.GetBeginArrowWidth());
                                    fig.SetBeginArrowHeight(this.arrowParameters.GetBeginArrowHeight());
                                    fig.SetEndArrowWidth(this.arrowParameters.GetEndArrowWidth());
                                    fig.SetEndArrowHeight(this.arrowParameters.GetEndArrowHeight());
                                }
                                fig.SetLineWidth(this.GetLineWidth());
                            }
                            
                            fig.ReadXML(x[i]);                            

                        }
                        k++;
                        continue;
                    }
                    if (x[i].nodeName === 'Text')
                    {
                        if (fig === null)
                        {
                            this.SetFigure(k, objM.newObject('TCanvasText_'));
                            fig = this.GetFigure(k);
                        }
                        if (fig !== null)
                        {
                            fig.SetVariables(this.GetVariables());
                            if (this.colourText !== null)
                                fig.SetColourTextRGBA(this.colourText.GetColour(this.GetObjectVariables()));
                            if (this.colourSideText !== null)
                                fig.SetColourSideTextRGBA(this.colourSideText.GetColour(this.GetObjectVariables()));
                            if (this.fontParameters !== null)
                            {
                                fig.SetFont(this.fontParameters.GetFont());
                                fig.SetFontStyle(this.fontParameters.GetFontStyle());
                                fig.SetFontWeight(this.fontParameters.GetFontWeight());
                                fig.SetFontSize(this.fontParameters.GetFontSize());
                            }

                            fig.ReadXML(x[i]);                            
                        }
                        k++;
                        continue;
                    }
                    if (x[i].nodeName === 'Chart')
                    {
                        if (fig === null)
                        {
                            this.SetFigure(k, objM.newObject('TCanvasChart_'));
                            fig = this.GetFigure(k);
                        }
                        if (fig !== null)
                        {
                            fig.SetVariables(this.GetVariables());
//                            if (this.colourText !== null)
//                                fig.SetColourTextRGBA(this.colourText.GetColour(this.GetObjectVariables()));
//                            if (this.colourSideText !== null)
//                                fig.SetColourSideTextRGBA(this.colourSideText.GetColour(this.GetObjectVariables()));
                            if (this.fontParameters !== null)
                            {
                                fig.SetFont(this.fontParameters.GetFont());
                                fig.SetFontStyle(this.fontParameters.GetFontStyle());
//                                fig.SetFontWeight(this.fontParameters.GetFontWeight());
                                fig.SetFontSize(this.fontParameters.GetFontSize());
                            }

                            fig.ReadXML(x[i]);                            
                        }
                        k++;
                        continue;
                    }
                    if (x[i].nodeName === 'DrawImage')
                    {
                        if (fig === null)
                        {
                            this.SetFigure(k, objM.newObject('TDrawImage_'));
                            fig = this.GetFigure(k);
                        }
                        if (fig !== null)
                        {
                            fig.SetVariables(this.GetVariables());
                            fig.ReadXML(x[i]);                            
                        }
                        k++;
                        continue;
                    }
                    if (x[i].nodeName === 'For')
                    {
                        if (fig === null)
                        {
                            this.SetFigure(k,objM.newObject('TCanvasFor'));
                            fig = this.GetFigure(k);
                        }
                        if (fig !== null)
                        {
                            fig.SetVariables(this.GetVariables());
                            fig.SetColourFillTXT(this.GetColourFill());
                            fig.SetColourLineTXT(this.GetColourLine());
                            fig.SetColourTextTXT(this.GetColourText());
                            fig.SetColourSideTextTXT(this.GetColourSideTextTXT());
                            fig.SetArrowParameters(this.GetArrowParameters());
                            fig.SetFontParameters(this.GetFontParameters());
                            fig.ReadXML(x[i]);                            
                        }
                        k++;
                        continue;
                    }
                    if (x[i].nodeName === 'If')
                    {
                        if (fig === null)
                        {
                            this.SetFigure(k,objM.newObject('TCanvasIf'));
                            fig = this.GetFigure(k);
                        }
                        if (fig !== null)
                        {
                            fig.SetVariables(this.GetVariables());
                            fig.SetColourFillTXT(this.GetColourFill());
                            fig.SetColourLineTXT(this.GetColourLine());
                            fig.SetColourTextTXT(this.GetColourText());
                            fig.SetColourSideTextTXT(this.GetColourSideTextTXT());
                            fig.SetArrowParameters(this.GetArrowParameters());
                            fig.SetFontParameters(this.GetFontParameters());
                            fig.ReadXML(x[i]);                            
                        }
                        k++;
                        continue;
                    }
                    if (x[i].nodeName === 'Colour')
                    {
                        if (this.colourFill === null)
                            this.colourFill = objM.newObject('TColourTXT');
                        if (this.colourFill !== null)
                            this.colourFill.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'ColourLine')
                    {
                        if (this.colourLine === null)
                            this.colourLine = objM.newObject('TColourTXT');
                        if (this.colourLine !== null)
                            this.colourLine.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'TextColour')
                    {
                        if (this.colourText === null)
                            this.colourText = objM.newObject('TColourTXT');
                        if (this.colourText !== null)
                            this.colourText.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'TextSideColour')
                    {
                        if (this.colourSideText === null)
                            this.colourSideText = objM.newObject('TColourTXT');
                        if (this.colourSideText !== null)
                            this.colourSideText.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'TextStyle')
                    {
                        if (this.fontParameters === null)
                            this.fontParameters = objM.newObject('TFontParameters');
                        if (this.fontParameters !== null)
                            this.fontParameters.ReadXML(x[i]);
                    }
                    if (x[i].nodeName === 'Style')
                    {
                        if (this.arrowParameters === null)
                            this.arrowParameters = objM.newObject('TArrowParameters');
                        if (this.arrowParameters !== null)
                            this.arrowParameters.ReadXML(x[i]);
                        attr = x[i].getAttribute('lineWidth');
                        if (typeof attr !== 'undefined' && attr !== null)
                            this.SetLineWidth(parseFloat(attr));
                    }
                }
            }
        }
    };

    TCanvasBlock.prototype.SetColourFill = function(c){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof c !== 'undefined' && c !== null && c.IsType('TColourTXT'))
            this.colourFill = objM.copy(c);
    };
    
    TCanvasBlock.prototype.GetColourFill = function(){
        var objM = this.GetObjectManager();
        if (objM !== null)
            return objM.copy(this.colourFill);
    };
    
    TCanvasBlock.prototype.SetColourLine = function(c){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof c !== 'undefined' && c !== null && c.IsType('TColourTXT'))
            this.colourLine = objM.copy(c);
    };
    
    TCanvasBlock.prototype.GetColourLine = function(){
        var objM = this.GetObjectManager();
        if (objM !== null)
            return objM.copy(this.colourLine);
    };
    
    TCanvasBlock.prototype.SetColourText = function(c){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof c !== 'undefined' && c !== null && c.IsType('TColourTXT'))
            this.colourText = objM.copy(c);
    };
    
    TCanvasBlock.prototype.GetColourText = function(){
        var objM = this.GetObjectManager();
        if (objM !== null)
            return objM.copy(this.colourText);
    };
    
    TCanvasBlock.prototype.SetColourSideText = function(c){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof c !== 'undefined' && c !== null && c.IsType('TColourTXT'))
            this.colourSideText = objM.copy(c);
    };
    
    TCanvasBlock.prototype.GetColourSideText = function(){
        var objM = this.GetObjectManager();
        if (objM !== null)
            return objM.copy(this.colourSideText);
    };
    
    TCanvasBlock.prototype.SetArrowParameters = function(c){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof c !== 'undefined' && c !== null && c.IsType('TArrowParameters'))
            this.arrowParameters = objM.copy(c);
    };
    
    TCanvasBlock.prototype.GetArrowParameters = function(){
        var objM = this.GetObjectManager();
        if (objM !== null)
            return objM.copy(this.arrowParameters);
    };
    
    TCanvasBlock.prototype.SetFontParameters = function(f){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof f !== 'undefined' && f !== null && f.IsType('TFontParameters'))
            this.fontParameters = objM.copy(f);
    };
    
    TCanvasBlock.prototype.GetFontParameters = function(){
        var objM = this.GetObjectManager();
        if (objM !== null)
            return objM.copy(this.fontParameters);
    };

    TCanvasBlock.prototype.GetFigure = function(number){
        if (typeof number !== 'undefined' && number !== null && IsInt(number) && number >= 0 && number < this.figures.length)
        {
            return this.figures[number];
        }
        return null;
    };

    TCanvasBlock.prototype.SetFigure = function(number,fig){
        if (typeof number !== 'undefined' && number !== null && IsInt(number) && number >= 0)
        {
            if (typeof fig !== 'undefined' && fig !== null && fig.IsType('TObjectFigure'))
                this.figures[number] = fig;
        }
    };

    TCanvasBlock.prototype.GetObjectVariables = function(){
        return this.variables;
    };

    TCanvasBlock.prototype.SetObjectVariables = function(var_){
        if (typeof var_ !== 'undefined' && var_ !== null && var_.IsType('TVariables'))
            this.variables = var_;
    };

    TCanvasBlock.prototype.GetFigures = function(){
        return this.figures;
    };

    TCanvasBlock.prototype.DrawFigure = function(ctx){
        if (typeof ctx !== 'undefined' && ctx !== null && ctx.IsType('TDrawContext'))
        {
            var i,n = this.figures.length;
            for (i = 0;i < n;i++)
            {
                if (typeof this.figures[i] !== 'undefined' && this.figures[i] !== null && this.figures[i].IsType('TObjectFigure'))
                {
                    this.figures[i].DrawFigure(ctx);
                }
            }
        }
    };

    TCanvasBlock.prototype.SetLineWidth = function(width){
        if (typeof width !== 'undefined' && width !== null && IsNumeric(width))
            this.lineWidth = width;
    };
    
    TCanvasBlock.prototype.GetLineWidth = function(){
        return this.lineWidth;
    };

};

TCanvasBlock.prototype = new TObjectFigure();


function TCanvasFor(){
    var type = 'TCanvasFor';
    TCanvasFor.prototype.InitConstructor = function(){
        TObjectFigure.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.variable = null;
        this.startValue = null;
        this.endValue = null;
        this.step = '1';
        this.figure2 = null;
    };
    this.InitConstructor();

    TCanvasFor.prototype.Init = function(_object){
        TObjectFigure.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasFor'))
        {
            if (typeof _object.variable !== 'undefined' && _object.variable !== null && _object.variable.IsType('TVariableDouble'))
                this.variable = _object.variable;
            if (typeof _object.startValue !== 'undefined' && _object.startValue !== null)
            {
                this.startValue = new String(_object.startValue);
                if (this.startValue !== null)
                    this.startValue = this.startValue.toString();
            }
            if (typeof _object.endValue !== 'undefined' && _object.endValue !== null)
            {
                this.endValue = new String(_object.endValue);
                if (this.endValue !== null)
                    this.endValue = this.endValue.toString();
            }
            if (typeof _object.step !== 'undefined' && _object.step !== null)
            {
                this.step = new String(_object.step);
                if (this.step !== null)
                    this.step = this.step.toString();
            }
            if (typeof _object.figure2 !== 'undefined' && _object.figure2 !== null && _object.figure2.IsType('TObjectFigure'))
                this.figure2 = objM.copy(_object.figure2);
        }
    };

    TCanvasFor.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TObjectFigure.prototype.IsType.call(this,_type);
    };
    
    TCanvasFor.prototype.ReadXML = function(tag){
        TObjectFigure.prototype.ReadXML.call(this,tag);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof tag !== 'undefined' && tag !== null)
        {
            var attr = tag.getAttribute('var');
            if (typeof attr !== 'undefined' && attr !== null)
            {
                this.variable = objM.newObject('TVariableDouble');
                if (this.variable !== null)
                    this.variable.SetName(attr);
            }
            attr = tag.getAttribute('startValue');
            if (typeof attr !== 'undefined' && attr !== null)
            {
                this.startValue = attr;
                this.variable.SetValue(attr);
                this.variable.SetEquation(attr);
            }
            attr = tag.getAttribute('endValue');
            if (typeof attr !== 'undefined' && attr !== null)
                this.endValue = attr;
            attr = tag.getAttribute('step');
            if (typeof attr !== 'undefined' && attr !== null)
                this.step = attr;
            var block = this.GetFigure();
            if (block === null)
                block = objM.newObject('TCanvasBlock');
            if (block !== null)
            {
                this.SetFigure(block);
                block.SetVariables(this.GetVariables());
                block.SetVariable(this.variable);
                block.SetColourFill(this.GetColourFillTXT());
                block.SetColourLine(this.GetColourLineTXT());
                block.SetColourText(this.GetColourTextTXT());
                block.SetColourSideText(this.GetColourSideTextTXT());
                block.SetArrowParameters(this.GetArrowParameters());
                block.SetFontParameters(this.GetFontParameters());
                block.ReadXML(tag);
            }
        }
    };

    TCanvasFor.prototype.SetFigure = function(fig)
    {
        if (typeof fig !== 'undefined' && fig !== null && fig.IsType('TObjectFigure'))
            this.figure2 = fig;
        if (fig === null)
            this.figure2 = null;
    };

    TCanvasFor.prototype.GetFigure = function()
    {
        return this.figure2;
    };

    TCanvasFor.prototype.DrawFigure = function(ctx){
        if (typeof ctx !== 'undefined' && ctx !== null && ctx.IsType('TDrawContext'))
        {
            var obj = this.GetFigure();
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TObjectFigure'))
            {
                if (this.variable !== null)
                {
                    var start_,stop_,step_,i;
                    start_ = this.CalculateValue(this.startValue);
                    stop_ = this.CalculateValue(this.endValue);
                    step_ = this.CalculateValue(this.step);
                    if (typeof start_ !== 'undefined' && start_ !== null && IsNumeric(start_))
                    {
                        if (typeof stop_ !== 'undefined' && stop_ !== null && IsNumeric(stop_))
                        {
                            if (typeof step_ !== 'undefined' && step_ !== null && IsNumeric(step_))
                            {
                                for (i = start_;i <= stop_;i = i + step_)
                                {
                                    this.variable.SetValue(i);
                                    obj.DrawFigure(ctx);                                    
                                }
                            }                        
                        }                        
                    }
                }
            }
        }
    };

};

TCanvasFor.prototype = new TObjectFigure();


function TCanvasIf(){
    var type = 'TCanvasIf';
    TCanvasIf.prototype.InitConstructor = function(){
        TObjectFigure.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.condition = null;
        this.figure2 = null;
    };
    this.InitConstructor();

    TCanvasIf.prototype.Init = function(_object){
        TObjectFigure.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasIf'))
        {
            if (typeof _object.condition !== 'undefined' && _object.condition !== null)
            {
                this.condition = new String(_object.condition);
                if (this.condition !== null)
                    this.condition = this.condition.toString();
            }
            if (typeof _object.figure2 !== 'undefined' && _object.figure2 !== null && _object.figure2.IsType('TObjectFigure'))
                this.figure2 = objM.copy(_object.figure2);
        }
    };

    TCanvasIf.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TObjectFigure.prototype.IsType.call(this,_type);
    };
    
    TCanvasIf.prototype.ReadXML = function(tag){
        TObjectFigure.prototype.ReadXML.call(this,tag);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof tag !== 'undefined' && tag !== null)
        {
            var attr = tag.getAttribute('condition');
            if (typeof attr !== 'undefined' && attr !== null)
                this.condition = attr;
            var block = this.GetFigure();
            if (block === null)
                block = objM.newObject('TCanvasBlock');
            if (block !== null)
            {
                this.SetFigure(block);
                block.SetVariables(this.GetVariables());
                block.SetVariable(this.variable);
                block.SetColourFill(this.GetColourFillTXT());
                block.SetColourLine(this.GetColourLineTXT());
                block.SetColourText(this.GetColourTextTXT());
                block.SetColourSideText(this.GetColourSideTextTXT());
                block.SetArrowParameters(this.GetArrowParameters());
                block.SetFontParameters(this.GetFontParameters());
                block.ReadXML(tag);
            }
        }
    };

    TCanvasIf.prototype.SetFigure = function(fig)
    {
        if (typeof fig !== 'undefined' && fig !== null && fig.IsType('TObjectFigure'))
            this.figure2 = fig;
        if (fig === null)
            this.figure2 = null;
    };

    TCanvasIf.prototype.GetFigure = function()
    {
        return this.figure2;
    };

    TCanvasIf.prototype.DrawFigure = function(ctx){
        if (typeof ctx !== 'undefined' && ctx !== null && ctx.IsType('TDrawContext'))
        {
            var obj = this.GetFigure();
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TObjectFigure'))
            {
                if (this.condition !== null)
                {
                    var cond;
                    cond = this.CalculateValue(this.condition);
                    if (cond)
                    {
                        obj.DrawFigure(ctx);                                    
                    }
                }
            }
        }
    };

};

TCanvasIf.prototype = new TObjectFigure();


function TCanvasLine_(){
    var type = 'TCanvasLine_';
    TCanvasLine_.prototype.InitConstructor = function(){
        TFigure_.prototype.InitConstructor.call(this);
        this.lineWidth = 1;
        this.SetType(type);
    };
    this.InitConstructor();

    TCanvasLine_.prototype.Init = function(_object){
        TFigure_.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasLine_'))
        {
            if (typeof _object.lineWidth !== 'undefined' && _object.lineWidth !== null && IsNumeric(_object.lineWidth))
                this.lineWidth = _object.lineWidth;
        }
    };

    TCanvasLine_.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TFigure_.prototype.IsType.call(this,_type);
    };

    TCanvasLine_.prototype.Recalculate = function(){
        TFigure_.prototype.Recalculate.call(this);
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            var i,coord,line,x,y,z;
            line = this.GetFigure();
            if (typeof line !== 'undefined' && line !== null)
            {
                line.SetLineWidth(this.GetLineWidth());
                line.SetLineColour(this.colourLine);
                for (i = 0;i< this.coordinates[0].length;i++)
                {
//                    if (this.coordinates[i].length > 0)
                    {
                        coord = objM.newObject('TVector3DT');
                        if (coord !== null)
                        {
                            x = this.GetCoordinate(0,i);
                            y = this.GetCoordinate(1,i);
                            z = this.GetCoordinate(2,i);
                            if (x !== null && y !== null && z !== null)
                            {
                                coord.SetCoordinates(x,y,z);
                                line.SetVerticle(i,coord);
                            }
                        }
                    }
                }
  
            }
            
        }
    };    
    
    TCanvasLine_.prototype.ReadXML = function(tag){
        TFigure_.prototype.ReadXML.call(this,tag);
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            var attr,i,coord,line = objM.newObject('TCanvasLine'),x,y,z=0;
            if (line !== null)
            {
                line.SetLineWidth(this.lineWidth);
                for (i = 0;i < this.coordinates[0].length;i++)
                {
                    coord = objM.newObject('TVector3DT');
                    if (coord !== null)
                    {
                        x = this.GetCoordinate(0,i);
                        y = this.GetCoordinate(1,i);
                        z = this.GetCoordinate(2,i);
                        if (x !== null && y !== null)
                        {
                            coord.SetCoordinates(x,y,z);
                            line.SetVerticle(i,coord);
                        }
                    }
                }
                attr = tag.getAttribute('begin');
                if (typeof attr !== 'undefined' && attr !== null)
                {
                    line.SetArrow('T' + attr,true);
                    line.SetBeginArrowWidth(this.beginArrowWidth);
                    line.SetBeginArrowHeight(this.beginArrowHeight);
                }
                attr = tag.getAttribute('end');
                if (typeof attr !== 'undefined' && attr !== null)
                {
                    line.SetArrow('T' + attr,false);
                    line.SetEndArrowWidth(this.endArrowWidth);
                    line.SetEndArrowHeight(this.endArrowHeight);
                }
    //                    this.SetFigure(line);

                attr = tag.getAttribute('beginLength');
                if (typeof attr !== 'undefined' && attr !== null && IsNumeric(attr))
                {
                    attr = parseFloat(attr);
                    if (attr !== null && IsNumeric(attr))
                        line.SetBeginLength(attr);
                }
                attr = tag.getAttribute('endLength');
                if (typeof attr !== 'undefined' && attr !== null && IsNumeric(attr))
                {
                    attr = parseFloat(attr);
                    if (attr !== null && IsNumeric(attr))
                        line.SetEndLength(attr);
                }
                this.SetFigure(line);
            }
        }
        
        this.Recalculate();
    };

    TCanvasLine_.prototype.SetBeginArrowWidth = function(width)
    {
        if (typeof width !== 'undefined' && width !== null && IsNumeric(width))
        {
            var obj = this.GetFigure();
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TCanvasLine'))
                obj.SetBeginArrowWidth(width);
            this.beginArrowWidth = parseFloat(width);
        }
    };

    TCanvasLine_.prototype.GetBeginArrowWidth = function()
    {
        return this.beginArrowWidth;
    };

    TCanvasLine_.prototype.SetBeginArrowHeight = function(height)
    {
        if (typeof height !== 'undefined' && height !== null && IsNumeric(height))
        {
            var obj = this.GetFigure();
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TCanvasLine'))
                obj.SetBeginArrowHeight(height);
            this.beginArrowHeight = parseFloat(height);
        }
    };

    TCanvasLine_.prototype.GetBeginArrowHeight = function()
    {
        return this.beginArrowHeight;
    };

    TCanvasLine_.prototype.SetEndArrowWidth = function(width)
    {
        if (typeof width !== 'undefined' && width !== null && IsNumeric(width))
        {
            var obj = this.GetFigure();
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TCanvasLine'))
                obj.SetEndArrowWidth(width);
            this.endArrowWidth = parseFloat(width);
        }
    };

    TCanvasLine_.prototype.GetEndArrowWidth = function()
    {
        return this.endArrowWidth;
    };

    TCanvasLine_.prototype.SetEndArrowHeight = function(height)
    {
        if (typeof height !== 'undefined' && height !== null && IsNumeric(height))
        {
            var obj = this.GetFigure();
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TCanvasLine'))
                obj.SetEndArrowHeight(height);
            this.endArrowHeight = parseFloat(height);
        }
    };

    TCanvasLine_.prototype.GetEndArrowHeight = function()
    {
        return this.endArrowHeight;
    };

    TCanvasLine_.prototype.SetLineWidth = function(width)
    {
        if (typeof width !== 'undefined' && width !== null && IsNumeric(width))
        {
            var obj = this.GetFigure();
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TCanvasLine'))
                obj.SetLineWidth(width);
            this.lineWidth = width;
        }
    };

    TCanvasLine_.prototype.GetLineWidth = function()
    {
        var obj = this.GetFigure();
        if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TCanvasLine'))
            return obj.GetLineWidth();
        return null;
    };


};

TCanvasLine_.prototype = new TFigure_();


function TCanvasPolygon_(){
    var type = 'TCanvasPolygon_';
    TCanvasPolygon_.prototype.InitConstructor = function(){
        TFigure_.prototype.InitConstructor.call(this);
        this.SetType(type);
    };
    this.InitConstructor();

    TCanvasPolygon_.prototype.Init = function(_object){
        TFigure_.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasPolygon_'))
        {
        }
    };

    TCanvasPolygon_.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TFigure_.prototype.IsType.call(this,_type);
    };

    TCanvasPolygon_.prototype.Recalculate = function(){
        TFigure_.prototype.Recalculate.call(this);
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            var i,coord,line,x,y,z;
            line = objM.newObject('TCanvasPolygon');
            if (typeof line !== 'undefined' && line !== null)
            {
                line.SetLineWidth(this.GetLineWidth());
                line.SetLineColour(this.colourLine);
                line.SetBackgroundColour(this.colourFill);
                for (i = 0;i< this.coordinates[0].length;i++)
                {
//                    if (this.coordinates[i].length > 0)
                    {
                        coord = objM.newObject('TVector3DT');
                        if (coord !== null)
                        {
                            x = this.GetCoordinate(0,i);
                            y = this.GetCoordinate(1,i);
                            z = this.GetCoordinate(2,i);
                            if (x !== null && y !== null && z !== null)
                            {
                                coord.SetCoordinates(x,y,z);
                                line.SetVerticle(i,coord);
                            }
                        }
                    }
                }
                this.SetFigure(line);  
            }
            
        }
    };    
    
    TCanvasPolygon_.prototype.ReadXML = function(tag){
        TFigure_.prototype.ReadXML.call(this,tag);
        this.Recalculate();
    };
};

TCanvasPolygon_.prototype = new TFigure_();


function TCanvasTriangle_(){
    var type = 'TCanvasTriangle_';
    TCanvasTriangle_.prototype.InitConstructor = function(){
        TFigure_.prototype.InitConstructor.call(this);
        this.SetType(type);
    };
    this.InitConstructor();

    TCanvasTriangle_.prototype.Init = function(_object){
        TFigure_.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasTriangle_'))
        {
        }
    };

    TCanvasTriangle_.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TFigure_.prototype.IsType.call(this,_type);
    };

    TCanvasTriangle_.prototype.Recalculate = function(){
        TFigure_.prototype.Recalculate.call(this);
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            var i,coord,triangle,x,y,z;
            triangle = objM.newObject('TCanvasTriangle');
            if (triangle !== null)
            {
                triangle.SetLineWidth(this.GetLineWidth());
                triangle.SetLineColour(this.colourLine);
                triangle.SetBackgroundColour(this.colourFill);
                if (this.coordinates[0].length > 0)
                {
                    coord = objM.newObject('TVector3DT');
                    if (coord !== null)
                    {
                        x = this.GetCoordinate(0,0);
                        y = this.GetCoordinate(1,0);
                        z = this.GetCoordinate(2,0);
                        if (x !== null && y !== null && z !== null)
                        {
                            coord.SetCoordinates(x,y,z);
                            triangle.SetVerticle(0,coord);
                        }
                    }
                }
                if (this.coordinates[1].length > 1)
                {
                    coord = objM.newObject('TVector3DT');
                    if (coord !== null)
                    {
                        x = this.GetCoordinate(0,1);
                        y = this.GetCoordinate(1,1);
                        z = this.GetCoordinate(2,1);
                        if (x !== null && y !== null && z !== null)
                        {
                            coord.SetCoordinates(x,y,z);
                            triangle.SetVerticle(1,coord);
                        }
                    }
                }
                if (this.coordinates[2].length > 1)
                {
                    coord = objM.newObject('TVector3DT');
                    if (coord !== null)
                    {
                        x = this.GetCoordinate(0,2);
                        y = this.GetCoordinate(1,2);
                        z = this.GetCoordinate(2,2);
                        if (x !== null && y !== null && z !== null)
                        {
                            coord.SetCoordinates(x,y,z);
                            triangle.SetVerticle(2,coord);
                        }
                    }
                }
                this.SetFigure(triangle);

            }
            
        }
    };    
    
    TCanvasTriangle_.prototype.ReadXML = function(tag){
        TFigure_.prototype.ReadXML.call(this,tag);
        this.Recalculate();
    };

};

TCanvasTriangle_.prototype = new TFigure_();


function TCanvasLocaleFigure(){
    var type = 'TCanvasLocaleFigure';
    TCanvasLocaleFigure.prototype.InitConstructor = function(){
        TLocaleFigure.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.x = null;
        this.y = null;
        this.z = null;
        this.alpha = null;
        this.scaleX = null;
        this.scaleY = null;
    };
    this.InitConstructor();

    TCanvasLocaleFigure.prototype.Init = function(_object){
        TLocaleFigure.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasLocaleFigure'))
        {
            if (typeof _object.x !== 'undefined' && _object.x !== null)
            {
                this.x = new String(_object.x);
                if (this.x !== null)
                    this.x = this.x.toString();
            }
            if (typeof _object.y !== 'undefined' && _object.y !== null)
            {
                this.y = new String(_object.y);
                if (this.y !== null)
                    this.y = this.y.toString();
            }
            if (typeof _object.z !== 'undefined' && _object.z !== null)
            {
                this.z = new String(_object.z);
                if (this.z !== null)
                    this.z = this.z.toString();
            }
            if (typeof _object.alpha !== 'undefined' && _object.alpha !== null)
            {
                this.alpha = new String(_object.alpha);
                if (this.alpha !== null)
                    this.alpha = this.alpha.toString();
            }
            if (typeof _object.scaleX !== 'undefined' && _object.scaleX !== null)
            {
                this.scaleX = new String(_object.scaleX);
                if (this.scaleX !== null)
                    this.scaleX = this.scaleX.toString();
            }
            if (typeof _object.scaleY !== 'undefined' && _object.scaleY !== null)
            {
                this.scaleY = new String(_object.scaleY);
                if (this.scaleY !== null)
                    this.scaleY = this.scaleY.toString();
            }
        }
    };

    TCanvasLocaleFigure.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TLocaleFigure.prototype.IsType.call(this,_type);
    };

    TCanvasLocaleFigure.prototype.SetX = function(x_){
        if (typeof x_ !== 'undefined' && x_ !== null)
        {
            this.x = new String(x_);
            if (this.x !== null)
                this.x = this.x.toString();
        }
        if (x_ === null)
            this.x = null;
    };

    TCanvasLocaleFigure.prototype.GetX = function(){
        var tmp = new String(this.x);
        if (tmp !== null)
            return tmp.toString();
        return tmp;
    };

    TCanvasLocaleFigure.prototype.SetY = function(y_){
        if (typeof y_ !== 'undefined' && y_ !== null)
        {
            this.y = new String(y_);
            if (this.y !== null)
                this.y = this.y.toString();
        }
        if (y_ === null)
            this.y = null;
    };

    TCanvasLocaleFigure.prototype.GetY = function(){
        var tmp = new String(this.y);
        if (tmp !== null)
            return tmp.toString();
        return tmp;
    };

    TCanvasLocaleFigure.prototype.SetZ = function(z_){
        if (typeof z_ !== 'undefined' && z_ !== null)
        {
            this.z = new String(z_);
            if (this.z !== null)
                this.z = this.z.toString();
        }
        if (z_ === null)
            this.z = null;
    };

    TCanvasLocaleFigure.prototype.GetZ = function(){
        var tmp = new String(this.z);
        if (tmp !== null)
            return tmp.toString();
        return tmp;
    };

    TCanvasLocaleFigure.prototype.SetAlpha = function(alpha_){
        if (typeof alpha_ !== 'undefined' && alpha_ !== null)
        {
            this.alpha = new String(alpha_);
            if (this.alpha !== null)
                this.alpha = this.alpha.toString();
        }
        if (alpha_ === null)
            this.alpha = null;
    };

    TCanvasLocaleFigure.prototype.GetAlpha = function(){
        var tmp = new String(this.alpha);
        if (tmp !== null)
            return this.CalculateValue(tmp.toString())*Math.PI/180;
        return tmp;
    };

    TCanvasLocaleFigure.prototype.SetScaleX = function(scale){
        if (typeof scale !== 'undefined' && scale !== null)
        {
            this.scaleX = new String(scale);
            if (this.scaleX !== null)
                this.scaleX = this.scaleX.toString();
        }
        if (scale === null)
            this.scaleX = null;
    };

    TCanvasLocaleFigure.prototype.GetScaleX = function(){
        var tmp = new String(this.scaleX);
        if (tmp !== null)
            return tmp.toString();
        return tmp;
    };

    TCanvasLocaleFigure.prototype.SetScaleY = function(scale){
        if (typeof scale !== 'undefined' && scale !== null)
        {
            this.scaleY = new String(scale);
            if (this.scaleY !== null)
                this.scaleY = this.scaleY.toString();
        }
        if (scale === null)
            this.scaleY = null;
    };

    TCanvasLocaleFigure.prototype.GetScaleY = function(){
        var tmp = new String(this.scaleY);
        if (tmp !== null)
            return tmp.toString();
        return tmp;
    };

    TCanvasLocaleFigure.prototype.SetScale = function(scale){
        if (typeof scale !== 'undefined' && scale !== null)
        {
            this.scaleX = new String(scale);
            if (this.scaleX !== null)
                this.scaleX = this.scaleX.toString();
            this.scaleY = new String(scale);
            if (this.scaleY !== null)
                this.scaleY = this.scaleY.toString();
        }
        if (scale === null)
        {
            this.scaleX = null;
            this.scaleY = null;
        }
    };

    TCanvasLocaleFigure.prototype.ParseXML = function(tag1,tag2){
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            var attr;
            attr = tag1.getAttribute('x');
            if (typeof attr !== 'undefined' && attr !== null)
                this.x = attr;
            attr = tag1.getAttribute('y');
            if (typeof attr !== 'undefined' && attr !== null)
                this.y = attr;
            attr = tag1.getAttribute('z');
            if (typeof attr !== 'undefined' && attr !== null)
                this.z = attr;
            attr = tag1.getAttribute('alpha');
            if (typeof attr !== 'undefined' && attr !== null)
                this.alpha = attr;
            attr = tag1.getAttribute('scaleX');
            if (typeof attr !== 'undefined' && attr !== null)
                this.scaleX = attr;
            attr = tag1.getAttribute('scaleY');
            if (typeof attr !== 'undefined' && attr !== null)
                this.scaleY = attr;
            attr = tag1.getAttribute('scale');
            if (typeof attr !== 'undefined' && attr !== null)
                this.SetScale(attr);
        }
    };
};

TCanvasLocaleFigure.prototype = new TLocaleFigure();


function TCanvasText_(){
    var type = 'TCanvasText_';
    TCanvasText_.prototype.InitConstructor = function(){
        TCanvasLocaleFigure.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.element = [];
        this.colourText = null;
        this.colourSide = null;
        this.fontSize = '1';
        this.font = 'Arial';
        this.alignmentX = 'center';
        this.alignmentY = 'center';
        this.height = '0.1';
        this.style = 'normal';
        this.weight = 'normal';
        this.rotate = 0;
    };
    this.InitConstructor();

    TCanvasText_.prototype.Init = function(_object){
        TCanvasLocaleFigure.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasText_'))
        {
            var i;
            if (typeof _object.element !== 'undefined' && _object.element !== null)
            {
                for (i = 0;i < _object.element.length;i++)
                {
                    if (typeof _object.element[i] !== 'undefined' && _object.element[i] !== null && _object.element[i].IsType('TParagraphElement'))
                        this.element[i] = objM.copy(_object.element[i]);
                }
            }
            if (typeof _object.colourText !== 'undefined' && _object.colourText !== null && _object.colourText.IsType('TColourRGBA'))
                this.colourText = objM.copy(_object.colourText);
            if (typeof _object.colourSide !== 'undefined' && _object.colourSide !== null && _object.colourSide.IsType('TColourRGBA'))
                this.colourSide = objM.copy(_object.colourSide);
            if (typeof _object.font !== 'undefined' && _object.font !== null)
            {
                this.font = new String(_object.font);
                if (this.font !== null)
                    this.font = this.font.toString();
            }
            if (typeof _object.alignmentX !== 'undefined' && _object.alignmentX !== null)
            {
                this.alignmentX = new String(_object.alignmentX);
                if (this.alignmentX !== null)
                    this.alignmentX = this.alignmentX.toString();
            }
            if (typeof _object.alignmentY !== 'undefined' && _object.alignmentY !== null)
            {
                this.alignmentY = new String(_object.alignmentY);
                if (this.alignmentY !== null)
                    this.alignmentY = this.alignmentY.toString();
            }
            if (typeof _object.fontSize !== 'undefined' && _object.fontSize !== null)
            {
                this.fontSize = new String(_object.fontSize);
                if (this.fontSize !== null)
                    this.fontSize = this.fontSize.toString();
            }
            if (typeof _object.height !== 'undefined' && _object.height !== null)
            {
                this.height = new String(_object.height);
                if (this.height !== null)
                    this.height = this.height.toString();
            }
            if (typeof _object.style !== 'undefined' && _object.style !== null)
            {
                this.style = new String(_object.style);
                if (this.style !== null)
                    this.style = this.style.toString();
            }
            if (typeof _object.weight !== 'undefined' && _object.weight !== null)
            {
                this.weight = new String(_object.weight);
                if (this.weight !== null)
                    this.weight = this.weight.toString();
            }
            if (typeof _object.rotate !== 'undefined' && _object.rotate !== null && IsNumeric(_object.rotate))
                this.rotate = _object.rotate;
        }
    };

    TCanvasText_.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TCanvasLocaleFigure.prototype.IsType.call(this,_type);
    };
    
    TCanvasText_.prototype.ParseXML = function(tag1,tag2){
        TCanvasLocaleFigure.prototype.ParseXML.call(this,tag1,tag2);
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            var i,attr;
            attr = tag1.getAttribute('fontSize');
            if (typeof attr !== 'undefined' && attr !== null)
                this.fontSize = attr;
            attr = tag1.getAttribute('font');
            if (typeof attr !== 'undefined' && attr !== null)
                this.font = attr;
            attr = tag1.getAttribute('alignmentX');
            if (typeof attr !== 'undefined' && attr !== null)
                this.alignmentX = attr;
            attr = tag1.getAttribute('alignmentY');
            if (typeof attr !== 'undefined' && attr !== null)
                this.alignmentY = attr;
            attr = tag1.getAttribute('fontHeight');
            if (typeof attr !== 'undefined' && attr !== null)
                this.height = attr;
            attr = tag1.getAttribute('rotate');
            if (typeof attr !== 'undefined' && attr !== null && IsNumeric(attr))
            {
                attr = parseFloat(this.CalculateValue(attr));
                if (attr !== null){
                    this.rotate = attr*Math.PI/180;
                }
            }

            var i,x_ = tag2.childNodes,attr,k;

            for (i = 0,k=0;i < x_.length;i++)
            {
                if (x_[i].nodeType === 3)
                {
                    if (this.element.length <= k || typeof this.element[k] === 'undefined' || this.element[k] === null)
                    {
                        this.element[k] = objM.newObject('TParagraphString');
                    }
                    if (this.element.length > k && typeof this.element[k] !== 'undefined' && this.element[k] !== null)
                    {
                        this.element[k++].ParseXML(x_[i]);
                    }
                }
            }
            
            var fig = this.GetFigure();
            if (fig === null)
            {
                fig = objM.newObject('TCanvasText');
                this.SetFigure(fig);
            }
        }
    };


    TCanvasText_.prototype.DrawFigure = function(ctx){
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
//            ctx.SetScaleTextYN(this.scaleTextYN);
            var i,txt = '';
            for (i = 0;i < this.element.length;i++)
            {
                if (typeof this.element[i] !== 'undefined' && this.element[i] !== null)
                    txt = txt + this.element[i].GetStringData();
            }
            var obj = this.GetFigure();
            if (typeof obj !== 'undefined' && obj !== null)
            {
                obj.SetText(txt);
                var coord = objM.newObject('TVector3DT');
                if (coord !== null)
                {
                    coord.SetX(this.CalculateValue(this.GetX()));
                    coord.SetY(this.CalculateValue(this.GetY()));
                    coord.SetZ(this.CalculateValue(this.GetZ()));
                    obj.SetVerticle(0,coord);
                }
                obj.SetAlpha(this.GetAlpha());
                obj.SetScaleX(this.GetScaleX());
                obj.SetScaleY(this.GetScaleY());
                obj.SetFontSize(this.CalculateValue(this.fontSize));
                obj.SetHeight(this.CalculateValue(this.height));
                obj.SetColourText(this.colourText);
                obj.SetSideColourText(this.colourSide);
                obj.SetFont(this.font);
                obj.SetFontStyle(this.style);
                obj.SetFontWeight(this.weight);
                obj.SetAlignX(this.alignmentX);
                obj.SetAlignY(this.alignmentY);
                obj.SetRotate(this.rotate);
            }
        }
        TCanvasLocaleFigure.prototype.DrawFigure.call(this,ctx);
    };



    TCanvasText_.prototype.ChangeCurrentLanguageNumber = function(_language){
        TCanvasLocaleFigure.prototype.ChangeCurrentLanguageNumber.call(this,_language);
        if (typeof this.element !== 'undefined' && this.element !== null)
        {
            var i;
            for (i = 0;i < this.element.length;i++)
                if (this.element[i] !== null)
                    this.element[i].ChangeCurrentLanguageNumber(_language);
        }
    };

    TCanvasText_.prototype.SetColourText = function(r,g,b,a){
        var objM = this.GetObjectManager();
        if (objM !== null && (typeof this.colourText === 'undefined' || this.colourText === null))
            this.colourText = objM.newObject('TColourRGBA');
        
        if (typeof this.colourText !== 'undefined' && this.colourText !== null)
            this.colourText.SetColourRGBA(r,g,b,a);
        
    };

    TCanvasText_.prototype.SetSideColourText = function(r,g,b,a){
        var objM = this.GetObjectManager();
        if (objM !== null && (typeof this.colourSide === 'undefined' || this.colourSide === null))
            this.colourSide = objM.newObject('TColourRGBA');
        
        if (typeof this.colourSide !== 'undefined' && this.colourSide !== null)
            this.colourSide.SetColourRGBA(r,g,b,a);
        
    };

    TCanvasText_.prototype.SetFont = function(font_){
        if (typeof font_ !== 'undefined' && font_ !== null)
        {
            this.font = new String(font_);
            if (this.font !== null)
                this.font = this.font.toString();
        }
        if (font_ === null)
            this.font = null;
    };

    TCanvasText_.prototype.SetFontStyle = function(style_){
        if (typeof style_ !== 'undefined' && style_ !== null)
        {
            this.style = new String(style_);
            if (this.style !== null)
                this.style = this.style.toString();
        }
    };

    TCanvasText_.prototype.SetFontWeight = function(weight_){
        if (typeof weight_ !== 'undefined' && weight_ !== null)
        {
            this.weight = new String(weight_);
            if (this.weight !== null)
                this.weight = this.weight.toString();
        }
    };

    TCanvasText_.prototype.SetFontSize = function(size_){
        if (typeof size_ !== 'undefined' && size_ !== null)
        {
            this.fontSize = new String(size_);
            if (this.fontSize !== null)
                this.fontSize = this.fontSize.toString();
        }
    };

    TCanvasText_.prototype.SetColourTextRGBA = function(c){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof c !== 'undefined' && c !== null && c.IsType('TColourRGBA'))
            this.colourText = objM.copy(c);
        if (c === null)
            this.colourText = null;
    };

    TCanvasText_.prototype.SetColourSideTextRGBA = function(c){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof c !== 'undefined' && c !== null && c.IsType('TColourRGBA'))
            this.colourSide = objM.copy(c);
        if (c === null)
            this.colourSide = null;
    };

};

TCanvasText_.prototype = new TCanvasLocaleFigure();

function TCanvasTableShow_(){
    var type = 'TCanvasTableShow_';
    TCanvasTableShow_.prototype.InitConstructor = function(){
        TFigure_.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.table = null;
    };
    this.InitConstructor();

    TCanvasTableShow_.prototype.Init = function(_object){
        TFigure_.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasTableShow_'))
        {
            if (typeof _object.table !== 'undefined' && _object.table !== null && _object.table.IsType('TTableShow'))
                this.table = _object.table;
        }
    };

    TCanvasTableShow_.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TFigure_.prototype.IsType.call(this,_type);
    };

    
    TCanvasTableShow_.prototype.ReadXML = function(tag){
        TFigure_.prototype.ReadXML.call(this,tag);
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            if (this.table === null)
            {
                this.table = objM.newObject('TTableShow');
                if (this.table !== null)
                {
                    this.table.SetVariables(this.GetVariables());
                    this.table.ReadXML(tag);
                }
            }
        }
        this.Recalculate();
    };

    TCanvasTableShow_.prototype.ActualizeActions = function(){
        TFigure_.prototype.ActualizeActions.call(this);
        if (this.table !== null)
            this.table.ActualizeActions();
    };

    TCanvasTableShow_.prototype.Recalculate = function(){
        TFigure_.prototype.Recalculate.call(this);
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            var fig;
            fig = objM.newObject('TCanvasTableShow');
            if (fig !== null)
            {
                if (this.coordinates[0].length > 0)
                {
                    var coord = objM.newObject('TVector3DT');
                    if (coord !== null)
                    {
                        var x = this.GetCoordinate(0,0);
                        var y = this.GetCoordinate(1,0);
                        var z = this.GetCoordinate(2,0);
                        if (x !== null && y !== null && z !== null)
                        {
                            coord.SetCoordinates(x,y,z);
                            fig.SetVerticle(0,coord);
                        }
                    }
                }
                fig.SetTable(this.table);
                this.SetFigure(fig);
            }
            
        }
    };    

};

TCanvasTableShow_.prototype = new TFigure_();




function TCanvasChart_(){
    var type = 'TCanvasChart_';
    TCanvasChart_.prototype.InitConstructor = function(){
        TChart_.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.nameObjectChart = 'TCanvasChart';
        this.chartType = 'Canvas';
    };
    this.InitConstructor();

    TCanvasChart_.prototype.Init = function(_object){
        TChart_.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TChart_'))
        {
        }
    };

    TCanvasChart_.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TChart_.prototype.IsType.call(this,_type);
    };

};

TCanvasChart_.prototype = new TChart_();


function TCanvasCircle_(){
    var type = 'TCanvasCircle_';
    TCanvasCircle_.prototype.InitConstructor = function(){
        TFigure_.prototype.InitConstructor.call(this);
        this.SetType(type);
        this.radius = 1;
    };
    this.InitConstructor();

    TCanvasCircle_.prototype.Init = function(_object){
        TFigure_.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null && typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasCircle_'))
        {
            if (typeof _object.radius !== 'undefined' && _object.radius !== null && IsNumeric(_object.radius))
                this.radius = _object.level;
        }
    };

    TCanvasCircle_.prototype.IsType = function(_type){
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TFigure_.prototype.IsType.call(this,_type);
    };

    TCanvasCircle_.prototype.Recalculate = function(){
        TFigure_.prototype.Recalculate.call(this);
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            var i,coord,circle,x,y,z;
            circle = objM.newObject('TCanvasCircle');
            if (circle !== null)
            {
                circle.SetLineWidth(this.GetLineWidth());
                circle.SetLineColour(this.colourLine);
                circle.SetBackgroundColour(this.colourFill);
                if (this.coordinates[0].length > 0)
                {
                    coord = objM.newObject('TVector3DT');
                    if (coord !== null)
                    {
                        x = this.GetCoordinate(0,0);
                        y = this.GetCoordinate(1,0);
                        z = this.GetCoordinate(2,0);
			if (z === null)
			    z = 0;
                        if (x !== null && y !== null && z !== null)
                        {
                            coord.SetCoordinates(x,y,z);
                            circle.SetVerticle(0,coord);
                        }
                    }
                }
                circle.SetRadius(this.radius);
                this.SetFigure(circle);

            }
            
        }
    };    
    
    TCanvasCircle_.prototype.ReadXML = function(tag){
        TFigure_.prototype.ReadXML.call(this,tag);
        this.SetRadius(parseFloat(tag.getAttribute('radius')));
        
        this.Recalculate();
    };

    TCanvasCircle_.prototype.SetRadius = function(r){
        if (typeof r !== 'undefined' && r !== null && IsNumeric(r))
            this.radius = r;
    };

};

TCanvasCircle_.prototype = new TFigure_();

function TCanvasTransformation(){
    var type = 'TCanvasTransformation';
    TCanvasTransformation.prototype.InitConstructor = function(){
        TVisibleFigure.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.coordinates = null;
        this.scaleX=1;
        this.scaleY=1;
        this.alpha=0;
    };
    this.InitConstructor();

    TCanvasTransformation.prototype.Init = function(_object){
        TVisibleFigure.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasTransformation') && objM !== null)
        {            
            if (typeof _object.coordinates !== 'undefined' && _object.coordinates !== null && coordinates.IsType('TVector3DT'))
                this.coordinates = objM.copy(_object.coordinates);
            if (typeof _object.scaleX !== 'undefined' && _object.scaleX !== null && IsNumeric(_object.scaleX))
                this.scaleX = _object.scaleX;
            if (typeof _object.scaleY !== 'undefined' && _object.scaleY !== null && IsNumeric(_object.scaleY))
                this.scaleY = _object.scaleY;
            if (typeof _object.alpha !== 'undefined' && _object.alpha !== null && IsNumeric(_object.alpha ))
                this.alpha = _object.alpha;
        }
    };
    
    TCanvasTransformation.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TVisibleFigure.prototype.IsType.call(this,_type);
    };

    TCanvasTransformation.prototype.SetCoordinates = function(coord){
        var objM = this.GetObjectManager();
        if (typeof objM !== 'undefined' && objM !== null && typeof coord !== 'undefined' && coord !== null && coord.IsType('TVector3DT'))
            this.coordinates = objM.copy(coord);
        if (coord === null)
            this.coordinates = null;
    };

    TCanvasTransformation.prototype.GetCoordinates = function(){
        var objM = this.GetObjectManager();
        if (typeof objM !== 'undefined' && objM !== null)
        {
            var tmp = objM.copy(this.coordinates);
            return tmp;
        }
    };

    TCanvasTransformation.prototype.SetScaleX = function(scale){
        if (typeof scale !== 'undefined' && scale !== null && IsNumeric(scale))
            this.scaleX = scale;
    };

    TCanvasTransformation.prototype.GetScaleX = function(){
        return this.scaleX;
    };
    
    TCanvasTransformation.prototype.SetScaleY = function(scale){
        if (typeof scale !== 'undefined' && scale !== null && IsNumeric(scale))
            this.scaleY = scale;
    };

    TCanvasTransformation.prototype.GetScaleY = function(){
        return this.scaleY;
    };
    
    TCanvasTransformation.prototype.SetScale = function(scale){
        if (typeof scale !== 'undefined' && scale !== null && IsNumeric(scale))
        {
            this.scaleX = scale;
            this.scaleY = scale;
        }
    };

    TCanvasTransformation.prototype.SetAlpha = function(alpha_){
        if (typeof alpha_ !== 'undefined' && alpha_ !== null && IsNumeric(alpha_))
            this.alpha = alpha_;
    };

    TCanvasTransformation.prototype.GetAlpha = function(){
        return this.alpha;
    };
    

}

TCanvasTransformation.prototype = new TVisibleFigure();


function TCanvasArrowTriangle(){
    var type = 'TCanvasArrowTriangle';
    TCanvasArrowTriangle.prototype.InitConstructor = function(){
        TArrow.prototype.InitConstructor.call(this);
        
        this.correctScale = 1;
        this.shift_ = 1;
        this.SetType(type);
            
    };
    this.InitConstructor();

    TCanvasArrowTriangle.prototype.Init = function(_object){
        //TODO: Implement Me 
        TArrow.prototype.Init.call(this,_object);
//        TObject.Init(_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TArrowTriangle') && objM !== null)
        {
            if (typeof _object.correctScale !== 'undefined' && _object.correctScale !== null && IsNumeric(_object.correctScale))
                this.correctScale = _object.correctScale;
            if (typeof _object.shift_ !== 'undefined' && _object.shift_ !== null && IsNumeric(_object.shift_))
                this.shift_ = _object.shift_;
        }
    };


    TCanvasArrowTriangle.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TArrow.prototype.IsType.call(this,_type);
    };

    TCanvasArrowTriangle.prototype.CalculateVertices = function(shift){
        var line = this.GetParent();
        if (typeof line !== 'undefined' && line !== null && line.IsType('TCanvasLine'))
        {
            shift=0;
            if (typeof shift === 'undefined' || shift === null)
                shift = 1;
            this.shift_ = shift;
            var n = line.GetNumberOfVerticles();
            var objM = this.GetObjectManager();
            if (objM !== null && n !== null && this.GetWidth() !== null && this.GetHeight() !== null && this.beginYN !== null && n >= 2)
            {
                var P0,Pn;
 
                if (this.beginYN)
                {
                    P0 = line.GetVerticle(0);
                    Pn = line.GetVerticle(1);
                }else
                {
                    Pn = line.GetVerticle(n-2);
                    P0 = line.GetVerticle(n-1);
                    
                }

                var matrix,tmpX,tmpY,tmpZ;
//                var matrix2 = this.GetTransformation();
                tmpX = P0.GetX();
                tmpY = P0.GetY();
                if (P0.IsType('TVector2DT'))// && matrix2 !== null && matrix2.IsType('TMatrixTransformation2D'))
                {
                    matrix = objM.newObject('TMatrixTransformation2D');
                    matrix.SetTranslationMatrix(tmpX,tmpY);
                }else
                {
                    if (P0.IsType('TVector3DT'))// && matrix2 !== null && matrix2.IsType('TMatrixTransformation3D'))
                    {
                        tmpZ = P0.GetZ();
                        matrix = objM.newObject('TMatrixTransformation3D');
                        matrix.SetTranslationMatrix(tmpX,tmpY,tmpZ);
                    }else
                        matrix.SetIdentityMatrix();
                }
                    
                Pn.Subtraction(P0);
                P0.SetZeros(P0.GetN());
                    
                this.SetTransformation(matrix);
              
                if (P0 !== null && Pn !== null)
                {
                    var YN = false;
                    if (Pn.GetCoordinate(0) === 0 && Pn.GetCoordinate(1) === 0 && Pn.GetCoordinate(2) !== 0)
                    {
                        var x = Pn.GetCoordinate(0),z = Pn.GetCoordinate(2);
                        Pn.SetCoordinate(0,z);
                        Pn.SetCoordinate(2,x);
                        x = P0.GetCoordinate(0);
                        z = P0.GetCoordinate(2);
                        P0.SetCoordinate(0,z);
                        P0.SetCoordinate(2,x);
                        YN = true;
                    }
                    var Psub = objM.copy(Pn),deltaP0;
                    Psub.Subtraction(P0);
                    deltaP0 = objM.copy(Psub);
                    var norm = Psub.Norm();
                    if (norm !== 0)
                    {
                        Psub.MultiplicationScalar(this.correctScale*this.GetWidth()/norm);
                        deltaP0.MultiplicationScalar(-2*shift/norm);//
                        var x0 = Psub.GetCoordinate(0);
                        var y0 = Psub.GetCoordinate(1);
                        if (x0 !== 0 || y0 !== 0)
                        {
                            var Psub_ = objM.newObject(Psub.GetType());
                            if (x0 > 0 && y0 > 0)
                            {
                                Psub_.SetCoordinate(0,x0);
                                Psub_.SetCoordinate(1,-y0);
                            }
                            if (x0 === 0 && y0 > 0)
                            {
                                Psub_.SetCoordinate(0,y0);
                                Psub_.SetCoordinate(1,0);
                            }
                            if (x0 > 0 && y0 < 0)
                            {
                                Psub_.SetCoordinate(0,-x0);
                                Psub_.SetCoordinate(1,y0);
                            }
                            if (x0 > 0 && y0 === 0)
                            {
                                Psub_.SetCoordinate(0,0);
                                Psub_.SetCoordinate(1,-x0);
                            }
                            if (x0 < 0 && y0 < 0)
                            {
                                Psub_.SetCoordinate(0,x0);
                                Psub_.SetCoordinate(1,-y0);
                            }
                            if (x0 === 0 && y0 < 0)
                            {
                                Psub_.SetCoordinate(0,y0);
                                Psub_.SetCoordinate(1,0);
                            }
                            if (x0 < 0 && y0 > 0)
                            {
                                Psub_.SetCoordinate(0,-x0);
                                Psub_.SetCoordinate(1,y0);
                            }
                            if (x0 < 0 && y0 === 0)
                            {
                                Psub_.SetCoordinate(0,0);
                                Psub_.SetCoordinate(1,-x0);
                            }
                            var Psub2;
                            if (Psub_.ScalarProduct(Psub) === 0)
                            {
                                Psub2 = objM.copy(Psub_);
                            }else
                            {
                                var c = Psub.VectorComponent(Psub_);
                                var tmp = objM.copy(Psub);
                                tmp.MultiplicationScalar(c);
                                Psub2 = objM.copy(Psub_);
                                Psub2.Subtraction(tmp);
                            }
                            norm = Psub2.Norm();
                            Psub2.MultiplicationScalar((this.correctScale*this.GetHeight() + shift)/(2*norm));//
//                            Psub2.MultiplicationScalar((this.height)/(2*norm));
                            var P1 = objM.copy(P0);
                            P1.Addition(Psub);
                            P1.Addition(Psub2);
                            var P2 = objM.copy(P0);
                            P2.Addition(Psub);
                            Psub2.MultiplicationScalar(-1);
                            P2.Addition(Psub2);
                            P0.Addition(deltaP0);//
                            if (YN)
                            {
                                x = P0.GetCoordinate(0);
                                z = P0.GetCoordinate(2);
                                P0.SetCoordinate(0,z);
                                P0.SetCoordinate(2,x);
                                x = P1.GetCoordinate(0);
                                z = P1.GetCoordinate(2);
                                P1.SetCoordinate(0,z);
                                P1.SetCoordinate(2,x);
                                x = P2.GetCoordinate(0);
                                z = P2.GetCoordinate(2);
                                P2.SetCoordinate(0,z);
                                P2.SetCoordinate(2,x);
                            }
                            this.SetVerticle(0,P0);
                            this.SetVerticle(1,P1);
                            this.SetVerticle(2,P2);
                       }
                    }
                }
            }
        }
    };

    TCanvasArrowTriangle.prototype.DrawFigure = function(scene){
        TArrow.prototype.DrawFigure.call(this,scene);
        if (typeof scene !== 'undefined' && scene !== null && scene.IsType('TCanvasScene'))
        {
            var tmp = scene.GetCorrectScale();
            if (typeof tmp !== 'undefined' && tmp !== null && IsNumeric(tmp))
            {
                if (tmp !== this.correctScale)
                {
                    this.correctScale = tmp;
                    this.CalculateVertices(this.shift_);
                }
            }
            if (this.GetLineColour() !== null)
            {
//                this.CalculateVertices();
                var coord1 = this.GetVerticle(0);
                var coord2 = this.GetVerticle(1);
                var coord3 = this.GetVerticle(2);
                if (coord1 !== null && coord2 !== null && coord2 !== null && coord1.IsType('TVector') && coord2.IsType('TVector') && coord3.IsType('TVector'))
                {
                    
                    var transformation = scene.GetTransformation();
            
                    var context = scene.GetContext();
            
                    context.beginPath();
                    result = transformation.MatrixVectorMultiplication(coord1);
                    context.moveTo(result.GetCoordinate(0),  result.GetCoordinate(1));
                    result = transformation.MatrixVectorMultiplication(coord2);
                    context.lineTo(result.GetCoordinate(0),  result.GetCoordinate(1));
                    result = transformation.MatrixVectorMultiplication(coord3);
                    context.lineTo(result.GetCoordinate(0),  result.GetCoordinate(1));
                    context.closePath();

                    var colour = this.GetLineColour();
                    if (colour !== null)
                        context.fillStyle  = '#' + colour.Get24bitColourHex();
                    else
                        context.fillStyle  = '#000000';
                    context.fill();

                }
                
            }
        }
    };

}

TCanvasArrowTriangle.prototype = new TArrow();



function TCanvasLine(){
    var type = 'TCanvasLine';
    TCanvasLine.prototype.InitConstructor = function(){
        TCanvasTransformation.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.beginArrowWidth = 0.15;
        this.beginArrowHeight = 0.10;
        this.endArrowWidth = 0.15;
        this.endArrowHeight = 0.10;
        this.beginLength = 1;
        this.endLength = 1;
            
    };
    this.InitConstructor();

    TCanvasLine.prototype.Init = function(_object){
        TCanvasTransformation.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasLine') && objM !== null)
        {            
            if (typeof _object.beginArrowWidth !== 'undefined' && _object.beginArrowWidth !== null && IsNumeric(_object.beginArrowWidth))
                this.beginArrowWidth = _object.beginArrowWidth;
            if (typeof _object.beginArrowHeight !== 'undefined' && _object.beginArrowHeight !== null && IsNumeric(_object.beginArrowHeight))
                this.beginArrowHeight = _object.beginArrowHeight;
            if (typeof _object.endArrowWidth !== 'undefined' && _object.endArrowWidth !== null && IsNumeric(_object.endArrowWidth))
                this.endArrowWidth = _object.endArrowWidth;
            if (typeof _object.endArrowHeight !== 'undefined' && _object.endArrowHeight !== null && IsNumeric(_object.endArrowHeight))
                this.endArrowHeight = _object.endArrowHeight;
            if (typeof _object.beginLength !== 'undefined' && _object.beginLength !== null && IsNumeric(_object.beginLength))
                this.beginLength = _object.beginLength;
            if (typeof _object.endLength !== 'undefined' && _object.endLength !== null && IsNumeric(_object.endLength))
                this.endLength = _object.endLength;
        }
    };
    
    TCanvasLine.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TCanvasTransformation.prototype.IsType.call(this,_type);
    };

    TCanvasLine.prototype.DrawFigure = function(scene){
        if (typeof scene !== 'undefined' && scene !== null && scene.IsType('TCanvasScene'))
        {
            var transformation = scene.GetTransformation();
            
            var i,n = this.GetNumberOfVerticles(),coord,result;
            var context = scene.GetContext();
            
/*            if (n === 2)
            {
                coord = this.GetVerticle(0);
                result = transformation.MatrixVectorMultiplication(coord);
                coord = this.GetVerticle(1);
                var result2 = transformation.MatrixVectorMultiplication(coord);
                drawArrow(context,result.GetCoordinate(0),result.GetCoordinate(1),result2.GetCoordinate(0),result2.GetCoordinate(1),1,1);
            }else*/
            {
                context.beginPath();
                for (i = 0;i < n;i++)
                {
                    coord = this.GetVerticle(i);
                    result = transformation.MatrixVectorMultiplication(coord);
                    if (i === 0)
                        context.moveTo(result.GetCoordinate(0),  result.GetCoordinate(1));
                    else
                        context.lineTo(result.GetCoordinate(0),  result.GetCoordinate(1));
                }
    //            context.closePath();
                switch(this.GetLineType())
                {
                    case 'solid':
                        context.setLineDash([]);
                        break;
                    case 'dashed1':
                        context.setLineDash([5, 5]);
                        break;
                    case 'dashed2':
                        context.setLineDash([15, 5]);
                        break;
                }
                context.lineWidth = this.GetLineWidth();
                var colour = this.GetLineColour();
                if (colour !== null)
                    context.strokeStyle = '#' + colour.Get24bitColourHex();
                else
                    context.strokeStyle = '#000000';
                context.stroke();
            }            
        }
    };


    TCanvasLine.prototype.SetArrow = function(arrow_,beginYN){
        var objM = this.GetObjectManager(),obj;
        if (objM !== null && typeof arrow_ !== 'undefined' && arrow_ !== null)
        {
            if (typeof beginYN !== 'undefined' && beginYN !== null)
            {
                var tmp;
                if (arrow_.substring(1,7) === 'Canvas')
                    tmp = arrow_;
                else
                    tmp = 'TCanvas' + arrow_.substring(1,arrow_.length);
                var arrow = objM.newObject(tmp);
                if (beginYN)
                    arrow.SetBegin(true);
                else
                    arrow.SetBegin(false);
                arrow.SetParent(this);
//                var tmp = objM.newObject('TColourRGBA');
//                tmp.SetColourRGBA(0,0,0,1);
                arrow.SetBackgroundColour(this.GetLineColour());
//                tmp = objM.newObject('TColourRGBA');
//                tmp.SetColourRGBA(0,0,0,1);
                arrow.SetLineColour(this.GetLineColour());
                arrow.SetLineWidth(1);
                arrow.CalculateVertices(this.GetLineWidth());
                if (beginYN)
                {
                    this.AddChild(arrow,0);
                    obj = this.GetChild(0);
                    if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
                    {
                        obj.SetWidth(this.beginArrowWidth);
                        obj.SetHeight(this.beginArrowHeight);
                    }
                }else
                {
                    this.AddChild(arrow,1);
                    obj = this.GetChild(1);
                    if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
                    {
                        obj.SetWidth(this.endArrowWidth);
                        obj.SetHeight(this.endArrowHeight);
                    }
                }
                
                return;
            }
        }
        
        if (beginYN)
            this.AddChild(null,0);
        else
            this.AddChild(null,1);
    };

    TCanvasLine.prototype.SetBeginArrowWidth = function(width)
    {
        if (typeof width !== 'undefined' && width !== null && IsNumeric(width))
        {
            var obj = this.GetChild(0);
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
            {
                if (width !== obj.GetWidth())
                {
                    obj.SetWidth(width);
                    obj.CalculateVertices(this.GetLineWidth());
                }
            }
            this.beginArrowWidth = parseFloat(width);
        }
    };

    TCanvasLine.prototype.GetBeginArrowWidth = function()
    {
        return this.beginArrowWidth;
    };

    TCanvasLine.prototype.SetBeginArrowHeight = function(height)
    {
        if (typeof height !== 'undefined' && height !== null && IsNumeric(height))
        {
            var obj = this.GetChild(0);
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
            {
                if (height !== obj.GetHeight())
                {
                    obj.SetHeight(height);
                    obj.CalculateVertices(this.GetLineWidth());
                }                
            }
            this.beginArrowHeight = parseFloat(height);
        }
    };

    TCanvasLine.prototype.GetBeginArrowHeight = function()
    {
        return this.beginArrowHeight;
    };

    TCanvasLine.prototype.SetEndArrowWidth = function(width)
    {
        if (typeof width !== 'undefined' && width !== null && IsNumeric(width))
        {
            var obj = this.GetChild(1);
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
            {
                if (width !== obj.GetWidth())
                {
                    obj.SetWidth(width);
                    obj.CalculateVertices(this.GetLineWidth());
                }
            }
            this.endArrowWidth = parseFloat(width);
        }
    };

    TCanvasLine.prototype.GetEndArrowWidth = function()
    {
        return this.endArrowWidth;
    };

    TCanvasLine.prototype.SetEndArrowHeight = function(height)
    {
        if (typeof height !== 'undefined' && height !== null && IsNumeric(height))
        {
            var obj = this.GetChild(1);
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
            {
                if (height !== obj.GetHeight())
                {
                    obj.SetHeight(height);
                    obj.CalculateVertices(this.GetLineWidth());
                }                
            }
            this.endArrowHeight = parseFloat(height);
        }
    };

    TCanvasLine.prototype.GetEndArrowHeight = function()
    {
        return this.endArrowHeight;
    };

    TCanvasLine.prototype.SetLineColour = function(colour){
        TCanvasTransformation.prototype.SetLineColour.call(this,colour);
        var obj = this.GetChild(0);
        if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
        {
            obj.SetLineColour(colour);
            obj.GetBackgroundColour(colour);
        }
        obj = this.GetChild(1);
        if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
        {
            obj.SetLineColour(colour);
            obj.GetBackgroundColour(colour);
        }
    };

    TCanvasLine.prototype.SetBeginLength = function(l)
    {
        if (typeof l !== 'undefined' && l !== null && IsNumeric(l))
        {
            if (l > 1)
                l = 1;
            if (l < 0)
                l = 0;
            
            this.beginLength = l;
            var obj = this.GetChild(0);
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
            {
                obj.CalculateVertices(this.GetLineWidth());
            }            
        }
    };

    TCanvasLine.prototype.SetEndLength = function(l)
    {
        if (typeof l !== 'undefined' && l !== null && IsNumeric(l))
        {
            if (l > 1)
                l = 1;
            if (l < 0)
                l = 0;

            this.endLength = l;
            var obj = this.GetChild(1);
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
            {
                obj.CalculateVertices(this.GetLineWidth());
            }
        }
    };
    
    TCanvasLine.prototype.GetVerticle = function(position)
    {
        var coord,coord2;
        if (position === 0 && this.GetNumberOfVerticles() > 1)
        {
            if (this.beginLength < 1)
            {
                coord = TCanvasTransformation.prototype.GetVerticle.call(this,0);
                coord2 = TCanvasTransformation.prototype.GetVerticle.call(this,1);
                if (coord !== null && coord2 !== null)
                {
                    coord.Subtraction(coord2);
                    coord.MultiplicationScalar(this.beginLength);
                    coord2.Addition(coord);
                    return coord2;                 
                }
            }            
        }
        if (position === this.GetNumberOfVerticles() - 1 && this.GetNumberOfVerticles() > 1)
        {
            if (this.endLength < 1)
            {
                coord = TCanvasTransformation.prototype.GetVerticle.call(this,position);
                coord2 = TCanvasTransformation.prototype.GetVerticle.call(this,position - 1);
                if (coord !== null && coord2 !== null)
                {
                    coord.Subtraction(coord2);
                    coord.MultiplicationScalar(this.endLength);
                    coord2.Addition(coord);
                    return coord2;                 
                }
            }
            
        }
        
        
        return TCanvasTransformation.prototype.GetVerticle.call(this,position);
    };

    TCanvasLine.prototype.SetVerticle = function(position,coordinates){
        TCanvasTransformation.prototype.SetVerticle.call(this,position,coordinates);
            var obj = this.GetChild(0);
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
                obj.CalculateVertices(this.GetLineWidth());
            obj = this.GetChild(1);
            if (typeof obj !== 'undefined' && obj !== null && obj.IsType('TArrow'))
                obj.CalculateVertices(this.GetLineWidth());
    };

}

TCanvasLine.prototype = new TCanvasTransformation();

function TCanvasPolygon(){
    var type = 'TCanvasPolygon';
    TCanvasPolygon.prototype.InitConstructor = function(){
        TCanvasTransformation.prototype.InitConstructor.call(this);
        
        this.SetType(type);
    };
    this.InitConstructor();

    TCanvasPolygon.prototype.Init = function(_object){
        TCanvasTransformation.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasPolygon') && objM !== null)
        {
        }
    };
    
    TCanvasPolygon.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TCanvasTransformation.prototype.IsType.call(this,_type);
    };

    TCanvasPolygon.prototype.DrawFigure = function(scene){
        if (typeof scene !== 'undefined' && scene !== null && scene.IsType('TCanvasScene'))
        {
            var transformation = scene.GetTransformation();
            
            var i,n = this.GetNumberOfVerticles(),coord,result;
            var context = scene.GetContext();
            
            context.beginPath();
            for (i = 0;i < n;i++)
            {
                coord = this.GetVerticle(i);
                result = transformation.MatrixVectorMultiplication(coord);
                if (i === 0)
                    context.moveTo(result.GetCoordinate(0),  result.GetCoordinate(1));
                else
                    context.lineTo(result.GetCoordinate(0),  result.GetCoordinate(1));
            }
            context.closePath();
            
            var colour = this.GetColour();
            if (colour !== null)
                context.fillStyle  = '#' + colour.Get24bitColourHex();
            else
                context.fillStyle  = '#000000';
            context.fill();
            
        }
    };

}

TCanvasPolygon.prototype = new TCanvasTransformation();

function TCanvasTriangle(){
    var type = 'TCanvasTriangle';
    TCanvasTriangle.prototype.InitConstructor = function(){
        TCanvasTransformation.prototype.InitConstructor.call(this);
        
        this.SetType(type);
            
    };
    this.InitConstructor();

    TCanvasTriangle.prototype.Init = function(_object){
        TCanvasTransformation.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && objM !== null && _object !== null && _object.IsType('TCanvasTriangle') && objM !== null)
        {            
        }
    };
    
    TCanvasTriangle.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TCanvasTransformation.prototype.IsType.call(this,_type);
    };

    TCanvasTriangle.prototype.DrawFigure = function(scene){
        if (typeof scene !== 'undefined' && scene !== null && scene.IsType('TCanvasScene'))
        {
            var transformation = scene.GetTransformation();
            
            var i,n = this.GetNumberOfVerticles(),coord,result;
            var context = scene.GetContext();
            
            context.beginPath();
            for (i = 0;i < n;i++)
            {
                coord = this.GetVerticle(i);
                result = transformation.MatrixVectorMultiplication(coord);
                if (i === 0)
                    context.moveTo(result.GetCoordinate(0),  result.GetCoordinate(1));
                else
                    context.lineTo(result.GetCoordinate(0),  result.GetCoordinate(1));
            }
            context.closePath();
            
            var colour = this.GetColour();
            if (colour !== null)
                context.fillStyle  = '#' + colour.Get24bitColourHex();
            else
                context.fillStyle  = '#000000';
            context.fill();
            
        }
    };
}

TCanvasTriangle.prototype = new TCanvasTransformation();

function TCanvasText(){
    var type = 'TCanvasText';
    TCanvasText.prototype.InitConstructor = function(){
        TCanvasTransformation.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.text = null;
        this.fontSize = 1;
        this.height = 0.1;
        this.colourText = null;
        this.colourSide = null;
        this.font = null;
        this.fontStyle = 'normal';
        this.fontWeight = 'normal';
        this.alignmentX = 'center';
        this.alignmentY = 'center';
        this.rotate = 0;
    };
    this.InitConstructor();

    TCanvasText.prototype.Init = function(_object){
        TCanvasTransformation.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasText') && objM !== null)
        {
            if (typeof _object.text !== 'undefined' && _object.txt !== null)
            {
                this.text = new String(_object.text);
                if (this.text !== null)
                    this.text = this.text.toString();
            }
            if (typeof _object.fontSize !== 'undefined' && _object.fontSize !== null && IsNumeric(_object.fontSize))
                this.fontSize = _object.fontSize;
            if (typeof _object.height !== 'undefined' && _object.height !== null && IsNumeric(_object.height))
                this.height = _object.height;
            if (typeof _object.colourText !== 'undefined' && _object.colourText !== null && _object.colourText.IsType('TColourRGBA'))
                this.colourText = objM.copy(_object.colourText);
            if (typeof _object.colourSide !== 'undefined' && _object.colourSide !== null && _object.colourSide.IsType('TColourRGBA'))
                this.colourSide = objM.copy(_object.colourSide);
            if (typeof _object.font !== 'undefined' && _object.font !== null)
            {
                this.font = new String(_object.font);
                if (this.font !== null)
                    this.font = this.font.toString();
            }
            if (typeof _object.fontStyle !== 'undefined' && _object.fontStyle !== null)
            {
                this.fontStyle = new String(_object.fontStyle);
                if (this.fontStyle !== null)
                    this.fontStyle = this.fontStyle.toString();
            }
            if (typeof _object.fontWeight !== 'undefined' && _object.fontWeight !== null)
            {
                this.fontWeight = new String(_object.fontWeight);
                if (this.fontWeight !== null)
                    this.fontWeight = this.fontWeight.toString();
            }
            if (typeof _object.alignmentX !== 'undefined' && _object.alignmentX !== null)
            {
                this.alignmentX = new String(_object.alignmentX);
                if (this.alignmentX !== null)
                    this.alignmentX = this.alignmentX.toString();
            }
            if (typeof _object.alignmentY !== 'undefined' && _object.alignmentY !== null)
            {
                this.alignmentY = new String(_object.alignmentY);
                if (this.alignmentY !== null)
                    this.alignmentY = this.alignmentY.toString();
            }
            if (typeof _object.rotate !== 'undefined' && _object.rotate !== null && IsNumeric(_object.rotate))
                this.rotate = _object.rotate;
        }
    };
    
    TCanvasText.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TCanvasTransformation.prototype.IsType.call(this,_type);
    };

    TCanvasText.prototype.DrawFigure = function(scene){
        if (typeof scene !== 'undefined' && scene !== null && scene.IsType('TCanvasScene'))
        {
            var transformation = scene.GetTransformation();
            
            var correct,n = this.GetNumberOfVerticles(),coord,result;
            var context = scene.GetContext();
            
            coord = this.GetVerticle(0);
            if (coord !== null && coord.IsType('TVector3DT') && typeof this.colourText !== 'undefined' && this.colourText !== null && this.colourText.IsType('TColourRGBA'))
            {
                result = transformation.MatrixVectorMultiplication(coord);
                correct = scene.GetCorrectScale()*this.fontSize;
                context.font = this.style + ' ' + correct + 'pt ' + this.font;
                context.textAlign = this.alignmentX;
                if (this.alignmentY === 'center')
                    context.textBaseline = 'middle';
                else
                    context.textBaseline = this.alignmentY;
                context.fillStyle = '#' + this.colourText.Get24bitColourHex();
                if (this.rotate !== 0)
                {
                    context.save();
                    context.translate(result.GetX(),result.GetY());
                    context.rotate(this.rotate);
                    context.translate(-result.GetX(),-result.GetY());
                    context.fillText(this.text, result.GetX(), result.GetY());
                    context.restore();
                }else
                    context.fillText(this.text, result.GetX(), result.GetY());
//                context.fillText('Hello World!', 20, 30);
            }
        }
        
    };

    TCanvasText.prototype.SetText = function(txt){
        if (typeof txt !== 'undefined' && txt !== null)
        {
            this.text = new String(txt);
            if (this.text !== null)
                this.text = this.text.toString();
        }
        if (txt === null)
            this.text = null;
    };
    
    TCanvasText.prototype.SetFontSize = function(size){
        if (typeof size !== 'undefined' && size !== null && IsNumeric(size))
            this.fontSize = size;
    };

    TCanvasText.prototype.SetHeight = function(height_){
        if (typeof height_ !== 'undefined' && height_ !== null && IsNumeric(height_))
            this.height = height_;
    };

    TCanvasText.prototype.SetColourText = function(colour){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof colour !== 'undefined' && colour !== null)
            this.colourText = objM.copy(colour);        
    };

    TCanvasText.prototype.SetSideColourText = function(colour){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof colour !== 'undefined' && colour !== null)
            this.colourSide = objM.copy(colour);        
    };

    TCanvasText.prototype.SetFont = function(font_){
        if (typeof font_ !== 'undefined' && font_ !== null)
        {
            this.font = new String(font_);
            if (this.font !== null)
                this.font = this.font.toString();
        }
        if (font_ === null)
            this.font = null;
    };

    TCanvasText.prototype.SetFontStyle = function(style_){
        if (typeof style_ !== 'undefined' && style_ !== null)
        {
            this.style = new String(style_);
            if (this.style !== null)
                this.style = this.style.toString();
        }
    };

    TCanvasText.prototype.SetFontWeight = function(weight_){
        if (typeof weight_ !== 'undefined' && weight_ !== null)
        {
            this.weight = new String(weight_);
            if (this.weight !== null)
                this.weight = this.weight.toString();
        }
    };

    TCanvasText.prototype.SetAlignX = function(align){
        if (typeof align !== 'undefined' && align !== null)
        {
            this.alignmentX = new String(align);
            if (this.alignmentX !== null)
                this.alignmentX = this.alignmentX.toString();
        }
    };

    TCanvasText.prototype.SetAlignY = function(align){
        if (typeof align !== 'undefined' && align !== null)
        {
            this.alignmentY = new String(align);
            if (this.alignmentY !== null)
                this.alignmentY = this.alignmentY.toString();
        }
    };

    TCanvasText.prototype.SetRotate = function(r){
        if (typeof r !== 'undefined' && r !== null && IsNumeric(r))
            this.rotate = r;
    };


}

TCanvasText.prototype = new TCanvasTransformation();


function TCanvasTableShow(){
    var type = 'TCanvasTableShow';
    TCanvasTableShow.prototype.InitConstructor = function(){
        TCanvasTransformation.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.table = null;
            
    };
    this.InitConstructor();

    TCanvasTableShow.prototype.Init = function(_object){
        TCanvasTransformation.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && objM !== null && _object !== null && _object.IsType('TCanvasTableShow') && objM !== null)
        {            
            if (typeof _object.table !== 'undefined' && _object.table !== null && _object.table.IsType('TTableShow'))
                this.table = _object.table;
        }
    };
    
    TCanvasTableShow.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TCanvasTransformation.prototype.IsType.call(this,_type);
    };

    TCanvasTableShow.prototype.DrawFigure = function(scene){
        if (typeof scene !== 'undefined' && scene !== null && scene.IsType('TCanvasScene'))
        {
            var transformation = scene.GetTransformation();
            
            var i,n = this.GetNumberOfVerticles(),coord,result;
            var context = scene.GetContext();
            
            if (n > 0 && this.table !== null)
            {
                coord = this.GetVerticle(0);
                result = transformation.MatrixVectorMultiplication(coord);
                var coord1 = transformation.CreateVector();
                var coord2 = transformation.CreateVector();
                var coord3 = transformation.CreateVector();
                var colour;
                var w = this.table.GetWidthCell();
                var h = this.table.GetHeightCell();
                var tab = this.table.GetTable();
                var min_ = this.table.GetMinValue();
                var max_ = this.table.GetMaxValue();
                var lineWidth = this.table.GetLineWidth();
                var alignX = this.table.GetAlignX();
                var alignY = this.table.GetAlignY();
                var alignTextX = this.table.GetAlignTextX();
                var alignTextY = this.table.GetAlignTextY();
                var sizeText = this.table.GetTextSize();
                if (sizeText === null || sizeText <= 0)
                    sizeText = 1;
                var fontStyle = this.table.GetFontStyle();
                var font = this.table.GetFont();
                var hexYN = this.table.GetHex();
                var hexDigit = this.table.GetHexDigit();
                if (hexDigit === null)
                    hexDigit = 2;
                var colour24bit = false;
                if (this.table.GetColourProfile() === 'colour24bit')
                {
                    hexYN = true;
                    colour24bit = true;
                    hexDigit = 6;
                }
                var weigth;
                var positionX = 0,positionY = 0;//left,top
                if (w !== null && w > 0 && h !== null && h > 0 && tab !== null)
                {
                    n = tab.length;
                    if (coord1 !== null && coord2 !== null)
                    {
                        coord1.SetZeros(coord1.GetN());
                        coord2.SetCoordinate(0,w);
                        coord2.SetCoordinate(1,h);
                        var tmp1 = transformation.MatrixVectorMultiplication(coord1);
                        var tmp2 = transformation.MatrixVectorMultiplication(coord2);
                        tmp2.Subtraction(tmp1);
                        w = Math.abs(tmp2.GetCoordinate(0));
                        h = Math.abs(tmp2.GetCoordinate(1));
                    }
                    if (coord1 !== null && coord3 !== null)
                    {
                        coord1.SetZeros(coord1.GetN());
                        coord3.SetCoordinate(0,sizeText);
                        var tmp1 = transformation.MatrixVectorMultiplication(coord1);
                        var tmp2 = transformation.MatrixVectorMultiplication(coord3);
                        tmp2.Subtraction(tmp1);   
                        sizeText = Math.abs(tmp2.GetCoordinate(0));
                    }
                    if (alignX !== null)
                    {
                        switch (alignX)
                        {
                            case 'left':
                                positionX = 0;
                                break;
                            case 'right':
                                if (n > 0)
                                    positionX = -w*tab[0].length;
                                break;
                            case 'center':
                                if (n > 0)
                                    positionX = -w*tab[0].length/2;
                                break;
                        }
                    }
                    if (alignY !== null)
                    {
                        switch (alignY)
                        {
                            case 'top':
                                positionY = 0;
                                break;
                            case 'bottom':
                                positionY = -h*n;
                                break;
                            case 'center':
                                positionY = -h*n/2;
                                break;
                        }
                    }
                    var i,j;
                    if (colour24bit)
                    {
                        for (i = 0;i < n;i++)
                            for (j = 0;j < tab[i].length;j++)
                            {
                                context.beginPath();
                                context.moveTo(positionX + result.GetCoordinate(0) + j*w,  positionY + result.GetCoordinate(1) + i*h);
                                context.lineTo(positionX + result.GetCoordinate(0) + (j + 1)*w,  positionY + result.GetCoordinate(1) + i*h);
                                context.lineTo(positionX + result.GetCoordinate(0) + (j + 1)*w,  positionY + result.GetCoordinate(1) + (i + 1)*h);
                                context.lineTo(positionX + result.GetCoordinate(0) + j*w,  positionY + result.GetCoordinate(1) + (i + 1)*h);
                                context.closePath();
                                context.fillStyle  = '#' + Numeric2Hex(tab[i][j],hexDigit);
                                context.fill();
                            }

                    }else
                    {
                        if (min_ !== null && max_ !== null)
                        {
                            var map = this.table.GetColourMap();
                            var nMap = 0,k,YN,colour2;
                            if (typeof map !== 'undefined' && map !== null)
                                nMap = map.length;
                            for (i = 0;i < n;i++)
                                for (j = 0;j < tab[i].length;j++)
                                {
                                    weigth = (tab[i][j] - min_)/(max_ - min_);
                                    colour = this.table.GetColourBackground(weigth);
                                    if (colour !== null)
                                    {
                                        YN = true;
                                        context.beginPath();
                                        context.moveTo(positionX + result.GetCoordinate(0) + j*w,  positionY + result.GetCoordinate(1) + i*h);
                                        context.lineTo(positionX + result.GetCoordinate(0) + (j + 1)*w,  positionY + result.GetCoordinate(1) + i*h);
                                        context.lineTo(positionX + result.GetCoordinate(0) + (j + 1)*w,  positionY + result.GetCoordinate(1) + (i + 1)*h);
                                        context.lineTo(positionX + result.GetCoordinate(0) + j*w,  positionY + result.GetCoordinate(1) + (i + 1)*h);
                                        context.closePath();
                                        if (nMap > 0)
                                        {
                                            for (k = 0;k < nMap;k++)
                                            {
                                                if (this.table.GetColourMapMin(k) >= tab[i][j] && this.table.GetColourMapMax(k) <= tab[i][j])
                                                {
                                                    colour2 = this.table.GetColourMapElement(k);
                                                    if (colour2 !== null)
                                                    {
                                                        YN = false;
                                                        context.fillStyle  = '#' + colour2.Get24bitColourHex();
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                        if (YN)
                                            context.fillStyle  = '#' + colour.Get24bitColourHex();
                                        context.fill();
                                    }
                                }
                        }
                    }
                    if (lineWidth !== null && lineWidth > 0)
                    {
                        for (i = 0;i < n;i++)
                            for (j = 0;j < tab[i].length;j++)
                            {
                                context.beginPath();
                                context.moveTo(positionX + result.GetCoordinate(0) + j*w,  positionY + result.GetCoordinate(1) + i*h);
                                context.lineTo(positionX + result.GetCoordinate(0) + (j + 1)*w,  positionY + result.GetCoordinate(1) + i*h);
                                context.lineTo(positionX + result.GetCoordinate(0) + (j + 1)*w,  positionY + result.GetCoordinate(1) + (i + 1)*h);
                                context.lineTo(positionX + result.GetCoordinate(0) + j*w,  positionY + result.GetCoordinate(1) + (i + 1)*h);
                                context.closePath();
                                context.strokeStyle  = '#000000';
                                context.stroke();
                            }
                    }
                    for (i = 0;i < n;i++)
                        for (j = 0;j < tab[i].length;j++)
                        {
                            if (min_ !== null && max_ !== null)
                            {
                                weigth = (tab[i][j] - min_)/(max_ - min_);
                                colour = this.table.GetColourText(weigth);
                                if (colour !== null)
                                    context.fillStyle = '#' + colour.Get24bitColourHex();
                                else
                                    context.fillStyle = '#000000';
                            }
                            else
                                context.fillStyle = '#000000';
                            
                            if (alignTextX !== null)
                                context.textAlign = alignTextX;
                            if (alignTextY !== null)
                            {
                                if (alignTextY === 'center')
                                    context.textBaseline = 'middle';
                                else
                                    context.textBaseline = alignTextY;
                            }

                            if (sizeText !== null && sizeText > 0)
                            {
                                var txt = '';
                                if (fontStyle !== null)
                                    txt = txt + fontStyle + ' ';
                                txt = txt + sizeText + 'pt ';
                                if (font !== null)
                                    txt = txt + font;
                                else
                                    txt = txt + 'sans-serif';
                                context.font = txt; //this.style + ' ' + correct + 'pt ' + this.font;
                            }
                            if (hexYN)
                            {
                                if (colour24bit)
                                {
                                    var r = Numeric2Hex((tab[i][j] & 16711680)/(256*256),2);
                                    var g = Numeric2Hex((tab[i][j] & 65280)/(256),2);
                                    var b = Numeric2Hex((tab[i][j] & 255),2);
                                    context.fillStyle = 'red';
                                    context.fillText(r, positionX + result.GetX() + j*w + w/2 - context.measureText('FF').width, positionY + result.GetY() + i*h + h/2);                                    
                                    context.fillStyle = 'green';
                                    context.fillText(g, positionX + result.GetX() + j*w + w/2, positionY + result.GetY() + i*h + h/2);                                    
                                    context.fillStyle = 'blue';
                                    context.fillText(b, positionX + result.GetX() + j*w + w/2 + context.measureText('FF').width, positionY + result.GetY() + i*h + h/2);                                    
                                }else
                                    context.fillText(Numeric2Hex(tab[i][j],hexDigit), positionX + result.GetX() + j*w + w/2, positionY + result.GetY() + i*h + h/2);
                            }else
                                context.fillText(tab[i][j], positionX + result.GetX() + j*w + w/2, positionY + result.GetY() + i*h + h/2);
                        }
                }
            }
        }
    };


    TCanvasTableShow.prototype.SetTable = function(table_){
        //TODO: Implement Me 
        if (typeof table_!== 'undefined' && table_ !== null && table_.IsType('TTableShow'))
        {
            this.table = table_;
        }
    };

}

TCanvasTableShow.prototype = new TCanvasTransformation();

function TCanvasLineChart(){
    var type = 'TCanvasLineChart';
    TCanvasLineChart.prototype.InitConstructor = function(){
        TLineChart.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.chartType = 'Canvas';
    };
    this.InitConstructor();

    TCanvasLineChart.prototype.Init = function(_object){
        TLineChart.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasLineChart') && objM !== null)
        {
        }
    };
    
    TCanvasLineChart.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TLineChart.prototype.IsType.call(this,_type);
    };

}

TCanvasLineChart.prototype = new TLineChart();

function TCanvasPointChart(){
    var type = 'TCanvasPointChart';
    TCanvasPointChart.prototype.InitConstructor = function(){
        TPointChart.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.chartType = 'Canvas';
    };
    this.InitConstructor();

    TCanvasPointChart.prototype.Init = function(_object){
        TPointChart.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasPointChart') && objM !== null)
        {
        }
    };
    
    TCanvasPointChart.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TPointChart.prototype.IsType.call(this,_type);
    };

}

TCanvasPointChart.prototype = new TPointChart();

function TCanvasBarChart(){
    var type = 'TCanvasBarChart';
    TCanvasBarChart.prototype.InitConstructor = function(){
        TBarChart.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.chartType = 'Canvas';
    };
    this.InitConstructor();

    TCanvasBarChart.prototype.Init = function(_object){
        TBarChart.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasPointChart') && objM !== null)
        {
        }
    };
    
    TCanvasBarChart.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TBarChart.prototype.IsType.call(this,_type);
    };

}

TCanvasBarChart.prototype = new TBarChart();


function TCanvasChartLegend(){
    var type = 'TCanvasPointChart';
    TCanvasChartLegend.prototype.InitConstructor = function(){
        TChartLegend.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.chartType = 'Canvas';
        this.textClass = 'TCanvasText';
    };
    this.InitConstructor();

    TCanvasChartLegend.prototype.Init = function(_object){
        TChartLegend.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasChartLegend') && objM !== null)
        {
        }
    };
    
    TCanvasChartLegend.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TChartLegend.prototype.IsType.call(this,_type);
    };

}

TCanvasChartLegend.prototype = new TChartLegend();


function TCanvasChart(){
    var type = 'TCanvasChart';
    TCanvasChart.prototype.InitConstructor = function(){
        TChart.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.lineClass = 'TCanvasLine';
        this.textClass = 'TCanvasText';       
    };
    this.InitConstructor();

    TCanvasChart.prototype.Init = function(_object){
        TChart.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && _object !== null && _object.IsType('TCanvasChart') && objM !== null)
        {
        }
    };
    
    TCanvasChart.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TChart.prototype.IsType.call(this,_type);
    };


}

TCanvasChart.prototype = new TChart();


function TCanvasCircle(){
    var type = 'TCanvasCircle';
    TCanvasCircle.prototype.InitConstructor = function(){
        TCanvasTransformation.prototype.InitConstructor.call(this);
        
        this.SetType(type);
        this.radius = 1;
            
    };
    this.InitConstructor();

    TCanvasCircle.prototype.Init = function(_object){
        TCanvasTransformation.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (typeof _object !== 'undefined' && objM !== null && _object !== null && _object.IsType('TCanvasCircle') && objM !== null)
        {            
            if (typeof _object.radius !== 'undefined' && _object.radius !== null && IsNumeric(_object.radius))
                this.radius = _object.radius;
        }
    };
    
    TCanvasCircle.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TCanvasTransformation.prototype.IsType.call(this,_type);
    };

    TCanvasCircle.prototype.DrawFigure = function(scene){
        if (typeof scene !== 'undefined' && scene !== null && scene.IsType('TCanvasScene'))
        {
            var transformation = scene.GetTransformation();
            
            var i,n = this.GetNumberOfVerticles(),coord,result;
            var context = scene.GetContext();
            var coord1 = transformation.CreateVector();
            var coord2 = transformation.CreateVector();
            coord2.SetCoordinate(0,this.radius);
            var result1 = transformation.MatrixVectorMultiplication(coord1);
            var result2 = transformation.MatrixVectorMultiplication(coord2);
            result2.Subtraction(result1);
            
            context.beginPath();
            if (n > 0)
            {
                coord = this.GetVerticle(0);
                result = transformation.MatrixVectorMultiplication(coord);
                context.arc(result.GetCoordinate(0),  result.GetCoordinate(1),result2.Norm(),0,2*Math.PI);
            }
            context.closePath();
            
            var colour = this.GetColour();
            if (colour !== null)
	    {
		if (colour.GetColourA() !== 0)
		{
		    context.fillStyle  = '#' + colour.Get24bitColourWidthAlphaHex();
		    context.fill();
		}
            }else
	    {
                context.fillStyle  = '#000000';
            	context.fill();
	    }
            var colourLine = this.GetLineColour();
            if (colourLine !== null)
	    {
                context.strokeStyle  = '#' + colourLine.Get24bitColourWidthAlphaHex();
		context.lineWidth = this.GetLineWidth();
		context.stroke();
            }	    
            
        }
    };

    TCanvasCircle.prototype.SetRadius = function(r){
        if (typeof r !== 'undefined' && r !== null && IsNumeric(r))
            this.radius = r;
    };

}

TCanvasCircle.prototype = new TCanvasTransformation();



function TCanvasScene(){
    var type = 'TCanvasScene';
    TCanvasScene.prototype.InitConstructor = function(){
        TDrawContext.prototype.InitConstructor.call(this);
        this.type_ = '';
        this.imageCatalog = null;
        this.synchronization = null;
        this.context = null;
        this.SetType(type);
    };
    this.InitConstructor();

    TCanvasScene.prototype.InitConstructor2 = function(){
        TDrawContext.prototype.InitConstructor2.call(this);
        
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
//            this.imageCatalog = RandomString(15);
        }
    };
    
    TCanvasScene.prototype.Init = function(_object){
        TDrawContext.prototype.Init.call(this,_object);
        var objM = this.GetObjectManager();
        if (objM !== null)
        {
            if (typeof _object.type_ !== 'undefined' && _object.type_ !== null)
            {
                this.type_ = new String(_object.type_);
                if (this.type_ !== null)
                    this.type_ = this.type_.toString();
            }
            if (typeof _object.imageCatalog !== 'undefined' && _object.imageCatalog !== null)
            {
                this.imageCatalog = new String(_object.imageCatalog);
                if (this.imageCatalog !== null)
                    this.imageCatalog = this.imageCatalog.toString();
            }
            if (typeof _object.context !== 'undefined' && _object.context !== null)
                this.context = _object.context;
       }
    };

    TCanvasScene.prototype.IsType = function(_type){
        //TODO: Implement Me 
        if (typeof _type !== 'undefined' && _type !== null)
        {
            if (_type === type)
                return true;
        }
        return TDrawContext.prototype.IsType.call(this,_type);
    };

    TCanvasScene.prototype.Begin = function(type_){
        if (typeof type_ !== 'undefined' && type_ !== null)
        {
            this.type_ = new String(type_);
            if (this.type_ !== null)
                this.type_ = this.type_.toString();
            this.geometryObject = new THREE.Geometry(); 
        }
    };

    TCanvasScene.prototype.End = function(){
        if (typeof this.scene !== 'undefined' && this.scene !== null && typeof this.geometryObject !== 'undefined' && this.geometryObject !== null)
        {
            switch(this.type_)
            {
                case 'triangle':
                    this.geometryObject.faces.push(new THREE.Face3(0, 1, 2)); 
//                    this.scene.add(this.geometryObject); 

                 var triangleMaterial = new THREE.MeshBasicMaterial({ 
                     color:0xFFFFFF, 
                     side:THREE.DoubleSide 
                 });                                         

                                        
                 var triangleMesh = new THREE.Mesh(this.geometryObject, triangleMaterial); 
                 triangleMesh.position.set(0,0, 0); 
                 this.scene.add(triangleMesh);         
                    
                    
                    break;
            }
        }
    };
    
    TCanvasScene.prototype.Vertex2D = function(x,y){
        if (typeof this.scene !== 'undefined' && this.scene !== null)
        {
            var objM = this.GetObjectManager();
            if ( objM !== null)
            {
                var vec = objM.newObject('TVector2DT');
                vec.SetCoordinates(x,y);
                this.Vertex(vec);
            }
        }
    };

    TCanvasScene.prototype.Vertex3D = function(x,y,z){
        if (typeof this.scene !== 'undefined' && this.scene !== null)
        {
            var objM = this.GetObjectManager();
            if ( objM !== null)
            {
                var vec = objM.newObject('TVector3DT');
                vec.SetCoordinates(x,y,z);
                this.Vertex(vec);
            }
        }
    };


    TCanvasScene.prototype.Vertex = function(coordinates){
        if (typeof this.scene !== 'undefined' && this.scene !== null && typeof this.geometryObject !== 'undefined' && this.geometryObject !== null && typeof this.transformation !== 'undefined' && this.transformation !== null && this.transformation.IsType('TMatrixTransformation'))
        {
            if (typeof coordinates !== 'undefined' && coordinates !== null && coordinates.IsType('TVector'))
            {
                var result = this.transformation.MatrixVectorMultiplication(coordinates);
                if (result !== null)
                {
                    this.geometryObject.vertices.push(new THREE.Vector3( result.GetCoordinate(0),  result.GetCoordinate(1), result.GetCoordinate(2))); 
                }
            }
        }
    };

    TCanvasScene.prototype.GetImageCatalog = function(){
        var tmp = new String(this.imageCatalog);
        if (tmp !== null)
            return tmp.toString();
        return null;
    };

    TCanvasScene.prototype.SetImageCatalog = function(catalog){
        if (typeof catalog !== 'undefined' && catalog !== null)
        {
            this.imageCatalog = new String(catalog);
            if (this.imageCatalog !== null)
                this.imageCatalog = this.imageCatalog.toString();
        }
    };
    
    TCanvasScene.prototype.ResetSynchronization = function(){
        var objM = this.GetObjectManager();
        if (objM !== null)
            this.synchronization = objM.newObject('TSynchronization');
    };
    
    TCanvasScene.prototype.IncSynchronization = function(){
        if (typeof this.synchronization !== 'undefined' && this.synchronization !== null && this.synchronization.IsType('TSynchronization'))
            this.synchronization.IncCounter();
    };
    
    TCanvasScene.prototype.DecSynchronization = function(){
        if (typeof this.synchronization !== 'undefined' && this.synchronization !== null && this.synchronization.IsType('TSynchronization'))
            return this.synchronization.DecCounter();
        return false;
    };

    TCanvasScene.prototype.SetSynchronizationFunction = function(fun){
        if (typeof this.synchronization !== 'undefined' && this.synchronization !== null && this.synchronization.IsType('TSynchronization'))
            this.synchronization.SetFun(fun);
    };

    TCanvasScene.prototype.SetContext = function(ctx){
        if (typeof ctx !== 'undefined' && ctx !== null)
        {
            this.context = ctx;
        }
        if (ctx === null)
            this.context = null;
    };

    TCanvasScene.prototype.GetContext = function(){
        return this.context;
    };


    TCanvasScene.prototype.SetSynchronization = function(synchro){
        if (typeof synchro !== 'undefined' && synchro !== null && synchro.IsType('TSynchronization'))
            this.synchronization = synchro;
        if (synchro === null)
            this.synchronization = null;
    };

    TCanvasScene.prototype.GetSynchronization = function(){
        return this.synchronization;
    };

    TCanvasScene.prototype.DrawTableImage = function(coordinates,img){
        var objM = this.GetObjectManager();
        if (objM !== null && typeof this.context !== 'undefined' && this.context !== null && typeof coordinates !== 'undefined' && coordinates !== null && coordinates.IsType('TVector') && typeof img !== 'undefined' && img !== null)
        {
            if (img.length > 0)
            {
                var i,j,k,tmp;
                var imgData=this.context.createImageData(img[0].length,img.length);
                var n = imgData.data.length/(imgData.height*imgData.width);
                tmp = n*imgData.width;
                for (i = 0;i < imgData.height;i++)
                {
                    for (j = 0;j < imgData.width;j++)
                    {
                        for (k = 0;k < n;k++)
                            imgData.data[k + j*n + i*tmp] = img[i][j][k];
                    }
                }
//                var img2 = new Image();
//                img2.data = imgData.data;
                var vec1 = objM.newObject('TVector3DT');
                vec1.SetCoordinates(imgData.width,imgData.height,0);
                var vec2 = objM.newObject('TVector3DT');
                vec2.SetCoordinates(0,0,0);
                var result = this.transformation.MatrixVectorMultiplication(coordinates);
                var result2 = this.transformation.MatrixVectorMultiplication(vec1);
                var result3 = this.transformation.MatrixVectorMultiplication(vec2);
                result3.Subtraction(result2);
                this.context.putImageData(imgData,result.GetX() + result3.GetX()/2,result.GetY());
//                  this.context.drawImage(img2,coordinates.GetX(),coordinates.GetY());
              }
        }
    };

}

TCanvasScene.prototype = new TDrawContext();
