Skip to content

Commit

Permalink
Merge pull request #27 from OpenSmock/dev-pla
Browse files Browse the repository at this point in the history
Create layer event to request repaint in case of internal layer stuff…
  • Loading branch information
labordep authored Sep 19, 2024
2 parents 70fb3a0 + f8976e0 commit 9f71ab4
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 46 deletions.
128 changes: 96 additions & 32 deletions GeoView-Bloc-Tests/BlAbstractGeoViewElementTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,99 @@ A BlAbstractGeoViewElementTest is a test class for testing the behavior of BlAbs
Class {
#name : #BlAbstractGeoViewElementTest,
#superclass : #TestCase,
#instVars : [
'geoView'
],
#category : #'GeoView-Bloc-Tests-Core'
}

{ #category : #tests }
BlAbstractGeoViewElementTest >> setUp [

| container |
super setUp.
geoView := BlAbstractGeoViewElement new.
geoView constraintsDo: [ :c | c horizontal matchParent. c vertical matchParent ].
container := BlElement new.
container size: 100@100.
container addChild: geoView.

geoView requestLayout.
container forceLayout.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> tearDown [

geoView := nil.
super tearDown.

]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testAbsoluteCoordinatesFromGlobalPoint [

| abs center |
center := geoView size / 2.
abs := geoView absoluteCoordinatesFromGlobalPoint: center.
self assert: abs latitudeInDegrees equals: 0.
self assert: abs longitudeInDegrees equals: 0.

geoView geoCenter: AbsoluteCoordinates frBrest.
abs := geoView absoluteCoordinatesFromGlobalPoint: center.
self assert: abs latitudeInDegrees rounded equals: AbsoluteCoordinates frBrest latitudeInDegrees rounded.
self assert: abs longitudeInDegrees rounded equals: AbsoluteCoordinates frBrest longitudeInDegrees rounded.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testAbsoluteCoordinatesFromGlobalPoint2 [

| abs |
"Center should be zero"
abs := geoView absoluteCoordinatesFromGlobalPoint: (geoView size / 2).
self assert: abs latitudeInDegrees equals: 0.
self assert: abs longitudeInDegrees equals: 0.

"at the top left corner"
abs := geoView absoluteCoordinatesFromGlobalPoint: 0@0.
self assert: abs latitudeInDegrees > 0.
self assert: abs longitudeInDegrees < 0.

"at the bottom right"
abs := geoView absoluteCoordinatesFromGlobalPoint: (geoView size).
self assert: abs latitudeInDegrees < 0.
self assert: abs longitudeInDegrees > 0.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testAddLayer [

| element layer |
element := BlAbstractGeoViewElement new.
| layer |
layer := GeoViewTestLayer new.
element addLayer: layer.
geoView addLayer: layer.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testGeoCenter [

geoView geoCenter: AbsoluteCoordinates frBrest.

self assert: geoView geoCenter equals: AbsoluteCoordinates frBrest.
self deny: geoView displayToGraphicProjection cartesianCenter equals: CartesianCoordinates zero.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testGeoViewLayerProcessDataChanged [

| element tag layer |
| tag layer |
"initialize geoview and event handler"
element := BlAbstractGeoViewElement new.
tag := false.
element addEventHandlerOn: GeoViewGeoObjectLayerProcessDataChanged do: [ :e | tag := true ].
geoView addEventHandlerOn: GeoViewGeoObjectLayerProcessDataChanged do: [ :e | tag := true ].
self deny: tag.

"create and add the layer"
layer := GeoViewGeoObjectsLayer new name: #myLayer.
element addLayer: layer.
geoView addLayer: layer.
self deny: tag.

"change layer process datas"
Expand All @@ -40,60 +108,56 @@ BlAbstractGeoViewElementTest >> testGeoViewLayerProcessDataChanged [
{ #category : #tests }
BlAbstractGeoViewElementTest >> testGetLayer [

| element |
element := BlAbstractGeoViewElement new.
self assert: (element getLayer: #test) isNil.
self assert: (geoView getLayer: #test) isNil.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testGetLayers [

| element |
element := BlAbstractGeoViewElement new.
self assert: element getLayers isEmpty.
self assert: geoView getLayers isEmpty.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testInitialize [

self assert: geoView size equals: 100@100.
self assert: geoView mapProjection class equals: GeoViewMercatorProjection.
self assert: geoView displayToGraphicProjection class equals: GeoView2DProjection.
self assert: geoView geoCenter equals: AbsoluteCoordinates zero.
self assert: geoView displayToGraphicProjection cartesianCenter equals: CartesianCoordinates zero.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testInteractionsStrategy [

| element |
element := BlAbstractGeoViewElement new.
self assert: element interactionsStrategy class equals: GeoViewDefaultInteractionsStrategy
self assert: geoView interactionsStrategy class equals: GeoViewDefaultInteractionsStrategy
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testNewInteractionsStrategy [

| element |
element := BlAbstractGeoViewElement new.
self assert: element newInteractionsStrategy class equals: GeoViewDefaultInteractionsStrategy.
self assert: geoView newInteractionsStrategy class equals: GeoViewDefaultInteractionsStrategy.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testObjectIndexAccessor [

| element |
element := BlAbstractGeoViewElement new.
self assert: element objectIndexAccessor equals: #key.
self assert: geoView objectIndexAccessor equals: #key.

element objectIndexAccessor: #id.
self assert: element objectIndexAccessor equals: #id.
geoView objectIndexAccessor: #id.
self assert: geoView objectIndexAccessor equals: #id.
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testRemoveInteractionsStrategy [

| element |
element := BlAbstractGeoViewElement new.
element removeInteractionsStrategy.
self assert: element interactionsStrategy isNil
geoView removeInteractionsStrategy.
self assert: geoView interactionsStrategy isNil
]

{ #category : #tests }
BlAbstractGeoViewElementTest >> testSetInteractionsStrategy [

| element |
element := BlAbstractGeoViewElement new.
element setInteractionsStrategy: nil.
self assert: element interactionsStrategy isNil
geoView setInteractionsStrategy: nil.
self assert: geoView interactionsStrategy isNil
]
16 changes: 13 additions & 3 deletions GeoView-Bloc/BlAbstractGeoViewElement.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ BlAbstractGeoViewElement >> configureLayer: aLayer [
"Setup the graphic projection (from a device point of view) of the layer"
aLayer graphicProjection: self displayToGraphicProjection.

"install common layers handlers"
aLayer announcer when: GeoViewLayerRepaintRequest send: #layerNeedToBeRepaint: to: self.

aLayer haveGeoObjects ifFalse:[ ^ self ].

"setup index accessor"
Expand All @@ -89,12 +92,13 @@ BlAbstractGeoViewElement >> configureLayer: aLayer [
aLayer graphicModel setProcessData: DTextGeoViewProcessData new for: SmockDText.
aLayer graphicModel setProcessData: DPolygonGeoViewProcessData new for: SmockDPolygon.
aLayer graphicModel setProcessData: DPolylineGeoViewProcessData new for: SmockDPolyline.
aLayer graphicModel setProcessData: DSegmentGeoViewProcessData new for: SmockDSegment.

"specify default process data"
"aLayer displayToGraphicModel defaultProcessData: DShapeAeProcessData new."

"notify when process datas changed internaly"
aLayer announcer when: GeoViewGeoObjectLayerProcessDataChanged send: #layerProcessDataChanged: to: self.
"install geo objects layers handlers"
aLayer announcer when: GeoViewGeoObjectLayerProcessDataChanged send: #layerProcessDataChanged: to: self
]

{ #category : #accessing }
Expand Down Expand Up @@ -134,7 +138,7 @@ BlAbstractGeoViewElement >> geoCenter: anAbsoluteCoordinates [

geoCenter := anAbsoluteCoordinates copy.

cartesianCoordinates := self mapProjection projLatLonToCart: self geoCenter.
cartesianCoordinates := self mapProjection projLatLonToCart: geoCenter.
self displayToGraphicProjection cartesianCenter: cartesianCoordinates.
self updateGraphicModel.

Expand Down Expand Up @@ -209,6 +213,12 @@ BlAbstractGeoViewElement >> isMarkedForSortDatas [
^ isMarkedForSortDatas ifNil: [ isMarkedForSortDatas := false ]
]

{ #category : #private }
BlAbstractGeoViewElement >> layerNeedToBeRepaint: anEvent [

self requestRepaint
]

{ #category : #private }
BlAbstractGeoViewElement >> layerProcessDataChanged: anEvent [

Expand Down
2 changes: 1 addition & 1 deletion GeoView-Bloc/GeoViewEventLogger.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ GeoViewEventLogger >> eventsToHandle [
GeoViewGeoObjectLayerProcessDataChanged.
GeoViewObjectSelectionChanged.
GeoViewObjectSelectionAdded.
GeoViewObjectSelectionRemoved .
GeoViewObjectSelectionRemoved.
GeoViewObjectSelectionCleared }
]

Expand Down
5 changes: 5 additions & 0 deletions GeoView-Bloc/GeoViewLayerRepaintRequest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Class {
#name : #GeoViewLayerRepaintRequest,
#superclass : #GeoViewLayerEvent,
#category : #'GeoView-Bloc-Events'
}
16 changes: 16 additions & 0 deletions GeoView-Tests/GeoView2DProjectionTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"
A GeoView2DProjectionTest is a test class for testing the behavior of GeoView2DProjection
"
Class {
#name : #GeoView2DProjectionTest,
#superclass : #TestCase,
#category : #'GeoView-Tests-Projection'
}

{ #category : #tests }
GeoView2DProjectionTest >> testInitialize [

| projection |
projection := GeoView2DProjection new.
self assert: projection cartesianCenter equals: CartesianCoordinates zero.
]
10 changes: 10 additions & 0 deletions GeoView/AbstractGeoViewLayer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ AbstractGeoViewLayer >> populatePickingResult: aPickingResult [
self explicitRequirement
]

{ #category : #private }
AbstractGeoViewLayer >> sendRepaintRequest [
"Notify that the layer need to be repaint, use it if the layer manage internal changes of his own graphical model"

| announcement |
announcement := GeoViewLayerRepaintRequest new.
announcement layerName: self name.
self announcer announce: announcement
]

{ #category : #'API -- symbology' }
AbstractGeoViewLayer >> symbologyProvider: aSymbologyProvider [

Expand Down
34 changes: 34 additions & 0 deletions GeoView/DSegmentGeoViewProcessData.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Class {
#name : #DSegmentGeoViewProcessData,
#superclass : #DLeafShapeGeoViewProcessData,
#category : #'GeoView-GShape-ProcessData'
}

{ #category : #private }
DSegmentGeoViewProcessData >> createGShape2D [

^ SmockGSSegment2D new
]

{ #category : #processing }
DSegmentGeoViewProcessData >> processUpdatedData: aKey incoming: aDSegment with: aGSegment2D context: aContext [

| from to |
super processUpdatedData: aKey incoming: aDSegment with: aGSegment2D context: aContext.
(aDSegment coordinates isNil or:[ aDSegment coordinates2 isNil]) ifTrue:[ ^ aGSegment2D ].

aDSegment isDrawModeDevice ifTrue:[
from := aDSegment coordinates.
to := aDSegment coordinates2.
] ifFalse: [
( aDSegment isDrawModeUser or:[ aDSegment isDrawModeUserProjected ] ) ifTrue:[
from := self processor projection projCartToPixel: aDSegment coordinates.
to := self processor projection projCartToPixel: aDSegment coordinates2.
].
].

aGSegment2D position: from.
aGSegment2D extent: to.

^ aGSegment2D
]
27 changes: 19 additions & 8 deletions GeoView/GeoView2DProjection.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ GeoView2DProjection >> altitudeInMeters: aNumber [
GeoView2DProjection >> cartesianCenter [

^ cartesianCenter ifNil: [
cartesianCenter := AbsoluteCoordinates zero ]
cartesianCenter := CartesianCoordinates zero ]
]

{ #category : #accessing }
Expand Down Expand Up @@ -98,14 +98,25 @@ GeoView2DProjection >> projCartToPixel: aCartesianCoordinates [
{ #category : #accessing }
GeoView2DProjection >> projPixelToCart: aPoint [

| point geoCenter |
geoCenter := self cartesianCenter asPoint.

point := self metersByPixel = 0
ifTrue:[ (aPoint - self offsetInPixels) + geoCenter]
ifFalse:[ (aPoint - self offsetInPixels) / self metersByPixel + geoCenter ].
| xCartesian yCartesian xOffset yOffset scale |

"Calculate the X offset from the center of the view"
xOffset := aPoint x - self offsetInPixels x.

"Calculate the Y offset from the center of the view, reversing the Y direction"
yOffset := self offsetInPixels y - aPoint y.

"Calculate the Cartesian coordinates based on the center of the view and the scale"
scale := self metersByPixel.
scale = 0 ifTrue:[
xCartesian := xOffset + self cartesianCenter xInMeters.
yCartesian := yOffset + self cartesianCenter yInMeters.
] ifFalse:[
xCartesian := (xOffset / scale) + self cartesianCenter xInMeters.
yCartesian := (yOffset / scale) + self cartesianCenter yInMeters.
].

^ CartesianCoordinates xInMeters: point x yInMeters: point y
^ CartesianCoordinates xInMeters: xCartesian yInMeters: yCartesian
]

{ #category : #accessing }
Expand Down
2 changes: 0 additions & 2 deletions GeoView/GeoViewGeoObjectsLayer.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,7 @@ GeoViewGeoObjectsLayer >> populatePickingResult: aPickingResult [

{ #category : #private }
GeoViewGeoObjectsLayer >> processDatasChanged [

"Notify internaly that process datas changed"
"self triggerEvent: #processDatasChanged"

| announcement |
announcement := GeoViewGeoObjectLayerProcessDataChanged new.
Expand Down

0 comments on commit 9f71ab4

Please sign in to comment.