Beispiel #1
0
        void typeIcons1_OnTypeSelected(object sender, EventArgs e)
        {
            Type t = sender as Type;

            if (t != null)
            {
                enumOperatorCategory     category = enumOperatorCategory.Decimal;
                EventArgsEletementSelect ec       = e as EventArgsEletementSelect;
                if (ec != null)
                {
                    category = ec.Category;
                }
                MathNode newNode = null;
                MathNode node    = mathExpCtrl1.FocusedNode;
                if (node != null && node != mathExpCtrl1.Root[0])
                {
                    newNode = mathExpCtrl1.ReplaceMathNode(node, t);
                }
                else
                {
                    newNode = mathExpCtrl1.AddMathNode(t);
                }
                mathExpCtrl1.RefreshVariableMap();
                if (newNode != null)
                {
                    MathNodeValue nv = newNode as MathNodeValue;
                    if (nv != null)
                    {
                        if (category == enumOperatorCategory.Integer)
                        {
                            nv.ValueType = new RaisDataType(typeof(Int32));
                        }
                        else if (category == enumOperatorCategory.Logic)
                        {
                            nv.ValueType = new RaisDataType(typeof(bool));
                        }
                        else if (category == enumOperatorCategory.String)
                        {
                            nv.ValueType = new RaisDataType(typeof(string));
                        }
                    }
                    object[] vs = t.GetCustomAttributes(typeof(UseModalSelectorAttribute), true);
                    if (vs != null && vs.Length > 0)
                    {
                        mathExpCtrl1.SetNodeSelection(newNode);
                        mathExpCtrl1.DoDoubleClick();
                    }
                }
            }
        }
Beispiel #2
0
        public void AddMathNode(Type type)
        {
            enumOperatorCategory category = MathNodeCategoryAttribute.GetTypeCategory(type);

            if ((category & enumOperatorCategory.Logic) != 0)
            {
                if (!typeIconsLogic.Contains(type))
                {
                    typeIconsLogic.AddIcon(type);
                }
            }
            if ((category & enumOperatorCategory.Integer) != 0)
            {
                if (!typeIconsInteger.Contains(type))
                {
                    typeIconsInteger.AddIcon(type);
                }
            }
            if ((category & enumOperatorCategory.String) != 0)
            {
                if (!typeIconsString.Contains(type))
                {
                    typeIconsString.AddIcon(type);
                }
            }
            if ((category & enumOperatorCategory.System) != 0)
            {
                if (!typeIconsOther.Contains(type))
                {
                    typeIconsOther.AddIcon(type);
                }
            }
            if ((category & enumOperatorCategory.Decimal) != 0)
            {
                if (!typeIcons1.Contains(type))
                {
                    typeIcons1.AddIcon(type);
                }
            }
        }
 public EventArgsEletementSelect(enumOperatorCategory category)
 {
     _cat = category;
 }
 public MathNodeCategoryAttribute(enumOperatorCategory category)
 {
     _category = category;
 }
Beispiel #5
0
        public MathExpEditor()
        {
            InitializeComponent();
            //
            mathExpCtrl1.SetMathEditor(this);
            //
            List <Type> NodeTypes;
            List <Type> NodeTypesLogic;
            List <Type> NodeTypesInteger;
            List <Type> NodeTypesString;
            List <Type> NodeTypesOther;

            propertyGrid1.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid1_PropertyValueChanged);
            propertyGrid2.PropertyValueChanged += new PropertyValueChangedEventHandler(propertyGrid2_PropertyValueChanged);
            tabGreek.Text    = new string((char)0x03b1, 1) + " - " + new string((char)0x03c9, 1);
            NodeTypes        = new List <Type>();     //decimal nodes
            NodeTypesLogic   = new List <Type>();     //logic nodes
            NodeTypesInteger = new List <Type>();     //integer nodes
            NodeTypesString  = new List <Type>();     //string nodes
            NodeTypesOther   = new List <Type>();     //other nodes
            //load types in this DLL
            Type[]      tps0  = this.GetType().Assembly.GetExportedTypes();
            List <Type> types = MathNode.MathNodePlugIns;

            Type[] tps = new Type[tps0.Length + types.Count];
            tps0.CopyTo(tps, 0);
            types.CopyTo(tps, tps0.Length);
            for (int i = 0; i < tps.Length; i++)
            {
                enumOperatorCategory opCat = MathNodeCategoryAttribute.GetTypeCategory(tps[i]);
                if (opCat != enumOperatorCategory.Internal)
                {
                    if (!tps[i].IsAbstract && tps[i].IsSubclassOf(typeof(MathNode)))
                    {
                        if (!tps[i].Equals(typeof(MathNodeRoot)))
                        {
                            if ((opCat & enumOperatorCategory.Logic) != 0)
                            {
                                NodeTypesLogic.Add(tps[i]);
                            }
                            if ((opCat & enumOperatorCategory.Integer) != 0)
                            {
                                NodeTypesInteger.Add(tps[i]);
                            }
                            if ((opCat & enumOperatorCategory.String) != 0)
                            {
                                NodeTypesString.Add(tps[i]);
                            }
                            if ((opCat & enumOperatorCategory.System) != 0)
                            {
                                if (ExcludeProjectItem)
                                {
                                    object[] vs = tps[i].GetCustomAttributes(typeof(ProjectItemAttribute), true);
                                    if (vs != null && vs.Length > 0)
                                    {
                                        continue;
                                    }
                                }
                                NodeTypesOther.Add(tps[i]);
                            }
                            if ((opCat & enumOperatorCategory.Decimal) != 0)
                            {
                                NodeTypes.Add(tps[i]);
                            }
                        }
                    }
                }
            }
            //load types from configuration XML
            string file = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(this.GetType().Assembly.Location), "MathTypes.xml");

            if (System.IO.File.Exists(file))
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(file);
                if (doc.DocumentElement != null)
                {
                    for (int i = 0; i < doc.DocumentElement.ChildNodes.Count; i++)
                    {
                        try
                        {
                            Type t = XmlUtil.GetLibTypeAttribute(doc.DocumentElement.ChildNodes[i]);
                            enumOperatorCategory opCat = MathNodeCategoryAttribute.GetTypeCategory(t);
                            if (opCat != enumOperatorCategory.Internal)
                            {
                                if ((opCat & enumOperatorCategory.Logic) != 0)
                                {
                                    if (!NodeTypesLogic.Contains(t))
                                    {
                                        NodeTypesLogic.Add(t);
                                    }
                                }
                            }
                            if ((opCat & enumOperatorCategory.Integer) != 0)
                            {
                                if (!NodeTypesInteger.Contains(t))
                                {
                                    NodeTypesInteger.Add(t);
                                }
                            }
                            if ((opCat & enumOperatorCategory.String) != 0)
                            {
                                if (!NodeTypesString.Contains(t))
                                {
                                    NodeTypesString.Add(t);
                                }
                            }
                            if ((opCat & enumOperatorCategory.System) != 0)
                            {
                                if (!NodeTypesOther.Contains(t))
                                {
                                    NodeTypesOther.Add(t);
                                }
                            }
                            if ((opCat & enumOperatorCategory.Decimal) != 0)
                            {
                                if (!NodeTypes.Contains(t))
                                {
                                    NodeTypes.Add(t);
                                }
                            }
                        }
                        catch (Exception err)
                        {
                            MessageBox.Show(err.Message);
                        }
                    }
                }
            }
            typeIcons1.Category        = enumOperatorCategory.Decimal;
            typeIcons1.lblTooltips     = lblTooltips;
            typeIcons1.OnTypeSelected += new EventHandler(typeIcons1_OnTypeSelected);
            typeIcons1.LoadData(NodeTypes);

            typeIconsLogic.lblTooltips     = lblTooltips;
            typeIconsLogic.Category        = enumOperatorCategory.Logic;
            typeIconsLogic.OnTypeSelected += new EventHandler(typeIcons1_OnTypeSelected);
            typeIconsLogic.LoadData(NodeTypesLogic);

            typeIconsInteger.lblTooltips     = lblTooltips;
            typeIconsInteger.Category        = enumOperatorCategory.Integer;
            typeIconsInteger.OnTypeSelected += new EventHandler(typeIcons1_OnTypeSelected);
            typeIconsInteger.LoadData(NodeTypesInteger);

            typeIconsString.lblTooltips     = lblTooltips;
            typeIconsString.Category        = enumOperatorCategory.String;
            typeIconsString.OnTypeSelected += new EventHandler(typeIcons1_OnTypeSelected);
            typeIconsString.LoadData(NodeTypesString);

            typeIconsOther.lblTooltips     = lblTooltips;
            typeIconsOther.Category        = enumOperatorCategory.System;
            typeIconsOther.OnTypeSelected += new EventHandler(typeIcons1_OnTypeSelected);
            typeIconsOther.LoadData(NodeTypesOther);

            //
            greekLetters1.OnLetterSelected += new EventHandler(greekLetters1_OnLetterSelected);
            //
            mathExpCtrl1.OnFinish         += new EventHandler(btOK_Click);
            mathExpCtrl1.OnCancel         += new EventHandler(btCancel_Click);
            mathExpCtrl1.OnCreateCompound += new EventHandler(mathExpCtrl1_OnCreateCompound);
            //
            //
            MethodType mt = (MethodType)MathNode.GetService(typeof(MethodType));

            typeIconsOther.SetIconVisible(typeof(MathNodeArgument), (mt != null && mt.ParameterCount > 0));
            //
            propertyGrid2.SetOnValueChange(onValueChanged);
            //
            if (Clipboard.ContainsData("MathNode"))
            {
                btPaste.Enabled    = true;
                btPaste.ImageIndex = IMG_Paste_Enable;
            }
            tabControl1.SelectedTab = tabPageOther;
            typeIconsOther.LoadIcons();
        }