Ejemplo n.º 1
0
        public MotionOperationScriptFunction(IMotionOperationBase operation)
        {
            if (operation == null)
            {
                throw new ArgumentNullException("operation", "'operation' cannot be null");
            }
            List <Type> validTypes = new List <Type> {
                typeof(IMotionOperationGeneral), typeof(IMotionOperationEditObject), typeof(IMotionOperationCreateObject), typeof(IMotionOperationOutputSequence)
            };

            if (!validTypes.Any(t => t.IsInstanceOfType(operation)))
            {
                StringBuilder msg = new StringBuilder();
                for (int i = 0; i < validTypes.Count; i++)
                {
                    if (i == validTypes.Count - 1)
                    {
                        msg.Append(" or ");
                    }
                    else if (i != 0)
                    {
                        msg.Append(", ");
                    }
                    msg.Append(validTypes[i].Name);
                }
                throw new ArgumentException("'operation' must be " + msg, "operation");
            }
            _operation = operation;
        }
Ejemplo n.º 2
0
 public MotionOperationExecution(IMotionOperationBase operation, ScriptConsole console)
 {
     if (operation == null)
     {
         throw new ArgumentNullException("operation", "'operation' cannot be null");
     }
     if (console == null)
     {
         throw new ArgumentNullException("console", "'console' cannot be null");
     }
     _operation = operation;
     _console   = console;
 }
 public DialogMotionOperation(ScriptConsole console, IMotionOperationBase operation)
     : this()
 {
     if (console == null)
     {
         throw new ArgumentNullException("console", "'console' cannot be null");
     }
     if (operation == null)
     {
         throw new ArgumentNullException("operation", "'operation' cannot be null");
     }
     _operation      = operation;
     _console        = console;
     _exec           = new MotionOperationExecution(operation, _console);
     _targetInfoList = _console.MotionDataSet.GetSelectedObjectInfoList(info => _operation.FilterSelection(info));
 }
 public OperationMenuItem(IMotionOperationBase operation, ToolStripMenuItem menuItem)
 {
     this.Operation = operation;
     this.MenuItem  = menuItem;
 }
        /// <summary>
        /// 各メニューを構築します
        /// </summary>
        public void InitializeMenus()
        {
            _menuAllItems = new List <OperationMenuItem>();

            // 作成メニュー
            _createMenuItem = new ToolStripMenuItem("Create");
            _createMenuItem.DropDownOpening += onMenuOpening;
            // 作成されるオブジェクトごとにメニューを分けるので,作成されるオブジェクトを列挙
            HashSet <Type> motionObjectTypes = new HashSet <Type>();
            bool           otherTypeExists   = false;

            foreach (IMotionOperationCreateObject ope in _dataSet.GetOperationCreateObject())
            {
                Type t = ope.CreatedType;
                if (t != null && t.IsSubclassOf(typeof(MotionObject)))
                {
                    motionObjectTypes.Add(t);
                }
                else
                {
                    otherTypeExists = true;
                }
            }
            // 作成されるオブジェクトごとのメニューを作成
            Dictionary <Type, ToolStripMenuItem> typeMenus = new Dictionary <Type, ToolStripMenuItem>();

            foreach (Type type in motionObjectTypes)
            {
                MotionObjectInfo  testInfo = new MotionObjectInfo(type);
                MotionObject      testObj  = testInfo.GetEmptyObject();
                ToolStripMenuItem item     = new ToolStripMenuItem(type.Name, testObj.GetIcon() ?? global::MotionDataHandler.Properties.Resources.question);
                typeMenus[type] = item;
            }
            ToolStripMenuItem otherTypeMenu = new ToolStripMenuItem("General");

            // 処理ごとにメニューを作成
            foreach (bool isEditWrapper in new bool[] { false, true })
            {
                if (isEditWrapper)
                {
                    foreach (Type t in motionObjectTypes)
                    {
                        typeMenus[t].DropDownItems.Add(new ToolStripSeparator());
                    }
                    if (otherTypeExists)
                    {
                        otherTypeMenu.DropDownItems.Add(new ToolStripSeparator());
                    }
                }
                foreach (IMotionOperationCreateObject ope in _dataSet.GetOperationCreateObject())
                {
                    if ((ope is MotionOperationEditToCreateWrapper) != isEditWrapper)
                    {
                        continue;
                    }
                    Type t = ope.CreatedType;
                    ToolStripMenuItem item = new ToolStripMenuItem(ope.GetTitle());
                    try {
                        Bitmap icon = ope.IconBitmap;
                        if (icon != null)
                        {
                            item.Image = icon;
                        }
                    } catch (NotImplementedException) { }
                    IMotionOperationCreateObject opeForLabmda = ope;
                    item.Click += new EventHandler((sender, e) => {
                        DialogMotionOperation dialog = new DialogMotionOperation(ScriptConsole.Singleton, opeForLabmda);
                        dialog.ShowDialog();
                    });
                    _menuAllItems.Add(new OperationMenuItem(ope, item));
                    if (motionObjectTypes.Contains(t))
                    {
                        typeMenus[t].DropDownItems.Add(item);
                    }
                    else
                    {
                        otherTypeMenu.DropDownItems.Add(item);
                    }
                }
            }
            foreach (Type t in motionObjectTypes.OrderBy(t => t.Name))
            {
                _createMenuItem.DropDownItems.Add(typeMenus[t]);
            }
            if (otherTypeExists)
            {
                _createMenuItem.DropDownItems.Add(otherTypeMenu);
            }
            if (_createMenuItem.DropDownItems.Count == 0)
            {
                _createMenuItem = null;
            }

            // その他
            _editMenuItem    = new ToolStripMenuItem();
            _outputMenuItem  = new ToolStripMenuItem();
            _generalMenuItem = new ToolStripMenuItem();
            List <MenuAutoGenerator> genList = new List <MenuAutoGenerator>();

            genList.Add(new MenuAutoGenerator("Edit", _editMenuItem, () => _dataSet.GetOperationEditObject().Select(ope => (IMotionOperationBase)ope).ToList()));
            genList.Add(new MenuAutoGenerator("Output", _outputMenuItem, () => _dataSet.GetOperationOutputSequence().Select(ope => (IMotionOperationBase)ope).ToList()));
            genList.Add(new MenuAutoGenerator("General", _generalMenuItem, () => _dataSet.GetOperationGeneral().Select(ope => (IMotionOperationBase)ope).ToList()));
            foreach (MenuAutoGenerator gen in genList)
            {
                gen.OutputMenu.Text             = gen.DefaultName;
                gen.OutputMenu.DropDownOpening += onMenuOpening;
                foreach (IMotionOperationBase ope in gen.OperationGenerator())
                {
                    ToolStripMenuItem item = new ToolStripMenuItem(ope.GetTitle());
                    try {
                        Bitmap icon = ope.IconBitmap;
                        if (icon != null)
                        {
                            item.Image = icon;
                        }
                    } catch (NotImplementedException) { }
                    IMotionOperationBase opeForLabmda = ope;
                    item.Click += new EventHandler((sender, e) => {
                        DialogMotionOperation dialog = new DialogMotionOperation(ScriptConsole.Singleton, opeForLabmda);
                        dialog.ShowDialog();
                    });
                    _menuAllItems.Add(new OperationMenuItem(ope, item));
                    gen.OutputMenu.DropDownItems.Add(item);
                }
            }
            if (_editMenuItem.DropDownItems.Count == 0)
            {
                _editMenuItem = null;
            }
            if (_outputMenuItem.DropDownItems.Count == 0)
            {
                _outputMenuItem = null;
            }
            if (_generalMenuItem.DropDownItems.Count == 0)
            {
                _generalMenuItem = null;
            }
        }