private void DialogMotionOperation_Load(object sender, EventArgs e)
        {
            if (_console == null)
            {
                return;
            }
            if (_operation == null)
            {
                return;
            }
            // ダイアログのタイトルを適当に設定
            this.Text = _operation.GetTitle();
            // ビューの設定
            motionDataViewer.AttachDataSet(_console.MotionDataSet);
            motionDataViewer.AttachTimeController(TimeController.Singleton);
            // 引数の値が変わったらプレビューしなおすよう設定する
            foreach (ProcParam <MotionProcEnv> param in _exec.Parameters)
            {
                param.ValueChanged += new EventHandler(param_ValueChanged);
            }
            // 引数のパネルを作って表示
            Panel panel = _exec.GetPanel();

            panel.AutoScroll = true;
            panel.Dock       = DockStyle.Fill;
            groupBoxSettings.Controls.Add(panel);

            // 選択されているオブジェクトが不適切だったらダイアログを閉じる
            string errorStr = "";

            if (!_operation.ValidateSelection(_targetInfoList, ref errorStr))
            {
                MessageBox.Show("Error: " + (errorStr ?? "something wrong"));
                this.Close();
                return;
            }
            // 説明書きを処理オブジェクトからもらって表示
            textBoxDescription.Text = _operation.GetDescription();

            // 選択されているオブジェクトを表示
            listBoxTarget.Items.Clear();
            foreach (MotionObjectInfo info in _targetInfoList)
            {
                listBoxTarget.Items.Add(string.Format("{0} ({1})", info.Name, info.ObjectType.Name));
            }
            // プレビューを更新
            this.SetPreview();
            // 引数がない場合にダイアログを表示しないオプションが付いていたら勝手に実行する
            if (checkIgnoreForm.Checked && _exec.Parameters.Count == 0)
            {
                this.Invoke(new EventHandler(buttonOK_Click), sender, e);
            }
        }
Ejemplo n.º 2
0
        public ScriptVariable Call(IList <ScriptVariable> args, ScriptConsole console)
        {
            _progress.Initialize(0, "Initializing...");
            if (args == null)
            {
                throw new ArgumentNullException("args", "args cannot be null");
            }
            if (args.Count < 1)
            {
                args = new List <ScriptVariable> {
                    null
                }
            }
            ;
            if (args[0] == null)
            {
                args[0] = new ListVariable();
            }
            IList <ScriptVariable> objectNamesVar = args[0].ToList();

            if (objectNamesVar.Any(n => n.IsNull()))
            {
                throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_ObjectNameCannotBeNull, "args");
            }
            List <string>           objectNames = objectNamesVar.Select(n => n.ToString()).ToList();
            MotionDataSet           dataSet     = console.MotionDataSet;
            MotionProcEnv           env2        = new MotionProcEnv(console);
            List <MotionObjectInfo> infoList    = new List <MotionObjectInfo>();

            foreach (string objectName in objectNames)
            {
                MotionObjectInfo info = dataSet.GetObjectInfoByName(objectName);
                if (info == null)
                {
                    throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_ObjectNotFound + ": " + objectName, "args");
                }
                infoList.Add(info);
            }
            foreach (MotionObjectInfo info in infoList)
            {
                if (!_operation.FilterSelection(info))
                {
                    throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_InvalidTargetObjectSpecified + ": " + info.Name, "args");
                }
            }
            string errorMessage = "";

            if (!_operation.ValidateSelection(infoList, ref errorMessage))
            {
                if (errorMessage == null)
                {
                    errorMessage = "";
                }
                throw new ArgumentException(global::MotionDataHandler.Properties.Settings.Default.Msg_ImproperObjectSelection + ": " + errorMessage, "args");
            }

            IList <ProcParam <MotionProcEnv> > parameters = _operation.GetParameters() ?? new ProcParam <MotionProcEnv> [0];

            if (args.Count != parameters.Count + 1)
            {
                throw new ArgumentException(string.Format(global::MotionDataHandler.Properties.Settings.Default.Msg_NumberOfArgumentsRequired, parameters.Count + 1));
            }
            for (int i = 0; i < parameters.Count; i++)
            {
                if (!parameters[i].FromScriptVariable(env2, args[i + 1], ref errorMessage))
                {
                    throw new ArgumentException(string.Format(global::MotionDataHandler.Properties.Settings.Default.Msg_InvalidNthArgument + ": {1}", i + 1, errorMessage ?? ""), "args");
                }
            }
            if (!_operation.ValidateArguments(parameters, ref errorMessage))
            {
                throw new ArgumentException(string.Format(global::MotionDataHandler.Properties.Settings.Default.Msg_InvalidArgument + ": {0}", errorMessage ?? ""), "args");
            }
            IMotionOperationGeneral general = _operation as IMotionOperationGeneral;

            if (general != null)
            {
                _progress.Initialize(0, "Operation");
                general.Operate(infoList, parameters, dataSet, _progress);
                return(new ListVariable(infoList.Select(info => new StringVariable(info.Name))));
            }
            IMotionOperationEditObject edit = _operation as IMotionOperationEditObject;

            if (edit != null)
            {
                _progress.Initialize(dataSet.FrameLength, "Edit Object");
                foreach (MotionFrame frame in dataSet.EnumerateFrame())
                {
                    IList <MotionObject> results = edit.EditObject(infoList, parameters, new ReadOnlyMotionFrame(frame), false);
                    int count = Math.Min(results.Count, infoList.Count);
                    for (int i = 0; i < count; i++)
                    {
                        frame[infoList[i]] = results[i];
                    }
                    _progress.CurrentValue++;
                }
                dataSet.DoFrameListChanged();
                return(new ListVariable(infoList.Select(info => new StringVariable(info.Name))));
            }
            IMotionOperationOutputSequence output = _operation as IMotionOperationOutputSequence;

            if (output != null)
            {
                _progress.Initialize(0, "Output");
                IList <Sequence.SequenceData> sequences = output.OutputSequence(infoList, parameters, dataSet.EnumerateFrame().Select(frame => new ReadOnlyMotionFrame(frame)), _progress);
                foreach (Sequence.SequenceData sequence in sequences)
                {
                    console.SequenceController.AddSequence(sequence);
                }
                return(new ListVariable(sequences.Select(s => new StringVariable(s.Title))));
            }
            IMotionOperationCreateObject create = _operation as IMotionOperationCreateObject;

            if (create != null)
            {
                _progress.Initialize(dataSet.FrameLength, "Create Object");
                IList <MotionObjectInfo> newInfoList = create.GetNewObjectInfoList(infoList, parameters);
                MotionFrame firstFrame = dataSet.GetFrameByIndex(0);
                if (firstFrame != null)
                {
                    IList <MotionObject> newObjects = create.CreateObjects(infoList, parameters, new ReadOnlyMotionFrame(firstFrame), false) ?? new MotionObject[0];
                    if (newObjects.Count != newInfoList.Count)
                    {
                        throw new InvalidOperationException(global::MotionDataHandler.Properties.Settings.Default.Msg_CreateObjectLengthMismatch);
                    }
                }
                foreach (MotionObjectInfo newInfo in newInfoList)
                {
                    dataSet.AddObject(newInfo);
                }
                foreach (MotionFrame frame in dataSet.EnumerateFrame())
                {
                    IList <MotionObject> newObjects = create.CreateObjects(infoList, parameters, new ReadOnlyMotionFrame(frame), false) ?? new MotionObject[0];
                    int count = Math.Min(newObjects.Count, newInfoList.Count);
                    for (int i = 0; i < count; i++)
                    {
                        frame[newInfoList[i]] = newObjects[i];
                    }
                    _progress.CurrentValue++;
                }
                dataSet.DoObjectInfoSetChanged();
                dataSet.DoFrameListChanged();
                return(new ListVariable(newInfoList.Select(info => new StringVariable(info.Name))));
            }
            return(null);
        }