Inheritance: IFormatExtension, IFormatData
コード例 #1
0
ファイル: DocumentationISO.cs プロジェクト: pipauwel/IfcDoc
        private static void GenerateExample(
            DocPublication docPublication,
            DocExample docExample,
            List<DocXsdFormat> listFormats,
            string path,
            List<int> indexpath,
            Dictionary<DocObject, bool> included,
            Dictionary<string, DocObject> mapEntity,
            Dictionary<string, string> mapSchema,
            Dictionary<string, Type> typemap,
            List<ContentRef> listFigures, 
            List<ContentRef> listTables,
            FormatHTM htmTOC,
            FormatHTM htmSectionTOC,
            Dictionary<DocFormatSchemaEnum, IFormatData> mapFormats,
            Dictionary<long, SEntity> outerinstancemap, // instance data of parent example, if inherited
            SEntity outerinstanceroot
            )
        {
            if (included == null || included.ContainsKey(docExample))
            {
                indexpath[indexpath.Count - 1]++;

                StringBuilder indexpathname = new StringBuilder();
                indexpathname.Append("E");
                foreach(int x in indexpath)
                {
                    indexpathname.Append(".");
                    indexpathname.Append(x);
                }
                string indexpathstring = indexpathname.ToString();

                string pathExample = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".htm";
                using (FormatHTM htmExample = new FormatHTM(pathExample, mapEntity, mapSchema, included))
                {
                    htmExample.WriteHeader(docExample.Name, 2, docPublication.Header);
                    htmExample.WriteScript(-5, indexpath[0], 0, 0);
                    htmExample.WriteLine("<h3 class=\"std\">" + indexpathstring + " " + docExample.Name + "</h3>");

                    // table of files
                    if (docExample.File != null)
                    {
                        htmExample.Write("<table class=\"gridtable\">");
                        htmExample.Write("<tr><th>Format</th><th>ASCII</th><th>HTML</th></tr>");

                        foreach(DocFormat docFormat in docPublication.Formats)
                        {
                            if (docFormat.FormatOptions == DocFormatOptionEnum.Examples)
                            {
                                string ext = docFormat.ExtensionInstances;
                                htmExample.WriteLine("<tr><td>" + docFormat.FormatType.ToString() + "</td><td><a href=\"" + MakeLinkName(docExample) + "." + ext + "\">File</a></td><td><a href=\"" + MakeLinkName(docExample) + "." + ext + ".htm\">Markup</a></td></tr>");
                            }
                        }

                        htmExample.Write("</table>");

                        htmExample.Write("<table class=\"gridtable\">");
                        htmExample.Write("<tr><th>View</th></tr>");
                        foreach (DocModelView docView in docExample.Views)
                        {
                            if (included != null && included.ContainsKey(docView))
                            {
                                string hyperlink = "../../schema/views/" + MakeLinkName(docView) + "/index.htm";
                                htmExample.Write("<tr><td><a href=\"" + hyperlink + "\">" + docView.Name + "</td></tr>");
                            }
                        }
                        htmExample.Write("</table>");

                        if (docExample.ApplicableType != null)
                        {
                            string[] ApplicableTypesArray = docExample.ApplicableType.Split(',');
                            htmExample.Write("<table class=\"gridtable\">");
                            htmExample.Write("<tr><th>Entity</th></tr>");
                            for (int i = 0; i < ApplicableTypesArray.Length; i++)
                            {
                                string hyperlink = "../../schema/" + mapSchema[ApplicableTypesArray.GetValue(i).ToString()].ToString().ToLower() + "/lexical/" + ApplicableTypesArray.GetValue(i).ToString().ToLower() + ".htm";
                                htmExample.Write("<tr><td><a href=" + hyperlink + ">" + ApplicableTypesArray.GetValue(i) + "</td></tr>");
                            }
                            htmExample.Write("</table>");
                        }
                    }

                    docExample.Documentation = UpdateNumbering(docExample.Documentation, listFigures, listTables, docExample);

                    htmExample.WriteDocumentationMarkup(docExample.Documentation, docExample, docPublication);

                    if (docExample.File == null && outerinstancemap != null)
                    {
                        // if specific to exchange, capture inline
                        if (docExample.Views.Count > 0)
                        {
                            // hack for now based on example name matching exchange name -- make explicit later
                            foreach (DocExchangeDefinition docExchange in docExample.Views[0].Exchanges)
                            {
                                if (docExample.Name.Equals(docExchange.Name))
                                {
                                    // matches -- generate
                                    FormatSQL fmt = new FormatSQL();
                                    string content = fmt.FormatData(docPublication, docExchange, mapEntity, outerinstancemap, outerinstanceroot, false);
                                    htmExample.Write(content);
                                    break;
                                }
                            }
                        }
                    }

                    htmExample.WriteLinkTo(docExample);
                    htmExample.WriteFooter(docPublication.Footer);
                }

                if (docExample.File != null && !Properties.Settings.Default.SkipDiagrams)
                {
                    string pathIFC = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifc";
                    using (System.IO.FileStream filestream = new System.IO.FileStream(pathIFC, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read))
                    {
                        filestream.Write(docExample.File, 0, docExample.File.Length);
                    }

                    using (FormatSPF spfExample = new FormatSPF(new System.IO.MemoryStream(docExample.File, false), typemap, null))
                    {
                        string pathListing = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifc.htm";

                        if (docPublication.GetFormatOption(DocFormatSchemaEnum.STEP) == DocFormatOptionEnum.Examples)//Properties.Settings.Default.ExampleSPF)
                        {
                            using (FormatHTM htmListing = new FormatHTM(pathListing, mapEntity, mapSchema, included))
                            {
                                htmListing.WriteHeader(docExample.Name, 2, docPublication.Header);

                                htmListing.WriteLine("<tt class=\"spf\">");
                                string htm = null;
                                try
                                {
                                    htm = spfExample.LoadMarkup();
                                    outerinstancemap = spfExample.Instances;
                                }
                                catch
                                {
                                }
                                htmListing.Write(htm);
                                htmListing.Write("</tt>");
                                htmListing.WriteFooter(String.Empty);
                            }
                        }
            #if false
                        else if(Properties.Settings.Default.ExampleXML)
                        {
                            // must load file in any case in order to generate xml
                            try
                            {
                                spfExample.Load();
                            }
                            catch
                            {
                            }
                        }
            #endif

                        // find the IfcProject
                        SEntity rootproject = null;
                        foreach (SEntity ent in spfExample.Instances.Values)
                        {
                            if (ent.GetType().Name.Equals("IfcProject"))
                            {
                                rootproject = ent;
                                break;
                            }
                        }

                        foreach (DocFormat docFormat in docPublication.Formats)
                        {
                            // generate example in other formats...
                            if (docFormat.FormatOptions == DocFormatOptionEnum.Examples)
                            {
                                switch(docFormat.FormatType)
                                {
                                    case DocFormatSchemaEnum.STEP:
                                        break; // do nothing

            #if false
                                    case DocFormatSchemaEnum.XML: // TODO: use generic formatter
                                        {
                                            // use xml namespace of first view
                                            string xmlns = "http://www.buildingsmart-tech.org/ifcXML/IFC4/final";
                                            if (docExample.Views.Count > 0 && !String.IsNullOrEmpty(docExample.Views[0].XsdUri))
                                            {
                                                xmlns = docExample.Views[0].XsdUri;
                                            }

                                            string pathXML = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifcxml";
                                            using (FormatSML xmlExample = new FormatSML(new System.IO.FileStream(pathXML, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite), listFormats, xmlns, docPublication.Code))
                                            {
                                                xmlExample.Instance = rootproject;
                                                xmlExample.Save();
                                            }

                                            string pathXMH = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifcxml.htm";
                                            using (FormatSML xmlExample = new FormatSML(new System.IO.FileStream(pathXMH, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite), listFormats, xmlns, docPublication.Code))
                                            {
                                                xmlExample.Instance = rootproject;
                                                xmlExample.Markup = true;
                                                xmlExample.Save();
                                            }
                                        }
                                        break;
            #endif // now use generic formatters

                                    case DocFormatSchemaEnum.TTL:
                                        {
                                            string ns = "http://ifcowl.openbimstandards.org/IFC4_ADD1#";

                                            string pathTTL = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ttl";
                                            Console.Out.WriteLine("------------------------------------------------");
                                            Console.Out.WriteLine("converting file: " + MakeLinkName(docExample) + ".ttl");
                                            Console.Out.WriteLine("------------------------------------------------");
                                            using (FormatTTL_Stream TTLExample = new FormatTTL_Stream(new System.IO.FileStream(pathTTL, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite), ns))
                                            {
                                                TTLExample.Instances = spfExample.Instances;
                                                TTLExample.Save();
                                            }

                                            //TODO: redo the HTM part later on
                                            //string pathTTLHTM = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ttl.htm";
                                            //using (FormatTTL_Stream TTLExample = new FormatTTL_Stream(new System.IO.FileStream(pathTTLHTM, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite), ns))
                                            //{
                                            //    TTLExample.Instances = spfExample.Instances;
                                            //    TTLExample.Markup = true;
                                            //    TTLExample.Save();
                                            //}
                                        }
                                        break;

                                    #if false
                                    case DocFormatTypeEnum.SQL: // todo: support others...
                                        // use formatter
                                        {
                                            FormatSQL fmt = new FormatSQL();
                                            string content = fmt.FormatData(docPublication, null, mapEntity, spfExample.Instances);

                                            string pathRAW = path + @"\annex\annex-e\" + MakeLinkName(docExample) + "." + docFormat.ExtensionInstances;
                                            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(pathRAW, false))
                                            {
                                                writer.Write(content);
                                            }

                                            string pathHTM = pathRAW + ".htm";
                                            using (FormatHTM fmtHTM = new FormatHTM(pathHTM, mapEntity, mapSchema, included))
                                            {
                                                fmtHTM.WriteHeader(docExample.Name, 2, docPublication.Header);
                                                fmtHTM.Write(content);
                                                fmtHTM.WriteFooter("");
                                            }
                                        }
                                        break;
            #endif

                                    default: // pluggable formatters
                                        {
                                            IFormatData formatext = null;
                                            if(mapFormats.TryGetValue(docFormat.FormatType, out formatext))
                                            {
                                                string content = formatext.FormatData(docPublication, null, mapEntity, spfExample.Instances, rootproject, false);
                                                string pathRAW = path + @"\annex\annex-e\" + MakeLinkName(docExample) + "." + docFormat.ExtensionInstances;
                                                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(pathRAW, false))
                                                {
                                                    writer.Write(content);
                                                }

                                                string conmark = formatext.FormatData(docPublication, null, mapEntity, spfExample.Instances, rootproject, true);
                                                string pathHTM = pathRAW + ".htm";
                                                using (FormatHTM fmtHTM = new FormatHTM(pathHTM, mapEntity, mapSchema, included))
                                                {
                                                    fmtHTM.WriteHeader(docExample.Name, 2, docPublication.Header);
                                                    fmtHTM.Write(conmark);
                                                    fmtHTM.WriteFooter("");
                                                }

                                            }
                                        }
                                        break;
                                }
                            }
                        }
                    }
                }

                using (FormatHTM htmLink = new FormatHTM(path + "/link/" + MakeLinkName(docExample) + ".htm", mapEntity, mapSchema, included))
                {
                    string linkurl = "../annex/annex-e/" + MakeLinkName(docExample) + ".htm";
                    htmLink.WriteLinkPage(linkurl, docPublication);
                }

                string urlExample = "annex-e/" + MakeLinkName(docExample) + ".htm";
                htmTOC.WriteTOC(2, "<a class=\"listing-link\" href=\"annex/" + urlExample + "\" >" + indexpathstring + " " + docExample.Name + "</a>");

                string linkid = "";
                if(indexpath.Count == 1)
                {
                    linkid = indexpath[0].ToString();
                }
                string htmllink = "<a class=\"listing-link\" id=\"" + linkid + "\" href=\"" + urlExample + "\" target=\"info\">" + docExample.Name + "</a>";
                htmSectionTOC.WriteLine("<tr class=\"std\"><td class=\"menu\">" + indexpathstring + " " + htmllink + "</td></tr>");

                if (docExample.Examples.Count > 0)
                {
                    indexpath.Add(0);
                    foreach(DocExample docSub in docExample.Examples)
                    {
                        GenerateExample(docPublication, docSub, listFormats, path, indexpath, included, mapEntity, mapSchema, typemap, listFigures, listTables, htmTOC, htmSectionTOC, mapFormats, outerinstancemap, outerinstanceroot);
                    }
                    indexpath.RemoveAt(indexpath.Count - 1);
                }
            }
        }
コード例 #2
0
        private static void GenerateExample(
            DocProject docProject,
            DocPublication docPublication,
            DocExample docExample,
            List<DocXsdFormat> listFormats,
            string path,
            List<int> indexpath,
            Dictionary<DocObject, bool> included,
            Dictionary<string, DocObject> mapEntity,
            Dictionary<string, string> mapSchema,
            Dictionary<string, Type> typemap,
            List<ContentRef> listFigures, 
            List<ContentRef> listTables,
            FormatHTM htmTOC,
            FormatHTM htmSectionTOC,
            Dictionary<DocFormatSchemaEnum, IFormatData> mapFormats,
            Dictionary<long, SEntity> outerinstancemap, // instance data of parent example, if inherited
            SEntity outerinstanceroot
            )
        {
            if (included == null || included.ContainsKey(docExample))
            {
                indexpath[indexpath.Count - 1]++;

                StringBuilder indexpathname = new StringBuilder();
                indexpathname.Append("E");
                foreach(int x in indexpath)
                {
                    indexpathname.Append(".");
                    indexpathname.Append(x);
                }
                string indexpathstring = indexpathname.ToString();

                string pathExample = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".htm";
                using (FormatHTM htmExample = new FormatHTM(pathExample, mapEntity, mapSchema, included))
                {
                    htmExample.WriteHeader(docExample.Name, 2, docPublication.Header);
                    htmExample.WriteScript(-5, indexpath[0], 0, 0);
                    htmExample.WriteLine("<h3 class=\"std\">" + indexpathstring + " " + docExample.Name + "</h3>");

                    // table of files
                    if (docExample.File != null)
                    {
                        htmExample.Write("<table class=\"gridtable\">");
                        htmExample.Write("<tr><th>Format</th><th>ASCII</th><th>HTML</th><th>Size</th></tr>");

                        if (docExample.File != null && !Properties.Settings.Default.SkipDiagrams)
                        {
                            string pathIFC = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifc";
                            using (System.IO.FileStream filestream = new System.IO.FileStream(pathIFC, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Read))
                            {
                                filestream.Write(docExample.File, 0, docExample.File.Length);
                            }

                            using (FormatSPF spfExample = new FormatSPF(new System.IO.MemoryStream(docExample.File, false), typemap, null))
                            {
                                string pathListing = path + @"\annex\annex-e\" + MakeLinkName(docExample) + ".ifc.htm";

                                if (docPublication.GetFormatOption(DocFormatSchemaEnum.STEP) == DocFormatOptionEnum.Examples)//Properties.Settings.Default.ExampleSPF)
                                {
                                    using (FormatHTM htmListing = new FormatHTM(pathListing, mapEntity, mapSchema, included))
                                    {
                                        htmListing.WriteHeader(docExample.Name, 2, docPublication.Header);

                                        htmListing.WriteLine("<tt class=\"spf\">");
                                        string htm = null;
                                        try
                                        {
                                            htm = spfExample.LoadMarkup();
                                            outerinstancemap = spfExample.Instances;
                                        }
                                        catch
                                        {
                                        }
                                        htmListing.Write(htm);
                                        htmListing.Write("</tt>");
                                        htmListing.WriteFooter(String.Empty);

                                    }
                                }

                                // find the IfcProject
                                SEntity rootproject = null;
                                foreach (SEntity ent in spfExample.Instances.Values)
                                {
                                    if (ent.GetType().Name.Equals("IfcProject"))
                                    {
                                        rootproject = ent;
                                        break;
                                    }
                                }

                                foreach (DocFormat docFormat in docPublication.Formats)
                                {
                                    // generate example in other formats...
                                    if (docFormat.FormatOptions == DocFormatOptionEnum.Examples)
                                    {
                                        long filesize = docExample.File.LongLength;
                                        if (docFormat.FormatType != DocFormatSchemaEnum.STEP)
                                        {
                                            IFormatData formatext = null;
                                            if (mapFormats.TryGetValue(docFormat.FormatType, out formatext))
                                            {
                                                string content = formatext.FormatData(docProject, docPublication, null, mapEntity, spfExample.Instances, rootproject, false);
                                                string pathRAW = path + @"\annex\annex-e\" + MakeLinkName(docExample) + "." + docFormat.ExtensionInstances;
                                                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(pathRAW, false))
                                                {
                                                    writer.Write(content);
                                                }

                                                string conmark = formatext.FormatData(docProject, docPublication, null, mapEntity, spfExample.Instances, rootproject, true);
                                                string pathHTM = pathRAW + ".htm";
                                                using (FormatHTM fmtHTM = new FormatHTM(pathHTM, mapEntity, mapSchema, included))
                                                {
                                                    fmtHTM.WriteHeader(docExample.Name, 2, docPublication.Header);
                                                    fmtHTM.Write(conmark);
                                                    fmtHTM.WriteFooter("");
                                                }

                                                filesize = content.Length;
                                            }
                                        }

                                        string sizetext = filesize.ToString();
                                        string ext = docFormat.ExtensionInstances;
                                        htmExample.WriteLine("<tr><td>" + docFormat.FormatType.ToString() + "</td><td><a href=\"" + MakeLinkName(docExample) + "." + ext + "\">File</a></td><td><a href=\"" + MakeLinkName(docExample) + "." + ext + ".htm\">Markup</a></td><td style=\"text-align:right\">" + sizetext + "</td></tr>");
                                    }
                                }

                            }

                        }

                        htmExample.Write("</table>");

                        htmExample.Write("<table class=\"gridtable\">");
                        htmExample.Write("<tr><th>View</th></tr>");
                        foreach (DocModelView docView in docExample.Views)
                        {
                            if (included != null && included.ContainsKey(docView))
                            {
                                string hyperlink = "../../schema/views/" + MakeLinkName(docView) + "/index.htm";
                                htmExample.Write("<tr><td><a href=\"" + hyperlink + "\">" + docView.Name + "</td></tr>");
                            }
                        }
                        htmExample.Write("</table>");

                        if (docExample.ApplicableType != null)
                        {
                            string[] ApplicableTypesArray = docExample.ApplicableType.Split(',');
                            htmExample.Write("<table class=\"gridtable\">");
                            htmExample.Write("<tr><th>Entity</th></tr>");
                            for (int i = 0; i < ApplicableTypesArray.Length; i++)
                            {
                                string hyperlink = "../../schema/" + mapSchema[ApplicableTypesArray.GetValue(i).ToString()].ToString().ToLower() + "/lexical/" + ApplicableTypesArray.GetValue(i).ToString().ToLower() + ".htm";
                                htmExample.Write("<tr><td><a href=" + hyperlink + ">" + ApplicableTypesArray.GetValue(i) + "</td></tr>");
                            }
                            htmExample.Write("</table>");
                        }
                    }

                    docExample.Documentation = UpdateNumbering(docExample.Documentation, listFigures, listTables, docExample);

                    htmExample.WriteDocumentationMarkup(docExample.Documentation, docExample, docPublication);

                    if (docExample.File == null && outerinstancemap != null)
                    {
                        // if specific to exchange, capture inline
                        if (docExample.Views.Count > 0)
                        {
                            // hack for now based on example name matching exchange name -- make explicit later
                            foreach (DocExchangeDefinition docExchange in docExample.Views[0].Exchanges)
                            {
                                if (docExample.Name.Equals(docExchange.Name))
                                {
                                    // matches -- generate
                                    FormatSQL fmt = new FormatSQL();
                                    string content = fmt.FormatData(docProject, docPublication, docExchange, mapEntity, outerinstancemap, outerinstanceroot, false);
                                    htmExample.Write(content);
                                    break;
                                }
                            }
                        }
                    }

                    htmExample.WriteLinkTo(docExample);
                    htmExample.WriteFooter(docPublication.Footer);
                }

                using (FormatHTM htmLink = new FormatHTM(path + "/link/" + MakeLinkName(docExample) + ".htm", mapEntity, mapSchema, included))
                {
                    string linkurl = "../annex/annex-e/" + MakeLinkName(docExample) + ".htm";
                    htmLink.WriteLinkPage(linkurl, docPublication);
                }

                string urlExample = "annex-e/" + MakeLinkName(docExample) + ".htm";
                htmTOC.WriteTOC(2, "<a class=\"listing-link\" href=\"annex/" + urlExample + "\" >" + indexpathstring + " " + docExample.Name + "</a>");

                string linkid = "";
                if(indexpath.Count == 1)
                {
                    linkid = indexpath[0].ToString();
                }
                string htmllink = "<a class=\"listing-link\" id=\"" + linkid + "\" href=\"" + urlExample + "\" target=\"info\">" + docExample.Name + "</a>";
                htmSectionTOC.WriteLine("<tr class=\"std\"><td class=\"menu\">" + indexpathstring + " " + htmllink + "</td></tr>");

                if (docExample.Examples.Count > 0)
                {
                    indexpath.Add(0);
                    foreach(DocExample docSub in docExample.Examples)
                    {
                        GenerateExample(docProject, docPublication, docSub, listFormats, path, indexpath, included, mapEntity, mapSchema, typemap, listFigures, listTables, htmTOC, htmSectionTOC, mapFormats, outerinstancemap, outerinstanceroot);
                    }
                    indexpath.RemoveAt(indexpath.Count - 1);
                }
            }
        }