/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { switch (controlPointId) { case TopCenterControlPoint: case MiddleLeftControlPoint: case MiddleRightControlPoint: case BottomCenterControlPoint: return ((controlPointCapability & ControlPointCapabilities.Resize) != 0 || ((controlPointCapability & ControlPointCapabilities.Connect) != 0 && IsConnectionPointEnabled(controlPointId))); default: return base.HasControlPointCapability(controlPointId, controlPointCapability); } }
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { if (controlPointId == controlPoints.Length) { return ((controlPointCapability & ControlPointCapabilities.Rotate) > 0 || (controlPointCapability & ControlPointCapabilities.Reference) > 0 || ((controlPointCapability & ControlPointCapabilities.Connect) > 0 && IsConnectionPointEnabled(controlPointId))); } else if (controlPointId >= 1) { return ((controlPointCapability & ControlPointCapabilities.Resize) > 0 || ((controlPointCapability & ControlPointCapabilities.Connect) > 0 && IsConnectionPointEnabled(controlPointId))); } else return base.HasControlPointCapability(controlPointId, controlPointCapability); }
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { switch (controlPointId) { case ControlPoint1: case ControlPoint2: case ControlPoint3: return ((controlPointCapability & ControlPointCapabilities.Resize) > 0 || ((controlPointCapability & ControlPointCapabilities.Connect) > 0 && IsConnectionPointEnabled(controlPointId))); case RotateControlPoint: return ((controlPointCapability & ControlPointCapabilities.Rotate) > 0 || (controlPointCapability & ControlPointCapabilities.Reference) > 0 || ((controlPointCapability & ControlPointCapabilities.Connect) > 0 && IsConnectionPointEnabled(controlPointId))); default: return base.HasControlPointCapability(controlPointId, controlPointCapability); } }
/// <summary> /// Calculates the angle of the line cap (this is usually the angle between the line's end vertex the its predecessor). /// If the predecessor of the line's end vertex is inside the line cap, the intersection point between the line cap and /// the rest of the line is calculated, like GDI+ does. /// </summary> public static float CalcLineCapAngle(Point[] points, ControlPointId pointId, Pen pen) { if (points == null) throw new ArgumentNullException("points"); if (points.Length < 2) throw new ArgumentException("Parameter points must have at least 2 elements."); if (pointId != ControlPointId.FirstVertex && pointId != ControlPointId.LastVertex) throw new ArgumentException("pointId"); float result = float.NaN; // Get required infos: Size of the cap, start point and point processing direction int startIdx = -1, step = 0; float capInset = 0; if (pointId == ControlPointId.FirstVertex) { startIdx = 0; step = 1; if (pen.StartCap == LineCap.Custom) capInset = pen.CustomStartCap.BaseInset * pen.Width; } else if (pointId == ControlPointId.LastVertex) { startIdx = points.Length - 1; step = -1; if (pen.EndCap == LineCap.Custom) capInset = pen.CustomEndCap.BaseInset * pen.Width; } else throw new NotSupportedException(); // Store point where the line cap is located Point capPoint = points[startIdx]; int maxIdx = points.Length - 1; int destIdx = startIdx + step; // Find first point *outside* the cap's area while (Geometry.DistancePointPoint(capPoint, points[destIdx]) < capInset && (destIdx > 0 && destIdx < maxIdx)) { startIdx = destIdx; destIdx += step; } // Calculate cap angle PointF p = Geometry.IntersectCircleWithLine(capPoint, capInset, points[startIdx], points[destIdx], true); if (Geometry.IsValid(p) && Geometry.LineContainsPoint(points[startIdx], points[destIdx], false, p.X, p.Y, 1)) result = Geometry.RadiansToDegrees(Geometry.Angle(capPoint, p)); if (float.IsNaN(result)) result = Geometry.RadiansToDegrees(Geometry.Angle(points[startIdx], points[destIdx])); Debug.Assert(!float.IsNaN(result)); return result; }
/// <override></override> protected override bool MovePointByCore(ControlPointId pointId, int deltaX, int deltaY, ResizeModifiers modifiers) { float transformedDeltaX, transformedDeltaY, sin, cos; Geometry.TransformMouseMovement(deltaX, deltaY, Angle, out transformedDeltaX, out transformedDeltaY, out sin, out cos); return MovePointByCore(pointId, transformedDeltaX, transformedDeltaY, sin, cos, modifiers); }
/// <override></override> public override Point GetControlPointPosition(ControlPointId controlPointId) { if (controlPointId == ControlPointId.Reference) { Point center = Point.Empty; center.X = X; center.Y = Y; return center; } else if (controlPointId == ControlPointId.None) throw new NShapeException("NotSupported PointId."); if (drawCacheIsInvalid) UpdateDrawCache(); int index = GetControlPointIndex(controlPointId); return controlPoints[index]; }
/// <override></override> protected internal override void AttachGluePointToConnectionPoint(ControlPointId ownPointId, Shape otherShape, ControlPointId gluePointId) { if (ownPointId != ControlPointId.Reference && !HasControlPointCapability(ownPointId, ControlPointCapabilities.Connect)) { throw new NShapeException(string.Format(Properties.Resources.MessageFm_AttachGluePointToConnectionPoint_0SPoint1HasToBeAConnectionPoint, Type.Name, ownPointId)); } if (!otherShape.HasControlPointCapability(gluePointId, ControlPointCapabilities.Glue)) { throw new NShapeException(string.Format(Properties.Resources.MessageFmt_AttachGluePointToConnectionPoint_0SPoint1HasToBeAGluePoint, otherShape.Type.Name, gluePointId)); } throw new NotSupportedException(); }
/// <override></override> public override void FollowConnectionPointWithGluePoint(ControlPointId gluePointId, Shape connectedShape, ControlPointId movedPointId) { // nothing to do }
/// <override></override> public override void Disconnect(ControlPointId gluePointId) { // nothing to do }
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { switch (controlPointId) { case TopLeftConnectionPoint: case TopRightConnectionPoint: case BottomLeftConnectionPoint: case BottomRightConnectionPoint: return ((controlPointCapability & ControlPointCapabilities.Connect) != 0 && IsConnectionPointEnabled(controlPointId)); default: return base.HasControlPointCapability(controlPointId, controlPointCapability); } }
private void CalcGluePointCalcInfo(ControlPointId gluePointId, Shape otherShape, ControlPointId otherPointId) { // Calculate GluePoint position and AnchorPoint position Point gluePtPos = GetControlPointPosition(gluePointId); Point labelPos = Point.Empty; labelPos.Offset(X, Y); int labelAngle; // Calculate target shape's outline intersection point and the relative position of the gluePoint in/on the target shape float alpha = float.NaN, beta = float.NaN; if (otherShape is ILinearShape) { // ToDo: Check if the point is on the line, if not, calculate an intersection point Point normalVector = ((ILinearShape)otherShape).CalcNormalVector(gluePtPos); float shapeAngleDeg = Geometry.RadiansToDegrees(Geometry.Angle(gluePtPos.X, gluePtPos.Y, normalVector.X, normalVector.Y)) - 90; alpha = 360 - shapeAngleDeg + Geometry.RadiansToDegrees(Geometry.Angle(gluePtPos, labelPos)); beta = Geometry.RadiansToDegrees(Geometry.Angle(labelPos, gluePtPos)); labelAngle = Angle - Geometry.DegreesToTenthsOfDegree(shapeAngleDeg); } else if (otherShape is IPlanarShape) { float shapeAngleDeg = Geometry.TenthsOfDegreeToDegrees(((IPlanarShape)otherShape).Angle); alpha = 360 - shapeAngleDeg + Geometry.RadiansToDegrees(Geometry.Angle(gluePtPos, labelPos)); beta = Geometry.RadiansToDegrees(Geometry.Angle(labelPos, gluePtPos)); labelAngle = Angle - ((IPlanarShape)otherShape).Angle; } else { alpha = 360 - Geometry.RadiansToDegrees(Geometry.Angle(gluePtPos, labelPos)); beta = Geometry.RadiansToDegrees(Geometry.Angle(labelPos, gluePtPos)); labelAngle = Angle; } RelativePosition relativePos = otherShape.CalculateRelativePosition(gluePtPos.X, gluePtPos.Y); float distance = Geometry.DistancePointPoint(gluePtPos, labelPos); // Store all calculated values in the GluePointCalcInfo structure this.calcInfo.Alpha = alpha % 360; this.calcInfo.Beta = beta % 360; this.calcInfo.Distance = distance; this.calcInfo.RelativePosition = relativePos; this.calcInfo.LabelAngle = labelAngle; Debug.Assert(calcInfo != GluePointCalcInfo.Empty); }
/// <override></override> public override ControlPointId IsConnected(ControlPointId ownPointId, Shape otherShape) { return(ControlPointId.None); }
/// <override></override> public override ShapeConnectionInfo GetConnectionInfo(ControlPointId gluePointId, Shape otherShape) { return(ShapeConnectionInfo.Empty); }
/// <override></override> public override IEnumerable <ShapeConnectionInfo> GetConnectionInfos(ControlPointId ownPointId, Shape otherShape) { yield break; }
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { switch (controlPointId) { case TopLeftControlPoint: case TopRightControlPoint: case BottomLeftControlPoint: case BottomRightControlPoint: return ((controlPointCapability & ControlPointCapabilities.Resize) != 0); default: return base.HasControlPointCapability(controlPointId, controlPointCapability); } }
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { if (controlPointId == MiddleCenterControlPoint) { if ((controlPointCapability & ControlPointCapabilities.Connect) != 0 || (controlPointCapability & ControlPointCapabilities.Reference) != 0 || (controlPointCapability & ControlPointCapabilities.Rotate) != 0) return true; } else if ((controlPointCapability & ControlPointCapabilities.Connect) != 0 || (controlPointCapability & ControlPointCapabilities.Resize) != 0) return IsConnectionPointEnabled(controlPointId); if ((controlPointCapability & ControlPointCapabilities.Glue) != 0) return false; return false; }
/// <override></override> public override void Disconnect(ControlPointId gluePointId) { base.Disconnect(gluePointId); calcInfo = GluePointCalcInfo.Empty; }
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { if (controlPointId == BottomCenterControlPoint && (controlPointCapability == ControlPointCapabilities.Connect)) return false; else return base.HasControlPointCapability(controlPointId, controlPointCapability); }
/// <override></override> public override void FollowConnectionPointWithGluePoint(ControlPointId gluePointId, Shape connectedShape, ControlPointId movedPointId) { if (connectedShape == null) { throw new ArgumentNullException("connectedShape"); } try { followingConnectedShape = true; Point currGluePtPos = gluePointPos; Point newGluePtPos = Geometry.InvalidPoint; // If the connection is a point-to-shape connection, the shape calculates the new glue point position // with the help of the connected shape. if (movedPointId == ControlPointId.Reference) { newGluePtPos = CalcGluePoint(gluePointId, connectedShape); } else { newGluePtPos = connectedShape.GetControlPointPosition(movedPointId); } // Ensure that the glue point is moved to a valid coordinate if (!Geometry.IsValid(newGluePtPos)) { //System.Diagnostics.Debug.Fail("Invalid glue point position"); newGluePtPos = currGluePtPos; } // Calculate new target outline intersection point along with old and new anchor point position int shapeAngle; if (connectedShape is ILinearShape) { Point normalVector = ((ILinearShape)connectedShape).CalcNormalVector(newGluePtPos); shapeAngle = Geometry.RadiansToTenthsOfDegree(Geometry.Angle(newGluePtPos.X, newGluePtPos.Y, normalVector.X, normalVector.Y)) - 900; } else if (connectedShape is IPlanarShape) { shapeAngle = ((IPlanarShape)connectedShape).Angle; } else { shapeAngle = 0; // There is no way to get an angle from a generic shape } // Move the glue point to the new position int dx, dy; dx = newGluePtPos.X - currGluePtPos.X; dy = newGluePtPos.Y - currGluePtPos.Y; // Calculate new position of the GlueLabel (calculation method depends on the desired behavior) Point newCenter = Point.Round(Geometry.CalcPoint(newGluePtPos.X, newGluePtPos.Y, calcInfo.Alpha + Geometry.TenthsOfDegreeToDegrees(shapeAngle), calcInfo.Distance)); // Move GlueLabel and update GluePointPos MoveTo(newCenter.X, newCenter.Y); this.gluePointPos = newGluePtPos; // Rotate shape if MaintainOrientation is set to false if (!maintainOrientation) { int newAngle = this.calcInfo.LabelAngle + shapeAngle; if (Angle != newAngle) { Angle = newAngle; } } } finally { followingConnectedShape = false; } }
/// <override></override> public override ShapeConnectionInfo GetConnectionInfo(ControlPointId gluePointId, Shape otherShape) { return ShapeConnectionInfo.Empty; }
/// <override></override> protected override bool MovePointByCore(ControlPointId pointId, float transformedDeltaX, float transformedDeltaY, float sin, float cos, ResizeModifiers modifiers) { bool result = true; int dx = 0, dy = 0; int size = DiameterInternal; int hSize = size, vSize = size; switch (pointId) { #region TopLeft case TopLeftControlPoint: if (Math.Abs(transformedDeltaX) > Math.Abs(transformedDeltaY)) { transformedDeltaY = transformedDeltaX; } else { transformedDeltaX = transformedDeltaY; } if (!Geometry.MoveRectangleTopLeft(size, size, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = Math.Min(hSize, vSize); break; #endregion #region TopCenter case TopCenterControlPoint: if (!Geometry.MoveRectangleTop(size, size, 0, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = vSize; break; #endregion #region TopRight case TopRightControlPoint: if (Math.Abs(transformedDeltaX) > Math.Abs(transformedDeltaY)) { transformedDeltaY = -transformedDeltaX; } else { transformedDeltaX = -transformedDeltaY; } if (!Geometry.MoveRectangleTopRight(size, size, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = Math.Min(hSize, vSize); break; #endregion #region Middle left case MiddleLeftControlPoint: if (!Geometry.MoveRectangleLeft(size, size, transformedDeltaX, 0, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = hSize; break; #endregion #region Middle right case MiddleRightControlPoint: if (!Geometry.MoveRectangleRight(size, size, transformedDeltaX, 0, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = hSize; break; #endregion #region Bottom left case BottomLeftControlPoint: if (Math.Abs(transformedDeltaX) > Math.Abs(transformedDeltaY)) { transformedDeltaY = -transformedDeltaX; } else { transformedDeltaX = -transformedDeltaY; } if (!Geometry.MoveRectangleBottomLeft(size, size, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = Math.Min(hSize, vSize); break; #endregion #region Bottom Center case BottomCenterControlPoint: if (!Geometry.MoveRectangleBottom(size, size, 0, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = vSize; break; #endregion #region Bottom right case BottomRightControlPoint: if (Math.Abs(transformedDeltaX) > Math.Abs(transformedDeltaY)) { transformedDeltaY = transformedDeltaX; } else { transformedDeltaX = transformedDeltaY; } if (!Geometry.MoveRectangleBottomRight(size, size, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = Math.Min(hSize, vSize); break; #endregion } // Perform Resizing DiameterInternal = size; MoveByCore(dx, dy); ControlPointsHaveMoved(); return(result); }
/// <override></override> protected override bool MovePointByCore(ControlPointId pointId, float transformedDeltaX, float transformedDeltaY, float sin, float cos, ResizeModifiers modifiers) { bool result = true; int dx = 0, dy = 0; int size = DiameterInternal; int hSize, vSize; // Diameter shapes always have to be resized with "MaintainAspect"! modifiers |= ResizeModifiers.MaintainAspect; switch (pointId) { // Top Left case TopLeftControlPoint: result = (transformedDeltaX == transformedDeltaY); if ( !Geometry.MoveRectangleTopLeft(size, size, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = Math.Min(hSize, vSize); break; // Top Center case TopCenterControlPoint: result = (transformedDeltaX == 0); if ( !Geometry.MoveRectangleTop(size, size, 0, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = vSize; break; // Top Right case TopRightControlPoint: result = (transformedDeltaX == -transformedDeltaY); if ( !Geometry.MoveRectangleTopRight(size, size, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = Math.Min(hSize, vSize); break; // Middle left case MiddleLeftControlPoint: result = (transformedDeltaY == 0); if ( !Geometry.MoveRectangleLeft(size, size, transformedDeltaX, 0, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = hSize; break; // Middle right case MiddleRightControlPoint: result = (transformedDeltaY == 0); if ( !Geometry.MoveRectangleRight(size, size, transformedDeltaX, 0, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = hSize; break; // Bottom left case BottomLeftControlPoint: result = (-transformedDeltaX == transformedDeltaY); if ( !Geometry.MoveRectangleBottomLeft(size, size, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = Math.Min(hSize, vSize); break; // Bottom Center case BottomCenterControlPoint: result = (transformedDeltaX == 0); if ( !Geometry.MoveRectangleBottom(size, size, 0, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = vSize; break; // Bottom right case BottomRightControlPoint: result = (transformedDeltaX == transformedDeltaY); if ( !Geometry.MoveRectangleBottomRight(size, size, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out hSize, out vSize)) { result = false; } size = Math.Min(hSize, vSize); break; } // Set field in order to avoid the shape being inserted into the owner's shape map internalDiameter = size; MoveByCore(dx, dy); ControlPointsHaveMoved(); return(result); }
public override Point GetControlPointPosition(ControlPointId controlPointId) { return(ControlPoints[controlPointId]); }
public void FakeShapeConnection(FilterSetupShapeBase shape, ControlPointId controlPoint, bool shapeIsSource) { DataFlowConnectionLine line = (DataFlowConnectionLine)project.ShapeTypes["DataFlowConnectionLine"].CreateInstance(); diagramDisplay.InsertShape(line); diagramDisplay.Diagram.Shapes.SetZOrder(line, 100); line.SecurityDomainName = SECURITY_DOMAIN_FIXED_SHAPE_NO_CONNECTIONS_DELETABLE; line.EndCapStyle = new CapStyle("fakecapstyle", CapShape.Flat, project.Design.ColorStyles.Blue); //line.LineStyle = new LineStyle("fakelinestyle", 1, project.Design.ColorStyles.Gray); line.LineStyle = project.Design.LineStyles.Dashed; if (shapeIsSource) { line.SourceDataFlowComponentReference = new DataFlowComponentReference(shape.DataFlowComponent, shape.GetOutputNumberForControlPoint(controlPoint)); line.Connect(ControlPointId.FirstVertex, shape, controlPoint); line.MoveControlPointTo(ControlPointId.LastVertex, shape.GetControlPointPosition(controlPoint).X + 40, shape.GetControlPointPosition(controlPoint).Y, ResizeModifiers.None); } else { line.DestinationDataComponent = shape.DataFlowComponent; line.Connect(ControlPointId.LastVertex, shape, controlPoint); line.MoveControlPointTo(ControlPointId.FirstVertex, shape.GetControlPointPosition(controlPoint).X - 40, shape.GetControlPointPosition(controlPoint).Y, ResizeModifiers.None); } }
/// <summary> /// Calculates the angle of the line cap (this is usually the angle between the line's end vertex the its predecessor). /// If the predecessor of the line's end vertex is inside the line cap, the intersection point between the line cap and /// the rest of the line is calculated, like GDI+ does. /// </summary> public static float CalcLineCapAngle(Point[] points, ControlPointId pointId, Pen pen) { if (points == null) { throw new ArgumentNullException("points"); } if (points.Length < 2) { throw new ArgumentException("Parameter points must have at least 2 elements."); } if (pointId != ControlPointId.FirstVertex && pointId != ControlPointId.LastVertex) { throw new ArgumentException("pointId"); } float result = float.NaN; // Get required infos: Size of the cap, start point and point processing direction int startIdx = -1, step = 0; float capInset = 0; if (pointId == ControlPointId.FirstVertex) { startIdx = 0; step = 1; if (pen.StartCap == LineCap.Custom) { capInset = pen.CustomStartCap.BaseInset * pen.Width; } } else if (pointId == ControlPointId.LastVertex) { startIdx = points.Length - 1; step = -1; if (pen.EndCap == LineCap.Custom) { capInset = pen.CustomEndCap.BaseInset * pen.Width; } } else { throw new NotSupportedException(); } // Store point where the line cap is located Point capPoint = points[startIdx]; int maxIdx = points.Length - 1; int destIdx = startIdx + step; // Find first point *outside* the cap's area while (Geometry.DistancePointPoint(capPoint, points[destIdx]) < capInset && (destIdx > 0 && destIdx < maxIdx)) { startIdx = destIdx; destIdx += step; } // Calculate cap angle PointF p = Geometry.IntersectCircleWithLine(capPoint, capInset, points[startIdx], points[destIdx], true); if (Geometry.IsValid(p) && Geometry.LineContainsPoint(points[startIdx], points[destIdx], false, p.X, p.Y, 1)) { result = Geometry.RadiansToDegrees(Geometry.Angle(capPoint, p)); } if (float.IsNaN(result)) { result = Geometry.RadiansToDegrees(Geometry.Angle(points[startIdx], points[destIdx])); } Debug.Assert(!float.IsNaN(result)); return(result); }
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { //if (ImageLayout == ImageLayoutMode.Original) { // if ((controlPointCapability & ControlPointCapabilities.Glue) != 0) // return false; // if ((controlPointCapability & ControlPointCapabilities.Connect) != 0 ) { // return (controlPointId != RotateControlPointId && IsConnectionPointEnabled(controlPointId)); // } // if ((controlPointCapability & ControlPointCapabilities.Reference) != 0) { // if (controlPointId == RotateControlPointId || controlPointId == ControlPointId.Reference) // return true; // } // if ((controlPointCapability & ControlPointCapabilities.Rotate) != 0) { // if (controlPointId == RotateControlPointId) // return true; // } return base.HasControlPointCapability(controlPointId, controlPointCapability); //} else return base.HasControlPointCapability(controlPointId, controlPointCapability); }
/// <ToBeCompleted></ToBeCompleted> protected abstract bool MovePointByCore(ControlPointId pointId, float transformedDeltaX, float transformedDeltaY, float sin, float cos, ResizeModifiers modifiers);
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { if (controlPointId == ControlPointId.Reference) return (controlPointCapability & ControlPointCapabilities.Connect) != 0; else return base.HasControlPointCapability(controlPointId, controlPointCapability); }
/// <summary> /// Calculates the angle of the line cap (this is usually the angle between the line's end vertex the its predecessor). /// If the predecessor of the line's end vertex is inside the line cap, the intersection point between the line cap and /// the rest of the line is calculated, like GDI+ does. /// </summary> public static float CalcLineCapAngle(Point[] points, ControlPointId pointId, Pen pen) { if (points == null) { throw new ArgumentNullException("points"); } if (points.Length < 2) { throw new ArgumentException("Parameter points must have at least 2 elements."); } if (pointId != ControlPointId.FirstVertex && pointId != ControlPointId.LastVertex) { throw new ArgumentException("pointId"); } float result = float.NaN; // Get required infos: Size of the cap, start point and point processing direction int startIdx; if (pointId == ControlPointId.FirstVertex) { startIdx = 0; } else if (pointId == ControlPointId.LastVertex) { startIdx = points.Length - 1; } else { throw new NotSupportedException(); } // Calculate cap angle int lastIdx = points.Length - 1; Point origStartPoint = points[0]; Point origEndPoint = points[lastIdx]; try { Point safeStartPoint, safeEndPoint; if (LineHasInvalidCapIntersection(points, pen, out safeStartPoint, out safeEndPoint)) { points[0] = safeStartPoint; points[lastIdx] = safeEndPoint; } // Now calculate the cap angle int destIdx; PointF p = CalcCapIntersectionWithLine(points, pen, (pointId == ControlPointId.FirstVertex), out destIdx); if (Geometry.IsValid(p)) // && Geometry.LineContainsPoint(points[startIdx], points[destIdx], false, p.X, p.Y, 1)) { result = Geometry.RadiansToDegrees(Geometry.Angle(points[startIdx], p)); } if (float.IsNaN(result)) { result = Geometry.RadiansToDegrees(Geometry.Angle(points[startIdx], points[destIdx])); } } finally { points[0] = origStartPoint; points[lastIdx] = origEndPoint; } Debug.Assert(!float.IsNaN(result)); return(result); }
public static void CreateDiagram(Project project, string diagramName, int shapesPerRow, int shapesPerColumn, bool connectShapes, bool withModels, bool withModelMappings, bool withLayers) { const int shapeSize = 80; int lineLength = shapeSize / 2; // // Create ModelMappings NumericModelMapping numericModelMapping = null; FormatModelMapping formatModelMapping = null; StyleModelMapping styleModelMapping = null; if (withModelMappings) { // Create numeric- and format model mappings numericModelMapping = new NumericModelMapping(2, 4, NumericModelMapping.MappingType.FloatInteger, 10, 0); formatModelMapping = new FormatModelMapping(4, 2, FormatModelMapping.MappingType.StringString, "{0}"); // Create style model mapping float range = (shapesPerRow * shapesPerColumn) / 15f; styleModelMapping = new StyleModelMapping(1, 4, StyleModelMapping.MappingType.FloatStyle); for (int i = 0; i < 15; ++i) { IStyle style = null; switch (i) { case 0: style = project.Design.LineStyles.None; break; case 1: style = project.Design.LineStyles.Dotted; break; case 2: style = project.Design.LineStyles.Dashed; break; case 3: style = project.Design.LineStyles.Special1; break; case 4: style = project.Design.LineStyles.Special2; break; case 5: style = project.Design.LineStyles.Normal; break; case 6: style = project.Design.LineStyles.Blue; break; case 7: style = project.Design.LineStyles.Green; break; case 8: style = project.Design.LineStyles.Yellow; break; case 9: style = project.Design.LineStyles.Red; break; case 10: style = project.Design.LineStyles.HighlightDotted; break; case 11: style = project.Design.LineStyles.HighlightDashed; break; case 12: style = project.Design.LineStyles.Highlight; break; case 13: style = project.Design.LineStyles.HighlightThick; break; case 14: style = project.Design.LineStyles.Thick; break; default: style = null; break; } if (style != null) { styleModelMapping.AddValueRange(i * range, style); } } } // // Create model obejct for the planar shape's template IModelObject planarModel = null; if (withModels) { planarModel = project.ModelObjectTypes["Core.GenericModelObject"].CreateInstance(); } // // Create a shape for the planar shape's template Circle circleShape = (Circle)project.ShapeTypes["Circle"].CreateInstance(); circleShape.Diameter = shapeSize; // // Create a template for the planar shapes Template planarTemplate = new Template("PlanarShape Template", circleShape); if (withModels) { planarTemplate.Shape.ModelObject = planarModel; if (withModelMappings) { planarTemplate.MapProperties(numericModelMapping); planarTemplate.MapProperties(formatModelMapping); planarTemplate.MapProperties(styleModelMapping); } } // // Create a template for the linear shapes Template linearTemplate = null; if (connectShapes) { linearTemplate = new Template("LinearShape Template", project.ShapeTypes["Polyline"].CreateInstance()); } // // Insert the created templates into the repository project.Repository.InsertTemplate(planarTemplate); foreach (IModelMapping modelMapping in planarTemplate.GetPropertyMappings()) { project.Repository.InsertModelMapping(modelMapping, planarTemplate); } if (connectShapes) { project.Repository.InsertTemplate(linearTemplate); foreach (IModelMapping modelMapping in linearTemplate.GetPropertyMappings()) { project.Repository.InsertModelMapping(modelMapping, linearTemplate); } } // // Prepare the connection points ControlPointId leftPoint = withModels ? ControlPointId.Reference : 4; ControlPointId rightPoint = withModels ? ControlPointId.Reference : 5; ControlPointId topPoint = withModels ? ControlPointId.Reference : 2; ControlPointId bottomPoint = withModels ? ControlPointId.Reference : 7; // // Create the diagram Diagram diagram = new Diagram(diagramName); // // Create and add layers LayerIds planarLayer = LayerIds.None, linearLayer = LayerIds.None, oddRowLayer = LayerIds.None, evenRowLayer = LayerIds.None, oddColLayer = LayerIds.None, evenColLayer = LayerIds.None; if (withLayers) { const string planarLayerName = "PlanarShapesLayer"; const string linearLayerName = "LinearShapesLayer"; const string oddRowsLayerName = "OddRowsLayer"; const string evenRowsLayerName = "EvenRowsLayer"; const string oddColsLayerName = "OddColsLayer"; const string evenColsLayerName = "EvenColsLayer"; // Create Layers Layer planarShapesLayer = new Layer(planarLayerName); planarShapesLayer.Title = "Planar Shapes"; planarShapesLayer.LowerZoomThreshold = 5; planarShapesLayer.UpperZoomThreshold = 750; diagram.Layers.Add(planarShapesLayer); Layer linearShapesLayer = new Layer(linearLayerName); linearShapesLayer.Title = "Linear Shapes"; linearShapesLayer.LowerZoomThreshold = 10; linearShapesLayer.UpperZoomThreshold = 500; diagram.Layers.Add(linearShapesLayer); Layer oddRowsLayer = new Layer(oddRowsLayerName); oddRowsLayer.Title = "Odd Rows"; oddRowsLayer.LowerZoomThreshold = 2; oddRowsLayer.UpperZoomThreshold = 1000; diagram.Layers.Add(oddRowsLayer); Layer evenRowsLayer = new Layer(evenRowsLayerName); evenRowsLayer.Title = "Even Rows"; evenRowsLayer.LowerZoomThreshold = 2; evenRowsLayer.UpperZoomThreshold = 1000; diagram.Layers.Add(evenRowsLayer); Layer oddColsLayer = new Layer(oddColsLayerName); oddColsLayer.Title = "Odd Columns"; oddColsLayer.LowerZoomThreshold = 2; oddColsLayer.UpperZoomThreshold = 1000; diagram.Layers.Add(oddColsLayer); Layer evenColsLayer = new Layer(evenColsLayerName); evenColsLayer.Title = "Even Columns"; evenColsLayer.LowerZoomThreshold = 2; evenColsLayer.UpperZoomThreshold = 1000; diagram.Layers.Add(evenColsLayer); // Assign LayerIds planarLayer = diagram.Layers.FindLayer(planarLayerName).Id; linearLayer = diagram.Layers.FindLayer(linearLayerName).Id; oddRowLayer = diagram.Layers.FindLayer(oddRowsLayerName).Id; evenRowLayer = diagram.Layers.FindLayer(evenRowsLayerName).Id; oddColLayer = diagram.Layers.FindLayer(oddColsLayerName).Id; evenColLayer = diagram.Layers.FindLayer(evenColsLayerName).Id; } for (int rowIdx = 0; rowIdx < shapesPerRow; ++rowIdx) { LayerIds rowLayer = ((rowIdx + 1) % 2 == 0) ? evenRowLayer : oddRowLayer; for (int colIdx = 0; colIdx < shapesPerRow; ++colIdx) { LayerIds colLayer = ((colIdx + 1) % 2 == 0) ? evenColLayer : oddColLayer; int shapePosX = shapeSize + colIdx * (lineLength + shapeSize); int shapePosY = shapeSize + rowIdx * (lineLength + shapeSize); circleShape = (Circle)planarTemplate.CreateShape(); circleShape.Text = string.Format("{0} / {1}", rowIdx + 1, colIdx + 1); circleShape.MoveTo(shapePosX, shapePosY); if (withModels) { project.Repository.InsertModelObject(circleShape.ModelObject); ((GenericModelObject)circleShape.ModelObject).IntegerValue = rowIdx; } diagram.Shapes.Add(circleShape, project.Repository.ObtainNewTopZOrder(diagram)); if (withLayers) { diagram.AddShapeToLayers(circleShape, planarLayer | rowLayer | colLayer); } if (connectShapes) { if (rowIdx > 0) { Shape lineShape = linearTemplate.CreateShape(); lineShape.Connect(ControlPointId.FirstVertex, circleShape, topPoint); Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.FirstVertex, circleShape)); Shape otherShape = diagram.Shapes.FindShape(shapePosX, shapePosY - shapeSize, ControlPointCapabilities.None, 0, null); lineShape.Connect(ControlPointId.LastVertex, otherShape, bottomPoint); diagram.Shapes.Add(lineShape, project.Repository.ObtainNewBottomZOrder(diagram)); if (withLayers) { diagram.AddShapeToLayers(lineShape, linearLayer); } Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.LastVertex, otherShape)); } if (colIdx > 0) { Shape lineShape = linearTemplate.CreateShape(); lineShape.Connect(1, circleShape, leftPoint); Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.FirstVertex, circleShape)); Shape otherShape = diagram.Shapes.FindShape(shapePosX - shapeSize, shapePosY, ControlPointCapabilities.None, 0, null); lineShape.Connect(2, otherShape, rightPoint); diagram.Shapes.Add(lineShape, project.Repository.ObtainNewBottomZOrder(diagram)); if (withLayers) { diagram.AddShapeToLayers(lineShape, linearLayer); } Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.LastVertex, otherShape)); } } } } diagram.Width = (lineLength + shapeSize) * shapesPerRow + 2 * shapeSize; diagram.Height = (lineLength + shapeSize) * shapesPerColumn + 2 * shapeSize; project.Repository.InsertDiagram(diagram); }
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { switch (controlPointId) { case ControlPointId.Reference: case MiddleCenterControlPoint: return base.HasControlPointCapability(controlPointId, controlPointCapability); case BottomCenterControlPoint: case TopCenterControlPoint: return ((controlPointCapability & ControlPointCapabilities.Resize) != 0 || (controlPointCapability & ControlPointCapabilities.Connect) != 0); default: return base.HasControlPointCapability(controlPointId, controlPointCapability); //return (controlPointCapability & ControlPointCapabilities.Resize) != 0; } }
/// <override></override> protected override bool MovePointByCore(ControlPointId pointId, float transformedDeltaX, float transformedDeltaY, float sin, float cos, ResizeModifiers modifiers) { bool result = true; int dx = 0, dy = 0; int width = Width; int height = Height; switch (pointId) { case ControlPointIds.ArrowTopControlPoint: case ControlPointIds.ArrowBottomControlPoint: if (pointId == ControlPointIds.ArrowTopControlPoint) { //result = (transformedDeltaX == 0); if (!Geometry.MoveRectangleTop(width, height, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out width, out height)) { result = false; } } else { //result = (transformedDeltaX == 0); if (!Geometry.MoveRectangleBottom(width, height, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out width, out height)) { result = false; } } int newHeadWidth = HeadWidth + (int)Math.Round(transformedDeltaX); if (newHeadWidth < 0) { newHeadWidth = 0; result = false; } else if (newHeadWidth > Width) { newHeadWidth = Width; result = false; } HeadWidth = newHeadWidth; break; case ControlPointIds.BodyTopControlPoint: case ControlPointIds.BodyBottomControlPoint: result = (transformedDeltaX == 0); int newBodyHeight = 0; if (pointId == ControlPointIds.BodyTopControlPoint) { newBodyHeight = (int)Math.Round(BodyHeight - (transformedDeltaY * 2)); } else { newBodyHeight = (int)Math.Round(BodyHeight + (transformedDeltaY * 2)); } if (newBodyHeight > Height) { newBodyHeight = Height; result = false; } else if (newBodyHeight < 0) { newBodyHeight = 0; result = false; } BodyHeight = newBodyHeight; break; default: return(base.MovePointByCore(pointId, transformedDeltaX, transformedDeltaY, sin, cos, modifiers)); } if (width < headWidth) { width = headWidth; result = false; } MoveByCore(dx, dy); Width = width; Height = height; return(result); }
protected override int GetControlPointIndex(ControlPointId id) { switch (id) { case TopLeftControlPoint: return 0; case TopCenterControlPoint: return 1; case MiddleLeftControlPoint: return 2; case MiddleRightControlPoint: return 3; case BottomLeftControlPoint: return 4; case BottomCenterControlPoint: return 5; case MiddleCenterControlPoint: return 6; default: return -1; } }
/// <override></override> protected internal override void AttachGluePointToConnectionPoint(ControlPointId ownPointId, Shape otherShape, ControlPointId gluePointId) { if (ownPointId != ControlPointId.Reference && !HasControlPointCapability(ownPointId, ControlPointCapabilities.Connect)) { throw new NShapeException(string.Format("{0}'s point {1} has to be a connection point.", Type.Name, ownPointId)); } if (!otherShape.HasControlPointCapability(gluePointId, ControlPointCapabilities.Glue)) { throw new NShapeException(string.Format("{0}'s point {1} has to be a glue point.", otherShape.Type.Name, gluePointId)); } throw new NotSupportedException(); }
/// <override></override> protected override bool MovePointByCore(ControlPointId pointId, float transformedDeltaX, float transformedDeltaY, float sin, float cos, ResizeModifiers modifiers) { bool result = true; int dx = 0, dy = 0; int width = Width; int height = Height; switch ((int)pointId) { case TopCenterControlPoint: result = (transformedDeltaX == 0); if (!Geometry.MoveRectangleTop(width, height, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out width, out height)) result = false; break; case MiddleLeftControlPoint: result = (transformedDeltaY == 0); if (!Geometry.MoveRectangleLeft(width, height, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out width, out height)) result = false; break; case MiddleRightControlPoint: result = (transformedDeltaY == 0); if (!Geometry.MoveRectangleRight(width, height, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out width, out height)) result = false; break; case BottomCenterControlPoint: result = (transformedDeltaX == 0); if (!Geometry.MoveRectangleBottom(width, height, transformedDeltaX, transformedDeltaY, cos, sin, modifiers, out dx, out dy, out width, out height)) result = false; break; default: break; } if (result) { Width = width; Height = height; X += dx; Y += dy; } ControlPointsHaveMoved(); return result; }
/// <override></override> protected internal override void DetachGluePointFromConnectionPoint(ControlPointId ownPointId, Shape targetShape, ControlPointId targetPointId) { throw new NotSupportedException(); }
/// <override></override> public override void Connect(ControlPointId gluePointId, Shape targetShape, ControlPointId targetPointId) { // nothing to do }
/// <override></override> public override bool CanConnect(ControlPointId gluePointId, Shape targetShape, ControlPointId targetPointId) { return(false); }
/// <override></override> public override IEnumerable<ShapeConnectionInfo> GetConnectionInfos(ControlPointId ownPointId, Shape otherShape) { yield break; }
/// <override></override> public override ControlPointId IsConnected(ControlPointId ownPointId, Shape otherShape) { return ControlPointId.None; }
/// <override></override> public override Point GetControlPointPosition(ControlPointId controlPointId) { if (controlPointId == ControlPointId.Reference) //return location; return children.Center; else if (controlPointId == RotatePointId) return RotatePoint; else if (controlPointId == ControlPointId.None) throw new ArgumentException(string.Format("{0} is not a valid {1} for this operation.", controlPointId, typeof (ControlPointId).Name)); return Point.Empty; }
/// <override></override> public override bool MoveControlPointBy(ControlPointId pointId, int deltaX, int deltaY, ResizeModifiers modifiers) { bool result = false; if (pointId == ControlPointId.Reference) result = MoveBy(deltaX, deltaY); else { if (Owner != null) Owner.NotifyChildResizing(this); result = false; if (Owner != null) Owner.NotifyChildResized(this); } return result; }
/// <override></override> protected internal override void AttachGluePointToConnectionPoint(ControlPointId ownPointId, Shape otherShape, ControlPointId gluePointId) { if (ownPointId != ControlPointId.Reference && !HasControlPointCapability(ownPointId, ControlPointCapabilities.Connect)) throw new NShapeException(string.Format("{0}'s point {1} has to be a connection point.", Type.Name, ownPointId)); if (!otherShape.HasControlPointCapability(gluePointId, ControlPointCapabilities.Glue)) throw new NShapeException(string.Format("{0}'s point {1} has to be a glue point.", otherShape.Type.Name, gluePointId)); throw new NotSupportedException(); }
/// <override></override> public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability) { if (controlPointId == RotatePointId || controlPointId == ControlPointId.Reference) return ((controlPointCapability & ControlPointCapabilities.Rotate) > 0 || (controlPointCapability & ControlPointCapabilities.Reference) > 0); return false; }
/// <ToBeCompleted></ToBeCompleted> public TemplateControllerPointMappingChangedEventArgs(Template template, ControlPointId controlPointId, TerminalId oldTerminalId, TerminalId newTerminalId) : base(template) { this.controlPointId = controlPointId; this.oldTerminalId = oldTerminalId; this.newTerminalId = newTerminalId; }
private void _RemoveDataFlowLinksFromShapePoint(FilterSetupShapeBase shape, ControlPointId controlPoint, bool removePatching) { foreach (ShapeConnectionInfo ci in shape.GetConnectionInfos(controlPoint, null)) { if (ci.OtherShape == null) continue; DataFlowConnectionLine line = ci.OtherShape as DataFlowConnectionLine; if (line == null) throw new Exception("a shape was connected to something other than a DataFlowLine!"); // only try and unpatch if we're supposed to; this function can also be used to hide/remove lines from the display if (removePatching) { // if the line is connected with the given shape as the SOURCE, remove the unknown DESTINATION's // source (on the other end of the line). Otherwise, it (should) be that the given shape is the // destination; so reset it's source. If neither of these are true, freak out. if (line.GetConnectionInfo(ControlPointId.FirstVertex, null).OtherShape == shape) { if (line.DestinationDataComponent != null) VixenSystem.DataFlow.ResetComponentSource(line.DestinationDataComponent); } else if (line.GetConnectionInfo(ControlPointId.LastVertex, null).OtherShape == shape) { VixenSystem.DataFlow.ResetComponentSource(shape.DataFlowComponent); } else { throw new Exception("Can't reset a link that has neither the source or destination for the given shape!"); } OnPatchingUpdated(); } _RemoveShapeFromDiagram(line, false); } }