1 /****************************************************************************
2 ** $Id: rs_actionmodifycut.cpp 2420 2005-07-01 16:47:35Z 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_actionmodifycut.h"
29 #include "rs_snapper.h"
32 RS_ActionModifyCut::RS_ActionModifyCut(RS_EntityContainer& container,
33 RS_GraphicView& graphicView)
34 :RS_ActionInterface("Cut Entity",
35 container, graphicView) {
38 cutCoord = Vector(false);
41 QAction* RS_ActionModifyCut::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/)
43 QAction * action = new QAction(tr("&Divide"), 0);
44 // QAction* action = new QAction(tr("Divide"), tr("&Divide"),
45 // QKeySequence(), NULL);
46 action->setStatusTip(tr("Cut Entities"));
51 void RS_ActionModifyCut::init(int status)
53 RS_ActionInterface::init(status);
58 void RS_ActionModifyCut::trigger() {
60 RS_DEBUG->print("RS_ActionModifyCut::trigger()");
62 if (cutEntity!=NULL && cutEntity->isAtomic() && cutCoord.valid &&
63 cutEntity->isPointOnEntity(cutCoord)) {
65 cutEntity->setHighlighted(false);
66 graphicView->drawEntity(cutEntity);
68 RS_Modification m(*container, graphicView);
69 m.cut(cutCoord, (RS_AtomicEntity*)cutEntity);
72 cutCoord = Vector(false);
73 setStatus(ChooseCutEntity);
75 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
81 void RS_ActionModifyCut::mouseMoveEvent(QMouseEvent* e) {
82 RS_DEBUG->print("RS_ActionModifyCut::mouseMoveEvent begin");
84 switch (getStatus()) {
96 RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end");
100 void RS_ActionModifyCut::mouseReleaseEvent(QMouseEvent* e) {
101 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
102 switch (getStatus()) {
103 case ChooseCutEntity:
104 cutEntity = catchEntity(e);
105 if (cutEntity==NULL) {
106 RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
107 } else if (cutEntity->rtti()!=RS2::EntityLine &&
108 cutEntity->rtti()!=RS2::EntityArc &&
109 cutEntity->rtti()!=RS2::EntityCircle &&
110 cutEntity->rtti()!=RS2::EntityEllipse) {
112 RS_DIALOGFACTORY->commandMessage(
113 tr("Entity must be a line, arc, circle or ellipse."));
115 cutEntity->setHighlighted(true);
116 graphicView->drawEntity(cutEntity);
117 setStatus(SetCutCoord);
122 cutCoord = snapPoint(e);
123 if (cutEntity==NULL) {
124 RS_DIALOGFACTORY->commandMessage(tr("No Entity found."));
125 } else if (!cutCoord.valid) {
126 RS_DIALOGFACTORY->commandMessage(tr("Cutting point is invalid."));
127 } else if (!cutEntity->isPointOnEntity(cutCoord)) {
128 RS_DIALOGFACTORY->commandMessage(
129 tr("Cutting point is not on entity."));
139 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
141 if (cutEntity!=NULL) {
142 cutEntity->setHighlighted(false);
143 graphicView->drawEntity(cutEntity);
151 void RS_ActionModifyCut::updateMouseButtonHints() {
152 switch (getStatus()) {
153 case ChooseCutEntity:
154 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify entity to cut"),
158 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify cutting point"),
162 RS_DIALOGFACTORY->updateMouseWidget("", "");
169 void RS_ActionModifyCut::updateMouseCursor() {
170 graphicView->setMouseCursor(RS2::CadCursor);
175 void RS_ActionModifyCut::updateToolBar() {
177 switch (getStatus()) {
179 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap);
181 case ChooseCutEntity:
183 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);