VSDGeometryList.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* libvisio
00003  * Version: MPL 1.1 / GPLv2+ / LGPLv2+
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License or as specified alternatively below. You may obtain a copy of
00008  * the License at http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * Major Contributor(s):
00016  * Copyright (C) 2011 Fridrich Strba <fridrich.strba@bluewin.ch>
00017  * Copyright (C) 2011 Eilidh McAdam <tibbylickle@gmail.com>
00018  *
00019  *
00020  * All Rights Reserved.
00021  *
00022  * For minor contributions see the git repository.
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPLv2+"), or
00026  * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
00027  * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable
00028  * instead of those above.
00029  */
00030 
00031 #ifndef __VSDGEOMETRYLIST_H__
00032 #define __VSDGEOMETRYLIST_H__
00033 
00034 #include <vector>
00035 #include <map>
00036 #include <vector>
00037 #include <functional>
00038 #include <algorithm>
00039 #include <boost/optional.hpp>
00040 #include "VSDTypes.h"
00041 
00042 namespace libvisio
00043 {
00044 
00045 class VSDCollector;
00046 
00047 class VSDGeometryListElement
00048 {
00049 public:
00050   VSDGeometryListElement(unsigned id, unsigned level)
00051     : m_id(id), m_level(level) {}
00052   virtual ~VSDGeometryListElement() {}
00053   virtual void handle(VSDCollector *collector) const = 0;
00054   virtual VSDGeometryListElement *clone() = 0;
00055   virtual unsigned getDataID() const
00056   {
00057     return MINUS_ONE;
00058   }
00059   void setLevel(unsigned level)
00060   {
00061     m_level = level;
00062   }
00063 protected:
00064   unsigned m_id;
00065   unsigned m_level;
00066 };
00067 
00068 class VSDGeometryList
00069 {
00070 public:
00071   VSDGeometryList();
00072   VSDGeometryList(const VSDGeometryList &geomList);
00073   ~VSDGeometryList();
00074   VSDGeometryList &operator=(const VSDGeometryList &geomList);
00075 
00076   void addGeometry(unsigned id, unsigned level, const boost::optional<bool> &noFill,
00077                    const boost::optional<bool> &noLine, const boost::optional<bool> &noShow);
00078   void addEmpty(unsigned id, unsigned level);
00079   void addMoveTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y);
00080   void addLineTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y);
00081   void addArcTo(unsigned id, unsigned level, const boost::optional<double> &x2, const boost::optional<double> &y2,
00082                 const boost::optional<double> &bow);
00083   void addNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType, unsigned degree,
00084                   const std::vector<std::pair<double, double> > &controlPoints, const std::vector<double> &knotVector,
00085                   const std::vector<double> &weights);
00086   void addNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID);
00087   void addNURBSTo(unsigned id, unsigned level, const boost::optional<double> &x2, const boost::optional<double> &y2,
00088                   const boost::optional<double> &knot, const boost::optional<double> &knotPrev, const boost::optional<double> &weight,
00089                   const boost::optional<double> &weightPrev, const boost::optional<NURBSData> &data);
00090   void addPolylineTo(unsigned id , unsigned level, double x, double y, unsigned char xType, unsigned char yType,
00091                      const std::vector<std::pair<double, double> > &points);
00092   void addPolylineTo(unsigned id , unsigned level, double x, double y, unsigned dataID);
00093   void addPolylineTo(unsigned id , unsigned level, boost::optional<double> &x, boost::optional<double> &y, boost::optional<PolylineData> &data);
00094   void addEllipse(unsigned id, unsigned level, const boost::optional<double> &cx, const boost::optional<double> &cy,
00095                   const boost::optional<double> &xleft, const boost::optional<double> &yleft,
00096                   const boost::optional<double> &xtop, const boost::optional<double> &ytop);
00097   void addEllipticalArcTo(unsigned id, unsigned level, const boost::optional<double> &x3, const boost::optional<double> &y3,
00098                           const boost::optional<double> &x2, const boost::optional<double> &y2,
00099                           const boost::optional<double> &angle, const boost::optional<double> &ecc);
00100   void addSplineStart(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y,
00101                       const boost::optional<double> &secondKnot, const boost::optional<double> &firstKnot,
00102                       const boost::optional<double> &lastKnot, const boost::optional<unsigned> &degree);
00103   void addSplineKnot(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y,
00104                      const boost::optional<double> &knot);
00105   void addInfiniteLine(unsigned id, unsigned level, const boost::optional<double> &x1, const boost::optional<double> &y1,
00106                        const boost::optional<double> &x2, const boost::optional<double> &y2);
00107   void addRelCubBezTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y,
00108                       const boost::optional<double> &a, const boost::optional<double> &b,
00109                       const boost::optional<double> &c, const boost::optional<double> &d);
00110   void addRelEllipticalArcTo(unsigned id, unsigned level, const boost::optional<double> &x3, const boost::optional<double> &y3,
00111                              const boost::optional<double> &x2, const boost::optional<double> &y2,
00112                              const boost::optional<double> &angle, const boost::optional<double> &ecc);
00113   void addRelMoveTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y);
00114   void addRelLineTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y);
00115   void addRelQuadBezTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y,
00116                        const boost::optional<double> &a, const boost::optional<double> &b);
00117   void setElementsOrder(const std::vector<unsigned> &m_elementsOrder);
00118   void handle(VSDCollector *collector) const;
00119   void clear();
00120   bool empty() const
00121   {
00122     return (m_elements.empty());
00123   }
00124   VSDGeometryListElement *getElement(unsigned index) const;
00125   std::vector<unsigned> getElementsOrder() const
00126   {
00127     return m_elementsOrder;
00128   }
00129   unsigned count() const
00130   {
00131     return m_elements.size();
00132   }
00133   void resetLevel(unsigned level);
00134 private:
00135   void clearElement(unsigned id);
00136   std::map<unsigned, VSDGeometryListElement *> m_elements;
00137   std::vector<unsigned> m_elementsOrder;
00138 };
00139 
00140 } // namespace libvisio
00141 
00142 #endif // __VSDGEOMETRYLIST_H__
00143 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */