1 /****************************************************************************
2 ** $Id: rs_actionmodifyround.cpp 1161 2004-12-09 23:10:09Z 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_actionmodifyround.h"
29 #include "rs_information.h"
30 #include "rs_snapper.h"
32 RS_ActionModifyRound::RS_ActionModifyRound(RS_EntityContainer& container,
33 RS_GraphicView& graphicView)
34 :RS_PreviewActionInterface("Round Entities", container, graphicView)
38 coord1 = Vector(false);
39 coord2 = Vector(false);
42 QAction * RS_ActionModifyRound::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/)
44 QAction * action = new QAction(tr("&Round"), 0);
45 // QAction* action = new QAction(tr("Round"), tr("&Round"),
46 // QKeySequence(), NULL);
47 action->setStatusTip(tr("Round Entities"));
51 void RS_ActionModifyRound::init(int status)
53 RS_ActionInterface::init(status);
55 snapMode = RS2::SnapFree;
56 snapRes = RS2::RestrictNothing;
59 void RS_ActionModifyRound::trigger()
61 RS_DEBUG->print("RS_ActionModifyRound::trigger()");
63 if (entity1!=NULL && entity1->isAtomic() &&
64 entity2!=NULL && entity2->isAtomic())
68 RS_Modification m(*container, graphicView);
71 (RS_AtomicEntity*)entity1,
73 (RS_AtomicEntity*)entity2,
76 //coord = Vector(false);
77 coord1 = Vector(false);
79 coord2 = Vector(false);
81 setStatus(SetEntity1);
85 if (RS_DIALOGFACTORY!=NULL) {
86 RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
93 void RS_ActionModifyRound::mouseMoveEvent(QMouseEvent* e) {
94 RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent begin");
96 Vector mouse = graphicView->toGraph(e->x(), e->y());
97 RS_Entity* se = catchEntity(e, RS2::ResolveAll);
99 switch (getStatus()) {
109 if (entity1!=NULL && entity2!=NULL && entity2->isAtomic() &&
110 RS_Information::isTrimmable(entity1, entity2)) {
114 //preview->addSelectionFrom(*container);
115 //preview->move(targetPoint-referencePoint);
116 RS_Entity* tmp1 = entity1->clone();
117 RS_Entity* tmp2 = entity2->clone();
118 tmp1->reparent(preview);
119 tmp2->reparent(preview);
120 preview->addEntity(tmp1);
121 preview->addEntity(tmp2);
123 bool trim = data.trim;
125 RS_Modification m(*preview, NULL, false);
128 (RS_AtomicEntity*)tmp1,
130 (RS_AtomicEntity*)tmp2,
134 preview->removeEntity(tmp1);
135 preview->removeEntity(tmp2);
144 RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent end");
149 void RS_ActionModifyRound::mouseReleaseEvent(QMouseEvent* e) {
150 Vector mouse = graphicView->toGraph(e->x(), e->y());
151 RS_Entity* se = catchEntity(e, RS2::ResolveAll);
153 if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) {
154 switch (getStatus()) {
158 if (entity1!=NULL && entity1->isAtomic() &&
159 RS_Information::isTrimmable(entity1)) {
160 setStatus(SetEntity2);
167 if (entity2!=NULL && entity2->isAtomic() &&
168 RS_Information::isTrimmable(entity1, entity2)) {
169 //setStatus(ChooseRounding);
177 } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) {
186 void RS_ActionModifyRound::commandEvent(RS_CommandEvent* e) {
187 QString c = e->getCommand().toLower();
189 if (checkCommand("help", c)) {
190 if (RS_DIALOGFACTORY!=NULL) {
191 RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
192 + getAvailableCommands().join(", "));
197 switch (getStatus()) {
200 if (checkCommand("radius", c)) {
204 lastStatus = (Status)getStatus();
205 setStatus(SetRadius);
206 } else if (checkCommand("trim", c)) {
210 lastStatus = (Status)getStatus();
213 data.trim = !data.trim;
214 if (RS_DIALOGFACTORY!=NULL) {
215 RS_DIALOGFACTORY->requestOptions(this, true, true);
222 double r = RS_Math::eval(c, &ok);
226 if (RS_DIALOGFACTORY!=NULL) {
227 RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
230 if (RS_DIALOGFACTORY!=NULL) {
231 RS_DIALOGFACTORY->requestOptions(this, true, true);
233 setStatus(lastStatus);
238 if (c==cmdYes.toLower() || c==cmdYes2) {
240 } else if (c==cmdNo.toLower() || c==cmdNo2) {
243 RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' "
246 RS_DIALOGFACTORY->requestOptions(this, true, true);
247 setStatus(lastStatus);
258 QStringList RS_ActionModifyRound::getAvailableCommands() {
260 switch (getStatus()) {
263 cmd += command("radius");
264 cmd += command("trim");
274 void RS_ActionModifyRound::showOptions() {
275 RS_ActionInterface::showOptions();
277 if (RS_DIALOGFACTORY!=NULL) {
278 RS_DIALOGFACTORY->requestOptions(this, true);
284 void RS_ActionModifyRound::hideOptions() {
285 RS_ActionInterface::hideOptions();
287 if (RS_DIALOGFACTORY!=NULL) {
288 RS_DIALOGFACTORY->requestOptions(this, false);
294 void RS_ActionModifyRound::updateMouseButtonHints() {
295 if (RS_DIALOGFACTORY!=NULL) {
296 switch (getStatus()) {
298 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first entity"),
302 RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second entity"),
306 RS_DIALOGFACTORY->updateMouseWidget(tr("Enter radius:"),
310 RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"),
314 RS_DIALOGFACTORY->updateMouseWidget("", "");
322 void RS_ActionModifyRound::updateMouseCursor() {
323 graphicView->setMouseCursor(RS2::CadCursor);
328 void RS_ActionModifyRound::updateToolBar() {
329 if (RS_DIALOGFACTORY!=NULL) {
330 RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify);