IfcDoc.DocumentationISO.FormatDiagram C# (CSharp) Method

FormatDiagram() private static method

private static FormatDiagram ( DocProject docProject, DocObject def, DocModelView docView, List listFigures, DocObject>.Dictionary mapEntity, string>.Dictionary mapSchema, string path ) : string
docProject DocProject
def DocObject
docView DocModelView
listFigures List
mapEntity DocObject>.Dictionary
mapSchema string>.Dictionary
path string
return string
        private static string FormatDiagram(DocProject docProject, DocObject def, DocModelView docView, List<ContentRef> listFigures, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema, string path)
        {
            // return if nothing to generate
            if (def is DocTemplateDefinition)
            {
                DocTemplateDefinition dtd = (DocTemplateDefinition)def;
                if (dtd.Rules == null || dtd.Rules.Count == 0)
                    return null;
            }
            else if (def is DocEntity)
            {
            }
            else
            {
                return null;
            }

            // create the figure file
            string filename = MakeLinkName(def) + ".png";
            Dictionary<Rectangle, DocModelRule> layout = new Dictionary<Rectangle, DocModelRule>();
            //if (!Properties.Settings.Default.SkipDiagrams)
            {
                try
                {
                    if (def is DocTemplateDefinition)
                    {
                        System.IO.Directory.CreateDirectory(path + "\\schema\\templates\\diagrams");
                        using (Image image = IfcDoc.Format.PNG.FormatPNG.CreateTemplateDiagram((DocTemplateDefinition)def, mapEntity, layout, docProject, null))
                        {
                            if (image != null)
                            {
                                string filepath = path + "\\schema\\templates\\diagrams\\" + filename;
                                image.Save(filepath, System.Drawing.Imaging.ImageFormat.Png);
                            }
                        }
                    }
                    else if (def is DocEntity) // no longer used directly; now for each model view in annex D
                    {
                        System.IO.Directory.CreateDirectory(path + "\\diagrams\\" + MakeLinkName(docView));
                        using (Image image = IfcDoc.Format.PNG.FormatPNG.CreateConceptDiagram((DocEntity)def, docView, mapEntity, layout, docProject, null))
                        {
                            string filepath = path + "\\diagrams\\" + MakeLinkName(docView) + "\\" + filename;
                            image.Save(filepath, System.Drawing.Imaging.ImageFormat.Png);
                        }
                    }
                }
                catch
                {
                }
            }

            // 2. figure
            StringBuilder sb = new StringBuilder();
            if (def is DocTemplateDefinition)
            {
                listFigures.Add(new ContentRef(def.Name + " instance diagram", def));

                // Per ISO guidelines, all figures must be referenced from text.
                sb.Append("<p class=\"fig-ref\">Figure ");
                sb.Append(listFigures.Count);
                sb.Append(" illustrates an instance diagram.</p>\r\n");
            }

            // include the figure with formatting below per ISO
            sb.Append("<table><tr><td><img alt=\"");
            sb.Append(def.Name);

            if (def is DocTemplateDefinition)
            {
                sb.Append("\" src=\"./diagrams/");
            }
            else
            {
                sb.Append("\" src=\"../../../diagrams/");
                sb.Append(MakeLinkName(docView));
                sb.Append("/");
            }
            sb.Append(filename);
            sb.Append("\" usemap=\"#f");
            sb.Append(listFigures.Count.ToString());
            sb.Append("\">");
            sb.Append("<map name=\"f");
            sb.Append(listFigures.Count.ToString());
            sb.Append("\">");
            foreach (Rectangle rc in layout.Keys)
            {
                DocModelRule rule = layout[rc];
                DocObject ruleObject = null;
                string strschema = null;

                string typename = null;
                if (rule != null)
                {
                    typename = rule.Name;
                }
                else if (def is DocTemplateDefinition)
                {
                    DocTemplateDefinition dtd = (DocTemplateDefinition)def;
                    typename = dtd.Type;
                }
                else if (def is DocObject)
                {
                    typename = def.Name;
                }

                if (mapEntity.TryGetValue(typename, out ruleObject) && mapSchema.TryGetValue(typename, out strschema))
                {
                    // hyperlink to IFC entity
                    // replace it with hyperlink
                    string relative = @"../";
                    if (def is DocEntity)
                    {
                        relative = "../../../schema/";
                    }
                    string hyperlink = relative + strschema.ToLower() + @"/lexical/" + ruleObject.Name.ToLower() + ".htm";

                    int indent = 0;
                    sb.Append("<area shape=\"rect\" coords=\"");
                    sb.Append(rc.Left + indent);
                    sb.Append(",");
                    sb.Append(rc.Top + indent);
                    sb.Append(",");
                    sb.Append(rc.Right + indent);
                    sb.Append(",");
                    sb.Append(rc.Bottom + indent);
                    sb.Append("\" href=\"");
                    sb.Append(hyperlink);
                    sb.Append("\" alt=\"");
                    sb.Append(ruleObject.Name);
                    sb.Append("\" />");
                }
            }
            sb.Append("</map>");

            // number figures in templates, but not annex
            if (def is DocTemplateDefinition)
            {
                sb.Append("</td></tr>");
                sb.Append("<tr><td><p class=\"figure\">Figure ");
                sb.Append(listFigures.Count);
                sb.Append(" &mdash; ");
                sb.Append(def.Name);
                sb.Append("</p></td></tr>");
            }

            sb.Append("</table>\r\n");
            sb.AppendLine();

            return sb.ToString();
        }