Re: [BLACKBOX] Opening an embedded form view

From: [at]} <Antony>
Date: Mon, 14 Dec 2009 00:23:59 -0800


Here's a version with no Model methods:

MODULE SolarTestgraph;

(************************************
 Creating the form with embedded graph
1. Use Controls/New Form to create form, Link: SolarTestgraph
1a. Increase the size of the form
1b. ctrl-space to select the document
1c Increase the size of the document to provide space for the graph
1d Click outside the document to deselect
2. "SolarTestgraph.Deposit; StdCmds.Open" to create a view of the graph.
(you will need to insert a commander right after "2.")
2a. Size the window to fit on the form from 1. The view will be the same size.
2b. ctrl-space to select the view
2c. ctrl-c to copy
3. select the form,
3a. ctrl-v to paste the view
3b. position and size
4. Select the controls, then Alt-Return to use the Inspector to
set the Notifier to SolarTestgraph.Redraw for each control.
4a. Note that there will be buttons for "Deposit" and "ShowGraph" on the form.
Once this form is saved as Solar/Rsrc/Testgraph, then Show"Graph will open another copy of itself.
The Deposit button will have as Link "SolarTestgraph.Deposit".
Clicking on the button will evoke "command error: no deposited view expected"
One has to add "StdCmds.Open" so that the link now reads
"SolarTestgraph.Deposit; StdCmds.Open"
Now the button will work.
These buttons can be removed.
5. Save the form as Solar/Rsrc/Testgraph
*************************************)

IMPORT Views, Models, Ports, Fonts, Properties, Stores, StdCmds;

CONST
minVersion = 0; maxVersion = 0;
xMin = 0; xMax = 100;
yMin = 0; yMax = 1000;
ptMul = Ports.point;

(* absolute left, and top of graphic in frame, in pixels *)
borderXpixels = 20;
borderYpixels = 20;
(* size of graphic in pixels *)
graphXpixels = 300;
graphYpixels = 200;
(* range of values *)
Xrange = xMax - xMin;
Yrange = yMax - yMin;
solid = -1;
outline = 1;


TYPE
View = POINTER TO RECORD (Views.View) END;
Msg = RECORD (Models.Message) END;
VAR
scaleFactor*: INTEGER; (* REAL; *)
Line* : RECORD
yIntercept*: REAL;
slope*: REAL;
END;

PROCEDURE ScaleX( p: REAL): INTEGER;
BEGIN RETURN (SHORT( ENTIER( (1+scaleFactor)/10 * graphXpixels * (p - xMin)/Xrange)) + borderXpixels)*Ports.point;
END ScaleX;

PROCEDURE ScaleY( p: REAL): INTEGER;
BEGIN RETURN (SHORT( ENTIER( (1+scaleFactor)/10 * graphYpixels * (yMax - p)/Yrange)) + borderYpixels)*Ports.point;
END ScaleY;

PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
VAR version: INTEGER;
BEGIN
rd.ReadVersion(minVersion, maxVersion, version)
END Internalize;

PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
BEGIN
wr.WriteVersion(maxVersion)
END Externalize;

PROCEDURE (v: View) HandleModelMsg (VAR msg: Models.Message);
BEGIN
WITH msg: Msg DO
Views.Update(v, Views.keepFrames)
ELSE
END
END HandleModelMsg;
PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: INTEGER);
VAR w, h, i, j: INTEGER;
PROCEDURE drawLine(x, y, x1, y1:REAL; color: Ports.Color);
BEGIN
f.DrawLine( ScaleX(x), ScaleY(y), ScaleX(x1), ScaleY(y1),
outline, color);
END drawLine;


PROCEDURE DrawGraph;

PROCEDURE Draw( y0, dydt: REAL; color: Ports.Color );
(* draw a line passing thru (0,y0) with slope dydt in color *)
VAR x0, x1, y1: REAL;
BEGIN
x1:= xMax;
y1:= y0+dydt*x1;
drawLine( 0, y0, x1, y1, color);
END Draw;

PROCEDURE DrawX ( y: REAL; col: Ports.Color);
(* draw a horizontal line at y *)
BEGIN
drawLine( xMin, y, xMax, y, col);
END DrawX;
PROCEDURE DrawY ( x: REAL; col: Ports.Color);
(* draw a vertical line at x *)
BEGIN
drawLine( x, yMin, x, yMax, col);
END DrawY;

BEGIN (* module specific code here, using frame methods - e.g. f.DrawLine, f.DrawString *)

(* draw limits of graph *)
DrawX(yMin, Ports.black);
DrawX(yMax, Ports.black);
DrawY( xMin, Ports.black);
DrawY( xMax, Ports.black);
Draw( Line.yIntercept, Line.slope, Ports.blue );
END DrawGraph;

BEGIN
v.context.GetSize(w, h);
DrawGraph;
END Restore;

PROCEDURE (v: View) HandlePropMsg (VAR p: Properties.Message);
CONST min = Xrange * Ports.point; max = 2 * Xrange * Ports.point;
minY = Yrange * Ports.point; maxY = 2 * Yrange * Ports.point;
BEGIN
WITH p: Properties.SizePref DO (* prevent illegal sizes *)
IF p.w = Views.undefined THEN
p.w := max
ELSIF p.w < min THEN p.w := min
ELSIF p.w > max THEN p.w := max
END;
IF p.h = Views.undefined THEN p.h := maxY
ELSIF p.h < min THEN p.h := minY
ELSIF p.h > max THEN p.h := maxY
END
| p: Properties.ResizePref DO
p.horFitToWin := TRUE; p.verFitToWin := TRUE
ELSE
END
END HandlePropMsg;
PROCEDURE Redraw*(op, from, to: INTEGER);
VAR msg: Msg;
BEGIN
Views.Omnicast(msg);
END Redraw;

PROCEDURE Deposit*;
VAR v: View;
BEGIN
NEW(v); Views.Deposit(v)
END Deposit;
PROCEDURE ShowGraph*;
BEGIN
StdCmds.OpenAux('Solar/Rsrc/TestGraph', 'Voltage vs Temperature');
END ShowGraph;

BEGIN
scaleFactor:= 2;
Line.yIntercept:= 100;
Line.slope:= 4;
END SolarTestgraph.

---- To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy
Received on Mon Dec 14 2009 - 09:23:59 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:38 UTC