GGObjectsImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last edited by Bier on March 10, 1987 7:23:43 pm PST
Contents: The procedural interface to the Gargoyle object modeler.
Stone, August 5, 1985 4:13:18 pm PDT
Pier, March 16, 1987 6:40:41 pm PST
Kurlander August 28, 1986 6:15:29 pm PDT
DIRECTORY
GGAlign, GGBasicTypes, GGBoundBox, GGInterfaceTypes, GGModelTypes, GGMultiGravity, GGObjects, GGOutline, GGSceneType, GGSegment, GGSegmentTypes, GGSelect, GGSequence, GGTraj, GGUtility, GList, Imager, ImagerPath, List, Rope;
GGObjectsImpl: CEDAR PROGRAM
IMPORTS GGAlign, GGBoundBox, GGMultiGravity, GGObjects, GGOutline, GGSegment, GGSelect, GGSequence, GGTraj, GGUtility, GList, Imager, List
EXPORTS GGObjects, GGModelTypes = BEGIN
BoundBox: TYPE = GGModelTypes.BoundBox;
BoundBoxGenerator: TYPE = REF BoundBoxGeneratorObj;
BoundBoxGeneratorObj: TYPE = GGModelTypes.BoundBoxGeneratorObj;
CurveType: TYPE = {line, bezier, conic};
EntityGenerator: TYPE = REF EntityGeneratorObj;
EntityGeneratorObj: TYPE = GGModelTypes.EntityGeneratorObj;
Joint: TYPE = REF JointObj;
JointGenerator: TYPE = REF JointGeneratorObj;
JointGeneratorObj: TYPE = GGModelTypes.JointGeneratorObj;
JointObj: TYPE = GGSegmentTypes.JointObj;
Outline: TYPE = REF OutlineObj;
OutlineObj: TYPE = GGModelTypes.OutlineObj;
OutlineDescriptor: TYPE = GGModelTypes.OutlineDescriptor;
OutlineGenerator: TYPE = REF OutlineGeneratorObj;
OutlineGeneratorObj: TYPE = GGModelTypes.OutlineGeneratorObj;
Point: TYPE = GGBasicTypes.Point;
Segment: TYPE = REF SegmentObj;
SegmentGenerator: TYPE = GGModelTypes.SegmentGenerator;
SegmentObj: TYPE = GGSegmentTypes.SegmentObj;
Sequence: TYPE = REF SequenceObj;
SequenceGenerator: TYPE = GGModelTypes.SequenceGenerator;
SequenceObj: TYPE = GGModelTypes.SequenceObj;
Slice: TYPE = GGModelTypes.Slice;
SliceDescriptor: TYPE = GGModelTypes.SliceDescriptor;
SliceGenerator: TYPE = REF SliceGeneratorObj;
SliceGeneratorObj: TYPE = GGModelTypes.SliceGeneratorObj;
Traj: TYPE = REF TrajObj;
TrajEnd: TYPE = GGModelTypes.TrajEnd; -- {lo, hi};
TrajGenerator: TYPE = REF TrajGeneratorObj;
TrajGeneratorObj: TYPE = GGModelTypes.TrajGeneratorObj;
TrajObj: TYPE = GGModelTypes.TrajObj;
Vector: TYPE = GGBasicTypes.Vector;
GargoyleData: TYPE = GGInterfaceTypes.GargoyleData;
The scene object has a list of entities, a "finger" REF (ptr) to the end of the list for quick appends, and a BOOL which is TRUE when ptr in fact points to the end. ptr MUST BE invalidated by setting ptrValid ← FALSE whenever a remove or delete is done from the entities. Any use of ptr must check ptrValid and recalculate its value if it is invalid. The only place that happens in here is in AppendEntity.
entities are kept in back to front order so that the list can be painted with a single traversal.
SceneRef: TYPE = REF SceneObj;
SceneObj: PUBLIC TYPE = GGSceneType.SceneObj;
NotYetImplemented: PUBLIC SIGNAL = CODE;
Problem: PUBLIC SIGNAL [msg: Rope.ROPE] = CODE;
fillColor: PUBLIC Imager.Color ← Imager.MakeGray[0.5];
Building and Destroying Clusters
MakeCluster: PUBLIC PROC [entities: LIST OF REF ANY] RETURNS [newCluster: Slice];
BreakCluster: PUBLIC PROC [oldCluster: Slice] RETURNS [entities: LIST OF REF ANY];
Creating, Modifying Scenes
The list scene.entities is kept in back to front order. Hence, newly added objects are usually added to the end of the list. This list may be mutated freely. Copies of it are made when needed.
CreateScene: PUBLIC PROC [] RETURNS [scene: SceneRef] = {
scene ← NEW[SceneObj ← [prioritiesValid: FALSE] ];
};
AddOutline: PUBLIC PROC [scene: SceneRef, outline: Outline, priority: INT ← -1] = {
Add the given outline to the scene with the given priority (the lower the priority number, the closer the outline is to the front. If priority is -1, the outline will be the rear-most entity. If an entity with the given priority already exists, all priority numbers greater than or equal to it will be increased by one.
IF priority = -1 THEN AppendEntity[scene, outline]
ELSE IF priority = 0 THEN {
scene.ptrValid ← FALSE;
scene.entities ← CONS[outline, scene.entities];
}
ELSE SIGNAL Problem["Not yet implemented."];
scene.prioritiesValid ← FALSE;
};
AddSlice: PUBLIC PROC [scene: SceneRef, slice: Slice, priority: INT ← -1] = {
Add the given slice to the scene with the given priority (the higher the priority number, the closer the outline is to the front of the scene). If priority is -1, the slice will be the front-most entity. If the priority given is too high, we proceed as if priority = -1.
IF priority = -1 THEN AppendEntity[scene, slice]
ELSE IF priority = 0 THEN {
scene.ptrValid ← FALSE;
scene.entities ← CONS[slice, scene.entities];
}
ELSE SIGNAL Problem["Not yet implemented."];
scene.prioritiesValid ← FALSE;
};
AddEntities: PUBLIC PROC [scene: SceneRef, entities: LIST OF REF ANY, priority: INT ← -1] = {
Adds the entities, assumed to be in back to front order, to the scene. IF priority = -1, they become the frontmost entities. Otherwise, the specified priority becomes the priority of the first entity in the list, if possible. If the priority given is too high, we proceed as if priority = -1.
IF priority = -1 THEN {
FOR list: LIST OF REF ANY ← entities, list.rest UNTIL list = NIL DO
AppendEntity[scene, list.first];
ENDLOOP;
}
ELSE SIGNAL Problem["Not yet implemented."];
scene.prioritiesValid ← FALSE;
};
AddEntity: PUBLIC PROC [scene: SceneRef, entity: REF ANY, priority: INT] = {
Adds the entity to the scene. If priority = 0, it becomes the rearmost entity. IF priority = -1, it becomes the frontmost entity. If the priority given is too high, we proceed as if priority = -1.
IF priority = -1 THEN AppendEntity[scene, entity]
ELSE IF priority = 0 THEN {
scene.ptrValid ← FALSE;
scene.entities ← CONS[entity, scene.entities];
}
ELSE SIGNAL Problem["Not yet implemented."];
scene.prioritiesValid ← FALSE;
};
AppendEntity: PROC [scene: SceneRef, entity: REF ANY] = {
IF NOT scene.ptrValid THEN { -- restore ptr
IF scene.entities=NIL THEN scene.ptr ← NIL ELSE
FOR list: LIST OF REF ANY ← scene.entities, list.rest UNTIL list=NIL DO
scene.ptr ← list;
ENDLOOP;
scene.ptrValid ← TRUE;
};
[scene.entities, scene.ptr] ← GGUtility.AddEntity[entity, scene.entities, scene.ptr];
};
EntityPriority: PUBLIC PROC [scene: SceneRef, entity: REF ANY] RETURNS [priority: INT] = {
IF NOT scene.prioritiesValid THEN UpdatePriorities[scene];
WITH entity SELECT FROM
outline: Outline => priority ← outline.priority;
slice: Slice => priority ← slice.priority;
ENDCASE => ERROR;
};
UpdatePriorities: PROC [scene: SceneRef] = {
entityGen: GGModelTypes.EntityGenerator;
index: NAT ← 0;
entityGen ← TopLevelEntitiesInScene[scene];
FOR entity: REF ANY ← GGObjects.NextEntity[entityGen], GGObjects.NextEntity[entityGen] UNTIL entity = NIL DO
WITH entity SELECT FROM
slice: Slice => slice.priority ← index;
outline: Outline => outline.priority ← index;
ENDCASE => ERROR;
index ← index + 1;
ENDLOOP;
scene.prioritiesValid ← TRUE;
};
DeleteEntity: PUBLIC PROC [scene: SceneRef, entity: REF ANY] = {
Removes the named entity from the scene. If the entity is not on the list, no action is taken.
scene.ptrValid ← FALSE;
scene.entities ← List.DRemove[entity, scene.entities];
scene.prioritiesValid ← FALSE;
};
DeleteOutline: PUBLIC PROC [scene: SceneRef, outline: Outline] = {
DeleteEntity[scene, outline];
scene.prioritiesValid ← FALSE;
};
DeleteSequence: PUBLIC PROC [seq: Sequence, scene: SceneRef] RETURNS [oldOutline: Outline, newOutlines: LIST OF Outline] = {
Takes the trajectory of which seq is a part. What is the role of this trajectory?
If role = hole, then create a new outline (and new trajectories), identical to seq.traj.outline, but without the hole. The index corresponding to this outline will be 0. Make separate outlines corresponding to those parts of the hole which were not deleted. The index for each of these outlines will be the segment number, in the original hole traj, of segment 0 in the new outline. The old outline (and all of its parts) is now obsolete.
If role = fence, then create new outlines and new trajectories for all of the parts of seq.traj.outline which remain. The index for each of these outlines will be the segment number, in the original fence traj, of segment 0 in the new outline. The old outline (and all of its parts) is now obsolete.
If role = open, then create new outlines and new trajectories for all of the parts of seq.traj which remain. The index for each of these outlines will be the segment number, in the original fence traj, of segment 0 in the new outline. The old outline is obsolete.
oldOutline ← GGOutline.OutlineOfTraj[seq.traj];
SELECT seq.traj.role FROM
hole => {
smallerOutline: Outline;
The parts of the hole become top level parts of the scene.
newOutlines ← OutlinesOfTrajMinusSequence[seq];
The rest of the outline is replaced by a single new outline.
smallerOutline ← OutlineMinusHole[oldOutline, seq.traj];
AddOutline[scene, smallerOutline, -1];
AddOutlinesToScene[newOutlines, scene]; -- put the deflated holes on top.
newOutlines ← CONS[smallerOutline, newOutlines];
};
open => {
newOutlines ← OutlinesOfTrajMinusSequence[seq];
AddOutlinesToScene[newOutlines, scene];
};
fence => {
fenceParts, freedHoles: LIST OF Outline;
fenceParts ← OutlinesOfTrajMinusSequence[seq];
AddOutlinesToScene[fenceParts, scene];
freedHoles ← OutlinesFromOutlineExcept[oldOutline, seq.traj];
AddOutlinesToScene[freedHoles, scene];
newOutlines ← AppendOutlines[fenceParts, freedHoles];
};
ENDCASE => ERROR;
DeleteOutline[scene, oldOutline];
};
AddOutlinesToScene: PROC [outlines: LIST OF Outline, scene: SceneRef] = {
FOR list: LIST OF Outline ← outlines, list.rest UNTIL list = NIL DO
AddOutline[scene, list.first, -1];
ENDLOOP;
};
OutlinesOfTrajMinusSequence: PROC [seq: Sequence] RETURNS [newOutlines: LIST OF Outline] = {
diff, wholeTraj: Sequence;
IF GGSequence.IsComplete[seq] THEN RETURN[NIL];
Parts of the trajectory are in the sequence. Take the segments which remain, and all the joints that they touch.
wholeTraj ← GGSequence.CreateComplete[seq.traj];
IF NOT GGSequence.IsEmpty[seq] AND seq.traj.segCount=1 THEN GGSegment.OpenUpSegment[GGTraj.FetchSegment[seq.traj, 0]]; -- cyclic segments must become acyclic
diff ← GGSequence.Difference[wholeTraj, seq];
[newOutlines] ← GroupPieces[diff];
};
GroupPieces: PROC [seq: Sequence] RETURNS [newOutlines: LIST OF Outline] = {
seqGen: SequenceGenerator;
newTraj: Traj;
newOutline, oldOutline: Outline;
runCount: NAT;
joint: Joint;
newOutlines ← NIL;
oldOutline ← GGOutline.OutlineOfTraj[seq.traj];
[seqGen, runCount] ← GGSequence.RunsInSequence[seq];
FOR run: Sequence ← GGSequence.NextSequence[seqGen], GGSequence.NextSequence[seqGen] UNTIL run = NIL DO
IF run.segCount=0 THEN LOOP; -- special case needed by BS command.
[newTraj] ← GGTraj.CopyTrajFromRun[run];
Make sure the end joints of the run are not active selected. They can be normal or hot selected. This is important for the delete operation.
joint ← GGTraj.FetchJoint[newTraj, 0];
joint.TselectedInFull.active ← FALSE;
joint ← GGTraj.FetchJoint[newTraj, GGTraj.HiJoint[newTraj]];
joint.TselectedInFull.active ← FALSE;
newTraj.role ← open;
newOutline ← GGOutline.CreateOutline[newTraj, oldOutline.fillColor];
newOutlines ← CONS[newOutline, newOutlines];
ENDLOOP;
};
OutlinesFromOutlineExcept: PROC [outline: Outline, except: Traj] RETURNS [newOutlines: LIST OF Outline] = {
trajGen: TrajGenerator;
newTraj: Traj;
newOutline: Outline;
ptr: LIST OF Outline;
trajGen ← GGOutline.TrajsInOutline[outline];
[newOutlines, ptr] ← StartOutlineList[];
FOR traj: Traj ← GGObjects.NextTraj[trajGen], GGObjects.NextTraj[trajGen] UNTIL traj = NIL DO
IF traj = except THEN LOOP;
newTraj ← GGTraj.CopyTraj[traj];
newOutline ← GGOutline.CreateOutline[newTraj, outline.fillColor];
[newOutlines, ptr] ← AddOutlineToList[newOutline, newOutlines, ptr];
ENDLOOP;
};
OutlineMinusHole: PROC [outline: Outline, except: Traj] RETURNS [newOutline: Outline] = {
holeGen: TrajGenerator;
newTraj, fence: Traj;
fence ← GGOutline.FenceOfOutline[outline];
newTraj ← GGTraj.CopyTraj[fence];
newOutline ← GGOutline.CreateOutline[newTraj, outline.fillColor];
holeGen ← GGOutline.HolesOfOutline[outline];
FOR hole: Traj ← GGObjects.NextTraj[holeGen], GGObjects.NextTraj[holeGen] UNTIL hole = NIL DO
IF hole = except THEN LOOP;
newTraj ← GGTraj.CopyTraj[hole];
newOutline ← GGOutline.AddHole[newOutline, newTraj];
ENDLOOP;
};
AppendOutlines: PROC [list1, list2: LIST OF Outline] RETURNS [result: LIST OF Outline] = {
Non-destructive (copies the first list).
pos: LIST OF Outline;
newCell: LIST OF Outline;
IF list1 = NIL THEN RETURN[list2];
result ← CONS[list1.first, NIL];
pos ← result;
FOR l: LIST OF Outline ← list1.rest, l.rest UNTIL l = NIL DO
newCell ← CONS[l.first, NIL];
pos.rest ← newCell;
pos ← newCell;
ENDLOOP;
pos.rest ← list2;
};
StartOutlineList: PROC [] RETURNS [entityList, ptr: LIST OF Outline] = {
ptr ← entityList ← NIL;
};
AddOutlineToList: PROC [entity: Outline, entityList, ptr: LIST OF Outline] RETURNS [newList, newPtr: LIST OF Outline] = {
IF ptr = NIL THEN {
IF NOT entityList = NIL THEN ERROR;
newPtr ← newList ← CONS[entity, NIL];
RETURN;
}
ELSE {
newList ← entityList;
ptr.rest ← CONS[entity, NIL];
newPtr ← ptr.rest;
};
};
undeleteSize: INT ← 20; -- temporarily hardwired size of undelete stack
PushScene: PUBLIC PROC [scene: SceneRef] = {
Makes a copy of the current scene list, and pushes it on a stack. For use in Undelete.
CopyList: PROC [list: LIST OF REF ANY] RETURNS [copy: LIST OF REF ANY] = {
entityList, ptr: LIST OF REF ANY;
[entityList, ptr] ← GGUtility.StartList[];
FOR entity: LIST OF REF ANY ← list, entity.rest UNTIL entity=NIL DO
[entityList, ptr] ← GGUtility.AddEntity[entity.first, entityList, ptr];
ENDLOOP;
copy ← entityList;
};
tList: LIST OF LIST OF REF ANY;
scene.oldEntities ← CONS[
CopyList[scene.entities],
scene.oldEntities];
tList ← scene.oldEntities;
FOR index: INT IN [0..undeleteSize) DO IF tList#NIL THEN tList ← tList.rest; ENDLOOP;
IF tList#NIL THEN tList.rest ← NIL; -- truncate the undelete stack
};
EmptySceneStack: PUBLIC PROC [scene: SceneRef] RETURNS [BOOL] = {
RETURN[scene.oldEntities=NIL OR scene.oldEntities.first=NIL];
};
PopScene: PUBLIC PROC [scene: SceneRef] = {
Lets scene be the most recently pushed scene, that has not yet been popped.
IF EmptySceneStack[scene] THEN ERROR;
scene.entities ← scene.oldEntities.first;
scene.ptrValid ← FALSE;
scene.oldEntities ← scene.oldEntities.rest;
};
MergeScenes: PUBLIC PROC [back: SceneRef, front: SceneRef] RETURNS [combined: SceneRef] = {
combined ← NEW[SceneObj ← [prioritiesValid: FALSE]];
combined.entities ← NARROW[GList.Append[back.entities, front.entities]];
combined.selected.normal ← NARROW[GList.Append[back.selected.normal, front.selected.normal]];
combined.selected.hot ← NARROW[GList.Append[back.selected.hot, front.selected.hot]];
combined.selected.active ← NARROW[GList.Append[back.selected.active, front.selected.active]];
};
UpOne: PUBLIC PROC [scene: SceneRef, entity: REF ANY] = {
Moves the named entity one step closer to the front in the priority order.
ExchangeWithNextEntity: PROC [scene: SceneRef, entity: REF ANY] = {
previous, next: LIST OF REF ANYNIL;
FOR list: LIST OF REF ANY ← scene.entities, list.rest UNTIL list = NIL DO
IF list.first=entity THEN { -- exchange this entity with its next neighbor
next ← list.rest;
IF next=NIL THEN RETURN; -- entity already at end (i.e. top) of list
list.rest ← next.rest; next.rest ← list;
IF previous#NIL THEN previous.rest ← next ELSE scene.entities ← next;
}
ELSE previous ← list;
ENDLOOP;
};
trueEntity: REF ANY;
WITH entity SELECT FROM
slice: Slice => trueEntity ← slice;
outline: Outline => trueEntity ← outline;
traj: Traj => trueEntity ← GGOutline.OutlineOfTraj[traj];
seq: Sequence => trueEntity ← GGOutline.OutlineOfTraj[seq.traj];
ENDCASE => ERROR;
ExchangeWithNextEntity[scene, trueEntity];
};
DownOne: PUBLIC PROC [scene: SceneRef, entity: REF ANY] = {
Moves the named entity one step closer to the back in the priority order.
ExchangeWithPreviousEntity: PROC [scene: SceneRef, entity: REF ANY] = {
preprev, previous: LIST OF REF ANYNIL;
FOR list: LIST OF REF ANY ← scene.entities, list.rest UNTIL list=NIL DO
IF list.first=entity THEN { -- exchange this entity with its previous neighbor
SELECT TRUE FROM
preprev=NIL AND previous=NIL => RETURN; -- entity already on bottom
preprev=NIL AND previous#NIL => { -- special case. Second from bottom
previous.rest ← list.rest; list.rest ← previous; scene.entities ← list; RETURN;
};
preprev#NIL AND previous=NIL => ERROR; -- Assert: can't happen
preprev#NIL AND previous#NIL => { -- usual case. Exchange list elements
previous.rest ← list.rest; list.rest ← previous; preprev.rest ← list; RETURN;
};
ENDCASE => ERROR; -- Assert: can't happen
}
ELSE { preprev ← previous; previous ← list; };
ENDLOOP;
};
trueEntity: REF ANY;
WITH entity SELECT FROM
slice: Slice => trueEntity ← slice;
outline: Outline => trueEntity ← outline;
traj: Traj => trueEntity ← GGOutline.OutlineOfTraj[traj];
seq: Sequence => trueEntity ← GGOutline.OutlineOfTraj[seq.traj];
ENDCASE => ERROR;
ExchangeWithPreviousEntity[scene, trueEntity];
};
Browsing the Scene Hierarchy -- Generators
TopLevelEntitiesInScene: PUBLIC PROC [scene: SceneRef] RETURNS [entityGenerator: EntityGenerator] = {
Generates all of the outlines and slices in the scene.
list: LIST OF REF ANY ← List.Reverse[scene.entities]; -- KAP October 22, 1986
entityGenerator ← NEW[EntityGeneratorObj ← [
list: scene.entities,
countValid: FALSE,
count: 0
]];
};
NextEntity: PUBLIC PROC [g: EntityGenerator] RETURNS [next: REF ANY] = {
IF g.list = NIL THEN RETURN[NIL]
ELSE {
next ← g.list.first;
g.list ← g.list.rest;
};
};
EntityCount: PUBLIC PROC [g: EntityGenerator] RETURNS [count: NAT] = {
IF g.countValid THEN RETURN[g.count];
count ← 0;
FOR list: LIST OF REF ANY ← g.list, list.rest UNTIL list = NIL DO
count ← count + 1;
ENDLOOP;
};
IsTopLevel: PUBLIC PROC [entity: REF ANY] RETURNS [BOOL] = {
Returns the unique fence trajectory of outline.
WITH entity SELECT FROM
slice: Slice => RETURN[slice.parent = NIL];
outline: Outline => RETURN[outline.parent = NIL OR outline.parent.parent = NIL];
traj: Traj => RETURN[traj.parent.parent = NIL OR traj.parent.parent.parent = NIL];
seq: Sequence => RETURN[IsTopLevel[seq.traj.parent]];
ENDCASE => ERROR;
};
TrajsInScene: PUBLIC PROC [scene: SceneRef] RETURNS [trajGen: TrajGenerator] = {
Generates all of the trajectories in the scene, wherever they occur.
list: LIST OF Traj ← ListTrajsInScene[scene];
trajGen ← NEW[TrajGeneratorObj ← [
list: list
]];
};
OutlinesInScene: PUBLIC PROC [scene: SceneRef] RETURNS [outlineGen: OutlineGenerator] = {
Generates all of the outlines in the scene, wherever they occur.
list: LIST OF Outline ← ListOutlinesInScene[scene];
outlineGen ← NEW[OutlineGeneratorObj ← [
list: list
]];
};
NextTraj: PUBLIC PROC [g: TrajGenerator] RETURNS [next: Traj] = {
IF g.list = NIL THEN RETURN[NIL]
ELSE {
next ← g.list.first;
g.list ← g.list.rest;
};
};
NextOutline: PUBLIC PROC [g: OutlineGenerator] RETURNS [next: Outline] = {
IF g.list = NIL THEN RETURN[NIL]
ELSE {
next ← g.list.first;
g.list ← g.list.rest;
};
};
SlicesInScene: PUBLIC PROC [scene: SceneRef] RETURNS [sliceGen: SliceGenerator] = {
list: LIST OF Slice ← ListSlicesInScene[scene];
sliceGen ← NEW[SliceGeneratorObj ← [
list: list
]];
};
NextSlice: PUBLIC PROC [g: SliceGenerator] RETURNS [next: Slice] = {
IF g.list = NIL THEN RETURN[NIL]
ELSE {
next ← g.list.first;
g.list ← g.list.rest;
};
};
Bounding Boxes
BoundBoxesInScene: PUBLIC PROC [scene: SceneRef] RETURNS [bBoxGen: BoundBoxGenerator] = {
Generates all of the boundBoxes in the scene, whereever they occur.
list: LIST OF BoundBox ← ListBoxesInScene[scene];
bBoxGen ← NEW[BoundBoxGeneratorObj ← [
list: list
]];
};
TightBoxesInScene: PUBLIC PROC [scene: SceneRef] RETURNS [bBoxGen: BoundBoxGenerator] = {
Generates all of the boundBoxes in the scene, whereever they occur.
list: LIST OF BoundBox ← ListTightBoxesInScene[scene];
bBoxGen ← NEW[BoundBoxGeneratorObj ← [
list: list
]];
};
NextBox: PUBLIC PROC [g: BoundBoxGenerator] RETURNS [next: BoundBox] = {
IF g.list = NIL THEN RETURN[NIL]
ELSE {
next ← g.list.first;
g.list ← g.list.rest;
};
};
ListBoxesInScene: PROC [scene: SceneRef] RETURNS [allBoxes: LIST OF BoundBox] = {
thisBox: BoundBox;
allBoxes ← NIL;
FOR entities: LIST OF REF ANY ← scene.entities, entities.rest UNTIL entities = NIL DO
WITH entities.first SELECT FROM
slice: Slice => {
thisBox ← slice.class.getBoundBox[slice, NIL];
allBoxes ← CONS[thisBox, allBoxes];
};
outline: Outline => {
thisBox ← outline.class.getBoundBox[outline, NIL];
allBoxes ← CONS[thisBox, allBoxes];
};
ENDCASE => ERROR;
ENDLOOP;
};
ListTightBoxesInScene: PROC [scene: SceneRef] RETURNS [allBoxes: LIST OF BoundBox] = {
thisBox: BoundBox;
allBoxes ← NIL;
FOR entities: LIST OF REF ANY ← scene.entities, entities.rest UNTIL entities = NIL DO
WITH entities.first SELECT FROM
slice: Slice => {
thisBox ← slice.class.getTightBox[slice, NIL];
allBoxes ← CONS[thisBox, allBoxes];
};
outline: Outline => {
thisBox ← outline.class.getTightBox[outline, NIL];
allBoxes ← CONS[thisBox, allBoxes];
};
ENDCASE => ERROR;
ENDLOOP;
};
BoundBoxOfScene: PUBLIC PROC [scene: SceneRef] RETURNS [bBox: BoundBox] = {
box is in local IP coordinates
bbGen: GGModelTypes.BoundBoxGenerator ← BoundBoxesInScene[scene];
bBox ← GGBoundBox.BoundBoxOfBoxes[bbGen.list]; -- cheating to go inside generator
};
TightBoxOfScene: PUBLIC PROC [scene: SceneRef] RETURNS [bBox: BoundBox] = {
box is in local IP coordinates
bbGen: GGModelTypes.BoundBoxGenerator ← TightBoxesInScene[scene];
bBox ← GGBoundBox.BoundBoxOfBoxes[bbGen.list]; -- cheating to go inside generator
};
Utility Routines
AppendTrajs: PUBLIC PROC [l1, l2: LIST OF Traj] RETURNS [result: LIST OF Traj] = {
Destructive append.
z: LIST OF Traj ← l1;
IF z = NIL THEN RETURN[l2];
UNTIL z.rest = NIL DO z ← z.rest; ENDLOOP;
z.rest ← l2;
RETURN[l1];
};
AppendBoxes: PUBLIC PROC [l1, l2: LIST OF BoundBox] RETURNS [result: LIST OF BoundBox] = {
Destructive append.
z: LIST OF BoundBox ← l1;
IF z = NIL THEN RETURN[l2];
UNTIL z.rest = NIL DO z ← z.rest; ENDLOOP;
z.rest ← l2;
RETURN[l1];
};
ListTrajsInScene: PUBLIC PROC [scene: SceneRef] RETURNS [allTrajs: LIST OF Traj] = {
allTrajs ← NIL;
FOR entities: LIST OF REF ANY ← scene.entities, entities.rest UNTIL entities = NIL DO
WITH entities.first SELECT FROM
slice: Slice => {
};
outline: Outline => {
FOR trajs: LIST OF Traj ← outline.children, trajs.rest UNTIL trajs = NIL DO
allTrajs ← CONS[trajs.first, allTrajs];
ENDLOOP;
};
ENDCASE => ERROR;
ENDLOOP;
};
ListOutlinesInScene: PUBLIC PROC [scene: SceneRef] RETURNS [allOutlines: LIST OF Outline] = {
allOutlines ← NIL;
FOR entities: LIST OF REF ANY ← scene.entities, entities.rest UNTIL entities = NIL DO
WITH entities.first SELECT FROM
slice: Slice => {
};
outline: Outline => {
allOutlines ← CONS[outline, allOutlines];
};
ENDCASE => ERROR;
ENDLOOP;
};
ListSlicesInScene: PUBLIC PROC [scene: SceneRef] RETURNS [allSlices: LIST OF Slice] = {
allSlices ← NIL;
FOR entities: LIST OF REF ANY ← scene.entities, entities.rest UNTIL entities = NIL DO
WITH entities.first SELECT FROM
slice: Slice => {
Doesn't work on Gargoyle slices.
allSlices ← CONS[slice, allSlices];
};
outline: Outline => {};
ENDCASE => ERROR;
ENDLOOP;
};
ListTrajsInOutline: PROC [outline: Outline] RETURNS [trajList: LIST OF Traj] = {
trajList ← outline.children;
};
ListHolesOfOutline: PROC [outline: Outline] RETURNS [trajList: LIST OF Traj] = {
trajList ← outline.children.rest;
};
ListSegmentsInTraj: PROC [traj: Traj] RETURNS [segList: LIST OF Segment] = {
segList ← NIL;
FOR i: NAT DECREASING IN [0..GGTraj.HiSegment[traj]] DO
segList ← CONS[GGTraj.FetchSegment[traj, i], segList];
ENDLOOP;
};
Hit Testing -- Outline-Specific routines. These should go away when Outlines become Slices.
NearestTrajectoryInScene: PUBLIC PROC [scene: SceneRef, worldPt: Point, gargoyleData: GargoyleData] RETURNS [traj: Traj] = {
feature: GGModelTypes.FeatureData;
resultPoint: Point;
sceneObjects: GGInterfaceTypes.TriggerBag;
sceneObjects ← NARROW[gargoyleData.hitTest.sceneBag];
[resultPoint, feature] ← GGMultiGravity.StrictDistance[worldPt, gargoyleData.hitTest.criticalR, GGAlign.emptyObjectBag, sceneObjects, gargoyleData];
RETURN[IF feature=NIL OR feature.type=slice THEN NIL ELSE NARROW[feature.shape, Sequence].traj];
};
Selections
SaveSelections: PUBLIC PROC [scene: SceneRef] = {
scene.savedSelected.normal ← List.Append[scene.selected.normal, NIL];
this is a trick to make a copy of the list quickly. The list will be modified in place later on.
};
RestoreSelections: PUBLIC PROC [scene: SceneRef] = {
normalSelectedList: LIST OF REF ANY ← scene.savedSelected.normal;
GGSelect.DeselectAll[scene, normal]; -- get rid of any transient selections
FOR list: LIST OF REF ANY ← normalSelectedList, list.rest UNTIL list = NIL DO
WITH list.first SELECT FROM
cD: SliceDescriptor => GGSelect.SelectSlice[cD, scene, normal];
oD: OutlineDescriptor => GGSelect.SelectOutline[oD, scene, normal];
ENDCASE => ERROR;
ENDLOOP;
};
GetSelections: PUBLIC PROC [scene: SceneRef, selectClass: GGSegmentTypes.SelectionClass] RETURNS [selected: LIST OF REF ANY] = {
SELECT selectClass FROM
normal => selected ← scene.selected.normal;
hot => selected ← scene.selected.hot;
active => selected ← scene.selected.active;
ENDCASE => ERROR;
};
END.
Pier, December 5, 1985 10:13:59 am PST
changes to: removed camera from definitions
Bier, January 7, 1986 4:42:32 pm PST
changes to: Reordered procedures to match GGObjects.