예제 #1
0
파일: script.cpp 프로젝트: alinelena/aten
ATEN_USING_NAMESPACE

// List available scripts
bool Commands::function_ListScripts(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (aten_.nScripts() == 0) Messenger::print("No scripts loaded.");
	else Messenger::print("Currently loaded scripts:");
	for (Program* prog = aten_.scripts(); prog != NULL; prog = prog->next) Messenger::print("  %s (%s)", qPrintable(prog->filename()), qPrintable(prog->name()));
	rv.reset();
	return true;
}
예제 #2
0
파일: grid.cpp 프로젝트: alinelena/aten
// Set grid axes (nine doubles)
bool Commands::function_GridAxes(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::GridPointer)) return false;
	Matrix mat;
	mat.setColumn(0, c->arg3d(0), 0.0);
	mat.setColumn(1, c->arg3d(3), 0.0);
	mat.setColumn(2, c->arg3d(6), 0.0);
	obj.g->setAxes(mat);
	rv.reset();
	return true;
}
예제 #3
0
파일: string.cpp 프로젝트: alinelena/aten
// 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;
}
예제 #4
0
파일: grid.cpp 프로젝트: alinelena/aten
// Set colour scale for grid
bool Commands::function_GridColourscale(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::GridPointer)) return false;
	int cs = c->argi(0);
	if ((cs < 0) || (cs > 10))
	{
		Messenger::print("ColourScale %i is out of range (1-10, or 0 to use object's internal colour).",cs);
		return false;
	}
	obj.g->setColourScale(cs-1);
	rv.reset();
	return true;
}
예제 #5
0
파일: string.cpp 프로젝트: alinelena/aten
// 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;
}
예제 #6
0
파일: grid.cpp 프로젝트: alinelena/aten
// Set loop order to use in 'gridnextpoint'
bool Commands::function_GridLoopOrder(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	if (obj.notifyNull(Bundle::GridPointer)) return false;
	if (c->argc(0).length() != 3)
	{
		Messenger::print("A string of three characters must be passed to 'gridLoopOrder' (got '%s').", qPrintable(c->argc(0)));
		return false;
	}

	obj.g->setLoopOrder(c->argc(0));

	rv.reset();
	return true;
}
예제 #7
0
파일: script.cpp 프로젝트: alinelena/aten
// Run specified script
bool Commands::function_RunScript(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	// Find the script...
	Program* prog;
	for (prog = aten_.scripts(); prog != NULL; prog = prog->next) if (c->argc(0) == prog->name()) break;
	if (prog != NULL)
	{
		Messenger::print("Executing script '%s':", qPrintable(c->argc(0)));
		ReturnValue result;
		prog->execute(result);
	}
	else Messenger::print("Couldn't find script '%s'.", qPrintable(c->argc(0)));
	rv.reset();
	return true;
}
예제 #8
0
파일: script.cpp 프로젝트: alinelena/aten
// Load script from disk
bool Commands::function_LoadScript(CommandNode* c, Bundle& obj, ReturnValue& rv)
{
	Program* prog = aten_.addScript();
	if (!prog->generateFromFile(c->argc(0), "ScriptFile"))
	{
		aten_.removeScript(prog);
		return false;
	}
	if (c->hasArg(1)) prog->setName(c->argc(1));
	else prog->setName(c->argc(0));
	rv.reset();

	// Update GUI
	aten_.atenWindow()->updateWidgets(AtenWindow::ToolsPanelTarget);

	return true;
}
예제 #9
0
파일: widget.cpp 프로젝트: alinelena/aten
// Perform desired function
bool WidgetVariable::performFunction(int i, ReturnValue& rv, TreeNode* node)
{
	Messenger::enter("WidgetVariable::performFunction");
	// Cast 'i' into Accessors enum value
	if ((i < 0) || (i >= nFunctions))
	{
		printf("Internal Error: FunctionAccessor id %i is out of range for Aten type.\n", i);
		Messenger::exit("WidgetVariable::performFunction");
		return false;
	}

	// Get current data from ReturnValue
	int xw, xh, l, t;
	TreeGuiWidgetEvent* event;
	TreeGuiWidgetEvent::EventProperty eventProperty;
	TreeGuiWidgetEvent::EventType eventType;
	TreeGuiWidget* targetWidget;
	ReturnValue value;
	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 (i)
	{
		case (WidgetVariable::AddButton):
			l = node->hasArg(2) ? node->argi(2) : -1;
			t = node->hasArg(3) ? node->argi(3) : -1;
			xw = node->hasArg(4) ? node->argi(4) : 0;
			xh = node->hasArg(5) ? node->argi(5) : 0;
			rv.set(VTypes::WidgetData, ptr->addCheck(node->argc(0), node->argc(1), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddCheck):
			l = node->hasArg(3) ? node->argi(3) : -1;
			t = node->hasArg(4) ? node->argi(4) : -1;
			xw = node->hasArg(5) ? node->argi(5) : 0;
			xh = node->hasArg(6) ? node->argi(6) : 0;
			rv.set(VTypes::WidgetData, ptr->addCheck(node->argc(0), node->argc(1), node->argi(2), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddCombo):
			l = node->hasArg(4) ? node->argi(4) : -1;
			t = node->hasArg(5) ? node->argi(5) : -1;
			xw = node->hasArg(6) ? node->argi(6) : 0;
			xh = node->hasArg(7) ? node->argi(7) : 0;
			rv.set(VTypes::WidgetData, ptr->addCombo(node->argc(0), node->argc(1), node->argc(2), node->argi(3), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddDoubleSpin):
			l = node->hasArg(6) ? node->argi(6) : -1;
			t = node->hasArg(7) ? node->argi(7) : -1;
			xw = node->hasArg(8) ? node->argi(8) : 0;
			xh = node->hasArg(9) ? node->argi(9) : 0;
			rv.set(VTypes::WidgetData, ptr->addDoubleSpin(node->argc(0), node->argc(1), node->argd(2), node->argd(3), node->argd(4), node->argd(5), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddEdit):
			l = node->hasArg(3) ? node->argi(3) : -1;
			t = node->hasArg(4) ? node->argi(4) : -1;
			xw = node->hasArg(5) ? node->argi(5) : 0;
			xh = node->hasArg(6) ? node->argi(6) : 0;
			rv.set(VTypes::WidgetData, ptr->addEdit(node->argc(0), node->argc(1), node->argc(2), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddFrame):
			l = node->hasArg(1) ? node->argi(1) : -1;
			t = node->hasArg(2) ? node->argi(2) : -1;
			xw = node->hasArg(3) ? node->argi(3) : 0;
			xh = node->hasArg(4) ? node->argi(4) : 0;
			rv.set(VTypes::WidgetData, ptr->addFrame(node->argc(0), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddGroup):
			l = node->hasArg(2) ? node->argi(2) : -1;
			t = node->hasArg(3) ? node->argi(3) : -1;
			xw = node->hasArg(4) ? node->argi(4) : 0;
			xh = node->hasArg(5) ? node->argi(5) : 0;
			rv.set(VTypes::WidgetData, ptr->addGroup(node->argc(0), node->argc(1), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddIntegerSpin):
			l = node->hasArg(6) ? node->argi(6) : -1;
			t = node->hasArg(7) ? node->argi(7) : -1;
			xw = node->hasArg(8) ? node->argi(8) : 0;
			xh = node->hasArg(9) ? node->argi(9) : 0;
			rv.set(VTypes::WidgetData, ptr->addIntegerSpin(node->argc(0), node->argc(1), node->argi(2), node->argi(3), node->argi(4), node->argi(5), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddLabel):
			l = node->hasArg(2) ? node->argi(2) : -1;
			t = node->hasArg(3) ? node->argi(3) : -1;
			xw = node->hasArg(4) ? node->argi(4) : 0;
			xh = node->hasArg(5) ? node->argi(5) : 0;
			rv.set(VTypes::WidgetData, ptr->addLabel(node->argc(0), node->argc(1), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddPage):
			rv.set(VTypes::WidgetData, ptr->addPage(node->argc(0), node->argc(1)));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddRadioButton):
			l = node->hasArg(4) ? node->argi(4) : -1;
			t = node->hasArg(5) ? node->argi(5) : -1;
			xw = node->hasArg(6) ? node->argi(6) : 0;
			xh = node->hasArg(7) ? node->argi(7) : 0;
			rv.set(VTypes::WidgetData, ptr->addRadioButton(node->argc(0), node->argc(1), node->argc(2), node->argi(3), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddRadioGroup):
			rv.set(VTypes::WidgetData, ptr->addRadioGroup(node->argc(0)));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddSpacer):
			l = node->hasArg(2) ? node->argi(2) : -1;
			t = node->hasArg(3) ? node->argi(3) : -1;
			xw = node->hasArg(4) ? node->argi(4) : 0;
			xh = node->hasArg(5) ? node->argi(5) : 0;
			if (!ptr->addSpacer(node->argb(0), node->argb(1), l, t, xw, xh))  result = false;
			rv.reset();
			break;
		case (WidgetVariable::AddStack):
			l = node->hasArg(1) ? node->argi(1) : -1;
			t = node->hasArg(2) ? node->argi(2) : -1;
			xw = node->hasArg(3) ? node->argi(3) : 0;
			xh = node->hasArg(4) ? node->argi(4) : 0;
			rv.set(VTypes::WidgetData, ptr->addStack(node->argc(0), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::AddTabs):
			l = node->hasArg(1) ? node->argi(1) : -1;
			t = node->hasArg(2) ? node->argi(2) : -1;
			xw = node->hasArg(3) ? node->argi(3) : 0;
			xh = node->hasArg(4) ? node->argi(4) : 0;
			rv.set(VTypes::WidgetData, ptr->addTabs(node->argc(0), l, t, xw, xh));
			if (rv.asPointer(VTypes::WidgetData) == NULL) result = false;
			break;
		case (WidgetVariable::OnDouble):
		case (WidgetVariable::OnInteger):
			rv.reset();
			// Check supplied parameters
			result = false;
			eventType = TreeGuiWidgetEvent::eventType(node->argc(2), true);
			if (eventType == TreeGuiWidgetEvent::nEventTypes) break;
			targetWidget = ptr->parent()->findWidget(node->argc(3));
			if (targetWidget == NULL)
			{
				Messenger::print("Error: No widget named '%s' is defined in the current dialog.", qPrintable(node->argc(3)));
				break;
			}
			eventProperty = TreeGuiWidgetEvent::eventProperty(node->argc(4), true);
			if (eventProperty == TreeGuiWidgetEvent::nEventProperties) break;
			event = ptr->addEvent(eventType, targetWidget, eventProperty);
			// Set qualifying value or range
			if (i == WidgetVariable::OnDouble) event->setQualifiers(node->argd(0), node->argd(1));
			else event->setQualifiers(node->argi(0), node->argi(1));
			// If a specific value(s) were supplied, store it. Otherwise the widget's current value will be sent
			if (node->hasArg(5))
			{
				// Can't set more than one value for an onDouble event
				if (i == WidgetVariable::OnDouble)
				{
					if (node->hasArg(6))
					{
						Messenger::print("Error: Can't set more than one send value for an 'onDouble' event.");
						result = false;
					}
					else
					{
						ReturnValue *sendValue = event->addSendValue();
						node->arg(5, *sendValue);
					}
				}
				else
				{
					// Values corresponding to each valid integer in the range may have been supplied
					int range = node->argi(1) - node->argi(0) + 1;
					for (int n = 0; n<range; ++n)
					{
						if (!node->hasArg(5+n)) break;
						ReturnValue *sendValue = event->addSendValue();
						node->arg(5+n, *sendValue);
					}
					// Check number of sendvalues supplied
					if ((event->nSendValues() != 1) && (event->nSendValues() != range))
					{
						Messenger::print("Error: %s values (%i) supplied to 'onRange' function, based on integer range provided (expected (%i).", (event->nSendValues() < range ? "Not enough" : "Too many"), event->nSendValues(), range);
						result = false;
						break;
					}
				}
			
			}
			result = true;
			break;
		case (WidgetVariable::OnString):
			rv.reset();
			// Check supplied parameters
			result = false;
			eventType = TreeGuiWidgetEvent::eventType(node->argc(1), true);
			if (eventType == TreeGuiWidgetEvent::nEventTypes) break;
			targetWidget = ptr->parent()->findWidget(node->argc(2));
			if (targetWidget == NULL)
			{
				Messenger::print("Error: No widget named '%s' is defined in the current dialog.", qPrintable(node->argc(2)));
				break;
			}
			eventProperty = TreeGuiWidgetEvent::eventProperty(node->argc(3), true);
			if (eventProperty == TreeGuiWidgetEvent::nEventProperties) break;
			event = ptr->addEvent(eventType, targetWidget, eventProperty);
			// Set qualifying value
			event->setQualifiers(node->argc(0));
			// If a specific value was supplied, store it. Otherwise the widget's current value will be sent
			if (node->hasArg(4))
			{
				ReturnValue *sendValue = event->addSendValue();
				node->arg(4, *sendValue);
			}
			result = true;
			break;
		case (WidgetVariable::SetProperty):
			eventProperty = TreeGuiWidgetEvent::eventProperty(node->argc(0), true);
			if (eventProperty == TreeGuiWidgetEvent::nEventProperties) break;
			if (node->argType(1) == VTypes::IntegerData) value.set(node->argi(1));
			else if (node->argType(1) == VTypes::DoubleData) value.set(node->argd(1));
			else value.set(node->argc(1));
			result = ptr->setProperty(eventProperty, value);
			break;
		default:
			printf("Internal Error: Access to function '%s' has not been defined in WidgetVariable.\n", qPrintable(functionData[i].name));
			result = false;
			break;
	}
	Messenger::exit("WidgetVariable::performFunction");
	return result;
}