private void OnRoutToolMoveMessage(RoutToolMoveMessage msg)
        {
            if (_stepObserver.Direction == StepExecutionDirection.Back)
            {
                return;
            }

            var tool  = ImplicitToolFactory.Create(msg.Position, msg.Direction, msg.Length, msg.Radius);
            var panel = new AxisAlignedBox3d(new Vector3d(_cornerX, _cornerY, _cornerZ), new Vector3d(_cornerX + SizeX, _cornerY + SizeY, _cornerZ + SizeZ));

            //DispatcherHelper.CheckBeginInvokeOnUI(() =>
            //{
            //    var builder = new MeshBuilder();

            //    builder.AddSphere(msg.Position, 10);
            //    PanelModel.Children.Add(new GeometryModel3D() { Geometry = builder.ToMesh(), Material = MaterialHelper.CreateMaterial(Colors.Yellow) });
            //});

            Task.Run(() =>
            {
                var toolBound = tool.Bounds();

                if (panel.Intersects(toolBound))
                {
                    var routing = _lastRoutings.GetOrAdd(msg.ToolId, (id) => ImplicitRoutingFactory.Create(id, msg.Direction.ToVector3d(), msg.Length, msg.Radius));
                    var pt      = msg.Position.ToVector3d();
                    var box     = routing.Add(ref pt);

                    var intersect = panel.Intersect(box);
                    var xMinIndex = GetSectionIndex(intersect.Min.x, panel.Min.x, panel.Max.x, _nxSection);
                    var xMaxIndex = GetSectionIndex(intersect.Max.x, panel.Min.x, panel.Max.x, _nxSection);
                    var yMinIndex = GetSectionIndex(intersect.Min.y, panel.Min.y, panel.Max.y, _nySection);
                    var yMaxIndex = GetSectionIndex(intersect.Max.y, panel.Min.y, panel.Max.y, _nySection);

                    if (xMinIndex < 0)
                    {
                        xMinIndex = 0;
                    }
                    if (yMinIndex < 0)
                    {
                        yMinIndex = 0;
                    }

                    for (int i = xMinIndex; i <= xMaxIndex; i++)
                    {
                        for (int j = yMinIndex; j <= yMaxIndex; j++)
                        {
                            MessengerInstance.Send(new SectionRoutToolMoveMessage()
                            {
                                XSectionIndex = i, YSectionIndex = j, Rout = routing
                            });
                        }
                    }
                }
                else
                {
                    _lastRoutings.TryRemove(msg.ToolId, out ImplicitRouting ir);
                }
            });
        }
        private void OnToolMoveMessage(ToolMoveMessage msg)
        {
            if (_stepObserver.Direction == StepExecutionDirection.Back)
            {
                return;
            }

            //var position = PanelModel.Transform.Inverse.Transform(msg.Position);
            //var tool = ImplicitToolFactory.Create(position.ToVector3d(), msg.Direction.ToVector3d(), msg.Length, msg.Radius);
            var tool  = ImplicitToolFactory.Create(msg.Position, msg.Direction, msg.Length, msg.Radius);
            var panel = new AxisAlignedBox3d(new Vector3d(_cornerX, _cornerY, _cornerZ), new Vector3d(_cornerX + SizeX, _cornerY + SizeY, _cornerZ + SizeZ));

            tool.Index = _stepObserver.Index;
            //{
            //    var builder = new MeshBuilder();

            //    builder.AddSphere(msg.Position, 10);
            //    PanelModel.Children.Add(new GeometryModel3D() { Geometry = builder.ToMesh(), Material = MaterialHelper.CreateMaterial(Colors.Yellow) });
            //}

            Task.Run(() =>
            {
                var toolBound = tool.Bounds();

                if (panel.Intersects(toolBound))
                {
                    var intersect = panel.Intersect(toolBound);
                    var xMinIndex = GetSectionIndex(intersect.Min.x, panel.Min.x, panel.Max.x, _nxSection);
                    var xMaxIndex = GetSectionIndex(intersect.Max.x, panel.Min.x, panel.Max.x, _nxSection);
                    var yMinIndex = GetSectionIndex(intersect.Min.y, panel.Min.y, panel.Max.y, _nySection);
                    var yMaxIndex = GetSectionIndex(intersect.Max.y, panel.Min.y, panel.Max.y, _nySection);

                    if (xMinIndex < 0)
                    {
                        xMinIndex = 0;
                    }
                    if (yMinIndex < 0)
                    {
                        yMinIndex = 0;
                    }

                    for (int i = xMinIndex; i <= xMaxIndex; i++)
                    {
                        for (int j = yMinIndex; j <= yMaxIndex; j++)
                        {
                            MessengerInstance.Send(new SectionToolMoveMessage()
                            {
                                XSectionIndex = i, YSectionIndex = j, Tool = tool
                            });
                        }
                    }
                }
            });
        }