diff --git a/Code/GraphMol/MolDraw2D/MolDraw2DSVG.h b/Code/GraphMol/MolDraw2D/MolDraw2DSVG.h index 15fd975d3..b85829ca1 100644 --- a/Code/GraphMol/MolDraw2D/MolDraw2DSVG.h +++ b/Code/GraphMol/MolDraw2D/MolDraw2DSVG.h @@ -16,6 +16,7 @@ #define MOLDRAW2DSVG_H #include +#include #include "MolDraw2D.h" // **************************************************************************** @@ -25,8 +26,12 @@ namespace RDKit { class MolDraw2DSVG : public MolDraw2D { public : + // initialize to use a particular ostream MolDraw2DSVG( int width , int height , std::ostream &os ) : MolDraw2D( width , height ) , d_os( os ) { initDrawing(); }; + // initialize to use the internal stringstream + MolDraw2DSVG( int width , int height ) : + MolDraw2D( width , height ) , d_os(d_ss) { initDrawing(); }; // set font size in molecule coordinate units. That's probably Angstrom for // RDKit. It will turned into drawing units using scale_, which might be @@ -50,8 +55,11 @@ namespace RDKit { void getStringSize( const std::string &label , float &label_width , float &label_height ) const; + // this only makes sense if the object was initialized without a stream + std::string getDrawingText() const {return d_ss.str(); }; private : std::ostream &d_os; + std::stringstream d_ss; void drawChar( char c , const std::pair &cds ); void initDrawing(); diff --git a/Code/GraphMol/MolDraw2D/test1.cpp b/Code/GraphMol/MolDraw2D/test1.cpp index be776141f..82143a55d 100644 --- a/Code/GraphMol/MolDraw2D/test1.cpp +++ b/Code/GraphMol/MolDraw2D/test1.cpp @@ -38,6 +38,21 @@ void test1(){ outs.flush(); delete m; } + { + // make sure this works with the stringstream too: + std::string smiles="CO[C@@H](O)C1=C(O[C@H](F)Cl)C=C1ONNC[NH3+]"; + ROMol *m = SmilesToMol(smiles); + TEST_ASSERT(m); + RDDepict::compute2DCoords(*m); + WedgeMolBonds(*m,&(m->getConformer())); + MolDraw2DSVG drawer(300,300); + drawer.drawMolecule(*m); + drawer.finishDrawing(); + std::string text = drawer.getDrawingText(); + TEST_ASSERT(text.find("")!=std::string::npos); + delete m; + } { std::string smiles="Cc1c(C(=O)NCCO)[n+](=O)c2ccccc2n1[O-]"; ROMol *m = SmilesToMol(smiles); diff --git a/Code/JavaWrappers/MolDraw2D.i b/Code/JavaWrappers/MolDraw2D.i index 7f79b7b4b..cd4666a20 100644 --- a/Code/JavaWrappers/MolDraw2D.i +++ b/Code/JavaWrappers/MolDraw2D.i @@ -40,6 +40,8 @@ %template(INT_DRAWCOLOUR_MAP) std::map< int, RDKit::DrawColour >; %template(DrawColour) boost::tuple; +%ignore RDKit::MolDraw2DSVG::MolDraw2DSVG(int,int,std::ostream &); + %include %include