Пример #1
0
        public static void Export(Omnigraffle.Document doc, TextWriter stream)
        {
            var root = ExportDocument(doc);

            using (MemoryStream memStream = new MemoryStream()) {
                root.Save(memStream, PListFormat.Xml);
                stream.Write(Encoding.UTF8.GetString(memStream.ToArray()));
            }
        }
Пример #2
0
        public static Document ExportModel(KAOSModel _model)
        {
            mapping = new Dictionary <Omnigraffle.Sheet, Dictionary <string, Omnigraffle.ShapedGraphic> >();

            var document = new Omnigraffle.Document();

            var canvas = new Omnigraffle.Sheet(1, string.Format("Model"));
            var shapes = new Dictionary <string, IList <Graphic> >();

            var u = new GoalModelGenerator(canvas, shapes);

            u.Render(_model);
            document.Canvas.Add(canvas);

            var s2 = new Omnigraffle.Sheet(1, "Goal and Obstacle Model");
            var u2 = new GoalAndObstacleModelGenerator(s2, new Dictionary <string, IList <Graphic> >());

            u2.Render(_model);

            document.Canvas.Add(s2);


            int i = 0;

            foreach (var o in _model.Obstructions().Select(x => x.Obstacle()))
            {
                i++;
                var s  = new Omnigraffle.Sheet(1, string.Format($"Obstacle diagram for '{o.FriendlyName}'"));
                var u3 = new ObstacleDiagramGenerator(s, new Dictionary <string, IList <Graphic> >());
                u3.Render(o, _model);
                document.Canvas.Add(s);
            }

            i = 0;
            foreach (var goalWithException in _model.Exceptions().Select(x => x.AnchorGoal())
                     .Union(_model.Replacements().Select(x => x.ResolvingGoal()))
                     .Union(_model.ObstacleAssumptions().Select(x => x.Anchor()))
                     .Distinct())
            {
                i++;
                var s  = new Omnigraffle.Sheet(1, string.Format($"Exception diagram for '{goalWithException.FriendlyName}'"));
                var u3 = new ExceptionDiagramGenerator(s, new Dictionary <string, IList <Graphic> >());
                u3.Render(goalWithException, _model);
                document.Canvas.Add(s);
            }

            return(document);
        }
Пример #3
0
        private static PListRoot ExportDocument(Omnigraffle.Document doc)
        {
            var root = new PListRoot();

            root.Format = PListFormat.Xml;

            var dict = new PListDict();

            var applicationVersion = new PListArray();

            applicationVersion.Add(new PListString(doc.ApplicationVersion.Name));
            applicationVersion.Add(new PListString(doc.ApplicationVersion.Version));
            dict.Add("ApplicationVersion", applicationVersion);

            var sheets = new PListArray();

            foreach (var sheet in doc.Canvas)
            {
                var sheet_dict = new PListDict();

                sheet_dict.Add("ActiveLayerIndex", new PListInteger(sheet.ActiveLayerIndex));
                sheet_dict.Add("AutoAdjust", new PListBool(sheet.AutoAdjust));

                var backgroundGraphic = new PListDict();
                backgroundGraphic.Add("Bounds", ExportBounds(sheet.BackgroundGraphic.Bounds));
                backgroundGraphic.Add("Class", ExportBackgroundGraphicClass(sheet.BackgroundGraphic.Class));
                backgroundGraphic.Add("ID", new PListInteger(sheet.BackgroundGraphic.ID));

                var style  = new PListDict();
                var shadow = ExportShadow(sheet.BackgroundGraphic.Shadow);

                var stroke = new PListDict();
                stroke.Add("Draws", new PListString(sheet.BackgroundGraphic.DrawStroke ? "YES" : "NO"));

                style.Add("shadow", shadow);
                style.Add("stroke", stroke);
                backgroundGraphic.Add("Style", style);

                sheet_dict.Add("BackgroundGraphic", backgroundGraphic);

                sheet_dict.Add("BaseZoom", new PListInteger(sheet.BaseZoom));
                sheet_dict.Add("CanvasOrigin", new PListString(sheet.CanvasOrigin));
                sheet_dict.Add("ColumnAlign", new PListInteger(sheet.ColumnAlign));

                sheet_dict.Add("ColumnSpacing", new PListReal(sheet.ColumnSpacing));

                sheet_dict.Add("DisplayScale", new PListString(sheet.DisplayScale));
                sheet_dict.Add("HPages", new PListInteger(sheet.HPages));

                var layers = new PListArray();
                if (sheet.Layers.Count > 1)
                {
                    foreach (var layer in sheet.Layers)
                    {
                        layers.Add(ExportLayer(layer));
                    }
                }
                else
                {
                    layers.Add(ExportLayer(new Omnigraffle.Layer()));
                }
                sheet_dict.Add("Layers", layers);

                var layoutInfo = new PListDict();
                layoutInfo.Add("Animate", new PListString(sheet.LayoutInfo.Animate ? "YES" : "NO"));

                if (sheet.LayoutInfo.AutoLayout)
                {
                    layoutInfo.Add("AutoLayout", new PListInteger(1));
                }

                if (sheet.LayoutInfo.HierarchicalOrientation == Omnigraffle.HierarchicalOrientation.LeftRight)
                {
                    layoutInfo.Add("HierarchicalOrientation", new PListInteger(0));
                }
                else if (sheet.LayoutInfo.HierarchicalOrientation == Omnigraffle.HierarchicalOrientation.TopBottom)
                {
                    layoutInfo.Add("HierarchicalOrientation", new PListInteger(1));
                }
                else if (sheet.LayoutInfo.HierarchicalOrientation == Omnigraffle.HierarchicalOrientation.RightLeft)
                {
                    layoutInfo.Add("HierarchicalOrientation", new PListInteger(2));
                }
                else if (sheet.LayoutInfo.HierarchicalOrientation == Omnigraffle.HierarchicalOrientation.BottomTop)
                {
                    layoutInfo.Add("HierarchicalOrientation", new PListInteger(3));
                }

                if (sheet.LayoutInfo.LayoutEngine == Omnigraffle.LayoutEngine.Circo)
                {
                    layoutInfo.Add("layoutEngine", new PListString("circo"));
                }
                else if (sheet.LayoutInfo.LayoutEngine == Omnigraffle.LayoutEngine.Dot)
                {
                    layoutInfo.Add("layoutEngine", new PListString("dot"));
                }
                else if (sheet.LayoutInfo.LayoutEngine == Omnigraffle.LayoutEngine.Neato)
                {
                    layoutInfo.Add("layoutEngine", new PListString("neato"));
                }
                else if (sheet.LayoutInfo.LayoutEngine == Omnigraffle.LayoutEngine.Twopi)
                {
                    layoutInfo.Add("layoutEngine", new PListString("twopi"));
                }

                layoutInfo.Add("circoMinDist", new PListReal(sheet.LayoutInfo.CircoMinDist));
                layoutInfo.Add("circoSeparation", new PListReal(sheet.LayoutInfo.CircoSeparation));
                layoutInfo.Add("dotRankSep", new PListReal(sheet.LayoutInfo.DotRankSep));

                layoutInfo.Add("neatoSeparation", new PListReal(sheet.LayoutInfo.NeatoSeparation));
                layoutInfo.Add("neatoLineLength", new PListReal(sheet.LayoutInfo.NeatoLineLength));
                layoutInfo.Add("neatoOverlap", new PListBool(sheet.LayoutInfo.NeatoOverlap));

                layoutInfo.Add("twopiOverlap", new PListBool(sheet.LayoutInfo.TwopiOverlap));
                layoutInfo.Add("twopiSeparation", new PListReal(sheet.LayoutInfo.TwopiSeparation));
                layoutInfo.Add("twopiRankSep", new PListReal(sheet.LayoutInfo.TwopiRankSep));

                sheet_dict.Add("LayoutInfo", layoutInfo);

                if (sheet.Orientation == Omnigraffle.Orientation.Portrait)
                {
                    sheet_dict.Add("Orientation", new PListInteger(0));
                }
                else if (sheet.Orientation == Omnigraffle.Orientation.Landscape)
                {
                    sheet_dict.Add("Orientation", new PListInteger(1));
                }
                else if (sheet.Orientation == Omnigraffle.Orientation.PageSetup)
                {
                    sheet_dict.Add("Orientation", new PListInteger(2));
                }

                sheet_dict.Add("PrintOnePage", new PListBool(sheet.PrintOnePage));
                sheet_dict.Add("RowAlign", new PListInteger(sheet.RowAlign));
                sheet_dict.Add("RowSpacing", new PListReal(sheet.RowSpacing));

                sheet_dict.Add("SheetTitle", new PListString(sheet.Title));

                sheet_dict.Add("UniqueID", new PListInteger(sheet.UniqueId));
                sheet_dict.Add("VPages", new PListInteger(sheet.VPages));

                var graphics_array = new PListArray();

                foreach (var graphic in sheet.GraphicsList)
                {
                    graphics_array.Add(ExportGraphic(graphic));
                }

                sheet_dict.Add("GraphicsList", graphics_array);

                sheet_dict.Add("GridInfo", new PListDict());

                sheets.Add(sheet_dict);
            }
            dict.Add("Sheets", sheets);


            dict.Add("CreationDate", new PListString(doc.CreationDate.ToString("yyyy-MM-dd hh:mm:ss +0000")));
            dict.Add("ModificationDate", new PListString(doc.ModificationDate.ToString("yyyy-MM-dd hh:mm:ss +0000")));

            dict.Add("Creator", new PListString(doc.Creator));

            dict.Add("GraphDocumentVersion", new PListInteger(doc.GraphDocumentVersion));

            dict.Add("GuidesLocked", new PListString(doc.GuidesLocked ? "YES" : "NO"));
            dict.Add("GuidesVisible", new PListString(doc.GuidesVisible ? "YES" : "NO"));

            dict.Add("ImageCounter", new PListInteger(doc.ImageCounter));

            dict.Add("KeepToScale", new PListBool());

            dict.Add("LinksVisible", new PListString(doc.LinksVisible ? "YES" : "NO"));
            dict.Add("MagnetsVisible", new PListString(doc.MagnetsVisible ? "YES" : "NO"));
            dict.Add("NotesVisible", new PListString(doc.NotesVisible ? "YES" : "NO"));
            dict.Add("OriginVisible", new PListString(doc.OriginVisible ? "YES" : "NO"));
            dict.Add("PageBreaks", new PListString(doc.PageBreaks ? "YES" : "NO"));

            dict.Add("MasterSheets", new PListArray());
            dict.Add("Modifier", new PListString());

            var printInfo = new PListDict();

            var bottomMargin = new PListArray();

            bottomMargin.Add(new PListString("float"));
            bottomMargin.Add(new PListString(doc.PrintInfo.BottomMargin.ToString()));
            printInfo.Add("NSBottomMargin", bottomMargin);

            var leftMargin = new PListArray();

            leftMargin.Add(new PListString("float"));
            leftMargin.Add(new PListString(doc.PrintInfo.LeftMargin.ToString()));
            printInfo.Add("NSLeftMargin", leftMargin);

            var rightMargin = new PListArray();

            rightMargin.Add(new PListString("float"));
            rightMargin.Add(new PListString(doc.PrintInfo.RightMargin.ToString()));
            printInfo.Add("NSRightMargin", rightMargin);

            var topMargin = new PListArray();

            topMargin.Add(new PListString("float"));
            topMargin.Add(new PListString(doc.PrintInfo.TopMargin.ToString()));
            printInfo.Add("NSTopMargin", topMargin);

            var horizonalPagination = new PListArray();

            horizonalPagination.Add(new PListString("coded"));
            horizonalPagination.Add(new PListString(doc.PrintInfo.HorizonalPagination));
            printInfo.Add("NSHorizonalPagination", horizonalPagination);

            var paperSize = new PListArray();

            paperSize.Add(new PListString("size"));
            paperSize.Add(new PListString(doc.PrintInfo.PaperSize));
            printInfo.Add("NSPaperSize", paperSize);

            var printReverseOrientation = new PListArray();

            printReverseOrientation.Add(new PListString("int"));
            printReverseOrientation.Add(new PListString(doc.PrintInfo.PrintReverseOrientation ? "1" : "0"));
            printInfo.Add("NSPrintReverseOrientation", printReverseOrientation);

            dict.Add("PrintInfo", printInfo);

            dict.Add("ReadOnly", new PListString(doc.ReadOnly ? "YES" : "NO"));
            dict.Add("SmartAlignmentGuidesActive", new PListString(doc.SmartAlignmentGuidesActive ? "YES" : "NO"));
            dict.Add("SmartDistanceGuidesActive", new PListString(doc.SmartDistanceGuidesActive ? "YES" : "NO"));


            dict.Add("UseEntirePage", new PListBool(doc.UseEntirePage));

            var windowInfo = new PListDict();

            windowInfo.Add("CurrentSheet", new PListInteger(doc.WindowInfo.CurrentSheet));

            var expanded_canvases = new PListArray();

            foreach (var sheet in doc.Canvas.Where(s => s.Expanded))
            {
                var canvas_dict = new PListDict();
                canvas_dict.Add("name", new PListString(sheet.Title));
                expanded_canvases.Add(canvas_dict);
            }
            windowInfo.Add("ExpandedCanvases", expanded_canvases);

            windowInfo.Add("Frame", new PListString(doc.WindowInfo.Frame));
            windowInfo.Add("ListView", new PListBool(doc.WindowInfo.ListView));
            windowInfo.Add("RightSidebar", new PListBool(doc.WindowInfo.RightSidebar));
            windowInfo.Add("ShowRuler", new PListBool(doc.WindowInfo.ShowRuler));
            windowInfo.Add("Sidebar", new PListBool(doc.WindowInfo.Sidebar));

            windowInfo.Add("SidebarWidth", new PListInteger(doc.WindowInfo.SidebarWidth));
            windowInfo.Add("OutlineWidth", new PListInteger(doc.WindowInfo.OutlineWidth));

            windowInfo.Add("VisibleRegion", new PListString("{{0, 0}, {558, 720}}"));

            windowInfo.Add("Zoom", new PListReal(doc.WindowInfo.Zoom));

            var zoom_values = new PListArray();

            foreach (var sheet in doc.Canvas)
            {
                var zoom_array = new PListArray();
                zoom_array.Add(new PListString(sheet.Title));
                zoom_array.Add(new PListReal(sheet.Zoom));
                zoom_array.Add(new PListReal(1));
            }
            windowInfo.Add("ZoomValues", zoom_values);

            dict.Add("WindowInfo", windowInfo);

            root.Root = dict;

            return(root);
        }
Пример #4
0
        public static void Export(Omnigraffle.Document doc, string filename)
        {
            var root = ExportDocument(doc);

            root.Save(filename);
        }