Esempio n. 1
0
 public bool IsHittedBy(HitTestPointData hitData)
 {
     foreach (var rect in _rectangles)
     {
         if (hitData.IsHit(rect, _transformation, out var z))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 2
0
        public bool IsHittedBy(HitTestPointData hitData)
        {
            foreach (var outline in _outlines)
            {
                if (outline.IsHittedBy(hitData))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 3
0
			public void MoveGrip(HitTestPointData newPosition)
			{
				foreach (var ele in GripList)
					ele.MoveGrip(newPosition);
			}
Esempio n. 4
0
		/// <summary>
		/// Gets the principal coordinate system that results of the camera facing a layer. The plane of the layer that best faced the camera is used for the calculations.
		/// The normal of that layer is returned as z-axis, the vector that best matches the up-vector of the camera is becoming the y-axis,
		/// and the x-axis results from the z-axis and the y-axis.
		/// </summary>
		/// <param name="camera">The camera.</param>
		/// <param name="activeLayer">The active layer of the graph document.</param>
		/// <param name="transformation">Matrix that contains the principal axes as described above. The axes coordinates are in the coordinates of the layer provided in the argument <paramref name="activeLayer"/>.</param>
		/// <exception cref="InvalidProgramException">There should always be a plane of a rectangle that can be hit!</exception>
		public static void GetCoordinateSystemBasedOnLayerPlaneFacingTheCamera(CameraBase camera, HostLayer activeLayer, out Matrix3x3 transformation)
		{
			PointD3D hitposition = new PointD3D(0.5, 0.5, 1); // this hit position is arbitrary, every other position should work similarly

			var activeLayerTransformation = activeLayer.TransformationFromRootToHere();

			var hitData = new HitTestPointData(camera.GetHitRayMatrix(hitposition));

			hitData = hitData.NewFromAdditionalTransformation(activeLayerTransformation); // now hitdata are in layer cos

			var targetToEye = hitData.WorldTransformation.Transform(camera.TargetToEyeVectorNormalized); // targetToEye in layer coordinates
			var upEye = hitData.WorldTransformation.Transform(camera.UpVectorPerpendicularToEyeVectorNormalized); // camera up vector in layer coordinates

			// get the face which has the best dot product between the eye vector of the camera and the plane's normal
			var layerRect = new RectangleD3D(PointD3D.Empty, activeLayer.Size);
			double maxval = double.MinValue;
			PlaneD3D maxPlane = PlaneD3D.Empty;
			foreach (var plane in layerRect.Planes)
			{
				double val = VectorD3D.DotProduct(plane.Normal, targetToEye);
				if (val > maxval)
				{
					maxval = val;
					maxPlane = plane;
				}
			}

			//	bool isHit = hitData.IsPlaneHitByRay(maxPlane, out hitPointOnPlaneInActiveLayerCoordinates); // hitPointOnPlane is in layer coordinates too

			//	if (!isHit)
			//	throw new InvalidProgramException("There should always be a plane of a rectangle that can be hit!");

			VectorD3D zaxis = maxPlane.Normal;
			VectorD3D yaxis = upEye;

			// Find y axis perpendicular to zaxis
			maxval = double.MinValue;
			foreach (var plane in layerRect.Planes)
			{
				double val = VectorD3D.DotProduct(plane.Normal, upEye);
				if (val > maxval && 0 == VectorD3D.DotProduct(plane.Normal, zaxis))
				{
					maxval = val;
					yaxis = plane.Normal;
				}
			}
			var xaxis = VectorD3D.CrossProduct(yaxis, zaxis);

			// now we have all information about the spatial position and orientation of the text:
			// hitPointOnPlane is the position of the text
			// maxPlane.Normal is the face orientation of the text
			// maxUpVector is the up orientation of the text

			xaxis = xaxis.Normalized;
			yaxis = yaxis.Normalized;
			zaxis = zaxis.Normalized;

			transformation = new Matrix3x3(
				xaxis.X, yaxis.X, zaxis.X,
				xaxis.Y, yaxis.Y, zaxis.Y,
				xaxis.Z, yaxis.Z, zaxis.Z
				);
		}
Esempio n. 5
0
		/// <summary>
		/// Handles the mouse move event.
		/// </summary>
		/// <param name="position">Mouse position.</param>
		/// <param name="e">MouseEventArgs as provided by the view.</param>
		/// <returns>The next mouse state handler that should handle mouse events.</returns>
		public override void OnMouseMove(PointD3D position, MouseEventArgs e)
		{
			base.OnMouseMove(position, e);

			if (null != ActiveGrip)
			{
				var graphCoord = new HitTestPointData(_grac.Doc.Camera.GetHitRayMatrix(position));
				ActiveGrip.MoveGrip(graphCoord);
				_wereObjectsMoved = true;
				_grac.RenderOverlay();
			}
			/*
			else if (e.LeftButton == MouseButtonState.Pressed)
			{
				var diffPos = position - _positionLastMouseDownInMouseCoordinates;

				var oldRect = _rectangleSelectionArea_GraphCoordinates;

				if (null != _rectangleSelectionArea_GraphCoordinates ||
						Math.Abs(diffPos.X) >= System.Windows.SystemParameters.MinimumHorizontalDragDistance ||
						Math.Abs(diffPos.Y) >= System.Windows.SystemParameters.MinimumHorizontalDragDistance)
				{
					if (null == _rectangleSelectionArea_GraphCoordinates)
					{
						_grac.CaptureMouse();
					}

					var pt1 = _grac.ConvertMouseToRootLayerCoordinates(_positionLastMouseDownInMouseCoordinates);
					var rect = new RectangleD2D(pt1, PointD2D.Empty);
					rect.ExpandToInclude(_grac.ConvertMouseToRootLayerCoordinates(position));
					_rectangleSelectionArea_GraphCoordinates = rect;
				}
				if (null != _rectangleSelectionArea_GraphCoordinates)
					_grac.RenderOverlay();
			}
			*/
		}
Esempio n. 6
0
		/// <summary>
		/// Tests if a grip from the <see cref="DisplayedGrips"/>  is hitted.
		/// </summary>
		/// <param name="pt">Mouse location.</param>
		/// <returns>The grip which was hitted, or null if no grip was hitted.</returns>
		public IGripManipulationHandle GripHitTest(HitTestPointData pt)
		{
			if (null == DisplayedGrips || DisplayedGrips.Length == 0)
				return null;

			for (int i = 0; i < DisplayedGrips.Length; i++)
			{
				if (DisplayedGrips[i].IsGripHit(pt))
					return DisplayedGrips[i];
			}
			return null;
		}
Esempio n. 7
0
		public bool IsHittedBy(HitTestPointData hitData)
		{
			foreach (var outline in _outlines)
				if (outline.IsHittedBy(hitData))
					return true;

			return false;
		}
Esempio n. 8
0
			public bool GetHittedElement(HitTestPointData point, out IGripManipulationHandle gripHandle, out IHitTestObject hitObject)
			{
				for (int i = GripList.Count - 1; i >= 0; i--)
				{
					if (GripList[i].IsGripHit(point))
					{
						gripHandle = GripList[i];
						hitObject = HittedList[i];
						return true;
					}
				}

				gripHandle = null;
				hitObject = null;
				return false;
			}
Esempio n. 9
0
 public bool IsGripHit(HitTestPointData point)
 {
     return(false);
 }
Esempio n. 10
0
		public bool IsHittedBy(HitTestPointData hitData)
		{
			double z;
			return hitData.IsHit(_rectangle, _transformation, out z);
		}
Esempio n. 11
0
 public void MoveGrip(HitTestPointData newPosition)
 {
 }
Esempio n. 12
0
 /// <summary>
 /// Activates this grip, providing the initial position of the mouse.
 /// </summary>
 /// <param name="initialPosition">Initial position of the mouse.</param>
 /// <param name="isActivatedUponCreation">If true the activation is called right after creation of this handle. If false,
 /// thie activation is due to a regular mouse click in this grip.</param>
 public void Activate(HitTestPointData initialPosition, bool isActivatedUponCreation)
 {
 }
Esempio n. 13
0
		/// <summary>
		/// Looks for a graph object at the position given by <paramref name="hitData"/> and returns true if one is found.
		/// </summary>
		/// <param name="hitData">The position of the mouse, expressed as transformation, that when applied, transformes the mouse coordinate to the point x=0, y=0, z=-Infinity....+Infinity.</param>
		/// <param name="plotItemsOnly">If true, only the plot items where hit tested.</param>
		/// <param name="foundObject">Found object if there is one found, else null</param>
		/// <param name="foundInLayerNumber">The layer the found object belongs to, otherwise 0</param>
		/// <returns>True if a object was found at the position given by <paramref name="hitData"/>, else false.</returns>
		public bool FindGraphObjectAtPixelPosition(HitTestPointData hitData, bool plotItemsOnly, out IHitTestObject foundObject, out int[] foundInLayerNumber)
		{
			foundObject = Doc.RootLayer.HitTest(hitData, plotItemsOnly);

			if (null != foundObject && null != foundObject.ParentLayer)
			{
				foundInLayerNumber = foundObject.ParentLayer.IndexOf().ToArray();
				return true;
			}

			foundObject = null;
			foundInLayerNumber = null;
			return false;
		}
Esempio n. 14
0
 public bool IsHittedBy(HitTestPointData hitData)
 {
     throw new NotImplementedException();
 }
Esempio n. 15
0
		public bool IsHittedBy(HitTestPointData hitData)
		{
			double z;
			foreach (var rect in _rectangles)
			{
				if (hitData.IsHit(rect, _transformation, out z))
					return true;
			}
			return false;
		}
Esempio n. 16
0
			public bool IsGripHit(HitTestPointData point)
			{
				foreach (var ele in GripList)
					if (ele.IsGripHit(point))
						return true;
				return false;
			}
Esempio n. 17
0
		public bool IsHittedBy(HitTestPointData hitData)
		{
			throw new NotImplementedException();
		}
Esempio n. 18
0
		public override void OnMouseDown(PointD3D position, MouseButtonEventArgs e)
		{
			base.OnMouseDown(position, e);

			if (e.ChangedButton == MouseButton.Left)
			{
				var hitData = new HitTestPointData(_grac.Doc.Camera.GetHitRayMatrix(position));

				// first, if we have a mousedown without shift key and the
				// position has changed with respect to the last mousedown
				// we have to deselect all objects
				var keyboardModifiers = System.Windows.Input.Keyboard.Modifiers;
				bool bControlKey = keyboardModifiers.HasFlag(ModifierKeys.Control);
				bool bShiftKey = keyboardModifiers.HasFlag(ModifierKeys.Shift);

				ActiveGrip = GripHitTest(hitData);
				if ((ActiveGrip is SuperGrip) && (bShiftKey || bControlKey))
				{
					var superGrip = ActiveGrip as SuperGrip;
					IHitTestObject hitTestObj;
					IGripManipulationHandle gripHandle;
					if (superGrip.GetHittedElement(hitData, out gripHandle, out hitTestObj))
					{
						_selectedObjects.Remove(hitTestObj);
						superGrip.Remove(gripHandle);
						return;
					}
				}
				else if (ActiveGrip != null)
				{
					ActiveGrip.Activate(hitData, false);
					return;
				}

				// search for a object first
				IHitTestObject clickedObject;
				int[] clickedLayerNumber = null;
				_grac.FindGraphObjectAtPixelPosition(hitData, false, out clickedObject, out clickedLayerNumber);

				if (!bShiftKey && !bControlKey) // if shift or control are pressed, we add the object to the selection list and start moving mode
					ClearSelections();

				if (null != clickedObject)
					AddSelectedObject(hitData, clickedObject);
			}
		}
Esempio n. 19
0
		/// <summary>
		/// Copy constructor.
		/// </summary>
		/// <param name="from">Another HitTestData object to copy from.</param>
		public HitTestPointData(HitTestPointData from)
		{
			this._hitTransformation = from._hitTransformation;
			this._worldTransformation = from._worldTransformation;
		}
Esempio n. 20
0
		private void AddSelectedObject(HitTestPointData hitPoint, IHitTestObject clickedObject)
		{
			_selectedObjects.Add(clickedObject);

			DisplayedGripLevel = 1;
			DisplayedGrips = GetGripsFromSelectedObjects();

			if (_selectedObjects.Count == 1) // single object selected
			{
				ActiveGrip = GripHitTest(hitPoint);
				if (ActiveGrip != null)
					ActiveGrip.Activate(hitPoint, true);
			}
			else // multiple objects selected
			{
				ActiveGrip = DisplayedGrips[0]; // this is our SuperGrip
				DisplayedGrips[0].Activate(hitPoint, true);
			}

			_grac.RenderOverlay();
		}
Esempio n. 21
0
		/// <summary>
		/// Gets the hit point on that plane of the active layer rectangle, that is facing the camera.
		/// </summary>
		/// <param name="doc">The graph document containing the active layer.</param>
		/// <param name="activeLayer">The active layer of the graph document.</param>
		/// <param name="hitposition">Hit point in relative screen coordinates. The z-component is the aspect ratio of the screen (y/x).</param>
		/// <param name="hitPointOnPlaneInActiveLayerCoordinates">Output: The hit point on the plane of the active layer that faces the camera. The hit point is returned in active layer coordinates.</param>
		/// <param name="rotationsRadian">The rotation angles that can be used e.g. to orient text so that the text is most readable from the current camera setting. Rotation angle around x is the x-component of the returned vector, and so on.</param>
		/// <exception cref="InvalidProgramException">There should always be a plane of a rectangle that can be hit!</exception>
		public static void GetHitPointOnActiveLayerPlaneFacingTheCamera(GraphDocument doc, HostLayer activeLayer, PointD3D hitposition, out PointD3D hitPointOnPlaneInActiveLayerCoordinates, out VectorD3D rotationsRadian)
		{
			var activeLayerTransformation = activeLayer.TransformationFromRootToHere();
			var camera = doc.Camera;
			var hitData = new HitTestPointData(camera.GetHitRayMatrix(hitposition));
			hitData = hitData.NewFromAdditionalTransformation(activeLayerTransformation); // now hitdata are in layer cos

			var targetToEye = hitData.WorldTransformation.Transform(camera.TargetToEyeVectorNormalized); // targetToEye in layer coordinates
			var upEye = hitData.WorldTransformation.Transform(camera.UpVectorPerpendicularToEyeVectorNormalized); // camera up vector in layer coordinates

			// get the face which has the best dot product between the eye vector of the camera and the plane's normal
			var layerRect = new RectangleD3D(PointD3D.Empty, activeLayer.Size);
			double maxval = double.MinValue;
			PlaneD3D maxPlane = PlaneD3D.Empty;
			foreach (var plane in layerRect.Planes)
			{
				double val = VectorD3D.DotProduct(plane.Normal, targetToEye);
				if (val > maxval)
				{
					maxval = val;
					maxPlane = plane;
				}
			}

			bool isHit = hitData.IsPlaneHitByRay(maxPlane, out hitPointOnPlaneInActiveLayerCoordinates); // hitPointOnPlane is in layer coordinates too

			if (!isHit)
				throw new InvalidProgramException("There should always be a plane of a rectangle that can be hit!");

			VectorD3D zaxis = maxPlane.Normal;
			VectorD3D yaxis = upEye;

			// Find y axis perpendicular to zaxis
			maxval = double.MinValue;
			foreach (var plane in layerRect.Planes)
			{
				double val = VectorD3D.DotProduct(plane.Normal, upEye);
				if (val > maxval && 0 == VectorD3D.DotProduct(plane.Normal, zaxis))
				{
					maxval = val;
					yaxis = plane.Normal;
				}
			}
			var xaxis = VectorD3D.CrossProduct(yaxis, zaxis);

			// now we have all information about the spatial position and orientation of the text:
			// hitPointOnPlane is the position of the text
			// maxPlane.Normal is the face orientation of the text
			// maxUpVector is the up orientation of the text

			double cx, sx, cy, sy, cz, sz;

			sy = xaxis.Z;
			if (1 != Math.Abs(sy))
			{
				cy = Math.Sqrt(1 - sy * sy);
				cz = xaxis.X / cy;
				sz = xaxis.Y / cy;
				sx = yaxis.Z / cy;
				cx = zaxis.Z / cy;
			}
			else // sy is +1, thus cy is zero
			{
				// we set x-rotation to zero, i.e. cx==1 and sx==0
				cy = 0;
				cx = 1;
				sx = 0;
				cz = yaxis.Y;
				sz = -yaxis.X;
			}

			rotationsRadian = new VectorD3D(Math.Atan2(sx, cx), Math.Atan2(sy, cy), Math.Atan2(sz, cz));
		}
Esempio n. 22
0
			/// <summary>
			/// Activates this grip, providing the initial position of the mouse.
			/// </summary>
			/// <param name="initialPosition">Initial position of the mouse.</param>
			/// <param name="isActivatedUponCreation">If true the activation is called right after creation of this handle. If false,
			/// thie activation is due to a regular mouse click in this grip.</param>
			public void Activate(HitTestPointData initialPosition, bool isActivatedUponCreation)
			{
				foreach (var ele in GripList)
					ele.Activate(initialPosition, isActivatedUponCreation);
			}
Esempio n. 23
0
 public bool IsHittedBy(HitTestPointData hitData)
 {
     return(hitData.IsHit(_rectangle, _transformation, out var z));
 }
Esempio n. 24
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="from">Another HitTestData object to copy from.</param>
 public HitTestPointData(HitTestPointData from)
 {
     _hitTransformation   = from._hitTransformation;
     _worldTransformation = from._worldTransformation;
 }
Esempio n. 25
0
		protected override IHitTestObject HitTestWithLocalCoordinates(HitTestPointData localCoord, bool plotItemsOnly)
		{
			IHitTestObject hit = null;

			if (!plotItemsOnly)
			{
				hit = _axisStyles.HitTest(localCoord, AxisScaleEditorMethod, AxisStyleEditorMethod, AxisLabelMajorStyleEditorMethod, AxisLabelMinorStyleEditorMethod);
			}

			if (null == hit)
			{
				hit = base.HitTestWithLocalCoordinates(localCoord, plotItemsOnly);
			}

			if (null != hit && hit.ParentLayer == null)
				hit.ParentLayer = this;

			return hit;
		}