예제 #1
0
        private static void UpdateColor(IGraphic graphic, Color color)
        {
            StandardStatefulGraphic statefulGraphic = graphic as StandardStatefulGraphic;

            if (statefulGraphic != null)
            {
                statefulGraphic.InactiveColor = color;
            }

            if (graphic is IControlGraphic)
            {
                IControlGraphic controlGraphic = (IControlGraphic)graphic;
                controlGraphic.Color = color;
            }
            else if (graphic is IVectorGraphic)
            {
                ((IVectorGraphic)graphic).Color = color;
            }

            if (graphic is CompositeGraphic)
            {
                foreach (IGraphic childGraphic in ((CompositeGraphic)graphic).Graphics)
                {
                    UpdateColor(childGraphic, color);
                }
            }
        }
            protected override void Dispose(bool disposing)
            {
                _owner               = null;
                _lineGraphic         = null;
                _sliceControlGraphic = null;
                _stateControlGraphic = null;

                base.Dispose(disposing);
            }
예제 #3
0
        private static IControlGraphic CreateTextAreaGraphic()
        {
            InvariantTextPrimitive textArea       = new InvariantTextPrimitive();
            TextEditControlGraphic controlGraphic = new TextEditControlGraphic(new MoveControlGraphic(textArea));

            controlGraphic.DeleteOnEmpty = true;

            StandardStatefulGraphic statefulGraphic = new StandardStatefulGraphic(controlGraphic);

            statefulGraphic.State = statefulGraphic.CreateInactiveState();

            ContextMenuControlGraphic contextGraphic = new ContextMenuControlGraphic(typeof(TextCalloutTool).FullName, "basicgraphic-menu", null, statefulGraphic);

            contextGraphic.Actions = new ToolSet(new GraphicToolExtensionPoint(), new GraphicToolContext(contextGraphic)).Actions;

            return(contextGraphic);
        }
예제 #4
0
        private static IControlGraphic CreateTextCalloutGraphic()
        {
            UserCalloutGraphic callout = new UserCalloutGraphic();

            callout.LineStyle     = LineStyle.Solid;
            callout.ShowArrowhead = true;

            StandardStatefulGraphic statefulGraphic = new StandardStatefulGraphic(callout);

            statefulGraphic.State = statefulGraphic.CreateInactiveState();

            /// TODO (CR Oct 2011): This is the wrong order - the "selected" graphic (stateful) gets
            /// deleted by the "delete graphics" tool, and then the top-level context menu
            /// graphic gets left dangling.
            ContextMenuControlGraphic contextGraphic = new ContextMenuControlGraphic(typeof(TextCalloutTool).FullName, "basicgraphic-menu", null, statefulGraphic);

            contextGraphic.Actions = new ToolSet(new GraphicToolExtensionPoint(), new GraphicToolContext(contextGraphic)).Actions;

            return(contextGraphic);
        }
            public ResliceToolGraphic(ResliceTool owner)
            {
                LineGraphic           lineGraphic        = new LineGraphic();
                MprMoveControlGraphic moveControlGraphic = new MprMoveControlGraphic(lineGraphic);

                moveControlGraphic.UndoableOperationStart  += OnControlGraphicUndoableOperationStart;
                moveControlGraphic.UndoableOperationStop   += OnControlGraphicUndoableOperationStop;
                moveControlGraphic.UndoableOperationCancel += OnControlGraphicUndoableOperationCancel;
                MprLineStretchControlGraphic lineControlGraphic = new MprLineStretchControlGraphic(moveControlGraphic);

                lineControlGraphic.UndoableOperationStart  += OnControlGraphicUndoableOperationStart;
                lineControlGraphic.UndoableOperationStop   += OnControlGraphicUndoableOperationStop;
                lineControlGraphic.UndoableOperationCancel += OnControlGraphicUndoableOperationCancel;
                SliceControlGraphic     sliceControlGraphic = new SliceControlGraphic(lineControlGraphic, this);
                StandardStatefulGraphic statefulGraphic     = new StandardStatefulGraphic(sliceControlGraphic);

                statefulGraphic.State = statefulGraphic.CreateInactiveState();
                base.Graphics.Add(statefulGraphic);

                _stateControlGraphic = statefulGraphic;
                _sliceControlGraphic = sliceControlGraphic;
                _lineGraphic         = lineGraphic;
                _owner = owner;
            }
예제 #6
0
        private static IGraphic CreateCalloutText(RectangleF annotationBounds, RectangleF displayedArea, GraphicAnnotationSequenceItem.TextObjectSequenceItem textItem)
        {
            if (textItem.AnchorPoint.HasValue)
            {
                CalloutGraphic callout = new CalloutGraphic(textItem.UnformattedTextValue);

                PointF anchor = textItem.AnchorPoint.Value;
                if (textItem.AnchorPointAnnotationUnits == GraphicAnnotationSequenceItem.AnchorPointAnnotationUnits.Display)
                {
                    anchor = GetPointInSourceCoordinates(displayedArea, anchor);
                }

                callout.AnchorPoint   = anchor;
                callout.ShowArrowhead = annotationBounds.IsEmpty;                 // show arrowhead if graphic annotation bounds are empty

                if (textItem.BoundingBoxTopLeftHandCorner.HasValue && textItem.BoundingBoxBottomRightHandCorner.HasValue)
                {
                    PointF topLeft     = textItem.BoundingBoxTopLeftHandCorner.Value;
                    PointF bottomRight = textItem.BoundingBoxBottomRightHandCorner.Value;

                    if (textItem.BoundingBoxAnnotationUnits == GraphicAnnotationSequenceItem.BoundingBoxAnnotationUnits.Display)
                    {
                        topLeft     = GetPointInSourceCoordinates(displayedArea, topLeft);
                        bottomRight = GetPointInSourceCoordinates(displayedArea, bottomRight);
                    }

                    callout.TextLocation = Vector.Midpoint(topLeft, bottomRight);
                }
                else
                {
                    if (!annotationBounds.IsEmpty)
                    {
                        callout.TextLocation = annotationBounds.Location - new SizeF(30, 30);
                    }
                    else
                    {
                        callout.TextLocation = anchor - new SizeF(30, 30);
                    }
                }

                StandardStatefulGraphic statefulCallout = new StandardStatefulGraphic(callout);
                statefulCallout.InactiveColor = Color.LemonChiffon;
                statefulCallout.State         = statefulCallout.CreateInactiveState();
                return(statefulCallout);
            }
            else if (textItem.BoundingBoxTopLeftHandCorner.HasValue && textItem.BoundingBoxBottomRightHandCorner.HasValue)
            {
                InvariantTextPrimitive text = new InvariantTextPrimitive(textItem.UnformattedTextValue);
                PointF topLeft     = textItem.BoundingBoxTopLeftHandCorner.Value;
                PointF bottomRight = textItem.BoundingBoxBottomRightHandCorner.Value;

                if (textItem.BoundingBoxAnnotationUnits == GraphicAnnotationSequenceItem.BoundingBoxAnnotationUnits.Display)
                {
                    topLeft     = GetPointInSourceCoordinates(displayedArea, topLeft);
                    bottomRight = GetPointInSourceCoordinates(displayedArea, bottomRight);
                }

                // TODO: make the text variant - rotated as specified by bounding area - as well as justified as requested
                // RectangleF boundingBox = RectangleF.FromLTRB(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y);
                // boundingBox = RectangleUtilities.ConvertToPositiveRectangle(boundingBox);
                // boundingBox.Location = boundingBox.Location - new SizeF(1, 1);
                text.Location = Vector.Midpoint(topLeft, bottomRight);

                return(text);
            }
            else
            {
                throw new InvalidDataException("The GraphicAnnotationSequenceItem must define either an anchor point or a bounding box.");
            }
        }
예제 #7
0
        internal static List <IGraphic> PopulateImageViewerWithSavedMarkup(List <IMarkup> markupList, IImageViewer imageViewer)
        {
            var graphics = new List <IGraphic>();

            foreach (var markup in markupList)
            {
                foreach (var box in imageViewer.PhysicalWorkspace.ImageBoxes)
                {
                    if (box.DisplaySet == null)
                    {
                        continue;
                    }

                    var imageSop =
                        box.DisplaySet.PresentationImages.Cast <IImageSopProvider>().FirstOrDefault(
                            pi => pi.ImageSop.SopInstanceUid == markup.PresentationImageUid && pi.Frame.FrameNumber == markup.FrameNumber);

                    var selectedPresentationImage = imageSop as IPresentationImage;
                    if (selectedPresentationImage == null)
                    {
                        continue;
                    }

                    var graphicsProvider = selectedPresentationImage as IOverlayGraphicsProvider;
                    if (graphicsProvider != null)
                    {
                        if (markup is MarkupEllipse)
                        {
                            var markupEllipse    = (MarkupEllipse)markup;
                            var ellipsePrimitive = new EllipsePrimitive();
                            var roiGraphic       = new RoiGraphic(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(
                                                                                                        new MoveControlGraphic(ellipsePrimitive))));
                            var boundableGraphic = roiGraphic.Subject as BoundableGraphic;

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            if (boundableGraphic != null)
                            {
                                roiGraphic.Suspend();                                 // prevent callout location calculation until all points are set
                                roiGraphic.Name = markup.Name;
                                ellipsePrimitive.BottomRight = markupEllipse.BottomRight;
                                ellipsePrimitive.TopLeft     = markupEllipse.TopLeft;
                                roiGraphic.State             = roiGraphic.CreateInactiveState();
                                roiGraphic.Resume(true);                                 // Force callout location calculation
                                roiGraphic.Callout.TextLocation = markupEllipse.CalloutLocation;
                            }
                        }
                        else if (markup is MarkupPolygonal)
                        {
                            var markupPolygon = (MarkupPolygonal)markup;

                            var polyline = new PolylineGraphic(true);
                            foreach (var point in markupPolygon.Vertices)
                            {
                                polyline.Points.Add(point);
                            }
                            var roiGraphic = new RoiGraphic(new PolygonControlGraphic(true, new MoveControlGraphic(polyline)));

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            //if (boundableGraphic != null)
                            {
                                roiGraphic.Suspend();                                 // prevent callout location calculation until all points are set
                                roiGraphic.Name  = markup.Name;
                                roiGraphic.State = roiGraphic.CreateInactiveState();
                                roiGraphic.Resume(true);                                 // Force callout location calculation
                                roiGraphic.Callout.TextLocation = markupPolygon.CalloutLocation;
                            }
                        }
                        else if (markup is MarkupRectangle)
                        {
                            var markupRectangle    = (MarkupRectangle)markup;
                            var rectanglePrimitive = new RectanglePrimitive();
                            var roiGraphic         = new RoiGraphic(new BoundableResizeControlGraphic(new BoundableStretchControlGraphic(
                                                                                                          new MoveControlGraphic(rectanglePrimitive))));
                            var boundableGraphic = roiGraphic.Subject as BoundableGraphic;

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            if (boundableGraphic != null)
                            {
                                roiGraphic.Suspend();                                 // prevent callout location calculation until all points are set
                                roiGraphic.Name = markup.Name;
                                rectanglePrimitive.BottomRight = markupRectangle.BottomRight;
                                rectanglePrimitive.TopLeft     = markupRectangle.TopLeft;
                                roiGraphic.State = roiGraphic.CreateInactiveState();
                                roiGraphic.Resume(true);                                 // Force callout location calculation
                                roiGraphic.Callout.TextLocation = markupRectangle.CalloutLocation;
                            }
                        }
                        else if (markup is MarkupProtractor)
                        {
                            var markupProtractor = (MarkupProtractor)markup;

                            var protractorGraphic = new ProtractorGraphic();
                            foreach (var point in markupProtractor.Points)
                            {
                                protractorGraphic.Points.Add(point);
                            }
                            var roiGraphic = new RoiGraphic(new VerticesControlGraphic(new MoveControlGraphic(protractorGraphic)));

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            roiGraphic.Suspend();                             // prevent callout location calculation until all points are set
                            roiGraphic.Name  = markup.Name;
                            roiGraphic.State = roiGraphic.CreateInactiveState();
                            roiGraphic.Resume(true);                             // Force callout location calculation
                            roiGraphic.Callout.TextLocation = markupProtractor.CalloutLocation;
                        }
                        else if (markup is MarkupLinear)
                        {
                            var markupLinear = (MarkupLinear)markup;

                            var polylineGraphic = new PolylineGraphic();
                            foreach (var point in markupLinear.Vertices)
                            {
                                polylineGraphic.Points.Add(point);
                            }
                            var roiGraphic = new RoiGraphic(new VerticesControlGraphic(new MoveControlGraphic(polylineGraphic)));

                            markup.GraphicHashcode = roiGraphic.GetHashCode();
                            graphics.Add(roiGraphic);
                            graphicsProvider.OverlayGraphics.Add(roiGraphic);

                            roiGraphic.Suspend();                             // prevent callout location calculation until all points are set
                            roiGraphic.Name  = markup.Name;
                            roiGraphic.State = roiGraphic.CreateInactiveState();
                            roiGraphic.Resume(true);                             // Force callout location calculation
                            roiGraphic.Callout.TextLocation = markupLinear.CalloutLocation;
                        }
                        else if (markup is MarkupPoint)
                        {
                            var markupPoint = (MarkupPoint)markup;

                            IGraphic calloutGraphic;
                            if (markupPoint.UseCrosshair)
                            {
                                calloutGraphic = new UserCrosshairCalloutGraphic
                                {
                                    AnchorPoint  = markupPoint.Point,
                                    TextLocation = markupPoint.CalloutLocation,
                                    Text         = markupPoint.CalloutText,
                                    ShowShaft    = !String.IsNullOrEmpty(markupPoint.CalloutText),
                                    LineStyle    = LineStyle.Dot
                                };
                            }
                            else
                            {
                                calloutGraphic = new UserCalloutGraphic
                                {
                                    AnchorPoint   = markupPoint.Point,
                                    TextLocation  = markupPoint.CalloutLocation,
                                    Text          = markupPoint.CalloutText,
                                    ShowArrowhead = true,
                                    LineStyle     = LineStyle.Solid
                                };
                            }

                            var statefulGraphic = new StandardStatefulGraphic(calloutGraphic);
                            statefulGraphic.State = statefulGraphic.CreateInactiveState();

                            var contextGraphic = new ContextMenuControlGraphic(typeof(ClearCanvas.ImageViewer.Tools.Standard.TextCalloutTool).FullName, "basicgraphic-menu", null, statefulGraphic);
                            contextGraphic.Actions = new ToolSet(new GraphicToolExtensionPoint(), new GraphicToolContext(contextGraphic)).Actions;

                            //if (markupPoint.Name != "RemoveForCalloutPlacement")
                            {
                                markup.GraphicHashcode = contextGraphic.GetHashCode();
                                graphics.Add(contextGraphic);
                                graphicsProvider.OverlayGraphics.Add(contextGraphic);
                                //selectedPresentationImage.Draw();
                            }
                        }
                    }

                    box.TopLeftPresentationImage = selectedPresentationImage;
                    box.Tiles[0].Select();
                    box.Draw();

                    break;
                }
            }
            return(graphics);
        }