DGtal  0.9.3
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

◆ 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.

References clone(), and name().

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.

References boundingBox().

Referenced by filled().

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

◆ 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(), LibBoard::Ellipse::Ellipse(), filled(), LibBoard::Polyline::operator[](), and LibBoard::Text::Text().

◆ center()

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

◆ clone()

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

◆ depth() [1/2]

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

◆ depth() [2/2]

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

Definition at line 195 of file Shapes.cpp.

References _depth.

196 {
197  _depth = d;
198 }

◆ fillColor()

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

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

References _fillColor.

Referenced by filled().

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

◆ filled()

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

◆ flushCairo()

virtual void LibBoard::Shape::flushCairo ( cairo_t *  cr,
const TransformCairo transform 
) const
pure virtual

◆ flushFIG()

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

◆ flushPostscript()

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

◆ flushSVG()

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

◆ flushTikZ()

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

◆ name()

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

◆ 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.

References _depth.

Referenced by filled().

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

◆ 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.

References _depth.

Referenced by filled().

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

◆ penColor()

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

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

References _penColor.

Referenced by filled().

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

◆ 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 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

◆ 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(), LibBoard::Circle::Circle(), LibBoard::Ellipse::Ellipse(), filled(), LibBoard::Polyline::operator[](), LibBoard::Ellipse::rotate(), rotateDeg(), and LibBoard::Text::Text().

◆ 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.

References rotate().

Referenced by filled().

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

◆ 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.

References center(), and rotate().

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

◆ scale() [1/2]

virtual Shape& LibBoard::Shape::scale ( double  sx,
double  sy 
)
pure virtual

◆ 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

◆ 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 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 }

◆ shiftDepth()

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

Reimplemented in LibBoard::ShapeList.

Definition at line 201 of file Shapes.cpp.

References _depth, and LibBoard::Dot::_name.

Referenced by filled(), and testDisplay().

202 {
203  _depth += shift;
204 }

◆ 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 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 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

◆ 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 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 }
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

◆ translate()

virtual Shape& LibBoard::Shape::translate ( double  dx,
double  dy 
)
pure virtual

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

◆ _penColor

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

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