In this post, we modify the TestDelete project such that if a component is moved, any input and output wires are stretched to the new component postion.
Make a copy of the TestDelete project directory in the EngineeringTools solution. Rename the directory and .csproj file to TestStretchWires.
Modify the Mouse Move event handler to change the end points of any wires associated with a component move:
Private void schematicCanvas_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown == true)
{
int x = e.X;
int y = e.Y;
SnapToGrid(ref x, ref y);
if (!lineDrawing)
{
if (tempComp != null)
{
tempComp.Loc = new Point(x
- offset.X, y - offset.Y);
// Stretch output wires
if (tempComp.wires[0] != null)
tempComp.wires[0].Pt1 = new Point(tempComp.Loc.X + tempComp.Width, tempComp.Loc.Y + 30);
// Stretch input wires
foreach(Comp comp in ckt.comps)
{
foreach(Wire wire in comp.wires)
{
if(wire.Cout == tempComp)
comp.wires[0].Pt2 = new Point(tempComp.Loc.X, tempComp.Loc.Y + 30);
}
}
}
}
schematicCanvas.Invalidate(); // Refresh the
drawing canvas pictureBox
}
}
Run the program and confirm that if a component is moved, the wire end points connected to the component are stretched to the new component location. The source code for this post is available on
GitHub.
No comments:
Post a Comment