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

EdgeWidget.cpp

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.cpp
00019 
00020 
00021 #include "EdgeWidget.h"
00022 #include "NodeWidget.h"
00023 #include <iostream>
00024 
00025 using namespace gutz;
00026 using namespace std;
00027 
00028 ///////////////////////////////////////////////////////////////////////////
00029 ///////////////////////////////////////////////////////////////////////////
00030 /// EdgeWidget
00031 ///////////////////////////////////////////////////////////////////////////
00032 ///////////////////////////////////////////////////////////////////////////
00033 
00034 ///////////////////////////////////////////////////////////////////////////
00035 /// Construct
00036 /// from a pair of nodes
00037 EdgeWidget::EdgeWidget( NodeWidget *start, NodeWidget *end, float rad, 
00038                         WidgetItem *parent)
00039 : WidgetItem( parent ), _rad(1)
00040 {
00041    if(rad != -1)
00042       _rad = rad;
00043    
00044    setStartNode(start);
00045    setEndNode(end);
00046 }
00047 
00048 /// just a line
00049 EdgeWidget::EdgeWidget( const gutz::vec3f &start, const gutz::vec3f &end,  
00050                        float rad, WidgetItem *parent)
00051 : WidgetItem( parent ), _rad(1), _start(start), _end(end)
00052 {
00053    if(rad != -1)
00054       _rad = rad;
00055 }
00056 
00057 EdgeWidget::~EdgeWidget() 
00058 {
00059 
00060 }
00061 
00062 ///////////////////////////////////////////////////////////////////////////
00063 /// Set Points
00064 void EdgeWidget::setPoints(const gutz::vec3f &start, const gutz::vec3f &end)
00065 {
00066    setStartPoint(start);
00067    setEndPoint(end);
00068 }
00069 
00070 
00071 ///////////////////////////////////////////////////////////////////////////
00072 /// area Points
00073 WidgetItem::Point2Array EdgeWidget::getValidArea() const
00074 {
00075    Point2Array p(4,Point2(0));
00076    /// line end points
00077    float x1 = _start.x;
00078    float x2 = _end.x;
00079    float y1 = _start.y;
00080    float y2 = _end.y;
00081    /// bar width
00082    float w = _rad;
00083    float dx = g_abs(x1-x2);
00084    float dy = g_abs(y1-y2);
00085    w = w*4/3+2; // approx pw*sqrt(2)
00086    float px = x1<x2 ? -w : w ;
00087    float py = y1<y2 ? -w : w ;
00088    if ( dx && dy && (dx > dy ? (dx*2/dy <= 2) : (dy*2/dx <= 2)) ) {
00089       // steep
00090       if ( px == py ) {
00091          p[0] = Point2(x1   ,y1+py);
00092          p[1] = Point2(x2-px,y2   );
00093          p[2] = Point2(x2   ,y2-py);
00094          p[3] = Point2(x1+px,y1   );
00095       } else {
00096          p[0] = Point2(x1+px,y1   );
00097          p[1] = Point2(x2   ,y2-py);
00098          p[2] = Point2(x2-px,y2   );
00099          p[3] = Point2(x1   ,y1+py);
00100       }
00101    } else if ( dx > dy ) {
00102       // horizontal
00103       p[0] = Point2(x1+px,y1+py);
00104       p[1] = Point2(x2-px,y2+py);
00105       p[2] = Point2(x2-px,y2-py);
00106       p[3] = Point2(x1+px,y1-py);
00107    } else {
00108       // vertical
00109       p[0] = Point2(x1+px,y1+py);
00110       p[1] = Point2(x2+px,y2-py);
00111       p[2] = Point2(x2-px,y2-py);
00112       p[3] = Point2(x1-px,y1+py);
00113    }
00114 
00115    return p;
00116 }
00117 
00118 ///////////////////////////////////////////////////////////////////////////
00119 /// Set Start Point
00120 void EdgeWidget::setStartPoint(const gutz::vec3f &start)
00121 {
00122    vec3f pt = getStartPoint() - start;
00123    if( pt.dot(pt) < .000001 ) return;
00124 
00125    _invalidate();
00126    {
00127       _start = _manip->getLocalPosWorld(start);
00128    }
00129    _update();
00130 
00131    startPointChanged(getStartPoint());
00132    appearanceChanged();
00133 }
00134 
00135 ///////////////////////////////////////////////////////////////////////////
00136 /// Set End Point
00137 void EdgeWidget::setEndPoint(const gutz::vec3f &end)
00138 {
00139    vec3f pt = getEndPoint() - end;
00140    if( pt.dot(pt) < .000001 ) return;
00141 
00142    _invalidate();
00143    {
00144       _end = _manip->getLocalPosWorld(end);
00145    }
00146    _update();
00147 
00148    endPointChanged(getEndPoint());
00149    appearanceChanged();
00150 }
00151 
00152 ///////////////////////////////////////////////////////////////////////////
00153 /// Set Start NODE
00154 void EdgeWidget::setStartNode(NodeWidget *nw)
00155 {
00156    if(!nw) return;
00157    setStartPoint(nw->getPoint());
00158    gutz::connect(nw->pointChanged,  this, &EdgeWidget::setStartPoint);
00159    gutz::connect(startPointChanged, nw,   &NodeWidget::setPoint);
00160 }
00161 
00162 ///////////////////////////////////////////////////////////////////////////
00163 /// Set End NODE
00164 void EdgeWidget::setEndNode(NodeWidget *nw)
00165 {
00166    if(!nw) return;
00167    setEndPoint(nw->getPoint());
00168    gutz::connect(nw->pointChanged, this, &EdgeWidget::setEndPoint);
00169    gutz::connect(endPointChanged,  nw,   &NodeWidget::setPoint);
00170 }
00171 
00172 #if 0
00173 ///////////////////////////////////////////////////////////////////////////
00174 /// Move
00175 bool EdgeWidget::moveDef(const gutz::MouseMoveEvent &mme)
00176 {
00177    return _manip->move(mme);
00178    /// TODO, should be a switch! 
00179    if( getEvent(mme) == NO_EVENT ) return false;
00180 
00181    vec3f last = getStartPoint();
00182 
00183    vec3f del = mme.getCamera()->getPickPos(mme.getPos()) -
00184                mme.getCamera()->getPickPos(mme.getLast());
00185 
00186    setStartPoint(_start + del);
00187    setEndPoint(_end + del);
00188 
00189    return true;
00190 }
00191 #endif
00192 

Send questions, comments, and bug reports to:
jmk