/** * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved. * * This file is part of the QCAD project. * * QCAD is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * QCAD is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with QCAD. */ /** * Command line tool. * Merges multiple drawing files (DWG, DXF) into one. */ include("scripts/Tools/arguments.js"); function printHelp() { print("Usage: " + args[1] + " [OPTIONS]... "); print(); print("Merges multiple drawing files (DWG, DXF, ...) into one."); print(); print(" -f, -force Overwrite existing output file"); print(" -h, -help Display this help"); print(" -t TYPE, -type=TYPE Set file type to TYPE "); print(" (e.g. R12...R27 or 2000...2013)"); print(" -o FILE, -outfile=FILE Set output file to FILE"); print(" default is same path and base name as input file"); printGenericUsage(); print(); print("XML format:"); print(""); print(""); print(" "); print(" "); print(" "); print(""); print(); } function main() { if (testArgument(args, "-h", "-help")) { printHelp(); return; } if (args.length < 3) { print("No input file given. Try -h for help."); return; } qApp.organizationName = "QCAD"; qApp.organizationDomain = "QCAD.org"; qApp.applicationVersion = RSettings.getVersionString(); qApp.applicationName = "QCAD"; RSettings.setApplicationNameOverride("QCAD3"); var xmlFile = args[args.length - 1]; if (xmlFile.indexOf("-") === 0) { print("No input file. Try -h for help."); return; } include("scripts/ImportExport/SvgImporter/SvgImporterInit.js"); RFileImporterRegistry.registerFileImporter(new SvgImporterFactory()); var fi = new QFileInfo(xmlFile); if (!fi.isAbsolute()) { xmlFile = RSettings.getLaunchPath() + QDir.separator + xmlFile; fi = new QFileInfo(xmlFile); } var outputFile = getArgument(args, "-o", "-outfile"); if (outputFile!==undefined) { if (!new QFileInfo(outputFile).isAbsolute()) { outputFile = RSettings.getLaunchPath() + QDir.separator + outputFile; } } else { outputFile = fi.absolutePath() + QDir.separator + fi.completeBaseName() + ".dxf"; } if (new QFileInfo(outputFile).exists() && !testArgument(args, "-f", "-force")) { print("Output file exists already, not overwriting: ", outputFile); print("Use -f to force overwrite"); return; } var type = getArgument(args, "-t", "-type"); if (type===undefined) { type = ""; } // parse XML into array: //var file = new QFile(xmlFile); //var xmlReader = new QXmlSimpleReader(); //var source = new QXmlInputSource(file); var handler = new XmlHandler(); //xmlReader.setContentHandler(handler); //var ok = xmlReader.parse(source, false); parseXml(xmlFile, handler); //file.close(); // target document: var docDest = new RDocument(new RMemoryStorage(), new RSpatialIndexSimple()); docDest.setUnit(handler.outputUnit); var diDest = new RDocumentInterface(docDest); for (var i=0; i