home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
BURKS 2
/
BURKS_AUG97.ISO
/
BURKS
/
LANGUAGE
/
SMALTALK
/
TEXTBOOK
/
AP16.ST
(
.txt
)
< prev
next >
Wrap
Text File
|
1997-04-22
|
19KB
|
573 lines
'Smalltalk Textbook Appendix 16'!
EngiDisplayModel subclass: #EngiFreehandElement
instanceVariableNames: 'polylines area starts bends ends image density spectra '
classVariableNames: ''
poolDictionaries: ''
category: 'Engi-Figure'!
EngiFreehandElement comment:
'
Engi 0.05 (3 March 1994)
Copyright (C) 1994 by Atsushi Aoki
'!
!EngiFreehandElement methodsFor: 'accessing'!
area
^area!
bends
bends isNil ifTrue: [^nil].
^bends collect: [:assoc | (self polylines at: assoc key)
at: assoc value]!
density
^density!
ends
ends isNil ifTrue: [^nil].
^ends collect: [:assoc | (self polylines at: assoc key)
at: assoc value]!
image
^image!
polylines
^polylines!
polylines: polylineCollection
polylines := polylineCollection.
Cursor execute
showWhile:
[self computeArea.
self computePoints.
self computeImage.
self computeDensity.
self computeSpectra].
self flushBounds!
spectra
^spectra!
starts
starts isNil ifTrue: [^nil].
^starts collect: [:assoc | (self polylines at: assoc key)
at: assoc value]! !
!EngiFreehandElement methodsFor: 'bounds accessing'!
computeBounds
| bounds box |
bounds := nil.
(self polylines isNil or: [self polylines isEmpty])
ifTrue: [bounds := Point zero extent: Point zero]
ifFalse:
[bounds := self computeArea.
bounds isNil ifTrue: [bounds := Point zero extent: Point zero]].
bounds := bounds expandedBy: self expandedRectangle.
bounds := bounds merge: (Point zero corner: Point zero).
self density isNil
ifFalse:
[box := self densityComposedText bounds.
box isNil
ifFalse:
[box := box translatedBy: self defaultImageSize x * 2 @ 0.
box := box merge: (self defaultImageSize extent: self defaultImageSize).
bounds := bounds merge: box]].
displayOrigin := Point zero - bounds origin.
^Point zero extent: bounds extent!
expandedRectangle
^5 @ 5 corner: 5 @ 5! !
!EngiFreehandElement methodsFor: 'displaying'!
displayAreaOn: graphicsContext at: aPoint
self area isNil ifTrue: [^nil].
graphicsContext capStyle: GraphicsContext capRound.
graphicsContext joinStyle: GraphicsContext joinRound.
graphicsContext lineWidth: 1.
graphicsContext paint: ColorValue red.
graphicsContext displayRectangularBorder: self area at: aPoint + displayOrigin!
displayBendsOn: graphicsContext at: aPoint
| assocs rectangle |
(assocs := self bends) isNil ifTrue: [^nil].
graphicsContext capStyle: GraphicsContext capRound.
graphicsContext joinStyle: GraphicsContext joinRound.
graphicsContext lineWidth: 1.
graphicsContext paint: ColorValue red.
assocs
do:
[:p |
rectangle := ((p extent: Point zero)
expandedBy: self expandedRectangle)
insetBy: 1.
graphicsContext
displayArcBoundedBy: rectangle
startAngle: 0
sweepAngle: 360
at: aPoint + displayOrigin]!
displayDensityOn: graphicsContext at: aPoint
| displayPoint |
self density isNil ifTrue: [^nil].
graphicsContext paint: ColorValue blue.
displayPoint := aPoint + displayOrigin + (self defaultImageSize x * 2 @ 0).
self densityComposedText displayOn: graphicsContext at: displayPoint!
displayEndsOn: graphicsContext at: aPoint
| assocs rectangle |
(assocs := self ends) isNil ifTrue: [^nil].
graphicsContext capStyle: GraphicsContext capRound.
graphicsContext joinStyle: GraphicsContext joinRound.
graphicsContext lineWidth: 1.
graphicsContext paint: ColorValue red.
assocs
do:
[:p |
rectangle := ((p extent: Point zero)
expandedBy: self expandedRectangle)
insetBy: 1.
graphicsContext displayRectangularBorder: rectangle at: aPoint + displayOrigin]!
displayImageOn: graphicsContext at: aPoint
| figure shape opaque |
self image isNil ifTrue: [^nil].
figure := self image copy.
figure palette: (MappedPalette with: ColorValue white with: ColorValue blue).
shape := self image copy.
shape palette: CoveragePalette monoMaskPalette.
opaque := OpaqueImage figure: figure shape: shape.
opaque displayOn: graphicsContext at: aPoint + displayOrigin!
displayPolylinesOn: graphicsContext at: aPoint
self polylines isNil ifTrue: [^nil].
graphicsContext capStyle: GraphicsContext capRound.
graphicsContext joinStyle: GraphicsContext joinRound.
graphicsContext lineWidth: self defaultLineWidth.
graphicsContext paint: ColorValue black.
self polylines do: [:each | graphicsContext displayPolyline: each at: aPoint + displayOrigin]!
displaySpectraOn: graphicsContext at: aPoint
| figure shape opaque |
self spectra isNil ifTrue: [^nil].
figure := self spectra first copy.
figure palette: (MappedPalette with: ColorValue white with: ColorValue red).
shape := self spectra first copy.
shape palette: CoveragePalette monoMaskPalette.
opaque := OpaqueImage figure: figure shape: shape.
opaque displayOn: graphicsContext at: aPoint + displayOrigin + (0 @ self defaultImageSize y).
figure := self spectra last copy.
figure palette: (MappedPalette with: ColorValue white with: ColorValue red).
shape := self spectra last copy.
shape palette: CoveragePalette monoMaskPalette.
opaque := OpaqueImage figure: figure shape: shape.
opaque displayOn: graphicsContext at: aPoint + displayOrigin + (self defaultImageSize x @ 0)!
displayStartsOn: graphicsContext at: aPoint
| assocs rectangle polyline |
(assocs := self starts) isNil ifTrue: [^nil].
graphicsContext capStyle: GraphicsContext capRound.
graphicsContext joinStyle: GraphicsContext joinRound.
graphicsContext lineWidth: 1.
graphicsContext paint: ColorValue red.
assocs
do:
[:p |
rectangle := ((p extent: Point zero)
expandedBy: self expandedRectangle)
insetBy: 1.
polyline := Array new: 5.
polyline at: 1 put: rectangle topCenter.
polyline at: 2 put: rectangle leftCenter.
polyline at: 3 put: rectangle bottomCenter.
polyline at: 4 put: rectangle rightCenter.
polyline at: 5 put: rectangle topCenter.
graphicsContext displayPolyline: polyline at: aPoint + displayOrigin]!
displayValueOn: graphicsContext at: aPoint
displayOrigin isNil ifTrue: [self bounds].
self displayPolylinesOn: graphicsContext at: aPoint.
self displayAreaOn: graphicsContext at: aPoint.
self displayStartsOn: graphicsContext at: aPoint.
self displayBendsOn: graphicsContext at: aPoint.
self displayEndsOn: graphicsContext at: aPoint.
self displayImageOn: graphicsContext at: aPoint.
self displayDensityOn: graphicsContext at: aPoint.
self displaySpectraOn: graphicsContext at: aPoint! !
!EngiFreehandElement methodsFor: 'defaults'!
defaultImageSize
^50 @ 50!
defaultLineWidth
^3!
defaultThresholdAngle
^40!
defaultWindowLabel
self value isNil ifTrue: [^'Freehand Element'].
^(self value printString copyUpTo: Character cr)
contractTo: 40! !
!EngiFreehandElement methodsFor: 'private'!
computeAngles: pointCollection
| angleCollection angleDegree anchorPoint directionPoint |
angleCollection := OrderedCollection new: pointCollection size.
1 to: pointCollection size
do:
[:index |
| i p |
anchorPoint := pointCollection at: index.
directionPoint := nil.
i := index.
[i <= pointCollection size and: [directionPoint isNil]]
whileTrue:
[p := pointCollection at: i.
3 < (anchorPoint dist: p) ifTrue: [directionPoint := pointCollection at: i].
i := i + 1].
directionPoint isNil
ifTrue:
[directionPoint := pointCollection at: index.
anchorPoint := nil.
i := index.
[i >= 1 and: [anchorPoint isNil]]
whileTrue:
[p := pointCollection at: i.
3 < (p dist: directionPoint) ifTrue: [anchorPoint := pointCollection at: i].
i := i - 1]].
anchorPoint isNil ifTrue: [anchorPoint := pointCollection first].
angleDegree := self lineAngleFrom: anchorPoint to: directionPoint.
angleCollection add: angleDegree].
^angleCollection!
computeArea
| bounds |
self polylines isNil ifTrue: [^nil].
bounds := nil.
self polylines do: [:polyline | polyline do: [:point | bounds isNil
ifTrue: [bounds := point extent: Point zero]
ifFalse: [bounds := bounds merge: (point extent: Point zero)]]].
area := bounds.
^bounds!
computeBendPoints: pointCollection thresholdAngle: thresholdAngle
| angleCollection resultCollection