00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __APP_PROFILE_H
00030 #define __APP_PROFILE_H
00031
00032 typedef struct{
00033 gchar *mitem;
00034 int msk;
00035 int neg;
00036 } menuoptionlist;
00037
00038 #define PROFILE_MODE_XGRID (1<<0)
00039 #define PROFILE_MODE_XLOG (1<<1)
00040 #define PROFILE_MODE_YGRID (1<<2)
00041 #define PROFILE_MODE_YLOG (1<<3)
00042 #define PROFILE_MODE_YLINREG (1<<4)
00043 #define PROFILE_MODE_POINTS (1<<5)
00044 #define PROFILE_MODE_CONNECT (1<<6)
00045 #define PROFILE_MODE_IMPULS (1<<7)
00046 #define PROFILE_MODE_NOTICS (1<<8)
00047 #define PROFILE_MODE_LEGEND (1<<9)
00048 #define PROFILE_MODE_SYMBOLS (1<<10)
00049 #define PROFILE_MODE_YPSD (1<<11)
00050
00051 #define PROFILE_SCALE_XAUTO (1<<0)
00052 #define PROFILE_SCALE_YAUTO (1<<1)
00053 #define PROFILE_SCALE_XHOLD (1<<3)
00054 #define PROFILE_SCALE_YHOLD (1<<4)
00055 #define PROFILE_SCALE_XEXPAND (1<<5)
00056 #define PROFILE_SCALE_YEXPAND (1<<6)
00057
00058 #define UTF8_DEGREE "\302\260"
00059
00060 class ProfileControl;
00061
00062 class ProfileElement{
00063 #define PROFILE_ELEM_HIDE (1<<0)
00064 public:
00065 ProfileElement(Scan *sc, ProfileControl *pc, gchar *color=NULL, int Yy=0);
00066 ProfileElement(ProfileElement *pe, gchar *color=NULL, int Yy=0);
00067 ~ProfileElement();
00068
00069 int GetNy(){ return scan->mem2d->GetNy(); };
00070 void SetY(int Yy=0){ yy=Yy; };
00071 void SetLastY(){ yy=scan->mem2d->GetNy()-1; };
00072 void SetMode(long Mode);
00073 void SetOptions(long Flg);
00074
00075 void calc(int ymode=0);
00076 void draw(GtkWidget *canvas);
00077
00078 void GetCurXYc(double *x, double *y, int i){
00079 if(pn)
00080 if(i<n && i>=0)
00081 *x=pn->coords[2*i], *y=pn->coords[2*i+1];
00082 };
00083
00084 int GetCurX(double *x, double *y){
00085 if(pn){
00086 int i = (int)(n*(*x-pn->coords[0])/(pn->coords[2*n-2]-pn->coords[0]));
00087
00088
00089 if(i<n && i>=0)
00090 *x=pn->coords[2*i], *y=pn->coords[2*i+1];
00091 return i;
00092 }
00093 return 0;
00094 };
00095
00096 gchar *GetInfo(int i, int ymode=0){
00097 double x,y;
00098 GetCurXYc (&x, &y, i);
00099 if(i<n && i>=0){
00100 Scan *sc = ymode & PROFILE_MODE_YPSD ? psd_scan : scan;
00101 x = sc->mem2d->data->GetXLookup(i);
00102 return g_strconcat("Cursor (",
00103 ymode & PROFILE_MODE_YPSD ?
00104 psd_scan->data.Xunit->UsrString (x) :
00105 scan->data.Xunit->UsrString (x),
00106 ", ",
00107 ymode & PROFILE_MODE_YPSD ?
00108 scan->data.Zunit->UsrString (y) :
00109 ymode & PROFILE_MODE_YLINREG ?
00110 scan->data.Zunit->UsrString (scan->mem2d->GetDataPktLineReg(i,yy)*scan->data.s.dz) :
00111 scan->data.Zunit->UsrString (scan->mem2d->GetDataPkt(i,yy)*scan->data.s.dz),
00112 ")",
00113 NULL);
00114 }
00115 else
00116 return g_strdup("out of scan !");
00117 };
00118
00119 double GetValue(int i){
00120 if(i<n && i>=0)
00121 return scan->mem2d->GetDataPktLineReg(i,yy)*scan->data.s.dz;
00122 return 0.;
00123 };
00124
00125 int nextMax(int i, int dir, double eps=1.){
00126 if(i<n && i>=0){
00127 int k;
00128 double v=scan->mem2d->GetDataPktLineReg(i,yy);
00129 if(v > scan->mem2d->GetDataPktLineReg(i+dir,yy)+eps){
00130 i=nextMin(i+dir,dir,eps);
00131 v=scan->mem2d->GetDataPktLineReg(i,yy);
00132 }
00133 for(k=i+dir; k>=0 && k<n && v < scan->mem2d->GetDataPktLineReg(k,yy)+eps; k+=dir){
00134 v=scan->mem2d->GetDataPktLineReg(k,yy);
00135 }
00136 k-=dir;
00137 return k;
00138 }
00139 else return 0;
00140 };
00141
00142 int nextMin(int i, int dir, double eps=1.){
00143 if(i<n && i>=0){
00144 int k;
00145 double v=scan->mem2d->GetDataPktLineReg(i,yy);
00146 if(v < scan->mem2d->GetDataPktLineReg(i+dir,yy)-eps){
00147 i=nextMax(i+dir,dir,eps);
00148 v=scan->mem2d->GetDataPktLineReg(i,yy);
00149 }
00150 for(k=i+dir; k>=0 && k<n && v > scan->mem2d->GetDataPktLineReg(k,yy)-eps; k+=dir)
00151 v=scan->mem2d->GetDataPktLineReg(k,yy);
00152 k-=dir;
00153 return k;
00154 }
00155 else return 0;
00156 };
00157
00158 gchar *GetDeltaInfo(int i, int j, int ymode=0){
00159 double x1,y1, x2,y2, dx,dz;
00160 GetCurXYc (&x1, &y1, i);
00161 GetCurXYc (&x2, &y2, j);
00162 if(i<n && i>=0 && j<n && j>=0){
00163 Scan *sc = ymode & PROFILE_MODE_YPSD ? psd_scan : scan;
00164 x1 = sc->mem2d->data->GetXLookup(i);
00165 x2 = sc->mem2d->data->GetXLookup(j);
00166 dx = x2-x1;
00167 gchar *s1 = sc->data.Xunit->UsrString (dx);
00168 gchar *s2 = ymode & PROFILE_MODE_YLINREG ?
00169 sc->data.Zunit->UsrString (dz = (( sc->mem2d->GetDataPktLineReg(i,yy)
00170 - sc->mem2d->GetDataPktLineReg(j,yy))
00171 *sc->data.s.dz))
00172 :
00173 sc->data.Zunit->UsrString (dz = (( sc->mem2d->GetDataPkt(i,yy)
00174 - sc->mem2d->GetDataPkt(j,yy) )
00175 *sc->data.s.dz));
00176 gchar *s3 = g_strdup_printf ("%g"UTF8_DEGREE, 180./M_PI*atan(fabs(dz/dx)));
00177 gchar *s = g_strconcat ("Cursor Delta (", s1, ", ", s2, ")",
00178 " Slope: ", s3,
00179 NULL);
00180 g_free (s1);
00181 g_free (s2);
00182 g_free (s3);
00183 return s;
00184 }
00185 else
00186 return g_strdup("out of scan !");
00187 };
00188
00189 double ylocmin, ylocmax;
00190 double xlocmin, xlocmax;
00191 private:
00192 int n;
00193 int yy;
00194
00195 ProfileControl *pctrl;
00196 GnomeCanvasPoints *pn;
00197 GnomeCanvasItem *pathitem;
00198
00199 Scan *scan;
00200 Scan *psd_scan;
00201 gchar *color;
00202 long flg;
00203 long mode;
00204 };
00205
00206 class ProfileControl : public AppBase, public LineProfile1D{
00207
00208 public:
00209 ProfileControl(gchar *titlestring=NULL, int ChNo=-1);
00210 ProfileControl(gchar *titlestring, int n, UnitObj *ux, UnitObj *uy, double xmin=0., double xmax=1., gchar *resid=NULL);
00211 ProfileControl(gchar *filename, gchar *resource_id_string);
00212 ~ProfileControl();
00213
00214 void Init(gchar *titlestring, int ChNo, gchar *resid=NULL);
00215
00216 static void file_open_callback (GtkWidget *widget, ProfileControl *pc);
00217 static void file_save_callback (GtkWidget *widget, ProfileControl *pc);
00218 static void file_save_as_callback (GtkWidget *widget, ProfileControl *pc);
00219 static void file_print1_callback (GtkWidget *widget, ProfileControl *pc);
00220 static void file_print2_callback (GtkWidget *widget, ProfileControl *pc);
00221 static void file_print3_callback (GtkWidget *widget, ProfileControl *pc);
00222 static void file_print4_callback (GtkWidget *widget, ProfileControl *pc);
00223
00224 static void file_print5_callback (GtkWidget *widget, ProfileControl *pc);
00225 static void file_print6_callback (GtkWidget *widget, ProfileControl *pc);
00226 static void file_activate_callback (GtkWidget *widget, ProfileControl *pc);
00227 static void file_close_callback (GtkWidget *widget, ProfileControl *pc);
00228
00229 static void logy_callback (GtkWidget *widget, ProfileControl *pc);
00230 static void linreg_callback (GtkWidget *widget, ProfileControl *pc);
00231 static void psd_callback (GtkWidget *widget, ProfileControl *pc);
00232 static void tics_callback (GtkWidget *widget, ProfileControl *pc);
00233 static void symbols_callback (GtkWidget *widget, ProfileControl *pc);
00234 static void legend_callback (GtkWidget *widget, ProfileControl *pc);
00235 static void nogrid_callback (GtkWidget *widget, ProfileControl *pc);
00236
00237 static void yhold_callback (GtkWidget *widget, ProfileControl *pc);
00238 static void yexpand_callback (GtkWidget *widget, ProfileControl *pc);
00239 static void skl_Yauto_callback (GtkWidget *widget, ProfileControl *pc);
00240 static void skl_Yupperup_callback (GtkWidget *widget, ProfileControl *pc);
00241 static void skl_Yupperdn_callback (GtkWidget *widget, ProfileControl *pc);
00242 static void skl_Ylowerup_callback (GtkWidget *widget, ProfileControl *pc);
00243 static void skl_Ylowerdn_callback (GtkWidget *widget, ProfileControl *pc);
00244 static void skl_Yzoomin_callback (GtkWidget *widget, ProfileControl *pc);
00245 static void skl_Yzoomout_callback (GtkWidget *widget, ProfileControl *pc);
00246 static void skl_Yset_callback (GtkWidget *widget, ProfileControl *pc);
00247 static void skl_Xauto_callback (GtkWidget *widget, ProfileControl *pc);
00248 static void skl_Xset_callback (GtkWidget *widget, ProfileControl *pc);
00249
00250 static void sel_next_p1_callback(GtkWidget *widget, ProfileControl *pc);
00251 static void sel_next_p5_callback(GtkWidget *widget, ProfileControl *pc);
00252 static void sel_next_p10_callback(GtkWidget *widget, ProfileControl *pc);
00253 static void sel_next_p50_callback(GtkWidget *widget, ProfileControl *pc);
00254 static void sel_next_p100_callback(GtkWidget *widget, ProfileControl *pc);
00255 static void sel_next_p500_callback(GtkWidget *widget, ProfileControl *pc);
00256 static void sel_next_m500_callback(GtkWidget *widget, ProfileControl *pc);
00257 static void sel_next_m100_callback(GtkWidget *widget, ProfileControl *pc);
00258 static void sel_next_m50_callback(GtkWidget *widget, ProfileControl *pc);
00259 static void sel_next_m10_callback(GtkWidget *widget, ProfileControl *pc);
00260 static void sel_next_m5_callback(GtkWidget *widget, ProfileControl *pc);
00261 static void sel_next_m1_callback(GtkWidget *widget, ProfileControl *pc);
00262 static void sel_all_callback(GtkWidget *widget, ProfileControl *pc);
00263 static void sel_first_callback(GtkWidget *widget, ProfileControl *pc);
00264 static void sel_last_callback(GtkWidget *widget, ProfileControl *pc);
00265
00266 static void cur_Ashow_callback (GtkWidget *widget, ProfileControl *pc);
00267 static void cur_Bshow_callback (GtkWidget *widget, ProfileControl *pc);
00268 static void cur_Aleft_callback (GtkWidget *widget, ProfileControl *pc);
00269 static void cur_Almax_callback (GtkWidget *widget, ProfileControl *pc);
00270 static void cur_Almin_callback (GtkWidget *widget, ProfileControl *pc);
00271 static void cur_Armax_callback (GtkWidget *widget, ProfileControl *pc);
00272 static void cur_Armin_callback (GtkWidget *widget, ProfileControl *pc);
00273 static void cur_Aright_callback (GtkWidget *widget, ProfileControl *pc);
00274 static void cur_Bleft_callback (GtkWidget *widget, ProfileControl *pc);
00275 static void cur_Blmax_callback (GtkWidget *widget, ProfileControl *pc);
00276 static void cur_Blmin_callback (GtkWidget *widget, ProfileControl *pc);
00277 static void cur_Brmax_callback (GtkWidget *widget, ProfileControl *pc);
00278 static void cur_Brmin_callback (GtkWidget *widget, ProfileControl *pc);
00279 static void cur_Bright_callback (GtkWidget *widget, ProfileControl *pc);
00280
00281 static gint cursor_event(GnomeCanvasItem *item, GdkEvent *event, ProfileControl *pc);
00282
00283 void file_print_callback (GtkWidget *widget, ProfileControl *pc, int index);
00284
00285 void showCur(int id, int show);
00286 void moveCur(int id, int dir, int search=0, double ix=0.);
00287
00288 void nextLine(int n);
00289
00290 void drawScans(int flg=0);
00291 void UpdateArea();
00292
00293 static void destroy_item(GnomeCanvasItem *gci, ProfileControl *pc){ gtk_object_destroy(GTK_OBJECT(gci)); };
00294 static void kill_elem(ProfileElement *pe, ProfileControl *pc){ delete pe; };
00295 static void draw_elem(ProfileElement *pe, ProfileControl *pc);
00296
00297 gint NewData(Scan* sc, int line=-1, int cpyscan=TRUE);
00298 void AddScan(Scan* scan, int line=0, gchar *col=NULL);
00299 void AddLine(int line=0, gchar *col=NULL);
00300 void RemoveScans();
00301
00302 void SetActive(int flg);
00303
00304 void SetYrange(double y1, double y2);
00305 void SetXrange(double x1, double x2);
00306
00307 void SetXlabel(gchar *xlab = NULL);
00308 void SetYlabel(gchar *ylab = NULL);
00309 void SetTitle(gchar *tit);
00310
00311 void SetMode(long flg) { mode=flg; };
00312 void SetScaling(long flg) { scaleing = flg; };
00313
00314 void scan2canvas(double sx, double sy, double &cx, double &cy){
00315 cx = (sx-xmin)*cxwidth/xrange;
00316 XSM_DEBUG (DBG_L2, "s2cxy"<< (mode& PROFILE_MODE_YLOG));
00317 if (mode & PROFILE_MODE_YLOG){
00318 if (fabs (sy)>0.)
00319 cy = cywidth*(1.-(log (sy)-lmin)/lmaxmin);
00320 else
00321 cy = 1.;
00322 }
00323 else
00324 cy = cywidth*(1.-(sy-ymin)/yrange);
00325 };
00326
00327 void scan2canvas(double &scx, double &scy){
00328 scx = (scx-xmin)*cxwidth/xrange;
00329 if(mode & PROFILE_MODE_YLOG){
00330 if (fabs(scy) > 0.)
00331 scy = cywidth*(1.-(log(scy)-lmin)/lmaxmin);
00332 else
00333 scy = 1.;
00334 }
00335 else
00336 scy = cywidth*(1.-(scy-ymin)/yrange);
00337 };
00338
00339 double scan2canvasX(double sx){
00340 return (sx-xmin)*cxwidth/xrange;
00341 };
00342
00343 double scan2canvasY(double sy){
00344 if (mode & PROFILE_MODE_YLOG){
00345 if (fabs(sy)>0.)
00346 return cywidth*(1.-(log (sy)-lmin)/lmaxmin);
00347 else
00348 return 1.;
00349 }
00350 else
00351 return cywidth*(1.-(sy-ymin)/yrange);
00352 };
00353 void ref (){ ++ref_count; };
00354 void unref (){ --ref_count; };
00355
00356 private:
00357
00358 void SetSize();
00359 void drawFrame();
00360 gint drawTics();
00361 void addTic(GnomeCanvasItem **tic, GnomeCanvasItem **lab,
00362 double val, double len, int pos, gchar *fmt=NULL, double tval=0.);
00363
00364 int chno;
00365 int working;
00366 int SklOnly;
00367
00368 int statusheight;
00369 double border;
00370 double pasize;
00371 double cxwidth, cywidth;
00372 double aspect;
00373 int papixel;
00374
00375 double xmin, xmax, xrange;
00376 double ymin, ymax, yrange;
00377 double lmaxmin, lmin;
00378
00379 int CursorsIdx[2];
00380
00381 long mode, scaleing;
00382
00383 gchar *xlabel, *xlabel0;
00384 gchar *ylabel, *ylabel0;
00385 gchar *title;
00386
00387 gchar *profile_res_id;
00388
00389 double tic_x1, tic_x2, tic_y1, tic_y2;
00390 int tic_ym;
00391 gchar *xticfmt;
00392 gchar *yticfmt;
00393
00394 GtkWidget *canvas;
00395 GtkWidget *statusbar;
00396 GtkWidget *linecounter;
00397 gint statusid;
00398 int new_data_nl, new_data_lastl;
00399
00400 GSList *ScanList;
00401 ProfileElement *last_pe;
00402
00403 GnomeCanvasItem *frame, *background, *xaxislabel, *yaxislabel;
00404
00405 #define PC_XTN (2*Xticn+100)
00406 #define PC_YTN (2*Xticn+100)
00407 #define PC_XLN (Xticn+1+100)
00408 #define PC_YLN (Yticn+1+100)
00409 int Yticn, Xticn;
00410 int ixt, iyt, ixl, iyl;
00411 GnomeCanvasItem **Xtics, **Ytics;
00412 GnomeCanvasItem **Xlabels, **Ylabels;
00413
00414 GnomeCanvasItem *Cursor[2][2];
00415 int scount;
00416
00417 int ref_count;
00418 };
00419
00420 #endif