/// <summary>
        /// ファイルビューのコンテキストメニュー [フォルダを削除]
        /// </summary>
        void RaiseFileViewDeleteFolderCommand()
        {
            var items = this.FileTree.First().Items.SourceCollection;

            foreach (var item in items)
            {
                var treeItem = item as FileTreeItem;
                if (treeItem.IsSelected)
                {
                    var path = treeItem._Directory.FullName;
                    if (OpenMessageBox(this.Title.Value, MessageBoxImage.Question, MessageBoxButton.OKCancel, MessageBoxResult.None,
                                       string.Format("{0} を削除してもよろしいですか?", path)) == MessageBoxResult.OK)
                    {
                        try {
                            Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(path,
                                                                                    Microsoft.VisualBasic.FileIO.UIOption.OnlyErrorDialogs,
                                                                                    Microsoft.VisualBasic.FileIO.RecycleOption.SendToRecycleBin,
                                                                                    Microsoft.VisualBasic.FileIO.UICancelOption.DoNothing);
                        } catch (Exception e) {
                            OpenMessageBox(this.Title.Value, MessageBoxImage.Error, MessageBoxButton.OK, MessageBoxResult.OK, e.Message);
                        }
                        FileTree.Clear();
                        FileTree.Add(new FileTreeItem(this.ProjectFolderPath.Value));
                    }
                }
            }
        }
        /// <summary>
        /// 新規プロジェクト作成ダイアログを開く
        /// </summary>
        void RaiseNewProjectCommand()
        {
            var notification = new NewProjectNotification {
                Title = "New Project"
            };

            notification.ProjectName    = this.ProjectName.Value;
            notification.BaseFolderPath = this.BaseFolderPath.Value;
            notification.ProjectComment = this.ProjectComment.Value;
            NewProjectRequest.Raise(notification);
            if (notification.Confirmed)
            {
                this.ProjectName.Value    = notification.ProjectName;
                this.BaseFolderPath.Value = notification.BaseFolderPath;
                this.ProjectComment.Value = notification.ProjectComment;
                if (Directory.Exists(this.ProjectFolderPath.Value))
                {
                    OpenMessageBox(this.Title.Value, MessageBoxImage.Error, MessageBoxButton.OK, MessageBoxResult.OK,
                                   this.ProjectFolderPath.Value + "は既に存在しています。新しい名前を指定してください。");
                }
                else
                {
                    Directory.CreateDirectory(this.ProjectFolderPath.Value);
                    // コメントを出力
                    using (var fs = new FileStream(Path.Combine(this.ProjectFolderPath.Value, "Comment.txt"), FileMode.CreateNew)) {
                        using (var sw = new StreamWriter(fs)) {
                            sw.WriteLine(this.ProjectComment.Value);
                        }
                    }
                    FileTree.Clear();
                    FileTree.Add(new FileTreeItem(this.ProjectFolderPath.Value));
                }
            }
        }
        /// <summary>
        /// プロジェクトを開く
        /// </summary>
        void RaiseOpenFolderCommand()
        {
            var notification = new FolderSelectDialogConfirmation()
            {
                InitialDirectory    = this.BaseFolderPath.Value,
                SelectedPath        = this.BaseFolderPath.Value,
                RootFolder          = Environment.SpecialFolder.Personal,
                ShowNewFolderButton = false
            };

            OpenFolderRequest.Raise(notification);
            if (notification.Confirmed)
            {
                // SelectedPath の最後のディレクトリ名をプロジェクト名に
                // その前までをベースフォルダに
                int lastPos = notification.SelectedPath.LastIndexOf("\\");
                this.BaseFolderPath.Value = notification.SelectedPath.Substring(0, lastPos + 1);
                this.ProjectName.Value    = notification.SelectedPath.Substring(lastPos + 1);

                FileTree.Clear();
                FileTree.Add(new FileTreeItem(this.ProjectFolderPath.Value));
            }
        }
        /// <summary>
        /// 撮影
        /// </summary>
        void RaiseCameraCapturing()
        {
            var notification = new CameraCapturingNotification {
                Title = "撮影番号設定"
            };

            CameraCapturingRequest.Raise(notification);
            if (!notification.Confirmed)
            {
                return;
            }
            // プレビュー中なら停止する
            IsCameraPreviewing.Value = false;

            try {
                // 撮影フォルダ名:
                // プロジェクトのフォルダ名+現在の年月日時分秒+撮影番号からなるフォルダ名のフォルダに画像を保存する
                string sTargetName = DateTime.Now.ToString("yyyyMMdd-HHmmss");
                if (!string.IsNullOrEmpty(notification.CapturingName))
                {
                    sTargetName += string.Format("({0})", notification.CapturingName);
                }
                string sTargetDir = Path.Combine(this.ProjectFolderPath.Value, sTargetName);
                Directory.CreateDirectory(sTargetDir);

                //// 正面カメラの画像を取得する
                //byte[] imaegData = _newSyncShooter.GetPreviewImageFront();
                //if ( imaegData.Length == 0 ) {
                //	OpenMessageBox( this.Title.Value, MessageBoxImage.Error, MessageBoxButton.OK, MessageBoxResult.OK,
                //		"正面カメラの画像を取得できませんでした。" );
                //	return;
                //}
                //var ms = new MemoryStream( imaegData );
                //BitmapSource bitmapSource = BitmapFrame.Create( ms, BitmapCreateOptions.None, BitmapCacheOption.OnLoad );

                // カメラ画像転送ダイアログを開く
                var notification2 = new ImagTransferingNotification()
                {
                    Title                  = "カメラ画像転送",
                    SyncShooter            = _newSyncShooter,
                    ConnectedIPAddressList = ConnectedIPAddressList,
                    TargetDir              = sTargetDir,
                    //Image = bitmapSource,
                };
                var t = DateTime.Now;

                this.ImageTransferingRequest.Raise(notification2);

                if (notification2.Confirmed)
                {
                    TimeSpan ts = DateTime.Now - t;
                    OpenMessageBox(this.Title.Value, MessageBoxImage.Information, MessageBoxButton.OK, MessageBoxResult.OK,
                                   "画像転送完了\n\nElapsed : " + ts.ToString("s\\.fff") + " sec");
                }

                // 「ファイルビュー」表示を更新
                FileTree.Clear();
                FileTree.Add(new FileTreeItem(this.ProjectFolderPath.Value));
            } catch (Exception e) {
                OpenMessageBox(this.Title.Value, MessageBoxImage.Error, MessageBoxButton.OK, MessageBoxResult.OK, e.Message);
            }
        }
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public MainWindowViewModel()
        {
            // レジストリからプロジェクト情報を復元する
            string sBaseRegKey = Path.Combine(_registryBaseKey, this.Title.Value);

            _project.Load(sBaseRegKey);
            // その他環境変数
            var regkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(Path.Combine(sBaseRegKey, "Environment"));

            _localHostIP = regkey.GetValue("LocalHostIP", _localHostIP) as string;


            _newSyncShooter = new NewSyncShooter.NewSyncShooter();
            _newSyncShooter.Initialize("syncshooterDefs.json");

            // Previewing timer を 500msecでセット
            _previewingTimer          = new DispatcherTimer(DispatcherPriority.Render);
            _previewingTimer.Interval = TimeSpan.FromMilliseconds(500);
            _previewingTimer.Tick    += (sender, args) => {
                try {
                    byte[] data = _newSyncShooter.GetPreviewImageFront();
                    if (data.Length > 0)
                    {
                        ShowPreviewImage(data);
                    }
                } catch (Exception e) {
                    Console.WriteLine(e.InnerException.Message);
                }
            };

            this.ConnectedIPAddressList = new ReactiveCollection <string>();
            this.ConnectedIPAddressList.PropertyChangedAsObservable().Subscribe(item => {
                CameraTree.Clear();
                CameraTree.Add(new CameraTreeItem(ConnectedIPAddressList));
            });

            // Models.Project のプロパティと双方向で同期する
            this.ProjectName          = _project.ProjectName.ToReactivePropertyAsSynchronized(val => val.Value).AddTo(_disposable);
            this.BaseFolderPath       = _project.BaseFolderPath.ToReactivePropertyAsSynchronized(val => val.Value).AddTo(_disposable);
            this.ProjectComment       = _project.Comment.ToReactivePropertyAsSynchronized(val => val.Value).AddTo(_disposable);
            this.ThreeDDataFolderPath = _project.ThreeDDataFolderPath.ToReactivePropertyAsSynchronized(val => val.Value).AddTo(_disposable);
            this.IsCutPetTable        = _project.IsCutPetTable.ToReactivePropertyAsSynchronized(val => val.Value).AddTo(_disposable);
            this.IsSkipAlreadyBuilt   = _project.IsSkipAlreadyBuilt.ToReactivePropertyAsSynchronized(val => val.Value).AddTo(_disposable);

            // プロジェクトのフォルダパス名は、ベースフォルダ名とプロジェクト名と同期する
            this.ProjectFolderPath = this.BaseFolderPath.CombineLatest(this.ProjectName, (b, p) =>
                                                                       (!string.IsNullOrEmpty(b) && !string.IsNullOrEmpty(p)) ? Path.Combine(b, p) : string.Empty).ToReadOnlyReactiveProperty();
            // ここでプロジェクトフォルダパスが有効であれば、ファイルビューのツリーを更新する
            if (!string.IsNullOrEmpty(this.ProjectFolderPath.Value))
            {
                FileTree.Clear();
                FileTree.Add(new FileTreeItem(this.ProjectFolderPath.Value));
            }

            // カメラの接続状態を示すプロパティは、接続しているIPアドレスのリストと同期する
            this.IsCameraConnected = this.ConnectedIPAddressList.CollectionChangedAsObservable().Select(e => {
                switch (e.Action)
                {
                case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                default:
                    return(false);

                case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                    return(e.NewItems.Count > 0);
                }
            }).ToReadOnlyReactiveProperty();

            this.IsCameraPreviewing.Subscribe(val => {
                if (val)
                {
                    _previewingTimer.Start();
                }
                else
                {
                    _previewingTimer.Stop();
                    this.PreviewingImage.Value = null;
                }
            });

            // Commands
            NewProjectCommand = new ReactiveCommand();
            NewProjectCommand.Subscribe(RaiseNewProjectCommand);
            OpenFolderCommand = new ReactiveCommand();
            OpenFolderCommand.Subscribe(RaiseOpenFolderCommand);
            CameraConnectionCommand = new ReactiveCommand();
            CameraConnectionCommand.Subscribe(RaiseCameraConnection);
            CameraSettingCommand = this.IsCameraConnected.ToReactiveCommand();
            CameraSettingCommand.Subscribe(RaiseCameraSetting);
            CameraCapturingCommand = this.IsCameraConnected.CombineLatest(this.ProjectName, (c, p) => c && !string.IsNullOrEmpty(p)).ToReactiveCommand();
            CameraCapturingCommand.Subscribe(RaiseCameraCapturing);
            CameraStopCommand = this.IsCameraConnected.ToReactiveCommand();
            CameraStopCommand.Subscribe(RaiseCameraStop);
            CameraRebootCommand = this.IsCameraConnected.ToReactiveCommand();
            CameraRebootCommand.Subscribe(RaiseCameraReboot);
            CameraFrontCommand = this.IsCameraConnected.ToReactiveCommand();
            CameraFrontCommand.Subscribe(RaiseCameraFront);
            CameraBackCommand = this.IsCameraConnected.ToReactiveCommand();
            CameraBackCommand.Subscribe(RaiseCameraBack);
            CameraRightCommand = this.IsCameraConnected.ToReactiveCommand();
            CameraRightCommand.Subscribe(RaiseCameraRight);
            CameraLeftCommand = this.IsCameraConnected.ToReactiveCommand();
            CameraLeftCommand.Subscribe(RaiseCameraLeft);
            NetworkSettingCommand = new ReactiveCommand();
            NetworkSettingCommand.Subscribe(RaiseNetworkSetting);
            ThreeDBuildingOneCommand = this.ProjectName.Select(p => !string.IsNullOrEmpty(p)).ToReactiveCommand();
            ThreeDBuildingOneCommand.Subscribe(RaiseThreeDBuildingOne);
            ThreeDBuildingAllCommand = this.ProjectName.Select(p => !string.IsNullOrEmpty(p)).ToReactiveCommand();
            ThreeDBuildingAllCommand.Subscribe(RaiseThreeDBuildingAll);
            ThreeDBuildingStopCommand = this.ProjectName.Select(p => !string.IsNullOrEmpty(p)).ToReactiveCommand();
            ThreeDBuildingStopCommand.Subscribe(RaiseThreeDBuildingStop);
            ThreeDDataFolderOpeningCommand = new[] { this.ProjectName, this.ThreeDDataFolderPath }.CombineLatest(x => x.All(y => !string.IsNullOrEmpty(y))).ToReactiveCommand();
            ThreeDDataFolderOpeningCommand.Subscribe(RaiseThreeDDataFolderOpening);
            FileViewOpenFolderCommand = new ReactiveCommand();
            FileViewOpenFolderCommand.Subscribe(RaiseFileViewOpenFolderCommand);
            FileViewDeleteFolderCommand = new ReactiveCommand();
            FileViewDeleteFolderCommand.Subscribe(RaiseFileViewDeleteFolderCommand);
            CameraViewShowPictureCommand = new ReactiveCommand();
            CameraViewShowPictureCommand.Subscribe(RaiseCameraViewShowPictureCommand);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 自動撮影を行う
        /// </summary>
        void CatureAutomatically()
        {
            // プレビュー中なら停止する
            IsCameraPreviewing.Value = false;

            try {
                // 現在のプロジェクトフォルダ内で、"Auto" で始まるフォルダ一覧を取得する
                // それらがある場合は、その最後の番号を、新規作成フォルダの番号とする
                // ない場合は "Auto0000" とする
                var directories = Directory.GetDirectories(this.ProjectFolderPath.Value);
                int nMaxIndex;
                if (directories.Length == 0)
                {
                    nMaxIndex = 0;
                }
                else
                {
                    directories = directories
                                  .Select(dir => Path.GetFileName(dir).ToUpper())
                                  .Where(dir => dir.StartsWith("AUTO(")).ToArray();
                    if (directories.Length == 0)
                    {
                        nMaxIndex = 0;
                    }
                    else
                    {
                        nMaxIndex = directories.Max(dir =>
                        {
                            string sName = dir.Remove(0, 5);
                            sName        = sName.Remove(sName.Length - 1);
                            return(int.Parse(sName));
                        });
                    }
                }
                string sTargetName = String.Format("Auto({0:0000})", nMaxIndex + 1);
                string sTargetDir  = Path.Combine(this.ProjectFolderPath.Value, sTargetName);
                Directory.CreateDirectory(sTargetDir);

                // カメラ画像転送ダイアログを開く
                var notification2 = new ImagTransferingNotification()
                {
                    Title                  = "カメラ画像転送",
                    SyncShooter            = _newSyncShooter,
                    ConnectedIPAddressList = ConnectedIPAddressList,
                    LocalHostIP            = _localHostIP,
                    TargetDir              = sTargetDir,
                };
                this.ImageTransferingRequest.Raise(notification2);

                // 「ファイルビュー」表示を更新
                FileTree.Clear();
                FileTree.Add(new FileTreeItem(this.ProjectFolderPath.Value));

                // 3D Dataを置くディレクトリを作る
                string sThreeDDataDir = Path.Combine(this.ThreeDDataFolderPath.Value, sTargetName);
                Directory.CreateDirectory(sThreeDDataDir);

                // 3D化(RC実行)タスクを実行
                var task = new Task(() => RunRCTask(sTargetDir, sThreeDDataDir, this.IsCutPetTable.Value));
                var pair = new Tuple <Task, string>(task, sTargetDir);
                task.ContinueWith(t => _runRCTaskList.Remove(pair));
                _runRCTaskList.Add(pair);
                task.Start();
            } catch (Exception e) {
                OpenMessageBox(this.Title.Value, MessageBoxImage.Error, MessageBoxButton.OK, MessageBoxResult.OK, e.Message);
            }
        }