Table Of Contents

Graph IDEProgramming ► Graphic View

The following is a complete script for programming a Graphic View. There are a few important ideas demonstrated by the script which are listed as follows:

Programming a Graphic View is not nearly as simple as programming individual graphics and you may want to steer clear of this object. However, if you are a beefy programmer then this section may be for you.

/*
This is a complete example of how to program without any user interaction.
*/

/* Declarations */

@@class() GraphicView:Object

@@method(public, class) (id)stored;
@@method(public, class) (id)alloc;
@@method(public, instance) (id)init;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void)empty;
@@method(public, instance) (void)release;

@@end

@@class() SingleCoordinateGraph:Object

@@method(public, class) (id)stored;
@@method(public, class) (id)alloc;
@@method(public, class) (id)append;
@@method(public, instance) (id)init;
@@method(public, instance) (void)setDoesAutoscaleAfterExecution:(unsigned)doesAutoscaleAfterExecution;
@@method(public, instance) (void)autoscale;
@@method(public, instance) (void)focus;
@@method(public, instance) (void)unfocus;
@@method(public, instance) (void)release;

@@end

@@class() Circle:Object

@@method(public, class) (id)insert;
@@method(public, class) (id)append;
@@method(public, class) (id)alloc;
@@method(public, instance) (id)init;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void)setCurveRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)setInteriorRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)moveCenterToXValue:(double)xValue yValue:(double)yValue;
@@method(public, instance) (void)sizeToCenteredWidth:(double)width height:(double)height;

@@method(public, instance) (void)finalize;
@@method(public, instance) (void)release;

@@end

@@class() Rectangle:Object

@@method(public, class) (id)insert;
@@method(public, class) (id)append;
@@method(public, class) (id)alloc;
@@method(public, instance) (id)init;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (void)setCurveRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)setInteriorRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)moveCenterToXValue:(double)xValue yValue:(double)yValue;
@@method(public, instance) (void)sizeToCenteredWidth:(double)width height:(double)height;

@@method(public, instance) (void)finalize;
@@method(public, instance) (void)release;

@@end

@@class() Function:Object

@@method(public, class) (id)alloc;
@@method(public, class) (id)stored;
@@method(public, class) (id)append;
@@method(public, instance) (id)init;
@@method(public, instance) (void)setSourceCode:(const char *)aString;
@@method(public, instance) (void)emptyData;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (unsigned)recursionCount;
@@method(public, instance) (void)appendXValue:(double)xValue yValue:(double)yValue;
@@method(public, instance) (void)setCurveRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)setInteriorRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)release;

@@end

/* Execution block */

{
id aGraphicView;
id aGraphic, aGraph;
int ii;
unsigned animationCount;
double red, green, blue;

aGraphicView = [GraphicView stored];

animationCount = [aGraphicView animationCount];

[aGraphicView empty];

aGraphic = [Circle append];

red = (animationCount % 10) / 10.0;
green = (animationCount % 20) / 20.0;
blue = 1.0;

[aGraphic setInteriorRed:1.0 green:green blue:1.0 alpha:1.0];
[aGraphic setCurveRed:red green:1.0 blue:1.0 alpha:1.0];
[aGraphic moveCenterToXValue:300.0 yValue:400.0];
[aGraphic sizeToCenteredWidth:50.0 height:200.0];

[aGraphic finalize];

aGraphic = [Rectangle append];

red = (animationCount % 10) / 10.0;
green = (animationCount % 20) / 20.0;
blue = 0.0;

[aGraphic setInteriorRed:red green:green blue:blue alpha:1.0];
[aGraphic setCurveRed:0.0 green:0.0 blue:0.0 alpha:1.0];
[aGraphic moveCenterToXValue:300.0 yValue:400.0];
[aGraphic sizeToCenteredWidth:50.0 height:200.0];

[aGraphic finalize];

aGraph = [SingleCoordinateGraph append];

[aGraph moveCenterToXValue:400.0 yValue:400.0];
[aGraph sizeToCenteredWidth:300.0 height:300.0];
[aGraph setDoesAutoscaleAfterExecution:1];

[aGraph focus];

aGraphic = [Function append];

[aGraphic setSourceCode:"
double cos(double a);

@@class() Function:Object

@@method(public, class) (id)alloc;
@@method(public, class) (id)stored;
@@method(public, class) (id)append;
@@method(public, instance) (id)init;
@@method(public, instance) (void)setSourceCode:(const char *)aString;
@@method(public, instance) (void)emptyData;
@@method(public, instance) (unsigned)animationCount;
@@method(public, instance) (unsigned)recursionCount;
@@method(public, instance) (void)appendXValue:(double)xValue yValue:(double)yValue;
@@method(public, instance) (void)setCurveRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)setInteriorRed:(double)red green:(double)green blue:(double)blue alpha:(double)alpha;
@@method(public, instance) (void)release;

@@end

{
id myFunction;
int ii;
double xValue, yValue;
unsigned animationCount;
unsigned recursionCount;
double red;

myFunction = [MyFunction stored];

animationCount = [myFunction animationCount];
recursionCount = [myFunction recursionCount];

/*
Empty the data and then append new data.
*/

[myFunction emptyData];

for(ii = 0; ii < 500; ii++)
{
xValue = 0.01 * ii + animationCount * 0.5;
yValue = cos(xValue) + recursionCount;
[myFunction appendXValue:xValue yValue:yValue];
}

red = (animationCount % 10) / 10.0;

[myFunction setCurveRed:red green:0.0 blue:0.0 alpha:1.0];

if(recursionCount < 5)
{
[myFunction recur];
}

}"
];

[aGraph unfocus];

[aGraph finalize];

[aGraphicView finalize];

}

The following is API description specific to the Graphic View.

@@method(public, class) (id)stored;
  Call like this:

aGraphicView = [GraphicView stored];

Returns an instance of the receiver class. That instance is stored by the associated Graphic View if the class implements the NSCoding protocol and hence the state is persistent and part of the document when saved and retrieved (see Plugin for additional details). If you call this method to make an instance then do not call release on the return. Reminder: if you use this then make sure to declare the method in a declaration section of the script. As none of the stock classes implement the NSCoding protocol this method is only applicable to custom classes defined in a plugin.

@@method(public, class) (id)alloc;
  Call like this:

[GraphicView alloc];

That allocates a Graphic View object.

@@method(public, instance) (id)init;
  Call like this:

myGraphicView = [[GraphicView alloc] init];

That allocates, initializes and associates the GraphicView object with the focused Graphic View. Make sure the variable assigned to is previously declared as an id type.

@@method(public, instance) (unsigned)animationCount;
  Call like this:

animationCount = [myGraphicView animationCount];

That assigns the Graphic View's animationCount to the variable on the left.

@@method(public, instance) (void)empty;
  Call like this:

[myGraphicView empty];

Removes all graphics from the Graphic View.

@@method(public, instance) (void)release;
  Call like this:

[myGraphicView release];

That releases the previously made Graphic View. It is very important that you release each object that has been previously allocated.




© Copyright 1993-2022 by VVimaging, Inc. (VVI); All Rights Reserved. Please email support@vvi.com with any comments you have concerning this documentation. See Legal for trademark and legal information.