| 13 |
|
GNU General Public License for more details. |
| 14 |
|
***********************************************************************/ |
| 15 |
|
|
| 16 |
< |
#include "povrayformat.hpp" |
| 16 |
> |
/* ---- C includes ---- */ |
| 17 |
> |
#include <math.h> |
| 18 |
> |
#include <time.h> |
| 19 |
> |
#include <stdlib.h> |
| 20 |
|
|
| 21 |
+ |
/* ---- OpenBabel include ---- */ |
| 22 |
+ |
#include "config.h" |
| 23 |
+ |
#include "mol.hpp" |
| 24 |
+ |
#include "obconversion.hpp" |
| 25 |
+ |
|
| 26 |
+ |
/* ---- C++ includes ---- */ |
| 27 |
+ |
#include <string> |
| 28 |
+ |
#if defined(HAVE_SSTREAM) |
| 29 |
+ |
#include <sstream> |
| 30 |
+ |
#else |
| 31 |
+ |
#include <strstream> |
| 32 |
+ |
#endif |
| 33 |
+ |
|
| 34 |
+ |
/* ---- Max. length of a atom-label ---- */ |
| 35 |
+ |
#define StrLen 32 |
| 36 |
+ |
|
| 37 |
+ |
/* ---- Define max. length of domainname ---- */ |
| 38 |
+ |
#define MAXDOMAINNAMELEN 256 |
| 39 |
+ |
|
| 40 |
+ |
/* ---- Maximal radius of an atom. Needed for bounding box ---- */ |
| 41 |
+ |
#define MAXRADIUS (double) 3.0 |
| 42 |
+ |
|
| 43 |
+ |
/* ---- Define index of first atom if needed ---- */ |
| 44 |
+ |
#ifndef MIN_ATOM |
| 45 |
+ |
#define MIN_ATOM 1 |
| 46 |
+ |
#endif |
| 47 |
+ |
|
| 48 |
+ |
/* ---- Size of time-string ---- */ |
| 49 |
+ |
#define TIME_STR_SIZE 64 |
| 50 |
+ |
|
| 51 |
+ |
/* ---- if x < = EPSILON then x = 0.0 ---- */ |
| 52 |
+ |
#define EPSILON (double) 1e-4 |
| 53 |
+ |
|
| 54 |
+ |
/* ---- Define makro for calculating x^2 ---- */ |
| 55 |
+ |
#ifdef SQUARE |
| 56 |
+ |
#undef SQUARE |
| 57 |
+ |
#endif |
| 58 |
+ |
#define SQUARE(x) ((x) * (x)) |
| 59 |
+ |
|
| 60 |
+ |
/* ---- Define PI (if needed) ---- */ |
| 61 |
+ |
#ifndef PI |
| 62 |
+ |
#define PI ((double) 3.1415926535897932384626433) |
| 63 |
+ |
#endif |
| 64 |
+ |
|
| 65 |
+ |
/* ---- Convert RAD to DEG ---- */ |
| 66 |
+ |
#define RAD2DEG(r) (((double) 180.0 * r) / PI) |
| 67 |
+ |
|
| 68 |
|
using namespace std; |
| 69 |
|
namespace OpenBabel |
| 70 |
+ |
{ |
| 71 |
+ |
|
| 72 |
+ |
class PovrayFormat : public OBFormat |
| 73 |
|
{ |
| 74 |
+ |
public: |
| 75 |
+ |
//Register this format type ID |
| 76 |
+ |
PovrayFormat() |
| 77 |
+ |
{ |
| 78 |
+ |
OBConversion::RegisterFormat("pov",this); |
| 79 |
+ |
} |
| 80 |
+ |
|
| 81 |
+ |
virtual const char* Description() //required |
| 82 |
+ |
{ |
| 83 |
+ |
return |
| 84 |
+ |
"POV-Ray input format\n \ |
| 85 |
+ |
No comments yet\n"; |
| 86 |
+ |
}; |
| 87 |
+ |
|
| 88 |
+ |
virtual const char* SpecificationURL() |
| 89 |
+ |
{return "http://www.povray.org/";}; //optional |
| 90 |
+ |
|
| 91 |
+ |
//Flags() can return be any the following combined by | or be omitted if none apply |
| 92 |
+ |
// NOTREADABLE READONEONLY NOTWRITABLE WRITEONEONLY |
| 93 |
+ |
virtual unsigned int Flags() |
| 94 |
+ |
{ |
| 95 |
+ |
return NOTREADABLE | WRITEONEONLY; |
| 96 |
+ |
}; |
| 97 |
+ |
|
| 98 |
+ |
//////////////////////////////////////////////////// |
| 99 |
+ |
/// The "API" interface functions |
| 100 |
+ |
virtual bool WriteMolecule(OBBase* pOb, OBConversion* pConv); |
| 101 |
|
|
| 102 |
+ |
//////////////////////////////////////////////////// |
| 103 |
+ |
/// The "Convert" interface functions |
| 104 |
+ |
virtual bool WriteChemObject(OBConversion* pConv) |
| 105 |
+ |
{ |
| 106 |
+ |
//Retrieve the target OBMol |
| 107 |
+ |
OBBase* pOb = pConv->GetChemObject(); |
| 108 |
+ |
OBMol* pmol = dynamic_cast<OBMol*> (pOb); |
| 109 |
+ |
bool ret=false; |
| 110 |
+ |
if(pmol) |
| 111 |
+ |
ret=WriteMolecule(pmol,pConv); |
| 112 |
|
|
| 113 |
+ |
std::string auditMsg = "OpenBabel::Write molecule "; |
| 114 |
+ |
std::string description(Description()); |
| 115 |
+ |
auditMsg += description.substr( 0, description.find('\n') ); |
| 116 |
+ |
obErrorLog.ThrowError(__func__, |
| 117 |
+ |
auditMsg, |
| 118 |
+ |
obAuditMsg); |
| 119 |
+ |
delete pOb; |
| 120 |
+ |
return ret; |
| 121 |
+ |
}; |
| 122 |
+ |
}; |
| 123 |
+ |
|
| 124 |
+ |
//Make an instance of the format class |
| 125 |
+ |
PovrayFormat thePovrayFormat; |
| 126 |
+ |
|
| 127 |
|
/* ---- Make a prefix from title of molecule ---- */ |
| 128 |
|
string MakePrefix(const char* title) |
| 129 |
|
{ |