fixpt.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 1999-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: Mon Jan  4 08:00:00 1999
00010 // commit: $Id: fixpt.cc 10065 2007-04-12 05:54:56Z rjpeters $
00011 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/visx/fixpt.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_VISX_FIXPT_CC_UTC20050626084016_DEFINED
00035 #define GROOVX_VISX_FIXPT_CC_UTC20050626084016_DEFINED
00036 
00037 #include "visx/fixpt.h"
00038 
00039 #include "geom/vec2.h"
00040 
00041 #include "gfx/bbox.h"
00042 #include "gfx/canvas.h"
00043 
00044 #include "io/ioproxy.h"
00045 #include "io/reader.h"
00046 #include "io/writer.h"
00047 
00048 #include "rutz/trace.h"
00049 #include "rutz/debug.h"
00050 GVX_DBG_REGISTER
00051 
00053 //
00054 // File scope data
00055 //
00057 
00058 namespace
00059 {
00060   const io::version_id FIXPT_SVID = 3;
00061 }
00062 
00064 //
00065 // FixPt member functions
00066 //
00068 
00069 const FieldMap& FixPt::classFields()
00070 {
00071   static const Field FIELD_ARRAY[] =
00072   {
00073     Field("length", &FixPt::itsLength, 0.1, 0.0, 10.0, 0.1, Field::NEW_GROUP),
00074     Field("width", &FixPt::itsWidth, 1, 1, 100, 1)
00075   };
00076 
00077   static FieldMap FIXPT_FIELDS(FIELD_ARRAY, &GxShapeKit::classFields());
00078 
00079   return FIXPT_FIELDS;
00080 }
00081 
00082 FixPt* FixPt::make()
00083 {
00084 GVX_TRACE("FixPt::make");
00085   return new FixPt;
00086 }
00087 
00088 FixPt::FixPt(double len, int wid) :
00089   itsLength(len), itsWidth(wid)
00090 {
00091   setFieldMap(FixPt::classFields());
00092 }
00093 
00094 FixPt::~FixPt() throw() {}
00095 
00096 io::version_id FixPt::class_version_id() const
00097 {
00098 GVX_TRACE("FixPt::class_version_id");
00099   return FIXPT_SVID;
00100 }
00101 
00102 void FixPt::read_from(io::reader& reader)
00103 {
00104 GVX_TRACE("FixPt::read_from");
00105 
00106   reader.ensure_version_id("FixPt", 3,
00107                            "Try cvs tag xml_conversion_20040526",
00108                            SRC_POS);
00109 
00110   readFieldsFrom(reader, classFields());
00111 
00112   reader.read_base_class("GxShapeKit", io::make_proxy<GxShapeKit>(this));
00113 }
00114 
00115 void FixPt::write_to(io::writer& writer) const
00116 {
00117 GVX_TRACE("FixPt::write_to");
00118 
00119   writer.ensure_output_version_id("FixPt", FIXPT_SVID, 3,
00120                               "Try groovx0.8a4", SRC_POS);
00121 
00122   writeFieldsTo(writer, classFields(), FIXPT_SVID);
00123 
00124   writer.write_base_class("GxShapeKit", io::make_const_proxy<GxShapeKit>(this));
00125 }
00126 
00127 void FixPt::grGetBoundingBox(Gfx::Bbox& bbox) const
00128 {
00129 GVX_TRACE("FixPt::grGetBoundingBox");
00130 
00131   bbox.vertex2(geom::vec2<double>(-itsLength/2.0, -itsLength/2.0));
00132   bbox.vertex2(geom::vec2<double>(+itsLength/2.0, +itsLength/2.0));
00133 }
00134 
00135 void FixPt::grRender(Gfx::Canvas& canvas) const
00136 {
00137 GVX_TRACE("FixPt::grRender");
00138 
00139   Gfx::AttribSaver saver(canvas);
00140 
00141   canvas.setLineWidth(itsWidth);
00142 
00143   {
00144     Gfx::LinesBlock block(canvas);
00145 
00146     canvas.vertex2(geom::vec2<double>(0.0, -itsLength/2.0));
00147     canvas.vertex2(geom::vec2<double>(0.0, itsLength/2.0));
00148 
00149     canvas.vertex2(geom::vec2<double>(-itsLength/2.0, 0.0));
00150     canvas.vertex2(geom::vec2<double>(itsLength/2.0, 0.0));
00151   }
00152 }
00153 
00154 static const char __attribute__((used)) vcid_groovx_visx_fixpt_cc_utc20050626084016[] = "$Id: fixpt.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00155 #endif // !GROOVX_VISX_FIXPT_CC_UTC20050626084016_DEFINED

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