arbeit
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

EdgeWidget.h

Go to the documentation of this file.
00001 //------------------------------------------------------------------------
00002 //
00003 //   Joe Kniss
00004 //     6-20-03
00005 //                   ________    ____   ___ 
00006 //                  |        \  /    | /  /
00007 //                  +---+     \/     |/  /
00008 //                  +--+|  |\    /|     < 
00009 //                  |  ||  | \  / |  |\  \ 
00010 //                  |      |  \/  |  | \  \ 
00011 //                   \_____|      |__|  \__\
00012 //                       Copyright  2003 
00013 //                      Joe Michael Kniss
00014 //                   <<< jmk@cs.utah.edu >>>
00015 //               "All Your Base are Belong to Us"
00016 //-------------------------------------------------------------------------
00017 
00018 /// EdgeWidget.h
00019 
00020 
00021 #ifndef __EDGE_WIDGET_DOT_H
00022 #define __EDGE_WIDGET_DOT_H
00023 
00024 #include "WidgetBase.h"
00025 #include <signalGutz.h>
00026 
00027 /// forward decl.
00028 class NodeWidget;
00029 
00030 const gutz::vec4f defEdgeColor = gutz::vec4f(.3645f, .3529f, .7569f, 1.0f);
00031 
00032 ///////////////////////////////////////////////////////////////////////////
00033 ///////////////////////////////////////////////////////////////////////////
00034 /// an edge (line) composed of 2 points (start/end)
00035 ///////////////////////////////////////////////////////////////////////////
00036 ///////////////////////////////////////////////////////////////////////////
00037 class EdgeWidget: public WidgetItem
00038 {
00039 public:
00040 
00041    virtual ~EdgeWidget(); 
00042 
00043    /// assignment operator, just copys start/end point info
00044    EdgeWidget &operator=(const EdgeWidget &ew)
00045    {
00046       WidgetItem::operator =(ew);
00047       setStartPoint(ew.getStartPoint());
00048       setEndPoint(ew.getEndPoint());
00049       setRad(ew.getRad());
00050       return *this;
00051    }
00052 
00053    ///@name Clones
00054    ///@{
00055 
00056    /// WidgetItem::clone definition
00057    WidgetItem *clone() const
00058    {  return cloneEdge(); }
00059 
00060    /// Pure virtual cloneEdge(), must be defined in concrete EdgeWidget class
00061    virtual EdgeWidget *cloneEdge() const = 0;
00062    
00063    ///@}
00064 
00065    /// object changed
00066    virtual void setChanged()
00067    {
00068       startPointChanged( getStartPoint() );
00069       endPointChanged( getEndPoint() );
00070    }
00071 
00072    HAS_SLOTS;
00073 
00074    /// set start [sx,sy] and end [ex, ey] points
00075    void setPoints(const gutz::vec3f &start, const gutz::vec3f &end);
00076 
00077    /// tightest 2D polygonal bound
00078    virtual Point2Array  getValidArea() const;
00079 
00080    ///////////////////////////////////////////////
00081    ///@name set/get Points
00082    ///    The "sets" serve as slots
00083    ///@{
00084    gutz::vec3f  getStartPoint() const                    
00085    { return _manip->getWorldPosLocal(_start); }
00086    gutz::vec3f  getEndPoint()   const                    
00087    { return _manip->getWorldPosLocal(_end); }
00088    virtual void setStartPoint(const gutz::vec3f &start);
00089    virtual void setEndPoint(const gutz::vec3f &end);
00090    ///@}
00091    ///////////////////////////////////////////////
00092 
00093    ///////////////////////////////////////////////
00094    ///@name set/get Radius
00095    ///     setRad(float) is a slot
00096    ///@{
00097    float         getRad() const  { return _rad; }
00098    virtual void  setRad(float r) 
00099    { if(_rad == r) return; _rad = r; radChanged(_rad); appearanceChanged();}
00100    ///@}
00101    ///////////////////////////////////////////////
00102 
00103    ///////////////////////////////////////////////
00104    ///@name Signals
00105    ///@{
00106 
00107    /// signal: startPointChanged(const vec3f &s)
00108    gutz::Signal<const gutz::vec3f &> startPointChanged;
00109    /// signal: endPointChanged(const vec3f &e)
00110    gutz::Signal<const gutz::vec3f &> endPointChanged;
00111    /// signal: radChanged(float r)
00112    gutz::Signal<float> radChanged;
00113 
00114    ///@}
00115    ///////////////////////////////////////////////
00116 
00117    ///////////////////////////////////////////////
00118    ///@name mouse Behaviors from WidgetItem
00119    ///   using default mouseDef from WidgetItem
00120    ///@{
00121    //virtual bool moveDef(const gutz::MouseMoveEvent &mme);
00122    ///@}
00123 
00124    ///////////////////////////////////////////////
00125    ///@name transform widget
00126    ///@{
00127    virtual void    applyXform(gutz::mat4f xf)
00128    { 
00129       setStartPoint(xf.tpoint(getStartPoint()));
00130       setEndPoint(xf.tpoint(getEndPoint()));
00131    }
00132    ///@}
00133 
00134    ///////////////////////////////////////////////
00135    ///@name Connect a NodeWidget to start/end
00136    ///   fully connects Node->Edge, Edge->Node
00137    ///@{
00138    void setStartNode(NodeWidget *nw);
00139    void setEndNode(NodeWidget *nw);
00140    ///@}
00141 
00142 protected:
00143 
00144    /// link to a pair of node widgets
00145    EdgeWidget( NodeWidget* start, NodeWidget* end, float rad = -1, 
00146                WidgetItem* parent = 0);
00147    /// just make it, using some default points
00148    EdgeWidget( const gutz::vec3f &start, const gutz::vec3f &end, float rad = -1,
00149                WidgetItem *parent = 0);
00150 
00151    EdgeWidget(const EdgeWidget &ew)
00152       : WidgetItem(ew), _start(ew._start), _end(ew._end), _rad(ew._rad)
00153    {}
00154 
00155    Point2Array get2DBound() const;
00156 
00157    gutz::vec3f   _start;
00158    gutz::vec3f   _end;
00159    float         _rad;
00160 };
00161 
00162 typedef gutz::SmartPtr<EdgeWidget> EdgeWidgetSP;
00163 typedef std::vector<EdgeWidgetSP>  EdgeWidgetVec;
00164 typedef EdgeWidgetVec::iterator    EdgeWidgetVecIter;
00165 
00166 
00167 #endif
00168 
00169 

Send questions, comments, and bug reports to:
jmk