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

TFItemSTD.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 /// TFItemSTD.cpp
00019 ///  simianUI
00020 
00021 #include "TFItemSTD.h"
00022 #include <iostream>
00023 
00024 using namespace std;
00025 using namespace gutz;
00026 //////////////////////////////////////////////////////////////////////////
00027 //////////////////////////////////////////////////////////////////////////
00028 /// TFBoxItem
00029 //////////////////////////////////////////////////////////////////////////
00030 //////////////////////////////////////////////////////////////////////////
00031 
00032 //////////////////////////////////////////////////////////////////////////
00033 /// construct
00034 TFBoxItem::TFBoxItem(QCanvas *canvas, TFElementBox *belt)
00035 : TFItem(canvas,TFEltSP(belt)), _belt(belt),
00036   _moving(false)
00037 {
00038    if(_belt.isNull())
00039    {
00040       cerr << "TFBoxItem::constructor, ERROR TFElement is null or incompatable type!!" << endl;      
00041    }
00042       
00043    initBox();
00044 }
00045 
00046 //////////////////////////////////////////////////////////////////////////
00047 /// init box
00048 void TFBoxItem::initBox()
00049 {
00050    double left   = getTFLeft();
00051    double right  = getTFRight();
00052    double bottom = getTFBottom();
00053    double top    = getTFTop();
00054 
00055    NodeItemSP nll = new NodeItem(canvas(),left,bottom, this);
00056    NodeItemSP nlr = new NodeItem(canvas(),right,bottom, this);
00057    NodeItemSP ntl = new NodeItem(canvas(),left,top, this);
00058    NodeItemSP ntr = new NodeItem(canvas(),right,top, this);
00059 
00060    _points = NodeItemVec(4,NodeItemSP(0));
00061    _points[LL] = nll;
00062    _points[LR] = nlr;
00063    _points[TL] = ntl;
00064    _points[TR] = ntr;
00065 
00066    /// edges have global manipulation, so we turn off auto node
00067    /// update so we can do that ourselves
00068    _edges = EdgeItemVec(4,EdgeItemSP(0));
00069    _edges[B] = new EdgeItem(_points[LL],_points[LR], canvas(), this);
00070    _edges[B]->setUpdateLinks(false);
00071    _edges[T] = new EdgeItem(_points[TL],_points[TR], canvas(), this);
00072    _edges[T]->setUpdateLinks(false);
00073    _edges[L] = new EdgeItem(_points[LL],_points[TL], canvas(), this);
00074    _edges[L]->setUpdateLinks(false);
00075    _edges[R] = new EdgeItem(_points[LR],_points[TR], canvas(), this);
00076    _edges[R]->setUpdateLinks(false);
00077 
00078    for(int i=0; i<4; ++i)
00079    {
00080       _points[i]->show();
00081       _edges[i]->show();
00082    }
00083 }
00084 
00085 //////////////////////////////////////////////////////////////////////////
00086 /// set box dims
00087 void TFBoxItem::setBoxDims(gutz::vec2f ll, gutz::vec2f ur)
00088 {
00089    if(!_points.size()){ cerr << "empty points" << endl; return; }
00090 
00091    _points[LL]->setPoint(ll.x,ll.y);
00092    _points[LR]->setPoint(ur.x,ll.y);
00093    _points[TL]->setPoint(ll.x,ur.y);
00094    _points[TR]->setPoint(ur.x,ur.y);
00095 
00096 }
00097 
00098 void TFBoxItem::setDims()
00099 {
00100    setBoxDims(vec2f(getTFLeft(),  getTFBottom()), 
00101               vec2f(getTFRight(), getTFTop()));
00102 }
00103 
00104 
00105 //////////////////////////////////////////////////////////////////////////
00106 /// update def
00107 void TFBoxItem::updateDef()
00108 {
00109    setDims();     
00110 }
00111 
00112 //////////////////////////////////////////////////////////////////////////
00113 /// child update
00114 void TFBoxItem::childUpdate(CanvasItemBase *child)
00115 {
00116    cerr << "child update" << endl;
00117 }
00118 
00119 //////////////////////////////////////////////////////////////////////////
00120 /// child moded by
00121 void TFBoxItem::childMovedBy(CanvasItemBase *child, gutz::vec3d dv)
00122 {
00123    /// prevent loops
00124    if(_moving) return;
00125    _moving = true;
00126 
00127    int idx;
00128    if( (idx = getNodeIndex(child)) != -1 )
00129    {
00130       moveNode(idx, dv);
00131    }
00132    if( (idx = getEdgeIndex(child)) != -1 )
00133    {
00134       moveEdge(idx, dv);
00135    }
00136 
00137    setDims();
00138 
00139    _moving = false;
00140 }
00141 
00142 //////////////////////////////////////////////////////////////////////////
00143 /// child moved
00144 void TFBoxItem::childMoved(CanvasItemBase *child, gutz::vec3d last, gutz::vec3d point)
00145 {
00146    /// prevent loops
00147    if(_moving) return;
00148    _moving = true;
00149 
00150    int idx;
00151    if( (idx = getNodeIndex(child)) != -1 )
00152    {
00153       moveNode(idx, point-last);
00154    }
00155    if( (idx = getEdgeIndex(child)) != -1 )
00156    {
00157       moveEdge(idx, point-last);
00158    }
00159 
00160    setDims();
00161    _moving = false;
00162 
00163 }
00164 
00165 //////////////////////////////////////////////////////////////////////////
00166 /// move node
00167 void TFBoxItem::moveNode(int nodeIdx, gutz::vec3d dv)
00168 {
00169    if(dv == vec3d_zero) return;
00170 
00171    if(nodeIdx == LL)
00172    {
00173       setTFLeft(getTFLeft() + dv.x);
00174       setTFBottom(getTFBottom() + dv.y);
00175    }
00176    if(nodeIdx == LR)
00177    {
00178       setTFRight(getTFRight() + dv.x);
00179       setTFBottom(getTFBottom() + dv.y);
00180    }
00181    if(nodeIdx == TL)
00182    {
00183       setTFLeft(getTFLeft() + dv.x);
00184       setTFTop(getTFTop() + dv.y);
00185    }
00186    if(nodeIdx == TR)
00187    {
00188       setTFRight(getTFRight() + dv.x);
00189       setTFTop(getTFTop() + dv.y);
00190    }
00191 }
00192 
00193 //////////////////////////////////////////////////////////////////////////
00194 /// move edge
00195 void TFBoxItem::moveEdge(int edgeIdx, gutz::vec3d dv)
00196 {
00197    setTFBottom(getTFBottom() + dv.y);
00198    setTFTop(getTFTop() + dv.y);
00199    setTFLeft(getTFLeft() + dv.x);
00200    setTFRight(getTFRight() + dv.x);
00201 }
00202 
00203 

Send questions, comments, and bug reports to:
jmk