DIRECTORY CD, CDApplications USING [NewApplicationI, BoundingRect], CDCallSpecific, CDCells, CDDirectory, CDInline, CDIO, CDOrient, CDProperties, CDRepetitions, TokenIO; CDRepetitionsImpl: CEDAR PROGRAM IMPORTS CD, CDApplications, CDCallSpecific, CDCells, CDDirectory, CDInline, CDIO, CDOrient, CDProperties, TokenIO EXPORTS CDRepetitions SHARES CDDirectory = BEGIN RepPtr: TYPE = CDRepetitions.RepPtr; RepRec: TYPE = CDRepetitions.RepRec; pForRepetitions: REF CD.ObjectProcs ~ CD.RegisterObjectType[$Repetitions]; RepositionElementsR: CDDirectory.RepositionElementsProc -- PROC [me: CD.ObPtr, objToReposition: CD.ObPtr, oldSize: CD.DesignPosition, newBound: CD.DesignRect, design: CD.Design] -- = BEGIN rp: RepPtr ~ NARROW[me.specificRef]; IF rp.ob=objToReposition THEN { rp.offsetOfFirst _ CDOrient.MapPosition[ itemInCell: newBound, cellSize: oldSize, cellInstOrient: rp.orientation, cellInstPos: rp.offsetOfFirst]; CDDirectory.RepositionAnObject[design, me]; } END; ComputeBoundsR: CDDirectory.ComputeBoundsProc -- PROC [ob: CD.ObPtr] RETURNS [CD.DesignRect] -- = BEGIN rp: RepPtr = NARROW[ob.specificRef]; sz: CD.DesignPosition = CDOrient.OrientedSize[rp.ob.size, rp.orientation]; toffset: CD.DesignPosition = [(rp.count-1)*rp.offset.x, (rp.count-1)*rp.offset.y]; r1: CD.DesignRect = CDInline.RectAt[rp.offsetOfFirst, sz]; r2: CD.DesignRect = CDInline.RectAt[CDInline.AddPoints[rp.offsetOfFirst, toffset], sz]; RETURN CDInline.Surround[r1, r2]; END; AdjustItselfR: CDDirectory.AdjustItselfProc -- PROC [objToReposition: CD.ObPtr, newBound: CD.DesignRect] -- = BEGIN rp: RepPtr = NARROW[objToReposition.specificRef]; rp.offsetOfFirst _ [0, 0]; IF rp.offset.x<0 THEN rp.offsetOfFirst.x_ -(rp.count-1)*rp.offset.x; IF rp.offset.y<0 THEN rp.offsetOfFirst.y_ -(rp.count-1)*rp.offset.y; END; InternalCreateRepetition: PROC [ob: CD.ObPtr, count: NAT, offset: CD.DesignPosition, orientation: CD.Orientation] RETURNS [CD.ObPtr] = BEGIN repOb: CD.ObPtr = NEW[CD.ObjectDefinition]; rp: RepPtr = NEW[RepRec]; sz: CD.DesignPosition = CDOrient.OrientedSize[ob.size, orientation]; repOb.p _ pForRepetitions; count _ MAX[1, MIN[count, 512]]; repOb.size.x _ sz.x+(count-1)*ABS[offset.x]; repOb.size.y _ sz.y+(count-1)*ABS[offset.y]; repOb.level _ ob.level; rp.ob _ ob; rp.offsetOfFirst _ [0, 0]; IF offset.x<0 THEN rp.offsetOfFirst.x_ -(count-1)*offset.x; IF offset.y<0 THEN rp.offsetOfFirst.y_ -(count-1)*offset.y; rp.orientation _ orientation; rp.offset _ offset; rp.count _ count; repOb.specificRef _ rp; RETURN [repOb]; END; CreateRepetition: PUBLIC PROC [design: CD.Design, ob: CD.ObPtr, count: NAT, offset: CD.DesignPosition, orientation: CD.Orientation_0] RETURNS [CD.ObPtr] = BEGIN repOb: CD.ObPtr = InternalCreateRepetition[ob, count, offset, orientation]; [] _ CDDirectory.Include[design, repOb]; RETURN [repOb]; END; DrawMeForRepetitions: PROC [aptr: CD.ApplicationPtr, pos: CD.DesignPosition, orient: CD.Orientation, pr: CD.DrawRef] = BEGIN ENABLE UNWIND => IF pr.nesting.first=aptr THEN pr.nesting _ pr.nesting.rest; rptr: RepPtr _ NARROW[aptr.ob.specificRef]; rel, sz: CD.DesignPosition; o: CD.Orientation _ CDOrient.ComposeOrient[rptr.orientation, orient]; dummyApp: CD.ApplicationPtr _ NEW[CD.Application]; xi: REF INT; dummyApp.ob _ rptr.ob; rel _ rptr.offsetOfFirst; sz _ CDOrient.OrientedSize[rptr.ob.size, rptr.orientation]; pr.nesting _ CONS[aptr, pr.nesting]; WITH CDProperties.GetPropFromApplication[aptr, $CDxIndex] SELECT FROM intP: REF INT => xi _ intP; ENDCASE => { xi _ NEW[INT]; CDProperties.PutPropOnApplication[aptr, $CDxIndex, xi]; WITH CDProperties.GetPropFromApplication[aptr, $CDxIndexProperty] SELECT FROM ixP: ATOM => { CDProperties.PutPropOnApplication[aptr, ixP, xi]; }; ENDCASE => NULL }; FOR i: INT IN [0..rptr.count) DO p: CD.DesignPosition _ CDOrient.MapPosition[ itemInCell: CDInline.RectAt[rel, sz], cellSize: aptr.ob.size, cellInstOrient: orient, cellInstPos: pos ]; IF pr.stopFlag^ THEN EXIT; xi^ _ i; pr.drawChild[dummyApp, p, o, pr]; rel _ CDInline.AddPoints[rel, rptr.offset]; ENDLOOP; IF pr.nesting.first=aptr THEN pr.nesting _ pr.nesting.rest END; QuickDrawMeForRepetitions: PROC [aptr: CD.ApplicationPtr, pos: CD.DesignPosition, orient: CD.Orientation, pr: CD.DrawRef] = BEGIN ENABLE UNWIND => IF pr.nesting.first=aptr THEN pr.nesting _ pr.nesting.rest; rptr: RepPtr _ NARROW[aptr.ob.specificRef]; rel, sz: CD.DesignPosition; o: CD.Orientation _ CDOrient.ComposeOrient[rptr.orientation, orient]; dummyApp: CD.ApplicationPtr _ NEW[CD.Application]; xi: REF INT; dummyApp.ob _ rptr.ob; rel _ rptr.offsetOfFirst; sz _ CDOrient.OrientedSize[rptr.ob.size, rptr.orientation]; pr.nesting _ CONS[aptr, pr.nesting]; WITH CDProperties.GetPropFromApplication[aptr, $CDxIndex] SELECT FROM intP: REF INT => xi _ intP; ENDCASE => { xi _ NEW[INT]; CDProperties.PutPropOnApplication[aptr, $CDxIndex, xi]; WITH CDProperties.GetPropFromApplication[aptr, $CDxIndexProperty] SELECT FROM ixP: ATOM => { CDProperties.PutPropOnApplication[aptr, ixP, xi]; }; ENDCASE => NULL }; FOR i: INT IN [0..rptr.count) DO p: CD.DesignPosition _ CDOrient.MapPosition[ itemInCell: CDInline.RectAt[rel, sz], cellSize: aptr.ob.size, cellInstOrient: orient, cellInstPos: pos ]; IF pr.stopFlag^ THEN EXIT; xi^ _ i; rptr.ob.p.quickDrawMe[dummyApp, p, o, pr]; rel _ CDInline.AddPoints[rel, rptr.offset]; ENDLOOP; IF pr.nesting.first=aptr THEN pr.nesting _ pr.nesting.rest END; IncCount: CDCallSpecific.CallProc -- PROC [design: CD.Design, aptr: CD.ApplicationPtr, x: REF] RETURNS [done: BOOL_TRUE, removeMe: BOOL_FALSE, include: CD.ApplicationList_NIL, repaintMe: BOOL_FALSE, repaintInclude: BOOL_FALSE] -- = BEGIN sz: CD.DesignPosition _ aptr.ob.size; ap: CD.ApplicationPtr _ NEW[CD.Application_aptr^]; rptr: RepPtr _ NARROW[aptr.ob.specificRef]; newOb: CD.ObPtr = CreateRepetition[design, rptr.ob, rptr.count+1, rptr.offset, rptr.orientation]; IF ap.ob.size#newOb.size THEN { relativeNewBound: CD.DesignRect _ [x1: 0, y1: 0, x2: aptr.ob.size.x, y2: aptr.ob.size.y]; IF rptr.offset.x>=0 THEN relativeNewBound.x2 _ aptr.ob.size.x+rptr.offset.x ELSE relativeNewBound.x1 _ rptr.offset.x; IF rptr.offset.y>=0 THEN relativeNewBound.y2 _ aptr.ob.size.y+rptr.offset.y ELSE relativeNewBound.y1 _ rptr.offset.y; ap.location _ CDOrient.MapPosition[ itemInCell: relativeNewBound, cellSize: aptr.ob.size, cellInstOrient: aptr.orientation, cellInstPos: aptr.location]; }; ap.ob _ newOb; include_LIST[ap]; repaintMe _ TRUE; removeMe_TRUE; repaintInclude_TRUE; END; DecCount: CDCallSpecific.CallProc -- PROC [design: CD.Design, aptr: CD.ApplicationPtr, x: REF] RETURNS [done: BOOL_TRUE, removeMe: BOOL_FALSE, include: CD.ApplicationList_NIL, repaintMe: BOOL_FALSE, repaintInclude: BOOL_FALSE] -- = BEGIN sz: CD.DesignPosition _ aptr.ob.size; ap: CD.ApplicationPtr _ NEW[CD.Application_aptr^]; rptr: RepPtr _ NARROW[aptr.ob.specificRef]; newOb: CD.ObPtr = CreateRepetition[design, rptr.ob, rptr.count-1, rptr.offset, rptr.orientation]; IF ap.ob.size#newOb.size THEN { relativeNewBound: CD.DesignRect _ [x1: 0, y1: 0, x2: aptr.ob.size.x, y2: aptr.ob.size.y]; IF rptr.offset.x>=0 THEN relativeNewBound.x2 _ aptr.ob.size.x-rptr.offset.x ELSE relativeNewBound.x1 _ -rptr.offset.x; IF rptr.offset.y>=0 THEN relativeNewBound.y2 _ aptr.ob.size.y-rptr.offset.y ELSE relativeNewBound.y1 _ -rptr.offset.y; ap.location _ CDOrient.MapPosition[ itemInCell: relativeNewBound, cellSize: aptr.ob.size, cellInstOrient: aptr.orientation, cellInstPos: aptr.location]; }; ap.ob _ newOb; include_LIST[ap]; repaintMe _ TRUE; removeMe_TRUE; repaintInclude_TRUE; END; TransformToCell: CDCallSpecific.CallProc -- PROC [design: CD.Design, aptr: CD.ApplicationPtr, x: REF] RETURNS [done: BOOL_TRUE, removeMe: BOOL_FALSE, include: CD.ApplicationList_NIL, repaintMe: BOOL_FALSE, repaintInclude: BOOL_FALSE] -- = BEGIN rptr: RepPtr_NARROW[aptr.ob.specificRef]; cob: CD.ObPtr _ CreateRepetitionCell[design: design, ob: rptr.ob, count: rptr.count, offset: rptr.offset, orientation: rptr.orientation ]; removeMe _ TRUE; repaintMe _ TRUE; include _ LIST[CDApplications.NewApplicationI[ cob, aptr.location, aptr.orientation, aptr.selected, aptr.properties]]; repaintInclude _ TRUE; END; EnumerateRepeatedObjects: PROC [me: CD.ObPtr, p: CDDirectory.EnumerateObjectsProc, x: REF] = BEGIN rptr: RepPtr = NARROW[me.specificRef]; p[rptr.ob, x]; END; ReadRepetition: CD.InternalReadProc --PROC [] RETURNS [ObPtr]-- = BEGIN ob: CD.ObPtr = CDIO.ReadObject[]; count: NAT = TokenIO.ReadInt[]; offsetx: INT = TokenIO.ReadInt[]; offsety: INT = TokenIO.ReadInt[]; orientation: CD.Orientation = CDIO.ReadOrientation[]; RETURN [ InternalCreateRepetition[ ob: ob, count: count, offset: [offsetx, offsety], orientation: orientation ]]; END; WriteRepetition: CD.InternalWriteProc -- PROC [me: ObPtr] -- = BEGIN specific: RepPtr = NARROW[me.specificRef]; CDIO.WriteObject[specific.ob]; TokenIO.WriteInt[specific.count]; TokenIO.WriteInt[specific.offset.x]; TokenIO.WriteInt[specific.offset.y]; CDIO.WriteOrientation[specific.orientation]; END; CreateRepetitionCell: PUBLIC PROC [design: CD.Design, ob: CD.ObPtr, count: NAT, offset: CD.DesignPosition, orientation: CD.Orientation_0] RETURNS [CD.ObPtr] = BEGIN ap: CD.ApplicationPtr; pos: CD.DesignPosition _ [0, 0]; co: CD.ObPtr _ CDCells.CreateEmptyCell[]; cp: CD.CellPtr _ NARROW[co.specificRef]; count _ MAX[count, 1]; IF offset.x<0 THEN {pos.x _ -offset.x*(count-1)}; IF offset.y<0 THEN {pos.y _ -offset.y*(count-1)}; FOR i: NAT IN [1..count] DO ap _ CDApplications.NewApplicationI[ob: ob, location: pos, orientation: orientation]; pos _ CDInline.AddPoints[pos, offset]; cp.contents _ CONS[ap, cp.contents] ENDLOOP; co.size _ CDInline.SizeOfRect[CDApplications.BoundingRect[cp.contents]]; [] _ CDDirectory.Include[design, co, "-repetition-"]; RETURN [co]; END; InitRepetitions: PROC [] = BEGIN rp: REF CDDirectory.DirectoryProcs ~ CDDirectory.InstallDirectoryProcs[pForRepetitions]; rp.enumerateChildObjects _ EnumerateRepeatedObjects; rp.adjustItself _ AdjustItselfR; rp.repositionElements _ RepositionElementsR; rp.computeBounds _ ComputeBoundsR; pForRepetitions.drawMe _ DrawMeForRepetitions; pForRepetitions.quickDrawMe _ QuickDrawMeForRepetitions; pForRepetitions.internalRead _ ReadRepetition; pForRepetitions.internalWrite _ WriteRepetition; CDCallSpecific.Register[$TransformToCell, pForRepetitions, TransformToCell]; CDCallSpecific.Register[$IncCount, pForRepetitions, IncCount]; CDCallSpecific.Register[$DecCount, pForRepetitions, DecCount]; END; InitRepetitions[]; END. ˆCDRepetitionsImpl.mesa (part of Chipndale) by Christian Jacobi October 27, 1983 3:36 pm last edited by Christian Jacobi December 14, 1983 10:44 am --hang two properties on the application; both pointing to the same int containing the --repetition number; --the first property has the name $CDxIndex --the second property name is the value of the property $CDxIndexProperty --do drawing --hang two properties on the application; both pointing to the same int containing the --repetition number; --the first property has the name $CDxIndex --the second property name is the value of the property $CDxIndexProperty --do drawing Ê )˜Jšœ1™1J˜Jšœ/™/Jšœ<™˜DJšœ˜Jšœœœ˜ Jšœœ ˜,Jšœœ ˜,Jšœ˜Jšœ ˜ Jšœ˜Jšœ œ)˜;Jšœ œ)˜;Jšœ˜Jšœ˜Jšœ˜Jšœ˜Jšœ ˜Jšœ˜—J˜š œœœ œ œœ œœœœ ˜šJš˜JšœœB˜KJšœ(˜(Jšœ ˜Jšœ˜—J˜š  œœœœœ ˜dJšœœ ˜š˜Jšœœœœ˜L—Jšœœ˜+Jšœ œ˜Jšœœ@˜EJšœ œœœ˜2Jšœœœ˜ Jšœ˜Jšœ˜Jšœ;˜;Jšœ œ˜$JšœW™WJšœ™Jšœ+™+JšœJ™Jšœ6œ˜EJšœœœ˜šœ˜ Jšœœœ˜Jšœ7˜7šœ>œ˜Mšœœ˜Jšœ1˜1Jšœ˜—Jšœ˜—J˜——Jšœ ™ šœœœ˜ šœœ'˜,Jšœ'˜'Jšœ˜Jšœ˜Jšœ˜Jšœ˜—Jšœœœ˜Jšœ˜Jšœ!˜!Jšœ+˜+Jšœ˜—Jšœœ˜:Jšœ˜—J˜š  œœœœœ ˜iJšœœ ˜š˜Jšœœœœ˜L—Jšœœ˜+Jšœ œ˜Jšœœ@˜EJšœ œœœ˜2Jšœœœ˜ Jšœ˜Jšœ˜Jšœ;˜;Jšœ œ˜$JšœW™WJšœ™Jšœ+™+JšœJ™Jšœ6œ˜EJšœœœ˜šœ˜ Jšœœœ˜Jšœ7˜7šœ>œ˜Mšœœ˜Jšœ1˜1Jšœ˜—Jšœ˜—J˜——Jšœ ™ šœœœ˜ šœœ'˜,Jšœ'˜'Jšœ˜Jšœ˜Jšœ˜Jšœ˜—Jšœœœ˜Jšœ˜Jšœ*˜*Jšœ+˜+Jšœ˜—Jšœœ˜:Jšœ˜—J˜šžœ˜!JšŸÃœ˜ÆJš˜Jšœœ˜%Jšœœœœ˜2Jšœœ˜+JšœœX˜ašœœ˜JšœœE˜YJšœœ4˜LJšœ%˜)Jšœœ4˜LJšœ%˜)šœ#˜#Jšœ˜Jšœ˜Jšœ!˜!Jšœ˜—Jšœ˜—Jšœ˜Jšœœ˜Jšœ œ˜Jšœ œ˜Jšœœ˜Jšœ˜—J˜šžœ˜!JšŸÃœ˜ÆJš˜Jšœœ˜%Jšœœœœ˜2Jšœœ˜+JšœœX˜ašœœ˜JšœœE˜YJšœœ4˜LJšœ&˜*Jšœœ4˜LJšœ'˜+šœ#˜#Jšœ˜Jšœ˜Jšœ!˜!Jšœ˜—Jšœ˜—Jšœ˜Jšœœ˜Jšœ œ˜Jšœ œ˜Jšœœ˜Jšœ˜—J˜šžœ˜)JšŸÃœ˜ÅJš˜Jšœ œ˜)šœœ.˜5Jšœ ˜ Jšœ˜Jšœ˜Jšœ˜Jšœ˜—Jšœ œ˜Jšœ œ˜šœ œ ˜.JšœG˜G—Jšœœ˜Jšœ˜—J˜š œœœ0œ˜]Jš˜Jšœœ˜&Jšœ˜Jšœ˜—J˜šžœœŸœ˜AJš˜Jšœœ œ˜!Jšœœ˜Jšœ œ˜!Jšœ œ˜!Jšœ œœ˜5šœ˜"Jšœ˜Jšœ ˜ Jšœ˜Jšœ˜Jšœ˜—Jšœ˜—J˜šžœœŸœ˜>Jš˜Jšœœ˜*Jšœ˜Jšœ!˜!Jšœ$˜$Jšœ$˜$Jšœ(˜,Jšœ˜—J˜š œœœ œ œœ œœœœ ˜žJš˜Jšœœ˜Jšœœ˜ Jšœœ#˜)Jšœœ œ˜(Jšœœ ˜Jšœ œ˜1Jšœ œ˜1šœœœ ˜JšœU˜UJšœ&˜&Jšœœ˜#Jšœ˜—JšœH˜HJšœ5˜5Jšœ˜ Jšœ˜—J˜š œœ˜Jš˜JšœœQ˜XJšœ4˜4Jšœ ˜ Jšœ,˜,Jšœ"˜"Jšœ.˜.Jšœ8˜8Jšœ.˜.Jšœ0˜0JšœL˜LJšœ>˜>Jšœ>˜>Jšœ˜—J˜Jšœ˜Jšœ˜J˜J˜—…—)7Å