// Select a variable of the specified type from the zmatrix provided Variable* AtenSelectVariable::selectVariable(ZMatrix* zmat, int vartype, Variable* currentVar, bool currentNegate) { // Check source if (zmat == NULL) return NULL; zMatrix_ = zmat; // Clear list and repopulate with variables of the correct type QTableWidgetItem *item; int count, nvars; TreeNode* vars; // Get number of relevant variables of specified type, and start of list... variableType_ = vartype; switch (variableType_) { case (0): nvars = zmat->nDistances(); vars = zmat->distances(); break; case (1): nvars = zmat->nAngles(); vars = zmat->angles(); break; case (2): nvars = zmat->nTorsions(); vars = zmat->torsions(); break; default: printf("Internal Error: Specified vartype given to AtenSelectVariable::selectVariable is unrecognised.\n"); return NULL; break; } // Clear and update list refreshing_ = true; ui.VariableTable->clear(); ui.VariableTable->setHorizontalHeaderLabels(QStringList() << "Variable" << "Current Value"); ui.VariableTable->setRowCount(nvars); ReturnValue rv; count = 0; for (TreeNode* v = vars; v != NULL; v = v->next) { Variable* var = (Variable*) v; // Set variable name item = new QTableWidgetItem(var->name()); ui.VariableTable->setItem(count, 0, item); // Set value v->execute(rv); item = new QTableWidgetItem(rv.asString()); ui.VariableTable->setItem(count, 1, item); // Select? if (currentVar == var) ui.VariableTable->setCurrentItem(item); count ++; } for (count=0; count<2; count++) ui.VariableTable->resizeColumnToContents(count); ui.NegateCheck->setChecked(currentNegate); refreshing_ = false; // Execute the dialog and check on the result return (exec() == 1 ? selectedVariable_ : NULL); }
ATEN_USING_NAMESPACE // Get part of string before specified character/string bool Commands::function_AfterStr(CommandNode* c, Bundle& obj, ReturnValue& rv) { rv.set(c->argc(0).section(c->argc(1), 1)); // ATEN2 TODO Test this if (c->hasArg(2) && c->argb(2) && (rv.asString()[0] == '\0')) rv.set(c->argc(0)); return true; }
// Set desired value bool GlyphVariable::setAccessor(int i, ReturnValue& sourcerv, ReturnValue& newValue, bool hasArrayIndex, int arrayIndex) { Messenger::enter("GlyphVariable::setAccessor"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nAccessors)) { printf("Internal Error: Accessor id %i is out of range for Glyph type.\n", i); Messenger::exit("GlyphVariable::setAccessor"); return false; } Accessors acc = (Accessors) i; // Check for correct lack/presence of array index given to original accessor, and nature of new value bool result = checkAccessorArrays(accessorData[acc], newValue, hasArrayIndex, arrayIndex); if (!result) { Messenger::exit("GlyphVariable::setAccessor"); return false; } // Get current data from ReturnValue Glyph* ptr = (Glyph*) sourcerv.asPointer(VTypes::GlyphData, result); if ((!result) || (ptr == NULL)) { Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::GlyphData)); result = false; } if (result) switch (acc) { case (GlyphVariable::Rotated): if (newValue.asInteger() == 0) ptr->resetRotation(); break; case (GlyphVariable::Rotation): ptr->setRotationElement( ((arrayIndex-1)/3)*4 + (arrayIndex-1)%3, newValue.asDouble()); break; case (GlyphVariable::Selected): ptr->setSelected(newValue.asBool()); break; case (GlyphVariable::Solid): ptr->setSolid(newValue.asBool()); break; case (GlyphVariable::Text): ptr->setText(newValue.asString()); break; case (GlyphVariable::Visible): ptr->setVisible(newValue.asBool()); break; default: printf("GlyphVariable::setAccessor doesn't know how to use member '%s'.\n", qPrintable(accessorData[acc].name)); result = false; break; } Messenger::exit("GlyphVariable::setAccessor"); return result; }
// Set desired value bool BasisShellVariable::setAccessor(int i, ReturnValue& sourcerv, ReturnValue& newValue, bool hasArrayIndex, int arrayIndex) { Messenger::enter("BasisShellVariable::setAccessor"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nAccessors)) { printf("Internal Error: Accessor id %i is out of range for BasisShell type.\n", i); Messenger::exit("BasisShellVariable::setAccessor"); return false; } Accessors acc = (Accessors) i; // Check for correct lack/presence of array index given to original accessor, and nature of new value bool result = checkAccessorArrays(accessorData[acc], newValue, hasArrayIndex, arrayIndex); if (!result) { Messenger::exit("BasisShellVariable::setAccessor"); return false; } // Get current data from ReturnValue BasisShell* ptr = (BasisShell*) sourcerv.asPointer(VTypes::BasisShellData, result); if ((!result) || (ptr == NULL)) { Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::BasisShellData)); result = false; } BasisShell::BasisShellType bft; if (result) switch (acc) { case (BasisShellVariable::AtomId): ptr->setAtomId( newValue.asInteger() - 1); break; case (BasisShellVariable::Type): bft = BasisShell::basisShellType( newValue.asString() ); if (bft == BasisShell::nBasisShellTypes) result = false; else ptr->setType(bft); break; default: printf("BasisShellVariable::setAccessor doesn't know how to use member '%s'.\n", qPrintable(accessorData[acc].name)); result = false; break; } Messenger::exit("BasisShellVariable::setAccessor"); return result; }
// Set desired value bool BondVariable::setAccessor(int i, ReturnValue& sourcerv, ReturnValue& newValue, bool hasArrayIndex, int arrayIndex) { Messenger::enter("BondVariable::setAccessor"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nAccessors)) { printf("Internal Error: Accessor id %i is out of range for Bond type.\n", i); Messenger::exit("BondVariable::setAccessor"); return false; } Accessors acc = (Accessors) i; // Check for correct lack/presence of array index given to original accessor, and nature of new value bool result = checkAccessorArrays(accessorData[acc], newValue, hasArrayIndex, arrayIndex); if (!result) { Messenger::exit("BondVariable::setAccessor"); return false; } // Get current data from ReturnValue Bond* ptr = (Bond*) sourcerv.asPointer(VTypes::BondData, result); Bond::BondType bt; if ((!result) || (ptr == NULL)) { Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::BondData)); result = false; } Model* ptrParent = ptr->atomI()->parent(); if (result) switch (acc) { case (BondVariable::Type): bt = Bond::bondType(newValue.asString(), true); if (bt == Bond::nBondTypes) break; ptrParent->changeBond(ptr, bt); break; default: printf("BondVariable::setAccessor doesn't know how to use member '%s'.\n", qPrintable(accessorData[acc].name)); result = false; break; } Messenger::exit("BondVariable::setAccessor"); return result; }
// Set desired value bool ForcefieldBoundVariable::setAccessor(int i, ReturnValue& sourcerv, ReturnValue& newValue, bool hasArrayIndex, int arrayIndex) { Messenger::enter("ForcefieldBoundVariable::setAccessor"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nAccessors)) { printf("Internal Error: Accessor id %i is out of range for ForcefieldBound type.\n", i); Messenger::exit("ForcefieldBoundVariable::setAccessor"); return false; } Accessors acc = (Accessors) i; // Check for correct lack/presence of array index given to original accessor, and nature of new value bool result = checkAccessorArrays(accessorData[acc], newValue, hasArrayIndex, arrayIndex); if (!result) { Messenger::exit("ForcefieldBoundVariable::setAccessor"); return false; } // Get current data from ReturnValue ForcefieldBound* ptr = (ForcefieldBound*) sourcerv.asPointer(VTypes::ForcefieldBoundData, result); if ((!result) || (ptr == NULL)) { Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::ForcefieldBoundData)); result = false; } int n; if (result) switch (acc) { case (ForcefieldBoundVariable::Data): if ((newValue.arraySize() != -1) && (newValue.arraySize() <= MAXFFPARAMDATA)) for (n=0; n<newValue.arraySize(); ++n) ptr->setParameter(n, newValue.asDouble(n, result)); else if (hasArrayIndex) ptr->setParameter(arrayIndex-1, newValue.asDouble()); else for (n=0; n<MAXFFPARAMDATA; ++n) ptr->setParameter(n, newValue.asDouble()); break; case (ForcefieldBoundVariable::EScale): if (ptr->type() != ForcefieldBound::TorsionInteraction) { Messenger::print("Tried to set the 1-4 coulombic scale factor for a non-torsion bound interaction."); result = false; } else ptr->setElecScale( newValue.asDouble() ); break; case (ForcefieldBoundVariable::Form): result = ptr->setForm(newValue.asString()); break; case (ForcefieldBoundVariable::TypeNames): if ((newValue.arraySize() != -1) && (newValue.arraySize() <= MAXFFBOUNDTYPES)) for (n=0; n<newValue.arraySize(); ++n) ptr->setTypeName(n, newValue.asString(n, result)); else if (hasArrayIndex) ptr->setTypeName(arrayIndex-1, newValue.asString()); else for (n=0; n<MAXFFBOUNDTYPES; ++n) ptr->setTypeName(n, newValue.asString()); break; case (ForcefieldBoundVariable::VScale): if (ptr->type() != ForcefieldBound::TorsionInteraction) { Messenger::print("Tried to set the 1-4 coulombic scale factor for a non-torsion bound interaction."); result = false; } else ptr->setVdwScale( newValue.asDouble() ); break; default: printf("ForcefieldBoundVariable::setAccessor doesn't know how to use member '%s'.\n", qPrintable(accessorData[acc].name)); result = false; break; } Messenger::exit("ForcefieldBoundVariable::setAccessor"); return result; }
// Get part of string before specified character bool Commands::function_BeforeStr(CommandNode* c, Bundle& obj, ReturnValue& rv) { rv.set( c->argc(0).section(c->argc(1), 0, 0) ); // ATEN2 TODO Test this if (c->hasArg(2) && c->argb(2) && (rv.asString()[0] == '\0')) rv.set(c->argc(0)); return true; }