예제 #1
0
        public void ApplyLayout(IImageViewer viewer, AppliedWorkspace layout)
        {
            if (layout.DisplaySets.Count != layout.WorkspaceLayout.Rows * layout.WorkspaceLayout.Columns)
            {
                throw new ArgumentException(string.Format(SR.MessageAmountOfImageBoxesMismatch, layout.DisplaySets.Count, layout.WorkspaceLayout.Rows, layout.WorkspaceLayout.Columns, layout.WorkspaceLayout.Name));
            }
            IPhysicalWorkspace workspace = viewer.PhysicalWorkspace;

            workspace.SetImageBoxGrid(layout.WorkspaceLayout.Rows, layout.WorkspaceLayout.Columns);
            var imageBoxIndex = 0;

            foreach (var displaySetLayout in layout.DisplaySets)
            {
                var imageBox = workspace.ImageBoxes[imageBoxIndex];

                imageBox.SetTileGrid(
                    displaySetLayout.Item1.TileRows,
                    displaySetLayout.Item1.TileColumns);
                if (null != displaySetLayout.Item2)
                {
                    imageBox.DisplaySet = displaySetLayout.Item2.CreateFreshCopy();
                }
                else
                {
                    imageBox.DisplaySet = null;
                }
                imageBoxIndex++;
            }
        }
        public IEnumerable <AppliedWorkspace> MakeLayouts(ILogicalWorkspace logicalWorkspace)
        {
            var primaryStudy    = logicalWorkspace.ImageViewer.StudyTree.Studies.First();
            var hangingProtocol = hangingProtocolsContainer.Value.HangingProtocols.Find(h => h.StudyFilter.Test(primaryStudy).Success);

            if (null == hangingProtocol)
            {
                throw new ArgumentException(string.Format(SR.MessageNoMatchingHangingProtocol, primaryStudy.ParentPatient, primaryStudy));
            }

            var imageSets           = GetImageSets(logicalWorkspace, hangingProtocol);
            var primaryImageSet     = imageSets.First();
            var residualDisplaySets = primaryImageSet.DisplaySets.ToList();
            var studyHasPriors      = imageSets.Count() > 1;
            var priorImageSets      = studyHasPriors ? imageSets.Skip(1) : new List <IImageSet>()
            {
                null
            };

            foreach (var iw in priorImageSets.Zip(
                         OneWorkspacesWithAndTheRestWithoutPrimary(hangingProtocol.Workspaces), (i, w) => new { Workspaces = w, priorImageSet = i }))
            {
                foreach (var workspace in iw.Workspaces)
                {
                    if (workspace.ImageBoxes.Count != workspace.Rows * workspace.Columns)
                    {
                        throw new ArgumentException(string.Format(SR.MessageAmountOfImageBoxesMismatch, workspace.ImageBoxes.Count, workspace.Rows, workspace.Columns, workspace.Name));
                    }
                    var appliedWorkspace = new AppliedWorkspace()
                    {
                        WorkspaceLayout = workspace
                    };
                    bool atLeastOneMatchingDisplaySet = false;
                    if (!studyHasPriors && workspace.ImageBoxes.Any(i => i.PriorStudy))
                    {
                        continue;
                    }

                    foreach (var imageBox in workspace.ImageBoxes)
                    {
                        var imageSet   = imageBox.PriorStudy ? iw.priorImageSet : primaryImageSet;
                        var displaySet = FindDisplaySet(hangingProtocol, imageSet, imageBox);
                        if (null != displaySet)
                        {
                            residualDisplaySets.Remove(displaySet);
                            atLeastOneMatchingDisplaySet = true;
                        }
                        else
                        {
                            displaySet = MessagePresentationImage.CreateDisplaySet(
                                string.Format(SR.MessageNoMatchingDisplaySet, imageBox.FilterName, null != imageSet ? imageSet.Name : string.Empty, workspace.Name));
                        }
                        appliedWorkspace.DisplaySets.Add(new Tuple <ImageBoxLayout, IDisplaySet>(imageBox, displaySet));
                    }
                    if (!workspace.Optional || atLeastOneMatchingDisplaySet)
                    {
                        yield return(appliedWorkspace);
                    }
                }
            }

            if (hangingProtocol.ShowResidualWorkspace && 0 != residualDisplaySets.Count)
            {
                var workspace = new WorkspaceLayout()
                {
                    Columns = hangingProtocol.ResidualWorkspaceColumns,
                    Rows    = hangingProtocol.ResidualWorkspaceRows
                };
                var residualImageBoxCount = workspace.Columns * workspace.Rows;
                var imageBox         = new ImageBoxLayout();
                var appliedWorkspace = new AppliedWorkspace()
                {
                    WorkspaceLayout = workspace
                };
                var index = 0;

                var missingImageBoxCount = residualImageBoxCount - (residualDisplaySets.Count % residualImageBoxCount);
                for (int i = 0; i < missingImageBoxCount; i++)
                {
                    residualDisplaySets.Add(null);
                }

                foreach (var displaySet in residualDisplaySets)
                {
                    appliedWorkspace.DisplaySets.Add(new Tuple <ImageBoxLayout, IDisplaySet>(imageBox, displaySet));
                    index++;
                    if (index % residualImageBoxCount == 0)
                    {
                        yield return(appliedWorkspace);

                        appliedWorkspace = new AppliedWorkspace()
                        {
                            WorkspaceLayout = workspace
                        };
                    }
                }
            }
        }