1 /****************************************************************************
2 ** $Id: rs_actiondrawlinebisector.cpp 1134 2004-07-13 23:26:13Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actiondrawlinebisector.h"
29 #include "rs_creation.h"
30 #include "rs_snapper.h"
34 RS_ActionDrawLineBisector::RS_ActionDrawLineBisector(
35 RS_EntityContainer& container,
36 RS_GraphicView& graphicView)
37 :RS_PreviewActionInterface("Draw Bisectors", container, graphicView) {
44 coord1 = Vector(false);
45 coord2 = Vector(false);
46 lastStatus = SetLine1;
49 QAction* RS_ActionDrawLineBisector::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
51 QAction * action = new QAction(tr("&Bisector"), 0);
52 // QAction* action = new QAction(tr("Bisector"), tr("&Bisector"),
53 // QKeySequence(), NULL);
54 action->setStatusTip(tr("Draw bisectors"));
59 void RS_ActionDrawLineBisector::trigger() {
60 RS_PreviewActionInterface::trigger();
62 //if (bisector!=NULL) {
63 RS_Creation creation(container, graphicView);
64 creation.createBisector(coord1,
70 /*RS_Entity* newEntity = NULL;
72 newEntity = new RS_Line(container,
75 if (newEntity!=NULL) {
76 newEntity->setLayerToActive();
77 newEntity->setPenToActive();
78 container->addEntity(newEntity);
82 document->startUndoCycle();
83 document->addUndoable(newEntity);
84 document->endUndoCycle();
86 graphicView->drawEntity(newEntity);
94 RS_DEBUG->print("RS_ActionDrawLineBisector::trigger:"
101 void RS_ActionDrawLineBisector::mouseMoveEvent(QMouseEvent* e) {
102 RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent begin");
104 Vector mouse = Vector(graphicView->toGraphX(e->x()),
105 graphicView->toGraphY(e->y()));
107 switch (getStatus()) {
113 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
114 if (en!=NULL && en->rtti()==RS2::EntityLine) {
115 line2 = (RS_Line*)en;
120 RS_Creation creation(preview, NULL, false);
121 creation.createBisector(coord1,
136 RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent end");
141 void RS_ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent* e) {
143 if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
149 Vector mouse = Vector(graphicView->toGraphX(e->x()),
150 graphicView->toGraphY(e->y()));
152 switch (getStatus()) {
155 RS_Entity* en = catchEntity(e, RS2::ResolveAll);
156 if (en!=NULL && en->rtti()==RS2::EntityLine) {
157 line1 = (RS_Line*)en;
174 void RS_ActionDrawLineBisector::commandEvent(RS_CommandEvent* e) {
175 QString c = e->getCommand().toLower();
177 if (checkCommand("help", c)) {
178 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
179 + getAvailableCommands().join(", "));
183 switch (getStatus()) {
186 lastStatus = (Status)getStatus();
187 if (checkCommand("length", c)) {
191 setStatus(SetLength);
192 } else if (checkCommand("number", c)) {
196 setStatus(SetNumber);
202 double l = RS_Math::eval(c, &ok);
206 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
208 RS_DIALOGFACTORY->requestOptions(this, true, true);
209 setStatus(lastStatus);
215 int n = (int)RS_Math::eval(c, &ok);
219 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
221 RS_DIALOGFACTORY->requestOptions(this, true, true);
222 setStatus(lastStatus);
234 QStringList RS_ActionDrawLineBisector::getAvailableCommands() {
237 switch (getStatus()) {
240 cmd += command("length");
241 cmd += command("number");
251 void RS_ActionDrawLineBisector::updateMouseButtonHints() {
252 switch (getStatus()) {
254 RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"),
258 RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"),
262 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"),
266 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"),
270 RS_DIALOGFACTORY->updateMouseWidget("", "");
277 void RS_ActionDrawLineBisector::showOptions() {
278 RS_ActionInterface::showOptions();
280 RS_DIALOGFACTORY->requestOptions(this, true);
285 void RS_ActionDrawLineBisector::hideOptions() {
286 RS_ActionInterface::hideOptions();
288 RS_DIALOGFACTORY->requestOptions(this, false);
293 void RS_ActionDrawLineBisector::updateMouseCursor() {
294 graphicView->setMouseCursor(RS2::CadCursor);
299 void RS_ActionDrawLineBisector::updateToolBar() {
300 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);