예제 #1
0
        public RecipeLayerUserControl()
        {
            InitializeComponent();

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

                if (File.Exists(MRecipeDeviceLayerItemSource.PatternFilePath))
                {
                    dialog.InitialDirectory = Path.GetDirectoryName(MRecipeDeviceLayerItemSource.PatternFilePath);
                }

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

                MRecipeDeviceLayerItemSource.PatternFilePath = dialog.FileName;
            }
                );

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

                    return;
                }

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

                if (dialog.ShowDialog() == true)
                {
                    MRecipeDeviceLayerItemSource.ProcessParametersFilePath = dialog.ParamFileManager.FilePath;
                }
            }
                );
        }
예제 #2
0
        private Model3D ImportModel3D(string stlFilePathIn)
        {
            Model3D model3d = null;

            try
            {
                var modelImporter = new ModelImporter();
                modelImporter.DefaultMaterial = ModelMaterial;
                model3d = modelImporter.Load(stlFilePathIn);
            }
            catch (Exception)
            {
                //_model.Log(exp);
                //_model.Log("Failed to parse STL file");

                DispatcherMessageBox.ShowBox(
                    "Failed to parse STL file."
                    );
            }

            return(model3d);
        }
예제 #3
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();
            }
                );
        }
예제 #4
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;
                }
            });
        }