DIRECTORY Atom, CD, CDApplications, CDCells, CDSimpleOps, CDDirectory, CDExtras, CDBasics, CDMarks, CDOps, CDProperties, IO, Process, Rope, SymTab; CDExtrasImpl: CEDAR MONITOR IMPORTS Atom, CD, CDApplications, CDCells, CDSimpleOps, CDDirectory, CDBasics, CDMarks, CDOps, CDProperties, IO, Process, Rope, SymTab EXPORTS CDExtras SHARES CD = BEGIN CreateDummyObject: PUBLIC PROC[design: CD.Design] RETURNS [CD.ObPtr] = BEGIN cellOb: CD.ObPtr _ CDCells.CreateEmptyCell[]; cptr: CD.CellPtr _ NARROW[cellOb.specificRef]; FOR l: LIST OF CD.PushRec _ design.actual, l.rest WHILE l#NIL DO cptr.contents _ CONS[ NEW[CD.Application _ [ ob: l.first.dummyCell.ob, location: [0, 0], orientation: CD.original, selected: FALSE ]], cptr.contents ]; ENDLOOP; RETURN [cellOb] END; Pair: TYPE = RECORD [p: CDDirectory.EnumerateObjectsProc, x: REF, key: REF]; EnumerationEnteredWhileInProgress: ERROR = CODE; entered: BOOL_FALSE; Enter: ENTRY PROC [] = BEGIN IF entered THEN RETURN WITH ERROR EnumerationEnteredWhileInProgress; entered_TRUE; END; Leave: ENTRY PROC [] = BEGIN entered_FALSE; END; EnumerateChildrenObjects: PUBLIC PROC[me: CD.ObPtr, p: CDDirectory.EnumerateObjectsProc, x: REF] = BEGIN ENABLE UNWIND => Leave[]; pair: REF Pair _ NEW[Pair]; pair^ _ [p, x, pair]; Enter[]; MyEnum[me, pair]; Leave[]; END; MyEnum: PROC [me: CD.ObPtr, x: REF] = BEGIN pair: REF Pair _ NARROW[x]; v: REF _ Atom.GetPropFromList[me.properties, $CDExtrasImplsTouched]; IF v=pair.key THEN RETURN; -- already visited me.properties _ Atom.PutPropOnList[me.properties, $CDExtrasImplsTouched, pair.key]; IF me.p.inDirectory THEN CDDirectory.EnumerateChildObjects[me, MyEnum, x]; pair.p[me, pair.x]; -- call clients enumerator proc END; EnumerateDesignObjects: PUBLIC PROC [design: CD.Design, p: CDDirectory.EnumerateObjectsProc, x: REF] = BEGIN ENABLE UNWIND => Leave[]; pair: REF Pair _ NEW[Pair]; EachCell: SymTab.EachPairAction --[key: Key, val: Val] RETURNS [quit: BOOLEAN] -- = BEGIN quit _ FALSE; MyEnum[NARROW[val, CD.ObPtr], pair] END; pair^ _ [p, x, pair]; Enter[]; [] _ SymTab.Pairs[design.cellDirectory, EachCell]; FOR l: LIST OF CD.PushRec _ design.actual, l.rest WHILE l#NIL DO MyEnum[l.first.dummyCell.ob, pair]; IF l.first.mightReplace#NIL THEN MyEnum[l.first.mightReplace.ob, pair]; ENDLOOP; Leave[]; END; BoundingBox: PUBLIC PROC [design: CD.Design] RETURNS [r: CD.DesignRect _ CDBasics.empty] = BEGIN FOR l: LIST OF CD.PushRec _ design.actual, l.rest WHILE l#NIL DO r _ CDBasics.Surround[r, CDApplications.BoundingRectO[ NARROW[l.first.dummyCell.ob.specificRef, CD.CellPtr].contents ]] ENDLOOP; END; PushedCellName: PUBLIC PROC [design: CD.Design] RETURNS [Rope.ROPE] = {RETURN [ IF design=NIL OR design.actual=NIL THEN "erronous" ELSE IF design.actual.rest=NIL THEN "top level" ELSE IF design.actual.first.specific=NIL THEN "erronous" ELSE IF design.actual.first.specific.name#NIL THEN design.actual.first.specific.name ELSE "unnamed cell" ] }; RPEachChildren: CDDirectory.EnumerateObjectsProc --PROC [me: ObPtr, x: REF]-- = BEGIN Process.Yield[]; IF ~me.p.inDirectory THEN CDProperties.PutPropOnObject[onto: me, prop: x, val: NIL] END; RemoveProps: PROC [design: CD.Design, key: REF] = BEGIN RPEachDirectoryEntry: CDDirectory.EachEntryAction = BEGIN CDProperties.PutPropOnObject[onto: ob, prop: key, val: NIL]; IF ob.p.inDirectory THEN CDDirectory.EnumerateChildObjects[me: ob, p: RPEachChildren, x: key]; END; TRUSTED{Process.SetPriority[Process.priorityBackground]}; [] _ CDDirectory.Enumerate[design: design, action: RPEachDirectoryEntry]; END; RemoveProperties: PUBLIC PROC [design: CD.Design, key: REF] = BEGIN TRUSTED {Process.Detach[FORK RemoveProps[design, key]]} END; ToLambda: PUBLIC PROC [n: CD.Number] RETURNS [Rope.ROPE] = BEGIN IF n MOD CD.lambda = 0 THEN RETURN IO.PutFR[format: " %g", v1: IO.int[n/CD.lambda]] ELSE { r: Rope.ROPE _ " "; IF n<0 THEN { n _ ABS[n]; r _ " -"; }; RETURN [IO.PutFR["%0g(%0g+%0g/%0g)", IO.rope[r], IO.int[n/CD.lambda], IO.int[n MOD CD.lambda], IO.int[CD.lambda] ]]; } END; PopToTopLayer: PUBLIC PROC [design: CD.Design] = BEGIN WHILE design.actual.rest#NIL DO IF NOT CDCells.PopFromCell[design, newcell] THEN EXIT ENDLOOP; IF design.actual.rest#NIL THEN ERROR END; Cellize: PUBLIC PROC [design: CD.Design, name: Rope.ROPE_NIL] RETURNS [cell: CD.ObPtr_NIL, pos: CD.DesignPosition] = BEGIN done: BOOL; al: CD.ApplicationList; PopToTopLayer[design]; CDSimpleOps.SelectAll[design]; IF (al_CDOps.AppList[design])#NIL THEN { IF al.rest=NIL AND ISTYPE[al.first.ob.specificRef, CD.CellPtr] AND al.first.orientation=CD.original THEN { cell _ al.first.ob; IF name#NIL THEN [] _ CDDirectory.Rename[design, cell, name]; done _ TRUE } ELSE { IF name=NIL THEN name _ design.name; IF name=NIL THEN name _ "no named design"; [done, cell] _ CDCells.CreateCellSelected[design, name]; }; IF done THEN { pos _ CDOps.AppList[design].first.location; } ELSE cell _ NIL }; CDOps.SetAppList[design, NIL] END; SkipAt: PROC [n: Rope.ROPE] RETURNS [Rope.ROPE] = BEGIN RETURN [Rope.Substr[base: n, len: Rope.SkipTo[s: n, skip: "@"]]] END; MergeIn: PUBLIC PROC [design: CD.Design, from: CD.Design, name: Rope.ROPE_NIL, fullDirectory: BOOL_TRUE] RETURNS [ob: CD.ObPtr_NIL, pos: CD.DesignPosition] = BEGIN m: CDMarks.MarkRange; IncludeOneEntry: CDDirectory.EachEntryAction = { IF fullDirectory OR ob.marked=m THEN { IF NOT CDDirectory.Remove[design: from, name: name, expectObject: ob] THEN ERROR; [] _ CDDirectory.Include[design: design, object: ob, alternateName: SkipAt[name]] } }; IF design=from THEN RETURN; IF design.technology#from.technology THEN RETURN WITH ERROR CD.Error[callingError, "MergIn design has different technology"]; [ob, pos] _ Cellize[from, name]; IF ob#NIL THEN { IF ~fullDirectory THEN { m _ CDMarks.GetNewMark[from]; CDMarks.MarkUnMarkedInclusiveChildren[from, ob, m]; }; [] _ CDDirectory.Enumerate[design: from, action: IncludeOneEntry]; CDOps.ResetDesign[from]; } ELSE ob _ NIL END; MergeInObjects: PUBLIC PROC [design: CD.Design, from: CD.Design, objects: LIST OF CD.ObPtr] = BEGIN m: CDMarks.MarkRange = CDMarks.GetNewMark[from]; IncludeOneEntry: CDDirectory.EachEntryAction = { IF ob.marked=m THEN { IF NOT CDDirectory.Remove[design: from, name: name, expectObject: ob] THEN ERROR; [] _ CDDirectory.Include[design: design, object: ob, alternateName: SkipAt[name]] } }; IF design=from THEN RETURN; IF design.technology#from.technology THEN RETURN WITH ERROR CD.Error[callingError, "MergInObjects design has different technology"]; FOR l: LIST OF CD.ObPtr _ objects, l.rest WHILE l#NIL DO CDMarks.MarkUnMarkedInclusiveChildren[from, l.first, m]; ENDLOOP; [] _ CDDirectory.Enumerate[design: from, action: IncludeOneEntry]; CDOps.ResetDesign[from]; END; END. dCDExtrasImpl.mesa (part of ChipNDale) Copyright c 1983, 1985 by Xerox Corporation. All rights reserved. by Christian Jacobi, September 8, 1983 9:45 am last edited by Christian Jacobi, May 8, 1985 12:43:13 pm PDT --create a dummy cell object which contains the whole design. --On future changes of the design, the dummy object may or may not --get obsolete. --enumerate me and its children objects --mark visited --enumerate my children first --RemoveProps --tries to remove the propertiy "key" from all objects of "design"; --may be delayed or incomplete --(only from objects, not applications...) --if "design" is pushed in, it will be popped out, either by flushing, --replacing cells or creating new cells --makes a single "cell" of of the "design", removes all applications; --pos: if "cell" is included at position "pos" in an empty design we would get "design" again --if "design" is pushed in, it will be popped out, either by flushing, --replacing cells or creating new cells --skip everything after and inclusive first "@" --"from" is transfered to an object, and is included (transitive) to "design"'s directory --"from" then may be resetted (preserving the rule: any object is in at most one directory) --the caller is assumed to have the locks of both designs --if "from" is pushed in, it's merged copy will be popped out, either by flushing, --replacing or creating new cells --"name" replaces "from"'s design name for the new created object, but it is a hint only --"pos": if "ob" is included at position "pos" in an empty design we would get "from" again --"fullDirectory": whether all objects of "from"'s directory are merged to design, --or only those used by "from"'s top layer --the "from"'s object's may change name to avoid conflicts with "design"'s directory --ob gets nil if "from" is empty --technologies must be compatible --[name: Rope.ROPE, ob: CD.ObPtr] RETURNS [quit: BOOL_FALSE]-- IF ~fullDirectory THEN CDMarks.ReturnMark[from]; --"objects" which are in "from"'s directory are transferrerd (transitive) to "design"'s directory --"from" then may be resetted (preserving the rule: any object is in at most one directory) --the caller is assumed to have the locks of both designs --the object's may change name to avoid conflicts with "design"'s directory --technologies must be compatible --[name: Rope.ROPE, ob: CD.ObPtr] RETURNS [quit: BOOL_FALSE]-- Ê |˜šœ,™,Jšœ Ïmœ7™BJšœ0™0Jšœ=™=J˜—šÏk ˜ J˜Jšžœ˜J˜J˜Jšœ ˜ J˜ J˜ J˜ J˜J˜J˜ J˜J˜J˜J˜J˜—šÏb œžœžœ˜Jšžœfžœ˜‡Jšžœ ˜Jšžœžœ˜ —Jšž˜J˜š Ïnœžœžœ žœ žœžœ ˜FJšœ=™=JšœB™Bšœ™Jšž˜Jšœžœ#˜-Jšœžœ žœ˜.š žœžœžœžœ!žœžœž˜@šœžœ˜šžœžœ˜Jšœ˜Jšœ˜Jšœ žœ ˜Jšœ ž˜Jšœ˜—Jšœ ˜ Jšœ˜—Jšžœ˜—Jšžœ ˜Jšžœ˜J˜——Jš œžœžœ*žœžœ˜LJ˜Jšœ#žœžœ˜0Jšœ žœžœ˜J˜J˜š œžœžœ˜Jšž˜Jš žœ žœžœžœžœ#˜DJšœžœ˜ Jšžœ˜J˜—š œžœžœ˜Jšž˜Jšœžœ˜Jšžœ˜J˜J˜—š  œžœžœžœ0žœ˜bJšœ'™'Jšžœžœžœ ˜Jšœžœžœ˜J˜J˜J˜J˜Jšžœ˜J˜—š œžœžœ žœ˜)Jšž˜Jšœžœžœ˜Jšœžœ>˜DJšžœ žœžœÏc˜-Jšœ™J˜SJšœ™Jšžœžœ2˜JJšœ¡˜3Jšžœ˜J˜—š  œžœžœ žœ1žœ˜fJšžœžœžœ ˜Jšœžœžœ˜J˜šŸœ¡1œ˜SJšž˜Jšœžœ˜ Jšœžœžœ˜#Jšžœ˜J˜—J˜J˜J˜2š žœžœžœžœ!žœžœž˜@J˜#Jšžœžœžœ'˜GJšžœ˜—J˜Jšžœ˜J˜—š  œžœžœ žœ ˜-Jšžœžœ˜-Jšž˜š žœžœžœžœ!žœžœž˜@˜6Jšžœ#žœ˜@—Jšžœ˜—Jšžœ˜J˜—š  œž œ žœ žœžœ˜Ešœžœ˜ Jš žœžœžœžœžœ ˜3Jšžœžœžœžœ ˜/Jšžœžœžœžœ ˜8Jšžœžœ#žœžœ"˜TJšžœ˜—J˜—J˜šŸœ#¡œ˜OJšž˜Jšœ˜šžœž˜Jšœ5žœ˜9—Jšžœ˜—J˜š  œžœ žœžœ˜1Jšž˜J˜šŸœ˜3Jšžœ˜Jšœ7žœ˜<šœžœ˜JšœE˜E—Jšžœ˜—J˜Jšœ ™ Jšžœ2˜9JšœI˜IJšžœ˜—J˜š œž œ žœžœ˜=JšœC™CJšœ™Jšœ*™*Jšž˜Jšžœžœ˜7Jšžœ˜—J˜š  œžœžœžœ žœžœ˜:Jšž˜šžœžœžœ žœ˜Jšžœžœžœžœ ˜7—šžœ˜Jšœžœ˜šžœžœ˜ Jšœžœ˜ J˜ J˜—šžœžœ˜%Jšžœ žœžœ žœžœžœ žœžœ˜KJšœ˜—J˜—Jšžœ˜—J˜J˜š  œž œ žœ ˜0JšœG™GJšœ'™'Jšž˜šžœžœž˜Jšžœžœ&žœž˜5Jšžœ˜—Jšžœžœžœž˜$Jšžœ˜J˜—š œž œ žœžœžœžœžœžœžœ˜tJšœF™FJšœ]™]JšœG™GJšœ'™'Jšž˜Jšœžœ˜ Jšœžœ˜Jšœ˜Jšœ˜šžœžœžœ˜(šžœ žœžœžœžœ žœžœ žœ˜jJšœ˜Jšžœžœžœ-˜=Jšœž˜ J˜—šžœ˜Jšžœžœžœ˜$Jšžœžœžœ˜*Jšœ8˜8J˜—šžœžœ˜Jšœ+˜+J˜—Jšžœž˜Jšœ˜—Jšœžœ˜Jšžœ˜J˜—š  œžœ žœžœžœ˜1Jšœ/™/Jšž˜Jšžœ:˜@Jšžœ˜J˜—š œžœžœ žœžœžœžœžœžœžœžœžœžœ˜JšœY™YJšœ[™[Jšœ9™9JšœS™SJšœ!™!JšœX™XJšœ[™[JšœR™RJšœ*™*JšœT™TJ™ Jšœ!™!Jšž˜Jšœ˜šŸœ!˜0Jšœ>™>šžœžœ žœ˜&Jšžœžœ@žœžœ˜QJšœQ˜QJ˜—Jšœ˜—Jšžœ žœžœ˜šžœ#žœ˜*Jšžœžœžœžœ?˜S—Jšœ ˜ šžœžœžœ˜šžœžœ˜Jšœ˜Jšœ3˜3J˜—JšœB˜BJšžœžœ™1J˜J˜—Jšžœž˜ Jšžœ˜—J˜š œžœžœ žœžœžœžœžœ ˜]Jšœa™aJšœ[™[Jšœ9™9JšœK™KJšœ!™!Jšž˜Jšœ0˜0šŸœ!˜0Jšœ>™>šžœ ž˜Jšžœžœ@žœžœ˜QJšœQ˜QJ˜—Jšœ˜—Jšžœ žœžœ˜šžœ#žœ˜*JšžœžœžœžœF˜Z—š žœžœžœžœžœžœž˜8Jšœ8˜8Jšž˜—JšœB˜BJšœ˜Jšžœ˜—J˜Jšžœ˜J˜J˜J˜J˜J˜—…—Z/: