Example #1
0
long
plot_canvas::on_cmd_paint(FXObject *, FXSelector, void *ptr)
{
  FXEvent* ev = (FXEvent*) ptr;
  draw_plot(dirty() ? NULL : ev);
  return 1;
}
Example #2
0
long
plot_canvas::on_update(FXObject *, FXSelector, void *)
{
  if (m_dirty_flag)
    {
      draw_plot(NULL);
      return 1;
    }
  return 0;
}
Example #3
0
File: ui.cpp Project: simedcn/fityk
UiApi::Status UserInterface::execute_line(const string& str)
{
    UiApi::Status status = UiApi::kStatusOk;
    try {
        cmd_executor_->raw_execute_line(str);
    }
    catch (SyntaxError &e) {
        warn(string("Syntax error: ") + e.what());
        status = UiApi::kStatusSyntaxError;
    }
    // ExecuteError and xylib::FormatError and xylib::RunTimeError
    // are derived from std::runtime_error
    catch (runtime_error &e) {
        warn(string("Error: ") + e.what());
        status = UiApi::kStatusExecuteError;
    }

    if (dirty_plot_ && ctx_->get_settings()->autoplot)
        draw_plot(UiApi::kRepaint);

    return status;
}
Example #4
0
void draw_tangent(void *obj, void *data)
{
	function_t *func = (function_t *)obj;
	bundled_info_t *bit = (bundled_info_t *)data;
	window_info_t *winfo = bit->winfo;
	int loc = bit->x;
	SDL_Surface *screen = bit->screen;
	plot_info_t info = bit->info;

	if(loc == winfo->width - 1 || loc == 0)
		return;

	if(!func->show_tan)
		return;

	function_t tangent = emptyFunction();
	tangent.plot_col = func->plot_col;

	double vals[winfo->width];

	double slope_right = (func->vals[loc + 1] - func->vals[loc]);
	double slope_left = (func->vals[loc] - func->vals[loc - 1]);

	double slope = (slope_right + slope_left) / 2;

	tangent.vals = vals;
	tangent.vals[loc] = func->vals[loc];

	int i;
	for(i = loc; i < winfo->width - 1; i++)
		tangent.vals[i + 1] = tangent.vals[i] + slope;
	for(i = loc; i > 0; i--)
		tangent.vals[i - 1] = tangent.vals[i] - slope;

	draw_plot((voidptr)&tangent, data);
}
Example #5
0
/*
 * Main program.
 */
int main()
{

    int appid,rlist;
    int xwork_id,text_id,box_id,data_id;
    int dataspec;
    int i;

    char text[6];

    float xdra[] = {0.0, 0.1, 0.5, 0.9, 1.0, 0.9, 0.5, 0.1, 0.0};
    float ydra[] = {0.5, 0.9, 1.0, 0.9, 0.5, 0.1, 0.0, 0.1, 0.5};
    float xpos,ypos;

/*
 * Define a simple color map (index 0 defines the background color).
 */
    float cmap[4][3] = { { 1.0, 1.0, 1.0 },
                 { 0.0, 0.0, 1.0 },
                 { 0.0, 1.0, 0.0 },
                 { 1.0, 0.0, 0.0 } };
    ng_size_t dims[] = {4,3};
/*
 * Set the display. Default is to display output to an X workstation.
 */
    char const *wks_type = "x11";

/*
 * Initialize the high level utility library and create application.
 */
    NhlInitialize();

        rlist = NhlRLCreate(NhlSETRL);
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNappUsrDir,"./");
        NhlCreate(&appid,"basic06",NhlappClass,NhlDEFAULT_APP,rlist);


    if (!strcmp(wks_type,"ncgm") || !strcmp(wks_type,"NCGM")) {
    /*
     * Create a meta file workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkMetaName,"./basic06c.ncgm");
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlncgmWorkstationClass,
              NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"x11") || !strcmp(wks_type,"X11")) {
    /*
     * Create an X workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetInteger(rlist,NhlNwkPause,True);
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlcairoWindowWorkstationClass,
                          NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"oldps") || !strcmp(wks_type,"OLDPS")) {
    /*
     * Create a PS file workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPSFileName,"./basic06c.ps");
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlpsWorkstationClass,
              NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"oldpdf") || !strcmp(wks_type,"OLDPDF")) {
    /*
     * Create a PS file workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkPDFFileName,"./basic06c.pdf");
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlpdfWorkstationClass,
              NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"pdf") || !strcmp(wks_type,"PDF") ||
             !strcmp(wks_type,"ps") || !strcmp(wks_type,"PS")) {
    /*
     * Create a cairo PS/PDF workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./basic06c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlcairoDocumentWorkstationClass,
              NhlDEFAULT_APP,rlist);
    }
    else if (!strcmp(wks_type,"png") || !strcmp(wks_type,"PNG")) {
    /*
     * Create a cairo PNG workstation.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNwkFileName,"./basic06c");
        NhlRLSetString(rlist,NhlNwkFormat,(char*)wks_type);
        NhlRLSetMDFloatArray(rlist,NhlNwkColorMap,&cmap[0][0],2,dims);
        NhlCreate(&xwork_id,"simple",NhlcairoImageWorkstationClass,
              NhlDEFAULT_APP,rlist);
    }

/*
 * Create data object for an XyPlot
 */
    NhlRLClear(rlist);
    NhlRLSetFloatArray(rlist,NhlNcaXArray,xdra,NhlNumber(xdra));
    NhlRLSetFloatArray(rlist,NhlNcaYArray,ydra,NhlNumber(ydra));
    NhlCreate(&data_id,"xyData",NhlcoordArraysClass,NhlDEFAULT_APP,rlist);

/*
 * Create a simple XyPlot object with no labels or borders.  The
 * parent for this object is xwork_id, hence it will be sent to
 * the workstation identified by xwork_id when the draw procedure
 * is invoked on it.
 */
    NhlRLClear(rlist);
    NhlRLSetString(rlist,NhlNtmXBBorderOn,"False");
    NhlRLSetString(rlist,NhlNtmXTBorderOn,"False");
    NhlRLSetString(rlist,NhlNtmYLBorderOn,"False");
    NhlRLSetString(rlist,NhlNtmYRBorderOn,"False");
    NhlRLSetString(rlist,NhlNtmXBOn,"False");
    NhlRLSetString(rlist,NhlNtmXTOn,"False");
    NhlRLSetString(rlist,NhlNtmYLOn,"False");
    NhlRLSetString(rlist,NhlNtmYROn,"False");
    NhlRLSetFloat(rlist,NhlNvpXF,0.0);
    NhlRLSetFloat(rlist,NhlNvpYF,1.0);
    NhlRLSetFloat(rlist,NhlNvpWidthF,1.0);
    NhlRLSetFloat(rlist,NhlNvpHeightF,1.0);
    NhlCreate(&box_id,"Box",NhlxyPlotClass,xwork_id,rlist);

/*
 * Create a TextItem object.
 */
    NhlRLClear(rlist);
    NhlRLSetFloat(rlist,NhlNtxPosXF,0.5);
    NhlRLSetFloat(rlist,NhlNtxPosYF,0.5);
    NhlRLSetInteger(rlist,NhlNtxFont,26);
        NhlCreate(&text_id,"Text",NhltextItemClass,xwork_id,rlist);

/*
 * Add the data identified by data_id to the XyPlot.
 */
    dataspec = NhlAddData(box_id,"xyCoordData",data_id);

/*
 * Draw three labeled boxes at different sizes and in different positions
 * and with different colors.
 */
    for(i=1;i<=3;++i)
    {
        xpos = -0.05*i*i + 0.5*i - 0.20;
        ypos = 1.0-xpos;
        sprintf(text,"%s %d","Box",i);  

    /*
     * Specify a text string and its color.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNtxString,text);
        NhlRLSetInteger(rlist,NhlNtxFontColor,4-i);
        NhlSetValues(text_id,rlist);

    /*
     * Set the XyPlot curve color.
     */
        NhlRLClear(rlist);
        NhlRLSetString(rlist,NhlNxyMonoLineColor,"True");
        NhlRLSetInteger(rlist,NhlNxyLineColor,i);
        NhlSetValues(dataspec,rlist);

    /*
     * Draw box and text.
     */
        draw_plot(box_id, xpos, ypos, 0.36-0.09*(i-1));
        draw_text(text_id, xpos, ypos, 0.08-0.02*(i-1));
    }

    NhlFrame(xwork_id);

    NhlDestroy(xwork_id);
        NhlClose();
    exit (0);
}