Commit ecbd777d authored by Claes Sjofors's avatar Claes Sjofors

Ge graph, export as image

parent c5a90a97
......@@ -226,6 +226,14 @@ void Graph::print( char *filename)
grow_Print( grow->ctx, filename, 0, 0, 1);
}
//
// Export to image file
//
int Graph::export_image( char *filename)
{
return grow_ExportImage( grow->ctx, filename);
}
//
// Rotate
//
......
......@@ -535,6 +535,10 @@ class Graph {
/*! \param filename Name of postscript file. */
void print( char *filename);
//! Print to image file.
/*! \param filename Name of image file. */
int export_image( char *filename);
//! Zoom with a specifed zoom factor.
/*! \param zoom_factor Zoom factor. */
void zoom( double zoom_factor);
......
......@@ -219,7 +219,7 @@ dcli_tCmdTable graph_command_table[] = {
{
"EXPORT",
&graph_export_func,
{"dcli_arg1", "/SIGNATURE", ""}
{"dcli_arg1", "/SIGNATURE", "/FILE", ""}
},
{
"DISABLE",
......@@ -1709,6 +1709,22 @@ static int graph_export_func( void *client_data,
graph->message( 'I', "This graph is not java frame or applet");
}
}
else if ( cdh_NoCaseStrncmp( arg1_str, "IMAGE", strlen( arg1_str)) == 0) {
char file_str[120];
int sts;
if ( EVEN( dcli_get_qualifier( "/FILE", file_str, sizeof(file_str)))) {
graph->message('E', "Enter file");
return GE__FILENAME;
}
sts = graph->export_image( file_str);
if ( EVEN(sts)) {
graph->message('E', "Export error");
}
else
graph->message('E', "Graph exported");
}
else
{
graph->message('E', "Syntax error");
......
......@@ -2556,6 +2556,32 @@ void GlowDrawGtk::buffer_background( DrawWind *wind)
}
}
int GlowDrawGtk::export_image( char *filename)
{
DrawWindGtk *w = &m_wind;
int window_width = ctx->mw.window_width;
int window_height = ctx->mw.window_height;
GdkPixbuf *image;
gboolean sts;
if ( w->double_buffer_on)
image = gdk_pixbuf_get_from_drawable( NULL, w->buffer, 0,
0, 0, 0, 0, w->buffer_width,
w->buffer_height);
else
image = gdk_pixbuf_get_from_drawable( NULL, w->window, 0,
0, 0, 0, 0, window_width,
window_height);
if ( !image)
return 0;
sts = gdk_pixbuf_save( image, filename, "png", NULL, "compression", "9", NULL);
if ( sts == 0)
return 0;
return 1;
}
int GlowDrawGtk::print( char *filename, double x0, double x1, int end)
{
......
......@@ -185,6 +185,7 @@ class GlowDrawGtk : public GlowDraw {
virtual void delete_buffer( GlowWind *w);
virtual void buffer_background( DrawWind *w);
virtual int print( char *filename, double x0, double x1, int end);
virtual int export_image( char *filename);
void set_clip( DrawWind *w, GdkGC *gc);
void reset_clip( DrawWind *w, GdkGC *gc);
......
......@@ -660,6 +660,11 @@ void GlowCtx::print( char *filename, double x0, double x1, int end)
gdraw->print( filename, x0, x1, end);
}
int GlowCtx::export_image( char *filename)
{
return gdraw->export_image( filename);
}
void GlowCtx::draw( GlowWind *w, int ll_x, int ll_y, int ur_x, int ur_y)
{
int i;
......
......@@ -481,7 +481,10 @@ class GlowCtx {
void print( double ll_x, double ll_y, double ur_x, double ur_y);
//! Print to postscript.
void print( char *filename, double x0, double x1, int end);
void print( char *filename, double x0, double x1, int end);
//! Export to image file.
int export_image( char *filename);
//! Redraw an area of the window.
/*!
......
......@@ -138,7 +138,8 @@ class GlowDraw {
virtual int create_buffer( GlowWind *w) {return 1;}
virtual void delete_buffer( GlowWind *w) {}
virtual void buffer_background( GlowWind *w) {}
virtual int print( char *filename, double x0, double x1, int end) { return 1;};
virtual int export_image( char *filename) { return 1;}
virtual int print( char *filename, double x0, double x1, int end) { return 1;}
//virtual void set_clip( DrawWind *w, GC gc) {}
//virtual void reset_clip( DrawWind *w, GC gc) {}
......
......@@ -579,6 +579,11 @@ void grow_Print( grow_tCtx ctx, char *filename, double x0, double x1, int end)
ctx->print( filename, x0, x1, end);
}
int grow_ExportImage( grow_tCtx ctx, char *filename)
{
return ctx->export_image( filename);
}
void grow_GetUserData( grow_tObject object, void **user_data)
{
((GlowArrayElem *)object)->get_user_data( user_data);
......
......@@ -608,6 +608,9 @@ extern "C" {
//! Print context to postscript file.
void grow_Print( grow_tCtx ctx, char *filename, double x0, double x1, int end);
//! Print graph to image file.
int grow_ExportImage( grow_tCtx ctx, char *filename);
//! Get user data of an object.
/*!
\param object Object.
......
......@@ -442,6 +442,10 @@ XttGeGtk::XttGeGtk( GtkWidget *xg_parent_wid, void *xg_parent_ctx, const char *x
gtk_window_maximize( GTK_WINDOW(toplevel));
else if ( options & ge_mOptions_Iconify)
gtk_window_iconify( GTK_WINDOW(toplevel));
else if ( options & ge_mOptions_Iconify)
gtk_window_iconify( GTK_WINDOW(toplevel));
else if ( options & ge_mOptions_Invisible)
g_object_set( toplevel, "visible", FALSE, NULL);
}
static gint confirm_delete_event( GtkWidget *w, GdkEvent *event, gpointer ge)
......
......@@ -214,6 +214,14 @@ void XttGe::print()
system(cmd);
}
void XttGe::export_image( char *filename)
{
pwr_tFileName fname;
dcli_translate_filename( fname, filename);
graph->export_image( fname);
}
void XttGe::swap( int mode)
{
graph->swap( mode);
......
......@@ -87,6 +87,7 @@ class XttGe {
void message( char severity, const char *msg);
void print();
void export_image( char *filename);
int set_object_focus( const char *name, int empty);
int set_folder_index( const char *name, int idx);
int set_subwindow_source( const char *name, char *source, char *object);
......
......@@ -193,7 +193,8 @@ typedef enum {
ge_mOptions_FullScreen = 1 << 0,
ge_mOptions_Maximize = 1 << 1,
ge_mOptions_FullMaximize = 1 << 2,
ge_mOptions_Iconify = 1 << 3
ge_mOptions_Iconify = 1 << 3,
ge_mOptions_Invisible = 1 << 4
} ge_mOptions;
typedef enum {
......
......@@ -228,6 +228,8 @@ static int xnav_check_func( void *client_data,
void *client_flag);
static int xnav_print_func( void *client_data,
void *client_flag);
static int xnav_export_func( void *client_data,
void *client_flag);
static int xnav_sound_func( void *client_data,
void *client_flag);
static int xnav_write_func( void *client_data,
......@@ -258,7 +260,7 @@ dcli_tCmdTable xnav_command_table[] = {
"/INSTANCE", "/COLLECT", "/FOCUS", "/INPUTEMPTY",
"/ENTRY", "/TITLE", "/ACCESS", "/CLASSGRAPH", "/PARENT", "/BYPASS",
"/CLOSEBUTTON", "/TARGET", "/TRIGGER", "/TYPE", "/FTYPE",
"/FULLSCREEN", "/MAXIMIZE", "/FULLMAXIMIZE", "/ICONIFY", ""}
"/FULLSCREEN", "/MAXIMIZE", "/FULLMAXIMIZE", "/ICONIFY", "/HIDE", ""}
},
{
"CLOSE",
......@@ -388,6 +390,13 @@ dcli_tCmdTable xnav_command_table[] = {
"/OBJECT", "/CLASSGRAPH", "/INSTANCE",
""}
},
{
"EXPORT",
&xnav_export_func,
{ "dcli_arg1", "/GRAPH", "/NAME", "/FILE",
"/OBJECT", "/CLASSGRAPH", "/INSTANCE",
""}
},
{
"SOUND",
&xnav_sound_func,
......@@ -2486,6 +2495,8 @@ static int xnav_open_func( void *client_data,
options |= ge_mOptions_FullMaximize;
if ( ODD( dcli_get_qualifier( "/ICONIFY", 0, 0)))
options |= ge_mOptions_Iconify;
if ( ODD( dcli_get_qualifier( "/HIDE", 0, 0)))
options |= ge_mOptions_Invisible;
if ( ODD( dcli_get_qualifier( "/INSTANCE", instance_str, sizeof(instance_str)))) {
......@@ -5617,6 +5628,130 @@ static int xnav_print_func(void *client_data,
return XNAV__SUCCESS;
}
static int xnav_export_func(void *client_data,
void *client_flag)
{
XNav *xnav = (XNav *)client_data;
char arg1_str[80];
int arg1_sts;
arg1_sts = dcli_get_qualifier( "dcli_arg1", arg1_str, sizeof(arg1_str));
if ( cdh_NoCaseStrncmp( arg1_str, "GRAPH", strlen( arg1_str)) == 0)
{
pwr_tFileName file_str;
pwr_tFileName graph_str;
pwr_tAName instance_str;
XttGe *gectx;
pwr_tFileName fname;
int classgraph;
char *instance_p;
int sts;
if ( ODD( dcli_get_qualifier( "/INSTANCE", instance_str, sizeof(instance_str)))) {
instance_p = instance_str;
}
else
instance_p = 0;
if ( ODD( dcli_get_qualifier( "/CLASSGRAPH", 0, 0))) {
classgraph = 1;
if ( !instance_p) {
xnav->message('E', "Instance is missing");
return XNAV__HOLDCOMMAND;
}
}
else
classgraph = 0;
if ( EVEN( dcli_get_qualifier( "/file", file_str, sizeof(file_str)))) {
xnav->message('E', "File is missing");
return XNAV__HOLDCOMMAND;
}
if ( ODD( dcli_get_qualifier( "/GRAPH", graph_str, sizeof(graph_str)))) {
// Get base class graphs on $pwr_exe
cdh_ToLower( graph_str, graph_str);
}
else if ( classgraph) {
// Get file from class of instance object
pwr_sAttrRef aref;
pwr_tObjName cname;
pwr_tCid cid;
pwr_tFileName found_file;
if ( !instance_p) {
xnav->message('E',"Enter instance object");
return XNAV__HOLDCOMMAND;
}
sts = gdh_NameToAttrref( pwr_cNObjid, instance_p, &aref);
if ( EVEN(sts)) {
xnav->message('E',"Instance object not found");
return XNAV__HOLDCOMMAND;
}
sts = gdh_GetAttrRefTid( &aref, &cid);
while ( ODD(sts)) {
// Try all superclasses
sts = gdh_ObjidToName( cdh_ClassIdToObjid( cid), cname, sizeof(cname),
cdh_mName_object);
if ( EVEN(sts)) return sts;
cdh_ToLower( cname, cname);
if ( cdh_CidToVid(cid) < cdh_cUserClassVolMin ||
(cdh_CidToVid(cid) >= cdh_cManufactClassVolMin &&
cdh_CidToVid(cid) <= cdh_cManufactClassVolMax)) {
if ( cname[0] == '$')
sprintf( graph_str, "pwr_c_%s", &cname[1]);
else
sprintf( graph_str, "pwr_c_%s", cname);
}
else
strcpy( graph_str, cname);
// Get base class graphs on $pwr_exe
cdh_ToLower( fname, graph_str);
if ( instance_p &&
(cdh_NoCaseStrncmp( fname, "pwr_c_", 6) == 0 ||
cdh_NoCaseStrncmp( fname, "pwr_c_", 6) == 0)) {
strcpy( fname, "$pwr_exe/");
strcat( fname, graph_str);
strcpy( graph_str, fname);
}
else {
strcpy( fname, "$pwrp_exe/");
strcat( fname, graph_str);
strcpy( graph_str, fname);
}
strcat( fname, ".pwg");
sts = dcli_search_file( fname, found_file, DCLI_DIR_SEARCH_INIT);
dcli_search_file( fname, found_file, DCLI_DIR_SEARCH_END);
if ( ODD(sts)) break;
sts = gdh_GetSuperClass( cid, &cid, aref.Objid);
}
if ( EVEN(sts)) {
xnav->message('E',"No classgraph found");
return XNAV__HOLDCOMMAND;
}
}
if ( xnav->appl.find( applist_eType_Graph, graph_str, instance_p,
(void **) &gectx))
gectx->export_image( file_str);
else {
xnav->message('E', "Graph not found");
return XNAV__HOLDCOMMAND;
}
}
else
xnav->message('E',"Syntax error");
return XNAV__SUCCESS;
}
static int xnav_sound_func(void *client_data,
void *client_flag)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment