first commit
This commit is contained in:
262
BlockRefExportAll/BlockRefExportAll.js
Normal file
262
BlockRefExportAll/BlockRefExportAll.js
Normal file
@@ -0,0 +1,262 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
include("../QcadStagePlot.js");
|
||||
include("scripts/File/File.js");
|
||||
|
||||
/**
|
||||
* \class BlockRefExport
|
||||
* \brief This action exports block references and positions as CSV file.
|
||||
* \ingroup ecma_misc_block
|
||||
*/
|
||||
function BlockRefExportAll(guiAction) {
|
||||
QcadStagePlot.call(this, guiAction);
|
||||
}
|
||||
|
||||
BlockRefExportAll.prototype = new QcadStagePlot();
|
||||
|
||||
BlockRefExportAll.prototype.dmxAttributes = [
|
||||
"position",
|
||||
"type",
|
||||
"dmx",
|
||||
"name",
|
||||
"id",
|
||||
"gel",
|
||||
"iris",
|
||||
"barndoor",
|
||||
"mode",
|
||||
"height",
|
||||
"weigth",
|
||||
"power"
|
||||
];
|
||||
|
||||
BlockRefExportAll.prototype.beginEvent = function () {
|
||||
QcadStagePlot.prototype.beginEvent.call(this);
|
||||
|
||||
var fileName = this.getFileName();
|
||||
|
||||
if (isNull(fileName)) {
|
||||
this.terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
var file = new QFile(fileName);
|
||||
var flags = makeQIODeviceOpenMode(QIODevice.WriteOnly, QIODevice.Text);
|
||||
if (!file.open(flags)) {
|
||||
this.terminate();
|
||||
return;
|
||||
}
|
||||
|
||||
var ts = new QTextStream(file);
|
||||
setUtf8Codec(ts);
|
||||
ts.writeString("Block Name\tX\tY\tPosition\tType\tDmx\tName\tId\tGel\tIris\tBarndoor\tMode\tHeigth\tWeigth\tPower");
|
||||
|
||||
var doc = this.getDocument();
|
||||
|
||||
// get blocks
|
||||
var block;
|
||||
var result = doc.queryAllBlocks();
|
||||
result = doc.sortBlocks(result);
|
||||
// iterate blocks
|
||||
for (var i = 0; i < result.length; ++i) {
|
||||
var id = result[i];
|
||||
block = doc.queryBlock(id);
|
||||
if (isNull(block)) {
|
||||
continue;
|
||||
}
|
||||
var blockRefIds = doc.queryBlockReferences(id);
|
||||
|
||||
var dmxReferences = [];
|
||||
|
||||
// iterate block references
|
||||
for (var k = 0; k < blockRefIds.length; k++) {
|
||||
var blockRefId = blockRefIds[k];
|
||||
var blockRef = doc.queryEntity(blockRefIds[k]);
|
||||
|
||||
// iterate through all attributes of the current block reference:
|
||||
var attributeIds = doc.queryChildEntities(blockRefId, RS.EntityAttribute);
|
||||
if (this.checkIfDmx(doc, attributeIds)) {
|
||||
var referenceDmxAttributes = {};
|
||||
for (var c = 0; c < attributeIds.length; c++) {
|
||||
var attributeId = attributeIds[c];
|
||||
var attribute = doc.queryEntityDirect(attributeId);
|
||||
if (attribute.isNull()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var attributeName = attribute.getTag();
|
||||
var attributeValue = attribute.getPlainText();
|
||||
if (this.dmxAttributes.indexOf(attributeName) !== -1) {
|
||||
referenceDmxAttributes[attributeName] = attributeValue;
|
||||
}
|
||||
}
|
||||
if (this.countObjects(referenceDmxAttributes)) {
|
||||
dmxReferences.push(referenceDmxAttributes);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dmxReferences.length > 0) {
|
||||
for (ref = 0; ref < dmxReferences.length; ref++) {
|
||||
ts.writeString("\n%1\t%2\t%3".arg(block.getName()).arg(blockRef.getPosition().x).arg(blockRef.getPosition().y));
|
||||
|
||||
if (dmxReferences[ref].position !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].position));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].type !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].type));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].dmx !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].dmx));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].name !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].name));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].id !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].id));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].gel !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].gel));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].iris !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].iris));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].barndoor !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].barndoor));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].mode !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].mode));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].height !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].height));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].weigth !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].weigth));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
if (dmxReferences[ref].power !== undefined) {
|
||||
ts.writeString("\t%1".arg(dmxReferences[ref].power));
|
||||
}
|
||||
else {
|
||||
ts.writeString("\t");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
file.close();
|
||||
this.terminate();
|
||||
};
|
||||
|
||||
BlockRefExportAll.prototype.countObjects = function (obj) {
|
||||
var count = 0;
|
||||
for (var key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
BlockRefExportAll.prototype.checkIfDmx = function (doc, attributeIds) {
|
||||
for (var i = 0; i < attributeIds.length; i++) {
|
||||
var attribute = doc.queryEntityDirect(attributeIds[i]);
|
||||
if (attribute.isNull()) continue;
|
||||
if (attribute.getTag() === "dmx") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
BlockRefExportAll.prototype.getFileName = function () {
|
||||
var drawingFileName = this.getDocument().getFileName();
|
||||
|
||||
var fi;
|
||||
var fileName;
|
||||
var initialPath = "";
|
||||
if (drawingFileName.length === 0) {
|
||||
var path = RSettings.getStringValue("BlockRefExport/Path", QDir.homePath());
|
||||
fi = new QFileInfo(path);
|
||||
initialPath = fi.absoluteFilePath() + QDir.separator
|
||||
+ stripDirtyFlag(EAction.getMdiChild().windowTitle) + ".csv";
|
||||
} else {
|
||||
fi = new QFileInfo(drawingFileName);
|
||||
initialPath = fi.path() + QDir.separator + fi.completeBaseName() + ".csv";
|
||||
}
|
||||
|
||||
var appWin = EAction.getMainWindow();
|
||||
var ret = File.getSaveFileName(appWin, qsTr("Export Block References List (CSV)"),
|
||||
initialPath, [qsTr("CSV") + " (*.csv)"]);
|
||||
if (isNull(ret)) {
|
||||
return undefined;
|
||||
}
|
||||
fileName = ret[0];
|
||||
|
||||
if (fileName === "") {
|
||||
return undefined;
|
||||
}
|
||||
if (drawingFileName.length === 0) {
|
||||
RSettings.setValue("BlockRefExport/Path", new QFileInfo(fileName).absolutePath());
|
||||
}
|
||||
|
||||
return fileName;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a menu for this action to the Misc menu.
|
||||
*/
|
||||
BlockRefExportAll.init = function (basePath) {
|
||||
var action = new RGuiAction(qsTr("&Export Block References List All") + "…", RMainWindowQt.getMainWindow());
|
||||
action.setRequiresDocument(true);
|
||||
action.setScriptFile(basePath + "/BlockRefExportAll.js");
|
||||
action.setGroupSortOrder(80100);
|
||||
action.setSortOrder(200);
|
||||
action.setWidgetNames(["QcadStagePlotMenu", "QcadStagePlotToolBar", "QcadStagePlotToolsPanel"]);
|
||||
};
|
||||
24
QcadStagePlot.js
Normal file
24
QcadStagePlot.js
Normal file
@@ -0,0 +1,24 @@
|
||||
include("scripts/EAction.js");
|
||||
|
||||
function QcadStagePlot(guiAction) {
|
||||
EAction.call(this, guiAction);
|
||||
}
|
||||
|
||||
QcadStagePlot.prototype = new EAction();
|
||||
|
||||
QcadStagePlot.getMenu = function() {
|
||||
return EAction.getMenu(QcadStagePlot.getTitle(), "QcadStagePlotMenu");
|
||||
};
|
||||
|
||||
QcadStagePlot.getToolBar = function() {
|
||||
return EAction.getToolBar(QcadStagePlot.getTitle(), "QcadStagePlotToolBar");
|
||||
};
|
||||
|
||||
QcadStagePlot.getTitle = function() {
|
||||
return qsTr("QcadStagePlot");
|
||||
};
|
||||
|
||||
QcadStagePlot.init = function() {
|
||||
QcadStagePlot.getMenu();
|
||||
QcadStagePlot.getToolBar();
|
||||
};
|
||||
Reference in New Issue
Block a user