[GRASS5] Embedding GRASS display in my application

Hi,
  Sorry if the question is already answered.
I am creating a s/w using grass at the backend.
I want to show GRASS Display in my app.(in grass
it is in a seperate window). I am using GTK, not Tcl/TK.
Someone please suggest me how to do it?

Currenlty I use PNG driver, create an Image and load that
image into my application, but it is not a good way. Does
implimenting another driver solve the problem? Or can my
application communicate with grass through some fifo, pipe etc\
Or some other simple solution?

Please help...

Thanks and regards,
--
Sajith VK <sajithvk@hotpop.com>
FSFI

Sajith VK wrote:

  Sorry if the question is already answered.
I am creating a s/w using grass at the backend.
I want to show GRASS Display in my app.(in grass
it is in a seperate window). I am using GTK, not Tcl/TK.
Someone please suggest me how to do it?

Currenlty I use PNG driver, create an Image and load that
image into my application, but it is not a good way.

Why not?

Does
implimenting another driver solve the problem? Or can my
application communicate with grass through some fifo, pipe etc\
Or some other simple solution?

Under X, you can set the environment variable XDRIVER_WINDOW to the
XID of an existing X window, and XDRIVER will use that window instead
of creating its own. That won't work on Windows, though.

--
Glynn Clements <glynn.clements@virgin.net>

On Sat, 2004-04-24 at 18:05, Glynn Clements wrote:

> Currenlty I use PNG driver, create an Image and load that
> image into my application, but it is not a good way.

Why not?

  I guess it is less efficient. It need some hardisk access
etc, which can be avoided if we can directly render it. Creating
and loading a new PNG image for each operation (say paning, or
displaying a new layer etc) will impact perfomance.. Correct
me if I am wrong

Under X, you can set the environment variable XDRIVER_WINDOW to the
XID of an existing X window, and XDRIVER will use that window instead
of creating its own. That won't work on Windows, though.

Thanks! it is enough, I dont plan to use my application is windows.
But will it render on my canvas, or in the entire window?
The driver knows only XID of my window, how can it render
on my canvas, which is one amoung several widgets in my window?
My window has menus, toobar etc and a canvas widget on which
I want to render the GRASS display...
(Sorry that I am not familiar with XID etc..., I have started
learning them.....)

Waiting for your comments....
--
"Freedom Matters"
Sajith VK

Sajith VK wrote:

> > Currenlty I use PNG driver, create an Image and load that
> > image into my application, but it is not a good way.
>
> Why not?

  I guess it is less efficient. It need some hardisk access
etc, which can be avoided if we can directly render it. Creating
and loading a new PNG image for each operation (say paning, or
displaying a new layer etc) will impact perfomance.. Correct
me if I am wrong

For most operations, the overhead of writing, reading and rendering
the rasterised image is negligible compared to the effort involved in
actually generating it. Most of the effort tends to be involved in
getting the data from GRASS to the driver.

> Under X, you can set the environment variable XDRIVER_WINDOW to the
> XID of an existing X window, and XDRIVER will use that window instead
> of creating its own. That won't work on Windows, though.

Thanks! it is enough, I dont plan to use my application is windows.
But will it render on my canvas, or in the entire window?
The driver knows only XID of my window, how can it render
on my canvas, which is one amoung several widgets in my window?
My window has menus, toobar etc and a canvas widget on which
I want to render the GRASS display...

In which case, you need to pass the XID of the canvas widget's window,
not the top-level window.

X "windows" aren't limited to top-level windows (the ones with a title
bar etc); each widget normally has its own window. Most toolkits have
some exceptions, e.g. menu items are often "gadgets", which are just
rectangular regions of the parent window, but "canvas" widgets (e.g.
GtkDrawingArea, XmDrawingArea) usually have their own window.

Incidentally, XDRIVER doesn't draw directly onto the window. Instead,
it creates a background pixmap for the window, and draws on that. That
eliminates the need to redraw the window in response to Expose events.

--
Glynn Clements <glynn.clements@virgin.net>

Hi all,
  Thanks Glynn for the help...(And sorry for delay in trying)
It worked perfectly when I passed XID of a window, But nothing
happended when I passwd XID of a gnomecanvas.window...
May be some issue with gnomecanvas or so.. I will try...

B/w I read that display modules and XDRIVER communicates
through sockets/fifo. (Am I correct?).. Can I read the
draw instrucions from the socket/fifo and write myown
functions to render them to my canvas? If possible it offers
me highest flexibility....

Sorry if my question is meaningless, I am just a bigginer
in grass programming....

Thanks for your help,

On Sun, 2004-04-25 at 00:11, Glynn Clements wrote:

> Thanks! it is enough, I dont plan to use my application is windows.
> But will it render on my canvas, or in the entire window?
> The driver knows only XID of my window, how can it render
> on my canvas, which is one amoung several widgets in my window?
> My window has menus, toobar etc and a canvas widget on which
> I want to render the GRASS display...

In which case, you need to pass the XID of the canvas widget's window,
not the top-level window.

X "windows" aren't limited to top-level windows (the ones with a title
bar etc); each widget normally has its own window. Most toolkits have
some exceptions, e.g. menu items are often "gadgets", which are just
rectangular regions of the parent window, but "canvas" widgets (e.g.
GtkDrawingArea, XmDrawingArea) usually have their own window.

Incidentally, XDRIVER doesn't draw directly onto the window. Instead,
it creates a background pixmap for the window, and draws on that. That
eliminates the need to redraw the window in response to Expose events.

--
"Freedom Matters"
Sajith VK

Sajith VK wrote:

  Thanks Glynn for the help...(And sorry for delay in trying)
It worked perfectly when I passed XID of a window, But nothing
happended when I passwd XID of a gnomecanvas.window...
May be some issue with gnomecanvas or so.. I will try...

You need to ensure that your application (or the toolkit) doesn't
either:

a) fill the window with a "background", or

b) replace the window's background pixmap.

as doing either of those will prevent the background pixmap's contents
from being visible.

Essentially, you need to use a "bare" window; one which XDRIVER can
use (almost) exclusively.

B/w I read that display modules and XDRIVER communicates
through sockets/fifo. (Am I correct?).. Can I read the
draw instrucions from the socket/fifo and write myown
functions to render them to my canvas? If possible it offers
me highest flexibility....

You can write your own driver; see src/display/devices/lib for the
framework and default implementations.

However, if you do this, any display commands which your application
spawns will have to run in a separate process or thread. Using e.g.
system("d.rast ...") won't work, as your application will block until
the command completes, but the command won't complete until your
application has read and processed the commands which the program
issues.

--
Glynn Clements <glynn.clements@virgin.net>