Ejemplo n.º 1
0
        private void checkVisible_CheckStateChanged(object sender, EventArgs e)
        {
            // _dataSetの途中変更を防ぐ
            MotionDataSet dataSet = _dataSet;

            if (dataSet == null)
            {
                return;
            }
            // 多重呼び出しの禁止
            if (!_mutex.WaitOne(0))
            {
                return;
            }
            try {
                if (_infoContentChanging)
                {
                    return;
                }
                _infoContentChanging = true;
                try {
                    var infoList = dataSet.GetSelectedObjectInfoList();
                    checkVisible.ThreeState = false;
                    bool visible = checkVisible.Checked;
                    if (infoList.Count > 0)
                    {
                        foreach (var info in infoList)
                        {
                            info.IsVisible = visible;
                        }
                        dataSet.DoObjectInfoSetChanged();
                    }
                } finally { _infoContentChanging = false; }
            } finally { _mutex.ReleaseMutex(); }
        }
Ejemplo n.º 2
0
        private void textGroup_Validated(object sender, EventArgs e)
        {
            // _dataSetの途中変更を防ぐ
            MotionDataSet dataSet = _dataSet;

            if (dataSet == null)
            {
                return;
            }
            var    infoList = dataSet.GetSelectedObjectInfoList();
            string to       = PathEx.NormalizePath(textGroup.Text);

            if (to == _currentGroup)
            {
                return;
            }
            bool found = false;

            foreach (var info in infoList)
            {
                if (PathEx.IsSubPath(info.Name, _currentGroup))
                {
                    string subName = PathEx.GetRelativePath(info.Name, _currentGroup);
                    _dataSet.RenameObjectInfo(info, PathEx.CombineName(to, subName), this);
                    found = true;
                }
            }
            _currentGroup = to;
            if (found)
            {
                dataSet.DoObjectInfoSetChanged();
            }
        }
Ejemplo n.º 3
0
 private void numericColorAlpha_ValueChanged(object sender, EventArgs e)
 {
     // 多重呼び出しの禁止
     if (!_mutex.WaitOne(0))
     {
         return;
     }
     try {
         if (_infoContentChanging)
         {
             return;
         }
         _infoContentChanging = true;
         try {
             // _dataSetの途中変更を防ぐ
             MotionDataSet dataSet = _dataSet;
             if (dataSet == null)
             {
                 return;
             }
             var infoList = dataSet.GetSelectedObjectInfoList();
             int alpha    = (int)(Math.Round(2.55 * (int)numericColorAlpha.Value));
             if (infoList.Count > 0)
             {
                 foreach (var info in infoList)
                 {
                     info.Color = Color.FromArgb(alpha, info.Color);
                 }
                 dataSet.DoObjectInfoSetChanged();
             }
         } finally { _infoContentChanging = false; }
     } finally { _mutex.ReleaseMutex(); }
 }
Ejemplo n.º 4
0
 private void askColor()
 {
     // 多重呼び出しの禁止
     if (!_mutex.WaitOne(0))
     {
         return;
     }
     try {
         // _dataSetの途中変更を防ぐ
         MotionDataSet dataSet = _dataSet;
         if (dataSet == null)
         {
             return;
         }
         var infoList = dataSet.GetSelectedObjectInfoList();
         if (infoList.Count > 0)
         {
             dialogColor.Color = Color.FromArgb(255, infoList[0].Color);
             if (dialogColor.ShowDialog() == DialogResult.OK)
             {
                 foreach (var info in infoList)
                 {
                     info.Color = Color.FromArgb(info.Color.A, dialogColor.Color);
                 }
                 dataSet.DoObjectInfoSetChanged();
             }
         }
     } finally {
         _mutex.ReleaseMutex();
     }
 }
Ejemplo n.º 5
0
        public void Operate(IList <MotionObjectInfo> selectedInfoList, IList <ProcParam <MotionProcEnv> > args, MotionDataSet dataSet, ProgressInformation progressInfo)
        {
            StringParameter name = args[0] as StringParameter;

            foreach (MotionObjectInfo info in selectedInfoList)
            {
                info.Name = name.Value ?? "unnamed";
            }
            dataSet.DoObjectInfoSetChanged();
        }
Ejemplo n.º 6
0
        private void showToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // _dataSetの途中変更を防ぐ
            MotionDataSet dataSet = _dataSet;

            if (dataSet == null)
            {
                return;
            }
            foreach (var info in dataSet.GetSelectedObjectInfoList())
            {
                info.IsVisible = true;
            }
            dataSet.DoObjectInfoSetChanged();
        }
Ejemplo n.º 7
0
 public void Operate(IList <MotionObjectInfo> selectedInfoList, IList <ProcParam <MotionProcEnv> > args, MotionDataSet dataSet, ProgressInformation progressInfo)
 {
     progressInfo.Initialize(dataSet.FrameLength, "Remove Object from Frames");
     foreach (MotionFrame frame in dataSet.EnumerateFrame())
     {
         progressInfo.CurrentValue++;
         foreach (MotionObjectInfo info in selectedInfoList)
         {
             frame.RemoveObject(info);
         }
     }
     foreach (MotionObjectInfo info in selectedInfoList)
     {
         dataSet.RemoveObject(info);
     }
     dataSet.DoObjectInfoSetChanged();
 }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public void Operate(IList <MotionObjectInfo> selectedInfoList, IList <ProcParam <MotionProcEnv> > args, MotionDataSet dataSet, ProgressInformation progressInfo)
        {
            SingleSelectParameter mode   = args[0] as SingleSelectParameter;
            NumberParameter       limit2 = args[1] as NumberParameter;
            bool addMode = mode.Value == 1;
            int  limit   = (int)limit2.Value;

            progressInfo.Initialize(selectedInfoList.Count, "Interpolate");
            foreach (var info in selectedInfoList)
            {
                // 欠落範囲の集合
                RangeSet <int> missings = new RangeSet <int>();

                bool exist = true;
                int  begin = 0;
                // 最初のフレームからかけている部分,最後のかけている部分は無視
                for (int i = 0; i < dataSet.FrameLength; i++)
                {
                    if (dataSet.GetFrameByIndex(i)[info] == null)
                    {
                        if (exist)
                        {
                            begin = i;
                            exist = false;
                        }
                    }
                    else
                    {
                        if (!exist)
                        {
                            if (begin != 0)
                            {
                                missings.Add(new RangeSet <int> .Range(begin, i));
                                exist = true;
                            }
                        }
                    }
                }
                // 別オブジェクトにするとき用に入力オブジェクトと出力オブジェクトを分ける
                MotionObjectInfo addInfo = info;
                if (addMode)
                {
                    // 別オブジェクトにするオプション
                    addInfo      = new MotionObjectInfo(info.ObjectType, info);
                    addInfo.Name = PathEx.GiveName("interpolate", info.Name);
                    dataSet.AddObject(addInfo);
                }
                // 線形補間
                foreach (var range in missings)
                {
                    if (limit == 0 || range.End - range.Start <= limit)
                    {
                        int          pre       = range.Start - 1;
                        int          post      = range.End;
                        MotionFrame  preFrame  = dataSet.GetFrameByIndex(pre);
                        MotionFrame  postFrame = dataSet.GetFrameByIndex(post);
                        MotionObject preObject = preFrame[info];
                        if (preObject != null)
                        {
                            for (int index = range.Start; index < range.End; index++)
                            {
                                float       interpolater = (float)(index - pre) / (post - pre);
                                MotionFrame frame        = dataSet.GetFrameByIndex(index);
                                frame[addInfo] = preObject.InterpolateLinear(postFrame[info], interpolater);
                            }
                        }
                    }
                }
                progressInfo.CurrentValue++;
            }

            dataSet.DoFrameListChanged();
            if (addMode)
            {
                dataSet.DoObjectInfoSetChanged();
            }
        }
Ejemplo n.º 10
0
        private void loadEVaRTTrc(TrcReader reader)
        {
            WaitForForm waitForm = new WaitForForm(ctrl => {
                try {
                    _dataSet.ClearFrame();
                    _dataSet.ClearObject();
                    Dictionary <int, uint> index2id = new Dictionary <int, uint>();
                    int length = reader.Header.NumFrames;
                    int count  = 0;
                    for (int i = 0; i < reader.Header.NumMarkers; i++)
                    {
                        MotionObjectInfo newInfo = new MotionObjectInfo(typeof(PointObject));
                        newInfo.Name             = reader.Header.Markers[i];
                        _dataSet.AddObject(newInfo);
                        index2id[i] = newInfo.Id;
                    }

                    while (!reader.EndOfStream)
                    {
                        TrcFrame inFrame = reader.ReadFrame();

                        MotionFrame outFrame = new MotionFrame(_dataSet, inFrame.Time);
                        for (int i = 0; i < inFrame.Markers.Length; i++)
                        {
                            uint id;
                            if (!index2id.TryGetValue(i, out id))
                            {
                                MotionObjectInfo newInfo = new MotionObjectInfo(typeof(PointObject));
                                newInfo.Name             = PathEx.CombineName("unnamed", (i + 1).ToString());
                                _dataSet.AddObject(newInfo);
                                id = index2id[i] = newInfo.Id;
                            }
                            if (inFrame.Markers[i].HasValue)
                            {
                                float x, y, z;
                                if (float.TryParse(inFrame.Markers[i].Value.X, out x) && float.TryParse(inFrame.Markers[i].Value.Y, out y) && float.TryParse(inFrame.Markers[i].Value.Z, out z))
                                {
                                    outFrame[id] = new PointObject(new Vector3(x, y, z));
                                }
                            }
                        }
                        _dataSet.AddFrame(outFrame);
                        if (length < count)
                        {
                            length = count;
                        }
                        if (length <= 0)
                        {
                            length = 1;
                        }
                        ctrl.ReportProgress(100 * count / length, string.Format("Load Frame: {0}/{1} ({2} sec)", count, length, inFrame.Time.ToString("0.00")));
                        count++;
                    }
                    ctrl.ReportProgress(100, string.Format("Done"));
                    ctrl.DialogResult = DialogResult.OK;
                } catch (Exception) {
                    _dataSet.ClearObject();
                    _dataSet.ClearFrame();
                    _dataSet.DoObjectInfoSetChanged();
                    _dataSet.DoFrameListChanged();
                    throw;
                }
            });

            if (waitForm.ShowDialog() == DialogResult.OK)
            {
                _dataSet.DoObjectInfoSetChanged();
                _dataSet.DoFrameListChanged();
            }
        }