Skip to content

Commit

Permalink
Fixed #733. Removed asGetterForEntityClass
Browse files Browse the repository at this point in the history
  • Loading branch information
olekscode committed Sep 18, 2023
1 parent b963935 commit 6b3cfcb
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 58 deletions.
8 changes: 4 additions & 4 deletions repository/Cormas-Core/CGStCormas.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CGStCormas >> confirmIsAbstractClass: aClass [
<< ' a concret class will have instances and ';
<< self cormasModelClass name;
<< ' will define an attribut called ';
<< aClass asGetterForEntityClass;
<< aClass buildGetterForEntityClass;
<< ').' ]).
]

Expand Down Expand Up @@ -159,7 +159,7 @@ CGStCormas >> createModelAccessorsIn: aClass [
CGStCormas >> createModelInstancesAccessorsIn: aClass [
| pop |

pop := aClass asGetterForEntityClass.
pop := aClass buildGetterForEntityClass.
aClass isAbstract
ifTrue: [
self targetClass
Expand All @@ -185,7 +185,7 @@ Ex: #theXXXs

| pop |

pop := aClass asGetterForEntityClass.
pop := aClass buildGetterForEntityClass.
self targetClass
compile: (self templateForModelReaderAccessor: pop)
classified: 'accessing'
Expand All @@ -201,7 +201,7 @@ aClassName = <String> or <Symbol>.
(aClassName ('XXX') is completed as theXXXs)"

| pop |
pop := aClass asGetterForEntityClass.
pop := aClass buildGetterForEntityClass.
self targetClass
compile: (self templateForModelSetterAccessor: pop)
classified: 'accessing'
Expand Down
26 changes: 10 additions & 16 deletions repository/Cormas-Core/CMAbstractModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -880,17 +880,6 @@ CMAbstractModel class >> setDescriptionFor: method withText: text [
notifying: nil
]

{ #category : #compiling }
CMAbstractModel class >> setterForEntityClass: aClass [
"efficiently create the setter selector for the entity class aClass (avoid concatenation).
ex : Object -> #theObjects:
self setterForEntityClass: CMEntity
"

^ aClass asSetterForEntityClass
]

{ #category : #accessing }
CMAbstractModel class >> shortName [
"Answer the model name as short string (without 'CM' nor 'Model').
Expand Down Expand Up @@ -1326,7 +1315,7 @@ CMAbstractModel >> comment: anObject [
{ #category : #'accessing - entities' }
CMAbstractModel >> compoundSpatialClasses [

| classes |
| classes getter |
classes := self class compoundSpatialClasses.

classes ifEmpty: [
Expand All @@ -1335,7 +1324,8 @@ CMAbstractModel >> compoundSpatialClasses [
classes size > 1 ifTrue: [
^ self cormas warn: 'There is more than one compound spatial entity class!'].

^ self perform: classes first asGetterForEntityClass
getter := self getterForEntityClass: classes first.
^ self perform: getter
]

{ #category : #accessing }
Expand Down Expand Up @@ -3154,7 +3144,7 @@ CMAbstractModel >> setterForEntityClass: aClass [
self basicNew setterForEntityClass: Object
"
^self class setterForEntityClass: aClass
^ (self getterForEntityClass: aClass) asMutator
]
{ #category : #'utilities - space metrics' }
Expand Down Expand Up @@ -3360,13 +3350,17 @@ CMAbstractModel >> theEntities: aClass [
"Returns a collection of all the instances of aClass"
| collection getter |
aClass isAbstract
ifTrue: [ ^ OrderedCollection new ].
getter := aClass asGetterForEntityClass.
getter := self getterForEntityClass: aClass.
collection := (self perform: getter)
ifNil: [
self class createModelReaderAccessor: aClass.
self perform: getter ].
^ collection
]
Expand Down Expand Up @@ -3484,7 +3478,7 @@ CMAbstractModel >> updateLocalData [
ifTrue: [
(self data at: className) keysAndValuesDo: [ : name : dict |
res := OrderedCollection new.
(self perform: cl asGetterForEntityClass) do: [ : c |
(self perform: (self getterForEntityClass: cl)) do: [ : c |
(aValue := c class perform: name) isSymbol
ifTrue: [
"The local probe is a reference to a global probe"
Expand Down
16 changes: 1 addition & 15 deletions repository/Cormas-Core/CMEntity.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ Class {
'image',
'activeProbes',
'povDict',
'activityDiagrams',
'getter'
'activityDiagrams'
],
#category : #'Cormas-Core-Entities'
}
Expand Down Expand Up @@ -349,19 +348,6 @@ Example: LandCover allTerminalClasses"
^ self withAllSubclasses select: #isTerminal
]

{ #category : #accessing }
CMEntity class >> asGetterForEntityClass [
"Create the getter selector for the entity class aClass.
CMEntity asGetterForEntityClass -> #theEntities"

^ getter ifNil: [ getter := self buildGetterForEntityClass ].
]

{ #category : #accessing }
CMEntity class >> asSetterForEntityClass [
^self asGetterForEntityClass asMutator
]

{ #category : #'accessing - methods & classes' }
CMEntity class >> availableInfo [
"Purpose: returns the list of available info methods
Expand Down
4 changes: 2 additions & 2 deletions repository/Cormas-Core/CMProjectModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ CMProjectModel >> removeEntity: aCMEntityAnnouncement [
| theClass theGetter |

theClass := self classFor: aCMEntityAnnouncement entityName.
theGetter := theClass asGetterForEntityClass.
theGetter := self cormasModel getterForEntityClass: theClass.

self removeEntitySubclasses: aCMEntityAnnouncement.

Expand Down Expand Up @@ -524,7 +524,7 @@ CMProjectModel >> removeEntitySubclasses: aCMEntityAnnouncement [

(OrderedCollection withAll: theClass allSubclasses)
do: [ : cl |
theGetter := cl asGetterForEntityClass.
theGetter := self cormasModel getterForEntityClass: cl.
(self perform: (aCMEntityAnnouncement type asLowercase , 'Classes') asSymbol)
remove: cl
ifAbsent: [ self error ].
Expand Down
52 changes: 33 additions & 19 deletions repository/Cormas-Core/CMSpaceModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1164,13 +1164,18 @@ CMSpaceModel >> getAggregatesFrom: baseEntity attribute: attributeName [

{ #category : #'private - regular polygons' }
CMSpaceModel >> getAggregatesFrom: baseEntity verifying: aBlock [
| eeInstances set seed neighbours newNeighbours collec |
self isNotTorroidal
ifFalse: [ ^ self warningBoundaries ].
eeInstances := ((self cormasModel
perform: baseEntity asGetterForEntityClass)

| selector eeInstances set seed neighbours newNeighbours collec |

self isNotTorroidal ifFalse: [ ^ self warningBoundaries ].

selector := self cormasModel getterForEntityClass: baseEntity.

eeInstances := ((self cormasModel perform: selector)
select: [ :c | aBlock value: c ]) copy asOrderedCollection.

collec := OrderedCollection new. "collec est une collection de set (composants des agregats)"

[ eeInstances isEmpty ]
whileFalse: [ set := IndexedSet new.
seed := eeInstances first.
Expand All @@ -1188,6 +1193,7 @@ CMSpaceModel >> getAggregatesFrom: baseEntity verifying: aBlock [
neighbours := newNeighbours ].
set do: [ :c | eeInstances remove: c ].
collec add: set ].

^ collec
]

Expand Down Expand Up @@ -1730,15 +1736,16 @@ CMSpaceModel >> lowerRightLocation [

{ #category : #'landscape indices' }
CMSpaceModel >> meanCompactness: aClass [
| sum aggregates |
aggregates := self cormasModel
perform: aClass asGetterForEntityClass.
sum := aggregates
inject: 0
into: [ :cumul :aggreg | cumul + aggreg updateCompactness ].
^ aggregates size = 0
ifTrue: [ 0 ]
ifFalse: [ sum / aggregates size ]

| selector aggregates sum |

selector := self cormasModel getterForEntityClass: aClass.
aggregates := self cormasModel perform: selector.

aggregates ifEmpty: [ ^ 0 ].

sum := aggregates sum: [ :each | each updateCompactness ].
^ sum / aggregates size
]

{ #category : #'landscape indices' }
Expand Down Expand Up @@ -2315,18 +2322,25 @@ CMSpaceModel >> setFragmentedEntities: compoundEntity from: baseEntity verifying
aBlock (example = [:cell | cell isTree] or [:aggregat | aggregat type = #forest] )
compoundEntity = a Class name inheriting from <SpatialEntityNotConnex>"

| fragmentedEntity beInstances |
self isNotTorroidal
ifFalse: [ ^ self warningBoundaries ].
| getter fragmentedEntity beInstances |

self isNotTorroidal ifFalse: [ ^ self warningBoundaries ].

self
resetCompoundSpatialEntity: compoundEntity
andTheirComponents: baseEntity.
beInstances := ((self cormasModel perform: baseEntity asGetterForEntityClass asSymbol)
select: [ :c | aBlock value: c ]) copy asOrderedCollection.

getter := self cormasModel getterForEntityClass: baseEntity.

beInstances := ((self cormasModel perform: getter)
select: [ :c | aBlock value: c ]) copy asOrderedCollection.

fragmentedEntity := compoundEntity new: self.
fragmentedEntity addSilentlyComponents: beInstances.

(self spatialEntitiesAt: compoundEntity name) add: fragmentedEntity.
self dispatchCompoundSpatialEntity: compoundEntity.

^ self spatialEntitiesAt: compoundEntity name
]

Expand Down
7 changes: 5 additions & 2 deletions repository/Cormas-Core/CMSpacePolygonNeighbourhood.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ CMSpacePolygonNeighbourhood >> gridCellShapeType [
{ #category : #'private - irregular polygons creation' }
CMSpacePolygonNeighbourhood >> initializeOrderedNeighbourhood: polygones [

| allPolygones |
| getter allPolygones |

polygones isEmpty ifTrue: [ ^ self ].
allPolygones := self cormasModel perform: polygones first asGetterForEntityClass.

getter := self cormasModel getterForEntityClass: polygones first.
allPolygones := self cormasModel perform: getter.

polygones do: [ : b | self initializePolygone: b in: allPolygones ]
]

Expand Down

0 comments on commit 6b3cfcb

Please sign in to comment.