MolDraw2Dwx.h
Go to the documentation of this file.
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
// Author: Igor Filippov based on the work of David Cosgrove (AstraZeneca)
//
// This is a concrete class derived from MolDraw2D that uses RDKit to draw a
// molecule into a wxDC
#ifndef MOLDRAW2DWX_H
#define MOLDRAW2DWX_H
#include <GraphMol/MolDraw2D/MolDraw2D.h>
#include <wx/dc.h>
#include <wx/font.h>
#include <wx/pen.h>
#include <wx/colour.h>
#include <wx/brush.h>
// ****************************************************************************
namespace RDKit {
class MolDraw2Dwx : public MolDraw2D {
public :
MolDraw2Dwx( int width , int height , wxDC &dc ) : MolDraw2D( width , height ), m_dc(dc)
{
// m_dc.SetFont(wxFont(10, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
}
// set font size in molecule coordinate units. That's probably Angstrom for
// RDKit. It will turned into drawing units using scale_, which might be
// changed as a result, to make sure things still appear in the window.
void setFontSize( double new_size )
{
MolDraw2D::setFontSize( new_size );
double font_size_in_points = fontSize() * scale();
wxFont font = m_dc.GetFont();
//font.SetPointSize(font_size_in_points);
font.SetPixelSize(wxSize(0,font_size_in_points));
m_dc.SetFont(font);
}
void setColour( const DrawColour &col )
{
MolDraw2D::setColour( col );
double r = col.get<0>();
double g = col.get<1>();
double b = col.get<2>();
wxColour colour(r * 255, g * 255, b * 255);
m_dc.SetTextForeground(colour);
m_dc.SetPen(wxPen(colour));
m_dc.SetBrush(wxBrush(colour));
}
void drawLine( const Point2D &cds1, const Point2D &cds2 )
{
Point2D c1 = getDrawCoords( cds1 );
Point2D c2 = getDrawCoords( cds2 );
m_dc.DrawLine(c1.x,c1.y,c2.x,c2.y);
}
void drawChar( char c , const Point2D &cds )
{
m_dc.DrawText(wxString(c),cds.x,cds.y);
}
void drawPolygon( const std::vector<Point2D > &cds ){
PRECONDITION(cds.size()>=3,"must have at least three points");
wxPoint lines[cds.size()];
for(unsigned int i=0;i<cds.size();++i){
Point2D c1 = getDrawCoords( cds[i] );
lines[i] = wxPoint(c1.x,c1.y);
}
// FIX: deal with toggling fills
m_dc.DrawPolygon(cds.size(),lines);
};
void clearDrawing()
{
wxColour backgroundColour = m_dc.GetTextBackground();
if (!backgroundColour.Ok())
backgroundColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
const wxBrush &brush = m_dc.GetBrush();
const wxPen &pen = m_dc.GetPen();
m_dc.SetBrush(wxBrush(backgroundColour));
m_dc.SetPen(wxPen(backgroundColour, 1));
m_dc.DrawRectangle(0,0, width(), height());
m_dc.SetBrush(brush);
m_dc.SetPen(pen);
}
// using the current scale, work out the size of the label in molecule coordinates
void getStringSize( const std::string &label, double &label_width, double &label_height ) const
{
if (m_dc.CanGetTextExtent())
{
wxCoord width, height;
m_dc.GetTextExtent(wxString(label), &width, &height);
label_width = double(width) / scale();
label_height = double(height) / scale();
}
}
private :
wxDC &m_dc;
};
}
#endif // MOLDRAW2DWX_H
RDKit::MolDraw2Dwx::setColour
void setColour(const DrawColour &col)
Definition: MolDraw2Dwx.h:50
RDKit::MolDraw2D::setColour
virtual void setColour(const DrawColour &col)
Definition: MolDraw2D.h:105
RDKit::MolDraw2D::height
virtual int height() const
Definition: MolDraw2D.h:95
RDKit::MolDraw2D::colour
virtual DrawColour colour() const
Definition: MolDraw2D.h:106
RDKit::MolDraw2Dwx::drawPolygon
void drawPolygon(const std::vector< Point2D > &cds)
Definition: MolDraw2Dwx.h:74
RDKit::MolDraw2Dwx::setFontSize
void setFontSize(double new_size)
Definition: MolDraw2Dwx.h:40
RDKit::MolDraw2Dwx::drawChar
void drawChar(char c, const Point2D &cds)
Definition: MolDraw2Dwx.h:69
RDGeom::Point2D::y
double y
Definition: point.h:265
RDKit::MolDraw2Dwx::MolDraw2Dwx
MolDraw2Dwx(int width, int height, wxDC &dc)
Definition: MolDraw2Dwx.h:31
RDKit::DrawColour
boost::tuple< float, float, float > DrawColour
Definition: MolDraw2D.h:37
RDGeom::Point2D
Definition: point.h:263
MolDraw2D.h
RDKit::MolDraw2Dwx
Definition: MolDraw2Dwx.h:27
RDKit::MolDraw2Dwx::drawLine
void drawLine(const Point2D &cds1, const Point2D &cds2)
Definition: MolDraw2Dwx.h:62
RDKit::MolDraw2D::getDrawCoords
virtual Point2D getDrawCoords(const Point2D &mol_cds) const
RDKit::MolDraw2Dwx::clearDrawing
void clearDrawing()
Definition: MolDraw2Dwx.h:85
RDKit::MolDraw2D::setFontSize
virtual void setFontSize(double new_size)
RDKit
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
RDKit::MolDraw2D::width
virtual int width() const
Definition: MolDraw2D.h:94
RDKit::MolDraw2D::scale
virtual double scale() const
Definition: MolDraw2D.h:97
RDKit::MolDraw2D
Definition: MolDraw2D.h:60
PRECONDITION
#define PRECONDITION(expr, mess)
Definition: Invariant.h:119
RDGeom::Point2D::x
double x
Definition: point.h:265
RDKit::MolDraw2D::fontSize
virtual double fontSize() const
Definition: MolDraw2D.h:100
RDKit::MolDraw2Dwx::getStringSize
void getStringSize(const std::string &label, double &label_width, double &label_height) const
Definition: MolDraw2Dwx.h:100