// Retrieve desired value bool BasisShellVariable::retrieveAccessor(int i, ReturnValue& rv, bool hasArrayIndex, int arrayIndex) { Messenger::enter("BasisShellVariable::retrieveAccessor"); // 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::retrieveAccessor"); return false; } Accessors acc = (Accessors) i; // Check for correct lack/presence of array index given if ((accessorData[i].arraySize == 0) && hasArrayIndex) { Messenger::print("Error: Unnecessary array index provided for member '%s'.", qPrintable(accessorData[i].name)); Messenger::exit("BasisShellVariable::retrieveAccessor"); return false; } else if ((accessorData[i].arraySize > 0) && (hasArrayIndex)) { if ((arrayIndex < 1) || (arrayIndex > accessorData[i].arraySize)) { Messenger::print("Error: Array index out of bounds for member '%s' (%i, range is 1-%i).", qPrintable(accessorData[i].name), arrayIndex, accessorData[i].arraySize); Messenger::exit("BasisShellVariable::retrieveAccessor"); return false; } } // Get current data from ReturnValue bool result = true; BasisShell* ptr = (BasisShell*) rv.asPointer(VTypes::BasisShellData, result); if ((!result) || (ptr == NULL)) { Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::BasisShellData)); result = false; } if (result) switch (acc) { case (BasisShellVariable::AtomId): rv.set(ptr->atomId()+1); break; case (BasisShellVariable::Primitives): if ((arrayIndex < 1) || (arrayIndex > ptr->nPrimitives())) { Messenger::print("Array index [%i] is out of range for 'primitives' member.", arrayIndex); result = false; } else rv.set(VTypes::BasisPrimitiveData, ptr->primitive(arrayIndex-1)); break; case (BasisShellVariable::Type): rv.set(BasisShell::basisShellType(ptr->type())); break; default: printf("Internal Error: Access to member '%s' has not been defined in BasisShellVariable.\n", qPrintable(accessorData[i].name)); result = false; break; } Messenger::exit("BasisShellVariable::retrieveAccessor"); return result; }
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; }
void TestCaller::callMegaString() { QMutexLocker locker(&mutex); qDebug() << "Iteration!" << this << thread() << QThread::currentThread(); ReturnValue ret = largeValues(megaString); QString value = ret.isError() ? ret.errString() : ret.toString(); if (value != megaString) qFatal(qPrintable(QString("ERROR: Malformed megastring: %1 (%2)").arg(value).arg(ret.errString()))); }
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(); }
// Retrieve desired value bool WidgetVariable::retrieveAccessor(int i, ReturnValue& rv, bool hasArrayIndex, int arrayIndex) { Messenger::enter("WidgetVariable::retrieveAccessor"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nAccessors)) { printf("Internal Error: Accessor id %i is out of range for Aten type.\n", i); Messenger::exit("WidgetVariable::retrieveAccessor"); return false; } Accessors acc = (Accessors) i; // Check for correct lack/presence of array index given if ((accessorData[i].arraySize == 0) && hasArrayIndex) { Messenger::print("Error: Unnecessary array index provided for member '%s'.", qPrintable(accessorData[i].name)); Messenger::exit("WidgetVariable::retrieveAccessor"); return false; } else if ((accessorData[i].arraySize > 0) && (hasArrayIndex)) { if ((arrayIndex < 1) || (arrayIndex > accessorData[i].arraySize)) { Messenger::print("Error: Array index out of bounds for member '%s' (%i, range is 1-%i).", qPrintable(accessorData[i].name), arrayIndex, accessorData[i].arraySize); Messenger::exit("WidgetVariable::retrieveAccessor"); return false; } } // Variables used in retrieval bool result = true; TreeGuiWidget* ptr = (TreeGuiWidget*) rv.asPointer(VTypes::WidgetData, result); if ((!result) || (ptr == NULL)) { Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::WidgetData)); result = false; } if (result) switch (acc) { case (WidgetVariable::Enabled): rv.set(ptr->enabled()); break; case (WidgetVariable::VerticalFill): rv.set(ptr->qtWidgetObject() == NULL ? false : ptr->qtWidgetObject()->autoFillVertical()); break; case (WidgetVariable::Visible): rv.set(ptr->visible()); break; default: printf("Internal Error: Access to member '%s' has not been defined in WidgetVariable.\n", qPrintable(accessorData[i].name)); result = false; break; } Messenger::exit("WidgetVariable::retrieveAccessor"); return result; }
void AtenPrefs::on_ElementList_currentRowChanged(int row) { // Update the info for the current element ui.ElementNameLabel->setText(ElementMap::name(row)); ui.ElementSymbolLabel->setText(ElementMap::symbol(row)); ui.ElementMassLabel->setText(QString::number(ElementMap::atomicMass(row))); ui.ElementRadiusSpin->setValue(ElementMap::atomicRadius(row)); ReturnValue rv; rv.setArray(VTypes::DoubleData, ElementMap::colour(row), 4); ui.ElementColourButton->callPopupMethod("setCurrentColour", rv); }
// Convert string to integer number bool Commands::function_AToI(CommandNode* c, Bundle& obj, ReturnValue& rv) { static QRegularExpression re("[\\d.\\-eE]+"); QRegularExpressionMatch match = re.match(c->argc(0)); if (match.hasMatch()) rv.set( match.captured(0).toInt() ); else { Messenger::warn("Couldn't convert '%s' to an integer number.\n", qPrintable(c->argc(0))); rv.reset(); } return true; }
// Retrieve desired value bool MatrixVariable::retrieveAccessor(int i, ReturnValue& rv, bool hasArrayIndex, int arrayIndex) { Messenger::enter("MatrixVariable::retrieveAccessor"); // 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::retrieveAccessor"); return false; } Accessors acc = (Accessors) i; // Check for correct lack/presence of array index given if (hasArrayIndex) { Messenger::print("Error: Unnecessary array index provided for member '%s'.", qPrintable(accessorData[i].name)); Messenger::exit("MatrixVariable::retrieveAccessor"); return false; } // Get current data from ReturnValue bool result = true; Matrix m = rv.asMatrix(result); if (result) switch (acc) { case (MatrixVariable::Determinant): rv.set(m.determinant()); break; 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): rv.set(m[acc-MatrixVariable::XX]); break; default: printf("Internal Error: Access to member '%s' has not been defined in MatrixVariable.\n", qPrintable(accessorData[i].name)); result = false; break; } Messenger::exit("MatrixVariable::retrieveAccessor"); return result; }
// Return string based on supplied format and arguments bool Commands::function_ToA(CommandNode* c, Bundle& obj, ReturnValue& rv) { Format* fmt = c->createFormat(0,1); if (fmt == NULL) { printf("Error - No format defined in 'toa' command.\n"); return false; } bool result = fmt->writeToString(); if (result) rv.set(fmt->string()); else rv.reset(); return result; }
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(); }
// 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; }
// Perform desired function bool ForcefieldBoundVariable::performFunction(int i, ReturnValue& rv, TreeNode* node) { Messenger::enter("ForcefieldBoundVariable::performFunction"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nFunctions)) { printf("Internal Error: FunctionAccessor id %i is out of range for ForcefieldBound type.\n", i); Messenger::exit("ForcefieldBoundVariable::performFunction"); return false; } // Get current data from ReturnValue bool result = true; ForcefieldBound* ptr = (ForcefieldBound*) rv.asPointer(VTypes::ForcefieldBoundData, result); int id; if (result) switch (i) { case (ForcefieldBoundVariable::Parameter): switch (ptr->type()) { case (ForcefieldBound::BondInteraction): case (ForcefieldBound::UreyBradleyInteraction): id = BondFunctions::bondParameter(ptr->bondForm(), node->argc(0), true); if (id == BondFunctions::functionData[ptr->bondForm()].nParameters) result = false; else rv.set(ptr->parameter(id)); break; case (ForcefieldBound::AngleInteraction): id = AngleFunctions::angleParameter(ptr->angleForm(), node->argc(0), true); if (id == AngleFunctions::functionData[ptr->angleForm()].nParameters) result = false; else rv.set(ptr->parameter(id)); break; case (ForcefieldBound::TorsionInteraction): case (ForcefieldBound::ImproperInteraction): id = TorsionFunctions::torsionParameter(ptr->torsionForm(), node->argc(0), true); if (id == TorsionFunctions::functionData[ptr->torsionForm()].nParameters) result = false; else rv.set(ptr->parameter(id)); break; default: break; } break; default: printf("Internal Error: Access to function '%s' has not been defined in ForcefieldBoundVariable.\n", qPrintable(functionData[i].name)); result = false; break; } Messenger::exit("ForcefieldBoundVariable::performFunction"); return result; }
void List<T>::shift(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 0); auto list = get_internal<T, ListClass<T>>(this_object); if (list->size() == 0) { list->verify_in_transaction(); return_value.set_undefined(); } else { auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(0)); return_value.set(RealmObject<T>::create_instance(ctx, realm_object)); list->remove(0); } }
// Set desired value bool WidgetVariable::setAccessor(int i, ReturnValue& sourcerv, ReturnValue& newValue, bool hasArrayIndex, int arrayIndex) { Messenger::enter("WidgetVariable::setAccessor"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nAccessors)) { printf("Internal Error: Accessor id %i is out of range for Aten type.\n", i); Messenger::exit("WidgetVariable::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("WidgetVariable::setAccessor"); return false; } // Get current data from ReturnValue TreeGuiWidget* ptr = (TreeGuiWidget*) sourcerv.asPointer(VTypes::WidgetData, result); if ((!result) || (ptr == NULL)) { Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::WidgetData)); result = false; } switch (acc) { case (WidgetVariable::Enabled): ptr->setEnabled(newValue.asBool()); if (ptr->qtWidgetObject()) ptr->qtWidgetObject()->updateQt();; break; case (WidgetVariable::VerticalFill): if (ptr->qtWidgetObject()) ptr->qtWidgetObject()->setAutoFillVertical(newValue.asBool()); break; case (WidgetVariable::Visible): ptr->setVisible(newValue.asBool()); if (ptr->qtWidgetObject()) ptr->qtWidgetObject()->updateQt();; break; default: printf("WidgetVariable::setAccessor doesn't know how to use member '%s'.\n", qPrintable(accessorData[acc].name)); result = false; break; } Messenger::exit("WidgetVariable::setAccessor"); return result; }
// Return value of node bool MatrixVariable::execute(ReturnValue& rv) { // If this matrix is a constant, read the nine stored expressions to recreate it if (readOnly_) reCreate(); rv.set(matrixData_); return true; }
// Replace characters in supplied string bool Commands::function_ReplaceChars(CommandNode* c, Bundle& obj, ReturnValue& rv) { QString result = c->argc(0); for (int n=0; n<c->argc(1).length(); ++n) result = result.replace(c->argc(1).at(n), c->argc(2)); rv.set(result); return true; }
// Call named method associated to popup bool ElementTablePopup::callMethod(QString methodName, ReturnValue& rv) { bool result = true; if (methodName == "TEST") return true; else if (methodName == "currentElement") { rv = currentElement_; return true; } else if (methodName == "setCurrentElement") { currentElement_ = rv.asInteger(); // Set icon on parent button parentMenuButton()->setIcon(ElementMap::icon(currentElement_)); return true; } else if (methodName == "hideEvent") { return true; } else { printf("No method called '%s' is available in this popup.\n", qPrintable(methodName)); result = false; } return result; }
// Add next gridpoint in sequence bool Commands::function_AddNextGridPoint(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; obj.g->setNextData(c->argd(0)); rv.reset(); return true; }
void List<T>::splice(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count_at_least(argc, 1); auto list = get_internal<T, ListClass<T>>(this_object); size_t size = list->size(); long index = std::min<long>(Value::to_number(ctx, arguments[0]), size); if (index < 0) { index = std::max<long>(size + index, 0); } size_t remove; if (argc < 2) { remove = size - index; } else { remove = std::max<long>(Value::to_number(ctx, arguments[1]), 0); remove = std::min<long>(remove, size - index); } std::vector<ValueType> removed_objects; removed_objects.reserve(remove); for (size_t i = 0; i < remove; i++) { auto realm_object = realm::Object(list->get_realm(), list->get_object_schema(), list->get(index)); removed_objects.push_back(RealmObject<T>::create_instance(ctx, realm_object)); list->remove(index); } for (size_t i = 2; i < argc; i++) { list->insert(ctx, arguments[i], index + i - 2); } return_value.set(Object::create_array(ctx, removed_objects)); }
// Set visibility of grid data bool Commands::function_GridVisible(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; if (c->hasArg(0)) obj.g->setVisible(c->argb(0)); rv.set(obj.g->isVisible()); return true; }
// Set whether 2D grid uses data value as height component bool Commands::function_GridUseZ(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; if (c->hasArg(0)) obj.g->setUseDataForZ(c->argb(0)); rv.set(obj.g->useDataForZ()); return true; }
// Set view percentage for secondary surface bool Commands::function_GridViewPercentageSecondary(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; if (c->hasArg(0)) obj.g->setSecondaryCutoffAsViewPercentage(c->argd(0), c->hasArg(1) ? c->argb(1) : false); rv.set((obj.g->partialSecondarySum() / obj.g->totalAbsoluteSum())*100.0); return true; }
// Set whether grid is periodic bool Commands::function_GridPeriodic(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; obj.g->setPeriodic(c->argb(0)); rv.reset(); return true; }
// Add grid point data at specified indices bool Commands::function_AddGridPoint(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; Vec3<int> veci = c->arg3i(0); obj.g->setData(veci.x-1, veci.y-1, veci.z-1, c->argd(3)); rv.reset(); return true; }
// Create new grid in the current model bool Commands::function_NewGrid(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::ModelPointer)) return false; obj.g = aten_.currentModel()->addGrid(); obj.g->setName(c->argc(0).trimmed()); rv.set(VTypes::GridData, obj.g); return true; }
// Initialise grid, setting extent of grid (number of points in each direction) bool Commands::function_InitialiseGrid(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; Grid::GridType gt = Grid::gridType(c->argc(0), true); if (gt == Grid::nGridTypes) return false; rv.set(obj.g->initialise(gt, c->arg3i(1))); return true; }
// Set secondary grid cutoff bool Commands::function_GridCutoffSecondary(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; obj.g->setLowerSecondaryCutoff(c->argd(0)); if (c->hasArg(1)) obj.g->setUpperSecondaryCutoff(c->argd(1)); rv.reset(); return true; }
// Set negative colour for grid bool Commands::function_GridColourSecondary(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; if (c->hasArg(3)) obj.g->setSecondaryColour(c->argd(0), c->argd(1), c->argd(2), c->argd(3)); else obj.g->setSecondaryColour(c->argd(0), c->argd(1), c->argd(2)); rv.reset(); return true; }
// Set transparency of primary and secondary grid surfaces bool Commands::function_GridAlpha(CommandNode* c, Bundle& obj, ReturnValue& rv) { if (obj.notifyNull(Bundle::GridPointer)) return false; obj.g->setPrimaryAlpha(c->argGLf(0)); obj.g->setSecondaryAlpha(c->argGLf(0)); rv.reset(); return true; }
// 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; }