void ErcMsgList::restoreIgnoreState() noexcept { if (mXmlFile->isCreated()) return; // the XML file does not yet exist QSharedPointer<XmlDomDocument> doc = mXmlFile->parseFileAndBuildDomTree(true); XmlDomElement& root = doc->getRoot(); // reset all ignore attributes foreach (ErcMsg* ercMsg, mItems) ercMsg->setIgnored(false); // scan ignored items and set ignore attributes for (XmlDomElement* node = root.getFirstChild("ignore/item", true, false); node; node = node->getNextSibling("item")) { foreach (ErcMsg* ercMsg, mItems) { if ((ercMsg->getOwner().getErcMsgOwnerClassName() == node->getAttribute("owner_class")) && (ercMsg->getOwnerKey() == node->getAttribute("owner_key")) && (ercMsg->getMsgKey() == node->getAttribute("msg_key"))) { ercMsg->setIgnored(true); } } } }
GenCompAttributeInstance::GenCompAttributeInstance(const XmlDomElement& domElement) throw (Exception) : mKey(), mType(nullptr), mValue(), mUnit(nullptr) { mKey = domElement.getAttribute("key", true); mType = &AttributeType::fromString(domElement.getFirstChild("type", true)->getText(true)); mValue = domElement.getFirstChild("value", true)->getText(); mUnit = mType->getUnitFromString(domElement.getFirstChild("unit", true)->getText()); if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__); }
XmlDomElement* LibraryBaseElement::serializeToXmlDomElement() const throw (Exception) { bool valid = checkAttributesValidity(); Q_ASSERT(valid == true); if (!valid) throw LogicError(__FILE__, __LINE__); QScopedPointer<XmlDomElement> root(new XmlDomElement(mXmlRootNodeName)); root->setAttribute("version", APP_VERSION_MAJOR); // meta XmlDomElement* meta = root->appendChild("meta"); meta->appendTextChild("uuid", mUuid.toString()); meta->appendTextChild("version", mVersion.toStr()); meta->appendTextChild("author", mAuthor); meta->appendTextChild("created", mCreated); meta->appendTextChild("last_modified", mLastModified); foreach (const QString& locale, mNames.keys()) meta->appendTextChild("name", mNames.value(locale))->setAttribute("locale", locale); foreach (const QString& locale, mDescriptions.keys()) meta->appendTextChild("description", mDescriptions.value(locale))->setAttribute("locale", locale); foreach (const QString& locale, mKeywords.keys()) meta->appendTextChild("keywords", mKeywords.value(locale))->setAttribute("locale", locale); return root.take(); }
ComponentAttributeInstance::ComponentAttributeInstance(ComponentInstance& cmp, const XmlDomElement& domElement) throw (Exception) : QObject(&cmp), mComponentInstance(cmp), mKey(), mType(nullptr), mValue(), mUnit(nullptr) { mKey = domElement.getAttribute<QString>("key", true); mType = &AttributeType::fromString(domElement.getFirstChild("type", true)->getText<QString>(true)); mValue = domElement.getFirstChild("value", true)->getText<QString>(false); mUnit = mType->getUnitFromString(domElement.getFirstChild("unit", true)->getText<QString>(false)); if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__); }
XmlDomElement* SI_Symbol::serializeToXmlDomElement() const throw (Exception) { if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__); QScopedPointer<XmlDomElement> root(new XmlDomElement("symbol")); root->setAttribute("uuid", mUuid); root->setAttribute("component_instance", mComponentInstance->getUuid()); root->setAttribute("symbol_item", mSymbVarItem->getUuid()); XmlDomElement* position = root->appendChild("position"); position->setAttribute("x", mPosition.getX()); position->setAttribute("y", mPosition.getY()); position->setAttribute("rotation", mRotation); return root.take(); }
XmlDomElement* Component::serializeToXmlDomElement() const throw (Exception) { QScopedPointer<XmlDomElement> root(LibraryElement::serializeToXmlDomElement()); root->getFirstChild("meta", true)->appendTextChild("generic_component", mGenericComponentUuid); root->getFirstChild("meta", true)->appendTextChild("package", mPackageUuid); XmlDomElement* padSignalMap = root->appendChild("pad_signal_map"); foreach (const QUuid& padUuid, mPadSignalMap.keys()) { XmlDomElement* child = padSignalMap->appendChild("map"); child->setAttribute("pad", padUuid); child->setAttribute("signal", mPadSignalMap.value(padUuid)); } return root.take(); }
XmlDomElement* DeviceInstance::serializeToXmlDomElement() const throw (Exception) { if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__); QScopedPointer<XmlDomElement> root(new XmlDomElement("device_instance")); root->setAttribute("component_instance", mCompInstance->getUuid()); root->setAttribute("device", mLibDevice->getUuid()); root->setAttribute("footprint", mLibFootprint->getUuid()); root->appendChild(mFootprint->serializeToXmlDomElement()); XmlDomElement* position = root->appendChild("position"); position->setAttribute("x", mPosition.getX()); position->setAttribute("y", mPosition.getY()); position->setAttribute("rotation", mRotation); position->setAttribute("mirror", mIsMirrored); return root.take(); }
XmlDomElement* Footprint::serializeToXmlDomElement() const throw (Exception) { QScopedPointer<XmlDomElement> root(LibraryElement::serializeToXmlDomElement()); XmlDomElement* geometry = root->appendChild("geometry"); foreach (const FootprintPolygon* polygon, mPolygons) geometry->appendChild(polygon->serializeToXmlDomElement()); foreach (const FootprintText* text, mTexts) geometry->appendChild(text->serializeToXmlDomElement()); foreach (const FootprintEllipse* ellipse, mEllipses) geometry->appendChild(ellipse->serializeToXmlDomElement()); foreach (const FootprintHole_t* hole, mHoles) { XmlDomElement* child = geometry->appendChild("hole"); child->setAttribute("x", hole->pos.getX()); child->setAttribute("y", hole->pos.getY()); child->setAttribute("diameter", hole->diameter); }
FootprintText::FootprintText(const XmlDomElement& domElement) throw (Exception) { mLayerId = domElement.getAttribute<uint>("layer"); // use "uint" to automatically check for >= 0 mText = domElement.getAttribute("text", true); // load geometry attributes mPosition.setX(domElement.getAttribute<Length>("x")); mPosition.setY(domElement.getAttribute<Length>("y")); mRotation = domElement.getAttribute<Angle>("rotation"); mHeight = domElement.getAttribute<Length>("height"); // text alignment mAlign.setH(domElement.getAttribute<HAlign>("h_align")); mAlign.setV(domElement.getAttribute<VAlign>("v_align")); if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__); }
void LibraryBaseElement::parseDomTree(const XmlDomElement& root) throw (Exception) { Q_ASSERT(mDomTreeParsed == false); // read attributes mUuid = root.getFirstChild("meta/uuid", true, true)->getText<QUuid>(); mVersion = root.getFirstChild("meta/version", true, true)->getText<Version>(); mAuthor = root.getFirstChild("meta/author", true, true)->getText(); mCreated = root.getFirstChild("meta/created", true, true)->getText<QDateTime>(); mLastModified = root.getFirstChild("meta/last_modified", true, true)->getText<QDateTime>(); // read names, descriptions and keywords in all available languages readLocaleDomNodes(*root.getFirstChild("meta", true), "name", mNames); readLocaleDomNodes(*root.getFirstChild("meta", true), "description", mDescriptions); readLocaleDomNodes(*root.getFirstChild("meta", true), "keywords", mKeywords); mDomTreeParsed = true; }
XmlDomElement* Symbol::serializeToXmlDomElement() const throw (Exception) { QScopedPointer<XmlDomElement> root(LibraryElement::serializeToXmlDomElement()); XmlDomElement* pins = root->appendChild("pins"); foreach (const SymbolPin* pin, mPins) pins->appendChild(pin->serializeToXmlDomElement()); XmlDomElement* geometry = root->appendChild("geometry"); foreach (const Polygon* polygon, mPolygons) geometry->appendChild(polygon->serializeToXmlDomElement()); foreach (const Text* text, mTexts) geometry->appendChild(text->serializeToXmlDomElement()); foreach (const Ellipse* ellipse, mEllipses) geometry->appendChild(ellipse->serializeToXmlDomElement()); return root.take(); }
XmlDomElement* ErcMsgList::serializeToXmlDomElement() const throw (Exception) { if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__); QScopedPointer<XmlDomElement> root(new XmlDomElement("erc")); XmlDomElement* ignoreNode = root->appendChild("ignore"); foreach (ErcMsg* ercMsg, mItems) { if (ercMsg->isIgnored()) { XmlDomElement* itemNode = ignoreNode->appendChild("item"); itemNode->setAttribute("owner_class", ercMsg->getOwner().getErcMsgOwnerClassName()); itemNode->setAttribute("owner_key", ercMsg->getOwnerKey()); itemNode->setAttribute("msg_key", ercMsg->getMsgKey()); } } return root.take(); }
void Symbol::parseDomTree(const XmlDomElement& root) throw (Exception) { LibraryElement::parseDomTree(root); // Load all pins for (XmlDomElement* node = root.getFirstChild("pins/pin", true, false); node; node = node->getNextSibling("pin")) { SymbolPin* pin = new SymbolPin(*node); if (mPins.contains(pin->getUuid())) { throw RuntimeError(__FILE__, __LINE__, pin->getUuid().toStr(), QString(tr("The pin \"%1\" exists multiple times in \"%2\".")) .arg(pin->getUuid().toStr(), mXmlFilepath.toNative())); } mPins.insert(pin->getUuid(), pin); } // Load all geometry elements for (XmlDomElement* node = root.getFirstChild("geometry/*", true, false); node; node = node->getNextSibling()) { if (node->getName() == "polygon") { mPolygons.append(new Polygon(*node)); } else if (node->getName() == "text") { mTexts.append(new Text(*node)); } else if (node->getName() == "ellipse") { mEllipses.append(new Ellipse(*node)); } else { throw RuntimeError(__FILE__, __LINE__, node->getName(), QString(tr("Unknown geometry element \"%1\" in \"%2\".")) .arg(node->getName(), mXmlFilepath.toNative())); } } }
void Footprint::parseDomTree(const XmlDomElement& root) throw (Exception) { LibraryElement::parseDomTree(root); // Load all pads for (XmlDomElement* node = root.getFirstChild("pads/pad", true, false); node; node = node->getNextSibling("pad")) { FootprintPad* pad = new FootprintPad(*node); if (mPads.contains(pad->getUuid())) { throw RuntimeError(__FILE__, __LINE__, pad->getUuid().toString(), QString(tr("The pad \"%1\" exists multiple times in \"%2\".")) .arg(pad->getUuid().toString(), mXmlFilepath.toNative())); } mPads.insert(pad->getUuid(), pad); } // Load all geometry elements for (XmlDomElement* node = root.getFirstChild("geometry/*", true, false); node; node = node->getNextSibling()) { if (node->getName() == "polygon") { mPolygons.append(new FootprintPolygon(*node)); } else if (node->getName() == "text") { mTexts.append(new FootprintText(*node)); } else if (node->getName() == "ellipse") { mEllipses.append(new FootprintEllipse(*node)); } else if (node->getName() == "hole") { FootprintHole_t* hole = new FootprintHole_t(); hole->pos.setX(node->getAttribute<Length>("x", true)); hole->pos.setY(node->getAttribute<Length>("y", true)); hole->diameter = node->getAttribute<Length>("diameter", true); mHoles.append(hole); } else { throw RuntimeError(__FILE__, __LINE__, node->getName(), QString(tr("Unknown geometry element \"%1\" in \"%2\".")) .arg(node->getName(), mXmlFilepath.toNative())); } } }
GridProperties::GridProperties(const XmlDomElement& domElement) noexcept { mType = stringToType(domElement.getAttribute("type", true)); mInterval = domElement.getAttribute<Length>("interval", true); mUnit = LengthUnit::fromString(domElement.getAttribute("unit", true)); }
void LibraryBaseElement::readLocaleDomNodes(const XmlDomElement& parentNode, const QString& childNodesName, QMap<QString, QString>& list) throw (Exception) { for (XmlDomElement* node = parentNode.getFirstChild(childNodesName, false); node; node = node->getNextSibling(childNodesName)) { QString locale = node->getAttribute("locale", true); if (locale.isEmpty()) { throw RuntimeError(__FILE__, __LINE__, parentNode.getDocFilePath().toStr(), QString(tr("Entry without locale found in \"%1\".")) .arg(parentNode.getDocFilePath().toNative())); } if (list.contains(locale)) { throw RuntimeError(__FILE__, __LINE__, parentNode.getDocFilePath().toStr(), QString(tr("Locale \"%1\" defined multiple times in \"%2\".")) .arg(locale, parentNode.getDocFilePath().toNative())); } list.insert(locale, node->getText()); } if (!list.contains("en_US")) { throw RuntimeError(__FILE__, __LINE__, parentNode.getDocFilePath().toStr(), QString( tr("At least one entry in \"%1\" has no translation for locale \"en_US\".")) .arg(parentNode.getDocFilePath().toNative())); } }