/// <summary> /// Cloning constructor. /// </summary> protected CalloutGraphic(CalloutGraphic source, ICloningContext context) : base() { context.CloneFields(source, this); }
private static IGraphic GeoShapeToGraphic(aim_dotnet.IGeometricShape geoShape, string shapeLabel) { if (geoShape.SpatialCoordinateCollection == null || geoShape.SpatialCoordinateCollection.Count == 0) return null; IGraphic graphic = null; if (geoShape is aim_dotnet.Circle) { // Ellipse var shapeCircle = geoShape as aim_dotnet.Circle; var centerPt = AsPointF(shapeCircle.Center); var radiusPt = AsPointF(shapeCircle.RadiusPoint); var radiusLength = Vector.Distance(centerPt, radiusPt); RoiGraphic roiGraphic = AimRoiGraphic.CreateEllipse(); var boundableGraphic = roiGraphic.Subject as BoundableGraphic; if (boundableGraphic != null) { roiGraphic.Suspend(); roiGraphic.Name = shapeLabel; boundableGraphic.TopLeft = new PointF((float) (centerPt.X - radiusLength), (float) (centerPt.Y - radiusLength)); boundableGraphic.BottomRight = new PointF((float) (centerPt.X + radiusLength), (float) (centerPt.Y + radiusLength)); roiGraphic.Resume(true); } graphic = roiGraphic; } else if (geoShape is aim_dotnet.Ellipse) { // Ellipse var shapeEllipse = geoShape as aim_dotnet.Ellipse; var firstMajorAxisPt = AsPointF(shapeEllipse.EllipseCollection[0]); var secondMajorAxisPt = AsPointF(shapeEllipse.EllipseCollection[1]); var firstMinorAxisPt = AsPointF(shapeEllipse.EllipseCollection[2]); var secondMinorAxisPt = AsPointF(shapeEllipse.EllipseCollection[3]); RoiGraphic roiGraphic = AimRoiGraphic.CreateEllipse(); var boundableGraphic = roiGraphic.Subject as BoundableGraphic; if (boundableGraphic != null) { roiGraphic.Suspend(); roiGraphic.Name = shapeLabel; boundableGraphic.TopLeft = new PointF(firstMajorAxisPt.X, firstMinorAxisPt.Y); boundableGraphic.BottomRight = new PointF(secondMajorAxisPt.X, secondMinorAxisPt.Y); roiGraphic.Resume(true); } graphic = roiGraphic; } else if (geoShape is aim_dotnet.Point) { var shapePoint = geoShape as aim_dotnet.Point; var callout = new CalloutGraphic(shapeLabel); callout.LineStyle = LineStyle.Solid; callout.ShowArrowhead = true; callout.AnchorPoint = AsPointF(shapePoint.Center); callout.TextLocation = callout.AnchorPoint - new SizeF(30, 30); var statefulGraphic = new StandardStatefulGraphic(callout); statefulGraphic.State = statefulGraphic.CreateInactiveState(); graphic = statefulGraphic; } else if (geoShape is aim_dotnet.MultiPoint) { // How this case works: // If we have 2 points, it's a line // If we have 3 points, it's a protractor // All others - unknown unclosed object (not supported) var shapeMultiPoint = geoShape as aim_dotnet.MultiPoint; switch (shapeMultiPoint.SpatialCoordinateCollection.Count) { case 2: { // Line var interactiveGraphic = new VerticesControlGraphic(new MoveControlGraphic(new PolylineGraphic())); var firstPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[0]); var secondPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[1]); interactiveGraphic.Subject.Points.Add(firstPt); interactiveGraphic.Subject.Points.Add(secondPt); var roiGraphic = CreateRoiGraphic(interactiveGraphic, null); roiGraphic.Name = shapeLabel; roiGraphic.Resume(true); graphic = roiGraphic; } break; case 3: { // Protractor var interactiveGraphic = new VerticesControlGraphic(new MoveControlGraphic(new ProtractorGraphic())); var firstPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[0]); var secondPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[1]); var thirdPt = AsPointF(shapeMultiPoint.SpatialCoordinateCollection[2]); interactiveGraphic.Subject.Points.Add(firstPt); interactiveGraphic.Subject.Points.Add(secondPt); interactiveGraphic.Subject.Points.Add(thirdPt); var roiGraphic = CreateRoiGraphic(interactiveGraphic, new ProtractorRoiCalloutLocationStrategy()); roiGraphic.Name = shapeLabel; roiGraphic.Resume(true); graphic = roiGraphic; } break; default: throw new NotImplementedException("Reading non-linear or non-triangular MultiPoint shape is not implemented"); } } else if (geoShape is aim_dotnet.Polyline) { var shapePolyline = geoShape as aim_dotnet.Polyline; var isRectangle = false; if (shapePolyline.SpatialCoordinateCollection.Count == 4) { var twoDPoint1 = AsPointF(shapePolyline.SpatialCoordinateCollection[0]); var twoDPoint2 = AsPointF(shapePolyline.SpatialCoordinateCollection[1]); var twoDPoint3 = AsPointF(shapePolyline.SpatialCoordinateCollection[2]); var twoDPoint4 = AsPointF(shapePolyline.SpatialCoordinateCollection[3]); if ((twoDPoint1.X == twoDPoint2.X && twoDPoint2.Y == twoDPoint3.Y && twoDPoint3.X == twoDPoint4.X && twoDPoint4.Y == twoDPoint1.Y) || (twoDPoint1.Y == twoDPoint2.Y && twoDPoint2.X == twoDPoint3.X && twoDPoint3.Y == twoDPoint4.Y && twoDPoint4.X == twoDPoint1.X)) { isRectangle = true; RoiGraphic roiGraphic = AimRoiGraphic.CreateRectangle(); var boundableGraphic = roiGraphic.Subject as BoundableGraphic; if (boundableGraphic != null) { roiGraphic.Suspend(); roiGraphic.Name = shapeLabel; boundableGraphic.TopLeft = twoDPoint1; boundableGraphic.BottomRight = twoDPoint3; roiGraphic.Resume(true); } graphic = roiGraphic; } } if (!isRectangle) { RoiGraphic roiGraphic = AimRoiGraphic.CreatePolygon(); var polylineGraphic = roiGraphic.Subject as PolylineGraphic; if (polylineGraphic != null) { roiGraphic.Suspend(); for (var i = 0; i < shapePolyline.SpatialCoordinateCollection.Count; i++) { var twoDPoint = AsPointF(shapePolyline.SpatialCoordinateCollection[i]); polylineGraphic.Points.Add(twoDPoint); } // We deal with closed polygons only if (polylineGraphic.Points.Count > 0) polylineGraphic.Points.Add(polylineGraphic.Points[0]); roiGraphic.Name = shapeLabel; roiGraphic.Resume(true); } graphic = roiGraphic; } } else throw new Exception("Unknown shape type encountered: " + geoShape.GetType().FullName); return graphic; }
private static IGraphic TextAnnotationToGraphic(aim_dotnet.TextAnnotation textAnnotation, string shapeLabel) { Platform.CheckForNullReference(textAnnotation.ConnectorPoints, "ConnectorPoints"); Platform.CheckForNullReference(textAnnotation.ConnectorPoints.SpatialCoordinateCollection, "SpatialCoordinateCollection"); Platform.CheckArgumentRange(textAnnotation.ConnectorPoints.SpatialCoordinateCollection.Count, 1, 2, "SpatialCoordinateCollection"); if (textAnnotation.ConnectorPoints == null || textAnnotation.ConnectorPoints.SpatialCoordinateCollection == null) return null; var graphicText = shapeLabel.Trim(); graphicText = string.IsNullOrEmpty(graphicText) ? textAnnotation.Text.Trim() : string.Format("{0}:\r\n{1}", graphicText, textAnnotation.Text.Trim()); switch (textAnnotation.ConnectorPoints.SpatialCoordinateCollection.Count) { case 1: { var textPrimitive = new InvariantTextPrimitive(graphicText); textPrimitive.Location = AsPointF(textAnnotation.ConnectorPoints.SpatialCoordinateCollection[0]); var statefulGraphic = new StandardStatefulGraphic(textPrimitive); statefulGraphic.State = statefulGraphic.CreateInactiveState(); return statefulGraphic; } break; case 2: { var callout = new CalloutGraphic(graphicText); callout.LineStyle = LineStyle.Solid; callout.ShowArrowhead = true; callout.AnchorPoint = AsPointF(textAnnotation.ConnectorPoints.SpatialCoordinateCollection[0]); callout.TextLocation = AsPointF(textAnnotation.ConnectorPoints.SpatialCoordinateCollection[1]); var statefulGraphic = new StandardStatefulGraphic(callout); statefulGraphic.State = statefulGraphic.CreateInactiveState(); return statefulGraphic; } break; default: break; } return null; }