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"
20 #include "dialogfactory.h"
21 #include "graphicview.h"
22 #include "information.h"
24 ActionDrawHatch::ActionDrawHatch(RS_EntityContainer & container, GraphicView & graphicView):
25 ActionInterface("Draw Hatch", container, graphicView)
30 ActionDrawHatch::~ActionDrawHatch()
34 void ActionDrawHatch::init(int status)
36 ActionInterface::init(status);
39 RS_Hatch tmp(container, data);
40 tmp.setLayerToActive();
43 if (RS_DIALOGFACTORY->requestHatchDialog(&tmp))
48 graphicView->redraw();
54 void ActionDrawHatch::trigger()
56 RS_DEBUG->print("ActionDrawHatch::trigger()");
61 // deselect unhatchable entities:
62 for(e=container->firstEntity(RS2::ResolveNone); e!=NULL;
63 e=container->nextEntity(RS2::ResolveNone))
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);
73 for(e=container->firstEntity(RS2::ResolveAll); e!=NULL;
74 e=container->nextEntity(RS2::ResolveAll))
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);
84 // look for selected contours:
85 bool haveContour = false;
87 for(e=container->firstEntity(RS2::ResolveAll); e!=NULL;
88 e=container->nextEntity(RS2::ResolveAll))
94 std::cerr << "no contour selected\n";
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));
104 // add selected contour:
105 for(RS_Entity * e=container->firstEntity(RS2::ResolveAll); e!=NULL;
106 e=container->nextEntity(RS2::ResolveAll))
110 e->setSelected(false);
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);
118 RS_Entity * cp = e->clone();
119 cp->setPen(RS_Pen(RS2::FlagInvalid));
125 hatch->addEntity(loop);
127 if (hatch->validate())
129 container->addEntity(hatch);
133 document->startUndoCycle();
134 document->addUndoable(hatch);
135 document->endUndoCycle();
139 graphicView->drawEntity(hatch);
140 RS_DIALOGFACTORY->commandMessage(tr("Hatch created successfully."));
146 RS_DIALOGFACTORY->commandMessage(tr("Invalid hatch area. Please check that "
147 "the entities chosen form one or more closed contours."));
151 void ActionDrawHatch::mouseMoveEvent(QMouseEvent *)
153 RS_DEBUG->print("ActionDrawHatch::mouseMoveEvent begin");
155 /*if (getStatus()==SetPos) {
156 Vector mouse = snapPoint(e);
161 if (hatch!=NULL && !hatch->isVisible()) {
162 hatch->setVisible(true);
164 offset = Vector(graphicView->toGuiDX(pos.x),
165 -graphicView->toGuiDY(pos.y));
169 RS_DEBUG->print("ActionDrawHatch::mouseMoveEvent end");
172 void ActionDrawHatch::mouseReleaseEvent(QMouseEvent * e)
174 if (e->button() == Qt::LeftButton)
176 Vector mouse = snapPoint(e);
187 else if (e->button() == Qt::RightButton)
191 init(getStatus() - 1);
195 void ActionDrawHatch::updateMouseButtonHints()
197 RS_DIALOGFACTORY->updateMouseWidget("", "");
200 void ActionDrawHatch::updateMouseCursor()
202 graphicView->setMouseCursor(RS2::CadCursor);
205 void ActionDrawHatch::updateToolBar()
207 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);