1 // rs_actiondrawhatch.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_actiondrawhatch.h"
17 #include "rs_dialogfactory.h"
18 #include "graphicview.h"
19 #include "rs_information.h"
21 RS_ActionDrawHatch::RS_ActionDrawHatch(RS_EntityContainer & container, GraphicView & graphicView):
22 RS_PreviewActionInterface("Draw Hatch", container, graphicView)
27 RS_ActionDrawHatch::~RS_ActionDrawHatch()
31 void RS_ActionDrawHatch::init(int status)
33 RS_ActionInterface::init(status);
36 RS_Hatch tmp(container, data);
37 tmp.setLayerToActive();
40 if (RS_DIALOGFACTORY->requestHatchDialog(&tmp))
45 graphicView->redraw();
51 void RS_ActionDrawHatch::trigger()
53 RS_DEBUG->print("RS_ActionDrawHatch::trigger()");
60 // deselect unhatchable entities:
61 for (e = container->firstEntity(RS2::ResolveNone); e != NULL;
62 e = container->nextEntity(RS2::ResolveNone))
64 && (e->rtti() == RS2::EntityHatch
65 || e->rtti() == RS2::EntityEllipse || e->rtti() == RS2::EntityPoint
66 || e->rtti() == RS2::EntityText
67 || RS_Information::isDimension(e->rtti())))
68 e->setSelected(false);
71 for (e = container->firstEntity(RS2::ResolveAll); e != NULL;
72 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);
80 // look for selected contours:
81 bool haveContour = false;
83 for (e = container->firstEntity(RS2::ResolveAll); e != NULL;
84 e = container->nextEntity(RS2::ResolveAll))
90 std::cerr << "no contour selected\n";
94 hatch = new RS_Hatch(container, data);
95 hatch->setLayerToActive();
96 hatch->setPenToActive();
97 RS_EntityContainer * loop = new RS_EntityContainer(hatch);
98 loop->setPen(RS_Pen(RS2::FlagInvalid));
100 // add selected contour:
101 for (RS_Entity * e = container->firstEntity(RS2::ResolveAll); e != NULL;
102 e = container->nextEntity(RS2::ResolveAll))
106 e->setSelected(false);
108 // entity is part of a complex entity (spline, polyline, ..):
109 if (e->getParent() != NULL
110 && (e->getParent()->rtti() == RS2::EntitySpline
111 || e->getParent()->rtti() == RS2::EntityPolyline))
112 e->getParent()->setSelected(false);
113 RS_Entity * cp = e->clone();
114 cp->setPen(RS_Pen(RS2::FlagInvalid));
119 hatch->addEntity(loop);
121 if (hatch->validate())
123 container->addEntity(hatch);
127 document->startUndoCycle();
128 document->addUndoable(hatch);
129 document->endUndoCycle();
133 graphicView->drawEntity(hatch);
135 RS_DIALOGFACTORY->commandMessage(tr("Hatch created successfully."));
141 RS_DIALOGFACTORY->commandMessage(tr("Invalid hatch area. Please check that "
142 "the entities chosen form one or more closed contours."));
147 void RS_ActionDrawHatch::mouseMoveEvent(QMouseEvent *)
149 RS_DEBUG->print("RS_ActionDrawHatch::mouseMoveEvent begin");
151 /*if (getStatus()==SetPos) {
152 Vector mouse = snapPoint(e);
157 if (hatch!=NULL && !hatch->isVisible()) {
158 hatch->setVisible(true);
160 offset = Vector(graphicView->toGuiDX(pos.x),
161 -graphicView->toGuiDY(pos.y));
165 RS_DEBUG->print("RS_ActionDrawHatch::mouseMoveEvent end");
168 void RS_ActionDrawHatch::mouseReleaseEvent(QMouseEvent * e)
170 // if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton)
171 if (e->button() == Qt::LeftButton)
173 Vector mouse = snapPoint(e);
184 // else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton)
185 else if (e->button() == Qt::RightButton)
189 init(getStatus() - 1);
193 void RS_ActionDrawHatch::updateMouseButtonHints()
195 RS_DIALOGFACTORY->updateMouseWidget("", "");
198 void RS_ActionDrawHatch::updateMouseCursor()
200 graphicView->setMouseCursor(RS2::CadCursor);
203 void RS_ActionDrawHatch::updateToolBar()
205 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);