Example #1
0
 /// <override></override>
 protected override bool MovePointByCore(ControlPointId pointId, int origDeltaX, int origDeltaY, ResizeModifiers modifiers)
 {
     if (pointId == GlueControlPoint)
     {
         bool result = false;
         // If the glue ponit is connected, recalculate glue point calculation info
         ShapeConnectionInfo ci = GetConnectionInfo(GlueControlPoint, null);
         if (ci.IsEmpty)
         {
             // If the glue point is not connected, move the glue point to the desired position
             if (Geometry.IsValid(gluePointPos))
             {
                 gluePointPos.X += origDeltaX;
                 gluePointPos.Y += origDeltaY;
                 InvalidateDrawCache();
                 result = true;
             }
         }
         else
         {
             if (ci.OtherPointId != ControlPointId.Reference)
             {
                 CalcGluePoint(GlueControlPoint, ci.OtherShape);
             }
         }
         return(result);
     }
     else
     {
         return(base.MovePointByCore(pointId, origDeltaX, origDeltaY, modifiers));
     }
 }
Example #2
0
        /// <override></override>
        protected override bool MoveByCore(int deltaX, int deltaY)
        {
            bool result = base.MoveByCore(deltaX, deltaY);
            // If the glue point is not connected, move it with the shape
            ShapeConnectionInfo ci = GetConnectionInfo(GlueControlPoint, null);

            if (ci.IsEmpty)
            {
                if (Geometry.IsValid(gluePointPos))
                {
                    gluePointPos.X += deltaX;
                    gluePointPos.Y += deltaY;
                }
            }
            else
            {
                // If the gluePoint is connected and the shape is not
                // following the connected shape, recalculate GluePointCalcInfo
                if (!followingConnectedShape)
                {
                    calcInfo = GluePointCalcInfo.Empty;
                    CalcGluePointCalcInfo(ci.OwnPointId, ci.OtherShape, ci.OtherPointId);
                }
            }
            return(result);
        }
Example #3
0
 private static void CompareConnection(Shape shapeA, ShapeConnectionInfo connectionA, Shape shapeB, ShapeConnectionInfo connectionB, int version)
 {
     CompareId(shapeA, shapeB);
     CompareId(connectionB.OtherShape, connectionB.OtherShape);
     if (connectionA != ShapeConnectionInfo.Empty && connectionB != ShapeConnectionInfo.Empty)
     {
         if (connectionA.OwnPointId >= ControlPointId.Reference && connectionB.OwnPointId >= ControlPointId.Reference)
         {
             Assert.IsTrue(connectionA.OwnPointId == connectionB.OwnPointId);
         }
         if (connectionA.OtherPointId >= ControlPointId.Reference && connectionB.OtherPointId >= ControlPointId.Reference)
         {
             Assert.IsTrue(connectionA.OtherPointId == connectionB.OtherPointId);
         }
         if (shapeA.HasControlPointCapability(connectionA.OwnPointId, ControlPointCapabilities.Glue))
         {
             Assert.AreEqual(connectionA.OtherPointId, connectionB.OtherPointId);
             Point pointA = shapeA.GetControlPointPosition(connectionA.OwnPointId);
             Point pointB = shapeB.GetControlPointPosition(connectionB.OwnPointId);
             ComparePosition(pointA, pointB, version);
         }
         else
         {
             Assert.AreEqual(connectionA.OwnPointId, connectionB.OwnPointId);
             Point pointA = connectionA.OtherShape.GetControlPointPosition(connectionA.OtherPointId);
             Point pointB = connectionB.OtherShape.GetControlPointPosition(connectionB.OtherPointId);
             ComparePosition(pointA, pointB, version);
         }
     }
     else
     {
         Assert.IsTrue(connectionA == ShapeConnectionInfo.Empty && connectionB == ShapeConnectionInfo.Empty);
     }
 }
Example #4
0
 private static void CompareConnectionsByControlPointIds(Shape shapeA, Shape shapeB)
 {
     foreach (ControlPointId gluePtId in shapeB.GetControlPointIds(ControlPointCapabilities.Glue))
     {
         ShapeConnectionInfo connectionA = shapeB.GetConnectionInfo(gluePtId, null);
         ShapeConnectionInfo connectionB = shapeB.GetConnectionInfo(gluePtId, null);
         CompareConnection(shapeA, connectionA, shapeB, connectionB);
     }
 }
Example #5
0
        /// <override></override>
        protected override bool RotateCore(int deltaAngle, int x, int y)
        {
            bool result = base.RotateCore(deltaAngle, x, y);

            if (!followingConnectedShape)
            {
                ShapeConnectionInfo ci = GetConnectionInfo(GlueControlPoint, null);
                if (!ci.IsEmpty)
                {
                    // If the gluePoint is connected, recalculate GluePointCalcInfo
                    this.calcInfo = GluePointCalcInfo.Empty;
                    CalcGluePointCalcInfo(ci.OwnPointId, ci.OtherShape, ci.OtherPointId);
                }
            }
            return(result);
        }
Example #6
0
 private static void CompareConnection(Shape shapeA, ShapeConnectionInfo connectionA, Shape shapeB, ShapeConnectionInfo connectionB)
 {
     CompareId(shapeA, shapeB);
     CompareId(connectionB.OtherShape, connectionB.OtherShape);
     if (connectionA != ShapeConnectionInfo.Empty && connectionB != ShapeConnectionInfo.Empty)
     {
         if (connectionA.OwnPointId >= ControlPointId.Reference && connectionB.OwnPointId >= ControlPointId.Reference)
         {
             Assert.IsTrue(connectionA.OwnPointId == connectionB.OwnPointId);
         }
         if (connectionA.OtherPointId >= ControlPointId.Reference && connectionB.OtherPointId >= ControlPointId.Reference)
         {
             Assert.IsTrue(connectionA.OtherPointId == connectionB.OtherPointId);
         }
         bool ownPointPosIsEqual   = false;
         bool otherPointPosIsEqual = false;
         if (shapeA.HasControlPointCapability(connectionA.OwnPointId, ControlPointCapabilities.Glue))
         {
             Point pointA = shapeA.GetControlPointPosition(connectionA.OwnPointId);
             Point pointB = shapeB.GetControlPointPosition(connectionB.OwnPointId);
             ownPointPosIsEqual   = (pointA == pointB);
             otherPointPosIsEqual = (connectionA.OtherPointId == connectionB.OtherPointId);
         }
         else
         {
             ownPointPosIsEqual = (connectionA.OwnPointId == connectionB.OwnPointId);
             Point pointA = connectionA.OtherShape.GetControlPointPosition(connectionA.OtherPointId);
             Point pointB = connectionB.OtherShape.GetControlPointPosition(connectionB.OtherPointId);
             otherPointPosIsEqual = (pointA == pointB);
         }
         Assert.IsTrue(ownPointPosIsEqual);
         Assert.IsTrue(otherPointPosIsEqual);
     }
     else
     {
         Assert.IsTrue(connectionA == ShapeConnectionInfo.Empty && connectionB == ShapeConnectionInfo.Empty);
     }
 }
		/// <summary>
		/// Creates (or finds) a preview of the connection's PassiveShape and connects it to the current preview shape
		/// </summary>
		private void CreateConnectedTargetPreviewShape(IDiagramPresenter diagramPresenter, Shape previewShape,
		                                               ShapeConnectionInfo connectionInfo)
		{
			// Check if any other selected shape is connected to the same non-selected shape
			Shape previewTargetShape;
			// If the current passiveShape is already connected to another shape of the current selection,
			// connect the current preview to the other preview's passiveShape
			if (!targetShapeBuffer.TryGetValue(connectionInfo.OtherShape, out previewTargetShape)) {
				// If the current passiveShape is not connected to any other of the selected selectedShapes,
				// create a clone of the passiveShape and connect it to the corresponding preview
				// If the preview exists, abort connecting (in this case, the shape is a preview of a child shape)
				if (previewShapes.ContainsKey(connectionInfo.OtherShape))
					return;
				else {
					previewTargetShape = connectionInfo.OtherShape.Type.CreatePreviewInstance(connectionInfo.OtherShape);
					AddPreview(connectionInfo.OtherShape, previewTargetShape, diagramPresenter.DisplayService);
				}
				// Add passive shape and it's clone to the passive shape dictionary
				targetShapeBuffer.Add(connectionInfo.OtherShape, previewTargetShape);
			}
			// Connect the (new or existing) preview shapes
			// Skip connecting if the preview is already connected.
			if (previewTargetShape.IsConnected(connectionInfo.OtherPointId, null) == ControlPointId.None) {
				previewTargetShape.Connect(connectionInfo.OtherPointId, previewShape, connectionInfo.OwnPointId);
				// check, if any shapes are connected to the connector (that is connected to the selected shape)
				foreach (ShapeConnectionInfo connectorCI in connectionInfo.OtherShape.GetConnectionInfos(ControlPointId.Any, null)) {
					if (!diagramPresenter.IsLayerVisible(connectorCI.OtherShape.Layers)) continue;
					// skip if the connector is connected to the shape with more than one glue point
					if (connectorCI.OtherShape == FindShapeOfPreview(previewShape)) continue;
					if (connectorCI.OwnPointId != connectionInfo.OtherPointId) {
						// Check if the shape on the other end is selected.
						// If it is, connect to it's preview or skip connecting if the target preview does 
						// not exist yet (it will be connected when creating the targt's preview)
						if (diagramPresenter.SelectedShapes.Contains(connectorCI.OtherShape)) {
							if (previewShapes.ContainsKey(connectorCI.OtherShape)) {
								Shape s = FindPreviewOfShape(connectorCI.OtherShape);
								if (s.IsConnected(connectorCI.OtherPointId, previewTargetShape) == ControlPointId.None)
									previewTargetShape.Connect(connectorCI.OwnPointId, s, connectorCI.OtherPointId);
							}
							else continue;
						}
						else if (connectorCI.OtherShape.HasControlPointCapability(connectorCI.OtherPointId, ControlPointCapabilities.Glue))
							// Connect connectors connected to the previewTargetShape
							CreateConnectedTargetPreviewShape(diagramPresenter, previewTargetShape, connectorCI);
						else if (connectorCI.OtherPointId == ControlPointId.Reference) {
							// Connect the other end of the previewTargetShape if the connection is a Point-To-Shape connection
							if (previewTargetShape.IsConnected(connectorCI.OwnPointId, null) == ControlPointId.None)
								previewTargetShape.Connect(connectorCI.OwnPointId, connectorCI.OtherShape, connectorCI.OtherPointId);
						}
					}
				}
			}
		}