'From VisualWorks® NonCommercial, Release 5i.4 of August 9, 2001 on June 17, 2002 at 5:39:26 pm'! CormasNS.Kernel defineClass: #SpatialEntity superclass: #{CormasNS.Kernel.Entity} indexedType: #none private: false instanceVariableNames: 'spaceModel visualState image center neighbourhood nodes extensiveNeighbourhood outline edge theOccupants theCSE includedEntities bounds ' classInstanceVariableNames: 'bounds ' imports: '' category: 'CormasKernel-Entities'! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! !CormasNS.Kernel.SpatialEntity class methodsFor: 'acces'! bounds ^bounds! bounds: x bounds := x! ! "-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "! !CormasNS.Kernel.SpatialEntity methodsFor: 'acces controller'! select: aPoint ^self outline regionIntersects: (aPoint extent: 1)! ! !CormasNS.Kernel.SpatialEntity methodsFor: 'accessing'! allOccupants | collec | collec := OrderedCollection new. self theOccupants notNil ifTrue: [self theOccupants values do: [:v | collec addAll: v]]. ^collec! bounds ^bounds! bounds: x bounds := x! center ^center! center: aPt center := aPt! compoundSpatialClasses ^theCSE! demand ^demand! demand: x demand := x! edge ^edge! edge: anObject edge := anObject! extensiveNeighbourhood ^extensiveNeighbourhood! extensiveNeighbourhood: something extensiveNeighbourhood := something! image image isNil ifTrue: [^nil]. ^(outline isNil or: [outline isEmpty]) ifFalse: [image asFiller] ifTrue: [image]! image: aWrapper image := aWrapper! includedEntities ^includedEntities! includedEntities: x includedEntities := x! neighbourhood "self subclassResponsibility ???" ^neighbourhood! neighbourhood: something "self subclassResponsibility ???" neighbourhood := something! nodes ^nodes! nodes: aDict nodes := aDict! outline ^outline! outline: a outline := a! spaceModel ^spaceModel! spaceModel: aSpaceModel spaceModel := aSpaceModel! surround ^surround! surround: x surround := x! theCSE ^theCSE! theCSE: aDict theCSE := aDict! theOccupants ^theOccupants! theOccupants: aDict theOccupants := aDict! visualState ^visualState! visualState: aVisualState visualState := aVisualState! ! !CormasNS.Kernel.SpatialEntity methodsFor: 'display'! color | couleur | self visualState isNil ifTrue: [^ColorValue veryLightGray] ifFalse: [self visualState class = ColorValue ifTrue: [couleur := visualState] ifFalse: [(ColorValue constantNames includes: self visualState) ifTrue: [couleur := ColorValue perform: self visualState] ifFalse: [couleur := self class colorsDict at: self visualState ifAbsent: [^nil]]]]. ^couleur! color: aColor image class = Polyline ifTrue: [self displayImageOn: (self view graphicsContext paint: (ColorValue perform: aColor))] ifFalse: [self image displayOn: (self view graphicsContext paint: (ColorValue perform: aColor)) at: self center]! colorC: aColor self components isNil ifFalse: [self spaceModel gridCellShape = #irregular ifTrue: [self components do: [:v | v displayImageOn: (self view graphicsContext paint: (ColorValue perform: aColor))]] ifFalse: [self components do: [:v | v image displayOn: (self view graphicsContext paint: (ColorValue perform: aColor)) at: self center]]]! colorN: aColor image class = Polyline ifTrue: [self neighbourhood do: [:v | v displayImageOn: (self view graphicsContext paint: (ColorValue perform: aColor))]] ifFalse: [self neighbourhood do: [:v | v image displayOn: (self view graphicsContext paint: (ColorValue perform: aColor)) at: v center]]! colorOld: aColor self spaceModel gridCellShape = #irregular ifTrue: [self displayImageOn: (self view graphicsContext paint: (ColorValue perform: aColor))] ifFalse: [self image displayOn: (self view graphicsContext paint: (ColorValue perform: aColor)) at: self center]! colorOldN: aColor self spaceModel gridCellShape = #irregular ifTrue: [self neighbourhood do: [:v | v displayImageOn: (self view graphicsContext paint: (ColorValue perform: aColor))]] ifFalse: [self neighbourhood do: [:v | v image displayOn: (self view graphicsContext paint: (ColorValue perform: aColor)) at: self center]]! defineVisualState self class activePov notNil ifTrue: [self visualState: (self perform: self class activePov)] ifFalse: [self visualState: nil]. self theOccupants isNil not ifTrue: [self theOccupants do: [:listeOcc | listeOcc do: [:occ | occ defineVisualState]]]! displayFlag | x y | flag isNil not ifTrue: [ x := self center x - (self image component width / 4). y := self center y + (self image component height / 4). self view graphicsContext displayString: flag printString at: (x @ y)]! displayId | x y | x := self center x - (self image component width / 4). y := self center y + (self image component height / 4). self view graphicsContext displayString: id printString at: (x @ y)! displayImageOn: aGC | couleur | self image = nil ifTrue:[^nil]. self spaceModel gridCellShape ~= #irregular & (self class inheritsFrom: SpatialEntityElement) ifTrue: [self image displayOn: aGC at: self center] ifFalse: [self image displayOn: aGC. aGC paint: ColorValue black. image asStroker displayOn: aGC. self includedEntities do: [:ic | ((ic class inheritsFrom: SpatialEntity) and: [ic visualState notNil]) ifTrue: [couleur := self class colorsDict at: ic visualState ifAbsent: [^nil]] ifFalse: [couleur := ColorValue perform: #veryLightGray]. (ic class inheritsFrom: SpatialEntity) ifTrue: [aGC paint: couleur. ic image displayOn: aGC. aGC paint: ColorValue black. ic image component asStroker displayOn: aGC] ifFalse: [aGC paint: ColorValue veryLightGray "white". ic displayFilledOn: aGC. aGC paint: ColorValue black. ic displayStrokedOn: aGC]]]! displayOn: aGC | couleur | couleur := self color. couleur notNil ifTrue: [self displayImageOn: (aGC paint: couleur). self theOccupants isNil ifFalse: [self theOccupants keysAndValuesDo: [:k :listeOcc | (self class environment at: k) activePov isNil ifFalse: [listeOcc do: [:occ | occ newPosition. occ displayOn: aGC]]]]]! displayOutlineOn: aGC self spaceModel gridCellShape = #irregular ifTrue: [aGC paint: ColorValue black. image asStroker displayOn: aGC "ifFalse: [self image displayOn: aGC at: self center]"]! displayString: aString | x y | " aString size > 1 ifTrue: [x := self center x - (self image component width / 2)] ifFalse: [x := self center x - (self image component width / 4)]." x := self center x - (self image component width / 2). y := self center y - (self image component height / 5). self view graphicsContext displayString: aString at: x @ y! displayString: aString color: aColor | x y | aString size > 1 ifTrue: [x := self center x - (self image component width / 2)] ifFalse: [x := self center x - (self image component width / 4)]. y := self center y + (self image component height / 4). self view graphicsContext paint: (ColorValue perform: aColor). self view graphicsContext displayString: aString at: x @ y! flash self image displayOn: (self view graphicsContext paint: (ColorValue perform: #yellow)) at: self center! flash: aGC self image displayOn: (aGC paint: (ColorValue perform: #yellow)) at: self center! printOn: aStream " aStream nextPutAll: 'Patch noOS: ' , nbOS displayString" super printOn: aStream! show (self view notNil and: [self spaceModel activeSpatialEntity = self class name]) ifTrue: [self displayOn: self view graphicsContext. self displayOn: self view buffer graphicsContext]! view ^self spaceModel vue! ! !CormasNS.Kernel.SpatialEntity methodsFor: 'init'! init self request: OrderedCollection new. self theCSE: Dictionary new. self includedEntities: Set new. "self neighbourhood: Set new."! init: aSpaceModel self spaceModel: aSpaceModel. self init.! initOcc: collec self allOccupants do: [:a | a leave]. self theOccupants: Dictionary new. collec do: [:e | self theOccupants at: e name put: OrderedCollection new]. "self defineVisualState; show"! ! !CormasNS.Kernel.SpatialEntity methodsFor: 'testing'! belongsToAggregat: anAggregat "Verify if it belongs to anAggregat, even if theCSE is nil. (cf isComponentOf:) Works whatever the aggregat level" ^anAggregat containsCell: self! isComponentOf: aCSE "aCSE is a class" ^(self theCSE keys includes: aCSE name) and: [(self theCSE at: aCSE name) isNil not]! isElementary self subclassResponsibility! ! !CormasNS.Kernel.SpatialEntity methodsFor: 'procedures'! distC: aSpatialEntity ^self center dist: aSpatialEntity center! distCell: aSpatialEntity | n | n := 0. [(self peripherieRayon: n) includes: aSpatialEntity] whileFalse: [n := n + 1]. ^n! distCenter: aSpatialEntity ^self center dist: aSpatialEntity center! nciAbout: aCSE ^(self neighbourhood select: [:c | aCSE components includes: c]) size / self neighbourhood size! neighbourhoodAndSelf | collec | collec := self neighbourhood asOrderedCollection. collec addFirst: self. ^collec! noOccupant | test | test := true. self theOccupants notNil ifTrue: [self theOccupants values do: [:list | list isEmpty ifFalse: [test := false]]]. ^test! occupantAt: className ^self theOccupants at: className! peripherieRayon: n | o | n = 0 ifTrue: [o := OrderedCollection new. o add: self. ^o]. n = 1 ifTrue: [^self neighbourhood] ifFalse: [n > 1 ifTrue: [^(self recursiveNeighbourhood: n) - (self recursiveNeighbourhood: n - 1)] ifFalse: [self halt]]! recursiveNeighbourhood: n | ensemble peripherie newVoisins | ensemble := Set new. ensemble add: self. peripherie := Set new. peripherie add: self. n timesRepeat: [newVoisins := Set new. peripherie do: [:p | newVoisins addAll: p neighbourhood]. peripherie := newVoisins - ensemble. ensemble addAll: newVoisins]. ^ensemble! wayTo: aCell constrainedBy: aCondition "On utilise l'attribut flag comme marqueur de distances relatives en partant de la destination " | distance newRound road step alreadyComputed newRound2 | (self spaceModel cormasModel perform: ('the' , self class name , 's') asSymbol) do: [:c | c resetFlag]. road := OrderedCollection new. alreadyComputed := Set new. alreadyComputed add: aCell. distance := 0. aCell flag: 0. newRound := aCell neighbourhood select: [:c | c perform: aCondition]. [newRound isEmpty not and: [(newRound includes: self) not]] whileTrue: [distance := distance + 1. newRound do: [:c | c flag: distance]. alreadyComputed addAll: newRound. newRound2 := Set new. newRound do: [:c | newRound2 addAll: (c neighbourhood select: [:cc | (cc perform: aCondition) and: [(alreadyComputed includes: cc) not]])]. newRound := newRound2]. "S'il y a un chemin possible, on le reconstruit en remontant le gradient, a partir de l'origine" (newRound includes: self) ifTrue: [step := self. [step = aCell] whileFalse: [road add: step. step := ((step neighbourhood select: [:c | c flag isNil not]) asSortedCollection: [:p :s | p flag < s flag]) first]. road add: step]. ^road! ! !CormasNS.Kernel.SpatialEntity methodsFor: 'print'! neighboorsStringWithSeparator: aChar "Return a String with 'self id' as first element and the id of all neighboors separated by aChar" | string | string := self id printString. self neighbourhood isNil ifFalse: [self neighbourhood do: [:i | string := string , aChar asSymbol asString , i id printString]]. ^string! !