diff options
author | Manoj Rajagopalan <manoj@nanorex.com> | 2008-04-06 06:05:51 +0000 |
---|---|---|
committer | Manoj Rajagopalan <manoj@nanorex.com> | 2008-04-06 06:05:51 +0000 |
commit | 781bda9ed3e84c5c01a144e8c06457059a8a72af (patch) | |
tree | 3d0ac0a4e7f716c7f418702440fac78976feb86e /cad/plugins/NanoVision-1/src/Plugins | |
parent | 34232fe3983323d04575984bc9ff270be50b978d (diff) | |
download | nanoengineer-781bda9ed3e84c5c01a144e8c06457059a8a72af.tar.gz nanoengineer-781bda9ed3e84c5c01a144e8c06457059a8a72af.zip |
Fixed mol->scenegraph conversion bug and closed a host of other bugs that were artifacts of this one.
Diffstat (limited to 'cad/plugins/NanoVision-1/src/Plugins')
9 files changed, 482 insertions, 221 deletions
diff --git a/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/MMPOpenGLRendererTest.cpp b/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/MMPOpenGLRendererTest.cpp index ce966d12c..86dd1756c 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/MMPOpenGLRendererTest.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/MMPOpenGLRendererTest.cpp @@ -19,27 +19,39 @@ int main(int argc, char *argv[]) // create application and main window QApplication app(argc, argv); QMainWindow mainWindow; + mainWindow.resize(640, 400); + NXOpenGLRenderingEngine *renderingEngine = new NXOpenGLRenderingEngine(&mainWindow); + mainWindow.setCentralWidget(renderingEngine); + mainWindow.show(); + NXBallAndStickOpenGLRenderer *renderer = new NXBallAndStickOpenGLRenderer(renderingEngine); renderingEngine->setRenderer("bas", renderer); renderingEngine->setRenderer("def", renderer); renderingEngine->initializePlugins(); - mainWindow.show(); - basRenderData.setRenderStyleCode("bas"); NXMoleculeSet theMoleculeSet; NXDataStoreInfo dataStoreInfo; NanorexMMPImportExport importer; NXCommandResult const *result = importer.importFromFile(&theMoleculeSet, &dataStoreInfo, - "../src/Testing/MMP_TestFiles/benzene.mmp", 0,0); - assert(result->getResult() == (int) NX_CMD_SUCCESS); + "../src/Testing/MMP_TestFiles/chlorophyll.mmp", 0,0); + if(result->getResult() != (int) NX_CMD_SUCCESS) { + vector<QString> const params = result->getParamVector(); + cerr << "Error: "; + vector<QString>::const_iterator paramIter; + for(paramIter = params.begin(); paramIter != params.end(); ++paramIter) { + cerr << ' ' << qPrintable(*paramIter); + } + cerr << endl; + return 1; + } - renderingEngine->clearFrames(); + // renderingEngine->clearFrames(); assert(renderingEngine->getFrameCount() == 0); result = renderingEngine->addFrame(&theMoleculeSet); assert(result->getResult() == (int) NX_CMD_SUCCESS); diff --git a/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.cpp b/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.cpp index c372ad896..e603759f4 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.cpp @@ -1,4 +1,4 @@ -#line 1 "NanorexMMPImportExport.rl" +/* #line 1 "NanorexMMPImportExport.rl" */ // *********************** GENERATED BY RAGEL 6.0 ******************* // ** Do not edit directly. Edit NanorexMMPImportExport.rl instead ** // ****************************************************************** @@ -41,15 +41,15 @@ inline void DEBUG_MSG(string const& filename, int line, string const& s) -#line 102 "NanorexMMPImportExport.rl" +/* #line 102 "NanorexMMPImportExport.rl" */ -#line 106 "NanorexMMPImportExport.rl" +/* #line 106 "NanorexMMPImportExport.rl" */ // static data from Ragel -#line 53 "NanorexMMPImportExport.cpp" +/* #line 53 "NanorexMMPImportExport.cpp" */ static const char _mmp_parser_actions[] = { 0, 1, 0, 1, 1, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, @@ -905,7 +905,7 @@ static const int mmp_parser_error = 0; static const int mmp_parser_en_group_scanner = 294; static const int mmp_parser_en_main = 1; -#line 110 "NanorexMMPImportExport.rl" +/* #line 110 "NanorexMMPImportExport.rl" */ // static data from class NanorexMMPImportExport @@ -924,6 +924,27 @@ char const NanorexMMPImportExport::_s_hybridizationName[8][8] = { "none", "sp", "sp2", "sp3", "X-hyb4", "X-hyb5", "X-hyb6", "X-hyb7" }; +/*static*/ +void NanorexMMPImportExport::SetResult(NXCommandResult& commandResult, + int errCode, + string const& errMsg) +{ + commandResult.setResult(errCode); + vector<QString> message; + message.push_back(QObject::tr(errMsg.c_str())); + commandResult.setParamVector(message); +} + +// ............................................................................. + +/* static */ +void NanorexMMPImportExport::ClearResult(NXCommandResult& commandResult) +{ + commandResult.setResult((int) NX_CMD_SUCCESS); + vector<QString> message; + commandResult.setParamVector(message); +} + /* CONSTRUCTOR */ NanorexMMPImportExport::NanorexMMPImportExport() @@ -968,7 +989,7 @@ void NanorexMMPImportExport::reset(void) // initialize the ragel engine -#line 972 "NanorexMMPImportExport.cpp" +/* #line 993 "NanorexMMPImportExport.cpp" */ { cs = mmp_parser_start; top = 0; @@ -976,7 +997,7 @@ void NanorexMMPImportExport::reset(void) te = 0; act = 0; } -#line 172 "NanorexMMPImportExport.rl" +/* #line 193 "NanorexMMPImportExport.rl" */ } @@ -991,12 +1012,11 @@ importFromFile(NXMoleculeSet *rootMoleculeSetPtr, reset(); bool success = true; - NXCommandResult *result = new NXCommandResult(); - result->setResult(NX_CMD_SUCCESS); + ClearResult(commandResult); ifstream mmpfile(theFilename.c_str(), ios::in); if(!mmpfile) { - populateCommandResult(result, + populateCommandResult(&commandResult, (string("Couldn't open file: ") + theFilename) .c_str()); success = false; @@ -1012,7 +1032,7 @@ importFromFile(NXMoleculeSet *rootMoleculeSetPtr, dataStoreInfo->setIsSingleStructure(true); } - return result; + return &commandResult; } @@ -1033,7 +1053,7 @@ bool NanorexMMPImportExport::readMMP(istream& instream, // Ragel parser implementation bool success = true; -#line 1037 "NanorexMMPImportExport.cpp" +/* #line 1057 "NanorexMMPImportExport.cpp" */ { int _klen; unsigned int _trans; @@ -1051,10 +1071,10 @@ _resume: while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 43: -#line 1 "NanorexMMPImportExport.rl" +/* #line 1 "NanorexMMPImportExport.rl" */ {ts = p;} break; -#line 1058 "NanorexMMPImportExport.cpp" +/* #line 1078 "NanorexMMPImportExport.cpp" */ } } @@ -1121,89 +1141,89 @@ _eof_trans: switch ( *_acts++ ) { case 0: -#line 24 "NanorexMMPImportExport.rl" +/* #line 24 "NanorexMMPImportExport.rl" */ {++lineNum;} break; case 2: -#line 41 "NanorexMMPImportExport.rl" +/* #line 41 "NanorexMMPImportExport.rl" */ {intVal = intVal*10 + ((*p)-'0');} break; case 4: -#line 46 "NanorexMMPImportExport.rl" +/* #line 46 "NanorexMMPImportExport.rl" */ {intVal2 = intVal2*10 + ((*p)-'0');} break; case 5: -#line 49 "NanorexMMPImportExport.rl" +/* #line 49 "NanorexMMPImportExport.rl" */ {intVal=-intVal;} break; case 6: -#line 73 "NanorexMMPImportExport.rl" +/* #line 73 "NanorexMMPImportExport.rl" */ { charStringWithSpaceStart = p-1; } break; case 7: -#line 74 "NanorexMMPImportExport.rl" +/* #line 74 "NanorexMMPImportExport.rl" */ { charStringWithSpaceStop = p; } break; case 8: -#line 83 "NanorexMMPImportExport.rl" +/* #line 83 "NanorexMMPImportExport.rl" */ { stringVal.resize(charStringWithSpaceStop - charStringWithSpaceStart + 1); std::copy(charStringWithSpaceStart, charStringWithSpaceStop+1, stringVal.begin()); } break; case 9: -#line 94 "NanorexMMPImportExport.rl" +/* #line 94 "NanorexMMPImportExport.rl" */ { stringVal2.resize(charStringWithSpaceStop - charStringWithSpaceStart + 1); std::copy(charStringWithSpaceStart, charStringWithSpaceStop+1, stringVal2.begin()); } break; case 10: -#line 29 "NanorexMMPImportExport.rl" +/* #line 29 "NanorexMMPImportExport.rl" */ { atomId = intVal; /*cerr << "atomId = " << atomId << endl;*/ } break; case 11: -#line 34 "NanorexMMPImportExport.rl" +/* #line 34 "NanorexMMPImportExport.rl" */ { atomicNum = intVal; /*cerr << "atomId = " << atomId << endl;*/} break; case 12: -#line 37 "NanorexMMPImportExport.rl" +/* #line 37 "NanorexMMPImportExport.rl" */ {x = intVal; } break; case 13: -#line 38 "NanorexMMPImportExport.rl" +/* #line 38 "NanorexMMPImportExport.rl" */ {y = intVal; } break; case 14: -#line 39 "NanorexMMPImportExport.rl" +/* #line 39 "NanorexMMPImportExport.rl" */ {z = intVal; } break; case 15: -#line 50 "NanorexMMPImportExport.rl" +/* #line 50 "NanorexMMPImportExport.rl" */ { atomStyle = stringVal; /*cerr << "atom_style = " << stringVal << endl;*/ } break; case 16: -#line 67 "NanorexMMPImportExport.rl" +/* #line 67 "NanorexMMPImportExport.rl" */ { newAtom(atomId, atomicNum, x, y, z, atomStyle); } break; case 17: -#line 71 "NanorexMMPImportExport.rl" +/* #line 71 "NanorexMMPImportExport.rl" */ { newBond(stringVal, intVal); } break; case 18: -#line 77 "NanorexMMPImportExport.rl" +/* #line 77 "NanorexMMPImportExport.rl" */ { stringVal = *p; } break; case 19: -#line 87 "NanorexMMPImportExport.rl" +/* #line 87 "NanorexMMPImportExport.rl" */ { newBondDirection(intVal, intVal2); } break; case 20: -#line 102 "NanorexMMPImportExport.rl" +/* #line 102 "NanorexMMPImportExport.rl" */ { // stripTrailingWhiteSpaces(stringVal); // stripTrailingWhiteSpaces(stringVal2); @@ -1211,11 +1231,11 @@ _eof_trans: } break; case 21: -#line 9 "NanorexMMPImportExport.rl" +/* #line 9 "NanorexMMPImportExport.rl" */ {lineStart=p;} break; case 23: -#line 16 "NanorexMMPImportExport.rl" +/* #line 16 "NanorexMMPImportExport.rl" */ { if(stringVal2 == "") stringVal2 = "def"; @@ -1223,63 +1243,63 @@ _eof_trans: } break; case 24: -#line 24 "NanorexMMPImportExport.rl" +/* #line 24 "NanorexMMPImportExport.rl" */ {lineStart=p;} break; case 25: -#line 35 "NanorexMMPImportExport.rl" +/* #line 35 "NanorexMMPImportExport.rl" */ { newChunkInfo(stringVal, stringVal2); } break; case 26: -#line 26 "NanorexMMPImportExport.rl" +/* #line 26 "NanorexMMPImportExport.rl" */ { lineStart = p; } break; case 27: -#line 29 "NanorexMMPImportExport.rl" +/* #line 29 "NanorexMMPImportExport.rl" */ { newViewDataGroup(); } break; case 28: -#line 40 "NanorexMMPImportExport.rl" +/* #line 40 "NanorexMMPImportExport.rl" */ { newMolStructGroup(stringVal/*, stringVal2*/); } break; case 29: -#line 47 "NanorexMMPImportExport.rl" +/* #line 47 "NanorexMMPImportExport.rl" */ { end1(); } break; case 30: -#line 51 "NanorexMMPImportExport.rl" +/* #line 51 "NanorexMMPImportExport.rl" */ { lineStart = p; } break; case 31: -#line 56 "NanorexMMPImportExport.rl" +/* #line 56 "NanorexMMPImportExport.rl" */ { newClipboardGroup(); } break; case 32: -#line 60 "NanorexMMPImportExport.rl" +/* #line 60 "NanorexMMPImportExport.rl" */ {lineStart=p;} break; case 33: -#line 61 "NanorexMMPImportExport.rl" +/* #line 61 "NanorexMMPImportExport.rl" */ { stringVal.clear(); } break; case 34: -#line 67 "NanorexMMPImportExport.rl" +/* #line 67 "NanorexMMPImportExport.rl" */ { endGroup(stringVal); } break; case 35: -#line 71 "NanorexMMPImportExport.rl" +/* #line 71 "NanorexMMPImportExport.rl" */ {lineStart=p;} break; case 36: -#line 81 "NanorexMMPImportExport.rl" +/* #line 81 "NanorexMMPImportExport.rl" */ { newOpenGroupInfo(stringVal, stringVal2); } break; case 37: -#line 65 "NanorexMMPImportExport.rl" +/* #line 65 "NanorexMMPImportExport.rl" */ { kelvinTemp = intVal; } break; case 38: -#line 79 "NanorexMMPImportExport.rl" +/* #line 79 "NanorexMMPImportExport.rl" */ { p--; { if(top == stackSize) { stackSize += stackSize; @@ -1289,7 +1309,7 @@ _eof_trans: {stack[top++] = cs; cs = 294; goto _again;}} } break; case 39: -#line 82 "NanorexMMPImportExport.rl" +/* #line 82 "NanorexMMPImportExport.rl" */ { p--; { if(top == stackSize) { stackSize += stackSize; @@ -1299,7 +1319,7 @@ _eof_trans: {stack[top++] = cs; cs = 294; goto _again;}} } break; case 40: -#line 87 "NanorexMMPImportExport.rl" +/* #line 87 "NanorexMMPImportExport.rl" */ { p--; { if(top == stackSize) { stackSize += stackSize; @@ -1309,69 +1329,69 @@ _eof_trans: {stack[top++] = cs; cs = 294; goto _again;}} } break; case 44: -#line 1 "NanorexMMPImportExport.rl" +/* #line 1 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 45: -#line 102 "NanorexMMPImportExport.rl" +/* #line 102 "NanorexMMPImportExport.rl" */ {act = 11;} break; case 46: -#line 89 "NanorexMMPImportExport.rl" +/* #line 89 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 47: -#line 90 "NanorexMMPImportExport.rl" +/* #line 90 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 48: -#line 91 "NanorexMMPImportExport.rl" +/* #line 91 "NanorexMMPImportExport.rl" */ {te = p+1;{{cs = stack[--top]; goto _again;}}} break; case 49: -#line 92 "NanorexMMPImportExport.rl" +/* #line 92 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 50: -#line 93 "NanorexMMPImportExport.rl" +/* #line 93 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 51: -#line 94 "NanorexMMPImportExport.rl" +/* #line 94 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 52: -#line 95 "NanorexMMPImportExport.rl" +/* #line 95 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 53: -#line 96 "NanorexMMPImportExport.rl" +/* #line 96 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 54: -#line 97 "NanorexMMPImportExport.rl" +/* #line 97 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 55: -#line 100 "NanorexMMPImportExport.rl" +/* #line 100 "NanorexMMPImportExport.rl" */ {te = p+1;} break; case 56: -#line 102 "NanorexMMPImportExport.rl" +/* #line 102 "NanorexMMPImportExport.rl" */ {te = p+1;{ cerr << lineNum << ": Syntax error or unsupported statement:\n\t"; std::copy(ts, te, std::ostream_iterator<char>(cerr)); cerr << endl; }} break; case 57: -#line 102 "NanorexMMPImportExport.rl" +/* #line 102 "NanorexMMPImportExport.rl" */ {te = p;p--;{ cerr << lineNum << ": Syntax error or unsupported statement:\n\t"; std::copy(ts, te, std::ostream_iterator<char>(cerr)); cerr << endl; }} break; case 58: -#line 1 "NanorexMMPImportExport.rl" +/* #line 1 "NanorexMMPImportExport.rl" */ { switch( act ) { case 0: {{cs = 0; goto _again;}} @@ -1386,7 +1406,7 @@ _eof_trans: } } break; -#line 1390 "NanorexMMPImportExport.cpp" +/* #line 1410 "NanorexMMPImportExport.cpp" */ } } @@ -1396,26 +1416,26 @@ _again: while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 1: -#line 40 "NanorexMMPImportExport.rl" +/* #line 40 "NanorexMMPImportExport.rl" */ {intVal=(*p)-'0';} break; case 3: -#line 45 "NanorexMMPImportExport.rl" +/* #line 45 "NanorexMMPImportExport.rl" */ {intVal2=(*p)-'0';} break; case 22: -#line 11 "NanorexMMPImportExport.rl" +/* #line 11 "NanorexMMPImportExport.rl" */ { stringVal2.clear(); /* 'style' string optional */ } break; case 41: -#line 1 "NanorexMMPImportExport.rl" +/* #line 1 "NanorexMMPImportExport.rl" */ {ts = 0;} break; case 42: -#line 1 "NanorexMMPImportExport.rl" +/* #line 1 "NanorexMMPImportExport.rl" */ {act = 0;} break; -#line 1419 "NanorexMMPImportExport.cpp" +/* #line 1439 "NanorexMMPImportExport.cpp" */ } } @@ -1434,7 +1454,7 @@ _again: _out: {} } -#line 228 "NanorexMMPImportExport.rl" +/* #line 248 "NanorexMMPImportExport.rl" */ // End-of-parsing sanity checks if(molSetPtrStack.size() != 0) { diff --git a/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.h b/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.h index f79bbe033..e1395c167 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.h +++ b/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.h @@ -105,6 +105,8 @@ private: RagelIstreamPtr charStringWithSpaceStart, charStringWithSpaceStop; RagelIstreamPtr lineStart; + NXCommandResult commandResult; + // helper functions void reset(void); @@ -153,6 +155,11 @@ private: static void populateCommandResult(NXCommandResult* result, const string& message); + + static void SetResult(NXCommandResult& cmdResult, + int errCode, std::string const& errMsg); + static void ClearResult(NXCommandResult& cmdResult); + friend class NanorexMMPImportExportTest; diff --git a/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.rl b/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.rl index be03cff1f..849467f83 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.rl +++ b/cad/plugins/NanoVision-1/src/Plugins/NanorexMMPImportExport/NanorexMMPImportExport.rl @@ -125,6 +125,27 @@ char const NanorexMMPImportExport::_s_hybridizationName[8][8] = { "none", "sp", "sp2", "sp3", "X-hyb4", "X-hyb5", "X-hyb6", "X-hyb7" }; +/*static*/ +void NanorexMMPImportExport::SetResult(NXCommandResult& commandResult, + int errCode, + string const& errMsg) +{ + commandResult.setResult(errCode); + vector<QString> message; + message.push_back(QObject::tr(errMsg.c_str())); + commandResult.setParamVector(message); +} + +// ............................................................................. + +/* static */ +void NanorexMMPImportExport::ClearResult(NXCommandResult& commandResult) +{ + commandResult.setResult((int) NX_CMD_SUCCESS); + vector<QString> message; + commandResult.setParamVector(message); +} + /* CONSTRUCTOR */ NanorexMMPImportExport::NanorexMMPImportExport() @@ -183,12 +204,11 @@ importFromFile(NXMoleculeSet *rootMoleculeSetPtr, reset(); bool success = true; - NXCommandResult *result = new NXCommandResult(); - result->setResult(NX_CMD_SUCCESS); + ClearResult(commandResult); ifstream mmpfile(theFilename.c_str(), ios::in); if(!mmpfile) { - populateCommandResult(result, + populateCommandResult(&commandResult, (string("Couldn't open file: ") + theFilename) .c_str()); success = false; @@ -204,7 +224,7 @@ importFromFile(NXMoleculeSet *rootMoleculeSetPtr, dataStoreInfo->setIsSingleStructure(true); } - return result; + return &commandResult; } diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.cpp index f83641254..45d60ceed 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.cpp @@ -14,6 +14,13 @@ using namespace std; using namespace OpenBabel; +#ifdef NX_DEBUG +#define NX_DEBUG_FAIL assert(0) +#else +#define NX_DEBUG_FAIL +#endif + + NXOpenGLRenderingEngine::NXOpenGLRenderingEngine(QWidget *parent) : QGLWidget(parent), NXRenderingEngine(), camera(this) { @@ -355,6 +362,8 @@ NXOpenGLRenderingEngine::createSceneGraph (NXMoleculeSet *const molSetPtr) return NULL; } + renderedAtoms.clear(); + renderedBonds.clear(); NXSGOpenGLNode *node = createOpenGLSceneGraph(molSetPtr); return static_cast<NXSGNode*>(node); } @@ -365,7 +374,7 @@ NXSGNode* createSceneGraph (OpenBabel::OBMol *const molPtr) { // Do nothing if no rendering plugins if(!pluginsInitialized) { SetResult(commandResult, NX_INTERNAL_ERROR, - "Rendering plugin not set/initialized"); +"Rendering plugin not set/initialized"); return NULL; } ClearResult(commandResult); @@ -402,10 +411,13 @@ NXOpenGLRenderingEngine::createOpenGLSceneGraph(NXMoleculeSet *const molSetPtr) commandResult.getResult() == (int) NX_CMD_SUCCESS) { bool childAdded = moleculeSetNode->addChild(molNode); - if(!childAdded) + if(!childAdded) { + NX_DEBUG_FAIL; return moleculeSetNode; + } } else { + NX_DEBUG_FAIL; return moleculeSetNode; } /// @todo POST-FNANO: delete molNode upon failures? @@ -421,10 +433,13 @@ NXOpenGLRenderingEngine::createOpenGLSceneGraph(NXMoleculeSet *const molSetPtr) commandResult.getResult() == (int) NX_CMD_SUCCESS) { bool childAdded = moleculeSetNode->addChild(childMoleculeSetNode); - if(!childAdded) + if(!childAdded) { + NX_DEBUG_FAIL; return moleculeSetNode; + } } else { + NX_DEBUG_FAIL; return moleculeSetNode; } /// @todo POST-FNANO: delete childMoleculeSetNode upon failures? @@ -433,23 +448,35 @@ NXOpenGLRenderingEngine::createOpenGLSceneGraph(NXMoleculeSet *const molSetPtr) } -NXSGOpenGLNode* NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const molPtr) +NXSGOpenGLNode* +NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const molPtr) { assert(!molPtr->Empty()); Vector const canonicalZAxis(0.0, 0.0, 1.0); - set<OBAtom*> renderedAtoms; // tracks atoms already rendered OBAtomIterator atomIter; - // first atom + // Find first atom that is not already rendered + // Necessary because bonds can bridge molecules and molecule-sets and in + // the case of the second to last molecules rendered, their first atoms + // may have been rendered while traversing the previous molecules. + OBAtom *firstAtomPtr = molPtr->BeginAtom(atomIter); + if(firstAtomPtr == (OBAtom*) NULL) { string const source("Molecule scenegraph creation"); string const msg("empty molecule slipped past check"); - SetResult(commandResult, NX_INTERNAL_ERROR, source+" - "+msg); + SetResult(commandResult, NX_INTERNAL_ERROR, source + " - " + msg); + NX_DEBUG_FAIL; return (NXSGOpenGLNode*) NULL; } + while(firstAtomPtr != (OBAtom*) NULL && isRendered(firstAtomPtr)) + firstAtomPtr = molPtr->NextAtom(atomIter); + + if(firstAtomPtr == (OBAtom*) NULL) + return new NXSGOpenGLNode; + Vector const firstAtomPosition(firstAtomPtr->GetX(), firstAtomPtr->GetY(), firstAtomPtr->GetZ()); @@ -468,12 +495,12 @@ NXSGOpenGLNode* NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const mol SetResult(commandResult, NX_INTERNAL_ERROR, "Error translating to first atom position"); + NX_DEBUG_FAIL; return NULL; } NXSGOpenGLNode *firstAtomNode = - createOpenGLSceneGraph(molPtr, firstAtomPtr, - renderedAtoms, canonicalZAxis); + createOpenGLSceneGraph(molPtr, firstAtomPtr, canonicalZAxis); if(firstAtomNode != NULL && commandResult.getResult() == (int) NX_CMD_SUCCESS) { @@ -482,10 +509,12 @@ NXSGOpenGLNode* NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const mol if(!childAdded) { SetResult(commandResult, NX_INTERNAL_ERROR, "Error adding child to first atom node"); + NX_DEBUG_FAIL; return rootMoleculeNode; } } else { + NX_DEBUG_FAIL; // either scenegraph could not be created or was created partially // commandResult should hold the error return rootMoleculeNode; @@ -494,68 +523,117 @@ NXSGOpenGLNode* NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const mol // rest of the atoms OBAtom *atomPtr = molPtr->NextAtom(atomIter); - while(atomPtr != (OBAtom*) NULL) { - set<OBAtom*>::iterator memberIter = renderedAtoms.find(atomPtr); - if(memberIter == renderedAtoms.end()) { // atom not already rendered - Vector const atomPosition(atomPtr->GetX(), - atomPtr->GetY(), - atomPtr->GetZ()); - Vector const atomRelativePosition = - (atomPosition - firstAtomPosition); + for(; atomPtr != (OBAtom*) NULL; + atomPtr = molPtr->NextAtom(atomIter)) + { + if(isRendered(atomPtr)) // atom already rendered + continue; + + Vector const atomPosition(atomPtr->GetX(), + atomPtr->GetY(), + atomPtr->GetZ()); + Vector const atomRelativePosition = + (atomPosition - firstAtomPosition); // move scenegraph "cursor" to this atom - NXSGOpenGLTranslate *translateToAtomNode = NULL; - try { - translateToAtomNode = - new NXSGOpenGLTranslate(atomRelativePosition.x(), - atomRelativePosition.y(), - atomRelativePosition.z()); - } - catch(...) { - if(translateToAtomNode != NULL) - delete translateToAtomNode; - SetResult(commandResult, NX_INTERNAL_ERROR, - "Error translating to atom"); - return rootMoleculeNode; - } - - bool childAdded = rootMoleculeNode->addChild(translateToAtomNode); - if(!childAdded) { - SetResult(commandResult, NX_INTERNAL_ERROR, - "Error adding translate-to-atom node to molecule root"); - return rootMoleculeNode; - } + NXSGOpenGLTranslate *translateToAtomNode = NULL; + try { + translateToAtomNode = + new NXSGOpenGLTranslate(atomRelativePosition.x(), + atomRelativePosition.y(), + atomRelativePosition.z()); + } + catch(...) { + if(translateToAtomNode != NULL) + delete translateToAtomNode; + SetResult(commandResult, NX_INTERNAL_ERROR, + "Error translating to atom"); + NX_DEBUG_FAIL; + return rootMoleculeNode; + } + + bool childAdded = rootMoleculeNode->addChild(translateToAtomNode); + if(!childAdded) { + SetResult(commandResult, NX_INTERNAL_ERROR, + "Error adding translate-to-atom node to molecule root"); + NX_DEBUG_FAIL; + return rootMoleculeNode; + } /// @todo POST-FNANO delete translateToAtomNode upon failure? - + // render subscenegraph rooted at this atom - NXSGOpenGLNode *atomNode = - createOpenGLSceneGraph(molPtr, atomPtr, - renderedAtoms, canonicalZAxis); - if(atomNode != NULL && - commandResult.getResult() == (int) NX_CMD_SUCCESS) - { - bool childAdded = translateToAtomNode->addChild(atomNode); - if(!childAdded) { - SetResult(commandResult, NX_INTERNAL_ERROR, - "Error submolecule scenegraph as child of " - "translation"); - return rootMoleculeNode; - } - } - else { + NXSGOpenGLNode *atomNode = + createOpenGLSceneGraph(molPtr, atomPtr, canonicalZAxis); + + if(atomNode != NULL && + commandResult.getResult() == (int) NX_CMD_SUCCESS) + { + bool childAdded = translateToAtomNode->addChild(atomNode); + if(!childAdded) { + SetResult(commandResult, NX_INTERNAL_ERROR, + "Error submolecule scenegraph as child of " + "translation"); + NX_DEBUG_FAIL; return rootMoleculeNode; } - /// @todo POST-FNANO delete atomNode upon failures? } - atomPtr = molPtr->NextAtom(atomIter); - } + else { + NX_DEBUG_FAIL; + return rootMoleculeNode; + } + /// @todo POST-FNANO delete atomNode upon failures? + } // loop over atoms + return rootMoleculeNode; } NXSGOpenGLNode* +NXOpenGLRenderingEngine::getRotationNode(Vector const& zAxis, + Vector const& newZAxis) +{ + double const dotProduct = zAxis * newZAxis; + + if(dotProduct < 0.99999) { + // Angle between both vectors is more than 0.25 degrees + // therefore there is a well-defined rotation + real const rotationAngleDeg = + acos(dotProduct) * 180.0 / M_PI; + + Vector rotationAxis = xProduct(zAxis, newZAxis); + rotationAxis.normalize(); + + NXSGOpenGLRotate *rotateZAxisNode = NULL; + try { + rotateZAxisNode = + new NXSGOpenGLRotate(rotationAngleDeg, + rotationAxis.x(), + rotationAxis.y(), + rotationAxis.z()); + } + catch(...) { + SetResult(commandResult, NX_INTERNAL_ERROR, + "Error creating axis rotation scenegraph node"); + NX_DEBUG_FAIL; + return NULL; + } + + return rotateZAxisNode; + } + else { + // length of cross-product is below 1% + // therefore the two z-axes are parallel to within numerical error + // bypass creation of rotation scenegraph node + return NULL; + + } + +} + +/// Render given atom in the molecule in a depth-first manner +/// Update the rendered-atoms set to include this atom if successful +NXSGOpenGLNode* NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const molPtr, OBAtom *const atomPtr, - set<OBAtom*>& renderedAtoms, Vector const& zAxis) { // Precondition: *atomPtr shouldn't have been rendered @@ -565,6 +643,7 @@ NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const molPtr, if(!pluginsInitialized) { SetResult(commandResult, NX_INTERNAL_ERROR, "Rendering plugin not set/initialized"); + NX_DEBUG_FAIL; return NULL; } @@ -602,9 +681,13 @@ NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const molPtr, assert(atomData != NULL); string const& atomRenderStyleCode = atomData->getRenderStyleCode(); atomData->addSupplementalData(static_cast<void const*>(&defaultAtomMaterial)); + /// @todo consider if supplemental data can be added repeatedly and the + /// corresponding vector grows needlessly + // The following dynamic_cast is ok because plugins were type-checked at // initialization time + /// @fixme Use qobject_cast instead of static_cast? dynamic_cast won't work NXOpenGLRendererPlugin *renderer = static_cast<NXOpenGLRendererPlugin*>(renderStyleMap[atomRenderStyleCode]); if(renderer == (NXOpenGLRendererPlugin*) NULL) { @@ -613,11 +696,13 @@ NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const molPtr, "No renderer-plugin found for rendering-style-code '" + atomRenderStyleCode + "'"); /// @todo POST-FNANO more descriptive error message - which atom# and moleculeSet + NX_DEBUG_FAIL; return (NXSGOpenGLNode*) NULL; } NXSGOpenGLNode *const atomNode = renderer->renderAtom(*atomData); if(atomNode == NULL) { commandResult = renderer->getCommandResult(); + NX_DEBUG_FAIL; return NULL; } renderedAtoms.insert(atomPtr); // mark as rendered @@ -628,101 +713,147 @@ NXOpenGLRenderingEngine::createOpenGLSceneGraph(OBMol *const molPtr, for(bondPtr = atomPtr->BeginBond(bondIter); bondPtr != NULL; bondPtr = atomPtr->NextBond(bondIter)) + { - // compute bond orientation OBAtom *const nbrAtomPtr = bondPtr->GetNbrAtom(atomPtr); + assert(nbrAtomPtr != atomPtr); Vector const nbrAtomPosition(nbrAtomPtr->GetX(), nbrAtomPtr->GetY(), nbrAtomPtr->GetZ()); - Vector newZAxis = (nbrAtomPosition - atomPosition); + Vector const nbrAtomRelativePosition = (nbrAtomPosition - atomPosition); + Vector newZAxis = nbrAtomRelativePosition; newZAxis.normalize(); - Vector const rotationAxis = xProduct(zAxis, newZAxis); - real const rotationAngleDeg = acos(newZAxis * zAxis) * 180.0 / M_PI; - // align z-axis with bond - NXSGOpenGLRotate *rotateZAxisNode = NULL; - try { - rotateZAxisNode = - new NXSGOpenGLRotate(rotationAngleDeg, - rotationAxis.x(), - rotationAxis.y(), - rotationAxis.z()); - } - catch(...) { - SetResult(commandResult, NX_INTERNAL_ERROR, - "Error creating axis rotation scenegraph node"); - return atomNode; - } + if(!isRendered(bondPtr)) { + // compute bond orientation + + // Rotate z-axis to align with bond-direction if necessary + NXSGOpenGLNode *rotateZAxisNode = getRotationNode(zAxis,newZAxis); + if(rotateZAxisNode == NULL) + rotateZAxisNode = atomNode; + + else { + bool childAdded = atomNode->addChild(rotateZAxisNode); + if(!childAdded) { + SetResult(commandResult, NX_INTERNAL_ERROR, + "Error adding rotation node as child to atom node"); + NX_DEBUG_FAIL; + return atomNode; + } + } + + void const *const defBondMatPtr = + static_cast<void const*>(&defaultBondMaterial); + NXBondData bondRenderData((BondType)bondPtr->GetBondOrder(), + bondPtr->GetLength()); + bondRenderData.addSupplementalData(defBondMatPtr); + NXSGOpenGLNode *const bondNode = renderer->renderBond(bondRenderData); + if(bondNode == NULL) { + commandResult = renderer->getCommandResult(); + NX_DEBUG_FAIL; + return atomNode; + } + bool const childAdded = rotateZAxisNode->addChild(bondNode); + if(!childAdded) { + SetResult(commandResult, NX_INTERNAL_ERROR, + "Error adding bond node to z-axis rotation node"); + NX_DEBUG_FAIL; + return atomNode; + } + + markBondRendered(bondPtr); + + } // if bond not already rendered - bool childAdded = atomNode->addChild(rotateZAxisNode); - if(!childAdded) { - SetResult(commandResult, NX_INTERNAL_ERROR, - "Error adding rotation node as child to atom node"); - return atomNode; - } - void const *const defBondMatPtr = - static_cast<void const*>(&defaultBondMaterial); - NXBondData bondRenderData((BondType)bondPtr->GetBondOrder(), - bondPtr->GetLength()); - bondRenderData.addSupplementalData(defBondMatPtr); - NXSGOpenGLNode *const bondNode = renderer->renderBond(bondRenderData); - if(bondNode == NULL) { - commandResult = renderer->getCommandResult(); - return atomNode; - } - childAdded = rotateZAxisNode->addChild(bondNode); - if(!childAdded) { - SetResult(commandResult, NX_INTERNAL_ERROR, - "Error adding bond node to z-axis rotation node"); - return atomNode; - } - // render neighbouring atom not already done, render submolecule - set<OBAtom*>::iterator memberIter = renderedAtoms.find(nbrAtomPtr); - if(memberIter == renderedAtoms.end()) { + if(!isRendered(nbrAtomPtr)) { // translate to neighbouring atom center - double const bondLength = bondPtr->GetLength(); + // double const bondLength = bondPtr->GetLength(); NXSGOpenGLTranslate *translateToNbrAtomNode = NULL; try { translateToNbrAtomNode = - new NXSGOpenGLTranslate(0.0, 0.0, bondLength); + new NXSGOpenGLTranslate(nbrAtomRelativePosition.x(), + nbrAtomRelativePosition.y(), + nbrAtomRelativePosition.z()); } catch(...) { SetResult(commandResult, NX_INTERNAL_ERROR, "Error creating trans-bond translation scenegraph node"); + NX_DEBUG_FAIL; return atomNode; } - childAdded = bondNode->addChild(translateToNbrAtomNode); + bool const childAdded = atomNode->addChild(translateToNbrAtomNode); if(!childAdded) { SetResult(commandResult, NX_INTERNAL_ERROR, - "Error adding trans-bond translation node as child of bond-node"); + "Error adding trans-bond translation node as child of" + " bond-node"); + NX_DEBUG_FAIL; return atomNode; } // create scenegraph rooted at neighbouring atom NXSGOpenGLNode *nbrAtomNode = - createOpenGLSceneGraph(molPtr, nbrAtomPtr, - renderedAtoms, atomPosition); + createOpenGLSceneGraph(molPtr, nbrAtomPtr, /*newZAxis*/ Vector(0.0, 0.0, 1.0)); if(nbrAtomNode == NULL) { + NX_DEBUG_FAIL; return atomNode; } else { - childAdded = translateToNbrAtomNode->addChild(nbrAtomNode); + bool const childAdded = + translateToNbrAtomNode->addChild(nbrAtomNode); if(!childAdded) { SetResult(commandResult, NX_INTERNAL_ERROR, "Error adding neighboring-atom scenegraph subtree" " as child of trans-bond translation node"); + NX_DEBUG_FAIL; return atomNode; } } - } + } // if neighbouring atom not already rendered } return atomNode; } +void NXOpenGLRenderingEngine::markBondRendered(OBBond *const bondPtr) +{ + OBAtom *const atom1 = bondPtr->GetBeginAtom(); + OBAtom *const atom2 = bondPtr->GetEndAtom(); + + pair<OBAtom*,OBAtom*> atomPair = ( atom1 < atom2 ? + make_pair(atom1, atom2) : + make_pair(atom2, atom1) ); + renderedBonds.insert(atomPair); +} + + +bool NXOpenGLRenderingEngine::isRendered(OBAtom *const atomPtr) const +{ + set<OBAtom*>::const_iterator memberIter = renderedAtoms.find(atomPtr); + bool const result = (memberIter != renderedAtoms.end()); + return result; +} + + +bool NXOpenGLRenderingEngine::isRendered(OBBond *const bondPtr) const +{ + OBAtom *atom1 = bondPtr->GetBeginAtom(); + OBAtom *atom2 = bondPtr->GetEndAtom(); + + pair<OBAtom*,OBAtom*> atomPair = (atom1 < atom2 ? + make_pair(atom1, atom2) : + make_pair(atom2, atom1)); + + RenderedBondsTableType::const_iterator memberIter = + renderedBonds.find(atomPair); + + bool const result = (memberIter != renderedBonds.end()); + return result; +} + + void NXOpenGLRenderingEngine::resetView(void) { // create axis-aligned bounding box @@ -761,11 +892,15 @@ void NXOpenGLRenderingEngine::resetView(void) } makeCurrent(); - camera.gluLookAt(bboxCenter.x(), bboxCenter.y(), - bboxCenter.z()+6.0*circumSphereDia, - bboxCenter.x(), bboxCenter.y(), bboxCenter.z(), - 0.0, 1.0, 0.0); +// camera.gluLookAt(bboxCenter.x(), bboxCenter.y(), +// bboxCenter.z()+circumSphereDia, +// bboxCenter.x(), bboxCenter.y(), bboxCenter.z(), +// 0.0, 1.0, 0.0); // camera.gluPerspective(60.0, double(width())/double(height()), n, f); + + camera.gluLookAt(0.0, 0.0, circumSphereDia, + 0.0, 0.0, 0.0, + 0.0, 1.0, 0.0); camera.glOrtho(l, r, b, t, n, f); updateGL(); diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.h b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.h index 152cea4f4..b57ba5aa1 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.h +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngine.h @@ -6,6 +6,7 @@ #include <set> #include <list> #include <vector> +#include <functional> // #include <QtGui> #include <QtOpenGL> @@ -82,6 +83,15 @@ public: private: typedef unsigned int uint; + + template<typename T1, typename T2> + struct PairwiseLess : public binary_function<T1, T2, bool> { + bool operator () (pair<T1,T2> const& a, pair<T1,T2> const& b) const + { + return (a.first < b.first || + (a.first == b.first && a.second < b.second)); + } + }; NXOpenGLCamera camera; @@ -99,7 +109,16 @@ private: std::map<uint, Nanorex::NXRGBColor> elementColorMap; NXOpenGLMaterial defaultAtomMaterial; NXOpenGLMaterial defaultBondMaterial; - + + typedef set<OBAtom*> RenderedAtomsTableType; + RenderedAtomsTableType renderedAtoms; // tracks rendered atoms + + typedef + set<pair<OBAtom*,OBAtom*>, PairwiseLess<OBAtom*,OBAtom*> > + RenderedBondsTableType; + + RenderedBondsTableType renderedBonds; // tracks rendered bonds + NXSGOpenGLNode* createOpenGLSceneGraph(Nanorex::NXMoleculeSet *const molSetPtr); @@ -109,13 +128,19 @@ private: NXSGOpenGLNode* createOpenGLSceneGraph(OpenBabel::OBMol *const molPtr, OpenBabel::OBAtom *const atomPtr, - std::set<OpenBabel::OBAtom*>& renderedAtoms, Vector const& zAxis); + NXSGOpenGLNode* getRotationNode(Vector const& zAxis, + Vector const& newZAxis); + // Implement inherited pure-virtual methods Nanorex::NXSGNode* createSceneGraph (Nanorex::NXMoleculeSet *const molSetPtr); + bool isRendered(OBAtom *const atomPtr) const; + bool isRendered(OBBond *const bondPtr) const; + void markBondRendered(OBBond *const bondPtr); + // NXSGNode* createSceneGraph (OpenBabel::OBMol *const molPtr); // QGLWidget methods to be overriden diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngineTest.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngineTest.cpp index fe5249052..dfe69a8df 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngineTest.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLRenderingEngineTest.cpp @@ -24,12 +24,13 @@ void makeNH3(OBMol *molPtr); void makeC2H2(OBMol *molPtr); void makeC2H4(OBMol *molPtr); void makeC2H6(OBMol *molPtr); +void makeC6H6(OBMol *molPtr); void makeTheMoleculeSet(NXMoleculeSet& theMoleculeSet); void translateMolecule(OBMol *molPtr, vector3 const& delta); void setRenderStyleBAS(OBMol *molPtr); -double const SCALE = 1.0e-9; +double const SCALE = 1.0e-10; void bond(OBMol *molPtr, OBAtom *atom1Ptr, OBAtom *atom2Ptr, int bondOrder) { @@ -70,7 +71,7 @@ int main(int argc, char *argv[]) mainWindow.resize(1000, 600); mainWindow.show(); - renderingEngine->clearFrames(); + // renderingEngine->clearFrames(); renderingEngine->addFrame(&theMoleculeSet); renderingEngine->setCurrentFrame(0); int result = app.exec(); @@ -80,11 +81,15 @@ int main(int argc, char *argv[]) void makeTheMoleculeSet(NXMoleculeSet& theMoleculeSet) { - OBMol *SF6 = theMoleculeSet.newMolecule(); - makeSF6(SF6); + OBMol *C6H6 = theMoleculeSet.newMolecule(); + makeC6H6(C6H6); + setRenderStyleBAS(C6H6); + + OBMol *SF6 = theMoleculeSet.newMolecule(); + makeSF6(SF6); setRenderStyleBAS(SF6); - NXMoleculeSet *triatomics = new NXMoleculeSet; + NXMoleculeSet *triatomics = new NXMoleculeSet; theMoleculeSet.addChild(triatomics); OBMol *CO2 = triatomics->newMolecule(); @@ -124,7 +129,8 @@ void makeTheMoleculeSet(NXMoleculeSet& theMoleculeSet) translateMolecule(C2H2, vector3(SCALE*-3.0, SCALE*3.0, SCALE*-3.0)); setRenderStyleBAS(C2H2); - OBMol *C2H4 = hydrocarbons->newMolecule(); + OBMol *C2H4 = hydrocarbons->newMolecule(); + // OBMol *C2H4 = theMoleculeSet.newMolecule(); makeC2H4(C2H4); translateMolecule(C2H4, vector3(SCALE*-3.0, SCALE*-3.0, SCALE*3.0)); setRenderStyleBAS(C2H4); @@ -133,6 +139,7 @@ void makeTheMoleculeSet(NXMoleculeSet& theMoleculeSet) makeC2H6(C2H6); translateMolecule(C2H6, vector3(SCALE*-3.0, SCALE*-3.0, SCALE*-3.0)); setRenderStyleBAS(C2H6); + } @@ -167,6 +174,7 @@ void setRenderStyleBAS(OBMol *molPtr) void makeCH4(OBMol *molPtr) { + molPtr->SetTitle("CH4"); OBAtom *C = molPtr->NewAtom(); C->SetAtomicNum(6); C->SetVector(0.0, 0.0, 0.0); @@ -195,6 +203,7 @@ void makeCH4(OBMol *molPtr) void makeNH3(OBMol *molPtr) { + molPtr->SetTitle("NH3"); // double const SCALE = 5.0; double const THETA = 120.0 * M_PI/180.0; double sinTheta = 0.0, cosTheta = 0.0; @@ -227,6 +236,7 @@ void makeNH3(OBMol *molPtr) void makeSF6(OBMol *molPtr) { + molPtr->SetTitle("SF6"); // double const SCALE = 5.0; OBAtom *S = molPtr->NewAtom(); @@ -267,6 +277,7 @@ void makeSF6(OBMol *molPtr) void makeH2O(OBMol *molPtr) { + molPtr->SetTitle("H2O"); // double const SCALE = 5.0; double const THETA = (180.0-104.45)/2 * M_PI/180.0; double sinTheta = 0.0, cosTheta = 0.0; @@ -295,6 +306,7 @@ void makeH2O(OBMol *molPtr) void makeNO2(OBMol *molPtr) { + molPtr->SetTitle("NO2"); // double const SCALE = 5.0; double const THETA = (180.0-134.3)/2 * M_PI/180.0; double sinTheta = 0.0, cosTheta = 0.0; @@ -323,6 +335,7 @@ void makeNO2(OBMol *molPtr) void makeCO2(OBMol *molPtr) { + molPtr->SetTitle("CO2"); OBAtom *C = molPtr->NewAtom(); C->SetAtomicNum(6); C->SetVector(0.0, 0.0, 0.0); @@ -341,6 +354,7 @@ void makeCO2(OBMol *molPtr) void makeC2H2(OBMol *molPtr) { + molPtr->SetTitle("C2H2"); OBAtom *C1 = molPtr->NewAtom(); C1->SetAtomicNum(6); C1->SetVector(0.0, SCALE*0.5, 0.0); @@ -364,6 +378,7 @@ void makeC2H2(OBMol *molPtr) void makeC2H4(OBMol *molPtr) { + molPtr->SetTitle("C2H4"); OBAtom *C1 = molPtr->NewAtom(); C1->SetAtomicNum(6); C1->SetVector(0.0, SCALE*0.5, 0.0); @@ -397,6 +412,8 @@ void makeC2H4(OBMol *molPtr) void makeC2H6(OBMol *molPtr) { + molPtr->SetTitle("C2H6"); + double const THETA = 120.0 * M_PI / 180.0; double sinTheta = 0.0, cosTheta = 0.0; #ifdef _GNU_SOURCE @@ -447,3 +464,27 @@ void makeC2H6(OBMol *molPtr) } +void makeC6H6(OBMol *molPtr) +{ + molPtr->SetTitle("C6H6"); + int const N = 6; + OBAtom *C[N], *H[N]; + for(int i=0; i<N; ++i) { + C[i] = molPtr->NewAtom(); + C[i]->SetAtomicNum(6); + H[i] = molPtr->NewAtom(); + H[i]->SetAtomicNum(1); + double const theta = (i * 360.0/N) * M_PI / 180.0; + double const cosTheta = cos(theta); + double const sinTheta = sin(theta); + C[i]->SetVector(0.0, 2.0*SCALE * cosTheta, 2.0*SCALE * sinTheta); + H[i]->SetVector(0.0, 3.0*SCALE * cosTheta, 3.0*SCALE * sinTheta); + bond(molPtr, C[i], H[i], 1); + } + + int bondOrder = 1; + for(int i=0; i<N; ++i) { + bond(molPtr, C[i], C[(i+1)%N], bondOrder); + bondOrder = 3 - bondOrder; + } +} diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.cpp index 22d63f428..a979fcfb0 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/NXOpenGLSceneGraph.cpp @@ -154,21 +154,22 @@ bool NXSGOpenGLModelViewTransform::applyRecursive(void) const throw() // apply transform and quit if error bool appliedOK = apply(); - if(!appliedOK) - return false; - - bool childrenOK = true; - ChildrenList::const_iterator child_iter; - for(child_iter = children.begin(); - child_iter != children.end() && childrenOK; - ++child_iter) - { - childrenOK = (*child_iter)->applyRecursive(); - } + if(appliedOK) { + bool childrenOK = true; + ChildrenList::const_iterator child_iter; + for(child_iter = children.begin(); + child_iter != children.end() && childrenOK; + ++child_iter) + { + childrenOK = (*child_iter)->applyRecursive(); + } + appliedOK = childrenOK; + } + // Restore model-view matrix glPopMatrix(); - return childrenOK; + return appliedOK; } // ............................................................................. diff --git a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRenderer.cpp b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRenderer.cpp index 2d6d97dc2..a198dbc61 100644 --- a/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRenderer.cpp +++ b/cad/plugins/NanoVision-1/src/Plugins/RenderingEngines/OpenGL/Renderers/NXBallAndStickOpenGLRenderer.cpp @@ -22,7 +22,7 @@ inline void guarded_delete(T* &ptr) // static data -double const NXBallAndStickOpenGLRenderer::BOND_WIDTH(0.25); +double const NXBallAndStickOpenGLRenderer::BOND_WIDTH(0.5); // ............................................................................. @@ -339,8 +339,8 @@ bool NXBallAndStickOpenGLRenderer::initializeCanonicalCylinderNode(void) } #ifdef NX_DEBUG - cout << "canonicalCylinderNode scenegraph:" << endl; - canonicalCylinderNode->writeDotGraph(cout); + // cout << "canonicalCylinderNode scenegraph:" << endl; + // canonicalCylinderNode->writeDotGraph(cout); #endif return true; } @@ -465,7 +465,7 @@ bool NXBallAndStickOpenGLRenderer::initializeCanonicalSingleBondNode(void) return false; } #ifdef NX_DEBUG - canonicalCylinderNode->writeDotGraph(cerr); + // canonicalCylinderNode->writeDotGraph(cerr); #endif assert(canonicalCylinderNode->getNumChildren()==0); assert(canonicalBondNode[SINGLE_BOND]->getNumChildren()==0); |