home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP28.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-22
|
11KB
|
411 lines
'Smalltalk Textbook Appendix 28'!
EngiGraph subclass: #EngiDirectedGraph
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Graph'!
EngiDirectedGraph comment:
'
Engi 0.07 (24 March 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiDirectedGraph methodsFor: 'testing'!
isDirectedGraph
^true! !
!EngiDirectedGraph methodsFor: 'connecting'!
connect: startVertex with: endVertex
| aBranch |
aBranch := self defaultBranch.
aBranch startVertex: startVertex.
aBranch endVertex: endVertex.
(self includesBranch: aBranch)
ifFalse: [self addBranch: aBranch].
(self includesVertex: startVertex)
ifFalse: [self addVertex: startVertex].
(self includesVertex: endVertex)
ifFalse: [self addVertex: endVertex]!
disconnect: startVertex with: endVertex
| aBranch |
aBranch := self defaultBranch.
aBranch startVertex: startVertex.
aBranch endVertex: endVertex.
(self includesBranch: aBranch)
ifTrue: [self removeBranch: aBranch]! !
!EngiDirectedGraph methodsFor: 'defaults'!
defaultBranchClass
^EngiBranchWithArrow!
defaultVertexClass
^EngiVertex! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EngiDirectedGraph class
instanceVariableNames: ''!
!EngiDirectedGraph class methodsFor: 'instance creation'!
new
^super new initialize! !
!EngiDirectedGraph class methodsFor: 'examples'!
example1
"EngiDirectedGraph example1."
| directedGraph aVertex activeWindow activeSensor previousPoint currentPoint colorValue |
directedGraph := EngiDirectedGraph exampleGraph.
aVertex := directedGraph atVertex: 4.
activeWindow := directedGraph class activeWindow.
activeWindow clear.
activeSensor := activeWindow sensor.
previousPoint := nil.
[activeSensor anyButtonPressed]
whileFalse:
[currentPoint := activeSensor cursorPoint.
previousPoint = currentPoint
ifFalse:
[previousPoint := currentPoint.
aVertex vertexPoint: currentPoint.
colorValue := directedGraph class sampleColor.
directedGraph doVertices: [:vertex | vertex strokeColor: colorValue].
directedGraph doBranches: [:branch | branch strokeColor: colorValue].
activeWindow clear.
directedGraph display]].
activeWindow display.
^directedGraph!
example2
"EngiDirectedGraph example2."
| directedGraph activeWindow activeSensor |
directedGraph := EngiDirectedGraph exampleGraph.
activeWindow := directedGraph class activeWindow.
activeWindow clear.
directedGraph
visitDepthFirstVertexDo:
[:vertex |
vertex strokeColor: directedGraph class sampleColor.
vertex display.
(Delay forMilliseconds: 500) wait]
branchDo:
[:branch |
branch strokeColor: directedGraph class sampleColor.
branch display.
(Delay forMilliseconds: 500) wait].
activeSensor := activeWindow sensor.
[activeSensor anyButtonPressed] whileFalse.
activeWindow display.
^directedGraph!
example3
"EngiDirectedGraph example3."
| directedGraph activeWindow activeSensor |
directedGraph := EngiDirectedGraph exampleGraph.
activeWindow := directedGraph class activeWindow.
activeWindow clear.
directedGraph
visitBreadthFirstVertexDo:
[:vertex |
vertex strokeColor: directedGraph class sampleColor.
vertex display.
(Delay forMilliseconds: 500) wait]
branchDo:
[:branch |
branch strokeColor: directedGraph class sampleColor.
branch display.
(Delay forMilliseconds: 500) wait].
activeSensor := activeWindow sensor.
[activeSensor anyButtonPressed] whileFalse.
activeWindow display.
^directedGraph!
example4
"EngiDirectedGraph example4."
| directedGraph activeWindow activeSensor |
directedGraph := EngiDirectedGraph exampleGraph.
activeWindow := directedGraph class activeWindow.
activeWindow clear.
directedGraph visitBreadthFirstInitialize.
directedGraph
visitDepthFirst: (directedGraph atVertex: 7)
vertexDo:
[:vertex |
vertex display.
(Delay forMilliseconds: 500) wait]
branchDo:
[:branch |
branch display.
(Delay forMilliseconds: 500) wait].
activeSensor := activeWindow sensor.
[activeSensor anyButtonPressed] whileFalse.
activeWindow display.
^directedGraph!
example5
"EngiDirectedGraph example5."
| directedGraph activeWindow activeSensor |
directedGraph := EngiDirectedGraph exampleGraph.
activeWindow := directedGraph class activeWindow.
activeWindow clear.
directedGraph visitBreadthFirstInitialize.
directedGraph
visitBreadthFirst: (directedGraph atVertex: 7)
vertexDo:
[:vertex |
vertex display.
(Delay forMilliseconds: 500) wait]
branchDo:
[:branch |
branch display.
(Delay forMilliseconds: 500) wait].
activeSensor := activeWindow sensor.
[activeSensor anyButtonPressed] whileFalse.
activeWindow display.
^directedGraph!
example6
"EngiDirectedGraph example6."
| directedGraph activeWindow activeSensor |
directedGraph := EngiDirectedGraph exampleGraph.
directedGraph arrangeScan.
activeWindow := directedGraph class activeWindow.
activeWindow clear.
directedGraph display.
activeSensor := activeWindow sensor.
[activeSensor anyButtonPressed] whileFalse.
activeWindow display.
^directedGraph! !
EngiGraph subclass: #EngiUndirectedGraph
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Graph'!
EngiUndirectedGraph comment:
'
Engi 0.07 (24 March 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiUndirectedGraph methodsFor: 'testing'!
isUndirectedGraph
^true! !
!EngiUndirectedGraph methodsFor: 'connecting'!
connect: startVertex with: endVertex
| aBranch |
aBranch := self defaultBranch.
aBranch startVertex: startVertex.
aBranch endVertex: endVertex.
(self includesBranch: aBranch)
ifFalse:
[self addBranch: aBranch.
self addVertex: startVertex.
self addVertex: endVertex].
aBranch := self defaultBranch.
aBranch startVertex: endVertex.
aBranch endVertex: startVertex.
(self includesBranch: aBranch)
ifFalse:
[self addBranch: aBranch.
self addVertex: startVertex.
self addVertex: endVertex]!
disconnect: startVertex with: endVertex
| aBranch |
aBranch := self defaultBranch.
aBranch startVertex: startVertex.
aBranch endVertex: endVertex.
(self includesBranch: aBranch)
ifTrue: [self removeBranch: aBranch].
aBranch := self defaultBranch.
aBranch startVertex: endVertex.
aBranch endVertex: startVertex.
(self includesBranch: aBranch)
ifTrue: [self removeBranch: aBranch]! !
!EngiUndirectedGraph methodsFor: 'defaults'!
defaultBranchClass
^EngiBranch!
defaultVertexClass
^EngiVertex! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
EngiUndirectedGraph class
instanceVariableNames: ''!
!EngiUndirectedGraph class methodsFor: 'instance creation'!
new
^super new initialize! !
!EngiUndirectedGraph class methodsFor: 'examples'!
example1
"EngiUndirectedGraph example1."
| undirectedGraph aVertex activeWindow activeSensor previousPoint currentPoint colorValue |
undirectedGraph := EngiUndirectedGraph exampleGraph.
aVertex := undirectedGraph atVertex: 4.
activeWindow := undirectedGraph class activeWindow.
activeWindow clear.
activeSensor := activeWindow sensor.
previousPoint := nil.
[activeSensor anyButtonPressed]
whileFalse:
[currentPoint := activeSensor cursorPoint.
previousPoint = currentPoint
ifFalse:
[previousPoint := currentPoint.
aVertex vertexPoint: currentPoint.
colorValue := undirectedGraph class sampleColor.
undirectedGraph doVertices: [:vertex | vertex strokeColor: colorValue].
undirectedGraph doBranches: [:branch | branch strokeColor: colorValue].
activeWindow clear.
undirectedGraph display]].
activeWindow display.
^undirectedGraph!
example2
"EngiUndirectedGraph example2."
| undirectedGraph activeWindow activeSensor |
undirectedGraph := EngiUndirectedGraph exampleGraph.
activeWindow := undirectedGraph class activeWindow.
activeWindow clear.
undirectedGraph
visitDepthFirstVertexDo:
[:vertex |
vertex strokeColor: undirectedGraph class sampleColor.
vertex display.
(Delay forMilliseconds: 500) wait]
branchDo:
[:branch |
branch strokeColor: undirectedGraph class sampleColor.
branch display.
(Delay forMill