# HG changeset patch # User ca # Date 889176658 -3600 # Node ID 5ff79f80245e0f79f2c814278c9b55ca058301ee # Parent c8848a173815aafd230a241f2e71e9734d49c67f separat task to access the GLX methods; -> implements: invalidate diff -r c8848a173815 -r 5ff79f80245e GraphColumnView3D.st --- a/GraphColumnView3D.st Thu Mar 05 20:43:24 1998 +0100 +++ b/GraphColumnView3D.st Fri Mar 06 10:30:58 1998 +0100 @@ -7,9 +7,9 @@ ! GLXView subclass:#GLXGraph - instanceVariableNames:'graph colorMap glxObjGraphs glxObjFcts glxObjRefs glxObjGrid - glxObjAxis maxY minY removeGraphs removeFcts removeRefs - removeGrid removeAxis redrawLock' + instanceVariableNames:'graph colorMap maxY minY loVCols loVRefs glxObjFunc glxObjRefs + glxObjGrid glxObjAxis removeFunc removeRefs removeGrid removeAxis + isInvalid lockCriticalTask criticalTask' classVariableNames:'' poolDictionaries:'' privateIn:GraphColumnView3D @@ -95,48 +95,6 @@ view := GraphColumnView3D origin:0@0 extent:1.0@1.0 in:top. list := OrderedCollection new. - top label:'2D-View'. - - #( red green yellow blue - ) keysAndValuesDo:[:idx :aColor| - |col| - - col := GraphColumn name:idx. - col foregroundColor:(Color perform:aColor). - - col functionYblock:[:start :anArray| - x := (start - 1) * 0.2. - (idx == 1 or:[idx == 3]) ifTrue:[ - 1 to:(anArray size) do:[:i| anArray at:i put:20 * (x sin). x := x + 0.2 ]. - ] ifFalse:[ - 1 to:(anArray size) do:[:i| anArray at:i put:20 * (x cos). x := x + 0.2 ]. - ]. - anArray - ]. - list add:col - ]. -"/ view rotateX:0. -"/ view rotateY:0. - view showGrid:true. - view columns:list. - top open. - - - - - -! - -test1 -" -self test1 -" - |top list view x| - - top := StandardSystemView extent:800 @ 400. - view := GraphColumnView3D origin:0@0 extent:1.0@1.0 in:top. - list := OrderedCollection new. - top label:'3D-View'. #( red green yellow blue @@ -162,19 +120,25 @@ view showDefaultMenu:true. top openAndWait. - [ |o i| + [ |o i t c| i := 0. + t := 0. + c := 0. [top shown] whileTrue:[ - view rotateX:i. - i := i + 10. - o := view removeFirst. - view add:o. - Delay waitForSeconds:0.2. + t := t + (Time millisecondsToRun:[ view rotateY:i]). + i := i + 1. + c := c + 1. + c == 90 ifTrue:[ + Transcript showCR:'Time: ', t printString. + t := 0. + c := 0. + ]. + Delay waitForSeconds:0.05. ] - ] forkAt:7. + ] forkAt:8. @@ -195,7 +159,7 @@ " showAxis ~~ aBool ifTrue:[ showAxis := aBool. - self doInvalidateGraph. + glxView invalidate. ]. ! @@ -212,7 +176,7 @@ " showGraph ~~ aBool ifTrue:[ showGraph := aBool. - self doInvalidateGraph. + glxView invalidate. ]. ! @@ -234,7 +198,7 @@ zZ = zoomZ ifFalse:[ zoomZ := zZ. - self doInvalidateGraph + glxView invalidate. ] ! ! @@ -387,7 +351,7 @@ doInvalidateGraph "set graph to invalidate " - glxView redraw + glxView invalidate ! doRecomputeGraph @@ -395,7 +359,6 @@ graph to invalidate " glxView deleteAllObjects. - self doInvalidateGraph ! updateColumns:what with:oldValue from:aColumn @@ -412,7 +375,7 @@ (what == #color or:[what == #foregroundColor]) ifTrue:[ glxView deleteColumns. - ^ self doInvalidateGraph. + ^ glxView invalidate. ]. ( aColumn isNil @@ -432,7 +395,7 @@ what == #color ifTrue:[ glxView deleteGrid ]. - self doInvalidateGraph. + glxView invalidate. ! updateReferences:what atRelX:aPhysX @@ -447,7 +410,7 @@ what == #state ifFalse:[ glxView deleteReferences ]. - self doInvalidateGraph + glxView invalidate. ! ! !GraphColumnView3D methodsFor:'rotation'! @@ -466,7 +429,7 @@ (r := self rotateValueFrom:aValue) ~~ rotateX ifTrue:[ rotateX := r. - self doInvalidateGraph + glxView invalidate. ] ! @@ -484,7 +447,7 @@ (r := self rotateValueFrom:aValue) ~~ rotateY ifTrue:[ rotateY := r. - self doInvalidateGraph + glxView invalidate. ] ! @@ -503,27 +466,81 @@ (r := self rotateValueFrom:aValue) ~~ rotateZ ifTrue:[ rotateZ := r. - self doInvalidateGraph + glxView invalidate. ] ! ! -!GraphColumnView3D::GLXGraph methodsFor:'drawing'! +!GraphColumnView3D::GLXGraph methodsFor:'event handling'! -redraw - "redraw +buttonPress:button x:x y:y + "delegate button to graph " - shown ifTrue:[ - self freeObjectsDo:[ - self redrawInBackBuffer. - self swapBuffers. - ] - ] + graph buttonPress:button x:x y:y +! ! + +!GraphColumnView3D::GLXGraph methodsFor:'initialization'! + +destroy + "remove dependencies + " + super destroy. + self deleteAllObjects. ! -redrawAxisFor:aListOfVisibleCols +for:aGraph + graph := aGraph +! + +initialize + "setup default values + " + super initialize. + + type := #colorIndexDoubleBuffer. "/ works on any device + colorMap := Dictionary new. + maxY := 1.0. + minY := -1.0. + + removeFunc := false. + removeRefs := false. + removeGrid := false. + removeAxis := false. + isInvalid := false. + lockCriticalTask := Semaphore forMutualExclusion. +! +realize + "define orthogonal projection; switch to back buffer drawing + " + super realize. + device glxOrthoLeft:-1.0 right:1.0 bottom:-1.0 top:1.0 near:10.0 far:-10.0 in:drawableId. + self backBuffer. + +! + +unrealize + "clear colorMap and objects + " + super unrealize. + self deleteAllObjects. +! ! + +!GraphColumnView3D::GLXGraph methodsFor:'making objects'! + +make:aSelector + + |id| + + id := self newObjectId. + self makeObject:id. + self perform:aSelector. + self closeObject. + ^ id +! + +makeAxis |y0 x0 z0 x1 y1 z1| x0 := 0.0. @@ -531,7 +548,7 @@ y0 := minY asFloat. y1 := maxY asFloat. x1 := graph windowSize asFloat. - z1 := aListOfVisibleCols size - 1.0. + z1 := loVCols size - 1.0. self setColor:(Color red). @@ -553,7 +570,7 @@ ! -redrawGraphFor:aListOfCols +makeFunc "draw the graph and spawn the grid dependend on the enabled attributes " @@ -570,7 +587,7 @@ data := Array new:noRows. maxY := nil. - aListOfCols do:[:aCol| + loVCols do:[:aCol| yVal := aCol yValuesStartAt:firstX into:data. x := 0.0. r := 1. @@ -579,6 +596,7 @@ maxY := minY := yVal at:r ]. self setColor:(aCol foregroundColor). + device glxBeginLineIn:drawableId. noRows timesRepeat:[ @@ -590,13 +608,12 @@ x := x + 1.0. r := r + 1. ]. - device glxEndLineIn:drawableId. z := z + 1.0. ] ! -redrawGridFor:aListOfCols +makeGrid "draw the graph and spawn the grid dependend on the enabled attributes " @@ -605,14 +622,11 @@ r "{ Class:SmallInteger }" | - aListOfCols size < 2 ifTrue:[ - ^ self - ]. noRows := graph windowSize. x := 0.0. r := graph graphOriginX. data := Array new:1. - maxY := minY := (aListOfCols at:1) yValueAt:1. + maxY := minY := (loVCols at:1) yValueAt:1. self setColor:(graph gridColor). @@ -620,7 +634,7 @@ device glxBeginLineIn:drawableId. z := 0.0. - aListOfCols do:[:aCol| + loVCols do:[:aCol| y := aCol yValueAt:r. maxY := maxY max:y. minY := minY min:y. @@ -639,49 +653,133 @@ ! +makeRefs + "redraw current visible references + " + |y0 y1 z0 z1 x0| + + y0 := minY asFloat. + y1 := maxY asFloat. + z0 := -0.1. + z1 := loVCols size - 0.9. + + self setColor:(graph referenceColor). + + loVRefs do:[:anIndex| + x0 := anIndex asFloat. + + device glxBeginLineIn:drawableId. + device glxV3fX:x0 y:y1 z:z0 in:drawableId. + device glxV3fX:x0 y:y0 z:z0 in:drawableId. + device glxEndLineIn:drawableId. + + device glxBeginLineIn:drawableId. + device glxV3fX:x0 y:y1 z:z1 in:drawableId. + device glxV3fX:x0 y:y0 z:z1 in:drawableId. + device glxEndLineIn:drawableId. + + loVCols do:[:aCol||y| + y := (aCol yValueAt:anIndex) asFloat. + + device glxBeginLineIn:drawableId. + device glxV3fX:x0 y:y z:z0 in:drawableId. + device glxV3fX:x0 y:y z:z1 in:drawableId. + device glxEndLineIn:drawableId. + ] + ] + +! ! + +!GraphColumnView3D::GLXGraph methodsFor:'private redraw'! + +criticalRedrawRoutine + "update all critical resources + " + removeFunc ifTrue:[ + loVCols := nil. + loVRefs := nil. + + glxObjFunc notNil ifTrue:[ + self deleteObject:glxObjFunc. + glxObjFunc := nil + ]. + removeFunc := false. + ]. + + removeRefs ifTrue:[ + loVRefs := nil. + + glxObjRefs notNil ifTrue:[ + self deleteObject:glxObjRefs. + glxObjRefs := nil. + ]. + removeRefs := false. + ]. + + removeGrid ifTrue:[ + glxObjGrid notNil ifTrue:[ + self deleteObject:glxObjGrid. + glxObjGrid := nil. + ]. + removeGrid := false. + ]. + + removeAxis ifTrue:[ + glxObjAxis notNil ifTrue:[ + self deleteObject:glxObjAxis. + glxObjAxis := nil. + ]. + removeAxis := false. + ]. + + shown ifTrue:[ + self redrawInBackBuffer. + self swapBuffers. + ] ifFalse:[ + colorMap := Dictionary new + ]. + + +! + redrawInBackBuffer "redraw in back " - |sY sX sZ noCols dY winSize w2 refList loCols| + |sY sX sZ noCols dY winSize w2 showRefs showGrid showFunc showAxis| self setColor:(graph backgroundColor). self clear. - (loCols := graph listOfVisibleColumns) isEmpty ifTrue:[ "/ no shown columns + loVCols isNil ifTrue:[ + loVCols := graph listOfVisibleColumns + ]. + + (noCols := loVCols size) == 0 ifTrue:[ ^ self ]. - noCols := loCols size. - winSize := graph windowSize. - - (graph showGrid and:[glxObjGrid isNil]) ifTrue:[ - self makeObject:(glxObjGrid := self newObjectId). - self redrawGridFor:loCols. - self closeObject. + ((showGrid := graph showGrid) and:[glxObjGrid isNil]) ifTrue:[ + noCols > 1 ifTrue:[glxObjGrid := self make:#makeGrid] + ifFalse:[showGrid := false] ]. - (graph showGraph and:[glxObjFcts isNil]) ifTrue:[ - self makeObject:(glxObjFcts := self newObjectId). - self redrawGraphFor:loCols. - self closeObject. + ((showFunc := graph showGraph) and:[glxObjFunc isNil]) ifTrue:[ + glxObjFunc := self make:#makeFunc ]. - (graph showAxis and:[glxObjAxis isNil]) ifTrue:[ - self makeObject:(glxObjAxis := self newObjectId). - self redrawAxisFor:loCols. - self closeObject. + ((showAxis := graph showAxis) and:[glxObjAxis isNil]) ifTrue:[ + glxObjAxis := self make:#makeAxis ]. - (graph showReferences and:[glxObjRefs isNil]) ifTrue:[ - refList := graph listOfVisibleRefIndices. - - refList notEmpty ifTrue:[ - self makeObject:(glxObjRefs := self newObjectId). - self redrawReferences:refList for:loCols. - self closeObject. - ] + ((showRefs := graph showReferences) and:[glxObjRefs isNil]) ifTrue:[ + loVRefs isNil ifTrue:[ + loVRefs := graph listOfVisibleRefIndices + ]. + loVRefs notEmpty ifTrue:[ glxObjRefs := self make:#makeRefs ] + ifFalse:[ showRefs := false ] ]. + winSize := graph windowSize. sZ := graph zoomZ * (1.0 / noCols). w2 := width // 2. @@ -693,7 +791,6 @@ sX := sX / (width / winSize). sX := 2.0 / (winSize + sX). - dY := (maxY - minY) / 2. sY := ((0.5 / (dY max:2.0)) min:sX) * graph zoomY. @@ -706,142 +803,12 @@ y:(dY - maxY) "/ translate to center z:(noCols - 1 / -2.0). "/ rotate center line - graph showGrid ifTrue:[ self callObject:glxObjGrid ]. - graph showGraph ifTrue:[ self callObject:glxObjFcts ]. - graph showAxis ifTrue:[ self callObject:glxObjAxis ]. - graph showReferences ifTrue:[ self callObject:glxObjRefs ]. + showGrid ifTrue:[ self callObject:glxObjGrid ]. + showFunc ifTrue:[ self callObject:glxObjFunc ]. + showAxis ifTrue:[ self callObject:glxObjAxis ]. + showRefs ifTrue:[ self callObject:glxObjRefs ]. self popMatrix. -! - -redrawReferences:aListOfReferences for:aListOfCols - "redraw current visible references - " - |y0 y1 z0 z1 x0| - - y0 := minY asFloat. - y1 := maxY asFloat. - z0 := -0.1. - z1 := aListOfCols size - 0.9. - - self setColor:(graph referenceColor). - - aListOfReferences do:[:anIndex| - x0 := anIndex asFloat. - - device glxBeginLineIn:drawableId. - device glxV3fX:x0 y:y1 z:z0 in:drawableId. - device glxV3fX:x0 y:y0 z:z0 in:drawableId. - device glxEndLineIn:drawableId. - - device glxBeginLineIn:drawableId. - device glxV3fX:x0 y:y1 z:z1 in:drawableId. - device glxV3fX:x0 y:y0 z:z1 in:drawableId. - device glxEndLineIn:drawableId. - - aListOfCols do:[:aCol||y| - y := (aCol yValueAt:anIndex) asFloat. - - device glxBeginLineIn:drawableId. - device glxV3fX:x0 y:y z:z0 in:drawableId. - device glxV3fX:x0 y:y z:z1 in:drawableId. - device glxEndLineIn:drawableId. - ] - ] - -! ! - -!GraphColumnView3D::GLXGraph methodsFor:'event handling'! - -buttonPress:button x:x y:y - "delegate button to graph - " - graph buttonPress:button x:x y:y -! ! - -!GraphColumnView3D::GLXGraph methodsFor:'initialization'! - -destroy - "remove dependencies - " - super destroy. - self deleteAllObjects. - self freeObjectsDo:nil. -! - -for:aGraph - graph := aGraph -! - -initialize - "setup default values - " - super initialize. - - type := #colorIndexDoubleBuffer. "/ works on any device - colorMap := Dictionary new. - maxY := 1.0. - minY := -1.0. - removeFcts := false. - removeRefs := false. - removeGrid := false. - removeAxis := false. - - redrawLock := Semaphore forMutualExclusion. -! - -realize - "define orthogonal projection; switch to back buffer drawing - " - super realize. - device glxOrthoLeft:-1.0 right:1.0 bottom:-1.0 top:1.0 near:10.0 far:-10.0 in:drawableId. - self backBuffer. - -! - -unrealize - "clear colorMap and objects - " - super unrealize. - - self deleteAllObjects. - self freeObjectsDo:[ - colorMap := Dictionary new. - ]. - -! ! - -!GraphColumnView3D::GLXGraph methodsFor:'private'! - -freeObjectsDo:aBlock - |id| - - redrawLock critical:[ - id := glxObjFcts printString. - - (removeFcts and:[glxObjFcts notNil]) ifTrue:[ - self deleteObject:glxObjFcts. - glxObjFcts := nil. - ]. - - (removeRefs and:[glxObjRefs notNil]) ifTrue:[ - self deleteObject:glxObjRefs. - glxObjRefs := nil. - ]. - - (removeGrid and:[glxObjGrid notNil]) ifTrue:[ - self deleteObject:glxObjGrid. - glxObjGrid := nil. - ]. - - (removeAxis and:[glxObjAxis notNil]) ifTrue:[ - self deleteObject:glxObjAxis. - glxObjAxis := nil. - ]. - - removeAxis := removeGrid := removeRefs := removeFcts := false. - aBlock value. - ] ! @@ -866,10 +833,38 @@ self color:index. +! ! + +!GraphColumnView3D::GLXGraph methodsFor:'redraw'! + +invalidate + + lockCriticalTask critical:[ + isInvalid := true. + + criticalTask isNil ifTrue:[ + criticalTask := [ + [ |repeat| + + lockCriticalTask critical:[ + (repeat := isInvalid) ifTrue:[isInvalid := false] + ifFalse:[criticalTask := nil] + ]. + repeat ifTrue:[ self criticalRedrawRoutine ]. + repeat + + ] whileTrue:[ Processor yield ]. + + ] forkAt:( Processor activePriority - 1 ). + ] + ] + ! -stepZ - ^ 1.0 +redraw + "redraw + " + self invalidate ! ! !GraphColumnView3D::GLXGraph methodsFor:'removing'! @@ -877,8 +872,8 @@ deleteAllObjects "delete all graphical objects " - removeGrid := removeAxis := removeFcts := removeRefs := true. - + removeGrid := removeAxis := removeFunc := removeRefs := true. + self invalidate. ! deleteAxis @@ -888,7 +883,7 @@ deleteColumns "delete the columns " - removeFcts := true. + removeFunc := true. ! deleteGrid @@ -906,5 +901,5 @@ !GraphColumnView3D class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libwidg2/GraphColumnView3D.st,v 1.4 1998-03-05 19:43:24 ca Exp $' + ^ '$Header: /cvs/stx/stx/libwidg2/GraphColumnView3D.st,v 1.5 1998-03-06 09:30:58 ca Exp $' ! !