/// <summary> /// Pulled directly from Reflector disassembly /// </summary> private LineSegment[] CalculateSegments(IGeometryHost geometryHost, DiagramHitTestInfo hitTestInfo) { IBinaryLinkGeometryData data1 = geometryHost as IBinaryLinkGeometryData; EdgePointCollection collection1 = data1.GeometryEdgePointsNoJumps; LineSegment[] segmentArray1 = new LineSegment[collection1.Count - 1]; Pen pen1 = geometryHost.GeometryStyleSet.GetPen(this.GetOutlinePenId(geometryHost)); if (pen1 != null) { for (int num1 = 0; num1 < (collection1.Count - 1); num1++) { RectangleD ed1 = GeometryHelpers.RectangleDFrom2Pts(collection1[num1].Point, collection1[num1 + 1].Point); // In DSL Tools v8.2, GetHitTestTolerance is an instance method, but in DSL Tools v9.0, it is a static method. // We call it without a qualifier here so that it will compile against both versions. SizeD ed2 = GetHitTestTolerance(hitTestInfo); if (ed1.Height < ed2.Height) { ed1.Inflate(0, (pen1.Width / 2f) + ed2.Height); } else if (ed1.Width < ed2.Width) { ed1.Inflate((pen1.Width / 2f) + ed2.Width, 0); } segmentArray1[num1] = new LineSegment(collection1[num1].Point, collection1[num1 + 1].Point, num1, num1 + 1, num1 == 0, (num1 + 1) == (collection1.Count - 1), ed1); } } return(segmentArray1); }
/// <summary> /// Retrieves a mouse action that should be made active on the next /// MouseDown event if the mouse is over the specified point. /// </summary> /// <param name="mouseButtons">The current mouse button state.</param> /// <param name="point">The mouse position relative to the diagram's top-left in world units.</param> /// <param name="hitTestInfo">Information detailing the results of the hit testing.</param> /// <returns>A mouse action that should be made active on the next MouseDown event if the mouse is over the specified point.</returns> public override MouseAction GetPotentialMouseAction(MouseButtons mouseButtons, PointD point, DiagramHitTestInfo hitTestInfo) { DiagramItem hitDiagramItem = hitTestInfo.HitDiagramItem; Diagram diagram = (hitDiagramItem != null) ? hitDiagramItem.Diagram : null; if (diagram == null) { return null; } return diagram.SelectAction; }
/// <summary> /// Gets the mouse action to perform for a MouseDown event over a specific point in the diagram. /// </summary> /// <param name="mouseButtons">The mouse buttons that can cause the MouseDown event.</param> /// <param name="point">The point on the diagram, relative to the top-left point of the diagram.</param> /// <param name="hitTestInfo">The hit test information.</param> /// <returns> /// The mouse action to perform for a MouseDown event over a specific point in the diagram. /// </returns> public override MouseAction GetPotentialMouseAction(MouseButtons mouseButtons, PointD point, DiagramHitTestInfo hitTestInfo) { MouseAction action = base.GetPotentialMouseAction(mouseButtons, point, hitTestInfo); if (mouseButtons == MouseButtons.Left && Utils.IsKeyPressed(Keys.Alt)) { return(((ComponentModelDiagram)Diagram).ReferenceConnectAction); } return(action); }
/// <summary> /// Helper function for TranslateAccessibleObject and EnsureAccessibleObjectVisible /// </summary> private DiagramItem TranslateAccessibleObjectToDiagramItem(AccessibleObject accessibleObject, bool returnShape) { if (accessibleObject == null) { return(null); } DiagramItem hitItem = null; DiagramClientView clientView = myClientView; DiagramHitTestInfo hitInfo = new DiagramHitTestInfo(clientView); RectangleD boundsD = clientView.DeviceToWorld(clientView.RectangleToClient(accessibleObject.Bounds)); if (clientView.Diagram.DoHitTest(boundsD.Center, hitInfo, false)) { hitItem = hitInfo.HitDiagramItem; if (!returnShape) { // Wind back out the parent stack if the hit test went too far if (hitItem.SubField != null) { if (!(accessibleObject is SubfieldAccessibleObject)) { if (!(accessibleObject is FieldAccessibleObject)) { hitItem = new DiagramItem(hitItem.Shape); } else { hitItem = new DiagramItem(hitItem.Shape, hitItem.Field); } } } else if (hitItem.Field != null && !(accessibleObject is FieldAccessibleObject)) { hitItem = new DiagramItem(hitItem.Shape); } } } return(hitItem); }
public override bool DoHitTest(PointD point, DiagramHitTestInfo hitTestInfo, bool includeTolerance) { return(base.DoHitTest(point, hitTestInfo, includeTolerance)); }
/// <summary> /// Helper function for TranslateAccessibleObject and EnsureAccessibleObjectVisible /// </summary> private DiagramItem TranslateAccessibleObjectToDiagramItem(AccessibleObject accessibleObject, bool returnShape) { if (accessibleObject == null) { return null; } DiagramItem hitItem = null; DiagramClientView clientView = myClientView; DiagramHitTestInfo hitInfo = new DiagramHitTestInfo(clientView); RectangleD boundsD = clientView.DeviceToWorld(clientView.RectangleToClient(accessibleObject.Bounds)); if (clientView.Diagram.DoHitTest(boundsD.Center, hitInfo, false)) { hitItem = hitInfo.HitDiagramItem; if (!returnShape) { // Wind back out the parent stack if the hit test went too far if (hitItem.SubField != null) { if (!(accessibleObject is SubfieldAccessibleObject)) { if (!(accessibleObject is FieldAccessibleObject)) { hitItem = new DiagramItem(hitItem.Shape); } else { hitItem = new DiagramItem(hitItem.Shape, hitItem.Field); } } } else if (hitItem.Field != null && !(accessibleObject is FieldAccessibleObject)) { hitItem = new DiagramItem(hitItem.Shape); } } } return hitItem; }
/// <summary> /// Override of DoHitTest so it works with non-rectilinear line segments /// </summary> public override bool DoHitTest(IGeometryHost geometryHost, PointD hitPoint, DiagramHitTestInfo hitTestInfo, bool includeTolerance) { bool retVal = false; LineSegment hitSegment = null; AnchorPoint anchorPoint = null; // In DSL Tools v8.2, GetHitTestTolerance is an instance method, but in DSL Tools v9.0, it is a static method. // We call it without a qualifier here so that it will compile against both versions. SizeD tolerance = GetHitTestTolerance(hitTestInfo); RectangleD perimeter = this.GetPerimeterBoundingBox(geometryHost); perimeter.Inflate(tolerance); if (perimeter.Contains(hitPoint)) { LineSegment[] segments = this.CalculateSegments(geometryHost, hitTestInfo); int segmentCount = segments.Length; for (int i = 0; i < segmentCount; ++i) { LineSegment testSegment = segments[i]; RectangleD testBounds = GeometryHelpers.RectangleDFrom2Pts(testSegment.StartPoint, testSegment.EndPoint); testBounds.Inflate(tolerance); if (testBounds.Contains(hitPoint)) { anchorPoint = TestHitAnchor(geometryHost as BinaryLinkShape, testSegment, tolerance, hitPoint); if (anchorPoint != null) { retVal = true; hitSegment = testSegment; break; } double distance = DistanceFromPointToLine(hitPoint, testSegment.StartPoint, testSegment.EndPoint, true); if (!double.IsNaN(distance) && distance < (tolerance.Width + geometryHost.GeometryStyleSet.GetPen(geometryHost.GeometryOutlinePenId).Width / 2f)) { retVal = true; hitSegment = testSegment; break; } } } } if (hitTestInfo != null) { DiagramItem diagramItem; if (retVal) { if (anchorPoint == null) { // In DSL Tools v8.2, CreateDiagramItem is an instance method, but in DSL Tools v9.0, it is a static method. // We call it without a qualifier here so that it will compile against both versions. diagramItem = CreateDiagramItem(geometryHost, hitSegment); } else { diagramItem = new DiagramItem(geometryHost as LinkShape, hitSegment, anchorPoint); } } else { diagramItem = null; } hitTestInfo.HitDiagramItem = diagramItem; hitTestInfo.HitGrabHandle = null; } return(retVal); }
/// <summary> /// Don't let the lines interfere with clicking on other items /// </summary> public override bool DoHitTest(IGeometryHost geometryHost, PointD hitPoint, DiagramHitTestInfo hitTestInfo, bool includeTolerance) { return(false); }
/// <summary> /// Retrieves a mouse action that should be made active on the next /// MouseDown event if the mouse is over the specified point. /// </summary> /// <param name="mouseButtons">The current mouse button state.</param> /// <param name="point">The mouse position relative to the diagram's top-left in world units.</param> /// <param name="hitTestInfo">Information detailing the results of the hit testing.</param> /// <returns>A mouse action that should be made active on the next MouseDown event if the mouse is over the specified point.</returns> public override MouseAction GetPotentialMouseAction(MouseButtons mouseButtons, PointD point, DiagramHitTestInfo hitTestInfo) { DiagramItem hitDiagramItem = hitTestInfo.HitDiagramItem; Diagram diagram = (hitDiagramItem != null) ? hitDiagramItem.Diagram : null; if (diagram == null) { return(null); } return(diagram.SelectAction); }
public override bool DoHitTest(PointD point, DiagramHitTestInfo hitTestInfo, bool includeTolerance) { return base.DoHitTest(point, hitTestInfo, includeTolerance); }
public override bool DoHitTest(IGeometryHost geometryHost, PointD hitPoint, DiagramHitTestInfo hitTestInfo, bool includeTolerance) { RectangleD perimeterBoundingBox = this.GetPerimeterBoundingBox(geometryHost); if (includeTolerance) { perimeterBoundingBox.Inflate(ShapeGeometry.GetHitTestTolerance(hitTestInfo)); } if (hitTestInfo != null) { hitTestInfo.HitDiagramItem = null; hitTestInfo.HitGrabHandle = null; } // point is in the bounding rectangle bool flag = false; if (perimeterBoundingBox.Contains(hitPoint)) { // point is in the diamond shape flag = isPointInTriangle( new PointD(perimeterBoundingBox.X, perimeterBoundingBox.Y + perimeterBoundingBox.Height / 2), new PointD(perimeterBoundingBox.X + perimeterBoundingBox.Width / 2, perimeterBoundingBox.Y), new PointD(perimeterBoundingBox.X + perimeterBoundingBox.Width, perimeterBoundingBox.Y + perimeterBoundingBox.Height / 2), hitPoint ); if (!flag) { flag = isPointInTriangle( new PointD(perimeterBoundingBox.X, perimeterBoundingBox.Y + perimeterBoundingBox.Height / 2), new PointD(perimeterBoundingBox.X + perimeterBoundingBox.Width / 2, perimeterBoundingBox.Y + perimeterBoundingBox.Height), new PointD(perimeterBoundingBox.X + perimeterBoundingBox.Width, perimeterBoundingBox.Y + perimeterBoundingBox.Height / 2), hitPoint ); } } if (flag && (hitTestInfo != null)) { hitTestInfo.HitDiagramItem = ShapeGeometry.CreateDiagramItem(geometryHost); } return(flag); }
/// <summary> /// Pulled directly from Reflector disassembly /// </summary> private LineSegment[] CalculateSegments(IGeometryHost geometryHost, DiagramHitTestInfo hitTestInfo) { IBinaryLinkGeometryData data1 = geometryHost as IBinaryLinkGeometryData; EdgePointCollection collection1 = data1.GeometryEdgePointsNoJumps; LineSegment[] segmentArray1 = new LineSegment[collection1.Count - 1]; Pen pen1 = geometryHost.GeometryStyleSet.GetPen(this.GetOutlinePenId(geometryHost)); if (pen1 != null) { for (int num1 = 0; num1 < (collection1.Count - 1); num1++) { RectangleD ed1 = GeometryHelpers.RectangleDFrom2Pts(collection1[num1].Point, collection1[num1 + 1].Point); // In DSL Tools v8.2, GetHitTestTolerance is an instance method, but in DSL Tools v9.0, it is a static method. // We call it without a qualifier here so that it will compile against both versions. SizeD ed2 = GetHitTestTolerance(hitTestInfo); if (ed1.Height < ed2.Height) { ed1.Inflate(0, (pen1.Width / 2f) + ed2.Height); } else if (ed1.Width < ed2.Width) { ed1.Inflate((pen1.Width / 2f) + ed2.Width, 0); } segmentArray1[num1] = new LineSegment(collection1[num1].Point, collection1[num1 + 1].Point, num1, num1 + 1, num1 == 0, (num1 + 1) == (collection1.Count - 1), ed1); } } return segmentArray1; }
/// <summary> /// Override of DoHitTest so it works with non-rectilinear line segments /// </summary> public override bool DoHitTest(IGeometryHost geometryHost, PointD hitPoint, DiagramHitTestInfo hitTestInfo, bool includeTolerance) { bool retVal = false; LineSegment hitSegment = null; AnchorPoint anchorPoint = null; // In DSL Tools v8.2, GetHitTestTolerance is an instance method, but in DSL Tools v9.0, it is a static method. // We call it without a qualifier here so that it will compile against both versions. SizeD tolerance = GetHitTestTolerance(hitTestInfo); RectangleD perimeter = this.GetPerimeterBoundingBox(geometryHost); perimeter.Inflate(tolerance); if (perimeter.Contains(hitPoint)) { LineSegment[] segments = this.CalculateSegments(geometryHost, hitTestInfo); int segmentCount = segments.Length; for (int i = 0; i < segmentCount; ++i) { LineSegment testSegment = segments[i]; RectangleD testBounds = GeometryHelpers.RectangleDFrom2Pts(testSegment.StartPoint, testSegment.EndPoint); testBounds.Inflate(tolerance); if (testBounds.Contains(hitPoint)) { anchorPoint = TestHitAnchor(geometryHost as BinaryLinkShape, testSegment, tolerance, hitPoint); if (anchorPoint != null) { retVal = true; hitSegment = testSegment; break; } double distance = DistanceFromPointToLine(hitPoint, testSegment.StartPoint, testSegment.EndPoint, true); if (!double.IsNaN(distance) && distance < (tolerance.Width + geometryHost.GeometryStyleSet.GetPen(geometryHost.GeometryOutlinePenId).Width / 2f)) { retVal = true; hitSegment = testSegment; break; } } } } if (hitTestInfo != null) { DiagramItem diagramItem; if (retVal) { if (anchorPoint == null) { // In DSL Tools v8.2, CreateDiagramItem is an instance method, but in DSL Tools v9.0, it is a static method. // We call it without a qualifier here so that it will compile against both versions. diagramItem = CreateDiagramItem(geometryHost, hitSegment); } else { diagramItem = new DiagramItem(geometryHost as LinkShape, hitSegment, anchorPoint); } } else { diagramItem = null; } hitTestInfo.HitDiagramItem = diagramItem; hitTestInfo.HitGrabHandle = null; } return retVal; }
/// <summary> /// Don't let the lines interfere with clicking on other items /// </summary> public override bool DoHitTest(IGeometryHost geometryHost, PointD hitPoint, DiagramHitTestInfo hitTestInfo, bool includeTolerance) { return false; }
//This lets user just click and drag a socket to connect, rather than needing to explicitly select the connection tool public override MouseAction GetPotentialMouseAction(System.Windows.Forms.MouseButtons mouseButtons, PointD point, DiagramHitTestInfo hitTestInfo) { var diagram = this.Diagram as GadgeteerDSLDiagram; if (diagram != null && !((SocketBase)this.ModelElement).IsConnected) { return(diagram.ConnectAction); } return(base.GetPotentialMouseAction(mouseButtons, point, hitTestInfo)); }