Bcfier.XbimXplorer.MainWindow.OnOpenView C# (CSharp) Method

OnOpenView() private method

private OnOpenView ( object sender, System.Windows.Input.ExecutedRoutedEventArgs e ) : void
sender object
e System.Windows.Input.ExecutedRoutedEventArgs
return void
        private void OnOpenView(object sender, ExecutedRoutedEventArgs e)
        {
            if (Bcfier.SelectedBcf() == null)
                return;
            var view = e?.Parameter as ViewPoint;

            if (view == null)
                return;
            var v = view.VisInfo;

            var position = new XbimPoint3D();
            var direction = new XbimPoint3D();
            var upDirection = new XbimPoint3D();

            if (v.PerspectiveCamera != null)
            {
                // todo: this works internally, but we must ensure it's compatible with other bcf viewers
                var pc = v.PerspectiveCamera;
                position = new XbimPoint3D(pc.CameraViewPoint.X, pc.CameraViewPoint.Y, pc.CameraViewPoint.Z);
                direction = new XbimPoint3D(pc.CameraDirection.X, pc.CameraDirection.Y, pc.CameraDirection.Z);
                upDirection = new XbimPoint3D(pc.CameraUpVector.X, pc.CameraUpVector.Y, pc.CameraUpVector.Z);

                _xpWindow.DrawingControl.Viewport.Orthographic = false;
                var pCam = _xpWindow.DrawingControl.Viewport.Camera as System.Windows.Media.Media3D.PerspectiveCamera;
                if (pCam != null)
                    pCam.FieldOfView = pc.FieldOfView;
            }
            else if (v.OrthogonalCamera != null)
            {
                // todo: this works internally, but we must ensure it's compatible with other bcf viewers
                var pc = v.OrthogonalCamera;
                _xpWindow.DrawingControl.Viewport.Orthographic = true;
                position = new XbimPoint3D(pc.CameraViewPoint.X, pc.CameraViewPoint.Y, pc.CameraViewPoint.Z);
                direction = new XbimPoint3D(pc.CameraDirection.X, pc.CameraDirection.Y, pc.CameraDirection.Z);
                upDirection = new XbimPoint3D(pc.CameraUpVector.X, pc.CameraUpVector.Y, pc.CameraUpVector.Z);

                var pCam = _xpWindow.DrawingControl.Viewport.Camera as OrthographicCamera;
                if (pCam != null)
                    pCam.Width = pc.ViewToWorldScale;
            }
            var directionV = new XbimVector3D(direction.X, direction.Y, direction.Z);
            var upDirectionV = new XbimVector3D(upDirection.X, upDirection.Y, upDirection.Z);

            var pos = new Point3D(position.X, position.Y, position.Z);
            var dir = new Vector3D(directionV.X, directionV.Y, directionV.Z);
            var upDir = new Vector3D(upDirectionV.X, upDirectionV.Y, upDirectionV.Z);
            _xpWindow.DrawingControl.Viewport.SetView(pos, dir, upDir, 500);

            if (v.ClippingPlanes != null && v.ClippingPlanes.Any()) {
                var curP = v.ClippingPlanes[0];
                _xpWindow.DrawingControl.SetCutPlane(
                    curP.Location.X, curP.Location.Y, curP.Location.Z,
                    curP.Direction.X, curP.Direction.Y, curP.Direction.Z
                    );
            }
            else
            {
                _xpWindow.DrawingControl.ClearCutPlane();
            }

            // todo: components list to be implemented
        }