Esempio n. 1
0
 internal void SetCommunicationManager(Viewport3DXext _comm_manager)
 {
     if (this.communcation_manager == null && _comm_manager != null)
     {
         this.communcation_manager = _comm_manager;
     }
 }
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // ============================================ OBJECT SNAP HANDLING ====================================== //
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////

        #region OBJECT SNAP

        // OLD: NOT IN USE
        public int OnMouseMove(Point _currentHit, Viewport3DXext _vp, out Point3D snapPoint, int _pixelTolerance = 20)
        {
            snapPoint = new Point3D(0, 0, 0);

            if (_currentHit == null || _vp == null)
            {
                return(-1);
            }

            // test the potential candidates
            int n = this.PointsVisible_End.Count;

            if (n == 0)
            {
                return(-1);
            }

            for (int i = 0; i < n; i++)
            {
                // device coordinates
                // lower left: (-1,-1), upper right: (1,1)
                Point test = _vp.Project(this.PointsVisible_End[i]);
                if (test != null)
                {
                    // viewport pixel coordinates
                    // screen upper left: (0,0), lower right (width, height)
                    Point  test_PixelCoords = new Point((1 + test.X) * 0.5 * _vp.ActualWidth, (1 - test.Y) * 0.5 * _vp.ActualHeight);
                    double dist             = Math.Abs(_currentHit.X - test_PixelCoords.X) + Math.Abs(_currentHit.Y - test_PixelCoords.Y);
                    if (dist < _pixelTolerance)
                    {
                        // snap found
                        Vector3D offset       = this.PointsVisible_End[i] - new Point3D(0, 0, 0);
                        double   scale        = Vector3.Distance(this.PointsVisible_End[i].ToVector3(), _vp.Camera.Position.ToVector3());
                        float    factOrthoCam = ((_vp.Camera as HelixToolkit.SharpDX.OrthographicCamera) != null) ? SNAP_ORTHOFACT : 1.0f;
                        scale *= factOrthoCam;

                        Matrix3D M = Matrix3D.Identity;
                        M.Scale(new Vector3D(scale, scale, scale));
                        M.Translate(offset);
                        this.snapMarker.Transform  = new MatrixTransform3D(M);
                        this.snapMarker.Visibility = Visibility.Visible;

                        snapPoint = this.PointsVisible_End[i];
                        return(i);
                    }
                    else
                    {
                        this.snapMarker.Transform  = new MatrixTransform3D(Matrix3D.Identity);
                        this.snapMarker.Visibility = Visibility.Hidden;
                    }
                }
            }

            return(-1);
        }
Esempio n. 3
0
        private void getActors()
        {
            var parent = this.Parent;

            if (parent == null)
            {
                return;
            }

            Viewport3DXext vp = parent as Viewport3DXext;

            if (vp == null)
            {
                return;
            }

            foreach (var item in vp.Items)
            {
                this.viewPort = vp;
                LineGenerator3D      linGen      = item as LineGenerator3D;
                ArchitectureDisplay  arcDisp     = item as ArchitectureDisplay;
                ZoneGroupDisplay     zoneDisp    = item as ZoneGroupDisplay;
                ComponentDisplay     comprepDisp = item as ComponentDisplay;
                OcTreeManager        otMan       = item as OcTreeManager;
                ViewFrustumFunctions vfFunc      = item as ViewFrustumFunctions;
                if (linGen != null)
                {
                    this.LineGen = linGen;
                }
                if (arcDisp != null)
                {
                    this.ArcDisp = arcDisp;
                }
                if (zoneDisp != null)
                {
                    this.ZoneDisp = zoneDisp;
                    if (zoneDisp != null)
                    {
                        this.ZoneDisp.PropertyChanged += ZoneDisp_PropertyChanged;
                    }
                }
                if (comprepDisp != null)
                {
                    this.CompDisp = comprepDisp;
                }
                if (otMan != null)
                {
                    this.OTManager = otMan;
                }
                if (vfFunc != null)
                {
                    this.ViewFF = vfFunc;
                }
            }
        }
        private static int SnapTestPoints(Point _currentHit, Viewport3DXext _vp, out Point3D snapPoint, int _pixelTolerance,
                                          List <Point3D> _pointsToTest)
        {
            snapPoint = new Point3D(0, 0, 0);

            if (_currentHit == null || _vp == null || _pointsToTest == null)
            {
                return(-1);
            }

            // test the potential candidates
            int n = _pointsToTest.Count;

            if (n == 0)
            {
                return(-1);
            }

            for (int i = 0; i < n; i++)
            {
                // device coordinates
                // lower left: (-1,-1), upper right: (1,1)
                Point test = _vp.Project(_pointsToTest[i]);
                if (test != null)
                {
                    // viewport pixel coordinates
                    // screen upper left: (0,0), lower right (width, height)
                    Point  test_PixelCoords = new Point((1 + test.X) * 0.5 * _vp.ActualWidth, (1 - test.Y) * 0.5 * _vp.ActualHeight);
                    double dist             = Math.Abs(_currentHit.X - test_PixelCoords.X) + Math.Abs(_currentHit.Y - test_PixelCoords.Y);
                    if (dist < _pixelTolerance)
                    {
                        snapPoint = _pointsToTest[i];
                        return(i);
                    }
                }
            }

            return(-1);
        }
        public int OnMouseMove(Point _currentHit, Viewport3DXext _vp, out Point3D snapPoint,
                               bool _testEnd, bool _testMid, bool _testInters, int _pixelTolerance = 20)
        {
            int foundIndex = -1;

            snapPoint = new Point3D(0, 0, 0);

            if (_currentHit == null || _vp == null)
            {
                return(foundIndex);
            }

            // test points priority: END > INTERSECTION > MIDPOINT
            if (_testEnd)
            {
                foundIndex = OcTreeManager.SnapTestPoints(_currentHit, _vp, out snapPoint, _pixelTolerance,
                                                          this.PointsVisible_End);
                if (foundIndex != -1)
                {
                    this.snapMarker.Geometry = OcTreeManager.EndPoint;
                }
            }

            if (_testInters && foundIndex == -1)
            {
                foundIndex = OcTreeManager.SnapTestPoints(_currentHit, _vp, out snapPoint, _pixelTolerance,
                                                          this.PointsCollision);
                if (foundIndex != -1)
                {
                    this.snapMarker.Geometry = OcTreeManager.IntPoint;
                }
            }

            if (_testMid && foundIndex == -1)
            {
                foundIndex = OcTreeManager.SnapTestPoints(_currentHit, _vp, out snapPoint, _pixelTolerance,
                                                          this.PointsVisible_Mid);
                if (foundIndex != -1)
                {
                    this.snapMarker.Geometry = OcTreeManager.MidPoint;
                }
            }

            // process display
            if (foundIndex != -1)
            {
                // snap found
                Vector3D offset       = snapPoint - new Point3D(0, 0, 0);
                double   scale        = Vector3.Distance(snapPoint.ToVector3(), _vp.Camera.Position.ToVector3());
                float    factOrthoCam = ((_vp.Camera as HelixToolkit.SharpDX.OrthographicCamera) != null) ? SNAP_ORTHOFACT : 1.0f;
                scale *= factOrthoCam;

                Matrix3D M = Matrix3D.Identity;
                M.Scale(new Vector3D(scale, scale, scale));
                M.Translate(offset);

                this.snapMarker.Transform  = new MatrixTransform3D(M);
                this.snapMarker.Visibility = Visibility.Visible;
            }
            else
            {
                this.snapMarker.Transform  = new MatrixTransform3D(Matrix3D.Identity);
                this.snapMarker.Visibility = Visibility.Hidden;
            }

            return(foundIndex);
        }