~hilaire-fernandes/drgeo/trunk

« back to all changes in this revision

Viewing changes to src/DrGeoII-Core/DrGeoDomain.class.st

  • Committer: Hilaire Fernandes
  • Date: 2017-11-15 13:17:03 UTC
  • Revision ID: hilaire.fernandes@gmail.com-20171115131703-pz09obavthi53ebt
DrGeo code under Tonel file format

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"
 
2
This is the domain object for DrGeo, aka the top level Model instance for one DrGeo instance
 
3
"
 
4
Class {
 
5
        #name : #DrGeoDomain,
 
6
        #superclass : #Model,
 
7
        #instVars : [
 
8
                'factory',
 
9
                'cmdManager',
 
10
                'actionMap'
 
11
        ],
 
12
        #category : #'DrGeoII-Core-App'
 
13
}
 
14
 
 
15
{ #category : #event }
 
16
DrGeoDomain >> actionMap [
 
17
        actionMap ifNil: [^self createActionMap].
 
18
        ^ actionMap 
 
19
]
 
20
 
 
21
{ #category : #'user interface' }
 
22
DrGeoDomain >> addModelItemsToWindowMenu: aMenu [ 
 
23
        aMenu addLine.
 
24
        aMenu
 
25
                add: 'About Dr. Geo...'
 
26
                target: self
 
27
                selector: #inform:
 
28
                argument: DrGeo drgeoCopyright
 
29
]
 
30
 
 
31
{ #category : #building }
 
32
DrGeoDomain >> createCompositeItem: aMathItemSelection [
 
33
        cmdManager compositeCommandFor: aMathItemSelection.
 
34
]
 
35
 
 
36
{ #category : #building }
 
37
DrGeoDomain >> createFromMathItem: aMathItem [
 
38
        "return the mathItem (newly created or the one in the pool, 
 
39
in case the caller want to do something with it"
 
40
        (factory pushAsLastWhenInPool: aMathItem) ifTrue:
 
41
                [^{factory last. false}].
 
42
        "create a new command and execute it"
 
43
        cmdManager buildCommandFor: aMathItem.
 
44
        ^{ aMathItem. true }
 
45
]
 
46
 
 
47
{ #category : #building }
 
48
DrGeoDomain >> createFromMathItemNoStack: aMathItem [
 
49
        "return the mathItem (newly created or the one in the pool, 
 
50
in case the caller want to do something with it, without stacking in the undo/redo stack"
 
51
        (factory pushAsLastWhenInPool: aMathItem) ifTrue: [^factory last].
 
52
        factory add: aMathItem.
 
53
        self triggerEvent: #newMathItem with: aMathItem.
 
54
        ^aMathItem
 
55
]
 
56
 
 
57
{ #category : #building }
 
58
DrGeoDomain >> createFromMathItemNoStackNoFactoryCheck: aMathItem [
 
59
        "return the mathItem. we do not check in the facory pool, without stacking in the undo/redo stack"
 
60
        factory add: aMathItem.
 
61
        self triggerEvent: #newMathItem with: aMathItem.
 
62
        ^aMathItem
 
63
]
 
64
 
 
65
{ #category : #building }
 
66
DrGeoDomain >> createMacro: aBuilder [ 
 
67
        (DrGMacroFactory new pushAsLastWhenInPool: (aBuilder getItem: self)) ifFalse: 
 
68
                [ "Create macro and register it in the factory"
 
69
                DrGMacroFactory new add: (aBuilder getItem: self) ]
 
70
]
 
71
 
 
72
{ #category : #building }
 
73
DrGeoDomain >> createMathItem: aBuilder [ 
 
74
        "return the mathItem (newly created or the one in the pool, 
 
75
in case the caller want to do something with it"
 
76
        (factory pushAsLastWhenInPool: aBuilder getItem first) ifTrue: 
 
77
                [ ^ {  (factory last). false  } ].
 
78
        "create a new command and execute it"
 
79
        ^ {  (cmdManager buildCommandWith: aBuilder). true  }
 
80
]
 
81
 
 
82
{ #category : #building }
 
83
DrGeoDomain >> deleteMathItem: aMathItem [ 
 
84
        "create a delete command and execute it"
 
85
        cmdManager deleteCommandFor: aMathItem
 
86
]
 
87
 
 
88
{ #category : #accessing }
 
89
DrGeoDomain >> factory [
 
90
        ^factory
 
91
]
 
92
 
 
93
{ #category : #building }
 
94
DrGeoDomain >> in: macroTree replaceParent: item with: newItem [ 
 
95
        | index |
 
96
        macroTree do: [ :anItem | 
 
97
                (anItem parents notNil and: [ (index := anItem parents indexOf: item) ~= 0 ])
 
98
                        ifTrue: [anItem parents at: index put: newItem ] ]
 
99
]
 
100
 
 
101
{ #category : #'initialize-release' }
 
102
DrGeoDomain >> initialize [
 
103
        super initialize.
 
104
        factory := DrGMathItemFactory new.
 
105
        cmdManager := DrGCommandManager new domain: self
 
106
]
 
107
 
 
108
{ #category : #accessing }
 
109
DrGeoDomain >> labelString [
 
110
        ^ 'Dr. Geo -- ', Date today asString
 
111
]
 
112
 
 
113
{ #category : #building }
 
114
DrGeoDomain >> merge: aMathItem with: aTarget [
 
115
        "create a merge command"
 
116
        cmdManager mergeCommandFor: aMathItem with: aTarget
 
117
]
 
118
 
 
119
{ #category : #updating }
 
120
DrGeoDomain >> moveEvent: aMathItem at: aPoint [
 
121
        aMathItem moveAt: aPoint.
 
122
        self updateAllMathItems
 
123
]
 
124
 
 
125
{ #category : #updating }
 
126
DrGeoDomain >> moveEvent: aMathItem at: aPoint withDirty: mathItems [
 
127
        aMathItem moveAt: aPoint.
 
128
        self updateDirty: mathItems
 
129
]
 
130
 
 
131
{ #category : #updating }
 
132
DrGeoDomain >> moveEvent: aMathItem inDirection: aPoint [ 
 
133
        aMathItem moveEvent: aPoint.
 
134
        self updateAllMathItems 
 
135
]
 
136
 
 
137
{ #category : #updating }
 
138
DrGeoDomain >> moveEvent: aMathItem inDirection: aPoint withDirty: mathItems [
 
139
        aMathItem moveEvent: aPoint.
 
140
        self updateDirty: mathItems
 
141
]
 
142
 
 
143
{ #category : #building }
 
144
DrGeoDomain >> moveMathItem: aMathItem with: aPoint [
 
145
        "create a move command"
 
146
        cmdManager moveCommandFor: aMathItem with: aPoint
 
147
]
 
148
 
 
149
{ #category : #updating }
 
150
DrGeoDomain >> mutate: aPointItem asFreeOn: aCurveItem at: aPosition [
 
151
        |item|
 
152
        item := DrGPointOncurveItem newWith: {aCurveItem .  aPosition}.
 
153
        item name: aPointItem name.
 
154
        item actionMap: aPointItem actionMap.
 
155
        aPointItem become: item.
 
156
        self updateAllMathItems 
 
157
]
 
158
 
 
159
{ #category : #updating }
 
160
DrGeoDomain >> mutate: aPointItem asIntersectionWith: curveA and: curveB at: aPosition [
 
161
        |item|
 
162
        item :=  DrGPointIntersectionItem newWith: {curveA. curveB.  aPosition}.
 
163
        item name: aPointItem name.
 
164
        item actionMap: aPointItem actionMap.
 
165
        aPointItem become: item.
 
166
        self updateAllMathItems.
 
167
]
 
168
 
 
169
{ #category : #updating }
 
170
DrGeoDomain >> mutateAsFreePoint: aPointItem [
 
171
        |freePointItem|
 
172
        (aPointItem isFreePointItem and: [aPointItem isPointItemOnCurve not]) ifTrue: [^aPointItem].
 
173
        freePointItem := DrGPointFreeItem new point: aPointItem point.
 
174
        freePointItem name: aPointItem name.
 
175
        freePointItem actionMap: aPointItem actionMap.
 
176
        aPointItem become: freePointItem.
 
177
        ^ freePointItem
 
178
]
 
179
 
 
180
{ #category : #building }
 
181
DrGeoDomain >> playMacro: aBuilder in: app [ 
 
182
        | answer macroTree |
 
183
        macroTree := aBuilder getItem.
 
184
        macroTree 
 
185
                with: aBuilder constructedNodes
 
186
                do: 
 
187
                        [ :item :node | 
 
188
                        answer := self createFromMathItem: item.
 
189
                        answer last 
 
190
                                ifTrue: 
 
191
                                        [ node isHiddenNode ifTrue: 
 
192
                                                [ (app costumeOf: item) ifNotNil: 
 
193
                                                        [ :aCostume | 
 
194
                                                        aCostume style hidden: true.
 
195
                                                        aCostume forceVisible: false ] ] ]
 
196
                                ifFalse: 
 
197
                                        [ "item twin in the factory, use it in the macro tree"
 
198
                                        self 
 
199
                                                in: macroTree
 
200
                                                replaceParent: item
 
201
                                                with: answer first ] ]
 
202
]
 
203
 
 
204
{ #category : #building }
 
205
DrGeoDomain >> propertyCommandFor: aMathItem with: aProperty [ 
 
206
        "create a move command"
 
207
        cmdManager propertyCommandFor: aMathItem with: aProperty 
 
208
]
 
209
 
 
210
{ #category : #accessing }
 
211
DrGeoDomain >> redo [
 
212
        cmdManager redo
 
213
]
 
214
 
 
215
{ #category : #'initialize-release' }
 
216
DrGeoDomain >> release [
 
217
        super release.
 
218
        factory release.
 
219
        cmdManager release.
 
220
]
 
221
 
 
222
{ #category : #event }
 
223
DrGeoDomain >> releaseActionMap [
 
224
        actionMap := nil
 
225
]
 
226
 
 
227
{ #category : #accessing }
 
228
DrGeoDomain >> undo [
 
229
        cmdManager undo
 
230
]
 
231
 
 
232
{ #category : #updating }
 
233
DrGeoDomain >> update: object [
 
234
        (object class == MethodModified and: [object methodClass superclass = DrGeoUserScript]) 
 
235
                ifTrue: [self updateAllMathItems]
 
236
]
 
237
 
 
238
{ #category : #updating }
 
239
DrGeoDomain >> updateAllMathItems [
 
240
        factory updateAllMathItems.
 
241
        self triggerEvent: #updatedItems
 
242
]
 
243
 
 
244
{ #category : #updating }
 
245
DrGeoDomain >> updateAllMathItemsButLocus [
 
246
        factory updateAllMathItemsButLocus.
 
247
        "We don't need to update the costumem we just want updated mathiteem'"
 
248
        "self triggerEvent: #updatedItems"
 
249
]
 
250
 
 
251
{ #category : #updating }
 
252
DrGeoDomain >> updateDirty: mathItems [
 
253
        mathItems do: [:item | item update].
 
254
        self triggerEvent: #updatedDirtyItems
 
255
]
 
256
 
 
257
{ #category : #event }
 
258
DrGeoDomain >> updateableActionMap [
 
259
        actionMap ifNil:
 
260
                [actionMap := self createActionMap].
 
261
        ^actionMap
 
262
]