Skip to content

Commit

Permalink
Factorization of DCompositeShape process datas management in OpenSmock.
Browse files Browse the repository at this point in the history
Optimization: On projection change, update only user draw mode shapes (or composites with user draw mode children).
Move tests into OpenSmock.
  • Loading branch information
labordep committed Oct 26, 2024
1 parent ff7a7f7 commit 74747cc
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 169 deletions.
37 changes: 0 additions & 37 deletions src/GeoView-Tests/DCompositeShapeGeoViewProcessDataTest.class.st

This file was deleted.

131 changes: 18 additions & 113 deletions src/GeoView/DCompositeShapeGeoViewProcessData.class.st
Original file line number Diff line number Diff line change
@@ -1,134 +1,39 @@
Class {
#name : #DCompositeShapeGeoViewProcessData,
#superclass : #DShapeGeoViewProcessData,
#traits : 'TSmockDCompositeShapeProcessData',
#classTraits : 'TSmockDCompositeShapeProcessData classTrait',
#category : #'GeoView-ProcessDatas'
}

{ #category : #processing }
DCompositeShapeGeoViewProcessData >> createAndAddGChildFrom: aDShape inGComposite: aGComposite2D [

| processData gShape2D |

"Not add no keyed dShape"
aDShape key ifNil:[ ^ self ].
self processor ifNil:[ ^ self ].

processData := (self processor getProcessDataFor: aDShape) ifNil:[ ^ self ].
self processor isRecyclingActive ifTrue:[
gShape2D := self processor destockRecycledDataFor: aDShape class.
].

gShape2D := processData processCreatedData: aDShape key incoming: aDShape with: gShape2D context: nil.
gShape2D ifNotNil:[
aGComposite2D addChild: gShape2D.
].

]

{ #category : #processing }
DCompositeShapeGeoViewProcessData >> processCreatedData: aKey incoming: aDComposite with: aGComposite2D context: aContext [
DCompositeShapeGeoViewProcessData >> processCreatedData: aKey incoming: aDCompositeShape with: aGCompositeShape2D context: aContext [

| gComposite2D |
gComposite2D := aGComposite2D
ifNil: [ SmockGCompositeShape2D id: aKey ]
ifNotNil:[ :e | e removeChildren ].

super processCreatedData: aKey incoming: aDComposite with: gComposite2D context: aContext.
gComposite2D := aGCompositeShape2D ifNil: [ SmockGCompositeShape2D id: aKey ].

"Sort the list before create GShape to manage zOrder"
aDComposite sortChildrenBy: [ :a :b | a zIndex < b zIndex ].
super processCreatedData: aKey incoming: aDCompositeShape with: gComposite2D context: aContext.
self processCreatedDComposite: aKey incoming: aDCompositeShape with: gComposite2D context: aContext.
self processUpdatedData: aKey incoming: aDCompositeShape with: gComposite2D context: aContext.

aDComposite dShapeList do:[ :dShape |
self createAndAddGChildFrom: dShape inGComposite: gComposite2D.
].

^ self processUpdatedData: aKey incoming: aDComposite with: gComposite2D context: aContext
^ gComposite2D
]

{ #category : #processing }
DCompositeShapeGeoViewProcessData >> processUpdatedData: aKey incoming: aDComposite with: aGComposite2D context: aContext [
DCompositeShapeGeoViewProcessData >> processRecycledData: aKey incoming: aDCompositeShape with: aGCompositeShape2D context: aContext [
"clean the GShape"

super processUpdatedData: aKey incoming: aDComposite with: aGComposite2D context: aContext.

self flag:'laborde: same principle between others view, factorize + tests'.

"new children was added"
aDComposite numberOfChildren > aGComposite2D numberOfChildren ifTrue:[

"Sort the list before create GShape to manage zOrder"
aDComposite sortChildrenBy: [ :a :b | a zIndex < b zIndex ].

aDComposite dShapeList do:[ :dShape | | gChild |
"cannot manage no keyed dShape"
dShape key ifNotNil:[
gChild := aGComposite2D getChild: dShape key.
gChild ifNil:[ self createAndAddGChildFrom: dShape inGComposite: aGComposite2D ].
].
].
].

aDComposite hasDirtyChildren ifTrue:[

"Sort the list before updated GShape to manage zOrder"
aDComposite sortChildrenBy: [ :a :b | a zIndex < b zIndex ].
super processRecycledData: aKey incoming: aDCompositeShape with: aGCompositeShape2D context: aContext.
self processRecycledDComposite: aKey incoming: aDCompositeShape with: aGCompositeShape2D context: aContext.

"check for updated children"
aDComposite toUpdateDShapeList do:[ :dShape | | processData gChild |
"cannot manage no keyed dShape"
dShape key ifNotNil:[
gChild := aGComposite2D getChild: dShape key.
gChild ifNotNil:[
processData := self processor getProcessDataFor: dShape.
processData processUpdatedData: dShape key incoming: dShape with: gChild context: aContext.
].
].
].

"check for remove children"
aDComposite toDeleteDShapeList do:[ :dShape | | gChild |
"cannot manage no keyed dShape"
dShape key ifNotNil:[
gChild := aGComposite2D getChild: dShape key.
gChild ifNil:[
"add the new dShape"
self removeGChild: gChild createdFrom: dShape offGComposite: aGComposite2D.
].
].
].

aDComposite clearChangedDShapeLists.
aDComposite updateModelWithChildren.
].

self flag:'labordep : déplacer ce code dans un pipeline de mise à jour graphique au changement de projection et pas sur maj des objets'.
aDComposite hasDrawModeUserChildren ifTrue:[
aDComposite dShapeList do:[ :dShape | | processData blChild |
"cannot manage no keyed dShape"
dShape key ifNotNil:[
blChild := aGComposite2D getChild: dShape key.
blChild ifNotNil:[
processData := self processor getProcessDataFor: dShape.
processData processUpdatedData: dShape key incoming: dShape with: blChild context: nil.
].
].
].
].

^ aGComposite2D
^ aGCompositeShape2D
]

{ #category : #processing }
DCompositeShapeGeoViewProcessData >> removeGChild: aGShape2D createdFrom: aDShape offGComposite: aGComposite2D [

| processData gChild |
DCompositeShapeGeoViewProcessData >> processUpdatedData: aKey incoming: aDCompositeShape with: aGCompositeShape2D context: aContext [

"Not remove no keyed dShape"
aDShape key ifNil:[ ^ self ].

processData := self processor getProcessDataFor: aDShape.
gChild := processData processDeletedData: aDShape key incoming: aDShape with: aGShape2D context: nil.
gChild ifNotNil:[
aGComposite2D removeChild: aDShape key.
self processor isRecyclingActive ifTrue:[self processor stockRecycledData: gChild for: aDShape class].
].
super processUpdatedData: aKey incoming: aDCompositeShape with: aGCompositeShape2D context: aContext.
self processUpdatedDComposite: aKey incoming: aDCompositeShape with: aGCompositeShape2D context: aContext.

^ aGCompositeShape2D
]
19 changes: 10 additions & 9 deletions src/GeoView/DShapeGeoViewProcessData.class.st
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Class {
#name : #DShapeGeoViewProcessData,
#superclass : #SmockProcessData,
#traits : 'TSmockDShapeProcessData',
#classTraits : 'TSmockDShapeProcessData classTrait',
#category : #'GeoView-ProcessDatas'
}

Expand All @@ -10,7 +12,7 @@ DShapeGeoViewProcessData class >> isAbstract [
^ self = DShapeGeoViewProcessData
]

{ #category : #processing }
{ #category : #computing }
DShapeGeoViewProcessData >> computePositionFor: aDShape context: aContext [

| offset |
Expand All @@ -30,7 +32,8 @@ DShapeGeoViewProcessData >> computePositionFor: aDShape context: aContext [
DShapeGeoViewProcessData >> processCreatedData: aKey incoming: aDShape with: aGShape2D context: aContext [

(aDShape isNil or: [ aGShape2D isNil ]) ifTrue: [ ^ nil ].
aGShape2D id: aKey.
self processCreatedDShape: aKey incoming: aDShape with: aGShape2D context: aContext.

^ aGShape2D
]

Expand All @@ -42,11 +45,9 @@ DShapeGeoViewProcessData >> processDeletedData: aKey incoming: aDShape with: aGS

{ #category : #processing }
DShapeGeoViewProcessData >> processRecycledData: aKey incoming: aDShape with: aGShape2D context: aContext [

"clean the GShape"
aGShape2D id: nil.
aGShape2D removeProperties.
aGShape2D isComposite ifTrue:[ aGShape2D removeChildren ].

self processRecycledDShape: aKey incoming: aDShape with: aGShape2D context: aContext.

^ aGShape2D
]
Expand All @@ -62,9 +63,9 @@ DShapeGeoViewProcessData >> processUpdatedData: aKey incoming: aDShape with: aGS

| position |
(aDShape isNil or: [ aGShape2D isNil ]) ifTrue: [ ^ nil ].
aGShape2D isVisible: aDShape isVisible.
aGShape2D properties: (aDShape properties copy).
aGShape2D isTranslatedByParent: aDShape isTranslatedByParent.
self processUpdatedDShape: aKey incoming: aDShape with: aGShape2D context: aContext.

"Update geo position"
position := self computePositionFor: aDShape context: aContext.
aGShape2D position: (position ifNil:[ 0@0 ]).

Expand Down
16 changes: 10 additions & 6 deletions src/GeoView/GeoViewAbstractElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,16 @@ GeoViewAbstractElement >> updateDisplayToGraphicProjection [
| extent offset |
extent := self viewInfos extent.
offset := extent / 2.

(self displayToGraphicProjection offsetInPixels ~= offset or:[(self displayToGraphicProjection haveResolution: extent) not]) ifTrue:[
self displayToGraphicProjection offsetInPixels: offset.
self displayToGraphicProjection updateResolution: extent.
self updateModel: ((GeoViewProjectionChanges new) isExtentChanged: true; isResolutionChanged: true).
].

(self displayToGraphicProjection offsetInPixels ~= offset or: [
(self displayToGraphicProjection haveResolution: extent) not ])
ifFalse: [ ^ self ].

self displayToGraphicProjection offsetInPixels: offset.
self displayToGraphicProjection updateResolution: extent.
self updateModel: (GeoViewProjectionChanges new
isExtentChanged: true;
isResolutionChanged: true)
]

{ #category : #private }
Expand Down
6 changes: 5 additions & 1 deletion src/GeoView/GeoViewDShapesLayer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ GeoViewDShapesLayer >> updateModel: aContext [

| dShapes |
self userDataChangesMutex critical: [
dShapes := self userModel copy.
dShapes := self userModel select: [ :e |
e isComposite
ifTrue: [ e hasDrawModeUserChildren ]
ifFalse: [ e isDrawModeUser ] ].

super updateDShapes: dShapes ]
]

Expand Down
9 changes: 6 additions & 3 deletions src/GeoView/GeoViewDomainObjectsLayer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,14 @@ GeoViewDomainObjectsLayer >> setProcessData: aProcessData forClass: aDomainObjec
{ #category : #private }
GeoViewDomainObjectsLayer >> updateModel: aContext [

| shapes |
| dShapes |
self userDataChangesMutex critical: [
shapes := self displayModel getDatas.
dShapes := self displayModel getDatas select: [ :e |
e isComposite
ifTrue: [ e hasDrawModeUserChildren ]
ifFalse: [ e isDrawModeUser ] ].

self updateDShapes: shapes ]
self updateDShapes: dShapes ]
]

{ #category : #'API -- objects management' }
Expand Down

0 comments on commit 74747cc

Please sign in to comment.