DGtal  0.9.3beta
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | Static Private Attributes
LibBoard::Shape Struct Referenceabstract

#include <Board/Shapes.h>

Inheritance diagram for LibBoard::Shape:
[legend]
Collaboration diagram for LibBoard::Shape:
[legend]

Public Types

enum  LineCap { ButtCap = 0, RoundCap, SquareCap }
 
enum  LineJoin { MiterJoin = 0, RoundJoin, BevelJoin }
 
enum  LineStyle {
  SolidStyle = 0, DashStyle, DotStyle, DashDotStyle,
  DashDotDotStyle, DashDotDotDotStyle
}
 

Public Member Functions

 Shape (DGtal::Color penColor, DGtal::Color fillColor, double lineWidth, LineStyle style, const LineCap cap, const LineJoin join, int depth)
 
virtual ~Shape ()
 
virtual const std::string & name () const
 
virtual Shapeclone () const =0
 
bool filled () const
 
virtual Point center () const =0
 
virtual Shaperotate (double angle, const Point &center)=0
 
virtual Shaperotate (double angle)=0
 
ShaperotateDeg (double angle, const Point &center)
 
ShaperotateDeg (double angle)
 
virtual Shapetranslate (double dx, double dy)=0
 
virtual Shapescale (double sx, double sy)=0
 
virtual Shapescale (double s)=0
 
virtual Rect boundingBox () const =0
 
Rect bbox ()
 
Shapeoperator-- ()
 
Shapeoperator++ ()
 
virtual void scaleAll (double s)=0
 
virtual void flushPostscript (std::ostream &stream, const TransformEPS &transform) const =0
 
virtual void flushFIG (std::ostream &stream, const TransformFIG &transform, std::map< DGtal::Color, int > &colormap) const =0
 
virtual void flushSVG (std::ostream &stream, const TransformSVG &transform) const =0
 
virtual void flushCairo (cairo_t *cr, const TransformCairo &transform) const =0
 
virtual void flushTikZ (std::ostream &stream, const TransformTikZ &transform) const =0
 
int depth () const
 
virtual void depth (int)
 
virtual void shiftDepth (int shift)
 
const DGtal::ColorpenColor () const
 
const DGtal::ColorfillColor () const
 

Protected Member Functions

std::string svgProperties (const TransformSVG &transform) const
 
std::string postscriptProperties () const
 
void setCairoDashStyle (cairo_t *cr, LineStyle type) const
 
std::string tikzProperties (const TransformTikZ &transform) const
 

Protected Attributes

int _depth
 
DGtal::Color _penColor
 
DGtal::Color _fillColor
 
double _lineWidth
 
LineStyle _lineStyle
 
LineCap _lineCap
 
LineJoin _lineJoin
 

Static Private Attributes

static const std::string _name
 

Detailed Description

Abstract structure for a 2D shape.

Shape structure.

Definition at line 58 of file Board/Shapes.h.

Member Enumeration Documentation

Enumerator
ButtCap 
RoundCap 
SquareCap 

Definition at line 60 of file Board/Shapes.h.

Enumerator
MiterJoin 
RoundJoin 
BevelJoin 

Definition at line 61 of file Board/Shapes.h.

Enumerator
SolidStyle 
DashStyle 
DotStyle 
DashDotStyle 
DashDotDotStyle 
DashDotDotDotStyle 

Definition at line 62 of file Board/Shapes.h.

Constructor & Destructor Documentation

LibBoard::Shape::Shape ( DGtal::Color  penColor,
DGtal::Color  fillColor,
double  lineWidth,
LineStyle  style,
const LineCap  cap,
const LineJoin  join,
int  depth 
)
inline

Shape constructor.

Parameters
penColorThe pen color of the shape.
fillColorThe fill color of the shape.
lineWidthThe line thickness.
styleThe line style.
capThe line cap.
joinThe line join.
depthThe depth of the shape.
virtual LibBoard::Shape::~Shape ( )
inlinevirtual

Shape destructor.

Definition at line 90 of file Board/Shapes.h.

90 { }

Member Function Documentation

Rect LibBoard::Shape::bbox ( )
inline

Returns the bounding box of the figure. (Convenience method to call "boundingBox" with a short name.)

Definition at line 339 of file Board/Shapes.h.

References boundingBox().

340 {
341  return this->boundingBox();
342 }
virtual Rect boundingBox() const =0
virtual Rect LibBoard::Shape::boundingBox ( ) const
pure virtual

Returns the bounding box of the figure.

Returns
The rectangle of the bounding box.

Implemented in LibBoard::Text, LibBoard::Ellipse, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, and LibBoard::ShapeList.

Referenced by bbox().

virtual Point LibBoard::Shape::center ( ) const
pure virtual

Returns the gravity center of the shape.

Returns
The center of the shape.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, and LibBoard::ShapeList.

Referenced by rotateDeg().

virtual Shape* LibBoard::Shape::clone ( ) const
pure virtual
int LibBoard::Shape::depth ( ) const
inline
void LibBoard::Shape::depth ( int  d)
virtual

Definition at line 195 of file Shapes.cpp.

References _depth.

196 {
197  _depth = d;
198 }
const DGtal::Color & LibBoard::Shape::fillColor ( ) const
inline

Definition at line 373 of file Board/Shapes.h.

References _fillColor.

374 {
375  return _fillColor;
376 }
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
bool LibBoard::Shape::filled ( ) const
inline
virtual void LibBoard::Shape::flushCairo ( cairo_t *  cr,
const TransformCairo transform 
) const
pure virtual

Writes the cairo code of the shape in a cairo drawing context according to a transform.

Parameters
crThe cairo drawing context.
transformA 2D transform to be applied.

Implemented in LibBoard::Text, LibBoard::Arc, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Image, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, and LibBoard::ShapeList.

virtual void LibBoard::Shape::flushFIG ( std::ostream &  stream,
const TransformFIG transform,
std::map< DGtal::Color, int > &  colormap 
) const
pure virtual

Writes the FIG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.
colormapA colormap.

Implemented in LibBoard::Text, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Image, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, and LibBoard::ShapeList.

virtual void LibBoard::Shape::flushPostscript ( std::ostream &  stream,
const TransformEPS transform 
) const
pure virtual

Writes the EPS code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implemented in LibBoard::Text, LibBoard::Arc, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, and LibBoard::ShapeList.

virtual void LibBoard::Shape::flushSVG ( std::ostream &  stream,
const TransformSVG transform 
) const
pure virtual

Writes the SVG code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implemented in LibBoard::Text, LibBoard::Arc, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Image, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, and LibBoard::ShapeList.

virtual void LibBoard::Shape::flushTikZ ( std::ostream &  stream,
const TransformTikZ transform 
) const
pure virtual

Writes the TikZ code of the shape in a stream according to a transform.

Parameters
streamThe output stream.
transformA 2D transform to be applied.

Implemented in LibBoard::Text, LibBoard::Arc, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Image, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, and LibBoard::ShapeList.

const std::string & LibBoard::Shape::name ( ) const
virtual

Returns the generic name of the shape (e.g., Circle, Rectangle, etc.)

Returns
object name

Reimplemented in LibBoard::Text, LibBoard::Arc, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::QuadraticBezierCurve, LibBoard::Triangle, LibBoard::Image, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Arrow, LibBoard::Line, LibBoard::Dot, LibBoard::Group, and LibBoard::ShapeList.

Definition at line 104 of file Shapes.cpp.

References _name.

105 {
106  return _name;
107 }
static const std::string _name
Definition: Board/Shapes.h:291
Shape & LibBoard::Shape::operator++ ( )
inline

Increment the depth of the shape. (Push the shape toward the background.)

Returns
a shape

Definition at line 346 of file Board/Shapes.h.

References _depth.

347 {
348  ++_depth;
349  return *this;
350 }
Shape & LibBoard::Shape::operator-- ( )
inline

Decrement the depth of the shape. (Pull the shape toward the foreground.)

Returns
a shape

Definition at line 353 of file Board/Shapes.h.

References _depth.

354 {
355  --_depth;
356  return *this;
357 }
const DGtal::Color & LibBoard::Shape::penColor ( ) const
inline

Definition at line 367 of file Board/Shapes.h.

References _penColor.

368 {
369  return _penColor;
370 }
DGtal::Color _penColor
Definition: Board/Shapes.h:296
std::string LibBoard::Shape::postscriptProperties ( ) const
protected

Return a string of the properties lineWidth, penColor, lineCap, and lineJoin as Postscript commands.

Returns
A string of the Postscript commands.

Definition at line 141 of file Shapes.cpp.

References _lineCap, _lineJoin, _lineStyle, and _lineWidth.

Referenced by LibBoard::Dot::flushPostscript(), LibBoard::Line::flushPostscript(), LibBoard::Arrow::flushPostscript(), LibBoard::Polyline::flushPostscript(), LibBoard::QuadraticBezierCurve::flushPostscript(), and LibBoard::Ellipse::flushPostscript().

142 {
143  std::stringstream str;
144  str << _lineWidth << " slw ";
145  str << _lineCap << " slc ";
146  str << _lineJoin << " slj";
147  str << xFigDashStylesPS[ _lineStyle ];
148 
149  return str.str();
150 }
LineJoin _lineJoin
Definition: Board/Shapes.h:301
LineStyle _lineStyle
Definition: Board/Shapes.h:299
virtual Shape& LibBoard::Shape::rotate ( double  angle,
const Point center 
)
pure virtual

Rotate the shape around a given center of rotation.

Parameters
angleThe rotation angle in radian.
centerThe center of rotation.
Returns
A reference to the shape itself.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Board, and LibBoard::ShapeList.

Referenced by LibBoard::Board::addDuplicates(), and rotateDeg().

virtual Shape& LibBoard::Shape::rotate ( double  angle)
pure virtual

Rotate the shape around its center.

Parameters
angleThe rotation angle in radian.
Returns
A reference to the shape itself.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Board, and LibBoard::ShapeList.

Shape & LibBoard::Shape::rotateDeg ( double  angle,
const Point center 
)
inline

Rotate the shape around a given center of rotation.

Parameters
angleThe rotation angle in degree.
centerThe center of rotation.
Returns
A reference to the shape itself.

Definition at line 379 of file Board/Shapes.h.

References rotate().

380 {
381  return rotate( angle * ( M_PI / 180.0 ), aCenter );
382 }
virtual Shape & rotate(double angle, const Point &center)=0
Shape & LibBoard::Shape::rotateDeg ( double  angle)
inline

Rotate the shape around its center.

Parameters
angleThe rotation angle in degree.
Returns
A reference to the shape itself.

Definition at line 385 of file Board/Shapes.h.

References center(), and rotate().

386 {
387  return rotate( angle * ( M_PI / 180.0 ), center() );
388 }
virtual Shape & rotate(double angle, const Point &center)=0
virtual Point center() const =0
virtual Shape& LibBoard::Shape::scale ( double  sx,
double  sy 
)
pure virtual

Scale the shape along the x an y axis.

Parameters
sxThe scale factor along the x axis.
syThe scale factor along the y axis.
Returns
The shape itself.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Board, and LibBoard::ShapeList.

Referenced by LibBoard::Board::addDuplicates().

virtual Shape& LibBoard::Shape::scale ( double  s)
pure virtual

Scale the shape along both axis.

Parameters
sThe scale factor along both axis.
Returns
The shape itself.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Board, and LibBoard::ShapeList.

virtual void LibBoard::Shape::scaleAll ( double  s)
pure virtual

Scales all the values (positions, dimensions, etc.) associated with the shape.

Parameters
sThe scaling factor.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::GouraudTriangle, LibBoard::Rectangle, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, and LibBoard::ShapeList.

Referenced by LibBoard::ShapeList::addShape(), and LibBoard::Board::State::unit().

void LibBoard::Shape::setCairoDashStyle ( cairo_t *  cr,
LineStyle  type 
) const
protected

Set a cairo dash style.

Parameters
crThe cairo drawing context.
typeLineStyle: SolidStyle, DashStyle, DotStyle, DashDotStyle, DashDotDotStyle, DashDotDotDotStyle.

Definition at line 154 of file Shapes.cpp.

References DashDotDotDotStyle, DashDotDotStyle, DashDotStyle, DashStyle, DotStyle, and SolidStyle.

Referenced by LibBoard::Dot::flushCairo(), LibBoard::Line::flushCairo(), LibBoard::Arrow::flushCairo(), LibBoard::Polyline::flushCairo(), LibBoard::Rectangle::flushCairo(), LibBoard::QuadraticBezierCurve::flushCairo(), LibBoard::Ellipse::flushCairo(), LibBoard::Circle::flushCairo(), and LibBoard::Arc::flushCairo().

155 {
156  switch (type)
157  {
158  case SolidStyle:
159  cairo_set_dash (cr, cairoSolidStyle, ARRAY_SIZE(cairoSolidStyle), cairoSolidStyle_offset); break;
160  case DashStyle:
161  cairo_set_dash (cr, cairoDashStyle, ARRAY_SIZE(cairoDashStyle), cairoDashStyle_offset); break;
162  case DotStyle:
163  cairo_set_dash (cr, cairoDotStyle, ARRAY_SIZE(cairoDotStyle), cairoDotStyle_offset); break;
164  case DashDotStyle:
165  cairo_set_dash (cr, cairoDashDotStyle, ARRAY_SIZE(cairoDashDotStyle), cairoDashDotStyle_offset); break;
166  case DashDotDotStyle:
167  cairo_set_dash (cr, cairoDashDotDotStyle, ARRAY_SIZE(cairoDashDotDotStyle), cairoDashDotDotStyle_offset); break;
168  case DashDotDotDotStyle:
169  cairo_set_dash (cr, cairoDashDotDotDotStyle, ARRAY_SIZE(cairoDashDotDotDotStyle), cairoDashDotDotDotStyle_offset); break;
170 
171  default: // SolidStyle
172  cairo_set_dash (cr, cairoSolidStyle, ARRAY_SIZE(cairoSolidStyle), cairoSolidStyle_offset);
173  }
174 }
void LibBoard::Shape::shiftDepth ( int  shift)
virtual

Reimplemented in LibBoard::ShapeList.

Definition at line 201 of file Shapes.cpp.

References _depth.

202 {
203  _depth += shift;
204 }
std::string LibBoard::Shape::svgProperties ( const TransformSVG transform) const
protected

Return a string of the svg properties lineWidth, opacity, penColor, fillColor, lineCap, and lineJoin.

Returns
A string of the properties suitable for inclusion in an svg tag.

Definition at line 110 of file Shapes.cpp.

References _fillColor, _lineCap, _lineJoin, _lineStyle, _lineWidth, _penColor, LibBoard::TransformSVG::mapWidth(), DGtal::Color::None, SolidStyle, DGtal::Color::svg(), and DGtal::Color::svgAlpha().

Referenced by LibBoard::Dot::flushSVG(), LibBoard::Line::flushSVG(), LibBoard::Polyline::flushSVG(), LibBoard::Rectangle::flushSVG(), LibBoard::QuadraticBezierCurve::flushSVG(), LibBoard::Ellipse::flushSVG(), LibBoard::Circle::flushSVG(), and LibBoard::Arc::flushSVG().

111 {
112  static const char * capStrings[3] = { "butt", "round", "square" };
113  static const char * joinStrings[3] = { "miter", "round", "bevel" };
114  std::stringstream str;
115  if ( _penColor != DGtal::Color::None ) {
116  str << " fill=\"" << _fillColor.svg() << '"'
117  << " stroke=\"" << _penColor.svg() << '"'
118  << " stroke-width=\"" << transform.mapWidth( _lineWidth ) << "mm\""
119  << " style=\"stroke-linecap:" << capStrings[ _lineCap ]
120  << ";stroke-linejoin:" << joinStrings[ _lineJoin ];
121  if ( _lineStyle != SolidStyle )
122  str << ";" << xFigDashStylesSVG[ _lineStyle ];
123  str << '"'
124  << _fillColor.svgAlpha( " fill" )
125  << _penColor.svgAlpha( " stroke" );
126  } else {
127  str << " fill=\"" << _fillColor.svg() << '"'
128 // << " stroke=\"" << _fillColor.svg() << '"'
129 // << " stroke-width=\"0.5px\""
130  << " stroke=\"none\""
131  << " stroke-width=\"0\""
132  << " style=\"stroke-linecap:round;stroke-linejoin:round;"
133  << '"'
134  << _fillColor.svgAlpha( " fill" )
135  << _fillColor.svgAlpha( " stroke" );
136  }
137  return str.str();
138 }
static const Color None
Definition: Color.h:387
std::string svg() const
Definition: Color.cpp:140
LineJoin _lineJoin
Definition: Board/Shapes.h:301
DGtal::Color _penColor
Definition: Board/Shapes.h:296
LineStyle _lineStyle
Definition: Board/Shapes.h:299
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
std::string svgAlpha(const char *aPrefix) const
Definition: Color.cpp:149
std::string LibBoard::Shape::tikzProperties ( const TransformTikZ transform) const
protected

Return a string of the properties lineWidth, penColor, lineCap, and lineJoin as TikZ commands.

Returns
A string of the TikZ commands.

Definition at line 178 of file Shapes.cpp.

References _fillColor, _lineCap, _lineJoin, _lineStyle, _lineWidth, _penColor, LibBoard::TransformSVG::mapWidth(), and DGtal::Color::tikz().

Referenced by LibBoard::Line::flushTikZ(), LibBoard::Arrow::flushTikZ(), LibBoard::Polyline::flushTikZ(), LibBoard::Rectangle::flushTikZ(), LibBoard::QuadraticBezierCurve::flushTikZ(), LibBoard::Ellipse::flushTikZ(), LibBoard::Circle::flushTikZ(), LibBoard::Arc::flushTikZ(), and LibBoard::Text::flushTikZ().

179 {
180  static const char * capStrings[3] = { "" /* initial value "butt" */, "line cap=round,", "line cap=rect," };
181  static const char * joinStrings[3] = { "" /* initial value "miter" */, "line join=round", "line join=bevel" };
182 
183  std::stringstream str;
184  str << "fill=" << _fillColor.tikz() << ',';
185  str << "draw=" << _penColor.tikz() << ',';
186  str << "line width=" << transform.mapWidth( _lineWidth ) << "mm,";
187  str << xFigDashStylesTikZ[ _lineStyle ];
188  str << capStrings[ _lineCap ];
189  str << joinStrings[ _lineJoin ];
190 
191  return str.str();
192 }
LineJoin _lineJoin
Definition: Board/Shapes.h:301
std::string tikz() const
Definition: Color.cpp:158
DGtal::Color _penColor
Definition: Board/Shapes.h:296
LineStyle _lineStyle
Definition: Board/Shapes.h:299
DGtal::Color _fillColor
Definition: Board/Shapes.h:297
virtual Shape& LibBoard::Shape::translate ( double  dx,
double  dy 
)
pure virtual

Translate the shape by a given offset.

Parameters
dxThe x offset.
dyThe y offset.
Returns
A reference to the shape itself.

Implemented in LibBoard::Text, LibBoard::Circle, LibBoard::Ellipse, LibBoard::Polyline, LibBoard::Line, LibBoard::Dot, LibBoard::Group, LibBoard::Board, and LibBoard::ShapeList.

Referenced by LibBoard::Board::addDuplicates().

Field Documentation

int LibBoard::Shape::_depth
protected
DGtal::Color LibBoard::Shape::_fillColor
protected
LineCap LibBoard::Shape::_lineCap
protected
LineJoin LibBoard::Shape::_lineJoin
protected
LineStyle LibBoard::Shape::_lineStyle
protected
double LibBoard::Shape::_lineWidth
protected
const std::string LibBoard::Shape::_name
staticprivate

The generic name of the shape.

Definition at line 291 of file Board/Shapes.h.

Referenced by name().

DGtal::Color LibBoard::Shape::_penColor
protected

The documentation for this struct was generated from the following files: