| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- /**
- * 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.
- */
- /**
- * \defgroup ecma_layer Layer Tools
- * \ingroup ecma_scripts
- *
- * \brief This module contains ECMAScript implementations of various
- * layer related tools.
- */
- include("scripts/EAction.js");
- /**
- * \class Layer
- * \brief Base class for all layer tools.
- * \ingroup ecma_layer
- */
- function Layer(guiAction) {
- EAction.call(this, guiAction);
- this.documentInterface = undefined;
- // if (!isNull(guiAction) && !isNull(guiAction.getDocumentInterface())) {
- // this.setDocumentInterface(guiAction.getDocumentInterface());
- // }
- }
- Layer.prototype = new EAction();
- Layer.includeBasePath = includeBasePath;
- Layer.prototype.beginEvent = function () {
- EAction.prototype.beginEvent.call(this);
- if (!isNull(this.getGuiAction()) && this.getGuiAction().objectName === "LayerToolsPanelAction") {
- EAction.showCadToolBarPanel("LayerToolsPanel");
- this.terminate();
- }
- };
- Layer.prototype.setDocumentInterface = function (di) {
- this.documentInterface = di;
- };
- Layer.prototype.getDocumentInterface = function () {
- if (!isNull(this.documentInterface)) {
- return this.documentInterface;
- }
- return EAction.prototype.getDocumentInterface.call(this);
- };
- Layer.prototype.getDocument = function () {
- if (!isNull(this.documentInterface)) {
- return this.documentInterface.getDocument();
- }
- return EAction.prototype.getDocument.call(this);
- };
- Layer.prototype.getCurrentLayer = function () {
- // get current or override document:
- var doc = this.getDocument();
- return doc.queryCurrentLayer();
- };
- Layer.getMenu = function () {
- var menu = EAction.getMenu(Layer.getTitle(), "LayerMenu");
- menu.setProperty("scriptFile", Layer.includeBasePath + "/Layer.js");
- return menu;
- };
- Layer.getToolBar = function () {
- var tb = EAction.getToolBar(Layer.getTitle(), "LayerToolBar");
- tb.visible = false;
- return tb;
- };
- Layer.getCadToolBarPanel = function () {
- var mtb = EAction.getMainCadToolBarPanel();
- var actionName = "LayerToolsPanelAction";
- if (!isNull(mtb) && mtb.findChild(actionName) == undefined) {
- var action = new RGuiAction(qsTr("Layer Tools"), mtb);
- action.setScriptFile(Layer.includeBasePath + "/Layer.js");
- action.objectName = actionName;
- action.setRequiresDocument(true);
- action.setIcon(Layer.includeBasePath + "/Layer.svg");
- //action.setStatusTip(qsTr("Show layer tools"));
- action.setDefaultShortcut(new QKeySequence("w,y"));
- action.setNoState();
- action.setDefaultCommands(["layermenu"]);
- action.setGroupSortOrder(60);
- action.setSortOrder(200);
- action.setWidgetNames(["!MainToolsPanel"]);
- }
- var tb = EAction.getCadToolBarPanel(
- Layer.getTitle(),
- "LayerToolsPanel",
- true
- );
- return tb;
- };
- Layer.getToolMatrixPanel = function () {
- RSettings.setValue("Layer/VisibleInMatrixPanel", false, false);
- return EAction.getToolMatrixPanel(Layer.getTitle(), "LayerMatrixPanel", 7000);
- };
- Layer.getTitle = function () {
- return qsTr("图层");
- // return qsTr("&Layer");
- };
- Layer.prototype.getTitle = function () {
- return Layer.getTitle();
- };
- Layer.init = function () {
- Layer.getMenu();
- Layer.getToolBar();
- Layer.getCadToolBarPanel();
- Layer.getToolMatrixPanel();
- };
- Layer.getShowFrozen = function () {
- if (hasPlugin("PROTOOLS")) {
- return RSettings.getBoolValue("LayerListPro/ShowFrozen", false);
- }
- else {
- return false;
- }
- };
- Layer.getFreezeLayer = function () {
- if (hasPlugin("PROTOOLS")) {
- return RSettings.getBoolValue("LayerListPro/FreezeLayer", true);
- }
- else {
- return true;
- }
- };
- /**
- * Show / hide all layers.
- *
- * \param show True to show, false to hide all
- * \param di RDocumentInterface
- * \param layerId ID of layer to exempt from the action
- * \param showProgress True to show progress information to progress listeners
- */
- Layer.showHide = function (show, di, layerId, showProgress) {
- if (showProgress === true) {
- if (show) {
- EAction.setProgressText(qsTr("Showing all layers"));
- }
- else {
- EAction.setProgressText(qsTr("Hiding all layers"));
- }
- }
- var showFrozen = Layer.getShowFrozen();
- var freezeLayer = Layer.getFreezeLayer();
- var operation = new RModifyObjectsOperation();
- var layers = di.getDocument().queryAllLayers();
- for (var l = 0; l < layers.length; ++l) {
- if (showProgress === true) {
- EAction.setProgress(100 / layers.length * l);
- }
- var layer = di.getDocument().queryLayer(layers[l]);
- if (layers[l] !== layerId) {
- if (showFrozen) {
- layer.setOff(!show);
- }
- else {
- if (freezeLayer) {
- layer.setFrozen(!show);
- }
- layer.setOff(!show);
- }
- } else {
- if (showFrozen) {
- layer.setOff(false);
- }
- else {
- layer.setOff(false);
- if (freezeLayer) {
- layer.setFrozen(false);
- }
- }
- }
- operation.addObject(layer);
- }
- di.applyOperation(operation);
- di.clearPreview();
- di.repaintViews();
- if (showProgress === true) {
- EAction.setProgressEnd();
- }
- };
- Layer.thawFreeze = function (freeze, di, layerId, showProgress) {
- if (showProgress === true) {
- if (freeze) {
- EAction.setProgressText(qsTr("Thawing all layers"));
- }
- else {
- EAction.setProgressText(qsTr("Freezing all layers"));
- }
- }
- var operation = new RModifyObjectsOperation();
- var layers = di.getDocument().queryAllLayers();
- for (var l = 0; l < layers.length; ++l) {
- if (showProgress === true) {
- EAction.setProgress(100 / layers.length * l);
- }
- var layer = di.getDocument().queryLayer(layers[l]);
- if (layers[l] !== layerId) {
- layer.setFrozen(!freeze);
- } else {
- layer.setFrozen(false);
- }
- operation.addObject(layer);
- }
- di.applyOperation(operation);
- di.clearPreview();
- di.repaintViews();
- if (showProgress === true) {
- EAction.setProgressEnd();
- }
- };
- Layer.lockUnlock = function (lock, di, showProgress) {
- if (showProgress === true) {
- if (lock) {
- EAction.setProgressText(qsTr("Locking all layers"));
- }
- else {
- EAction.setProgressText(qsTr("Unlocking all layers"));
- }
- }
- var operation = new RModifyObjectsOperation();
- operation.setTransactionType(RTransaction.LayerLockStatusChange);
- var layers = di.getDocument().queryAllLayers();
- for (var l = 0; l < layers.length; ++l) {
- if (showProgress === true) {
- EAction.setProgress(50 / layers.length * l);
- }
- var layer = di.getDocument().queryLayer(layers[l]);
- layer.setLocked(lock);
- operation.addObject(layer);
- }
- di.applyOperation(operation);
- di.clearPreview();
- if (showProgress === true) {
- EAction.setProgress(90);
- }
- di.repaintViews();
- if (showProgress === true) {
- EAction.setProgress(100);
- }
- if (showProgress === true) {
- EAction.setProgressEnd();
- }
- };
- Layer.removeAll = function (di, showProgress) {
- if (showProgress === true) {
- EAction.setProgressText(qsTr("remove all layers"));
- }
- var operation = new RModifyObjectsOperation();
- operation.setTransactionType(RTransaction.LayerLockStatusChange);
- var layers = di.getDocument().queryAllLayers();
- for (var l = 0; l < layers.length; ++l) {
- if (showProgress === true) {
- EAction.setProgress(50 / layers.length * l);
- }
- // 最后一个不删除
- if (l != layers.length - 1) {
- var layer = di.getDocument().queryLayer(layers[l]);
- var operation = new RDeleteObjectOperation(layer);
- di.applyOperation(operation);
- }
- }
- di.applyOperation(operation);
- di.clearPreview();
- if (showProgress === true) {
- EAction.setProgress(90);
- }
- di.repaintViews();
- if (showProgress === true) {
- EAction.setProgress(100);
- }
- if (showProgress === true) {
- EAction.setProgressEnd();
- }
- };
- /**
- * Can be reimplemented in derived classes to provide an advanced dialog.
- */
- Layer.prototype.createLayerDialog = function (di, layer) {
- return new LayerDialog(di, layer);
- };
|