SciFigs/Symbol.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of SciFigs.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2002-10-08
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (ULg, Liège, Belgium)
00025 **    Marc Wathelet (LGIT, Grenoble, France)
00026 **
00027 ***************************************************************************/
00028 
00029 #ifndef SYMBOL_H
00030 #define SYMBOL_H
00031 
00032 #include "SciFigsDLLExport.h"
00033 #include "Pen.h"
00034 #include "Brush.h"
00035 
00036 namespace SciFigs {
00037 
00038   class SCIFIGS_EXPORT Symbol : public XMLClass
00039   {
00040    public:
00041     enum Type{NoSymbol, Cross, Square, Circle, TriangleUp, TriangleDown, Losange, Star};
00042     Symbol(Type type=NoSymbol, double size=1.2, Pen pen=Pen(Qt::black),
00043            Brush brush=Brush(Qt::NoBrush));
00044     Symbol(const Symbol& s);
00045     virtual ~Symbol() {}
00046 
00047     Symbol& operator=(const Symbol& o);
00048     bool operator==(const Symbol& o) const;
00049 
00050     virtual const QString& xml_tagName() const {return xmlSymbolTag;}
00051     static const QString xmlSymbolTag;
00052 
00053     static Type symbolValue(QString s);
00054     static QString symbolName(Type s);
00055 
00056     void fromStream(QTextStream& s);
00057 
00058     void setType(Type t) {_type=t;}
00059     Type type() const {return _type;}
00060 
00061     void setSize(double s) {_size=s;}
00062     double size() const {return _size;}
00063 
00064     void setPen(const Pen& p) {_pen=p;}
00065     const Pen& pen() const {return _pen;}
00066 
00067     void setBrush(const Brush& b) {_brush=b;}
00068     const Brush& brush() const {return _brush;}
00069 
00070     void paint(QPainter& p, const QPointF &center, double dotpercm=28.346457) const;
00071     static inline void paint(Type type, QPainter& p, QPointF center,
00072                              double size, double halfSize);
00073 
00074     static const Symbol null;
00075   protected:
00076     virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00077     virtual void xml_writeChildren(XML_WRITECHILDREN_ARGS) const;
00078     virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00079     virtual XMLMember xml_member(XML_MEMBER_ARGS);
00080   protected:
00081     Type _type;
00082     // Size in mm
00083     double _size;
00084     Pen _pen;
00085     Brush _brush;
00086   };
00087 
00088   // SCIFIGS_EXPORT QTextStream& operator>>(QTextStream& s, Symbol& sym);
00089 
00090   inline void Symbol::paint(Type type, QPainter& p, QPointF center,
00091                             double size, double halfSize)
00092   {
00093     TRACE;
00094     switch(type) {
00095     case Cross: {
00096         QPointF h1(halfSize, halfSize);
00097         QPointF h2(halfSize, -halfSize);
00098         p.drawLine(center-h1, center+h1);
00099         p.drawLine(center-h2, center+h2);
00100       }
00101       break;
00102     case Square: {
00103         p.drawRect(QRectF(center-QPointF(halfSize, halfSize),QSizeF(size,size)));
00104       }
00105       break;
00106     case Circle: {
00107         p.drawEllipse(center, halfSize, halfSize);
00108       }
00109       break;
00110     case TriangleUp: {
00111         QPolygonF points(4);
00112         double halfSize=0.5*0.866025403784439*size;
00113         center+=QPointF(-halfSize, 0.25*size);
00114         points[0]=center;
00115         points[1]=center+QPointF(0.866025403784439*size, 0);
00116         points[2]=center+QPointF(halfSize, -0.75*size);
00117         points[3]=points[0];
00118         p.drawPolygon(points);
00119       }
00120       break;
00121     case TriangleDown: {
00122         QPolygonF points(4);
00123         double halfSize=0.5*0.866025403784439*size;
00124         center+=QPointF(-halfSize, -0.25*size);
00125         points[0]=center;
00126         points[1]=center+QPointF(0.866025403784439*size, 0);
00127         points[2]=center+QPointF(halfSize, 0.75*size);
00128         points[3]=points[0];
00129         p.drawPolygon(points);
00130       }
00131       break;
00132     case Losange: {
00133         QPolygonF points(5);
00134         double quarterSize=size*0.25;
00135         points[0]=center-QPointF(0.0, halfSize);
00136         points[1]=center+QPointF(quarterSize, 0.0);
00137         points[2]=center+QPointF(0.0, halfSize);
00138         points[3]=center-QPointF(quarterSize, 0.0);
00139         points[4]=points[0];
00140         p.drawPolygon (points);
00141       }
00142       break;
00143     case Star: {
00144         QPointF h1(halfSize, halfSize);
00145         QPointF h2(halfSize, -halfSize);
00146         QPointF h3(halfSize, 0.0);
00147         QPointF h4(0.0, halfSize);
00148         p.drawLine(center-h1, center+h1);
00149         p.drawLine(center-h2, center+h2);
00150         p.drawLine(center-h3, center+h3);
00151         p.drawLine(center-h4, center+h4);
00152       }
00153       break;
00154     default:
00155       break;
00156     }
00157   }
00158 
00159 } // namespace SciFigs
00160 
00161 #endif // SYMBOL_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines