| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- /**
- * 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/EAction.js");
- include("scripts/Apollonius.js");
- include("scripts/ShapeAlgorithms.js");
- /**
- * \class LineRadicalAxis
- * \brief Point at the power center of three chosen circles.
- * \ingroup ecma_misc_draw
- */
- function LineRadicalAxis(guiAction) {
- EAction.call(this, guiAction);
- this.entity1 = undefined;
- this.shape1 = undefined;
- this.pos1 = undefined;
- this.entity2 = undefined;
- this.shape2 = undefined;
- this.pos2 = undefined;
- this.setUiOptions("LineRadicalAxis.ui");
- }
- LineRadicalAxis.prototype = new EAction();
- LineRadicalAxis.State = {
- ChoosingShape1 : 0,
- ChoosingShape2 : 1
- };
- LineRadicalAxis.prototype.beginEvent = function() {
- EAction.prototype.beginEvent.call(this);
- this.setState(LineRadicalAxis.State.ChoosingShape1);
- };
- LineRadicalAxis.prototype.setState = function(state) {
- EAction.prototype.setState.call(this, state);
- this.getDocumentInterface().setClickMode(RAction.PickEntity);
- this.setCrosshairCursor();
- var appWin = RMainWindowQt.getMainWindow();
- switch (this.state) {
- case LineRadicalAxis.State.ChoosingShape1:
- this.entity1 = undefined;
- this.shape1 = undefined;
- this.entity2 = undefined;
- this.shape2 = undefined;
- var trFirstEntity = qsTr("First arc or circle");
- this.setCommandPrompt(trFirstEntity);
- this.setLeftMouseTip(trFirstEntity);
- this.setRightMouseTip(EAction.trCancel);
- break;
- case LineRadicalAxis.State.ChoosingShape2:
- this.entity2 = undefined;
- this.shape2 = undefined;
- var trSecondEntity = qsTr("Second arc or circle");
- this.setCommandPrompt(trSecondEntity);
- this.setLeftMouseTip(trSecondEntity);
- this.setRightMouseTip(EAction.trBack);
- break;
- }
- };
- LineRadicalAxis.prototype.escapeEvent = function() {
- switch (this.state) {
- case LineRadicalAxis.State.ChoosingShape1:
- EAction.prototype.escapeEvent.call(this);
- break;
- case LineRadicalAxis.State.ChoosingShape2:
- this.setState(LineRadicalAxis.State.ChoosingShape1);
- break;
- }
- };
- LineRadicalAxis.prototype.pickEntity = function(event, preview) {
- this.error = "";
- var di = this.getDocumentInterface();
- var doc = this.getDocument();
- var entityId = this.getEntityId(event, preview);
- var entity = doc.queryEntity(entityId);
- var pos = event.getModelPosition();
- if (isNull(entity)) {
- return;
- }
- var shape = entity.getClosestSimpleShape(pos);
- if (!isArcShape(shape) &&
- !isCircleShape(shape)) {
- if (!preview) {
- EAction.warnNotArcCircle();
- }
- return;
- }
- switch (this.state) {
- case LineRadicalAxis.State.ChoosingShape1:
- this.entity1 = entity;
- this.shape1 = shape;
- this.pos1 = pos;
- if (preview) {
- this.updatePreview();
- }
- else {
- this.setState(LineRadicalAxis.State.ChoosingShape2);
- }
- break;
- case LineRadicalAxis.State.ChoosingShape2:
- this.entity2 = entity;
- this.shape2 = shape;
- this.pos2 = pos;
- if (preview) {
- this.updatePreview();
- }
- else {
- var op = this.getOperation(false);
- if (!isNull(op)) {
- di.applyOperation(op);
- this.setState(LineRadicalAxis.State.ChoosingShape1);
- }
- }
- break;
- }
- if (!preview && this.error.length!==0) {
- EAction.handleUserWarning(this.error);
- }
- };
- LineRadicalAxis.prototype.getOperation = function(preview) {
- var shape = this.getLineRadicalAxis(preview);
- if (isNull(shape)) {
- return undefined;
- }
- var doc = this.getDocument();
- var entity = shapeToEntity(doc, shape);
- if (!isEntity(entity)) {
- return undefined;
- }
- return new RAddObjectOperation(entity, this.getToolTitle());
- };
- LineRadicalAxis.prototype.getLineRadicalAxis = function(preview) {
- if (isNull(this.shape1) || isNull(this.shape2)) {
- return undefined;
- }
- return Apollonius.getRadicalAxis(getPtr(this.shape1), getPtr(this.shape2));
- };
- LineRadicalAxis.prototype.getHighlightedEntities = function() {
- var ret = [];
- if (isEntity(this.entity1)) {
- ret.push(this.entity1.getId());
- }
- if (isEntity(this.entity2)) {
- ret.push(this.entity2.getId());
- }
- return ret;
- };
|