Пример #1
0
        public IList <ScriptVariable> ParameterToVariable(IList <ProcParam <MotionProcEnv> > paramaters)
        {
            MotionProcEnv env = this.GetEnvironment();
            Collection <ScriptVariable> ret = new Collection <ScriptVariable>();

            ret.Add(new ListVariable(_console.MotionDataSet.GetSelectedObjectInfoList(info => _operation.FilterSelection(info)).Select(info => (ScriptVariable) new StringVariable(info.Name))));
            paramaters.Select(p => p == null ? null : p.ToScriptVariable(env)).ToList().ForEach(p => ret.Add(p));
            return(ret);
        }
Пример #2
0
        public Panel GetPanel()
        {
            MotionProcEnv env = this.GetEnvironment();

            Panel ret = new Panel();

            ret.Padding = new Padding(8, 8, 8, 8);
            foreach (var param in this.Parameters)
            {
                Panel sub = param.CreatePanel(env);
                sub.Dock = DockStyle.Top;
                ret.Controls.Add(sub);
                sub.BringToFront();
            }
            if (Parameters.Count == 0)
            {
                Label empty = new Label();
                empty.Dock = DockStyle.Top;
                empty.Text = "No parameter";
                ret.Controls.Add(empty);
            }
            ret.AutoScroll = true;
            return(ret);
        }
Пример #3
0
        public MotionProcEnv GetEnvironment()
        {
            MotionProcEnv env = new MotionProcEnv(_console);

            return(env);
        }
Пример #4
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);
        }