| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- /**
- * 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("Draw.js");
- /**
- * \class DrawBasedOnThreeCircles
- * \brief Base class for drawing tools that draw something based on
- * three given circles or arcs.
- * \ingroup ecma_misc_draw
- */
- function DrawBasedOnThreeCircles(guiAction) {
- EAction.call(this, guiAction);
- this.entity1 = undefined;
- this.shape1 = undefined;
- this.pos1 = undefined;
- this.entity2 = undefined;
- this.shape2 = undefined;
- this.pos2 = undefined;
- this.entity3 = undefined;
- this.shape3 = undefined;
- this.pos3 = undefined;
- }
- DrawBasedOnThreeCircles.prototype = new EAction();
- DrawBasedOnThreeCircles.State = {
- ChoosingShape1 : 0,
- ChoosingShape2 : 1,
- ChoosingShape3 : 2
- };
- DrawBasedOnThreeCircles.prototype.beginEvent = function() {
- EAction.prototype.beginEvent.call(this);
- this.setState(DrawBasedOnThreeCircles.State.ChoosingShape1);
- };
- DrawBasedOnThreeCircles.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 DrawBasedOnThreeCircles.State.ChoosingShape1:
- this.entity1 = undefined;
- this.shape1 = undefined;
- this.entity2 = undefined;
- this.shape2 = undefined;
- this.entity3 = undefined;
- this.shape3 = undefined;
- this.center = undefined;
- var trFirstEntity = qsTr("First arc or circle");
- this.setCommandPrompt(trFirstEntity);
- this.setLeftMouseTip(trFirstEntity);
- this.setRightMouseTip(EAction.trCancel);
- break;
- case DrawBasedOnThreeCircles.State.ChoosingShape2:
- this.entity2 = undefined;
- this.shape2 = undefined;
- this.entity3 = undefined;
- this.shape3 = undefined;
- this.center = undefined;
- var trSecondEntity = qsTr("Second arc or circle");
- this.setCommandPrompt(trSecondEntity);
- this.setLeftMouseTip(trSecondEntity);
- this.setRightMouseTip(EAction.trBack);
- break;
- case DrawBasedOnThreeCircles.State.ChoosingShape3:
- this.entity3 = undefined;
- this.shape3 = undefined;
- this.center = undefined;
- var trThirdEntity = qsTr("Third arc or circle");
- this.setCommandPrompt(trThirdEntity);
- this.setLeftMouseTip(trThirdEntity);
- this.setRightMouseTip(EAction.trBack);
- break;
- }
- };
- DrawBasedOnThreeCircles.prototype.escapeEvent = function() {
- switch (this.state) {
- case DrawBasedOnThreeCircles.State.ChoosingShape1:
- EAction.prototype.escapeEvent.call(this);
- break;
- case DrawBasedOnThreeCircles.State.ChoosingShape2:
- this.setState(DrawBasedOnThreeCircles.State.ChoosingShape1);
- break;
- case DrawBasedOnThreeCircles.State.ChoosingShape3:
- this.setState(DrawBasedOnThreeCircles.State.ChoosingShape2);
- break;
- }
- };
- DrawBasedOnThreeCircles.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 DrawBasedOnThreeCircles.State.ChoosingShape1:
- this.entity1 = entity;
- this.shape1 = shape;
- this.pos1 = pos;
- if (preview) {
- this.updatePreview();
- }
- else {
- this.setState(DrawBasedOnThreeCircles.State.ChoosingShape2);
- }
- break;
- case DrawBasedOnThreeCircles.State.ChoosingShape2:
- this.entity2 = entity;
- this.shape2 = shape;
- this.pos2 = pos;
- if (preview) {
- this.updatePreview();
- }
- else {
- this.setState(DrawBasedOnThreeCircles.State.ChoosingShape3);
- }
- break;
- case DrawBasedOnThreeCircles.State.ChoosingShape3:
- this.entity3 = entity;
- this.shape3 = shape;
- this.pos3 = pos;
- if (preview) {
- this.updatePreview();
- }
- else {
- var op = this.getOperation(false);
- if (!isNull(op)) {
- di.applyOperation(op);
- this.setState(DrawBasedOnThreeCircles.State.ChoosingShape1);
- }
- }
- break;
- }
- if (!preview && this.error.length!==0) {
- EAction.handleUserWarning(this.error);
- }
- };
- DrawBasedOnThreeCircles.prototype.getOperation = function(preview) {
- var shapes = this.getShapes(preview);
- if (isNull(shapes)) {
- return undefined;
- }
- var doc = this.getDocument();
- var op = new RAddObjectsOperation();
- op.setText(this.getToolTitle());
- for (var i=0; i<shapes.length; i++) {
- var entity = shapeToEntity(doc, shapes[i]);
- if (!isEntity(entity)) {
- continue;
- }
- op.addObject(entity);
- }
- return op;
- };
- /**
- * Implemented by child classes.
- */
- DrawBasedOnThreeCircles.prototype.getShapes = function(preview) {
- return undefined;
- };
- DrawBasedOnThreeCircles.prototype.getHighlightedEntities = function() {
- var ret = [];
- if (isEntity(this.entity1)) {
- ret.push(this.entity1.getId());
- }
- if (isEntity(this.entity2)) {
- ret.push(this.entity2.getId());
- }
- if (isEntity(this.entity3)) {
- ret.push(this.entity3.getId());
- }
- return ret;
- };
|