Gui/ViewProvider.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2004 Jürgen Riegel <juergen.riegel@web.de>              *
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 
00024 #ifndef GUI_VIEWPROVIDER_H
00025 #define GUI_VIEWPROVIDER_H
00026 
00027 #include <map>
00028 #include <vector>
00029 #include <string>
00030 #include <QIcon>
00031 #include <boost/signals.hpp>
00032 
00033 class SbVec3f;
00034 class SoNode;
00035 class SoPath;
00036 class SoSeparator;
00037 class SoEvent;
00038 class SoSwitch;
00039 class SoTransform;
00040 class SbMatrix;
00041 class SoEventCallback;
00042 class SoPickedPoint;
00043 class QString;
00044 class QMenu;
00045 class QObject;
00046 
00047 
00048 namespace Base {
00049   class Matrix4D;
00050 }
00051 namespace App {
00052   class Color;
00053 }
00054 
00055 #include <App/PropertyContainer.h>
00056 #include <Base/Vector3D.h>
00057 
00058 namespace Gui {
00059     namespace TaskView {
00060         class TaskContent;
00061     }
00062 class View3DInventorViewer;
00063 class ViewProviderPy;
00064 class ObjectItem;
00065 
00066 
00074 class GuiExport ViewProvider : public App::PropertyContainer
00075 {
00076     PROPERTY_HEADER(Gui::ViewProvider);
00077 
00078 public:
00080     ViewProvider();
00081 
00083     virtual ~ViewProvider();
00084 
00085     // returns the root node of the Provider (3D)
00086     virtual SoSeparator* getRoot(void){return pcRoot;}
00087     // returns the root for the Annotations. 
00088     SoSeparator* getAnnotation(void);
00089     // returns the root node of the Provider (3D)
00090     virtual SoSeparator* getFrontRoot(void) const {return 0;}
00091     // returns the root node of the Provider (3D)
00092     virtual SoSeparator* getBackRoot(void) const {return 0;}
00093 
00100 
00102     virtual bool useNewSelectionModel(void) const {return false;}
00104     virtual bool isSelectable(void) const {return true;}
00106     virtual std::string getElement(const SoPickedPoint *) const { return std::string(); }
00108     virtual std::vector<Base::Vector3d> getSelectionShape(const char* Element) const
00109     { return std::vector<Base::Vector3d>(); };
00111     virtual bool onDelete(const std::vector<std::string> &)
00112     { return true;}
00114 
00115 
00122 
00123     virtual QIcon getIcon(void) const;
00131     virtual std::vector<App::DocumentObject*> claimChildren(void) const
00132     { return std::vector<App::DocumentObject*>(); }
00134 
00137 
00138     boost::signal<void ()> signalChangeIcon;
00140     boost::signal<void (const QString&)> signalChangeToolTip;
00142     boost::signal<void (const QString&)> signalChangeStatusTip;
00144 
00151     void update(const App::Property*);
00152     virtual void updateData(const App::Property*)=0;
00153     bool isUpdatesEnabled () const;
00154     void setUpdatesEnabled (bool enable);
00155 
00156     std::string toString() const;
00157     PyObject* getPyObject();
00158 
00162     std::string getActiveDisplayMode(void) const;
00164     virtual void setDisplayMode(const char* ModeName);
00166     virtual const char* getDefaultDisplayMode() const=0;
00168     virtual std::vector<std::string> getDisplayModes(void) const=0;
00170     virtual void hide(void);
00172     virtual void show(void);
00174     virtual bool isShow(void) const;
00175     void setVisible(bool);
00176     bool isVisible() const;
00178 
00184     enum EditMode {Default = 0,
00185                    Transform,
00186                    Cutting,
00187                    Color,
00188     };
00189 protected:
00191     virtual bool setEdit(int ModNum);
00193     virtual void unsetEdit(int ModNum);
00195     int getEditingMode() const;
00196 
00197 public:
00198     bool startEditing(int ModNum = 0);
00199     bool isEditing() const;
00200     void finishEditing();
00202     virtual void setEditViewer(View3DInventorViewer*, int ModNum);
00204     virtual void unsetEditViewer(View3DInventorViewer*);
00206 
00212 
00213     virtual void getTaskViewContent(std::vector<Gui::TaskView::TaskContent*>&) const {}
00215 
00217     virtual bool keyPressed(bool pressed, int key) { return false; }
00219     virtual bool doubleClicked(void) { return false; }
00221     virtual bool mouseMove(const SbVec3f &pos, const SbVec3f &norm, const SoPickedPoint* pp)
00222     { return false; }
00224     virtual bool mouseButtonPressed(int Button, bool pressed, const SbVec3f &pos,
00225                                     const SbVec3f &norm, const SoPickedPoint* pp)
00226     { return false; }
00228     virtual void setupContextMenu(QMenu*, QObject*, const char*) {}
00229 
00237 
00238     virtual void setTransformation(const Base::Matrix4D &rcMatrix);
00239     virtual void setTransformation(const SbMatrix &rcMatrix);
00240     SbMatrix convert(const Base::Matrix4D &rcMatrix) const;
00242 
00243 public:
00244     // this method is called by the viewer when the ViewProvider is in edit
00245     static void eventCallback(void * ud, SoEventCallback * node);
00246 
00247 protected:
00256 
00257     void addDisplayMaskMode( SoNode *node, const char* type );
00259     void setDisplayMaskMode( const char* type );
00261     std::vector<std::string> getDisplayMaskModes() const;
00262     void setDefaultMode(int);
00264 
00265     SoPickedPoint* getPointOnRay(const SbVec3f& pos,const SbVec3f& dir,
00266         const View3DInventorViewer& viewer) const;
00268     void onChanged(const App::Property* prop);
00269 
00270 protected:
00272     SoSeparator *pcRoot;
00274     SoTransform *pcTransform;
00275     const char* sPixmap;
00277     SoSwitch    *pcModeSwitch;
00279     SoSeparator *pcAnnotation;
00280     ViewProviderPy* pyViewObject;
00281 
00282 private:
00283     int _iActualMode;
00284     int _iEditMode;
00285     std::string _sCurrentMode;
00286     std::map<std::string, int> _sDisplayMaskModes;
00287     bool _updateData;
00288 
00289     // friends
00290     friend class ViewProviderPythonFeaturePy;
00291 };
00292 
00293 } // namespace Gui
00294 
00295 #endif // GUI_VIEWPROVIDER_H
00296 

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