| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- /**
- * 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/Draw/Dimension/Dimension.js");
- /**
- * \class DimRotated
- * \brief Draw rotated dimension (horizontal, vertical or other fixed angle).
- * \ingroup ecma_draw_dimension
- */
- function DimRotated(guiAction) {
- Dimension.call(this, guiAction);
- this.data = new RDimRotatedData();
- this.setUiOptions(["../Dimension.ui", "DimRotated.ui"], false);
- }
- DimRotated.prototype = new Dimension();
- DimRotated.State = {
- SettingPoint1 : 0,
- SettingPoint2 : 1,
- SettingDimPos : 2
- };
- DimRotated.prototype.beginEvent = function() {
- Dimension.prototype.beginEvent.call(this);
- this.setState(DimRotated.State.SettingPoint1);
- };
- DimRotated.prototype.setState = function(state) {
- Dimension.prototype.setState.call(this, state);
- this.getDocumentInterface().setClickMode(RAction.PickCoordinate);
- this.setCrosshairCursor();
- var appWin = RMainWindowQt.getMainWindow();
- switch (this.state) {
- case DimRotated.State.SettingPoint1:
- this.data.setExtensionPoint1(RVector.invalid);
- this.data.setExtensionPoint2(RVector.invalid);
- this.data.setDefinitionPoint(RVector.invalid);
- var trFirstPoint = qsTr("First extension line origin");
- this.setCommandPrompt(trFirstPoint);
- this.setLeftMouseTip(trFirstPoint);
- this.setRightMouseTip(EAction.trCancel);
- break;
- case DimRotated.State.SettingPoint2:
- this.data.setExtensionPoint2(RVector.invalid);
- this.data.setDefinitionPoint(RVector.invalid);
- var trSecondPoint = qsTr("Second extension line origin");
- this.setCommandPrompt(trSecondPoint);
- this.setLeftMouseTip(trSecondPoint);
- this.setRightMouseTip(EAction.trBack);
- break;
- case DimRotated.State.SettingDimPos:
- this.data.setDefinitionPoint(RVector.invalid);
- var trDimPos = qsTr("Dimension line location");
- this.setCommandPrompt(trDimPos);
- this.setLeftMouseTip(trDimPos);
- this.setRightMouseTip(EAction.trBack);
- break;
- }
- EAction.showSnapTools();
- };
- DimRotated.prototype.escapeEvent = function() {
- switch (this.state) {
- case DimRotated.State.SettingPoint1:
- EAction.prototype.escapeEvent.call(this);
- break;
- case DimRotated.State.SettingPoint2:
- this.setState(DimRotated.State.SettingPoint1);
- break;
- case DimRotated.State.SettingDimPos:
- this.setState(DimRotated.State.SettingPoint2);
- break;
- }
- };
- DimRotated.prototype.pickCoordinate = function(event, preview) {
- var di = this.getDocumentInterface();
- var pos = event.getModelPosition();
- switch (this.state) {
- case DimRotated.State.SettingPoint1:
- this.autoAdjustScale(pos);
- this.data.setExtensionPoint1(pos);
- if (!preview) {
- di.setRelativeZero(pos);
- this.setState(DimRotated.State.SettingPoint2);
- }
- break;
- case DimRotated.State.SettingPoint2:
- this.data.setExtensionPoint2(pos);
- // set definition point (dimension line position) to something
- // reasonable for the preview:
- var angle =
- this.data.getExtensionPoint1().getAngleTo(this.data.getExtensionPoint2()) +
- Math.PI/2.0;
- var doc = di.getDocument();
- var dimStyle = doc.queryDimStyleDirect();
- var dimtxt = dimStyle.getDouble(RS.DIMTXT);
- var dimscale = dimStyle.getDouble(RS.DIMSCALE);
- var dp = this.data.getExtensionPoint2();
- dp = dp.operator_add(RVector.createPolar(dimtxt*2*dimscale, angle));
- this.data.setDefinitionPoint(dp);
- if (preview) {
- this.updatePreview();
- }
- else {
- di.setRelativeZero(pos);
- this.setState(DimRotated.State.SettingDimPos);
- }
- break;
- case DimRotated.State.SettingDimPos:
- this.data.setDefinitionPoint(pos);
- if (preview) {
- this.updatePreview();
- }
- else {
- var op = this.getOperation(false);
- if (!isNull(op)) {
- di.applyOperation(op);
- di.setRelativeZero(pos);
- this.setState(DimRotated.State.SettingPoint1);
- }
- }
- break;
- }
- };
- DimRotated.prototype.getOperation = function(preview) {
- var entity = this.getEntity(preview);
- if (isNull(entity)) {
- return undefined;
- }
- return new RAddObjectOperation(entity, this.getToolTitle());
- };
- DimRotated.prototype.getEntity = function(preview) {
- if (!this.data.isValid()) {
- return undefined;
- }
- var doc = this.getDocument();
- var factor = this.getFactor();
- var scaled_data = this.data;
- scaled_data.setLinearFactor(factor);
- var entity = new RDimRotatedEntity(doc, scaled_data);
- if (!isEntity(entity)) {
- return undefined;
- }
- this.initEntity(entity, preview);
- return entity;
- };
- /**
- * Can be overwritten to initialize the added entity.
- */
- DimRotated.prototype.initEntity = function(entity, preview) {
- };
- /*
- DimRotated.prototype.showUiOptions = function(resume, restoreFromSettings) {
- Dimension.prototype.showUiOptions.call(this, resume, restoreFromSettings);
- };
- DimRotated.prototype.hideUiOptions = function(saveToSettings) {
- debugger;
- Dimension.prototype.hideUiOptions.call(this, saveToSettings);
- };
- */
- /**
- * Called when the user changes the angle in the options toolbar.
- */
- DimRotated.prototype.slotAngleChanged = function(value) {
- if (!isNull(this.data)) {
- if (isNaN(value)) {
- value=0.0;
- }
- this.data.setRotation(value);
- }
- };
|