VSDGeometryList.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libvisio project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef __VSDGEOMETRYLIST_H__
00011 #define __VSDGEOMETRYLIST_H__
00012 
00013 #include <vector>
00014 #include <map>
00015 #include <vector>
00016 #include <functional>
00017 #include <algorithm>
00018 #include <boost/optional.hpp>
00019 #include "VSDTypes.h"
00020 
00021 namespace libvisio
00022 {
00023 
00024 class VSDCollector;
00025 
00026 class VSDGeometryListElement
00027 {
00028 public:
00029   VSDGeometryListElement(unsigned id, unsigned level)
00030     : m_id(id), m_level(level) {}
00031   virtual ~VSDGeometryListElement() {}
00032   virtual void handle(VSDCollector *collector) const = 0;
00033   virtual VSDGeometryListElement *clone() = 0;
00034   virtual unsigned getDataID() const
00035   {
00036     return MINUS_ONE;
00037   }
00038   void setLevel(unsigned level)
00039   {
00040     m_level = level;
00041   }
00042 protected:
00043   unsigned m_id;
00044   unsigned m_level;
00045 };
00046 
00047 class VSDGeometryList
00048 {
00049 public:
00050   VSDGeometryList();
00051   VSDGeometryList(const VSDGeometryList &geomList);
00052   ~VSDGeometryList();
00053   VSDGeometryList &operator=(const VSDGeometryList &geomList);
00054 
00055   void addGeometry(unsigned id, unsigned level, const boost::optional<bool> &noFill,
00056                    const boost::optional<bool> &noLine, const boost::optional<bool> &noShow);
00057   void addEmpty(unsigned id, unsigned level);
00058   void addMoveTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y);
00059   void addLineTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y);
00060   void addArcTo(unsigned id, unsigned level, const boost::optional<double> &x2, const boost::optional<double> &y2,
00061                 const boost::optional<double> &bow);
00062   void addNURBSTo(unsigned id, unsigned level, double x2, double y2, unsigned char xType, unsigned char yType, unsigned degree,
00063                   const std::vector<std::pair<double, double> > &controlPoints, const std::vector<double> &knotVector,
00064                   const std::vector<double> &weights);
00065   void addNURBSTo(unsigned id, unsigned level, double x2, double y2, double knot, double knotPrev, double weight, double weightPrev, unsigned dataID);
00066   void addNURBSTo(unsigned id, unsigned level, const boost::optional<double> &x2, const boost::optional<double> &y2,
00067                   const boost::optional<double> &knot, const boost::optional<double> &knotPrev, const boost::optional<double> &weight,
00068                   const boost::optional<double> &weightPrev, const boost::optional<NURBSData> &data);
00069   void addPolylineTo(unsigned id , unsigned level, double x, double y, unsigned char xType, unsigned char yType,
00070                      const std::vector<std::pair<double, double> > &points);
00071   void addPolylineTo(unsigned id , unsigned level, double x, double y, unsigned dataID);
00072   void addPolylineTo(unsigned id , unsigned level, boost::optional<double> &x, boost::optional<double> &y, boost::optional<PolylineData> &data);
00073   void addEllipse(unsigned id, unsigned level, const boost::optional<double> &cx, const boost::optional<double> &cy,
00074                   const boost::optional<double> &xleft, const boost::optional<double> &yleft,
00075                   const boost::optional<double> &xtop, const boost::optional<double> &ytop);
00076   void addEllipticalArcTo(unsigned id, unsigned level, const boost::optional<double> &x3, const boost::optional<double> &y3,
00077                           const boost::optional<double> &x2, const boost::optional<double> &y2,
00078                           const boost::optional<double> &angle, const boost::optional<double> &ecc);
00079   void addSplineStart(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y,
00080                       const boost::optional<double> &secondKnot, const boost::optional<double> &firstKnot,
00081                       const boost::optional<double> &lastKnot, const boost::optional<unsigned> &degree);
00082   void addSplineKnot(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y,
00083                      const boost::optional<double> &knot);
00084   void addInfiniteLine(unsigned id, unsigned level, const boost::optional<double> &x1, const boost::optional<double> &y1,
00085                        const boost::optional<double> &x2, const boost::optional<double> &y2);
00086   void addRelCubBezTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y,
00087                       const boost::optional<double> &a, const boost::optional<double> &b,
00088                       const boost::optional<double> &c, const boost::optional<double> &d);
00089   void addRelEllipticalArcTo(unsigned id, unsigned level, const boost::optional<double> &x3, const boost::optional<double> &y3,
00090                              const boost::optional<double> &x2, const boost::optional<double> &y2,
00091                              const boost::optional<double> &angle, const boost::optional<double> &ecc);
00092   void addRelMoveTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y);
00093   void addRelLineTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y);
00094   void addRelQuadBezTo(unsigned id, unsigned level, const boost::optional<double> &x, const boost::optional<double> &y,
00095                        const boost::optional<double> &a, const boost::optional<double> &b);
00096   void setElementsOrder(const std::vector<unsigned> &m_elementsOrder);
00097   void handle(VSDCollector *collector) const;
00098   void clear();
00099   bool empty() const
00100   {
00101     return (m_elements.empty());
00102   }
00103   VSDGeometryListElement *getElement(unsigned index) const;
00104   std::vector<unsigned> getElementsOrder() const
00105   {
00106     return m_elementsOrder;
00107   }
00108   unsigned count() const
00109   {
00110     return m_elements.size();
00111   }
00112   void resetLevel(unsigned level);
00113 private:
00114   void clearElement(unsigned id);
00115   std::map<unsigned, VSDGeometryListElement *> m_elements;
00116   std::vector<unsigned> m_elementsOrder;
00117 };
00118 
00119 } // namespace libvisio
00120 
00121 #endif // __VSDGEOMETRYLIST_H__
00122 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */