1 /****************************************************************************
2 **
3 ** This file is part of the LibreCAD project, a 2D CAD program
4 **
5 ** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
6 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
7 **
8 **
9 ** This file may be distributed and/or modified under the terms of the
10 ** GNU General Public License version 2 as published by the Free Software
11 ** Foundation and appearing in the file gpl-2.0.txt included in the
12 ** packaging of this file.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ** GNU General Public License for more details.
18 **
19 ** You should have received a copy of the GNU General Public License
20 ** along with this program; if not, write to the Free Software
21 ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 **
23 ** This copyright notice MUST APPEAR in all copies of the script!
24 **
25 **********************************************************************/
26 
27 #include "rs_actiondrawpoint.h"
28 
29 #include <QAction>
30 #include <QMouseEvent>
31 #include "rs_dialogfactory.h"
32 #include "rs_graphicview.h"
33 #include "rs_commandevent.h"
34 #include "rs_point.h"
35 #include "rs_coordinateevent.h"
36 
RS_ActionDrawPoint(RS_EntityContainer & container,RS_GraphicView & graphicView)37 RS_ActionDrawPoint::RS_ActionDrawPoint(RS_EntityContainer& container,
38                                        RS_GraphicView& graphicView)
39         :RS_PreviewActionInterface("Draw Points",
40 						   container, graphicView)
41 		, pt(new RS_Vector{})
42 {
43 	actionType=RS2::ActionDrawPoint;
44 }
45 
46 RS_ActionDrawPoint::~RS_ActionDrawPoint() = default;
47 
48 
trigger()49 void RS_ActionDrawPoint::trigger() {
50 	if (pt->valid) {
51 		RS_Point* point = new RS_Point(container, RS_PointData(*pt));
52         container->addEntity(point);
53 
54         if (document) {
55             document->startUndoCycle();
56             document->addUndoable(point);
57             document->endUndoCycle();
58         }
59 
60 		graphicView->moveRelativeZero(*pt);
61 		graphicView->redraw((RS2::RedrawMethod) (RS2::RedrawDrawing | RS2::RedrawOverlay));
62     }
63 }
64 
65 
66 
mouseMoveEvent(QMouseEvent * e)67 void RS_ActionDrawPoint::mouseMoveEvent(QMouseEvent* e) {
68     snapPoint(e);
69 }
70 
71 
72 
mouseReleaseEvent(QMouseEvent * e)73 void RS_ActionDrawPoint::mouseReleaseEvent(QMouseEvent* e) {
74     if (e->button()==Qt::LeftButton) {
75         RS_CoordinateEvent ce(snapPoint(e));
76         coordinateEvent(&ce);
77     } else if (e->button()==Qt::RightButton) {
78         init(getStatus()-1);
79     }
80 }
81 
82 
83 
coordinateEvent(RS_CoordinateEvent * e)84 void RS_ActionDrawPoint::coordinateEvent(RS_CoordinateEvent* e) {
85 	if (e==nullptr) {
86         return;
87     }
88 
89     RS_Vector mouse = e->getCoordinate();
90 
91 	*pt = mouse;
92     trigger();
93 }
94 
95 
96 
commandEvent(RS_CommandEvent * e)97 void RS_ActionDrawPoint::commandEvent(RS_CommandEvent* e) {
98     QString c = e->getCommand().toLower();
99 
100 	if (checkCommand("help", c)) {
101 		RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
102 										 + getAvailableCommands().join(", "));
103 		return;
104 	}
105 }
106 
107 
108 
getAvailableCommands()109 QStringList RS_ActionDrawPoint::getAvailableCommands() {
110 	return {};
111 }
112 
113 
updateMouseButtonHints()114 void RS_ActionDrawPoint::updateMouseButtonHints() {
115 	switch (getStatus()) {
116 	case 0:
117 		RS_DIALOGFACTORY->updateMouseWidget(tr("Specify location"), tr("Cancel"));
118 		break;
119 	default:
120 		RS_DIALOGFACTORY->updateMouseWidget();
121 		break;
122 	}
123 }
124 
125 
126 
updateMouseCursor()127 void RS_ActionDrawPoint::updateMouseCursor() {
128     graphicView->setMouseCursor(RS2::CadCursor);
129 }
130 
131 // EOF
132