AuthorStrokeTypes = {
    Solid:0,
    Dashed:1
};
AuthorDrawingTypes = {
    Line:0,
    Rectangle:1,
    Ellipse:2,
    Sector:3
};
LineTypes = {
    LeftToRight:0,
    RightToLeft:1,
    TopToBottom:2,
    BottomToTop:3,
    TLToBR:4,
    BRToTL:5,
    TRToBL:6,
    BLToTR:7
};
Ext.define('DrawingClass15', {
    extend:'DisplayableAction',
    constructor:function (cfgXML, o, actionSequence) {
        this.StrokeWidth = 0;
        this.StrokeType = AuthorStrokeTypes.Solid;
        this.StrokeColor = "#000000";
        this.IsFill = true;
        this.FillOpacity = 100;
        this.FillColor = "#FFFFFF";
        this.DrawType = AuthorDrawingTypes.Rectangle;
        this.LineType = LineTypes.LeftToRight;
        this.LineStartX = 0;
        this.LineStartY = 0;
        this.LineEndX = 0;
        this.LineEndY = 0;
        this.VLineStartX = null;
        this.VLineStartY = null;
        this.VLineEndX = null;
        this.VLineEndY = null;
        this.RectX = 0;
        this.RectY = 0;
        this.RectWidth = 0;
        this.RectHeight = 0;
        this.VRectX = null;
        this.VRectY = null;
        this.VRectWidth = null;
        this.VRectHeight = null;
        this.CenterX = 0;
        this.CenterY = 0;
        this.ERadiusX = 0;
        this.ERadiusY = 0;
        this.VCenterX = null;
        this.VCenterY = null;
        this.VRadiusX = null;
        this.VRadiusY = null;
        this.StartAngle = 0;
        this.EndAngle = 0;
        this.VStartAngle = null;
        this.VEndAngle = null;
        this.Shape = null;
        this.callParent([ cfgXML, o, actionSequence]);

        this.StrokeWidth = XmlHelper.getInteger(cfgXML, "strokeWidth");
        this.StrokeType = XmlHelper.getInteger(cfgXML, "strokeType");
        this.StrokeColor = XmlHelper.getString(cfgXML, "strokeColor");
        this.IsFill = XmlHelper.getBoolean(cfgXML, "isFill");
        this.FillOpacity = XmlHelper.getInteger(cfgXML, "fillOpacity");
        this.FillColor = XmlHelper.getString(cfgXML, "fillColor");
        this.DrawType = XmlHelper.getInteger(cfgXML, "drawType");
        this.LineType = XmlHelper.getInteger(cfgXML, "lineType");
        this.LineStartX = XmlHelper.getInteger(cfgXML, "lineStartX");
        this.LineStartY = XmlHelper.getInteger(cfgXML, "lineStartY");
        this.LineEndX = XmlHelper.getInteger(cfgXML, "lineEndX");
        this.LineEndY = XmlHelper.getInteger(cfgXML, "lineEndY");
        this.VLineStartX = XmlHelper.tryGetValue(cfgXML, "vLineStartX", TryGetValueOption.Normal, null);
        this.VLineStartY = XmlHelper.tryGetValue(cfgXML, "vLineStartY", TryGetValueOption.Normal, null);
        this.VLineEndX = XmlHelper.tryGetValue(cfgXML, "vLineEndX", TryGetValueOption.Normal, null);
        this.VLineEndY = XmlHelper.tryGetValue(cfgXML, "vLineEndY", TryGetValueOption.Normal, null);

        this.RectX = XmlHelper.getInteger(cfgXML, "rectX");
        this.RectY = XmlHelper.getInteger(cfgXML, "rectY");
        this.RectWidth = XmlHelper.getInteger(cfgXML, "rectWidth");
        this.RectHeight = XmlHelper.getInteger(cfgXML, "rectHeight");
        this.VRectX = XmlHelper.tryGetValue(cfgXML, "vRectX", TryGetValueOption.Normal, null);
        this.VRectY = XmlHelper.tryGetValue(cfgXML, "vRectY", TryGetValueOption.Normal, null);
        this.VRectWidth = XmlHelper.tryGetValue(cfgXML, "vRectWidth", TryGetValueOption.Normal, null);
        this.VRectHeight = XmlHelper.tryGetValue(cfgXML, "vRectHeight", TryGetValueOption.Normal, null);


        this.CenterX = XmlHelper.getInteger(cfgXML, "centerX");
        this.CenterY = XmlHelper.getInteger(cfgXML, "centerY");
        this.ERadiusX = XmlHelper.getInteger(cfgXML, "eRadiusX");
        this.ERadiusY = XmlHelper.getInteger(cfgXML, "eRadiusY");
        this.VCenterX = XmlHelper.tryGetValue(cfgXML, "vCenterX", TryGetValueOption.Normal, null);
        this.VCenterY = XmlHelper.tryGetValue(cfgXML, "vCenterY", TryGetValueOption.Normal, null);
        this.VRadiusX = XmlHelper.tryGetValue(cfgXML, "vRadiusX", TryGetValueOption.Normal, null);
        this.VRadiusY = XmlHelper.tryGetValue(cfgXML, "vRadiusY", TryGetValueOption.Normal, null);

        this.StartAngle = XmlHelper.getInteger(cfgXML, "startAngle");
        this.EndAngle = XmlHelper.getInteger(cfgXML, "endAngle");
        this.VStartAngle = XmlHelper.tryGetValue(cfgXML, "vStartAngle", TryGetValueOption.Normal, null);
        this.VEndAngle = XmlHelper.tryGetValue(cfgXML, "vEndAngle", TryGetValueOption.Normal, null);

    },

    calculateRequiredSize:function () {
        var left, top, width, height;
        var lsx, lsy, lex, ley, rx, ry, rw, rh, cx, cy, erx, ery;
        lsx = Author.VariableManager.getNumericVariableValueByName(this.VLineStartX, this.LineStartX);
        lsy = Author.VariableManager.getNumericVariableValueByName(this.VLineStartY, this.LineStartY);
        lex = Author.VariableManager.getNumericVariableValueByName(this.VLineEndX, this.LineEndX);
        ley = Author.VariableManager.getNumericVariableValueByName(this.VLineEndY, this.LineEndY);
        rx = Author.VariableManager.getNumericVariableValueByName(this.VRectX, this.RectX);
        ry = Author.VariableManager.getNumericVariableValueByName(this.VRectY, this.RectY);
        rw = Author.VariableManager.getNumericVariableValueByName(this.VRectWidth, this.RectWidth);
        rh = Author.VariableManager.getNumericVariableValueByName(this.VRectHeight, this.RectHeight);
        cx = Author.VariableManager.getNumericVariableValueByName(this.VCenterX, this.CenterX);
        cy = Author.VariableManager.getNumericVariableValueByName(this.VCenterY, this.CenterY);
        erx = Author.VariableManager.getNumericVariableValueByName(this.VRadiusX, this.ERadiusX);
        ery = Author.VariableManager.getNumericVariableValueByName(this.VRadiusY, this.ERadiusY);

        switch (this.DrawType) {
            case AuthorDrawingTypes.Line:
                left = Math.min(lsx, lex);
                top = Math.min(lsy, ley);
                width = Math.max(Math.abs(lex - lsx), this.StrokeWidth);

                height = Math.max(Math.abs(ley - lsy), this.StrokeWidth);
              //  Author.log(Ext.String.format("lsx:{0},lex:{1},lsy:{2},ley:{3}", lsx, lex, lsy, ley))        ;
                break;
            case AuthorDrawingTypes.Rectangle:
                left = rx;
                top = ry;
                width = rw;
                height = rh;
                break;
            case AuthorDrawingTypes.Ellipse:
            case AuthorDrawingTypes.Sector:
                left = cx - erx;
                top = cy - ery;
                width = erx * 2;
                height = ery * 2;
                break;
        }
        this.Left = left;
        this.Top = top;
        this.Width = width;
        this.Height = height;
         //  Author.log(Ext.String.format("L:{0},T:{1},W:{2},H:{3}", left, top, width, height));
    },
    initializeDC:function (bg) {
        this.calculateRequiredSize();
        this.initializeDisplayComponent(bg);
        //this.ContentContainer.setStyle("background-color", "green");

    },
    drawShape:function () {
        if (typeof (this.BgRaphael) == 'undefined') {
            Author.log('Raphael is not supported by this browser.');
            return;
        }
        switch (this.DrawType) {
            case AuthorDrawingTypes.Line:
                var pathData = "M{0},{1}L{2},{3}";
                switch (this.LineType) {
                    case LineTypes.RightToLeft:
                    case LineTypes.LeftToRight:
                        this.Shape = this.BgRaphael.path(Ext.String.format(pathData, 0, this.Height / 2, this.Width, this.Height / 2));
                        break;
                    case LineTypes.TopToBottom:
                    case LineTypes.BottomToTop:
                        this.Shape = this.BgRaphael.path(Ext.String.format(pathData, this.Width / 2, 0, this.Width / 2, this.Height));
                        break;
                    case LineTypes.TLToBR:
                    case LineTypes.BRToTL:
                        this.Shape = this.BgRaphael.path(Ext.String.format(pathData, 0, 0, this.Width, this.Height));
                        break;
                    case LineTypes.BLToTR:
                    case LineTypes.TRToBL:
                        this.Shape = this.BgRaphael.path(Ext.String.format(pathData, this.Width, 0, 0, this.Height));
                        break;
                }
                break;
            case AuthorDrawingTypes.Rectangle:
                this.Shape = this.BgRaphael.rect(this.StrokeWidth, this.StrokeWidth, this.Width - this.StrokeWidth * 2, this.Height - this.StrokeWidth * 2);
                break;
            case AuthorDrawingTypes.Ellipse:
                this.Shape = this.BgRaphael.ellipse(this.Width / 2, this.Height / 2, this.Width / 2 - this.StrokeWidth, this.Height / 2 - this.StrokeWidth);
                break;
            case AuthorDrawingTypes.Sector:
                //get SA and EA
                var sa, ea;
                sa = Author.VariableManager.getNumericVariableValueByName(this.VStartAngle, this.StartAngle);
                ea = Author.VariableManager.getNumericVariableValueByName(this.VEndAngle, this.EndAngle);
                this.Shape = this.drawSector(this.Width / 2, this.Height / 2, this.Width / 2 - this.StrokeWidth, this.Height / 2 - this.StrokeWidth, sa, ea);
                break;
        }
        this.Shape.attr({
            'stroke-width':this.StrokeWidth,
            'stroke-dasharray':this.StrokeType == AuthorStrokeTypes.Solid ? "" : "-",
            stroke:this.StrokeColor

        });
        if (this.IsFill) {
            this.Shape.attr({
                fill:this.FillColor,
                'fill-opacity':this.FillOpacity / 100
            });
        }

    },
    drawSector:function (cx, cy, rx, ry, startAngle, endAngle) {
        var rad = Math.PI / 180;
        var x1 = cx + rx * Math.cos(-startAngle * rad);
        var x2 = cx + rx * Math.cos(-endAngle * rad);
        var y1 = cy + ry * Math.sin(-startAngle * rad);
        var y2 = cy + ry * Math.sin(-endAngle * rad);
        var shape = this.BgRaphael.path(["M", cx, cy, "L", x1, y1, "A", rx, ry, 0, +(endAngle - startAngle > 180), 0, x2, y2, "z"]);
        return shape;
    },
    processAction:function (bg) {
        if (this.IsChangeAction) {
            Author.DisplayManager.changeAction(this);
        }
        this.initializeDC(bg);
        this.drawShape();
        this.setInitialVisibility();
        this.applyEffect();
        return {MoveOn:true, Interval:0};
    }

});


