public PrimitiveImage(Point location, byte[] imageData, string path, double width, double height, double rotation, CadColor?color = null) { Location = location; ImageData = imageData ?? throw new ArgumentNullException(nameof(imageData)); Path = path ?? throw new ArgumentNullException(nameof(path)); Width = width; Height = height; Rotation = rotation; Color = color; var radians = Rotation * MathHelper.DegreesToRadians; var upVector = new Vector(-Math.Sin(radians) * Height, Math.Cos(radians) * Height, 0.0); var rightVector = new Vector(Math.Cos(radians) * Width, Math.Sin(radians) * Width, 0.0); var bottomLeft = Location; var bottomRight = bottomLeft + rightVector; var topLeft = bottomLeft + upVector; var topRight = bottomRight + upVector; _boundaryLines = new[] { new PrimitiveLine(bottomLeft, bottomRight, Color), new PrimitiveLine(bottomRight, topRight, Color), new PrimitiveLine(topRight, topLeft, Color), new PrimitiveLine(topLeft, bottomLeft, Color), }; _boundingBox = BoundingBox.FromPoints(bottomLeft, bottomRight, topLeft, topRight); }
public static DxfColor ToDxfColor(this CadColor?color) { if (color == null) { return(DxfColor.ByLayer); } else { // find the index of the matching default color int i; for (i = 0; i < DxfColor.DefaultColors.Count; i++) { if (color.Value.ToUInt32() == DxfColor.DefaultColors[i]) { break; } } if (i < 256) { return(DxfColor.FromIndex((byte)i)); } else { // TODO: find closest matching color? return(DxfColor.ByLayer); } } }
public Polyline(IEnumerable <Vertex> vertices, CadColor?color = null, object tag = null) : base(color, tag) { var vertexList = new List <Vertex>(vertices); // to prevent backing changes Vertices = vertexList; if (vertexList.Count < 2) { throw new ArgumentOutOfRangeException(nameof(vertices)); } // walk all vertices and compute primitives and snap points _primitives = new List <IPrimitive>(); _snapPoints = new List <SnapPoint>(); var last = vertexList[0]; _snapPoints.Add(new EndPoint(last.Location)); for (int i = 1; i < vertexList.Count; i++) { var current = vertexList[i]; var primitive = Vertex.PrimitiveFromPointAndVertex(last.Location, current); _primitives.Add(primitive); _snapPoints.Add(new MidPoint(primitive.MidPoint())); _snapPoints.Add(new EndPoint(current.Location)); last = current; } BoundingBox = BoundingBox.FromPoints(_snapPoints.Select(sp => sp.Point).ToArray()); }
private Entity UpdateColor(Entity entity, CadColor?newColor) { switch (entity.Kind) { case EntityKind.Aggregate: return(((AggregateEntity)entity).Update(color: newColor)); case EntityKind.Arc: return(((Arc)entity).Update(color: newColor)); case EntityKind.Circle: return(((Circle)entity).Update(color: newColor)); case EntityKind.Ellipse: return(((Ellipse)entity).Update(color: newColor)); case EntityKind.Line: return(((Line)entity).Update(color: newColor)); case EntityKind.Location: return(((Location)entity).Update(color: newColor)); case EntityKind.Polyline: return(((Polyline)entity).Update(color: newColor)); case EntityKind.Text: return(((Text)entity).Update(color: newColor)); default: throw new InvalidOperationException("Unsupported entity type"); } }
public Layer(string name, ReadOnlyTree <uint, Entity> entities = null, CadColor?color = null, bool isVisible = true) { this.name = name; this.color = color; this.isVisible = isVisible; this.entities = entities ?? new ReadOnlyTree <uint, Entity>(); }
public MutableLayerViewModel(Layer layer) { this.layer = layer; this.name = layer.Name; this.color = layer.Color; this.isVisible = layer.IsVisible; }
public PrimitiveLine(Point p1, Point p2, CadColor?color = null, double thickness = default(double)) { this.P1 = p1; this.P2 = p2; this.Color = color; this.Thickness = thickness; }
public ClientEllipse(double startAngle, double endAngle, double[] transform, CadColor?color) { StartAngle = startAngle; EndAngle = endAngle; Transform = transform; Color = color; }
private void DrawEntity(Graphics graphics, ProjectedEntity entity, CadColor?layerColor, Vector offset = default(Vector)) { switch (entity.Kind) { case EntityKind.Line: DrawEntity(graphics, (ProjectedLine)entity, layerColor, offset); break; case EntityKind.Circle: case EntityKind.Ellipse: DrawEntity(graphics, (ProjectedCircle)entity, layerColor, offset); break; case EntityKind.Text: DrawEntity(graphics, (ProjectedText)entity, layerColor, offset); break; case EntityKind.Aggregate: var ag = (ProjectedAggregate)entity; foreach (var child in ag.Children) { DrawEntity(graphics, child, layerColor, offset + ag.Location); } break; default: break; } }
private void DrawEntity(Graphics graphics, ProjectedText text, CadColor?layerColor, Vector offset) { // TODO: handle rotation var x = (float)(text.Location.X + offset.X); var y = (float)(text.Location.Y - text.Height + offset.Y); graphics.DrawString(text.OriginalText.Value, SystemFonts.DefaultFont, ColorToBrush(text.OriginalText.Color ?? layerColor ?? autoColor), x, y); }
public ClientText(string text, ClientPoint location, double height, double rotationAngle, CadColor?color) { Text = text; Location = location; Height = height; RotationAngle = rotationAngle; Color = color; }
public static void AssignColor(this IgesEntity entity, CadColor?color) { entity.Color = color.ToIgesColor(); if (entity.Color == IgesColorNumber.Custom) { Debug.Assert(color != null); entity.CustomColor = new IgesColorDefinition(color.GetValueOrDefault().R / 255.0, color.GetValueOrDefault().G / 255.0, color.GetValueOrDefault().B / 255.0); } }
private void DrawEntity(Graphics graphics, ProjectedCircle circle, CadColor?layerColor, Vector offset) { // TODO: handle rotation var width = circle.RadiusX * 2.0; var height = circle.RadiusY * 2.0; var topLeft = (Point)(circle.Center - new Point(circle.RadiusX, circle.RadiusX, 0.0) + offset); graphics.DrawEllipse(ColorToPen(GetDisplayColor(layerColor, circle.OriginalCircle.Color)), (float)topLeft.X, (float)topLeft.Y, (float)width, (float)height); }
public PrimitiveBezier(Point p1, Point p2, Point p3, Point p4, CadColor?color = null) { P1 = p1; P2 = p2; P3 = p3; P4 = p4; Color = color; _intersectionPrimitives = new Lazy <IPrimitive[]>(() => AsSimplePrimitives(this)); }
private Grid CreatePrimitivePoint(PrimitivePoint point, CadColor?color) { const double size = 0.5; var loc = PlaneProjection.Transform(point.Location); var path = new Path() { Data = new GeometryGroup() { Children = new GeometryCollection() { new PathGeometry() { Figures = new PathFigureCollection() { new PathFigure() { StartPoint = new DisplayPoint(-size, 0.0), Segments = new PathSegmentCollection() { new LineSegment() { Point = new DisplayPoint(size, 0.0) } } }, new PathFigure() { StartPoint = new DisplayPoint(0.0, -size), Segments = new PathSegmentCollection() { new LineSegment() { Point = new DisplayPoint(0.0, size) } } }, } } } }, StrokeThickness = 1.0 / PointSize }; SetBinding(path, "Scale", Path.RenderTransformProperty); SetColor(path, color); var grid = new Grid(); grid.Children.Add(path); grid.RenderTransform = new TranslateTransform() { X = loc.X, Y = loc.Y }; return(grid); }
public ClientImage(Point location, string base64ImageData, string path, double width, double height, double rotation, CadColor?color = null) { Location = location; Base64ImageData = base64ImageData; Path = path; Width = width; Height = height; Rotation = rotation; Color = color; }
private void AddPrimitive(IPrimitive prim, CadColor?color, Entity containingEntity, PrimitiveKind supported, Canvas canvas) { FrameworkElement element = null; switch (prim.Kind) { case PrimitiveKind.Ellipse: if ((supported & PrimitiveKind.Ellipse) == PrimitiveKind.Ellipse) { element = CreatePrimitiveEllipse((PrimitiveEllipse)prim, color); } break; case PrimitiveKind.Line: if ((supported & PrimitiveKind.Line) == PrimitiveKind.Line) { element = CreatePrimitiveLine((PrimitiveLine)prim, color); } break; case PrimitiveKind.Point: if ((supported & PrimitiveKind.Point) == PrimitiveKind.Point) { element = CreatePrimitivePoint((PrimitivePoint)prim, color); } break; case PrimitiveKind.Text: if ((supported & PrimitiveKind.Text) == PrimitiveKind.Text) { element = CreatePrimitiveText((PrimitiveText)prim, color); } break; default: throw new NotImplementedException(); } if (element != null) { element.Tag = containingEntity; canvas.Children.Add(element); if (containingEntity != null) { if (!entityMap.ContainsKey(containingEntity.Id)) { entityMap.Add(containingEntity.Id, new List <FrameworkElement>()); } entityMap[containingEntity.Id].Add(element); } } }
private Shapes.Line CreatePrimitiveLine(PrimitiveLine line, CadColor?color) { var p1 = PlaneProjection.Transform(line.P1); var p2 = PlaneProjection.Transform(line.P2); var newLine = new Shapes.Line() { X1 = p1.X, Y1 = p1.Y, X2 = p2.X, Y2 = p2.Y }; SetThicknessBinding(newLine); SetColor(newLine, color); return(newLine); }
private void SetColor(FrameworkElement element, DependencyProperty property, CadColor?color) { if (color == null) { SetBinding(element, "AutoBrush", property); } else { var uicolor = ColorOverride.HasValue ? ColorOverride.GetValueOrDefault().ToUIColor() : Color.FromArgb(color.Value.A, color.Value.R, color.Value.G, color.Value.B); element.SetValue(property, new SolidColorBrush(uicolor)); } }
public PrimitiveLine(Point p1, double slope, CadColor?color = null) { this.P1 = p1; if (double.IsNaN(slope)) { // vertical this.P2 = new Point(p1.X, p1.Y + 1.0, p1.Z); } else { this.P2 = this.P1 + new Vector(1.0, slope, 0.0); } this.Color = color; }
public static void AssignDxfEntityColor(this DxfEntity dxfEntity, CadColor?color) { dxfEntity.Color = color.ToDxfColor(); if (dxfEntity.Color == DxfColor.ByLayer && color.HasValue) { // specified color not found in color table dxfEntity.Color24Bit = color.GetValueOrDefault().ToInt32(); dxfEntity.ColorName = "Custom"; } else { dxfEntity.Color24Bit = 0; dxfEntity.ColorName = null; } }
private static ClientPropertyPaneValue GetEntityColorValue(CadColor?currentColor, bool isUnrepresentable = false) { return(ClientPropertyPaneValue.CreateForEntity <Entity>("color", "Color", currentColor.ToPropertyColorString(), (entity, colorString) => { CadColor?newColor = colorString == null ? null : CadColor.Parse(colorString); if (entity.Color == newColor) { // no change return null; } var updatedEntity = entity.WithColor(newColor); return updatedEntity; }, isUnrepresentable: isUnrepresentable)); }
public static Entity WithColor(this Entity entity, CadColor?color) { return(entity.MapEntity <Entity>( aggregate => aggregate.Update(color: color), arc => arc.Update(color: color), circle => circle.Update(color: color), ellipse => ellipse.Update(color: color), image => image.Update(color: color), line => line.Update(color: color), location => location.Update(color: color), polyline => polyline.Update(color: color), spline => spline.Update(color: color), text => text.Update(color: color) )); }
private static void AddFillIfNotDefault(XElement xml, CadColor?color) { if (color.HasValue) { var stroke = xml.Attribute("fill"); var colorString = color.Value.ToRGBString(); if (stroke == null) { // add new attribute xml.Add(new XAttribute("fill", colorString)); } else { // replace attribute stroke.Value = colorString; } } }
public AggregateEntity(Point location, ReadOnlyList <Entity> children, CadColor?color = null, object tag = null) : base(color, tag) { if (children == null) { throw new ArgumentNullException("children"); } this.location = location; this.children = children; if (children.Any(c => c.Kind == EntityKind.Aggregate)) { throw new ArgumentOutOfRangeException("children", "Aggregate entities cannot contain other aggregate entities"); } var offset = (Vector)location; this.primitives = children.SelectMany(c => c.GetPrimitives().Select(p => p.Move(offset))).ToArray(); this.snapPoints = children.SelectMany(c => c.GetSnapPoints().Select(p => p.Move(offset))).ToArray(); this.boundingBox = BoundingBox.Includes(children.Select(c => c.BoundingBox)); }
public static IgesColorNumber ToIgesColor(this CadColor?color) { if (color == null) { return(IgesColorNumber.Default); } else { switch (color.GetValueOrDefault().ToInt32() & 0xFFFFFF) { case 0x000000: return(IgesColorNumber.Black); case 0xFF0000: return(IgesColorNumber.Red); case 0xFFFF00: return(IgesColorNumber.Yellow); case 0x00FF00: return(IgesColorNumber.Green); case 0x00FFFF: return(IgesColorNumber.Cyan); case 0x0000FF: return(IgesColorNumber.Blue); case 0xFF00FF: return(IgesColorNumber.Magenta); case 0xFFFFFF: return(IgesColorNumber.White); default: return(IgesColorNumber.Custom); } } }
private TextBlock CreatePrimitiveText(PrimitiveText text, CadColor?color) { var location = PlaneProjection.Transform(text.Location); var t = new TextBlock(); t.Text = text.Value; t.FontFamily = new FontFamily("Consolas"); t.FontSize = text.Height * 0.75; // 0.75 = 72ppi/96dpi var trans = new TransformGroup(); trans.Children.Add(new ScaleTransform() { ScaleX = 1, ScaleY = -1 }); trans.Children.Add(new RotateTransform() { Angle = text.Rotation, CenterX = 0, CenterY = -text.Height }); t.RenderTransform = trans; Canvas.SetLeft(t, location.X); Canvas.SetTop(t, location.Y + text.Height); SetColor(t, TextBlock.ForegroundProperty, color); return(t); }
public Location(Point location, CadColor?color = null, object tag = null) : this(new PrimitivePoint(location, color), tag) { }
public Layer(string name, IEnumerable <Entity> entities, CadColor?color = null, bool isVisible = true) : this(name, ReadOnlyTree <uint, Entity> .FromEnumerable(entities, (ent) => ent.Id), color, isVisible) { }
public Circle(Point center, double radius, Vector normal, CadColor?color = null, object tag = null, double thickness = default(double)) : this(new PrimitiveEllipse(center, radius, normal, color, thickness), tag) { }