Chemical Data Processing Library C++ API - Version 1.2.0
StructureGridView2D.hpp
Go to the documentation of this file.
1 /*
2  * StructureGridView2D.hpp
3  *
4  * This file is part of the Chemical Data Processing Toolkit
5  *
6  * Copyright (C) 2003 Thomas Seidel <thomas.seidel@univie.ac.at>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this library; see the file COPYING. If not, write to
20  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23 
29 #ifndef CDPL_VIS_STRUCTUREGRIDVIEW2D_HPP
30 #define CDPL_VIS_STRUCTUREGRIDVIEW2D_HPP
31 
32 #include <memory>
33 #include <utility>
34 #include <cstddef>
35 #include <iosfwd>
36 #include <iterator>
37 
38 #include <boost/unordered_map.hpp>
39 
40 #include "CDPL/Config.hpp"
41 #include "CDPL/Vis/APIPrefix.hpp"
44 #include "CDPL/Vis/Alignment.hpp"
46 #include "CDPL/Math/Vector.hpp"
47 #include "CDPL/Util/ObjectPool.hpp"
48 
49 
50 namespace CDPL
51 {
52 
53  namespace Base
54  {
55 
56  class DataFormat;
57  }
58 
59  namespace Vis
60  {
61 
126  {
127 
128  public:
132  static constexpr double DEF_CELL_WIDTH = 250.0;
133 
137  static constexpr double DEF_CELL_HEIGHT = 250.0;
138 
142  typedef std::shared_ptr<StructureGridView2D> SharedPointer;
143 
148  {
149 
150  public:
154  typedef std::shared_ptr<Cell> SharedPointer;
155 
159  static constexpr unsigned int DEF_TEXT_POSITION = Alignment::BOTTOM | Alignment::H_CENTER;
160 
161  Cell(const Cell&) = delete;
162 
171  void setStructure(const Chem::MolecularGraph& molgraph);
172 
178 
183 
188  bool hasStructure() const;
189 
203  void setText(const std::string& text, unsigned int pos = DEF_TEXT_POSITION,
204  unsigned int line_almnt = Alignment::NONE);
205 
211  const std::string& getText(unsigned int pos = DEF_TEXT_POSITION) const;
212 
217  void clearText(unsigned int pos = DEF_TEXT_POSITION);
218 
223  bool hasText(unsigned int pos = DEF_TEXT_POSITION) const;
224 
228  void clearAllText();
229 
234  bool hasAnyText() const;
235 
241  Cell& operator=(const Cell& cell);
242 
243  private:
244  friend class StructureGridView2D;
245 
246  Cell();
247  ~Cell();
248 
249  void setFontMetrics(FontMetrics* font_metrics);
250 
251  void setSize(double width, double height);
252 
253  void parameterChanged(const Base::LookupKey& key, const Base::Any& value);
254  void parameterRemoved(const Base::LookupKey& key);
255  void parentChanged();
256 
257  void layout();
258  void render(Renderer2D& renderer);
259 
260  static std::size_t posToArrayIndex(unsigned int pos);
261 
262  StructureView2D structView;
263  TextBlockPrimitive2D textBlocks[9];
264  Chem::BasicMolecule molecule;
265  FontMetrics* fontMetrics;
266  double width;
267  double height;
268  bool layoutValid;
269  };
270 
276 
282 
287 
288  void render(Renderer2D& renderer);
289 
290 #ifdef HAVE_CAIRO
291 
301  bool write(const std::string& file_name);
302 
314  bool write(const std::string& file_name, const std::string& fmt);
315 
327  bool write(const std::string& file_name, const Base::DataFormat& fmt);
328 
340  bool write(std::ostream& os, const std::string& fmt);
341 
353  bool write(std::ostream& os, const Base::DataFormat& fmt);
354 
355 #endif // HAVE_CAIRO
356 
357  void setFontMetrics(FontMetrics* font_metrics);
358 
364 
366 
377  Cell& operator()(std::size_t row, std::size_t col);
378 
390  const Cell& operator()(std::size_t row, std::size_t col) const;
391 
401  void setCellSize(double width, double height);
402 
407  double getCellWidth() const;
408 
413  double getCellHeight() const;
414 
425  void resize(std::size_t num_rows, std::size_t num_cols);
426 
431  std::size_t getNumRows() const;
432 
437  std::size_t getNumColumns() const;
438 
444 
449  void clearAllText();
450 
457 
458  private:
460  typedef CellCache::SharedObjectPointer CellPointer;
461 
462  void copy(const StructureGridView2D& grid_view);
463 
464  void getGridPosition(Math::Vector2D& pos);
465 
466  CellPointer allocCell();
467 
468  static Cell* newCell();
469  static void deleteCell(Cell* cell);
470  static void cleanupCell(Cell& cell);
471 
472  typedef std::pair<std::size_t, std::size_t> CellID;
473  typedef boost::unordered_map<CellID, Cell::SharedPointer> CellMap;
474 
475  CellCache cellCache;
476  FontMetrics* fontMetrics;
477  CellMap cells;
478  double cellWidth;
479  double cellHeight;
480  std::size_t numRows;
481  std::size_t numColumns;
482  };
483  } // namespace Vis
484 } // namespace CDPL
485 
486 #endif // CDPL_VIS_STRUCTUREGRIDVIEW2D_HPP
Definition of constants in namespace CDPL::Vis::Alignment.
Definition of the class CDPL::Chem::BasicMolecule.
Provides CDPKit build configuration information.
Definition of the class CDPL::Util::ObjectPool.
Definition of the class CDPL::Vis::StructureView2D.
Definition of the class CDPL::Vis::TextBlockPrimitive2D.
Definition of vector data types.
Definition of the preprocessor macro CDPL_VIS_API.
#define CDPL_VIS_API
Tells the compiler/linker which classes, functions and variables are part of the library API.
A safe, type checked container for arbitrary data of variable type.
Definition: Any.hpp:59
A class providing methods for the storage and lookup of control-parameter values.
Definition: ControlParameterContainer.hpp:93
Provides meta-information about a particular data storage format.
Definition: Base/DataFormat.hpp:49
An unique lookup key for control-parameter and property values.
Definition: LookupKey.hpp:54
BasicMolecule.
Definition: BasicMolecule.hpp:54
MolecularGraph.
Definition: MolecularGraph.hpp:52
std::shared_ptr< ObjectType > SharedObjectPointer
Definition: ObjectPool.hpp:65
An interface class with methods that provide information about the metrics of a font.
Definition: FontMetrics.hpp:71
Specifies an axis aligned rectangular area in 2D space.
Definition: Rectangle2D.hpp:51
An interface that provides methods for low level 2D drawing operations.
Definition: Renderer2D.hpp:86
Data structure storing the contents of a grid cell.
Definition: StructureGridView2D.hpp:148
void clearStructure()
Hides the dcurrently displayed molecular structure (if any) and clears the stored data.
bool hasText(unsigned int pos=DEF_TEXT_POSITION) const
Tells whether any text is displayed at the specified position.
const Chem::MolecularGraph & getStructure() const
Returns the stored data of the currently displayed molecular structure (if any).
std::shared_ptr< Cell > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated Cell instances.
Definition: StructureGridView2D.hpp:154
bool hasAnyText() const
Tells whether this cell displays any text.
Cell & operator=(const Cell &cell)
Performs a copy assignment of the specified Cell instance.
bool hasStructure() const
Tells whether this cell displays a molecular structure.
void setText(const std::string &text, unsigned int pos=DEF_TEXT_POSITION, unsigned int line_almnt=Alignment::NONE)
Specifies the text that shall be displayed at the given position.
const std::string & getText(unsigned int pos=DEF_TEXT_POSITION) const
Returns the text displayed at the specified position.
void clearAllText()
Clears all text blocks.
void setStructure(const Chem::MolecularGraph &molgraph)
Specifies the molecular structure that shall be displayed in this cell.
void clearText(unsigned int pos=DEF_TEXT_POSITION)
Clears the text displayed at the specified position.
Implements the 2D visualization of multiple chemical structures arrange in a grid.
Definition: StructureGridView2D.hpp:126
StructureGridView2D()
Constructs and initializes a StructureGridView2D instance for the visualization of multiple chemical ...
std::size_t getNumColumns() const
Returns the current number of grid columns.
void setFontMetrics(FontMetrics *font_metrics)
Specifies a font metrics object that will be used to measure the dimension of text labels.
Cell & operator()(std::size_t row, std::size_t col)
Returns the Cell instance storing the contents of the specified grid cell.
double getCellHeight() const
Returns the active grid cell height.
void clearStructures()
Clears all specified structures.
FontMetrics * getFontMetrics() const
Returns a pointer to the used font metrics object.
void clearAllText()
Clears all specified text blocks.
void setCellSize(double width, double height)
Allows to specify the desired width and height of the cells in grid output renderings.
bool write(std::ostream &os, const Base::DataFormat &fmt)
Renders the grid with the specified cell contents and writes the generated image data to the output s...
bool write(const std::string &file_name)
Renders the grid with the specified cell contents and stores the generated image in the file file_nam...
StructureGridView2D & operator=(const StructureGridView2D &grid_view)
Performs a copy assignment of the specified StructureGridView2D instance.
const Cell & operator()(std::size_t row, std::size_t col) const
Returns the Cell instance storing the contents of the specified grid cell.
std::size_t getNumRows() const
Returns the current number of grid rows.
void getModelBounds(Rectangle2D &bounds)
Calculates the bounding rectangle of the visualized model.
void resize(std::size_t num_rows, std::size_t num_cols)
Chnages the current number of grid rows and columns.
bool write(const std::string &file_name, const std::string &fmt)
Renders the grid with the specified cell contents and stores the generated image in the file file_nam...
bool write(std::ostream &os, const std::string &fmt)
Renders the grid with the specified cell contents and writes the generated image data to the output s...
StructureGridView2D(const StructureGridView2D &grid_view)
Constructs a copy of the StructureGridView2D instance grid_view.
double getCellWidth() const
Returns the active grid cell width.
void render(Renderer2D &renderer)
Renders the visual representation of the model using the specified Vis::Renderer2D instance.
bool write(const std::string &file_name, const Base::DataFormat &fmt)
Renders the grid with the specified cell contents and stores the generated image in the file file_nam...
std::shared_ptr< StructureGridView2D > SharedPointer
A reference-counted smart pointer [SHPTR] for dynamically allocated StructureGridView2D instances.
Definition: StructureGridView2D.hpp:142
Implements the 2D visualization of chemical structures.
Definition: StructureView2D.hpp:678
A graphics primitive representing a block of styled text.
Definition: TextBlockPrimitive2D.hpp:69
The abstract base of classes implementing the 2D visualization of data objects.
Definition: View2D.hpp:59
MatrixRow< M > row(MatrixExpression< M > &e, typename MatrixRow< M >::SizeType i)
Definition: MatrixProxy.hpp:716
CVector< double, 2 > Vector2D
A bounded 2 element vector holding floating point values of type double.
Definition: Vector.hpp:1632
constexpr unsigned int H_CENTER
Specifies that an object has to be centered horizontally.
Definition: Alignment.hpp:67
constexpr unsigned int BOTTOM
Specifies an alignment to the bottom.
Definition: Alignment.hpp:82
constexpr unsigned int NONE
Specifies that an object has no special alignment.
Definition: Alignment.hpp:52
The namespace of the Chemical Data Processing Library.