00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "FrameWidget.h"
00021 #include <iostream>
00022
00023 using namespace gutz;
00024 using namespace std;
00025
00026
00027
00028
00029 FrameWidget::FrameWidget(const WidgetFactory &wf,
00030 WidgetItem *parent,
00031 const gutz::vec3f &ll,
00032 const gutz::vec3f &lr,
00033 const gutz::vec3f &ul,
00034 const gutz::vec3f &ur)
00035 : PolygonWidget(parent), _planeConst(0)
00036 {
00037 configureFrame(wf.getNodeProto(),wf.getEdgeProto(),ll,lr,ul,ur);
00038 }
00039
00040
00041
00042
00043 FrameWidget::FrameWidget(const NodeWidget *const nodeProto,
00044 const EdgeWidget *const edgeProto,
00045 WidgetItem *parent,
00046 const gutz::vec3f &ll,
00047 const gutz::vec3f &lr,
00048 const gutz::vec3f &ul,
00049 const gutz::vec3f &ur)
00050 : PolygonWidget(parent), _planeConst(0)
00051 {
00052 configureFrame(nodeProto,edgeProto, ll,lr,ul,ur);
00053 }
00054
00055
00056
00057
00058 FrameWidget::FrameWidget(const FrameWidget &fw)
00059 : PolygonWidget(fw), _planeConst(fw._planeConst)
00060 {
00061 configureFrame(fw._nodes[0].getPtr(), fw._edges[0].getPtr(),
00062 fw._nodes[LL]->getPoint(),
00063 fw._nodes[LR]->getPoint(),
00064 fw._nodes[UL]->getPoint(),
00065 fw._nodes[UR]->getPoint());
00066 if(fw._surface)
00067 setSurface(fw._surface->cloneSurface());
00068 _planeConst = fw._planeConst;
00069 }
00070
00071
00072
00073
00074 void FrameWidget::configureFrame(const NodeWidget *const nodeProto,
00075 const EdgeWidget *const edgeProto,
00076 const gutz::vec3f &ll, const gutz::vec3f &lr,
00077 const gutz::vec3f &ul, const gutz::vec3f &ur)
00078 {
00079
00080
00081 if(!_planeConst)
00082 {
00083 TransPlaneManipEvent *pc = new TransPlaneManipEvent();
00084 connect(planeChanged, pc, &TransPlaneManipEvent::setPlane);
00085 _planeConst = pc;
00086 }
00087 gutz::ManipEventMap nodeEvents;
00088 nodeEvents.mapEvent(GUTZ_LEFT_MOUSE, _planeConst);
00089
00090
00091
00092 NodeWidgetSP np = nodeProto->cloneNode();
00093 np->getManip()->clearEvents();
00094 np->getManip()->shareEvents(nodeEvents);
00095 np->setParent(this);
00096
00097 _nodes.resize(4, NodeWidgetSP(0));
00098
00099 _nodes[LL] = np;
00100 _nodes[LL]->setPoint(ll);
00101
00102 _nodes[LR] = np->cloneNode();
00103 _nodes[LR]->setPoint(lr);
00104
00105 _nodes[UL] = np->cloneNode();
00106 _nodes[UL]->setPoint(ul);
00107
00108 _nodes[UR] = np->cloneNode();
00109 _nodes[UR]->setPoint(ur);
00110
00111
00112
00113 _edges.resize(4, EdgeWidgetSP(0));
00114 _edges[LEFT] = edgeProto->cloneEdge();
00115 _edges[LEFT]->setParent(this);
00116 _edges[LEFT]->setStartNode(_nodes[LL]);
00117 _edges[LEFT]->setEndNode(_nodes[UL]);
00118
00119 _edges[RIGHT] = edgeProto->cloneEdge();
00120 _edges[RIGHT]->setParent(this);
00121 _edges[RIGHT]->setStartNode(_nodes[LR]);
00122 _edges[RIGHT]->setEndNode(_nodes[UR]);
00123
00124 _edges[TOP] = edgeProto->cloneEdge();
00125 _edges[TOP]->setParent(this);
00126 _edges[TOP]->setStartNode(_nodes[UL]);
00127 _edges[TOP]->setEndNode(_nodes[UR]);
00128
00129 _edges[BOTTOM] = edgeProto->cloneEdge();
00130 _edges[BOTTOM]->setParent(this);
00131 _edges[BOTTOM]->setStartNode(_nodes[LL]);
00132 _edges[BOTTOM]->setEndNode(_nodes[LR]);
00133
00134
00135
00136 _manip->mapEvent(GUTZ_LEFT_MOUSE, new TransXYManipEvent());
00137 _manip->mapEvent(GUTZ_MIDDLE_MOUSE, new TransZManipEvent());
00138 _manip->mapEvent(GUTZ_RIGHT_MOUSE, new RotateManipEvent());
00139
00140 updateManip();
00141 }
00142
00143
00144
00145
00146
00147 void FrameWidget::setDims(float width, float height)
00148 {
00149 _invalidate();
00150 {
00151 Point3 center = getCenter();
00152 scale(Point3(width/getWidth(), height/getHeight(), 1.0f));
00153 translate(center - getCenter());
00154 }
00155 _update();
00156 }
00157
00158
00159
00160
00161 void FrameWidget::setWidth(float width)
00162 {
00163 _invalidate();
00164 {
00165 Point3 center = getCenter();
00166 scale(Point3(width/getWidth(), 1.0f, 1.0f));
00167 translate(center - getCenter());
00168 }
00169 _update();
00170 }
00171
00172
00173
00174
00175 void FrameWidget::setHeight(float height)
00176 {
00177 _invalidate();
00178 {
00179 Point3 center = getCenter();
00180 scale(Point3(1.0f, height/getHeight(), 1.0f));
00181 translate(center - getCenter());
00182 }
00183 _update();
00184 }
00185
00186
00187
00188
00189 void FrameWidget::setCenter(const gutz::vec3f ¢er)
00190 {
00191 _invalidate();
00192 {
00193 translate(center - getCenter());
00194 }
00195 _update();
00196 }
00197
00198
00199 bool FrameWidget::mouseChild(WidgetItem *child, const gutz::MouseEvent &me)
00200 {
00201 return child->mouseDef(me) || _manip->mouse(me);
00202 }
00203
00204
00205
00206
00207 bool FrameWidget::moveChild(WidgetItem *child, const gutz::MouseMoveEvent &mme)
00208 {
00209
00210
00211 int idx = -1;
00212
00213 if( (idx = getNodeIdx(child)) != -1 )
00214 {
00215
00216 vec3f width = _nodes[LR]->getPoint() - _nodes[LL]->getPoint();
00217 vec3f height = _nodes[UL]->getPoint() - _nodes[LL]->getPoint();
00218 if( _nodes[idx]->moveDef(mme) )
00219 {
00220 nodeMoved(idx, width,height);
00221 planeChanged(getPlane());
00222 return true;
00223 }
00224 }
00225
00226
00227 if( child->moveDef(mme) )
00228 {
00229 return true;
00230 }
00231 else if ( _manip->move(mme) )
00232 {
00233 setChanged();
00234 return true;
00235 }
00236
00237 return false;
00238
00239 }
00240
00241
00242
00243
00244 void FrameWidget::nodeMoved(int idx, const gutz::vec3f &oldW, const gutz::vec3f &oldH)
00245 {
00246 vec3f nWidth, nHeight;
00247 switch(idx)
00248 {
00249 case LL:
00250 nWidth = gutz::project(_nodes[LR]->getPoint() - _nodes[LL]->getPoint(), oldW);
00251 nHeight= gutz::project(_nodes[UL]->getPoint() - _nodes[LL]->getPoint(), oldH);
00252 _nodes[LR]->setPoint(_nodes[LL]->getPoint() + nWidth);
00253 _nodes[UL]->setPoint(_nodes[LL]->getPoint() + nHeight);
00254 _nodes[UR]->setPoint(_nodes[LL]->getPoint() + nWidth + nHeight);
00255 break;
00256 case LR:
00257 nWidth = gutz::project(_nodes[LL]->getPoint() - _nodes[LR]->getPoint(), oldW);
00258 nHeight= gutz::project(_nodes[UR]->getPoint() - _nodes[LR]->getPoint(), oldH);
00259 _nodes[LL]->setPoint(_nodes[LR]->getPoint() + nWidth);
00260 _nodes[UL]->setPoint(_nodes[LR]->getPoint() + nHeight + nWidth);
00261 _nodes[UR]->setPoint(_nodes[LR]->getPoint() + nHeight);
00262 break;
00263 case UL:
00264 nWidth = gutz::project(_nodes[UR]->getPoint() - _nodes[UL]->getPoint(), oldW);
00265 nHeight= gutz::project(_nodes[LL]->getPoint() - _nodes[UL]->getPoint(), oldH);
00266 _nodes[LR]->setPoint(_nodes[UL]->getPoint() + nWidth + nHeight);
00267 _nodes[LL]->setPoint(_nodes[UL]->getPoint() + nHeight);
00268 _nodes[UR]->setPoint(_nodes[UL]->getPoint() + nWidth);
00269 break;
00270 case UR:
00271 nWidth = gutz::project(_nodes[UL]->getPoint() - _nodes[UR]->getPoint(), oldW);
00272 nHeight= gutz::project(_nodes[LR]->getPoint() - _nodes[UR]->getPoint(), oldH);
00273 _nodes[LR]->setPoint(_nodes[UR]->getPoint() + nHeight);
00274 _nodes[LL]->setPoint(_nodes[UR]->getPoint() + nHeight + nWidth);
00275 _nodes[UL]->setPoint(_nodes[UR]->getPoint() + nWidth);
00276 break;
00277 }
00278
00279 }
00280
00281
00282
00283
00284 void FrameWidget::setSurface(SurfaceWidget *sw)
00285 {
00286 delSurface();
00287 _surface = sw;
00288 if(!_surface) return;
00289 _surface->setParent(this);
00290 connect(_nodes[LL]->pointChanged, _surface.getPtr(), &SurfaceWidget::setLL);
00291 connect(_nodes[LR]->pointChanged, _surface.getPtr(), &SurfaceWidget::setLR);
00292 connect(_nodes[UL]->pointChanged, _surface.getPtr(), &SurfaceWidget::setUL);
00293 connect(_nodes[UR]->pointChanged, _surface.getPtr(), &SurfaceWidget::setUR);
00294
00295 sw->setLL(_nodes[LL]->getPoint());
00296 sw->setLR(_nodes[LR]->getPoint());
00297 sw->setUL(_nodes[UL]->getPoint());
00298 sw->setUR(_nodes[UR]->getPoint());
00299 }
00300
00301
00302
00303
00304 void FrameWidget::delSurface()
00305 {
00306 if(!_surface) return;
00307 disconnect(_nodes[LL]->pointChanged, _surface.getPtr(), &SurfaceWidget::setLL);
00308 disconnect(_nodes[LR]->pointChanged, _surface.getPtr(), &SurfaceWidget::setLR);
00309 disconnect(_nodes[UL]->pointChanged, _surface.getPtr(), &SurfaceWidget::setUL);
00310 disconnect(_nodes[UR]->pointChanged, _surface.getPtr(), &SurfaceWidget::setUR);
00311 }
00312
00313
00314
00315
00316 void FrameWidget::delChild(WidgetItem *child)
00317 {
00318 if(SurfaceWidget *sw = dynamic_cast<SurfaceWidget*>(child))
00319 {
00320 if(sw == _surface)
00321 delSurface();
00322 return;
00323 }
00324 }
00325