コード例 #1
0
ファイル: CustomModel.cpp プロジェクト: nerd-toolkit/nerd
void CustomModel::createModel(bool ignorePhysicsManager) {

	QString pathName = "/";
	pathName = pathName.append(getName());

	for(QListIterator<SimObject*> i(mSimObjects); i.hasNext();) {
		SimObject *object = i.next();
		object->setName(object->getName().prepend("/"));

		if(!ignorePhysicsManager) {
			QList<Value*> parameters = object->getParameters();
			for(QListIterator<Value*> j(parameters); j.hasNext();) {
				StringValue *stringValue = dynamic_cast<StringValue*>(j.next());
				if(stringValue != 0) {
					if(stringValue->get().contains("$name$")) {
						QString replacedString = stringValue->get().replace("$name$", pathName);
						stringValue->set(replacedString);
					}
				}
			}
		}
		mAgent->addObject(object);
	}

	if(!ignorePhysicsManager) {
		Physics::getPhysicsManager()->addSimObjectGroup(mAgent);
	}
	else {
		delete mAgent;
	}
}
コード例 #2
0
ファイル: CustomModel.cpp プロジェクト: nerd-toolkit/nerd
void CustomModel::addSimObjectPrefix(const QString &prefix) {

	QList<StringValue*> stringValues;

	QHash<QString, QString> nameLookup;
	for(QListIterator<SimObject*> i(mSimObjects); i.hasNext();) {
		SimObject *object = i.next();
		QString name = object->getName();
		object->setName(prefix + name);
		Core::log("Renaming: " + name + " with " + prefix + " to " + object->getName(), true);
		nameLookup.insert(name, object->getName());

		QList<Value*> objectParameters = object->getParameters();
		for(QListIterator<Value*> j(objectParameters); j.hasNext();) {
			StringValue *sv = dynamic_cast<StringValue*>(j.next());
			if(sv != 0) {
				stringValues.append(sv);
			}
		}
	}
	//check if there are strings to change.
	for(QListIterator<StringValue*> i(stringValues); i.hasNext();) {
		StringValue *sv = i.next();
		QString value = sv->get();
		bool hasNameMacro = false;
		if(value.startsWith("$name$")) {
			hasNameMacro = true;
			value = value.mid(6);
		}
		if(nameLookup.contains(value)) {
			QString prefix = "";
			if(hasNameMacro) {
				prefix = "$name$/";
			}
			sv->set(prefix + nameLookup.value(value));
		}
	}
	//TODO change variable names
}