PWBasicsImpl.mesa,
Created by Bertrand Serlet
Last Edited by Bertrand Serlet, May 2, 1985 1:47:03 am PDT
Last Edited by: Monier, February 7, 1985 4:53:57 pm PST
All the data structures common to low-level stretch algorithms, and some commonly used ops on those data types.
Also contains all the stuff for error messages, warnings, bugs ...
DIRECTORY
CD,
CDBasics,
CDCells,
CDDirectory USING [Fetch, Include, Name],
CDOrient USING [MapRect],
CDProperties,
CDX USING [IncludeOb],
Convert USING [RopeFromInt],
PWBasics,
Rope USING [Cat, ROPE],
TerminalIO USING [WriteRope];
PWBasicsImpl: CEDAR PROGRAM
IMPORTS CD, CDBasics, CDCells, CDDirectory, CDOrient, CDProperties, CDX, Convert, Rope, TerminalIO
EXPORTS PWBasics =
BEGIN
OPEN PWBasics;
-- Utilities
ROPE: PUBLIC TYPE = Rope.ROPE;
Output: PUBLIC PROC [r1, r2, r3, r4, r5, r6: ROPENIL] = {
TerminalIO.WriteRope[Rope.Cat[r1, r2, r3, r4, r5, r6]]
};
RopeFromCell: PUBLIC PROC [cell: CD.ObPtr] RETURNS [rope: ROPE] = {
rope ← Rope.Cat["Cell ", NameFromObj[cell]]
};
RopeFromPos: PUBLIC PROC [pos: CD.Position] RETURNS [rope: ROPE] = {
ropeRope.Cat["[", Convert.RopeFromInt[pos.x], ", ", Convert.RopeFromInt[pos.y], "]"];
};
RopeFromRect: PUBLIC PROC [rect: CD.Rect] RETURNS [rope: ROPE] = {
rope ← Rope.Cat[
"[", Convert.RopeFromInt[rect.x1], ", ", Convert.RopeFromInt[rect.y1], ", ",
Rope.Cat[Convert.RopeFromInt[rect.x2], ", ", Convert.RopeFromInt[rect.y2], "]"]]
};
-- Converting from PWLow to PW
If name=NIL or if name is not found, returns NIL
ObjFromName: PUBLIC PROC [design: CD.Design, name: ROPE] RETURNS [object: CD.ObPtr ← NIL] =
BEGIN
found: BOOL;
IF name=NIL THEN RETURN;
[found: found, object: object] ← CDDirectory.Fetch[design, name];
IF ~found THEN Output["Object '", name, "' does not exist in directory. NIL object used instead.\n"];
END;
Gets the name from the object.
If object=NIL returns NIL
NameFromObj: PUBLIC PROC [object: CD.ObPtr] RETURNS [name: ROPENIL] =
BEGIN
IF object=NIL THEN RETURN;
name ← CDDirectory.Name[object];
END;
-- Geometric primitives
The following primitive allow the use of the interestRectangle coordinates only
GetLocation: PUBLIC PROC [appl: CD.ApplicationPtr, obj: CD.ObPtr] RETURNS [location: CD.Position] = {
locationCDBasics.SubPoints[
CDBasics.BaseOfRect[
CDOrient.MapRect[CD.InterestRect[appl.ob], appl.ob.size, appl.orientation, appl.location]],
CDBasics.BaseOfRect[CD.InterestRect[obj]]]
};
Gives the size of the interest Rect
GetISize: PUBLIC PROC [obj: CD.ObPtr] RETURNS [size: CD.Position] = {
size ← CDBasics.SizeOfRect[CD.InterestRect[obj]]
};
SizeX: PUBLIC IntFromRectProc = {sizerect.x2-rect.x1};
SizeY: PUBLIC IntFromRectProc = {size rect.y2-rect.y1};
-- Creation of a new cell
-- Inclusion of an application of a subCell in a cell
IncludeApplication: PUBLIC PROC [cell, subcell: CD.ObPtr, location: CD.Position ← [0, 0], orientation: CD.Orientation ← CD.combined] RETURNS [newAppl: CD.ApplicationPtr] = {
newAppl ← CDX.IncludeOb[
design: NIL, cell: cell, ob: subcell, position: location, orientation: orientation,
cellCSystem: interrestCoords, obCSystem: interrestCoords, mode: dontPropagate
].newApp
};
-- When all inclusions have been made, this proc should be called. Assumptions are that object is a cell and that Size and InterestRect are meaningless and need being recomputed.
If design is given, the cell is added to to directory, if not previously done.
If name is given, it is the preferred name of the new cell.
RepositionCell: PUBLIC PROC [design: CD.Design, cell: CD.ObPtr, name: ROPENIL] =
BEGIN
[] ← CDCells.RepositionCell[cell, NIL]; -- NIL because cell is not yet included in design
IF design#NIL THEN Include[design, cell, name];
END;
As CDDirectory.Include, but may include the same cell twice in the same design
Include: PUBLIC PROC [design: CD.Design, object: CD.ObPtr, name: ROPENIL] = {
IF CDProperties.GetPropFromObject[from: object, prop: $Owner]#design THEN
IF ~CDDirectory.Include[design, object, name] THEN ERROR;
};
Adds the properties of obj which are copiable to the ones of newObj,
AppendProps: PUBLIC PROC [newObj, obj: CD.ObPtr] = {
FOR l: CDProperties.Properties ← obj.properties, l.rest WHILE l#NIL DO
IF ISTYPE[l.first.key, ATOM] AND CDProperties.GetPropFromObject[newObj, l.first.key]=NIL THEN {
p: CDProperties.PropertyProcs = CDProperties.FetchProcs[l.first.key];
IF p#NIL AND p.makeCopy#NIL THEN
CDProperties.PutPropOnObject[
newObj, l.first.key, p.makeCopy[l.first.key, l.first.val]];
};
ENDLOOP;
};
END.