Example #1
0
        private void toolStripButtonRuleRef_Click(object sender, EventArgs e)
        {
            DocOp op = this.GetSelectedOp();

            if (op is DocOpStatement)
            {
                DocOpStatement statement = (DocOpStatement)op;
                if (this.Rule is DocModelRuleAttribute)
                {
                    DocOpParameter param = new DocOpParameter();
                    param.Operation     = DocOpCode.LoadArgument;
                    param.AttributeRule = (DocModelRuleAttribute)this.Rule;
                    statement.Value     = param;
                }
                else if (this.Rule is DocModelRuleEntity)
                {
                    DocOpReference opref = new DocOpReference();
                    opref.Operation  = DocOpCode.LoadField;
                    opref.EntityRule = (DocModelRuleEntity)this.Rule;
                    statement.Value  = opref;
                }

                this.treeViewRules.SelectedNode.Text = op.ToString(this.Template);
            }
        }
Example #2
0
        public void DoInsert()
        {
            if (this.Template == null)
            {
                return;
            }

            DocModelRule docModelRule = this.Rule;

            if (docModelRule == null)
            {
                return;
            }

            if (!(this.Rule is DocModelRuleEntity))
            {
                return;
            }

            TreeNode tnSelect = this.treeViewRules.SelectedNode;

            DocOpLiteral oplit = new DocOpLiteral();

            oplit.Operation = DocOpCode.LoadString;
            oplit.Literal   = null;

            DocOpStatement op = new DocOpStatement();

            op.Operation = DocOpCode.CompareEqual;
            op.Value     = oplit;

            DocOpReference opref = new DocOpReference();

            opref.Operation  = DocOpCode.NoOperation;            // ldfld...
            opref.EntityRule = this.Rule as DocModelRuleEntity;
            op.Reference     = opref;

            if (tnSelect != null)
            {
                DocOpExpression opSelect = tnSelect.Tag as DocOpExpression;
                if (tnSelect.Tag is DocModelRuleConstraint)
                {
                    opSelect = ((DocModelRuleConstraint)tnSelect.Tag).Expression;
                }


                // convert existing node into new Logical operator

                DocOpLogical opLog = new DocOpLogical();
                opLog.Operation   = DocOpCode.And;
                opLog.ExpressionA = opSelect;
                opLog.ExpressionB = op;

                if (tnSelect.Tag is DocModelRuleConstraint)
                {
                    DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnSelect.Tag;
                    dmr.Expression = opLog;
                }
                else if (tnSelect.Parent != null)
                {
                    DocOpLogical opParent = tnSelect.Parent.Tag as DocOpLogical;
                    if (tnSelect.Parent.Tag is DocModelRuleConstraint)
                    {
                        opParent = ((DocModelRuleConstraint)tnSelect.Parent.Tag).Expression as DocOpLogical;
                    }

                    if (tnSelect.Parent.Nodes[0] == tnSelect)
                    {
                        opParent.ExpressionA = opLog;
                    }
                    else if (tnSelect.Parent.Nodes[1] == tnSelect)
                    {
                        opParent.ExpressionB = opLog;
                    }
                }
                else if (tnSelect.Parent != null && tnSelect.Parent.Nodes[1] == tnSelect)
                {
                    DocOpLogical opParent = (DocOpLogical)tnSelect.Parent.Tag;
                    opParent.ExpressionB = opLog;
                }

                this.LoadRules(op);
            }
            else
            {
                // create new constraint
                DocModelRuleConstraint docCon = new DocModelRuleConstraint();
                docCon.Expression = op;
                docModelRule.Rules.Add(docCon);
                docCon.ParentRule = docModelRule;

                TreeNode tnCon = new TreeNode();
                tnCon.Tag                = docCon;
                tnCon.Text               = op.ToString(this.Template);
                tnCon.ImageIndex         = 3;
                tnCon.SelectedImageIndex = tnCon.ImageIndex;
                this.treeViewRules.Nodes.Add(tnCon);

                this.treeViewRules.SelectedNode = tnCon;
            }
        }
Example #3
0
        private void LoadRules(List <DocModelRule> list, DocModelRule parentrule)
        {
            if (list == null)
            {
                return;
            }

            foreach (DocModelRule docRule in list)
            {
                if (docRule is DocModelRuleConstraint)
                {
                    DocModelRuleConstraint rc = (DocModelRuleConstraint)docRule;
                    TreeNode tn = new TreeNode();
                    tn.Tag        = docRule;
                    tn.Text       = docRule.Description;
                    tn.ImageIndex = 4;
                    this.treeViewRules.Nodes.Add(tn);

                    // backward compatibility before V6.1 -- generate rule from syntax
                    if (rc.Expression == null && docRule.Description != null)
                    {
                        DocOpReference reference = new DocOpReference();
                        reference.EntityRule = parentrule as DocModelRuleEntity;

                        DocOpLiteral literal = new DocOpLiteral();

                        DocOpStatement statement = new DocOpStatement();
                        statement.Reference = reference;
                        statement.Value     = literal;
                        rc.Expression       = statement;

                        string value = docRule.Description;
                        int    index = value.IndexOfAny(new char[] { '=', '!', '>', '<' });
                        if (index > 0)
                        {
                            string metric = value.Substring(0, index);
                            switch (metric)
                            {
                            case "Value":
                                ///...
                                break;

                            case "Length":
                                ///...
                                break;
                            }

                            string oper  = value.Substring(index, 1);
                            string bench = value.Substring(index + 1);
                            if (value.Length > index + 1 && value[index + 1] == '=')
                            {
                                oper  = value.Substring(index, 2);
                                bench = value.Substring(index + 2);
                            }

                            switch (oper)
                            {
                            case "=":
                                statement.Operation = DocOpCode.CompareEqual;
                                break;

                            case "!=":
                                statement.Operation = DocOpCode.CompareNotEqual;
                                break;

                            case "<=":
                                statement.Operation = DocOpCode.CompareLessThanOrEqual;
                                break;

                            case "<":
                                statement.Operation = DocOpCode.CompareLessThan;
                                break;

                            case ">=":
                                statement.Operation = DocOpCode.CompareGreaterThanOrEqual;
                                break;

                            case ">":
                                statement.Operation = DocOpCode.CompareGreaterThan;
                                break;
                            }

                            literal.Literal = bench;
                        }
                    }

                    LoadOpExpression(tn, rc.Expression);
                }

                LoadRules(docRule.Rules, docRule);
            }
        }
Example #4
0
        private DocModelRuleEntity ToModelRule()
        {
            if (this.Type == null)
            {
                return(null);
            }

            DocModelRuleEntity docRuleEntity = new DocModelRuleEntity();

            docRuleEntity.Name = this.Type.Name;

            if (this.Property != null)
            {
                DocModelRuleAttribute docRuleAttr = new DocModelRuleAttribute();
                docRuleAttr.Name = this.Property.Name;
                docRuleEntity.Rules.Add(docRuleAttr);
                docRuleAttr.ParentRule = docRuleEntity;

                if (this.InnerPath != null)
                {
                    DocModelRuleEntity docInner = this.InnerPath.ToModelRule();
                    if (docInner != null)
                    {
                        docRuleAttr.Rules.Add(docInner);
                        docInner.ParentRule = docRuleAttr;
                    }

                    if (this.Identifier != null)
                    {
                        // traverse to the default attribute

                        DocModelRuleEntity docApplicableRule = docInner;
                        if (this.InnerPath.Type.Name.Equals("IfcRelDefinesByProperties"))
                        {
                            // hack for back compat
                            DocModelRuleAttribute docPsetAttr = docInner.Rules[0] as DocModelRuleAttribute;
                            DocModelRuleEntity    docPsetEnt  = docPsetAttr.Rules[0] as DocModelRuleEntity;

                            docApplicableRule = docPsetEnt;
                        }

                        DocModelRuleAttribute docWhereAttr = new DocModelRuleAttribute();
                        docWhereAttr.Name = "Name";//... dynamically check...
                        docApplicableRule.Rules.Add(docWhereAttr);
                        docWhereAttr.ParentRule = docApplicableRule;

                        DocModelRuleEntity docWhereEnt = new DocModelRuleEntity();
                        docWhereEnt.Name = "IfcLabel";//... dynamically check...
                        docWhereAttr.Rules.Add(docWhereEnt);
                        docWhereEnt.ParentRule = docWhereAttr;

                        DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint();

                        // general case
                        docWhereEnt.Rules.Add(docRuleConstraint);
                        docRuleConstraint.ParentRule = docWhereEnt;


                        DocOpLiteral oplit = new DocOpLiteral();
                        oplit.Operation = DocOpCode.LoadString;
                        oplit.Literal   = this.Identifier;

                        DocOpStatement op = new DocOpStatement();
                        op.Operation = DocOpCode.CompareEqual;
                        op.Value     = oplit;

                        DocOpReference opref = new DocOpReference();
                        opref.Operation  = DocOpCode.NoOperation; // ldfld...
                        opref.EntityRule = docWhereEnt;
                        op.Reference     = opref;

                        docRuleConstraint.Expression = op;
                    }
                }
            }


            return(docRuleEntity);
        }
Example #5
0
        public void DoInsert()
        {
            if (this.m_template == null)
            {
                return;
            }

            if (this.treeViewTemplate.Nodes.Count == 0)
            {
                DocEntity docEntityBase = null;
                if (this.m_parent is DocTemplateDefinition)
                {
                    string classname = ((DocTemplateDefinition)this.m_parent).Type;
                    docEntityBase = this.m_project.GetDefinition(classname) as DocEntity;
                }

                // get selected entity
                DocEntity docEntityThis = this.m_project.GetDefinition(this.m_template.Type) as DocEntity;

                using (FormSelectEntity form = new FormSelectEntity(docEntityBase, docEntityThis, this.m_project, SelectDefinitionOptions.Entity))
                {
                    DialogResult res = form.ShowDialog(this);
                    if (res == DialogResult.OK && form.SelectedEntity != null)
                    {
                        this.m_template.Type = form.SelectedEntity.Name;
                        this.ChangeTemplate(this.m_template);
                        this.LoadTemplateGraph();
                        this.ContentChanged(this, EventArgs.Empty);
                    }
                }

                return;
            }

            if (this.m_attribute != null && !String.IsNullOrEmpty(this.m_attribute.DefinedType))
            {
                DocTemplateDefinition docTemplate  = this.m_template;
                DocAttribute          docAttribute = this.m_attribute;

                string entityname = null;
                switch (this.m_attribute.DefinedType)
                {
                case "BOOLEAN":
                case "LOGICAL":
                case "BINARY":
                case "STRING":
                case "REAL":
                case "INTEGER":
                case "NUMBER":
                    entityname = this.m_attribute.DefinedType;
                    break;

                default:
                {
                    // qualify schema
                    DocObject docobj = null;

                    if (!String.IsNullOrEmpty(this.m_template.Code))
                    {
                        foreach (DocSection docSection in this.m_project.Sections)
                        {
                            foreach (DocSchema docSchema in docSection.Schemas)
                            {
                                if (docSchema.Name.Equals(this.m_template.Code, StringComparison.OrdinalIgnoreCase))
                                {
                                    docobj = docSchema.GetDefinition(docAttribute.DefinedType);
                                    break;
                                }
                            }
                        }
                    }

                    if (docobj == null)
                    {
                        docobj = this.m_project.GetDefinition(docAttribute.DefinedType);
                    }

                    using (FormSelectEntity form = new FormSelectEntity((DocDefinition)docobj, null, this.m_project, SelectDefinitionOptions.Entity | SelectDefinitionOptions.Type))
                    {
                        DialogResult res = form.ShowDialog(this);
                        if (res == DialogResult.OK && form.SelectedEntity != null)
                        {
                            entityname = form.SelectedEntity.Name;
                        }
                    }
                    break;
                }
                }

                if (entityname != null)
                {
                    // get or add attribute rule
                    TreeNode tn = this.treeViewTemplate.SelectedNode;
                    DocModelRuleAttribute docRuleAtt = null;
                    if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleAttribute)
                    {
                        docRuleAtt = (DocModelRuleAttribute)this.treeViewTemplate.SelectedNode.Tag;
                    }
                    else
                    {
                        docRuleAtt      = new DocModelRuleAttribute();
                        docRuleAtt.Name = docAttribute.Name;

                        if (this.treeViewTemplate.SelectedNode.Tag is DocModelRuleEntity)
                        {
                            DocModelRuleEntity docRuleEnt = (DocModelRuleEntity)this.treeViewTemplate.SelectedNode.Tag;
                            docRuleEnt.Rules.Add(docRuleAtt);
                            docRuleAtt.ParentRule = docRuleEnt;
                        }
                        else if (this.treeViewTemplate.SelectedNode.Tag is DocTemplateDefinition)
                        {
                            docTemplate.Rules.Add(docRuleAtt);
                            docRuleAtt.ParentRule = null;
                        }

                        tn = this.LoadTemplateGraph(tn, docRuleAtt);
                    }

                    // get and add entity rule
                    DocModelRuleEntity docRuleEntity = new DocModelRuleEntity();
                    docRuleEntity.Name = entityname;
                    docRuleAtt.Rules.Add(docRuleEntity);
                    docRuleEntity.ParentRule           = docRuleAtt;
                    this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(tn, docRuleEntity);

                    // copy to child templates
                    docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath);

                    this.m_selection = docRuleEntity;
                    this.ContentChanged(this, EventArgs.Empty);
                    this.SelectionChanged(this, EventArgs.Empty);
                }
            }
            else
            {
                // pick attribute, including attribute that may be on subtype
                DocModelRule rule = null;
                if (this.treeViewTemplate.SelectedNode != null)
                {
                    rule = this.treeViewTemplate.SelectedNode.Tag as DocModelRule;
                }

                //if (rule == null)
                //   return;

                DocTemplateDefinition docTemplate = (DocTemplateDefinition)this.m_template;

                string typename = null;
                if (rule is DocModelRuleEntity)
                {
                    DocModelRuleEntity docRuleEntity = (DocModelRuleEntity)rule;
                    typename = docRuleEntity.Name;
                }
                else
                {
                    // get applicable entity of target (or parent entity rule)
                    typename = docTemplate.Type;
                }

                DocEntity docEntity = this.m_project.GetDefinition(typename) as DocEntity;
                if (docEntity == null)
                {
#if true // constraints now edited at operations
                    // launch dialog for constraint
                    using (FormConstraint form = new FormConstraint())
                    {
                        form.DataType = this.m_project.GetDefinition(typename) as DocType;

                        DialogResult res = form.ShowDialog(this);
                        if (res == DialogResult.OK)
                        {
                            DocModelRuleConstraint docRuleConstraint = new DocModelRuleConstraint();
                            rule.Rules.Add(docRuleConstraint);
                            docRuleConstraint.ParentRule = rule;
                            //docRuleConstraint.Description = form.Expression;
                            //docRuleConstraint.Name = form.Expression; // for viewing

                            DocOpLiteral oplit = new DocOpLiteral();
                            oplit.Operation = DocOpCode.LoadString;
                            oplit.Literal   = form.Literal;

                            DocOpStatement op = new DocOpStatement();
                            op.Operation = DocOpCode.CompareEqual;
                            op.Value     = oplit;

                            DocOpReference opref = new DocOpReference();
                            opref.Operation  = DocOpCode.NoOperation; // ldfld...
                            opref.EntityRule = rule as DocModelRuleEntity;
                            op.Reference     = opref;

                            docRuleConstraint.Expression = op;

                            this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleConstraint);

                            //update...this.upd

                            // copy to child templates
                            docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath);

                            this.ContentChanged(this, EventArgs.Empty);
                        }
                    }
#endif
                }
                else
                {
                    // launch dialog to pick attribute of entity
                    using (FormSelectAttribute form = new FormSelectAttribute(docEntity, this.m_project, null, true))
                    {
                        DialogResult res = form.ShowDialog(this);
                        if (res == DialogResult.OK && form.Selection != null)
                        {
                            // then add and update tree
                            DocModelRuleAttribute docRuleAttr = new DocModelRuleAttribute();
                            docRuleAttr.Name = form.Selection;
                            if (rule != null)
                            {
                                rule.Rules.Add(docRuleAttr);
                                docRuleAttr.ParentRule = rule;
                            }
                            else
                            {
                                docTemplate.Rules.Add(docRuleAttr);
                                docRuleAttr.ParentRule = null;
                            }
                            this.treeViewTemplate.SelectedNode = this.LoadTemplateGraph(this.treeViewTemplate.SelectedNode, docRuleAttr);

                            // copy to child templates
                            docTemplate.PropagateRule(this.treeViewTemplate.SelectedNode.FullPath);
                        }
                    }
                }
            }
        }
Example #6
0
        public void DoInsert()
        {
            if (this.Template == null)
                return;

            DocModelRule docModelRule = this.Rule;
            if (docModelRule == null)
                return;

            if (!(this.Rule is DocModelRuleEntity))
                return;

            TreeNode tnSelect = this.treeViewRules.SelectedNode;

            DocOpLiteral oplit = new DocOpLiteral();
            oplit.Operation = DocOpCode.LoadString;
            oplit.Literal = null;

            DocOpStatement op = new DocOpStatement();
            op.Operation = DocOpCode.CompareEqual;
            op.Value = oplit;

            DocOpReference opref = new DocOpReference();
            opref.Operation = DocOpCode.NoOperation; // ldfld...
            opref.EntityRule = this.Rule as DocModelRuleEntity;
            op.Reference = opref;

            if (tnSelect != null)
            {
                DocOpExpression opSelect = tnSelect.Tag as DocOpExpression;
                if (tnSelect.Tag is DocModelRuleConstraint)
                {
                    opSelect = ((DocModelRuleConstraint)tnSelect.Tag).Expression;

                }


                // convert existing node into new Logical operator

                DocOpLogical opLog = new DocOpLogical();
                opLog.Operation = DocOpCode.And;
                opLog.ExpressionA = opSelect;
                opLog.ExpressionB = op;

                if (tnSelect.Tag is DocModelRuleConstraint)
                {
                    DocModelRuleConstraint dmr = (DocModelRuleConstraint)tnSelect.Tag;
                    dmr.Expression = opLog;
                }
                else if (tnSelect.Parent != null)
                {
                    DocOpLogical opParent = tnSelect.Parent.Tag as DocOpLogical;
                    if (tnSelect.Parent.Tag is DocModelRuleConstraint)
                    {
                        opParent = ((DocModelRuleConstraint)tnSelect.Parent.Tag).Expression as DocOpLogical;
                    }

                    if (tnSelect.Parent.Nodes[0] == tnSelect)
                    {
                        opParent.ExpressionA = opLog;
                    }
                    else if (tnSelect.Parent.Nodes[1] == tnSelect)
                    {
                        opParent.ExpressionB = opLog;
                    }
                }
                else if (tnSelect.Parent != null && tnSelect.Parent.Nodes[1] == tnSelect)
                {
                    DocOpLogical opParent = (DocOpLogical)tnSelect.Parent.Tag;
                    opParent.ExpressionB = opLog;
                }

                this.LoadRules(op);
            }
            else
            {
                // create new constraint
                DocModelRuleConstraint docCon = new DocModelRuleConstraint();
                docCon.Expression = op;
                docModelRule.Rules.Add(docCon);

                TreeNode tnCon = new TreeNode();
                tnCon.Tag = docCon;
                tnCon.Text = op.ToString(this.Template);
                tnCon.ImageIndex = 3;
                tnCon.SelectedImageIndex = tnCon.ImageIndex;
                this.treeViewRules.Nodes.Add(tnCon);

                this.treeViewRules.SelectedNode = tnCon;
            }

        }
Example #7
0
        private void toolStripButtonRuleRef_Click(object sender, EventArgs e)
        {
            DocOp op = this.GetSelectedOp();
            if (op is DocOpStatement)
            {
                DocOpStatement statement = (DocOpStatement)op;
                if (this.Rule is DocModelRuleAttribute)
                {
                    DocOpParameter param = new DocOpParameter();
                    param.Operation = DocOpCode.LoadArgument;
                    param.AttributeRule = (DocModelRuleAttribute)this.Rule;
                    statement.Value = param;
                }
                else if (this.Rule is DocModelRuleEntity)
                {
                    DocOpReference opref = new DocOpReference();
                    opref.Operation = DocOpCode.LoadField;
                    opref.EntityRule = (DocModelRuleEntity)this.Rule;
                    statement.Value = opref;
                }

                this.treeViewRules.SelectedNode.Text = op.ToString(this.Template);
            }
        }
Example #8
0
        private void LoadRules(List<DocModelRule> list, DocModelRule parentrule)
        {
            if (list == null)
                return;

            foreach (DocModelRule docRule in list)
            {
                if (docRule is DocModelRuleConstraint)
                {
                    DocModelRuleConstraint rc = (DocModelRuleConstraint)docRule;
                    TreeNode tn = new TreeNode();
                    tn.Tag = docRule;
                    tn.Text = docRule.Description;
                    tn.ImageIndex = 4;
                    this.treeViewRules.Nodes.Add(tn);

                    // backward compatibility before V6.1 -- generate rule from syntax
                    if (rc.Expression == null && docRule.Description != null)
                    {
                        DocOpReference reference = new DocOpReference();
                        reference.EntityRule = parentrule as DocModelRuleEntity;

                        DocOpLiteral literal = new DocOpLiteral();

                        DocOpStatement statement = new DocOpStatement();
                        statement.Reference = reference;
                        statement.Value = literal;
                        rc.Expression = statement;

                        string value = docRule.Description;
                        int index = value.IndexOfAny(new char[] { '=', '!', '>', '<' });
                        if (index > 0)
                        {
                            string metric = value.Substring(0, index);
                            switch (metric)
                            {
                                case "Value":
                                    ///...
                                    break;

                                case "Length":
                                    ///...
                                    break;
                            }

                            string oper = value.Substring(index, 1);
                            string bench = value.Substring(index + 1);
                            if (value.Length > index + 1 && value[index + 1] == '=')
                            {
                                oper = value.Substring(index, 2);
                                bench = value.Substring(index + 2);
                            }

                            switch (oper)
                            {
                                case "=":
                                    statement.Operation = DocOpCode.CompareEqual;
                                    break;

                                case "!=":
                                    statement.Operation = DocOpCode.CompareNotEqual;
                                    break;

                                case "<=":
                                    statement.Operation = DocOpCode.CompareLessThanOrEqual;
                                    break;

                                case "<":
                                    statement.Operation = DocOpCode.CompareLessThan;
                                    break;

                                case ">=":
                                    statement.Operation = DocOpCode.CompareGreaterThanOrEqual;
                                    break;

                                case ">":
                                    statement.Operation = DocOpCode.CompareGreaterThan;
                                    break;
                            }

                            literal.Literal = bench;
                        }
                    }

                    LoadOpExpression(tn, rc.Expression);
                }

                LoadRules(docRule.Rules, docRule);
            }
        }