/** * 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("scripts/library.js"); include("scripts/WidgetFactory.js"); include("scripts/Widgets/OptionsToolBar/OptionsToolBar.js"); /** * Base class for all ECMAScript based actions. */ function EAction(guiAction) { RActionAdapter.call(this); this.guiAction = guiAction; if (!isNull(guiAction)) { this.setGuiAction(guiAction); } // Constructor is called without arguments to create prototype // for derived class. At this point, includeBasePath is set correctly: if (isNull(guiAction)) { this.includeBasePath = includeBasePath; } this.delegate = undefined; this.state = undefined; this.settingsGroup = undefined; this.uiFile = undefined; this.splitUiOptions = false; this.additionalOptionsToolBars = undefined; this.optionsToolBarEnabled = false; this.relativeZeroPos = undefined; // set to true to prefer dialog over options tool bar: this.useDialog = false; this.dialogUiFile = undefined; this.waitingForContextMenu = false; this.optOutRelativeZeroResume = false; this.resuming = false; } EAction.prototype = new RActionAdapter(); EAction.includeBasePath = includeBasePath; // some commonly used translated strings: EAction.trBack = qsTr("Back"); EAction.trCancel = qsTr("Cancel"); EAction.trDone = qsTr("Done"); EAction.crossCursor = undefined; EAction.noRelativeZeroResume = false; /** * Called when the user starts this action by clicking a button, choosing a * menu, entering a command, etc. * * Shows the GUI elements that refer to this action as checked. Displays GUI * options if this.uiFile is set to a valid UI file. Displays tool help in Help * Viewer if available. */ EAction.prototype.beginEvent = function() { if (this.delegate) { this.delegate.beginEvent(); } if (this.hasNoState()) { return; } var appWin = EAction.getMainWindow(); if (!isNull(this.getGuiAction())) { this.getGuiAction().setChecked(true); } this.showUiOptions(false); // reset snap to auto snap / no restriction: if (isNull(this.getGuiAction()) || (this.getGuiAction().getGroup() !== "snaps" && this.getGuiAction().getGroup() !== "snaprestrictions" && this.getGuiAction().property("NoSnapReset")!==true)) { var di = this.getDocumentInterface(); if (!isNull(di)) { if (!di.isSnapLocked()) { var guiAction = RGuiAction.getByScriptFile("scripts/Snap/SnapAuto/SnapAuto.js"); if (!isNull(guiAction)) { guiAction.slotTrigger(); } di.setSnap(new RSnapAuto()); guiAction = RGuiAction.getByScriptFile("scripts/Snap/RestrictOff/RestrictOff.js"); if (!isNull(guiAction)) { guiAction.slotTrigger(); } di.setSnapRestriction(new RRestrictOff(di)); } } } }; /** * Called when this action is terminated. * * Shows the GUI elements that refer to this action as un-checked. Hides GUI * options if this.uiFile is set to a valid UI file. Clears up mouse tips, etc. */ EAction.prototype.finishEvent = function() { if (this.hasNoState()) { return; } var guiAction = this.getGuiAction(); // unckeck tool GUI action: if (!isNull(guiAction) && !isDeleted(guiAction)) { if (guiAction.getGroup().isEmpty() || guiAction.isOverride()) { guiAction.setChecked(false); } } this.hideUiOptions(); // clear mouse tips: if (!isNull(EAction.getMainWindow())) { this.setLeftMouseTip(""); this.setRightMouseTip(""); } // reset CAD tool bar: if (!isNull(guiAction) && guiAction.getGroup() === "") { var appWin = EAction.getMainWindow(); var cadToolBar = appWin.findChild("CadToolBar"); if (!isNull(cadToolBar) && cadToolBar.getCurrentPanelName()==="SnapToolsPanel") { cadToolBar.back(); } } // to remove snap info: var di = this.getDocumentInterface(); if (!isNull(di)) { di.repaintViews(); } this.setCommandPrompt(); }; /** * Does nothing. Needs to be implemented here to avoid recursion when child * classes call the base class implementation. */ EAction.prototype.mousePressEvent = function(event) { }; EAction.prototype.mouseReleaseEvent = function(event) { if (event.button() === Qt.RightButton) { this.escapeEvent(); } }; EAction.prototype.mouseDoubleClickEvent = function(event) { if (event.button() == Qt.RightButton) { // right double-click to reset: if (RSettings.getBoolValue("GraphicsView/RightDoubleClickToReset", false)) { var di = this.getDocumentInterface(); if (!isNull(di)) { di.killAllActions(); } EAction.showMainTools(); } } }; /** * Sets the UI options toolbar content for this tool. By default, a tool shows * the options toolbar defined in "DefaultOptions.ui". * * \param uiFile A path to a single UI file or an array of UI file paths. * \param split If true, the options are split up into multiple toolbars. */ EAction.prototype.setUiOptions = function(uiFile, split) { if (isNull(split)) { split = false; } this.splitUiOptions = split; if (isNull(uiFile)) { this.uiFile = undefined; return; } if (isArray(uiFile)) { this.uiFile = uiFile; } else { this.uiFile = [ uiFile ]; } }; /** * Set the state of this action. Action implementations overwrite this function * to initialize this action for the given state. This includes setting the * appropriate click mode, displaying the appropriate CAD toolbar, setting * mouse tips, mouse cursor, etc. */ EAction.prototype.setState = function(state) { if (!isNumber(state)) { qWarning("EAction.prototype.setState: invalid state"); debugger; return; } this.state = state; this.initState(); if (state!==-1) { this.simulateMouseMoveEvent(); } }; /** * Called to initialize a new state of this action. Overwrite to * set mouse tips, show desired toolbars, etc. */ EAction.prototype.initState = function() { }; /** * Called whenever the action resumes its operation, for example after it was * temporary suspended for another action. */ EAction.prototype.resumeEvent = function() { if (this.hasNoState()) { return; } var appWin = EAction.getMainWindow(); if (!isNull(this.getGuiAction())) { this.getGuiAction().setChecked(true); } this.showUiOptions(true); if (!isNull(this.state)) { this.setState(this.state); } if (!this.optOutRelativeZeroResume) { // restore relative zero position when returning from another command: var di = this.getDocumentInterface(); if (!isNull(di) && isValidVector(this.relativeZeroPos)) { if (EAction.noRelativeZeroResume===true) { EAction.noRelativeZeroResume = false; } else { di.setRelativeZero(this.relativeZeroPos); } } this.relativeZeroPos = undefined; } }; /** * Called whenever the action is suspended, for example if another action is * started while this action is active. */ EAction.prototype.suspendEvent = function() { if (this.hasNoState()) { return; } if (!isNull(this.getGuiAction())) { this.getGuiAction().setChecked(false); } this.hideUiOptions(); // store relative zero position: var di = this.getDocumentInterface(); if (!isNull(di)) { this.relativeZeroPos = di.getRelativeZero(); } }; /** * Shows the UI options of this action if this.uiFile is set. UI options are * typically shown in a horizontal toolbar at the top of the drawing area. * * Usually this function does not need to be called directly by implementing * actions. * * \param resume Action was resumed from suspension. * \param restoreFromSettings Restore settings from document / config file (default). */ EAction.prototype.showUiOptions = function(resume, restoreFromSettings) { if (isNull(restoreFromSettings)) { restoreFromSettings = true; } if (!isNull(this.optionWidgetActions)) { return; } if (this.optionsToolBarEnabled === false) { return; } var optionsToolBar = EAction.getOptionsToolBar(); if (isNull(optionsToolBar)) { qWarning("EAction.prototype.showUiOptions: no options toolbar"); return; } this.optionWidgetActions = []; var guiAction = this.getGuiAction(); if (!isNull(guiAction) && guiAction.getGroup() !== "snaps" && guiAction.getGroup() !== "snaprestrictions") { // automatically add icon of current action to toolbar: if (!guiAction.icon.isNull() && !guiAction.isOverride()) { var iconLabel = optionsToolBar.findChild("Icon"); if (!isNull(iconLabel)) { iconLabel.toolTip = qsTr("Active Tool:") + " " + guiAction.text.replace("&", ""); OptionsToolBar.setIcon(guiAction.icon); iconLabel.setFixedWidth(iconLabel.height + 12); } } } // add widgets from action specific options toolbar: if (isNull(this.uiFile)) { return; } this.resuming = true; this.optionWidgetActions = []; for (var i = 0; i < this.uiFile.length; ++i) { var uiFile = this.uiFile[i]; var wOptions = this.createWidget(uiFile); //qDebug("adjust icons for uiFile: ", uiFile); if (isNull(wOptions)) { qWarning("Cannot create widget from UI file: ", uiFile); continue; } // create new toolbar for additional tool options: if (this.splitUiOptions === true && i != 0) { EAction.getMainWindow().addToolBarBreak(); optionsToolBar = new QToolBar(EAction.getMainWindow()); optionsToolBar.objectName = wOptions.objectName; EAction.getMainWindow().addToolBar(Qt.TopToolBarArea, optionsToolBar); if (isNull(this.additionalOptionsToolBars)) { this.additionalOptionsToolBars = []; } this.additionalOptionsToolBars.push(optionsToolBar); } // show: this.settingsGroup = wOptions.objectName; this.optionWidgetActions = this.optionWidgetActions .concat(WidgetFactory.moveChildren(wOptions, optionsToolBar, this.settingsGroup)); // required for undocked options tool bar: if (optionsToolBar.floating) { optionsToolBar.resize(optionsToolBar.sizeHint.width(), optionsToolBar.height); } destr(wOptions); // automatically add separator to toolbar: var a = optionsToolBar.addSeparator(); a.objectName = "LastSeparator" + i; this.optionWidgetActions.push(a); // give action a chance to initialize toolbar widgets that cannot // be initialized in Qt Designer: this.initUiOptions(resume, optionsToolBar); // restore previously stored state: if (restoreFromSettings===true) { WidgetFactory.restoreState(optionsToolBar, this.settingsGroup, this); } } // hide options tool bar widgets which are shown in a dialog instead: this.hideOptionsToolBarWidgets(); this.resuming = false; }; /** * Overwrite to initialize combo boxes and other UI elements of the options tool * bar. */ EAction.prototype.initUiOptions = function(resume, optionsToolBar) { var prefixChar = RSettings.getStringValue("ToolBar/PrefixChar", ","); if (isNull(optionsToolBar)) { return; } var children = optionsToolBar.children(); for (var i=0; i= '!' && firstChar <= '~') { // isgraph() str = str.replace(firstChar, prefixChar); child.shortcut = new QKeySequence(str); child.toolTip = RGuiAction.formatToolTip(child.toolTip, str); } } } } }; /** * Hides the UI options of this action. * * Usually this function does not need to be called directly by implementing * actions. * \param saveToSettings if true, the state is saved to settings */ EAction.prototype.hideUiOptions = function(saveToSettings) { if (isNull(saveToSettings)) { saveToSettings = true; } if (isNull(this.optionWidgetActions)) { return; } if (this.optionsToolBarEnabled === false) { return; } var optionsToolBar = EAction.getOptionsToolBar(); if (isNull(optionsToolBar)) { return; } if (saveToSettings) { WidgetFactory.saveState(optionsToolBar, this.settingsGroup); } // automatically reset icon of current action from toolbar: if (!isNull(this.getGuiAction()) && this.getGuiAction().getGroup() !== "snaps" && this.getGuiAction().getGroup() !== "snaprestrictions") { if (!this.getGuiAction().icon.isNull()) { var iconLabel = optionsToolBar.findChild("Icon"); if (!isNull(iconLabel)) { OptionsToolBar.setIcon("scripts/Reset/Reset.svg"); iconLabel.toolTip = qsTr("Active Tool:") + " " + qsTr("None"); } } } // delete all option widgets / actions of this tool: var i; while (this.optionWidgetActions.length>0) { var a = this.optionWidgetActions.pop(); if (!isNull(optionsToolBar)) { optionsToolBar.removeAction(a); } destr(a); } // delete additional toolbars of this tool if available: if (!isNull(this.additionalOptionsToolBars)) { for (i = 0; i < this.additionalOptionsToolBars.length; ++i) { var tb = this.additionalOptionsToolBars[i]; if (isDeleted(tb)) { continue; } destr(tb); } } // required for undocked options tool bar: if (optionsToolBar.floating) { optionsToolBar.resize(optionsToolBar.sizeHint.width(), optionsToolBar.height); } this.optionWidgetActions = undefined; this.additionalOptionsToolBars = undefined; }; /** * Hides all widgets in the options tool bar which are shown in the tool dialog instead. */ EAction.prototype.hideOptionsToolBarWidgets = function(widgets, noSyncWidgets) { if (!this.useDialog) { return; } if (isNull(widgets)) { widgets = []; } if (isNull(noSyncWidgets)) { noSyncWidgets = []; } // collect widgets which are tagged to be shown in the dialog: var i, c; //var widgets = []; //var noSyncWidgets = []; var optionsToolBar = EAction.getOptionsToolBar(); var children = optionsToolBar.children(); for (i = 0; i < children.length; ++i) { c = children[i]; if (isNull(c)) { continue; } if (c["HideInDialogMode"]===true) { destr(c); } else if (c["MoveToDialog"]===true) { widgets.push(c); } else { if (isQWidget(c)) { noSyncWidgets.push(c); } } } if (widgets.length===0) { // no widgets to show in dialog, return to normal operation without dialog: return; } WidgetFactory.saveState(optionsToolBar, this.settingsGroup); for (i = 0; i < widgets.length; i++) { var a = optionsToolBar.findChild(widgets[i].objectName + "Action"); if (!isNull(a)) { a.visible = false; } } // remove double separators: OptionsToolBar.normalizeSeparators(this); }; /** * Called when user presses enter. Default implementation calls showDialog if configured. */ EAction.prototype.enterEvent = function() { if (RSettings.getBoolValue("Transform/EnterShowsDialog", false)===true) { this.showDialog(); } }; /** * Show dialog to enter some or all of the options. * The default implementation creates a dialog based on this.dialogUiFile. * Widgets in the options tool bar which have the property "MoveToDialog" or * "HideInDialogMode" set are hidden in the options tool bar. */ EAction.prototype.showDialog = function() { if (!this.useDialog) { return QDialog.Rejected; } var di = this.getDocumentInterface(); if (!isNull(di)) { di.clearPreview(); di.repaintViews(); } var widgets = []; var noSyncWidgets = []; this.hideOptionsToolBarWidgets(widgets, noSyncWidgets); // show dialog and move tool bar widgets to its layout: var formLayout = undefined; if (isNull(this.dialogUiFile)) { return QDialog.Rejected; } this.dialog = WidgetFactory.createDialog(this.includeBasePath, this.dialogUiFile, EAction.getMainWindow()); this.initUiOptions(false, this.dialog); WidgetFactory.restoreState(this.dialog, this.settingsGroup, this); var title = this.getToolTitle(); if (title.indexOf("\t")!==-1) { // remove shortcuts Windows: title = title.replace(/\t.*/g, ""); } this.dialog.windowTitle = title; this.dialog.windowIcon = new QIcon(); // give focus to control with custom property 'DefaultFocus': var children = this.dialog.children(); var i; for (i=0; i= Qt.Key_0.valueOf() && event.key() <= Qt.Key_9.valueOf()) || event.key() === Qt.Key_Period.valueOf()) { // number or dot entered: // give focus to first input widget in options tool bar and set text to number entered: var w = OptionsToolBar.getFirstInputWidget(); if (!isNull(w)) { w.setFocus(Qt.OtherFocusReason); w.text = String.fromCharCode(event.key()); event.accept(); return; } } } event.ignore(); }; /** * Called when the user releases a key. By default, the event is ignored. */ EAction.prototype.keyReleaseEvent = function(event) { event.ignore(); }; /** * Sets the current cursor of the current document interface (all views attached * to it) to crosshair cursor. */ EAction.prototype.setCrosshairCursor = function() { if (isNull(EAction.crossCursor)) { if (RSettings.getBoolValue("GraphicsView/SystemCursors", false)===true) { EAction.crossCursor = new QCursor(Qt.CrossCursor); } else { var bitmap, mask if (RSettings.getDevicePixelRatio()===2 && RS.getSystemId()!=="osx") { bitmap = new QBitmap(EAction.includeBasePath + "/CrosshairCursor@2x.png", "PNG"); mask = new QBitmap(EAction.includeBasePath + "/CrosshairCursorMask@2x.png", "PNG"); //bitmap.setDevicePixelRatio(2); //mask.setDevicePixelRatio(2); EAction.crossCursor = new QCursor(bitmap, mask, 30, 30); } else { bitmap = new QBitmap(EAction.includeBasePath + "/CrosshairCursor.png", "PNG"); mask = new QBitmap(EAction.includeBasePath + "/CrosshairCursorMask.png", "PNG"); EAction.crossCursor = new QCursor(bitmap, mask, 15, 15); } } } this.setCursor(EAction.crossCursor, "CrossCursor"); }; /** * Sets the current cursor of the current document interface (all views attached * to it) to the normal arrow cursor. */ EAction.prototype.setArrowCursor = function() { this.setCursor(new QCursor(Qt.ArrowCursor)); }; EAction.prototype.setCursor = function(cursor, name) { var di = this.getDocumentInterface(); if (!isNull(di)) { di.setCursor(cursor); } // if (!isNull(name)) { // var views = this.getGraphicsViews(); // for (var i=0; i=5. * Not necessary with Qt>=5.10. */ EAction.activateMainWindow = function() { // if (RSettings.isQt(5)) { // var appWin = EAction.getMainWindow(); // if (isNull(appWin)) { // return; // } // appWin.activateWindow(); // var view = EAction.getGraphicsView(); // if (!isNull(view)) { // // view loses focus because of dialogs: // view.giveFocus(); // } // } }; /** * \return The current MDI child or null. */ EAction.getMdiChild = function() { var appWin = RMainWindowQt.getMainWindow(); if (isNull(appWin)) { return undefined; } return appWin.getMdiChild(); }; /** * \return The MDI area or null. */ EAction.getMdiArea = function() { var appWin = EAction.getMainWindow(); if (isNull(appWin)) { return undefined; } return appWin.getMdiArea(); }; /** * \return List of all graphics views attached to the current document interface. */ EAction.prototype.getGraphicsViews = function() { var di = this.getDocumentInterface(); if (isNull(di)) { return []; } return EAction.getGraphicsViews(di); }; EAction.getGraphicsViews = function(di) { var ret = []; var scenes = di.getGraphicsScenes(); for (var i=0; i sortOrder) { // actionBefore = subMenuActions[i]; // break; // } // } // subMenu = new QMenu(title, menu); // if (!isNull(iconFile)) { // subMenu.icon = new QIcon(iconFile); // } // var separator; // if (addSeparator) { // separator = new RGuiAction("", RMainWindowQt.getMainWindow()); // separator.setSeparator(true); // separator.setSortOrder(sortOrder - 1); // separator.addToMenu(menu); // } // var subMenuAction; // if (isNull(actionBefore)) { // subMenuAction = menu.addMenu(subMenu); // } else { // subMenuAction = menu.insertMenu(actionBefore, subMenu); // } // subMenu.objectName = objectName; // subMenuAction.setProperty("SortOrder", sortOrder); } return subMenu; }; /** * \return Existing or new toolbar. * * \param title Translated title of the toolbar. E.g. qsTr("Snap"). * \param objectName Object name to use for the toolbar. Used mainly for later * identification of the toolbar. E.g. "line". * \param toolBarArea Area where the new toolbar should be added. Note that the * actual location where the toolbar is added may also depend on the previously * saved state of the tool bars. Defaults to Qt.TopToolBarArea. */ EAction.getToolBar = function(title, objectName, toolBarArea, category, before) { if (isNull(objectName)) { objectName = ""; } if (isNull(toolBarArea)) { toolBarArea = Qt.TopToolBarArea; } var appWin = EAction.getMainWindow(); if (isNull(appWin)) { return undefined; } var tb = undefined; if (objectName.length !== 0) { tb = appWin.findChild(objectName); } if (!isNull(tb) && !isOfType(tb, QToolBar)) { qWarning("Not a toolbar: " + tb); return undefined; } if (isNull(tb)) { tb = new QToolBar(title); tb.objectName = objectName; if (!isNull(category)) { tb.setProperty("Category", category); } var s = RSettings.getIntValue("ToolBar/IconSize", tb.iconSize.width()); tb.iconSize = new QSize(s,s); if (isNull(before)) { appWin.addToolBar(toolBarArea, tb); } else { appWin.insertToolBar(before, tb); } } return tb; }; /** * \return Existing or new dock. * * \param title Translated title of the dock widget. E.g. qsTr("Snap"). * \param objectName Object name to use for the dock widget. Used mainly for later * identification of the dock widget. E.g. "line". * \param toolBarArea Area where the new dock should be added. Note that the * actual location where the dock is added may also depend on the previously * saved state of the docks. Defaults to Qt.LeftDockWidgetArea. */ EAction.getToolMatrixPanel = function(title, objectName, order) { if (isNull(objectName)) { objectName = ""; } include("scripts/Widgets/CadToolMatrix/CadToolMatrix.js"); return CadToolMatrix.getToolMatrixPanel(title, objectName, order); }; /** * \return Existing or new options toolbar (used to display options for the * current tool). */ EAction.getOptionsToolBar = function() { var appWin = EAction.getMainWindow(); if (isNull(EAction.optionsToolBar)) { if (!isNull(appWin)) { appWin.addToolBarBreak(); } EAction.optionsToolBar = EAction.getToolBar(qsTr("Options"), "Options"); } if (!isNull(EAction.optionsToolBar)) { if (!RSettings.getOriginalArguments().contains("-no-show")) { EAction.optionsToolBar.visible = false; } } return EAction.optionsToolBar; }; /** * \return Existing or new block toolbar (used to display options for the * current block). */ //EAction.getBlockToolBar = function() { // if (isNull(EAction.blockToolBar)) { // EAction.blockToolBar = EAction.getToolBar(qsTr("Block Options"), "BlockOptions"); // } // return EAction.blockToolBar; //}; /** * \return The main (top) CAD toolbar panel. */ EAction.getMainCadToolBarPanel = function() { return EAction.getCadToolBarPanel(qsTr("Main Tools"), "MainToolsPanel", false); }; /** * \return Existing or new CAD toolbar panel. Each CAD toolbar panel contains * a set of tools, e.g. to draw lines, change the snap tool, etc. The CAD tool * bar itself is created automatically when this function is called for the * first time. * * \param title Translated title to use for the CAD toolbar panel. E.g. * qsTr("Snap"). \param objectName Object name to use for the panel. Used mainly * for later identification of the panel. E.g. "snap". \param hasBackButton True * to display a back button at the top or left to allow the user to navigate * back to the main CAD toolbar panel. */ EAction.getCadToolBarPanel = function(title, objectName, hasBackButton) { var appWin = EAction.getMainWindow(); var cadToolBar = appWin.findChild("CadToolBar"); // create CAD toolbar if it does not exist already: if (isNull(cadToolBar)) { cadToolBar = new RCadToolBar(qsTr("CAD Tools"), appWin); cadToolBar.objectName = "CadToolBar"; // cadToolBar.updateIconSize(); cadToolBar.topLevelChanged.connect(function(onOff) { RSettings.setValue("CadToolBar/VerticalWhenFloating", false); }); cadToolBar.orientationChanged.connect(function(orientation) { RSettings.setValue("CadToolBar/VerticalWhenFloating", false); }); } return cadToolBar.getPanel(title, objectName, hasBackButton); }; /** * Shows the CAD toolbar panel with the given objectName. */ EAction.showCadToolBarPanel = function(objectName) { var appWin = EAction.getMainWindow(); if (isNull(appWin)) { return; } var toolBar = appWin.findChild("CadToolBar"); toolBar.showPanel(objectName); }; /** * Shows the CAD toolbar panel with the snap tools. */ EAction.showSnapTools = function() { EAction.showCadToolBarPanel("SnapToolsPanel"); }; /** * Shows the CAD toolbar panel with the main tools. */ EAction.showMainTools = function() { EAction.showCadToolBarPanel("MainToolsPanel"); }; /** * Shows the CAD toolbar panel with the point tools. */ EAction.showPointTools = function() { EAction.showCadToolBarPanel("PointToolsPanel"); }; /** * Shows the CAD toolbar panel with the line tools. */ EAction.showLineTools = function() { EAction.showCadToolBarPanel("LineToolsPanel"); }; /** * Shows the CAD toolbar panel with the arc tools. */ EAction.showArcTools = function() { EAction.showCadToolBarPanel("ArcToolsPanel"); }; /** * Shows the CAD toolbar panel with the circle tools. */ EAction.showCircleTools = function() { EAction.showCadToolBarPanel("CircleToolsPanel"); }; /** * Shows the CAD toolbar panel with the dimension tools. */ EAction.showDimensionTools = function() { EAction.showCadToolBarPanel("DimensionToolsPanel"); }; /** * Shows the CAD toolbar panel with the ellipse tools. */ EAction.showEllipseTools = function() { EAction.showCadToolBarPanel("EllipseToolsPanel"); }; /** * Shows the CAD toolbar panel with the spline tools. */ EAction.showSplineTools = function() { EAction.showCadToolBarPanel("SplineToolsPanel"); }; /** * Shows the CAD toolbar panel with the polyline tools. */ EAction.showPolylineTools = function() { EAction.showCadToolBarPanel("PolylineToolsPanel"); }; /** * Shows the CAD toolbar panel with the shape tools. */ EAction.showShapeTools = function() { EAction.showCadToolBarPanel("ShapeToolsPanel"); }; /** * Shows the CAD toolbar panel with the modification tools. */ EAction.showModificationTools = function() { EAction.showCadToolBarPanel("ModifyToolsPanel"); }; /** * Shows the CAD toolbar panel with the measuring / info tools. */ EAction.showInformationTools = function() { EAction.showCadToolBarPanel("InformationToolsPanel"); }; /** * Shows the CAD toolbar panel with the selection tools. */ EAction.showSelectTools = function() { EAction.showCadToolBarPanel("SelectToolsPanel"); }; /** * Helper function to conveniently add the given action to a menu, toolbar and * CAD toolbar. * * \param action RAction object. * \param iface Interface to use to retrieve the appropriate menu, toolbar and CAD toolbar panel. * \param addToMenu True to add this action to the appropriate menu. * \param addToToolbar True to add this action to the appropriate toolbar. * \param addToCadToolbar True to add this action to the appropriate CAD toolbar panel. * \param addSeparator True to add a separator before this action. */ EAction.addGuiActionTo = function(action, iface, addToMenu, addToToolBar, addToCadToolBar, addSeparator) { var className = action.getScriptClass(); if (isNull(addToMenu)) { addToMenu = false; } if (isNull(addToToolBar)) { addToToolBar = false; } if (isNull(addToCadToolBar)) { addToCadToolBar = false; } if (isNull(addSeparator)) { addSeparator = false; } var addToUserToolBar1 = false; var addToUserToolBar2 = false; if (className.length!==0) { var key = className + "/VisibleInMenu"; addToMenu = RSettings.getBoolValue(key, addToMenu); if (!RSettings.hasValue(key)) { RSettings.setValue(key, addToMenu); } key = className + "/VisibleInToolBar"; addToToolBar = RSettings.getBoolValue(key, addToToolBar); if (!RSettings.hasValue(key)) { RSettings.setValue(key, addToToolBar); } key = className + "/VisibleInCadToolBar"; addToCadToolBar = RSettings.getBoolValue(key, addToCadToolBar); if (!RSettings.hasValue(key)) { RSettings.setValue(key, addToCadToolBar); } key = className + "/VisibleInUserToolBar1"; addToUserToolBar1 = RSettings.getBoolValue(key, addToUserToolBar1); if (!RSettings.hasValue(key)) { RSettings.setValue(key, addToUserToolBar1); } key = className + "/VisibleInUserToolBar2"; addToUserToolBar2 = RSettings.getBoolValue(key, addToUserToolBar2); if (!RSettings.hasValue(key)) { RSettings.setValue(key, addToUserToolBar2); } } if (isNull(iface)) { qWarning("EAction.js:", "addGuiActionTo(): iface not defined"); } if (action.icon.isNull() && !action.isIconDisabled()) { action.setIcon(autoPath("scripts/Empty.svg")); } var separator; if (addSeparator) { separator = new RGuiAction("", RMainWindowQt.getMainWindow()); separator.setSeparator(true); //separator.setSortOrder(action.getSortOrder() - 1); } if (addToMenu) { if (isFunction(iface.getMenu)) { var menu = iface.getMenu(); if (!isNull(menu)) { if (!isNull(separator)) { separator.addToMenu(menu); } action.addToMenu(menu); } } } if (addToToolBar) { if (isFunction(iface.getToolBar)) { var tb = iface.getToolBar(); if (!isNull(tb)) { action.addToToolBar(tb); if (addSeparator) { var sp = new RGuiAction("", RMainWindowQt.getMainWindow()); sp.setSeparator(true); sp.setSortOrder(action.getSortOrder() - 1); sp.addToToolBar(tb); } } } } if (addToCadToolBar) { if (isFunction(iface.getCadToolBarPanel)) { var ctb = iface.getCadToolBarPanel(); if (!isNull(ctb)) { // if (!isNull(separator)) { // CadToolBarPanel.prototype.addAction.call(ctb, separator); // } //CadToolBarPanel.prototype.addAction.call(ctb, action); //ctb.addAction(action); action.addToWidget(ctb); } } } var appWin = EAction.getMainWindow(); if (addToUserToolBar1) { var tb = appWin.findChild("UserToolBar1"); if (!isNull(tb)) { action.addToToolBar(tb); } } if (addToUserToolBar2) { var tb = appWin.findChild("UserToolBar2"); if (!isNull(tb)) { action.addToToolBar(tb); } } }; //EAction.addGuiActionToWidgets = function(action, widgetNames) { // var appWin = EAction.getMainWindow(); // var className = action.getScriptClass(); // var addToMenu, addToToolBar, addToCadToolBar; // if (className.length!==0) { // var key = className + "/VisibleInMenu"; // addToMenu = RSettings.getBoolValue(key, addToMenu); // if (!RSettings.hasValue(key)) { // RSettings.setValue(key, addToMenu); // } // key = className + "/VisibleInToolBar"; // addToToolBar = RSettings.getBoolValue(key, addToToolBar); // if (!RSettings.hasValue(key)) { // RSettings.setValue(key, addToToolBar); // } // key = className + "/VisibleInCadToolBar"; // addToCadToolBar = RSettings.getBoolValue(key, addToCadToolBar); // if (!RSettings.hasValue(key)) { // RSettings.setValue(key, addToCadToolBar); // } // } // var i, w; // var oldWidgets = action.associatedWidgets(); // for (i=0; i