hipp  1.0
hipp/gui/HippShape.h
Go to the documentation of this file.
00001 /*
00002         Copyright 2011 Certec, Lund University, Sweden
00003 
00004     This file is part of HIPP.
00005 
00006     HIPP is free software: you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation, either version 3 of the License, or
00009     (at your option) any later version.
00010 
00011     HIPP is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with HIPP.  If not, see <http://www.gnu.org/licenses/>.
00018 
00019  */
00020 
00021 #ifndef __HIPPSHAPE_H__
00022 #define __HIPPSHAPE_H__
00023 
00024 #include "config.h"
00025 
00026 #include <wx/object.h>
00027 #include <wx/stream.h>
00028 #include <wx/filename.h>
00029 #include <wx/wx.h>
00030 #include <cairomm/context.h>
00031 #include <map>
00032 #include <string>
00033 #include <iostream>
00034 #include <wx/dc.h>
00035 #include <xercesc/sax2/Attributes.hpp>
00036 #include <xercesc/util/XMLString.hpp>
00037 #include <boost/assign.hpp>
00038 
00040 namespace hipp {
00041 static enum ShapeType {
00042     NotUsed, Polyline, Polygon, Line, Circle, Rectangle, Ellipse, Path, Image
00043 };
00044 
00045 static std::map<std::string, ShapeType> ShapeTypeMap =
00046                                         boost::assign::map_list_of("polyline",Polyline)
00047                                                                   ("polygon",Polygon)
00048                                                                   ("line",Line)
00049                                                                   ("circle",Circle)
00050                                                                   ("rect", Rectangle)
00051                                                                   ("ellipse", Ellipse)
00052                                                                   ("path",Path)
00053                                                                   ("image",Image);
00054 
00069 class HippShape: public wxEvtHandler {
00070 public:
00071     HippShape();
00072     ~HippShape();
00073 
00085     virtual void LoadObject(const xercesc::Attributes& attrs, const XMLCh* const localnam);
00086 
00102     virtual void LoadObject(const XMLCh* const chars);
00103     virtual std::ostream& SaveObject(std::ostream& stream);
00104     virtual void cloneMeta(HippShape* hs) const;
00105 
00106     //This does not take into account the width of the lines in the shape
00107     virtual const wxRect& getBounds() const = 0;
00108     //This includes the width of the lines of the shape
00109     virtual wxRect getFullBounds() const;
00110 
00111     virtual bool containsPoint(wxPoint p) const = 0;
00112     //if the type of texture is not specified, output the haptic version
00113     virtual void OnDraw(Cairo::RefPtr<Cairo::Context> context, bool isHaptic = true) const;
00114     virtual HippShape* clone() const = 0;
00115 
00116 #if SHOW_SHAPE_BOUNDS
00117     virtual void DrawBounds(Cairo::RefPtr<Cairo::Context> context) const;
00118 #endif
00119 
00120     virtual void move(int diffX, int diffY) = 0;
00121     virtual void zoom(int scaleX, int scaleY) = 0;
00122 
00123     wxString getDescription() const {
00124         return m_desc;
00125     }
00126 
00127     wxString getTitle() const {
00128         return m_title;
00129     }
00130 
00131     wxString getTitleOrUntitled() const {
00132         return getTitle().IsEmpty() ? _("Untitled") : getTitle();
00133     }
00134 
00135     void setDescription(wxString desc) {
00136         this->m_desc = desc;
00137     }
00138 
00139     void setTitle(wxString title) {
00140         this->m_title = title;
00141     }
00142 
00143     void toggleFill(){
00144         if (isFilled()){
00145             m_filling = wxNullColour;
00146         } else {
00147             if(getColourWhite()) m_filling.Set("white");
00148             else m_filling.Set("black");
00149         }
00150     }
00151 
00152     bool isFilled() const {
00153         return m_filling.IsOk() ? true : false;
00154     }
00155 
00156     int getLineWidth() const {
00157         return lineWidth;
00158     }
00159 
00160         virtual void setLineWidth(int w) {
00161                 if (w>0 && w<512*2) lineWidth = w;
00162         }
00163 
00164     void setSoundFile (wxString soundfile) {
00165         this->m_soundfile = soundfile;
00166         wxLogDebug (m_soundfile);
00167     }
00168 
00169     wxString getSoundFile () const {
00170         return m_soundfile;
00171     }
00172 
00173         // The colour of the shape decides if haptic of the shape is positive or negative
00174         void setColourWhite(bool c) {
00175                 colourWhite = c;
00176         if(isFilled()){
00177             if(c) m_filling.Set("white");
00178             else m_filling.Set("black");
00179         }
00180         }
00181 
00182         bool getColourWhite() const {
00183                 return colourWhite;
00184         }
00185 
00186         bool isDirty() {
00187                 return dirty;
00188         }
00189 
00190         virtual void setDirty() {
00191                 dirty = true;
00192         }
00193 
00194         virtual void resetDirty() {
00195                 dirty = false;
00196         }
00197 
00198     bool hasSound () const;
00199     bool hasMetaInfo() const;
00200     virtual ShapeType getShapeType()=0;
00201 
00202 protected:
00203     wxString m_title;
00204     wxString m_desc;
00205     wxString m_soundfile;
00206         // If haptic feedback of the shape is positive or negative
00207     bool colourWhite;
00208     bool dirty;
00209     wxColour m_filling;
00210         int lineWidth;
00211 private:
00212     wxString* awaiting_data;
00213 };
00214 }//end of hipp namespace
00215 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines