1 /****************************************************************************
2 ** $Id: rs_actiondrawhatch.cpp 2381 2005-05-16 17:05:44Z andrew $
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
6 ** This file is part of the qcadlib Library project.
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 ** See http://www.ribbonsoft.com for further details.
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
25 **********************************************************************/
27 #include "rs_actiondrawhatch.h"
29 #include "rs_snapper.h"
30 #include "rs_graphicview.h"
31 #include "rs_information.h"
33 RS_ActionDrawHatch::RS_ActionDrawHatch(RS_EntityContainer& container,
34 RS_GraphicView& graphicView):
35 RS_PreviewActionInterface("Draw Hatch", container, graphicView)
40 QAction * RS_ActionDrawHatch::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
42 QAction * action = new QAction(tr("&Hatch"), 0);
43 // QAction* action = new QAction(tr("Hatch"), tr("&Hatch"),
44 // QKeySequence(), NULL);
45 action->setStatusTip(tr("Draw Hatches and Solid Fills"));
49 void RS_ActionDrawHatch::init(int status)
51 RS_ActionInterface::init(status);
55 RS_Hatch tmp(container, data);
56 tmp.setLayerToActive();
58 if (RS_DIALOGFACTORY->requestHatchDialog(&tmp)) {
62 graphicView->redraw();
70 void RS_ActionDrawHatch::trigger() {
72 RS_DEBUG->print("RS_ActionDrawHatch::trigger()");
79 // deselect unhatchable entities:
80 for (e=container->firstEntity(RS2::ResolveNone); e!=NULL;
81 e=container->nextEntity(RS2::ResolveNone)) {
82 if (e->isSelected() &&
83 (e->rtti()==RS2::EntityHatch ||
84 e->rtti()==RS2::EntityEllipse || e->rtti()==RS2::EntityPoint ||
85 e->rtti()==RS2::EntityText ||
86 RS_Information::isDimension(e->rtti()))) {
87 e->setSelected(false);
90 for (e=container->firstEntity(RS2::ResolveAll); e!=NULL;
91 e=container->nextEntity(RS2::ResolveAll)) {
92 if (e->isSelected() &&
93 (e->rtti()==RS2::EntityHatch ||
94 e->rtti()==RS2::EntityEllipse || e->rtti()==RS2::EntityPoint ||
95 e->rtti()==RS2::EntityText ||
96 RS_Information::isDimension(e->rtti()))) {
97 e->setSelected(false);
101 // look for selected contours:
102 bool haveContour = false;
103 for (e=container->firstEntity(RS2::ResolveAll); e!=NULL;
104 e=container->nextEntity(RS2::ResolveAll)) {
105 if (e->isSelected()) {
111 std::cerr << "no contour selected\n";
115 hatch = new RS_Hatch(container, data);
116 hatch->setLayerToActive();
117 hatch->setPenToActive();
118 RS_EntityContainer* loop = new RS_EntityContainer(hatch);
119 loop->setPen(RS_Pen(RS2::FlagInvalid));
121 // add selected contour:
122 for (RS_Entity* e=container->firstEntity(RS2::ResolveAll); e!=NULL;
123 e=container->nextEntity(RS2::ResolveAll)) {
125 if (e->isSelected()) {
126 e->setSelected(false);
127 // entity is part of a complex entity (spline, polyline, ..):
128 if (e->getParent()!=NULL &&
129 (e->getParent()->rtti()==RS2::EntitySpline ||
130 e->getParent()->rtti()==RS2::EntityPolyline)) {
131 e->getParent()->setSelected(false);
133 RS_Entity* cp = e->clone();
134 cp->setPen(RS_Pen(RS2::FlagInvalid));
140 hatch->addEntity(loop);
141 if (hatch->validate()) {
142 container->addEntity(hatch);
145 document->startUndoCycle();
146 document->addUndoable(hatch);
147 document->endUndoCycle();
151 graphicView->drawEntity(hatch);
153 RS_DIALOGFACTORY->commandMessage(tr("Hatch created successfully."));
158 RS_DIALOGFACTORY->commandMessage(tr("Invalid hatch area. Please check that "
159 "the entities chosen form one or more closed contours."));
166 void RS_ActionDrawHatch::mouseMoveEvent(QMouseEvent*) {
167 RS_DEBUG->print("RS_ActionDrawHatch::mouseMoveEvent begin");
169 /*if (getStatus()==SetPos) {
170 Vector mouse = snapPoint(e);
175 if (hatch!=NULL && !hatch->isVisible()) {
176 hatch->setVisible(true);
178 offset = Vector(graphicView->toGuiDX(pos.x),
179 -graphicView->toGuiDY(pos.y));
183 RS_DEBUG->print("RS_ActionDrawHatch::mouseMoveEvent end");
188 void RS_ActionDrawHatch::mouseReleaseEvent(QMouseEvent* e) {
189 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
190 Vector mouse = snapPoint(e);
192 switch (getStatus()) {
199 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
208 void RS_ActionDrawHatch::updateMouseButtonHints() {
209 RS_DIALOGFACTORY->updateMouseWidget("", "");
214 void RS_ActionDrawHatch::updateMouseCursor() {
215 graphicView->setMouseCursor(RS2::CadCursor);
220 void RS_ActionDrawHatch::updateToolBar() {
221 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);