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(EntityContainer & container, GraphicView & graphicView):
25 ActionInterface("Draw Hatch", container, graphicView)
30 ActionDrawHatch::~ActionDrawHatch()
34 void ActionDrawHatch::init(int status)
36 ActionInterface::init(status);
39 Hatch tmp(container, data);
40 tmp.setLayerToActive();
43 if (DIALOGFACTORY->requestHatchDialog(&tmp))
48 graphicView->redraw();
54 void ActionDrawHatch::trigger()
56 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 || 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 || 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 Hatch(container, data);
99 hatch->setLayerToActive();
100 hatch->setPenToActive();
101 EntityContainer * loop = new EntityContainer(hatch);
102 loop->setPen(Pen(RS2::FlagInvalid));
104 // add selected contour:
105 for(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 Entity * cp = e->clone();
119 cp->setPen(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 DIALOGFACTORY->commandMessage(tr("Hatch created successfully."));
145 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 DEBUG->print("ActionDrawHatch::mouseMoveEvent begin");
153 DEBUG->print("ActionDrawHatch::mouseMoveEvent end");
156 void ActionDrawHatch::mouseReleaseEvent(QMouseEvent * e)
158 if (e->button() == Qt::LeftButton)
160 Vector mouse = snapPoint(e);
171 else if (e->button() == Qt::RightButton)
173 init(getStatus() - 1);
174 //doesn't clear the preview or snapper.
175 graphicView->redraw(); // hm.
179 void ActionDrawHatch::updateMouseButtonHints()
181 DIALOGFACTORY->updateMouseWidget("", "");
184 void ActionDrawHatch::updateMouseCursor()
186 graphicView->setMouseCursor(RS2::CadCursor);
189 void ActionDrawHatch::updateToolBar()
191 DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);