void MongodbStorage::storeEdge(const SlamEdge &edge) { // Delete edge, if it exists. edge_collection_->removeMessages(QUERY("id" << edge.id_)); // Add edge to database. graph_slam_msgs::Edge edge_msg = Conversions::toMsg(edge); edge_collection_->insert(edge_msg, makeMetadata(edge_msg)); }
void MongodbStorage::storeNode(const SlamNode &node) { // Delete node, if it exists. node_collection_->removeMessages(QUERY("id" << node.id_)); // Add node. graph_slam_msgs::Node node_msg = Conversions::toMsg(node); node_collection_->insert(node_msg, makeMetadata(node_msg)); }
QString KicadSchematic2Svg::convert(const QString & filename, const QString & defName) { initLimits(); QFile file(filename); if (!file.open(QFile::ReadOnly)) { throw QObject::tr("unable to open %1").arg(filename); } QTextStream textStream(&file); QString metadata = makeMetadata(filename, "schematic part", defName); metadata += endMetadata(); QString reference; int textOffset = 0; bool drawPinNumber = true; bool drawPinName = true; bool gotDef = false; while (true) { QString line = textStream.readLine(); if (line.isNull()) { break; } if (line.startsWith("DEF") && line.contains(defName, Qt::CaseInsensitive)) { QStringList defs = splitLine(line); if (defs.count() < 8) { throw QObject::tr("bad schematic definition %1").arg(filename); } reference = defs[2]; textOffset = defs[4].toInt(); drawPinName = defs[6] == "Y"; drawPinNumber = defs[5] == "Y"; gotDef = true; break; } } if (!gotDef) { throw QObject::tr("schematic part %1 not found in %2").arg(defName).arg(filename); } QString contents = "<g id='schematic'>\n"; bool inFPLIST = false; while (true) { QString fline = textStream.readLine(); if (fline.isNull()) { throw QObject::tr("schematic %1 unexpectedly ends (1) in %2").arg(defName).arg(filename); } if (fline.contains("ENDDEF")) { throw QObject::tr("schematic %1 unexpectedly ends (2) in %2").arg(defName).arg(filename); } if (fline.startsWith("DRAW")) { break; } if (fline.startsWith("ALIAS")) continue; if (fline.startsWith("F")) { contents += convertField(fline); continue; } if (fline.startsWith("$FPLIST")) { inFPLIST = true; break; } } while (inFPLIST) { QString fline = textStream.readLine(); if (fline.isNull()) { throw QObject::tr("schematic %1 unexpectedly ends (1) in %2").arg(defName).arg(filename); } if (fline.startsWith("$ENDFPLIST")) { inFPLIST = false; break; } if (fline.contains("ENDDEF")) { throw QObject::tr("schematic %1 unexpectedly ends (2) in %2").arg(defName).arg(filename); } } int pinIndex = 0; while (true) { QString line = textStream.readLine(); if (line.isNull()) { throw QObject::tr("schematic %1 unexpectedly ends (3) in %2").arg(defName).arg(filename); } if (line.startsWith("DRAW")) { continue; } if (line.contains("ENDDEF")) { break; } if (line.contains("ENDDRAW")) { break; } if (line.startsWith("S")) { contents += convertRect(line); } else if (line.startsWith("X")) { // need to look at them all before formatting (I think) contents += convertPin(line, textOffset, drawPinName, drawPinNumber, pinIndex++); } else if (line.startsWith("C")) { contents += convertCircle(line); } else if (line.startsWith("P")) { contents += convertPoly(line); } else if (line.startsWith("A")) { contents += convertArc(line); } else if (line.startsWith("T")) { contents += convertText(line); } else { DebugDialog::debug("Unknown line " + line); } } contents += "</g>\n"; QString svg = TextUtils::makeSVGHeader(GraphicsUtils::StandardFritzingDPI, GraphicsUtils::StandardFritzingDPI, m_maxX - m_minX, m_maxY - m_minY) + m_title + m_description + metadata + offsetMin(contents) + "</svg>"; return svg; }
QString KicadModule2Svg::convert(const QString & filename, const QString & moduleName, bool allowPadsAndPins) { m_nonConnectorNumber = 0; initLimits(); QFile file(filename); if (!file.open(QFile::ReadOnly)) { throw QObject::tr("unable to open %1").arg(filename); } QString text; QTextStream textStream(&file); QString metadata = makeMetadata(filename, "module", moduleName); bool gotModule = false; while (true) { QString line = textStream.readLine(); if (line.isNull()) { break; } if (line.contains("$MODULE") && line.contains(moduleName, Qt::CaseInsensitive)) { gotModule = true; break; } } if (!gotModule) { throw QObject::tr("footprint %1 not found in %2").arg(moduleName).arg(filename); } bool gotT0; QString line; while (true) { line = textStream.readLine(); if (line.isNull()) { throw QObject::tr("unexpected end of file in footprint %1 in file %2").arg(moduleName).arg(filename); } if (line.startsWith("T0") || line.startsWith("DS") || line.startsWith("DA") || line.startsWith("DC")) { gotT0 = true; break; } else if (line.startsWith("Cd")) { metadata += m_comment.arg(TextUtils::stripNonValidXMLCharacters(TextUtils::escapeAnd(line.remove(0,3)))); } else if (line.startsWith("Kw")) { QStringList keywords = line.split(" "); for (int i = 1; i < keywords.count(); i++) { metadata += m_attribute.arg("keyword").arg(TextUtils::stripNonValidXMLCharacters(TextUtils::escapeAnd(keywords[i]))); } } } metadata += endMetadata(); if (!gotT0) { throw QObject::tr("unexpected format (1) in %1 from %2").arg(moduleName).arg(filename); } while (line.startsWith("T")) { line = textStream.readLine(); if (line.isNull()) { throw QObject::tr("unexpected end of file in footprint %1 in file %2").arg(moduleName).arg(filename); } } bool done = false; QString copper0; QString copper1; QString silkscreen0; QString silkscreen1; while (true) { if (line.startsWith("$PAD")) break; if (line.startsWith("$EndMODULE")) { done = true; break; } int layer = 0; QString svgElement; if (line.startsWith("DS")) { layer = drawDSegment(line, svgElement); } else if (line.startsWith("DA")) { layer = drawDArc(line, svgElement); } else if (line.startsWith("DC")) { layer = drawDCircle(line, svgElement); } switch (layer) { case KicadSilkscreenTop: silkscreen1 += svgElement; break; case KicadSilkscreenBottom: silkscreen0 += svgElement; break; default: break; } line = textStream.readLine(); if (line.isNull()) { throw QObject::tr("unexpected end of file in footprint %1 in file %2").arg(moduleName).arg(filename); } } if (!done) { QList<int> numbers; for (int i = 0; i < 512; i++) { numbers << i; } int pads = 0; int pins = 0; while (!done) { try { QString pad; PadLayer padLayer = convertPad(textStream, pad, numbers); switch (padLayer) { case ToCopper0: copper0 += pad; pins++; break; case ToCopper1: copper1 += pad; pads++; break; default: break; } } catch (const QString & msg) { DebugDialog::debug(QString("kicad pad %1 conversion failed in %2: %3").arg(moduleName).arg(filename).arg(msg)); } while (true) { line = textStream.readLine(); if (line.isNull()) { throw QObject::tr("unexpected end of file in footprint %1 in file %2").arg(moduleName).arg(filename); } if (line.contains("$SHAPE3D")) { done = true; break; } if (line.contains("$EndMODULE")) { done = true; break; } if (line.contains("$PAD")) { break; } } } if (!allowPadsAndPins && pins > 0 && pads > 0) { throw QObject::tr("Sorry, Fritzing can't yet handle both pins and pads together (in %1 in %2)").arg(moduleName).arg(filename); } } if (!copper0.isEmpty()) { copper0 = offsetMin("\n<g id='copper0'><g id='copper1'>" + copper0 + "</g></g>\n"); } if (!copper1.isEmpty()) { copper1 = offsetMin("\n<g id='copper1'>" + copper1 + "</g>\n"); } if (!silkscreen1.isEmpty()) { silkscreen1 = offsetMin("\n<g id='silkscreen'>" + silkscreen1 + "</g>\n"); } if (!silkscreen0.isEmpty()) { silkscreen0 = offsetMin("\n<g id='silkscreen0'>" + silkscreen0 + "</g>\n"); } QString svg = TextUtils::makeSVGHeader(10000, 10000, m_maxX - m_minX, m_maxY - m_minY) + m_title + m_description + metadata + copper0 + copper1 + silkscreen0 + silkscreen1 + "</svg>"; return svg; }
void MongodbStorage::storeMetaData(const SlamGraph &graph) { meta_collection_->removeMessages(mr::Query()); graph_slam_msgs::GraphMeta meta = graph.toMetaData(tfl_); meta_collection_->insert(meta, makeMetadata(meta)); }