]> Shamusworld >> Repos - architektonas/blob - src/actions/actiondrawhatch.cpp
Fixed problem with MDI activation.
[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(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         Hatch tmp(container, data);
40         tmp.setLayerToActive();
41         tmp.setPenToActive();
42
43         if (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         DEBUG->print("ActionDrawHatch::trigger()");
57
58 //      deleteSnapper();
59         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                         || 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                         || 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 Hatch(container, data);
99         hatch->setLayerToActive();
100         hatch->setPenToActive();
101         EntityContainer * loop = new EntityContainer(hatch);
102         loop->setPen(Pen(RS2::FlagInvalid));
103
104         // add selected contour:
105         for(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                         Entity * cp = e->clone();
119                         cp->setPen(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                 DIALOGFACTORY->commandMessage(tr("Hatch created successfully."));
140         }
141         else
142         {
143                 delete hatch;
144                 hatch = NULL;
145                 DIALOGFACTORY->commandMessage(tr("Invalid hatch area. Please check that "
146                         "the entities chosen form one or more closed contours."));
147         }
148 }
149
150 void ActionDrawHatch::mouseMoveEvent(QMouseEvent *)
151 {
152         DEBUG->print("ActionDrawHatch::mouseMoveEvent begin");
153         DEBUG->print("ActionDrawHatch::mouseMoveEvent end");
154 }
155
156 void ActionDrawHatch::mouseReleaseEvent(QMouseEvent * e)
157 {
158         if (e->button() == Qt::LeftButton)
159         {
160                 Vector mouse = snapPoint(e);
161
162                 switch (getStatus())
163                 {
164                 case ShowDialog:
165                         break;
166
167                 default:
168                         break;
169                 }
170         }
171         else if (e->button() == Qt::RightButton)
172         {
173                 init(getStatus() - 1);
174 //doesn't clear the preview or snapper.
175                 graphicView->redraw();  // hm.
176         }
177 }
178
179 void ActionDrawHatch::updateMouseButtonHints()
180 {
181         DIALOGFACTORY->updateMouseWidget("", "");
182 }
183
184 void ActionDrawHatch::updateMouseCursor()
185 {
186         graphicView->setMouseCursor(RS2::CadCursor);
187 }
188
189 void ActionDrawHatch::updateToolBar()
190 {
191         DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
192 }