Beispiel #1
0
 public void Test_Division_and_ChargeGroup_Fess()
 {
     List<Point> points = new List<Point> {new Point(0F,0F), new Point(100F,10F), new Point(10F,100F)};
       Polygon testPoly = new Polygon(points, 100F, 100F, 0F, 0F);
       Division div = new Division(testPoly);
       Field fFess = new Field("solid", new string[] {"argent"});
       Field fShield = new Field("solid", new string[] {"gules"});
       div.field = fShield;
       ChargeGroup cg = new ChargeGroup(div, "fess", 1, fFess);
       div.chargeGroups.Add(cg);
       Assert.Equal(4, div.chargeGroups[0].chargeDivs[0].shape.vertices.Count);
 }
Beispiel #2
0
        public HomeModule()
        {
            Get["/"] = _ => {

            string path = "/blazon/per+pale+per+fess+sable+a+chief+or+and+purpure+overall+a+bend+argent+and+vert+11+mullets+argent+overall+a+lozenge+azure/shieldShape/1";
            return Response.AsRedirect(path);
              };
              Post["/blazon"] =_=> {
            string input = Request.Form["blazon-string"];
            string shieldShape = Request.Form["shield-shape"];
            string formattedBlazon = string.Join("+",Parser.FormatBlazon(input));
            string path = "/blazon/"+formattedBlazon+"/shieldShape/"+shieldShape;
            return Response.AsRedirect(path);
              };
              Get["/blazon/{blazon}/shieldShape/{shieldShape}"]= parameter => {
            int shieldNumber = parameter.shieldShape;
            string input = parameter.blazon;
            string newBlazon = input.Replace("+"," ");
            Division div = new Division(GetShieldPoly(shieldNumber));
            dynamic Model = new ExpandoObject();
            Model.outputString = Parser.Parse(newBlazon, div);
            Model.html = GenerateHTML(div);
            Model.shieldShape = parameter.shieldShape;
            Model.newBlazon = newBlazon;
            Model.allBlazons = SaveBlazon.GetAll();
            return View["index.cshtml", Model];
              };
              Post["/save"]= _ => {
            string blazonName = Request.Form["blazon-name"];
            string blazonBlazon = Request.Form["blazon-blazon"];
            int blazonShape = (int)Request.Form["shield-shape"];
            SaveBlazon newSaveBlazon = new SaveBlazon(blazonName, blazonBlazon, blazonShape);
            newSaveBlazon.Save();
            string formattedBlazon = blazonBlazon.Replace(" ", "+");
            string path = "/blazon/"+formattedBlazon+"/shieldShape/"+blazonShape;
            return Response.AsRedirect(path);
              };
              Post["/delete"]= _ => {
            SaveBlazon.DeleteAll();
            string path = "/blazon/per+pale+per+fess+sable+a+chief+or+and+purpure+overall+a+bend+argent+and+vert+11+mullets+argent+overall+a+lozenge+azure/shieldShape/1";
            return Response.AsRedirect(path);

              };
        }
Beispiel #3
0
        public static string Parse(string blazonString, Division div)
        {
            //Console.WriteLine("---NEW ARMS BEGIN---");
              divStack.Clear();
              divStack.Push(div);
              string[] blazon = FormatBlazon(blazonString);
              //Console.WriteLine(string.Join(" ",blazon));
              if(!AllTermsInDict(blazon))
              {
            return "Not all words are recognized";
              }
              string commandType = termTypes[blazon[0]];
              List<string> command = new List<string> {};
              int modifyingCharge = 0;
              usingOn = false;
              for(int i=0; i<blazon.Length; i++)
              {
            if(blazon[i]=="quarterly" && i!=0)
            {
              return "Only one quartering allowed, use 'per pale' and 'per fess' instead";
            }
            command.Add(blazon[i]);
            // Get Term Type
            string termType = GetTermType(blazon, i, commandType);
            //Console.WriteLine("Stack Size: {0}",divStack.Count);
            //Console.WriteLine(blazon[i]+": "+termType);
            commandType = commandType=="none" ? termType : commandType;
            // Check for command completeness
            bool complete = false;
            if(i==blazon.Length-1)
            {
              complete = true;
            }
            else if(termType=="division" && (command.Count==2 || blazon[i]=="quarterly"))
            {
              complete = true;
            }
            else if(blazon[i]=="on" || blazon[i+1]=="on")
            {
              complete = true;
            }
            else
            {
              string nextTermType = GetTermType(blazon, i+1, commandType);
              complete = nextTermType!=commandType ? true : complete;
            }

            // Execute command if complete
            if(complete)
            {
              //Console.WriteLine("Executing: "+string.Join(" ",command));
              modifyingCharge = ExecuteCommand(command, commandType, modifyingCharge);
              if(modifyingCharge==-1){return "Problem at word "+i.ToString();}
              commandType = "none";
              command = new List<string> {};
            }
            //Console.WriteLine("Finished with Term");
              }
              //Console.WriteLine("---------");
              return "";
        }
Beispiel #4
0
 public Division[] ExecuteCommand(List<string> command, string commandType)
 {
     if(commandType=="tincture")
       {
     if(command[0]=="ermine" || (command[0]=="vair" || command[0]=="potent"))
     {
       _field = new Field("fur", command.ToArray());
     }
     else
     {
       _field = new Field("solid", command.ToArray());
     }
       }
       if(commandType=="charge")
       {
     ChargeGroup cg = new ChargeGroup(this, command[1], Int32.Parse(command[0]));
     _chargeGroups.Add(cg);
     return cg.chargeDivs;
       }
       if(commandType=="division")
       {
     string divType;
     if(command[0]=="quarterly")
     {
       divType = "quarterly";
     }
     else
     {
       divType = command[1];
     }
     List<Polygon> shapes = this.shape.PartyPer(divType);
     _subdivisions = new Division[shapes.Count];
     for(int i=0; i<shapes.Count; i++)
     {
       _subdivisions[i] = new Division(shapes[i]);
     }
     return _subdivisions;
       }
       return new Division[] {};
 }
Beispiel #5
0
        public ChargeGroup(Division Parent, string chargeDevice, int Number=1, Field inputField=null, string Layout="unspecified")
        {
            _parent = Parent;
              _layout = Layout;
              _chargesDivs = new Division[Number];
              Point center = _parent.shape.GetCenter();
              float centerOffsetX = center.X-(_parent.shape.width/2);
              float centerOffsetY = center.Y-(_parent.shape.height/2);
              int numberOfDisplayRows;
              Line[] displayRows;
              if(Layout=="unspecified")
              {
            numberOfDisplayRows = (int)Math.Floor(Math.Sqrt(Number));
            displayRows = parent.shape.GetSectionLines(numberOfDisplayRows, true);
              }
              else // if(Layout=="fess")
              {
            numberOfDisplayRows = 1;
            displayRows = parent.shape.GetSectionLines(numberOfDisplayRows, true);
              }
              float totalDisplayLength = 0F;
              foreach(Line l in displayRows)
              {
            totalDisplayLength += l.GetLength();
              }
              int chargesPerRow = (int)Math.Floor(totalDisplayLength/Number);
              bool leftoverCharge = numberOfDisplayRows*chargesPerRow != Number;
              float paddingX = totalDisplayLength/(float)(Number+1);
              float paddingY = parent.shape.height/(numberOfDisplayRows+1);

              for(int i=0; i<_chargesDivs.Length; i++)
              {
            Polygon newChargeDivShape = null;
            Point parentCenter = _parent.shape.GetCenter();
            if(chargeDevice=="fess")
            {
              newChargeDivShape = new Polygon(new List<Point> {new Point(0F,0F),new Point(100F,0F),new Point(100F,100F),new Point(0F,100F)}, 100F, 25F, 0F, parentCenter.Y-12.5F);
            }
            else if(chargeDevice=="chief")
            {
              newChargeDivShape = new Polygon(new List<Point> {new Point(0F,0F),new Point(100F,0F),new Point(100F,100F),new Point(0F,100F)}, 100F, 25F, 0F, 0F);
            }
            else if(chargeDevice=="pile")
            {
              newChargeDivShape = new Polygon(new List<Point> {new Point(0F,0F),new Point(center.X,100F),new Point(100F,0F)}, 100F, 80F, 0F, 0F);
            }
            else if(chargeDevice=="pale")
            {
              newChargeDivShape = new Polygon(new List<Point> {new Point(0F,0F),new Point(100F,0F),new Point(100F,100F),new Point(0F,100F)}, 25F, 100F, parentCenter.X-12.5F, 0F);
            }
            else if(chargeDevice=="bend")
            {
              float size = 20F;
              Line bendLine = new Line(center, new Point(center.X+1, center.Y+1));
              Point left = new Point(bendLine.GetXAtYPos(0F), 0F);
              Point right = new Point(bendLine.GetXAtYPos(100F), 100F);
              newChargeDivShape = new Polygon(new List<Point> {new Point(left.X-size,100F),new Point(left.X+size,100F),new Point(right.X+size,0F),new Point(right.X-size,0F)}, 100F, 100F, 0F, 0F);
            }
            else if(chargeDevice=="bend-sinister")
            {
              float size = 20F;
              Line bendLine = new Line(center, new Point(center.X+1, center.Y-1));
              Point left = new Point(bendLine.GetXAtYPos(0F), 0F);
              Point right = new Point(bendLine.GetXAtYPos(100F), 100F);
              newChargeDivShape = new Polygon(new List<Point> {new Point(left.X-size,100F),new Point(left.X+size,100F),new Point(right.X+size,0F),new Point(right.X-size,0F)}, 100F, 100F, 0F, 0F);
            }
            else if(chargeDevice=="saltire")
            {
              float size = 15F;
              Line bendLine = new Line(center, new Point(center.X+1, center.Y+1));
              Line bendSinisterLine = new Line(center, new Point(center.X-1, center.Y+1));
              Point lowerLeft = new Point(bendLine.GetXAtYPos(100F) ,100F);
              Point lowerRight = new Point(bendSinisterLine.GetXAtYPos(100F) ,100F);
              Point upperRight = new Point(bendLine.GetXAtYPos(0F) ,0F);
              Point upperLeft = new Point(bendSinisterLine.GetXAtYPos(0F) ,0F);

              newChargeDivShape = new Polygon(new List<Point> {new Point(lowerLeft.X-size,lowerLeft.Y),new Point(lowerLeft.X+size,lowerLeft.Y),new Point(center.X,center.Y-size),new Point(lowerRight.X-size,lowerRight.Y), new Point(lowerRight.X+size,lowerRight.Y),new Point(center.X+size,center.Y),new Point(upperRight.X+size,upperRight.Y),new Point(upperRight.X-size,upperRight.Y),new Point(center.X,center.Y+size),new Point(upperLeft.X+size,upperLeft.Y),new Point(upperLeft.X-size,upperLeft.Y),new Point(center.X-size,center.Y)}, 100F, 100F, 0F, 0F);
            }
            else if(chargeDevice=="cross")
            {
              float size = 15F;
              newChargeDivShape = new Polygon(new List<Point> {new Point(center.X-size,0F),new Point(center.X+size,0F),new Point(center.X+size,center.Y-size),new Point(100F,center.Y-size),new Point(100F,center.Y+size),new Point(center.X+size,center.Y+size),new Point(center.X+size,100F),new Point(center.X-size,100F),new Point(center.X-size,center.Y+size),new Point(0F,center.Y+size),new Point(0F,center.Y-size),new Point(center.X-size,center.Y-size)}, 100F, 100F, 0F, 0F);
            }
            else if(chargeDevice=="chevron")
            {
              float size = 50F;
              newChargeDivShape = new Polygon(new List<Point> {new Point(0F,100F),new Point(0F,100F-size), new Point(50F,0F),new Point(100F,100F-size),new Point(100F,100F), new Point(50F,size)}, 100F, 30F, 0F, center.Y-15F);
            }
            else if(chargeDevice=="pall")
            {
              float size = 15F;
              Line bendLine = new Line(center, new Point(center.X+1, center.Y+1));
              Line bendSinisterLine = new Line(center, new Point(center.X-1, center.Y+1));
              Point upperRight = new Point(bendLine.GetXAtYPos(0F) ,0F);
              Point upperLeft = new Point(bendSinisterLine.GetXAtYPos(0F) ,0F);

              newChargeDivShape = new Polygon(new List<Point> {new Point(upperLeft.X+size,upperLeft.Y),new Point(upperLeft.X-size,upperLeft.Y),new Point(center.X,center.Y-size),new Point(upperRight.X+size,upperRight.Y),new Point(upperRight.X-size,upperRight.Y),new Point(center.X-size,center.Y),new Point(center.X-size,100F),new Point(center.X+size,100F),new Point(center.X+size,center.Y)}, 100F, 100F, 0F, 0F);//
            }
            else if(chargeDevice=="pall-reversed")
            {
              float size = 15F;
              Line bendLine = new Line(center, new Point(center.X+1, center.Y+1));
              Line bendSinisterLine = new Line(center, new Point(center.X-1, center.Y+1));
              Point left = new Point(bendLine.GetXAtYPos(100F) ,100F);
              Point right = new Point(bendSinisterLine.GetXAtYPos(100F) ,100F);

              newChargeDivShape = new Polygon(new List<Point> {new Point(right.X+size,right.Y),new Point(right.X-size,right.Y),new Point(center.X,center.Y-size),new Point(left.X+size,left.Y),new Point(left.X-size,left.Y),new Point(center.X-size,center.Y),new Point(center.X-size,0F),new Point(center.X+size,0F),new Point(center.X+size,center.Y)}, 100F, 100F, 0F, 0F);
            }
            else
            {
              float position = paddingX*(float)(i+1);
              float addPosition = 0F;
              Line displayRow = displayRows[0];
              for(int j=0; addPosition<position; j++)
              {
            addPosition += displayRows[j].GetLength();
            displayRow = displayRows[j];
              }
              if(displayRow.GetLength()%paddingX < 0.01F && Number > displayRow.GetLength()/paddingX)
              {
            position -= paddingX/2;
              }
              float positionOnRow = displayRow.GetLength() - (addPosition-position);
              Point displayPoint = new Point(displayRow.P1.X+positionOnRow, displayRow.P1.Y);
              if(chargeDevice == "lozenge")
              {
            newChargeDivShape = new Polygon(new List<Point> {new Point(0F,50F),new Point(50F,100F),new Point(100F,50F),new Point(50F,0F)}, paddingX*.6F, paddingY*.8F, displayPoint.X-(paddingX*.6F)/2F, displayPoint.Y-(paddingY*.8F)/2F);
              }
              if(chargeDevice == "mullet")
              {
            float chargeWidth = Math.Min(paddingX*.7F,paddingY*.7F);
            float chargeHeight = Math.Min(paddingX*.5F,paddingY*.5F)*(_parent.shape.width/_parent.shape.height);
            newChargeDivShape = new Polygon(new List<Point> {new Point(0F,40F),new Point(33.333F,62F),new Point(20F,100F),new Point(50F,80F),new Point(80F,100F),new Point(66.6666F,62F),new Point(100F,40F),new Point(62F,40F),new Point(50F,0F),new Point(38F,40F)}, chargeWidth, chargeHeight, displayPoint.X-chargeWidth/2F, displayPoint.Y-chargeHeight/2F);
              }
              if(chargeDevice == "inescutcheon" || chargeDevice == "escutcheon")
              {
            float chargeWidth = Math.Min(paddingX*.6F,paddingY*.6F);
            float chargeHeight = Math.Min(paddingX*.6F,paddingY*.6F)*(_parent.shape.width/_parent.shape.height);
            newChargeDivShape = new Polygon(new List<Point> {new Point(0F,0F), new Point(0F,80F), new Point(50F,100F), new Point(100F,80F), new Point(100F,0F)}, chargeWidth, chargeHeight, displayPoint.X-chargeWidth/2F, displayPoint.Y-chargeHeight/2F);
              }
            }
            _chargesDivs[i] = new Division(newChargeDivShape);
            _chargesDivs[i].field = inputField ?? new Field("solid", new string[]{"argent"});
              }
        }
Beispiel #6
0
 private string GenerateHTML(Division division)
 {
     string result = "<div style=' height:"+division.shape.height+"%; "+
                             "width:"+division.shape.width+"%; "+
                             "position:absolute; "+
                             "top:"+division.shape.offsetY+"%; "+
                             "left:"+division.shape.offsetX+"%; ";
       if(division.subdivisions.Length == 0)
       {
     if(division.field.pattern=="solid")
     {
       result += "background-color:"+division.field.tinctures[0]+"; ";
     }
       }
       result += "-webkit-clip-path:polygon(";
       foreach(Point vertex in division.shape.vertices)
       {
     result += vertex.X.ToString()+"% "+vertex.Y.ToString()+"%, ";
       }
       result = result.Substring(0, result.Length-2);
       result += ");'";
       if(division.field.pattern=="fur")
       {
     result += "class="+division.field.tinctures[0];
       }
       result += "> ";
       foreach(Division sub in division.subdivisions)
       {
     result += GenerateHTML(sub);
       }
       foreach(ChargeGroup cg in division.chargeGroups)
       {
     foreach(Division charge in cg.chargeDivs)
     {
       result += GenerateHTML(charge);
     }
       }
       result += "</div>";
       return result;
 }