/** * 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_draw_image Image Drawing Tool * \ingroup ecma_draw * * \brief This module contains the ECMAScript implementation of the image * drawing tool. */ include("scripts/Draw/Draw.js"); /** * \class Image * \brief Inserts an image (bitmap) into the drawing. * \ingroup ecma_draw_image */ function Image(guiAction) { Draw.call(this, guiAction); this.fileName = undefined; this.image = undefined; this.width = undefined; this.height = undefined; this.angle = undefined; this.pos = undefined; if (!isNull(guiAction)) { var url = this.guiAction.data(); if (!isNull(url) && isFunction(url.isLocalFile) && url.isLocalFile()) { this.fileName = url.toLocalFile(); } } this.setUiOptions(Image.includeBasePath + "/Image.ui"); } Image.State = { SettingPosition : 0 }; Image.prototype = new Draw(); Image.includeBasePath = includeBasePath; Image.prototype.beginEvent = function() { Draw.prototype.beginEvent.call(this); if (isNull(this.fileName)) { this.fileName = this.getFileName(); } if (isNull(this.fileName)) { this.terminate(); return; } this.image = new RImageEntity( this.getDocument(), new RImageData(this.fileName, new RVector(0,0), new RVector(1,0), new RVector(0,1), 50, 50, 0) ); // initial size is image size in pixels (i.e. one pixel -> one unit): this.width = this.image.getPixelWidth(); this.height = this.image.getPixelHeight(); var optionsToolBar = EAction.getOptionsToolBar(); var widthEdit = optionsToolBar.findChild("Width"); var heightEdit = optionsToolBar.findChild("Height"); widthEdit.setValue(this.width); heightEdit.setValue(this.height); this.setState(Image.State.SettingPosition); }; Image.prototype.finishEvent = function() { Draw.prototype.finishEvent.call(this); if (!isNull(this.image)) { destr(this.image); } }; Image.isSupportedBitmapFile = function(filePath) { var formats = Image.getSupportedFormats(false); var fi = new QFileInfo(filePath); return formats.indexOf(fi.suffix().toLowerCase())!==-1; }; Image.getSupportedFormats = function(noAlias) { var ret = []; var formats = QImageReader.supportedImageFormats(); for (var i=0; i