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

Abstract structure for a 2D shape. More...

#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

◆ LineCap

Enumerator
ButtCap 
RoundCap 
SquareCap 

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

◆ LineJoin

Enumerator
MiterJoin 
RoundJoin 
BevelJoin 

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

◆ LineStyle

Enumerator
SolidStyle 
DashStyle 
DotStyle 
DashDotStyle 
DashDotDotStyle 
DashDotDotDotStyle 

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

Constructor & Destructor Documentation

◆ Shape()

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.

◆ ~Shape()

virtual LibBoard::Shape::~Shape ( )
inlinevirtual

Shape destructor.

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

90 { }

Member Function Documentation

◆ bbox()

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.

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

References boundingBox().

◆ boundingBox()

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().

◆ center()

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().

◆ clone()

virtual Shape* LibBoard::Shape::clone ( ) const
pure virtual

◆ depth() [1/2]

int LibBoard::Shape::depth ( ) const
inline

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

362 {
363  return _depth;
364 }

References _depth.

Referenced by LibBoard::ShapeList::addShape(), LibBoard::ShapeList::operator<<(), and LibBoard::shapeGreaterDepth().

◆ depth() [2/2]

void LibBoard::Shape::depth ( int  d)
virtual

Definition at line 194 of file Shapes.cpp.

195 {
196  _depth = d;
197 }

References _depth.

◆ fillColor()

const DGtal::Color & LibBoard::Shape::fillColor ( ) const
inline

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

374 {
375  return _fillColor;
376 }
DGtal::Color _fillColor
Definition: Board/Shapes.h:297

References _fillColor.

◆ filled()

bool LibBoard::Shape::filled ( ) const
inline

◆ flushCairo()

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.

◆ flushFIG()

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.

◆ flushPostscript()

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.

◆ flushSVG()

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.

◆ flushTikZ()

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.

◆ name()

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 103 of file Shapes.cpp.

104 {
105  return _name;
106 }
static const std::string _name
Definition: Board/Shapes.h:291

References _name.

◆ operator++()

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.

347 {
348  ++_depth;
349  return *this;
350 }

References _depth.

◆ operator--()

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.

354 {
355  --_depth;
356  return *this;
357 }

References _depth.

◆ penColor()

const DGtal::Color & LibBoard::Shape::penColor ( ) const
inline

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

368 {
369  return _penColor;
370 }
DGtal::Color _penColor
Definition: Board/Shapes.h:296

References _penColor.

◆ postscriptProperties()

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 140 of file Shapes.cpp.

141 {
142  std::stringstream str;
143  str << _lineWidth << " slw ";
144  str << _lineCap << " slc ";
145  str << _lineJoin << " slj";
146  str << xFigDashStylesPS[ _lineStyle ];
147 
148  return str.str();
149 }
LineJoin _lineJoin
Definition: Board/Shapes.h:301
LineStyle _lineStyle
Definition: Board/Shapes.h:299

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().

◆ rotate() [1/2]

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().

◆ rotate() [2/2]

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.

◆ rotateDeg() [1/2]

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.

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

References rotate().

◆ rotateDeg() [2/2]

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.

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

References center(), and rotate().

◆ scale() [1/2]

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().

◆ scale() [2/2]

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.

◆ scaleAll()

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::Board::State::unit().

◆ setCairoDashStyle()

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 153 of file Shapes.cpp.

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

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().

◆ shiftDepth()

void LibBoard::Shape::shiftDepth ( int  shift)
virtual

Reimplemented in LibBoard::ShapeList.

Definition at line 200 of file Shapes.cpp.

201 {
202  _depth += shift;
203 }

References _depth.

◆ svgProperties()

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 109 of file Shapes.cpp.

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

References _fillColor, _lineCap, _lineJoin, _lineStyle, _lineWidth, _penColor, 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().

◆ tikzProperties()

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 177 of file Shapes.cpp.

178 {
179  static const char * capStrings[3] = { "" /* initial value "butt" */, "line cap=round,", "line cap=rect," };
180  static const char * joinStrings[3] = { "" /* initial value "miter" */, "line join=round", "line join=bevel" };
181 
182  std::stringstream str;
183  str << "fill=" << _fillColor.tikz() << ',';
184  str << "draw=" << _penColor.tikz() << ',';
185  str << "line width=" << transform.mapWidth( _lineWidth ) << "mm,";
186  str << xFigDashStylesTikZ[ _lineStyle ];
187  str << capStrings[ _lineCap ];
188  str << joinStrings[ _lineJoin ];
189 
190  return str.str();
191 }
std::string tikz() const
Definition: Color.cpp:158
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

References _fillColor, _lineCap, _lineJoin, _lineStyle, _lineWidth, _penColor, 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().

◆ translate()

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

◆ _depth

int LibBoard::Shape::_depth
protected

◆ _fillColor

DGtal::Color LibBoard::Shape::_fillColor
protected

◆ _lineCap

LineCap LibBoard::Shape::_lineCap
protected

◆ _lineJoin

LineJoin LibBoard::Shape::_lineJoin
protected

◆ _lineStyle

LineStyle LibBoard::Shape::_lineStyle
protected

◆ _lineWidth

double LibBoard::Shape::_lineWidth
protected

◆ _name

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().

◆ _penColor

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

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