jdxbase.h
1 /***************************************************************************
2  jdxbase.h - description
3  -------------------
4  begin : Sun Jun 6 2004
5  copyright : (C) 2000-2014 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 JDXBASE_H
19 #define JDXBASE_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 
28 // some defines for Bruker-type strings
29 #define _BRUKER_MODE_STRING_CAP_START_ 1000
30 #define _BRUKER_MODE_STRING_MIN_SIZE_ 256
31 #define _BRUKER_MODE_STRING_CAP_FACTOR_ 3
32 
33 
47 enum compatMode {bruker,notBroken};
48 
49 
56 enum parameterMode {edit,noedit,hidden};
57 
58 
66 enum fileMode {include,compressed,exclude};
67 
68 
69 
71 
72 
73 class JcampDxBlock; // Forward Declaration
74 class JDXfunction; // Forward Declaration
75 class JDXtriple; // Forward Declaration
76 class JDXaction; // Forward Declaration
77 class JDXenum; // Forward Declaration
78 class JDXfileName; // Forward Declaration
79 class JDXformula; // Forward Declaration
80 class JDXrecoIndices; // Forward Declaration
81 
82 
84 
89 class JcampDx {
90  public:
91  static const char* get_compName();
92 };
93 
95 
103 enum scaleType {displayScale=0,xPlotScale,yPlotScaleLeft,yPlotScaleRight,n_ScaleTypes};
104 
105 
109 struct ArrayScale {
110 
111  ArrayScale() : minval(0), maxval(0), enable(true) {}
112 
113  ArrayScale(const STD_string& scalelabel, const STD_string& scaleunit, float scalemin=0.0, float scalemax=0.0, bool enablescale=true);
114 
115  STD_string get_label_with_unit() const;
116 
120  STD_string label;
121 
125  STD_string unit;
126 
130  float minval,maxval;
131 
135  bool enable;
136 };
137 
139 
143 struct PixmapProps {
144 
145  PixmapProps() : minsize(128), maxsize(1024), autoscale(true), color(false), overlay_minval(0), overlay_maxval(0), overlay_firescale(false), overlay_rectsize(0.8f) {}
146 
147 
148  void get_overlay_range(float& min, float& max) const;
149 
153  unsigned int minsize, maxsize;
154 
158  bool autoscale;
159 
163  bool color;
164 
165 
170 
174  float overlay_minval, overlay_maxval;
175 
180 
185 };
186 
187 
189 
193 struct GuiProps {
194  GuiProps() : fixedsize(true) {}
195 
199  ArrayScale scale[n_ScaleTypes];
200 
205  bool fixedsize;
206 
211 };
212 
214 
215 
226 enum parxCodeType {parx_def, parx_passval, parx_passval_head, parx_parclass_def, parx_parclass_init, parx_parclass_passval};
227 
228 
233 struct ParxEquiv {
234  ParxEquiv() : factor(1.0), offset(0.0) {}
235 
239  STD_string name;
240 
244  STD_string type;
245 
249  double factor;
250 
254  double offset;
255 
256 };
257 
259 
268 class JcampDxClass : public ListItem<JcampDxClass>, public virtual Labeled {
269 
270  public:
271 
272  virtual ~JcampDxClass();
273 
278  virtual STD_string print() const;
279 
283  virtual STD_ostream& print2stream(STD_ostream& os) const {return os << printvalstring();}
284 
288  friend STD_ostream& operator << (STD_ostream& s,const JcampDxClass& value) { return value.print2stream(s);}
289 
290 
298  virtual bool parse(STD_string& parstring);
299 
309  virtual int load(const STD_string &filename);
310 
318  virtual int write(const STD_string &filename) const;
319 
320 
325  virtual bool parsevalstring (const STD_string&) = 0;
326 
331  virtual STD_string printvalstring() const = 0;
332 
333 
338  virtual JcampDxClass& set_compatmode(compatMode compat_mode) {compatmode=compat_mode; return *this;}
339 
344  virtual compatMode get_compatmode() const {return compatmode;}
345 
346 
350  virtual const char* get_typeInfo() const = 0;
351 
352 
357  virtual double get_minval() const {return 0.0;}
358 
359 
364  virtual double get_maxval() const {return 0.0;}
365 
370  bool has_minmax() const {return get_maxval()>get_minval();}
371 
372 
376  virtual JcampDxClass* create_copy() const = 0;
377 
378 
379 
384  JcampDxClass& set_userDefParameter(bool userDef) {userDefParameter=userDef; return *this;}
385 
386 
391  bool isUserDefParameter() const {return userDefParameter;}
392 
393 
398  const STD_string& get_description() const {return description;}
399 
404  JcampDxClass& set_description(const STD_string& descr) {description=descr; return *this;}
405 
406 
410  virtual svector get_alternatives() const {return svector();}
411 
412 
417  const STD_string& get_unit() const {return unit;}
418 
423  JcampDxClass& set_unit(const STD_string& un) {unit=un; return *this;}
424 
425 
430  virtual parameterMode get_parmode() const {return parmode;}
431 
436  virtual JcampDxClass& set_parmode(parameterMode parameter_mode) {parmode=parameter_mode; return *this;}
437 
442  virtual fileMode get_filemode() const {return filemode;}
443 
448  virtual JcampDxClass& set_filemode(fileMode file_mode) {filemode=file_mode; return *this;}
449 
450 
451 
456  virtual GuiProps get_gui_props() const {return GuiProps();}
457 
462  virtual JcampDxClass& set_gui_props(const GuiProps&) {return *this;}
463 
464 
465 
470  virtual STD_string get_parx_code(parxCodeType type, const ParxEquiv& equiv=ParxEquiv()) const;
471 
478  virtual ParxEquiv get_parx_equiv() const {ParxEquiv pe; pe.type=get_typeInfo(); return pe;}
479 
480 
481 
482 
483  // virtual functions to emulate a dynamic cast
484  virtual JcampDxBlock* cast(JcampDxBlock*) {return 0;}
485  virtual int* cast(int*) {return 0;}
486  virtual long* cast(long*) {return 0;}
487  virtual float* cast(float*) {return 0;}
488  virtual double* cast(double*) {return 0;}
489  virtual bool* cast(bool*) {return 0;}
490  virtual STD_complex* cast(STD_complex*) {return 0;}
491  virtual JDXenum* cast(JDXenum*) {return 0;}
492  virtual STD_string* cast(STD_string*) {return 0;}
493  virtual JDXfileName* cast(JDXfileName*) {return 0;}
494  virtual JDXformula* cast(JDXformula*) {return 0;}
495  virtual JDXaction* cast(JDXaction*) {return 0;}
496  virtual iarray* cast(iarray*) {return 0;}
497  virtual darray* cast(darray*) {return 0;}
498  virtual farray* cast(farray*) {return 0;}
499  virtual carray* cast(carray*) {return 0;}
500  virtual sarray* cast(sarray*) {return 0;}
501  virtual JDXtriple* cast(JDXtriple*) {return 0;}
502  virtual JDXfunction* cast(JDXfunction*) {return 0;}
503 
504 
505  // with these functions it is possible to assign a unique id to each paramerer
506  int set_parameter_id(int newid) {id=newid; return 0;}
507  int get_parameter_id() const {return id;}
508 
509  JcampDxClass& set_cmdline_option(const STD_string& opt) {cmdline_option=opt; return *this;}
510  STD_string get_cmdline_option() const {return cmdline_option;}
511 
512 
513  protected:
514 
515  JcampDxClass();
516  JcampDxClass(const JcampDxClass& jdc);
517  JcampDxClass& operator = (const JcampDxClass& jdc);
518 
519  STD_string get_parx_def_string(const STD_string type, unsigned int dim) const;
520 
521  private:
522  friend class JDXwidget;
523  friend class JcampDxBlock;
524 
525  virtual STD_string get_jdx_prefix() const;
526  virtual STD_string get_jdx_postfix() const {return "\n";}
527 
528  compatMode compatmode;
529  bool userDefParameter;
530  parameterMode parmode;
531  fileMode filemode;
532 
533  STD_string description;
534  STD_string unit;
535 
536  int id;
537 
538  STD_string cmdline_option;
539 
540 };
541 
542 
543 
545 //
546 // Some interface classes which help editing parameters in a GUI
547 
548 class JDXeditWidget {
549 
550  public:
551 
552  virtual void updateWidget() = 0;
553 
554  virtual ~JDXeditWidget() {} // to avoid compiler warnings
555 };
556 
557 
558 
559 class JDXeditCaller {
560 
561  public:
562 
563  virtual void parameter_relations(JDXeditWidget* editwidget) = 0;
564 
565  virtual ~JDXeditCaller() {} // to avoid compiler warnings
566 };
567 
568 
569 
583 #endif