Example #1
0
        private GeometryExtents <double> AddLayer(MRecipe recipe, MRecipeDeviceLayer layer)
        {
            var extents = GeometryExtents <double> .CreateDefaultDouble();

            // calculate layer's transform
            var transform = MRecipe.GetRelativeTransform(recipe, layer);

            // fetch geometries from pattern file
            var geometries = _fetchDxfFunc(layer.PatternFilePath);

            for (int i = 0; i < geometries?.Count; i++)
            {
                var clone = (IMarkGeometry)geometries[i].Clone();
                clone.Transform(transform);

                // render geometry
                AddDefault(
                    clone,
                    DefaultColor
                    );

                // update extents
                extents = GeometryExtents <double> .Combine(
                    extents,
                    clone.Extents
                    );
            }

            return(extents);
        }
Example #2
0
        public virtual void AddLayerTiles(MRecipe recipe, MRecipeDeviceLayer layer)
        {
            // get layer's transform
            var transform = MRecipe.GetRelativeTransform(recipe, layer);

            // update layer's tile info
            if (layer.TileDescriptions.Count <= 0)
            {
                layer.GenerateTileDescriptionsFromSettings(
                    (patternFilePath) =>
                {
                    return(GeometricArithmeticModule.CalculateExtents(
                               _fetchDxfFunc(patternFilePath)
                               ));
                }
                    );
            }

            // render tiles
            for (int i = 0; i < layer.TileDescriptions.Count; i++)
            {
                var tile = (MarkGeometryRectangle)layer.TileDescriptions[i];
                tile.Transform(transform);

                AddDefault(tile, TileColor);
            }
        }
Example #3
0
        public async Task <Matrix4x4> GetAbsoluteTransformFromStageOrigin(
            IProcessConfigurationTasksHandler taskHandler,
            ICamToBeam cam2Beam,
            MRecipe recipe,
            MRecipeBaseNode recipeNode,
            CancellationToken ctIn
            )
        {
            // firstly, find closest parent with fiducials
            var parent = recipeNode;

            while (
                parent != null &&
                parent.Fiducials.Count <= 0
                )
            {
                parent = parent.Parent as MRecipeBaseNode;
            }

            if (parent != null)
            {
                // recursion - get it's parent's transform
                var baseTransform = await GetAbsoluteTransformFromStageOrigin(
                    taskHandler, cam2Beam, recipe, parent.Parent as MRecipeBaseNode, ctIn
                    );

                var fiducialPoints = new List <MarkGeometryPoint>();
                var measuredPoints = new List <MarkGeometryPoint>();

                for (int i = 0; i < parent.Fiducials.Count; i++)
                {
                    var fiducial = parent.Fiducials[i];

                    if (!_cachedFiducials.ContainsKey(fiducial))
                    {
                        // estimate stage position
                        var stageLocation = new MarkGeometryPoint(
                            fiducial.X, fiducial.Y, fiducial.Z
                            );
                        stageLocation.Transform(baseTransform);

                        // goto estimated position
                        if (!await taskHandler.GotoXY(
                                stageLocation.X, stageLocation.Y, ctIn
                                ))
                        {
                            throw new Exception($"Failed to goto the estimated position; origin: {await taskHandler.GetStageOrigin(ctIn)}, fiducial: {(fiducial.X, fiducial.Y)} est: {stageLocation}");
                        }

                        // find and centre
                        {
                            if (!await cam2Beam.MoveBeamToCamOffset(ctIn))
                            {
                                throw new Exception($"Failed to move beam to cam offset");
                            }

                            if (!await taskHandler.MovetoCameraFocus(ctIn))
                            {
                                throw new Exception($"Failed to move camera to focus");
                            }

                            await taskHandler.SwitchCameraLedOn(ctIn);

                            // attempt to centre on fiducial
                            if (!await taskHandler.CentreOnVisibleObject(ctIn))
                            {
                                _logger.Info($"Failed to centre on fiducial");

                                // ask user to locate fiducials
                                Application.Current.Dispatcher.Invoke(
                                    () =>
                                {
                                    var fidVm              = taskHandler.GetNewFidFindViewModel();
                                    var inspectionDialog   = new InspectionWindow(fidVm, Application.Current.MainWindow);
                                    inspectionDialog.Owner = Application.Current.MainWindow;

                                    if (inspectionDialog.ShowDialog() != true)
                                    {
                                        throw new Exception("Failed to find fiducial");
                                    }

                                    // TODO : think about updating the machine's origin
                                }
                                    );
                            }

                            if (!await cam2Beam.MoveCamToBeamOffset(ctIn))
                            {
                                throw new Exception($"Failed to move camera to beam offset");
                            }
                        }

                        // read fiducial position
                        var(stgX, stgY, success) = await taskHandler.GetStageXY(ctIn);

                        if (!success)
                        {
                            throw new Exception("Failed to read the current stage position");
                        }

                        // update cache
                        _cachedFiducials[fiducial] = new MarkGeometryPoint(stgX, stgY);
                    }

                    // update measured points
                    fiducialPoints.Add(new MarkGeometryPoint(fiducial.X, fiducial.Y));
                    measuredPoints.Add(_cachedFiducials[fiducial]);
                }

                // calculate transform from measured fiducials
                var parentTransform = GeometricArithmeticModule.EstimateTransformationMatrixFromPoints(
                    fiducialPoints, measuredPoints
                    );

                return(GeometricArithmeticModule.CombineTransformations(
                           parentTransform,
                           await InvertTransform(
                               taskHandler,
                               parentTransform,
                               MRecipe.GetRelativeTransformFromParent(
                                   parent, recipeNode
                                   ),
                               ctIn
                               )
                           ));
            }

            var origin = await taskHandler.GetStageOrigin(ctIn);

            var stageOrigin = GeometricArithmeticModule.GetTranslationTransformationMatrix(
                origin.X, origin.Y
                );

            return(GeometricArithmeticModule.CombineTransformations(
                       stageOrigin,
                       await InvertTransform(
                           taskHandler,
                           stageOrigin,
                           MRecipe.GetRelativeTransform(
                               recipe, recipeNode
                               ),
                           ctIn
                           )
                       ));
        }
Example #4
0
        public void Render()
        {
            _terminableTaskExecutor.CancelCurrentAndRun(
                (ctIn) =>
            {
                // reset shader
                MShader.Reset();

                // stop if new render is requested
                ctIn.ThrowIfCancellationRequested();

                // as we only render one layer at a time
                // choose the closest layer in the recipe tree
                var layer = GetClosestLayer();

                if (layer != null)
                {
                    // extract device's absolute transform
                    var baseTransform = MRecipe.GetRelativeTransform(RecipeVm, layer);

                    // calculate layer's transform
                    var transform = GeometricArithmeticModule.CombineTransformations(
                        baseTransform,
                        layer.TransformInfo.ToMatrix4x4()
                        );

                    // fetch pattern
                    var pattern = FetchDXF(layer);

                    for (int j = 0; j < pattern?.Count; j++)
                    {
                        // get copy of geometry
                        var geometry = (IMarkGeometry)pattern[j].Clone();

                        // apply transform to geometry
                        geometry.Transform(transform);

                        // add geometry
                        MShader.AddDefault(geometry);
                    }

                    // overlay tiles
                    foreach (var tile in layer.TileDescriptions)
                    {
                        var rect = (MarkGeometryRectangle)tile;

                        // apply transform to rect
                        rect.Transform(transform);

                        // add geometry
                        MShader.AddDefault(rect, MGLShader.Violet);
                    }
                }

                // stop if new render is requested
                ctIn.ThrowIfCancellationRequested();

                MShader.Render();
                UpdateStats();
            }
                );
        }