1 // rs_actiondrawlineparallel.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -----------------------------------------------------------
12 // JLH 05/22/2010 Added this text. :-)
15 #include "rs_actiondrawlineparallel.h"
17 #include "rs_creation.h"
18 #include "rs_snapper.h"
19 #include "rs_actiondrawlineparallelthrough.h"
21 RS_ActionDrawLineParallel::RS_ActionDrawLineParallel(
22 RS_EntityContainer& container,
23 RS_GraphicView& graphicView)
24 :RS_PreviewActionInterface("Draw Parallels", container, graphicView)
30 coord = Vector(false);
33 QAction * RS_ActionDrawLineParallel::createGUIAction(RS2::ActionType type, QObject * /*parent*/)
35 QAction * action = NULL;
37 if (type == RS2::ActionDrawLineParallel)
39 action = new QAction(tr("Para&llel"), 0);
40 // action = new QAction(tr("Parallel"), tr("Para&llel"),
41 // QKeySequence(), NULL);
43 else if (type == RS2::ActionDrawArcParallel)
45 action = new QAction(tr("&Concentric"), 0);
46 // action = new QAction(tr("Concentric"), tr("&Concentric"),
47 // QKeySequence(), NULL);
49 else if (type == RS2::ActionDrawCircleParallel)
51 action = new QAction(tr("&Concentric"), 0);
52 // action = new QAction(tr("Concentric"), tr("&Concentric"),
53 // QKeySequence(), NULL);
56 action->setStatusTip(tr("Draw parallels to existing lines, arcs, circles"));
60 void RS_ActionDrawLineParallel::trigger()
62 RS_PreviewActionInterface::trigger();
64 RS_Creation creation(container, graphicView);
65 RS_Entity* e = creation.createParallel(coord,
70 RS_DEBUG->print("RS_ActionDrawLineParallel::trigger:"
71 " No parallels added\n");
77 void RS_ActionDrawLineParallel::mouseMoveEvent(QMouseEvent* e) {
78 RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent begin");
80 coord = Vector(graphicView->toGraphX(e->x()),
81 graphicView->toGraphY(e->y()));
83 entity = catchEntity(e, RS2::ResolveAll);
85 switch (getStatus()) {
90 RS_Creation creation(preview, NULL, false);
91 creation.createParallel(coord,
103 RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent end");
108 void RS_ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent* e) {
109 if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
118 void RS_ActionDrawLineParallel::updateMouseButtonHints() {
119 if (RS_DIALOGFACTORY!=NULL) {
120 switch (getStatus()) {
122 RS_DIALOGFACTORY->updateMouseWidget(
123 tr("Specify Distance <%1> or select entity or [%2]")
124 .arg(distance).arg(RS_COMMANDS->command("through")),
129 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), "");
133 RS_DIALOGFACTORY->updateMouseWidget("", "");
141 void RS_ActionDrawLineParallel::showOptions() {
142 RS_ActionInterface::showOptions();
144 if (RS_DIALOGFACTORY!=NULL) {
145 RS_DIALOGFACTORY->requestOptions(this, true);
147 updateMouseButtonHints();
152 void RS_ActionDrawLineParallel::hideOptions() {
153 RS_ActionInterface::hideOptions();
155 if (RS_DIALOGFACTORY!=NULL) {
156 RS_DIALOGFACTORY->requestOptions(this, false);
162 void RS_ActionDrawLineParallel::commandEvent(RS_CommandEvent* e) {
163 QString c = e->getCommand().toLower();
165 if (checkCommand("help", c)) {
166 if (RS_DIALOGFACTORY!=NULL) {
167 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
168 + getAvailableCommands().join(", "));
173 switch (getStatus()) {
175 if (checkCommand("through", c)) {
177 graphicView->setCurrentAction(
178 new RS_ActionDrawLineParallelThrough(*container,
180 } else if (checkCommand("number", c)) {
184 setStatus(SetNumber);
187 double d = RS_Math::eval(c, &ok);
188 if (ok==true && d>1.0e-10) {
191 if (RS_DIALOGFACTORY!=NULL) {
192 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
195 if (RS_DIALOGFACTORY!=NULL) {
196 RS_DIALOGFACTORY->requestOptions(this, true, true);
198 updateMouseButtonHints();
199 //setStatus(SetEntity);
206 int n = c.toInt(&ok);
211 if (RS_DIALOGFACTORY!=NULL) {
212 RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. "
217 if (RS_DIALOGFACTORY!=NULL) {
218 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
221 if (RS_DIALOGFACTORY!=NULL) {
222 RS_DIALOGFACTORY->requestOptions(this, true, true);
224 setStatus(SetEntity);
235 QStringList RS_ActionDrawLineParallel::getAvailableCommands() {
238 switch (getStatus()) {
240 cmd += command("number");
241 cmd += command("through");
252 void RS_ActionDrawLineParallel::updateMouseCursor() {
253 graphicView->setMouseCursor(RS2::CadCursor);
258 void RS_ActionDrawLineParallel::updateToolBar() {
259 if (RS_DIALOGFACTORY!=NULL) {
260 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines);