private void FireStudyAnnotationsChanged(StudyAimAnnotationsChangedEventArgs e)
 {
     if (!_disposed)
     {
         EventsHelper.Fire(_studyAnnotationsChanged, this, e);
     }
 }
 private void OnStudyAnnotationsChanged(object sender, StudyAimAnnotationsChangedEventArgs args)
 {
     if (_synchronizationContext != null)
     {
         _synchronizationContext.Post(ignore => FireStudyAnnotationsChanged(args), null);
     }
     else
     {
         FireStudyAnnotationsChanged(args);
     }
 }
 private void OnStudyAnnotationsChanged(object sender, StudyAimAnnotationsChangedEventArgs args)
 {
     if (_synchronizationContext != null)
         _synchronizationContext.Post(ignore => FireStudyAnnotationsChanged(args), null);
     else
         FireStudyAnnotationsChanged(args);
 }
 private void FireStudyAnnotationsChanged(StudyAimAnnotationsChangedEventArgs e)
 {
     if (!_disposed)
         EventsHelper.Fire(_studyAnnotationsChanged, this, e);
 }
        private void OnStudyAnnotationsChanged(object sender, StudyAimAnnotationsChangedEventArgs studyAimAnnotationsChangedEventArgs)
        {
            var imageViewer = Context.Viewer;
            if (imageViewer != null)
            {
                // 1. Remove deleted AIM Annotations from displayed images
                // 2. Add new AIM Annotations to displayed images
                AimGraphicHelpers.ImageViewerImageOperation(imageViewer, false, image =>
                {
                    var imageSop = image as IImageSopProvider;
                    if (imageSop != null && imageSop.ImageSop.StudyInstanceUid != studyAimAnnotationsChangedEventArgs.StudyInstanceUid)
                        return false;

                    var overlayGraphicsProvider = image as IOverlayGraphicsProvider;
                    if (overlayGraphicsProvider == null)
                        return false;

                    var aimGraphics = overlayGraphicsProvider.OverlayGraphics.OfType<IAimGraphic>().ToList();

                    bool graphicsUpdated = false;

                    // Remove deleted annotations
                    if (aimGraphics.Any() && studyAimAnnotationsChangedEventArgs.RemovedAnnotations != null)
                    {
                        var graphicsToDelete =
                            aimGraphics.Where(
                                aimGraphic =>
                                studyAimAnnotationsChangedEventArgs.RemovedAnnotations.Any(
                                    aimDocumentInstance => aimDocumentInstance.SopInstanceUid == aimGraphic.AimAnnotation.ParentAimDocument.SopInstanceUid)).ToList();
                        foreach (var aimGraphic in graphicsToDelete)
                        {
                            overlayGraphicsProvider.OverlayGraphics.Remove(aimGraphic);
                            graphicsUpdated = true;
                        }
                    }

                    // Add new annotations
                    foreach (var aimDocumentInstance in studyAimAnnotationsChangedEventArgs.AddedAnnotations)
                    {
                        // This check is needed while we're not 100% sure that AIM caching works correctly
                        if (aimGraphics.All(aimGraphic => aimDocumentInstance.SopInstanceUid != aimGraphic.AimAnnotation.ParentAimDocument.SopInstanceUid))
                        {
                            AimManager.AimManager.Instance.ReadGraphicsFromAnnotation(aimDocumentInstance, image);
                            graphicsUpdated = true;
                        }
                    }

                    if (graphicsUpdated && image.ParentDisplaySet.ImageBox.TopLeftPresentationImage == image)
                        image.ParentDisplaySet.ImageBox.Draw(); // TODO - check that we are on the UI thread

                    return graphicsUpdated;
                }, true);
            }

            // NOTE: sending new AIM SOP Instances to the original server where the study came from was done by DicomPublishingHelper
        }