/// <summary> /// /// </summary> /// <param name="pts"></param> /// <returns></returns> public static double CalcLineLength(IPoints pts) { if (pts == null) { throw new EInvalidParameter(); } double length = 0.0f; int vertexIdx1 = 0; int vertexIdx2 = 1; PointF vertex1; PointF vertex2; int numPts = pts.PointCount; while (vertexIdx2 < numPts) { vertex1 = pts.GetPoint(vertexIdx1); vertex2 = pts.GetPoint(vertexIdx2); length += Geometry.PointDistance(vertex1, vertex2); vertexIdx1++; vertexIdx2++; } return(length); }
/// <summary> /// /// </summary> /// <param name="pts"></param> /// <param name="percent"></param> /// <param name="ptReturn"></param> /// <param name="vertexIdx1"></param> /// <param name="vertexIdx2"></param> /// <returns></returns> public static bool CalcPercentageAlong(IPoints pts, int percent, out System.Drawing.PointF ptReturn, out int vertexIdx1, out int vertexIdx2) { bool found = false; if (pts == null) { throw new EInvalidParameter(); } if (percent < 0 || percent > 100) { throw new EInvalidParameter(); } int numPts = pts.PointCount; double totalLength = Geometry.CalcLineLength(pts); double lengthAlong = totalLength * (percent / 100.0f); double lengthSoFar = 0.0f; PointF vertex1; PointF vertex2; double curSegmentLength; double curSegmentPct; vertexIdx1 = 0; vertexIdx2 = 1; ptReturn = new PointF(0, 0); while (vertexIdx2 < numPts && !found) { vertex1 = pts.GetPoint(vertexIdx1); vertex2 = pts.GetPoint(vertexIdx2); curSegmentLength = Geometry.PointDistance(vertex1, vertex2); if (curSegmentLength > 0.0f && (lengthSoFar + curSegmentLength) >= lengthAlong) { // calculate percentage along this segment curSegmentPct = (lengthAlong - lengthSoFar) * 100.0f / curSegmentLength; // find the point on the segment double ptX = vertex1.X + (curSegmentPct * (vertex2.X - vertex1.X) / 100.0f); double ptY = vertex1.Y + (curSegmentPct * (vertex2.Y - vertex1.Y) / 100.0f); ptReturn = new PointF((float)ptX, (float)ptY); // Exit loop and return found = true; } else { vertexIdx1++; vertexIdx2++; } } return(found); }
/// <summary> /// Moves the vertex of the node by the specified amount. /// </summary> /// <param name="cmdTarget">Unused</param> /// <returns>true if successful, otherwise false</returns> /// <remarks> /// The node must support the IPoints interface. The IPoints.SetPoint /// method is used to move the point by the specified offset. /// </remarks> public override bool Do(object cmdTarget) { bool success = false; if (this.Node != null) { IPoints objPoints = this.Node as IPoints; if (objPoints != null) { ITransform objTransform = this.Node as ITransform; Matrix worldXform = null; Matrix invWorldXform = null; if (objTransform != null) { worldXform = objTransform.WorldTransform; invWorldXform = worldXform.Clone(); invWorldXform.Invert(); } if (this.vertexIdx >= 0 && this.vertexIdx < objPoints.PointCount) { PointF[] pt = new PointF[1] { objPoints.GetPoint(this.vertexIdx) }; if (worldXform != null) { worldXform.TransformPoints(pt); } pt[0].X += this.dx; pt[0].Y += this.dy; if (invWorldXform != null) { invWorldXform.TransformPoints(pt); } objPoints.SetPoint(this.vertexIdx, pt[0]); success = true; } } } return(success); }
/// <summary> /// Deletes the specified vertex from the node. /// </summary> /// <param name="cmdTarget">Unused</param> /// <returns>true if successful, otherwise false</returns> /// <remarks> /// This method gets the IPoints interface from the node and /// calls <see cref="Syncfusion.Windows.Forms.Diagram.IPoints.RemovePoint"/> /// to remove the vertex. /// </remarks> public override bool Do(object cmdTarget) { bool success = false; if (this.Node != null) { IPoints objPoints = this.Node as IPoints; if (objPoints != null) { if (this.vertexIdx >= 0 && this.vertexIdx < objPoints.PointCount) { this.ptValue = objPoints.GetPoint(this.vertexIdx); objPoints.RemovePoint(this.vertexIdx); success = true; } } } return(success); }
/// <summary> /// Moves the vertex back to the position it was in before the /// command was executed. /// </summary> /// <returns>true if successful, otherwise false</returns> public override bool Undo() { bool success = false; if (this.Node != null) { IPoints objPoints = this.Node as IPoints; if (objPoints != null) { if (this.vertexIdx >= 0 && this.vertexIdx < objPoints.PointCount) { PointF pt = objPoints.GetPoint(this.vertexIdx); pt.X -= this.dx; pt.Y -= this.dy; objPoints.SetPoint(this.vertexIdx, pt); success = true; } } } return(success); }
/// <summary> /// Adjusts the endpoints of the link so that they are docked with the /// foreign ports they are connected to. /// </summary> /// <remarks> /// <para> /// This method iterates through every connection in the link. For each /// connection, the location of the local port is updated to match /// the location of the foreign port. If the foreign port has its /// AttachAtPerimeter flag set to true, then some additional calculations /// are made in order to move the local port to the perimeter of the /// foreign port's container. /// </para> /// <seealso cref="Syncfusion.Windows.Forms.Diagram.Port.AttachAtPerimeter"/> /// </remarks> protected virtual void DockConnections() { IPoints shapePts = this.Points; LinkPort curLocalPort; Port curForeignPort; IPortContainer curForeignObj; int numPoints = 0; ConnectionCollection perimeterConnections = new ConnectionCollection(); PointF ptStart; int ptIdx; PointF ptBoundary; if (shapePts != null) { numPoints = shapePts.PointCount; foreach (Connection curConnection in this.Connections) { curLocalPort = curConnection.GetLocalPort(this) as LinkPort; curForeignPort = curConnection.GetForeignPort(this); if (curLocalPort != null && curForeignPort != null) { curLocalPort.Location = curForeignPort.Location; if (curForeignPort.AttachAtPerimeter) { perimeterConnections.Add(curConnection); } } } foreach (Connection curConnection in perimeterConnections) { curLocalPort = curConnection.GetLocalPort(this) as LinkPort; curForeignPort = curConnection.GetForeignPort(this); if (curLocalPort != null && curForeignPort != null) { curForeignObj = curForeignPort.Container; if (curForeignObj != null) { ptIdx = curLocalPort.PointIndex; if (ptIdx > 0 && ptIdx == numPoints - 1) { ptStart = shapePts.GetPoint(ptIdx - 1); } else if (ptIdx == 0 && numPoints > 1) { ptStart = shapePts.GetPoint(ptIdx + 1); } else { ptStart = curLocalPort.Location; } IGraphics curForeignObjGraphics = curForeignObj as IGraphics; if (curForeignObjGraphics != null) { if (Geometry.GetBoundaryIntercept(curForeignObjGraphics.CreateRegion(0.0f), curLocalPort.Location, ptStart, out ptBoundary)) { curLocalPort.Location = ptBoundary; } } } } } } }