]> Shamusworld >> Repos - architektonas/blob - src/actions/actiondrawhatch.cpp
Initial removal of unnecessary rs_ prefixes from files.
[architektonas] / src / actions / actiondrawhatch.cpp
1 // actiondrawhatch.cpp
2 //
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 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/22/2010  Added this text. :-)
15 //
16
17 #include "actiondrawhatch.h"
18
19 #include "debug.h"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
22 #include "information.h"
23
24 ActionDrawHatch::ActionDrawHatch(RS_EntityContainer & container, GraphicView & graphicView):
25         ActionInterface("Draw Hatch", container, graphicView)
26 {
27         hatch = NULL;
28 }
29
30 ActionDrawHatch::~ActionDrawHatch()
31 {
32 }
33
34 void ActionDrawHatch::init(int status)
35 {
36         ActionInterface::init(status);
37         clearPreview();
38
39         RS_Hatch tmp(container, data);
40         tmp.setLayerToActive();
41         tmp.setPenToActive();
42
43         if (RS_DIALOGFACTORY->requestHatchDialog(&tmp))
44         {
45                 data = tmp.getData();
46                 trigger();
47                 finish();
48                 graphicView->redraw();
49         }
50         else
51                 finish();
52 }
53
54 void ActionDrawHatch::trigger()
55 {
56         RS_DEBUG->print("ActionDrawHatch::trigger()");
57
58         deleteSnapper();
59         RS_Entity * e;
60
61         // deselect unhatchable entities:
62         for(e=container->firstEntity(RS2::ResolveNone); e!=NULL;
63                 e=container->nextEntity(RS2::ResolveNone))
64         {
65                 if (e->isSelected()
66                     && (e->rtti() == RS2::EntityHatch
67                         || e->rtti() == RS2::EntityEllipse || e->rtti() == RS2::EntityPoint
68                         || e->rtti() == RS2::EntityText
69                         || RS_Information::isDimension(e->rtti())))
70                         e->setSelected(false);
71         }
72
73         for(e=container->firstEntity(RS2::ResolveAll); e!=NULL;
74                 e=container->nextEntity(RS2::ResolveAll))
75         {
76                 if (e->isSelected()
77                         && (e->rtti() == RS2::EntityHatch
78                         || e->rtti() == RS2::EntityEllipse || e->rtti() == RS2::EntityPoint
79                         || e->rtti() == RS2::EntityText
80                         || RS_Information::isDimension(e->rtti())))
81                         e->setSelected(false);
82         }
83
84         // look for selected contours:
85         bool haveContour = false;
86
87         for(e=container->firstEntity(RS2::ResolveAll); e!=NULL;
88                 e=container->nextEntity(RS2::ResolveAll))
89                 if (e->isSelected())
90                         haveContour = true;
91
92         if (!haveContour)
93         {
94                 std::cerr << "no contour selected\n";
95                 return;
96         }
97
98         hatch = new RS_Hatch(container, data);
99         hatch->setLayerToActive();
100         hatch->setPenToActive();
101         RS_EntityContainer * loop = new RS_EntityContainer(hatch);
102         loop->setPen(RS_Pen(RS2::FlagInvalid));
103
104         // add selected contour:
105         for(RS_Entity * e=container->firstEntity(RS2::ResolveAll); e!=NULL;
106              e=container->nextEntity(RS2::ResolveAll))
107         {
108                 if (e->isSelected())
109                 {
110                         e->setSelected(false);
111
112                         // entity is part of a complex entity (spline, polyline, ..):
113                         if (e->getParent() != NULL
114                                 && (e->getParent()->rtti() == RS2::EntitySpline
115                                 || e->getParent()->rtti() == RS2::EntityPolyline))
116                                 e->getParent()->setSelected(false);
117
118                         RS_Entity * cp = e->clone();
119                         cp->setPen(RS_Pen(RS2::FlagInvalid));
120                         cp->reparent(loop);
121                         loop->addEntity(cp);
122                 }
123         }
124
125         hatch->addEntity(loop);
126
127         if (hatch->validate())
128         {
129                 container->addEntity(hatch);
130
131                 if (document)
132                 {
133                         document->startUndoCycle();
134                         document->addUndoable(hatch);
135                         document->endUndoCycle();
136                 }
137
138                 hatch->update();
139                 graphicView->drawEntity(hatch);
140                 RS_DIALOGFACTORY->commandMessage(tr("Hatch created successfully."));
141         }
142         else
143         {
144                 delete hatch;
145                 hatch = NULL;
146                 RS_DIALOGFACTORY->commandMessage(tr("Invalid hatch area. Please check that "
147                         "the entities chosen form one or more closed contours."));
148         }
149 }
150
151 void ActionDrawHatch::mouseMoveEvent(QMouseEvent *)
152 {
153         RS_DEBUG->print("ActionDrawHatch::mouseMoveEvent begin");
154
155         /*if (getStatus()==SetPos) {
156             Vector mouse = snapPoint(e);
157             pos = mouse;
158
159
160             deletePreview();
161             if (hatch!=NULL && !hatch->isVisible()) {
162                 hatch->setVisible(true);
163             }
164             offset = Vector(graphicView->toGuiDX(pos.x),
165                                -graphicView->toGuiDY(pos.y));
166             drawPreview();
167            }*/
168
169         RS_DEBUG->print("ActionDrawHatch::mouseMoveEvent end");
170 }
171
172 void ActionDrawHatch::mouseReleaseEvent(QMouseEvent * e)
173 {
174         if (e->button() == Qt::LeftButton)
175         {
176                 Vector mouse = snapPoint(e);
177
178                 switch (getStatus())
179                 {
180                 case ShowDialog:
181                         break;
182
183                 default:
184                         break;
185                 }
186         }
187         else if (e->button() == Qt::RightButton)
188         {
189                 //deletePreview();
190                 deleteSnapper();
191                 init(getStatus() - 1);
192         }
193 }
194
195 void ActionDrawHatch::updateMouseButtonHints()
196 {
197         RS_DIALOGFACTORY->updateMouseWidget("", "");
198 }
199
200 void ActionDrawHatch::updateMouseCursor()
201 {
202         graphicView->setMouseCursor(RS2::CadCursor);
203 }
204
205 void ActionDrawHatch::updateToolBar()
206 {
207         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
208 }