Utilities.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2010 Werner Mayer <wmayer[at]users.sourceforge.net>     *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  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 Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 #ifndef GUI_UTILITIES_H
00024 #define GUI_UTILITIES_H
00025 
00026 #include <Base/ViewProj.h>
00027 #include <App/Material.h>
00028 #include <vector>
00029 #include <Inventor/SbColor.h>
00030 #include <Inventor/SbVec2f.h>
00031 #include <Inventor/SbViewVolume.h>
00032 
00033 class SbViewVolume;
00034 class QAbstractItemView;
00035 
00036 namespace Base {
00037 // Specialization for SbVec3f
00038 template <>
00039 struct vec_traits<SbVec3f> {
00040     typedef SbVec3f vec_type;
00041     typedef float float_type;
00042     vec_traits(const vec_type& v) : v(v){}
00043     inline float_type x() { return v[0]; }
00044     inline float_type y() { return v[1]; }
00045     inline float_type z() { return v[2]; }
00046 private:
00047     const vec_type& v;
00048 };
00049 
00050 // Specialization for SbVec3d
00051 template <>
00052 struct vec_traits<SbVec3d> {
00053     typedef SbVec3d vec_type;
00054     typedef double float_type;
00055     vec_traits(const vec_type& v) : v(v){}
00056     inline float_type x() { return v[0]; }
00057     inline float_type y() { return v[1]; }
00058     inline float_type z() { return v[2]; }
00059 private:
00060     const vec_type& v;
00061 };
00062 
00063 // Specialization for SbColor
00064 template <>
00065 struct vec_traits<SbColor> {
00066     typedef SbColor vec_type;
00067     typedef float float_type;
00068     vec_traits(const vec_type& v) : v(v){}
00069     inline float_type x() { return v[0]; }
00070     inline float_type y() { return v[1]; }
00071     inline float_type z() { return v[2]; }
00072 private:
00073     const vec_type& v;
00074 };
00075 
00076 // Specialization for Color
00077 template <>
00078 struct vec_traits<App::Color> {
00079     typedef App::Color vec_type;
00080     typedef float float_type;
00081     vec_traits(const vec_type& v) : v(v){}
00082     inline float_type x() { return v.r; }
00083     inline float_type y() { return v.g; }
00084     inline float_type z() { return v.b; }
00085 private:
00086     const vec_type& v;
00087 };
00088 }
00089 
00090 namespace App{ class DocumentObject; }
00091 namespace Gui {
00092 
00095 class GuiExport ViewVolumeProjection : public Base::ViewProjMethod
00096 {
00097 public:
00098     ViewVolumeProjection (const SbViewVolume &vv);
00099     virtual ~ViewVolumeProjection(){};
00100 
00101     Base::Vector3f operator()(const Base::Vector3f &rclPt) const;
00102     Base::Vector3d operator()(const Base::Vector3d &rclPt) const;
00103     Base::Vector3f inverse (const Base::Vector3f &rclPt) const;
00104     Base::Vector3d inverse (const Base::Vector3d &rclPt) const;
00105 
00106     Base::Matrix4D getProjectionMatrix () const;
00107 
00108 protected:
00109     SbViewVolume viewVolume;
00110 };
00111 
00112 class GuiExport Tessellator
00113 {
00114 public:
00115     Tessellator(const std::vector<SbVec2f>&);
00116     std::vector<int> tessellate() const;
00117 
00118 private:
00119     static void tessCB(void * v0, void * v1, void * v2, void * cbdata);
00120 
00121 private:
00122     std::vector<SbVec2f> polygon;
00123 };
00124 
00125 class GuiExport ItemViewSelection
00126 {
00127 public:
00128     ItemViewSelection(QAbstractItemView* view);
00129     void applyFrom(const std::vector<App::DocumentObject*> objs);
00130 
00131 private:
00132     QAbstractItemView* view;
00133     class MatchName;
00134 };
00135 
00136 } // namespace Gui
00137 
00138 #endif // GUI_UTILITIES_H

Generated on Wed Nov 23 19:00:56 2011 for FreeCAD by  doxygen 1.6.1