public void CreateComplexShape_HappyPathWithoutEffect_NotNull() { int result = 0; var complaxeShape = new CreateComplexShapeRequestDTO() { Name = "Simple Image", Shapes = new System.Collections.Generic.List <CreateShapeRequestDTO>() { new CreateShapeRequestDTO() { Type = "Square", StartPositionX = 1, StartPositionY = 2, Width = 5, } } }; var entity = new Entities.ComplexShape() { Id = 1, Name = complaxeShape.Name, Content = "{\"$type\":\"GeoPaint.Component.ComplexShape, GeoWeb.DTO\",\"Shapes\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.BaseObject, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.Line, GeoWeb.DTO\",\"EndPositionX\":50,\"EndPositionY\":30,\"Id\":0,\"PositionX\":0,\"PositionY\":0,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"5\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"blue\"}]}},{\"$type\":\"GeoPaint.Component.Square, GeoWeb.DTO\",\"Width\":30,\"Id\":1,\"PositionX\":80,\"PositionY\":80,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"red\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"false\"}]}},{\"$type\":\"GeoPaint.Component.Circle, GeoWeb.DTO\",\"Radius\":30,\"Id\":2,\"PositionX\":10,\"PositionY\":20,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"yellow\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"true\"}]}}]},\"Id\":0,\"Name\":\"Tool\",\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ComplexShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[]}}", }; _mockDataRepositoryFactory.GetRepository <Entities.ComplexShape>().Insert(entity); var engine = new ShapeEngine(_mockDataRepositoryFactory, _mockBusinessEngineFactory); result = engine.Create(complaxeShape); Assert.AreEqual(complaxeShape.Name, entity.Name); }
public void GetComplexShape_NullOrZeroValue_ReturnsArgumentNullException(int shapeId) { var complaxeShape = new Entities.ComplexShape(); complaxeShape.Id = shapeId; _mockDataRepositoryFactory.GetRepository <Entities.ComplexShape>().Get(Arg.Any <int>()).ReturnsForAnyArgs(complaxeShape); var engine = new ShapeEngine(_mockDataRepositoryFactory, _mockBusinessEngineFactory); Assert.That(() => engine.Get(Arg.Any <int>()), Throws.ArgumentNullException); }
public void UpdateComplexShape_HappyPathWithEffect_NotNull() { int result = 0; var complaxeShape = new CreateComplexShapeRequestDTO() { Name = "Simple Image", Shapes = new System.Collections.Generic.List <CreateShapeRequestDTO>() { new CreateShapeRequestDTO() { Type = "Square", StartPositionX = 80, StartPositionY = 80, Width = 5, Effects = new System.Collections.Generic.List <Component.ShapeEffect>() { new Component.ShapeEffect() { Value = "2", EffectType = VirtualEffectTypes.BorderWidth } } } } }; var entity = new Entities.ComplexShape() { Id = 1, Name = complaxeShape.Name, Content = "{\"$type\":\"GeoPaint.Component.ComplexShape, GeoWeb.DTO\",\"Shapes\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.BaseObject, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.Line, GeoWeb.DTO\",\"EndPositionX\":50,\"EndPositionY\":30,\"Id\":0,\"PositionX\":0,\"PositionY\":0,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"5\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"blue\"}]}},{\"$type\":\"GeoPaint.Component.Square, GeoWeb.DTO\",\"Width\":30,\"Id\":1,\"PositionX\":80,\"PositionY\":80,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"red\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"false\"}]}},{\"$type\":\"GeoPaint.Component.Circle, GeoWeb.DTO\",\"Radius\":30,\"Id\":2,\"PositionX\":10,\"PositionY\":20,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"yellow\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"true\"}]}}]},\"Id\":0,\"Name\":\"Tool\",\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ComplexShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[]}}", }; _mockDataRepositoryFactory.GetRepository <Entities.ComplexShape>().Insert(entity); var engine = new ShapeEngine(_mockDataRepositoryFactory, _mockBusinessEngineFactory); result = engine.Create(complaxeShape); JsonSerializerSettings settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All }; var deserializedComplexShape = JsonConvert.DeserializeObject <ComplexShape>(entity.Content, settings); Assert.AreEqual(complaxeShape.Name, entity.Name); Assert.AreEqual(complaxeShape.Shapes.First().StartPositionX, deserializedComplexShape.Shapes[1].PositionX); Assert.AreEqual(complaxeShape.Shapes.First().StartPositionY, deserializedComplexShape.Shapes[1].PositionY); Assert.AreEqual(complaxeShape.Shapes.First().Effects.First().EffectType, deserializedComplexShape.Shapes[1].Effects.First().EffectType); Assert.AreEqual(complaxeShape.Shapes.First().Effects.First().Value, deserializedComplexShape.Shapes[1].Effects.First().Value); }
public void CreateComplexShape_Null_ReturnsArgumentNullException() { var complaxeShape = new CreateComplexShapeRequestDTO() { Name = "", Shapes = new System.Collections.Generic.List <CreateShapeRequestDTO>() { new CreateShapeRequestDTO() } }; var engine = new ShapeEngine(_mockDataRepositoryFactory, _mockBusinessEngineFactory); Assert.That(() => engine.Create(complaxeShape), Throws.ArgumentNullException); }
public void Get_HappyPath_NotNull() { var complaxeShape = new Entities.ComplexShape() { Id = 1, Name = "Test", Content = "{\"$type\":\"GeoPaint.Component.ComplexShape, GeoWeb.DTO\",\"Shapes\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.BaseObject, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.Line, GeoWeb.DTO\",\"EndPositionX\":50,\"EndPositionY\":30,\"Id\":0,\"PositionX\":0,\"PositionY\":0,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"5\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"blue\"}]}},{\"$type\":\"GeoPaint.Component.Square, GeoWeb.DTO\",\"Width\":30,\"Id\":1,\"PositionX\":80,\"PositionY\":80,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"red\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"false\"}]}},{\"$type\":\"GeoPaint.Component.Circle, GeoWeb.DTO\",\"Radius\":30,\"Id\":2,\"PositionX\":10,\"PositionY\":20,\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":1,\"Value\":\"2\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":3,\"Value\":\"black\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":2,\"Value\":\"yellow\"},{\"$type\":\"GeoPaint.Component.ShapeEffect, GeoWeb.DTO\",\"EffectType\":4,\"Value\":\"true\"}]}}]},\"Id\":0,\"Name\":\"Tool\",\"Effects\":{\"$type\":\"System.Collections.Generic.List`1[[GeoPaint.Component.ComplexShapeEffect, GeoWeb.DTO]], mscorlib\",\"$values\":[]}}", EntityId = 2 }; _mockDataRepositoryFactory.GetRepository <Entities.ComplexShape>().Get(Arg.Any <int>()).ReturnsForAnyArgs(complaxeShape); var engine = new ShapeEngine(_mockDataRepositoryFactory, _mockBusinessEngineFactory); var result = engine.Get(1); //_mockDataRepositoryFactory.GetRepository<Entities.ComplexShape>().Get(Arg.Any<int>()).Received(); Assert.AreEqual(complaxeShape.Id, result.Id); Assert.AreEqual(complaxeShape.Name, result.Name); }
protected virtual void DrawExtras(ref Rectangle? dirty, Context g, ShapeEngine engine) { }
/// <summary> /// Copy the given shape's settings to the toolbar settings. Calls StorePreviousSettings. /// </summary> /// <param name="engine"></param> public virtual void UpdateToolbarSettings(ShapeEngine engine) { if (engine != null) { owner.UseAntialiasing = engine.AntiAliasing; //Update the DashPatternBox to represent the current shape's DashPattern. (dash_pattern_box.comboBox.ComboBox as Gtk.ComboBoxEntry).Entry.Text = engine.DashPattern; OutlineColor = engine.OutlineColor.Clone(); FillColor = engine.FillColor.Clone(); BrushWidth = engine.BrushWidth; StorePreviousSettings(); } }
protected Rectangle DrawShape(ShapeEngine engine, Layer l, bool drawCP, bool drawHoverSelection) { Document doc = PintaCore.Workspace.ActiveDocument; Rectangle? dirty = null; ShapeEngine activeEngine = ActiveShapeEngine; if (activeEngine != null) { using (Context g = new Context(l.Surface)) { g.AppendPath(doc.Selection.SelectionPath); g.FillRule = FillRule.EvenOdd; g.Clip(); g.Antialias = activeEngine.AntiAliasing ? Antialias.Subpixel : Antialias.None; g.SetDash(DashPatternBox.GenerateDashArray(activeEngine.DashPattern, activeEngine.BrushWidth), 0.0); g.LineWidth = activeEngine.BrushWidth; //Draw the shape. if (activeEngine.ControlPoints.Count > 0) { //Generate the points that make up the shape. activeEngine.GeneratePoints(activeEngine.BrushWidth); PointD[] points = activeEngine.GetActualPoints (); //Expand the invalidation rectangle as necessary. if (FillShape) { Color fill_color = StrokeShape ? activeEngine.FillColor : activeEngine.OutlineColor; dirty = dirty.UnionRectangles (g.FillPolygonal (points, fill_color)); } if (StrokeShape) { dirty = dirty.UnionRectangles(g.DrawPolygonal(points, activeEngine.OutlineColor)); } } g.SetDash(new double[] { }, 0.0); //Draw anything extra (that not every shape has), like arrows. DrawExtras(ref dirty, g, engine); if (drawCP) { DrawControlPoints(g, drawHoverSelection); } } } return dirty ?? new Rectangle(0d, 0d, 0d, 0d); }
/// <summary> /// Do not call. Use DrawActiveShape. /// </summary> /// <param name="engine"></param> private void OrganizePoints(ShapeEngine engine) { Document doc = PintaCore.Workspace.ActiveDocument; //Organize the generated points for quick mouse interaction detection. //First, clear the previously organized points, if any. engine.OrganizedPoints.ClearCollection(); foreach (GeneratedPoint gp in engine.GeneratedPoints) { //For each generated point on the shape, calculate the spatial hashing for it and then store this information for later usage. engine.OrganizedPoints.StoreAndOrganizePoint(new OrganizedPoint(new PointD(gp.Position.X, gp.Position.Y), gp.ControlPointIndex)); } }
/// <summary> /// Do not call. Use DrawActiveShape. /// </summary> /// <param name="engine"></param> /// <param name="dirty"></param> /// <param name="drawHoverSelection"></param> /// <param name="shiftKey"></param> private Rectangle DrawUnfinalized(ShapeEngine engine, bool drawHoverSelection, bool shiftKey) { //Not finalizing the shape; drawing it on the temporary DrawingLayer. //Calculate the hover point unless told otherwise. if (drawHoverSelection) { CalculateHoverPoint(); } else { //Do not draw the hover point. Instead, reset the hover point. NOTE: this is necessary even though the hover point //is reset later. It affects the DrawShape call. hover_point = new PointD(-1d, -1d); hovered_pt_as_control_pt = -1; } //Draw the shape onto the temporary DrawingLayer. Rectangle dirty = DrawShape(engine, engine.DrawingLayer.Layer, true, drawHoverSelection); //Reset the hover point after each drawing. hover_point = new PointD(-1d, -1d); hovered_pt_as_control_pt = -1; return dirty; }
/// <summary> /// Do not call. Use DrawActiveShape. /// </summary> /// <param name="engine"></param> /// <param name="dirty"></param> /// <param name="shiftKey"></param> private Rectangle DrawFinalized(ShapeEngine engine, bool createHistoryItem, bool shiftKey) { Document doc = PintaCore.Workspace.ActiveDocument; //Finalize the shape onto the CurrentUserLayer. ImageSurface undoSurface = null; if (createHistoryItem) { //We only need to create a history item if there was a previous shape. if (engine.ControlPoints.Count > 0) { undoSurface = doc.CurrentUserLayer.Surface.Clone(); } } //Draw the finalized shape. Rectangle dirty = DrawShape(engine, doc.CurrentUserLayer, false, false); if (createHistoryItem) { //Make sure that the undo surface isn't null. if (undoSurface != null) { //Create a new ShapesHistoryItem so that the finalization of the shape can be undone. doc.History.PushNewItem(new ShapesHistoryItem(this, owner.Icon, ShapeName + " " + Catalog.GetString("Finalized"), undoSurface, doc.CurrentUserLayer, SelectedPointIndex, SelectedShapeIndex, false)); } } return dirty; }
public override int GetHashCode() { return(this.GetType().FullName.GetHashCode() ^ ShapeEngine.GetHashCode() ^ LangEngine.GetHashCode() ^ Font.GetHashCode() ^ Level.GetHashCode() ^ Gravity.GetHashCode() ^ Flags.GetHashCode() ^ Script.GetHashCode() ^ Language.GetHashCode() ^ _extra_attrs.GetHashCode()); }
public override void UpdateToolbarSettings(ShapeEngine engine) { if (engine != null && engine.ShapeType == ShapeTypes.OpenLineCurveSeries) { if (showArrowOneBox != null) { LineCurveSeriesEngine lCSEngine = (LineCurveSeriesEngine)engine; showArrowOneBox.Active = lCSEngine.Arrow1.Show; showArrowTwoBox.Active = lCSEngine.Arrow2.Show; if (showOtherArrowOptions) { (arrowSize.ComboBox as Gtk.ComboBoxEntry).Entry.Text = lCSEngine.Arrow1.ArrowSize.ToString(); (arrowAngleOffset.ComboBox as Gtk.ComboBoxEntry).Entry.Text = lCSEngine.Arrow1.AngleOffset.ToString(); (arrowLengthOffset.ComboBox as Gtk.ComboBoxEntry).Entry.Text = lCSEngine.Arrow1.LengthOffset.ToString(); } } base.UpdateToolbarSettings(engine); } }
protected void AddRectanglePoints(bool ctrlKey, bool clickedOnControlPoint, ShapeEngine selEngine, PointD prevSelPoint) { PointD startingPoint; //Create the initial points of the shape. The second point will follow the mouse around until released. if (ctrlKey && clickedOnControlPoint) { startingPoint = prevSelPoint; clicked_without_modifying = false; } else { startingPoint = shape_origin; } selEngine.ControlPoints.Add(new ControlPoint(new PointD(startingPoint.X, startingPoint.Y), 0.0)); selEngine.ControlPoints.Add( new ControlPoint(new PointD(startingPoint.X, startingPoint.Y + .01d), 0.0)); selEngine.ControlPoints.Add( new ControlPoint(new PointD(startingPoint.X + .01d, startingPoint.Y + .01d), 0.0)); selEngine.ControlPoints.Add( new ControlPoint(new PointD(startingPoint.X + .01d, startingPoint.Y), 0.0)); SelectedPointIndex = 2; SelectedShapeIndex = SEngines.Count - 1; }
protected override void DrawExtras(ref Rectangle? dirty, Context g, ShapeEngine engine) { LineCurveSeriesEngine lCSEngine = engine as LineCurveSeriesEngine; if (lCSEngine != null && engine.ControlPoints.Count > 0) { // Draw the arrows for the currently active shape. GeneratedPoint[] genPoints = engine.GeneratedPoints; if (lCSEngine.Arrow1.Show) { if (genPoints.Length > 1) { dirty = dirty.UnionRectangles(lCSEngine.Arrow1.Draw(g, lCSEngine.OutlineColor, genPoints[0].Position, genPoints[1].Position)); } } if (lCSEngine.Arrow2.Show) { if (genPoints.Length > 1) { dirty = dirty.UnionRectangles(lCSEngine.Arrow2.Draw(g, lCSEngine.OutlineColor, genPoints[genPoints.Length - 1].Position, genPoints[genPoints.Length - 2].Position)); } } } base.DrawExtras(ref dirty, g, engine); }
public override void UpdateToolbarSettings(ShapeEngine engine) { if (engine != null && engine.ShapeType == ShapeTypes.RoundedLineSeries) { RoundedLineEngine rLEngine = (RoundedLineEngine)engine; Radius = rLEngine.Radius; base.UpdateToolbarSettings(engine); } }
public bool Equals(Analysis other) { return(true && ShapeEngine.Equals(other.ShapeEngine) && LangEngine.Equals(other.LangEngine) && Font.Equals(other.Font) && Level.Equals(other.Level) && Gravity.Equals(other.Gravity) && Flags.Equals(other.Flags) && Script.Equals(other.Script) && Language.Equals(other.Language) && _extra_attrs.Equals(other._extra_attrs)); }