liborigin2 13/09/2010
/builddir/build/BUILD/liborigin2-20101029/OriginObj.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : OriginObj.h
00003     --------------------------------------------------------------------
00004     Copyright            : (C) 2005-2007 Stefan Gerlach
00005                            (C) 2007-2008 Alex Kargovsky, Ion Vasilief
00006     Email (use @ for *)  : kargovsky*yumr.phys.msu.su, ion_vasilief*yahoo.fr
00007     Description          : Origin internal object classes
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 
00030 
00031 #ifndef ORIGIN_OBJ_H
00032 #define ORIGIN_OBJ_H
00033 
00034 #include <cstring>
00035 #include <ctime>
00036 #include <vector>
00037 #include "boost/variant.hpp"
00038 
00039 using namespace std;
00040 
00041 #define _ONAN       (-1.23456789E-300)
00042 
00043 namespace Origin
00044 {
00045     enum ValueType {Numeric = 0, Text = 1, Time = 2, Date = 3,  Month = 4, Day = 5, ColumnHeading = 6, TickIndexedDataset = 7, TextNumeric = 9, Categorical = 10};
00046     enum NumericDisplayType {DefaultDecimalDigits = 0, DecimalPlaces = 1, SignificantDigits = 2};
00047     enum Attach {Frame = 0, Page = 1, Scale = 2};
00048     enum BorderType {BlackLine = 0, Shadow = 1, DarkMarble = 2, WhiteOut = 3, BlackOut = 4, None = -1};
00049     enum FillPattern {NoFill, BDiagDense, BDiagMedium, BDiagSparse, FDiagDense, FDiagMedium, FDiagSparse, 
00050         DiagCrossDense, DiagCrossMedium, DiagCrossSparse, HorizontalDense, HorizontalMedium, HorizontalSparse, 
00051         VerticalDense, VerticalMedium, VerticalSparse, CrossDense, CrossMedium, CrossSparse};
00052 
00053     struct Color
00054     {
00055         enum ColorType {None, Automatic, Regular, Custom, Increment, Indexing, RGB, Mapping};
00056         enum RegularColor {Black = 0, Red = 1, Green = 2, Blue = 3, Cyan = 4, Magenta = 5, Yellow = 6, DarkYellow = 7, Navy = 8,
00057             Purple = 9, Wine = 10, Olive = 11, DarkCyan = 12, Royal=  13, Orange = 14, Violet = 15, Pink = 16, White = 17,
00058             LightGray = 18, Gray = 19, LTYellow = 20, LTCyan = 21, LTMagenta = 22, DarkGray = 23/*, Custom = 255*/};
00059 
00060         ColorType type;
00061         union
00062         {
00063             unsigned char regular;
00064             unsigned char custom[3];
00065             unsigned char starting;
00066             unsigned char column;
00067         };
00068     };
00069 
00070     struct Rect
00071     {
00072         short left;
00073         short top;
00074         short right;
00075         short bottom;
00076 
00077         Rect(short width = 0, short height = 0)
00078         :   left(0)
00079         ,   top(0)
00080         ,   right(width)
00081         ,   bottom(height)
00082         {
00083         };
00084 
00085         int height() const
00086         {
00087             return bottom - top;
00088         };
00089 
00090         int width() const
00091         {
00092             return right - left;
00093         };
00094 
00095         bool isValid() const
00096         {
00097             return height() > 0 && width() > 0;
00098         }
00099     };
00100 
00101     struct ColorMapLevel
00102     {
00103         Color fillColor;
00104         unsigned char fillPattern;
00105         Color fillPatternColor;
00106         double fillPatternLineWidth;
00107 
00108         bool lineVisible;
00109         Color lineColor;
00110         unsigned char lineStyle;
00111         double lineWidth;
00112 
00113         bool labelVisible;
00114     };
00115 
00116     typedef vector<pair<double, ColorMapLevel> > ColorMapVector;
00117 
00118     struct ColorMap
00119     {
00120         bool fillEnabled;
00121         ColorMapVector levels;
00122     };
00123 
00124     struct Window
00125     {
00126         enum State {Normal, Minimized, Maximized};
00127         enum Title {Name, Label, Both};
00128 
00129         string name;
00130         string label;
00131         int objectID;
00132         bool hidden;
00133         State state;
00134         Title title;
00135         Rect frameRect;
00136         time_t creationDate;
00137         time_t modificationDate;
00138 
00139         Window(const string& _name= "", const string& _label = "", bool _hidden = false)
00140         :   name(_name)
00141         ,   label(_label)
00142         ,   objectID(-1)
00143         ,   hidden(_hidden)
00144         ,   state(Normal)
00145         ,   title(Both)
00146         {};
00147     };
00148 
00149     typedef boost::variant<double, string> variant;
00150 
00151     struct SpreadColumn
00152     {
00153         enum ColumnType {X, Y, Z, XErr, YErr, Label, NONE};
00154 
00155         string name;
00156         ColumnType type;
00157         ValueType valueType;
00158         int valueTypeSpecification;
00159         int significantDigits;
00160         int decimalPlaces;
00161         NumericDisplayType numericDisplayType;
00162         string command;
00163         string comment;
00164         int width;
00165         unsigned int index;
00166         unsigned int sheet;
00167         vector<variant> data;
00168 
00169         SpreadColumn(const string& _name = "", unsigned int _index = 0)
00170         :   name(_name)
00171         ,   valueType(Numeric)
00172         ,   valueTypeSpecification(0)
00173         ,   significantDigits(6)
00174         ,   decimalPlaces(6)
00175         ,   numericDisplayType(DefaultDecimalDigits)
00176         ,   command("")
00177         ,   comment("")
00178         ,   width(8)
00179         ,   index(_index)
00180         ,   sheet(0)
00181         {};
00182     };
00183 
00184     struct SpreadSheet : public Window
00185     {
00186         unsigned int maxRows;
00187         bool loose;
00188         bool multisheet;
00189         unsigned int sheets;
00190         vector<SpreadColumn> columns;
00191 
00192         SpreadSheet(const string& _name = "")
00193         :   Window(_name)
00194         ,   loose(true)
00195         ,   multisheet(false)
00196         ,   sheets(1)
00197         {};
00198     };
00199 
00200     struct Excel : public Window
00201     {
00202         unsigned int maxRows;
00203         bool loose;
00204         vector<SpreadSheet> sheets;
00205 
00206         Excel(const string& _name = "", const string& _label = "", int _maxRows = 0, bool _hidden = false, bool _loose = true)
00207         :   Window(_name, _label, _hidden)
00208         ,   maxRows(_maxRows)
00209         ,   loose(_loose)
00210         {
00211         };
00212     };
00213 
00214     struct Matrix : public Window
00215     {
00216         enum ViewType {DataView, ImageView};
00217         enum HeaderViewType {ColumnRow, XY};
00218 
00219         unsigned short rowCount;
00220         unsigned short columnCount;
00221         int valueTypeSpecification;
00222         int significantDigits;
00223         int decimalPlaces;
00224         NumericDisplayType numericDisplayType;
00225         string command;
00226         int width;
00227         unsigned int index;
00228         unsigned int sheets;
00229         ViewType view;
00230         HeaderViewType header;
00231         ColorMap colorMap;
00232         vector<double> data;
00233         vector<double> coordinates;
00234 
00235         Matrix(const string& _name = "", unsigned int _index = 0)
00236         :   Window(_name)
00237         ,   valueTypeSpecification(0)
00238         ,   significantDigits(6)
00239         ,   decimalPlaces(6)
00240         ,   numericDisplayType(DefaultDecimalDigits)
00241         ,   command("")
00242         ,   width(8)
00243         ,   index(_index)
00244         ,   sheets(1)
00245         ,   view(DataView)
00246         ,   header(ColumnRow)
00247         {coordinates.push_back(10.0);coordinates.push_back(10.0);coordinates.push_back(1.0);coordinates.push_back(1.0);};
00248     };
00249 
00250     struct Function
00251     {
00252         enum FunctionType {Normal, Polar};
00253 
00254         string name;
00255         FunctionType type;
00256         string formula;
00257         double begin;
00258         double end;
00259         int totalPoints;
00260         unsigned int index;
00261 
00262         Function(const string& _name = "", unsigned int _index = 0)
00263         :   name(_name)
00264         ,   type(Normal)
00265         ,   formula("")
00266         ,   begin(0.0)
00267         ,   end(0.0)
00268         ,   totalPoints(0)
00269         ,   index(_index)
00270         {};
00271     };
00272 
00273 
00274     struct TextBox
00275     {
00276         string text;
00277         Rect clientRect;
00278         Color color;
00279         unsigned short fontSize;
00280         int rotation;
00281         int tab;
00282         BorderType borderType;
00283         Attach attach;
00284 
00285         TextBox(const string& _text = "")
00286         :   text(_text)
00287         {};
00288 
00289         TextBox(const string& _text, const Rect& _clientRect, const Color& _color, unsigned short _fontSize, int _rotation, int _tab, BorderType _borderType, Attach _attach)
00290         :   text(_text)
00291         ,   clientRect(_clientRect)
00292         ,   color(_color)
00293         ,   fontSize(_fontSize)
00294         ,   rotation(_rotation)
00295         ,   tab(_tab)
00296         ,   borderType(_borderType)
00297         ,   attach(_attach)
00298         {};
00299     };
00300 
00301     struct PieProperties
00302     {
00303         unsigned char viewAngle;
00304         unsigned char thickness;
00305         bool clockwiseRotation;
00306         short rotation;
00307         unsigned short radius;
00308         unsigned short horizontalOffset;
00309         unsigned long displacedSectionCount; // maximum - 32 sections
00310         unsigned short displacement;
00311         
00312         //labels
00313         bool formatAutomatic;
00314         bool formatValues;
00315         bool formatPercentages;
00316         bool formatCategories;
00317         bool positionAssociate;
00318         unsigned short distance;
00319 
00320         PieProperties()
00321         :   clockwiseRotation(false)
00322         ,   formatAutomatic(false)
00323         ,   formatValues(false)
00324         ,   formatPercentages(false)
00325         ,   formatCategories(false)
00326         ,   positionAssociate(false)
00327         {};
00328     };
00329 
00330     struct VectorProperties
00331     {
00332         enum VectorPosition {Tail, Midpoint, Head};
00333 
00334         Color color;
00335         double width;
00336         unsigned short arrowLenght;
00337         unsigned char arrowAngle;
00338         bool arrowClosed;
00339         string endXColumnName;
00340         string endYColumnName;
00341 
00342         VectorPosition position;
00343         string angleColumnName;
00344         string magnitudeColumnName;
00345         float multiplier;
00346         int constAngle;
00347         int constMagnitude;
00348 
00349         VectorProperties()
00350         :   arrowClosed(false)
00351         ,   position(Tail)
00352         ,   multiplier(1.0)
00353         ,   constAngle(0)
00354         ,   constMagnitude(0)
00355         {};
00356     };
00357 
00358     struct TextProperties
00359     {
00360         enum Justify {Left, Center, Right};
00361 
00362         Color color;
00363         bool fontBold;
00364         bool fontItalic;
00365         bool fontUnderline;
00366         bool whiteOut;
00367         Justify justify;
00368 
00369         short rotation;
00370         short xOffset;
00371         short yOffset;
00372         unsigned short fontSize;
00373     };
00374 
00375     struct SurfaceProperties
00376     {
00377         struct SurfaceColoration
00378         {
00379             bool fill;
00380             bool contour;
00381             Color lineColor;
00382             double lineWidth;
00383         };
00384 
00385         enum Type {ColorMap3D, ColorFill, WireFrame, Bars};
00386         enum Grids {None, X, Y, XY};
00387 
00388         unsigned char type;
00389         Grids grids;
00390         double gridLineWidth;
00391         Color gridColor;
00392 
00393         bool backColorEnabled;
00394         Color frontColor;
00395         Color backColor;
00396 
00397         bool sideWallEnabled;
00398         Color xSideWallColor;
00399         Color ySideWallColor;
00400 
00401         SurfaceColoration surface;
00402         SurfaceColoration topContour;
00403         SurfaceColoration bottomContour;
00404 
00405         ColorMap colorMap;
00406     };
00407 
00408     struct PercentileProperties
00409     {
00410         unsigned char maxSymbolType;
00411         unsigned char p99SymbolType;
00412         unsigned char meanSymbolType;
00413         unsigned char p1SymbolType;
00414         unsigned char minSymbolType;
00415         Color symbolColor;
00416         Color symbolFillColor;
00417         unsigned short symbolSize;
00418         unsigned char boxRange;
00419         unsigned char whiskersRange;
00420         double boxCoeff;
00421         double whiskersCoeff;
00422         bool diamondBox;
00423     };
00424 
00425     struct GraphCurve
00426     {
00427         enum Plot {Line = 200, Scatter=201, LineSymbol=202, Column = 203, Area = 204, HiLoClose = 205, Box = 206,
00428             ColumnFloat = 207, Vector = 208, PlotDot = 209, Wall3D = 210, Ribbon3D = 211, Bar3D = 212, ColumnStack = 213,
00429             AreaStack = 214, Bar = 215, BarStack = 216, FlowVector = 218, Histogram = 219, MatrixImage = 220, Pie = 225,
00430             Contour = 226, Unknown = 230, ErrorBar = 231, TextPlot = 232, XErrorBar = 233, SurfaceColorMap = 236,
00431             SurfaceColorFill = 237, SurfaceWireframe = 238, SurfaceBars = 239, Line3D = 240, Text3D = 241, Mesh3D = 242,
00432             XYZContour = 243, XYZTriangular = 245, LineSeries = 246, YErrorBar = 254, XYErrorBar = 255, GraphScatter3D = 0x8AF0,
00433             GraphTrajectory3D = 0x8AF1, Polar = 0x00020000, SmithChart = 0x00040000, FillArea = 0x00800000};
00434         enum LineStyle {Solid = 0, Dash = 1, Dot = 2, DashDot = 3, DashDotDot = 4, ShortDash = 5, ShortDot = 6, ShortDashDot = 7};
00435         enum LineConnect {NoLine = 0, Straight = 1, TwoPointSegment = 2, ThreePointSegment = 3, BSpline = 8, Spline = 9, StepHorizontal = 11, StepVertical = 12, StepHCenter = 13, StepVCenter = 14, Bezier = 15};
00436 
00437         unsigned char type;
00438         string dataName;
00439         string xColumnName;
00440         string yColumnName;
00441         string zColumnName;
00442         Color lineColor;
00443         unsigned char lineStyle;
00444         unsigned char lineConnect;
00445         unsigned char boxWidth;
00446         double lineWidth;
00447 
00448         bool fillArea;
00449         unsigned char fillAreaType;
00450         unsigned char fillAreaPattern;
00451         Color fillAreaColor;
00452         Color fillAreaPatternColor;
00453         double fillAreaPatternWidth;
00454         unsigned char fillAreaPatternBorderStyle;
00455         Color fillAreaPatternBorderColor;
00456         double fillAreaPatternBorderWidth;
00457 
00458         unsigned short symbolType;
00459         Color symbolColor;
00460         Color symbolFillColor;
00461         double symbolSize;
00462         unsigned char symbolThickness;
00463         unsigned char pointOffset;
00464 
00465         bool connectSymbols;
00466 
00467         //pie
00468         PieProperties pie;
00469 
00470         //vector
00471         VectorProperties vector;
00472 
00473         //text
00474         TextProperties text;
00475 
00476         //surface
00477         SurfaceProperties surface;
00478 
00479         //contour
00480         ColorMap colorMap;
00481     };
00482 
00483     struct GraphAxisBreak
00484     {
00485         bool show;
00486 
00487         bool log10;
00488         double from;
00489         double to;
00490         double position;
00491 
00492         double scaleIncrementBefore;
00493         double scaleIncrementAfter;
00494 
00495         unsigned char minorTicksBefore;
00496         unsigned char minorTicksAfter;
00497 
00498         GraphAxisBreak()
00499         :   show(false)
00500         {};
00501     };
00502 
00503     struct GraphGrid
00504     {
00505         bool hidden;
00506         unsigned char color;
00507         unsigned char style;
00508         double width;
00509     };
00510 
00511     struct GraphAxisFormat
00512     {
00513         bool hidden;
00514         unsigned char color;
00515         double thickness;
00516         double majorTickLength;
00517         int majorTicksType;
00518         int minorTicksType;
00519         int axisPosition;
00520         double axisPositionValue;
00521         TextBox label;
00522         string prefix;
00523         string suffix;
00524     };
00525 
00526     struct GraphAxisTick
00527     {
00528         bool hidden;
00529         unsigned char color;
00530         ValueType valueType;
00531         int valueTypeSpecification; 
00532         int decimalPlaces;
00533         unsigned short fontSize;
00534         bool fontBold;
00535         string dataName;
00536         string columnName;
00537         int rotation;
00538     };
00539 
00540     struct GraphAxis
00541     {
00542         enum AxisPosition {Left = 0, Bottom, Right, Top, Front, Back};
00543         enum Scale {Linear = 0, Log10 = 1, Probability = 2, Probit = 3, Reciprocal = 4, OffsetReciprocal = 5, Logit = 6, Ln = 7, Log2 = 8};
00544 
00545         AxisPosition position;
00546         double min;
00547         double max;
00548         double step;
00549         unsigned char majorTicks;
00550         unsigned char minorTicks;
00551         unsigned char scale;
00552         GraphGrid majorGrid;
00553         GraphGrid minorGrid;
00554         GraphAxisFormat formatAxis[2];
00555         GraphAxisTick tickAxis[2]; //bottom-top, left-right
00556     };
00557 
00558     struct Figure
00559     {
00560         enum FigureType {Rectangle, Circle};
00561 
00562         FigureType type;
00563         Rect clientRect;
00564         Attach attach;
00565         Color color;
00566         unsigned char style;
00567         double width;
00568         Color fillAreaColor;
00569         unsigned char fillAreaPattern;
00570         Color fillAreaPatternColor;
00571         double fillAreaPatternWidth;
00572         bool useBorderColor;
00573 
00574         Figure(FigureType _type = Rectangle)
00575         :   type(_type)
00576         {
00577         };
00578     };
00579 
00580     struct LineVertex
00581     {
00582         unsigned char shapeType;
00583         double shapeWidth;
00584         double shapeLength;
00585         double x;
00586         double y;
00587 
00588         LineVertex()
00589         :   shapeType(0)
00590         ,   shapeWidth(0.0)
00591         ,   shapeLength(0.0)
00592         ,   x(0.0)
00593         ,   y(0.0)
00594         {};
00595     };
00596 
00597     struct Line
00598     {
00599         Rect clientRect;
00600         Color color;
00601         Attach attach;
00602         double width;
00603         unsigned char style;
00604         LineVertex begin;
00605         LineVertex end;
00606     };
00607 
00608     struct Bitmap
00609     {
00610         Rect clientRect;
00611         Attach attach;
00612         unsigned long size;
00613         string windowName;
00614         BorderType borderType;
00615         unsigned char* data;
00616 
00617         Bitmap(const string& _name = "")
00618         :   size(0)
00619         ,   windowName(_name)
00620         ,   borderType(Origin::None)
00621         ,   data(0)
00622         {
00623         };
00624 
00625         Bitmap(const Bitmap& bitmap)
00626         :   clientRect(bitmap.clientRect)
00627         ,   attach(bitmap.attach)
00628         ,   size(bitmap.size)
00629         ,   windowName(bitmap.windowName)
00630         ,   borderType(bitmap.borderType)
00631         {
00632             if(size > 0)
00633             {
00634                 data = new unsigned char[size];
00635                 memcpy(data, bitmap.data, size);
00636             }
00637         };
00638 
00639         ~Bitmap()
00640         {
00641             if(size > 0)
00642                 delete data;
00643         };
00644     };
00645 
00646     struct ColorScale
00647     {
00648         bool reverseOrder;
00649         unsigned short labelGap;
00650         unsigned short colorBarThickness;
00651         Color labelsColor;
00652     };
00653 
00654     struct GraphLayer
00655     {
00656         Rect clientRect;
00657         TextBox legend;
00658         Color backgroundColor;
00659         BorderType borderType;
00660 
00661         GraphAxis xAxis;
00662         GraphAxis yAxis;
00663         GraphAxis zAxis;
00664 
00665         GraphAxisBreak xAxisBreak;
00666         GraphAxisBreak yAxisBreak;
00667         GraphAxisBreak zAxisBreak;
00668 
00669         double histogramBin;
00670         double histogramBegin;
00671         double histogramEnd;
00672 
00673         PercentileProperties percentile;
00674         ColorScale colorScale;
00675 
00676         vector<TextBox> texts;
00677         vector<TextBox> pieTexts;
00678         vector<Line> lines;
00679         vector<Figure> figures;
00680         vector<Bitmap> bitmaps;
00681         vector<GraphCurve> curves;
00682 
00683         float xLength;
00684         float yLength;
00685         float zLength;
00686 
00687         bool imageProfileTool;
00688         double vLine;
00689         double hLine;
00690 
00691         bool isXYY3D;
00692 
00693         GraphLayer()
00694         :   imageProfileTool(false)
00695         ,   isXYY3D(false)
00696         {};
00697 
00698         //bool threeDimensional;
00699         bool is3D() const
00700         {
00701             for (vector<GraphCurve>::const_iterator it = curves.begin(); it != curves.end(); ++it)
00702             {
00703                 if (it->type == GraphCurve::Line3D) return true;
00704                 if (it->type == GraphCurve::Mesh3D) return true;
00705             }
00706         return false;
00707         }
00708     };
00709 
00710     struct GraphLayerRange
00711     {
00712         double min;
00713         double max;
00714         double step;
00715 
00716         GraphLayerRange(double _min = 0.0, double _max = 0.0, double _step = 0.0)
00717         :   min(_min)
00718         ,   max(_max)
00719         ,   step(_step)
00720         {};
00721     };
00722 
00723     struct Graph : public Window
00724     {
00725         vector<GraphLayer> layers;
00726         unsigned short width;
00727         unsigned short height;
00728         bool is3D;
00729         bool isLayout;
00730 
00731         Graph(const string& _name = "")
00732         :   Window(_name)
00733         ,   is3D(false)
00734         ,   isLayout(false)
00735         {};
00736     };
00737 
00738     struct Note : public Window
00739     {
00740         string text;
00741         Note(const string& _name = "")
00742         :   Window(_name)
00743         {};
00744     };
00745 
00746     struct ProjectNode
00747     {
00748         enum NodeType {SpreadSheet, Matrix, Excel, Graph, Graph3D, Note, Folder};
00749 
00750         NodeType type;
00751         string name;
00752         time_t creationDate;
00753         time_t modificationDate;
00754 
00755         ProjectNode(const string& _name = "", NodeType _type = Folder, const time_t _creationDate = time(NULL), const time_t _modificationDate = time(NULL))
00756         :   type(_type)
00757         ,   name(_name)
00758         ,   creationDate(_creationDate)
00759         ,   modificationDate(_modificationDate)
00760         {};
00761     };
00762 }
00763 
00764 
00765 
00766 #endif // ORIGIN_OBJ_H