X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actionmodifyround.cpp;h=8b6eaf389cf1de1a7d9521217544de939fc12993;hb=3f46c180da0806c9c263e6d87d0f1404632402da;hp=8311997098d9d410091b6b5ee1db782c02a4363d;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actionmodifyround.cpp b/src/actions/rs_actionmodifyround.cpp index 8311997..8b6eaf3 100644 --- a/src/actions/rs_actionmodifyround.cpp +++ b/src/actions/rs_actionmodifyround.cpp @@ -1,37 +1,25 @@ -/**************************************************************************** -** $Id: rs_actionmodifyround.cpp 1161 2004-12-09 23:10:09Z andrew $ -** -** Copyright (C) 2001-2003 RibbonSoft. All rights reserved. -** -** This file is part of the qcadlib Library project. -** -** This file may be distributed and/or modified under the terms of the -** GNU General Public License version 2 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. -** -** Licensees holding valid qcadlib Professional Edition licenses may use -** this file in accordance with the qcadlib Commercial License -** Agreement provided with the Software. -** -** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -** -** See http://www.ribbonsoft.com for further details. -** -** Contact info@ribbonsoft.com if any conditions of this licensing are -** not clear to you. -** -**********************************************************************/ +// rs_actionmodifyround.cpp +// +// Part of the Architektonas Project +// Originally part of QCad Community Edition by Andrew Mustun +// Extensively rewritten and refactored by James L. Hammons +// (C) 2010 Underground Software +// +// JLH = James L. Hammons +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 06/04/2010 Added this text. :-) +// #include "rs_actionmodifyround.h" +#include "rs_dialogfactory.h" #include "rs_information.h" -#include "rs_snapper.h" +#include "rs_preview.h" -RS_ActionModifyRound::RS_ActionModifyRound(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Round Entities", container, graphicView) +RS_ActionModifyRound::RS_ActionModifyRound(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_PreviewActionInterface("Round Entities", container, graphicView) { entity1 = NULL; entity2 = NULL; @@ -39,297 +27,317 @@ RS_ActionModifyRound::RS_ActionModifyRound(RS_EntityContainer& container, coord2 = Vector(false); } -QAction * RS_ActionModifyRound::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionModifyRound::~RS_ActionModifyRound() { - QAction * action = new QAction(tr("&Round"), 0); -// QAction* action = new QAction(tr("Round"), tr("&Round"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Round Entities")); - return action; +} + +/*virtual*/ RS2::ActionType RS_ActionModifyRound::rtti() +{ + return RS2::ActionModifyRound; } void RS_ActionModifyRound::init(int status) { - RS_ActionInterface::init(status); + RS_ActionInterface::init(status); - snapMode = RS2::SnapFree; - snapRes = RS2::RestrictNothing; + snapMode = RS2::SnapFree; + snapRes = RS2::RestrictNothing; } void RS_ActionModifyRound::trigger() { - RS_DEBUG->print("RS_ActionModifyRound::trigger()"); + RS_DEBUG->print("RS_ActionModifyRound::trigger()"); - if (entity1!=NULL && entity1->isAtomic() && - entity2!=NULL && entity2->isAtomic()) + if (entity1 != NULL && entity1->isAtomic() + && entity2 != NULL && entity2->isAtomic()) { - deletePreview(); - - RS_Modification m(*container, graphicView); - m.round(coord2, - coord1, - (RS_AtomicEntity*)entity1, - coord2, - (RS_AtomicEntity*)entity2, - data); - - //coord = Vector(false); - coord1 = Vector(false); - entity1 = NULL; - coord2 = Vector(false); - entity2 = NULL; - setStatus(SetEntity1); - - clearPreview(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } - } + deletePreview(); + + RS_Modification m(*container, graphicView); + m.round(coord2, + coord1, + (RS_AtomicEntity *)entity1, + coord2, + (RS_AtomicEntity *)entity2, + data); + + //coord = Vector(false); + coord1 = Vector(false); + entity1 = NULL; + coord2 = Vector(false); + entity2 = NULL; + setStatus(SetEntity1); + + clearPreview(); + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } } +void RS_ActionModifyRound::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent begin"); + Vector mouse = graphicView->toGraph(e->x(), e->y()); + RS_Entity * se = catchEntity(e, RS2::ResolveAll); -void RS_ActionModifyRound::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent begin"); - - Vector mouse = graphicView->toGraph(e->x(), e->y()); - RS_Entity* se = catchEntity(e, RS2::ResolveAll); - - switch (getStatus()) { - case SetEntity1: - entity1 = se; - coord1 = mouse; - break; - - case SetEntity2: - entity2 = se; - coord2 = mouse; - - if (entity1!=NULL && entity2!=NULL && entity2->isAtomic() && - RS_Information::isTrimmable(entity1, entity2)) { - - deletePreview(); - clearPreview(); - //preview->addSelectionFrom(*container); - //preview->move(targetPoint-referencePoint); - RS_Entity* tmp1 = entity1->clone(); - RS_Entity* tmp2 = entity2->clone(); - tmp1->reparent(preview); - tmp2->reparent(preview); - preview->addEntity(tmp1); - preview->addEntity(tmp2); - - bool trim = data.trim; - data.trim = false; - RS_Modification m(*preview, NULL, false); - m.round(coord2, - coord1, - (RS_AtomicEntity*)tmp1, - coord2, - (RS_AtomicEntity*)tmp2, - data); - data.trim = trim; - - preview->removeEntity(tmp1); - preview->removeEntity(tmp2); - drawPreview(); - } - break; - - default: - break; - } - - RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent end"); + switch (getStatus()) + { + case SetEntity1: + entity1 = se; + coord1 = mouse; + break; + + case SetEntity2: + entity2 = se; + coord2 = mouse; + + if (entity1 != NULL && entity2 != NULL && entity2->isAtomic() + && RS_Information::isTrimmable(entity1, entity2)) + { + deletePreview(); + clearPreview(); + //preview->addSelectionFrom(*container); + //preview->move(targetPoint-referencePoint); + RS_Entity * tmp1 = entity1->clone(); + RS_Entity * tmp2 = entity2->clone(); + tmp1->reparent(preview); + tmp2->reparent(preview); + preview->addEntity(tmp1); + preview->addEntity(tmp2); + + bool trim = data.trim; + data.trim = false; + RS_Modification m(*preview, NULL, false); + m.round(coord2, + coord1, + (RS_AtomicEntity *)tmp1, + coord2, + (RS_AtomicEntity *)tmp2, + data); + data.trim = trim; + + preview->removeEntity(tmp1); + preview->removeEntity(tmp2); + drawPreview(); + } + break; + + default: + break; + } + + RS_DEBUG->print("RS_ActionModifyRound::mouseMoveEvent end"); } +void RS_ActionModifyRound::mouseReleaseEvent(QMouseEvent * e) +{ + Vector mouse = graphicView->toGraph(e->x(), e->y()); + RS_Entity * se = catchEntity(e, RS2::ResolveAll); - -void RS_ActionModifyRound::mouseReleaseEvent(QMouseEvent* e) { - Vector mouse = graphicView->toGraph(e->x(), e->y()); - RS_Entity* se = catchEntity(e, RS2::ResolveAll); - - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetEntity1: - entity1 = se; - coord1 = mouse; - if (entity1!=NULL && entity1->isAtomic() && - RS_Information::isTrimmable(entity1)) { - setStatus(SetEntity2); - } - break; - - case SetEntity2: - entity2 = se; - coord2 = mouse; - if (entity2!=NULL && entity2->isAtomic() && - RS_Information::isTrimmable(entity1, entity2)) { - //setStatus(ChooseRounding); - trigger(); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } + if (e->button() == Qt::LeftButton) + { + switch (getStatus()) + { + case SetEntity1: + entity1 = se; + coord1 = mouse; + + if (entity1 != NULL && entity1->isAtomic() + && RS_Information::isTrimmable(entity1)) + setStatus(SetEntity2); + break; + + case SetEntity2: + entity2 = se; + coord2 = mouse; + + if (entity2 != NULL && entity2->isAtomic() + && RS_Information::isTrimmable(entity1, entity2)) + //setStatus(ChooseRounding); + trigger(); + break; + + default: + break; + } + } + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } +void RS_ActionModifyRound::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + if (checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } -void RS_ActionModifyRound::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - } - return; - } - - switch (getStatus()) { - case SetEntity1: - case SetEntity2: - if (checkCommand("radius", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetRadius); - } else if (checkCommand("trim", c)) { - /*deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetTrim); - */ - data.trim = !data.trim; - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - } - break; - - case SetRadius: { - bool ok; - double r = RS_Math::eval(c, &ok); - if (ok==true) { - data.radius = r; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - setStatus(lastStatus); - } - break; - - /*case SetTrim: { - if (c==cmdYes.toLower() || c==cmdYes2) { - data.trim = true; - } else if (c==cmdNo.toLower() || c==cmdNo2) { - data.trim = false; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' " - "or 'No'")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break;*/ - - default: - break; - } + switch (getStatus()) + { + case SetEntity1: + case SetEntity2: + + if (checkCommand("radius", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetRadius); + } + else if (checkCommand("trim", c)) + { + /*deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetTrim); + */ + data.trim = !data.trim; + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + } + break; + + case SetRadius: { + bool ok; + double r = RS_Math::eval(c, &ok); + + if (ok == true) + data.radius = r; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + /*case SetTrim: { + if (c==cmdYes.toLower() || c==cmdYes2) { + data.trim = true; + } else if (c==cmdNo.toLower() || c==cmdNo2) { + data.trim = false; + } else { + RS_DIALOGFACTORY->commandMessage(tr("Please enter 'Yes' " + "or 'No'")); + } + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break;*/ + + default: + break; + } } +QStringList RS_ActionModifyRound::getAvailableCommands() +{ + QStringList cmd; - -QStringList RS_ActionModifyRound::getAvailableCommands() { - QStringList cmd; - switch (getStatus()) { - case SetEntity1: - case SetEntity2: - cmd += command("radius"); - cmd += command("trim"); - break; - default: - break; - } - return cmd; + switch (getStatus()) + { + case SetEntity1: + case SetEntity2: + cmd += command("radius"); + cmd += command("trim"); + break; + + default: + break; + } + return cmd; } +void RS_ActionModifyRound::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionModifyRound::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionModifyRound::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionModifyRound::hideOptions() { - RS_ActionInterface::hideOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionModifyRound::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetEntity1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first entity"), - tr("Back")); - break; - case SetEntity2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second entity"), - tr("Back")); - break; - case SetRadius: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter radius:"), - tr("Cancel")); - break; - /*case SetTrim: - RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"), - ""); - break;*/ - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionModifyRound::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetEntity1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first entity"), + tr("Back")); + break; + + case SetEntity2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second entity"), + tr("Back")); + break; + + case SetRadius: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter radius:"), + tr("Cancel")); + break; + + /*case SetTrim: + RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"), + ""); + break;*/ + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } - - -void RS_ActionModifyRound::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionModifyRound::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionModifyRound::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); +} +void RS_ActionModifyRound::setRadius(double r) +{ + data.radius = r; +} -void RS_ActionModifyRound::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - } +double RS_ActionModifyRound::getRadius() +{ + return data.radius; } +void RS_ActionModifyRound::setTrim(bool t) +{ + data.trim = t; +} -// EOF +bool RS_ActionModifyRound::isTrimOn() +{ + return data.trim; +}