Esempio n. 1
0
// Starter function for modular product
void modprod(char *modP1, char *modP2) {

	unsigned char *modP1Char = malloc(8 * sizeof (unsigned char));
	unsigned char *modP2Char = malloc(8 * sizeof (unsigned char));
	memset(modP1Char, 0, 8);
	memset(modP2Char, 0, 8);

	uint32_t returnVal = 0;

	if (polyCheck(modP1) != 8) {
		fprintf(stderr, "Poly 1 is invalid. Please check the input and try again.\n");
	}
	if (polyCheck(modP2) != 8) {
		fprintf(stderr, "Poly 2 is invalid. Please check the input and try again.\n");
	}

	convertPoly(modP1, modP1Char);
	convertPoly(modP2, modP2Char);

	returnVal = checkInverse(modP1Char, modP2Char);	

	printModProd(modP1Char, modP2Char, returnVal);

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