Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on an old C++ Console project which used Flash Graphics to plot data. I wish to upgrade this project so it calls GNUPlot to display the data. The original code was written so that it could accommodate other plotting software by placing all calls to Flash Graphics in a single C++ file so that it should be relatively simple to translate them to similar calls in another plotting package if required. I do not have the old Flash Graphics Libraries/code and so have had to comment out references to them to compile the project.

I understand that GNUPlot is probably one of the better open source plotting packages but cannot get GNUPlot to compile in the project. I think that GNUPlot was more designed to be used via "pipes" from the users project that called on the GNUPLot .exe to plot the data. Either way I'm a bit out of my depth now and would appreciate any help converting the Flash Graphics calls to GNUPlot (or any other plotting package suggested). I'm a newbie C++ student who is learning by customizing an old project but the graphics issue has really bogged me down. Any help would be appreciated. Using VS2008 console project.

C++
/*                                                                            */
/*  GRAPHICS - These are Flash Graphics interface routines.                   */
/*             All routines that are specific to that library are here.       */
/*             Other routines call routines here to do graphics operations.   */
/*                                                                            */
/*  This also includes Symantec text-mode save and restore routines.          */
/*                                                                            */


#include "stdafx.h"

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <conio.h>
#include <ctype.h>
#include <stdlib.h>
#include "disp.h"
#include <dos.h>
#include "const.h"  // System, limitation constants, typedefs, structs
#include "classes.h"  // Includes all class headers
#include "funcdefs.h" // Function prototypes
#include "fg.h"                 // FlashGraphics

static int mode ;           // Display mode
static int drows, dcols ;   // Dimensions in pixels
static int crows, ccols ;   // Size of a character
static double aspect ;      // Aspect ratio




/*
--------------------------------------------------------------------------------

   Call this routine at the start of the program.
   It returns 0 if all went well, 1 if the adapter is not supported.

--------------------------------------------------------------------------------
*/

int init_graphics ()
{
#ifdef FLASH_GRAPHICS
   mode = fg_get_first () ;
   while (mode) {
      if (mode == FG_VGA12) {
         drows = 480 ;
         dcols = 640 ;
         fg_set_8x16_font () ;
         crows = fg.charbox[FG_Y2] + 1 ;
         ccols = fg.charbox[FG_X2] + 1 ;
         aspect = 3.0 / 4.0 ;
         return 0 ;   // Normal return
         }
      mode = fg_get_next () ;
      }

   mode = fg_get_first () ;
   while (mode) {
      if (mode == FG_VESA3) {
         drows = 600 ;
         dcols = 800 ;
         fg_set_8x16_font () ;
         crows = fg.charbox[FG_Y2] + 1 ;
         ccols = fg.charbox[FG_X2] + 1 ;
         aspect = 3.0 / 4.0 ;
         return 0 ;   // Normal return
         }
      mode = fg_get_next () ;
      }

   drows = -1 ; // Flag error
   return 1 ;   // And tell caller
#endif // FLASH_GRAPHICS   
return 1;  // TPR - tell caller there's no graphics
}

/*
--------------------------------------------------------------------------------

   Switch to graphics mode.

--------------------------------------------------------------------------------
*/

void goto_graphics ( int *nrows , int *ncols , int *chrows , int *chcols ,
                     double *aspect_ratio )
{
#ifdef FLASH_GRAPHICS
   if (drows <= 0)
      return ;

   fg_init_mode ( mode ) ;

   *nrows = drows ;
   *ncols = dcols ;
   *aspect_ratio = aspect ;
   *chrows = crows ;
   *chcols = ccols ;
#endif // FLASH_GRAPHICS   
}

/*
--------------------------------------------------------------------------------

   Return to text mode

--------------------------------------------------------------------------------
*/

void exit_graphics ()
{
#ifdef FLASH_GRAPHICS
   if (drows <= 0)
      return ;

   fg_term () ;
#endif // FLASH_GRAPHICS   
}

/*
--------------------------------------------------------------------------------

   Draw a line

--------------------------------------------------------------------------------
*/

void drawline ( int x1 , int y1 , int x2 , int y2 , int color )
{
#ifdef FLASH_GRAPHICS
   fg_line_t line ;

   if (drows <= 0)
      return ;

   line[FG_X1] = x1 ;
   line[FG_X2] = x2 ;
   line[FG_Y1] = y1 ;
   line[FG_Y2] = y2 ;
   fg_drawline ( color , FG_MODE_SET , ~0 , FG_LINE_SOLID , line ) ;
#endif // FLASH_GRAPHICS
}

void write_graphics_text ( int row , int col , char *text , int color )
{
#ifdef FLASH_GRAPHICS
   fg_box_t box ;

   if (drows <= 0)
      return ;

   fg_make_box ( box , col , row , col + strlen ( text ) * ccols - 1 ,
                 row + crows - 1 ) ;
   fg_box_normalize ( box ) ;
   fg_fillbox ( 0 , FG_MODE_SET , ~0 , box ) ;
   fg_puts ( color , FG_MODE_SET , ~0 , FG_ROT0 , col ,
             row , text , fg.displaybox ) ;
#endif // FLASH_GRAPHICS
}

/*
--------------------------------------------------------------------------------

   These are for Symantic text-mode operations (not Flash Graphics)

--------------------------------------------------------------------------------
*/

static unsigned short *screen = NULL ;
static unsigned short cursor_row, cursor_col ;

void init_textmode ()
{
#ifdef DISP_LIBRARY
   if (disp_getmode () != 3)
      disp_setmode ( 3 ) ;
   disp_open () ;
#endif   
}

void close_textmode ()
{
#ifdef DISP_LIBRARY
   disp_close () ;
#endif   
}

int save_screen ()
{
#ifdef DISP_LIBRARY
   union REGS r ;
   MEMTEXT ( "GRAPHICS: screen" ) ;
   screen = MALLOC ( 25 * 80 * 2 ) ;
   if (screen == NULL)
      return 1 ;

   r.h.ah = 3 ;    // Read cursor
   r.h.bh = 0 ;    // Page
   int86 ( 0x10 , &r , &r ) ;
   cursor_row = r.h.dh ;
   cursor_col = r.h.dl ;
   disp_peekbox ( screen , 0 , 0 , 24 , 79 ) ;
#endif   
   return 0 ;
}

void restore_screen ()
{
#ifdef DISP_LIBRARY
   union REGS r ;
   if (screen == NULL)
      return ;
   disp_pokebox ( screen , 0 , 0 , 24 , 79 ) ;
   MEMTEXT ( "GRAPHICS: screen" ) ;
   FREE ( screen ) ;
   r.h.ah = 2 ;    // Set cursor
   r.h.bh = 0 ;    // Page
   r.h.dh = cursor_row ;
   r.h.dl = cursor_col ;
   int86 ( 0x10 , &r , &r ) ;
#endif   
}



What I have tried:

Have tried compiling GNUPlot within the project but run into so many problems that I cannot continue with that solution in the short term.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900