bool FixtureManager::addFixture(QString manuf, QString model, QString mode, QString name, int uniIdx, int address, int channels, int quantity, quint32 gap, qreal xPos, qreal yPos) { qDebug() << Q_FUNC_INFO << manuf << model << quantity; QLCFixtureDef *fxiDef = m_doc->fixtureDefCache()->fixtureDef(manuf, model); Q_ASSERT(fxiDef != NULL); QLCFixtureMode *fxiMode = fxiDef->mode(mode); Q_ASSERT(fxiMode != NULL); for (int i = 0; i < quantity; i++) { Fixture *fxi = new Fixture(m_doc); /* If we're adding more than one fixture, append a number to the end of the name */ if (quantity > 1) fxi->setName(QString("%1 #%2").arg(name).arg(i + 1)); else fxi->setName(name); fxi->setAddress(address + (i * channels) + (i * gap)); fxi->setUniverse(uniIdx); fxi->setFixtureDefinition(fxiDef, fxiMode); m_doc->addFixture(fxi); emit newFixtureCreated(fxi->id(), xPos, yPos); } m_fixtureList.clear(); m_fixtureList = m_doc->fixtures(); emit fixturesCountChanged(); return true; }
bool Doc::replaceFixtures(QList<Fixture*> newFixturesList) { // Delete all fixture instances QListIterator <quint32> fxit(m_fixtures.keys()); while (fxit.hasNext() == true) { Fixture* fxi = m_fixtures.take(fxit.next()); delete fxi; m_fixturesListCacheUpToDate = false; } m_latestFixtureId = 0; m_addresses.clear(); foreach(Fixture *fixture, newFixturesList) { quint32 id = fixture->id(); // create a copy of the original cause remapping will // destroy it later Fixture *newFixture = new Fixture(this); newFixture->setID(id); newFixture->setName(fixture->name()); newFixture->setAddress(fixture->address()); newFixture->setUniverse(fixture->universe()); if (fixture->fixtureDef() == NULL || (fixture->fixtureDef()->manufacturer() == KXMLFixtureGeneric && fixture->fixtureDef()->model() == KXMLFixtureGeneric)) { newFixture->setChannels(fixture->channels()); } else { QLCFixtureDef *def = fixtureDefCache()->fixtureDef(fixture->fixtureDef()->manufacturer(), fixture->fixtureDef()->model()); QLCFixtureMode *mode = NULL; if (def != NULL) mode = def->mode(fixture->fixtureMode()->name()); newFixture->setFixtureDefinition(def, mode); } newFixture->setExcludeFadeChannels(fixture->excludeFadeChannels()); m_fixtures.insert(id, newFixture); m_fixturesListCacheUpToDate = false; /* Patch fixture change signals thru Doc */ connect(newFixture, SIGNAL(changed(quint32)), this, SLOT(slotFixtureChanged(quint32))); /* Keep track of fixture addresses */ for (uint i = newFixture->universeAddress(); i < newFixture->universeAddress() + newFixture->channels(); i++) { m_addresses[i] = id; } m_latestFixtureId = id; }
void QLCFixtureDef_Test::mode() { QLCFixtureDef* fd = new QLCFixtureDef(); QLCFixtureMode* mode1 = new QLCFixtureMode(fd); mode1->setName("foo"); fd->addMode(mode1); QLCFixtureMode* mode2 = new QLCFixtureMode(fd); mode2->setName("bar"); fd->addMode(mode2); QLCFixtureMode* mode3 = new QLCFixtureMode(fd); mode3->setName("xyzzy"); fd->addMode(mode3); QVERIFY(fd->mode("foo") == mode1); QVERIFY(fd->mode("bar") == mode2); QVERIFY(fd->mode("xyzzy") == mode3); QVERIFY(fd->mode("foobar") == NULL); delete fd; }
void ChaserRunner_Test::init() { QLCFixtureDef* def = m_doc->fixtureDefCache()->fixtureDef("Futurelight", "DJScan250"); QVERIFY(def != NULL); QLCFixtureMode* mode = def->mode("Mode 1"); QVERIFY(mode != NULL); Fixture* fxi = new Fixture(m_doc); QVERIFY(fxi != NULL); fxi->setFixtureDefinition(def, mode); fxi->setName("Test Fixture"); fxi->setAddress(0); fxi->setUniverse(0); m_doc->addFixture(fxi); m_scene1 = new Scene(m_doc); m_scene1->setName("S1"); QVERIFY(m_scene1 != NULL); for (quint32 i = 0; i < fxi->channels(); i++) m_scene1->setValue(fxi->id(), i, 255 - i); m_doc->addFunction(m_scene1); m_scene2 = new Scene(m_doc); m_scene2->setName("S2"); QVERIFY(m_scene2 != NULL); for (quint32 i = 0; i < fxi->channels(); i++) m_scene2->setValue(fxi->id(), i, 127 - i); m_doc->addFunction(m_scene2); m_scene3 = new Scene(m_doc); m_scene3->setName("S3"); QVERIFY(m_scene3 != NULL); for (quint32 i = 0; i < fxi->channels(); i++) m_scene3->setValue(fxi->id(), i, 0 + i); m_doc->addFunction(m_scene3); m_chaser = new Chaser(m_doc); m_chaser->addStep(ChaserStep(m_scene1->id())); m_chaser->addStep(ChaserStep(m_scene2->id())); m_chaser->addStep(ChaserStep(m_scene3->id())); }
bool Fixture::loadXML(const QDomElement& root, Doc *doc, const QLCFixtureDefCache* fixtureDefCache) { QLCFixtureDef* fixtureDef = NULL; QLCFixtureMode* fixtureMode = NULL; QString manufacturer; QString model; QString modeName; QString name; quint32 id = Fixture::invalidId(); quint32 universe = 0; quint32 address = 0; quint32 channels = 0; quint32 width = 0, height = 0; QList<int> excludeList; QList<int> forcedHTP; QList<int> forcedLTP; QList<quint32>modifierIndices; QList<ChannelModifier *>modifierPointers; if (root.tagName() != KXMLFixture) { qWarning() << Q_FUNC_INFO << "Fixture node not found"; return false; } QDomNode node = root.firstChild(); while (node.isNull() == false) { QDomElement tag = node.toElement(); if (tag.tagName() == KXMLQLCFixtureDefManufacturer) { manufacturer = tag.text(); } else if (tag.tagName() == KXMLQLCFixtureDefModel) { model = tag.text(); } else if (tag.tagName() == KXMLQLCFixtureMode) { modeName = tag.text(); } else if (tag.tagName() == KXMLQLCPhysicalDimensionsWeight) { width = tag.text().toUInt(); } else if (tag.tagName() == KXMLQLCPhysicalDimensionsHeight) { height = tag.text().toUInt(); } else if (tag.tagName() == KXMLFixtureID) { id = tag.text().toUInt(); } else if (tag.tagName() == KXMLFixtureName) { name = tag.text(); } else if (tag.tagName() == KXMLFixtureUniverse) { universe = tag.text().toInt(); } else if (tag.tagName() == KXMLFixtureAddress) { address = tag.text().toInt(); } else if (tag.tagName() == KXMLFixtureChannels) { channels = tag.text().toInt(); } else if (tag.tagName() == KXMLFixtureExcludeFade) { QString list = tag.text(); QStringList values = list.split(","); for (int i = 0; i < values.count(); i++) excludeList.append(values.at(i).toInt()); } else if (tag.tagName() == KXMLFixtureForcedHTP) { QString list = tag.text(); QStringList values = list.split(","); for (int i = 0; i < values.count(); i++) forcedHTP.append(values.at(i).toInt()); } else if (tag.tagName() == KXMLFixtureForcedLTP) { QString list = tag.text(); QStringList values = list.split(","); for (int i = 0; i < values.count(); i++) forcedLTP.append(values.at(i).toInt()); } else if (tag.tagName() == KXMLFixtureChannelModifier) { if (tag.hasAttribute(KXMLFixtureChannelIndex) && tag.hasAttribute(KXMLFixtureModifierName)) { quint32 chIdx = tag.attribute(KXMLFixtureChannelIndex).toUInt(); QString modName = tag.attribute(KXMLFixtureModifierName); ChannelModifier *chMod = doc->modifiersCache()->modifier(modName); if (chMod != NULL) { modifierIndices.append(chIdx); modifierPointers.append(chMod); } } } else { qWarning() << Q_FUNC_INFO << "Unknown fixture tag:" << tag.tagName(); } node = node.nextSibling(); } /* Find the given fixture definition, unless its a generic dimmer */ if (model != KXMLFixtureGeneric && model != KXMLFixtureRGBPanel) { fixtureDef = fixtureDefCache->fixtureDef(manufacturer, model); if (fixtureDef == NULL) { doc->appendToErrorLog(QString("No fixture definition found for <%1> <%2>") .arg(manufacturer) .arg(model)); } else { /* Find the given fixture mode */ fixtureMode = fixtureDef->mode(modeName); if (fixtureMode == NULL) { doc->appendToErrorLog(QString("Fixture mode <%1> not found for <%2> <%3>") .arg(modeName).arg(manufacturer).arg(model)); /* Set this also NULL so that a generic dimmer will be created instead as a backup. */ fixtureDef = NULL; } } } /* Number of channels */ if (channels <= 0) { doc->appendToErrorLog(QString("%1 channels of fixture <%2> are our of bounds") .arg(QString::number(channels)) .arg(name)); channels = 1; } /* Make sure that address is something sensible */ if (address > 511 || address + (channels - 1) > 511) { doc->appendToErrorLog(QString("Fixture address range %1-%2 is out of DMX bounds") .arg(QString::number(address)) .arg(QString::number(address + channels - 1))); address = 0; } /* Check that the invalid ID is not used */ if (id == Fixture::invalidId()) { qWarning() << Q_FUNC_INFO << "Fixture ID" << id << "is not allowed."; return false; } if (model == KXMLFixtureRGBPanel) { Components components = RGB; int compNum = 3; if (modeName == "BGR") { components = BGR; } else if (modeName == "RGBW") { components = RGBW; compNum = 4; } else if (modeName == "RGBWW") { components = RGBWW; compNum = 5; } fixtureDef = genericRGBPanelDef(channels / compNum, components); fixtureMode = genericRGBPanelMode(fixtureDef, components, width, height); } if (fixtureDef != NULL && fixtureMode != NULL) { /* Assign fixtureDef & mode only if BOTH are not NULL */ setFixtureDefinition(fixtureDef, fixtureMode); } else { /* Otherwise set just the channel count */ setChannels(channels); } setAddress(address); setUniverse(universe); setName(name); setExcludeFadeChannels(excludeList); setForcedHTPChannels(forcedHTP); setForcedLTPChannels(forcedLTP); for (int i = 0; i < modifierIndices.count(); i++) setChannelModifier(modifierIndices.at(i), modifierPointers.at(i)); setID(id); return true; }
Fixture* Fixture::loader(QDomDocument* doc, QDomElement* root) { Fixture* fxi = NULL; QLCFixtureDef* fixtureDef = NULL; QLCFixtureMode* fixtureMode = NULL; QString manufacturer; QString model; QString modeName; QString name; t_fixture_id id = KNoID; t_channel universe = 0; t_channel address = 0; t_channel channels = 0; QDomNode node; QDomElement tag; QDomElement consoletag; Q_ASSERT(doc != NULL); Q_ASSERT(root != NULL); if (root->tagName() != KXMLFixture) { qWarning("Fixture instance node not found!"); return NULL; } node = root->firstChild(); while (node.isNull() == false) { tag = node.toElement(); if (tag.tagName() == KXMLQLCFixtureDefManufacturer) { manufacturer = tag.text(); } else if (tag.tagName() == KXMLQLCFixtureDefModel) { model = tag.text(); } else if (tag.tagName() == KXMLQLCFixtureMode) { modeName = tag.text(); } else if (tag.tagName() == KXMLFixtureID) { id = tag.text().toInt(); } else if (tag.tagName() == KXMLFixtureName) { name = tag.text(); } else if (tag.tagName() == KXMLFixtureUniverse) { universe = tag.text().toInt(); } else if (tag.tagName() == KXMLFixtureAddress) { address = tag.text().toInt(); } else if (tag.tagName() == KXMLFixtureChannels) { channels = tag.text().toInt(); } else if (tag.tagName() == KXMLQLCFixtureConsole) { consoletag = tag; } else { qDebug("Unknown fixture instance tag: %s", (const char*) tag.tagName()); } node = node.nextSibling(); } /* Find the given fixture definition */ fixtureDef = _app->fixtureDef(manufacturer, model); if (fixtureDef == NULL) { qWarning("Fixture definition for [%s - %s] not found!", (const char*) manufacturer, (const char*) model); } else { /* Find the given fixture mode */ fixtureMode = fixtureDef->mode(modeName); if (fixtureMode == NULL) { qWarning("Fixture mode [%s] for [%s - %s] not found!", (const char*) modeName, (const char*) manufacturer, (const char*) model); } } /* Number of channels */ if (channels <= 0 || channels > KFixtureChannelsMax) { qWarning("Fixture <%s> channels %d out of bounds (%d - %d)!", (const char*) name, channels, 1, KFixtureChannelsMax); channels = 1; } /* Make sure that address is something sensible */ if (address > 511 || address + (channels - 1) > 511) { qWarning("Fixture channel range %d - %d out of DMX " \ "bounds (%d - %d)!", address + 1, address + channels, 1, 512); address = 0; } /* Make sure that universe is something sensible */ if (universe > KUniverseCount) { qWarning("Fixture universe %d out of bounds (%d - %d)!", universe, 0, KUniverseCount); universe = 0; } /* Check that we have a sensible ID, otherwise we can't continue */ if (id < 0 || id > KFixtureArraySize) { qWarning("Fixture ID %d out of bounds (%d - %d)!", id, 0, KFixtureArraySize); return NULL; } /* Create the fixture */ if (fixtureDef != NULL && fixtureMode != NULL) { /* Create a normal fixture */ fxi = new Fixture(fixtureDef, fixtureMode, address, universe, name, id); } else { /* Create a generic fixture */ fxi = new Fixture(address, universe, channels, name, id); } /* Insert the fixture to Doc's fixture array */ if (_app->doc()->newFixture(fxi) == false) { delete fxi; fxi = NULL; } else { /* Load the fixture's console settings */ if (consoletag.tagName() == KXMLQLCFixtureConsole) { if (fxi->createConsole() == true) fxi->m_console->loadXML(doc, &tag); } } return fxi; }