Exemplo n.º 1
0
        /// <summary>
        /// Builds syntax for referencing select
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="docEntity"></param>
        /// <param name="map"></param>
        /// <param name="included"></param>
        /// <param name="hasentry">Whether entries already listed; if not, then colon is added</param>
        private void BuildSelectEntries(StringBuilder sb, DocDefinition docEntity, Dictionary <string, DocObject> map, Dictionary <DocObject, bool> included, bool hasentry)
        {
            SortedList <string, DocSelect> listSelects = new SortedList <string, DocSelect>();

            foreach (DocObject obj in map.Values)
            {
                if (obj is DocSelect)
                {
                    DocSelect docSelect = (DocSelect)obj;
                    foreach (DocSelectItem docItem in docSelect.Selects)
                    {
                        if (docItem.Name != null && docItem.Name.Equals(docEntity.Name) && !listSelects.ContainsKey(docSelect.Name))
                        {
                            // found it; add it
                            listSelects.Add(docSelect.Name, docSelect);
                        }
                    }
                }
            }

            foreach (DocSelect docSelect in listSelects.Values)
            {
                if (docSelect == listSelects.Values[0] && !hasentry)
                {
                    sb.Append(" : ");
                }
                else
                {
                    sb.Append(", ");
                }
                sb.Append(docSelect.Name);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs a value path with all parameters
 /// </summary>
 /// <param name="type"></param>
 /// <param name="property"></param>
 /// <param name="identifier"></param>
 /// <param name="inner"></param>
 public CvtValuePath(DocDefinition type, DocAttribute property, string identifier, CvtValuePath inner)
 {
     this.m_type = type;
     this.m_property = property;
     this.m_identifier = identifier;
     this.m_inner = inner;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Constructs a value path with all parameters
 /// </summary>
 /// <param name="type"></param>
 /// <param name="property"></param>
 /// <param name="identifier"></param>
 /// <param name="inner"></param>
 public CvtValuePath(DocDefinition type, DocAttribute property, string identifier, CvtValuePath inner)
 {
     this.m_type       = type;
     this.m_property   = property;
     this.m_identifier = identifier;
     this.m_inner      = inner;
 }
Exemplo n.º 4
0
        private void CtlExpressG_DragOver(object sender, DragEventArgs e)
        {
            Point  clientPoint = this.PointToClient(new Point(e.X, e.Y));
            double X           = (clientPoint.X - this.AutoScrollPosition.X) / Factor;
            double Y           = (clientPoint.Y - this.AutoScrollPosition.Y) / Factor;

            DocDefinition docDef = e.Data.GetData(typeof(DocEntity)) as DocEntity;

            if (docDef == null)
            {
                docDef = e.Data.GetData(typeof(DocType)) as DocType;
            }

            if (docDef != null)
            {
                e.Effect = DragDropEffects.Move;

                if (docDef.DiagramRectangle == null)
                {
                    docDef.DiagramRectangle = new DocRectangle();
                }

                docDef.DiagramRectangle.X = X;
                docDef.DiagramRectangle.Y = Y;

                if (docDef.DiagramRectangle.Width <= 0.0 || docDef.DiagramRectangle.Height <= 0.0)
                {
                    docDef.DiagramRectangle.Width  = 400.0;
                    docDef.DiagramRectangle.Height = 100.0;// +50.0 * docEnt.Attributes.Count;
                }

                this.Redraw();
            }
        }
Exemplo n.º 5
0
        public static void LayoutLine(DocDefinition defA, DocDefinition defB, List <DocPoint> list)
        {
            if (list == null)
            {
                return;
            }

            while (list.Count > 3)
            {
                list[list.Count - 1].Delete();
                list.RemoveAt(list.Count - 1);
            }
            while (list.Count < 3)
            {
                list.Add(new DocPoint());
            }
            DocPoint ptA = list[0];
            DocPoint ptM = list[1];
            DocPoint ptB = list[2];

            DocRectangle rB = null;

            if (defB != null)
            {
                rB = defB.DiagramRectangle;
            }

            LayoutLine(defA.DiagramRectangle, rB, ptA, ptM, ptB);
        }
Exemplo n.º 6
0
        public static void UploadTemplateUsage(DocProject docProject, string baseurl, string sessionid, string parentid, DocTemplateUsage docConc)
        {
            // MVD Concept entry is a relationship in BSDD; contexts are exchanges
            foreach (DocTemplateItem docItem in docConc.Items)
            {
                if (docItem.Concepts.Count == 0)
                {
                    string code = docItem.GetParameterValue("Reference");
                    if (String.IsNullOrEmpty(code))
                    {
                        code = docItem.Name;
                    }
                    code = HttpUtility.UrlEncode(code);

                    string name = docItem.GetParameterValue("Name");
                    if (code != null && name != null)
                    {
                        // if no sub-concepts, then its a property
                        IfdBase ifdItem = CreateConcept(baseurl, sessionid, docItem, code, name, null, IfdConceptTypeEnum.PROPERTY);
                        CreateRelationship(baseurl, sessionid, parentid, ifdItem.guid, IfdRelationshipTypeEnum.ASSIGNS_PROPERTIES);

                        string paramval = docItem.GetParameterValue("Value");
                        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, ifdItem.guid, ifdType.guid, IfdRelationshipTypeEnum.ASSIGNS_MEASURES);
                            }
                        }
                    }
                }
                else
                {
                    // otherwise its a nest
                    if (docItem.Name != null)
                    {
                        IfdBase ifdItem = CreateConcept(baseurl, sessionid, docItem, docItem.Name, docItem.Name, null, IfdConceptTypeEnum.NEST);
                        CreateRelationship(baseurl, sessionid, parentid, ifdItem.guid, IfdRelationshipTypeEnum.ASSIGNS_COLLECTIONS);

                        // recurse -- e.g. properties within property sets
                        foreach (DocTemplateUsage docInner in docItem.Concepts)
                        {
                            UploadTemplateUsage(docProject, baseurl, sessionid, ifdItem.guid, docInner);
                        }
                    }
                }
            }
        }
Exemplo n.º 7
0
        public FormReference(DocProject docProject, DocDefinition docBase, Dictionary<string, DocObject> map, string value)
            : this()
        {
            this.m_project = docProject;
            this.m_base = docBase;
            this.m_map = map;

            // parse value
            CvtValuePath valuepath = CvtValuePath.Parse(value, map);
            LoadValuePath(valuepath);
        }
Exemplo n.º 8
0
        public CellValue GetCell(int row, int col)
        {
            if (col >= this.m_listTemplate.Count || row >= this.m_view.ConceptRoots.Count)
            {
                return(CellValue.Unavailable);
            }

            DocTemplateDefinition docTemplate = this.m_listTemplate[col];
            DocConceptRoot        docRoot     = this.m_view.ConceptRoots[row];

            // return Unavailable if template is incompatible with root
            bool          applicable = false;
            DocDefinition docDef     = this.m_project.GetDefinition(docTemplate.Type);
            DocEntity     docEnt     = docRoot.ApplicableEntity;

            while (docEnt != null)
            {
                if (docEnt == docDef)
                {
                    applicable = true;
                    break;
                }

                docEnt = this.m_project.GetDefinition(docEnt.BaseDefinition) as DocEntity;
            }

            if (!applicable)
            {
                return(CellValue.Unavailable);
            }

            foreach (DocTemplateUsage docUsage in docRoot.Concepts)
            {
                if (docUsage.Definition == docTemplate)
                {
                    foreach (DocExchangeItem docExchangeItem in docUsage.Exchanges)
                    {
                        if (docExchangeItem.Exchange == this.m_exchange && docExchangeItem.Applicability == DocExchangeApplicabilityEnum.Export)
                        {
                            switch (docExchangeItem.Requirement)
                            {
                            case DocExchangeRequirementEnum.Mandatory:
                                return(CellValue.Required);

                            case DocExchangeRequirementEnum.Optional:
                                return(CellValue.Optional);
                            }
                        }
                    }
                }
            }

            return(CellValue.None);
        }
Exemplo n.º 9
0
        public FormReference(DocProject docProject, DocDefinition docBase, Dictionary <string, DocObject> map, string value)
            : this()
        {
            this.m_project = docProject;
            this.m_base    = docBase;
            this.m_map     = map;

            // parse value
            CvtValuePath valuepath = CvtValuePath.Parse(value, map);

            LoadValuePath(valuepath);
        }
Exemplo n.º 10
0
        private static CvtValuePath FromModelRule(DocModelRuleEntity docRuleEntity, DocProject docProject)
        {
            DocDefinition docDef     = docProject.GetDefinition(docRuleEntity.Name);
            DocAttribute  docAtt     = null;
            string        identifier = null;
            CvtValuePath  pathInner  = null;

            if (docDef is DocEntity && docRuleEntity.Rules.Count > 0 && docRuleEntity.Rules[0] is DocModelRuleAttribute)
            {
                DocModelRuleAttribute docRuleAtt = (DocModelRuleAttribute)docRuleEntity.Rules[0];
                DocEntity             docEnt     = (DocEntity)docDef;
                docAtt = docEnt.ResolveAttribute(docRuleAtt.Name, docProject);

                if (docRuleAtt.Rules.Count > 0 && docRuleAtt.Rules[0] is DocModelRuleEntity)
                {
                    DocModelRuleEntity docRuleInner = (DocModelRuleEntity)docRuleAtt.Rules[0];
                    pathInner = FromModelRule(docRuleInner, docProject);


                    // look for identifier
                    if (docRuleInner.Rules.Count > 1 && docRuleInner.Rules[1] is DocModelRuleAttribute)
                    {
                        DocModelRuleAttribute docRuleIndexAtt = (DocModelRuleAttribute)docRuleInner.Rules[1];
                        if (docRuleIndexAtt.Rules.Count > 0)
                        {
                            DocModelRuleEntity docRuleIndexEnt = (DocModelRuleEntity)docRuleIndexAtt.Rules[0];
                            if (docRuleIndexEnt.Rules.Count > 0 && docRuleIndexEnt.Rules[0] is DocModelRuleConstraint)
                            {
                                DocModelRuleConstraint docRuleIndexCon = (DocModelRuleConstraint)docRuleIndexEnt.Rules[0];
                                if (docRuleIndexCon.Expression is DocOpStatement)
                                {
                                    DocOpStatement docOpStatement = (DocOpStatement)docRuleIndexCon.Expression;
                                    if (docOpStatement.Value != null)
                                    {
                                        identifier = docOpStatement.Value.ToString();
                                        if (identifier.StartsWith("'") && identifier.EndsWith("'"))
                                        {
                                            identifier = identifier.Substring(1, identifier.Length - 2);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            CvtValuePath pathOuter = new CvtValuePath(docDef, docAtt, identifier, pathInner);

            return(pathOuter);
        }
Exemplo n.º 11
0
        private void treeViewAlphabetical_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (this.treeViewAlphabetical.SelectedNode == null)
            {
                return;
            }

            DocDefinition entity = this.treeViewAlphabetical.SelectedNode.Tag as DocDefinition;

            if (entity != null)
            {
                this.treeViewInheritance.SelectedNode = this.m_mapInherit[entity];
            }

            this.LoadPredefined();
        }
Exemplo n.º 12
0
        private static void ImportVexRectangle(DocDefinition docDefinition, RECTANGLE rectangle, SCHEMATA schemata)
        {
            if (rectangle != null && schemata.settings != null && schemata.settings.page != null)
            {
                int px = (int)(rectangle.x / schemata.settings.page.width);
                int py = (int)(rectangle.y / schemata.settings.page.height);
                int page = 1 + py * schemata.settings.page.nhorizontalpages + px;
                docDefinition.DiagramNumber = page;

                docDefinition.DiagramRectangle = new DocRectangle();
                docDefinition.DiagramRectangle.X = rectangle.x;
                docDefinition.DiagramRectangle.Y = rectangle.y;
                docDefinition.DiagramRectangle.Width = rectangle.dx;
                docDefinition.DiagramRectangle.Height = rectangle.dy;
            }
        }
Exemplo n.º 13
0
        private void SelectWithinRectangle(DocDefinition def, Rectangle rc)
        {
            if (def.DiagramRectangle == null)
            {
                return;
            }

            Rectangle rcObject = new Rectangle(
                (int)(def.DiagramRectangle.X * Factor) + this.AutoScrollPosition.X,
                (int)(def.DiagramRectangle.Y * Factor) + this.AutoScrollPosition.Y,
                (int)(def.DiagramRectangle.Width * Factor),
                (int)(def.DiagramRectangle.Height * Factor));

            if (rc.IntersectsWith(rcObject))
            {
                this.m_multiselect.Add(def);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Updates layout of node end of tree, adjusting tree segment as necessary
        /// </summary>
        /// <param name="docLine"></param>
        /// <param name="docDef"></param>
        public static void LayoutNode(DocLine docTree, DocLine docLine)
        {
            DocDefinition docDef = docLine.Definition;

            if (docLine.DiagramLine.Count >= 2)
            {
                while (docLine.DiagramLine.Count < 3)
                {
                    docLine.DiagramLine.Insert(1, new DocPoint());
                }

                // shortcut: make up a rectangle for the line -- don't use constructor as that will allocate as object to be serialized within current project
                DocRectangle fakeRectangle = (DocRectangle)System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(DocRectangle));
                fakeRectangle.X      = docTree.DiagramLine[docTree.DiagramLine.Count - 1].X;
                fakeRectangle.Y      = docTree.DiagramLine[docTree.DiagramLine.Count - 1].Y;
                fakeRectangle.Width  = 0;
                fakeRectangle.Height = 0;

                LayoutLine(fakeRectangle, docDef.DiagramRectangle, docLine.DiagramLine[0], docLine.DiagramLine[1], docLine.DiagramLine[2]);
            }
        }
Exemplo n.º 15
0
        private void CtlExpressG_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != System.Windows.Forms.MouseButtons.Left)
            {
                return;
            }

            bool multi = ((System.Windows.Forms.Control.ModifierKeys & Keys.Control) == Keys.Control);

            this.m_mousedown = true;
            this.m_ptDown    = e.Location;

            if (!multi)
            {
                this.m_multiselect.Clear();
            }

            this.Selection = this.Pick(e.Location, out this.m_lineselection, out this.m_handle);
            UpdateCursor(this.m_handle);

            m_pointmap.Clear();
            if (this.m_selection is DocDefinition)
            {
                DocDefinition docDef = (DocDefinition)this.Selection;
                m_pointmap.Add(docDef, new PointF((float)docDef.DiagramRectangle.X, (float)docDef.DiagramRectangle.Y));
                m_selectionsize = new SizeF((float)docDef.DiagramRectangle.Width, (float)docDef.DiagramRectangle.Height);
            }

            if (multi && this.Selection is DocDefinition)
            {
                DocDefinition docDef = (DocDefinition)this.Selection;
                if (!this.m_multiselect.Contains(docDef))
                {
                    this.m_multiselect.Add(docDef);
                }
            }

            this.Invalidate();
        }
Exemplo n.º 16
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);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        private void dataGridViewConceptRules_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex < 0 || e.ColumnIndex < 0)
            {
                return;
            }

            // for button types, launch dialog
            DataGridViewCell cell      = this.dataGridViewConceptRules.Rows[e.RowIndex].Cells[e.ColumnIndex];
            DocDefinition    docEntity = cell.Tag as DocDefinition;

            if (docEntity == null)
            {
                return;
            }

            DocDefinition docSelect = null;

            if (cell.Value != null && this.m_map.ContainsKey(cell.Value.ToString()))
            {
                docSelect = this.m_map[cell.Value.ToString()] as DocDefinition;
            }

            if (docEntity.Name != null && docEntity.Name.Equals("IfcReference"))
            {
                DocDefinition docDef = this.m_conceptroot.ApplicableEntity as DocDefinition;

                // special case for building reference paths
                using (FormReference form = new FormReference(this.m_project, docDef, this.m_map, cell.Value as string))
                {
                    DialogResult res = form.ShowDialog(this);
                    if (res == System.Windows.Forms.DialogResult.OK)
                    {
                        if (form.ValuePath != null && form.ValuePath.StartsWith("\\"))
                        {
                            cell.Value = form.ValuePath.Substring(1);
                        }
                        else if (form.ValuePath == "")
                        {
                            cell.Value = String.Empty;// "\\";
                        }
                        dataGridViewConceptRules_CellValidated(this, e);
                        this.dataGridViewConceptRules.NotifyCurrentCellDirty(true);
                    }
                }
            }
            else
            {
                // new: if a referenced concept template applies, then edit that; otherwise, edit type

                // get the model view

                DocTemplateDefinition docTemplateInner = null;
                DocModelRule          docRule          = this.m_columns[e.ColumnIndex];
                if (docRule is DocModelRuleAttribute)
                {
                    DocModelRuleAttribute dma = (DocModelRuleAttribute)docRule;
                    if (dma.Rules.Count > 0 && dma.Rules[0] is DocModelRuleEntity)
                    {
                        DocModelRuleEntity dme = (DocModelRuleEntity)dma.Rules[0];
                        if (dme.References.Count == 1)
                        {
                            docTemplateInner = dme.References[0];

                            if (dma.Rules.Count > 1)
                            {
                                // prompt user to select which template...
                            }
                        }
                    }
                }

                if (docTemplateInner != null)
                {
                    DocTemplateItem docConceptItem = (DocTemplateItem)this.dataGridViewConceptRules.Rows[e.RowIndex].Tag;
                    if (docConceptItem != null)
                    {
                        DocTemplateUsage docConceptInner = docConceptItem.RegisterParameterConcept(docRule.Identification, docTemplateInner);

                        using (FormParameters form = new FormParameters())
                        {
                            form.Project         = this.m_project;
                            form.ConceptRoot     = this.m_conceptroot;
                            form.ConceptItem     = docConceptItem;
                            form.ConceptLeaf     = docConceptInner;
                            form.CurrentInstance = this.m_instance;
                            form.ShowDialog(this);
                        }
                    }
                }
                else
                {
                    // set type of item
                    using (FormSelectEntity form = new FormSelectEntity(docEntity, docSelect, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type))
                    {
                        DialogResult res = form.ShowDialog(this);
                        if (res == DialogResult.OK && form.SelectedEntity != null)
                        {
                            cell.Value = form.SelectedEntity.Name;
                            this.dataGridViewConceptRules.NotifyCurrentCellDirty(true);
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
        public void Save()
        {
            string dirpath = System.IO.Path.GetDirectoryName(this.m_filename);

            if (!System.IO.Directory.Exists(this.m_filename))
            {
                System.IO.Directory.CreateDirectory(dirpath);
            }

            using (System.IO.StreamWriter writer = new System.IO.StreamWriter(this.m_filename))
            {
                writer.WriteLine("// This file was automatically generated from IFCDOC at www.buildingsmart-tech.org.");
                writer.WriteLine("// IFC content is copyright (C) 1996-2013 BuildingSMART International Ltd.");
                writer.WriteLine();

                if (this.m_definition != null)
                {
                    writer.WriteLine("package buildingsmart.ifc");
                    writer.WriteLine("{");

                    if (this.m_definition is DocDefined)
                    {
                        // do nothing - don't make a separate type in Java, as that would require extra heap allocation
                    }
                    else if (this.m_definition is DocSelect)
                    {
                        writer.WriteLine("\tpublic interface " + this.m_definition.Name);
                        writer.WriteLine("\t{");
                        writer.WriteLine("\t}");
                    }
                    else if (this.m_definition is DocEnumeration)
                    {
                        DocEnumeration docEnumumeration = (DocEnumeration)this.m_definition;

                        writer.WriteLine("\tpublic enum " + this.m_definition.Name);
                        writer.WriteLine("\t{");
                        foreach (DocConstant docConstant in docEnumumeration.Constants)
                        {
                            writer.WriteLine("\t\t" + docConstant.Name + ",");
                        }
                        writer.WriteLine("\t}");
                    }
                    else if (this.m_definition is DocEntity)
                    {
                        DocEntity docEntity = (DocEntity)this.m_definition;

                        string basedef = docEntity.BaseDefinition;
                        if (String.IsNullOrEmpty(basedef))
                        {
                            basedef = "IfcBase";
                        }

                        writer.WriteLine("\tpublic class " + this.m_definition.Name + " extends " + basedef);
                        writer.WriteLine("\t{");

                        // fields
                        foreach (DocAttribute docAttribute in docEntity.Attributes)
                        {
                            string deftype = docAttribute.DefinedType;

                            // if defined type, use raw type (avoiding extra memory allocation)
                            DocDefinition docDef = GetDefinition(deftype);
                            if (docDef is DocDefined)
                            {
                                deftype = ((DocDefined)docDef).DefinedType;

                                switch (deftype)
                                {
                                case "STRING":
                                    deftype = "string";
                                    break;

                                case "INTEGER":
                                    deftype = "int";
                                    break;

                                case "REAL":
                                    deftype = "double";
                                    break;

                                case "BOOLEAN":
                                    deftype = "bool";
                                    break;

                                case "LOGICAL":
                                    deftype = "int";
                                    break;

                                case "BINARY":
                                    deftype = "byte[]";
                                    break;
                                }
                            }

                            switch (docAttribute.GetAggregation())
                            {
                            case DocAggregationEnum.SET:
                                writer.WriteLine("\t\tprivate " + deftype + "[] " + docAttribute.Name + ";");
                                break;

                            case DocAggregationEnum.LIST:
                                writer.WriteLine("\t\tprivate " + deftype + "[] " + docAttribute.Name + ";");
                                break;

                            default:
                                writer.WriteLine("\t\tprivate " + deftype + " " + docAttribute.Name + ";");
                                break;
                            }
                        }

                        writer.WriteLine("\t}");
                    }

                    writer.WriteLine("}");
                }
                else
                {
#if false // TBD
                    writer.WriteLine("package buildingsmart.ifc.properties");
                    writer.WriteLine("{");
                    writer.WriteLine();

                    Dictionary <string, string[]> mapEnums = new Dictionary <string, string[]>();

                    foreach (DocSection docSection in this.m_project.Sections)
                    {
                        foreach (DocSchema docSchema in docSection.Schemas)
                        {
                            foreach (DocPropertySet docPset in docSchema.PropertySets)
                            {
                                writer.WriteLine("    /// <summary>");
                                writer.WriteLine("    /// " + docPset.Documentation.Replace('\r', ' ').Replace('\n', ' '));
                                writer.WriteLine("    /// </summary>");

                                writer.WriteLine("    public class " + docPset.Name + " : Pset");
                                writer.WriteLine("    {");

                                foreach (DocProperty docProperty in docPset.Properties)
                                {
                                    writer.WriteLine("        /// <summary>");
                                    writer.WriteLine("        /// " + docProperty.Documentation.Replace('\r', ' ').Replace('\n', ' '));
                                    writer.WriteLine("        /// </summary>");

                                    switch (docProperty.PropertyType)
                                    {
                                    case DocPropertyTemplateTypeEnum.P_SINGLEVALUE:
                                        writer.WriteLine("        public " + docProperty.PrimaryDataType + " " + docProperty.Name + " { get { return this.GetValue<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\"); } set { this.SetValue<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\", value); } }");
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE:
                                        // record enum for later
                                    {
                                        string[] parts = docProperty.SecondaryDataType.Split(':');
                                        if (parts.Length == 2)
                                        {
                                            string typename = parts[0];
                                            if (!mapEnums.ContainsKey(typename))
                                            {
                                                string[] enums = parts[1].Split(',');
                                                mapEnums.Add(typename, enums);

                                                writer.WriteLine("        public " + typename + " " + docProperty.Name + " { get { return this.GetValue<" + typename + ">(\"" + docProperty.Name + "\"); } set { this.SetValue<" + typename + ">(\"" + docProperty.Name + "\", value); } }");
                                            }
                                        }
                                    }
                                    break;

                                    case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE:
                                        writer.WriteLine("        public PBound<" + docProperty.PrimaryDataType + "> " + docProperty.Name + " { get { return this.GetBound<" + docProperty.PrimaryDataType + ">(\"" + docProperty.Name + "\"); } }");
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_LISTVALUE:
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_TABLEVALUE:
                                        writer.WriteLine("        public PTable<" + docProperty.PrimaryDataType + ", " + docProperty.SecondaryDataType + "> " + docProperty.Name + " { get { return this.GetTable<" + docProperty.PrimaryDataType + ", " + docProperty.SecondaryDataType + ">(\"" + docProperty.Name + "\"); } }");
                                        break;

                                    case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE:
                                        if (docProperty.PrimaryDataType.Equals("IfcTimeSeries"))
                                        {
                                            string datatype = docProperty.SecondaryDataType;
                                            if (String.IsNullOrEmpty(datatype))
                                            {
                                                datatype = "IfcReal";
                                            }
                                            writer.WriteLine("        public PTimeSeries<" + datatype + "> " + docProperty.Name + " { get { return this.GetTimeSeries<" + datatype + ">(\"" + docProperty.Name + "\"); } }");
                                        }
                                        // ... TBD
                                        break;

                                    case DocPropertyTemplateTypeEnum.COMPLEX:
                                        //... TBD
                                        break;
                                    }
                                }

                                writer.WriteLine("    }");
                                writer.WriteLine();
                            }
                        }
                    }

                    // enums
                    foreach (string strEnum in mapEnums.Keys)
                    {
                        string[] enums = mapEnums[strEnum];

                        writer.WriteLine("    /// <summary>");
                        writer.WriteLine("    /// </summary>");
                        writer.WriteLine("    public enum " + strEnum);
                        writer.WriteLine("    {");

                        int counter = 0;
                        foreach (string val in enums)
                        {
                            int    num = 0;
                            string id  = val.ToUpper().Trim('.').Replace('-', '_');
                            switch (id)
                            {
                            case "OTHER":
                                num = -1;
                                break;

                            case "NOTKNOWN":
                                num = -2;
                                break;

                            case "UNSET":
                                num = 0;
                                break;

                            default:
                                counter++;
                                num = counter;
                                break;
                            }

                            if (id[0] >= '0' && id[0] <= '9')
                            {
                                id = "_" + id; // avoid numbers
                            }

                            writer.WriteLine("        /// <summary></summary>");
                            writer.WriteLine("        " + id + " = " + num + ",");
                        }

                        writer.WriteLine("    }");
                        writer.WriteLine();
                    }

                    writer.WriteLine("}");
#endif
                }
            }
        }
Exemplo n.º 19
0
        private DocDefinition CreateLink(DocDefinition target, DocPoint docPoint)
        {
            if (target is DocPageTarget)
            {
                DocPageTarget docPageTarget = (DocPageTarget)target;
                DocPageSource docPageSource = new DocPageSource();
                docPageTarget.Sources.Add(docPageSource);

                //docPageSource.Target = docPageTarget;
                docPageSource.DiagramRectangle = new DocRectangle();
                docPageSource.DiagramRectangle.X = docPoint.X + 400.0;
                docPageSource.DiagramRectangle.Y = docPoint.Y;
                docPageSource.DiagramRectangle.Width = 400.0;
                docPageSource.DiagramRectangle.Height = 100.0;

                int px = (int)(docPageSource.DiagramRectangle.X / CtlExpressG.PageX);
                int py = (int)(docPageSource.DiagramRectangle.Y / CtlExpressG.PageY);
                int page = 1 + py * this.ctlExpressG.Schema.DiagramPagesHorz + px;
                docPageSource.DiagramNumber = page;

                return docPageSource;
            }
            else
            {
                return target;
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Updates any connected geometry to match definition
        /// </summary>
        /// <param name="docDef"></param>
        public void LayoutDefinition(DocDefinition selection)
        {
            // then traverse all dependencies on selection
            if (selection is DocEntity)
            {
                DocEntity docEntity = (DocEntity)selection;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine);
                    if (docAttr.DiagramLabel != null)
                    {
                        docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                        docAttr.DiagramLabel.Y = docAttr.DiagramLine[2].Y - 20.0;
                    }
                }

                foreach (DocLine docLine in docEntity.Tree)
                {
                    LayoutTree(docEntity, docLine);
                }
            }
            else if (selection is DocDefinitionRef)
            {
                DocDefinitionRef docRef = (DocDefinitionRef)selection;
                foreach (DocLine docLine in docRef.Tree)
                {
                    LayoutTree(docRef, docLine);
                }
            }
            else if (selection is DocDefined)
            {
                DocDefined docDef = (DocDefined)selection;
                LayoutLine(docDef, docDef.Definition, docDef.DiagramLine);
            }
            else if (selection is DocSelect)
            {
                DocSelect docSelect = (DocSelect)selection;
                foreach (DocLine docLine in docSelect.Tree)
                {
                    LayoutTree(docSelect, docLine);
                }
            }
            else if (selection is DocPageTarget)
            {
                DocPageTarget docTarget = (DocPageTarget)selection;
                LayoutLine(docTarget.Definition, docTarget, docTarget.DiagramLine);
                docTarget.DiagramLine.Reverse();
            }

            foreach (DocPageTarget docPageTarget in this.m_schema.PageTargets)
            {
                if (docPageTarget.Definition == selection)
                {
                    LayoutLine(docPageTarget.Definition, docPageTarget, docPageTarget.DiagramLine);
                    docPageTarget.DiagramLine.Reverse();
                }
            }

            foreach (DocSchemaRef docSchemaRef in this.m_schema.SchemaRefs)
            {
                foreach (DocDefinitionRef docDefRef in docSchemaRef.Definitions)
                {
                    foreach (DocLine docLine in docDefRef.Tree)
                    {
                        if (docLine.Definition == selection)
                        {
                            LayoutLine(docDefRef, docLine.Definition, docLine.DiagramLine);
                        }
                        else
                        {
                            foreach (DocLine docSub in docLine.Tree)
                            {
                                if (docSub.Definition == selection)
                                {
                                    LayoutNode(docLine, docSub);
                                }
                            }
                        }
                    }
                }
            }

            foreach (DocEntity docEntity in this.m_schema.Entities)
            {
                // if there multile attributes refer to the same definition, then space evenly
                int count = 0;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    if (docAttr.Definition == selection)
                    {
                        count++;
                    }
                }

                int each = 0;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    if (docAttr.Definition == selection)
                    {
                        LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine);
                        if (count > 1 && docAttr.DiagramLine.Count == 3)
                        {
                            each++;
                            docAttr.DiagramLine[0].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count + 1));
                            docAttr.DiagramLine[1].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count + 1));
                            docAttr.DiagramLine[2].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count + 1));
                        }

                        if (docAttr.DiagramLabel == null)
                        {
                            docAttr.DiagramLabel = new DocRectangle();
                        }
                        docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                        docAttr.DiagramLabel.Y = docAttr.DiagramLine[2].Y - 20.0;
                    }
                }

                foreach (DocLine docLine in docEntity.Tree)
                {
                    if (docLine.Definition == selection)
                    {
                        LayoutLine(docEntity, docLine.Definition, docLine.DiagramLine);
                    }
                    else
                    {
                        foreach (DocLine docSub in docLine.Tree)
                        {
                            if (docSub.Definition == selection)
                            {
                                LayoutNode(docLine, docSub);
                            }
                        }
                    }
                }
            }

            foreach (DocType docType in this.m_schema.Types)
            {
                if (docType is DocDefined)
                {
                    DocDefined docDef = (DocDefined)docType;
                    if (docDef.Definition == selection)
                    {
                        LayoutLine(docDef, docDef.Definition, docDef.DiagramLine);
                    }
                }
                else if (docType is DocSelect)
                {
                    DocSelect docSel = (DocSelect)docType;
                    foreach (DocLine docLine in docSel.Tree)
                    {
                        if (docLine.Definition == selection)
                        {
                            LayoutLine(docSel, selection, docLine.DiagramLine);
                        }

                        foreach (DocLine docSub in docLine.Tree)
                        {
                            if (docSub.Definition == selection)
                            {
                                LayoutNode(docLine, docSub);
                            }
                        }
                    }
                }
            }

            // recalculate page extents and resize/repaginate if necessary
            double cx = 0.0;
            double cy = 0.0;

            foreach (DocType docDef in this.m_schema.Types)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocEntity docDef in this.m_schema.Entities)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocPrimitive docDef in this.m_schema.Primitives)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocPageTarget docDef in this.m_schema.PageTargets)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
                foreach (DocPageSource docSource in docDef.Sources)
                {
                    ExpandExtents(docSource.DiagramRectangle, ref cx, ref cy);
                }
            }
            foreach (DocSchemaRef docRef in this.m_schema.SchemaRefs)
            {
                foreach (DocDefinitionRef docDef in docRef.Definitions)
                {
                    ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
                }
            }
            foreach (DocComment docDef in this.m_schema.Comments)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            this.m_schema.DiagramPagesHorz = 1 + (int)Math.Floor(cx * Factor / PageX);
            this.m_schema.DiagramPagesVert = 1 + (int)Math.Floor(cy * Factor / PageY);
        }
Exemplo n.º 21
0
        private void SelectWithinRectangle(DocDefinition def, Rectangle rc)
        {
            if (def.DiagramRectangle == null)
                return;

            Rectangle rcObject = new Rectangle(
                (int)(def.DiagramRectangle.X * Factor) + this.AutoScrollPosition.X,
                (int)(def.DiagramRectangle.Y * Factor) + this.AutoScrollPosition.Y,
                (int)(def.DiagramRectangle.Width * Factor),
                (int)(def.DiagramRectangle.Height * Factor));

            if(rc.IntersectsWith(rcObject))
            {
                this.m_multiselect.Add(def);
            }
        }
Exemplo n.º 22
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
                    {
                    }
                }
            }
        }
Exemplo n.º 23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="basetype">DocEntity or DocSelect.</param>
        /// <param name="selection"></param>
        /// <param name="project"></param>
        /// <param name="predefined">Select predefined type.</param>
        public FormSelectEntity(
            DocDefinition basetype,
            DocDefinition selection,
            DocProject project,
            SelectDefinitionOptions options)
            : this()
        {
            this.m_basetype  = basetype;
            this.m_selection = selection;
            this.m_project   = project;
            this.m_options   = options;

            this.m_mapAlpha   = new Dictionary <DocDefinition, TreeNode>();
            this.m_mapInherit = new Dictionary <DocDefinition, TreeNode>();

            // load subtypes, sort alphabetically
            if (this.m_basetype is DocEntity)
            {
                this.LoadEntity(null, (DocEntity)this.m_basetype);
                this.tabControl1.TabPages.RemoveAt(1);
            }
            else if (this.m_basetype is DocSelect)
            {
                this.LoadSelect(null, (DocSelect)this.m_basetype);
                this.tabControl1.TabPages.RemoveAt(1);
            }
            else if (this.m_basetype != null)
            {
                // add single node for type
                TreeNode tn = new TreeNode();
                tn.Tag  = basetype;
                tn.Text = basetype.Name;
                this.treeViewInheritance.Nodes.Add(tn);

                this.tabControl1.TabPages.RemoveAt(1);
            }
            else
            {
                // all entities
                SortedList <string, DocDefinition> sort    = new SortedList <string, DocDefinition>();
                SortedList <string, DocDefinition> sortAll = new SortedList <string, DocDefinition>();
                foreach (DocSection docSection in this.m_project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        foreach (DocEntity docEntity in docSchema.Entities)
                        {
                            if (docEntity.BaseDefinition == null)
                            {
                                if (!sort.ContainsKey(docEntity.Name))
                                {
                                    sort.Add(docEntity.Name, docEntity);
                                }
                            }

                            if (!sortAll.ContainsKey(docEntity.Name))
                            {
                                sortAll.Add(docEntity.Name, docEntity);
                            }
                        }

                        if ((options & SelectDefinitionOptions.Type) != 0)
                        {
                            // temp: all types too; todo: specify parameter
                            foreach (DocType docType in docSchema.Types)
                            {
                                sort.Add(docType.Name, docType);

                                if (!sortAll.ContainsKey(docType.Name))
                                {
                                    sortAll.Add(docType.Name, docType);
                                }
                            }
                        }
                    }
                }

                foreach (DocDefinition docDef in sort.Values)
                {
                    if (docDef is DocEntity)
                    {
                        this.LoadEntity(null, (DocEntity)docDef);
                    }
                    else if (docDef is DocType)
                    {
                        this.LoadType(null, (DocType)docDef);
                    }
                }

                foreach (DocDefinition docDef in sortAll.Values)
                {
                    TreeNode tnAlpha = new TreeNode();
                    tnAlpha.Tag  = docDef;
                    tnAlpha.Text = docDef.Name;
                    this.m_mapAlpha.Add(docDef, tnAlpha);
                    this.treeViewAlphabetical.Nodes.Add(tnAlpha);
                }
            }

            if (this.treeViewInheritance.SelectedNode == null && this.treeViewInheritance.Nodes.Count > 0)
            {
                this.treeViewInheritance.SelectedNode = this.treeViewInheritance.Nodes[0];
            }

            this.treeViewInheritance.ExpandAll();
            this.treeViewInheritance.Focus();
        }
Exemplo n.º 24
0
        private g SaveDefinition(DocObject docObj, string displayname)
        {
            g group = new g();

            group.id = docObj.Name;

            DocDefinition docDef = docObj as DocDefinition;

            if (docDef == null || docDef.DiagramRectangle == null)
            {
                return(group);
            }

            double x  = docDef.DiagramRectangle.X * CtlExpressG.Factor;
            double y  = docDef.DiagramRectangle.Y * CtlExpressG.Factor;
            double cx = docDef.DiagramRectangle.Width * CtlExpressG.Factor;
            double cy = docDef.DiagramRectangle.Height * CtlExpressG.Factor;

            rect r = new rect();

            r.x      = x.ToString();
            r.y      = y.ToString();
            r.width  = cx.ToString();
            r.height = cy.ToString();
            r.stroke = "black";
            group.rect.Add(r);

            text t = new text();

            t.x    = (x + cx * 0.5).ToString();
            t.y    = (y + cy * 0.5).ToString();
            t.fill = "black";
            t.alignment_baseline = "middle";
            t.text_anchor        = "middle";
            t.font_size          = "10";
            t.font_family        = "Arial, Helvetica, sans-serif";
            if (displayname != null)
            {
                t.value = displayname;
            }
            else
            {
                t.value = docDef.Name;
            }
            group.text.Add(t);

            if (docDef is DocEntity)
            {
                group.fill = "yellow";
            }
            else if (docDef is DocType)
            {
                group.fill = "green";
            }
            else if (docDef is DocPageTarget)
            {
                group.fill = "blue";
                r.rx       = "10";
                r.ry       = "10";
            }
            else if (docDef is DocPageSource)
            {
                group.fill = "silver";
                r.rx       = "10";
                r.ry       = "10";
            }
            else
            {
                group.fill = "grey";
            }

            return(group);
        }
Exemplo n.º 25
0
        public Compiler(DocProject project, DocModelView[] views, DocExchangeDefinition exchange, bool psets)
        {
            this.m_project  = project;
            this.m_views    = views;
            this.m_exchange = exchange;
            this.m_psets    = psets;

            // version needs to be included for extracting XML namespace (Major.Minor.Addendum.Corrigendum)
            string                 version            = project.GetSchemaVersion();
            ConstructorInfo        conContract        = (typeof(AssemblyVersionAttribute).GetConstructor(new Type[] { typeof(string) }));
            CustomAttributeBuilder cabAssemblyVersion = new CustomAttributeBuilder(conContract, new object[] { version });

            string schemaid = project.GetSchemaIdentifier();
            string assembly = "buildingSmart." + schemaid;
            string module   = assembly + ".dll";

            this.m_rootnamespace = assembly + ".";

            this.m_assembly    = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(assembly), AssemblyBuilderAccess.RunAndSave, new CustomAttributeBuilder[] { cabAssemblyVersion });
            this.m_module      = this.m_assembly.DefineDynamicModule(module, module);
            this.m_definitions = new Dictionary <string, DocObject>();
            this.m_types       = new Dictionary <string, Type>();
            this.m_fields      = new Dictionary <Type, Dictionary <string, FieldInfo> >();
            this.m_templates   = new Dictionary <DocTemplateDefinition, MethodInfo>();
            this.m_namespaces  = new Dictionary <string, string>();

            Dictionary <DocObject, bool> included = null;

            if (this.m_views != null)
            {
                included = new Dictionary <DocObject, bool>();
                foreach (DocModelView docView in this.m_views)
                {
                    this.m_project.RegisterObjectsInScope(docView, included);
                }
            }
            if (psets)
            {
                foreach (DocPropertyEnumeration docPropEnum in project.PropertyEnumerations)
                {
                    DocEnumeration docType = docPropEnum.ToEnumeration();
                    if (!this.m_definitions.ContainsKey(docType.Name))
                    {
                        this.m_definitions.Add(docType.Name, docType);
                    }
                }
            }

            foreach (DocSection docSection in project.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        if (included == null || included.ContainsKey(docEntity))
                        {
                            if (!this.m_definitions.ContainsKey(docEntity.Name))
                            {
                                this.m_definitions.Add(docEntity.Name, docEntity);
                                this.m_namespaces.Add(docEntity.Name, docSchema.Name);
                            }
                        }
                    }

                    foreach (DocType docType in docSchema.Types)
                    {
                        if (included == null || included.ContainsKey(docType))
                        {
                            if (!this.m_definitions.ContainsKey(docType.Name))
                            {
                                this.m_definitions.Add(docType.Name, docType);
                                this.m_namespaces.Add(docType.Name, docSchema.Name);
                            }
                        }
                    }
                }
            }

            // second pass:
            if (psets)
            {
                foreach (DocSection docSection in project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        foreach (DocPropertySet docPset in docSchema.PropertySets)
                        {
                            DocEntity docType = docPset.ToEntity(this.m_definitions);
                            if (!this.m_definitions.ContainsKey(docType.Name))
                            {
                                this.m_definitions.Add(docType.Name, docType);
                                this.m_namespaces.Add(docType.Name, docSchema.Name);
                            }
                        }

                        foreach (DocQuantitySet docQset in docSchema.QuantitySets)
                        {
                            DocEntity docType = docQset.ToEntity(this.m_definitions);
                            if (!this.m_definitions.ContainsKey(docType.Name))
                            {
                                this.m_definitions.Add(docType.Name, docType);
                                this.m_namespaces.Add(docType.Name, docSchema.Name);
                            }
                        }
                    }
                }
            }

            // first register types and fields
            foreach (string key in this.m_definitions.Keys)
            {
                Type typereg = RegisterType(key);

                // localization -- use custom attributes for now -- ideal way would be to use assembly resources, though has bugs in .net 4.0
                if (typereg is TypeBuilder)
                {
                    TypeBuilder tb = (TypeBuilder)typereg;

                    DocObject docObj = this.m_definitions[key];
                    foreach (DocLocalization docLocal in docObj.Localization)
                    {
                        CustomAttributeBuilder cab = docLocal.ToCustomAttributeBuilder();
                        if (cab != null)
                        {
                            tb.SetCustomAttribute(cab);
                        }
                    }
                }
            }

            // now register template functions (may depend on fields existing)

            // find associated ConceptRoot for model view, define validation function
            if (this.m_views != null)
            {
                foreach (DocModelView view in this.m_views)
                {
                    string viewname = view.Code;
                    foreach (DocConceptRoot root in view.ConceptRoots)
                    {
                        Type tOpen = null;

                        if (this.m_types.TryGetValue(root.ApplicableEntity.Name, out tOpen) && tOpen is TypeBuilder)
                        {
                            TypeBuilder tb = (TypeBuilder)tOpen;


                            // new: generate type for concept root
                            //if (view.Name != null && root.Name != null)
                            {
                                /*
                                 * string typename = this.m_rootnamespace + "." + view.Name.Replace(" ", "_") + "." + root.Name.Replace(" ", "_");
                                 * //Type tbConceptRoot = RegisterType(typename);
                                 * TypeBuilder tbRoot = this.m_module.DefineType(typename, attr, typebase);
                                 */

                                // add typebuilder to map temporarily in case referenced by an attribute within same class or base class
                                //this.m_types.Add(typename, tb);

                                foreach (DocTemplateUsage concept in root.Concepts)
                                {
                                    CompileConcept(concept, view, tb);
                                }
                            }
                        }
                    }
                }
            }

            //Dictionary<string, Stream> mapResStreams = new Dictionary<string, Stream>();
            //Dictionary<string, ResXResourceWriter> mapResources = new Dictionary<string, ResXResourceWriter>();

            // seal types once all are built
            List <TypeBuilder> listBase = new List <TypeBuilder>();

            foreach (string key in this.m_definitions.Keys)
            {
                Type tOpen = this.m_types[key];
                while (tOpen is TypeBuilder)
                {
                    listBase.Add((TypeBuilder)tOpen);
                    tOpen = tOpen.BaseType;
                }

                // seal in base class order
                for (int i = listBase.Count - 1; i >= 0; i--)
                {
                    Type tClosed = listBase[i].CreateType();
                    this.m_types[tClosed.Name] = tClosed;
                }
                listBase.Clear();


                // record bindings
                DocDefinition docDef = this.m_definitions[key] as DocDefinition;
                if (docDef != null)
                {
                    docDef.RuntimeType = this.m_types[key];

                    if (docDef is DocEntity)
                    {
                        DocEntity docEnt = (DocEntity)docDef;
                        foreach (DocAttribute docAttr in docEnt.Attributes)
                        {
                            docAttr.RuntimeField = docDef.RuntimeType.GetProperty(docAttr.Name);
                        }
                    }

#if false // bug in .net framework 4.0+ -- can't read resources dynamically defined
                    // capture localization
                    foreach (DocLocalization docLocal in docDef.Localization)
                    {
                        if (!String.IsNullOrEmpty(docLocal.Locale))
                        {
                            string major = docLocal.Locale.Substring(0, 2).ToLower();

                            ResXResourceWriter reswriter = null;
                            if (!mapResources.TryGetValue(major, out reswriter))
                            {
                                MemoryStream stream = new MemoryStream();
                                mapResStreams.Add(major, stream);

                                reswriter = new ResXResourceWriter(stream);
                                mapResources.Add(major, reswriter);
                            }

                            ResXDataNode node = new ResXDataNode(docDef.Name, docLocal.Name);
                            node.Comment = docLocal.Documentation;
                            reswriter.AddResource(node);
                        }
                    }
#endif
                }
            }

#if false
            foreach (string locale in mapResStreams.Keys)
            {
                ResXResourceWriter writer = mapResources[locale];
                writer.Generate();
                Stream stream = mapResStreams[locale];
                stream.Seek(0, SeekOrigin.Begin);
                m_module.DefineManifestResource("Resources." + locale + ".resx", stream, ResourceAttributes.Public);
            }
#endif
        }
Exemplo n.º 26
0
        public Compiler(DocProject project, DocModelView[] views, DocExchangeDefinition exchange)
        {
            this.m_project  = project;
            this.m_views    = views;
            this.m_exchange = exchange;

            string schemaid = project.GetSchemaIdentifier();

            this.m_assembly    = AppDomain.CurrentDomain.DefineDynamicAssembly(new AssemblyName(schemaid), AssemblyBuilderAccess.RunAndSave);
            this.m_module      = this.m_assembly.DefineDynamicModule("IFC4.dll", "IFC4.dll");
            this.m_definitions = new Dictionary <string, DocObject>();
            this.m_types       = new Dictionary <string, Type>();
            this.m_fields      = new Dictionary <Type, Dictionary <string, FieldInfo> >();
            this.m_templates   = new Dictionary <DocTemplateDefinition, MethodInfo>();
            this.m_namespaces  = new Dictionary <string, string>();

            Dictionary <DocObject, bool> included = null;

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

            foreach (DocSection docSection in project.Sections)
            {
                foreach (DocSchema docSchema in docSection.Schemas)
                {
                    foreach (DocEntity docEntity in docSchema.Entities)
                    {
                        if (included == null || included.ContainsKey(docEntity))
                        {
                            if (!this.m_definitions.ContainsKey(docEntity.Name))
                            {
                                this.m_definitions.Add(docEntity.Name, docEntity);
                                this.m_namespaces.Add(docEntity.Name, docSchema.Name);
                            }
                        }
                    }

                    foreach (DocType docType in docSchema.Types)
                    {
                        if (included == null || included.ContainsKey(docType))
                        {
                            if (!this.m_definitions.ContainsKey(docType.Name))
                            {
                                this.m_definitions.Add(docType.Name, docType);
                                this.m_namespaces.Add(docType.Name, docSchema.Name);
                            }
                        }
                    }
                }
            }

            // first register types and fields
            foreach (string key in this.m_definitions.Keys)
            {
                RegisterType(key);
            }

            // now register template functions (may depend on fields existing)

            // find associated ConceptRoot for model view, define validation function
            if (this.m_views != null)
            {
                foreach (DocModelView view in this.m_views)
                {
                    string viewname = view.Code;
                    foreach (DocConceptRoot root in view.ConceptRoots)
                    {
                        Type tOpen = null;

                        if (this.m_types.TryGetValue(root.ApplicableEntity.Name, out tOpen) && tOpen is TypeBuilder)
                        {
                            TypeBuilder tb = (TypeBuilder)tOpen;
                            foreach (DocTemplateUsage concept in root.Concepts)
                            {
                                CompileConcept(concept, view, tb);
                            }
                        }
                    }
                }
            }



            // seal types once all are built
            List <TypeBuilder> listBase = new List <TypeBuilder>();

            foreach (string key in this.m_definitions.Keys)
            {
                Type tOpen = this.m_types[key];
                while (tOpen is TypeBuilder)
                {
                    listBase.Add((TypeBuilder)tOpen);
                    tOpen = tOpen.BaseType;
                }

                // seal in base class order
                for (int i = listBase.Count - 1; i >= 0; i--)
                {
                    Type tClosed = listBase[i].CreateType();
                    this.m_types[tClosed.Name] = tClosed;
                }
                listBase.Clear();


                // record bindings
                DocDefinition docDef = this.m_definitions[key] as DocDefinition;
                if (docDef != null)
                {
                    docDef.RuntimeType = this.m_types[key];

                    if (docDef is DocEntity)
                    {
                        DocEntity docEnt = (DocEntity)docDef;
                        foreach (DocAttribute docAttr in docEnt.Attributes)
                        {
                            docAttr.RuntimeField = docDef.RuntimeType.GetField(docAttr.Name);
                        }
                    }
                }
            }
        }
Exemplo n.º 27
0
        private void CtlExpressG_MouseMove(object sender, MouseEventArgs e)
        {
            this.m_ptMove = e.Location;

            if (this.m_mousedown && this.m_toolmode == ToolMode.Move)
            {
                UpdateCursor(this.m_handle);

                Point ptLocation = e.Location;
                if (ptLocation.X < 0)
                {
                    ptLocation.X = 0;
                }
                if (ptLocation.Y < 0)
                {
                    ptLocation.Y = 0;
                }

                if (this.m_lineselection != null && this.m_selection is DocDefinition)
                {
                    // moving tree node
                    DocPoint docPoint = m_lineselection.DiagramLine[m_lineselection.DiagramLine.Count - 1];
                    docPoint.X = (ptLocation.X - this.AutoScrollPosition.X) / Factor;
                    docPoint.Y = (ptLocation.Y - this.AutoScrollPosition.Y) / Factor;

                    // layout the owning element
                    LayoutDefinition((DocDefinition)this.m_selection);

                    // layout lines to all subtypes
                    foreach (DocLine docSub in this.m_lineselection.Tree)
                    {
                        LayoutNode(this.m_lineselection, docSub);
                    }

                    this.Redraw();
                }
                else if (this.m_selection is DocDefinition)
                {
                    float dx = (float)(ptLocation.X - this.m_ptDown.X);
                    float dy = (float)(ptLocation.Y - this.m_ptDown.Y);

                    // move or resize the object...
                    DocDefinition docSelection = (DocDefinition)this.m_selection;
                    if (this.m_pointmap.ContainsKey(docSelection))
                    {
                        PointF ptSelection = this.m_pointmap[docSelection];

                        if ((this.m_handle & ResizeHandle.North) != 0)
                        {
                            double yTail = docSelection.DiagramRectangle.Y + docSelection.DiagramRectangle.Height;
                            docSelection.DiagramRectangle.Y      = ptSelection.Y + dy / Factor;
                            docSelection.DiagramRectangle.Height = yTail - docSelection.DiagramRectangle.Y;
                        }
                        else if ((this.m_handle & ResizeHandle.South) != 0)
                        {
                            docSelection.DiagramRectangle.Height = m_selectionsize.Height + dy / Factor;
                        }

                        if ((this.m_handle & ResizeHandle.West) != 0)
                        {
                            double xTail = docSelection.DiagramRectangle.X + docSelection.DiagramRectangle.Width;
                            docSelection.DiagramRectangle.X     = ptSelection.X + dx / Factor;
                            docSelection.DiagramRectangle.Width = xTail - docSelection.DiagramRectangle.X;
                        }
                        else if ((this.m_handle & ResizeHandle.East) != 0)
                        {
                            docSelection.DiagramRectangle.Width = m_selectionsize.Width + dx / Factor;
                        }

                        if (this.m_handle == ResizeHandle.Move)
                        {
                            docSelection.DiagramRectangle.X = ptSelection.X + dx / Factor;
                            docSelection.DiagramRectangle.Y = ptSelection.Y + dy / Factor;
                        }

                        if (this.m_selection is DocDefinition)
                        {
                            LayoutDefinition((DocDefinition)this.m_selection);
                        }
                    }

                    this.Redraw();
                }
                else if (this.m_selection == null)
                {
                    // draw box and highlight multiple within region
                    this.m_multiselect.Clear();
                    Rectangle rc = CreateNormalizedRectangle(this.m_ptDown, this.m_ptMove);
                    foreach (DocEntity docEntity in this.m_schema.Entities)
                    {
                        SelectWithinRectangle(docEntity, rc);
                    }
                    foreach (DocType docType in this.m_schema.Types)
                    {
                        SelectWithinRectangle(docType, rc);
                    }
                    foreach (DocPrimitive docType in this.m_schema.Primitives)
                    {
                        SelectWithinRectangle(docType, rc);
                    }
                    foreach (DocPageTarget docTarget in this.m_schema.PageTargets)
                    {
                        SelectWithinRectangle(docTarget, rc);
                        foreach (DocPageSource docSource in docTarget.Sources)
                        {
                            SelectWithinRectangle(docSource, rc);
                        }
                    }
                    foreach (DocSchemaRef docSchemaRef in this.m_schema.SchemaRefs)
                    {
                        foreach (DocDefinitionRef docRef in docSchemaRef.Definitions)
                        {
                            SelectWithinRectangle(docRef, rc);
                        }
                    }
                    // don't select comments

                    this.Invalidate();
                }
            }
            else
            {
                ResizeHandle handle    = ResizeHandle.None;
                DocObject    highlight = this.Pick(e.Location, out this.m_linehighlight, out handle);
                if (this.m_highlight != highlight)
                {
                    this.m_highlight = highlight;
                    this.Invalidate();
                }

                if (this.m_mousedown && this.m_toolmode == ToolMode.Link)
                {
                    this.Invalidate();
                }

                UpdateCursor(handle);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Updates layout of parent end of tree
        /// </summary>
        /// <param name="defA"></param>
        /// <param name="docLine"></param>
        public static void LayoutTree(DocDefinition defA, DocLine docLine)
        {
            if(docLine.Definition != null)
            {
                LayoutLine(defA, docLine.Definition, docLine.DiagramLine);
            }
            else if(docLine.DiagramLine.Count >= 2)
            {
                while (docLine.DiagramLine.Count < 3)
                {
                    docLine.DiagramLine.Insert(1, new DocPoint());
                }

                // shortcut: make up a rectangle for the line -- don't use constructor as that will allocate as object to be serialized within current project
                DocRectangle fakeRectangle = (DocRectangle)System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(DocRectangle));
                fakeRectangle.X = docLine.DiagramLine[docLine.DiagramLine.Count-1].X;
                fakeRectangle.Y = docLine.DiagramLine[docLine.DiagramLine.Count - 1].Y;
                fakeRectangle.Width = 0;
                fakeRectangle.Height = 0;

                LayoutLine(defA.DiagramRectangle, fakeRectangle, docLine.DiagramLine[0], docLine.DiagramLine[1], docLine.DiagramLine[2]);
            }
        }
Exemplo n.º 29
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);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Updates any connected geometry to match definition
        /// </summary>
        /// <param name="docDef"></param>
        public void LayoutDefinition(DocDefinition selection)
        {
            // then traverse all dependencies on selection
            if (selection is DocEntity)
            {
                DocEntity docEntity = (DocEntity)selection;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine);
                    if (docAttr.DiagramLabel != null)
                    {
                        if (docAttr.DiagramLine[2].Y > docAttr.DiagramLine[0].Y)
                        {
                            docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                            docAttr.DiagramLabel.Y = docAttr.DiagramLine[0].Y + 20.0;
                        }
                        else
                        {
                            docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                            docAttr.DiagramLabel.Y = docAttr.DiagramLine[0].Y - 20.0;
                        }
                    }
                }

                foreach (DocLine docLine in docEntity.Tree)
                {
                    LayoutTree(docEntity, docLine);
                }
            }
            else if (selection is DocDefinitionRef)
            {
                DocDefinitionRef docRef = (DocDefinitionRef)selection;
                foreach (DocLine docLine in docRef.Tree)
                {
                    LayoutTree(docRef, docLine);
                }
            }
            else if (selection is DocDefined)
            {
                DocDefined docDef = (DocDefined)selection;
                LayoutLine(docDef, docDef.Definition, docDef.DiagramLine);
            }
            else if (selection is DocSelect)
            {
                DocSelect docSelect = (DocSelect)selection;
                foreach (DocLine docLine in docSelect.Tree)
                {
                    LayoutTree(docSelect, docLine);
                }
            }
            else if (selection is DocPageTarget)
            {
                DocPageTarget docTarget = (DocPageTarget)selection;
                LayoutLine(docTarget.Definition, docTarget, docTarget.DiagramLine);
                docTarget.DiagramLine.Reverse();
            }

            foreach (DocPageTarget docPageTarget in this.m_schema.PageTargets)
            {
                if (docPageTarget.Definition == selection)
                {
                    LayoutLine(docPageTarget.Definition, docPageTarget, docPageTarget.DiagramLine);
                    docPageTarget.DiagramLine.Reverse();
                }
            }

            foreach(DocSchemaRef docSchemaRef in this.m_schema.SchemaRefs)
            {
                foreach(DocDefinitionRef docDefRef in docSchemaRef.Definitions)
                {
                    foreach (DocLine docLine in docDefRef.Tree)
                    {
                        if (docLine.Definition == selection)
                        {
                            LayoutLine(docDefRef, docLine.Definition, docLine.DiagramLine);
                        }
                        else
                        {
                            foreach (DocLine docSub in docLine.Tree)
                            {
                                if (docSub.Definition == selection)
                                {
                                    LayoutNode(docLine, docSub);
                                }
                            }
                        }
                    }
                }
            }

            foreach (DocEntity docEntity in this.m_schema.Entities)
            {
                // if there multile attributes refer to the same definition, then space evenly
                int count = 0;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    if (docAttr.Definition == selection)
                    {
                        count++;
                    }
                }

                int each = 0;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    if (docAttr.Definition == selection)
                    {
                        LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine);
                        if(count > 1 && docAttr.DiagramLine.Count == 3)
                        {
                            each++;
                            docAttr.DiagramLine[0].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count+1));
                            docAttr.DiagramLine[1].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count+1));
                            docAttr.DiagramLine[2].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count+1));
                        }

                        if (docAttr.DiagramLabel == null)
                        {
                            docAttr.DiagramLabel = new DocRectangle();
                        }

                        if (docAttr.DiagramLine[2].Y > docAttr.DiagramLine[0].Y)
                        {
                            docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                            docAttr.DiagramLabel.Y = docAttr.DiagramLine[0].Y + 20.0;
                        }
                        else
                        {
                            docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                            docAttr.DiagramLabel.Y = docAttr.DiagramLine[0].Y - 20.0;
                        }
                    }
                }

                if (docEntity.Name.Equals("IfcBooleanResult"))
                {
                    this.ToString();
                }

                foreach(DocLine docLine in docEntity.Tree)
                {
                    // workaround to fix-up broken data (due to bug in previous import from Visual Express -- no longer occurs with new files)
            #if false
                    if (docLine.Definition == null && selection is DocEntity && ((DocEntity)selection).BaseDefinition == docEntity.Name)
                    {
                        docLine.Definition = selection;
                        System.Diagnostics.Debug.WriteLine("CtlExpressG::LayoutDefinition -- fixed up null reference to subtype");
                    }
            #endif
                    if (docLine.Definition == selection)
                    {
                        LayoutLine(docEntity, docLine.Definition, docLine.DiagramLine);
                    }
                    else
                    {
                        foreach (DocLine docSub in docLine.Tree)
                        {
                            if (docSub.Definition == selection)
                            {
                                LayoutNode(docLine, docSub);
                            }
                        }
                    }
                }
            }

            foreach (DocType docType in this.m_schema.Types)
            {
                if (docType is DocDefined)
                {
                    DocDefined docDef = (DocDefined)docType;
                    if (docDef.Definition == selection)
                    {
                        LayoutLine(docDef, docDef.Definition, docDef.DiagramLine);
                    }
                }
                else if (docType is DocSelect)
                {
                    DocSelect docSel = (DocSelect)docType;
                    foreach (DocLine docLine in docSel.Tree)
                    {
                        if(docLine.Definition == selection)
                        {
                            LayoutLine(docSel, selection, docLine.DiagramLine);
                        }

                        foreach(DocLine docSub in docLine.Tree)
                        {
                            if(docSub.Definition == selection)
                            {
                                LayoutNode(docLine, docSub);
                            }
                        }
                    }
                }
            }

            // recalculate page extents and resize/repaginate if necessary
            double cx = 0.0;
            double cy = 0.0;
            foreach (DocType docDef in this.m_schema.Types)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocEntity docDef in this.m_schema.Entities)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocPrimitive docDef in this.m_schema.Primitives)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocPageTarget docDef in this.m_schema.PageTargets)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
                foreach (DocPageSource docSource in docDef.Sources)
                {
                    ExpandExtents(docSource.DiagramRectangle, ref cx, ref cy);
                }
            }
            foreach (DocSchemaRef docRef in this.m_schema.SchemaRefs)
            {
                foreach (DocDefinitionRef docDef in docRef.Definitions)
                {
                    ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
                }
            }
            foreach (DocComment docDef in this.m_schema.Comments)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            this.m_schema.DiagramPagesHorz = 1 + (int)Math.Floor(cx * Factor / PageX);
            this.m_schema.DiagramPagesVert = 1 + (int)Math.Floor(cy * Factor / PageY);

            int px = (int)(selection.DiagramRectangle.X * Factor / CtlExpressG.PageX);
            int py = (int)(selection.DiagramRectangle.Y * Factor / CtlExpressG.PageY);
            int page = 1 + py * this.m_schema.DiagramPagesHorz + px;
            selection.DiagramNumber = page;
        }
Exemplo n.º 31
0
        public static void LayoutLine(DocDefinition defA, DocDefinition defB, List<DocPoint> list)
        {
            if (list == null)
                return;

            while (list.Count > 3)
            {
                list[list.Count - 1].Delete();
                list.RemoveAt(list.Count - 1);
            }
            while (list.Count < 3)
            {
                list.Add(new DocPoint());
            }
            DocPoint ptA = list[0];
            DocPoint ptM = list[1];
            DocPoint ptB = list[2];

            DocRectangle rB = null;
            if(defB != null)
            {
                rB = defB.DiagramRectangle;
            }

            LayoutLine(defA.DiagramRectangle, rB, ptA, ptM, ptB);
        }
Exemplo n.º 32
0
        private void InitDefinition(DocDefinition docEntity)
        {
            docEntity.DiagramRectangle = new DocRectangle();
            docEntity.DiagramRectangle.X = (this.ctlExpressG.Marker.X - this.ctlExpressG.AutoScrollPosition.X) / CtlExpressG.Factor;
            docEntity.DiagramRectangle.Y = (this.ctlExpressG.Marker.Y - this.ctlExpressG.AutoScrollPosition.Y) / CtlExpressG.Factor;
            docEntity.DiagramRectangle.Width = 400.0f;
            docEntity.DiagramRectangle.Height = 100.0f;

            int px = (int)(docEntity.DiagramRectangle.X * CtlExpressG.Factor / CtlExpressG.PageX);
            int py = (int)(docEntity.DiagramRectangle.Y * CtlExpressG.Factor / CtlExpressG.PageY);
            int page = 1 + py * this.ctlExpressG.Schema.DiagramPagesHorz + px;
            docEntity.DiagramNumber = page;
        }
Exemplo n.º 33
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 34
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);//?...
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 35
0
        private void CompileConcept(DocTemplateUsage concept, DocModelView view, TypeBuilder tb)
        {
            bool includeconcept = true;

            if (this.m_exchange != null)
            {
                includeconcept = false;
                foreach (DocExchangeItem ei in concept.Exchanges)
                {
                    if (ei.Exchange == this.m_exchange && ei.Applicability == DocExchangeApplicabilityEnum.Export &&
                        (ei.Requirement == DocExchangeRequirementEnum.Mandatory || ei.Requirement == DocExchangeRequirementEnum.Optional))
                    {
                        includeconcept = true;
                    }
                }
            }

            // bool ConceptTemplateA([Parameter1, ...]);
            // {
            //    // for loading reference value:
            //    .ldfld [AttributeRule]
            //    .ldelem [Index] // for collection, get element by index
            //    .castclass [EntityRule] for entity, cast to expected type;
            //    // for object graphs, repeat the above instructions to load value
            //
            //    for loading constant:
            //    .ldstr 'value'
            //
            //    for comparison functions:
            //    .cge
            //
            //    for logical aggregations, repeat each item, pushing 2 elements on stack, then run comparison
            //    .or
            //
            //    return the boolean value on the stack
            //    .ret;
            // }

            // bool[] ConceptA()
            // {
            //    bool[] result = new bool[2];
            //
            //    if parameters are specified, call for each template rule; otherwise call just once
            //    result[0] = ConceptTemplateA([Parameter1, ...]); // TemplateRule#1
            //    result[1] = ConceptTemplateA([Parameter1, ...]); // TemplateRule#2
            //
            //    return result;
            // }

            // compile a method for the template definition, where parameters are passed to the template


#if true
            if (includeconcept && concept.Definition != null)
            {
                MethodInfo methodTemplate = this.RegisterTemplate(concept.Definition);

                // verify that definition is compatible with entity (user error)
                if (methodTemplate != null && methodTemplate.DeclaringType.IsAssignableFrom(tb))
                {
                    string methodname = DocumentationISO.MakeLinkName(view) + "_" + DocumentationISO.MakeLinkName(concept.Definition);



                    MethodBuilder method    = tb.DefineMethod(methodname, MethodAttributes.Public, CallingConventions.HasThis, typeof(bool[]), null);
                    ILGenerator   generator = method.GetILGenerator();

                    DocModelRule[] parameters = concept.Definition.GetParameterRules();

                    if (parameters != null && parameters.Length > 0)
                    {
                        // allocate array of booleans, store as local variable
                        generator.DeclareLocal(typeof(bool[]));
                        generator.Emit(OpCodes.Ldc_I4, concept.Items.Count);
                        generator.Emit(OpCodes.Newarr, typeof(bool));
                        generator.Emit(OpCodes.Stloc_0);

                        // call for each item with specific parameters
                        for (int row = 0; row < concept.Items.Count; row++)
                        {
                            DocTemplateItem docItem = concept.Items[row];

                            generator.Emit(OpCodes.Ldloc_0);                               // push the array object onto the stack, for storage later
                            generator.Emit(OpCodes.Ldc_I4, row);                           // push the array index onto the stack for storage later

                            generator.Emit(OpCodes.Ldarg_0);                               // push the *this* pointer for the IFC object instance

                            // push parameters onto stack
                            for (int col = 0; col < parameters.Length; col++)
                            {
                                DocModelRule docParam   = parameters[col];
                                string       paramvalue = docItem.GetParameterValue(docParam.Identification);
                                if (paramvalue != null)
                                {
                                    DocDefinition docParamType = concept.Definition.GetParameterType(docParam.Identification, this.m_definitions);
                                    if (docParamType is DocDefined)
                                    {
                                        DocDefined docDefined = (DocDefined)docParamType;
                                        switch (docDefined.DefinedType)
                                        {
                                        case "INTEGER":
                                        {
                                            Int64 ival = 0;
                                            Int64.TryParse(paramvalue, out ival);
                                            generator.Emit(OpCodes.Ldc_I8, ival);
                                            generator.Emit(OpCodes.Box);
                                        }
                                        break;

                                        case "REAL":
                                        {
                                            Double dval = 0.0;
                                            Double.TryParse(paramvalue, out dval);
                                            generator.Emit(OpCodes.Ldc_R8, dval);
                                            generator.Emit(OpCodes.Box);
                                        }
                                        break;

                                        case "STRING":
                                            generator.Emit(OpCodes.Ldstr, paramvalue);
                                            break;

                                        default:
                                            generator.Emit(OpCodes.Ldstr, paramvalue);
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        // assume string
                                        generator.Emit(OpCodes.Ldstr, paramvalue);
                                    }
                                }
                                else
                                {
                                    generator.Emit(OpCodes.Ldnull);
                                }
                            }

                            generator.Emit(OpCodes.Call, methodTemplate);                  // call the validation function for the concept template
                            generator.Emit(OpCodes.Stelem_I1);                             // store the result (bool) into an array slot
                        }

                        // return the array of boolean results
                        generator.Emit(OpCodes.Ldloc_0);
                        generator.Emit(OpCodes.Ret);
                    }
                    else
                    {
                        // allocate array of booleans, store as local variable
                        generator.DeclareLocal(typeof(bool[]));
                        generator.Emit(OpCodes.Ldc_I4, 1);
                        generator.Emit(OpCodes.Newarr, typeof(bool));
                        generator.Emit(OpCodes.Stloc_0);

                        generator.Emit(OpCodes.Ldloc_0);                           // push the array object onto the stack, for storage later
                        generator.Emit(OpCodes.Ldc_I4, 0);                         // push the array index onto the stack for storage later

                        // call once
                        generator.Emit(OpCodes.Ldarg_0);                           // push the *this* pointer for the IFC object instance
                        generator.Emit(OpCodes.Call, methodTemplate);              // call the validation function for the concept template
                        generator.Emit(OpCodes.Stelem_I1);                         // store the result (bool) into an array slot

                        // return the array of boolean results
                        generator.Emit(OpCodes.Ldloc_0);
                        generator.Emit(OpCodes.Ret);
                    }
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("Incompatible template: " + tb.Name + " - " + concept.Definition.Name);
                }
            }
#endif
            // recurse
            foreach (DocTemplateUsage docChild in concept.Concepts)
            {
                CompileConcept(docChild, view, tb);
            }
        }
Exemplo n.º 36
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="basetype">DocEntity or DocSelect.</param>
        /// <param name="selection"></param>
        /// <param name="project"></param>
        /// <param name="predefined">Select predefined type.</param>
        public FormSelectEntity(
            DocDefinition basetype, 
            DocDefinition selection, 
            DocProject project,
            SelectDefinitionOptions options)
            : this()
        {
            this.m_basetype = basetype;
            this.m_selection = selection;
            this.m_project = project;
            this.m_options = options;

            this.m_mapAlpha = new Dictionary<DocDefinition, TreeNode>();
            this.m_mapInherit = new Dictionary<DocDefinition, TreeNode>();

            // load subtypes, sort alphabetically
            if (this.m_basetype is DocEntity)
            {
                this.LoadEntity(null, (DocEntity)this.m_basetype);
                this.tabControl1.TabPages.RemoveAt(1);
            }
            else if (this.m_basetype is DocSelect)
            {
                this.LoadSelect(null, (DocSelect)this.m_basetype);
                this.tabControl1.TabPages.RemoveAt(1);
            }
            else if (this.m_basetype != null)
            {
                // add single node for type
                TreeNode tn = new TreeNode();
                tn.Tag = basetype;
                tn.Text = basetype.Name;
                this.treeViewInheritance.Nodes.Add(tn);

                this.tabControl1.TabPages.RemoveAt(1);
            }
            else
            {
                // all entities
                SortedList<string, DocDefinition> sort = new SortedList<string, DocDefinition>();
                SortedList<string, DocDefinition> sortAll = new SortedList<string, DocDefinition>();
                foreach (DocSection docSection in this.m_project.Sections)
                {
                    foreach (DocSchema docSchema in docSection.Schemas)
                    {
                        foreach (DocEntity docEntity in docSchema.Entities)
                        {
                            if (docEntity.BaseDefinition == null)
                            {
                                if(!sort.ContainsKey(docEntity.Name))
                                { 
                                    sort.Add(docEntity.Name, docEntity);
                                }
                            }

                            if (!sortAll.ContainsKey(docEntity.Name))
                            {
                                sortAll.Add(docEntity.Name, docEntity);
                            }
                        }

                        if ((options & SelectDefinitionOptions.Type) != 0)
                        {
                            // temp: all types too; todo: specify parameter
                            foreach (DocType docType in docSchema.Types)
                            {
                                sort.Add(docType.Name, docType);

                                if (!sortAll.ContainsKey(docType.Name))
                                {
                                    sortAll.Add(docType.Name, docType);
                                }
                            }
                        }
                    }
                }

                foreach (DocDefinition docDef in sort.Values)
                {
                    if (docDef is DocEntity)
                    {
                        this.LoadEntity(null, (DocEntity)docDef);
                    }
                    else if (docDef is DocType)
                    {
                        this.LoadType(null, (DocType)docDef);
                    }
                }

                foreach(DocDefinition docDef in sortAll.Values)
                {
                    TreeNode tnAlpha = new TreeNode();
                    tnAlpha.Tag = docDef;
                    tnAlpha.Text = docDef.Name;
                    this.m_mapAlpha.Add(docDef, tnAlpha);
                    this.treeViewAlphabetical.Nodes.Add(tnAlpha);
                }
            }

            if (this.treeViewInheritance.SelectedNode == null && this.treeViewInheritance.Nodes.Count > 0)
            {
                this.treeViewInheritance.SelectedNode = this.treeViewInheritance.Nodes[0];
            }

            this.treeViewInheritance.ExpandAll();
            this.treeViewInheritance.Focus();
        }
Exemplo n.º 37
0
        private MethodInfo RegisterTemplate(DocTemplateDefinition dtd)
        {
            if (dtd == null || dtd.Rules == null)
            {
                return(null);
            }

            MethodInfo methodexist = null;

            if (this.m_templates.TryGetValue(dtd, out methodexist))
            {
                return(methodexist);
            }

            Type[]         paramtypes = null;
            DocModelRule[] parameters = dtd.GetParameterRules();
            if (parameters != null && parameters.Length > 0)
            {
                paramtypes = new Type[parameters.Length];
                for (int iParam = 0; iParam < parameters.Length; iParam++)
                {
#if false
                    DocModelRule param = parameters[iParam];
                    if (param is DocModelRuleAttribute)
                    {
                        DocDefinition paramtype = dtd.GetParameterType(param.Name, this.m_definitions);
                        if (paramtype != null)
                        {
                            paramtypes[iParam] = RegisterType(paramtype.Name);
                        }
                    }
                    else if (param is DocModelRuleEntity)
                    {
                        paramtypes[iParam] = RegisterType(param.Name);
                    }
#endif

                    if (paramtypes[iParam] == null)
                    {
                        paramtypes[iParam] = typeof(string);                         // fallback
                    }
                }
            }

            if (dtd.Type == null)
            {
                return(null);
            }

            TypeBuilder tb = (System.Reflection.Emit.TypeBuilder) this.RegisterType(dtd.Type);
            if (tb == null)
            {
                return(null);
            }

            string methodname;
            if (dtd.Name != null)
            {
                methodname = dtd.Name;
            }
            else
            {
                methodname = dtd.UniqueId;
            }
            methodname = methodname.Replace(' ', '_').Replace(':', '_').Replace('-', '_');
            MethodBuilder method    = tb.DefineMethod(methodname, MethodAttributes.Public, CallingConventions.HasThis, typeof(bool), paramtypes);
            ILGenerator   generator = method.GetILGenerator();
            foreach (DocModelRule docRule in dtd.Rules)
            {
                docRule.EmitInstructions(this, generator, dtd);
            }

            // if made it to the end, then successful, so return true
            generator.Emit(OpCodes.Ldc_I4_1);
            generator.Emit(OpCodes.Ret);

            return(method);
        }
Exemplo n.º 38
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
                    {
                    }
                }
            }
        }
Exemplo n.º 39
0
        private void buttonInsert_Click(object sender, EventArgs e)
        {
            DocDefinition docBase       = this.m_base;
            DocDefinition docDefinition = null;


            // for now, clear it -- future: allow incremental replacement

            CvtValuePath valuepathouter = null;
            CvtValuePath valuepathinner = null;

            // keep building
            while (docBase != null)
            {
                using (FormSelectEntity formEntity = new FormSelectEntity(docBase, docDefinition, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type))
                {
                    if (formEntity.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && formEntity.SelectedEntity != null)
                    {
                        CvtValuePath valuepath = null;
                        if (formEntity.SelectedEntity is DocEntity)
                        {
                            using (FormSelectAttribute formAttribute = new FormSelectAttribute((DocEntity)formEntity.SelectedEntity, this.m_project, null, false))
                            {
                                if (formAttribute.ShowDialog(this) == System.Windows.Forms.DialogResult.OK && formAttribute.SelectedAttribute != null)
                                {
                                    string item = null;
                                    switch (formAttribute.SelectedAttribute.GetAggregation())
                                    {
                                    case DocAggregationEnum.SET:
                                        // if set collection, then qualify by name
                                        // future: more intelligent UI for picking property sets, properties
                                        using (FormSelectItem formItem = new FormSelectItem())
                                        {
                                            if (formItem.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                                            {
                                                item = formItem.Item;
                                            }
                                        }
                                        break;

                                    case DocAggregationEnum.LIST:
                                        // if list collection, then qualify by index
                                        // future: more intelligent UI for picking list indices
                                        using (FormSelectItem formItem = new FormSelectItem())
                                        {
                                            if (formItem.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                                            {
                                                item = formItem.Item;
                                            }
                                        }
                                        break;
                                    }

                                    // now add entry to listview
                                    valuepath = new CvtValuePath(formEntity.SelectedEntity, formAttribute.SelectedAttribute, item, null);

                                    if (valuepathinner != null)
                                    {
                                        valuepathinner.InnerPath = valuepath;
                                    }
                                    valuepathinner = valuepath;

                                    if (valuepathouter == null)
                                    {
                                        valuepathouter = valuepath;
                                    }

                                    // drill in
                                    if (this.m_map.ContainsKey(formAttribute.SelectedAttribute.DefinedType))
                                    {
                                        docBase = this.m_map[formAttribute.SelectedAttribute.DefinedType] as DocDefinition;
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                        else if (formEntity.SelectedEntity is DocType)
                        {
                            valuepath = new CvtValuePath(formEntity.SelectedEntity, null, null, null);

                            if (valuepathinner != null)
                            {
                                valuepathinner.InnerPath = valuepath;
                            }
                            valuepathinner = valuepath;

                            if (valuepathouter == null)
                            {
                                valuepathouter = valuepath;
                            }

                            docBase = null;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            this.LoadValuePath(valuepathouter);
        }
Exemplo n.º 40
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
        }
Exemplo n.º 41
0
        private g SaveDefinition(DocObject docObj, string displayname)
        {
            g group = new g();

            group.id = docObj.Name;

            DocDefinition docDef = docObj as DocDefinition;

            if (docDef == null || docDef.DiagramRectangle == null)
            {
                return(group);
            }

            double x  = docDef.DiagramRectangle.X * CtlExpressG.Factor;
            double y  = docDef.DiagramRectangle.Y * CtlExpressG.Factor;
            double cx = docDef.DiagramRectangle.Width * CtlExpressG.Factor;
            double cy = docDef.DiagramRectangle.Height * CtlExpressG.Factor;

            rect r = new rect();

            r.x      = x.ToString();
            r.y      = y.ToString();
            r.width  = cx.ToString();
            r.height = cy.ToString();
            r.stroke = "black";
            group.rect.Add(r);

            text t = new text();

            t.x    = (x + cx * 0.5).ToString();
            t.y    = (y + cy * 0.5).ToString();
            t.fill = "black";
            t.alignment_baseline = "middle";
            t.text_anchor        = "middle";
            t.font_size          = "10";
            t.font_family        = "Arial, Helvetica, sans-serif";
            if (displayname != null)
            {
                t.value = displayname;
            }
            else
            {
                t.value = docDef.Name;
            }

            group.text.Add(t);

            if (this.m_format == DiagramFormat.UML)
            {
                y += 10;

                group.fill           = "lightyellow";
                t.y                  = y.ToString();
                t.alignment_baseline = "top";
                t.font_weight        = "bold";
                t.value              = docDef.Name;

                // separator line
                y += 2;
                List <DocPoint> listPoint = new List <DocPoint>();
                listPoint.Add(new DocPoint(x / CtlExpressG.Factor, y / CtlExpressG.Factor));
                listPoint.Add(new DocPoint((x + cx) / CtlExpressG.Factor, y / CtlExpressG.Factor));
                SaveLine(group, listPoint, null, false);
                y += 2;

                // add attributes
                if (docDef is DocDefinitionRef)
                {
                    DocDefinitionRef docDefRef = (DocDefinitionRef)docDef;

                    DocObject docObjRef = this.m_project.GetDefinition(docDefRef.Name);
                    if (docObjRef is DocEntity)
                    {
                        DocEntity docEnt = (DocEntity)docObjRef;
                        foreach (DocAttribute docAtt in docEnt.Attributes)
                        {
                            if (docAtt.Derived == null && docAtt.Inverse == null)
                            {
                                DocObject docAttrType = this.m_project.GetDefinition(docAtt.DefinedType);

                                // include native types, enumerations, and defined types
                                if (docAttrType == null || docAttrType is DocEnumeration || docAttrType is DocDefined)
                                {
                                    y += 12;

                                    string agg = "[1]";
                                    if (docAtt.AggregationType != 0)
                                    {
                                        string lower = docAtt.AggregationLower;
                                        string upper = docAtt.AggregationUpper;
                                        if (String.IsNullOrEmpty(lower))
                                        {
                                            lower = "0";
                                        }
                                        if (String.IsNullOrEmpty(upper) || upper == "0")
                                        {
                                            upper = "*";
                                        }

                                        agg = "[" + lower + ".." + upper + "]";
                                    }
                                    else if (docAtt.IsOptional)
                                    {
                                        agg = "[0..1]";
                                    }


                                    text ta = new text();
                                    ta.x    = (x + 4).ToString();
                                    ta.y    = y.ToString();
                                    ta.fill = "black";
                                    ta.alignment_baseline = "top";
                                    ta.text_anchor        = "start";
                                    ta.font_size          = "9";
                                    ta.font_family        = "Arial, Helvetica, sans-serif";
                                    ta.value = docAtt.Name + agg + " : " + docAtt.DefinedType;
                                    group.text.Add(ta);
                                }
                            }
                        }


                        // UML only (not in original EXPRESS-G diagrams)
                        foreach (DocAttributeRef docAttrRef in docDefRef.AttributeRefs)
                        {
                            DocAttribute docAtt = docAttrRef.Attribute;

                            //if (docAtt.Inverse == null)
                            {
                                //... also need to capture attribute name...
                                //DrawLine(g, Pens.Black, docAttrRef.DiagramLine, format);
                                SaveLine(group, docAttrRef.DiagramLine, null, false);

                                // draw diamond at beginning of line
#if false /// not yet correct
                                if (this.m_format == DiagramFormat.UML)
                                {
                                    DocPoint ptHead = docAttrRef.DiagramLine[0];
                                    DocPoint ptNext = docAttrRef.DiagramLine[1];
                                    double   ux     = ptNext.X - ptHead.X;
                                    double   uy     = ptNext.Y - ptHead.Y;
                                    double   uv     = Math.Sqrt(ux * ux + uy * uy);
                                    ux = ux / uv;
                                    uy = uy / uv;
                                    DocPoint        ptR   = new DocPoint(ptHead.X + uy * 8, ptHead.Y + ux * 8);
                                    DocPoint        ptF   = new DocPoint(ptHead.X + ux * 16, ptHead.Y + uy * 8);
                                    DocPoint        ptL   = new DocPoint(ptHead.X + uy * 8, ptHead.Y - ux * 8);
                                    List <DocPoint> listP = new List <DocPoint>();
                                    listP.Add(ptHead);
                                    listP.Add(ptR);
                                    listP.Add(ptF);
                                    listP.Add(ptL);
                                    listP.Add(ptHead);
                                    SaveLine(group, listP, null, false);
                                }
#endif
                                if (docAtt.Name == "Items")
                                {
                                    docAtt.ToString();
                                }

                                string agg = "[1]";
                                if (docAtt.AggregationType != 0)
                                {
                                    string lower = docAtt.AggregationLower;
                                    string upper = docAtt.AggregationUpper;
                                    if (String.IsNullOrEmpty(lower))
                                    {
                                        lower = "0";
                                    }
                                    if (String.IsNullOrEmpty(upper))
                                    {
                                        upper = "*";
                                    }

                                    agg = "[" + lower + ".." + upper + "]";
                                }
                                else if (docAtt.IsOptional)
                                {
                                    agg = "[0..1]";
                                }


                                double ty = docAttrRef.DiagramLine[0].Y * CtlExpressG.Factor;
                                if (docAttrRef.DiagramLine[1].Y > docAttrRef.DiagramLine[0].Y)
                                {
                                    ty -= 10;
                                }
                                else
                                {
                                    ty += 10;
                                }

                                text tr = new text();
                                tr.x = (docAttrRef.DiagramLine[0].X * CtlExpressG.Factor + 4).ToString();
                                tr.y = (ty).ToString();


                                tr.fill = "black";
                                tr.alignment_baseline = "top";
                                tr.text_anchor        = "start";
                                tr.font_size          = "9";
                                tr.font_family        = "Arial, Helvetica, sans-serif";
                                tr.value = docAtt.Name + agg;
                                group.text.Add(tr);
                            }
                        }
                    }
                }
            }
            else
            {
                if (docDef is DocEntity)
                {
                    group.fill = "yellow";
                }
                else if (docDef is DocType)
                {
                    group.fill = "green";
                }
                else if (docDef is DocPageTarget)
                {
                    group.fill = "blue";
                    r.rx       = "10";
                    r.ry       = "10";
                }
                else if (docDef is DocPageSource)
                {
                    group.fill = "silver";
                    r.rx       = "10";
                    r.ry       = "10";
                }
                else
                {
                    group.fill = "grey";
                }
            }


            return(group);
        }
Exemplo n.º 42
0
        /// <summary>
        /// Updates any connected geometry to match definition
        /// </summary>
        /// <param name="docDef"></param>
        public void LayoutDefinition(DocDefinition selection)
        {
            // then traverse all dependencies on selection
            if (selection is DocEntity)
            {
                DocEntity docEntity = (DocEntity)selection;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine);
                    if (docAttr.DiagramLabel != null)
                    {
                        docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                        docAttr.DiagramLabel.Y = docAttr.DiagramLine[2].Y - 20.0;
                    }
                }

                foreach (DocLine docLine in docEntity.Tree)
                {
                    LayoutTree(docEntity, docLine);
                }
            }
            else if (selection is DocDefinitionRef)
            {
                DocDefinitionRef docRef = (DocDefinitionRef)selection;
                foreach (DocLine docLine in docRef.Tree)
                {
                    LayoutTree(docRef, docLine);
                }
            }
            else if (selection is DocDefined)
            {
                DocDefined docDef = (DocDefined)selection;
                LayoutLine(docDef, docDef.Definition, docDef.DiagramLine);
            }
            else if (selection is DocSelect)
            {
                DocSelect docSelect = (DocSelect)selection;
                foreach (DocLine docLine in docSelect.Tree)
                {
                    LayoutTree(docSelect, docLine);
                }
            }
            else if (selection is DocPageTarget)
            {
                DocPageTarget docTarget = (DocPageTarget)selection;
                LayoutLine(docTarget.Definition, docTarget, docTarget.DiagramLine);
                docTarget.DiagramLine.Reverse();
            }

            foreach (DocPageTarget docPageTarget in this.m_schema.PageTargets)
            {
                if (docPageTarget.Definition == selection)
                {
                    LayoutLine(docPageTarget.Definition, docPageTarget, docPageTarget.DiagramLine);
                    docPageTarget.DiagramLine.Reverse();
                }
            }

            foreach(DocSchemaRef docSchemaRef in this.m_schema.SchemaRefs)
            {
                foreach(DocDefinitionRef docDefRef in docSchemaRef.Definitions)
                {
                    foreach (DocLine docLine in docDefRef.Tree)
                    {
                        if (docLine.Definition == selection)
                        {
                            LayoutLine(docDefRef, docLine.Definition, docLine.DiagramLine);
                        }
                        else
                        {
                            foreach (DocLine docSub in docLine.Tree)
                            {
                                if (docSub.Definition == selection)
                                {
                                    LayoutNode(docLine, docSub);
                                }
                            }
                        }
                    }
                }
            }

            foreach (DocEntity docEntity in this.m_schema.Entities)
            {
                // if there multile attributes refer to the same definition, then space evenly
                int count = 0;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    if (docAttr.Definition == selection)
                    {
                        count++;
                    }
                }

                int each = 0;
                foreach (DocAttribute docAttr in docEntity.Attributes)
                {
                    if (docAttr.Definition == selection)
                    {
                        LayoutLine(docEntity, docAttr.Definition, docAttr.DiagramLine);
                        if(count > 1 && docAttr.DiagramLine.Count == 3)
                        {
                            each++;
                            docAttr.DiagramLine[0].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count+1));
                            docAttr.DiagramLine[1].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count+1));
                            docAttr.DiagramLine[2].Y = selection.DiagramRectangle.Y + (selection.DiagramRectangle.Height * (double)each / (double)(count+1));
                        }

                        if (docAttr.DiagramLabel == null)
                        {
                            docAttr.DiagramLabel = new DocRectangle();
                        }
                        docAttr.DiagramLabel.X = docAttr.DiagramLine[0].X;
                        docAttr.DiagramLabel.Y = docAttr.DiagramLine[2].Y - 20.0;
                    }
                }

                foreach(DocLine docLine in docEntity.Tree)
                {
                    if (docLine.Definition == selection)
                    {
                        LayoutLine(docEntity, docLine.Definition, docLine.DiagramLine);
                    }
                    else
                    {
                        foreach (DocLine docSub in docLine.Tree)
                        {
                            if (docSub.Definition == selection)
                            {
                                LayoutNode(docLine, docSub);
                            }
                        }
                    }
                }
            }

            foreach (DocType docType in this.m_schema.Types)
            {
                if (docType is DocDefined)
                {
                    DocDefined docDef = (DocDefined)docType;
                    if (docDef.Definition == selection)
                    {
                        LayoutLine(docDef, docDef.Definition, docDef.DiagramLine);
                    }
                }
                else if (docType is DocSelect)
                {
                    DocSelect docSel = (DocSelect)docType;
                    foreach (DocLine docLine in docSel.Tree)
                    {
                        if(docLine.Definition == selection)
                        {
                            LayoutLine(docSel, selection, docLine.DiagramLine);
                        }
                        
                        foreach(DocLine docSub in docLine.Tree)
                        {
                            if(docSub.Definition == selection)
                            {
                                LayoutNode(docLine, docSub);
                            }
                        }
                    }
                }
            }

            // recalculate page extents and resize/repaginate if necessary
            double cx = 0.0;
            double cy = 0.0;
            foreach (DocType docDef in this.m_schema.Types)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocEntity docDef in this.m_schema.Entities)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocPrimitive docDef in this.m_schema.Primitives)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            foreach (DocPageTarget docDef in this.m_schema.PageTargets)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
                foreach (DocPageSource docSource in docDef.Sources)
                {
                    ExpandExtents(docSource.DiagramRectangle, ref cx, ref cy);
                }
            }
            foreach (DocSchemaRef docRef in this.m_schema.SchemaRefs)
            {
                foreach (DocDefinitionRef docDef in docRef.Definitions)
                {
                    ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
                }
            }
            foreach (DocComment docDef in this.m_schema.Comments)
            {
                ExpandExtents(docDef.DiagramRectangle, ref cx, ref cy);
            }
            this.m_schema.DiagramPagesHorz = 1 + (int)Math.Floor(cx * Factor / PageX);
            this.m_schema.DiagramPagesVert = 1 + (int)Math.Floor(cy * Factor / PageY);

        }