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
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/22/2010 Added this text. :-)
17 #include "actiondrawhatch.h"
19 #include "rs_dialogfactory.h"
20 #include "graphicview.h"
21 #include "rs_information.h"
23 ActionDrawHatch::ActionDrawHatch(RS_EntityContainer & container, GraphicView & graphicView):
24 ActionInterface("Draw Hatch", container, graphicView)
29 ActionDrawHatch::~ActionDrawHatch()
33 void ActionDrawHatch::init(int status)
35 ActionInterface::init(status);
38 RS_Hatch tmp(container, data);
39 tmp.setLayerToActive();
42 if (RS_DIALOGFACTORY->requestHatchDialog(&tmp))
47 graphicView->redraw();
53 void ActionDrawHatch::trigger()
55 RS_DEBUG->print("ActionDrawHatch::trigger()");
60 // deselect unhatchable entities:
61 for(e=container->firstEntity(RS2::ResolveNone); e!=NULL;
62 e=container->nextEntity(RS2::ResolveNone))
65 && (e->rtti() == RS2::EntityHatch
66 || e->rtti() == RS2::EntityEllipse || e->rtti() == RS2::EntityPoint
67 || e->rtti() == RS2::EntityText
68 || RS_Information::isDimension(e->rtti())))
69 e->setSelected(false);
72 for(e=container->firstEntity(RS2::ResolveAll); e!=NULL;
73 e=container->nextEntity(RS2::ResolveAll))
76 && (e->rtti() == RS2::EntityHatch
77 || e->rtti() == RS2::EntityEllipse || e->rtti() == RS2::EntityPoint
78 || e->rtti() == RS2::EntityText
79 || RS_Information::isDimension(e->rtti())))
80 e->setSelected(false);
83 // look for selected contours:
84 bool haveContour = false;
86 for(e=container->firstEntity(RS2::ResolveAll); e!=NULL;
87 e=container->nextEntity(RS2::ResolveAll))
93 std::cerr << "no contour selected\n";
97 hatch = new RS_Hatch(container, data);
98 hatch->setLayerToActive();
99 hatch->setPenToActive();
100 RS_EntityContainer * loop = new RS_EntityContainer(hatch);
101 loop->setPen(RS_Pen(RS2::FlagInvalid));
103 // add selected contour:
104 for(RS_Entity * e=container->firstEntity(RS2::ResolveAll); e!=NULL;
105 e=container->nextEntity(RS2::ResolveAll))
109 e->setSelected(false);
111 // entity is part of a complex entity (spline, polyline, ..):
112 if (e->getParent() != NULL
113 && (e->getParent()->rtti() == RS2::EntitySpline
114 || e->getParent()->rtti() == RS2::EntityPolyline))
115 e->getParent()->setSelected(false);
117 RS_Entity * cp = e->clone();
118 cp->setPen(RS_Pen(RS2::FlagInvalid));
124 hatch->addEntity(loop);
126 if (hatch->validate())
128 container->addEntity(hatch);
132 document->startUndoCycle();
133 document->addUndoable(hatch);
134 document->endUndoCycle();
138 graphicView->drawEntity(hatch);
139 RS_DIALOGFACTORY->commandMessage(tr("Hatch created successfully."));
145 RS_DIALOGFACTORY->commandMessage(tr("Invalid hatch area. Please check that "
146 "the entities chosen form one or more closed contours."));
150 void ActionDrawHatch::mouseMoveEvent(QMouseEvent *)
152 RS_DEBUG->print("ActionDrawHatch::mouseMoveEvent begin");
154 /*if (getStatus()==SetPos) {
155 Vector mouse = snapPoint(e);
160 if (hatch!=NULL && !hatch->isVisible()) {
161 hatch->setVisible(true);
163 offset = Vector(graphicView->toGuiDX(pos.x),
164 -graphicView->toGuiDY(pos.y));
168 RS_DEBUG->print("ActionDrawHatch::mouseMoveEvent end");
171 void ActionDrawHatch::mouseReleaseEvent(QMouseEvent * e)
173 if (e->button() == Qt::LeftButton)
175 Vector mouse = snapPoint(e);
186 else if (e->button() == Qt::RightButton)
190 init(getStatus() - 1);
194 void ActionDrawHatch::updateMouseButtonHints()
196 RS_DIALOGFACTORY->updateMouseWidget("", "");
199 void ActionDrawHatch::updateMouseCursor()
201 graphicView->setMouseCursor(RS2::CadCursor);
204 void ActionDrawHatch::updateToolBar()
206 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);