示例#1
0
void TwoDModelScene::deleteSelectedItems()
{
	QStringList worldItemsToDelete;
	QList<QPair<model::RobotModel *, kitBase::robotModel::PortInfo>> sensorsToDelete;
	for (QGraphicsItem * const item : selectedItems()) {
		SensorItem * const sensor = dynamic_cast<SensorItem *>(item);
		items::WallItem * const wall = dynamic_cast<items::WallItem *>(item);
		items::ColorFieldItem * const colorField = dynamic_cast<items::ColorFieldItem *>(item);
		items::ImageItem * const image = dynamic_cast<items::ImageItem *>(item);

		if (sensor && !mSensorsReadOnly) {
			for (RobotItem * const robotItem : mRobots.values()) {
				const kitBase::robotModel::PortInfo port = robotItem->sensors().key(sensor);
				if (port.isValid()) {
					sensorsToDelete << qMakePair(&robotItem->robotModel(), port);
				}
			}
		} else if (wall && !mWorldReadOnly) {
			worldItemsToDelete << wall->id();
			mCurrentWall = nullptr;
		} else if (colorField && !mWorldReadOnly) {
			worldItemsToDelete << colorField->id();
			mCurrentLine = nullptr;
			mCurrentStylus = nullptr;
			mCurrentEllipse = nullptr;
			mCurrentRectangle = nullptr;
			mCurrentCurve = nullptr;
		} else if (image && !mWorldReadOnly) {
			mModel.worldModel().removeImage(image);
		}
	}

	deleteWithCommand(worldItemsToDelete, sensorsToDelete, {});
}
QString ReservedVariablesConverter::deviceExpression(const kitBase::robotModel::PortInfo &port) const
{
	const kitBase::robotModel::DeviceInfo device = mDevices[port];
	if (device.isNull()) {
		mErrorReporter.addError(QObject::tr("Device on port %1 is not configured."\
				" Please select it on the \"Configure devices\" panel on the right-hand side.")
						.arg(port.userFriendlyName())
		);
		return QObject::tr("/* ERROR: SELECT DEVICE TYPE */");
	}

	const QString templatePath = mDeviceVariables.variableTemplatePath(device, port);

	// Converter must take a string like "1" or "2" (and etc) and return correct value
	return readTemplate(templatePath).replace("@@PORT@@", mInputConverter->convert(port.name()));
}
示例#3
0
QString Sensors::code(const QString &directory
		, const kitBase::robotModel::PortInfo &port
		, const kitBase::robotModel::DeviceInfo &device)
{
	const QString portString = mInputPortConverter->convert(port.name());
	const QString templatePath = QString("%1/%2.t").arg(directory, device.name());
	return readTemplateIfExists(templatePath).replace("@@PORT@@", portString);
}
示例#4
0
QString TrikDeviceVariables::variableTemplatePath(const kitBase::robotModel::DeviceInfo &device
		, const kitBase::robotModel::PortInfo &port) const
{
	if (device.name() == "trikLineSensor"
			|| device.name() == "trikObjectSensor"
			|| device.name() == "trikColorSensor")
	{
		QString templateName = port.name();
		templateName.remove("Port");
		return "videosensors/" + templateName + ".t";
	} else if (device.name() == "gyroscope" || device.name() == "accelerometer") {
		return QString("%1/%2.t").arg(device.name(), port.reservedVariable());
	} else if (device.name().startsWith("gamepad")) {
		return QString("gamepad/%1.t").arg(device.name());
	}

	return generatorBase::parts::DeviceVariables::variableTemplatePath(device, port);
}
示例#5
0
QString ConstraintsChecker::portName(const QString &robotId
		, model::RobotModel * const robot, const kitBase::robotModel::PortInfo &port) const
{
	// We wish to know would be there a collision if someone writes "A1" or not.
	int portsWithSuchName = 0;
	for (kitBase::robotModel::PortInfo &otherPort : robot->info().availablePorts()) {
		if (port.name() == otherPort.name()) {
			++portsWithSuchName;
		}
	}

	// Making user write "robot1.DisplayPort_out.ellipses" or "robot1.MarkerPort_out" is non-humanistic.
	// So letting him write "robot1.display.ellipses" or "robot1.marker".
	QRegExp portRegExp("^(\\w+)Port$");
	const QString readablePortName = portRegExp.exactMatch(port.name())
			? utils::StringUtils::lowercaseFirstLetter(portRegExp.cap(1))
			: port.name();

	return portsWithSuchName > 1
			// If collision in name exists then user must specify what port exactly he wishes to process.
			? QString("%1.%2_%3").arg(robotId, readablePortName
					, port.direction() == kitBase::robotModel::input ? "in" : "out")
			: QString("%1.%2").arg(robotId, readablePortName);
}
示例#6
0
void TwoDModelScene::deleteItem(QGraphicsItem *item)
{
	if (!items().contains(item)) {
		return;
	}

	if (SensorItem * const sensor = dynamic_cast<SensorItem *>(item)) {
		for (RobotItem * const robotItem : mRobots.values()) {
			const kitBase::robotModel::PortInfo port = robotItem->sensors().key(sensor);
			if (port.isValid()) {
				deviceConfigurationChanged(robotItem->robotModel().info().robotId()
						, port, kitBase::robotModel::DeviceInfo(), Reason::userAction);
			}
		}
	} else if (items::WallItem * const wall = dynamic_cast<items::WallItem *>(item)) {
		mModel.worldModel().removeWall(wall);
		mCurrentWall = nullptr;
	} else if (items::ColorFieldItem *colorField = dynamic_cast<items::ColorFieldItem *>(item)) {
		mModel.worldModel().removeColorField(colorField);
		mCurrentLine = nullptr;
		mCurrentStylus = nullptr;
		mCurrentEllipse = nullptr;
	}
}
示例#7
0
NxtInputDevice::NxtInputDevice(
		utils::robotCommunication::RobotCommunicator &robotCommunicator
		, const kitBase::robotModel::PortInfo &port
		, const enums::lowLevelSensorType::SensorTypeEnum &lowLevelSensorType
		, const enums::sensorMode::SensorModeEnum &sensorMode)
	: mRobotCommunicator(robotCommunicator)
	, mLowLevelPort(port.name().at(0).toLatin1() - '1')
	, mLowLevelSensorType(lowLevelSensorType)
	, mSensorMode(sensorMode)
	, mState(idle)
	, mIsConfigured(false)
	, mResetDone(false)
{
	QObject::connect(&mRobotCommunicator, &utils::robotCommunication::RobotCommunicator::response
			, this, &NxtInputDevice::readingDone);
}
示例#8
0
char I2CCommunicator::toNxtInputPort(const kitBase::robotModel::PortInfo &port)
{
	return static_cast<char>(port.name().toInt() - 1);
}
示例#9
0
Ev3InputDevice::Ev3InputDevice(utils::robotCommunication::RobotCommunicator &robotCommunicator
		, const kitBase::robotModel::PortInfo &port)
	: mRobotCommunicator(robotCommunicator)
	, mLowLevelPort(port.name().at(0).toLatin1() - '1')
{
}
示例#10
0
QString ConstraintsChecker::portName(const QString &robotId, const kitBase::robotModel::PortInfo &port) const
{
	return QString("%1.%2_%3").arg(robotId, port.name()
			, port.direction() == kitBase::robotModel::input ? "in" : "out");
}