X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Factions%2Frs_actionmodifydeletefree.cpp;h=2a4c8bb72dc6a2ec4515724c2584267ca47efeb5;hb=27d4a138d23453e93a833e9347444b828a971cb4;hp=8d2275c79dc85738c013746d8290655f1b398303;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/actions/rs_actionmodifydeletefree.cpp b/src/actions/rs_actionmodifydeletefree.cpp index 8d2275c..2a4c8bb 100644 --- a/src/actions/rs_actionmodifydeletefree.cpp +++ b/src/actions/rs_actionmodifydeletefree.cpp @@ -1,176 +1,169 @@ -/**************************************************************************** -** $Id: rs_actionmodifydeletefree.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_actionmodifydeletefree.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_actionmodifydeletefree.h" -#include "rs_point.h" -#include "rs_polyline.h" +#include "rs_dialogfactory.h" +#include "graphicview.h" #include "rs_modification.h" - - +#include "rs_polyline.h" +#include "rs_undo.h" RS_ActionModifyDeleteFree::RS_ActionModifyDeleteFree( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Delete Entities Freehand", - container, graphicView) {} - -QAction* RS_ActionModifyDeleteFree::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) + RS_EntityContainer & container, GraphicView & graphicView): + RS_ActionInterface("Delete Entities Freehand", + container, graphicView) { - QAction * action = new QAction(tr("&Delete Freehand"), 0); -// QAction* action = new QAction(tr("Delete Freehand"), tr("&Delete Freehand"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Delete Freehand")); - return action; } - -void RS_ActionModifyDeleteFree::init(int status) { - RS_ActionInterface::init(status); - polyline = NULL; - e1 = e2 = NULL; - v1 = v2 = Vector(false); - setSnapMode(RS2::SnapOnEntity); +RS_ActionModifyDeleteFree::~RS_ActionModifyDeleteFree() +{ } - - -void RS_ActionModifyDeleteFree::trigger() { - if (e1!=NULL && e2!=NULL) { - RS_EntityContainer* parent = e2->getParent(); - if (parent!=NULL) { - if (parent->rtti()==RS2::EntityPolyline) { - if(parent->getId() == polyline->getId()) { - - // deletes whole polyline on screen: - graphicView->deleteEntity((RS_Entity*)polyline); - - // splits up the polyline in the container: - RS_Polyline* pl1; - RS_Polyline* pl2; - RS_Modification m(*container); - m.splitPolyline(*polyline, - *e1, v1, - *e2, v2, - &pl1, &pl2); - - if (document) { - document->startUndoCycle(); - document->addUndoable(polyline); - document->addUndoable(pl1); - document->addUndoable(pl2); - document->endUndoCycle(); - } - - // draws the new polylines on the screen: - graphicView->drawEntity((RS_Entity*)pl1); - graphicView->drawEntity((RS_Entity*)pl2); - - init(); - - RS_DIALOGFACTORY->updateSelectionWidget( - container->countSelected()); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Entities not in the same polyline.")); - } - } else { - RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is not a polyline")); - } - } else { - RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is NULL")); - } - } else { - RS_DIALOGFACTORY->commandMessage(tr("One of the chosen entities is NULL")); - } +void RS_ActionModifyDeleteFree::init(int status) +{ + RS_ActionInterface::init(status); + polyline = NULL; + e1 = e2 = NULL; + v1 = v2 = Vector(false); + setSnapMode(RS2::SnapOnEntity); } - - -void RS_ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - init(getStatus()-1); - } else { - - switch (getStatus()) { - case 0: { - v1 = snapPoint(e); - e1 = getKeyEntity(); - if (e1!=NULL) { - RS_EntityContainer* parent = e1->getParent(); - if (parent!=NULL) { - if (parent->rtti()==RS2::EntityPolyline) { - polyline = (RS_Polyline*)parent; - setStatus(1); - } else { - RS_DIALOGFACTORY->commandMessage( - tr("Parent of first entity is not a polyline")); - } - } else { - RS_DIALOGFACTORY->commandMessage( - tr("Parent of first entity is NULL")); - } - } else { - RS_DIALOGFACTORY->commandMessage( - tr("First entity is NULL")); - } - } - break; - - case 1: { - v2 = snapPoint(e); - e2 = getKeyEntity(); - - if (e2!=NULL) { - trigger(); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Second entity is NULL")); - } - } - break; - } - } +void RS_ActionModifyDeleteFree::trigger() +{ + if (e1 != NULL && e2 != NULL) + { + RS_EntityContainer * parent = e2->getParent(); + + if (parent != NULL) + { + if (parent->rtti() == RS2::EntityPolyline) + { + if (parent->getId() == polyline->getId()) + { + // deletes whole polyline on screen: + graphicView->deleteEntity((RS_Entity *)polyline); + + // splits up the polyline in the container: + RS_Polyline * pl1; + RS_Polyline * pl2; + RS_Modification m(*container); + m.splitPolyline(*polyline, + *e1, v1, + *e2, v2, + &pl1, &pl2); + + if (document) + { + document->startUndoCycle(); + document->addUndoable(polyline); + document->addUndoable(pl1); + document->addUndoable(pl2); + document->endUndoCycle(); + } + + // draws the new polylines on the screen: + graphicView->drawEntity((RS_Entity *)pl1); + graphicView->drawEntity((RS_Entity *)pl2); + + init(); + + RS_DIALOGFACTORY->updateSelectionWidget( + container->countSelected()); + } + else + RS_DIALOGFACTORY->commandMessage(tr("Entities not in the same polyline.")); + } + else + RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is not a polyline")); + } + else + RS_DIALOGFACTORY->commandMessage(tr("Parent of second entity is NULL")); + } + else + RS_DIALOGFACTORY->commandMessage(tr("One of the chosen entities is NULL")); } +void RS_ActionModifyDeleteFree::mouseReleaseEvent(QMouseEvent * e) +{ + if (e->button() == Qt::RightButton) + init(getStatus() - 1); + else + { + switch (getStatus()) + { + case 0: + v1 = snapPoint(e); + e1 = getKeyEntity(); + + if (e1 != NULL) + { + RS_EntityContainer * parent = e1->getParent(); + + if (parent != NULL) + { + if (parent->rtti() == RS2::EntityPolyline) + { + polyline = (RS_Polyline *)parent; + setStatus(1); + } + else + RS_DIALOGFACTORY->commandMessage( + tr("Parent of first entity is not a polyline")); + } + else + RS_DIALOGFACTORY->commandMessage( + tr("Parent of first entity is NULL")); + } + else + RS_DIALOGFACTORY->commandMessage( + tr("First entity is NULL")); + + break; + + case 1: + v2 = snapPoint(e); + e2 = getKeyEntity(); + + if (e2 != NULL) + trigger(); + else + RS_DIALOGFACTORY->commandMessage(tr("Second entity is NULL")); + + break; + } + } +} - -void RS_ActionModifyDeleteFree::updateMouseButtonHints() { - switch (getStatus()) { - case 0: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first break point " - "on a polyline"), tr("Cancel")); - break; - case 1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second break point " - "on the same polyline"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyDeleteFree::updateMouseButtonHints() +{ + switch (getStatus()) + { + case 0: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first break point " + "on a polyline"), tr("Cancel")); + break; + + case 1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second break point " + "on the same polyline"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } -// EOF