using System; using System.Text; using ClearCanvas.Common; using ClearCanvas.Desktop; using ClearCanvas.Desktop.Actions; using ClearCanvas.Dicom; using ClearCanvas.Dicom.Iod; using ClearCanvas.ImageViewer; using ClearCanvas.ImageViewer.BaseTools; using ClearCanvas.ImageViewer.Graphics; using ClearCanvas.ImageViewer.Imaging; using ClearCanvas.ImageViewer.PresentationStates; using ClearCanvas.ImageViewer.PresentationStates.Dicom; namespace Nullstack.ClearCanvas.ImageViewerTools { [MenuAction("save", "global-menus/mnDebug/mnImageViewer/mnDumpDicomSceneGraph", "Dump")] [ExtensionOf(typeof(ImageViewerToolExtensionPoint))] internal class DicomGraphicsPlaneDumpTool : ImageViewerTool { public void Dump() { StringBuilder sb = new StringBuilder(); sb.AppendLine(); try { DicomGraphicsPlane dgp = DicomGraphicsPlane.GetDicomGraphicsPlane((IDicomPresentationImage) base.SelectedPresentationImage, false); Dump(dgp, sb, string.Empty); } catch(Exception ex) { sb.AppendLine(string.Format("Dump Failed with Exception {0}", ex.Message)); } Platform.Log(LogLevel.Info, "The following three FATAL-level log entries are for debugging purposes. It does not indicate an error."); Platform.Log(LogLevel.Fatal, "BEGIN DUMPING DICOM SCENE GRAPH"); Platform.Log(LogLevel.Fatal, sb.ToString()); Platform.Log(LogLevel.Fatal, "END DUMPING DICOM SCENE GRAPH"); Platform.Log(LogLevel.Info, "The preceding three FATAL-level log entries were for debugging purposes. It does not indicate an error."); } private void Dump(DicomGraphicsPlane dgp, StringBuilder sb, string indent) { if(dgp == null) { sb.AppendLine(string.Format("{0}DicomGraphicsPlane: null", indent)); } else { string nextIndent = indent + "+--"; sb.AppendLine(string.Format("{0}DicomGraphicsPlane", indent)); sb.AppendLine(string.Format("{0}Shutters", nextIndent)); Dump(dgp.Shutters as IGraphic, sb, nextIndent + "+--"); sb.AppendLine(string.Format("{0}Layers", nextIndent)); Dump(dgp.Layers as IGraphic, sb, nextIndent + "+--"); } } private void Dump(IGraphic g, StringBuilder sb, string indent) { if (g is OverlayPlaneGraphic) { sb.AppendLine(string.Format("{0}OVERLAY: {1}", indent, ((OverlayPlaneGraphic) g).Description)); sb.AppendLine(string.Format("{0}Source={1} #{2}", indent + "+--", ((OverlayPlaneGraphic) g).Source, ((OverlayPlaneGraphic) g).Index)); sb.AppendLine(string.Format("{0}Group=0x{1:x4}", indent + "+--", ((OverlayPlaneGraphic) g).Index*2 + 0x6000)); sb.AppendLine(string.Format("{0}Visible={1}", indent + "+--", g.Visible)); } else if (g is IShutterGraphic) { sb.AppendLine(string.Format("{0}SHUTTER: {1}", indent, g.GetType().Name)); sb.AppendLine(string.Format("{0}Visible={1}", indent + "+--", g.Visible)); } else if (g is ILayer) { sb.AppendLine(string.Format("{0}LAYER: {1}", indent, ((ILayer) g).Id)); sb.AppendLine(string.Format("{0}Visible={1}", indent + "+--", g.Visible)); foreach (IGraphic graphic in ((ILayer) g).Graphics) Dump(graphic, sb, indent + "+--"); } else if (g is IDicomGraphicsPlaneShutters) { foreach (IGraphic graphic in ((CompositeGraphic) g).Graphics) Dump(graphic, sb, indent); } else if (g is IDicomGraphicsPlaneLayers) { foreach (IGraphic graphic in ((CompositeGraphic) g).Graphics) Dump(graphic, sb, indent); } else if (g == null) { sb.AppendLine(string.Format("{0}null", indent)); } else { sb.AppendLine(string.Format("{0}{1}", indent, g.GetType().Name)); sb.AppendLine(string.Format("{0}Visible={1}", indent + "+--", g.Visible)); } } } }