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; }