Re: Beginner Question About CustomView, -drawRect: and Plotting Data.
Re: Beginner Question About CustomView, -drawRect: and Plotting Data.
- Subject: Re: Beginner Question About CustomView, -drawRect: and Plotting Data.
- From: Daniel J Farrell <email@hidden>
- Date: Tue, 27 Jun 2006 23:40:54 +0100
Hi folks,
This is getting a bit too complicated for me to understand now!
However, I've managed (finally after several hours) to get something
to work from the first suggestion.
Have a look here:
http://www.boyfarrell.com/xcode/PlotView.dmg
(explanation of in the PS)
However, could somebody explain this:
Current I have quite a traditional programme style where I initialise
all my objects an run code from the main.m file. I'm not to sure how
to integrate this method of working with the new code that plots the
data? All the number crunching happens inside my Model class do I
just have to paste all my current main.m code into the -init method
of the model so that if runs when it is called? Or is there a more
elegant solution?
Hope you can see what I'm getting at? I'm just having to completely
change the way I've been working for the last year, it seems a bit
alien not doing everything from your main.m, instead you just have
one line in there:
return NSApplicationMain(argc, (const char **) argv);
Regards,
Daniel.
PS - This is how it works:
(The programme probably leaks like crazy, I've not been too careful,
just wanted something that worked!)
#1 The CustomView
I have made a subclass of NSView called QDCPlotView. This has all the
instance variables and methods need to make a plot with NSBezierPath.
i.e. I added methods that transform from the NSView coordinate system
to the data's coordinate system (these methods are called -
coordinateForXData:MinRange:MaxRange:Bounds: there is also one for Y
coodinates) and the usual setter and getter methods. It also
contained a copy of the data passed in from the controller.
#2 The Controller
I then made a Controller class which I hooked up to the View and the
Model Classes. In this way (because the controller has both the View
and Model as instance variables) the Model data could be stored in
the view class, ready to be plotted. I gave the Controller a action
(using interface builder) method -plot and also a -plotDataX:Y:
method. The -plot method is just a wrapper that calls the -
plotDataX:Y method when the button is pressed.
#3 The Model
Well not much here really! I just make an NSArray holding some numbers
On 27 Jun 2006, at 15:38, Janek Priimann wrote:
Plot your data into an offscreen buffer and then then draw the
resulting image in your custom view (NSGraphicsContext +
NSBitmapImageRep or CGContext + CGImage). OR do as you suggested.
For example:
- (void)drawRect:rect x:x y:y
{
[self setX:x y:y];
[self setNeedsDisplayInRect:rect];
}
On 6/27/06, Daniel J Farrell < email@hidden> wrote:
Hi Atze,
Thanks for that.
From reading the documentation on -display I see it calls -drawRect.
I'm not so clear on how to pass in the data (see below)? You suggest
that I add an instance variable to the custom view class.
Do you think this will work:
Add a new instance variable to the custom view class:
NSPointArray data;
Then add an method such as -setData: to fill this with NSPoint values.
Then change the -drawRect: method to always draw the data that is in
it's data instance.
How do I get the data into the -setData: method in the first place?
You see, I would like my programme to every now again send some data
for plotting to the custom view class once it has finished a
particular chunk of computation. I don't require a GUI because I'm
just number crunching. The way I work at the moment is to just go
into the code change the path to the initial data and recompile (the
programme is fairly small and only takes seconds to build). It's the
computation on this initial data (as it becomes more refined) that I
to set to the setData: method for plotting, every few seconds.
Regards,
Daniel.
On 27 Jun 2006, at 12:33, Alexander Spohr wrote:
>
> Am 27.06.2006 um 12:10 schrieb Daniel J Farrell:
>
>> Hi folks,
>>
>> I have a CustomView that does some NSBezierPath drawing from an
>> array of data point that I pass it: I'm plotting some scientific
>> data.
>>
>> At the moment the only way I can get a custom view to draw is my
>> placing the data inside the -drawRect: method. So my question is:
>> How can I make a method that will plot my data on the custom view
>> every time I call the method e.g. something like -
>> drawRect:WithXData:YData: ?
>
> you won't.
> set the data in some ivars, then call -display
> or let your CustomView drag the data in -drawRect:
>
> evething else would be working against the appkit.
>
> atze
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden