// Set value of variable bool MatrixVariable::set(ReturnValue& rv) { if (readOnly_) { Messenger::print("A constant value (in this case a matrix) cannot be assigned to."); return false; } bool success = false; if (rv.arraySize() == -1) matrixData_ = rv.asMatrix(success); else if (rv.arraySize() == 9) { matrixData_.setIdentity(); for (int n=0; n<9; ++n) { matrixData_[n/3*4+n%3] = rv.asDouble(n, success); if (!success) break; } } else if (rv.arraySize() == 16) { for (int n=0; n<16; ++n) { matrixData_[n] = rv.asDouble(n, success); if (!success) break; } } else { Messenger::print("Error: Array assigned to matrix variable must contain nine or sixteen elements."); success = false; } return success; }
void AtenPrefs::spotlightSpecularChanged() { // Get and store new colour ReturnValue rv; bool success; ui.SpotlightSpecularColourButton->callPopupMethod("currentColour", rv); prefs.setSpotlightColour(Prefs::SpecularComponent, rv.asDouble(0, success), rv.asDouble(1, success), rv.asDouble(2, success)); parent_.updateWidgets(); }
void AtenPrefs::elementColourChanged() { // Get selected element int el = ui.ElementList->currentRow(); if (el == -1) return; // Get and store new colour ReturnValue rv; bool success; ui.ElementColourButton->callPopupMethod("currentColour", rv); ElementMap::setColour(el, rv.asDouble(0, success), rv.asDouble(1, success), rv.asDouble(2, success), rv.asDouble(3, success)); updateAfterViewPrefs(); }
// Call named method associated to popup bool GridColourPopup::callMethod(QString methodName, ReturnValue& rv) { bool result = true; if (methodName == "TEST") return true; else if (methodName == "currentColour") { QColor newColor = ui.ColourWidget->currentColour(); double colour[4]; colour[0] = newColor.redF(); colour[1] = newColor.greenF(); colour[2] = newColor.blueF(); colour[3] = newColor.alphaF(); rv.setArray(VTypes::DoubleData, colour, 4); return true; } else if (methodName == "setCurrentColour") { bool success; QColor newColour; newColour.setRedF(rv.asDouble(0, success)); if (success) newColour.setGreenF(rv.asDouble(1, success)); if (success) newColour.setBlueF(rv.asDouble(2, success)); if (success) newColour.setAlphaF(rv.asDouble(3, success)); if (!success) { printf("Failed to get colour information from supplied ReturnValue.\n"); return false; } setCurrentColour(newColour); updateParentButtonIcon(newColour); return true; } else if (methodName == "hideEvent") { updateParentButtonIcon(ui.ColourWidget->currentColour()); return true; } else { printf("No method called '%s' is available in this popup.\n", qPrintable(methodName)); result = false; } return result; }
// 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 MatrixVariable::setAccessor(int i, ReturnValue& sourcerv, ReturnValue& newValue, bool hasArrayIndex, int arrayIndex) { Messenger::enter("MatrixVariable::setAccessor"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nAccessors)) { printf("Internal Error: Accessor id %i is out of range for Matrix type.\n", i); Messenger::exit("MatrixVariable::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("MatrixVariable::setAccessor"); return false; } // Get current data from ReturnValue Matrix& m = sourcerv.matrix(); if (result) switch (acc) { case (MatrixVariable::XX): case (MatrixVariable::XY): case (MatrixVariable::XZ): case (MatrixVariable::XW): case (MatrixVariable::YX): case (MatrixVariable::YY): case (MatrixVariable::YZ): case (MatrixVariable::YW): case (MatrixVariable::ZX): case (MatrixVariable::ZY): case (MatrixVariable::ZZ): case (MatrixVariable::ZW): case (MatrixVariable::WX): case (MatrixVariable::WY): case (MatrixVariable::WZ): case (MatrixVariable::WW): m[acc-MatrixVariable::XX] = newValue.asDouble(result); break; default: printf("MatrixVariable::setAccessor doesn't know how to use member '%s'.\n", qPrintable(accessorData[acc].name)); result = false; break; } Messenger::exit("MatrixVariable::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; }