private bool trySaveState(bool ask)
 {
     try {
         if ((!ask && _isSavePathSet) || dialogSaveState.ShowDialog() == DialogResult.OK)
         {
             string      path     = dialogSaveState.FileName;
             WaitForForm waitForm = new WaitForForm(ctrl => {
                 ctrl.OperationTitle = string.Format("Save: {0}", Path.GetFileName(path));
                 _viewerController.SaveState(path, true);
                 ctrl.DialogResult = DialogResult.OK;
             }, () => _viewerController.GetSerializeProgress());
             if (waitForm.ShowDialog() == DialogResult.OK)
             {
                 _isSavePathSet = true;
                 changeSaveStateEnabled();
                 setStatusLabel("ビュー一覧が保存されました");
                 return(true);
             }
             return(false);
         }
         else
         {
             return(false);
         }
     } catch (Exception ex) {
         ErrorLogger.Tell(ex, "ファイルの書き込みに失敗しました");
         return(false);
     }
 }
 private void loadState(bool addPanels)
 {
     try {
         if (dialogOpenState.ShowDialog() == DialogResult.OK)
         {
             string path = dialogOpenState.FileName;
             path = Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path));
             WaitForForm waitForm = new WaitForForm(ctrl => {
                 ctrl.OperationTitle = string.Format("Load: {0}", Path.GetFileName(path));
                 _viewerController.LoadState(path, addPanels);
                 ctrl.DialogResult = DialogResult.OK;
             }, () => _viewerController.GetSerializeProgress());
             if (waitForm.ShowDialog() == DialogResult.OK)
             {
                 if (!addPanels)
                 {
                     dialogSaveState.FileName = dialogOpenState.FileName;
                     _isSavePathSet           = true;
                     changeSaveStateEnabled();
                 }
             }
         }
     } catch (Exception ex) {
         ErrorLogger.Tell(ex, "ファイルの読み込みに失敗しました");
     }
 }
예제 #3
0
        public static void Execution(Action action, ILogger log = null, bool silent = false)
        {
            using (var form = new WaitForForm(log, silent)) {
                Task
                .Run(action)
                .ContinueWith(Continuation, form);

                form.ShowDialog();
            }
        }
예제 #4
0
        public bool OperateThread(Control parentControl)
        {
            WaitForForm form = new WaitForForm(ctrl => {
                ctrl.OperationTitle = _operation.GetDescription();
                ctrl.FormTitle      = _operation.GetTitle();
                this.Operate(parentControl);
                ctrl.DialogResult = DialogResult.OK;
            }, () => this.GetProgress());

            return(form.ShowDialog() == DialogResult.OK);
        }
예제 #5
0
        public static TResult Execution <TResult>(Func <TResult> action, ILogger log = null, bool silent = false)
        {
            var task = new Task <TResult>(action);

            using (var form = new WaitForForm(log, silent)) {
                task.ContinueWith(Continuation, form);
                task.Start();

                form.ShowDialog();
            }
            return(task.Result);
        }
예제 #6
0
        private void saveMotionData(string path)
        {
            string ext = Path.GetExtension(path);

            try {
                DialogResult result = DialogResult.None;
                using (Stream stream = new FileStream(path + "~", FileMode.Create)) {
                    WaitForForm waitForm = new WaitForForm(ctrl => {
                        try {
                            if (ext == ".mdsx2")
                            {
                                using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(stream)) {
                                    _dataSet.SerializeXml(writer);
                                }
                            }
                            else if (ext == ".mdsb2")
                            {
                                using (BinaryWriter writer = new BinaryWriter(stream)) {
                                    _dataSet.SerializeBinary(writer);
                                }
                            }
                            else
                            {
                                throw new ArgumentException("Unknown format: " + ext);
                            }
                            ctrl.DialogResult = DialogResult.OK;
                        } catch (Exception ex) {
                            ErrorLogger.Tell(ex, path + ": ファイルを保存できませんでした");
                        }
                    }, () => _dataSet.ProgressChangedEventArgs);
                    waitForm.SetOperationTitle(path);
                    result = waitForm.ShowDialog();
                }
                if (result == DialogResult.OK)
                {
                    if (File.Exists(path))
                    {
                        File.Replace(path + "~", path, path + "~~");
                        File.Delete(path + "~~");
                    }
                    else
                    {
                        File.Move(path + "~", path);
                    }
                    _isDataSetModified = false;
                    _isOverWritable    = true;
                }
            } catch (NullReferenceException ex) {
                ErrorLogger.Tell(ex, path + ": ファイルを保存できませんでした");
            }
        }
예제 #7
0
        private void loadPhaseSpace(PhaseSpaceDataReader reader)
        {
            WaitForForm waitForm = new WaitForForm(ctrl => {
                try {
                    _dataSet.ClearFrame();
                    _dataSet.ClearObject();
                    Dictionary <int, uint> index2id = new Dictionary <int, uint>();
                    int count = 1;
                    while (!reader.EndOfStream)
                    {
                        PhaseSpaceFrame 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].Condition > 0)
                            {
                                outFrame[id] = new PointObject(new Vector3(inFrame.Markers[i].X, inFrame.Markers[i].Y, inFrame.Markers[i].Z));
                            }
                        }
                        _dataSet.AddFrame(outFrame);

                        ctrl.ReportProgress(99 - 990000 / (count + 10000), string.Format("Load Frame: {0} ({1} sec)", count, 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();
            }
        }
예제 #8
0
        public string ExecuteThread(TextReader reader)
        {
            string      ret          = "";
            WaitForForm _waitForForm = new WaitForForm(ctrl => {
                // 実行処理
                try {
                    ret = this.Execute(reader);
                } finally {
                    ctrl.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
            }, () => {
                try {
                    // どの関数にいるか
                    string call = "Script Body";
                    if (_executedFunctionStack.Count > 0)
                    {
                        IScriptFunction subroutine = null;
                        try {
                            _executedFunctionStack.Peek();
                        } catch (InvalidOperationException) { }
                        if (subroutine != null)
                        {
                            ITimeConsumingScriptFunction timeConsume = subroutine as ITimeConsumingScriptFunction;
                            if (timeConsume != null)
                            {
                                return(timeConsume.GetProgress());
                            }
                            call = subroutine.Name;
                        }
                    }
                    // どの行にいるか
                    string position = "";
                    if (_executedSyntaxElementStack.Count > 0)
                    {
                        SyntaxElement syntax = _executedSyntaxElementStack.Peek();
                        if (syntax == null)
                        {
                            position = ", ...";
                        }
                        else
                        {
                            position = string.Format(", Column {0} at Line {1}", syntax.LexAtStart.Column, syntax.LexAtStart.Line);
                        }
                    }
                    return(new System.ComponentModel.ProgressChangedEventArgs(0, "Process at " + call + position));
                } catch (InvalidOperationException) {
                    return(new System.ComponentModel.ProgressChangedEventArgs(0, ""));
                }
            });

            _waitForForm.Icon = global::MotionDataHandler.Properties.Resources.script;
            try {
                _waitForForm.CancelEnabled = true;
                if (_waitForForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    return(ret);
                }
            } finally {
                if (_executedFunctionStack.Count > 0)
                {
                    _executedFunctionStack.Clear();
                }
                if (_executedSyntaxElementStack.Count > 0)
                {
                    _executedSyntaxElementStack.Clear();
                }
            }
            return(null);
        }
예제 #9
0
        private void addPhaseSpace(PhaseSpaceDataReader reader)
        {
            WaitForForm waitForm = new WaitForForm(ctrl => {
                try {
                    Dictionary <int, uint> index2id = new Dictionary <int, uint>();
                    int count = 1;
                    int index = 0;
                    PhaseSpaceFrame prevInFrame = new PhaseSpaceFrame();
                    bool first = true;
                    Action <PhaseSpaceFrame, int> import = (inFrame, endIndex) => {
                        for (; index < endIndex && index < _dataSet.FrameLength; index++)
                        {
                            MotionFrame frame = _dataSet.GetFrameByIndex(index);
                            if (frame == null)
                            {
                                continue;
                            }
                            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].Condition > 0)
                                {
                                    frame[id] = new PointObject(new Vector3(inFrame.Markers[i].X, inFrame.Markers[i].Y, inFrame.Markers[i].Z));
                                }
                            }
                        }
                    };
                    while (!reader.EndOfStream)
                    {
                        PhaseSpaceFrame inFrame = reader.ReadFrame();
                        int inIndex             = _dataSet.GetFrameIndexAt(inFrame.Time);
                        MotionFrame tmp         = _dataSet.GetFrameByIndex(inIndex);
                        if (tmp == null || tmp.Time == inFrame.Time)
                        {
                            inIndex++;
                        }
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            import(prevInFrame, inIndex);
                        }
                        prevInFrame = inFrame;
                        ctrl.ReportProgress(99 - 990000 / (count + 10000), string.Format("Load Frame Data: {0} ({1} sec)", count, inFrame.Time.ToString("0.00")));
                        count++;
                    }
                    if (!first)
                    {
                        import(prevInFrame, _dataSet.FrameLength);
                    }
                    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();
            }
        }
예제 #10
0
        bool openMotionData(string fileName)
        {
            if (fileName == null)
            {
                if (dialogOpenMotionData.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }
                fileName = dialogOpenMotionData.FileName;
            }
            string ext = Path.GetExtension(fileName);

            using (Stream stream = new FileStream(fileName, FileMode.Open)) {
                switch (ext)
                {
                case ".mdsx":
                case ".mdsb":
                    using (MotionDataHandler.Motion.Old.MotionDataSet newDataSet = new MotionDataHandler.Motion.Old.MotionDataSet()) {
                        // 古いデータをロード
                        WaitForForm waitForm2 = new WaitForForm(ctrl => {
                            newDataSet.ProgressChanged += ctrl.OnProgressChanged;
                            try {
                                switch (ext)
                                {
                                case ".mdsx":
                                    newDataSet.RetrieveXml(stream);
                                    break;

                                case ".mdsb":
                                    newDataSet.RetrieveBinary(stream);
                                    break;

                                default:
                                    System.Diagnostics.Debug.Fail("format naming error");
                                    break;
                                }
                                ctrl.DialogResult = DialogResult.OK;
                            } catch (Exception ex) {
                                ErrorLogger.Tell(ex, fileName + ": ファイルを読み込めませんでした");
                            } finally {
                                newDataSet.ProgressChanged -= ctrl.OnProgressChanged;
                            }
                        });
                        waitForm2.SetOperationTitle(fileName);
                        if (waitForm2.ShowDialog() == DialogResult.OK)
                        {
                            // データを変換
                            WaitForForm waitForm = new WaitForForm(ctrl => {
                                ctrl.OperationTitle = "Converting into New Data Format...";
                                _dataSet.FromOldVersion(newDataSet);
                                ctrl.DialogResult = DialogResult.OK;
                            }, () => new ProgressChangedEventArgs(_dataSet.ProgressPercentage, _dataSet.ProgressMessage));
                            if (waitForm.ShowDialog() == DialogResult.OK)
                            {
                                TimeController.Singleton.SetVisibleTime(TimeController.Singleton.BeginTime, TimeController.Singleton.EndTime);
                                setSaveMotionDataFileName(fileName);
                                _dataSet.DoObjectInfoSetChanged();
                                _dataSet.DoFrameListChanged();
                                _isOverWritable = false;
                                return(true);
                            }
                        }
                        return(false);
                    }

                case ".mdsx2":
                case ".mdsb2": {
                    WaitForForm waitForm = new WaitForForm(ctrl => {
                            ctrl.OperationTitle = fileName;
                            try {
                                switch (ext)
                                {
                                case ".mdsx2":
                                    using (XmlReader reader = XmlReader.Create(stream)) {
                                        _dataSet.RetrieveXml(reader);
                                    }
                                    break;

                                case ".mdsb2":
                                    using (BinaryReader reader = new BinaryReader(stream)) {
                                        _dataSet.RetrieveBinary(reader);
                                    }
                                    break;

                                default:
                                    System.Diagnostics.Debug.Fail("format naming error");
                                    break;
                                }
                                ctrl.DialogResult = DialogResult.OK;
                            } catch (Exception ex) {
                                ErrorLogger.Tell(ex, fileName + ": ファイルを読み込めませんでした");
                            }
                        }, () => _dataSet.ProgressChangedEventArgs);
                    if (waitForm.ShowDialog() == DialogResult.OK)
                    {
                        TimeController.Singleton.SetVisibleTime(TimeController.Singleton.BeginTime, TimeController.Singleton.EndTime);
                        setSaveMotionDataFileName(fileName);
                        _dataSet.DoObjectInfoSetChanged();
                        _dataSet.DoFrameListChanged();
                        _isDataSetModified = false;
                        _isOverWritable    = true;
                        return(true);
                    }
                    return(false);
                }

                default:
                    try {
                        throw new ArgumentException("Unknown format: " + ext);
                    } catch (Exception ex) {
                        ErrorLogger.Tell(ex, fileName + ": ファイルを読み込めませんでした");
                    }
                    return(false);
                }
            }
        }
예제 #11
0
        bool openEyeSight(string fileName)
        {
            if (fileName == null)
            {
                if (dialogLoadEyeSight.ShowDialog() != DialogResult.OK)
                {
                    return(false);
                }
                // すべて開く
                return(dialogLoadEyeSight.FileNames.All(path => openEyeSight(path)));
            }
            WaitForForm waitForm = new WaitForForm(ctrl => {
                lock (_dataSet) {
                    try {
                        ctrl.OperationTitle      = fileName;
                        MotionObjectInfo newInfo = new MotionObjectInfo(typeof(LineObject));
                        newInfo.Name             = Path.GetFileNameWithoutExtension(fileName);
                        _dataSet.AddObject(newInfo);
                        using (CSVReader reader = new CSVReader(fileName)) {
                            int index = 0;
                            while (!reader.EndOfStream)
                            {
                                if (index < 0 || index >= _dataSet.FrameLength)
                                {
                                    break;
                                }
                                MotionFrame frame = _dataSet.GetFrameByIndex(index);
                                int progress      = 0;
                                if (_dataSet.FrameLength > 0)
                                {
                                    progress = Math.Min(99, 100 * index / _dataSet.FrameLength);
                                }
                                ctrl.ReportProgress(progress, "Loading...: " + index.ToString());

                                string[] values = reader.ReadValues();
                                if (values == null)
                                {
                                    break;
                                }

                                if (values.Length >= 8)
                                {
                                    float[] floats = new float[8];
                                    bool failure   = false;
                                    for (int i = 0; !failure && i < 8; i++)
                                    {
                                        if (!float.TryParse(values[i], out floats[i]))
                                        {
                                            failure = true;
                                        }
                                    }
                                    if (!failure)
                                    {
                                        if (floats[0] > 0 && floats[4] > 0)
                                        {
                                            Vector3 end = new Vector3(floats[1], floats[2], floats[3]);
                                            Vector3 dir = new Vector3(floats[5], floats[6], floats[7]);
                                            dir.Normalize();
                                            frame[newInfo] = new LineObject(end, dir * 1000);
                                        }
                                    }
                                }
                                index++;
                            }
                        }
                    } catch (Exception ex) {
                        ErrorLogger.Tell(ex, "読み込みに失敗しました");
                    } finally {
                        _dataSet.DoObjectInfoSetChanged();
                        _dataSet.DoFrameListChanged();
                    }
                }
            });

            if (waitForm.ShowDialog() == DialogResult.OK)
            {
                return(true);
            }
            return(false);
        }
예제 #12
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();
            }
        }