Exemplo n.º 1
0
        private void toolStripButtonMoveDown_Click(object sender, EventArgs e)
        {
            this.m_editcon = true;
            int index = this.dataGridViewConceptRules.SelectedRows[0].Index;

            if (index < this.dataGridViewConceptRules.Rows.Count - 2)
            {
                List <DocTemplateItem> listItems = null;
                if (this.m_conceptleaf != null)
                {
                    listItems = this.m_conceptleaf.Items;
                }
                else
                {
                    listItems = this.m_conceptroot.ApplicableItems;
                }

                DocTemplateItem dti = listItems[index];
                listItems.Insert(index + 2, dti);
                listItems.RemoveAt(index);

                LoadUsage();
                this.dataGridViewConceptRules.Rows[index + 1].Selected = true;
            }
            this.m_editcon = false;
        }
Exemplo n.º 2
0
        private void dataGridViewConceptRules_UserAddedRow(object sender, DataGridViewRowEventArgs e)
        {
            DocTemplateItem dti = new DocTemplateItem();

            this.m_conceptleaf.Items.Add(dti);
            e.Row.Tag = dti;
        }
Exemplo n.º 3
0
        private void dataGridViewConceptRules_SelectionChanged(object sender, EventArgs e)
        {
            if (this.m_editcon)
            {
                return;
            }

            //select template item
            if (sender is DataGridView)
            {
                DataGridView sendingGridView = (DataGridView)sender;

                if (sendingGridView.SelectedRows.Count > 0)
                {
                    if (sendingGridView.SelectedRows[0].Tag is DocTemplateItem)
                    {
                        DocTemplateItem selectedTemplateItem = (DocTemplateItem)sendingGridView.SelectedRows[0].Tag;
                        //this.ConceptItem = selectedTemplateItem;
                    }
                    else if (sendingGridView.SelectedRows[0].Tag == null)
                    {
                        return;
                    }
                }
            }

            //toolStripButtonTemplateInsert
            ToolStripButtonVisibility();
        }
Exemplo n.º 4
0
        private void dataGridViewConceptRules_CellValidated(object sender, DataGridViewCellEventArgs e)
        {
            if (this.m_editcon)
            {
                return;
            }

            // format parameters

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < this.dataGridViewConceptRules.Columns.Count - 1; i++)
            {
                object val = this.dataGridViewConceptRules[i, e.RowIndex].Value;
                if (val != null)
                {
                    DataGridViewColumn col = this.dataGridViewConceptRules.Columns[i];
                    if (col.Tag is DocModelRule)
                    {
                        DocModelRule rule = (DocModelRule)col.Tag;

                        sb.Append(rule.Identification);
                        sb.Append("=");
                        sb.Append(val as string);
                        sb.Append(";");
                    }
                    else
                    {
                        this.ToString(); // description???
                    }
                }
            }

            List <DocTemplateItem> listItems = null;

            if (this.m_conceptleaf != null)
            {
                listItems = this.m_conceptleaf.Items;
            }
            else
            {
                listItems = this.m_conceptroot.ApplicableItems;
            }

            if (listItems.Count > e.RowIndex)
            {
                DocTemplateItem docItem = listItems[e.RowIndex];
                docItem.RuleParameters = sb.ToString();
                object val = this.dataGridViewConceptRules[this.dataGridViewConceptRules.Columns.Count - 1, e.RowIndex].Value;
                docItem.Documentation = val as string;

                object usage = this.dataGridViewConceptRules[0, e.RowIndex].Value;
                docItem.SetUsage(usage as string);
            }
        }
Exemplo n.º 5
0
        private void toolStripButtonMoveUp_Click(object sender, EventArgs e)
        {
            this.m_editcon = true;
            int index = this.dataGridViewConceptRules.SelectedRows[0].Index;
            DocTemplateUsage docUsage = (DocTemplateUsage)this.m_conceptleaf;
            DocTemplateItem  dti      = docUsage.Items[index];

            docUsage.Items.Insert(index - 1, dti);
            docUsage.Items.RemoveAt(index + 1);

            LoadUsage();
            this.m_editcon = false;
        }
Exemplo n.º 6
0
        private void dataGridViewConceptRules_UserAddedRow(object sender, DataGridViewRowEventArgs e)
        {
            DocTemplateItem dti = new DocTemplateItem();

            if (this.m_conceptleaf != null)
            {
                this.m_conceptleaf.Items.Add(dti);
            }
            else
            {
                this.m_conceptroot.ApplicableItems.Add(dti);
            }
            e.Row.Tag = dti;
        }
Exemplo n.º 7
0
        private void dataGridViewConceptRules_CurrentCellDirtyStateChanged(object sender, EventArgs e)
        {
            // fired when combobox changes -- handle immediately to update color
            if (this.dataGridViewConceptRules.SelectedCells.Count == 1 &&
                this.dataGridViewConceptRules.SelectedCells[0].ColumnIndex == 0 &&
                this.dataGridViewConceptRules.SelectedCells[0].RowIndex >= 0)
            {
                int row = this.dataGridViewConceptRules.SelectedCells[0].RowIndex;

                DocTemplateItem docItem = (DocTemplateItem)this.dataGridViewConceptRules.SelectedCells[0].OwningRow.Tag;
                if (docItem != null)
                {
                    docItem.SetUsage(this.dataGridViewConceptRules.SelectedCells[0].Value as string);
                    this.dataGridViewConceptRules.SelectedCells[0].OwningRow.DefaultCellStyle.BackColor = docItem.GetColor();
                    this.dataGridViewConceptRules.InvalidateRow(row);
                }
            }
        }
Exemplo n.º 8
0
        private void toolStripMenuItemFileImport_Click(object sender, EventArgs e)
        {
            StringBuilder sbErrors = new StringBuilder();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        }

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

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

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

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

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

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

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

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

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

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

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

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

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

                }

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

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

            if (sbErrors.Length > 0)
            {
                MessageBox.Show(this, "Import succeeded, however one or more definitions have missing or incorrect information:\r\n" + sbErrors.ToString(), "Import Errors");
            }
        }
Exemplo n.º 9
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.º 10
0
        private void toolStripButtonTemplateInsert_Click(object sender, EventArgs e)
        {
            if (this.dataGridViewConceptRules.SelectedRows.Count == 0)
            {
                return;
            }

            this.m_editcon = true;

            DocPropertySet existingPropertySet = null;

            bool isPsetDefined     = false;
            bool isPropertyDefined = false;

            if (this.m_conceptleaf != null)
            {
                if (this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyList || this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyBounded ||
                    this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyEnumerated || this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyReference ||
                    this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertySingle || this.m_conceptleaf.Definition.Uuid == DocTemplateDefinition.guidTemplatePropertyTable)
                {
                    foreach (DocSection docSection in this.Project.Sections)
                    {
                        foreach (DocSchema docSchema in docSection.Schemas)
                        {
                            foreach (DocPropertySet docPset in docSchema.PropertySets)
                            {
                                if (docPset.Name == this.ConceptItem.Name)
                                {
                                    isPsetDefined       = true;
                                    existingPropertySet = docPset;
                                }
                                // search properties
                                foreach (DocProperty docProp in docPset.Properties)
                                {
                                    for (int i = 0; i < this.dataGridViewConceptRules.SelectedRows.Count; i++)
                                    {
                                        if (dataGridViewConceptRules.SelectedRows[i].Tag is DocTemplateItem)
                                        {
                                            DocTemplateItem propertyItem = (DocTemplateItem)dataGridViewConceptRules.SelectedRows[i].Tag;
                                            if (docProp.Name == propertyItem.GetParameterValue("PropertyName"))
                                            {
                                                isPropertyDefined = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    //this.m_conceptroot.ApplicableItems.RemoveAt(index);
                }

                if (!isPsetDefined)
                {
                    FormSelectSchema schemaSelect = new FormSelectSchema(this.Project);
                    schemaSelect.ShowDialog();

                    DocPropertySet  pset     = new DocPropertySet();
                    DocTemplateItem psetItem = (DocTemplateItem)this.ConceptItem;
                    pset.Name = psetItem.GetParameterValue("PsetName");
                    if (!isPropertyDefined)
                    {
                        for (int i = 0; i < this.dataGridViewConceptRules.SelectedRows.Count; i++)
                        {
                            DocProperty property = new DocProperty();
                            if (dataGridViewConceptRules.SelectedRows[i].Tag is DocTemplateItem)
                            {
                                DocTemplateItem propertyItem = (DocTemplateItem)dataGridViewConceptRules.SelectedRows[i].Tag;
                                property.Name = propertyItem.GetParameterValue("PropertyName");
                                //if (propertyItem.GetParameterValue("Value") != null)
                                //{
                                property.PrimaryDataType = propertyItem.GetParameterValue("Value");
                                //}
                                pset.Properties.Add(property);
                            }
                        }
                    }
                    schemaSelect.Selection.PropertySets.Add(pset);
                }
                else
                {
                    if (!isPropertyDefined)
                    {
                        for (int i = 0; i < this.dataGridViewConceptRules.SelectedRows.Count; i++)
                        {
                            DocProperty property = new DocProperty();
                            if (dataGridViewConceptRules.SelectedRows[i].Tag is DocTemplateItem)
                            {
                                DocTemplateItem propertyItem = (DocTemplateItem)dataGridViewConceptRules.SelectedRows[i].Tag;
                                property.Name = propertyItem.GetParameterValue("PropertyName");
                                //if (propertyItem.GetParameterValue("Value") != null)
                                //{
                                property.PrimaryDataType = propertyItem.GetParameterValue("Value");
                                //}
                                existingPropertySet.Properties.Add(property);
                            }
                        }
                    }
                }

                if (this.ParentForm.Owner is FormEdit)
                {
                    FormEdit ownerForm = (FormEdit)this.ParentForm.Owner;
                    //ownerForm.i
                }
                this.m_editcon = false;
            }
        }
Exemplo n.º 11
0
        internal static TemplateRule ExportMvdItem(DocTemplateItem docRule)
        {
            TemplateRule mvdTemplateRule = new TemplateRule();
            if (!String.IsNullOrEmpty(docRule.RuleInstanceID))
            {
                mvdTemplateRule.RuleID = docRule.RuleInstanceID;
            }
            mvdTemplateRule.Description = docRule.Documentation;

            // new: use special mvdXML 1.1 syntax
            mvdTemplateRule.Parameters = docRule.FormatParameterExpressions(); // was RuleParameters;

            return mvdTemplateRule;
        }
Exemplo n.º 12
0
        private static DocTemplateItem ImportMvdItem(TemplateRule rule, DocProject docProject, Dictionary<Guid, ExchangeRequirement> mapExchange)
        {
            DocTemplateItem docItem = new DocTemplateItem();
            docItem.Documentation = rule.Description;
            docItem.RuleInstanceID = rule.RuleID;
            docItem.ParseParameterExpressions(rule.Parameters); // convert from mvdXML

            if (rule.References != null)
            {
                foreach (Concept con in rule.References)
                {
                    DocTemplateUsage docInner = new DocTemplateUsage();
                    docItem.Concepts.Add(docInner);
                    ImportMvdConcept(con, docInner, docProject, mapExchange);
                }
            }

            return docItem;
        }
Exemplo n.º 13
0
        private void CreateAndAssignProperty(FormSelectProperty form, DocTemplateUsage propertyConcept, DocTemplateItem property, string psetName)
        {
            propertyConcept.Items.Add(property);

            foreach (DocTemplateItem pset in this.Concept.Items)
            {
                if (pset.Name == psetName)
                {
                    pset.Concepts.Add(propertyConcept);
                    //if (pset.Concepts.Count == 0)
                    //{
                    //    pset.Concepts.Add(propertyConcept);
                    //}
                    //else
                    //{
                    //    bool propertyAdded = false;
                    //    foreach (DocTemplateUsage propConcept in pset.Concepts)
                    //    {
                    //        if (propConcept.Definition.Equals(propertyConcept.Definition))
                    //        {
                    //            propConcept.Items.Add(property);
                    //            propertyAdded = true;
                    //        }
                    //        //if (form.SelectedProperty.PropertyType == prop.)
                    //    }
                    //    if (!propertyAdded)
                    //    {
                    //        pset.Concepts.Add(propertyConcept);
                    //    }
                    //}

                    //this.Concept.Items.Add(propertySetProperty);
                }
            }
        }
Exemplo n.º 14
0
        private void toolStripButtonProperty_Click(object sender, EventArgs e)
        {
            DocEntity docBaseEntity = this.m_project.GetDefinition(this.m_template.Type) as DocEntity;

            if (this.m_conceptroot != null && this.m_conceptroot.ApplicableEntity != null)
            {
                docBaseEntity = this.m_conceptroot.ApplicableEntity;
            }

            using (FormSelectProperty form = new FormSelectProperty(docBaseEntity, this.m_project, false))
            {
                if (form.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                {
                    string value = form.GenerateValuePath();

                    Dictionary <string, DocObject> mapEntity = new Dictionary <string, DocObject>();
                    foreach (DocSection docSection in this.m_project.Sections)
                    {
                        foreach (DocSchema docSchema in docSection.Schemas)
                        {
                            foreach (DocEntity docEntity in docSchema.Entities)
                            {
                                mapEntity.Add(docEntity.Name, docEntity);
                            }
                            foreach (DocType docType in docSchema.Types)
                            {
                                mapEntity.Add(docType.Name, docType);
                            }
                        }
                    }

                    if (docBaseEntity.BaseDefinition == "IfcElement" || docBaseEntity.BaseDefinition == "IfcElementComponent" || docBaseEntity.BaseDefinition == "IfcBuildingElement" ||
                        docBaseEntity.BaseDefinition == "IfcReinforcingElement" || docBaseEntity.BaseDefinition == "IfcFlowSegment" || docBaseEntity.BaseDefinition == "IfcFeatureElement" ||
                        docBaseEntity.BaseDefinition == "IfcContext" || docBaseEntity.BaseDefinition == "IfcSpatialStructureElement" || docBaseEntity.BaseDefinition == "IfcFacility" ||
                        docBaseEntity.BaseDefinition == "IfcFacilityPart")
                    {
                        this.ChangeTemplate(this.m_project.GetTemplate(DocTemplateDefinition.guidTemplatePsetObject));

                        string[]        psetParamNames = this.Concept.Definition.GetParameterNames();
                        DocTemplateItem pset           = new DocTemplateItem();
                        pset.Name = form.SelectedPropertySet.Name;

                        if (form.SelectedPropertySet.Name == "Pset_ElementCommon")
                        {
                            pset.Name = form.SelectedPropertySet.Name.Replace("Element", docBaseEntity.Name);
                        }

                        pset.RuleParameters = "PsetName=" + pset.Name;
                        if (this.Concept.Items.Count == 0)
                        {
                            this.Concept.Items.Add(pset);
                        }
                        else
                        {
                            bool addItem = true;
                            foreach (DocTemplateItem existingPsetDefinition in this.Concept.Items)
                            {
                                if (existingPsetDefinition.Name == pset.Name)
                                {
                                    addItem = false;
                                }
                            }
                            if (addItem)
                            {
                                this.Concept.Items.Add(pset);
                            }
                        }

                        DocTemplateUsage            propertyConcept = new DocTemplateUsage();
                        DocPropertyTemplateTypeEnum propertyType    = form.SelectedProperty.PropertyType;
                        propertyConcept.Operator = DocTemplateOperator.And;
                        DocTemplateItem property = new DocTemplateItem();
                        string          psetName = pset.Name;
                        propertyConcept.Name = String.Join(" ", Regex.Split(form.SelectedProperty.Name, @"(?<!^)(?=[A-Z])"));
                        switch (propertyType)
                        {
                        case DocPropertyTemplateTypeEnum.P_SINGLEVALUE:
                            //propertyConcept.Name = "Single Value";
                            //propertyRule.RuleParameters = parameterNames[0] + "[Value]=" + "'" + form.SelectedProperty.Name + "'" + parameterNames[1] + "[Type]=" + "'" + form.SelectedProperty.PrimaryDataType + "'";
                            propertyConcept.Definition = this.m_project.GetTemplate(DocTemplateDefinition.guidTemplatePropertySingle);
                            //parameterNames = property.Definition.GetParameterNames();
                            property.RuleParameters = propertyConcept.Definition.GetParameterNames()[0] + "=" + form.SelectedProperty.Name + ";" + propertyConcept.Definition.GetParameterNames()[1] + "=" + form.SelectedProperty.PrimaryDataType + ";";
                            CreateAndAssignProperty(form, propertyConcept, property, psetName);
                            break;

                        case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE:
                            //propertyConcept.Name = "Enumerated Value";
                            propertyConcept.Definition = this.m_project.GetTemplate(DocTemplateDefinition.guidTemplatePropertyEnumerated);
                            //parameterNames = property.Definition.GetParameterNames();
                            property.RuleParameters = propertyConcept.Definition.GetParameterNames()[0] + "=" + form.SelectedProperty.Name + ";" + propertyConcept.Definition.GetParameterNames()[1] + "=" + form.SelectedProperty.PrimaryDataType + ";";
                            CreateAndAssignProperty(form, propertyConcept, property, psetName);
                            break;

                        case DocPropertyTemplateTypeEnum.P_LISTVALUE:
                            propertyConcept.Definition = this.m_project.GetTemplate(DocTemplateDefinition.guidTemplatePropertyList);
                            property.RuleParameters    = propertyConcept.Definition.GetParameterNames()[0] + "=" + form.SelectedProperty.Name + ";" + propertyConcept.Definition.GetParameterNames()[1] + "=" + form.SelectedProperty.PrimaryDataType + ";";
                            CreateAndAssignProperty(form, propertyConcept, property, psetName);
                            break;

                        case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE:
                            propertyConcept.Definition = this.m_project.GetTemplate(DocTemplateDefinition.guidTemplatePropertyBounded);
                            property.RuleParameters    = propertyConcept.Definition.GetParameterNames()[0] + "=" + form.SelectedProperty.Name + ";" + propertyConcept.Definition.GetParameterNames()[1] + "=" + form.SelectedProperty.PrimaryDataType + ";";
                            CreateAndAssignProperty(form, propertyConcept, property, psetName);
                            break;

                        case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE:
                            propertyConcept.Definition = this.m_project.GetTemplate(DocTemplateDefinition.guidTemplatePropertyReference);
                            property.RuleParameters    = propertyConcept.Definition.GetParameterNames()[0] + "=" + form.SelectedProperty.Name + ";" + propertyConcept.Definition.GetParameterNames()[1] + "=" + form.SelectedProperty.PrimaryDataType + ";";
                            CreateAndAssignProperty(form, propertyConcept, property, psetName);
                            break;

                        case DocPropertyTemplateTypeEnum.P_TABLEVALUE:
                            propertyConcept.Definition = this.m_project.GetTemplate(DocTemplateDefinition.guidTemplatePropertyTable);
                            property.RuleParameters    = propertyConcept.Definition.GetParameterNames()[0] + "=" + form.SelectedProperty.Name + ";" + propertyConcept.Definition.GetParameterNames()[1] + "=" + form.SelectedProperty.PrimaryDataType + ";";
                            CreateAndAssignProperty(form, propertyConcept, property, psetName);
                            break;
                        }

                        //foreach(DocModelRule rule in property.Definition.Rules)
                        //{
                        //    if (!string.IsNullOrEmpty(rule.Identification))
                        //    {

                        //    }
                        //}
                    }
                    else
                    {
                        CvtValuePath valuepath = CvtValuePath.Parse(value, mapEntity);
                        this.ChangeTemplate(valuepath.ToTemplateDefinition());
                    }
                }
            }
        }
Exemplo n.º 15
0
 private void dataGridViewConceptRules_UserAddedRow(object sender, DataGridViewRowEventArgs e)
 {
     DocTemplateItem dti = new DocTemplateItem();
     if (this.m_conceptleaf != null)
     {
         this.m_conceptleaf.Items.Add(dti);
     }
     else
     {
         this.m_conceptroot.ApplicableItems.Add(dti);
     }
     e.Row.Tag = dti;
 }
Exemplo n.º 16
0
 internal static TemplateRule ExportMvdItem(DocTemplateItem docRule)
 {
     TemplateRule mvdTemplateRule = new TemplateRule();
     mvdTemplateRule.RuleID = docRule.RuleInstanceID;
     mvdTemplateRule.Description = docRule.Documentation;
     mvdTemplateRule.Parameters = docRule.RuleParameters;
     return mvdTemplateRule;
 }
Exemplo n.º 17
0
 private void dataGridViewConceptRules_UserAddedRow(object sender, DataGridViewRowEventArgs e)
 {
     DocTemplateItem dti = new DocTemplateItem();
     this.m_conceptleaf.Items.Add(dti);
     e.Row.Tag = dti;
 }
Exemplo n.º 18
0
        /// <summary>
        /// Recursively copies concepts
        /// </summary>
        /// <param name="docSource"></param>
        /// <param name="docTarget"></param>
        private static void CopyTemplateUsage(DocTemplateUsage docSource, DocTemplateUsage docTarget)
        {
            docTarget.Name = docSource.Name;
            docTarget.Documentation = docSource.Documentation;
            docTarget.Author = docSource.Author;
            docTarget.Copyright = docSource.Copyright;
            docTarget.Owner = docSource.Owner;
            docTarget.Definition = docSource.Definition;

            foreach (DocTemplateItem docSourceItem in docSource.Items)
            {
                DocTemplateItem docTargetItem = new DocTemplateItem();
                docTarget.Items.Add(docTargetItem);

                docTargetItem.Name = docSourceItem.Name;
                docTargetItem.Documentation = docSourceItem.Documentation;
                docTargetItem.RuleInstanceID = docSourceItem.RuleInstanceID;
                docTargetItem.RuleParameters = docSourceItem.RuleParameters;
                docTargetItem.Optional = docSourceItem.Optional;

                foreach (DocTemplateUsage docSourceInner in docSourceItem.Concepts)
                {
                    DocTemplateUsage docTargetInner = new DocTemplateUsage();
                    docTargetItem.Concepts.Add(docTargetInner);
                    CopyTemplateUsage(docSourceInner, docTargetInner);
                }
            }
        }
Exemplo n.º 19
0
        private void BuildConceptForPropertySets(DocConceptRoot docRoot, DocTemplateDefinition docTemplatePset, DocPropertySet[] psets)
        {
            DocTemplateUsage docConcept = null;

            // get any existing concept for psets
            foreach (DocTemplateUsage docExistConcept in docRoot.Concepts)
            {
                if (docExistConcept.Definition == docTemplatePset)
                {
                    docConcept = docExistConcept;
                    break;
                }
            }

            if (psets.Length > 0)
            {
                if (docConcept == null)
                {
                    docConcept = new DocTemplateUsage();
                    docConcept.Definition = docTemplatePset;
                    docRoot.Concepts.Add(docConcept);

                    LoadNode(this.treeView.SelectedNode, docConcept, docConcept.Name, false);
                }

                // remove old listings
                for (int iExist = docConcept.Items.Count - 1; iExist >= 0; iExist--)
                {
                    docConcept.Items[iExist].Delete();
                    docConcept.Items.RemoveAt(iExist);
                }

                foreach (DocPropertySet docPset in psets)
                {
                    //if (docPset.PropertySetType == "PSET_OCCURRENCEDRIVEN" ||
                    //    docPset.PropertySetType == "PSET_TYPEDRIVENOVERRIDE")
                    {
                        // add new, in order
                        DocTemplateItem docItemPset = new DocTemplateItem();
                        docItemPset.RuleParameters = "Name=" + docPset.Name + ";";
                        docConcept.Items.Add(docItemPset);

                        //... predefined type

                        //... properties...
                        foreach (DocProperty docProp in docPset.Properties)
                        {
                            DocTemplateDefinition docInnerTemplate = null;
                            switch (docProp.PropertyType)
                            {
                                case DocPropertyTemplateTypeEnum.P_SINGLEVALUE:
                                    docInnerTemplate = this.m_project.GetTemplate(new Guid("6655f6d0-29a8-47b8-8f3d-c9fce9c9a620"));
                                    break;

                                case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE:
                                    docInnerTemplate = this.m_project.GetTemplate(new Guid("3d67a2d2-761d-44d9-a09e-b7fbb1fa5632"));
                                    break;

                                case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE:
                                    docInnerTemplate = this.m_project.GetTemplate(new Guid("c148a099-c351-43a8-9266-5f3de0b45a95"));
                                    break;
                            }

                            if (docInnerTemplate != null)
                            {
                                DocTemplateUsage docInnerConcept = docItemPset.RegisterParameterConcept("Properties", docInnerTemplate);
                                DocTemplateItem docInnerItem = new DocTemplateItem();
                                docInnerItem.RuleParameters = "Name=" + docProp.Name + ";Value=" + docProp.PrimaryDataType + ";";
                                docInnerConcept.Items.Add(docInnerItem);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 20
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.º 21
0
        private void BuildConceptForPropertySets(DocConceptRoot docRoot, DocTemplateDefinition docTemplatePset, DocPropertySet[] psets)
        {
            DocTemplateUsage docConcept = null;

            // get any existing concept for psets
            foreach (DocTemplateUsage docExistConcept in docRoot.Concepts)
            {
                if (docExistConcept.Definition == docTemplatePset)
                {
                    docConcept = docExistConcept;
                    break;
                }
            }

            if (psets.Length > 0)
            {
                if (docConcept == null)
                {
                    docConcept = new DocTemplateUsage();
                    docConcept.Definition = docTemplatePset;
                    docRoot.Concepts.Add(docConcept);

                    LoadNode(this.treeView.SelectedNode, docConcept, docConcept.ToString(), false);
                }

                // remove old listings
                for (int iExist = docConcept.Items.Count - 1; iExist >= 0; iExist--)
                {
                    docConcept.Items[iExist].Delete();
                    docConcept.Items.RemoveAt(iExist);
                }

                foreach (DocPropertySet docPset in psets)
                {
                    //if (docPset.PropertySetType == "PSET_OCCURRENCEDRIVEN" ||
                    //    docPset.PropertySetType == "PSET_TYPEDRIVENOVERRIDE")
                    {
                        // add new, in order
                        DocTemplateItem docItemPset = new DocTemplateItem();
                        docItemPset.RuleParameters = "Name=" + docPset.Name + ";";
                        docConcept.Items.Add(docItemPset);

                        //... predefined type

                        //... properties...
                        int order = 0;
                        foreach (DocProperty docProp in docPset.Properties)
                        {
                            DocTemplateDefinition docInnerTemplate = null;
                            string suffix = String.Empty;
                            switch (docProp.PropertyType)
                            {
                                case DocPropertyTemplateTypeEnum.P_SINGLEVALUE:
                                    docInnerTemplate = this.m_project.GetTemplate(new Guid("6655f6d0-29a8-47b8-8f3d-c9fce9c9a620"));
                                    break;

                                case DocPropertyTemplateTypeEnum.P_BOUNDEDVALUE:
                                    docInnerTemplate = this.m_project.GetTemplate(new Guid("3d67a2d2-761d-44d9-a09e-b7fbb1fa5632"));
                                    break;

                                case DocPropertyTemplateTypeEnum.P_ENUMERATEDVALUE:
                                    docInnerTemplate = this.m_project.GetTemplate(new Guid("c148a099-c351-43a8-9266-5f3de0b45a95"));
                                    suffix = "Reference=" + docProp.SecondaryDataType.Substring(0, docProp.SecondaryDataType.IndexOf(':'));
                                    break;

                                case DocPropertyTemplateTypeEnum.P_LISTVALUE:
                                    docInnerTemplate = this.m_project.GetTemplate(new Guid("8e10b688-9179-4e3a-8db2-6abcaafe952d"));
                                    break;

                                case DocPropertyTemplateTypeEnum.P_TABLEVALUE:
                                    docInnerTemplate = this.m_project.GetTemplate(new Guid("35c947b0-6abc-4b13-8ec7-696ef2041721"));
                                    suffix = "Reference=" + docProp.SecondaryDataType;
                                    break;

                                case DocPropertyTemplateTypeEnum.P_REFERENCEVALUE:
                                    docInnerTemplate = this.m_project.GetTemplate(new Guid("e20bc116-889b-46cc-b193-31b3e2376a8e"));
                                    suffix = "Reference=" + docProp.SecondaryDataType;
                                    break;
                            }

                            if (docInnerTemplate != null)
                            {
                                order++;
                                DocTemplateUsage docInnerConcept = docItemPset.RegisterParameterConcept("Properties", docInnerTemplate);
                                DocTemplateItem docInnerItem = new DocTemplateItem();
                                docInnerItem.RuleParameters = "Order=" + order + ";Name=" + docProp.Name + ";Value=" + docProp.PrimaryDataType + ";" + suffix;
                                docInnerConcept.Items.Add(docInnerItem);
                            }
                        }
                    }
                }
            }
        }