Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="filename">Local file path</param>
 /// <param name="docSchema">Schema of diagram</param>
 /// <param name="docProject">Project</param>
 /// <param name="uml">Diagram format</param>
 public SchemaSVG(string filename, DocSchema docSchema, DocProject docProject, DiagramFormat format)
 {
     this.m_filename = filename;
     this.m_schema   = docSchema;
     this.m_project  = docProject;
     this.m_format   = format;
 }
Пример #2
0
        bool m_oneof = true; // always use ONEOF, even if only one subtype -- was False for IFC2x3 and IFC4 final; True for IFC4 TC1.

        public FormatEXP(DocProject docProject, DocSchema docSchema, DocModelView[] modelviews, string filename)
        {
            this.m_project  = docProject;
            this.m_schema   = docSchema;
            this.m_views    = modelviews;
            this.m_filename = filename;

            this.m_included = null;
            if (this.m_views != null)
            {
                this.m_included = new Dictionary <DocObject, bool>();
                foreach (DocModelView docView in this.m_views)
                {
                    this.m_project.RegisterObjectsInScope(docView, this.m_included);
                }
            }
        }
Пример #3
0
 private static void extractListingsV12_1(DocProject project, DocSchema schema, Dictionary <string, DocPropertyEnumeration> encounteredPropertyEnumerations)
 {
     foreach (DocPropertyEnumeration enumeration in schema.PropertyEnumerations)
     {
         if (encounteredPropertyEnumerations.ContainsKey(enumeration.Name))
         {
             continue;
         }
         project.PropertyEnumerations.Add(enumeration);
         encounteredPropertyEnumerations[enumeration.Name] = enumeration;
         foreach (DocPropertyConstant constant in enumeration.Constants)
         {
             constant.Name = constant.Name.Trim();
             if (!project.PropertyConstants.Contains(constant))
             {
                 project.PropertyConstants.Add(constant);
             }
         }
     }
     foreach (DocType t in schema.Types)
     {
         DocEnumeration enumeration = t as DocEnumeration;
         if (enumeration != null)
         {
             foreach (DocConstant constant in enumeration.Constants)
             {
                 if (!project.Constants.Contains(constant))
                 {
                     project.Constants.Add(constant);
                 }
             }
         }
     }
     foreach (DocProperty property in schema.PropertySets.SelectMany(x => x.Properties))
     {
         extractListings(project, property, encounteredPropertyEnumerations);                 //listings
     }
     foreach (DocQuantity quantity in schema.QuantitySets.SelectMany(x => x.Quantities))
     {
         project.Quantities.Add(quantity);
     }
 }
        private async Task CreateContentDocSchemas(VerifiedUserContext userContext)
        {
            var kitSchema = new DocSchema
            {
                ID = "HSKitProductAssignment",
                RestrictedAssignmentTypes = new List <ResourceType> {
                },
                Schema = JObject.Parse(File.ReadAllText("../Headstart.Common/Assets/ContentDocSchemas/kitproduct.json"))
            };

            var supplierFilterConfigSchema = new DocSchema
            {
                ID = "SupplierFilterConfig",
                RestrictedAssignmentTypes = new List <ResourceType> {
                },
                Schema = JObject.Parse(File.ReadAllText("../Headstart.Common/Assets/ContentDocSchemas/supplierfilterconfig.json"))
            };

            await Task.WhenAll(
                _cms.Schemas.Create(kitSchema, userContext.AccessToken),
                _cms.Schemas.Create(supplierFilterConfigSchema, userContext.AccessToken)
                );
        }
Пример #5
0
        internal static Image CreateSchemaDiagram(DocSchema docSchema, Dictionary<string, DocObject> map, DiagramFormat format)
        {
            float pageX = (float)CtlExpressG.PageX;
            float pageY = (float)CtlExpressG.PageY;

            int cDiagrams = docSchema.UpdateDiagramPageNumbers();
            int cPagesY = docSchema.DiagramPagesVert;
            int cPagesX = docSchema.DiagramPagesHorz;
            if(cPagesX == 0 || cPagesY == 0)
            {
                // fallback if using earlier version without diagram info
                cPagesX = cDiagrams;
                cPagesY = 1;

                if (cPagesX == 0)
                    cPagesX = 1;
            }

            int xTotal = cPagesX * (int)pageX;
            int yTotal = cPagesY * (int)pageY;
            Image image = new Bitmap(xTotal, yTotal, System.Drawing.Imaging.PixelFormat.Format24bppRgb);

            using (Graphics g = Graphics.FromImage(image))
            {
                Pen penDash = new Pen(System.Drawing.Color.Black);
                penDash.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                using (penDash)
                {
                    g.FillRectangle(Brushes.White, new Rectangle(0, 0, image.Width, image.Height));

                    for (float x = 0; x <= image.Width; x += pageX)
                    {
                        g.DrawLine(Pens.Green, new PointF(x-1, 0.0f), new PointF(x-1, (float)image.Height - 1.0f));
                        g.DrawLine(Pens.Green, new PointF(x, 0.0f), new PointF(x, (float)image.Height - 1.0f));
                    }
                    for (float y = 0; y <= image.Height; y += pageY)
                    {
                        g.DrawLine(Pens.Green, new PointF(0.0f, y-1), new PointF((float)image.Width - 1.0f, y-1));
                        g.DrawLine(Pens.Green, new PointF(0.0f, y), new PointF((float)image.Width - 1.0f, y));
                    }

                    StringFormat sf = new StringFormat(StringFormat.GenericDefault);
                    sf.Alignment = StringAlignment.Center;
                    sf.LineAlignment = StringAlignment.Center;

                    StringFormat sfLeft = new StringFormat(StringFormat.GenericDefault);
                    sfLeft.Alignment = StringAlignment.Near;
                    sfLeft.LineAlignment = StringAlignment.Near;
                    sfLeft.FormatFlags = StringFormatFlags.NoWrap;

                    using (Font font = new Font(FontFamily.GenericSansSerif, 7.0f))
                    {
                        using (Font fontBold = new Font(font, FontStyle.Bold))
                        {
                            using (Font fontBoldItalic = new Font(font, FontStyle.Bold | FontStyle.Italic))
                            {
                                foreach (DocType docType in docSchema.Types)
                                {
                                    if (docType.DiagramRectangle != null)
                                    {
                                        Rectangle rc = new Rectangle(
                                            (int)(docType.DiagramRectangle.X * Factor),
                                            (int)(docType.DiagramRectangle.Y * Factor),
                                            (int)(docType.DiagramRectangle.Width * Factor),
                                            (int)(docType.DiagramRectangle.Height * Factor));

                                        if (format == DiagramFormat.ExpressG)
                                        {
                                            g.FillRectangle(Brushes.Lime, rc);
                                            g.DrawRectangle(penDash, rc);
                                            g.DrawString(docType.Name, font, Brushes.Black, rc, sf);

                                            if (docType is DocEnumeration)
                                            {
                                                g.DrawLine(penDash, rc.Right - 6, rc.Top, rc.Right - 6, rc.Bottom);
                                            }
                                            else if(docType is DocSelect)
                                            {
                                                g.DrawLine(penDash, rc.Left + 6, rc.Top, rc.Left + 6, rc.Bottom);
                                            }
                                            else if (docType is DocDefined)
                                            {
                                                DocDefined docItem = (DocDefined)docType;
                                                if (docItem.DiagramLine.Count > 0)
                                                {
                                                    DrawLine(g, Pens.Black, docItem.DiagramLine, format);
                                                }
                                            }
                                        }
                                        else if (format == DiagramFormat.UML)
                                        {
                                            g.FillRectangle(Brushes.LightYellow, rc);
                                            g.DrawRectangle(Pens.Black, rc);

                                            Rectangle rcTop = rc;
                                            rcTop.Height = 8;

                                            Rectangle rcName = new Rectangle(rc.X, rc.Y + 8, rc.Width, 16);
                                            string typename = null;
                                            if (docType is DocEnumeration)
                                            {
                                                typename = "enumeration";
                                                g.DrawLine(Pens.Black, rcName.X, rcName.Bottom, rcName.Right, rcName.Bottom);
                                            }
                                            else if (docType is DocSelect)
                                            {
                                                typename = "interface";
                                            }
                                            else if (docType is DocDefined)
                                            {
                                                typename = "datatype";
                                            }

                                            g.DrawString(Char.ConvertFromUtf32(0xAB) + typename + Char.ConvertFromUtf32(0xBB), font, Brushes.Black, rcTop, sf);
                                            g.DrawString(docType.Name, font, Brushes.Black, rcName, sf);

                                            // members of enumeration...
                                        }

                                        if (docType is DocSelect)
                                        {
                                            DocSelect docSelect = (DocSelect)docType;

                                            if (docSelect.Tree != null)
                                            {
                                                foreach (DocLine docItem in docSelect.Tree)
                                                {
                                                    if (docItem.Definition != null)
                                                    {
                                                        DrawLine(g, Pens.Black, docItem.DiagramLine, format);
                                                    }
                                                    else
                                                    {
                                                        // tree structure -- don't draw endcap
                                                        for (int i = 0; i < docItem.DiagramLine.Count - 1; i++)
                                                        {
                                                            g.DrawLine(Pens.Black,
                                                                new Point((int)(docItem.DiagramLine[i].X * Factor), (int)(docItem.DiagramLine[i].Y * Factor)),
                                                                new Point((int)(docItem.DiagramLine[i + 1].X * Factor), (int)(docItem.DiagramLine[i + 1].Y * Factor)));
                                                        }

                                                        foreach (DocLine docItem2 in docItem.Tree)
                                                        {
                                                            // link parent if necessary (needed for imported vex diagrams)
                                                            g.DrawLine(Pens.Black,
                                                                new Point((int)(docItem.DiagramLine[docItem.DiagramLine.Count - 1].X * Factor), (int)(docItem.DiagramLine[docItem.DiagramLine.Count - 1].Y * Factor)),
                                                                new Point((int)(docItem2.DiagramLine[0].X * Factor), (int)(docItem2.DiagramLine[0].Y * Factor)));

                                                            DrawLine(g, Pens.Black, docItem2.DiagramLine, format);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                foreach (DocEntity docType in docSchema.Entities)
                                {
                                    if (docType.DiagramRectangle != null)
                                    {
                                        Rectangle rc = new Rectangle(
                                            (int)(docType.DiagramRectangle.X * Factor),
                                            (int)(docType.DiagramRectangle.Y * Factor),
                                            (int)(docType.DiagramRectangle.Width * Factor),
                                            (int)(docType.DiagramRectangle.Height * Factor));

                                        string caption = docType.Name;

                                        if (format == DiagramFormat.ExpressG)
                                        {
                                            if (docType.WhereRules.Count > 0 || docType.UniqueRules.Count > 0)
                                            {
                                                caption = "*" + caption;
                                            }
                                            if (docType.IsAbstract())
                                            {
                                                caption = "(ABS)\r\n" + caption;
                                            }
                                            g.FillRectangle(Brushes.Yellow, rc);
                                            g.DrawRectangle(Pens.Black, rc);
                                            g.DrawString(caption, fontBold, Brushes.Black, rc, sf);
                                        }
                                        else if (format == DiagramFormat.UML)
                                        {
                                            g.FillRectangle(Brushes.LightYellow, rc);
                                            g.DrawRectangle(Pens.Red, rc);

                                            Rectangle rcTop = rc;
                                            rcTop.Height = 16;

                                            if (docType.IsAbstract())
                                            {
                                                g.DrawString(caption, fontBoldItalic, Brushes.Black, rcTop, sf);
                                            }
                                            else
                                            {
                                                g.DrawString(caption, fontBold, Brushes.Black, rcTop, sf);
                                            }

                                            g.DrawLine(Pens.Black, rcTop.Left, rcTop.Bottom, rcTop.Right, rcTop.Bottom);

                                            // attributes of value types...
                                            int y = rcTop.Bottom;
                                            foreach (DocAttribute docAttr in docType.Attributes)
                                            {
                                                DocObject docAttrType = null;

                                                // include native types, enumerations, and defined types
                                                if(!map.TryGetValue(docAttr.DefinedType, out docAttrType) || docAttrType is DocEnumeration || docAttrType is DocDefined)
                                                {
                                                    Rectangle rcAttr = new Rectangle(rc.Left, y, rc.Width, 12);
                                                    g.DrawString(docAttr.Name + ":" + docAttr.DefinedType, font, Brushes.Black, rcAttr, sfLeft);
                                                    y += 12;
                                                }
                                            }
                                        }

                                    }

                                    foreach (DocAttribute docAttr in docType.Attributes)
                                    {
                                        bool include = true;
                                        if(format == DiagramFormat.UML)
                                        {
                                            DocObject docAttrType = null;
                                            include = (map.TryGetValue(docAttr.DefinedType, out docAttrType) && (docAttrType is DocEntity || docAttrType is DocSelect));
                                        }

                                        if (include)
                                        {
                                            if (docAttr.DiagramLine != null)
                                            {
                                                Pen pen = new Pen(System.Drawing.Color.Black);

                                                if (docAttr.IsOptional)
                                                {
                                                    pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                                                }

                                                using (pen)
                                                {
                                                    DrawLine(g, pen, docAttr.DiagramLine, format);
                                                }

                                            }

                                            if (docAttr.DiagramLabel != null && docAttr.DiagramLine != null)
                                            {
                                                if (format == DiagramFormat.ExpressG)
                                                {
                                                    string caption = docAttr.Name;
                                                    if(!String.IsNullOrEmpty(docAttr.Derived))
                                                    {
                                                        caption = "(DER) " + caption;
                                                    }
                                                    else if (!String.IsNullOrEmpty(docAttr.Inverse))
                                                    {
                                                        caption = "(" + docAttr.DefinedType + "." + docAttr.Inverse + ")\r\n(INV) " + caption;
                                                    }
                                                    if (docAttr.GetAggregation() != DocAggregationEnum.NONE)
                                                    {
                                                        caption += " " + docAttr.GetAggregationExpression();
                                                    }

                                                    // determine X/Y based on midpoint of stated coordinate and target attribute
                                                    double x = (docAttr.DiagramLabel.X + docAttr.DiagramLine[docAttr.DiagramLine.Count - 1].X) * 0.5 * Factor;
                                                    double y = docAttr.DiagramLabel.Y * Factor;
                                                    g.DrawString(caption, font, Brushes.Black, (int)x, (int)y, sf);
                                                }
                                                else if(format == DiagramFormat.UML)
                                                {
                                                    double xHead = docAttr.DiagramLine[0].X * Factor;

                                                    double x = docAttr.DiagramLine[docAttr.DiagramLine.Count - 1].X * Factor;
                                                    double y = docAttr.DiagramLine[docAttr.DiagramLine.Count - 1].Y * Factor;

                                                    StringFormat sfFar = new StringFormat();
                                                    if (x > xHead)
                                                    {
                                                        sfFar.Alignment = StringAlignment.Far;
                                                        x -= 8;
                                                    }
                                                    else
                                                    {
                                                        sfFar.Alignment = StringAlignment.Near;
                                                        x += 8;
                                                    }
                                                    sfFar.LineAlignment = StringAlignment.Far;
                                                    g.DrawString(docAttr.Name, font, Brushes.Black, (int)x, (int)y, sfFar);
                                                    sfFar.LineAlignment = StringAlignment.Near;
                                                    g.DrawString(docAttr.GetAggregationExpression(), font, Brushes.Black, (int)x, (int)y, sfFar);
                                                }
                                            }
                                        }
                                    }

                                    foreach (DocLine docSub in docType.Tree)
                                    {
                                        DrawTree(g, docSub, Factor, Point.Empty, format);
                                    }
                                }

                                if (docSchema.PageTargets != null)
                                {
                                    using (Pen penRound = new Pen(Color.Black))
                                    {
                                        penRound.StartCap = LineCap.Round;
                                        penRound.EndCap = LineCap.Round;

                                        foreach (DocPageTarget docTarget in docSchema.PageTargets)
                                        {
                                            bool include = true;
                                            if(format == DiagramFormat.UML)
                                            {
                                                DocObject docRef = null;
                                                if (map.TryGetValue(docTarget.Definition.Name, out docRef))
                                                {
                                                    include = (docRef is DocEntity || docRef is DocSelect);
                                                }
                                            }

                                            if (include)
                                            {

                                            int page = docSchema.GetDefinitionPageNumber(docTarget);
                                            int item = docSchema.GetPageTargetItemNumber(docTarget);
                                            string caption = page + "," + item;

                                            if (docTarget.DiagramRectangle != null)
                                            {
                                                Rectangle rc = new Rectangle(
                                                    (int)(docTarget.DiagramRectangle.X * Factor),
                                                    (int)(docTarget.DiagramRectangle.Y * Factor),
                                                    (int)(docTarget.DiagramRectangle.Width * Factor),
                                                    (int)(docTarget.DiagramRectangle.Height * Factor));
                                                DrawRoundedRectangle(g, rc, (int)(docTarget.DiagramRectangle.Height * Factor), penRound, Brushes.Silver);
                                                g.DrawString(caption, font, Brushes.Black, rc, sf);
                                            }

                                            if (docTarget.DiagramLine != null)
                                            {
                                                using (Pen penBlue = new Pen(Color.Blue, 2.0f))
                                                {
                                                    for (int i = 0; i < docTarget.DiagramLine.Count - 1; i++)
                                                    {
                                                        g.DrawLine(penBlue,
                                                            new Point((int)(docTarget.DiagramLine[i].X * Factor), (int)(docTarget.DiagramLine[i].Y * Factor)),
                                                            new Point((int)(docTarget.DiagramLine[i + 1].X * Factor), (int)(docTarget.DiagramLine[i + 1].Y * Factor)));
                                                    }
                                                }
                                            }

                                                int iSource = 0;
                                                foreach (DocPageSource docSource in docTarget.Sources)
                                                {
                                                    iSource++;
                                                    if (docSource.DiagramRectangle != null)
                                                    {
                                                        Rectangle rc = new Rectangle(
                                                            (int)(docSource.DiagramRectangle.X * Factor),
                                                            (int)(docSource.DiagramRectangle.Y * Factor),
                                                            (int)(docSource.DiagramRectangle.Width * Factor),
                                                            (int)(docSource.DiagramRectangle.Height * Factor));
                                                        DrawRoundedRectangle(g, rc, (int)(docSource.DiagramRectangle.Height * Factor), penRound, Brushes.Silver);

                                                        string name = docSource.Name;
                                                        if (docTarget.Definition != null)
                                                        {
                                                            name = page + "," + item + " " + docTarget.Definition.Name;
                                                        }

                                                        g.DrawString(name, font, Brushes.Black, rc, sf);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }

                                if (docSchema.SchemaRefs != null)
                                {
                                    foreach (DocSchemaRef docSchemaRef in docSchema.SchemaRefs)
                                    {
                                        foreach (DocDefinitionRef docDefRef in docSchemaRef.Definitions)
                                        {
                                            bool include = true;
                                            if (format == DiagramFormat.UML)
                                            {
                                                DocObject docRef = null;
                                                if (map.TryGetValue(docDefRef.Name, out docRef))
                                                {
                                                    include = (docRef is DocEntity || docRef is DocSelect);
                                                }
                                            }

                                            if (include && docDefRef.DiagramRectangle != null)
                                            {
                                                //string caption = docSchemaRef.Name.ToUpper() + "." + docDefRef.Name;

                                                Rectangle rc = new Rectangle(
                                                    (int)(docDefRef.DiagramRectangle.X * Factor),
                                                    (int)(docDefRef.DiagramRectangle.Y * Factor),
                                                    (int)(docDefRef.DiagramRectangle.Width * Factor),
                                                    (int)(docDefRef.DiagramRectangle.Height * Factor));

                                                Rectangle rcInner = rc;
                                                rcInner.Y = rc.Y + rc.Height / 3;
                                                rcInner.Height = rc.Height / 3;

                                                g.FillRectangle(Brushes.Silver, rc);
                                                g.DrawRectangle(penDash, rc);
                                                DrawRoundedRectangle(g, rcInner, 8, Pens.Black, Brushes.Silver);

                                                //rc.Y -= 6;
                                                rc.Height = 12;
                                                g.DrawString(docSchemaRef.Name.ToUpper(), font, Brushes.Black, rc, sf);

                                                //rc.Y += 12;
                                                rc.Y = rcInner.Y;
                                                g.DrawString(docDefRef.Name, font, Brushes.Black, rc, sf);

                                                foreach (DocLine docSub in docDefRef.Tree)
                                                {
                                                    DrawTree(g, docSub, Factor, Point.Empty, format);
                                                }

                                            }

                                        }
                                    }
                                }

                                if (docSchema.Comments != null && format == DiagramFormat.ExpressG)
                                {
                                    using (Font fontItalic = new Font(font, FontStyle.Italic))
                                    {
                                        foreach (DocComment docComment in docSchema.Comments)
                                        {
                                            if (docComment.DiagramRectangle != null)
                                            {
                                                Rectangle rc = new Rectangle(
                                                    (int)(docComment.DiagramRectangle.X * Factor),
                                                    (int)(docComment.DiagramRectangle.Y * Factor),
                                                    (int)(docComment.DiagramRectangle.Width * Factor),
                                                    (int)(docComment.DiagramRectangle.Height * Factor));
                                                g.DrawString(docComment.Documentation, fontItalic, Brushes.Blue, rc, sf);
                                            }
                                        }
                                    }
                                }

                                if (docSchema.Primitives != null && format == DiagramFormat.ExpressG)
                                {
                                    foreach (DocPrimitive docPrimitive in docSchema.Primitives)
                                    {
                                        if (docPrimitive.DiagramRectangle != null)
                                        {
                                            Rectangle rc = new Rectangle(
                                                (int)(docPrimitive.DiagramRectangle.X * Factor),
                                                (int)(docPrimitive.DiagramRectangle.Y * Factor),
                                                (int)(docPrimitive.DiagramRectangle.Width * Factor),
                                                (int)(docPrimitive.DiagramRectangle.Height * Factor));

                                            g.FillRectangle(Brushes.Lime, rc);
                                            g.DrawRectangle(Pens.Black, rc);
                                            g.DrawString(docPrimitive.Name, font, Brushes.Black, rc, sf);

                                            g.DrawLine(Pens.Black, rc.Right - 6, rc.Top, rc.Right - 6, rc.Bottom);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return image;
        }
Пример #6
0
        private static void DrawAttribute(
            Graphics g, 
            int lane, 
            List<int> lanes, 
            DocEntity docEntity, 
            DocModelView docView, 
            DocModelRuleAttribute ruleAttribute, 
            Dictionary<string, DocObject> map, 
            int offset, 
            Dictionary<Rectangle, DocModelRule> layout, 
            DocProject docProject,
            DocSchema docSchema,
            SEntity instance)
        {
            int x = lane * CX + FormatPNG.Border;
            int y = lanes[lane] + FormatPNG.Border;

            // find the index of the attribute
            List<DocAttribute> listAttr = new List<DocAttribute>();
            BuildAttributeList(docEntity, listAttr, map);

            int iAttr = -1;
            for (int i = 0; i < listAttr.Count; i++)
            {
                if (listAttr[i].Name.Equals(ruleAttribute.Name))
                {
                    // found it
                    iAttr = i;
                    break;
                }
            }

            if (iAttr >= 0)
            {
                DocAttribute docAttr = listAttr[iAttr];

                object valueinstance = null;
                if (instance != null)
                {
                    System.Reflection.FieldInfo field = instance.GetType().GetField(docAttr.Name);
                    if(field != null)
                    {
                        valueinstance = field.GetValue(instance);
                    }
                }

                // map it
                foreach (DocModelRule ruleEach in ruleAttribute.Rules)
                {
                    if (ruleEach is DocModelRuleEntity)
                    {
                        DocModelRuleEntity ruleEntity = (DocModelRuleEntity)ruleEach;

                        DocObject docObj = null;

                        if (docSchema != null)
                        {
                            docObj = docSchema.GetDefinition(ruleEntity.Name);
                            if (docObj is DocDefinitionRef)
                                docObj = null;
                        }

                        if (docObj == null)
                        {
                            map.TryGetValue(ruleEntity.Name, out docObj);
                        }

                        {
                            int dest = FormatPNG.Border;
                            if (lanes.Count > lane + 1)
                            {
                                dest = lanes[lane + 1] + FormatPNG.Border;
                            }

                            if (docObj is DocEntity)
                            {
                                DocEntity docEntityTarget = (DocEntity)docObj;

                                // resolve inverse attribute
                                List<DocAttribute> listTarget = new List<DocAttribute>();
                                BuildAttributeList(docEntityTarget, listTarget, map);
                                for (int i = 0; i < listTarget.Count; i++)
                                {
                                    DocAttribute docAttrTarget = listTarget[i];
                                    if (docAttr.Inverse != null && docAttrTarget.Name.Equals(docAttr.Inverse))
                                    {
                                        // found it
                                        dest += CY * (i + 1);
                                        break;
                                    }
                                    else if (docAttrTarget.Inverse != null && docAttr.Name.Equals(docAttrTarget.Inverse))
                                    {
                                        //...also need to check for type compatibility

                                        bool found = false;
                                        DocEntity docTest = docEntity;
                                        while (docTest != null)
                                        {
                                            if (docTest.Name.Equals(docAttrTarget.DefinedType))
                                            {
                                                found = true;
                                                break;
                                            }

                                            if (docTest.BaseDefinition == null)
                                                break;

                                            DocObject docBase = null;
                                            if (map.TryGetValue(docTest.BaseDefinition, out docBase))
                                            {
                                                docTest = docBase as DocEntity;
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }

                                        // found it
                                        if (found)
                                        {
                                            dest += CY * (i + 1);
                                            break;
                                        }
                                    }
                                }

                                // draw the entity, recurse
                                DrawEntity(g, lane + 1, lanes, docEntityTarget, docView, null, ruleEntity, map, layout, docProject, docSchema, valueinstance);
                            }
                            else
                            {
                                int targetY = lanes[lane + 1] + FormatPNG.Border;

                                if (g != null)
                                {
                                    Brush brush = Brushes.Black;

                                    if (instance != null)
                                    {
                                        if (valueinstance == null)
                                        {
                                            brush = Brushes.Red;
                                        }
                                        else if(valueinstance is System.Collections.IList)
                                        {
                                            brush = Brushes.Blue;
                                        }
                                        else
                                        {
                                            string typename = valueinstance.GetType().Name;
                                            if (typename == ruleEntity.Name)
                                            {
                                                brush = Brushes.Lime;
                                            }
                                            else
                                            {
                                                brush = Brushes.Red;
                                            }
                                        }
                                    }

                                    g.FillRectangle(brush, x + CX, targetY, CX - DX, CY);
                                    g.DrawRectangle(Pens.Black, x + CX, targetY, CX - DX, CY);
                                    using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f))
                                    {
                                        string content = ruleEntity.Name;//docObj.Name;
                                        foreach (DocModelRule ruleConstraint in ruleEntity.Rules)
                                        {
                                            if (ruleConstraint.Description != null && ruleConstraint.Description.StartsWith("Value="))
                                            {
                                                content = ruleConstraint.Description.Substring(6);

                                                using (StringFormat fmt = new StringFormat())
                                                {
                                                    fmt.Alignment = StringAlignment.Far;
                                                    g.DrawString(content, font, Brushes.White, new RectangleF(x + CX, targetY, CX - DX, CY), fmt);
                                                }
                                            }
                                        }

                                        g.DrawString(ruleEntity.Name, font, Brushes.White, x + CX, targetY);

                                        if (ruleEntity.Identification == "Value")
                                        {
                                            // mark rule serving as default value
                                            g.FillEllipse(Brushes.Green, new Rectangle(x + CX - DX - CY, y, CY, CY));
                                        }
                                    }
                                }

                                // record rectangle
                                if (layout != null)
                                {
                                    layout.Add(new Rectangle(x + CX, targetY, CX - DX, CY), ruleEntity);
                                }

                                // increment lane offset for all lanes
                                int minlane = targetY + CY * 2;
                                int i = lane + 1;
                                if (lanes[i] < minlane)
                                {
                                    lanes[i] = minlane;
                                }
                            }

                            // draw arrow
                            if (g != null)
                            {
                                int x0 = x + CX - DX;
                                int y0 = y + CY * (iAttr + 1) + CY / 2;
                                int x1 = x + CX;
                                int y1 = dest + CY / 2;
                                int xM = x0 + DX / 2 - offset * 2;

                                if(!String.IsNullOrEmpty(ruleAttribute.Identification))
                                {
                                    // mark the attribute as using parameter
                                    //g.DrawRectangle(Pens.Blue, x, y + CY * (iAttr + 1), CX - DX, CY);
                                    using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Regular))
                                    {
                                        using (StringFormat fmt = new StringFormat())
                                        {
                                            fmt.Alignment = StringAlignment.Near;
                                            g.DrawString(docAttr.Name, font, Brushes.Blue, x, y + CY * (iAttr + 1), fmt);
                                        }
                                    }
                                }

                                g.DrawLine(Pens.Black, x0, y0, xM, y0);
                                g.DrawLine(Pens.Black, xM, y0, xM, y1);
                                g.DrawLine(Pens.Black, xM, y1, x1, y1);
                            }
                        }
                    }
                }

                if (g != null && ruleAttribute.Identification == "Name")
                {
                    // mark rule serving as default name
                    g.FillEllipse(Brushes.Blue, new Rectangle(x + CX - DX - CY, y + CY * (iAttr+1), CY, CY));
                }

            #if false
                string card = ruleAttribute.GetCardinalityExpression();
                if (g != null && card != null)
                {
                    card = card.Trim();
                    switch (docAttr.GetAggregation())
                    {
                        case DocAggregationEnum.SET:
                            card = "S" + card;
                            break;

                        case DocAggregationEnum.LIST:
                            card = "L" + card;
                            break;
                    }

                    int px = x + CX - DX;
                    int py = y + CY * (iAttr + 1);
                    g.FillRectangle(Brushes.White, px - CX / 5, py, CX / 5, CY);
                    using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Regular))
                    {
                        using (StringFormat fmt = new StringFormat())
                        {
                            fmt.Alignment = StringAlignment.Far;
                            g.DrawString(card, font, Brushes.Blue, px, py, fmt);
                        }
                    }
                }
            #endif
            }
        }
Пример #7
0
        /// <summary>
        /// Loads all content from a folder hierarchy (overlaying anything already existing)
        /// </summary>
        /// <param name="project"></param>
        /// <param name="path"></param>
        public static void LoadFolder(DocProject project, string path)
        {
            // get all files within folder hierarchy
            string pathSchema         = path + @"\schemas";
            IEnumerable <string> en   = System.IO.Directory.EnumerateFiles(pathSchema, "*.cs", System.IO.SearchOption.AllDirectories);
            List <string>        list = new List <string>();

            foreach (string s in en)
            {
                list.Add(s);
            }
            string[] files = list.ToArray();

            Dictionary <string, string> options = new Dictionary <string, string> {
                { "CompilerVersion", "v4.0" }
            };

            Microsoft.CSharp.CSharpCodeProvider        prov  = new Microsoft.CSharp.CSharpCodeProvider(options);
            System.CodeDom.Compiler.CompilerParameters parms = new System.CodeDom.Compiler.CompilerParameters();
            parms.GenerateInMemory   = true;
            parms.GenerateExecutable = false;
            parms.ReferencedAssemblies.Add("System.dll");
            parms.ReferencedAssemblies.Add("System.Core.dll");
            parms.ReferencedAssemblies.Add("System.ComponentModel.dll");
            parms.ReferencedAssemblies.Add("System.ComponentModel.DataAnnotations.dll");
            parms.ReferencedAssemblies.Add("System.Data.dll");
            parms.ReferencedAssemblies.Add("System.Runtime.Serialization.dll");
            parms.ReferencedAssemblies.Add("System.Xml.dll");

            System.CodeDom.Compiler.CompilerResults results = prov.CompileAssemblyFromFile(parms, files);
            System.Reflection.Assembly assem = results.CompiledAssembly;

            LoadAssembly(project, assem);

            // EXPRESS rules (eventually in C#, though .exp file snippets for now)
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.exp", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                string expr = null;
                using (StreamReader readExpr = new StreamReader(file, Encoding.UTF8))
                {
                    if (name.Contains('-'))
                    {
                        // where rule
                        expr = readExpr.ReadToEnd();
                    }
                    else
                    {
                        // function: skip first and last lines
                        readExpr.ReadLine();

                        StringBuilder sbExpr = new StringBuilder();
                        while (!readExpr.EndOfStream)
                        {
                            string line = readExpr.ReadLine();
                            if (!readExpr.EndOfStream)
                            {
                                sbExpr.AppendLine(line);
                            }
                        }

                        expr = sbExpr.ToString();
                    }
                }

                if (name.Contains('-'))
                {
                    // where rule
                    string[] parts = name.Split('-');
                    if (parts.Length == 2)
                    {
                        DocWhereRule docWhere = new DocWhereRule();
                        docWhere.Name       = parts[1];
                        docWhere.Expression = expr;

                        DocDefinition docDef = project.GetDefinition(parts[0]);
                        if (docDef is DocEntity)
                        {
                            DocEntity docEnt = (DocEntity)docDef;
                            docEnt.WhereRules.Add(docWhere);
                        }
                        else if (docDef is DocDefined)
                        {
                            DocDefined docEnt = (DocDefined)docDef;
                            docEnt.WhereRules.Add(docWhere);
                        }
                        else if (docDef == null)
                        {
                            //... global rule...
                        }
                    }
                }
                else
                {
                    // function
                    string schema = Path.GetDirectoryName(file);
                    schema = Path.GetDirectoryName(schema);
                    schema = Path.GetFileName(schema);
                    DocSchema docSchema = project.GetSchema(schema);
                    if (docSchema != null)
                    {
                        DocFunction docFunction = new DocFunction();
                        docSchema.Functions.Add(docFunction);
                        docFunction.Name       = name;
                        docFunction.Expression = expr;
                    }
                }
            }

            // now, hook up html documentation
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.htm", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string    name   = Path.GetFileNameWithoutExtension(file);
                DocObject docObj = null;
                if (name == "schema")
                {
                    string schema = Path.GetDirectoryName(file);
                    schema = Path.GetFileName(schema);
                    docObj = project.GetSchema(schema);
                }
                else if (name.Contains('-'))
                {
                    // where rule
                    string[] parts = name.Split('-');
                    if (parts.Length == 2)
                    {
                        DocDefinition docDef = project.GetDefinition(parts[0]);
                        if (docDef is DocEntity)
                        {
                            DocEntity docEnt = (DocEntity)docDef;
                            foreach (DocWhereRule docWhereRule in docEnt.WhereRules)
                            {
                                if (docWhereRule.Name.Equals(parts[1]))
                                {
                                    docObj = docWhereRule;
                                    break;
                                }
                            }
                        }
                        else if (docDef is DocDefined)
                        {
                            DocDefined docEnt = (DocDefined)docDef;
                            foreach (DocWhereRule docWhereRule in docEnt.WhereRules)
                            {
                                if (docWhereRule.Name.Equals(parts[1]))
                                {
                                    docObj = docWhereRule;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    docObj = project.GetDefinition(name);

                    if (docObj == null)
                    {
                        docObj = project.GetFunction(name);
                    }
                }

                if (docObj != null)
                {
                    using (StreamReader readHtml = new StreamReader(file, Encoding.UTF8))
                    {
                        docObj.Documentation = readHtml.ReadToEnd();
                    }
                }
            }

            // load schema diagrams
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.svg", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string schema = Path.GetDirectoryName(file);
                schema = Path.GetFileName(schema);

                DocSchema docSchema = project.GetSchema(schema);
                if (docSchema != null)
                {
                    using (IfcDoc.Schema.SVG.SchemaSVG schemaSVG = new IfcDoc.Schema.SVG.SchemaSVG(file, docSchema, project, DiagramFormat.UML))
                    {
                        schemaSVG.Load();
                    }
                }
            }

            // psets, qsets
            //...

            // exchanges
            en = System.IO.Directory.EnumerateFiles(path, "*.mvdxml", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                IfcDoc.Schema.MVD.SchemaMVD.Load(project, file);
            }

            // examples
            string pathExamples = path + @"\examples";

            if (Directory.Exists(pathExamples))
            {
                en = System.IO.Directory.EnumerateFiles(pathExamples, "*.htm", SearchOption.TopDirectoryOnly);
                foreach (string file in en)
                {
                    DocExample docExample = new DocExample();
                    docExample.Name = Path.GetFileNameWithoutExtension(file);
                    project.Examples.Add(docExample);

                    using (StreamReader reader = new StreamReader(file))
                    {
                        docExample.Documentation = reader.ReadToEnd();
                    }

                    string dirpath = file.Substring(0, file.Length - 4);
                    if (Directory.Exists(dirpath))
                    {
                        IEnumerable <string> suben = System.IO.Directory.EnumerateFiles(dirpath, "*.ifc", SearchOption.TopDirectoryOnly);
                        foreach (string ex in suben)
                        {
                            DocExample docEx = new DocExample();
                            docEx.Name = Path.GetFileNameWithoutExtension(ex);
                            docExample.Examples.Add(docEx);

                            // read the content of the file
                            using (FileStream fs = new FileStream(ex, FileMode.Open, FileAccess.Read))
                            {
                                docEx.File = new byte[fs.Length];
                                fs.Read(docEx.File, 0, docEx.File.Length);
                            }

                            // read documentation
                            string exdoc = ex.Substring(0, ex.Length - 4) + ".htm";
                            if (File.Exists(exdoc))
                            {
                                using (StreamReader reader = new StreamReader(exdoc))
                                {
                                    docEx.Documentation = reader.ReadToEnd();
                                }
                            }
                        }
                    }
                }
            }

            // localization
            en = System.IO.Directory.EnumerateFiles(path, "*.txt", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                using (FormatCSV format = new FormatCSV(file))
                {
                    try
                    {
                        format.Instance = project;
                        format.Load();
                    }
                    catch
                    {
                    }
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Draws entity and recurses.
        /// </summary>
        /// <param name="g">Graphics device.</param>
        /// <param name="lane">Horizontal lane for which to draw the entity.</param>
        /// <param name="lanes">List of lanes left-to-right.</param>
        /// <param name="docEntity">The entity to draw.</param>
        /// <param name="docView">The model view for which to draw the entity.</param>
        /// <param name="docTemplate">The template to draw.</param>
        /// <param name="docRule">Optional rule for recursing.</param>
        /// <param name="map">Map of definitions.</param>
        /// <param name="layout">Optional layout to receive rectangles for building image map</param>
        /// <param name="docProject">Required project.</param>
        /// <param name="instance">Optional instance where included or missing attributes are highlighted.</param>
        private static void DrawEntity(
            Graphics g, 
            int lane, 
            List<int> lanes, 
            DocEntity docEntity,
            DocModelView docView,
            DocTemplateDefinition docTemplate, 
            DocModelRuleEntity docRule, 
            Dictionary<string, DocObject> map, 
            Dictionary<Rectangle, DocModelRule> layout,
            DocProject docProject,
            DocSchema docSchema,
            object instance)
        {
            List<DocAttribute> listAttr = new List<DocAttribute>();
            BuildAttributeList(docEntity, listAttr, map);

            while(lanes.Count < lane + 1)
            {
                int miny = 0;
                if (lanes.Count > lane)
                {
                    miny = lanes[lane];
                }

                lanes.Add(miny);
            }

            int x = lane * CX + FormatPNG.Border;
            int y = lanes[lane] + FormatPNG.Border;

            if (g != null)
            {
                Brush brush = Brushes.Black;

                if (instance != null)
                {
                    brush = Brushes.Red;

                    if (instance is System.Collections.IList)
                    {
                        string typename = instance.GetType().Name;

                        // keep going until matching instance
                        System.Collections.IList list = (System.Collections.IList)instance;
                        foreach (object member in list)
                        {
                            string membertypename = member.GetType().Name;
                            DocEntity docType = docProject.GetDefinition(membertypename) as DocEntity;
                            while (docType != null)
                            {
                                if (docType == docEntity)
                                {
                                    brush = Brushes.Lime;
                                    instance = member;
                                    break;
                                }

                                docType = docProject.GetDefinition(docType.BaseDefinition) as DocEntity;
                            }

                            if (brush != Brushes.Red)
                                break;
                        }
                    }
                    else
                    {
                        string typename = instance.GetType().Name;
                        DocEntity docType = docProject.GetDefinition(typename) as DocEntity;
                        while (docType != null)
                        {
                            if (docType == docEntity)
                            {
                                brush = Brushes.Lime;
                                break;
                            }

                            docType = docProject.GetDefinition(docType.BaseDefinition) as DocEntity;
                        }
                    }
                }
                else if (docEntity.IsAbstract())
                {
                    brush = Brushes.Gray;
                }
                else
                {
                    brush = Brushes.Black;
                }
                g.FillRectangle(brush, x, y, CX - DX, CY);
                g.DrawRectangle(Pens.Black, x, y, CX - DX, CY);
                using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Bold))
                {
                    g.DrawString(docEntity.Name, font, Brushes.White, x, y);
                }

                if (docRule != null && docRule.Identification == "Value")
                {
                    // mark rule serving as default value
                    g.FillEllipse(Brushes.Green, new Rectangle(x + CX - DX - CY, y, CY, CY));
                }

                g.DrawRectangle(Pens.Black, x, y + CY, CX - DX, CY * listAttr.Count);
                using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Regular))
                {
                    for (int iAttr = 0; iAttr < listAttr.Count; iAttr++)
                    {
                        DocAttribute docAttr = listAttr[iAttr];

                        string display = docAttr.GetAggregationExpression();
                        brush = Brushes.Black;
                        if (docAttr.Inverse != null)
                        {
                            brush = Brushes.Gray;
                        }
                        if(String.IsNullOrEmpty(display))
                        {
                            if(docAttr.IsOptional)
                            {
                                display = "[0:1]";
                            }
                            else
                            {
                                display = "[1:1]";
                            }
                        }

                        g.DrawString(docAttr.Name, font, brush, x, y + CY * (iAttr + 1));
                        using (StringFormat fmt = new StringFormat())
                        {
                            fmt.Alignment = StringAlignment.Far;
                            g.DrawString(display, font, brush, new RectangleF(x, y + CY * (iAttr + 1), CX - DX, CY), fmt);
                        }

                    }
                }
            }

            // record rectangle
            if (layout != null)
            {
                layout.Add(new Rectangle(x, y, CX - DX, CY + CY * listAttr.Count), docRule);
            }

            SortedList<int, List<DocModelRuleAttribute>> mapAttribute = new SortedList<int, List<DocModelRuleAttribute>>();
            Dictionary<DocModelRuleAttribute, DocTemplateDefinition> mapTemplate = new Dictionary<DocModelRuleAttribute,DocTemplateDefinition>();
            if (docRule != null && docRule.Rules != null)
            {
                // map inner rules

                // sort
                foreach (DocModelRule rule in docRule.Rules)
                {
                    if (rule is DocModelRuleAttribute)
                    {
                        DocModelRuleAttribute ruleAttribute = (DocModelRuleAttribute)rule;
                        for (int i = 0; i < listAttr.Count; i++)
                        {
                            if (listAttr[i].Name.Equals(ruleAttribute.Name))
                            {
                                // found it
                                if (!mapAttribute.ContainsKey(i))
                                {
                                    mapAttribute.Add(i, new List<DocModelRuleAttribute>());
                                }

                                mapAttribute[i].Add(ruleAttribute);
                                break;
                            }
                        }
                    }
                }
            }
            else if (docTemplate != null)
            {
                if (docTemplate.Rules != null)
                {
                    foreach (DocModelRuleAttribute ruleAttribute in docTemplate.Rules)
                    {
                        for (int i = 0; i < listAttr.Count; i++)
                        {
                            if (listAttr[i].Name != null && listAttr[i].Name.Equals(ruleAttribute.Name))
                            {
                                // found it
                                //iAttr = i;
                                if (!mapAttribute.ContainsKey(i))
                                {
                                    mapAttribute.Add(i, new List<DocModelRuleAttribute>());
                                }
                                mapAttribute[i].Add(ruleAttribute);
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                // map each use definition at top-level

                // build list of inherited views
                List<DocModelView> listViews = new List<DocModelView>();
                DocModelView docBaseView = docView;
                while (docBaseView != null)
                {
                    listViews.Add(docBaseView);

                    if (!String.IsNullOrEmpty(docBaseView.BaseView))
                    {
                        Guid guidBase = Guid.Parse(docBaseView.BaseView);
                        if (guidBase != docBaseView.Uuid)
                        {
                            docBaseView = docProject.GetView(guidBase);
                        }
                        else
                        {
                            docBaseView = null;
                        }
                    }
                    else
                    {
                        docBaseView = null;
                    }
                }

                // build from inherited entities too

                List<DocTemplateDefinition> listTemplates = new List<DocTemplateDefinition>(); // keep track of templates so we don't repeat at supertypes
                List<DocTemplateDefinition> listSuppress = new List<DocTemplateDefinition>(); // list of templates that are suppressed

                DocEntity docEntitySuper = docEntity;
                while(docEntitySuper != null)
                {

                    foreach (DocModelView docEachView in docProject.ModelViews)
                    {
                        if (docView == null || listViews.Contains(docEachView))
                        {
                            foreach (DocConceptRoot docRoot in docEachView.ConceptRoots)
                            {
                                if (docRoot.ApplicableEntity == docEntitySuper)
                                {
                                    foreach (DocTemplateUsage docUsage in docRoot.Concepts)
                                    {
                                        if (docUsage.Definition != null && docUsage.Definition.Rules != null && !listTemplates.Contains(docUsage.Definition) && !listSuppress.Contains(docUsage.Definition))
                                        {
                                            if (docUsage.Suppress)
                                            {
                                                listSuppress.Add(docUsage.Definition);
                                            }
                                            else
                                            {

                                                listTemplates.Add(docUsage.Definition);

                                                foreach (DocModelRuleAttribute ruleAttribute in docUsage.Definition.Rules)
                                                {
                                                    for (int i = 0; i < listAttr.Count; i++)
                                                    {
                                                        if (listAttr[i].Name.Equals(ruleAttribute.Name))
                                                        {
                                                            // found it
                                                            if (!mapAttribute.ContainsKey(i))
                                                            {
                                                                mapAttribute.Add(i, new List<DocModelRuleAttribute>());
                                                            }

                                                            mapAttribute[i].Add(ruleAttribute);
                                                            if (!mapTemplate.ContainsKey(ruleAttribute))
                                                            {
                                                                mapTemplate.Add(ruleAttribute, docUsage.Definition);
                                                            }
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    DocObject docTest = null;
                    if (docEntitySuper.BaseDefinition != null && map.TryGetValue(docEntitySuper.BaseDefinition, out docTest))
                    {
                        docEntitySuper = docTest as DocEntity;
                    }
                    else
                    {
                        docEntitySuper = null;
                    }
                }
            }

            int offset = -mapAttribute.Values.Count / 2;

            DocTemplateDefinition lastTemplate = null;
            foreach (List<DocModelRuleAttribute> listSort in mapAttribute.Values)
            {
                if (docRule == null && docTemplate == null)
                {
                    // offset all lanes
                    int maxlane = 0;
                    for (int i = 1; i < lanes.Count; i++)
                    {
                        if (lanes[i] > maxlane)
                        {
                            maxlane = lanes[i];
                        }
                    }

                    for (int i = 1; i < lanes.Count; i++)
                    {
                        lanes[i] = maxlane;
                    }
                }

                foreach (DocModelRuleAttribute ruleAttributeSort in listSort)
                {
                    // indicate each template
                    DocTemplateDefinition eachTemplate = null;
                    if (mapTemplate.TryGetValue(ruleAttributeSort, out eachTemplate))
                    {
                        // offset for use definition
                        int minlan = 0;
                        for (int i = 1; i < lanes.Count; i++)
                        {
                            if (eachTemplate != lastTemplate)
                            {
                                lanes[i] += CY * 2;
                            }

                            if (lanes[i] > minlan)
                            {
                                minlan = lanes[i];
                            }
                        }

                        // verify this...
                        for (int i = 1; i < lanes.Count; i++)
                        {
                            if (lanes[i] < minlan)
                            {
                                lanes[i] = minlan;
                            }
                        }

                        if (g != null && eachTemplate != lastTemplate)
                        {
                            using (Font font = new Font(FontFamily.GenericSansSerif, 8.0f, FontStyle.Italic))
                            {
                                g.DrawString(eachTemplate.Name, font, Brushes.Gray, CX + FormatPNG.Border, lanes[1] - CY * 2 + FormatPNG.Border);
                            }
                            int lineY = lanes[1] - CY * 2 + FormatPNG.Border;
                            g.DrawLine(Pens.Gray, CX + FormatPNG.Border, lineY, 1920, lineY);
                        }

                        lastTemplate = eachTemplate;
                    }

                    DrawAttribute(g, lane, lanes, docEntity, docView, ruleAttributeSort, map, offset, layout, docProject, docSchema, instance as SEntity);
                }
                offset++;
            }

            // increment lane offset
            int minlane = y + CY * (listAttr.Count + 2);
            if (lanes[lane] < minlane)
            {
                lanes[lane] = minlane;
            }
        }
Пример #9
0
        private void DeleteReferencesForSchemaDefinition(DocSchema docSchema, DocDefinition docDef)
        {
            // delete attribute(s) referencing the definition
            foreach (DocEntity docEnt in docSchema.Entities)
            {
                for (int iAttr = docEnt.Attributes.Count - 1; iAttr >= 0; iAttr--)
                {
                    DocAttribute docAttr = docEnt.Attributes[iAttr];
                    if (docAttr.Definition == docDef)
                    {
                        docAttr.Delete();
                        docEnt.Attributes.RemoveAt(iAttr);
                    }
                }
            }

            for(int iType = docSchema.Types.Count-1; iType >= 0; iType--)
            {
                DocType docType = docSchema.Types[iType];
                if (docType is DocDefined)
                {
                    DocDefined docDefined = (DocDefined)docType;
                    if (docDefined.Definition == docDef)
                    {
                        docDefined.Delete();
                        docSchema.Types.RemoveAt(iType);
                    }
                }
            }

            // delete page refs referencing the definition
            for (int iPage = docSchema.PageTargets.Count - 1; iPage >= 0; iPage--)
            {
                DocPageTarget docPageTarget = docSchema.PageTargets[iPage];
                if(docPageTarget.Definition == docDef)
                {
                    // cascade deletion of sources
                    foreach(DocPageSource docPageSource in docPageTarget.Sources)
                    {
                        DeleteReferencesForSchemaDefinition(docSchema, docPageSource);
                    }

                    docPageTarget.Delete();
                    docSchema.PageTargets.RemoveAt(iPage);
                }
            }

            this.ctlExpressG.Schema = docSchema; // redraw
        }
Пример #10
0
        public static void LoadAssembly(DocProject project, Assembly assem)
        {
            // look through classes of assembly
            foreach (Type t in assem.GetTypes())
            {
                if (t.Namespace != null)
                {
                    string[]   namespaceparts = t.Namespace.Split('.');
                    string     schema         = namespaceparts[namespaceparts.Length - 1];
                    DocSection docSection     = null;
                    if (t.Namespace.EndsWith("Resource"))
                    {
                        docSection = project.Sections[7];
                    }
                    else if (t.Namespace.EndsWith("Domain"))
                    {
                        docSection = project.Sections[6];
                    }
                    else if (t.Namespace.Contains("Shared"))
                    {
                        docSection = project.Sections[5];
                    }
                    else
                    {
                        docSection = project.Sections[4];                         // kernel, extensions
                    }

                    // find schema
                    DocSchema docSchema = null;
                    foreach (DocSchema docEachSchema in docSection.Schemas)
                    {
                        if (docEachSchema.Name.Equals(schema))
                        {
                            docSchema = docEachSchema;
                            break;
                        }
                    }

                    if (docSchema == null)
                    {
                        docSchema      = new DocSchema();
                        docSchema.Name = schema;
                        docSection.Schemas.Add(docSchema);
                        docSection.SortSection();
                    }

                    DocDefinition docDef = null;
                    if (t.IsEnum)
                    {
                        DocEnumeration docEnum = new DocEnumeration();
                        docSchema.Types.Add(docEnum);
                        docDef = docEnum;

                        System.Reflection.FieldInfo[] fields = t.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                        foreach (System.Reflection.FieldInfo field in fields)
                        {
                            DocConstant docConst = new DocConstant();
                            docEnum.Constants.Add(docConst);
                            docConst.Name = field.Name;

                            DescriptionAttribute[] attrs = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                            if (attrs.Length == 1)
                            {
                                docConst.Documentation = attrs[0].Description;
                            }
                        }
                    }
                    else if (t.IsValueType)
                    {
                        PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                        if (fields.Length > 0)
                        {
                            Type typeField = fields[0].PropertyType;

                            DocDefined docDefined = new DocDefined();
                            docSchema.Types.Add(docDefined);
                            docDef = docDefined;
                            docDefined.DefinedType = FormatCSC.GetExpressType(typeField);

                            if (typeField.IsGenericType)
                            {
                                Type typeGeneric = typeField.GetGenericTypeDefinition();
                                typeField = typeField.GetGenericArguments()[0];
                                if (typeGeneric == typeof(ISet <>) ||
                                    typeGeneric == typeof(HashSet <>))
                                {
                                    docDefined.Aggregation = new DocAttribute();
                                    docDefined.Aggregation.AggregationType = (int)DocAggregationEnum.SET;
                                }
                                else if (typeGeneric == typeof(IList <>) ||
                                         typeGeneric == typeof(List <>))
                                {
                                    docDefined.Aggregation = new DocAttribute();
                                    docDefined.Aggregation.AggregationType = (int)DocAggregationEnum.LIST;
                                }
                            }

                            MaxLengthAttribute mxa = (MaxLengthAttribute)fields[0].GetCustomAttribute(typeof(MaxLengthAttribute));
                            if (mxa != null)
                            {
                                docDefined.Length = mxa.Length;
                            }
                        }
                    }
                    else if (t.IsInterface)
                    {
                        DocSelect docSelect = new DocSelect();
                        docSchema.Types.Add(docSelect);
                        docDef = docSelect;
                    }
                    else if (t.IsClass)
                    {
                        DocEntity docEntity = new DocEntity();
                        docSchema.Entities.Add(docEntity);
                        docDef = docEntity;

                        if (t.BaseType != null)
                        {
                            if (t.BaseType != typeof(object) && t.BaseType.Name != "SEntity")                             // back-compat for reflecting on IfcDoc types to generate Express
                            {
                                docEntity.BaseDefinition = t.BaseType.Name;
                            }
                        }

                        docEntity.IsAbstract = t.IsAbstract;

                        Dictionary <int, DocAttribute> attrsDirect  = new Dictionary <int, DocAttribute>();
                        List <DocAttribute>            attrsInverse = new List <DocAttribute>();
                        PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | BindingFlags.DeclaredOnly);
                        foreach (PropertyInfo field in fields)
                        {
                            DocAttribute docAttr = new DocAttribute();
                            docAttr.Name = field.Name;

                            Type typeField = field.PropertyType;
                            if (typeField.IsGenericType)
                            {
                                Type typeGeneric = typeField.GetGenericTypeDefinition();
                                typeField = typeField.GetGenericArguments()[0];
                                if (typeGeneric == typeof(Nullable <>))
                                {
                                    docAttr.IsOptional = true;
                                }
                                else if (typeGeneric == typeof(ISet <>) ||
                                         typeGeneric == typeof(HashSet <>))
                                {
                                    docAttr.AggregationType = (int)DocAggregationEnum.SET;
                                }
                                else if (typeGeneric == typeof(IList <>) ||
                                         typeGeneric == typeof(List <>))
                                {
                                    docAttr.AggregationType = (int)DocAggregationEnum.LIST;
                                }
                            }

                            // primitives
                            docAttr.DefinedType = FormatCSC.GetExpressType(typeField);

                            MinLengthAttribute mla = (MinLengthAttribute)field.GetCustomAttribute(typeof(MinLengthAttribute));
                            if (mla != null)
                            {
                                docAttr.AggregationLower = mla.Length.ToString();
                            }

                            MaxLengthAttribute mxa = (MaxLengthAttribute)field.GetCustomAttribute(typeof(MaxLengthAttribute));
                            if (mxa != null)
                            {
                                docAttr.AggregationUpper = mxa.Length.ToString();
                            }

                            DescriptionAttribute da = (DescriptionAttribute)field.GetCustomAttribute(typeof(DescriptionAttribute));
                            if (da != null)
                            {
                                docAttr.Documentation = da.Description;
                            }

                            DataMemberAttribute dma = (DataMemberAttribute)field.GetCustomAttribute(typeof(DataMemberAttribute));
                            if (dma != null)
                            {
                                attrsDirect.Add(dma.Order, docAttr);

                                RequiredAttribute rqa = (RequiredAttribute)field.GetCustomAttribute(typeof(RequiredAttribute));
                                if (rqa == null)
                                {
                                    docAttr.IsOptional = true;
                                }

                                CustomValidationAttribute cva = (CustomValidationAttribute)field.GetCustomAttribute(typeof(CustomValidationAttribute));
                                if (cva != null)
                                {
                                    docAttr.IsUnique = true;
                                }
                            }
                            else
                            {
                                InversePropertyAttribute ipa = (InversePropertyAttribute)field.GetCustomAttribute(typeof(InversePropertyAttribute));
                                if (ipa != null)
                                {
                                    docAttr.Inverse = ipa.Property;
                                    attrsInverse.Add(docAttr);
                                }
                            }

                            // xml
                            XmlIgnoreAttribute xia = (XmlIgnoreAttribute)field.GetCustomAttribute(typeof(XmlIgnoreAttribute));
                            if (xia != null)
                            {
                                docAttr.XsdFormat = DocXsdFormatEnum.Hidden;
                            }
                            else
                            {
                                XmlElementAttribute xea = (XmlElementAttribute)field.GetCustomAttribute(typeof(XmlElementAttribute));
                                if (xea != null)
                                {
                                    if (!String.IsNullOrEmpty(xea.ElementName))
                                    {
                                        docAttr.XsdFormat = DocXsdFormatEnum.Element;
                                    }
                                    else
                                    {
                                        docAttr.XsdFormat = DocXsdFormatEnum.Attribute;
                                    }
                                }
                            }
                        }

                        foreach (DocAttribute docAttr in attrsDirect.Values)
                        {
                            docEntity.Attributes.Add(docAttr);
                        }

                        foreach (DocAttribute docAttr in attrsInverse)
                        {
                            docEntity.Attributes.Add(docAttr);
                        }

                        // get derived attributes based on properties
#if false
                        PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
                        foreach (PropertyInfo prop in props)
                        {
                            // if no backing field, then derived
                            FieldInfo field = t.GetField("_" + prop.Name, BindingFlags.NonPublic | BindingFlags.Instance);
                            if (field == null)
                            {
                                DocAttribute docDerived = new DocAttribute();
                                docDerived.Name = prop.Name;
                                docEntity.Attributes.Add(docDerived);
                            }
                        }
#endif
                    }

                    if (docDef != null)
                    {
                        docDef.Name = t.Name;
                        docDef.Uuid = t.GUID;
                    }

                    docSchema.SortTypes();
                    docSchema.SortEntities();
                }
            }

            // pass 2: hook up selects
            foreach (Type t in assem.GetTypes())
            {
                Type[] typeInterfaces = t.GetInterfaces();

                Type[] typeInherit = null;
                if (t.BaseType != null)
                {
                    typeInherit = t.BaseType.GetInterfaces();
                }

                if (typeInterfaces.Length > 0)
                {
                    foreach (Type typeI in typeInterfaces)
                    {
                        if (typeInherit == null || !typeInherit.Contains <Type>(typeI))
                        {
                            DocSelect docSelect = project.GetDefinition(typeI.Name) as DocSelect;
                            if (docSelect != null)
                            {
                                DocSelectItem docItem = new DocSelectItem();
                                docItem.Name = t.Name;
                                docSelect.Selects.Add(docItem);
                            }
                        }
                    }
                }
            }
        }
Пример #11
0
        public static DocProject LoadFile(string filePath)
        {
            List <object> instances = new List <object>();
            string        ext       = System.IO.Path.GetExtension(filePath).ToLower();
            string        schema    = "";
            DocProject    project   = null;

            switch (ext)
            {
            case ".ifcdoc":
                using (FileStream streamDoc = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    Dictionary <long, object> dictionaryInstances = null;
                    StepSerializer            formatDoc           = new StepSerializer(typeof(DocProject), SchemaDOC.Types);
                    project = (DocProject)formatDoc.ReadObject(streamDoc, out dictionaryInstances);
                    instances.AddRange(dictionaryInstances.Values);
                    schema = formatDoc.Schema;
                }
                break;

            case ".ifcdocxml":
                using (FileStream streamDoc = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    Dictionary <string, object> dictionaryInstances = null;
                    XmlSerializer formatDoc = new XmlSerializer(typeof(DocProject));
                    project = (DocProject)formatDoc.ReadObject(streamDoc, out dictionaryInstances);
                    instances.AddRange(dictionaryInstances.Values);
                }
                break;

            default:
                MessageBox.Show("Unsupported file type " + ext, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;

#if MDB
            case ".mdb":
                using (FormatMDB format = new FormatMDB(this.m_file, SchemaDOC.Types, this.m_instances))
                {
                    format.Load();
                }
                break;
#endif
            }
            if (project == null)
            {
                return(null);
            }

            double schemaVersion = 0;
            if (!string.IsNullOrEmpty(schema))
            {
                string[] fields = schema.Split("_".ToCharArray());
                int      i      = 0;
                if (fields.Length > 1)
                {
                    if (int.TryParse(fields[1], out i))
                    {
                        schemaVersion = i;
                    }
                    if (fields.Length > 2 && int.TryParse(fields[2], out i))
                    {
                        schemaVersion += i / 10.0;
                    }
                }
            }
            List <SEntity> listDelete = new List <SEntity>();
            List <DocTemplateDefinition> listTemplate = new List <DocTemplateDefinition>();

            foreach (object o in instances)
            {
                if (o is DocSchema)
                {
                    DocSchema docSchema = (DocSchema)o;

                    // renumber page references
                    foreach (DocPageTarget docTarget in docSchema.PageTargets)
                    {
                        if (docTarget.Definition != null)                         // fix it up -- NULL bug from older .ifcdoc files
                        {
                            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 DocConceptRoot)
                {
                    // V12.0: ensure template is defined
                    DocConceptRoot docConcRoot = (DocConceptRoot)o;
                    if (docConcRoot.ApplicableTemplate == null && docConcRoot.ApplicableEntity != null)
                    {
                        docConcRoot.ApplicableTemplate      = new DocTemplateDefinition();
                        docConcRoot.ApplicableTemplate.Type = docConcRoot.ApplicableEntity.Name;
                    }
                }
                else if (o is DocTemplateUsage)
                {
                    // V12.0: ensure template is defined
                    DocTemplateUsage docUsage = (DocTemplateUsage)o;
                    if (docUsage.Definition == null)
                    {
                        docUsage.Definition = new DocTemplateDefinition();
                    }
                }
                else if (o is DocLocalization)
                {
                    DocLocalization localization = o as DocLocalization;
                    if (!string.IsNullOrEmpty(localization.Name))
                    {
                        localization.Name = localization.Name.Trim();
                    }
                }
                // ensure all objects have valid guid
                DocObject docObject = o as DocObject;
                if (docObject != null)
                {
                    if (docObject.Uuid == Guid.Empty)
                    {
                        docObject.Uuid = Guid.NewGuid();
                    }
                    if (!string.IsNullOrEmpty(docObject.Documentation))
                    {
                        docObject.Documentation = docObject.Documentation.Trim();
                    }

                    if (schemaVersion < 12.1)
                    {
                        DocChangeSet docChangeSet = docObject as DocChangeSet;
                        if (docChangeSet != null)
                        {
                            docChangeSet.ChangesEntities.RemoveAll(x => !isUnchanged(x));
                        }
                        else
                        {
                            if (schemaVersion < 12)
                            {
                                DocEntity entity = docObject as DocEntity;
                                if (entity != null)
                                {
                                    entity.ClearDefaultMember();
                                }
                            }
                        }
                    }
                }
            }

            if (project == null)
            {
                return(null);
            }

            if (schemaVersion > 0 && schemaVersion < 12.1)
            {
                Dictionary <string, DocPropertyEnumeration> encounteredPropertyEnumerations = new Dictionary <string, DocPropertyEnumeration>();
                foreach (DocSchema docSchema in project.Sections.SelectMany(x => x.Schemas))
                {
                    extractListingsV12_1(project, docSchema, encounteredPropertyEnumerations);
                }
            }
            foreach (DocModelView docModelView in project.ModelViews)
            {
                // sort alphabetically (V11.3+)
                docModelView.SortConceptRoots();
            }

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

                DocAnnotation docCover    = project.Annotations[0];
                DocAnnotation docContents = project.Annotations[1];
                DocAnnotation docForeword = project.Annotations[2];
                DocAnnotation docIntro    = 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);

                project.Publications.Add(docPub);

                docCover.Delete();
                docContents.Delete();
                project.Annotations.Clear();
            }
            project.SortProject();
            return(project);
        }
Пример #12
0
        public void Load()
        {
            svg s = null;

            using (FormatXML format = new FormatXML(this.m_filename, typeof(svg), "http://www.w3.org/2000/svg"))
            {
                format.Load();
                s = format.Instance as svg;
            }

            if (s == null)
            {
                return;
            }

            // apply diagram to existing schema elements
            foreach (g group in s.g)
            {
                // primitive
                DocDefinition docDef = null;
                switch (group.id)
                {
                case "INTEGER":
                case "REAL":
                case "BOOLEAN":
                case "LOGICAL":
                case "STRING":
                case "BINARY":
                    docDef      = new DocPrimitive();
                    docDef.Name = group.id;
                    m_schema.Primitives.Add((DocPrimitive)docDef);
                    break;

                default:
                    docDef = this.m_schema.GetDefinition(group.id);
                    break;
                }

                if (docDef != null)
                {
                    docDef.DiagramRectangle = LoadRectangle(group);

                    // attributes, supertype...
                    if (docDef is DocEntity)
                    {
                        DocEntity docEnt = (DocEntity)docDef;
                        LoadTree(group, docEnt.Tree);

                        foreach (g subgroup in group.groups)
                        {
                            foreach (DocAttribute docAttr in docEnt.Attributes)
                            {
                                if (docAttr.Name.Equals(subgroup.id))
                                {
                                    LoadLine(subgroup, docAttr.DiagramLine);

                                    if (subgroup.text.Count == 1)
                                    {
                                        double ax = Double.Parse(subgroup.text[0].x) / CtlExpressG.Factor;
                                        double ay = Double.Parse(subgroup.text[0].y) / CtlExpressG.Factor;

                                        docAttr.DiagramLabel   = new DocRectangle();
                                        docAttr.DiagramLabel.X = ax;
                                        docAttr.DiagramLabel.Y = ay;
                                    }

                                    break;
                                }
                            }
                        }

                        // base type???
                    }
                    else if (docDef is DocDefined)
                    {
                        DocDefined docDefined = (DocDefined)docDef;
                        LoadLine(group, docDefined.DiagramLine);
                    }
                    else if (docDef is DocSelect)
                    {
                        DocSelect docSelect = (DocSelect)docDef;
                        LoadTree(group, docSelect.Tree);
                    }
                }
                else
                {
                    // schema ref
                    DocSchema docTargetSchema = this.m_project.GetSchema(group.id);
                    if (docTargetSchema != null)
                    {
                        DocSchemaRef docSchemaRef = new DocSchemaRef();
                        docSchemaRef.Name = group.id;
                        this.m_schema.SchemaRefs.Add(docSchemaRef);

                        foreach (g subgroup in group.groups)
                        {
                            DocDefinition docTargetDef = docTargetSchema.GetDefinition(subgroup.id);
                            if (docTargetDef != null)
                            {
                                DocDefinitionRef docDefRef = new DocDefinitionRef();
                                docDefRef.Name = subgroup.id;
                                docSchemaRef.Definitions.Add(docDefRef);
                                docDefRef.DiagramRectangle = LoadRectangle(subgroup);

                                LoadTree(subgroup, docDefRef.Tree);
                            }
                        }
                    }
                    else
                    {
                        // primitive?

                        // page targets
                        DocPageTarget docPageTarget = new DocPageTarget();
                        docPageTarget.Name = group.id;
                        this.m_schema.PageTargets.Add(docPageTarget);
                        docPageTarget.DiagramRectangle = LoadRectangle(group);
                        //...docPageTarget.Definition =
                        LoadLine(group, docPageTarget.DiagramLine);

                        foreach (g subgroup in group.groups)
                        {
                            DocPageSource docPageSource = new DocPageSource();
                            docPageSource.Name = subgroup.id;
                            docPageTarget.Sources.Add(docPageSource);
                            docPageSource.DiagramRectangle = LoadRectangle(subgroup);
                        }
                    }
                }
            }
        }
Пример #13
0
        internal static DocSchema ImportXsd(IfcDoc.Schema.XSD.schema schema, DocProject docProject)
        {
            // use resource-level section
            DocSection docSection = docProject.Sections[6]; // source schemas

            DocSchema docSchema = new DocSchema();
            docSchema.Name = schema.id;//??
            docSchema.Code = schema.id;
            docSchema.Version = schema.version;
            docSection.Schemas.Add(docSchema);

            foreach(IfcDoc.Schema.XSD.simpleType simple in schema.simpleType)
            {
                ImportXsdSimple(simple, docSchema, null);
            }

            foreach (IfcDoc.Schema.XSD.complexType complex in schema.complexType)
            {
                DocEntity docEntity = new DocEntity();
                docSchema.Entities.Add(docEntity);
                docEntity.Name = complex.name;
                docEntity.Documentation = ImportXsdAnnotation(complex.annotation);

                ImportXsdComplex(complex, docSchema, docEntity);
            }

            foreach (IfcDoc.Schema.XSD.element element in schema.element)
            {
                DocEntity docEntity = new DocEntity();
                docSchema.Entities.Add(docEntity);
                docEntity.Name = element.name;
                docEntity.Documentation = ImportXsdAnnotation(element.annotation);

                ImportXsdComplex(element.complexType, docSchema, docEntity);
            }

            return docSchema;
        }
Пример #14
0
        internal static void ImportXsdAttribute(IfcDoc.Schema.XSD.attribute att, DocSchema docSchema, DocEntity docEntity)
        {
            DocAttribute docAttr = new DocAttribute();
            docEntity.Attributes.Add(docAttr);
            docAttr.Name = att.name;
            docAttr.IsOptional = (att.use == Schema.XSD.use.optional);

            if (att.simpleType != null)
            {
                string refname = docEntity.Name + "_" + att.name;
                docAttr.DefinedType = refname;
                ImportXsdSimple(att.simpleType, docSchema, refname);
            }
            else
            {
                docAttr.DefinedType = ImportXsdType(att.type);
            }
        }
Пример #15
0
 private void toolStripMenuItemInsertSchema_Click(object sender, EventArgs e)
 {
     TreeNode tnParent = this.treeView.SelectedNode;
     DocSection docSection = (DocSection)tnParent.Tag;
     DocSchema docSchema = new DocSchema();
     docSection.Schemas.Add(docSchema);
     this.treeView.SelectedNode = this.LoadNode(tnParent, docSchema, null, true);
     LoadNodeSchema(this.treeView.SelectedNode, docSchema);
     toolStripMenuItemEditRename_Click(this, e);
 }
Пример #16
0
        /// <summary>
        /// Replaces links from one object to another, such as page references
        /// </summary>
        /// <param name="docSchema"></param>
        /// <param name="docOld">The old reference to unlink</param>
        /// <param name="docNew">The new reference to link</param>
        /// <param name="force">If true, redirects even if on same page; if false and on same page, then doesn't redirect</param>
        private void RedirectReference(DocSchema docSchema, DocDefinition docOld, DocDefinition docNew, bool force)
        {
            // find reference to each source and redirect to target definition
            foreach (DocEntity docEntity in docSchema.Entities)
            {
                if (force || (docEntity.DiagramNumber != docOld.DiagramNumber))
                {
                    foreach (DocAttribute docAttr in docEntity.Attributes)
                    {
                        if (docAttr.Definition == docOld)
                        {
                            docAttr.Definition = CreateLink(docNew, docAttr.DiagramLine[0]);
                            this.ctlExpressG.LayoutDefinition(docEntity);
                        }
                    }

                    foreach (DocLine docLine in docEntity.Tree)
                    {
                        if (docLine.Definition == docOld)
                        {
                            docLine.Definition = CreateLink(docNew, docLine.DiagramLine[0]);
                            this.ctlExpressG.LayoutDefinition(docEntity);
                        }
                        foreach (DocLine docNode in docLine.Tree)
                        {
                            if (docNode.Definition == docOld)
                            {
                                docNode.Definition = CreateLink(docNew, docLine.DiagramLine[0]);
                                this.ctlExpressG.LayoutDefinition(docEntity);
                            }
                        }
                    }
                }
            }

            foreach (DocType docType in docSchema.Types)
            {
                if (force || (docType.DiagramNumber != docOld.DiagramNumber))
                {
                    if (docType is DocDefined)
                    {
                        DocDefined docDef = (DocDefined)docType;
                        if (docDef.Definition == docOld)
                        {
                            docDef.Definition = CreateLink(docNew, docDef.DiagramLine[0]);
                            this.ctlExpressG.LayoutDefinition(docDef);
                        }
                    }
                    else if (docType is DocSelect)
                    {
                        DocSelect docSel = (DocSelect)docType;
                        foreach (DocLine docLine in docSel.Tree)
                        {
                            if (docLine.Definition == docOld)
                            {
                                docLine.Definition = CreateLink(docNew, docLine.DiagramLine[0]);
                                this.ctlExpressG.LayoutDefinition(docSel);
                            }
                            foreach (DocLine docNode in docLine.Tree)
                            {
                                if (docNode.Definition == docOld)
                                {
                                    docNode.Definition = CreateLink(docNew, docLine.DiagramLine[0]);
                                    this.ctlExpressG.LayoutDefinition(docSel);//?...
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #17
0
        private void LoadNodeSchema(TreeNode tnSchema, DocSchema schema)
        {
            TreeNode tnTypeHeader = LoadNode(tnSchema, typeof(DocType), "Types", false);
            foreach (DocType type in schema.Types)
            {
                TreeNode tnType = LoadNode(tnTypeHeader, type, type.Name, true);
                if (type is DocEnumeration)
                {
                    DocEnumeration enumeration = (DocEnumeration)type;
                    foreach (DocConstant constant in enumeration.Constants)
                    {
                        LoadNode(tnType, constant, constant.Name, false);
                    }
                }
                else if (type is DocSelect)
                {
                    DocSelect select = (DocSelect)type;
                    foreach (DocSelectItem selitem in select.Selects)
                    {
                        LoadNode(tnType, selitem, selitem.Name, false);
                    }
                }
                else if (type is DocDefined)
                {
                    DocDefined define = (DocDefined)type;
                    foreach(DocWhereRule docRule in define.WhereRules)
                    {
                        LoadNode(tnType, docRule, docRule.Name, false);
                    }
                }
            }

            TreeNode tnEntityHeader = LoadNode(tnSchema, typeof(DocEntity), "Entities", false);
            foreach (DocEntity type in schema.Entities)
            {
                TreeNode tnType = LoadNode(tnEntityHeader, type, type.Name, true);

                string key = type.Name.ToLowerInvariant();

                foreach (DocAttribute attr in type.Attributes)
                {
                    TreeNode tnAttribute = LoadNode(tnType, attr, attr.Name, false);
                    if (!String.IsNullOrEmpty(attr.Derived))
                    {
                        tnAttribute.ImageIndex = ImageIndexAttributeDerived;
                        tnAttribute.SelectedImageIndex = ImageIndexAttributeDerived;
                    }
                    else if (!String.IsNullOrEmpty(attr.Inverse))
                    {
                        tnAttribute.ImageIndex = ImageIndexAttributeInverse;
                        tnAttribute.SelectedImageIndex = ImageIndexAttributeInverse;
                    }
                }

                foreach (DocWhereRule wr in type.WhereRules)
                {
                    LoadNode(tnType, wr, wr.Name, false);
                }

                foreach (DocUniqueRule ur in type.UniqueRules)
                {
                    LoadNode(tnType, ur, ur.Name, false);
                }

                // new style templates
                foreach (DocModelView docModelView in this.m_project.ModelViews)
                {
                    if (docModelView.ConceptRoots != null)
                    {
                        foreach (DocConceptRoot docConceptRoot in docModelView.ConceptRoots)
                        {
                            if (docConceptRoot.ApplicableEntity == type)
                            {
                                string rootname = docConceptRoot.Name;
                                if(String.IsNullOrEmpty(rootname))
                                {
                                    rootname = docModelView.Name;
                                }
                                TreeNode tnConceptRoot = LoadNode(tnType, docConceptRoot, rootname, false);
                                foreach (DocTemplateUsage docConcept in docConceptRoot.Concepts)
                                {
                                    LoadNodeConcept(tnConceptRoot, docConcept);
                                }
                            }
                        }
                    }
                }
            }

            TreeNode tnGlobHeader = LoadNode(tnSchema, typeof(DocGlobalRule), "Global Rules", false);
            if (schema.GlobalRules.Count > 0)
            {
                foreach (DocGlobalRule func in schema.GlobalRules)
                {
                    LoadNode(tnGlobHeader, func, func.Name, true);
                }
            }

            TreeNode tnFuncHeader = LoadNode(tnSchema, typeof(DocFunction), "Functions", false);
            if (schema.Functions.Count > 0)
            {
                foreach (DocFunction func in schema.Functions)
                {
                    LoadNode(tnFuncHeader, func, func.Name, true);
                }
            }

            TreeNode tnPsetHeader = LoadNode(tnSchema, typeof(DocPropertySet), "Property Sets", false);
            foreach (DocPropertySet pset in schema.PropertySets)
            {
                TreeNode tnPset = LoadNode(tnPsetHeader, pset, pset.Name, true);
                foreach (DocProperty docprop in pset.Properties)
                {
                    TreeNode tnProp = LoadNode(tnPset, docprop, docprop.Name, false);

                    // complex properties
                    foreach (DocProperty docpropelem in docprop.Elements)
                    {
                        LoadNode(tnProp, docpropelem, docpropelem.Name, false);
                    }
                }
            }

            TreeNode tnPeHeader = LoadNode(tnSchema, typeof(DocPropertyEnumeration), "Property Enumerations", false);
            foreach (DocPropertyEnumeration en in schema.PropertyEnums)
            {
                TreeNode tnEnum = LoadNode(tnPeHeader, en, en.Name, true);
                foreach (DocPropertyConstant docconst in en.Constants)
                {
                    LoadNode(tnEnum, docconst, docconst.Name, false);
                }
            }

            TreeNode tnQsetHeader = LoadNode(tnSchema, typeof(DocQuantitySet), "Quantity Sets", false);
            if (schema.QuantitySets.Count > 0)
            {
                foreach (DocQuantitySet qset in schema.QuantitySets)
                {
                    TreeNode tnQset = LoadNode(tnQsetHeader, qset, qset.Name, true);
                    foreach (DocQuantity docprop in qset.Quantities)
                    {
                        LoadNode(tnQset, docprop, docprop.Name, false);
                    }
                }
            }

            TreeNode tnGraphicsHeader = LoadNode(tnSchema, typeof(DocSchemaRef), "Schema References", false);
            foreach (DocSchemaRef docItem in schema.SchemaRefs)
            {
                TreeNode tnTarget = LoadNode(tnGraphicsHeader, docItem, docItem.Name, false);
                foreach (DocDefinitionRef docSource in docItem.Definitions)
                {
                    LoadNode(tnTarget, docSource, docSource.Name, false);
                }
            }
            tnGraphicsHeader = LoadNode(tnSchema, typeof(DocPageTarget), "Page References", false);
            foreach (DocPageTarget docItem in schema.PageTargets)
            {
                TreeNode tnTarget = LoadNode(tnGraphicsHeader, docItem, docItem.Name, false);
                foreach (DocPageSource docSource in docItem.Sources)
                {
                    LoadNode(tnTarget, docSource, docSource.Name, false);
                }
            }
            tnGraphicsHeader = LoadNode(tnSchema, typeof(DocPrimitive), "Primitive References", false);
            foreach (DocPrimitive docItem in schema.Primitives)
            {
                LoadNode(tnGraphicsHeader, docItem, docItem.Name, false);
            }
            tnGraphicsHeader = LoadNode(tnSchema, typeof(DocComment), "Comments", false);
            foreach (DocComment docItem in schema.Comments)
            {
                LoadNode(tnGraphicsHeader, docItem, docItem.Name, false);
            }
        }
Пример #18
0
 public SchemaSVG(string filename, DocSchema docSchema, DocProject docProject)
 {
     this.m_filename = filename;
     this.m_schema   = docSchema;
     this.m_project  = docProject;
 }
Пример #19
0
 public Task <DocSchema> Save(string schemaID, DocSchema schema, string token) => PutAsync <DocSchema>(schema, token, "schemas", schemaID);
Пример #20
0
        internal static void ImportXsdComplex(IfcDoc.Schema.XSD.complexType complex, DocSchema docSchema, DocEntity docEntity)
        {
            if (complex == null)
                return;

            foreach (IfcDoc.Schema.XSD.attribute att in complex.attribute)
            {
                ImportXsdAttribute(att, docSchema, docEntity);
            }

            if (complex.choice != null)
            {
                foreach (IfcDoc.Schema.XSD.element sub in complex.choice.element)
                {
                    ImportXsdElement(sub, docEntity, true);
                }
            }

            if (complex.sequence != null)
            {
                foreach (IfcDoc.Schema.XSD.element sub in complex.sequence.element)
                {
                    ImportXsdElement(sub, docEntity, true);
                }
            }

            if (complex.all != null)
            {
                foreach (IfcDoc.Schema.XSD.element sub in complex.all.element)
                {
                    ImportXsdElement(sub, docEntity, true);
                }
            }

            if (complex.complexContent != null)
            {
                if(complex.complexContent.extension != null)
                {
                    docEntity.BaseDefinition = complex.complexContent.extension.basetype;

                    foreach (IfcDoc.Schema.XSD.attribute att in complex.complexContent.extension.attribute)
                    {
                        ImportXsdAttribute(att, docSchema, docEntity);
                    }

                    if(complex.complexContent.extension.choice != null)
                    {
                        foreach (IfcDoc.Schema.XSD.element sub in complex.complexContent.extension.choice.element)
                        {
                            ImportXsdElement(sub, docEntity, true);
                        }
                    }
                }
            }
        }
Пример #21
0
        /// <summary>
        /// Loads all content from a folder hierarchy (overlaying anything already existing)
        /// </summary>
        /// <param name="project"></param>
        /// <param name="path"></param>
        public static void Load(DocProject project, string path)
        {
            // get all files within folder hierarchy
            string pathSchema         = path + @"\schemas";
            IEnumerable <string> en   = System.IO.Directory.EnumerateFiles(pathSchema, "*.cs", System.IO.SearchOption.AllDirectories);
            List <string>        list = new List <string>();

            foreach (string s in en)
            {
                list.Add(s);
            }
            string[] files = list.ToArray();

            Dictionary <string, string> options = new Dictionary <string, string> {
                { "CompilerVersion", "v4.0" }
            };

            Microsoft.CSharp.CSharpCodeProvider        prov  = new Microsoft.CSharp.CSharpCodeProvider(options);
            System.CodeDom.Compiler.CompilerParameters parms = new System.CodeDom.Compiler.CompilerParameters();
            parms.GenerateInMemory   = true;
            parms.GenerateExecutable = false;
            parms.ReferencedAssemblies.Add("System.dll");
            parms.ReferencedAssemblies.Add("System.Core.dll");
            parms.ReferencedAssemblies.Add("System.ComponentModel.dll");
            parms.ReferencedAssemblies.Add("System.ComponentModel.DataAnnotations.dll");
            parms.ReferencedAssemblies.Add("System.Data.dll");
            parms.ReferencedAssemblies.Add("System.Runtime.Serialization.dll");
            parms.ReferencedAssemblies.Add("System.Xml.dll");

            System.CodeDom.Compiler.CompilerResults results = prov.CompileAssemblyFromFile(parms, files);
            System.Reflection.Assembly assem = results.CompiledAssembly;

            // look through classes of assembly
            foreach (Type t in assem.GetTypes())
            {
                string[]   namespaceparts = t.Namespace.Split('.');
                string     schema         = namespaceparts[namespaceparts.Length - 1];
                DocSection docSection     = null;
                if (t.Namespace.EndsWith("Resource"))
                {
                    docSection = project.Sections[7];
                }
                else if (t.Namespace.EndsWith("Domain"))
                {
                    docSection = project.Sections[6];
                }
                else if (t.Namespace.Contains("Shared"))
                {
                    docSection = project.Sections[5];
                }
                else
                {
                    docSection = project.Sections[4]; // kernel, extensions
                }

                // find schema
                DocSchema docSchema = null;
                foreach (DocSchema docEachSchema in docSection.Schemas)
                {
                    if (docEachSchema.Name.Equals(schema))
                    {
                        docSchema = docEachSchema;
                        break;
                    }
                }

                if (docSchema == null)
                {
                    docSchema      = new DocSchema();
                    docSchema.Name = schema;
                    docSection.Schemas.Add(docSchema);
                    docSection.SortSchemas();
                }

                DocDefinition docDef = null;
                if (t.IsEnum)
                {
                    DocEnumeration docEnum = new DocEnumeration();
                    docSchema.Types.Add(docEnum);
                    docDef = docEnum;

                    System.Reflection.FieldInfo[] fields = t.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                    foreach (System.Reflection.FieldInfo field in fields)
                    {
                        DocConstant docConst = new DocConstant();
                        docEnum.Constants.Add(docConst);
                        docConst.Name = field.Name;

                        DescriptionAttribute[] attrs = (DescriptionAttribute[])field.GetCustomAttributes(typeof(DescriptionAttribute), false);
                        if (attrs.Length == 1)
                        {
                            docConst.Documentation = attrs[0].Description;
                        }
                    }
                }
                else if (t.IsValueType)
                {
                    DocDefined docDefined = new DocDefined();
                    docSchema.Types.Add(docDefined);
                    docDef = docDefined;

                    PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                    docDefined.DefinedType = fields[0].PropertyType.Name;
                }
                else if (t.IsInterface)
                {
                    DocSelect docSelect = new DocSelect();
                    docSchema.Types.Add(docSelect);
                    docDef = docSelect;
                }
                else if (t.IsClass)
                {
                    DocEntity docEntity = new DocEntity();
                    docSchema.Entities.Add(docEntity);
                    docDef = docEntity;

                    if (t.BaseType != typeof(object))
                    {
                        docEntity.BaseDefinition = t.BaseType.Name;
                    }

                    if (!t.IsAbstract)
                    {
                        docEntity.EntityFlags = 0x20;
                    }

                    Dictionary <int, DocAttribute> attrsDirect  = new Dictionary <int, DocAttribute>();
                    List <DocAttribute>            attrsInverse = new List <DocAttribute>();
                    PropertyInfo[] fields = t.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                    foreach (PropertyInfo field in fields)
                    {
                        DocAttribute docAttr = new DocAttribute();
                        docAttr.Name = field.Name.Substring(1);

                        Type typeField = field.PropertyType;
                        if (typeField.IsGenericType)
                        {
                            Type typeGeneric = typeField.GetGenericTypeDefinition();
                            typeField = typeField.GetGenericArguments()[0];
                            if (typeGeneric == typeof(Nullable <>))
                            {
                                docAttr.IsOptional = true;
                            }
                            else if (typeGeneric == typeof(ISet <>))
                            {
                                docAttr.AggregationType = (int)DocAggregationEnum.SET;
                            }
                            else if (typeGeneric == typeof(IList <>))
                            {
                                docAttr.AggregationType = (int)DocAggregationEnum.LIST;
                            }
                        }

                        docAttr.DefinedType = typeField.Name;


                        MinLengthAttribute mla = (MinLengthAttribute)field.GetCustomAttribute(typeof(MinLengthAttribute));
                        if (mla != null)
                        {
                            docAttr.AggregationLower = mla.Length.ToString();
                        }

                        MaxLengthAttribute mxa = (MaxLengthAttribute)field.GetCustomAttribute(typeof(MaxLengthAttribute));
                        if (mxa != null)
                        {
                            docAttr.AggregationUpper = mxa.Length.ToString();
                        }

                        PropertyInfo propinfo = t.GetProperty(docAttr.Name);
                        if (propinfo != null)
                        {
                            DescriptionAttribute da = (DescriptionAttribute)propinfo.GetCustomAttribute(typeof(DescriptionAttribute));
                            if (da != null)
                            {
                                docAttr.Documentation = da.Description;
                            }
                        }

                        DataMemberAttribute dma = (DataMemberAttribute)field.GetCustomAttribute(typeof(DataMemberAttribute));
                        if (dma != null)
                        {
                            attrsDirect.Add(dma.Order, docAttr);

                            RequiredAttribute rqa = (RequiredAttribute)field.GetCustomAttribute(typeof(RequiredAttribute));
                            if (rqa == null)
                            {
                                docAttr.IsOptional = true;
                            }

                            CustomValidationAttribute cva = (CustomValidationAttribute)field.GetCustomAttribute(typeof(CustomValidationAttribute));
                            if (cva != null)
                            {
                                docAttr.IsUnique = true;
                            }
                        }
                        else
                        {
                            InversePropertyAttribute ipa = (InversePropertyAttribute)field.GetCustomAttribute(typeof(InversePropertyAttribute));
                            if (ipa != null)
                            {
                                docAttr.Inverse = ipa.Property;
                                attrsInverse.Add(docAttr);
                            }
                        }

                        // xml
                        XmlIgnoreAttribute xia = (XmlIgnoreAttribute)field.GetCustomAttribute(typeof(XmlIgnoreAttribute));
                        if (xia != null)
                        {
                            docAttr.XsdFormat = DocXsdFormatEnum.Hidden;
                        }
                        else
                        {
                            XmlElementAttribute xea = (XmlElementAttribute)field.GetCustomAttribute(typeof(XmlElementAttribute));
                            if (xea != null)
                            {
                                if (!String.IsNullOrEmpty(xea.ElementName))
                                {
                                    docAttr.XsdFormat = DocXsdFormatEnum.Element;
                                }
                                else
                                {
                                    docAttr.XsdFormat = DocXsdFormatEnum.Attribute;
                                }
                            }
                        }
                    }

                    foreach (DocAttribute docAttr in attrsDirect.Values)
                    {
                        docEntity.Attributes.Add(docAttr);
                    }

                    foreach (DocAttribute docAttr in attrsInverse)
                    {
                        docEntity.Attributes.Add(docAttr);
                    }

                    // get derived attributes based on properties
                    PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public);
                    foreach (PropertyInfo prop in props)
                    {
                        // if no backing field, then derived
                        FieldInfo field = t.GetField("_" + prop.Name, BindingFlags.NonPublic | BindingFlags.Instance);
                        if (field == null)
                        {
                            DocAttribute docDerived = new DocAttribute();
                            docDerived.Name = prop.Name;
                            docEntity.Attributes.Add(docDerived);
                        }
                    }
                }

                if (docDef != null)
                {
                    docDef.Name = t.Name;
                    docDef.Uuid = t.GUID;
                }

                docSchema.SortTypes();
                docSchema.SortEntities();
            }

            // pass 2: hook up selects
            foreach (Type t in assem.GetTypes())
            {
                Type[] typeInterfaces = t.GetInterfaces();
                if (typeInterfaces.Length > 0)
                {
                    foreach (Type typeI in typeInterfaces)
                    {
                        DocSelect docSelect = project.GetDefinition(typeI.Name) as DocSelect;
                        if (docSelect != null)
                        {
                            DocSelectItem docItem = new DocSelectItem();
                            docItem.Name = t.Name;
                            docSelect.Selects.Add(docItem);
                        }
                    }
                }
            }

            // EXPRESS rules (eventually in C#, though .exp file snippets for now)
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.exp", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string name = Path.GetFileNameWithoutExtension(file);
                string expr = null;
                using (StreamReader readExpr = new StreamReader(file, Encoding.UTF8))
                {
                    expr = readExpr.ReadToEnd();
                }

                if (name.Contains('-'))
                {
                    // where rule
                    string[] parts = name.Split('-');
                    if (parts.Length == 2)
                    {
                        DocWhereRule docWhere = new DocWhereRule();
                        docWhere.Name       = parts[1];
                        docWhere.Expression = expr;

                        DocDefinition docDef = project.GetDefinition(parts[0]);
                        if (docDef is DocEntity)
                        {
                            DocEntity docEnt = (DocEntity)docDef;
                            docEnt.WhereRules.Add(docWhere);
                        }
                        else if (docDef is DocDefined)
                        {
                            DocDefined docEnt = (DocDefined)docDef;
                            docEnt.WhereRules.Add(docWhere);
                        }
                        else if (docDef == null)
                        {
                            //... global rule...
                        }
                    }
                }
                else
                {
                    // function
                    string schema = Path.GetDirectoryName(file);
                    schema = Path.GetDirectoryName(schema);
                    schema = Path.GetFileName(schema);
                    DocSchema docSchema = project.GetSchema(schema);
                    if (docSchema != null)
                    {
                        DocFunction docFunction = new DocFunction();
                        docSchema.Functions.Add(docFunction);
                        docFunction.Name       = name;
                        docFunction.Expression = expr;
                    }
                }
            }

            // now, hook up html documentation
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.htm", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string    name   = Path.GetFileNameWithoutExtension(file);
                DocObject docObj = null;
                if (name == "schema")
                {
                    string schema = Path.GetDirectoryName(file);
                    schema = Path.GetFileName(schema);
                    docObj = project.GetSchema(schema);
                }
                else if (name.Contains('-'))
                {
                    // where rule
                    string[] parts = name.Split('-');
                    if (parts.Length == 2)
                    {
                        DocDefinition docDef = project.GetDefinition(parts[0]);
                        if (docDef is DocEntity)
                        {
                            DocEntity docEnt = (DocEntity)docDef;
                            foreach (DocWhereRule docWhereRule in docEnt.WhereRules)
                            {
                                if (docWhereRule.Name.Equals(parts[1]))
                                {
                                    docObj = docWhereRule;
                                    break;
                                }
                            }
                        }
                        else if (docDef is DocDefined)
                        {
                            DocDefined docEnt = (DocDefined)docDef;
                            foreach (DocWhereRule docWhereRule in docEnt.WhereRules)
                            {
                                if (docWhereRule.Name.Equals(parts[1]))
                                {
                                    docObj = docWhereRule;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    docObj = project.GetDefinition(name);

                    if (docObj == null)
                    {
                        docObj = project.GetFunction(name);
                    }
                }

                if (docObj != null)
                {
                    using (StreamReader readHtml = new StreamReader(file, Encoding.UTF8))
                    {
                        docObj.Documentation = readHtml.ReadToEnd();
                    }
                }
            }

            // load schema diagrams
            en = System.IO.Directory.EnumerateFiles(pathSchema, "*.svg", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                string schema = Path.GetDirectoryName(file);
                schema = Path.GetFileName(schema);

                DocSchema docSchema = project.GetSchema(schema);
                if (docSchema != null)
                {
                    using (IfcDoc.Schema.SVG.SchemaSVG schemaSVG = new IfcDoc.Schema.SVG.SchemaSVG(file, docSchema, project))
                    {
                        schemaSVG.Load();
                    }
                }
            }

            // psets, qsets
            //...

            // exchanges
            en = System.IO.Directory.EnumerateFiles(path, "*.mvdxml", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                IfcDoc.Schema.MVD.SchemaMVD.Load(project, file);
            }

            // examples
            string pathExamples = path + @"\examples";

            if (Directory.Exists(pathExamples))
            {
                en = System.IO.Directory.EnumerateFiles(pathExamples, "*.htm", SearchOption.TopDirectoryOnly);
                foreach (string file in en)
                {
                    DocExample docExample = new DocExample();
                    docExample.Name = Path.GetFileNameWithoutExtension(file);
                    project.Examples.Add(docExample);

                    using (StreamReader reader = new StreamReader(file))
                    {
                        docExample.Documentation = reader.ReadToEnd();
                    }

                    string dirpath = file.Substring(0, file.Length - 4);
                    if (Directory.Exists(dirpath))
                    {
                        IEnumerable <string> suben = System.IO.Directory.EnumerateFiles(dirpath, "*.ifc", SearchOption.TopDirectoryOnly);
                        foreach (string ex in suben)
                        {
                            DocExample docEx = new DocExample();
                            docEx.Name = Path.GetFileNameWithoutExtension(ex);
                            docExample.Examples.Add(docEx);

                            // read the content of the file
                            using (FileStream fs = new FileStream(ex, FileMode.Open, FileAccess.Read))
                            {
                                docEx.File = new byte[fs.Length];
                                fs.Read(docEx.File, 0, docEx.File.Length);
                            }

                            // read documentation
                            string exdoc = ex.Substring(0, ex.Length - 4) + ".htm";
                            if (File.Exists(exdoc))
                            {
                                using (StreamReader reader = new StreamReader(exdoc))
                                {
                                    docEx.Documentation = reader.ReadToEnd();
                                }
                            }
                        }
                    }
                }
            }

            // localization
            en = System.IO.Directory.EnumerateFiles(path, "*.txt", System.IO.SearchOption.AllDirectories);
            foreach (string file in en)
            {
                using (FormatCSV format = new FormatCSV(file))
                {
                    try
                    {
                        format.Instance = project;
                        format.Load();
                    }
                    catch
                    {
                    }
                }
            }
        }
Пример #22
0
        private void SaveNode(TreeNode tn)
        {
            ChangeInfo info = (ChangeInfo)tn.Tag;

            if (tn.Checked)
            {
                if (info.Original == null)
                {
                    // add new item
                    if (info.Change is DocLocalization)
                    {
                        DocLocalization localChange = (DocLocalization)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocObject  docObj     = (DocObject)parentinfo.Original;
                        docObj.RegisterLocalization(localChange.Locale, localChange.Name, localChange.Documentation);
                    }
                    else if (info.Change is DocAttribute)
                    {
                        DocAttribute localAttr = (DocAttribute)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocEntity  docEntity  = (DocEntity)parentinfo.Original;

                        DocAttribute docAttr = (DocAttribute)localAttr.Clone();
                        docEntity.Attributes.Add(docAttr);
                    }
                    else if (info.Change is DocWhereRule)
                    {
                        DocWhereRule localAttr = (DocWhereRule)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocEntity  docEntity  = (DocEntity)parentinfo.Original;

                        DocWhereRule docAttr = (DocWhereRule)localAttr.Clone();
                        docEntity.WhereRules.Add(docAttr);
                    }
                    else if (info.Change is DocFunction)
                    {
                        DocFunction localAttr = (DocFunction)info.Change;

                        ChangeInfo parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocSchema  docSchema  = (DocSchema)parentinfo.Original;

                        DocFunction docAttr = (DocFunction)localAttr.Clone();
                        docSchema.Functions.Add(docAttr);
                    }
                    else if (info.Change is DocConstant)
                    {
                        this.ToString();
                    }
                    else if (info.Change is DocProperty)
                    {
                        this.ToString();

                        DocProperty localProp = (DocProperty)info.Change;

                        ChangeInfo     parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocPropertySet docPset    = (DocPropertySet)parentinfo.Original;

                        DocProperty docProperty = (DocProperty)localProp.Clone();
                        docPset.Properties.Add(docProperty);
                    }
                    else if (info.Change is DocPropertyConstant)
                    {
                        this.ToString();

                        DocPropertyConstant localProp = (DocPropertyConstant)info.Change;

                        ChangeInfo             parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocPropertyEnumeration docPset    = (DocPropertyEnumeration)parentinfo.Original;

                        DocPropertyEnumeration docEnumChange = (DocPropertyEnumeration)parentinfo.Change;
                        int index = docEnumChange.Constants.IndexOf(localProp);

                        DocPropertyConstant docProperty = (DocPropertyConstant)localProp.Clone();
                        docPset.Constants.Insert(index, docProperty);
                    }
                    else
                    {
                        this.ToString();
                    }
                }
                else if (info.Change == null)
                {
                    // removal of definition
                    if (info.Original is DocAttribute)
                    {
                        DocAttribute docAttr    = (DocAttribute)info.Original;
                        ChangeInfo   parentinfo = (ChangeInfo)tn.Parent.Tag;
                        DocEntity    docEntity  = (DocEntity)parentinfo.Original;

                        docEntity.Attributes.Remove(docAttr);
                        docAttr.Delete();
                    }
                    else
                    {
                        this.ToString();
                    }
                }
                else
                {
                    // change of documentation
                    info.Original.Name          = info.Change.Name;
                    info.Original.Documentation = info.Change.Documentation;

                    if (info.Original is DocWhereRule)
                    {
                        DocWhereRule whereOriginal = (DocWhereRule)info.Original;
                        DocWhereRule whereChange   = (DocWhereRule)info.Change;
                        whereOriginal.Expression = whereChange.Expression;
                    }
                    else if (info.Original is DocFunction)
                    {
                        DocFunction whereOriginal = (DocFunction)info.Original;
                        DocFunction whereChange   = (DocFunction)info.Change;
                        whereOriginal.Expression = whereChange.Expression;
                    }
                }
            }

            foreach (TreeNode tnSub in tn.Nodes)
            {
                SaveNode(tnSub);
            }
        }
Пример #23
0
        internal static void ImportXsdSimple(IfcDoc.Schema.XSD.simpleType simple, DocSchema docSchema, string name)
        {
            string thename = simple.name;
            if (simple.name == null)
            {
                thename = name;
            }

            if (simple.restriction != null && simple.restriction.enumeration.Count > 0)
            {
                DocEnumeration docEnum = new DocEnumeration();
                docSchema.Types.Add(docEnum);
                docEnum.Name = thename;
                docEnum.Documentation = ImportXsdAnnotation(simple.annotation);
                foreach (IfcDoc.Schema.XSD.enumeration en in simple.restriction.enumeration)
                {
                    DocConstant docConst = new DocConstant();
                    docConst.Name = en.value;
                    docConst.Documentation = ImportXsdAnnotation(en.annotation);

                    docEnum.Constants.Add(docConst);
                }
            }
            else
            {
                DocDefined docDef = new DocDefined();
                docDef.Name = thename;
                docDef.Documentation = ImportXsdAnnotation(simple.annotation);
                if (simple.restriction != null)
                {
                    docDef.DefinedType = ImportXsdType(simple.restriction.basetype);
                }
                docSchema.Types.Add(docDef);
            }
        }
Пример #24
0
        public static void Upload(DocProject docProject, BackgroundWorker worker, string baseurl, string username, string password, string parentid, DocModelView[] docViews)
        {
            string sessionid = Connect(docProject, worker, baseurl, username, password);

#if false
            if (docViews != null && docViews.Length > 0)
            {
                foreach (DocModelView docView in docViews)//docProject.ModelViews)
                {
                    // hack: only bridge view for now
                    if (docView.Name.Contains("Bridge"))
                    {
                        string codename = docView.Name;
                        if (!String.IsNullOrEmpty(docView.Code))
                        {
                            codename = docView.Code;
                        }

                        IfdBase ifdView = CreateConcept(baseurl, sessionid, docView, codename, docView.Name, IfdConceptTypeEnum.BAG);
                        //CreateRelationship(baseurl, sessionid, parentid, ifdView.guid, "COLLECTS"); // no top-level item for now

                        foreach (DocConceptRoot docRoot in docView.ConceptRoots)
                        {
                            if (docRoot.Name != null)
                            {
                                System.Diagnostics.Debug.WriteLine(docRoot.ToString());

                                IfdBase ifdRoot = CreateConcept(baseurl, sessionid, docRoot, docRoot.ApplicableEntity.Name, docRoot.Name, IfdConceptTypeEnum.SUBJECT);
                                CreateRelationship(baseurl, sessionid, ifdView.guid, ifdRoot.guid, IfdRelationshipTypeEnum.COLLECTS);

                                foreach (DocTemplateUsage docConc in docRoot.Concepts)
                                {
                                    UploadTemplateUsage(docProject, baseurl, sessionid, ifdRoot.guid, docConc);
                                }
                            }
                        }
                    }
                }
            }
            else
#endif
            {
                // build list of types referenced by property sets
                Dictionary <string, IfdBase> mapEntities = new Dictionary <string, IfdBase>();


                // core schema
                foreach (DocSection docSection in docProject.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        // only export objects that have associated property sets
                        foreach (DocPropertySet docPset in docSchema.PropertySets)
                        {
                            IfdBase ifdPset = CreateConcept(baseurl, sessionid, docPset, docPset.Name, docPset.Name, docPset.PropertySetType.ToString(), IfdConceptTypeEnum.BAG);
                            foreach (DocProperty docProp in docPset.Properties)
                            {
                                IfdBase ifdProp = CreateConcept(baseurl, sessionid, docProp, docProp.Name, docProp.Name, docProp.PropertyType.ToString(), IfdConceptTypeEnum.PROPERTY);
                                if (ifdProp != null)
                                {
                                    CreateRelationship(baseurl, sessionid, ifdPset.guid, ifdProp.guid, IfdRelationshipTypeEnum.COLLECTS);

                                    string paramval = docProp.PrimaryDataType;
                                    if (!String.IsNullOrEmpty(paramval))
                                    {
                                        DocDefinition docDef = docProject.GetDefinition(paramval);
                                        if (docDef != null)
                                        {
                                            // get the measure type
                                            IfdBase ifdType = SearchConcept(baseurl, sessionid, docDef.Name, IfdConceptTypeEnum.MEASURE);
                                            if (ifdType == null)
                                            {
                                                // create concept
                                                ifdType = CreateConcept(baseurl, sessionid, docDef, docDef.Name, docDef.Name, null, IfdConceptTypeEnum.MEASURE);

                                                // for enums, get enumerated type
                                                if (docProp.PropertyType == DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE)
                                                {
                                                    DocSchema docPropSchema            = null;
                                                    DocPropertyEnumeration docPropEnum = docProject.FindPropertyEnumeration(docProp.SecondaryDataType, out docPropSchema);
                                                    if (docPropEnum != null)
                                                    {
                                                        foreach (DocPropertyConstant docPropConst in docPropEnum.Constants)
                                                        {
                                                            IfdBase ifdConst = CreateConcept(baseurl, sessionid, docPropConst, docPropConst.Name, docPropConst.Name, null, IfdConceptTypeEnum.VALUE);
                                                            CreateRelationship(baseurl, sessionid, ifdType.guid, ifdConst.guid, IfdRelationshipTypeEnum.ASSIGNS_VALUES);
                                                        }
                                                    }
                                                }
                                            }
                                            CreateRelationship(baseurl, sessionid, ifdProp.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES); // ??? fails for Pset_BuildingUse.NarrativeText / IfcText
                                        }
                                    }
                                }
                            }

                            // now link the property set to applicable type
                            DocEntity[] docEntities = docPset.GetApplicableTypeDefinitions(docProject);
                            if (docEntities != null && docEntities.Length > 0)
                            {
                                // only the first one matters
                                DocEntity docEnt = docEntities[0];
                                IfdBase   ifdEnt = null;
                                if (!mapEntities.TryGetValue(docEnt.Name, out ifdEnt))
                                {
                                    ifdEnt = CreateConcept(baseurl, sessionid, docEnt, docEnt.Name, docEnt.Name, null, IfdConceptTypeEnum.SUBJECT);
                                    mapEntities.Add(docEnt.Name, ifdEnt);

                                    // subtypes (predefined type)
                                    foreach (DocAttribute docAttr in docEnt.Attributes)
                                    {
                                        if (docAttr.Name.Equals("PredefinedType"))
                                        {
                                            DocEnumeration docEnum = docProject.GetDefinition(docAttr.DefinedType) as DocEnumeration;
                                            if (docEnum != null)
                                            {
                                                foreach (DocConstant docConst in docEnum.Constants)
                                                {
                                                    IfdBase ifdConst = CreateConcept(baseurl, sessionid, docConst, docConst.Name, docConst.Name, null, IfdConceptTypeEnum.SUBJECT);
                                                    CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdConst.guid, IfdRelationshipTypeEnum.SPECIALIZES);
                                                }
                                            }
                                        }
                                    }
                                }
                                CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdPset.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS); //!!! Fails with Forbidden!!! why???
                                // http://test.bsdd.buildingsmart.org/api/4.0/IfdRelationship/validrelations/SUBJECT/BAG indicates
                                // <ifdRelationshipTypeEnums>
                                //   <IfdRelationshipType xmlns="http://peregrine.catenda.no/objects">ASSIGNS_COLLECTIONS</IfdRelationshipType>
                                // </ifdRelationshipTypeEnums>
                            }
                        }

                        foreach (DocQuantitySet docPset in docSchema.QuantitySets)
                        {
                            IfdBase ifdPset = CreateConcept(baseurl, sessionid, docPset, docPset.Name, docPset.Name, "QTO_OCCURRENCEDRIVEN", IfdConceptTypeEnum.BAG);
                            foreach (DocQuantity docProp in docPset.Quantities)
                            {
                                IfdBase ifdProp = CreateConcept(baseurl, sessionid, docProp, docProp.Name, docProp.Name, docProp.QuantityType.ToString(), IfdConceptTypeEnum.PROPERTY);
                                if (ifdProp != null)
                                {
                                    CreateRelationship(baseurl, sessionid, ifdPset.guid, ifdProp.guid, IfdRelationshipTypeEnum.COLLECTS);

                                    string propclass = "IfcQuantityCount";
                                    switch (docProp.QuantityType)
                                    {
                                    case DocQuantityTemplateTypeEnum.Q_AREA:
                                        propclass = "IfcQuantityArea";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_COUNT:
                                        propclass = "IfcQuantityCount";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_LENGTH:
                                        propclass = "IfcQuantityLength";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_TIME:
                                        propclass = "IfcQuantityTime";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_VOLUME:
                                        propclass = "IfcQuantityVolume";
                                        break;

                                    case DocQuantityTemplateTypeEnum.Q_WEIGHT:
                                        propclass = "IfcQuantityWeight";
                                        break;
                                    }

                                    string paramval = propclass;
                                    if (!String.IsNullOrEmpty(paramval))
                                    {
                                        DocDefinition docDef = docProject.GetDefinition(paramval);
                                        if (docDef != null)
                                        {
                                            // get the measure type
                                            IfdBase ifdType = SearchConcept(baseurl, sessionid, docDef.Name, IfdConceptTypeEnum.MEASURE);
                                            if (ifdType == null)
                                            {
                                                // create concept
                                                ifdType = CreateConcept(baseurl, sessionid, docDef, docDef.Name, docDef.Name, null, IfdConceptTypeEnum.MEASURE);
                                            }
                                            CreateRelationship(baseurl, sessionid, ifdProp.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES); // ??? fails for Pset_BuildingUse.NarrativeText / IfcText
                                        }
                                    }
                                }
                            }

                            // now link the property set to applicable type
                            DocEntity[] docEntities = docPset.GetApplicableTypeDefinitions(docProject);
                            if (docEntities != null && docEntities.Length > 0)
                            {
                                // only the first one matters
                                DocEntity docEnt = docEntities[0];
                                IfdBase   ifdEnt = null;
                                if (mapEntities.TryGetValue(docEnt.Name, out ifdEnt))
                                {
                                    CreateRelationship(baseurl, sessionid, ifdEnt.guid, ifdPset.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #25
0
 public Task <DocSchema> Create(DocSchema schema, string token) => PostAsync(schema, token, "schemas");