gxshapekit.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 1998-2004 California Institute of Technology
00006 // Copyright (c) 2004-2007 University of Southern California
00007 // Rob Peters <rjpeters at usc dot edu>
00008 //
00009 // created: Tue Dec  1 08:00:00 1998 (as grobj.cc)
00010 // commit: $Id: gxshapekit.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/gfx/gxshapekit.cc $
00012 //
00013 // --------------------------------------------------------------------
00014 //
00015 // This file is part of GroovX.
00016 //   [http://ilab.usc.edu/rjpeters/groovx/]
00017 //
00018 // GroovX is free software; you can redistribute it and/or modify it
00019 // under the terms of the GNU General Public License as published by
00020 // the Free Software Foundation; either version 2 of the License, or
00021 // (at your option) any later version.
00022 //
00023 // GroovX is distributed in the hope that it will be useful, but
00024 // WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00026 // General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License
00029 // along with GroovX; if not, write to the Free Software Foundation,
00030 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00031 //
00033 
00034 #ifndef GROOVX_GFX_GXSHAPEKIT_CC_UTC20050626084023_DEFINED
00035 #define GROOVX_GFX_GXSHAPEKIT_CC_UTC20050626084023_DEFINED
00036 
00037 #include "gfx/gxshapekit.h"
00038 
00039 #include "geom/box.h"
00040 
00041 #include "gfx/bbox.h"
00042 #include "gfx/canvas.h"
00043 #include "gfx/gxaligner.h"
00044 #include "gfx/gxbin.h"
00045 #include "gfx/gxbounds.h"
00046 #include "gfx/gxcache.h"
00047 #include "gfx/gxscaler.h"
00048 
00049 #include "io/reader.h"
00050 #include "io/writer.h"
00051 
00052 #include "nub/volatileobject.h"
00053 
00054 #define GVX_DYNAMIC_TRACE_EXPR GxShapeKit::tracer.status()
00055 #include "rutz/trace.h"
00056 #include "rutz/debug.h"
00057 GVX_DBG_REGISTER
00058 
00059 //  #######################################################
00060 //  =======================================================
00061 
00063 
00064 class GxShapeKitNode : public GxBin
00065 {
00066   GxShapeKit* itsObj;
00067 
00068 public:
00069   GxShapeKitNode(GxShapeKit* obj) : GxBin(), itsObj(obj) {}
00070 
00071   virtual ~GxShapeKitNode() throw() {}
00072 
00073   virtual void read_from(io::reader& /*reader*/) {};
00074   virtual void write_to(io::writer& /*writer*/) const {};
00075 
00076   virtual void draw(Gfx::Canvas& canvas) const
00077   { itsObj->grRender(canvas); }
00078 
00079   virtual void getBoundingCube(Gfx::Bbox& bbox) const
00080   {
00081     itsObj->grGetBoundingBox(bbox);
00082     dbg_dump(2, bbox.cube());
00083   }
00084 };
00085 
00086 //  #######################################################
00087 //  =======================================================
00088 
00090 
00091 class GxShapeKitImpl : public nub::volatile_object
00092 {
00093 private:
00094   GxShapeKitImpl(const GxShapeKitImpl&);
00095   GxShapeKitImpl& operator=(const GxShapeKitImpl&);
00096 
00097 public:
00098 
00099   //
00100   // Data members
00101   //
00102 
00103   int category;
00104 
00105   nub::ref<GxShapeKitNode> nativeNode;
00106   nub::ref<GxBounds> boundsOutline;
00107   nub::ref<GxCache> cache;
00108   nub::ref<GxAligner> aligner;
00109   nub::ref<GxScaler> scaler;
00110 
00111   nub::ref<GxNode> topNode;
00112 
00113   //
00114   // Methods
00115   //
00116 
00117   static GxShapeKitImpl* make(GxShapeKit* obj)
00118   {
00119     GVX_TRACE("GxShapeKitImpl::make");
00120     return new GxShapeKitImpl(obj);
00121   }
00122 
00123   GxShapeKitImpl(GxShapeKit* obj) :
00124     category(-1),
00125     nativeNode(new GxShapeKitNode(obj), nub::PRIVATE),
00126     boundsOutline(new GxBounds(nativeNode), nub::PRIVATE),
00127     cache(new GxCache(boundsOutline), nub::PRIVATE),
00128     aligner(new GxAligner(cache), nub::PRIVATE),
00129     scaler(new GxScaler(aligner), nub::PRIVATE),
00130     topNode(scaler)
00131   {
00132     GVX_TRACE("GxShapeKitImpl::GxShapeKitImpl");
00133     // We connect to sigNodeChanged in order to update any caches
00134     // according to state changes.
00135     obj->sigNodeChanged.connect(this, &GxShapeKitImpl::invalidateCaches);
00136   }
00137 
00138   virtual ~GxShapeKitImpl() throw() {}
00139 
00140   void invalidateCaches()
00141   {
00142     cache->invalidate();
00143   }
00144 };
00145 
00146 namespace
00147 {
00148   const io::version_id GXSHAPEKIT_SVID = 4;
00149 }
00150 
00151 rutz::tracer GxShapeKit::tracer;
00152 
00154 //
00155 // GxShapeKit member definitions
00156 //
00158 
00159 
00161 // creators //
00163 
00164 // GxShapeKit default constructor
00165 GxShapeKit::GxShapeKit() :
00166   FieldContainer(&sigNodeChanged),
00167   rep(GxShapeKitImpl::make(this))
00168 {
00169 GVX_TRACE("GxShapeKit::GxShapeKit");
00170 
00171   setFieldMap(GxShapeKit::classFields());
00172 
00173   // This is necessary because any representations that have been
00174   // cached during the GxShapeKit constructor will become invalid upon
00175   // return to the derived class constructor.
00176   sigNodeChanged.emit();
00177 }
00178 
00179 // GxShapeKit destructor
00180 GxShapeKit::~GxShapeKit() throw()
00181 {
00182 GVX_TRACE("GxShapeKit::~GxShapeKit");
00183   rep->destroy();
00184 }
00185 
00186 io::version_id GxShapeKit::class_version_id() const
00187 {
00188 GVX_TRACE("GxShapeKit::class_version_id");
00189   return GXSHAPEKIT_SVID;
00190 }
00191 
00192 void GxShapeKit::read_from(io::reader& reader)
00193 {
00194 GVX_TRACE("GxShapeKit::read_from");
00195 
00196   const int svid =
00197     reader.ensure_version_id("GxShapeKit", 3,
00198                              "Try groovx0.8a7", SRC_POS);
00199 
00200   readFieldsFrom(reader, classFields());
00201 
00202   if (svid >= 4)
00203     {
00204       reader.read_owned_object("bounds", rep->boundsOutline);
00205       reader.read_owned_object("cache", rep->cache);
00206       reader.read_owned_object("aligner", rep->aligner);
00207       reader.read_owned_object("scaler", rep->scaler);
00208     }
00209 }
00210 
00211 void GxShapeKit::write_to(io::writer& writer) const
00212 {
00213 GVX_TRACE("GxShapeKit::write_to");
00214 
00215   writer.ensure_output_version_id("GxShapeKit",
00216                               GXSHAPEKIT_SVID, 4,
00217                               "Try groovx0.8a7", SRC_POS);
00218 
00219   writeFieldsTo(writer, classFields(), GXSHAPEKIT_SVID);
00220 
00221   writer.write_owned_object("bounds", rep->boundsOutline);
00222   writer.write_owned_object("cache", rep->cache);
00223   writer.write_owned_object("aligner", rep->aligner);
00224   writer.write_owned_object("scaler", rep->scaler);
00225 }
00226 
00227 const FieldMap& GxShapeKit::classFields()
00228 {
00229 #define GETSET(attr) &GxShapeKit::get##attr, &GxShapeKit::set##attr
00230 
00231   static const Field FIELD_ARRAY[] =
00232   {
00233     Field("category", &GxShapeKit::category, &GxShapeKit::setCategory,
00234           0, 0, 20, 1, Field::NEW_GROUP),
00235     Field("renderMode", GETSET(RenderMode), 1, 1, 4, 1).versions(0,3),
00236     Field("bbVisibility", GETSET(BBVisibility),
00237           false, false, true, true, Field::BOOLEAN).versions(0,3),
00238     Field("scalingMode", GETSET(ScalingMode), 1, 1, 3, 1).versions(0,3),
00239     Field("widthFactor", GETSET(WidthFactor), 1.0, 0.1, 10.0, 0.1,
00240           Field::PRIVATE).versions(0,3),
00241     Field("heightFactor", GETSET(HeightFactor), 1.0, 0.1, 10.0, 0.1,
00242           Field::PRIVATE).versions(0,3),
00243     Field("aspectRatio", GETSET(AspectRatio), 1.0, 0.1, 10.0, 0.1,
00244           Field::TRANSIENT),
00245     Field("width", GETSET(Width), 1.0, 0.1, 10.0, 0.1,
00246           Field::TRANSIENT),
00247     Field("height", GETSET(Height), 1.0, 0.1, 10.0, 0.1,
00248           Field::TRANSIENT),
00249     Field("maxDimension", GETSET(MaxDimension), 1.0, 0.1, 10.0, 0.1,
00250           Field::TRANSIENT),
00251     Field("alignmentMode", GETSET(AlignmentMode), 1, 1, 7, 1).versions(0,3),
00252     Field("centerX", GETSET(CenterX), 0.0, -10.0, 10.0, 0.1).versions(0,3),
00253     Field("centerY", GETSET(CenterY), 0.0, -10.0, 10.0, 0.1).versions(0,3)
00254   };
00255 #undef GETSET
00256 
00257   static FieldMap GROBJ_FIELDS(FIELD_ARRAY);
00258 
00259   return GROBJ_FIELDS;
00260 }
00261 
00263 // accessors //
00265 
00266 bool GxShapeKit::getBBVisibility() const
00267 {
00268 GVX_TRACE("GxShapeKit::getBBVisibility");
00269   return rep->boundsOutline->isVisible();
00270 }
00271 
00272 void GxShapeKit::getBoundingCube(Gfx::Bbox& bbox) const
00273 {
00274 GVX_TRACE("GxShapeKit::getBoundingCube");
00275 
00276   rep->topNode->getBoundingCube(bbox);
00277 }
00278 
00279 int GxShapeKit::getScalingMode() const
00280 {
00281 GVX_TRACE("GxShapeKit::getScalingMode");
00282   return rep->scaler->getMode();
00283 }
00284 
00285 double GxShapeKit::getWidth() const
00286 {
00287 GVX_TRACE("GxShapeKit::getWidth");
00288   return rep->scaler->scaledWidth();
00289 }
00290 
00291 double GxShapeKit::getHeight() const
00292 {
00293 GVX_TRACE("GxShapeKit::getHeight");
00294   return rep->scaler->scaledHeight();
00295 }
00296 
00297 double GxShapeKit::getAspectRatio() const
00298 {
00299 GVX_TRACE("GxShapeKit::getAspectRatio");
00300   return rep->scaler->aspectRatio();
00301 }
00302 
00303 double GxShapeKit::getMaxDimension() const
00304 {
00305 GVX_TRACE("GxShapeKit::getMaxDimension");
00306   return rep->scaler->scaledMaxDim();
00307 }
00308 
00309 int GxShapeKit::getAlignmentMode() const
00310 {
00311 GVX_TRACE("GxShapeKit::getAlignmentMode");
00312   return rep->aligner->getMode();
00313 }
00314 
00315 double GxShapeKit::getCenterX() const
00316 {
00317 GVX_TRACE("GxShapeKit::getCenterX");
00318   return rep->aligner->itsCenter.x();
00319 }
00320 
00321 double GxShapeKit::getCenterY() const
00322 {
00323 GVX_TRACE("GxShapeKit::getCenterY");
00324   return rep->aligner->itsCenter.y();
00325 }
00326 
00327 int GxShapeKit::getPercentBorder() const
00328 {
00329 GVX_TRACE("GxShapeKit::getPercentBorder");
00330   return rep->boundsOutline->percentBorder();
00331 }
00332 
00333 int GxShapeKit::category() const
00334 {
00335 GVX_TRACE("GxShapeKit::category");
00336   return rep->category;
00337 }
00338 
00339 int GxShapeKit::getRenderMode() const
00340 {
00341   return rep->cache->getMode();
00342 }
00343 
00345 // manipulators //
00347 
00348 void GxShapeKit::setBBVisibility(bool visibility)
00349 {
00350   rep->boundsOutline->setVisible(visibility);
00351   this->sigNodeChanged.emit();
00352 }
00353 
00354 void GxShapeKit::setScalingMode(int val)
00355 {
00356 GVX_TRACE("GxShapeKit::setScalingMode");
00357 
00358   rep->scaler->setMode(val);
00359   this->sigNodeChanged.emit();
00360 }
00361 
00362 void GxShapeKit::setWidth(double val)
00363 {
00364 GVX_TRACE("GxShapeKit::setWidth");
00365 
00366   rep->scaler->setWidth(val);
00367   this->sigNodeChanged.emit();
00368 }
00369 
00370 void GxShapeKit::setHeight(double val)
00371 {
00372 GVX_TRACE("GxShapeKit::setHeight");
00373 
00374   rep->scaler->setHeight(val);
00375   this->sigNodeChanged.emit();
00376 }
00377 
00378 void GxShapeKit::setAspectRatio(double val)
00379 {
00380 GVX_TRACE("GxShapeKit::setAspectRatio");
00381 
00382   rep->scaler->setAspectRatio(val);
00383   this->sigNodeChanged.emit();
00384 }
00385 
00386 void GxShapeKit::setMaxDimension(double val)
00387 {
00388 GVX_TRACE("GxShapeKit::setMaxDimension");
00389 
00390   rep->scaler->setMaxDim(val);
00391   this->sigNodeChanged.emit();
00392 }
00393 
00394 void GxShapeKit::setAlignmentMode(int val)
00395 {
00396 GVX_TRACE("GxShapeKit::setAlignmentMode");
00397 
00398   rep->aligner->setMode(val);
00399   this->sigNodeChanged.emit();
00400 }
00401 
00402 void GxShapeKit::setCenterX(double val)
00403 {
00404 GVX_TRACE("GxShapeKit::setCenterX");
00405 
00406   rep->aligner->itsCenter.x() = val;
00407   this->sigNodeChanged.emit();
00408 }
00409 
00410 void GxShapeKit::setCenterY(double val)
00411 {
00412 GVX_TRACE("GxShapeKit::setCenterY");
00413 
00414   rep->aligner->itsCenter.y() = val;
00415   this->sigNodeChanged.emit();
00416 }
00417 
00418 void GxShapeKit::setPercentBorder(int pixels)
00419 {
00420 GVX_TRACE("GxShapeKit::setPercentBorder");
00421   rep->boundsOutline->setPercentBorder(pixels);
00422 }
00423 
00424 void GxShapeKit::setCategory(int val)
00425 {
00426 GVX_TRACE("GxShapeKit::setCategory");
00427   rep->category = val;
00428 }
00429 
00430 void GxShapeKit::setRenderMode(int mode)
00431 {
00432 GVX_TRACE("GxShapeKit::setRenderMode");
00433 
00434   rep->cache->setMode(mode);
00435   this->sigNodeChanged.emit();
00436 }
00437 
00438 
00440 // actions //
00442 
00443 void GxShapeKit::draw(Gfx::Canvas& canvas) const
00444 {
00445 GVX_TRACE("GxShapeKit::draw");
00446   rep->topNode->draw(canvas);
00447 }
00448 
00449 double GxShapeKit::getWidthFactor() const
00450 {
00451 GVX_TRACE("GxShapeKit::getWidthFactor");
00452   return rep->scaler->widthFactor();
00453 }
00454 
00455 void GxShapeKit::setWidthFactor(double val)
00456 {
00457 GVX_TRACE("GxShapeKit::setWidthFactor");
00458   rep->scaler->setWidthFactor(val);
00459 }
00460 
00461 double GxShapeKit::getHeightFactor() const
00462 {
00463 GVX_TRACE("GxShapeKit::getHeightFactor");
00464   return rep->scaler->heightFactor();
00465 }
00466 
00467 void GxShapeKit::setHeightFactor(double val)
00468 {
00469 GVX_TRACE("GxShapeKit::setHeightFactor");
00470   rep->scaler->setHeightFactor(val);
00471 }
00472 
00473 static const char __attribute__((used)) vcid_groovx_gfx_gxshapekit_cc_utc20050626084023[] = "$Id: gxshapekit.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00474 #endif // !GROOVX_GFX_GXSHAPEKIT_CC_UTC20050626084023_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:38 2008 by Doxygen version 1.5.5.