/// <summary> /// 打开矢量数据 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripButton_OpenVector_Click(object sender, EventArgs e) { ICommand command = new VectorCommand(); command.OnCreate(axMapControl2); command.OnClick(); }
private void VerticalLine(VectorCommand instruction, bool isRelative) { var points = new List <Vector2>(); for (var i = 0; i < instruction.Arguments.Length; i++) { var point = new Vector2(previousPoint.X, instruction.Arguments[i]); if (isRelative) { point += new Vector2(0, previousPoint.Y); } points.Add(point); previousPoint = points[i]; } sink.AddLines(points); }
void CubicBezierCurve(VectorCommand instruction, bool isRelative) { for (int i = 0; i < instruction.Arguments.Length; i = i + 6) { var p1 = new Vector2(instruction.Arguments[0], instruction.Arguments[1]); var p2 = new Vector2(instruction.Arguments[2], instruction.Arguments[3]); var p3 = new Vector2(instruction.Arguments[4], instruction.Arguments[5]); if (isRelative) { p1 += previousPoint; p2 += previousPoint; p3 += previousPoint; } sink.AddCubicBezierCurve(p1, p2, p3); } }
void Line(VectorCommand instruction, bool isRelative) { var points = new List <Vector2>(); for (var i = 0; i < instruction.Arguments.Length; i = i + 2) { var point = new Vector2(instruction.Arguments[i], instruction.Arguments[i + 1]); if (isRelative) { point += previousPoint; } points.Add(point); previousPoint = points[i]; } sink.AddLines(points); }
void Move(VectorCommand instruction, bool isRelative) { if (IsFigureOpen) { Close(FigureEnd.Open); } var point = new Vector2(instruction.Arguments[0], instruction.Arguments[1]); if (isRelative) { point += startPoint; } startPoint = isRelative ? point + startPoint : point; previousPoint = startPoint; sink.BeginFigure(startPoint, FigureBegin.Filled); IsFigureOpen = true; }
void Arc(VectorCommand instruction, bool isRelative) { for (int i = 0; i < instruction.Arguments.Length; i = i + 6) { float w = instruction.Arguments[0]; float h = instruction.Arguments[1]; float a = instruction.Arguments[2]; bool isLargeArc = (int)instruction.Arguments[3] == 1; bool sweepDirection = (int)instruction.Arguments[4] == 1; var p = new Vector2(instruction.Arguments[5], instruction.Arguments[6]); if (isRelative) { p += previousPoint; } sink.AddArc(w, h, a, isLargeArc, sweepDirection, p); } }
/// <summary> /// Creates a new VectorCommand based on the specified input text. /// </summary> /// <param name="input">The input text to get a match for. For example, "hide a".</param> /// <returns>Returns the new VectorCommand, or null if a no matches were found for the specified input.</returns> public static VectorCommand Create(string input) { const string pattern = @"^(?<command>\w+)\s*(?<vectorName>\w+)$"; Regex regex = new Regex(pattern); MatchCollection matches = regex.Matches(input); if (matches.Count == 0) { return(null); } VectorCommand vectorCommand = new VectorCommand(); vectorCommand.command = RegexHelper.GetValue <string>(matches, "command"); vectorCommand.vectorName = RegexHelper.GetValue <string>(matches, "vectorName"); return(vectorCommand); }
public void AddCommand(VectorCommand command) { Contract.Requires <ArgumentNullException>(command != null, "command"); commands.Add(command); }
private void ExecuteCommandLine(string text) { SuperVector superVector = SuperVector.Create(text); if (superVector != null) { CreateOrUpdateSuperVector(superVector); return; } SetColor setColor = SetColor.Create(text); if (setColor != null) { ChangeVectorColor(setColor.vectorName, setColor.hexCode); return; } SetNamedColor setNamedColor = SetNamedColor.Create(text); if (setNamedColor != null) { string hexCode; if (colorLookups.ContainsKey(setNamedColor.colorName)) { hexCode = colorLookups[setNamedColor.colorName]; ChangeVectorColor(setNamedColor.vectorName, hexCode); } else { Debug.LogError($"\"{setNamedColor.colorName}\" needs to be defined first!!!"); } return; } DefineColor defineColor = DefineColor.Create(text); if (defineColor != null) { DefineColorName(defineColor.colorName, defineColor.hexCode); return; } MoveVector moveVector = MoveVector.Create(text); if (moveVector != null) { MoveVectorTo(moveVector.vector1, moveVector.vector2); return; } SumVectors sumVectors = SumVectors.Create(text); if (sumVectors != null) { SumAllVectors(sumVectors.newVectorName, sumVectors.vector1, sumVectors.vector2, sumVectors.vector3, sumVectors.vector4, sumVectors.vector5); return; } NegativeVector negativeVector = NegativeVector.Create(text); if (negativeVector != null) { MakeVectorNegative(negativeVector.vectorName); return; } AssignNegativeVector assignNegativeVector = AssignNegativeVector.Create(text); if (assignNegativeVector != null) { CreateNegativeVector(assignNegativeVector.existingVectorName, assignNegativeVector.newVectorName); return; } VectorCommand vectorCommand = VectorCommand.Create(text); if (vectorCommand != null) { HandleVectorCommand(vectorCommand.command, vectorCommand.vectorName); return; } OffsetVector offsetVector = OffsetVector.Create(text); if (offsetVector != null) { OffsetVectorBy(offsetVector.vectorName, offsetVector.offsetX, offsetVector.offsetY, offsetVector.offsetZ); return; } }