liborigin2  29/08/2011
/build/liborigin2/src/liborigin2/OriginObj.h
Go to the documentation of this file.
1 /***************************************************************************
2  File : OriginObj.h
3  --------------------------------------------------------------------
4  Copyright : (C) 2005-2007 Stefan Gerlach
5  (C) 2007-2008 Alex Kargovsky
6  (C) 2009-2011 Ion Vasilief
7  Email (use @ for *) : ion_vasilief*yahoo.fr
8  Description : Origin internal object classes
9 
10  ***************************************************************************/
11 
12 /***************************************************************************
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the Free Software *
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
27  * Boston, MA 02110-1301 USA *
28  * *
29  ***************************************************************************/
30 
31 
32 #ifndef ORIGIN_OBJ_H
33 #define ORIGIN_OBJ_H
34 
35 #include <string.h>
36 #include <vector>
37 #include "boost/variant.hpp"
38 #include "boost/bind.hpp"
39 #include <ctime>
40 #include <algorithm>
41 
42 using namespace std;
43 
44 #define _ONAN (-1.23456789E-300)
45 
46 namespace Origin
47 {
48  enum ValueType {Numeric = 0, Text = 1, Time = 2, Date = 3, Month = 4, Day = 5, ColumnHeading = 6, TickIndexedDataset = 7, TextNumeric = 9, Categorical = 10};
50  enum Attach {Frame = 0, Page = 1, Scale = 2};
51  enum BorderType {BlackLine = 0, Shadow = 1, DarkMarble = 2, WhiteOut = 3, BlackOut = 4, None = -1};
55 
56  struct Color
57  {
58  enum ColorType {None, Automatic, Regular, Custom, Increment, Indexing, RGB, Mapping};
59  enum RegularColor {Black = 0, Red = 1, Green = 2, Blue = 3, Cyan = 4, Magenta = 5, Yellow = 6, DarkYellow = 7, Navy = 8,
60  Purple = 9, Wine = 10, Olive = 11, DarkCyan = 12, Royal= 13, Orange = 14, Violet = 15, Pink = 16, White = 17,
61  LightGray = 18, Gray = 19, LTYellow = 20, LTCyan = 21, LTMagenta = 22, DarkGray = 23/*, Custom = 255*/};
62 
64  union
65  {
66  unsigned char regular;
67  unsigned char custom[3];
68  unsigned char starting;
69  unsigned char column;
70  };
71  };
72 
73  struct Rect
74  {
75  short left;
76  short top;
77  short right;
78  short bottom;
79 
80  Rect(short width = 0, short height = 0)
81  : left(0)
82  , top(0)
83  , right(width)
84  , bottom(height)
85  {
86  };
87 
88  int height() const
89  {
90  return bottom - top;
91  };
92 
93  int width() const
94  {
95  return right - left;
96  };
97 
98  bool isValid() const
99  {
100  return height() > 0 && width() > 0;
101  }
102  };
103 
105  {
107  unsigned char fillPattern;
110 
113  unsigned char lineStyle;
114  double lineWidth;
115 
117  };
118 
119  typedef vector<pair<double, ColorMapLevel> > ColorMapVector;
120 
121  struct ColorMap
122  {
125  };
126 
127  struct Window
128  {
129  enum State {Normal, Minimized, Maximized};
130  enum Title {Name, Label, Both};
131 
132  string name;
133  string label;
134  int objectID;
135  bool hidden;
139  time_t creationDate;
141 
142  Window(const string& _name= "", const string& _label = "", bool _hidden = false)
143  : name(_name)
144  , label(_label)
145  , objectID(-1)
146  , hidden(_hidden)
147  , state(Normal)
148  , title(Both)
149  {};
150  };
151 
152  typedef boost::variant<double, string> variant;
153 
155  {
156  enum ColumnType {X, Y, Z, XErr, YErr, Label, NONE};
157 
158  string name;
165  string command;
166  string comment;
167  int width;
168  unsigned int index;
169  unsigned int colIndex;
170  unsigned int sheet;
171  vector<variant> data;
172 
173  SpreadColumn(const string& _name = "", unsigned int _index = 0)
174  : name(_name)
175  , valueType(Numeric)
176  , valueTypeSpecification(0)
177  , significantDigits(6)
178  , decimalPlaces(6)
179  , numericDisplayType(DefaultDecimalDigits)
180  , command("")
181  , comment("")
182  , width(8)
183  , index(_index)
184  , colIndex(0)
185  , sheet(0)
186  {};
187  };
188 
189  struct SpreadSheet : public Window
190  {
191  unsigned int maxRows;
192  bool loose;
193  unsigned int sheets;
194  vector<SpreadColumn> columns;
195 
196  SpreadSheet(const string& _name = "")
197  : Window(_name)
198  , loose(true)
199  , sheets(1)
200  {};
201  };
202 
203  struct Excel : public Window
204  {
205  unsigned int maxRows;
206  bool loose;
207  vector<SpreadSheet> sheets;
208 
209  Excel(const string& _name = "", const string& _label = "", int _maxRows = 0, bool _hidden = false, bool _loose = true)
210  : Window(_name, _label, _hidden)
211  , maxRows(_maxRows)
212  , loose(_loose)
213  {
214  };
215  };
216 
217  struct MatrixSheet
218  {
219  enum ViewType {DataView, ImageView};
220 
221  string name;
222  unsigned short rowCount;
223  unsigned short columnCount;
228  string command;
229  unsigned short width;
230  unsigned int index;
233  vector<double> data;
234  vector<double> coordinates;
235 
236  MatrixSheet(const string& _name = "", unsigned int _index = 0)
237  : name(_name)
238  , valueTypeSpecification(0)
239  , significantDigits(6)
240  , decimalPlaces(6)
241  , numericDisplayType(DefaultDecimalDigits)
242  , command("")
243  , width(8)
244  , index(_index)
245  , view(DataView)
246  {coordinates.push_back(10.0);coordinates.push_back(10.0);coordinates.push_back(1.0);coordinates.push_back(1.0);};
247  };
248 
249  struct Matrix : public Window
250  {
251  enum HeaderViewType {ColumnRow, XY};
252 
253  unsigned int activeSheet;
255  vector<MatrixSheet> sheets;
256 
257  Matrix(const string& _name = "")
258  : Window(_name)
259  , activeSheet(0)
260  , header(ColumnRow)
261  {};
262  };
263 
264  struct Function
265  {
266  enum FunctionType {Normal, Polar};
267 
268  string name;
270  string formula;
271  double begin;
272  double end;
274  unsigned int index;
275 
276  Function(const string& _name = "", unsigned int _index = 0)
277  : name(_name)
278  , type(Normal)
279  , formula("")
280  , begin(0.0)
281  , end(0.0)
282  , totalPoints(0)
283  , index(_index)
284  {};
285  };
286 
287 
288  struct TextBox
289  {
290  string text;
293  unsigned short fontSize;
294  int rotation;
295  int tab;
298 
299  TextBox(const string& _text = "")
300  : text(_text)
301  {};
302 
303  TextBox(const string& _text, const Rect& _clientRect, const Color& _color, unsigned short _fontSize, int _rotation, int _tab, BorderType _borderType, Attach _attach)
304  : text(_text)
305  , clientRect(_clientRect)
306  , color(_color)
307  , fontSize(_fontSize)
308  , rotation(_rotation)
309  , tab(_tab)
310  , borderType(_borderType)
311  , attach(_attach)
312  {};
313  };
314 
316  {
317  unsigned char viewAngle;
318  unsigned char thickness;
320  short rotation;
321  unsigned short radius;
322  unsigned short horizontalOffset;
323  unsigned long displacedSectionCount; // maximum - 32 sections
324  unsigned short displacement;
325 
326  //labels
332  unsigned short distance;
333 
335  : clockwiseRotation(false)
336  , formatAutomatic(false)
337  , formatValues(false)
338  , formatPercentages(false)
339  , formatCategories(false)
340  , positionAssociate(false)
341  {};
342  };
343 
345  {
346  enum VectorPosition {Tail, Midpoint, Head};
347 
349  double width;
350  unsigned short arrowLenght;
351  unsigned char arrowAngle;
355 
359  float multiplier;
362 
364  : arrowClosed(false)
365  , position(Tail)
366  , multiplier(1.0)
367  , constAngle(0)
368  , constMagnitude(0)
369  {};
370  };
371 
373  {
374  enum Justify {Left, Center, Right};
375 
377  bool fontBold;
380  bool whiteOut;
382 
383  short rotation;
384  short xOffset;
385  short yOffset;
386  unsigned short fontSize;
387  };
388 
390  {
392  {
393  bool fill;
394  bool contour;
396  double lineWidth;
397  };
398 
399  enum Type {ColorMap3D, ColorFill, WireFrame, Bars};
400  enum Grids {None, X, Y, XY};
401 
402  unsigned char type;
406 
410 
414 
418 
420  };
421 
423  {
424  unsigned char maxSymbolType;
425  unsigned char p99SymbolType;
426  unsigned char meanSymbolType;
427  unsigned char p1SymbolType;
428  unsigned char minSymbolType;
431  unsigned short symbolSize;
432  unsigned char boxRange;
433  unsigned char whiskersRange;
434  double boxCoeff;
437  unsigned char labels;
438  };
439 
440  struct GraphCurve
441  {
442  enum Plot {Line = 200, Scatter=201, LineSymbol=202, Column = 203, Area = 204, HiLoClose = 205, Box = 206,
443  ColumnFloat = 207, Vector = 208, PlotDot = 209, Wall3D = 210, Ribbon3D = 211, Bar3D = 212, ColumnStack = 213,
444  AreaStack = 214, Bar = 215, BarStack = 216, FlowVector = 218, Histogram = 219, MatrixImage = 220, Pie = 225,
445  Contour = 226, Unknown = 230, ErrorBar = 231, TextPlot = 232, XErrorBar = 233, SurfaceColorMap = 236,
446  SurfaceColorFill = 237, SurfaceWireframe = 238, SurfaceBars = 239, Line3D = 240, Text3D = 241, Mesh3D = 242,
447  XYZContour = 243, XYZTriangular = 245, LineSeries = 246, YErrorBar = 254, XYErrorBar = 255, GraphScatter3D = 0x8AF0,
448  GraphTrajectory3D = 0x8AF1, Polar = 0x00020000, SmithChart = 0x00040000, FillArea = 0x00800000};
449  enum LineStyle {Solid = 0, Dash = 1, Dot = 2, DashDot = 3, DashDotDot = 4, ShortDash = 5, ShortDot = 6, ShortDashDot = 7};
450  enum LineConnect {NoLine = 0, Straight = 1, TwoPointSegment = 2, ThreePointSegment = 3, BSpline = 8, Spline = 9, StepHorizontal = 11, StepVertical = 12, StepHCenter = 13, StepVCenter = 14, Bezier = 15};
451 
452  bool hidden;
453  unsigned char type;
454  string dataName;
455  string xDataName;
456  string xColumnName;
457  string yColumnName;
458  string zColumnName;
460  unsigned char lineTransparency;
461  unsigned char lineStyle;
462  unsigned char lineConnect;
463  unsigned char boxWidth;
464  double lineWidth;
465 
466  bool fillArea;
467  unsigned char fillAreaType;
468  unsigned char fillAreaPattern;
470  unsigned char fillAreaTransparency;
477 
478  unsigned short symbolType;
481  unsigned char symbolFillTransparency;
482  double symbolSize;
483  unsigned char symbolThickness;
484  unsigned char pointOffset;
485 
487 
488  //pie
490 
491  //vector
493 
494  //text
496 
497  //surface
499 
500  //contour
502  };
503 
505  {
506  bool show;
507 
508  bool log10;
509  double from;
510  double to;
511  double position;
512 
515 
516  unsigned char minorTicksBefore;
517  unsigned char minorTicksAfter;
518 
520  : show(false)
521  {};
522  };
523 
524  struct GraphGrid
525  {
526  bool hidden;
527  unsigned char color;
528  unsigned char style;
529  double width;
530  };
531 
533  {
534  bool hidden;
535  unsigned char color;
536  double thickness;
543  string prefix;
544  string suffix;
545  string factor;
546  };
547 
549  {
551  unsigned char color;
555  unsigned short fontSize;
556  bool fontBold;
557  string dataName;
558  string columnName;
559  int rotation;
560  };
561 
562  struct GraphAxis
563  {
564  enum AxisPosition {Left = 0, Bottom, Right, Top, Front, Back};
565  enum Scale {Linear = 0, Log10 = 1, Probability = 2, Probit = 3, Reciprocal = 4, OffsetReciprocal = 5, Logit = 6, Ln = 7, Log2 = 8};
566 
568  bool zeroLine;
570  double min;
571  double max;
572  double step;
573  unsigned char majorTicks;
574  unsigned char minorTicks;
575  unsigned char scale;
578  GraphAxisFormat formatAxis[2];
579  GraphAxisTick tickAxis[2]; //bottom-top, left-right
580  };
581 
582  struct Figure
583  {
584  enum FigureType {Rectangle, Circle};
585 
590  unsigned char style;
591  double width;
593  unsigned char fillAreaPattern;
597 
598  Figure(FigureType _type = Rectangle)
599  : type(_type)
600  {
601  };
602  };
603 
604  struct LineVertex
605  {
606  unsigned char shapeType;
607  double shapeWidth;
608  double shapeLength;
609  double x;
610  double y;
611 
613  : shapeType(0)
614  , shapeWidth(0.0)
615  , shapeLength(0.0)
616  , x(0.0)
617  , y(0.0)
618  {};
619  };
620 
621  struct Line
622  {
626  double width;
627  unsigned char style;
630  };
631 
632  struct Bitmap
633  {
636  unsigned long size;
637  string windowName;
639  unsigned char* data;
640 
641  Bitmap(const string& _name = "")
642  : size(0)
643  , windowName(_name)
644  , borderType(Origin::None)
645  , data(0)
646  {
647  };
648 
649  Bitmap(const Bitmap& bitmap)
650  : clientRect(bitmap.clientRect)
651  , attach(bitmap.attach)
652  , size(bitmap.size)
653  , windowName(bitmap.windowName)
654  , borderType(bitmap.borderType)
655  {
656  if(size > 0)
657  {
658  data = new unsigned char[size];
659  memcpy(data, bitmap.data, size);
660  }
661  };
662 
664  {
665  if(size > 0)
666  delete data;
667  };
668  };
669 
670  struct ColorScale
671  {
672  bool visible;
674  unsigned short labelGap;
675  unsigned short colorBarThickness;
677  };
678 
679  struct GraphLayer
680  {
685 
689 
693 
694  double histogramBin;
696  double histogramEnd;
697 
700 
701  vector<TextBox> texts;
702  vector<TextBox> pieTexts;
703  vector<Line> lines;
704  vector<Figure> figures;
705  vector<Bitmap> bitmaps;
706  vector<GraphCurve> curves;
707 
708  float xAngle;
709  float yAngle;
710  float zAngle;
711 
712  float xLength;
713  float yLength;
714  float zLength;
715 
717  double vLine;
718  double hLine;
719 
721  int xOffset;
722  int yOffset;
723 
724  bool gridOnTop;
726  bool isXYY3D;
728 
730  : imageProfileTool(0)
731  , isWaterfall(false)
732  , gridOnTop(false)
733  , exchangedAxes(false)
734  , isXYY3D(false)
735  , orthographic3D(false)
736  {colorScale.visible = false;};
737 
738  //bool threeDimensional;
739  bool is3D() const
740  {
741  return curves.end() != find_if(curves.begin(), curves.end(),
742  boost::bind(logical_or<bool>(), boost::bind(&GraphCurve::type, _1) == GraphCurve::Line3D,
743  boost::bind(&GraphCurve::type, _1) == GraphCurve::Mesh3D));
744  }
745  };
746 
748  {
749  double min;
750  double max;
751  double step;
752 
753  GraphLayerRange(double _min = 0.0, double _max = 0.0, double _step = 0.0)
754  : min(_min)
755  , max(_max)
756  , step(_step)
757  {};
758  };
759 
760  struct Graph : public Window
761  {
762  vector<GraphLayer> layers;
763  unsigned short width;
764  unsigned short height;
765  bool is3D;
766  bool isLayout;
768  string templateName;
769 
770  Graph(const string& _name = "")
771  : Window(_name)
772  , is3D(false)
773  , isLayout(false)
774  , connectMissingData(false)
775  , templateName("")
776  {};
777  };
778 
779  struct Note : public Window
780  {
781  string text;
782  Note(const string& _name = "")
783  : Window(_name)
784  {};
785  };
786 
787  struct ProjectNode
788  {
789  enum NodeType {SpreadSheet, Matrix, Excel, Graph, Graph3D, Note, Folder};
790 
792  string name;
793  time_t creationDate;
795  bool active;
796 
797  ProjectNode(const string& _name = "", NodeType _type = Folder, const time_t _creationDate = time(NULL), const time_t _modificationDate = time(NULL), bool _active = false)
798  : type(_type)
799  , name(_name)
800  , creationDate(_creationDate)
801  , modificationDate(_modificationDate)
802  , active(_active)
803  {};
804  };
805 }
806 
807 
808 
809 #endif // ORIGIN_OBJ_H