예제 #1
0
        /// <summary>
        /// It creates a new element copying all attributes from eleToClone; the new
        /// element is inserted under the parent element provided.
        /// </summary>
        /// <param name="parent">Parent element. If null the element is added under the root.</param>
        /// <param name="eleToClone">Element to be cloned</param>
        /// <returns></returns>
        public SvgElement CloneElement(SvgElement parent, SvgElement eleToClone)
        {
            // calculate unique id
            string sOldId = eleToClone.GetAttributeStringValue(SvgAttribute._SvgAttribute.attrCore_Id);
            string sNewId = sOldId;

            if (sOldId != "")
            {
                int i = 1;

                // check if it is unique
                while (GetSvgElement(sNewId) != null)
                {
                    sNewId = sOldId + "_" + i.ToString();
                    i++;
                }
            }

            // clone operation
            SvgElement eleNew = AddElement(parent, eleToClone.getElementName());

            eleNew.CloneAttributeList(eleToClone);

            if (sNewId != "")
            {
                eleNew.SetAttributeValue(SvgAttribute._SvgAttribute.attrCore_Id, sNewId);
            }

            if (eleToClone.getChild() != null)
            {
                eleNew.setChild(CloneElement(eleNew, eleToClone.getChild()));

                if (eleToClone.getChild().getNext() != null)
                {
                    eleNew.getChild().setNext(CloneElement(eleNew, eleToClone.getChild().getNext()));
                }
            }

            return(eleNew);
        }
예제 #2
0
        protected void btnCalc_Click(object sender, EventArgs e)
        {
            // clear error messages
            dialog.InnerHtml = "";


            // FORM ITEMS ================================================================
            //file info:
            fileName.InnerHtml = HttpUtility.HtmlEncode(Context.Request.Form["cFileName"]);
            string fPath    = Context.Server.MapPath(@"imgLibrary");
            string fullPath = fPath + @"\" + Context.Request.Form["cFileName"];
            string fName    = Context.Request.Form["cFileName"];

            // user selected options:
            int materialId = Convert.ToInt32(svgMaterial.SelectedValue);
            int quantity   = Convert.ToInt32(svgQuantity.Text);
            int mmId       = Convert.ToInt32(svgMm.SelectedValue);

            // END FORM ==================================================================


            //get the template size id from the uloaded file
            templateSize myTemp         = new templateSize();
            int          templateSizeId = myTemp.detectTemplate(fullPath);

            if (templateSizeId == 0)
            {
                // is not a valid template - show error
                errors errType = new errors();
                errType.errTemplate();
                openError(errType.currentError + errType.helpUrl);
                errType = null;
                return;
            }

            //show template size on screen
            lblSvgTemplateSize.Text = "Template size " + myTemp.txtTemplateSize;
            myTemp = null;


            //load the svg doc into the svg library
            SvgDoc myDoc = new SvgDoc();

            myDoc.LoadFromFile(fullPath);


            SVGLib.SvgElement elYourDesigns = myDoc.GetSvgElement("Your_Designs");
            if (elYourDesigns.getChild() != null)
            {
                AddFromSvg2(elYourDesigns);
            }
            else
            {
                //check inkscape added group labled "Your Designs"
                // get the id by searching for the label then us the ID with getSvgElement
                inkscapeGroupFix gf      = new inkscapeGroupFix();
                string           groupId = gf.getgroupId("Your Designs", fullPath, "Your Designs");
                if (groupId == "")
                {
                    //throw error, no design detected
                    errors errType = new errors();
                    errType.errDesign();
                    openError(errType.currentError + errType.helpUrl);
                    errType = null;
                    return;
                }
                else
                {
                    elYourDesigns = myDoc.GetSvgElement(groupId);
                    AddFromSvg2(elYourDesigns);
                }

                gf = null;
            }

            myDoc = null;

            List <shapePrice> priceArray = allShapes;
            zapQuote          newQuote   = new zapQuote(materialId, templateSizeId, mmId);

            //check if error returned from AddFromSvg
            if (isValidSvgDesign == false)
            {
                //show error and halt progress
                openError(svgError);
                return;
            }


            foreach (shapePrice i in priceArray)
            {
                newQuote.appendShapeData(i.length, i.area, i.zapType, i.height, i.xpos, i.ypos);
                // raster line area from objects
                rasterExtraArea += i.rasterArea;
            }


            //calculate extra raster area from coordinates
            if (rasterPoints.Count > 0)
            {
                //find 4 outer points and calculate area as a rectangle

                double lX = rasterPoints.Min(c => c.X);
                double rX = rasterPoints.Max(c => c.X);
                double tY = rasterPoints.Min(c => c.Y);
                double bY = rasterPoints.Max(c => c.Y);

                rasterExtraArea = Common.rasterAreaFromPoints(lX, rX, tY, bY);
                extraHeight     = Common.rasterHeight(tY, bY);
            }



            newQuote.calcTotalTime(materialId, templateSizeId, mmId, rasterExtraArea, extraHeight);



            materialPrice mPrice = new materialPrice();

            mPrice.getMaterialPrices(materialId, templateSizeId, mmId);


            //cut lines price
            decimal cutPrice = Convert.ToDecimal(newQuote.cutTime * mPrice.costCutSec);
            // engrave lines
            decimal engravePrice = Convert.ToDecimal(newQuote.engraveTime * mPrice.costVectorSec);
            // raster engrave
            //decimal rasterPrice = Convert.ToDecimal((newQuote.totalAreaFill / 100) * mPrice.costRasterPerSqCm);

            decimal rasterPrice = Convert.ToDecimal(newQuote.fillTime * mPrice.costRasterPerSec);

            decimal totalLaserPrice = cutPrice + engravePrice + rasterPrice;

            decimal materialCost = Convert.ToDecimal(mPrice.pricePerUnit);

            decimal unitPrice = totalLaserPrice + materialCost;

            decimal totalPrice = unitPrice * quantity;


            //populate labels / session values

            StringBuilder quoteInfo = new StringBuilder();

            quoteInfo.Append("<ul>");
            quoteInfo.Append("<li><b>File Cost</b>");
            quoteInfo.Append("<div class='formInfo'>- " + fName + " = <span class='formBlue'>" + string.Format(CultureInfo.CreateSpecificCulture("en-GB"), "{0:C}", totalLaserPrice) + "</span></div>");
            quoteInfo.Append("<div class='formInfo'>- Quantity = <span class='formBlue'>x" + quantity + "</span></div>");
            quoteInfo.Append("<div class='formBlue'>Total File Cost = " + string.Format(CultureInfo.CreateSpecificCulture("en-GB"), "{0:C}", totalLaserPrice * quantity) + "</div>");
            quoteInfo.Append("</li>");
            quoteInfo.Append("<li><b>Material Cost</b>");
            quoteInfo.Append("<div class='formInfo'>- " + svgMaterial.SelectedItem.Text + "</div>");
            quoteInfo.Append("<div class='formInfo'>- " + svgMm.SelectedItem.Text + "</div>");
            quoteInfo.Append("<div class='formInfo'>- " + materialColour.SelectedItem.Text + "</div>");
            quoteInfo.Append("<div class='formInfo'>- = <span class='formBlue'>" + string.Format(CultureInfo.CreateSpecificCulture("en-GB"), "{0:C}", materialCost) + "</span></div>");
            quoteInfo.Append("<div class='formInfo'>- Quantity = <span class='formBlue'>x" + quantity + "</span></div>");
            quoteInfo.Append("<div class='formInfo'>- Total material cost= <span class='formBlue'>" + string.Format(CultureInfo.CreateSpecificCulture("en-GB"), "{0:C}", materialCost * quantity) + "</span></div>");
            quoteInfo.Append("</li>");
            quoteInfo.Append("<li><b>Total Cost</b> <span class='formBlue'>" + string.Format(CultureInfo.CreateSpecificCulture("en-GB"), "{0:C}", totalPrice) + "</span>");
            quoteInfo.Append("</li>");
            quoteInfo.Append("</ul>");

            divQuote.InnerHtml = quoteInfo.ToString();

            quoteInfo = null;



            StringBuilder debugInfo = new StringBuilder();


            debugInfo.Append("<p>Cut price:" + cutPrice + "</p>");
            debugInfo.Append("<p>Cut time:" + newQuote.cutTime + "</p>");
            debugInfo.Append("<p>Cut length mm:" + newQuote.totalCutLength + "</p>");
            debugInfo.Append("<p>Cut cost per sec:" + mPrice.costCutSec + "</p>");
            debugInfo.Append("<p>Number of cuts:" + newQuote.cutCount + "</p>");
            debugInfo.Append("<p>Cut area:" + newQuote.totalCutArea + "</p>");

            debugInfo.Append("<p>Vector engrave price:" + engravePrice + "</p>");
            debugInfo.Append("<p>Vector engrave time:" + newQuote.engraveTime + "</p>");
            debugInfo.Append("<p>Vector engrave cost per sec:" + mPrice.costVectorSec + "</p>");

            debugInfo.Append("<p>Vector engrave light length:" + newQuote.totalLightEngrave + "</p>");
            debugInfo.Append("<p>Vector engrave med length:" + newQuote.totalMedEngrave + "</p>");
            debugInfo.Append("<p>Vector engrave heavy length:" + newQuote.totalHeavyEngrave + "</p>");


            debugInfo.Append("<p>Raster price:" + rasterPrice + "</p>");
            debugInfo.Append("<p>Raster time:" + newQuote.fillTime + "</p>");
            debugInfo.Append("<p>Raster cost per sec:" + mPrice.costRasterPerSec + "</p>");
            debugInfo.Append("<p>Raster area:" + newQuote.rasterArea + "</p>");



            litErr.Text = debugInfo.ToString();

            debugInfo = null;
        }
예제 #3
0
        // ---------- PUBLIC METHODS END

        // ---------- PRIVATE METHODS

        private bool DeleteElement(SvgElement ele, bool bDeleteFromParent)
        {
            ErrH err = new ErrH("SvgDoc", "DeleteElement");

            if (ele == null)
            {
                err.LogEnd(false);

                return(false);
            }

            SvgElement parent = ele.getParent();

            if (parent == null)
            {
                // root node cannot be delete!
                err.Log("root node cannot be delete!", ErrH._LogPriority.Info);
                err.LogEnd(false);

                return(false);
            }

            // set the Next reference of the previous
            if (ele.getPrevious() != null)
            {
                ele.getPrevious().setNext(ele.getNext());
            }

            // set the Previous reference of the next
            if (ele.getNext() != null)
            {
                ele.getNext().setPrevious(ele.getPrevious());
            }

            // check if the element is the first child
            // the bDeleteFromParent flag is used to avoid deleting
            // all parent-child relationship. This is used in the Cut
            // operation where the subtree can be pasted
            if (bDeleteFromParent)
            {
                if (IsFirstChild(ele))
                {
                    // set the Child reference of the parent to the next
                    ele.getParent().setChild(ele.getNext());
                }
            }

            // delete its children
            SvgElement child = ele.getChild();

            while (child != null)
            {
                DeleteElement(child, false);
                child = child.getNext();
            }

            // delete the element from the colloection
            m_elements.Remove(ele.getInternalId());

            err.Log(ele.ElementInfo(), ErrH._LogPriority.Info);
            err.LogEnd(true);

            return(true);
        }
예제 #4
0
        public int detectTemplate(string docPath)
        {
            // XDocument test = XDocument.Load(docPath);

            // IEnumerable<XElement> users = (from el in test.Root.Descendants() where (string)el.Attribute("id") == "Your_Designs" select el);

            // XElement element = users.First();
            // string mc = element.Attribute("class").Value.ToString();


            // another change 15 june 2012 now using fill value from nested path in group with id = borders
            string pathFill = "";
            SvgDoc myDoc    = new SvgDoc();

            myDoc.LoadFromFile(docPath);
            SVGLib.SvgElement elBorders = myDoc.GetSvgElement("Borders");
            if (elBorders != null)
            {
                if (elBorders.getChild() != null)
                {
                    SvgElement pathBorder = elBorders.getChild();
                    pathData   myPath     = new pathData((SvgPath)pathBorder);
                    pathFill   = myPath.fillColor;
                    pathBorder = null;
                    myPath     = null;
                }
            }
            else
            {
                // check if is an inkscape
                //check inkscape added group labled "Borders"
                // get the id by searching for the label then us the ID with getSvgElement
                inkscapeGroupFix gf      = new inkscapeGroupFix();
                string           groupId = gf.getgroupId("Borders", docPath, "Borders");
                if (groupId == "")
                {
                    //show template error - not recognised
                }
                else
                {
                    //get the fill colour
                    elBorders = myDoc.GetSvgElement(groupId);
                    SvgElement   pathBorder = elBorders.getChild();
                    pathData     myPath     = new pathData((SvgPath)pathBorder);
                    string       pathStyle  = myPath.style;
                    extractStyle rStyle     = new extractStyle();
                    rStyle.getStyle(pathStyle);
                    pathFill = rStyle.fillColour;

                    //convert to RGB values
                    Color htmlPath = ColorTranslator.FromHtml(pathFill);
                    pathFill = Convert.ToString(htmlPath.R) + Convert.ToString(htmlPath.G) + Convert.ToString(htmlPath.B);

                    rStyle     = null;
                    pathBorder = null;
                    myPath     = null;
                }
                myDoc = null;
            }



            //IEnumerable<XElement> users = test.Root.Descendants();

            //string viewBox = svgTree.Attribute("viewBox").Value.ToString();



            // chang to get the fill colour from the borders child path element TODO


            // pathData myPath = new pathData((SvgPath)elBorders.getChild());
            // myShapes shapeData = new myShapes();

            //string pathData = myPath.shapeData;
            //double length = shapeData.getPathLength(pathData);
            //int absLength = Convert.ToInt32(Math.Round(length));

            //myDoc = null;
            // elBorders = null;
            //myPath = null;
            //shapeData = null;
            //svgTree = null;



            SqlConnection myConn = new SqlConnection(ConfigurationManager.ConnectionStrings["zapCartDb"].ConnectionString);

            myConn.Open();

            //SqlCommand myCmd = new SqlCommand("SELECT * FROM tbl_templateSizes where viewBox = @viewBox");
            //SqlCommand myCmd = new SqlCommand("SELECT * FROM tbl_templateSizes where templateSizeText = @viewBox");
            SqlCommand myCmd = new SqlCommand("SELECT * FROM tbl_templateSizes where borders = @borders");

            myCmd.Connection = myConn;
            SqlParameter myParam = new SqlParameter();

            myParam.ParameterName = "@borders";
            //myParam.Value = viewBox;
            myParam.Value = pathFill;
            myCmd.Parameters.Add(myParam);

            SqlDataReader myReader = null;

            myReader = myCmd.ExecuteReader();

            int templateSizeId = 0;

            while (myReader.Read())
            {
                templateSizeId  = (int)myReader["templateSizeId"];
                txtTemplateSize = (string)myReader["templateSizeText"];
            }

            myReader = null;
            myConn.Close();
            myCmd  = null;
            myConn = null;


            return(templateSizeId);
        }