コード例 #1
0
        public override string ToTexCode()
        {
            if (Content.Length == 0)
            {
                return("");
            }

            string        typestr = type == ClassType.Interface ? "Schnittstelle" : "Klasse";
            List <string> lines   = new List <string> ();

            lines.Add(@"\subsubsection{" + typestr + @" " + name + @"}\index{" + Packages.GetPackage(name) + "!" + name + @"}\label{" + name + "}");

            // wrapfigure
            //lines.Add (@"\begin{wrapfigure}{R}{9cm}{0}" + "\n" + @"\centering");
            //lines.Add (@"\includegraphics[scale=0.5]{Klassen/" + Name.Clean () + @"}");
            //lines.Add (@"\end{wrapfigure}");

            // in der mitte
            lines.Add(@"\begin{figure}[h!]" + "\n" + @"\centering");
            lines.Add(@"\includegraphics[scale=1]{Klassen/" + Name.Clean() + @"}");
            lines.Add(@"\end{figure}");


            lines.Add(@"\paragraph{Beschreibung:}\mbox{}\newline\newline");
            foreach (string cmt in Comments.GetComments(commentsKey))
            {
                if (cmt.StartsWith("[") && cmt.EndsWith("]") && cmt.Contains("="))
                {
                    continue;
                }

                lines.Add(Packages.AddTexCommands(cmt));
            }
            //lines.Add (@"\setlength{\columnsep}{10pt}%");
            lines.Add("\n");
            IEnumerable <UmlAttribute> attributes  = Content.OfType <UmlAttribute> ();
            IEnumerable <UmlMethod>    contructors = Content.OfType <UmlMethod> ().Where((m) => m.Name == Name);
            IEnumerable <UmlMethod>    methods     = Content.OfType <UmlMethod> ().Where((m) => m.Name != Name);

            if (attributes.Count() > 0)
            {
                lines.Add(@"\paragraph{Eigenschaften:}\mbox{} \newline\newline");
                bool first = true;
                foreach (UmlAttribute obj in attributes)
                {
                    if (!first)
                    {
                        lines.Add(@"~\\\\");
                    }
                    lines.Add(obj.ToTexCode());
                    first = false;
                }
                //lines.Add (@"\end{description}");
            }
            if (contructors.Count() > 0)
            {
                // lines.Add (@"\paragraph{Konstruktoren:}\mbox{} \begin{description} ");
                lines.Add(@"\paragraph{Konstruktoren:}\mbox{} \newline\newline");
                bool first = true;
                foreach (UmlMethod obj in contructors)
                {
                    if (!first)
                    {
                        lines.Add(@"~\\\\");
                    }
                    obj.IsContructor = true;
                    lines.Add(obj.ToTexCode());
                    first = false;
                }
                //lines.Add (@"\end{description}");
            }
            if (methods.Count() > 0)
            {
                // lines.Add (@"\paragraph{Methoden:}\mbox{} \begin{description} ");
                lines.Add(@"\paragraph{Methoden:}\mbox{} \newline\newline");
                bool first = true;
                foreach (UmlMethod obj in methods)
                {
                    if (!first)
                    {
                        lines.Add(@"~\\\\");
                    }
                    lines.Add(obj.ToTexCode());
                    first = false;
                }
                // lines.Add (@"\end{description}");
            }
            return(string.Join("\n", lines).Replace("<", "$<$").Replace(">", "$>$"));
        }
コード例 #2
0
        private static void Uml2Tex(IEnumerable <string> umlfiles, string target)
        {
            List <IUmlObject> allObjects = new List <IUmlObject> ();

            foreach (string umlfile in umlfiles)
            {
                IParser parser = new UmlParser();
                Console.WriteLine("Read: " + umlfile);
                allObjects.AddRange(parser.Parse(umlfile));
            }

            Console.WriteLine("Write: " + target);
            List <string> lines = new List <string> ();

            lines.AddRange(UmlObject.TexHeader);
            foreach (string package in Packages.PackageMap.Keys)
            {
                lines.Add(@"\section{Paket " + package + @"}");

                lines.Add(@"\subsection{Klassen}");
                foreach (UmlClass obj in allObjects.OfType <UmlClass>().Where((c) => Packages.IsInPackage(package, c.Name)))
                {
                    if (obj.type != ClassType.Interface)
                    {
                        lines.Add(obj.ToTexCode());
                        lines.Add("");
                    }
                }
                lines.Add(@"\subsection{Schnittstellen}");
                foreach (UmlClass obj in allObjects.OfType <UmlClass>().Where((c) => Packages.IsInPackage(package, c.Name)))
                {
                    if (obj.type == ClassType.Interface)
                    {
                        lines.Add(obj.ToTexCode());
                        lines.Add("");
                    }
                }
                lines.Add(@"\subsection{Enumerationen}");
                foreach (UmlEnum obj in allObjects.OfType <UmlEnum>().Where((c) => Packages.IsInPackage(package, c.Name)))
                {
                    lines.Add(obj.ToTexCode());
                    lines.Add("");
                }
            }

            Files.WriteLines(target, lines);

            lines.Clear();

            newCommand(ref lines, "CountClasses", "" + allObjects.OfType <UmlClass> ()
                       .Where((o) => o.type == ClassType.Class).Count()
                       );
            newCommand(ref lines, "CountInterfaces", "" + allObjects.OfType <UmlClass> ()
                       .Where((o) => o.type == ClassType.Interface).Count()
                       );
            newCommand(ref lines, "CountEnums", "" + allObjects.OfType <UmlEnum> ()
                       .Count()
                       );
            newCommand(ref lines, "CountAll", ""
                       + (allObjects.OfType <UmlClass> ()
                          .Where((o) => o.type == ClassType.Class).Count()
                          + allObjects.OfType <UmlClass> ()
                          .Where((o) => o.type == ClassType.Interface).Count()
                          + allObjects.OfType <UmlEnum> ()      /* Strukturen? */
                          .Count())
                       );

            Files.WriteLines(Path.GetDirectoryName(target) + "/Definitionen.gentex", lines);

            if (IsRunningOnMono())
            {
                foreach (UmlClass obj in allObjects.OfType <UmlClass>())
                {
                    // write class diagram
                    ClassDiagram dia      = new ClassDiagram(new IUmlObject[] { obj });
                    string       filename = Path.GetDirectoryName(target) + "/Klassen/" + obj.Name.Clean();
                    Files.WriteLines(filename + ".dot", dia.DotCode("", "ffffff", 200));
                    //GraphViz.Dot ("svg", filename + ".dot", filename + ".svg");
                    //GraphViz.Dot ("jpg", filename + ".dot", filename + ".jpg");
                    //GraphViz.Dot ("png", filename + ".dot", filename + ".png");
                    GraphViz.Dot("svg", filename + ".dot", filename + ".svg");
                    //GraphViz.Convert ("-density 100", "svg:" + filename + ".svg", filename + ".png");
                    //GraphViz.RsvgConvert ("--dpi-x 120", "--dpi-y 120", filename + ".svg", ">", filename + ".png");
                    GraphViz.InkScape("--export-png=" + filename + ".png", "--export-dpi=150", filename + ".svg");
                }
            }
        }
コード例 #3
0
        public override string ToCSharpCode(int padding = 0)
        {
            string        paddingStr = String.Concat(Enumerable.Repeat(" ", padding));
            List <string> lines      = new List <string> ();

            lines.AddRange(Packages.GetUsingStatements(Packages.GetPackage(name)));

            if (Packages.IsInPackage(name))
            {
                lines.Add(paddingStr + "namespace " + Packages.GetPackage(name));
                lines.Add(paddingStr + "{");
                paddingStr += "    ";
                padding    += 4;
            }

            lines.AddRange(Comments.CSharpComments(commentsKey, paddingStr));
            lines.Add(
                paddingStr + Publicity.ToCode("", " ") + Virtuality.ToCode("", " ") + type.ToCode("", " ")
                + name
                + (bases.Length > 0 ? " : " + string.Join(", ", bases).Replace("XNA.", "") : "")
                );
            lines.Add(paddingStr + "{");
            lines.Add("");

            IEnumerable <UmlAttribute> attributes  = Content.OfType <UmlAttribute> ();
            IEnumerable <UmlMethod>    contructors = Content.OfType <UmlMethod> ().Where((m) => m.Name == Name);
            IEnumerable <UmlMethod>    methods     = Content.OfType <UmlMethod> ().Where((m) => m.Name != Name);

            if (attributes.Count() > 0)
            {
                lines.Add(paddingStr + "    #region Properties");
                lines.Add("");
                foreach (UmlAttribute obj in attributes)
                {
                    lines.Add(obj.ToCSharpCode(padding + 4, Virtuality.Virtual, this));
                    lines.Add("");
                }
                lines.Add(paddingStr + "    #endregion");
                lines.Add("");
            }

            if (contructors.Count() > 0)
            {
                lines.Add(paddingStr + "    #region Constructors");
                lines.Add("");
                foreach (UmlMethod obj in contructors)
                {
                    obj.IsContructor = true;
                    lines.Add(obj.ToCSharpCode(padding + 4, Virtuality.None, this));
                    lines.Add("");
                }
                lines.Add(paddingStr + "    #endregion");
                lines.Add("");
            }

            if (methods.Count() > 0)
            {
                lines.Add(paddingStr + "    #region Methods");
                lines.Add("");
                foreach (UmlMethod obj in methods)
                {
                    lines.Add(obj.ToCSharpCode(padding + 4, Virtuality.Virtual, this));
                    lines.Add("");
                }
                lines.Add(paddingStr + "    #endregion");
                lines.Add("");
            }

            lines.Add(paddingStr + "}");

            if (Packages.IsInPackage(name))
            {
                padding   -= 4;
                paddingStr = paddingStr.Substring(4);
                lines.Add(paddingStr + "}");
            }

            return(string.Join("\n", lines));
        }