CDSplitWireCommands.mesa (part of Chipndale)
Copyright © 1984 by Xerox Corporation. All rights reserved.
Last Edited by: Monier, July 24, 1984 11:31:03 am PDT
DIRECTORY
CD,
CDApplications,
CDBasics,
CDRects,
CDSequencer,
CDCallSpecific,
CDOps,
CDOrient,
CDProperties,
TerminalIO;
CDSplitWireCommands: CEDAR PROGRAM
IMPORTS CDApplications, CDBasics, CDOps, CDOrient, CDProperties, CDSequencer, TerminalIO, CDRects =
BEGIN
SplitApplication: PROC [design: CD.Design, aPtr: CD.ApplicationPtr, from, to: CD.DesignPosition] =
BEGIN
cutPos, oldRectPos, oldSize: CD.DesignPosition;
oldRect: CD.DesignRect; -- the bounding box
L1, L2, W1, W2: CD.DesignNumber;
wireLeft, wireRight: CD.ObPtr;
vertical, intersect: BOOL;
NearlyRoundToLambda: PROC[x: CD.DesignNumber] RETURNS[r: CD.DesignNumber] =
BEGIN
r ← (x/CD.lambda)*CD.lambda;
IF x=0 THEN r ← CD.lambda;
END;
FindCut: PROC[from, to: CD.DesignPosition, oldRect: CD.DesignRect, vertical: BOOL] RETURNS[cutPos: CD.DesignPosition, intersect: BOOLTRUE] =
BEGIN
For now OK, but check if there is any risk to make anything smaller than one lambda
inter, ctr: CD.DesignPosition; -- the intersection of the two lines, if any, and the center of the wire
dx, dy: CD.DesignNumber;
cursorBox: CD.DesignRect;
cursorBox ← CDBasics.ToRect[from, to];
dx ← to.x-from.x; dy ← to.y-from.y;
ctr ← CDBasics.Center[oldRect];
Test if vector parallel to wire
IF vertical AND (dx=0) OR (NOT vertical) AND (dy=0) THEN RETURN[[0,0], FALSE];
Now we can divide and find the intersection of lines (not yet segments)
inter ← IF vertical
THEN [ctr.x, from.y+(dy*(ctr.x-from.x)/dx)]
ELSE [dx*(ctr.y-from.y)/dy+from.x, ctr.y];
Monier-Sindhu theorem: if inter is in cursorBox and in oldRect, then it is the intersection of segments
IF NOT (CDBasics.InsidePos[inter, cursorBox] AND CDBasics.InsidePos[inter, oldRect]) THEN RETURN[[0,0], FALSE];
cutPos ← IF vertical THEN [oldRect.x1, NearlyRoundToLambda[inter.y]] ELSE [NearlyRoundToLambda[inter.x], oldRect.y1];
END;
oldRect ← CDApplications.ARectI[aPtr];
oldRectPos ← CDBasics.BaseOfRect[oldRect];
oldSize ← CDBasics.SizeOfRect[oldRect];
vertical ← oldSize.y > oldSize.x;
[cutPos, intersect] ← FindCut[from, to, oldRect, vertical];
IF NOT intersect THEN RETURN;
IF vertical THEN {
L1 ← cutPos.y - oldRect.y1;
L2 ← oldSize.y - L1;
W1 ← W2 ← oldSize.x;
}
ELSE {
L1 ← L2 ← oldSize.y;
W1 ← cutPos.x - oldRect.x1;
W2 ← oldSize.x - W1;
};
wireLeft ← CDRects.CreateRect[CDOrient.OrientedSize[[W1, L1], aPtr.orientation], aPtr.ob.level];
wireRight ← CDRects.CreateRect[CDOrient.OrientedSize[[W2, L2], aPtr.orientation], aPtr.ob.level];
CDOps.IncludeApplication[design, CDApplications.NewApplicationI[wireLeft, oldRectPos, aPtr.orientation, TRUE, CDProperties.CopyProps[aPtr.properties]], FALSE];
CDOps.IncludeApplication[design, CDApplications.NewApplicationI[wireRight, cutPos, aPtr.orientation, TRUE, CDProperties.CopyProps[aPtr.properties]], FALSE];
CDOps.RemoveApplication[design, aPtr];
END;
DoAllSplits: PROC [design: CD.Design, from, to: CD.DesignPosition, pointed: BOOLFALSE] =
BEGIN
The mouse track defines the cut vector. Let's define the "spine" of a wire as the centerline, roughly in the middle (lambda) and following the visible length, i.e. the longer edge, not the CD length. Then we cut the wire at the position where the spine meets the cut vector. The cut always reduces the visible length of the wire. (Pff, not easy to describe without drawing!)
A vertical wire freshly drawn has even (0) orientation.
FOR list: CD.ApplicationList ← CDOps.AppList[design], list.rest WHILE list#NIL DO
IF list.first.selected AND list.first.ob.p.wireTyped THEN SplitApplication[design, list.first, from, to];
ENDLOOP;
END;
SplitWireCommandS: PROC [comm: CDSequencer.Command] =
BEGIN
TerminalIO.WriteRope["Split selected\n"];
DoAllSplits[design: comm.design, from: comm.sPos, to: comm.pos, pointed: FALSE]
END;
CDSequencer.ImplementCommand[$SplitWireS, SplitWireCommandS];
END.