Exemplo n.º 1
0
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 QString& key, const AttributeType& type, const QString& value,
        const AttributeUnit* unit) throw (Exception) :
    QObject(&cmp), mComponentInstance(cmp), mKey(key), mType(&type), mValue(value),
    mUnit(unit)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);
}
Exemplo n.º 3
0
void NetSignal::serialize(SExpression& root) const {
  if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

  root.appendChild(mUuid);
  root.appendChild("auto", mHasAutoName, false);
  root.appendChild("name", mName, false);
  root.appendChild("netclass", mNetClass->getUuid(), true);
}
GenCompAttributeInstance::GenCompAttributeInstance(const QString& key,
        const AttributeType& type,
        const QString& value,
        const AttributeUnit* unit) throw (Exception) :
    mKey(key), mType(&type), mValue(value), mUnit(unit)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);
}
Exemplo n.º 5
0
XmlDomElement* ComponentSignalInstance::serializeToXmlDomElement() const throw (Exception)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    QScopedPointer<XmlDomElement> root(new XmlDomElement("map"));
    root->setAttribute("comp_signal", mComponentSignal->getUuid());
    root->setAttribute("netsignal", mNetSignal ? mNetSignal->getUuid() : Uuid());
    return root.take();
}
ComponentPinSignalMapItem::ComponentPinSignalMapItem(const XmlDomElement& domElement) throw (Exception)
{
    // read attributes
    mPinUuid = domElement.getAttribute<Uuid>("pin", true);
    mDisplayType = stringToDisplayType(domElement.getAttribute<QString>("display", true));
    mSignalUuid = domElement.getText<Uuid>(false);

    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);
}
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* ComponentPinSignalMapItem::serializeToXmlDomElement() const throw (Exception)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    QScopedPointer<XmlDomElement> root(new XmlDomElement("map"));
    root->setAttribute("pin", mPinUuid);
    root->setAttribute<QString>("display", displayTypeToString(mDisplayType));
    root->setText(mSignalUuid);
    return root.take();
}
Exemplo n.º 9
0
XmlDomElement* GridProperties::serializeToXmlDomElement() const throw (Exception)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    QScopedPointer<XmlDomElement> root(new XmlDomElement("grid_properties"));
    root->setAttribute("type", typeToString(mType));
    root->setAttribute("interval", mInterval);
    root->setAttribute("unit", mUnit);
    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__);
}
Exemplo n.º 11
0
XmlDomElement* GenCompAttributeInstance::serializeToXmlDomElement() const throw (Exception)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    QScopedPointer<XmlDomElement> root(new XmlDomElement("attribute"));
    root->setAttribute("key", mKey);
    root->appendTextChild("type", mType->getName());
    root->appendTextChild("value", mValue);
    root->appendTextChild("unit", mUnit ? mUnit->getName() : "");
    return root.take();
}
Exemplo n.º 12
0
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();
}
Exemplo n.º 13
0
FootprintEllipse::FootprintEllipse(const XmlDomElement& domElement) throw (Exception)
{
    mLayerId = domElement.getAttribute<uint>("layer"); // use "uint" to automatically check for >= 0
    mLineWidth = domElement.getAttribute<Length>("width");
    mIsFilled = domElement.getAttribute<bool>("fill");
    mIsGrabArea = domElement.getAttribute<bool>("grab_area");
    mCenter.setX(domElement.getAttribute<Length>("x"));
    mCenter.setY(domElement.getAttribute<Length>("y"));
    mRadiusX = domElement.getAttribute<Length>("radius_x");
    mRadiusY = domElement.getAttribute<Length>("radius_y");
    mRotation = domElement.getAttribute<Angle>("rotation");

    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);
}
Exemplo n.º 14
0
XmlDomElement* FootprintText::serializeToXmlDomElement() const throw (Exception)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    QScopedPointer<XmlDomElement> root(new XmlDomElement("text"));
    root->setAttribute("layer", mLayerId);
    root->setAttribute("text", mText);
    root->setAttribute("x", mPosition.getX().toMmString());
    root->setAttribute("y", mPosition.getY().toMmString());
    root->setAttribute("rotation", mRotation.toDegString());
    root->setAttribute("height", mHeight.toMmString());
    root->setAttribute("h_align", mAlign.getH());
    root->setAttribute("v_align", mAlign.getV());
    return root.take();
}
Exemplo n.º 15
0
XmlDomElement* FootprintEllipse::serializeToXmlDomElement() const throw (Exception)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    QScopedPointer<XmlDomElement> root(new XmlDomElement("ellipse"));
    root->setAttribute("layer", mLayerId);
    root->setAttribute("width", mLineWidth.toMmString());
    root->setAttribute("fill", mIsFilled);
    root->setAttribute("grab_area", mIsGrabArea);
    root->setAttribute("x", mCenter.getX().toMmString());
    root->setAttribute("y", mCenter.getY().toMmString());
    root->setAttribute("radius_x", mRadiusX.toMmString());
    root->setAttribute("radius_y", mRadiusY.toMmString());
    root->setAttribute("rotation", mRotation.toDegString());
    return root.take();
}
Exemplo n.º 16
0
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();
}
Exemplo n.º 17
0
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__);
}
Exemplo n.º 18
0
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();
}
Exemplo n.º 19
0
void ComponentSignalInstance::init() throw (Exception)
{
    // create ERC messages
    mErcMsgUnconnectedRequiredSignal.reset(new ErcMsg(mCircuit.getProject(), *this,
        QString("%1/%2").arg(mComponentInstance.getUuid().toStr()).arg(mComponentSignal->getUuid().toStr()),
        "UnconnectedRequiredSignal", ErcMsg::ErcMsgType_t::CircuitError, QString()));
    mErcMsgForcedNetSignalNameConflict.reset(new ErcMsg(mCircuit.getProject(), *this,
        QString("%1/%2").arg(mComponentInstance.getUuid().toStr()).arg(mComponentSignal->getUuid().toStr()),
        "ForcedNetSignalNameConflict", ErcMsg::ErcMsgType_t::SchematicError, QString()));
    updateErcMessages();

    // register to component attributes changed
    connect(&mComponentInstance, &ComponentInstance::attributesChanged,
            this, &ComponentSignalInstance::updateErcMessages);

    // register to net signal name changed
    if (mNetSignal) connect(mNetSignal, &NetSignal::nameChanged, this, &ComponentSignalInstance::netSignalNameChanged);

    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);
}
Exemplo n.º 20
0
XmlDomElement* FootprintPad::serializeToXmlDomElement() const throw (Exception)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    QScopedPointer<XmlDomElement> root(new XmlDomElement("pad"));
    root->setAttribute("uuid", mUuid);
    root->setAttribute("type", typeToString(mType));
    root->setAttribute("x", mPosition.getX().toMmString());
    root->setAttribute("y", mPosition.getY().toMmString());
    root->setAttribute("rotation", mRotation);
    root->setAttribute("width", mWidth);
    root->setAttribute("height", mHeight);
    root->setAttribute("drill", mDrillDiameter);
    root->setAttribute("layer", mLayerId);
    foreach (const QString& locale, mNames.keys())
        root->appendTextChild("name", mNames.value(locale))->setAttribute("locale", locale);
    foreach (const QString& locale, mDescriptions.keys())
        root->appendTextChild("description", mDescriptions.value(locale))->setAttribute("locale", locale);
    return root.take();
}
Exemplo n.º 21
0
void LibraryBaseElement::readFromFile() throw (Exception)
{
    Q_ASSERT(mDomTreeParsed == false);

    // check directory
    QUuid dirUuid = QUuid(mDirectory.getFilename());
    if ((!mDirectory.isExistingDir()) || (dirUuid.isNull()))
    {
        throw RuntimeError(__FILE__, __LINE__, dirUuid.toString(),
            QString(tr("Directory does not exist or is not a valid UUID: \"%1\""))
            .arg(mDirectory.toNative()));
    }

    // find the xml file with the highest file version number
    for (int version = APP_VERSION_MAJOR; version >= 0; version--)
    {
        QString filename = QString("v%1/%2.xml").arg(version).arg(mXmlFileNamePrefix);
        mXmlFilepath = mDirectory.getPathTo(filename);
        if (mXmlFilepath.isExistingFile()) break; // file found
    }

    // open XML file
    SmartXmlFile file(mXmlFilepath, false, false);
    QSharedPointer<XmlDomDocument> doc = file.parseFileAndBuildDomTree(true);
    parseDomTree(doc->getRoot());

    // check UUID
    if (mUuid != dirUuid)
    {
        throw RuntimeError(__FILE__, __LINE__,
            QString("%1/%2").arg(mUuid.toString(), dirUuid.toString()),
            QString(tr("UUID mismatch between element directory and XML file: \"%1\""))
            .arg(mXmlFilepath.toNative()));
    }

    // check attributes
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    Q_ASSERT(mDomTreeParsed == true);
}
Exemplo n.º 22
0
XmlDomElement* BI_NetPoint::serializeToXmlDomElement() const throw (Exception)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    QScopedPointer<XmlDomElement> root(new XmlDomElement("netpoint"));
    root->setAttribute("uuid", mUuid);
    root->setAttribute("layer", mLayer->getId());
    root->setAttribute("netsignal", mNetSignal->getUuid());
    if (isAttachedToPad()) {
        root->setAttribute("attached_to", QString("pad"));
        root->setAttribute("component", mFootprintPad->getFootprint().getComponentInstanceUuid());
        root->setAttribute("pad", mFootprintPad->getLibPadUuid());
    } else if (isAttachedToVia()) {
        root->setAttribute("attached_to", QString("via"));
        root->setAttribute("via", mVia->getUuid());
    } else {
        root->setAttribute("attached_to", QString("none"));
        root->setAttribute("x", mPosition.getX());
        root->setAttribute("y", mPosition.getY());
    }
    return root.take();
}
Exemplo n.º 23
0
XmlDomElement* GenCompSymbVarItem::serializeToXmlDomElement() const throw (Exception)
{
    if (!checkAttributesValidity()) throw LogicError(__FILE__, __LINE__);

    QScopedPointer<XmlDomElement> root(new XmlDomElement("item"));
    root->setAttribute("uuid", mUuid);
    root->setAttribute("symbol", mSymbolUuid);
    root->setAttribute("required", mIsRequired);
    root->setAttribute("suffix", mSuffix);
    XmlDomElement* pin_signal_map = root->appendChild("pin_signal_map");
    foreach (const PinSignalMapItem_t& item, mPinSignalMap)
    {
        XmlDomElement* child = pin_signal_map->appendChild("map");
        child->setAttribute("pin", item.pin);
        child->setAttribute("signal", item.signal);
        switch (item.displayType)
        {
            case PinDisplayType_t::None:            child->setAttribute<QString>("display", "none"); break;
            case PinDisplayType_t::PinName:         child->setAttribute<QString>("display", "pin_name"); break;
            case PinDisplayType_t::GenCompSignal:   child->setAttribute<QString>("display", "gen_comp_signal"); break;
            case PinDisplayType_t::NetSignal:       child->setAttribute<QString>("display", "net_signal"); break;
            default: throw LogicError(__FILE__, __LINE__);
        }
    }