예제 #1
0
        public RunRecipeDialogViewModel(RunRecipeDialogModel modelIn, MRecipe recipe)
        {
            _model = modelIn;
            _terminableTaskExecutor        = new TerminableTaskExecutor();
            _processTerminableTaskExecutor = new TerminableTaskExecutor();
            _dxfCachedLoader = new CachedLoader <List <IMarkGeometry> >();
            RecipeInfo       = new ObservableCollection <RecipeProcessEntityInfo>();
            _fiducialFinder  = new FiducialFinder();

            _processTimer.Elapsed += _processTimer_Elapsed;

            IsPaused  = false;
            IsRunning = false;

            try
            {
                IsLoading = true;
                SelectedSubProcessInfo = null;
                RecipeVm = recipe;
                GenerateRecipeInfo();
                Render();
            }
            catch (Exception exp)
            {
                _model.Log(exp);
                _model.Log("Failed to load recipe");
            }
            finally
            {
                IsLoading = false;
            }

            StartRecipeCommand = new DelegateCommand(
                () => {
                StartProcess();
            }
                );

            RestartCommand = new DelegateCommand(
                async() =>
            {
                if (IsRunning)
                {
                    Abort();

                    // wait a second for running tasks to stop
                    await Task.Delay(1000);
                }

                StartProcess();
            }
                );

            PauseContinueCommand = new DelegateCommand(
                () =>
            {
                try
                {
                    if (!IsPaused)
                    {
                        DispatcherMessageBox.ShowBox(
                            "The process will be paused when it is safe to do so.",
                            "Pause Request"
                            );

                        PrintLog("Process Paused ...");
                    }
                    else
                    {
                        PrintLog("Continue Process");
                    }

                    IsPaused = !IsPaused;
                }
                finally
                {
                }
            }
                );

            AbortRecipeCommand = new DelegateCommand(
                () =>
            {
                Abort();
            }
                );
        }
예제 #2
0
        public ImportPatternDialogViewModel(IEnumerable <IProcessConfiguration> availableProcessConfigurations, string defaultPatternDirectory, string defaultRecipeDirectory)
        {
            MShader = new MGLShader();
            _terminableTaskExecutor = new TerminableTaskExecutor();

            DefaultRecipeDirectory  = defaultRecipeDirectory;
            DefaultPatternDirectory = defaultPatternDirectory;

            SeperateLayers        = true;
            AlignmentType         = MAlignmentType.TypeAuto;
            TileSettings          = new MTileSettings();
            Fiducials             = new ObservableCollection <MFiducialInfo>();
            AvailableProcessModes = new ObservableCollection <IProcessConfiguration>(availableProcessConfigurations);

            SelectPatternFileCommand = new DelegateCommand(
                () =>
            {
                var dialog              = new OpenFileDialog();
                dialog.Filter           = "DXF files (*.dxf)|*.dxf";
                dialog.AddExtension     = true;
                dialog.InitialDirectory = defaultPatternDirectory;

                if (dialog.ShowDialog() != true)
                {
                    return;
                }

                PatternFilePath = dialog.FileName;
                FetchDXF(PatternFilePath);
                Render();
            }
                );

            SelectParametersFileCommand = new DelegateCommand(
                () =>
            {
                if (TargetProcessMode == null)
                {
                    MessageBox.Show(
                        @"Invalid process mode selected, please select a valid process mode.",
                        "Select a Process Mode"
                        );

                    return;
                }

                var dialog = new MarkParamEditorDialog(
                    TargetProcessMode?.ProcessParameterFileManager,
                    ProcessParametersFilePath
                    );

                if (dialog.ShowDialog() != true)
                {
                    return;
                }

                ProcessParametersFilePath = dialog.ParamFileManager.FilePath;
            }
                );

            AddFiducialCommand = new DelegateCommand(
                () =>
            {
                Fiducials.Add(new MFiducialInfo()
                {
                    Index = Fiducials.Count
                });
                Render();
            }
                );

            DeleteFiducialCommand = new DelegateCommand <MFiducialInfo>(
                (fiducial) =>
            {
                Fiducials.Remove(fiducial);

                // update Index
                for (int i = 0; i < Fiducials.Count; i++)
                {
                    Fiducials[i].Index = i;
                }

                Render();
            }
                );

            DeleteAllFiducialsCommand = new DelegateCommand(
                () =>
            {
                Fiducials.Clear();
                Render();
            }
                );

            RefreshCommand = new DelegateCommand(
                () =>
            {
                Render();
            }
                );
        }
예제 #3
0
        public ImportSTLDialogViewModel(IEnumerable <IProcessConfiguration> availableProcessConfigurations, string defaultSTLDirectory, string defaultRecipeDirectory)
        {
            MShader = new MGLShader();
            _terminableTaskExecutor = new TerminableTaskExecutor();

            DefaultRecipeDirectory = defaultRecipeDirectory;
            DefaultStlDirectory    = defaultSTLDirectory;

            _modelGroup            = new Model3DGroup();
            _stlSlices             = new List <MSTLSlice>();
            _slicePlanes           = new List <GeometryModel3D>();
            StlModelReferencePoint = new MVertexViewModel();
            HatchSettings          = new MHatchSettings();
            AlignmentType          = MAlignmentType.TypeAuto;
            TileSettings           = new MTileSettings();
            Fiducials             = new ObservableCollection <MFiducialInfo>();
            AvailableProcessModes = new ObservableCollection <IProcessConfiguration>(availableProcessConfigurations);

            SelectPatternFileCommand = new DelegateCommand(
                async() =>
            {
                var dialog              = new OpenFileDialog();
                dialog.Filter           = "STL files (*.stl)|*.stl";
                dialog.AddExtension     = true;
                dialog.InitialDirectory = defaultSTLDirectory;

                if (dialog.ShowDialog() != true)
                {
                    return;
                }

                PatternFilePath = dialog.FileName;
                await FetchSTL(PatternFilePath);
                Render();
            }
                );

            SelectParametersFileCommand = new DelegateCommand(
                () =>
            {
                if (TargetProcessMode == null)
                {
                    MessageBox.Show(
                        @"Invalid process mode selected, please select a valid process mode.",
                        "Select a Process Mode"
                        );

                    return;
                }

                var dialog = new MarkParamEditorDialog(
                    TargetProcessMode?.ProcessParameterFileManager,
                    ProcessParametersFilePath
                    );

                if (dialog.ShowDialog() != true)
                {
                    return;
                }

                ProcessParametersFilePath = dialog.ParamFileManager.FilePath;
            }
                );

            AddFiducialCommand = new DelegateCommand(
                () =>
            {
                Fiducials.Add(new MFiducialInfo()
                {
                    Index = Fiducials.Count
                });
                Render();
            }
                );

            DeleteFiducialCommand = new DelegateCommand <MFiducialInfo>(
                (fiducial) =>
            {
                Fiducials.Remove(fiducial);

                // update Index
                for (int i = 0; i < Fiducials.Count; i++)
                {
                    Fiducials[i].Index = i;
                }

                Render();
            }
                );

            DeleteAllFiducialsCommand = new DelegateCommand(
                () =>
            {
                Fiducials.Clear();
                Render();
            }
                );

            RefreshCommand = new DelegateCommand(
                () =>
            {
                Render();
            }
                );

            ShowPreviousSliceCommand = new DelegateCommand(() =>
            {
                if (NumberOfSlices == 0)
                {
                    CurrentSlice = 0;
                    return;
                }
                else if (CurrentSlice == 0)
                {
                    CurrentSlice = NumberOfSlices;
                }

                CurrentSlice = Math.Abs((CurrentSlice - 1) % NumberOfSlices);
                ShowSlice(CurrentSlice);
            });

            ShowNextSliceCommand = new DelegateCommand(() =>
            {
                if (NumberOfSlices == 0)
                {
                    CurrentSlice = 0;
                    return;
                }

                CurrentSlice = (CurrentSlice + 1) % NumberOfSlices;
                ShowSlice(CurrentSlice);
            });

            HatchCurrentLayerCommand = new DelegateCommand(async() =>
            {
                if (NumberOfSlices == 0)
                {
                    DispatcherMessageBox.ShowBox(
                        "There's no slice to hatch"
                        );
                    return;
                }

                var response = DispatcherMessageBox.ShowBox(
                    "This could take a while, do you wish to continue",
                    "Warning",
                    MessageBoxButton.YesNo
                    );

                if (response != MessageBoxResult.Yes)
                {
                    return;
                }

                try
                {
                    IsLoading = true;

                    await HatchSlice(CurrentSlice);

                    Render();
                }
                finally
                {
                    IsLoading = false;
                }
            });

            TileCurrentLayerCommand = new DelegateCommand(async() =>
            {
                if (NumberOfSlices == 0)
                {
                    DispatcherMessageBox.ShowBox(
                        "There's no slice to tile"
                        );
                    return;
                }

                try
                {
                    IsLoading = true;

                    await TileSlice(CurrentSlice);

                    Render();
                }
                finally
                {
                    IsLoading = false;
                }
            });

            HatchAllLayersCommand = new DelegateCommand(async() =>
            {
                if (NumberOfSlices == 0)
                {
                    DispatcherMessageBox.ShowBox(
                        "There's no slice to hatch"
                        );
                    return;
                }

                var response = DispatcherMessageBox.ShowBox(
                    "This could take a while, do you wish to continue",
                    "Warning",
                    MessageBoxButton.YesNo
                    );

                if (response != MessageBoxResult.Yes)
                {
                    return;
                }

                try
                {
                    IsLoading = true;

                    await HatchAllSlices();

                    Render();
                }
                finally
                {
                    IsLoading = false;
                }
            });

            TileAllLayersCommand = new DelegateCommand(async() =>
            {
                if (NumberOfSlices == 0)
                {
                    DispatcherMessageBox.ShowBox(
                        "There's no slice to hatch"
                        );
                    return;
                }

                try
                {
                    IsLoading = true;

                    await TileAllSlices();

                    Render();
                }
                finally
                {
                    IsLoading = false;
                }
            });
        }