ViewProviderSketch.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef SKETCHERGUI_VIEWPROVIDERSKETCH_H
00025 #define SKETCHERGUI_VIEWPROVIDERSKETCH_H
00026
00027 #include <Mod/Part/Gui/ViewProvider2DObject.h>
00028 #include <Inventor/SbColor.h>
00029 #include <Base/Tools2D.h>
00030 #include <Gui/Selection.h>
00031 #include <boost/signals.hpp>
00032
00033
00034 class TopoDS_Shape;
00035 class TopoDS_Face;
00036 class SoSeparator;
00037 class SbVec3f;
00038 class SoCoordinate3;
00039 class SoPointSet;
00040 class SoTransform;
00041 class SoLineSet;
00042 class SoMarkerSet;
00043
00044 class SoText2;
00045 class SoTranslation;
00046 class SbTime;
00047
00048 struct EditData;
00049
00050 namespace Gui {
00051 class View3DInventorViewer;
00052 class SoFCSelection;
00053 }
00054
00055 namespace Sketcher {
00056 class Sketch;
00057 class SketchObject;
00058 }
00059
00060 namespace SketcherGui {
00061
00062 class DrawSketchHandler;
00063
00070 class SketcherGuiExport ViewProviderSketch : public PartGui::ViewProvider2DObject, public Gui::SelectionObserver
00071 {
00072 PROPERTY_HEADER(PartGui::ViewProviderSketch);
00073
00074 public:
00076 ViewProviderSketch();
00078 virtual ~ViewProviderSketch();
00079
00080 App::PropertyBool Autoconstraints;
00081
00083 void drawConstraintIcons();
00085 void draw(bool temp=false);
00087 void drawEdit(const std::vector<Base::Vector2D> &EditCurve);
00088
00090 bool isSelectable(void) const;
00092 virtual void onSelectionChanged(const Gui::SelectionChanges& msg);
00093
00096
00097 void activateHandler(DrawSketchHandler *newHandler);
00099 void purgeHandler(void);
00101
00104
00105 enum SketchMode{
00106 STATUS_NONE,
00107 STATUS_SELECT_Point,
00108 STATUS_SELECT_Edge,
00109 STATUS_SELECT_Constraint,
00110 STATUS_SELECT_Cross,
00111 STATUS_SKETCH_DragPoint,
00112 STATUS_SKETCH_DragCurve,
00113 STATUS_SKETCH_DragConstraint,
00114 STATUS_SKETCH_UseHandler
00115 };
00117 void setSketchMode(SketchMode mode) {Mode = mode;}
00119 SketchMode getSketchMode(void) const {return Mode;}
00121
00124
00125 void getCoordsOnSketchPlane(double &u, double &v,const SbVec3f &point, const SbVec3f &normal);
00127
00129 bool detectPreselection(const SoPickedPoint *Point, int &PtIndex,int &CurvIndex, int &ConstrIndex, int &CrossIndex);
00131 void updateColor(void);
00133 Sketcher::SketchObject *getSketchObject(void) const;
00134
00136 void snapToGrid(double &x, double &y);
00137
00139 void moveConstraint(int constNum, const Base::Vector2D &toPos);
00141 bool isConstraintAtPosition(const Base::Vector3d &constrPos, const SoNode *constraint);
00143 Base::Vector3d seekConstraintPosition(const Base::Vector3d &suggestedPos,
00144 const Base::Vector3d &dir, float step,
00145 const SoNode *constraint);
00146
00147 float getScaleFactor();
00148 int getPreselectPoint(void) const;
00149 int getPreselectCurve(void) const;
00150 int getPreselectConstraint(void) const;
00152
00155 virtual void attach(App::DocumentObject *);
00156 virtual void updateData(const App::Property *);
00157
00158 virtual void setupContextMenu(QMenu *menu, QObject *receiver, const char *member);
00160 virtual bool onDelete(const std::vector<std::string> &);
00162 virtual bool doubleClicked(void);
00164 virtual bool mouseMove(const SbVec3f &pNear, const SbVec3f &pFar, const SoPickedPoint *pp);
00166 virtual bool keyPressed(bool pressed, int key);
00168 virtual bool mouseButtonPressed(int Button, bool pressed, const SbVec3f &point,
00169 const SbVec3f &normal, const SoPickedPoint *pp);
00171
00172 friend class DrawSketchHandler;
00173
00175 boost::signal<void ()> signalConstraintsChanged;
00177 boost::signal<void (int type, int dofs, std::string &msg)> signalSetUp;
00179 boost::signal<void (int type, float time)> signalSolved;
00180
00181 protected:
00182 virtual bool setEdit(int ModNum);
00183 virtual void unsetEdit(int ModNum);
00184 virtual void setEditViewer(Gui::View3DInventorViewer*, int ModNum);
00185 virtual void unsetEditViewer(Gui::View3DInventorViewer*);
00187 bool isPointOnSketch(const SoPickedPoint *pp) const;
00189 virtual void onChanged(const App::Property *prop);
00190
00192 void editDoubleClicked(void);
00193
00195 void createEditInventorNodes(void);
00197 EditData *edit;
00199 void rebuildConstraintsVisual(void);
00200
00201 void setPositionText(const Base::Vector2D &Pos);
00202 void resetPositionText(void);
00203
00204
00205 void setPreselectPoint(int PreselectPoint);
00206 void resetPreselectPoint(void);
00207 void addSelectPoint(int SelectPoint);
00208 void removeSelectPoint(int SelectPoint);
00209 void clearSelectPoints(void);
00210
00211
00212 SketchMode Mode;
00213
00214
00215 static SbColor VertexColor;
00216 static SbColor CurveColor;
00217 static SbColor CurveDraftColor;
00218 static SbColor CrossColorV;
00219 static SbColor CrossColorH;
00220 static SbColor FullyConstrainedColor;
00221 static SbColor ConstrDimColor;
00222 static SbColor ConstrIcoColor;
00223 static SbColor PreselectColor;
00224 static SbColor SelectColor;
00225
00226 static SbTime prvClickTime;
00227 static SbVec3f prvClickPoint;
00228
00229 float zCross;
00230 float zLines;
00231 float zPoints;
00232 float zConstr;
00233 float zHighlight;
00234 float zText;
00235 float zEdit;
00236
00237
00238 double xInit,yInit;
00239 bool relative;
00240 };
00241
00242 }
00243
00244
00245 #endif // SKETCHERGUI_VIEWPROVIDERSKETCH_H
00246