Inheritance: IDisposable
Esempio n. 1
0
        static SCHEMATA GetSchemata(FormatSPF file)
        {
            foreach (SEntity entity in file.Instances.Values)
            {
                if (entity is SCHEMATA)
                {
                    return (SCHEMATA)entity;
                }
            }

            return null;
        }
Esempio n. 2
0
        public static void Export(DocProject project, DocModelView docView, string path, Dictionary<string, DocObject> mapEntity, Dictionary<string, string> mapSchema)
        {
            Dictionary<DocObject, bool> included = docView.Filter(project);

            const string HEADERCELL = "<th style=\"-webkit-transform:rotate(90deg); writing-mode:tb-rl; -moz-transform:rotate(90deg); -o-transform: rotate(90deg); white-space:nowrap; display:blocking; ms-filter: \"progid:DXImageTransform.Microsoft.BasicImage(rotation=0.083)\"; >";

            // get list of entities in order
            List<DocEntity> sortEntity = project.GetEntityList();

            // build list of templates in use (to preserve sort order)
            Dictionary<DocTemplateDefinition, List<DocConceptRoot>> mapTemplates = new Dictionary<DocTemplateDefinition, List<DocConceptRoot>>();

            // double-loop not optimal, but lists aren't that large
            foreach (DocEntity docSortEnt in sortEntity)
            {
                foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    if (docRoot.ApplicableEntity == docSortEnt)
                    {
                        foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                        {
                            if (!mapTemplates.ContainsKey(docConcept.Definition))
                            {
                                mapTemplates.Add(docConcept.Definition, new List<DocConceptRoot>());
                            }
                            mapTemplates[docConcept.Definition].Add(docRoot);
                        }
                    }
                }
            }

            // build list of concept roots sorted by entity order
            List<DocConceptRoot> sortConceptRoot = new List<DocConceptRoot>();
            foreach (DocEntity docSortEntity in sortEntity)
            {
                foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    if (docRoot.ApplicableEntity == docSortEntity)
                    {
                        sortConceptRoot.Add(docRoot);
                        break;
                    }
                }
            }

            using (FormatEXP formatEXP = new FormatEXP(path + @"\" + docView.Code + ".exp"))
            {
                formatEXP.Instance = project;
                formatEXP.ModelViews = new DocModelView[] { docView };
                formatEXP.Save();
            }

            using (FormatXSD formatXSD = new FormatXSD(path + @"\" + docView.Code + ".xsd"))
            {
                formatXSD.Instance = project;
                formatXSD.ModelViews = new DocModelView[] { docView };
                formatXSD.Save();
            }

            using (FormatSPF format = new FormatSPF(path + @"\" + docView.Code + ".ifc", Schema.IFC.SchemaIfc.Types, new Dictionary<long, SEntity>()))
            {
                format.InitHeaders(docView.Code, "IFC4");
                Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
                Program.ExportIfc(ifcProject, project, included);
                format.Save();
            }

            using (FormatXML format = new FormatXML(path + @"\" + docView.Code + ".mvdxml", typeof(mvdXML), mvdXML.DefaultNamespace))
            {
                mvdXML mvd = new mvdXML();
                Program.ExportMvd(mvd, project, included);
                format.Instance = mvd;
                format.Save();
            }

            using (FormatHTM format = new FormatHTM(path + @"\" + docView.Code + ".htm", mapEntity, new Dictionary<string, string>(), included))
            {
                format.WriteHeader(docView.Name, 0, null);

                // 1 Scope
                // 1.1 Business Case Description
                // 1.2 Participants and Stakeholders

                // 2 Normative References

                // 3 Terms and definitions

                // 4 Symbols and abbreviated terms

                // 5 Business processes
                // 5.1 Process models provided
                // 5.2 Representative process models
                // 5.3 Process models formatting

                format.WriteLine("<h1>6 Exchange requirements</h1>");
                format.WriteLine("<h2>6.1 Exchange requirements legibility</h2>");
                format.WriteLine("<h3>6.1.1 Exchange requirements list</h3>");
                format.WriteLine("<p>Each exchange is listed by name as follows.</p>");
                Dictionary<string, string> mapExchangeClass = new Dictionary<string, string>();
                format.WriteLine("<ul>");
                foreach (DocExchangeDefinition docExchange in docView.Exchanges)
                {
                    if (docExchange.ExchangeClass != null && !mapExchangeClass.ContainsKey(docExchange.ExchangeClass) && !String.IsNullOrEmpty(docExchange.ExchangeClass))
                    {
                        mapExchangeClass.Add(docExchange.ExchangeClass, docExchange.ExchangeClass);
                    }

                    format.WriteLine("<li>" + docExchange.Name + "</li>");
                }
                format.WriteLine("</ul>");

                format.WriteLine("<h3>6.1.2 Exchange requirement classification list</h3>");
                format.WriteLine("<p>Each phase classification used by this model view is listed by Omniclass notation and title as follows.</p>");
                format.WriteLine("<ul>");
                foreach (string key in mapExchangeClass.Keys)
                {
                    format.WriteLine("<li>" + key + "</li>");
                }
                format.WriteLine("</ul>");

                format.WriteLine("<h3>6.1.3 Exchange requirement coverage analysis</h3>");
                format.WriteLine("<p>Each exchange is listed by name and corresponding classifications for the process undertaken, the sender of the information, and the receiver of the information.</p>");
                format.WriteLine("<table class=\"gridtable\">");
                format.WriteLine("<tr><th>Exchange</th><th>Process</th><th>Sender</th><th>Receiver</th></tr>");
                foreach (DocExchangeDefinition docExchange in docView.Exchanges)
                {
                    format.WriteLine("<tr><td>" + docExchange.Name + "</td><td>" + docExchange.ExchangeClass + "</td><td>" + docExchange.SenderClass + "</td><td>" + docExchange.ReceiverClass);
                }
                format.WriteLine("</table>");

                format.WriteLine("<h2>6.2 Exchange requirements detail</h2>");
                format.WriteLine("<h3>6.2.1 Exchange requirements definition</h3>");
                format.WriteLine("<p>Each exchange is listed by name and a description of the information contained.</p>");
                foreach (DocExchangeDefinition docExchange in docView.Exchanges)
                {
                    format.WriteLine("<h4>" + docExchange.Name + "</h4>");
                    format.WriteLine(docExchange.Documentation);
                }

                format.WriteLine("<h3>6.2.2 Business rule list</h3>");
                format.WriteLine("<p>Each exchange consists of a set of entity data definitions with usage defined according to business rule concepts. " +
                    "An entity describes an object class having one or more attributes, where each attribute may refer to values, collections, or references to other objects. "+
                    "A concept describes usage of object classes, where allowable values and object types are indicated for specific attributes." +
                    "Each heading that follows refers to an exchange, where each table row corresponds to an entity, each table column corresponds to an exchange, and each cell indicates whether the concept is used for the entity within the exchange.</p>");
                foreach (DocExchangeDefinition docExchange in docView.Exchanges)
                {
                    format.WriteLine("<h4>" + docExchange.Name + "</h4>");

                    List<DocTemplateDefinition> listTemplate = project.GetTemplateList();
                    List<DocTemplateDefinition> usedTemplate = new List<DocTemplateDefinition>();

                    foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                    {
                        foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                        {
                            if (!usedTemplate.Contains(docConcept.Definition))
                            {
                                foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges)
                                {
                                    if (docExchangeItem.Exchange == docExchange &&
                                        (docExchangeItem.Requirement == DocExchangeRequirementEnum.Mandatory || docExchangeItem.Requirement == DocExchangeRequirementEnum.Optional))
                                    {
                                        usedTemplate.Add(docConcept.Definition);
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    for(int i = listTemplate.Count - 1; i >= 0; i--)
                    {
                        if (!usedTemplate.Contains(listTemplate[i]))
                        {
                            listTemplate.RemoveAt(i);
                        }
                    }

                    format.WriteLine("<table class=\"gridtable\">");
                    format.Write("<tr>");
                    format.Write("<th>Entity</th>");
                    for (int i = 0; i < listTemplate.Count; i++)
                    {
                        format.Write(HEADERCELL);
                        format.Write(listTemplate[i].Name);
                        format.Write("</th>");
                    }
                    format.WriteLine("</tr>");

                    foreach (DocConceptRoot docRoot in sortConceptRoot)
                    {
                        DocExchangeRequirementEnum[] reqs = new DocExchangeRequirementEnum[listTemplate.Count];
                        bool include = false;
                        foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                        {
                            foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges)
                            {
                                if (docExchangeItem.Exchange == docExchange &&
                                    (docExchangeItem.Requirement == DocExchangeRequirementEnum.Mandatory || docExchangeItem.Requirement == DocExchangeRequirementEnum.Optional))
                                {
                                    int index = listTemplate.IndexOf(docConcept.Definition);
                                    reqs[index] = docExchangeItem.Requirement;
                                    include = true;
                                    break;
                                }
                            }
                        }

                        if (include)
                        {
                            format.Write("<tr>");
                            format.Write("<td>" + docRoot.ApplicableEntity.Name + "</td>");
                            for (int i = 0; i < reqs.Length; i++)
                            {
                                format.Write("<td>");
                                switch (reqs[i])
                                {
                                    case DocExchangeRequirementEnum.Mandatory:
                                        format.Write("R");
                                        break;

                                    case DocExchangeRequirementEnum.Optional:
                                        format.Write("O");
                                        break;
                                }
                                format.Write("</td>");
                            }
                            format.WriteLine("</tr>");
                        }
                    }

                    format.WriteLine("</table>");
                }

                format.WriteLine("<h3>6.2.3 Business rule definition</h3>");
                format.WriteLine("<p>Business rule definitions are all defined as re-usable templates as indicated in Clause 7.3.5.</p>");

                format.WriteLine("<h2>6.3 Exchange requirements reusability</h2>");
                format.WriteLine("<p>Names and classifications of exchanges are intended to be consistent across other model views where applicable, "+
                    "while the content of a particular exchange is intended to be unique.</p>");

                format.WriteLine("<h3>6.3.1 Related business process list</h3>");
                format.WriteLine("<p>Business processes within this model view are correlated with those used in other model views as follows.</p>");

                // Rows: Business processes; Columns: Views; Cells: mark if applicable
                format.WriteLine("<table class=\"gridtable\">");
                format.Write("<tr><th>Process</th>");
                foreach (DocModelView docEachView in project.ModelViews)
                {
                    format.Write(HEADERCELL + docEachView.Name + "</th>");
                }
                format.WriteLine("</tr>");
                foreach (string proc in mapExchangeClass.Keys)
                {
                    format.Write("<tr><td>" + proc + "</td>");
                    foreach (DocModelView docEachView in project.ModelViews)
                    {
                        bool yes = false;
                        foreach (DocExchangeDefinition docEachExchange in docEachView.Exchanges)
                        {
                            if (!String.IsNullOrEmpty(docEachExchange.ExchangeClass) && docEachExchange.ExchangeClass.Equals(proc))
                            {
                                yes = true;
                                break;
                            }
                        }

                        format.Write("<td>");
                        if (yes)
                        {
                            format.Write("X");
                        }
                        format.Write("</td>");
                    }
                    format.WriteLine("</tr>");
                }
                format.WriteLine("</table>");

                format.WriteLine("<h3>6.3.2 Related exchange requirement list</h3>");
                format.WriteLine("<p>Exchange requirements within this model view are correlated with those used in other model views as follows.</p>");
                // Rows: Exchanges; Columns: Views; Cells: Mark if applicable
                format.WriteLine("<table class=\"gridtable\">");
                format.Write("<tr><th>Exchange</th>");
                foreach (DocModelView docEachView in project.ModelViews)
                {
                    format.Write(HEADERCELL + docEachView.Name + "</th>");
                }
                format.WriteLine("</tr>");
                foreach (DocExchangeDefinition docExchange in docView.Exchanges)
                {
                    format.Write("<tr><td>" + docExchange.Name + "</td>");
                    foreach (DocModelView docEachView in project.ModelViews)
                    {
                        bool yes = false;
                        foreach (DocExchangeDefinition docEachExchange in docEachView.Exchanges)
                        {
                            if (!String.IsNullOrEmpty(docEachExchange.Name) && docEachExchange.Name.Equals(docExchange.Name))
                            {
                                yes = true;
                                break;
                            }
                        }

                        format.Write("<td>");
                        if (yes)
                        {
                            format.Write("X");
                        }
                        format.Write("</td>");
                    }
                    format.WriteLine("</tr>");
                }
                format.WriteLine("</table>");

                format.WriteLine("<h3>6.3.3 Related exchange requirement reuse analysis</h3>");
                format.WriteLine("<p>Exchange requirements across other model views are correlated as follows.</p>");

                // Rows: Exchange names; Columns: Views; Cells: Mark if applicable
                List<string> listExchangeNames = new List<string>();
                foreach (DocModelView docEachView in project.ModelViews)
                {
                    foreach (DocExchangeDefinition docEachExchange in docEachView.Exchanges)
                    {
                        if (!listExchangeNames.Contains(docEachExchange.Name))
                        {
                            listExchangeNames.Add(docEachExchange.Name);
                        }
                    }
                }
                format.WriteLine("<table class=\"gridtable\">");
                format.Write("<tr><th>Exchange</th>");
                foreach (DocModelView docEachView in project.ModelViews)
                {
                    format.Write(HEADERCELL + docEachView.Name + "</th>");
                }
                format.WriteLine("</tr>");
                foreach (string exchangename in listExchangeNames)
                {
                    format.Write("<tr><td>" + exchangename + "</td>");
                    foreach (DocModelView docEachView in project.ModelViews)
                    {
                        bool yes = false;
                        foreach (DocExchangeDefinition docEachExchange in docEachView.Exchanges)
                        {
                            if (!String.IsNullOrEmpty(docEachExchange.Name) && docEachExchange.Name.Equals(exchangename))
                            {
                                yes = true;
                                break;
                            }
                        }

                        format.Write("<td>");
                        if (yes)
                        {
                            format.Write("X");
                        }
                        format.Write("</td>");
                    }
                    format.WriteLine("</tr>");
                }
                format.WriteLine("</table>");

                format.WriteLine("<h1>7 Model view definition</h1>");
                format.WriteLine("<h2>7.1 Data Definition</h2>");
                format.WriteLine("<h3>7.1.1 Data definitions list</h3>");
                format.WriteLine("<p>Each entity data definition is listed by schema and entity name as follows.</p>");
                format.WriteLine("<ul>");
                string lastschema = null;
                foreach (DocConceptRoot docRoot in sortConceptRoot)
                {
                    string schema = mapSchema[docRoot.ApplicableEntity.Name];
                    if (schema != lastschema)
                    {
                        // close out last
                        if (docRoot != sortConceptRoot[0])
                        {
                            format.WriteLine("</ul></li>");
                        }

                        // open next
                        format.WriteLine("<li>" + schema + "<ul>");

                        lastschema = schema;
                    }

                    format.WriteLine("<li>" + docRoot.ApplicableEntity.Name + "</li>");
                }
                format.WriteLine("</ul></ul>");

                format.WriteLine("<h3>7.1.2 Data definitions</h3>");
                format.WriteLine("<p>Each entity data definition is described within subsections as follows, with electronic representations provided in EXPRESS and XSD formats.</p>");
                FormatXSD formatXSD = new FormatXSD(null);
                foreach (DocConceptRoot docRoot in sortConceptRoot)
                {
                    string xsd = formatXSD.FormatEntity(docRoot.ApplicableEntity, mapEntity, included);

                    format.WriteLine("<h4>" + docRoot.ApplicableEntity.Name + "</h4>");
                    format.WriteLine(docRoot.ApplicableEntity.Documentation);
                    format.WriteLine("<br/>");

                    format.WriteExpressEntitySpecification(docRoot.ApplicableEntity, true, false);
                    format.WriteLine("<br/>");
                    format.WriteFormatted(xsd);
                }

                format.WriteLine("<h3>7.1.3 Data definition reference schema list</h3>");
                format.WriteLine("<p>Each referenced schema is listed by standards body notation and official title.</p>");
                format.WriteLine("<table class=\"gridtable\">");
                format.WriteLine("<tr><th>Reference</th><th>Description</th></tr>");
                format.WriteLine("<tr><td>ISO 16739:2013</td><td>Industry Foundation Classes (IFC) for data sharing in the construction and facilities management industries</td></tr>");
                format.WriteLine("</table>");

                // 7.2 Concept definitions
                format.WriteLine("<h2>7.2 Concept definitions</h2>");
                format.WriteLine("<h3>7.2.1 Concept list</h3>");
                format.WriteLine("<p>Each concept is listed by entity name and concept template within the following table. "+
                    "Each row corresponds to an entity, each column corresponds to a concept template, and each cell indicates usage of a concept template for an entity.</p>");
                format.WriteLine("<table class=\"gridtable\">");
                format.Write("<tr><th>Entity</th>");
                foreach (DocTemplateDefinition docTemplate in mapTemplates.Keys)
                {
                    format.Write(HEADERCELL + docTemplate.Name + "</th>");
                }
                format.WriteLine("</tr>");

                foreach (DocConceptRoot docRoot in sortConceptRoot)
                {
                    if (docRoot.Concepts.Count > 0)
                    {
                        format.Write("<tr><td>" + docRoot.ApplicableEntity.Name + "</td>");

                        foreach (DocTemplateDefinition docTemplate in mapTemplates.Keys)
                        {
                            format.Write("<td>");
                            foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                            {
                                if (docConcept.Definition == docTemplate)
                                {
                                    format.Write("X");
                                }
                            }
                            format.Write("</td>");
                        }

                        format.WriteLine("</tr>");
                    }
                }
                format.WriteLine("</table>");

                string pathImages = path + "\\" + docView.Code;
                System.IO.Directory.CreateDirectory(pathImages);

                format.WriteLine("<h3>7.2.2 Concept definitions</h3>");
                format.WriteLine("<p>Each entity is described within subsections, with diagrams indicating the graph of attributes and objects representing the combination of all concepts applied to instances of the entity. "+
                    "Each block in the diagram represents an entity, where the entity name is shown at the top of the block with background in black.  "+
                    "Each attribute within the entity is shown in order, where black is used to indicate a direct attribute and grey is used to indicate an inverse attribute. "+
                    "Notation to the right of each attribute indicates aggregation, where S indicates a SET (unordered unique objects) and L indicates a LIST (ordered objects), "+
                    "the first number in brackets indicates the minimum count, and the second number in brackets indicates the maximum count or “?” for unlimited. "+
                    "Lines connecting blocks indicates attributes that point to objects of other data definitions.</p>");
                foreach (DocConceptRoot docRoot in sortConceptRoot)
                {
                    format.WriteLine("<h4>" + docRoot.ApplicableEntity.Name + "</h4>");

                    string img = "";
                    if (docView.Code != null)
                    {
                        int cx = 0;
                        int cy = 0;
                        try
                        {
                            using (System.Drawing.Image image = IfcDoc.Format.PNG.FormatPNG.CreateConceptDiagram(docRoot.ApplicableEntity, docView, mapEntity, new Dictionary<System.Drawing.Rectangle,DocModelRule>(), project, null))
                            {
                                cx = image.Width;
                                cy = image.Height;
                                string filepath = path + "\\" + docView.Code.ToLower() + "\\" + docRoot.ApplicableEntity.Name.ToLower() + ".png";
                                image.Save(filepath, System.Drawing.Imaging.ImageFormat.Png);
                            }
                        }
                        catch
                        {
                        }

                        // shrink for access from MS Word
                        cx = cx / 2;
                        cy = cy / 2;

                        img = "<br/><img src=\"" + docView.Code.ToLower() + "/" + docRoot.ApplicableEntity.Name.ToLower() + ".png\" width=\"" + cx + "\" height=\"" + cy + "\"/>";
                    }

                    format.WriteLine(docRoot.Documentation);
                    format.WriteLine(img);
                    foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                    {
                        if (!String.IsNullOrEmpty(docConcept.Documentation))
                        {
                            format.WriteLine("<h5>" + docConcept.Definition.Name + "</h5>");
                            format.WriteLine(docConcept.Documentation);
                        }
                    }
                }
                format.WriteLine("</table>");

                format.WriteLine("<h3>7.2.3 Concept attributes list</h3>");
                format.WriteLine("<p>Concepts may be defined that use parameters to indicate applicable values. "+
                    "For example, plumbing objects may make use of ports to enable connectivity to other objects for distribution of water, "+
                    "and a specific entity such as a hot water heater may have specific ports such as “ColdWaterIn” and “HotWaterOut”. "+
                    "Defining attributes at concepts enables re-use of concepts where the data structures are the same, but applicable values may differ."+
                    "Each concept is shown in a subsection as follows, with rows correspoding to entities and rule instances, columns corresponding to template parameters, and cells corresponding to values applied to rules.</p>");

                // then format each template
                foreach (DocTemplateDefinition docTemplate in mapTemplates.Keys)
                {
                    string[] parameters = docTemplate.GetParameterNames();

                    if (parameters.Length > 0)
                    {
                        format.WriteLine("<h4>" + docTemplate.Name + "</h4>");
                        format.WriteLine("<table class=\"gridtable\">");
                        format.Write("<tr><th>Entity</th>");

                        foreach (string parm in parameters)
                        {
                            format.Write("<th>" + parm + "</th>");
                        }

                        format.WriteLine("</tr>");

                        List<DocConceptRoot> listRoots = mapTemplates[docTemplate];
                        foreach (DocConceptRoot docRoot in listRoots)
                        {
                            foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                            {
                                if (docConcept.Definition == docTemplate)
                                {
                                    if (docConcept.Items.Count == 0)
                                    {
                                        format.WriteLine("<tr><td>" + docRoot.ApplicableEntity.Name + "</td></tr>");
                                    }
                                    else
                                    {
                                        foreach (DocTemplateItem docItem in docConcept.Items)
                                        {
                                            if (docItem == docConcept.Items[0])
                                            {
                                                format.Write("<tr><td rowspan=\"" + docConcept.Items.Count + "\">" + docRoot.ApplicableEntity.Name + "</td>");
                                            }
                                            else
                                            {
                                                format.Write("<tr>");
                                            }

                                            foreach (string parm in parameters)
                                            {
                                                string val = docItem.GetParameterValue(parm);
                                                format.Write("<td>" + val + "</td>");
                                            }

                                            format.WriteLine("</tr>");
                                        }
                                    }
                                }
                            }
                        }

                        format.WriteLine("</table>");
                    }
                }

                format.WriteLine("<h3>7.2.4 Concept relationship description</h3>");
                format.WriteLine("<p>Concepts may inherit from other concepts such that more generic rules may be defined at a higher level and more specific rules at a lower level.  "+
                    "For example, geometry may be defined for a distribution segment (e.g. ducts, pipes, cables) that indicate permitted use of an extruded area solid (IfcExtrudedAreaSolid) "+
                    "which defines a 2D cross section extruded along a 3D linear segment. "+
                    "Such rule may be further refined for ducts to indicate that the cross-sections are further restricted to shapes such as hollow rectangles (IfcRectangleHollowProfileDef) "+
                    "or hollow circles (IfcCircleHollowProfileDef)."+
                    "Concepts are shown in a hierarchy as follows where inner concepts inherit from outer concepts.</p>");
                WriteTemplateList(format, project.Templates, included);

                format.WriteLine("<h3>7.2.5 Concept requirements applicability</h3>");
                format.WriteLine("<p>Each entity is shown in subsections as follows, with rows corresponding to concepts, columns corresponding to exchanges, "+
                    "and cells indicating requirements where 'R' indicates required and 'O' indicates optional.</p>");
                foreach (DocConceptRoot docRoot in sortConceptRoot)
                {
                    if (docRoot.Concepts.Count > 0)
                    {
                        format.WriteLine("<h4>" + docRoot.ApplicableEntity.Name + "</h4>");

                        format.WriteLine("<table class=\"gridtable\">");
                        format.Write("<tr><th>Concept</th>");
                        for (int i = 0; i < docView.Exchanges.Count; i++)
                        {
                            format.Write(HEADERCELL);
                            format.Write(docView.Exchanges[i].Name);
                            format.Write("</th>");
                        }
                        format.WriteLine("</tr>");

                        DocExchangeRequirementEnum[] reqs = new DocExchangeRequirementEnum[docView.Exchanges.Count];

                        foreach (DocTemplateUsage docConcept in docRoot.Concepts)
                        {
                            StringBuilder sbRequired = new StringBuilder();
                            StringBuilder sbOptional = new StringBuilder();
                            foreach (DocExchangeItem docExchangeItem in docConcept.Exchanges)
                            {
                                int index = docView.Exchanges.IndexOf(docExchangeItem.Exchange);
                                reqs[index] = docExchangeItem.Requirement;
                            }

                            format.Write("<tr><td>" + docConcept.Definition.Name + "</td>");
                            for (int i = 0; i < docView.Exchanges.Count; i++)
                            {
                                format.Write("<td>");
                                switch (reqs[i])
                                {
                                    case DocExchangeRequirementEnum.Mandatory:
                                        format.Write("R");
                                        break;

                                    case DocExchangeRequirementEnum.Optional:
                                        format.Write("O");
                                        break;
                                }
                                format.Write("</td>");
                            }
                            format.WriteLine("</tr>");
                        }

                        format.WriteLine("</table>");
                    }
                }

                format.WriteLine("<h2>7.3 Concept reusability</h2>");
                format.WriteLine("<h3>7.3.1 Concept list</h3>");
                format.WriteLine("<p>Each concept used within this model view is listed as follows.</p>");

                format.WriteLine("<ul>");
                foreach (DocTemplateDefinition docTemplate in mapTemplates.Keys)
                {
                    format.WriteLine("<li>" + docTemplate.Name + "</li>");
                }

                format.WriteLine("</ul>");

                format.WriteLine("<h3>7.3.2 Related existing concept list</h3>");
                format.WriteLine("<p>In the following table, each row corresponds to a concept used within this model view, "+
                    "each column corresponds to another model view, and each cell indicates usage of the concept within the corresponding model view.</p>");
                format.WriteLine("<table class=\"gridtable\">");
                format.Write("<tr><th>Concept</th>");
                foreach (DocModelView docEachView in project.ModelViews)
                {
                    format.Write(HEADERCELL + docEachView.Name + "</th>");
                }
                format.WriteLine("</tr>");

                foreach (DocTemplateDefinition docTemplate in mapTemplates.Keys)
                {
                    format.Write("<tr><td>" + docTemplate.Name + "</td>");

                    foreach (DocModelView docEachView in project.ModelViews)
                    {
                        bool yes = false;
                        foreach (DocConceptRoot docEachRoot in docEachView.ConceptRoots)
                        {
                            foreach (DocTemplateUsage docEachUsage in docEachRoot.Concepts)
                            {
                                if (docEachUsage.Definition == docTemplate)
                                {
                                    yes = true;
                                    break;
                                }
                            }
                        }

                        if (yes)
                        {
                            format.Write("<td>X</td>");
                        }
                        else
                        {
                            format.Write("<td></td>");
                        }
                    }

                    format.WriteLine("</tr>");
                }
                format.WriteLine("</table>");

                format.WriteLine("<h3>7.3.4 Concept business rule list</h3>");
                format.WriteLine("<p>Each concept template is defined in a subsection as follows, with rows corresponding to each business rule. "+
                    "The <i>Reference</i> column identifies the path to the entity and attribute. " +
                    "The <i>Cardinality</i> column indicates whether the number of permitted instances is restricted differently than the underlying schema, using [N:M] notation where N indicates the minimum number of instances, M indicates the maximum number of instances, where '?' indicates unbounded. "+
                    "The <i>Parameter</i> column indicates the name of a substitutable parameter, if applicable, defined at each usage of the business rule.<p>");
                foreach (DocTemplateDefinition docTemplate in mapTemplates.Keys)
                {
                    format.WriteLine("<h4>" + docTemplate.Name + "</h4>");

                    format.WriteLine("<table class=\"gridtable\">");
                    format.WriteLine("<tr><th>Reference</th><th>Cardinality</th><th>Parameter</th></tr>");

                    if (docTemplate.Rules != null)
                    {
                        foreach (DocModelRule docRule in docTemplate.Rules)
                        {
                            WriteModelRule(format, docRule, "\\" + docTemplate.Type + "." + docRule.Name);
                        }
                    }

                    format.WriteLine("</table>");
                }

                format.WriteLine("<h3>7.3.5 Concept business rule description</h3>");
                format.WriteLine("<p>Each concept template is described in a subsection as follows, with diagrams indicating usage of attributes and entities reflecting defined business rules.</p>");
                foreach (DocTemplateDefinition docTemplate in mapTemplates.Keys)
                {
                    format.WriteLine("<h4>" + docTemplate.Name + "</h4>");

                    format.WriteLine(docTemplate.Documentation);

                    string img = "";
                    if (docTemplate.Rules != null && docTemplate.Rules.Count > 0)
                    {
                        img = GenerateTemplateImage(docTemplate, mapEntity, project, path);
                        format.WriteLine(img);
                    }
                }

                format.WriteLine("<h2>7.4 Implementation</h2>");
                format.WriteLine("<h3>7.4.1 MVD Schema Listing</h3>");
                format.WriteLine("The schema encapsulating the data definitions for this model view is published in multiple representations. " +
            "<p>An MVDXML file defines the referenced entities and rules for this model view. This file may be used to validate instance data (in IFC-SPF or IFC-XML files), filter instance data to include entities and attributes within scope of this model view, or generate sub-schemas (including the EXP and XSD representations). " +
            "<p>An EXP file represents the schema in EXPRESS format (ISO 10303-11) which adapts the referenced Industry Foundation Classes schema (ISO 16739) by including a subset of data definitions and a subset of attributes within each data definition. The EXP file may be used by software development tools for generating programming languages schemas (e.g. C++, C#, Java), database definitions (e.g. SQL DDL), and data transport schema definitions (e.g. XSD). " +
            "<p>An XSD file represents the schema in XML Data Definition Language (XSD) which adapts the referenced subset of data definitions. The XSD file may be used by software development tools (e.g. Eclipse, Microsoft Visual Studio) to validate XML files and generate language-specific classes. " +
            "<p>An IFC file represents the dynamic portions of the schema in the form of property sets within an SPF (ISO 10303-21) instance file.</p>" +
            "<p>The rationale for publishing multiple representations is to provide the richest level of integration for different implementations; "+
            "while XSD is often used in defining web standards replacing document-based exchanges (e.g. invoices), it lacks data model information needed for type safety, data integrity, indexing, and optimization; "+
            "all of which may be derived from the EXPRESS representation. "+
            "</p>");
                format.WriteLine("<table class=\"gridtable\">");
                format.WriteLine("<tr><th>File</th><th>Format</th></tr>");
                format.WriteLine("<tr><td>" + docView.Code + ".exp</td><td>EXPRESS schema definition</td></tr>");
                format.WriteLine("<tr><td>" + docView.Code + ".xsd</td><td>XML schema definition (XSD)</td></tr>");
                format.WriteLine("<tr><td>" + docView.Code + ".mvdxml</td><td>MVDXML schema transform</td></tr>");
                format.WriteLine("<tr><td>" + docView.Code + ".ifc</td><td>IFC dynamic schema definition</td></tr>");
                format.WriteLine("</table>");

                format.WriteLine("<h3>7.4.2 MVD Format Description</h3>");

                format.WriteLine("<p>Implementations of this model view may publish instance data in various formats. "+
                    "Such format indicates the data encoding and does not necessarily imply that data may only be exchanged using physical files on computers; "+
                    "formats may be transmitted over the Internet as the “presentation layer” (OSI Layer 6) of any API. "+
                    "As the IFC data model supports both full and partial data models where all objects can be tagged to indicate merge directives (Create/Update/Delete using IfcOwnerHistory.ChangeAction), "+
                    "data may be transmitted in whole or in part, such as indicating only data changes.</p>");
                format.WriteLine("<p>As other OSI layers are already standardized, a full web API may be defined by referencing each layer as follows:</p>");
                format.WriteLine("<table class=\"gridtable\">");
                format.WriteLine("<tr><th>OSI Layer</th><th>OSI Layer Name</th><th>Protocol</th><th>Description</th></tr>");
                format.WriteLine("<tr><td>7</td><td>Application</td><td>WebDav</td><td>Defines valid operations such as GET, PUT, POST, DELETE, MKCOL, LOCK, UNLOCK</td></tr>");
                format.WriteLine("<tr><td>6</td><td>Presentation</td><td>IFC-SPF/IFC-XML</td><td>Defines data encoding</td></tr>");
                format.WriteLine("<tr><td>5</td><td>Session</td><td>HTTP/HTTPS</td><td>Defines establishment of sessions, compression, authentication, requests, responses, and errors</td></tr>");
                format.WriteLine("<tr><td>4</td><td>Transport</td><td>TCP</td><td>Defines message delivery</td></tr>");
                format.WriteLine("<tr><td>3</td><td>Network</td><td>IP</td><td>Defines network paths across multiple nodes</td></tr>");
                format.WriteLine("<tr><td>2</td><td>Data Link</td><td>MAC</td><td>Defines data frame communications between two nodes</td></tr>");
                format.WriteLine("<tr><td>1</td><td>Physical</td><td>(undefined)</td><td>Defines physical connectivity</td></tr>");
                format.WriteLine("</table>");

                format.WriteLine("<p>Each supported format is listed by name, with Extension indicating the default file extension to use on applicable platforms (e.g. Windows), MIME type for indicating the HTTP header when transmitting over the Internet, and Reference standard indicating the presentation layer encoding format.</p>");

                format.WriteLine("<table class=\"gridtable\">");
                format.WriteLine("<tr><th>Format</th><th>Extension</th><th>MIME</th><th>Reference</th></tr>");
                format.WriteLine("<tr><td>IFC-SPF</td><td>.ifc</td><td>application/step</td><td>ISO 10303-21</td></tr>");
                format.WriteLine("<tr><td>IFC-XML</td><td>.ifcxml</td><td>application/xml</td><td>ISO 10303-28</td></tr>");
                format.WriteLine("</table>");

                format.WriteLine("<p>IFC-SPF (ISO 10303-21) is a text format optimized to carry data with complex relationships, supporting human readability yet more compact representation (typically around 10% of size of equivalent XML).</p>");

                format.WriteLine("<p>IFC-HDF (ISO 10303-26) is a binary file format encapsulating data in a compact, indexable encoding optimized for quick retrieval and minimal memory usage. ");
                format.WriteLine("<blockquote class=\"note\">NOTE&nbsp; As this file type is not yet widely implemented, it is not officially part of this model view, however implementations may prefer such format for internal use.</blockquote>");

                format.WriteLine("<p>IFC-XML (ISO 10303-28) is a hierarchical markup format with wide support from software development tools and platforms, supporting greater human readability at the expense of larger representation.  </p>");
                format.WriteLine("<blockquote class=\"note\">NOTE&nbsp; As typical buildings contain millions of elements with graphs of relationships resulting in gigabytes of data, " +
            "XML is not yet suitable for representing complete buildings from a pragmatic standpoint of data size, transmission cost, and loading time. " +
            "However, using derived formats along with MVDXML to filter data sets may enable more efficient exchanges to take place.</blockquote>");

                format.WriteLine("<p>IFC-ZIP (ISO 21320-1) is a compressed file format encapsulating one of the above formats to minimize data size. ");
                format.WriteLine("<blockquote class=\"note\">NOTE&nbsp; As this model view is primarily intended for web-based exchange, zip compression may be selected by other means according to the client and server; therefore, the IFC-ZIP format is not officially part of this model view.</blockquote>");

                format.WriteLine("<h3>7.4.3 MVD Dynamic Schema Analysis</h3>");
                format.WriteLine("<p>Portions of data definitions are defined dynamically, to allow software applications to support extensible definitions while minimizing implementation overhead. "+
                    "Each property set is shown within a subsection as follows, with rows corresponding to properties. See <i>IfcPropertySet</i> for usage information.</p>");
                foreach (DocSection docSection in project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        foreach (DocPropertySet docPset in docSchema.PropertySets)
                        {
                            if (included == null || included.ContainsKey(docPset))
                            {
                                format.WriteLine("<h4>" + docPset.Name + "</h4>");
                                format.WriteLine("<table class=\"gridtable\">");
                                format.WriteLine("<tr><th>Property</th><th>Property Type</th><th>Data Type</th><th>Description</th></tr>");

                                foreach (DocProperty docProp in docPset.Properties)
                                {
                                    string datatype = docProp.PrimaryDataType;
                                    if (!String.IsNullOrEmpty(docProp.SecondaryDataType))
                                    {
                                        datatype += "/" + docProp.SecondaryDataType;
                                    }

                                    format.WriteLine("<tr><td>" + docProp.Name + "</td><td>" + docProp.PropertyType + "</td><td>" + datatype + "</td><td>" + docProp.Documentation + "</td></tr>");
                                }

                                format.WriteLine("</table>");
                            }
                        }
                    }
                }

                format.WriteLine("<h3>7.4.4 Non-Applicable Entity Exclusion Analysis</h3>");
                format.WriteLine("<p>The referenced IFC schema is shown in the following table, with each row corresponding to a schema namespace, with data definitions listed within, where bold items indicate definitions within scope of this Model View Definition.</p>");
                format.WriteLine("<table class=\"gridtable\">");
                format.WriteLine("<tr><th>Namespace</th><th>Definitions</th><th>Usage</th></tr>");
                foreach (DocSection docSection in project.Sections)
                {
                    if (docSection.Schemas.Count > 0)
                    {
                        foreach (DocSchema docSchema in docSection.Schemas)
                        {
                            format.Write("<tr><td>" + docSchema.Name + "</td><td>");

                            int min = 0;
                            int max = 0;

                            foreach (DocEntity docEntity in docSchema.Entities)
                            {
                                max++;
                                if (included == null || included.ContainsKey(docEntity))
                                {
                                    min++;
                                    format.Write("<b>");
                                }
                                format.Write(docEntity.Name);
                                format.Write("; ");
                                if (included == null || included.ContainsKey(docEntity))
                                {
                                    format.Write("</b>");
                                }
                            }

                            foreach (DocType docType in docSchema.Types)
                            {
                                max++;
                                if (included == null || included.ContainsKey(docType))
                                {
                                    min++;
                                    format.Write("<b>");
                                }
                                format.Write(docType.Name);
                                format.Write("; ");
                                if (included == null || included.ContainsKey(docType))
                                {
                                    format.Write("</b>");
                                }
                            }

                            format.Write("</td>");

                            format.Write("<td>" + min + "/" + max + " (" + (100.0 *(double)min/(double)max).ToString("N0") + "%)</td>");

                            format.WriteLine("</tr>");

                        }
                    }
                }
                format.WriteLine("</table>");

                // 8 Conformance testing procedures

                // 9 Implementation resources

                // 10 Revision Plans

                format.WriteFooter("");
            }
        }
        /// <summary>
        /// Exports file according to format.
        /// </summary>
        /// <param name="filepath">File path to export.</param>
        /// <param name="templates">Optional filter of templates to export.</param>
        /// <param name="views">Optional filter of views to export.</param>
        /// <param name="schemas">Optional filter of schemas to export.</param>
        /// <param name="locales">Optional filter of locales to export.</param>
        public static void DoExport(DocProject docProject, string filepath, DocModelView[] views, string[] locales, Dictionary<long, SEntity> instances)
        {
            string ext = System.IO.Path.GetExtension(filepath).ToLower();

            Dictionary<DocObject, bool> included = null;
            if (views != null)
            {
                included = new Dictionary<DocObject, bool>();
                foreach (DocModelView docView in views)
                {
                    docProject.RegisterObjectsInScope(docView, included);
                }
            }

            switch (ext)
            {
                case ".ifc":
                    using (FormatSPF format = new FormatSPF(filepath, Schema.IFC.SchemaIfc.Types, instances))
                    {
                        format.InitHeaders(docProject.Annotations[0].Code, "IFC4");
                        Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
                        Program.ExportIfc(ifcProject, docProject, included);
                        format.Save();
                    }
                    break;

                case ".ifcxml":
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.IFC.IfcProject), "http://www.buildingsmart-tech.org/ifcXML/IFC4"))
                    {
                        Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
                        Program.ExportIfc(ifcProject, docProject, included);
                        format.Instance = ifcProject;
                        format.Save();
                    }
                    break;

                case ".mvdxml":
                    using (FormatXML format = new FormatXML(filepath, typeof(mvdXML), mvdXML.DefaultNamespace))
                    {
                        mvdXML mvd = new mvdXML();
                        Program.ExportMvd(mvd, docProject, included);
                        format.Instance = mvd;
                        format.Save();
                    }
                    break;

                case ".cs":
                    using (FormatCSC format = new FormatCSC(filepath))
                    {
                        format.Instance = docProject;
                        format.Save();
                    }
                    break;

                case ".exp":
                    // use currently visible model view(s)
                    using (FormatEXP format = new FormatEXP(filepath))
                    {
                        format.Instance = docProject;
                        format.ModelViews = views;
                        format.Save();
                    }
                    break;

                case ".xsd":
                    // use currently visible model view(s)
                    using (FormatXSD format = new FormatXSD(filepath))
                    {
                        format.Instance = docProject;
                        format.ModelViews = views;
                        format.Save();
                    }
                    break;

                case ".xml": // Express XSD Configuration
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.CNF.configuration), null, Schema.CNF.SchemaCNF.Prefixes))
                    {
                        Schema.CNF.configuration config = new Schema.CNF.configuration();
                        Program.ExportCnf(config, docProject, views, included);
                        format.Instance = config;
                        format.Save();
                    }
                    break;

                case ".txt":
                    // pick locale
                    using (FormatCSV format = new FormatCSV(filepath))
                    {
                        format.Instance = docProject;
                        format.Locales = locales;
                        format.Save();
                    }
                    break;

                case ".sch":
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.SCH.schema), "http://purl.oclc.org/dsdl/schematron"))
                    {
                        Schema.SCH.schema sch = new Schema.SCH.schema();
                        Program.ExportSch(sch, docProject, included);
                        format.Instance = sch;
                        format.Save();
                    }
                    break;
            }

        }
        private static void GenerateExample(
            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
            )
        {
            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);
                    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>");

                        if (Properties.Settings.Default.ExampleSPF)
                        {
                            htmExample.Write("<tr><td>IFC-SPF</td><td><a href=\"" + MakeLinkName(docExample) + ".ifc\">File</a></td><td><a href=\"" + MakeLinkName(docExample) + ".ifc.htm\">Markup</a></td></tr>");
                        }
                        if (Properties.Settings.Default.ExampleXML)
                        {
                            htmExample.Write("<tr><td>IFC-XML</td><td><a href=\"" + MakeLinkName(docExample) + ".ifcxml\">File</a></td><td><a href=\"" + MakeLinkName(docExample) + ".ifcxml.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.WriteDocumentationForISO(docExample.Documentation, docExample, false);
                    htmExample.WriteLinkTo(docExample);
                    htmExample.WriteFooter(Properties.Settings.Default.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 (Properties.Settings.Default.ExampleSPF)
                        {
                            using (FormatHTM htmListing = new FormatHTM(pathListing, mapEntity, mapSchema, included))
                            {
                                htmListing.WriteHeader(docExample.Name, 2);

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

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

                            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))
                            {
                                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))
                            {
                                xmlExample.Instance = rootproject;
                                xmlExample.Markup = true;
                                xmlExample.Save();
                            }
                        }

                    }

                }

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

                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(docSub, listFormats, path, indexpath, included, mapEntity, mapSchema, typemap, listFigures, listTables, htmTOC, htmSectionTOC);
                    }
                    indexpath.RemoveAt(indexpath.Count - 1);
                }
            }

        }
Esempio n. 5
0
        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);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Exports file according to format.
        /// </summary>
        /// <param name="filepath">File path to export.</param>
        /// <param name="templates">Optional filter of templates to export.</param>
        /// <param name="views">Optional filter of views to export.</param>
        /// <param name="schemas">Optional filter of schemas to export.</param>
        /// <param name="locales">Optional filter of locales to export.</param>
        public static void DoExport(DocProject docProject, string filepath, DocModelView[] views, string[] locales, Dictionary<long, SEntity> instances)
        {
            string ext = System.IO.Path.GetExtension(filepath).ToLower();

            Dictionary<DocObject, bool> included = null;
            if (views != null)
            {
                included = new Dictionary<DocObject, bool>();
                foreach (DocModelView docView in views)
                {
                    docProject.RegisterObjectsInScope(docView, included);
                }
            }

            // special case for zip files -- determine based on special naming; make configurable in future
            Type typeExport = null;
            if (filepath.EndsWith("-psd.zip"))
            {
                typeExport = typeof(DocPropertySet);
            }
            else if(filepath.EndsWith("-qto.zip"))
            {
                typeExport = typeof(DocQuantitySet);
            }

            switch (ext)
            {
                case ".ifc":
                    using (FormatSPF format = new FormatSPF(filepath, Schema.IFC.SchemaIfc.Types, instances))
                    {
                        string filename = System.IO.Path.GetFileName(filepath);
                        format.InitHeaders(filename, "IFC4"); // we always use IFC4 (not later schema) for exporting templates, as that is the earliest version required.
                        Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
                        Program.ExportIfc(ifcProject, docProject, included);
                        format.Save();
                    }
                    break;

                case ".ifcxml":
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.IFC.IfcProject), "http://www.buildingsmart-tech.org/ifcXML/IFC4"))
                    {
                        Schema.IFC.IfcProject ifcProject = new IfcDoc.Schema.IFC.IfcProject();
                        Program.ExportIfc(ifcProject, docProject, included);
                        format.Instance = ifcProject;
                        format.Save();
                    }
                    break;

                case ".mvdxml":
                    using (FormatXML format = new FormatXML(filepath, typeof(mvdXML), mvdXML.DefaultNamespace))
                    {
                        mvdXML mvd = new mvdXML();
                        Program.ExportMvd(mvd, docProject, included);
                        format.Instance = mvd;
                        format.Save();
                    }
                    break;

                case ".cs":
                    using (FormatCSC format = new FormatCSC(filepath))
                    {
                        format.Instance = docProject;
                        format.Save();
                    }
                    break;

                case ".exp":
                    // use currently visible model view(s)
                    using (FormatEXP format = new FormatEXP(filepath))
                    {
                        format.Instance = docProject;
                        format.ModelViews = views;
                        format.Save();
                    }
                    break;

                case ".xsd":
                    // use currently visible model view(s)
                    using (FormatXSD format = new FormatXSD(filepath))
                    {
                        format.Instance = docProject;
                        format.ModelViews = views;
                        format.Save();
                    }
                    break;

                case ".xml": // Express XSD Configuration
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.CNF.configuration), null, Schema.CNF.SchemaCNF.Prefixes))
                    {
                        Schema.CNF.configuration config = new Schema.CNF.configuration();
                        Program.ExportCnf(config, docProject, views, included);
                        format.Instance = config;
                        format.Save();
                    }
                    break;

                case ".txt":
                    // pick locale
                    using (FormatCSV format = new FormatCSV(filepath))
                    {
                        format.Instance = docProject;
                        format.Locales = locales;
                        format.Save();
                    }
                    break;

                case ".sch":
                    using (FormatXML format = new FormatXML(filepath, typeof(Schema.SCH.schema), "http://purl.oclc.org/dsdl/schematron"))
                    {
                        Schema.SCH.schema sch = new Schema.SCH.schema();
                        Program.ExportSch(sch, docProject, included);
                        format.Instance = sch;
                        format.Save();
                    }
                    break;

                case ".zip":
                    using (FormatZIP format = new FormatZIP(new System.IO.FileStream(filepath, System.IO.FileMode.Create), docProject, included, typeExport))
                    {
                        format.Save();
                    }
                    break;

            }
        }
Esempio n. 7
0
        private void toolStripMenuItemToolsConvert_Click(object sender, EventArgs e)
        {
            using(OpenFileDialog dlgImport = new OpenFileDialog())
            {
                dlgImport.Title = "Convert [Step 1 of 2]: Choose the input file";
                dlgImport.Filter = "IFC-SPF (*.ifc)|*.ifc";
                if(dlgImport.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    using(SaveFileDialog dlgExport = new SaveFileDialog())
                    {
                        dlgExport.Filter =
                            "IFC-JSN (*.ifcjsn)|*.ifcjsn|"+
                            "IFC-RDF (*.ttl)|*.ttl|" +
                            "IFC-XML (*.ifcxml)|*.ifcxml";

                        dlgExport.Title = "Convert [Step 2 of 2]: Specify the output file and format";
                        dlgExport.FileName = System.IO.Path.GetFileNameWithoutExtension(dlgImport.FileName);
                        if(dlgExport.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                        {
                            //todo: run in background, show progress

                            Dictionary<string, Type> typemap = new Dictionary<string, Type>();

                            Compiler compiler = new Compiler(this.m_project, this.m_filterviews, this.m_filterexchange);
                            System.Reflection.Emit.AssemblyBuilder assembly = compiler.Assembly;
                            Type[] types = assembly.GetTypes();
                            foreach (Type t in types)
                            {
                                typemap.Add(t.Name.ToUpper(), t);
                            }

                            Dictionary<long, SEntity> instances = new Dictionary<long, SEntity>();
                            try
                            {
                                m_loading = true;
                                using (FormatSPF format = new FormatSPF(dlgImport.FileName, typemap, instances))
                                {
                                    format.Load();
                                }
                            }
                            catch(Exception xx)
                            {
                                MessageBox.Show(xx.Message);
                                return;
                            }
                            finally
                            {
                                this.m_loading = false;
                            }

                            // build dictionary to map IFC type name to entity and schema
                            Dictionary<string, DocObject> mapEntity = new Dictionary<string, DocObject>();

                            // build dictionary to map IFC type name to schema
                            Dictionary<string, string> mapSchema = new Dictionary<string, string>();

                            this.BuildMaps(mapEntity, mapSchema);

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

                            //TODO: use schema according to source file, look up publication...
                            List<DocXsdFormat> xsdFormatBase = this.m_project.BuildXsdFormatList();
                            string xmlns = "http://www.buildingsmart-tech.org/ifcXML/IFC4/final";
                            string code = "IFC4";//...
                            string ifcowlns = "http://ifcowl.openbimstandards.org/IFC4_ADD1";

                            try
                            {
                                IFormatData formatter = null;
                                switch (dlgExport.FilterIndex)
                                {
                                    case 1:
                                        formatter = new FormatJSN(xsdFormatBase, xmlns, code);
                                        break;

                                    case 2:
                                        formatter = new FormatTTL_Stream(new System.IO.MemoryStream(), ifcowlns);
                                        break;

                                    case 3:
                                        formatter = new FormatSML(new System.IO.MemoryStream(), xsdFormatBase, xmlns, code);
                                        break;
                                }

                                if (formatter != null)
                                {
                                    string content = formatter.FormatData(this.m_project, null, null, mapEntity, instances, rootproject, false);

                                    using (System.IO.FileStream filestream = System.IO.File.OpenWrite(dlgExport.FileName))
                                    {
                                        System.IO.TextWriter writer = new System.IO.StreamWriter(filestream);
                                        writer.Write(content);
                                        writer.Flush();
                                        filestream.Close();
                                    }
                                }
                            }
                            catch (Exception yy)
                            {
                                MessageBox.Show(yy.Message);
                                return;
                            }
                        }
                    }
                }
            }
            //...
        }
Esempio n. 8
0
        private void toolStripMenuItemFileUpdate_Click(object sender, EventArgs e)
        {
            DialogResult res = this.openFileDialogUpdate.ShowDialog(this);
            if (res == DialogResult.OK)
            {
                foreach (string filename in this.openFileDialogUpdate.FileNames)
                {
                    string ext = System.IO.Path.GetExtension(filename).ToLower();
                    switch (ext)
                    {
                        case ".vex":
                            using (FormatSPF format = new FormatSPF(filename, SchemaVEX.Types, null))
                            {
                                format.Load();

                                // loop through relevent entities, update from database
                                foreach (SEntity entity in format.Instances.Values)
                                {
                                    if (entity is ENTITIES)
                                    {
                                        ENTITIES ent = (ENTITIES)entity;
                                        if (ent.comment != null && ent.comment.text != null)
                                        {
                                            // get corresponding instance in documentation database
                                            TreeNode tn = null;
                                            if (this.m_mapTree.TryGetValue(ent.name.text.ToLowerInvariant(), out tn))
                                            {
                                                DocEntity docEntity = (DocEntity)tn.Tag;

                                                ent.comment.text.text = docEntity.Documentation;

                                                // also update attributes
                                                if (ent.attributes != null)
                                                {
                                                    foreach (ATTRIBUTE_DEF attr in ent.attributes)
                                                    {
                                                        if (attr.comment != null && attr.comment.text != null)
                                                        {
                                                            foreach (DocAttribute docattr in docEntity.Attributes)
                                                            {
                                                                if (docattr.Name.Equals(attr.name.text))
                                                                {
                                                                    attr.comment.text.text = docattr.Documentation;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }

                                                // where rules
                                                if (ent.wheres != null)
                                                {
                                                    foreach (WHERE_RULE attr in ent.wheres)
                                                    {
                                                        if (attr.comment != null && attr.comment.text != null)
                                                        {
                                                            foreach (DocWhereRule docattr in docEntity.WhereRules)
                                                            {
                                                                if (docattr.Name.Equals(attr.name))
                                                                {
                                                                    attr.comment.text.text = docattr.Documentation;
                                                                    attr.rule_context = docattr.Expression; // update where rule expression
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else if (entity is ENUMERATIONS)
                                    {
                                        ENUMERATIONS ent = (ENUMERATIONS)entity;
                                        if (ent.comment != null && ent.comment.text != null)
                                        {
                                            TreeNode tn = null;
                                            if (this.m_mapTree.TryGetValue(ent.name.text.ToLowerInvariant(), out tn))
                                            {
                                                DocEnumeration docEntity = (DocEnumeration)tn.Tag;
                                                ent.comment.text.text = docEntity.Documentation;
                                            }

                                        }
                                    }
                                    else if (entity is DEFINED_TYPE)
                                    {
                                        DEFINED_TYPE ent = (DEFINED_TYPE)entity;
                                        if (ent.comment != null && ent.comment.text != null)
                                        {
                                            TreeNode tn = null;
                                            if (this.m_mapTree.TryGetValue(ent.name.text.ToLowerInvariant(), out tn))
                                            {
                                                DocDefined docEntity = (DocDefined)tn.Tag;
                                                ent.comment.text.text = docEntity.Documentation;
                                            }
                                        }
                                    }
                                    else if (entity is SELECTS)
                                    {
                                        SELECTS ent = (SELECTS)entity;
                                        if (ent.comment != null && ent.comment.text != null)
                                        {
                                            TreeNode tn = null;
                                            if (this.m_mapTree.TryGetValue(ent.name.text.ToLowerInvariant(), out tn))
                                            {
                                                DocSelect docEntity = (DocSelect)tn.Tag;
                                                ent.comment.text.text = docEntity.Documentation;
                                            }
                                        }
                                    }
                                    else if (entity is GLOBAL_RULE)
                                    {
                                        GLOBAL_RULE rule = (GLOBAL_RULE)entity;
                                        if (rule.comment != null && rule.comment.text != null)
                                        {
                                            TreeNode tn = null;
                                            if (this.m_mapTree.TryGetValue(rule.name.ToLowerInvariant(), out tn))
                                            {
                                                DocGlobalRule docEntity = (DocGlobalRule)tn.Tag;
                                                rule.comment.text.text = docEntity.Documentation;
                                                rule.rule_context = docEntity.Expression;
                                            }
                                        }
                                    }
                                    else if (entity is USER_FUNCTION)
                                    {
                                        USER_FUNCTION func = (USER_FUNCTION)entity;
                                        TreeNode tn = null;
                                        if (func.name != null && this.m_mapTree.TryGetValue(func.name.ToLowerInvariant(), out tn))
                                        {
                                            DocFunction docFunc = (DocFunction)tn.Tag;
                                            if (func.comment != null && func.comment.text != null)
                                            {
                                                func.comment.text.text = docFunc.Documentation;
                                            }
                                            func.rule_context = docFunc.Expression;
                                        }
                                    }
                                    else if (entity is USER_PROCEDURE)
                                    {
                                        //?? unused for IFC
                                    }
                                    else if (entity is SCHEMATA)
                                    {
                                        SCHEMATA ent = (SCHEMATA)entity;
                                        if (ent.comment != null && ent.comment.text != null)
                                        {
                                            TreeNode tn = null;
                                            if (this.m_mapTree.TryGetValue(ent.name.ToLowerInvariant(), out tn))
                                            {
                                                DocSchema docSchema = (DocSchema)tn.Tag;
                                                ent.comment.text.text = docSchema.Documentation;
                                            }
                                        }
                                    }
                                }

                                format.Save();
                            }
                            break;
                    }
                }
            }
        }
Esempio n. 9
0
        private void toolStripMenuItemFileSave_Click(object sender, EventArgs e)
        {
            if (this.m_file != null)
            {
                string ext = System.IO.Path.GetExtension(this.m_file).ToLower();

                try
                {
                    switch (ext)
                    {
                        case ".ifcdoc":
                            using (FormatSPF format = new FormatSPF(this.m_file, SchemaDOC.Types, this.m_instances))
                            {
                                format.InitHeaders(this.m_file, "IFCDOC_10_4");
                                format.Save();
                            }
                            break;

            #if MDB
                        case ".mdb":
                            using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances))
                            {
                                format.Save();
                            }
                            break;
            #endif
                    }
                    this.m_modified = false;
                }
                catch (System.Exception x)
                {
                    MessageBox.Show(x.Message);
                }

                // then optionally upload if connected to server
                if (this.m_server != null)
                {
                    this.toolStripMenuItemPublish_Click(this, EventArgs.Empty);
                }
            }
            else
            {
                toolStripMenuItemFileSaveAs_Click(sender, e);
            }
        }
Esempio n. 10
0
        private void toolStripMenuItemFileImport_Click(object sender, EventArgs e)
        {
            StringBuilder sbErrors = new StringBuilder();

            DialogResult res = this.openFileDialogImport.ShowDialog(this);
            if (res == DialogResult.OK)
            {
                List<DocSchema> importedschemas = new List<DocSchema>();

                bool updateDescriptions = false;
                if(this.openFileDialogImport.FileName.EndsWith(".vex"))
                {
                    DialogResult resUpdate = MessageBox.Show(this, "Do you want to update the documentation? Click Yes to update documentation and definitions, or No to update just definitions.", "Import VEX", MessageBoxButtons.YesNoCancel);
                    if (resUpdate == System.Windows.Forms.DialogResult.Cancel)
                        return;

                    if (resUpdate == System.Windows.Forms.DialogResult.Yes)
                        updateDescriptions = true;
                }

                foreach (string filename in this.openFileDialogImport.FileNames)
                {
                    string ext = System.IO.Path.GetExtension(filename).ToLower();
                    switch (ext)
                    {
                        case ".vex":
                            using (FormatSPF format = new FormatSPF(filename, SchemaVEX.Types, null))
                            {
                                format.Load();

                                // get the root schemata
                                SCHEMATA vexschema = null;
                                foreach (SEntity entity in format.Instances.Values)
                                {
                                    if (entity is SCHEMATA)
                                    {
                                        vexschema = (SCHEMATA)entity;
                                        break;
                                    }
                                }

                                if (vexschema != null)
                                {
                                    DocSchema schema = Program.ImportVex(vexschema, this.m_project, updateDescriptions);
                                    importedschemas.Add(schema); // add schemas from multiple files first, process later
                                }
                            }
                            break;

                        case ".xml":
                            if (filename.Contains("Pset_"))
                            {
                                using (FormatXML format = new FormatXML(filename, typeof(PropertySetDef), "http://buildingSMART-tech.org/xml/psd/PSD_IFC4.xsd"))
                                {
                                    format.Load();
                                    PropertySetDef psd = (PropertySetDef)format.Instance;

                                    string schema = null;
                                    if (psd.Versions != null && psd.Versions.Count > 0)
                                    {
                                        schema = psd.Versions[0].schema;
                                    }

                                    if (String.IsNullOrEmpty(schema))
                                    {
                                        // guess the schema according to applicable type value
                                        if (psd.ApplicableTypeValue != null)
                                        {
                                            string[] parts = psd.ApplicableTypeValue.Split(new char[] { '/', '[' });
                                            TreeNode tnEntity = null;
                                            if (this.m_mapTree.TryGetValue(parts[0].ToLowerInvariant(), out tnEntity))
                                            {
                                                DocSchema docschema = (DocSchema)tnEntity.Parent.Parent.Tag;
                                                schema = docschema.Name;
                                            }
                                        }
                                    }

                                    if(schema == null)
                                    {
                                        schema = "IfcProductExtension";//fallback
                                    }

                                    // find the schema
                                    TreeNode tn = null;
                                    if (schema != null && this.m_mapTree.TryGetValue(schema.ToLowerInvariant(), out tn))
                                    {
                                        DocSchema docschema = (DocSchema)tn.Tag;

                                        // find existing pset if applicable
                                        DocPropertySet pset = docschema.RegisterPset(psd.Name);

                                        // use hashed guid
                                        if (pset.Uuid == Guid.Empty)
                                        {
                                            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
                                            byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(pset.Name));
                                            pset.Uuid = new Guid(hash);
                                        }

                                        pset.Name = psd.Name;
                                        if (psd.Definition != null)
                                        {
                                            pset.Documentation = psd.Definition.Trim();
                                        }
                                        if (psd.ApplicableTypeValue != null)
                                        {
                                            pset.ApplicableType = psd.ApplicableTypeValue.Replace("Type", "").Replace("[PerformanceHistory]", ""); // organize at occurrences; use pset type to determine type applicability
                                        }

                                        // for now, rely on naming convention (better to capture in pset schema eventually)
                                        if (psd.Name.Contains("PHistory")) // special naming convention
                                        {
                                            pset.PropertySetType = "PSET_PERFORMANCEDRIVEN";
                                        }
                                        else if (psd.Name.Contains("Occurrence"))
                                        {
                                            pset.PropertySetType = "PSET_OCCURRENCEDRIVEN";
                                        }
                                        else
                                        {
                                            pset.PropertySetType = "PSET_TYPEDRIVENOVERRIDE";
                                        }

                                        // import localized definitions
                                        if (psd.PsetDefinitionAliases != null)
                                        {
                                            foreach (PsetDefinitionAlias pl in psd.PsetDefinitionAliases)
                                            {
                                                pset.RegisterLocalization(pl.lang, null, pl.Value);
                                            }
                                        }

                                        foreach (PropertyDef subdef in psd.PropertyDefs)
                                        {
                                            DocProperty docprop = pset.RegisterProperty(subdef.Name);
                                            Program.ImportPsdPropertyTemplate(subdef, docprop);
                                        }

                                        // add to Use Definition at applicable entity
            #if false
                                        if (pset.ApplicableType != null)
                                        {
                                            string[] apptypes = pset.ApplicableType.Split('/');
                                            if (this.m_mapTree.TryGetValue(apptypes[0].ToLowerInvariant(), out tn))
                                            {
                                                DocEntity entity = (DocEntity)tn.Tag;

                                                if (this.m_project.ModelViews.Count == 0)
                                                {
                                                    // must have at least one model view for populating property set links
                                                    this.m_project.ModelViews.Add(new DocModelView());
                                                }

                                                foreach (DocModelView docView in this.m_project.ModelViews)
                                                {
                                                    DocConceptRoot docRoot = null;
                                                    foreach (DocConceptRoot eachRoot in docView.ConceptRoots)
                                                    {
                                                        if (eachRoot.ApplicableEntity == entity)
                                                        {
                                                            docRoot = eachRoot;
                                                            break;
                                                        }
                                                    }

                                                    if (docRoot == null)
                                                    {
                                                        docRoot = new DocConceptRoot();
                                                        docRoot.ApplicableEntity = entity;
                                                        docView.ConceptRoots.Add(docRoot);
                                                    }

                                                    // find the pset template
                                                    DocTemplateUsage templateuse = null;
                                                    foreach (DocTemplateUsage eachtemplateuse in docRoot.Concepts)
                                                    {
                                                        if (eachtemplateuse.Definition != null && eachtemplateuse.Definition.Name.StartsWith("Property"))
                                                        {
                                                            templateuse = eachtemplateuse;
                                                            break;
                                                        }
                                                    }

                                                    DocTemplateDefinition docdefpset = this.m_project.GetTemplate(new Guid("f74255a6-0c0e-4f31-84ad-24981db62461"));
                                                    if (docdefpset != null)
                                                    {
                                                        // if no template, add it
                                                        if (templateuse == null)
                                                        {
                                                            // get the pset template
                                                            templateuse = new DocTemplateUsage();
                                                            docRoot.Concepts.Add(templateuse);
                                                            templateuse.Definition = docdefpset;
                                                        }

                                                        DocTemplateItem templateitem = new DocTemplateItem();
                                                        templateuse.Items.Add(templateitem);
                                                        templateitem.RuleInstanceID = "IfcPropertySet";

                                                        if (apptypes.Length == 2)
                                                        {
                                                            templateitem.RuleParameters += "PredefinedType=" + apptypes[1] + ";";
                                                        }
                                                        templateitem.RuleParameters += "Name=" + pset.Name + ";";
                                                        templateitem.RuleParameters += "TemplateType=" + pset.PropertySetType + ";";
                                                        // don't include documentation -- too wordy templateitem.Documentation = pset.Documentation;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                sbErrors.Append(System.IO.Path.GetFileNameWithoutExtension(filename) + ": unrecognized ApplicableTypeValue; ");
                                            }
                                        }
            #endif
                                    }
                                    else
                                    {
                                        sbErrors.Append(System.IO.Path.GetFileNameWithoutExtension(filename) + ": unrecognized schema; ");
                                    }

                                }
                            }
                            else if (filename.Contains("Qto_"))
                            {
                                using (FormatXML format = new FormatXML(filename, typeof(QtoSetDef)))
                                {
                                    format.Load();
                                    QtoSetDef qto = (QtoSetDef)format.Instance;

                                    string schema = qto.Versions[0].schema;
                                    TreeNode tn = null;
                                    if (schema != null && this.m_mapTree.TryGetValue(schema.ToLowerInvariant(), out tn))
                                    {
                                        DocSchema docschema = (DocSchema)tn.Tag;

                                        // find existing pset if applicable
                                        DocQuantitySet qset = docschema.RegisterQset(qto.Name);

                                        // use hashed guid
                                        if (qset.Uuid == Guid.Empty)
                                        {
                                            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
                                            byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(qset.Name));
                                            qset.Uuid = new Guid(hash);
                                        }

                                        // everything is currently named "Base Quantities"; get name from file instead; e.g. "Qto_Beam"
                                        qset.Name = System.IO.Path.GetFileNameWithoutExtension(filename);
                                        qset.Documentation = qto.Definition;
                                        qset.ApplicableType = qto.ApplicableClasses[0].Value;

                                        // fix: remove "Type"
                                        if (qset.ApplicableType.EndsWith("Type"))
                                        {
                                            qset.ApplicableType = qset.ApplicableType.Substring(0, qset.ApplicableType.Length - 4);
                                        }

                                        // import localized definitions
                                        if (qto.QtoDefinitionAliases != null)
                                        {
                                            foreach (QtoDefinitionAlias pl in qto.QtoDefinitionAliases)
                                            {
                                                qset.RegisterLocalization(pl.lang, null, pl.Value);
                                            }
                                        }

                                        foreach (QtoDef qtodef in qto.QtoDefs)
                                        {
                                            DocQuantity q = qset.RegisterQuantity(qtodef.Name);
                                            q.Documentation = qtodef.Definition;

                                            switch (qtodef.QtoType)
                                            {
                                                case "IfcQuantityCount":
                                                    q.QuantityType = DocQuantityTemplateTypeEnum.Q_COUNT;
                                                    break;

                                                case "IfcQuantityLength":
                                                    q.QuantityType = DocQuantityTemplateTypeEnum.Q_LENGTH;
                                                    break;

                                                case "IfcQuantityArea":
                                                    q.QuantityType = DocQuantityTemplateTypeEnum.Q_AREA;
                                                    break;

                                                case "IfcQuantityVolume":
                                                    q.QuantityType = DocQuantityTemplateTypeEnum.Q_VOLUME;
                                                    break;

                                                case "IfcQuantityWeight":
                                                    q.QuantityType = DocQuantityTemplateTypeEnum.Q_WEIGHT;
                                                    break;

                                                case "IfcQuantityTime":
                                                    q.QuantityType = DocQuantityTemplateTypeEnum.Q_TIME;
                                                    break;
                                            }

                                            foreach (NameAlias namealias in qtodef.NameAliases)
                                            {
                                                string desc = null;
                                                foreach (DefinitionAlias docalias in qtodef.DefinitionAliases)
                                                {
                                                    if (docalias.lang.Equals(namealias.lang))
                                                    {
                                                        desc = docalias.Value;
                                                        break;
                                                    }
                                                }

                                                q.RegisterLocalization(namealias.lang, namealias.Value, desc);
                                            }

                                        }

                                        // map to use definition
                                        if (this.m_mapTree.TryGetValue(qset.ApplicableType.ToLowerInvariant(), out tn))
                                        {
                                            DocEntity entity = (DocEntity)tn.Tag;

                                            if (this.m_project.ModelViews.Count == 0)
                                            {
                                                // must have at least one model view for populating property set links
                                                this.m_project.ModelViews.Add(new DocModelView());
                                            }

                                            foreach (DocModelView docView in this.m_project.ModelViews)
                                            {
                                                DocConceptRoot docRoot = null;
                                                foreach (DocConceptRoot eachRoot in docView.ConceptRoots)
                                                {
                                                    if (eachRoot.ApplicableEntity == entity)
                                                    {
                                                        docRoot = eachRoot;
                                                        break;
                                                    }
                                                }

                                                if (docRoot == null)
                                                {
                                                    docRoot = new DocConceptRoot();
                                                    docRoot.ApplicableEntity = entity;
                                                    docView.ConceptRoots.Add(docRoot);
                                                }

                                                // find the qset template
                                                DocTemplateUsage templateuse = null;
                                                foreach (DocTemplateUsage eachtemplateuse in docRoot.Concepts)
                                                {
                                                    if (eachtemplateuse.Definition.Name.StartsWith("Quantity"))
                                                    {
                                                        templateuse = eachtemplateuse;
                                                        break;
                                                    }
                                                }

                                                // if no template, add it
                                                if (templateuse == null)
                                                {
                                                    // get the pset template
                                                    templateuse = new DocTemplateUsage();
                                                    docRoot.Concepts.Add(templateuse);
                                                    templateuse.Definition = this.m_project.GetTemplate(new Guid("6652398e-6579-4460-8cb4-26295acfacc7"));
                                                }

                                                if (templateuse != null)
                                                {
                                                    DocTemplateItem templateitem = new DocTemplateItem();
                                                    templateuse.Items.Add(templateitem);
                                                    templateitem.RuleInstanceID = "IfcElementQuantity";
                                                    templateitem.RuleParameters = "Name=" + qset.Name + ";TemplateType=QTO_OCCURRENCEDRIVEN;";
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        sbErrors.Append(System.IO.Path.GetFileNameWithoutExtension(filename) + ": unrecognized schema; ");
                                    }
                                }
                            }
                            else if (filename.Contains("ifcXML"))
                            {
                                using (FormatXML format = new FormatXML(filename, typeof(configuration), null, SchemaCNF.Prefixes))
                                {
                                    try
                                    {
                                        this.m_loading = true; // prevent constructors from registering instances (xml serializer instantiates)
                                        format.Load();

                                        DocModelView docView = null;
                                        using(FormSelectView form = new FormSelectView(this.m_project, null))
                                        {
                                            if(form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && form.Selection != null && form.Selection.Length == 1)
                                            {
                                                docView = form.Selection[0];
                                            }
                                        }

                                        configuration cnf = (configuration)format.Instance;
                                        Program.ImportCnf(cnf, this.m_project, docView);
                                    }
                                    catch (Exception xx)
                                    {
                                        MessageBox.Show(this, xx.Message, "Import CNFXML");
                                    }
                                    finally
                                    {
                                        this.m_loading = false;
                                    }
                                }
                            }
                            break;

                        case ".mvdxml":
                            this.ImportMVD(filename);
                            break;

                        case ".txt":
                            using (FormatCSV format = new FormatCSV(filename))
                            {
                                try
                                {
                                    format.Instance = this.m_project;
                                    format.Load();
                                }
                                catch (System.Exception xx)
                                {
                                    MessageBox.Show(this, xx.Message, "Import CSV");
                                }
                            }
                            break;

                        case ".ifd":
                            using (FormatIFD format = new FormatIFD(filename))
                            {
                                try
                                {
                                    format.Instance = this.m_project;
                                    format.Load();
                                }
                                catch (System.Exception xx)
                                {
                                    MessageBox.Show(this, xx.Message, "Import IFD");
                                }
                            }
                            break;

                        case ".xsd":
                            using (FormatXML format = new FormatXML(filename, typeof(IfcDoc.Schema.XSD.schema), IfcDoc.Schema.XSD.SchemaXsd.DefaultNamespace))
                            {
                                try
                                {
                                    format.Load();
                                    DocSchema docSchema = Program.ImportXsd((IfcDoc.Schema.XSD.schema)format.Instance, this.m_project);
                                    if(docSchema.Name == null)
                                    {
                                        docSchema.Name = System.IO.Path.GetFileNameWithoutExtension(filename);
                                    }
                                }
                                catch(System.Exception xx)
                                {
                                    MessageBox.Show(this, xx.Message, "Import XSD");
                                }
                            }
                            break;
                    }

                }

                // load tree before generating use definitions
                this.LoadTree();

                // load tree again to pick up definitions
                if (importedschemas.Count > 0)
                {
                    LoadTree();
                }
            }

            if (sbErrors.Length > 0)
            {
                MessageBox.Show(this, "Import succeeded, however one or more definitions have missing or incorrect information:\r\n" + sbErrors.ToString(), "Import Errors");
            }
        }
Esempio n. 11
0
        private void backgroundWorkerValidate_DoWork(object sender, DoWorkEventArgs e)
        {
            if (this.m_filterviews == null)
                return;

            // reset state
            foreach(DocTemplateDefinition template in this.m_project.Templates)
            {
                TemplateReset(template);
            }

            // count active roots
            int progressTotal = 2;
            foreach (DocModelView docView in this.m_filterviews)
            {
                // reset state
                foreach(DocConceptRoot docRoot in docView.ConceptRoots)
                {
                    foreach(DocTemplateUsage docUsage in docRoot.Concepts)
                    {
                        docUsage.ResetValidation();
                    }
                }

                progressTotal += docView.ConceptRoots.Count;
            }
            this.m_formProgress.SetProgressTotal(progressTotal);
            int progress = 0;

            // build schema dynamically
            this.backgroundWorkerValidate.ReportProgress(++progress, "Compiling schema...");
            Dictionary<string, Type> typemap = new Dictionary<string, Type>();

            Compiler compiler = new Compiler(this.m_project, this.m_filterviews, this.m_filterexchange);
            System.Reflection.Emit.AssemblyBuilder assembly = compiler.Assembly;

            this.m_assembly = assembly;

            Type[] types = assembly.GetTypes();
            foreach (Type t in types)
            {
                typemap.Add(t.Name.ToUpper(), t);
            }

            int grandtotallist = 0;
            int grandtotalskip = 0;
            int grandtotalpass = 0;
            StringBuilder sb = new StringBuilder();

            // Example:
            // | IfcWall   | #2, #3 | PASS (30/30) |
            // | +Identity | #2     | FAIL (23/30) |

            try
            {
                m_loading = true;
                Dictionary<long, SEntity> instances = new Dictionary<long, SEntity>();
                this.backgroundWorkerValidate.ReportProgress(++progress, "Loading file...");
                using (FormatSPF format = new FormatSPF(Properties.Settings.Default.ValidateFile, typemap, instances))
                {
                    format.Load();

                    string[] errors = format.Errors;
                    if (errors != null && errors.Length > 0)
                    {
                        sb.AppendLine("This file contains format errors which may impact data validation results:");
                        sb.AppendLine("<ul>");
                        for (int i = 0; i < errors.Length; i++)
                        {
                            sb.AppendLine("<li>" + errors[i] + "</li>");
                        }
                        sb.AppendLine("</ul>");
                    }

                    // now iterate through each concept root
                    foreach (DocModelView docView in this.m_filterviews)
                    {
                        foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                        {
                            if (this.backgroundWorkerValidate.CancellationPending)
                                return;

                            this.backgroundWorkerValidate.ReportProgress(++progress, docRoot);

                            Type typeEntity = null;
                            if (typemap.TryGetValue(docRoot.ApplicableEntity.Name.ToUpper(), out typeEntity))
                            {
                                // build list of instances
                                List<SEntity> list = new List<SEntity>();
                                foreach (SEntity instance in format.Instances.Values)
                                {
                                    if (typeEntity.IsInstanceOfType(instance))
                                    {
                                        list.Add(instance);
                                    }
                                }

                                //if (list.Count > 0)
                                {
                                    sb.AppendLine("<h3>" + docRoot.ApplicableEntity.Name + " (" + list.Count + ")</h3>");

                                    foreach (DocTemplateUsage docUsage in docRoot.Concepts)
                                    {
                                        ValidateConcept(docUsage, docView, DocExchangeRequirementEnum.NotRelevant, typeEntity, list, sb, typemap, ref grandtotalpass, ref grandtotalskip, ref grandtotallist);
                                    }
                                }
                            }
                        }
                    }
                    this.m_formatTest = format;
                }
            }
            catch (Exception x)
            {
                this.m_exception = x;
            }
            finally
            {
                m_loading = false;
            }

            sb.AppendLine("</table>");

            // create html doc
            int grandtotalpercent = 0;
            if (grandtotallist > 0)
            {
                grandtotalpercent = 100 * (grandtotalpass + grandtotalskip) / grandtotallist;
            }

            if (Properties.Settings.Default.ValidateReport)
            {
                string path = Properties.Settings.Default.ValidateFile + ".htm";
                using (System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create))
                {
                    using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fs))
                    {
                        writer.WriteLine("<html>");
                        writer.WriteLine("<body>");

                        string exchange = null;
                        if (this.m_filterexchange != null)
                        {
                            exchange = this.m_filterexchange.Name;
                        }

                        writer.WriteLine("<h1>Validation Results</h1>");
                        writer.WriteLine("<table border='1'>");
                        writer.WriteLine("<tr><td>Instance File</td><td>" + Properties.Settings.Default.ValidateFile + "</td></tr>");
                        writer.WriteLine("<tr><td>Project File</td><td>" + this.m_file + "</td></tr>");
                        writer.WriteLine("<tr><td>Model View</td><td>" + this.m_filterviews[0].Name + "</td></tr>");
                        writer.WriteLine("<tr><td>Exchange</td><td>" + exchange + "</td></tr>");
                        writer.WriteLine("<tr><td>Tests Executed</td><td>" + grandtotallist + "</td></tr>");
                        writer.WriteLine("<tr><td>Tests Passed</td><td>" + grandtotalpass + "</td></tr>");
                        writer.WriteLine("<tr><td>Tests Ignored</td><td>" + grandtotalskip + "</td></tr>");
                        writer.WriteLine("<tr><td>Tests Percentage</td><td>" + grandtotalpercent + "%</td></tr>");
                        writer.WriteLine("</table>");

                        writer.WriteLine(sb.ToString());

                        writer.WriteLine("</body>");
                        writer.WriteLine("</html>");
                    }
                }

                // launch
                System.Diagnostics.Process.Start(path);
            }
        }
Esempio n. 12
0
        private void mergeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult res = this.openFileDialogMerge.ShowDialog();
            if (res != DialogResult.OK)
                return;

            // load file into different context, compare
            this.m_loading = true;

            Dictionary<long, SEntity> instances = new Dictionary<long, SEntity>();
            using (FormatSPF format = new FormatSPF(this.openFileDialogMerge.FileName, SchemaDOC.Types, instances))
            {
                format.Load();
            }

            this.m_loading = false;

            // now import changes
            DocProject docProjectBase = null;
            foreach (SEntity o in instances.Values)
            {
                if (o is DocProject)
                {
                    docProjectBase = (DocProject)o;
                }
            }

            // create guid map for rapid lookup
            Dictionary<Guid, DocObject> mapGuid = new Dictionary<Guid, DocObject>();
            foreach (SEntity o in this.m_instances.Values)
            {
                if (o is DocObject)
                {
                    DocObject docObj = (DocObject)o;
                    try
                    {
                        mapGuid.Add(docObj.Uuid, docObj);
                    }
                    catch
                    {
                        System.Diagnostics.Debug.WriteLine("Duplicate Guid: " + docObj.Uuid.ToString() + " - " + docObj.GetType().ToString() + " - " + docObj.Name);
                    }
                }
            }

            using (FormMerge formMerge = new FormMerge(mapGuid, docProjectBase))
            {
                res = formMerge.ShowDialog(this);
                if(res == System.Windows.Forms.DialogResult.OK)
                {
                    this.LoadTree();
                }
            }
        }
Esempio n. 13
0
        private void LoadFile(string filename)
        {
            this.SetCurrentFile(filename);

            this.m_lastid = 0;
            this.m_instances.Clear();
            this.m_mapTree.Clear();
            this.m_clipboard = null;
            this.m_project = null;

            List<DocChangeAction> listChange = new List<DocChangeAction>(); //temp

            string ext = System.IO.Path.GetExtension(this.m_file).ToLower();
            try
            {
                switch (ext)
                {
                    case ".ifcdoc":
                        using (FormatSPF format = new FormatSPF(this.m_file, SchemaDOC.Types, this.m_instances))
                        {
                            format.Load();
                        }
                        break;

            #if MDB
                    case ".mdb":
                        using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances))
                        {
                            format.Load();
                        }
                        break;
            #endif
                }
            }
            catch (Exception x)
            {
                MessageBox.Show(this, x.Message, "Error", MessageBoxButtons.OK);

                // force new as state is now invalid
                this.m_modified = false;
                this.toolStripMenuItemFileNew_Click(this, EventArgs.Empty);
                return;
            }

            List<SEntity> listDelete = new List<SEntity>();
            List<DocTemplateDefinition> listTemplate = new List<DocTemplateDefinition>();

            // get the project, determine the next OID to use
            foreach (SEntity o in this.m_instances.Values)
            {
                if (o is DocProject)
                {
                    this.m_project = (DocProject)o;
                }
                else if (o is DocEntity)
                {
                    DocEntity docent = (DocEntity)o;

            #if false
                    // files before V5.3 had Description field; no longer needed so use regular Documentation field again.
                    if (docent._Description != null)
                    {
                        docent.Documentation = docent._Description;
                        docent._Description = null;
                    }
            #endif
                }
                else if(o is DocAttribute)
                {
            #if false
                    // files before V8.7 didn't have nullable tagless
                    DocAttribute docAttr = (DocAttribute)o;
                    if (docAttr.XsdTagless == false)
                    {
                        docAttr.XsdTagless = null;
                    }
            #endif
                }
                else if(o is DocSchema)
                {
                    DocSchema docSchema = (DocSchema)o;

                    // renumber page references
                    foreach (DocPageTarget docTarget in docSchema.PageTargets)
                    {
                        int page = docSchema.GetDefinitionPageNumber(docTarget);
                        int item = docSchema.GetPageTargetItemNumber(docTarget);
                        docTarget.Name = page + "," + item + " " + docTarget.Definition.Name;

                        foreach(DocPageSource docSource in docTarget.Sources)
                        {
                            docSource.Name = docTarget.Name;
                        }
                    }
                }
                else if (o is DocExchangeDefinition)
                {
                    // files before V4.9 had Description field; no longer needed so use regular Documentation field again.
                    DocExchangeDefinition docexchange = (DocExchangeDefinition)o;
                    if (docexchange._Description != null)
                    {
                        docexchange.Documentation = docexchange._Description;
                        docexchange._Description = null;
                    }
                }
                else if (o is DocTemplateDefinition)
                {
                    // files before V5.0 had Description field; no longer needed so use regular Documentation field again.
                    DocTemplateDefinition doctemplate = (DocTemplateDefinition)o;
                    if (doctemplate._Description != null)
                    {
                        doctemplate.Documentation = doctemplate._Description;
                        doctemplate._Description = null;
                    }

                    listTemplate.Add((DocTemplateDefinition)o);
                }
                else if(o is DocChangeAction)
                {
                    // tempdebug -- delete old change actions -- need to clean up
                    //o.Delete();
                    listChange.Add((DocChangeAction)o);
                }

                // ensure all objects have valid guid
                if (o is DocObject)
                {
                    DocObject docobj = (DocObject)o;
                    if (docobj.Uuid == Guid.Empty)
                    {
                        docobj.Uuid = Guid.NewGuid();
                    }

            #if false
                    // ensure any image references are in lowercase
                    if(docobj.Documentation != null && docobj.Documentation.Length > 0)
                    {
                        int i = 0;
                        while (i != -1)
                        {
                            i = docobj.Documentation.IndexOf("../figures/", i + 1);
                            if(i != -1)
                            {
                                int start = i + 11;
                                int end = docobj.Documentation.IndexOf('"', start);
                                if(end > start)
                                {
                                    string strold = docobj.Documentation.Substring(start, end - start);
                                    string strnew = strold.ToLower();

                                    docobj.Documentation = docobj.Documentation.Substring(0, start) + strnew + docobj.Documentation.Substring(end);
                                    System.Diagnostics.Debug.WriteLine(strnew);
                                }
                            }
                        }
                    }
            #endif
                }

                if (o.OID > this.m_lastid)
                {
                    this.m_lastid = o.OID;
                }
            }

            if (this.m_project == null)
            {
                MessageBox.Show(this, "File is invalid; no project is defined.", "Error", MessageBoxButtons.OK);
                return;
            }

            //tempcleanip
            //for (int i = listChange.Count - 1; i >= 0;i-- )
            {
                //listChange[i].Delete();
            }

                // now capture any template definitions (upgrade in V3.5)
                foreach (DocModelView docModelView in this.m_project.ModelViews)
                {
                    if (docModelView.ConceptRoots == null)
                    {
                        // must convert to new format
                        docModelView.ConceptRoots = new List<DocConceptRoot>();

                        foreach (DocSection docSection in this.m_project.Sections)
                        {
                            foreach (DocSchema docSchema in docSection.Schemas)
                            {
                                foreach (DocEntity docEntity in docSchema.Entities)
                                {
                                    if (docEntity.__Templates != null)
                                    {
                                        foreach (DocTemplateUsage docTemplateUsage in docEntity.__Templates)
                                        {
                                            // must generate or use existing concept root

                                            DocConceptRoot docConceptRoot = null;
                                            foreach (DocConceptRoot eachConceptRoot in docModelView.ConceptRoots)
                                            {
                                                if (eachConceptRoot.ApplicableEntity == docEntity)
                                                {
                                                    docConceptRoot = eachConceptRoot;
                                                    break;
                                                }
                                            }

                                            if (docConceptRoot == null)
                                            {
                                                docConceptRoot = new DocConceptRoot();
                                                docConceptRoot.ApplicableEntity = docEntity;
                                                docModelView.ConceptRoots.Add(docConceptRoot);
                                            }

                                            docConceptRoot.Concepts.Add(docTemplateUsage);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

            // upgrade to Publications (V9.6)
            if (this.m_project.Annotations.Count == 4)
            {
                this.m_project.Publications.Clear();

                DocAnnotation docCover = this.m_project.Annotations[0];
                DocAnnotation docContents = this.m_project.Annotations[1];
                DocAnnotation docForeword = this.m_project.Annotations[2];
                DocAnnotation docIntro = this.m_project.Annotations[3];

                DocPublication docPub = new DocPublication();
                docPub.Name = "Default";
                docPub.Documentation = docCover.Documentation;
                docPub.Owner = docCover.Owner;
                docPub.Author = docCover.Author;
                docPub.Code = docCover.Code;
                docPub.Copyright = docCover.Copyright;
                docPub.Status = docCover.Status;
                docPub.Version = docCover.Version;

                docPub.Annotations.Add(docForeword);
                docPub.Annotations.Add(docIntro);

                this.m_project.Publications.Add(docPub);

                docCover.Delete();
                docContents.Delete();
                this.m_project.Annotations.Clear();
            }

            LoadTree();
        }
Esempio n. 14
0
        private void generateChangeLogToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult res = this.openFileDialogChanges.ShowDialog(this);
            if (res != DialogResult.OK)
                return;

            Dictionary<long, SEntity> instances = new Dictionary<long, SEntity>();
            this.m_loading = true;
            try
            {
                using (FormatSPF format = new FormatSPF(this.openFileDialogChanges.FileName, SchemaDOC.Types, instances))
                {
                    format.Load();
                }
            }
            catch(Exception x)
            {
                MessageBox.Show(x.Message);
                return;
            }
            finally
            {
                this.m_loading = false;
            }

            // now import changes
            DocProject docProjectBase = null;
            foreach (SEntity o in instances.Values)
            {
                if (o is DocProject)
                {
                    docProjectBase = (DocProject)o;
                    break;
                }
            }

            ChangeLogGenerator.Generate(docProjectBase, this.m_project);
            this.LoadTree();
        }
Esempio n. 15
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);
                }
            }
        }
Esempio n. 16
0
        private void LoadFile(string filename)
        {
            this.SetCurrentFile(filename);


            this.m_lastid = 0;
            this.m_instances.Clear();
            this.m_mapTree.Clear();
            this.m_clipboard = null;
            this.m_project = null;

            string ext = System.IO.Path.GetExtension(this.m_file).ToLower();
            try
            {
                switch (ext)
                {
                    case ".ifcdoc":
                        using (FormatSPF format = new FormatSPF(this.m_file, SchemaDOC.Types, this.m_instances))
                        {
                            format.Load();
                        }
                        break;

                    case ".mdb":
                        using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances))
                        {
                            format.Load();
                        }
                        break;
                }
            }
            catch (Exception x)
            {
                MessageBox.Show(this, x.Message, "Error", MessageBoxButtons.OK);

                // force new as state is now invalid
                this.m_modified = false;
                this.toolStripMenuItemFileNew_Click(this, EventArgs.Empty);
                return;
            }

            List<SEntity> listDelete = new List<SEntity>();
            List<DocTemplateDefinition> listTemplate = new List<DocTemplateDefinition>();

            // get the project, determine the next OID to use
            foreach (SEntity o in this.m_instances.Values)
            {
                if (o is DocProject)
                {
                    this.m_project = (DocProject)o;
                }
                else if (o is DocEntity)
                {
                    DocEntity docent = (DocEntity)o;

#if false
                    // files before V5.3 had Description field; no longer needed so use regular Documentation field again.
                    if (docent._Description != null)
                    {
                        docent.Documentation = docent._Description;
                        docent._Description = null;
                    }
#endif
                }
                else if(o is DocAttribute)
                {
#if false
                    // files before V8.7 didn't have nullable tagless
                    DocAttribute docAttr = (DocAttribute)o;
                    if (docAttr.XsdTagless == false)
                    {
                        docAttr.XsdTagless = null;
                    }
#endif
                }
                else if (o is DocExchangeDefinition)
                {
                    // files before V4.9 had Description field; no longer needed so use regular Documentation field again.
                    DocExchangeDefinition docexchange = (DocExchangeDefinition)o;
                    if (docexchange._Description != null)
                    {
                        docexchange.Documentation = docexchange._Description;
                        docexchange._Description = null;
                    }
                }
                else if (o is DocTemplateDefinition)
                {
                    // files before V5.0 had Description field; no longer needed so use regular Documentation field again.
                    DocTemplateDefinition doctemplate = (DocTemplateDefinition)o;
                    if (doctemplate._Description != null)
                    {
                        doctemplate.Documentation = doctemplate._Description;
                        doctemplate._Description = null;
                    }

                    listTemplate.Add((DocTemplateDefinition)o);
                }

                // ensure all objects have valid guid
                if (o is DocObject)
                {
                    DocObject docobj = (DocObject)o;
                    if (docobj.Uuid == Guid.Empty)
                    {
                        docobj.Uuid = Guid.NewGuid();
                    }

#if false
                    // ensure any image references are in lowercase
                    if(docobj.Documentation != null && docobj.Documentation.Length > 0)
                    {
                        int i = 0;
                        while (i != -1)
                        {
                            i = docobj.Documentation.IndexOf("../figures/", i + 1);
                            if(i != -1)
                            {
                                int start = i + 11;
                                int end = docobj.Documentation.IndexOf('"', start);
                                if(end > start)
                                {
                                    string strold = docobj.Documentation.Substring(start, end - start);
                                    string strnew = strold.ToLower();

                                    docobj.Documentation = docobj.Documentation.Substring(0, start) + strnew + docobj.Documentation.Substring(end);
                                    System.Diagnostics.Debug.WriteLine(strnew);
                                }
                            }
                        }
                    }
#endif
                }


                if (o.OID > this.m_lastid)
                {
                    this.m_lastid = o.OID;
                }
            }

            if (this.m_project == null)
            {
                MessageBox.Show(this, "File is invalid; no project is defined.", "Error", MessageBoxButtons.OK);
                return;
            }

            // now capture any template definitions (upgrade in V3.5)
            foreach (DocModelView docModelView in this.m_project.ModelViews)
            {
                if (docModelView.ConceptRoots == null)
                {
                    // must convert to new format
                    docModelView.ConceptRoots = new List<DocConceptRoot>();

                    foreach (DocSection docSection in this.m_project.Sections)
                    {
                        foreach (DocSchema docSchema in docSection.Schemas)
                        {
                            foreach (DocEntity docEntity in docSchema.Entities)
                            {
                                if (docEntity.__Templates != null)
                                {
                                    foreach (DocTemplateUsage docTemplateUsage in docEntity.__Templates)
                                    {
                                        // must generate or use existing concept root

                                        DocConceptRoot docConceptRoot = null;
                                        foreach (DocConceptRoot eachConceptRoot in docModelView.ConceptRoots)
                                        {
                                            if (eachConceptRoot.ApplicableEntity == docEntity)
                                            {
                                                docConceptRoot = eachConceptRoot;
                                                break;
                                            }
                                        }

                                        if (docConceptRoot == null)
                                        {
                                            docConceptRoot = new DocConceptRoot();
                                            docConceptRoot.ApplicableEntity = docEntity;
                                            docModelView.ConceptRoots.Add(docConceptRoot);
                                        }

                                        docConceptRoot.Concepts.Add(docTemplateUsage);
                                    }
                                }
                            }
                        }
                    }
                }
            }

#if false
            // temp fixup
            foreach (DocSection docSection in this.m_project.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    //docSchema.PropertyEnums.Sort();

                    foreach (DocPropertyEnumeration docEnum in docSchema.PropertyEnums)
                    {
                        foreach(DocPropertyConstant docConst in docEnum.Constants)
                        {
                            docConst.Name = docConst.Name.ToUpper(); // ensure uppercase throughout

                            switch(docConst.Name)
                            {
                                case "OTHER":
                                    docConst.RegisterLocalization("en", "(other)", "Value is not listed.");
                                    break;

                                case "NOTKNOWN":
                                    docConst.RegisterLocalization("en", "(unknown)", "Value is unknown.");
                                    break;

                                case "UNSET":
                                    docConst.RegisterLocalization("en", "(unset)", "Value has not been specified.");
                                    break;
                            }
                        }
                    }
                }
            }
#endif

#if false
            // ensure property enumerations are defined (upgrade to V5.8) and provide localizations
            Dictionary<string, DocPropertyEnumeration> mapEnums = new Dictionary<string, DocPropertyEnumeration>();

            foreach(DocSection docSection in this.m_project.Sections)
            {
                foreach(DocSchema docSchema in docSection.Schemas)
                {
                    foreach(DocType docType in docSchema.Types)
                    {
                        EnsureLocalized(docType);
                    }

                    foreach(DocEntity docEntity in docSchema.Entities)
                    {
                        EnsureLocalized(docEntity);
                    }

                    foreach(DocFunction docFunction in docSchema.Functions)
                    {
                        EnsureLocalized(docFunction);
                    }

                    foreach(DocGlobalRule docRule in docSchema.GlobalRules)
                    {
                        EnsureLocalized(docRule);
                    }

                    foreach(DocPropertySet docPset in docSchema.PropertySets)
                    {
                        EnsureLocalized(docPset);

                        foreach(DocProperty docProp in docPset.Properties)
                        {
                            EnsureLocalized(docProp);

                            if (docProp.PropertyType == DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE)
                            {
                                // temporary migration
                                string match = "PEnum_Status:";
                                if (docProp.SecondaryDataType.StartsWith(match))
                                {
                                    docProp.SecondaryDataType = "PEnum_ElementStatus:" + docProp.SecondaryDataType.Substring(match.Length);
                                }

                                string[] enumhost = docProp.SecondaryDataType.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                                if (enumhost.Length == 2)
                                {
                                    string enumname = enumhost[0];


                                    DocPropertyEnumeration docEnum = null;
                                    if (docProp.PrimaryDataType != null && !mapEnums.TryGetValue(enumname, out docEnum))
                                    {
                                        docEnum = new DocPropertyEnumeration();
                                        docEnum.Name = enumname;
                                        docSchema.PropertyEnums.Add(docEnum);

                                        mapEnums.Add(docEnum.Name, docEnum);

                                        string[] enumvals = enumhost[1].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                                        foreach (string val in enumvals)
                                        {
                                            DocPropertyConstant docConstant = new DocPropertyConstant();
                                            docConstant.Name = val;
                                            docEnum.Constants.Add(docConstant);

                                            // localize constant
                                            StringBuilder sb = new StringBuilder();

                                            // if constant is entirely uppercase, then convert such that only first character is uppercase
                                            for (int i = 0; i < val.Length; i++ )
                                            {
                                                char ch = val[i];
                                                if (ch == '_')
                                                {
                                                    ch = ' ';
                                                }
                                                else if (Char.IsUpper(ch) && i > 0 && !Char.IsUpper(val[i - 1]))
                                                {
                                                    sb.Append(" ");
                                                }
                                                else if(Char.IsUpper(ch) && i > 0 && Char.IsUpper(val[i-1]))
                                                {
                                                    ch = Char.ToLower(ch);
                                                }

                                                sb.Append(ch);
                                            }

                                            // find description for constant
                                            string doc = null;
                                            int iDoc = docProp.Documentation.IndexOf(docConstant.Name + ":");
                                            if(iDoc > 0)
                                            {
                                                int iTail = docProp.Documentation.IndexOfAny(new char[] { '.', ';', '\r', '\n'}, iDoc+1);
                                                if (iTail == -1)
                                                {
                                                    iTail = docProp.Documentation.Length;
                                                }
                                                doc = docProp.Documentation.Substring(iDoc + docConstant.Name.Length + 2, iTail - iDoc - docConstant.Name.Length - 2);
                                            }

                                            docConstant.RegisterLocalization("en", sb.ToString(), doc);
                                        }

                                    }
                                }
                            }
                        }

                    }

                    foreach(DocQuantitySet docQset in docSchema.QuantitySets)
                    {
                        EnsureLocalized(docQset);

                        foreach(DocQuantity docQuantiy in docQset.Quantities)
                        {
                            EnsureLocalized(docQuantiy);
                        }
                    }
                }
            }
#endif


#if false
            // temp: garbage collection for files that didn't clean up properly
            StringBuilder sb = new StringBuilder();
            this.m_project.Mark();
            List<SEntity> collect = new List<SEntity>();
            foreach (SEntity o in this.m_instances.Values)
            {
                if(!o.Existing)
                {
                    collect.Add(o);
                }
            }

            for (int i = collect.Count - 1; i >= 0; i--)
            {
                SEntity ent = collect[i];
                if(!ent.Existing)
                {
                    sb.AppendLine("#" + ent.OID + "=" + ent.GetType().Name + ";");
                    this.m_instances.Remove(ent.OID);
                }
            }
            string sss = sb.ToString();
#endif

            // now clear out the lists going forward.
            LoadTree();
        }