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 "actiondrawhatch.h"
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_information.h"
21 ActionDrawHatch::ActionDrawHatch(RS_EntityContainer & container, GraphicView & graphicView):
22 ActionInterface("Draw Hatch", container, graphicView)
27 ActionDrawHatch::~ActionDrawHatch()
31 void ActionDrawHatch::init(int status)
33 ActionInterface::init(status);
36 RS_Hatch tmp(container, data);
37 tmp.setLayerToActive();
40 if (RS_DIALOGFACTORY->requestHatchDialog(&tmp))
45 graphicView->redraw();
51 void ActionDrawHatch::trigger()
53 RS_DEBUG->print("ActionDrawHatch::trigger()");
58 // deselect unhatchable entities:
59 for(e=container->firstEntity(RS2::ResolveNone); e!=NULL;
60 e=container->nextEntity(RS2::ResolveNone))
63 && (e->rtti() == RS2::EntityHatch
64 || e->rtti() == RS2::EntityEllipse || e->rtti() == RS2::EntityPoint
65 || e->rtti() == RS2::EntityText
66 || RS_Information::isDimension(e->rtti())))
67 e->setSelected(false);
70 for(e=container->firstEntity(RS2::ResolveAll); e!=NULL;
71 e=container->nextEntity(RS2::ResolveAll))
74 && (e->rtti() == RS2::EntityHatch
75 || e->rtti() == RS2::EntityEllipse || e->rtti() == RS2::EntityPoint
76 || e->rtti() == RS2::EntityText
77 || RS_Information::isDimension(e->rtti())))
78 e->setSelected(false);
81 // look for selected contours:
82 bool haveContour = false;
84 for(e=container->firstEntity(RS2::ResolveAll); e!=NULL;
85 e=container->nextEntity(RS2::ResolveAll))
91 std::cerr << "no contour selected\n";
95 hatch = new RS_Hatch(container, data);
96 hatch->setLayerToActive();
97 hatch->setPenToActive();
98 RS_EntityContainer * loop = new RS_EntityContainer(hatch);
99 loop->setPen(RS_Pen(RS2::FlagInvalid));
101 // add selected contour:
102 for(RS_Entity * e=container->firstEntity(RS2::ResolveAll); e!=NULL;
103 e=container->nextEntity(RS2::ResolveAll))
107 e->setSelected(false);
109 // entity is part of a complex entity (spline, polyline, ..):
110 if (e->getParent() != NULL
111 && (e->getParent()->rtti() == RS2::EntitySpline
112 || e->getParent()->rtti() == RS2::EntityPolyline))
113 e->getParent()->setSelected(false);
115 RS_Entity * cp = e->clone();
116 cp->setPen(RS_Pen(RS2::FlagInvalid));
122 hatch->addEntity(loop);
124 if (hatch->validate())
126 container->addEntity(hatch);
130 document->startUndoCycle();
131 document->addUndoable(hatch);
132 document->endUndoCycle();
136 graphicView->drawEntity(hatch);
137 RS_DIALOGFACTORY->commandMessage(tr("Hatch created successfully."));
143 RS_DIALOGFACTORY->commandMessage(tr("Invalid hatch area. Please check that "
144 "the entities chosen form one or more closed contours."));
148 void ActionDrawHatch::mouseMoveEvent(QMouseEvent *)
150 RS_DEBUG->print("ActionDrawHatch::mouseMoveEvent begin");
152 /*if (getStatus()==SetPos) {
153 Vector mouse = snapPoint(e);
158 if (hatch!=NULL && !hatch->isVisible()) {
159 hatch->setVisible(true);
161 offset = Vector(graphicView->toGuiDX(pos.x),
162 -graphicView->toGuiDY(pos.y));
166 RS_DEBUG->print("ActionDrawHatch::mouseMoveEvent end");
169 void ActionDrawHatch::mouseReleaseEvent(QMouseEvent * e)
171 if (e->button() == Qt::LeftButton)
173 Vector mouse = snapPoint(e);
184 else if (e->button() == Qt::RightButton)
188 init(getStatus() - 1);
192 void ActionDrawHatch::updateMouseButtonHints()
194 RS_DIALOGFACTORY->updateMouseWidget("", "");
197 void ActionDrawHatch::updateMouseCursor()
199 graphicView->setMouseCursor(RS2::CadCursor);
202 void ActionDrawHatch::updateToolBar()
204 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);