Inheritance: Identity
Example #1
0
        internal static void Load(DOC.DocProject docProject, string filename)
        {
            for (int iNS = 0; iNS < mvdXML.Namespaces.Length; iNS++)
            {
                string xmlns = mvdXML.Namespaces[iNS];
                using (FormatXML format = new FormatXML(filename, typeof(mvdXML), xmlns))
                {
                    try
                    {
                        format.Load();
                        mvdXML mvd = (mvdXML)format.Instance;
                        Program.ImportMvd(mvd, docProject, filename);
                        break;
                    }
                    catch (InvalidOperationException xx)
                    {
                        // keep going until successful

                        if (iNS == mvdXML.Namespaces.Length - 1)
                        {
                            throw new InvalidOperationException("The file is not of a supported format (mvdXML 1.0 or mvdXML 1.1).");
                        }
                    }
                    catch (Exception xx)
                    {
                        xmlns = null;
                    }
                }
            }
        }
Example #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;
            }

        }
Example #4
0
        // each list is optional- if specified then must be followed; if null, then no filter applies (all included)
        internal static void ExportMvd(
            mvdXML mvd,
            DocProject docProject,
            Dictionary<DocObject, bool> included)
        {
            mvd.Uuid = Guid.NewGuid(); // changes every time saved
            mvd.Name = String.Empty;

            foreach (DocTemplateDefinition docTemplateDef in docProject.Templates)
            {
                if (included == null || included.ContainsKey(docTemplateDef))
                {
                    ConceptTemplate mvdConceptTemplate = new ConceptTemplate();
                    mvd.Templates.Add(mvdConceptTemplate);
                    ExportMvdTemplate(mvdConceptTemplate, docTemplateDef, included, true);
                }
            }

            foreach (DocModelView docModelView in docProject.ModelViews)
            {
                if (included == null || included.ContainsKey(docModelView))
                {
                    ModelView mvdModelView = new ModelView();
                    mvd.Views.Add(mvdModelView);
                    ExportMvdObject(mvdModelView, docModelView, true);
                    mvdModelView.ApplicableSchema = "IFC4";
                    mvdModelView.BaseView = docModelView.BaseView;

                    foreach (DocExchangeDefinition docExchangeDef in docModelView.Exchanges)
                    {
                        ExchangeRequirement mvdExchangeDef = new ExchangeRequirement();
                        mvdModelView.ExchangeRequirements.Add(mvdExchangeDef);
                        ExportMvdObject(mvdExchangeDef, docExchangeDef, true);
                        switch (docExchangeDef.Applicability)
                        {
                            case DocExchangeApplicabilityEnum.Export:
                                mvdExchangeDef.Applicability = ApplicabilityEnum.Export;
                                break;

                            case DocExchangeApplicabilityEnum.Import:
                                mvdExchangeDef.Applicability = ApplicabilityEnum.Import;
                                break;
                        }
                    }

                    // export template usages for model view
                    foreach (DocConceptRoot docRoot in docModelView.ConceptRoots)
                    {
                        if (docRoot.ApplicableEntity != null)
                        {
                            // check if entity contains any concept roots
                            ConceptRoot mvdConceptRoot = new ConceptRoot();
                            mvdModelView.Roots.Add(mvdConceptRoot);

                            Program.ExportMvdConceptRoot(mvdConceptRoot, docRoot, true);
                        }
                    }
                }
            }
        }
Example #5
0
        internal static void ImportMvd(mvdXML mvd, DocProject docProject, string filepath)
        {
            if (mvd.Templates != null)
            {
                Dictionary<EntityRule, DocModelRuleEntity> fixups = new Dictionary<EntityRule, DocModelRuleEntity>();
                foreach (ConceptTemplate mvdTemplate in mvd.Templates)
                {
                    DocTemplateDefinition docDef = docProject.GetTemplate(mvdTemplate.Uuid);
                    if (docDef == null)
                    {
                        docDef = new DocTemplateDefinition();
                        docProject.Templates.Add(docDef);
                    }

                    ImportMvdTemplate(mvdTemplate, docDef, fixups);
                }

                foreach(EntityRule er in fixups.Keys)
                {
                    DocModelRuleEntity docEntityRule = fixups[er];
                    if(er.References != null)
                    {
                        foreach(TemplateRef tr in er.References)
                        {
                            DocTemplateDefinition dtd = docProject.GetTemplate(tr.Ref);
                            if(dtd != null)
                            {
                                docEntityRule.References.Add(dtd);
                            }
                        }
                    }
                }
            }

            if (mvd.Views != null)
            {
                foreach (ModelView mvdView in mvd.Views)
                {
                    DocModelView docView = docProject.GetView(mvdView.Uuid);
                    if (docView == null)
                    {
                        docView = new DocModelView();
                        docProject.ModelViews.Add(docView);
                    }

                    ImportMvdObject(mvdView, docView);

                    docView.BaseView = mvdView.BaseView;
                    docView.Exchanges.Clear();
                    Dictionary<Guid, ExchangeRequirement> mapExchange = new Dictionary<Guid, ExchangeRequirement>();
                    foreach (ExchangeRequirement mvdExchange in mvdView.ExchangeRequirements)
                    {
                        mapExchange.Add(mvdExchange.Uuid, mvdExchange);

                        DocExchangeDefinition docExchange = new DocExchangeDefinition();
                        ImportMvdObject(mvdExchange, docExchange);
                        docView.Exchanges.Add(docExchange);

                        docExchange.Applicability = (DocExchangeApplicabilityEnum)mvdExchange.Applicability;

                        // attempt to find icons if exists -- remove extention
                        try
                        {
                            string iconpath = filepath.Substring(0, filepath.Length - 7) + @"\mvd-" + docExchange.Name.ToLower().Replace(' ', '-') + ".png";
                            if (System.IO.File.Exists(iconpath))
                            {
                                docExchange.Icon = System.IO.File.ReadAllBytes(iconpath);
                            }
                        }
                        catch
                        {

                        }
                    }

                    foreach (ConceptRoot mvdRoot in mvdView.Roots)
                    {
                        // find the entity
                        DocEntity docEntity = LookupEntity(docProject, mvdRoot.ApplicableRootEntity);
                        if (docEntity != null)
                        {
                            DocConceptRoot docConceptRoot = docView.GetConceptRoot(mvdRoot.Uuid);
                            if (docConceptRoot == null)
                            {
                                docConceptRoot = new DocConceptRoot();
                                if (docView.ConceptRoots == null)
                                {
                                    docView.ConceptRoots = new List<DocConceptRoot>();
                                }
                                docView.ConceptRoots.Add(docConceptRoot);
                            }

                            ImportMvdObject(mvdRoot, docConceptRoot);
                            docConceptRoot.ApplicableEntity = docEntity;

                            if (mvdRoot.Applicability != null)
                            {
                                docConceptRoot.ApplicableTemplate = docProject.GetTemplate(mvdRoot.Applicability.Template.Ref);
                                if(mvdRoot.Applicability.TemplateRules != null)
                                {
                                    docConceptRoot.ApplicableOperator = (DocTemplateOperator)Enum.Parse(typeof(TemplateOperator), mvdRoot.Applicability.TemplateRules.Operator.ToString());
                                    foreach (TemplateRule r in mvdRoot.Applicability.TemplateRules.TemplateRule)
                                    {
                                        DocTemplateItem docItem = ImportMvdItem(r, docProject, mapExchange);
                                        docConceptRoot.ApplicableItems.Add(docItem);
                                    }
                                }
                            }

                            docConceptRoot.Concepts.Clear();
                            foreach (Concept mvdNode in mvdRoot.Concepts)
                            {
                                DocTemplateUsage docUse = new DocTemplateUsage();
                                docConceptRoot.Concepts.Add(docUse);
                                ImportMvdConcept(mvdNode, docUse, docProject, mapExchange);
                            }
                        }
                        else
                        {
                            //TODO: log error
                        }
                    }
                }
            }
        }
Example #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;

            }
        }
Example #7
0
        // each list is optional- if specified then must be followed; if null, then no filter applies (all included)
        internal static void ExportMvd(
            mvdXML mvd,
            DocProject docProject,
            Dictionary<DocObject, bool> included)
        {
            mvd.Name = String.Empty;

            foreach (DocTemplateDefinition docTemplateDef in docProject.Templates)
            {
                if (included == null || included.ContainsKey(docTemplateDef))
                {
                    ConceptTemplate mvdConceptTemplate = new ConceptTemplate();
                    mvd.Templates.Add(mvdConceptTemplate);
                    ExportMvdTemplate(mvdConceptTemplate, docTemplateDef, included);
                }
            }

            foreach (DocModelView docModelView in docProject.ModelViews)
            {
                if (included == null || included.ContainsKey(docModelView))
                {
                    ModelView mvdModelView = new ModelView();
                    mvd.Views.Add(mvdModelView);
                    ExportMvdObject(mvdModelView, docModelView);
                    mvdModelView.ApplicableSchema = "IFC4";
                    mvdModelView.BaseView = docModelView.BaseView;

                    foreach (DocExchangeDefinition docExchangeDef in docModelView.Exchanges)
                    {
                        ExchangeRequirement mvdExchangeDef = new ExchangeRequirement();
                        mvdModelView.ExchangeRequirements.Add(mvdExchangeDef);
                        ExportMvdObject(mvdExchangeDef, docExchangeDef);
                        switch (docExchangeDef.Applicability)
                        {
                            case DocExchangeApplicabilityEnum.Export:
                                mvdExchangeDef.Applicability = ApplicabilityEnum.Export;
                                break;

                            case DocExchangeApplicabilityEnum.Import:
                                mvdExchangeDef.Applicability = ApplicabilityEnum.Import;
                                break;
                        }
                    }

                    // export template usages for model view
                    foreach (DocConceptRoot docRoot in docModelView.ConceptRoots)
                    {
                        if (docRoot.ApplicableEntity != null)
                        {
                            // check if entity contains any concept roots
                            ConceptRoot mvdConceptRoot = new ConceptRoot();
                            mvdModelView.Roots.Add(mvdConceptRoot);

                            ExportMvdObject(mvdConceptRoot, docRoot);
                            mvdConceptRoot.ApplicableRootEntity = docRoot.ApplicableEntity.Name;
                            if (docRoot.ApplicableTemplate != null)
                            {
                                mvdConceptRoot.Applicability = new ApplicabilityRules();
                                mvdConceptRoot.Applicability.Template = new TemplateRef();
                                mvdConceptRoot.Applicability.Template.Ref = docRoot.ApplicableTemplate.Uuid;
                                mvdConceptRoot.Applicability.TemplateRules = new TemplateRules();

                                mvdConceptRoot.Applicability.TemplateRules.Operator = (TemplateOperator)Enum.Parse(typeof(TemplateOperator), docRoot.ApplicableOperator.ToString());
                                foreach (DocTemplateItem docItem in docRoot.ApplicableItems)
                                {
                                    TemplateRule rule = ExportMvdItem(docItem);
                                    mvdConceptRoot.Applicability.TemplateRules.TemplateRule.Add(rule);
                                }
                            }

                            foreach (DocTemplateUsage docTemplateUsage in docRoot.Concepts)
                            {
                                Concept mvdConceptLeaf = new Concept();
                                mvdConceptRoot.Concepts.Add(mvdConceptLeaf);
                                ExportMvdConcept(mvdConceptLeaf, docTemplateUsage);
                            }
                        }
                    }
                }
            }
        }