ldrbase.h
1 /***************************************************************************
2  ldrbase.h - description
3  -------------------
4  begin : Sun Jun 6 2004
5  copyright : (C) 2000-2015 by Thies H. Jochimsen
6  email : thies@jochimsen.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef LDRBASE_H
19 #define LDRBASE_H
20 
21 
22 #include <tjutils/tjutils.h>
23 #include <tjutils/tjlabel.h>
24 #include <tjutils/tjlist.h>
25 #include <tjutils/tjarray.h>
26 
27 #include <odinpara/ldrser.h>
28 
29 
30 
31 
44 enum parameterMode {edit,noedit,hidden};
45 
46 
54 enum fileMode {include,compressed,exclude};
55 
56 
57 
59 
60 
61 class LDRblock; // Forward Declaration
62 class LDRfunction; // Forward Declaration
63 class LDRtriple; // Forward Declaration
64 class LDRaction; // Forward Declaration
65 class LDRenum; // Forward Declaration
66 class LDRfileName; // Forward Declaration
67 class LDRformula; // Forward Declaration
68 class LDRrecoIndices; // Forward Declaration
69 
70 
72 
77 class LDRcomp {
78  public:
79  static const char* get_compName();
80 };
81 
83 
91 enum scaleType {displayScale=0,xPlotScale,yPlotScaleLeft,yPlotScaleRight,n_ScaleTypes};
92 
93 
97 struct ArrayScale {
98 
99  ArrayScale() : minval(0), maxval(0), enable(true) {}
100 
101  ArrayScale(const STD_string& scalelabel, const STD_string& scaleunit, float scalemin=0.0, float scalemax=0.0, bool enablescale=true);
102 
103  STD_string get_label_with_unit() const;
104 
108  STD_string label;
109 
113  STD_string unit;
114 
118  float minval,maxval;
119 
123  bool enable;
124 };
125 
127 
131 struct PixmapProps {
132 
133  PixmapProps() : minsize(128), maxsize(1024), autoscale(true), color(false), overlay_minval(0), overlay_maxval(0), overlay_firescale(false), overlay_rectsize(0.8f) {}
134 
135 
136  void get_overlay_range(float& min, float& max) const;
137 
141  unsigned int minsize, maxsize;
142 
146  bool autoscale;
147 
151  bool color;
152 
153 
158 
162  float overlay_minval, overlay_maxval;
163 
168 
173 };
174 
175 
177 
181 struct GuiProps {
182  GuiProps() : fixedsize(true) {}
183 
187  ArrayScale scale[n_ScaleTypes];
188 
193  bool fixedsize;
194 
199 };
200 
202 
203 
204 
205 
216 enum parxCodeType {parx_def, parx_passval, parx_passval_head, parx_parclass_def, parx_parclass_init, parx_parclass_passval};
217 
218 
219 
220 
224 struct JcampDxProps {
225 
229  JcampDxProps(bool user_defined_parameter=true,
230  const STD_string& parx_name="", double parx_assign_factor=1.0, double parx_assign_offset=0.0)
231  : userdef_parameter(user_defined_parameter),
232  parx_equiv_name(parx_name), parx_equiv_factor(parx_assign_factor), parx_equiv_offset(parx_assign_offset) {}
233 
239 
243  STD_string parx_equiv_name;
244 
249 
254 
255 };
256 
257 
258 
259 
261 
270 class LDRbase : public ListItem<LDRbase>, public virtual Labeled {
271 
272  public:
273 
274  virtual ~LDRbase();
275 
280  virtual STD_string print(const LDRserBase& serializer=LDRserJDX()) const;
281 
285  virtual STD_ostream& print2stream(STD_ostream& os, const LDRserBase& serializer) const;
286 
290  friend STD_ostream& operator << (STD_ostream& s, const LDRbase& value) { return value.print2stream(s,LDRserJDX());}
291 
292 
300  virtual int write(const STD_string &filename, const LDRserBase& serializer=LDRserJDX()) const;
301 
306  virtual STD_string printvalstring(const LDRserBase* ser=0) const = 0;
307 
308 
309 
315  virtual bool parse(STD_string& parstring, const LDRserBase& serializer=LDRserJDX());
316 
326  virtual int load(const STD_string &filename, const LDRserBase& serializer=LDRserJDX());
327 
328 
333  virtual bool parsevalstring(const STD_string&, const LDRserBase* ser=0) = 0;
334 
335 
336 
337 
338 
343  virtual STD_string get_typeInfo(bool parx_equivtype=false) const = 0;
344 
345 
350  virtual double get_minval() const {return 0.0;}
351 
352 
357  virtual double get_maxval() const {return 0.0;}
358 
363  bool has_minmax() const {return get_maxval()>get_minval();}
364 
365 
369  virtual LDRbase* create_copy() const = 0;
370 
371 
376  const STD_string& get_description() const {return description;}
377 
382  LDRbase& set_description(const STD_string& descr) {description=descr; return *this;}
383 
384 
388  virtual svector get_alternatives() const {return svector();}
389 
390 
395  const STD_string& get_unit() const {return unit;}
396 
401  LDRbase& set_unit(const STD_string& un) {unit=un; return *this;}
402 
403 
408  virtual parameterMode get_parmode() const {return parmode;}
409 
414  virtual LDRbase& set_parmode(parameterMode parameter_mode) {parmode=parameter_mode; return *this;}
415 
420  virtual fileMode get_filemode() const {return filemode;}
421 
426  virtual LDRbase& set_filemode(fileMode file_mode) {filemode=file_mode; return *this;}
427 
428 
429 
434  virtual GuiProps get_gui_props() const {return GuiProps();}
435 
440  virtual LDRbase& set_gui_props(const GuiProps&) {return *this;}
441 
442 
443 
448  virtual STD_string get_parx_code(parxCodeType type) const;
449 
450 
455  JcampDxProps get_jdx_props() const {return jdx_props;}
456 
461  LDRbase& set_jdx_props(const JcampDxProps& jp) {jdx_props=jp; return *this;}
462 
463 
464 
465  // virtual functions to emulate a dynamic cast
466  virtual LDRblock* cast(LDRblock*) {return 0;}
467  virtual int* cast(int*) {return 0;}
468  virtual long* cast(long*) {return 0;}
469  virtual float* cast(float*) {return 0;}
470  virtual double* cast(double*) {return 0;}
471  virtual bool* cast(bool*) {return 0;}
472  virtual STD_complex* cast(STD_complex*) {return 0;}
473  virtual LDRenum* cast(LDRenum*) {return 0;}
474  virtual STD_string* cast(STD_string*) {return 0;}
475  virtual LDRfileName* cast(LDRfileName*) {return 0;}
476  virtual LDRformula* cast(LDRformula*) {return 0;}
477  virtual LDRaction* cast(LDRaction*) {return 0;}
478  virtual iarray* cast(iarray*) {return 0;}
479  virtual darray* cast(darray*) {return 0;}
480  virtual farray* cast(farray*) {return 0;}
481  virtual carray* cast(carray*) {return 0;}
482  virtual sarray* cast(sarray*) {return 0;}
483  virtual LDRtriple* cast(LDRtriple*) {return 0;}
484  virtual LDRfunction* cast(LDRfunction*) {return 0;}
485 
486 
487  // with these functions it is possible to assign a unique id to each paramerer
488  int set_parameter_id(int newid) {id=newid; return 0;}
489  int get_parameter_id() const {return id;}
490 
491  LDRbase& set_cmdline_option(const STD_string& opt) {cmdline_option=opt; return *this;}
492  STD_string get_cmdline_option() const {return cmdline_option;}
493 
494 
495  protected:
496 
497  LDRbase();
498  LDRbase(const LDRbase& ldr);
499  LDRbase& operator = (const LDRbase& ldr);
500 
501  STD_string get_parx_def_string(const STD_string type, unsigned int dim) const;
502 
503 
504 
505  private:
506  friend class LDRwidget;
507  friend class LDRblock;
508 
509  JcampDxProps jdx_props;
510 
511 
512  parameterMode parmode;
513  fileMode filemode;
514 
515  STD_string description;
516  STD_string unit;
517 
518  int id;
519 
520  STD_string cmdline_option;
521 
522 };
523 
524 
525 
527 //
528 // Some interface classes which help editing parameters in a GUI
529 
530 class LDReditWidget {
531 
532  public:
533 
534  virtual void updateWidget() = 0;
535 
536  virtual ~LDReditWidget() {} // to avoid compiler warnings
537 };
538 
539 
540 
541 class LDReditCaller {
542 
543  public:
544 
545  virtual void parameter_relations(LDReditWidget* editwidget) = 0;
546 
547  virtual ~LDReditCaller() {} // to avoid compiler warnings
548 };
549 
550 
551 
565 #endif
LDRbase & set_unit(const STD_string &un)
Definition: ldrbase.h:401
STD_string label
Definition: ldrbase.h:108
virtual parameterMode get_parmode() const
Definition: ldrbase.h:408
virtual double get_maxval() const
Definition: ldrbase.h:357
parxCodeType
Definition: ldrbase.h:216
bool color
Definition: ldrbase.h:151
bool autoscale
Definition: ldrbase.h:146
float overlay_minval
Definition: ldrbase.h:162
STD_string parx_equiv_name
Definition: ldrbase.h:243
STD_string unit
Definition: ldrbase.h:113
const STD_string & get_unit() const
Definition: ldrbase.h:395
float overlay_rectsize
Definition: ldrbase.h:172
virtual fileMode get_filemode() const
Definition: ldrbase.h:420
unsigned int minsize
Definition: ldrbase.h:141
bool enable
Definition: ldrbase.h:123
LDRbase & set_jdx_props(const JcampDxProps &jp)
Definition: ldrbase.h:461
int write(const STD_string &str, const STD_string &filename, fopenMode mode=overwriteMode)
float minval
Definition: ldrbase.h:118
double parx_equiv_offset
Definition: ldrbase.h:253
parameterMode
Definition: ldrbase.h:44
scaleType
Definition: ldrbase.h:91
LDRbase & set_description(const STD_string &descr)
Definition: ldrbase.h:382
bool overlay_firescale
Definition: ldrbase.h:167
virtual STD_ostream & print2stream(STD_ostream &os, const LDRserBase &serializer) const
farray overlay_map
Definition: ldrbase.h:157
int load(STD_string &str, const STD_string &filename)
virtual LDRbase & set_gui_props(const GuiProps &)
Definition: ldrbase.h:440
virtual svector get_alternatives() const
Definition: ldrbase.h:388
virtual LDRbase & set_filemode(fileMode file_mode)
Definition: ldrbase.h:426
double parx_equiv_factor
Definition: ldrbase.h:248
PixmapProps pixmap
Definition: ldrbase.h:198
bool has_minmax() const
Definition: ldrbase.h:363
fileMode
Definition: ldrbase.h:54
virtual double get_minval() const
Definition: ldrbase.h:350
bool userdef_parameter
Definition: ldrbase.h:238
bool fixedsize
Definition: ldrbase.h:193
JcampDxProps get_jdx_props() const
Definition: ldrbase.h:455
JcampDxProps(bool user_defined_parameter=true, const STD_string &parx_name="", double parx_assign_factor=1.0, double parx_assign_offset=0.0)
Definition: ldrbase.h:229
virtual LDRbase & set_parmode(parameterMode parameter_mode)
Definition: ldrbase.h:414
virtual GuiProps get_gui_props() const
Definition: ldrbase.h:434
const STD_string & get_description() const
Definition: ldrbase.h:376