コード例 #1
0
#pragma warning disable 1591
        public override void SetValueOrMissing(TRowKey rowKey, TColKey colKey, TValue value)
#pragma warning restore 1591
        {
            //This is needed because rows and columns are are OK in the parent may not be OK here
            Helper.CheckCondition(ContainsRowAndColKeys(rowKey, colKey), Properties.Resource.ExpectedRowKeyAndColKeyToBeInMatrix, rowKey, colKey);
            ParentMatrix.SetValueOrMissing(rowKey, colKey, value);
        }
コード例 #2
0
 private TValueParent ViewValueOrMissingToParentValueOrMissing(TValueView value)
 {
     if (IsMissing(value))
     {
         return(ParentMatrix.MissingValue);
     }
     else
     {
         TValueParent valueParent = ViewValueToParentValue(value);
         Helper.CheckCondition(!ParentMatrix.IsMissing(valueParent), Properties.Resource.MayNotConvert);
         return(valueParent);
     }
 }
コード例 #3
0
 private TValueParent ViewValueOrMissingToParentValueOrMissing(TValueView value)
 {
     if (IsMissing(value))
     {
         return(ParentMatrix.MissingValue);
     }
     else
     {
         TValueParent valueParent = ViewValueToParentValue(value);
         Helper.CheckCondition(!ParentMatrix.IsMissing(valueParent), "The Converter may not convert a non-missing value into the missing value.");
         return(valueParent);
     }
 }
コード例 #4
0
#pragma warning disable 1591
        public override bool TryGetValue(TRowKey rowKey, TColKey colKey, out TValueView valueView)
#pragma warning restore 1591
        {
            TValueParent parentValueOrMissing = ParentMatrix.GetValueOrMissing(rowKey, colKey);

            valueView = ParentValueToViewValue(parentValueOrMissing);
            if (!IsMissing(valueView))
            {
                return(true);
            }
            else
            {
                valueView = MissingValue;
                return(false);
            }
        }
コード例 #5
0
        #pragma warning disable 1591
        public override bool TryGetValue(int rowIndex, int colIndex, out TValueView value)
        #pragma warning restore 1591
        {
            TValueParent valueParent;

            if (ParentMatrix.TryGetValue(rowIndex, colIndex, out valueParent))
            {
                value = ParentValueToViewValue(valueParent);
                return(true);
            }
            else
            {
                value = MissingValue;
                return(false);
            }
        }
コード例 #6
0
        #pragma warning disable 1591
        public override bool TryGetValue(TRowKey rowKey, TColKey colKey, out TValueView value)
        #pragma warning restore 1591
        {
            TValueParent valueParent;

            if (ParentMatrix.TryGetValue(rowKey, colKey, out valueParent))
            {
                value = ParentValueToViewValue(valueParent);
                return(true);
            }
            else
            {
                value = MissingValue;
                return(false);
            }
        }
コード例 #7
0
#pragma warning disable 1591
        public override bool TryGetValue(int rowIndex, int colIndex, out TValueView valueView)
#pragma warning restore 1591
        {
            TValueParent parentValueOrMissing = ParentMatrix.GetValueOrMissing(rowIndex, colIndex);

            valueView = ParentValueToViewValue(parentValueOrMissing);
            if (!IsMissing(valueView))
            {
                return(true);
            }
            else
            {
                valueView = MissingValue;
                return(false);
            }
        }
コード例 #8
0
#pragma warning disable 1591
        public override bool TryGetValue(TRowKey rowKey, TColKey colKey, out TValueView value)
#pragma warning restore 1591
        {
            TValueParent valueParent;

            if (ParentMatrix.TryGetValue(rowKey, colKey, out valueParent))
            {
                value = ParentValueToViewValue(valueParent);
                Helper.CheckCondition(!IsMissing(value), Properties.Resource.MayNotConvert);
                return(true);
            }
            else
            {
                value = MissingValue;
                return(false);
            }
        }
コード例 #9
0
        #pragma warning disable 1591
        public override bool TryGetValue(TRowKey rowKey, TColKey colKey, out TValueView valueView)
        #pragma warning restore 1591
        {
            TValueParent valueParent;

            if (ParentMatrix.TryGetValue(rowKey, colKey, out valueParent))
            {
                valueView = ParentValueToViewValue(valueParent);
                Helper.CheckCondition(!IsMissing(valueView), "The Converter may not convert a non-missing value into the missing value.");
                return(true);
            }
            else
            {
                valueView = MissingValue;
                return(false);
            }
        }
コード例 #10
0
ファイル: MoveableHelper.cs プロジェクト: Abishai2007/actools
        public bool MoveObject(Vector2 relativeFrom, Vector2 relativeDelta, CameraBase camera, bool tryToClone, [CanBeNull] out IMoveable cloned)
        {
            if (_keepHighlight)
            {
                tryToClone = false;
            }
            else
            {
                _keepHighlight = true;
            }

            cloned = null;

            if (_arrowHighlighted != default(Vector3))
            {
                Vector3 planeNormal;
                if (_arrowHighlighted.Y == 0f)
                {
                    planeNormal = Vector3.UnitY;
                }
                else if (_arrowHighlighted.X == 0f)
                {
                    if (_arrowHighlighted.Z == 0f)
                    {
                        planeNormal = camera.Look.X.Abs() < camera.Look.Z.Abs() ? Vector3.UnitZ : Vector3.UnitX;
                    }
                    else
                    {
                        planeNormal = Vector3.UnitX;
                    }
                }
                else if (_arrowHighlighted.Z == 0f)
                {
                    planeNormal = Vector3.UnitZ;
                }
                else
                {
                    planeNormal = -camera.Look;
                }

                var plane   = new Plane(ParentMatrix.GetTranslationVector(), planeNormal);
                var rayFrom = camera.GetPickingRay(relativeFrom, new Vector2(1f, 1f));
                var rayTo   = camera.GetPickingRay(relativeFrom + relativeDelta, new Vector2(1f, 1f));

                float distance;

                if (!Ray.Intersects(rayFrom, plane, out distance))
                {
                    return(false);
                }
                var pointFrom = rayFrom.Position + rayFrom.Direction * distance;

                if (!Ray.Intersects(rayTo, plane, out distance))
                {
                    return(false);
                }
                var pointTo    = rayTo.Position + rayTo.Direction * distance;
                var pointDelta = pointTo - pointFrom;

                if (tryToClone)
                {
                    cloned = _parent.Clone();
                }

                var xOver = pointDelta.X.Abs();
                if (xOver > 1f)
                {
                    pointDelta.X /= xOver;
                }

                var yOver = pointDelta.Y.Abs();
                if (yOver > 1f)
                {
                    pointDelta.Y /= yOver;
                }

                var zOver = pointDelta.Z.Abs();
                if (zOver > 1f)
                {
                    pointDelta.Z /= zOver;
                }

                var resultMovement = new Vector3(
                    pointDelta.X * _arrowHighlighted.X,
                    pointDelta.Y * _arrowHighlighted.Y,
                    pointDelta.Z * _arrowHighlighted.Z);
                _parent.Move(resultMovement);
                UpdateBoundingBox();
                return(true);
            }

            if (_circleHighlighted != default(Vector3))
            {
                var rotationAxis = _circleHighlighted.X * _circleHighlighted.Y * _circleHighlighted.Z != 0f ?
                                   camera.Look : _circleHighlighted;

                if (tryToClone)
                {
                    cloned = _parent.Clone();
                }

                _parent.Rotate(Quaternion.RotationAxis(rotationAxis, relativeDelta.X * 10f));
                UpdateBoundingBox();
                return(true);
            }

            return(false);
        }
コード例 #11
0
 #pragma warning disable 1591
 public override bool Remove(TRowKey rowKey, TColKey colKey)
 #pragma warning restore 1591
 {
     Helper.CheckCondition(ContainsRowAndColKeys(rowKey, colKey), Properties.Resource.ExpectedRowKeyAndColKeyToBeInMatrix, rowKey, colKey);
     return(ParentMatrix.Remove(rowKey, colKey));
 }
コード例 #12
0
#pragma warning disable 1591
        public override void SetValueOrMissing(TRowKey rowKey, TColKey colKey, TValueView value)
#pragma warning restore 1591
        {
            ParentMatrix.SetValueOrMissing(rowKey, colKey, ViewValueOrMissingToParentValueOrMissing(value));
        }
コード例 #13
0
#pragma warning disable 1591
        public override void SetValueOrMissing(int rowIndex, int colIndex, TValueView value)
#pragma warning restore 1591
        {
            ParentMatrix.SetValueOrMissing(rowIndex, colIndex, ViewValueOrMissingToParentValueOrMissing(value));
        }
コード例 #14
0
        public void Draw(IDeviceContextHolder holder, ICamera camera, SpecialRenderMode mode, Func <IRenderableObject, bool> filter = null)
        {
            const float arrowSize  = 0.08f;
            const float circleSize = 0.06f;
            const float boxSize    = 0.14f;

            if (_arrowX == null)
            {
                _arrowX = DebugLinesObject.GetLinesArrow(Matrix.Identity, Vector3.UnitX, new Color4(0f, 1f, 0f, 0f), arrowSize);
                _arrowY = DebugLinesObject.GetLinesArrow(Matrix.Identity, Vector3.UnitY, new Color4(0f, 0f, 1f, 0f), arrowSize);
                _arrowZ = DebugLinesObject.GetLinesArrow(Matrix.Identity, Vector3.UnitZ, new Color4(0f, 0f, 0f, 1f), arrowSize);

                if (_rotationAxis.HasFlag(MoveableRotationAxis.X))
                {
                    _circleX = DebugLinesObject.GetLinesCircle(Matrix.Identity, Vector3.UnitX, new Color4(0f, 1f, 0f, 0f), radius: circleSize);
                }

                if (_rotationAxis.HasFlag(MoveableRotationAxis.Y))
                {
                    _circleY = DebugLinesObject.GetLinesCircle(Matrix.Identity, Vector3.UnitY, new Color4(0f, 0f, 1f, 0f), radius: circleSize);
                }

                if (_rotationAxis.HasFlag(MoveableRotationAxis.Z))
                {
                    _circleZ = DebugLinesObject.GetLinesCircle(Matrix.Identity, Vector3.UnitZ, new Color4(0f, 0f, 0f, 1f), radius: circleSize);
                }

                if (_allowScaling)
                {
                    _scale = DebugLinesObject.GetLinesBox(Matrix.Identity, new Vector3(boxSize), new Color4(0f, 1f, 1f, 0f));
                }
            }

            var matrix = ParentMatrix.GetTranslationVector().ToFixedSizeMatrix(camera);

            if (_arrowX.ParentMatrix != matrix)
            {
                _arrowX.ParentMatrix = matrix;
                _arrowY.ParentMatrix = matrix;
                _arrowZ.ParentMatrix = matrix;

                _arrowX.UpdateBoundingBox();
                _arrowY.UpdateBoundingBox();
                _arrowZ.UpdateBoundingBox();

                if (_circleX != null)
                {
                    _circleX.ParentMatrix = matrix;
                    _circleX.UpdateBoundingBox();
                }

                if (_circleY != null)
                {
                    _circleY.ParentMatrix = matrix;
                    _circleY.UpdateBoundingBox();
                }

                if (_circleZ != null)
                {
                    _circleZ.ParentMatrix = matrix;
                    _circleZ.UpdateBoundingBox();
                }

                if (_scale != null)
                {
                    _scale.ParentMatrix = matrix;
                    _scale.UpdateBoundingBox();
                }
            }

            if (_keepHighlight)
            {
                _arrowX.Draw(holder, camera, _arrowHighlighted.X == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _arrowY.Draw(holder, camera, _arrowHighlighted.Y == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _arrowZ.Draw(holder, camera, _arrowHighlighted.Z == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _circleX?.Draw(holder, camera, _circleHighlighted.X == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _circleY?.Draw(holder, camera, _circleHighlighted.Y == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _circleZ?.Draw(holder, camera, _circleHighlighted.Z == 0f ? SpecialRenderMode.Simple : SpecialRenderMode.Outline);
                _scale?.Draw(holder, camera, _scaleHighlighted ? SpecialRenderMode.Outline : SpecialRenderMode.Simple);
            }
            else
            {
                var mousePosition = holder.TryToGet <IMousePositionProvider>()?.GetRelative();
                var rayN          = mousePosition == null ? null : (camera as CameraBase)?.GetPickingRay(mousePosition.Value, new Vector2(1f, 1f));
                if (!rayN.HasValue)
                {
                    return;
                }

                var ray = rayN.Value;
                _arrowHighlighted = new Vector3(
                    _arrowX.DrawHighlighted(ray, holder, camera) ? 1f : 0f,
                    _arrowY.DrawHighlighted(ray, holder, camera) ? 1f : 0f,
                    _arrowZ.DrawHighlighted(ray, holder, camera) ? 1f : 0f);

                if (_arrowHighlighted == Vector3.Zero)
                {
                    _circleHighlighted = new Vector3(
                        _circleX?.DrawHighlighted(ray, holder, camera) ?? false ? 1f : 0f,
                        _circleY?.DrawHighlighted(ray, holder, camera) ?? false ? 1f : 0f,
                        _circleZ?.DrawHighlighted(ray, holder, camera) ?? false ? 1f : 0f);
                }
                else
                {
                    _circleHighlighted = Vector3.Zero;
                    _circleX?.Draw(holder, camera, SpecialRenderMode.Simple);
                    _circleY?.Draw(holder, camera, SpecialRenderMode.Simple);
                    _circleZ?.Draw(holder, camera, SpecialRenderMode.Simple);
                }

                if (_arrowHighlighted == Vector3.Zero && _circleHighlighted == Vector3.Zero)
                {
                    _scaleHighlighted = _scale?.DrawHighlighted(ray, holder, camera) ?? false;
                }
                else
                {
                    _scaleHighlighted = false;
                    _scale?.Draw(holder, camera, SpecialRenderMode.Simple);
                }
            }
        }
コード例 #15
0
        public bool MoveObject(Vector2 relativeFrom, Vector2 relativeDelta, CameraBase camera, bool tryToClone, [CanBeNull] out IMoveable cloned)
        {
            if (_keepHighlight)
            {
                tryToClone = false;
            }
            else
            {
                _keepHighlight = true;
            }

            if (_justCloned)
            {
                tryToClone = false;
            }

            cloned = null;

            if (_arrowHighlighted != default(Vector3))
            {
                var plane   = new Plane(ParentMatrix.GetTranslationVector(), -camera.Look);
                var rayFrom = camera.GetPickingRay(relativeFrom, new Vector2(1f, 1f));
                var rayTo   = camera.GetPickingRay(relativeFrom + relativeDelta, new Vector2(1f, 1f));
                if (!Ray.Intersects(rayFrom, plane, out var distanceFrom) ||
                    !Ray.Intersects(rayTo, plane, out var distanceTo))
                {
                    return(false);
                }

                var pointDelta = rayTo.Direction * distanceTo - rayFrom.Direction * distanceFrom;
                if (tryToClone)
                {
                    cloned      = _parent.Clone();
                    _justCloned = true;
                }

                var totalDistance  = pointDelta.Length();
                var resultMovement = new Vector3(
                    pointDelta.X * _arrowHighlighted.X,
                    pointDelta.Y * _arrowHighlighted.Y,
                    pointDelta.Z * _arrowHighlighted.Z);
                resultMovement.Normalize();
                resultMovement *= totalDistance;

                _parent.Move(resultMovement);
                UpdateBoundingBox();
                return(true);
            }

            if (_circleHighlighted != default(Vector3))
            {
                var rotationAxis = _circleHighlighted.X * _circleHighlighted.Y * _circleHighlighted.Z != 0f ?
                                   camera.Look : _circleHighlighted;

                if (tryToClone)
                {
                    cloned      = _parent.Clone();
                    _justCloned = true;
                }

                _parent.Rotate(Quaternion.RotationAxis(rotationAxis, relativeDelta.X * 10f));
                UpdateBoundingBox();
                return(true);
            }

            if (_scaleHighlighted)
            {
                var v = relativeDelta.X + relativeDelta.Y;
                _parent.Scale(new Vector3(v > 0f ? 1.01f : 1f / 1.01f));
                UpdateBoundingBox();
                return(true);
            }

            return(false);
        }
コード例 #16
0
#pragma warning disable 1591
        public override void SetValueOrMissing(int rowIndex, int colIndex, TValue value)
#pragma warning restore 1591
        {
            //IndexOfParentRowKey will raise an error if the indexs are invalid, so we don't need to double check
            ParentMatrix.SetValueOrMissing(IndexOfParentRowKey[rowIndex], IndexOfParentColKey[colIndex], value);
        }
コード例 #17
0
 #pragma warning disable 1591
 public override bool IsMissing(int rowIndex, int colIndex)
 #pragma warning restore 1591
 {
     return(ParentMatrix.IsMissing(IndexOfParentRowKey[rowIndex], IndexOfParentColKey[colIndex]));
 }
コード例 #18
0
 #pragma warning disable 1591
 public override bool Remove(TRowKey rowKey, TColKey colKey)
 #pragma warning restore 1591
 {
     return(ParentMatrix.Remove(colKey, rowKey));
 }
コード例 #19
0
#pragma warning disable 1591
        public override void SetValueOrMissing(int rowIndex, int colIndex, TValue value)
#pragma warning restore 1591
        {
            ParentMatrix.SetValueOrMissing(rowIndex, IndexOfParentCol[colIndex], value);
        }
コード例 #20
0
#pragma warning disable 1591
        public override bool TryGetValue(TRowKey rowKey, TColKey colKey, out TValue value)
#pragma warning restore 1591
        {
            return(ParentMatrix.TryGetValue(rowKey, colKey, out value));
        }
コード例 #21
0
 #pragma warning disable 1591
 public override bool Remove(TRowKey rowKey, TColKey colKey)
 #pragma warning restore 1591
 {
     Helper.CheckCondition(ContainsRowAndColKeys(rowKey, colKey), "Invalid rowKey or colKey");
     return(ParentMatrix.Remove(rowKey, colKey));
 }
コード例 #22
0
#pragma warning disable 1591
        public override void SetValueOrMissing(TRowKey rowKey, TColKey colKey, TValue value)
#pragma warning restore 1591
        {
            Helper.CheckCondition(ContainsRowAndColKeys(rowKey, colKey), "Invalid rowKey or colKey");    //This is needed because rows and columns are are OK in the parent may not be OK here
            ParentMatrix.SetValueOrMissing(rowKey, colKey, value);
        }
コード例 #23
0
 #pragma warning disable 1591
 public override bool TryGetValue(int rowIndex, int colIndex, out TValue value)
 #pragma warning restore 1591
 {
     return(ParentMatrix.TryGetValue(rowIndex, IndexOfParentCol[colIndex], out value));
 }
コード例 #24
0
 #pragma warning disable 1591
 public override bool Remove(int rowIndex, int colIndex)
 #pragma warning restore 1591
 {
     //IndexOfParentRowKey will raise an error if the indexs are invalid, so we don't need to double check
     return(ParentMatrix.Remove(IndexOfParentRowKey[rowIndex], IndexOfParentColKey[colIndex]));
 }
コード例 #25
0
 #pragma warning disable 1591
 public override bool IsMissing(TRowKey rowKey, TColKey colKey)
 #pragma warning restore 1591
 {
     return(ParentMatrix.IsMissing(rowKey, colKey));
 }
コード例 #26
0
#pragma warning disable 1591
        public override void SetValueOrMissing(TRowKey rowKey, TColKey colKey, TValue value)
#pragma warning restore 1591
        {
            ParentMatrix.SetValueOrMissing(colKey, rowKey, value);
        }