Beijer Electronics (formerly QSI Corporation)

Manufacturer of Mobile Data and Human Machine Interface Terminals.
It is currently Fri Nov 24, 2017 6:15 am

All times are UTC - 7 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Best way to do graphics
PostPosted: Thu Jan 06, 2011 4:14 pm 
Offline

Joined: Fri May 28, 2010 6:35 am
Posts: 22
I need to make my own graphics screen using lines or something. what is the best way to do that? do I draw on some off screen canvas and then copy it to a panel?

what i really need is a graph where i can plot thousands of points on a custom x,y scale. the existing components didn't seem to fit the bill.

Thanks for any help on the best way to do this.

Thanks,

jv


Top
 Profile  
 
PostPosted: Fri Jan 07, 2011 9:17 am 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
Have you tried using the PlotTraceV2 object in the Extra library?

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
PostPosted: Fri Jan 07, 2011 11:56 am 
Offline

Joined: Fri May 28, 2010 6:35 am
Posts: 22
I looked at it but didn't try to use it. The pop up help was confusing and contradicted itself (it talks about motors? the fastdraw property and the numtracepoints contradict each other around 100 points) of and seems to imply that 100 is a lot of points. I may have 10's of thousands of points to plot.

Obviously I won't have the resolution to display it all but another alternative I am considering is doing a rolling average of my own and use trend plot component.

My other other idea is plot my own dots. I don't plan on keeping more than a 100 points at a time in memory I was hoping to find some canvas or other image object that I could draw into and then redisplay it as needed.

jv


Top
 Profile  
 
PostPosted: Fri Jan 07, 2011 12:16 pm 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
Here's some example code where I'm drawing points to a ScreenV2. Create a ScreenV2 object and copy this code into it's "Code View".

Code:
func Draw(pass as boolean)
    handles MSG_DRAW
    if pass then
        return
    endif
    default (pass)

    SetFGColor(rgb_black)
    SetPixel(1,1)
    SetPixel(10,10)
    SetPixel(11,11)
endfunc

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
PostPosted: Fri Jan 07, 2011 12:28 pm 
Offline
QSI Support
QSI Support
User avatar

Joined: Wed Mar 08, 2006 12:25 pm
Posts: 881
Location: Salt Lake City, Utah
You might consider seeing what the PlotTrace will do for you. 100 trace points is a lot *if* you are using the slow draw technique. If you are using fast draw, you can go much higher (although I don't have a good upper limit to give you). The slow draw technique draws many individual lines, calculating a gradient between them. The fast draw draws a single polyline.

Now, it is possible if the number of points is high enough that even a single polyline may not be fast enough. Then your idea of a canvas is not a bad one. The only real problem with it is that we don't have a good object to do quite what you want, which would put you in the realm of creating your own object. Here is the code for a quick and dirty one that I wrote, that uses the canvas technique. (There is still a ton of missing stuff such as dealing with colors, scaling the axes and much more).

I selected Edit->Add/Edit Templates->New Template->Create A completely Blank Template. I selected Template name="TestCanvas" and Object type="Area Object".

I then put the following code into that template:
Code:
'*******************************************************************
'Object:        <New Object>
'Author:        <New Author>
'Date:          06 Oct 2010
'
'Description:   <Place your descripiton here>
'
'Version:       1.01
'Copyright 2001 <Modify the copyright to suit your needs>
'*******************************************************************



library standard source ToolMessages

dim enabled as boolean
init enabled := true
func enabled(newval as boolean)
    enabled := newval
    Enable (me, enabled)
endfunc

dim parent as objref
init parent := default
func parent(newval as objref)
    parent := newval
    Attach(me, parent)
endfunc

dim xPos as integer
init xPos := 0
func xPos(newval as integer)
    xPos := newVal
    Relocate (me, xPos, yPos)
endfunc

dim yPos as integer
init yPos := 0
func yPos(newval as integer)
    yPos := newval
    Relocate (me, xPos, yPos)
endfunc

dim width as integer
init width := 25
func width(newval as integer)
    width := newval
    Resize (me, width, height)
endfunc

dim height as integer
init height := 25
func height(newval as integer)
    height := newval
    Resize (me, width, height)
endfunc

func StartUp()
    handles MSG_INIT
    Relocate (me, xPos, yPos)
    Resize (me, width, height)
    Enable (me, enabled)
    Attach (me, parent)
endfunc


func Draw()
    handles MSG_DRAW

    if len(pixmap) > 0 then
        DrawPixmap(xPos, yPos, pixmap, pw, ph)
    else
        SetBgColor(rgb_black)
        SetFgColor(rgb_black)
        DrawBox (xpos, ypos, xPos+width-1, yPos+height-1)
    endif

    SetFgColor(rgb_red)
    SetBgColor(rgb_black)
    if len(xPts) > 1 then
        DrawPolygon (xPts, yPts, POLY_NOCONNECT)
        redim (xPts, 1) 'Leave the last coordinate in there for reference for the next draw
        redim (yPts, 1) 'Leave the last coordinate in there for reference for the next draw
    endif

    pixmap = GetObjPixmap(pw, ph)
endfunc

private dim xpts[], ypts[] as integer
private dim pixmap[] as byte
private dim pw, ph as integer

func PlotPoint (x as integer, y as integer)
    dim leng as integer
    leng = len(xpts)

    redim (xpts, leng+1)
    redim (ypts, leng+1)
    xpts[leng] := x + xPos
    ypts[leng] := y + yPos
    rerender (me)
endfunc

'The rest of these functions add functionality to the PC development tool.  The
'#if _TOOL line ensures that the code will not be compiled into a BFF that
'is loaded into the terminal

'These functions are called in response to actions taken in the PC development tool.
'If as a result of these actions you change one or more of the properties of
'this object that should be permanently recorded (for instance changing xPos in
'response to MSG_TOOL_MOVE) then you should call Tool_Persist to save the new
'value of the property in your source code of your object instance

#if _TOOL
'This function is called by the PC development tool, when you change the attachment
'of an object (i.e. in response to dragging it around the object tree).
'Note: the purpose of this function is to allow you to attach to another
'container, you should not change your parent property or call Tool_Persist
'until you receive a MSG_TOOL_ATTACHED.  A MSG_TOOL_ATTACHED will be sent
'in response to an Attach API function call.
func ToolAttach (attachTo as objref)
    handles MSG_TOOL_ATTACH

    Attach (me, attachTo)
endfunc

'This function is called in response to calling Attach (primarily in a
'handler for MSG_TOOL_ATTACH, but possibly in other places as well_.
func ToolAttached (newParent as objref)
    handles MSG_TOOL_ATTACHED

    'Set our parent property to reflect who we are attached to and save
    parent := newParent
    Tool_Persist (parent) 'Save parent
endfunc

'This function is called when the user drags an object instance with the
'mouse in the PC development tool.  dx and dy are relative offsets from the current
'location of the object
func ToolMove (dx as integer, dy as integer)
    handles MSG_TOOL_MOVE

    xPos := xPos + dx
    yPos := yPos + dy
    Relocate (me, xPos, yPos)

    'Save the changes we just made
    Tool_Persist (xPos)
    Tool_Persist (yPos)
endfunc

'This function is called by the PC development tool to obtain the coordinates of
'the resize grips.  The arrays xCoords, yCoords, and cursors all contain 0
'elements initially.  This means that you should either call redim on those
'arrays and set their values, or declare local arrays, set the values of
'the local arrays, and then assign xCoords, yCoords and cursors to those
'local arrays. Closed indicates whether the Foundry should connect the
'first and last grips to make a closed object.  xCoords, yCoords, and
'cursors should all contain the same number of elements when this function
'completes
func ToolGetHandles (xCoords[] as reference to integer, ->
                     yCoords[] as reference to integer, ->
                     cursors[] as reference to GuiCursors, ->
                     closed as reference to boolean)
    handles MSG_TOOL_GETHANDLES

    'Call a standard function to handle common functionality.
    'You can omit this function call and implement your own custom functionality
    'if desired
    _ToolGetHandles (xCoords, yCoords, cursors, closed, xPos, yPos, width, height)

endfunc

'This function is called in response to a user moving a resize grip within
'the PC development tool.  handleNum is the index into the arrays that were returned
'by the handler for MSG_TOOL_GETHANDLES.  You should return true from this
'function
func ToolMoveHandle (handleNum as reference to integer, dx as integer, dy as integer)
    handles MSG_TOOL_MOVEHANDLE

    'Call a standard function to handle common functionality.
    'You can omit this function call and implement your own custom functionality
    'if desired
    _ToolMoveHandle (handleNum, dx, dy, xPos, yPos, width, height, me)

endfunc

'This function is called when the user created an instance of this template by
'selecting it from the object palette and dragging it in the layout view.
'The handler for MSG_INIT is not called automatically, and if you want it
'called, you should call it manually.
'You should call Tool_Persist on all the properties that you set up in this
'message handler.  (x1, y1) are the coordinates that the user started his
'drag and (x2, y2) are the coordinates that the mouse was released
func ToolDragCreate (parentObj as objref, x1 as integer, y1 as integer, ->
                     x2 as integer, y2 as integer)
    handles MSG_TOOL_DRAGCREATE

    'Call a standard function to handle common functionality.
    'You can omit this function call and implement your own custom functionality
    'if desired
    _ToolDragCreate (parentObj, x1, y1, x2, y2, xPos, yPos, width, height, parent)

    'Call our MSG_INIT handler
    StartUp()
endfunc

#endif



Finally, to test it, I created an object called TestCanvas_1 and a button object. In the button object, I added the following click event:
Code:
func click()
    dim i as integer

    for i = integer(4 * GetRandomNum()) to 0 step -1
        TestCanvas_1.PlotPoint(TestCanvas_1.width * GetRandomNum(), testCanvas_1.height * GetRandomNum())
    next
endfunc

_________________
Jeremy
http://www.beijerinc.com


Top
 Profile  
 
PostPosted: Fri Jan 07, 2011 2:10 pm 
Offline

Joined: Fri May 28, 2010 6:35 am
Posts: 22
This looks excellent, thanks!

I will let you know how it goes.

jv


Top
 Profile  
 
PostPosted: Mon Jan 17, 2011 9:23 am 
Offline

Joined: Fri May 28, 2010 6:35 am
Posts: 22
I ended up using plottrace but doing my own point scaling down to a couple hundred points. I didn't want the extra work for this but in the end I am happy with the results and have the extra advantage that I can autoscale the results.

I noticed though that the object has several trace color properties. Does this mean it can display more than one trace? How do I do this? I would like to have another trace and I could do it with a second PlotTrace with invisible background but if there is already a way to do multi traces I would prefer that.

This brings up another more general question: Is there a document that describes the UI objects? The programmer's doc is about the language and the foundry doc is about the tools and besides for the objects themselves I haven't found anything that says how to use them.

thanks,

jv


Top
 Profile  
 
PostPosted: Mon Jan 17, 2011 10:36 am 
Offline
User avatar

Joined: Thu Mar 02, 2006 2:12 pm
Posts: 487
Location: Salt Lake City, Utah
The trace color property lets you have different colors for the same lines. This might be useful to visually see the history of when a line was drawn.

To draw a second set of vector lines, what you would want to do is create another PlotTraceV2, set it's transparent property to true and place it in-front of the other object.

All of the Objects are documented in the auto-doc which can be found under Help->Object Documentation. There's also some Tutorials under the Help menu and some application notes. There's also a summary of objects on the website:
http://www.qsicorp.com/product/qlarity/library.php

_________________
Ron L.

http://www.beijerelectronicsinc.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 7 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group