DIRECTORY CD, CDInstances, CDCells, CDCellsInteractions, CDDirectory, CDDirectoryOps, PopUpMenus, CDEvents, CDBasics, CDMarks, CDOps, CDProperties, CDSequencer, Rope, TerminalIO; CDCellsInteractionsImpl: CEDAR PROGRAM IMPORTS CD, CDCells, CDInstances, CDDirectory, CDDirectoryOps, CDEvents, CDBasics, CDMarks, PopUpMenus, CDOps, CDProperties, CDSequencer, Rope, TerminalIO EXPORTS CDCellsInteractions SHARES CD = BEGIN EventRegistration: TYPE = CDEvents.EventRegistration; beforeReplace: EventRegistration = CDEvents.RegisterEventType[$BeforeCellReplacement]; afterReplace: EventRegistration = CDEvents.RegisterEventType[$AfterCellReplacement]; pushEvent: EventRegistration = CDEvents.RegisterEventType[$AfterPush]; popEvent: EventRegistration = CDEvents.RegisterEventType[$AfterPop]; createEvent: EventRegistration = CDEvents.RegisterEventType[$InteractiveCreatedCell]; fullPopMenu: PopUpMenus.Menu = PopUpMenus.Create["Pop from cell", "select menu entry to go back outside"]; partialPopMenu: PopUpMenus.Menu = PopUpMenus.Create["Pop from cell", "replace is not possible! it would create recursion"]; emptyPopMenu: PopUpMenus.Menu = PopUpMenus.Create["Pop from cell: empty cell", "cell is empty; you can not create an empty cell"]; expandPopMenu: PopUpMenus.Menu = PopUpMenus.Create["Pop from expanded object"]; expandResultKey: REF = NEW[INT]; Init: PROC [] = { [] _ PopUpMenus.Entry[fullPopMenu, "flush", NIL, $flush, "undo all modifications of cell"]; [] _ PopUpMenus.Entry[partialPopMenu, "flush", NIL, $flush, "undo all modifications of cell"]; [] _ PopUpMenus.Entry[emptyPopMenu, "flush", NIL, $flush, "undo all modifications of cell"]; [] _ PopUpMenus.Entry[fullPopMenu, "new cell", NIL, $new, "create a new cell; original cell is unmodified"]; [] _ PopUpMenus.Entry[partialPopMenu, "new cell", NIL, $new, "create a new cell; original cell is unmodified"]; [] _ PopUpMenus.Entry[fullPopMenu, "replace", NIL, $replace, "make edits permanent in all instances of cell"]; [] _ PopUpMenus.Entry[expandPopMenu, "flush", NIL, $flush, "undo all modifications of cell"]; [] _ PopUpMenus.Entry[expandPopMenu, "new cell this instance", NIL, $new, "create a new cell; original object is unmodified"]; [] _ PopUpMenus.Entry[expandPopMenu, "new cell and replace all instances", NIL, $newAll, "tries to forget original object"]; }; IncludeAndNameCell: PROC [design: CD.Design, cell: CD.Object, interactive: BOOL _ TRUE, allowAbort: BOOL _ FALSE] RETURNS [done: BOOL] = { IF ~interactive THEN { [] _ CDDirectory.Include[design, cell]; RETURN [done_TRUE]; }; DO fiddle: BOOL _ FALSE; aborted: BOOL _ FALSE; name: Rope.ROPE; name _ TerminalIO.RequestRope["enter object name: " ! TerminalIO.UserAbort => {aborted _ TRUE; fiddle _ TRUE; CONTINUE} ]; IF aborted THEN { TerminalIO.PutRope[" **name input aborted\n"]; IF allowAbort THEN RETURN [done_FALSE]; }; IF Rope.IsEmpty[name] THEN { fiddle _ TRUE; name _ "-no name"; }; IF Rope.Fetch[name, name.Length[]-1]='@ THEN { fiddle _ TRUE; name _ Rope.Substr[name, 0, name.Length[]-1]; }; IF CDDirectory.Include[design, cell, name, fiddle] THEN { TerminalIO.PutRopes[CDDirectory.Name[cell], " included\n"]; RETURN [done_TRUE]; }; TerminalIO.PutRopes[name, " does already exist\nnot accepted, please repeat\n"]; ENDLOOP; }; CreateCellSelected: PUBLIC PROC [design: CD.Design, name: Rope.ROPE _ NIL] RETURNS [done: BOOL _ FALSE, cellInst: CD.Instance _ NIL] = { RemoveSelectedFromWorld: PROC [design: CD.Design] RETURNS [remove: CD.InstanceList] = { keep: CD.InstanceList; [others: keep, selected: remove] _ CDInstances.SplitSelected[CDOps.InstList[design]]; CDOps.SetInstList[design, keep]; }; cellOb: CD.Object; sel: CD.InstanceList = RemoveSelectedFromWorld[design]; cellInst _ NEW[CD.InstanceRep_[selected: TRUE, trans: [CDBasics.BaseOfRect[CDInstances.BoundingRectI[sel]], original] ]]; cellInst.ob _ CDCells.CreateCellXTransformed[il: sel, cTrans: cellInst.trans]; cellOb _ cellInst.ob; IF name=NIL THEN { IF ~IncludeAndNameCell[design: design, cell: cellOb, allowAbort: TRUE, interactive: TRUE].done THEN { CDOps.IncludeInstanceList[design, sel, FALSE]; RETURN [done: FALSE, cellInst: NIL] }; } ELSE [] _ CDDirectory.Include[design, cellOb, name]; CDOps.IncludeInstance[design, cellInst, TRUE]; -- redraw removes seletion [] _ CDEvents.ProcessEvent[createEvent, design, cellOb]; RETURN [done: TRUE, cellInst: cellInst] }; PushInCellInstance: PUBLIC PROC [design: CD.Design, inst: CD.Instance, convertIfNecessary: BOOL _ TRUE] RETURNS [done: BOOL _ FALSE] = { IsCellInstance: PROC [inst: CD.Instance] RETURNS [yes: BOOL _ FALSE] = { SELECT TRUE FROM inst=NIL => TerminalIO.PutRope[" no object\n"]; inst.ob=NIL OR inst.ob.specific=NIL => TerminalIO.PutRope[" bad object\n"]; ISTYPE[inst.ob.specific, CD.CellSpecific] => yes _ TRUE; ENDCASE => TerminalIO.PutRopes[" object is not cell but ", CDOps.ObjectRope[inst.ob], "\n"]; }; CheckRecursionForPush: PROC [design: CD.Design, ob: CD.Object] RETURNS [yes: BOOL _ FALSE] = { FOR l: LIST OF CD.PushRec _ design.actual, l.rest WHILE l#NIL DO IF l.first.mightReplace#NIL AND l.first.mightReplace.ob=ob THEN RETURN [yes _ TRUE] ENDLOOP; }; old: CD.Object _ inst.ob; --the original object; or if not a cell: the original conversion WHILE old#NIL AND ~CDCells.IsCell[old] AND convertIfNecessary DO ob2: CD.Object _ CDDirectory.ExpandComplete[old, design, design]; IF ob2=NIL OR ob2=old THEN {TerminalIO.PutRope["expand failed\n"]; RETURN [FALSE]}; old _ ob2; CDProperties.PutProp[inst, expandResultKey, ob2]; ENDLOOP; IF CDCells.IsCell[old] THEN { dummy: CD.Object = CDCells.CreateEmptyCell[]; oldCp: CD.CellSpecific = NARROW[old.specific]; newCp: CD.CellSpecific = NARROW[dummy.specific]; dummyCellInst: CD.Instance; dummy.bbox _ CDBasics.universe; IF CheckRecursionForPush[design, old] THEN { TerminalIO.PutRopes[" recursive push into ", CDOps.ObjectRope[old], " not possible\n"]; RETURN [FALSE]; }; newCp^ _ oldCp^; --copies interest rect .... newCp.ir _ CDBasics.MapRect[oldCp.ir, inst.trans]; newCp.contents _ ComposeToList[oldCp.contents, oldCp.sequence, inst.trans]; newCp.sequence _ NIL; newCp.dummyCell _ TRUE; dummyCellInst _ NEW[CD.InstanceRep_[ ob: dummy, trans: [], selected: TRUE, properties: CDProperties.DCopyProps[inst.properties] ]]; CDProperties.CopyProps[inst.ob.properties, dummy]; CDOps.RemoveInstance[design, inst]; design^.actual _ CONS[ CD.PushRec[dummyCell: dummyCellInst, specific: newCp, mightReplace: inst], design^.actual ]; [] _ CDEvents.ProcessEvent[pushEvent, design]; PushForUnDo[design]; RETURN [done _ TRUE]; } }; ComposeToList: PROC [il: CD.InstanceList_NIL, seq: CD.InstanceSequence_NIL, trans: CD.Transformation] RETURNS [cl: CD.InstanceList _ NIL] = { FOR l: CD.InstanceList _ il, l.rest WHILE l#NIL DO cl _ CONS[CDInstances.Composed[l.first, trans], cl]; ENDLOOP; IF seq#NIL THEN FOR n: NAT IN [0..seq.length) DO cl _ CONS[CDInstances.Composed[seq[n], trans], cl]; ENDLOOP; }; PushForUnDo: PROC [design: CD.Design] = { old: CD.PropRef _ design.unDoBuffers; design.unDoBuffers _ CD.InitPropRef[]; CDProperties.PutProp[design.unDoBuffers, $pushed, old]; }; PopForUnDo: PROC [design: CD.Design] = { new: CD.PropRef _ NIL; old: CD.PropRef _ design.unDoBuffers; IF old#NIL THEN WITH CDProperties.GetListProp[old^, $pushed] SELECT FROM used: CD.PropRef => new _ used ENDCASE => NULL; design.unDoBuffers _ (IF new#NIL THEN new ELSE CD.InitPropRef[]); }; PopFromCell: PUBLIC PROC [design: CD.Design, m: CDCellsInteractions.Method_interactive, name: Rope.ROPE_NIL] RETURNS [done: BOOL] = { done _ IPopFromCell[design, m, name]; IF done THEN { [] _ CDEvents.ProcessEvent[popEvent, design]; PopForUnDo[design] } }; IPopFromCell: PROC [design: CD.Design, m: CDCellsInteractions.Method, name: Rope.ROPE] RETURNS [done: BOOL_FALSE] = { currentInst, originalInst: CD.Instance; currentCell, originalCell: CD.Object; recursive: BOOL _ FALSE; CheckRecursionForPop: PROC [mark: CDMarks.MarkRange] = { CDMarks.MarkUnMarkedInclusiveChildren[design, currentCell, mark]; recursive _ (originalInst.ob.marked=mark); }; RemoveRemaindsFromExpands: PROC [design: CD.Design, originalInst: CD.Instance] = { IF ~CDCells.IsCell[originalInst.ob] THEN WITH CDProperties.GetProp[originalInst, expandResultKey] SELECT FROM ob: CD.Object => { CDProperties.PutProp[originalInst, expandResultKey, NIL]; [] _ CDDirectoryOps.RemoveIfUnused[design, ob]; }; ENDCASE => NULL; }; DoFlush: PROC [] = { TerminalIO.PutRope["flush\n"]; design^.actual _ design^.actual.rest; CDOps.IncludeInstance[design, originalInst, FALSE]; RemoveRemaindsFromExpands[design, originalInst]; }; HackSetOwner: PROC [ob: CD.Object, design: CD.Design] = { CDProperties.PutObjectProp[ob, $OwnerDesign, design.cdDirectoryPriv2]; }; DoReplace: PROC [] = { needsRes: BOOL _ FALSE; currentCP: CD.CellSpecific _ NARROW[currentCell.specific]; originalCP: CD.CellSpecific _ NARROW[originalCell.specific]; [] _ CDEvents.ProcessEvent[beforeReplace, design, originalCell]; TerminalIO.PutRope["replace\n"]; CDProperties.CopyProps[currentCell.properties, originalCell, $Replace]; HackSetOwner[originalCell, design]; design^.actual _ design^.actual.rest; originalCP.contents _ currentCP.contents; originalCP.sequence _ currentCP.sequence; originalCP.ir _ currentCP.ir; originalCP.specifiedIr _ currentCP.specifiedIr; CDCells.ToSequenceMode[originalCell]; [] _ CDCells.ResizeCell[design, originalCell]; CDOps.IncludeInstance[design, originalInst, FALSE]; [] _ CDEvents.ProcessEvent[afterReplace, design, originalCell]; CDDirectory.PropagateChange[originalCell, design]; CDSequencer.MarkChangedIOOnly[design]; }; DoNewCell: PROC [interactive: BOOL_FALSE, all: BOOL_FALSE] = { IF all THEN TerminalIO.PutRope["new cell and replace all instances\n"] ELSE TerminalIO.PutRope["new cell for this instance\n"]; CDCells.ToSequenceMode[currentCell]; currentInst.ob _ currentCell; design^.actual _ design^.actual.rest; design^.actual.first.specific.changed _ TRUE; IF ~IncludeAndNameCell[design, currentCell, interactive, FALSE].done THEN ERROR; CDOps.IncludeInstance[design, currentInst, FALSE]; [] _ CDEvents.ProcessEvent[createEvent, design, currentCell]; CDDirectory.PropagateChange[currentCell, design]; IF ~CDCells.IsCell[originalCell] AND all THEN { CDDirectory.ReplaceObject[design: design, old: originalCell, new: currentCell] }; CDSequencer.MarkChanged[design]; RemoveRemaindsFromExpands[design, originalInst] }; menu: PopUpMenus.Menu _ fullPopMenu; IF design^.actual.rest=NIL THEN { TerminalIO.PutRope["not in cell\n"]; RETURN [FALSE] }; originalInst _ design^.actual.first.mightReplace; originalCell _ originalInst.ob; TerminalIO.PutRopes["Pop from ", CDOps.ObjectRope[originalCell], "\n"]; currentCell _ CDCells.CreateCellXTransformed[ il: CDOps.InstList[design], ir: (IF design^.actual.first.specific.specifiedIr THEN design^.actual.first.specific.ir ELSE [0, 0, -1, -1]), cTrans: originalInst.trans]; currentInst _ NEW[CD.InstanceRep _ [ob: currentCell, trans: originalInst.trans, selected: TRUE, properties: CDProperties.DCopyProps[design^.actual.first.dummyCell.properties]]]; CDProperties.CopyProps[design^.actual.first.dummyCell.ob.properties, currentCell]; IF m=flush OR (m=interactive AND ~design^.actual.first.specific.changed) THEN { DoFlush[]; RETURN [TRUE] }; IF CDBasics.NonEmpty[currentCell.bbox] THEN { IF m=newcell THEN {DoNewCell[interactive: FALSE]; RETURN [TRUE]}; CDMarks.DoWithMark[design, CheckRecursionForPop]; IF recursive THEN { TerminalIO.PutRope[" Original cell used inside, replace not possible\n"]; IF m=replace THEN {DoNewCell[interactive: FALSE, all: FALSE]; RETURN [TRUE]}; menu _ partialPopMenu; } ELSE IF ~CDCells.IsCell[originalCell] THEN { IF m=replace THEN {DoNewCell[interactive: FALSE, all: TRUE]; RETURN [TRUE]}; menu _ expandPopMenu; } ELSE { --ok, normal case IF m=replace THEN { DoReplace[]; RETURN [TRUE] }; } } ELSE { -- empty TerminalIO.PutRope[" create empty cell not possible\n"]; IF m#interactive THEN {DoFlush[]; RETURN [TRUE]}; menu _ emptyPopMenu; }; SELECT PopUpMenus.Call[menu] FROM $flush => DoFlush[]; $replace => DoReplace[]; $new => DoNewCell[interactive: TRUE, all: FALSE]; $newAll => DoNewCell[interactive: TRUE, all: TRUE]; ENDCASE => {TerminalIO.PutRope["skipped\n"]; RETURN [FALSE]}; RETURN [TRUE]; }; PopToTopLevel: PUBLIC PROC [design: CD.Design] = { WHILE CDCells.IsPushedIn[design] DO [] _ PopFromCell[design, newcell, "--wasPushedIn--"]; ENDLOOP; }; MakeTopInstance: PUBLIC PROC [design: CD.Design] RETURNS [inst: CD.Instance_NIL] = { done: BOOL; il: CD.InstanceList; PopToTopLevel[design]; il _ CDOps.InstList[design]; IF il=NIL THEN RETURN [NIL]; IF il.rest=NIL THEN RETURN [il.first]; FOR w: CD.InstanceList _ il, w.rest WHILE w#NIL DO w.first.selected _ TRUE ENDLOOP; [done, inst] _ CreateCellSelected[design, design.name]; IF inst#NIL AND (~done OR inst.ob=NIL) THEN inst _ NIL; }; Init[]; END. bCDCellsInteractionsImpl.mesa (part of ChipNDale) Copyright c 1983, 1986 by Xerox Corporation. All rights reserved. Created by Christian Jacobi, June 24, 1983 5:00 pm Last Edited by: Christian Jacobi, December 17, 1986 11:22:51 am PST --interactive -- removes the selected instances from design and returns them --undo the command --verbose if inst is not a cell --Returns "pushing into ob would cause recursion" --pushes undo state --rebuild undo state from before push --(You can't undo pop) --if originalInst wasn't a cell, tries to remove results of original expansion --HACK for CDDirectory-- Κ²˜codešœ2™2Kšœ Οmœ7™BKšœ5™5K™CK˜—šΟk ˜ Kšžœ˜K˜ K˜K˜K˜ K˜Kšœ ˜ K˜ Kšœ ˜ Kšœ˜Kšœ˜Kšœ ˜ Kšœ ˜ Kšœ˜Kšœ ˜ —K˜šΟnœžœžœ˜'Kšžœ“˜šKšžœ˜Kšžœžœ˜ —Kšž˜K˜Kšœžœ˜5K˜K˜VK˜TK˜FK˜D˜UK˜—Kšœj˜jKšœ{˜{Kšœ‚˜‚KšœO˜OK˜Kšœžœžœžœ˜ K˜šŸœžœ˜Kšœ,žœ,˜[Kšœ/žœ,˜^Kšœ-žœ,˜\Kšœ/žœ:˜lKšœ2žœ:˜oKšœ.žœ=˜nKšœ.žœ,˜]Kšœ?žœ<˜~KšœKžœ.˜|Kšœ˜—K˜K˜šŸœžœ žœžœžœžœžœžœžœžœ˜Ššžœžœ˜Kšœ'˜'Kšžœžœ˜K˜—KšΟc ™ šžœ˜Kš œžœžœ žœžœ žœ˜=šœ5˜5Kšœ%žœ žœžœ˜CKšœ˜—šžœ žœ˜Kšœ.˜.Kšžœ žœžœžœ˜'K˜—šžœžœ˜Kšœ žœ˜Kšœ˜Kšœ˜—šžœ&žœ˜.Kšœ žœ˜Kšœ-˜-Kšœ˜—šžœ1žœ˜:Kšœ<˜™>Kšœžœ˜KšœU˜UKšœ ˜ Kšžœ˜—K˜Kšœ˜Kšœžœ0˜7šœ žœžœžœ˜/KšœF˜FKšœ˜—KšœN˜NKšœ˜šžœžœžœ˜šžœ?žœžœžœ˜eKšœ™Kšœ'žœ˜.Kšžœžœ žœ˜#K˜—K˜—Kšžœ0˜4Kšœ(žœ ˜IKšœ8˜8Kšžœžœ˜'Kšœ˜—K˜šŸœž œ žœžœžœžœžœžœžœ˜ˆK˜š Ÿœžœžœ žœžœžœ˜HKšœ™šžœžœž˜Kšœžœ'˜/Kšœžœžœžœ)˜LKšžœžœžœ˜8KšžœU˜\—Kšœ˜K˜—šŸœžœ žœ žœ žœžœžœ˜^Kš 1™1š žœžœžœžœ!žœžœž˜@Kš žœžœžœžœžœžœ˜SKšžœ˜—Kšœ˜—K˜Kšœžœ @˜Zš žœžœžœžœž˜@Kšœžœ:˜AKš žœžœžœ žœ)žœžœ˜SKšœ ˜ Kšœ1˜1Kšžœ˜—šžœžœ˜Kšœžœ$˜-Kšœžœžœ˜.Kšœžœžœ˜0Kšœžœ ˜Kšœ˜šžœ$žœ˜,KšœX˜XKšžœžœ˜Kšœ˜—Kšœ ˜,Kšœ2˜2KšœK˜KKšœžœ˜Kšœžœ˜šœžœžœ˜$Kšœ ˜ Kšœ ˜ Kšœ žœ˜Kšœ4˜4Kšœ˜—Kšœ2˜2Kšœ$˜$šœžœ˜KšžœI˜KK˜K˜—K˜.Kšœ˜Kšžœ žœ˜K˜—Kšœ˜—K˜šŸ œžœžœžœžœžœ žœžœžœžœ˜š žœžœžœžœž˜2Kšœžœ+˜4Kšžœ˜—šžœžœž˜šžœžœžœž˜ Kšœžœ*˜3Kšžœ˜——Kšœ˜K˜—šŸ œžœ žœ ˜)Kšœ™Kšœžœ˜%Kšœžœ˜&Kšœ7˜7K˜K˜—šŸ œžœ žœ ˜(Kšœ%™%Kšœ™Kšœžœ žœ˜Kšœžœ˜%šžœžœž˜šžœ)žœž˜8Kšœžœ˜Kšžœžœ˜——Kš œžœžœžœžœžœ˜AK˜K˜—šŸ œžœžœ žœ?žœžœžœžœ˜…K˜%šžœžœ˜Kšœ-˜-Kšœ˜Kšœ˜—Kšœ˜—K˜š Ÿ œžœ žœ3žœžœž œ˜uKšœžœ ˜'Kšœžœ˜%Kšœ žœžœ˜K˜šŸœžœ˜8KšœA˜AKšœ*˜*Kšžœ˜—K˜šŸœžœ žœžœ˜RKšœN™Nšžœ"ž˜(šžœ5žœž˜Dšœžœ ˜Kšœ4žœ˜9Kšœ/˜/K˜—Kšžœžœ˜——Kšœ˜—K˜šŸœžœ˜Kšœ˜K˜%Kšœ,žœ˜3Kšœ0˜0Kšœ˜K˜—šŸ œžœžœžœ ˜9KšœF˜FK˜—K˜šŸ œžœ˜Kšœ žœžœ˜Kšœ žœžœ˜:Kšœ žœžœ˜Kšžœžœ;˜FKšžœ4˜8Kšœ$˜$Kšœ˜K˜%Kšœ(žœ˜-Kšžœ7žœžœžœ˜PKšœ+žœ˜2Kšœ=˜=Kšœ1˜1šžœžœžœ˜/KšœN˜NKšœ˜—Kšœ ˜ Kšœ/˜/Kšœ˜—K˜Kšœ$˜$šžœžœžœ˜!Kšœ%˜%Kšžœžœ˜Kšœ˜—Kšœ1˜1Kšœ˜KšœG˜Gšœ-˜-Kšœ˜Kšœžœ+žœ"žœ˜nKšœ˜—KšœžœžœFžœS˜±KšœR˜Ršžœ žœžœ)žœ˜OKšœ žœžœ˜Kšœ˜—šžœ%žœ˜.Kš žœ žœžœžœžœ˜AKšœ1˜1šžœ žœ˜KšœI˜IKš žœ žœžœžœžœžœ˜MKšœ˜Kšœ˜—šžœžœžœ˜-Kš žœ žœžœžœžœžœ˜LKšœ˜Kšœ˜—šžœ ˜šžœ žœ˜Kšœ ˜ Kšžœžœ˜ Kšœ˜—Kšœ˜—Kšœ˜—šžœ  ˜Kšœ8˜8Kšžœžœ žœžœ˜1Kšœ˜Kšœ˜—šžœž˜!Kšœ˜Kšœ˜Kšœžœžœ˜1Kšœ"žœžœ˜3Kšžœ&žœžœ˜=—Kšžœžœ˜Kšžœ˜—K˜šŸ œžœžœ žœ ˜2šžœž˜#Kšœ5˜5Kšžœ˜—Jšœ˜K˜—šŸœžœžœ žœ žœžœ žœ˜TKšœžœžœ˜ Kšœ˜Kšœ˜Kš žœžœžœžœžœ˜Kšžœ žœžœžœ ˜&š žœžœžœžœž˜2Kšœž˜Kšžœ˜—Kšœ7˜7Kšžœžœžœžœ žœžœžœ˜7Kšœ˜K˜—K˜Kšžœ˜—…—2@CT