Skip to content

Commit

Permalink
Merge pull request #730 from olekscode/729-Cormas-Space-View-is-blinking
Browse files Browse the repository at this point in the history
729 cormas space view is blinking
  • Loading branch information
olekscode committed Aug 30, 2023
2 parents c20f927 + 9facbcf commit d3dd9f1
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 59 deletions.
13 changes: 13 additions & 0 deletions repository/Cormas-Core/TCMLocated.trait.st
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,19 @@ TCMLocated >> randomJump [
self moveTo: (Cormas selectRandomlyFrom: patch grid)
]

{ #category : #'star moving' }
TCMLocated >> randomJumpConstrainedBy: aBlock [

| destination candidates |
patch ifNil: [ ^ nil ].

candidates := patch grid select: [ :cell | aBlock value: cell ].
candidates isEmpty ifTrue: [ ^ self ].

destination := Cormas selectRandomlyFrom: candidates.
self moveTo: destination
]

{ #category : #'star moving' }
TCMLocated >> randomWalk [
" Moves to a spatial entity randomly picked from the direct neighbourhood (relative distance = 1) of the current location "
Expand Down
96 changes: 52 additions & 44 deletions repository/Cormas-UI-Roassal3/CMR3ChartDiagram.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ CMR3ChartDiagram class >> owner: anOwningPresenter on: aDomainObject [

^ self basicNew
owner: anOwningPresenter;
setModelBeforeInitialization: aDomainObject;
initialize;
setModel: aDomainObject;
yourself
]

Expand All @@ -32,9 +32,9 @@ CMR3ChartDiagram >> addAZeroDataSet [
initialPlot
x: xValue
y: { 0 };
color: Color blue "trans".
color: Color blue.

self chartBuilder
chartBuilder
maxValueX: self newMaxX;
addPlot: initialPlot;
renderIn: self canvas.
Expand All @@ -57,7 +57,7 @@ CMR3ChartDiagram >> addControllers: aCanvas [
CMR3ChartDiagram >> addDataSet [
" Private - The receiver was opened but the model already has simulation data. Replicate into the diagram "

self chartBuilder maxValueX: self cormasModel timeStep.
chartBuilder maxValueX: self cormasModel timeStep.
self updateYAxis.

self updateProbes.
Expand All @@ -67,7 +67,6 @@ CMR3ChartDiagram >> addDataSet [
CMR3ChartDiagram >> chartBuilder [

^ chartBuilder
ifNil: [ chartBuilder := self newChartBuilder ]
]

{ #category : #accessing }
Expand All @@ -76,6 +75,16 @@ CMR3ChartDiagram >> chartBuilder: anObject [
chartBuilder := anObject
]

{ #category : #private }
CMR3ChartDiagram >> configureCanvas: canvas [
canvas shapes first borderColor: Color black.
canvas shapes
reject: [ :each | each class = RSPolyline or: [ each class = RSBox ] ]"there are plots"
thenDo: [ :each | each color: Color black ].
"we need css"

]

{ #category : #accessing }
CMR3ChartDiagram >> cormasModelClass [

Expand Down Expand Up @@ -111,6 +120,12 @@ CMR3ChartDiagram >> detectMaxProbeValue [

]

{ #category : #initialization }
CMR3ChartDiagram >> initialize [
super initialize.
chartBuilder := self newChartBuilder.
]

{ #category : #defaults }
CMR3ChartDiagram >> maxYValue [
" Private - Answer a <Number> of the maximum value for the Y axis in the receiver "
Expand All @@ -129,32 +144,29 @@ CMR3ChartDiagram >> minYValue [
]

{ #category : #'accessing - chart' }
CMR3ChartDiagram >> newBasicChartBuilder [
" Private - Answer a new <RSChart> with the basic decorations and settings "

CMR3ChartDiagram >> newChartBuilder [
" Private - Answer a new <RSChart> with ticksAssoc as the number of X ticks"
^ RSChart new
extent: 400@300;
padding: 5;
addDecoration: self newHorizontalTick;
addDecoration: self newVerticalTick;
addDecoration: (RSXLabelDecoration new title: 'Time'; offset: 0 @ self newMaxX);
"addDecoration: (RSYLabelDecoration new title: 'Value'; offset: 0 @ 0);"
addDecoration: (RSXLabelDecoration new
in: [ :label | label baseShape color: Color black ];
title: 'Time';
fontSize: 12);
minValueY: self minYValue;
maxValueY: self maxYValue;
yourself.
]

{ #category : #'accessing - chart' }
CMR3ChartDiagram >> newChartBuilder [
" Private - Answer a new <RSChart> with ticksAssoc as the number of X ticks"

^ self newBasicChartBuilder
]

{ #category : #'accessing - ticks' }
CMR3ChartDiagram >> newHorizontalTick [
" Answer a new <RSHorizontalTick> with default or applied settings "

^ RSHorizontalTick new
integer;
fontSize: 10;
numberOfTicks: 10;
yourself.
]

Expand All @@ -170,8 +182,8 @@ CMR3ChartDiagram >> newVerticalTick [
" Answer a new <RSVerticalTick> with default or applied settings "

^ RSVerticalTick new
doNotUseNiceLabel;
numberOfTicks: 2;
numberOfTicks: 10;
fontSize: 10;
yourself.
]

Expand Down Expand Up @@ -210,23 +222,22 @@ CMR3ChartDiagram >> probeYValuesAt: x in: probeValues [
^ probeValues at: x + 1
]

{ #category : #callbacks }
CMR3ChartDiagram >> refreshProbesChart [
" Private - A probe has been selected/deselected. Update the receiver including the Y Axis "

self removeAllElements.
self chartBuilder plots removeAll.
self canvas signalUpdate.
self updateYAxis.
self updateProbes
]

{ #category : #'accessing - chart' }
CMR3ChartDiagram >> removeAllElements [
" Remove all the receiver's chart elements "

self canvas shapes do: [ : s | s remove ].

{ #category : #rendering }
CMR3ChartDiagram >> renderIn: canvas [
| group interaction |
chartBuilder := self newChartBuilder.

self probeLines do: [ :linePlot | chartBuilder addPlot: linePlot ].
group := RSGroup new.
chartBuilder plots
ifNotEmpty: [ chartBuilder renderIn: group. ].

canvas addAll: group.
self configureCanvas: canvas.

interaction := RSCanvasController new.
interaction noLegend.
canvas addInteraction: interaction.
]

{ #category : #'accessing - chart' }
Expand All @@ -244,7 +255,7 @@ CMR3ChartDiagram >> selectedProbes [
]

{ #category : #'accessing - model' }
CMR3ChartDiagram >> setModelBeforeInitialization: aDomainObject [
CMR3ChartDiagram >> setModel: aDomainObject [
" Private - See superimplementor's comment "

cormasModel := aDomainObject.
Expand All @@ -264,21 +275,18 @@ CMR3ChartDiagram >> setModelBeforeInitialization: aDomainObject [
{ #category : #'accessing - chart' }
CMR3ChartDiagram >> timeChanged: aNewTimeStep [

"newMaxX := (aNewTimeStep max: 1) min: 10."
newMaxX := aNewTimeStep.
self removeAllElements.

self chartBuilder maxValueX: newMaxX + 1.
chartBuilder maxValueX: newMaxX + 1.
self updateYAxis.

self updateProbes.

self refresh.
]

{ #category : #'accessing - chart' }
CMR3ChartDiagram >> updateProbes [

| probesToDisplay |

"probesToDisplay := self cormasModelClass activeProbes asOrderedCollection.
(self owner selectedProbes hasEqualElements: probesToDisplay)
ifFalse: [ probesToDisplay addAll: (self selectedProbes difference: probesToDisplay) ]."
Expand Down
16 changes: 15 additions & 1 deletion repository/Cormas-UI-Roassal3/CMR3SpaceAgentsBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ CMR3SpaceAgentsBuilder >> moveAgentShape: anAgentShape [
| agent cell cellSize |

agent := anAgentShape model.

cell := agent patch.
cell ifNil: [ ^ self ].

cellSize := diagramBuilder cellShapes anyOne encompassingRectangle extent.

(anAgentShape propertyAt: #RSLabeled) ifNotNil: [ :p |
Expand All @@ -107,8 +110,19 @@ CMR3SpaceAgentsBuilder >> objects [
^ diagramBuilder cormasModel theAgents
]

{ #category : #updating }
CMR3SpaceAgentsBuilder >> update [

shapes do:#remove.
self container
addAll: (shapes := self shapesFor: self objects).
shapes do: [ :each | self updateShape: each ].
]

{ #category : #updating }
CMR3SpaceAgentsBuilder >> updateShape: aShape [

self moveAgentShape: aShape
self moveAgentShape: aShape.

Transcript show: diagramBuilder cormasModel theAgents size; cr.
]
16 changes: 13 additions & 3 deletions repository/Cormas-UI-Roassal3/CMR3SpaceDiagramBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,13 @@ CMR3SpaceDiagramBuilder >> cormasModel: anObject [
{ #category : #'as yet unclassified' }
CMR3SpaceDiagramBuilder >> defaultContainer [

| canvas |
| canvas interaction |
canvas := RSCanvas new.
canvas addInteraction: RSCanvasController.

interaction := RSCanvasController new.
interaction noLegend.

canvas addInteraction: interaction.

^ canvas
]
Expand Down Expand Up @@ -105,7 +109,13 @@ CMR3SpaceDiagramBuilder >> masterShapeForCells: aShape [

{ #category : #rendering }
CMR3SpaceDiagramBuilder >> renderIn: aCanvas [

cellsBuilder renderIn: aCanvas.
agentsBuilder renderIn: aCanvas.
]

{ #category : #accessing }
CMR3SpaceDiagramBuilder >> update [
cellsBuilder update.
agentsBuilder update.
self container signalUpdate.
]
22 changes: 14 additions & 8 deletions repository/Cormas-UI-Roassal3/CMR3SpacePresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Class {
'cormasModel',
'translator',
'diagram',
'menuToolbar'
'menuToolbar',
'builder'
],
#category : #'Cormas-UI-Roassal3-Space'
}
Expand Down Expand Up @@ -112,10 +113,14 @@ CMR3SpacePresenter >> initializeCanvasInteractions [
{ #category : #initialization }
CMR3SpacePresenter >> initializeDiagram [
" Private - Create the configured receiver's diagram "

diagram := CMR3SpaceDiagramBuilder new
cormasModel: self cormasModel;
asPresenter.

builder := CMR3SpaceDiagramBuilder new
cormasModel: self cormasModel.

"diagram := self newRoassal.
diagram script: [ :canvas | builder renderIn: canvas ].
"
diagram := builder asPresenter.

diagram owner: self.
self update.
Expand All @@ -127,11 +132,11 @@ CMR3SpacePresenter >> initializeEvents [

self projectAnnouncer
when: CMSChangePoVAnnouncement
do: [ self initializeDiagram ].
do: [ builder update ].

self projectAnnouncer
when: CMTimeChangedAnnouncement
do: [ self initializeDiagram ].
do: [ builder update ].

"self projectAnnouncer
when: CMSimulationInitializationAnnouncement
Expand Down Expand Up @@ -201,6 +206,7 @@ CMR3SpacePresenter >> initializePresenters [

menuToolbar := self mainMenuToolbar.


self initializeDiagram.
self initializeCanvasInteractions.
self initializeEvents.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CMR3SpaceShapeBuilder class >> for: aBuilder [

^ self new
diagramBuilder: aBuilder;
container: aBuilder container;
yourself
]

Expand Down Expand Up @@ -113,7 +114,6 @@ CMR3SpaceShapeBuilder >> shapeFor: anObject index: aNumber [

{ #category : #'as yet unclassified' }
CMR3SpaceShapeBuilder >> update [

shapes do: [ :shape |
self updateShape: shape ].
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ CMSpChartOptionsPresenter >> probesMinMaxOptionsPresenter: anObject [
{ #category : #callbacks }
CMSpChartOptionsPresenter >> refreshProbesChart [
" Private - See comment in #refreshProbesChart "

self roassalChartPresenter refreshProbesChart.
self roassalChartPresenter refresh.
"self roassalChartPresenter refreshProbesChart"

]

Expand Down
11 changes: 11 additions & 0 deletions repository/Cormas-UI-Roassal3/CMSpRoassalPresenter.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ CMSpRoassalPresenter >> cormasModel: anObject [
cormasModel := anObject
]

{ #category : #initialization }
CMSpRoassalPresenter >> initialize [
super initialize.
self script: [ :canvas | self renderIn: canvas ].
]

{ #category : #accessing }
CMSpRoassalPresenter >> projectAnnouncer [
" Private - Answer the <Announcer> used by the receiver's project "

^ self cormasModel projectAnnouncer
]

{ #category : #initialization }
CMSpRoassalPresenter >> renderIn: canvas [
self subclassResponsibility
]

{ #category : #accessing }
CMSpRoassalPresenter >> spaceModel [
" Answer the receiver's <CMSpaceModel> "
Expand Down

0 comments on commit d3dd9f1

Please sign in to comment.