public bool GenerateTiles(MTileSettings settings) { // delete previous tiles Tiles.Clear(); double refWidth = Extents.Width + settings.XPadding; double refHeight = Extents.Height + settings.YPadding; int nRows = (int)Math.Ceiling(refHeight / settings.YSize); int nColumns = (int)Math.Ceiling(refWidth / settings.XSize); var _halfTileWidth = 0.5 * settings.XSize; var _halfTileHeight = 0.5 * settings.YSize; var _centre = Extents.Centre - new MarkGeometryPoint(0.5 * (nColumns * settings.XSize), 0.5 * (nRows * settings.YSize)); for (int row = 0; row < nRows; row++) { for (int col = 0; col < nColumns; col++) { var centrePoint = new MarkGeometryPoint( (col * settings.XSize) + _halfTileWidth, (row * settings.YSize) + _halfTileHeight ); GeometricArithmeticModule.Translate(centrePoint, _centre.X + settings.XOffset, _centre.Y + settings.YOffset); Tiles.Add(new MarkGeometryRectangle(centrePoint, settings.XSize, settings.YSize)); } } return(true); }
public void Render() { _terminableTaskExecutor.CancelCurrentAndRun( (ctIn) => { // reset shader MShader.Reset(); if (_geometriesBuffer != null) { int count = 0; var extents = GeometryExtents <double> .CreateDefaultDouble(); foreach (var layerName in _geometriesBuffer.Keys) { MShader.AddDefault( _geometriesBuffer[layerName], _colours[(count++) % _colours.Length] ); extents = GeometryExtents <double> .Combine( extents, GeometricArithmeticModule.CalculateExtents(_geometriesBuffer[layerName]) ); } // overlay tiles foreach (var tile in MTileSettings.ToTiles(TileSettings, extents)) { MShader.AddDefault((MarkGeometryRectangle)tile, _tileColor); } // calculate size of fiducial relative to the node var fiducialSize = 0.05 * extents.Hypotenuse; // generate fiducial pattern GenerateFiducialPattern(fiducialSize); // get base transform var baseTransform = GeometricArithmeticModule.GetTranslationTransformationMatrix( extents.Centre.X, extents.Centre.Y ); // render fiducials in parent's reference frame foreach (var fiducial in Fiducials) { var transform = GeometricArithmeticModule.CombineTransformations( baseTransform, GeometricArithmeticModule.GetTranslationTransformationMatrix( fiducial.X, fiducial.Y, fiducial.Z ) ); foreach (var geometry in _fiducialPattern) { var clone = (IMarkGeometry)geometry.Clone(); clone.Transform(transform); MShader.AddDefault(clone, _fiducialColor); } } } // stop if new render is requested ctIn.ThrowIfCancellationRequested(); MShader.Render(); DrawingExtentsX = MShader.Width; DrawingExtentsY = MShader.Height; DrawingCount = MShader.Count; } ); }
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(); } ); }
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; } }); }