From ee048ce722e7beb53e702825bb3285cd5cacd8bb Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sat, 5 Jun 2010 12:55:00 +0000 Subject: [PATCH] Major refactoring of actions: Moved implementation from header files to ,cpp files, removed all createGUIAction() functions, removed unnecessary includes from header files. --- architektonas.pro | 2 - src/actions/rs_actionblocksadd.cpp | 33 +- src/actions/rs_actionblocksadd.h | 23 +- src/actions/rs_actionblocksattributes.cpp | 82 +-- src/actions/rs_actionblocksattributes.h | 23 +- src/actions/rs_actionblockscreate.cpp | 295 ++++---- src/actions/rs_actionblockscreate.h | 103 +-- src/actions/rs_actionblocksedit.cpp | 52 +- src/actions/rs_actionblocksedit.h | 21 +- src/actions/rs_actionblocksexplode.cpp | 45 +- src/actions/rs_actionblocksexplode.h | 27 +- src/actions/rs_actionblocksfreezeall.cpp | 29 +- src/actions/rs_actionblocksfreezeall.h | 48 +- src/actions/rs_actionblocksinsert.cpp | 694 ++++++++++-------- src/actions/rs_actionblocksinsert.h | 181 ++--- src/actions/rs_actionblocksremove.cpp | 65 +- src/actions/rs_actionblocksremove.h | 31 +- src/actions/rs_actionblockstoggleview.cpp | 87 +-- src/actions/rs_actionblockstoggleview.h | 45 +- src/actions/rs_actiondefault.cpp | 598 ++++++++------- src/actions/rs_actiondefault.h | 107 +-- src/actions/rs_actiondimaligned.cpp | 456 ++++++------ src/actions/rs_actiondimaligned.h | 118 +-- src/actions/rs_actiondimangular.cpp | 534 +++++++------- src/actions/rs_actiondimangular.h | 113 +-- src/actions/rs_actiondimdiametric.cpp | 540 +++++++------- src/actions/rs_actiondimdiametric.h | 109 +-- src/actions/rs_actiondimension.cpp | 148 ++-- src/actions/rs_actiondimension.h | 161 +--- src/actions/rs_actiondimleader.cpp | 72 +- src/actions/rs_actiondimleader.h | 42 +- src/actions/rs_actiondimlinear.cpp | 501 ++++++------- src/actions/rs_actiondimlinear.h | 149 ++-- src/actions/rs_actiondimradial.cpp | 541 +++++++------- src/actions/rs_actiondimradial.h | 110 +-- src/actions/rs_actiondrawarc.cpp | 434 ++++++----- src/actions/rs_actiondrawarc.h | 49 +- src/actions/rs_actiondrawarc3p.cpp | 66 +- src/actions/rs_actiondrawarc3p.h | 131 ++-- src/actions/rs_actiondrawarctangential.cpp | 488 ++++++------ src/actions/rs_actiondrawarctangential.h | 143 ++-- src/actions/rs_actiondrawcircle.cpp | 414 +++++------ src/actions/rs_actiondrawcircle.h | 112 +-- src/actions/rs_actiondrawcircle2p.cpp | 394 +++++----- src/actions/rs_actiondrawcircle2p.h | 121 ++- src/actions/rs_actiondrawcircle3p.cpp | 405 +++++----- src/actions/rs_actiondrawcircle3p.h | 131 ++-- src/actions/rs_actiondrawcirclecr.cpp | 407 +++++----- src/actions/rs_actiondrawcirclecr.h | 123 +--- src/actions/rs_actiondrawellipseaxis.cpp | 630 ++++++++-------- src/actions/rs_actiondrawellipseaxis.h | 120 ++- src/actions/rs_actiondrawhatch.cpp | 316 ++++---- src/actions/rs_actiondrawhatch.h | 82 +-- src/actions/rs_actiondrawimage.cpp | 161 ++-- src/actions/rs_actiondrawimage.h | 149 ++-- src/actions/rs_actiondrawline.cpp | 40 +- src/actions/rs_actiondrawline.h | 16 +- src/actions/rs_actiondrawlineangle.cpp | 462 ++++++------ src/actions/rs_actiondrawlineangle.h | 192 ++--- src/actions/rs_actiondrawlinebisector.cpp | 542 +++++++------- src/actions/rs_actiondrawlinebisector.h | 142 ++-- src/actions/rs_actiondrawlinefree.cpp | 243 +++--- src/actions/rs_actiondrawlinefree.h | 63 +- src/actions/rs_actiondrawlinehorvert.cpp | 279 ++++--- src/actions/rs_actiondrawlinehorvert.h | 103 +-- src/actions/rs_actiondrawlineparallel.cpp | 382 +++++----- src/actions/rs_actiondrawlineparallel.h | 123 ++-- .../rs_actiondrawlineparallelthrough.cpp | 496 ++++++------- .../rs_actiondrawlineparallelthrough.h | 141 ++-- src/actions/rs_actiondrawlinepolygon.cpp | 439 ++++++----- src/actions/rs_actiondrawlinepolygon.h | 118 +-- src/actions/rs_actiondrawlinepolygon2.cpp | 441 ++++++----- src/actions/rs_actiondrawlinepolygon2.h | 118 +-- src/actions/rs_actiondrawlinerectangle.cpp | 366 +++++---- src/actions/rs_actiondrawlinerectangle.h | 119 ++- src/actions/rs_actiondrawlinerelangle.cpp | 606 +++++++-------- src/actions/rs_actiondrawlinerelangle.h | 134 ++-- src/actions/rs_actiondrawlinetangent1.cpp | 371 +++++----- src/actions/rs_actiondrawlinetangent1.h | 94 +-- src/actions/rs_actiondrawlinetangent2.cpp | 325 ++++---- src/actions/rs_actiondrawlinetangent2.h | 92 +-- src/actions/rs_actiondrawpoint.cpp | 33 +- src/actions/rs_actiondrawpoint.h | 20 +- src/actions/rs_actiondrawspline.cpp | 497 +++++++------ src/actions/rs_actiondrawspline.h | 65 +- src/actions/rs_actiondrawtext.cpp | 43 +- src/actions/rs_actiondrawtext.h | 2 +- src/actions/rs_actioneditcopy.cpp | 147 ++-- src/actions/rs_actioneditcopy.h | 20 +- src/actions/rs_actioneditpaste.cpp | 199 +++-- src/actions/rs_actioneditpaste.h | 84 +-- src/actions/rs_actioneditundo.cpp | 38 +- src/actions/rs_actioneditundo.h | 9 +- src/actions/rs_actionfilenew.cpp | 77 +- src/actions/rs_actionfilenew.h | 44 +- src/actions/rs_actionfileopen.cpp | 55 +- src/actions/rs_actionfileopen.h | 3 - src/actions/rs_actionfilesave.cpp | 65 +- src/actions/rs_actionfilesave.h | 44 +- src/actions/rs_actionfilesaveas.cpp | 72 +- src/actions/rs_actionfilesaveas.h | 44 +- src/actions/rs_actioninfoangle.cpp | 293 ++++---- src/actions/rs_actioninfoangle.h | 93 +-- src/actions/rs_actioninfoarea.cpp | 460 ++++++------ src/actions/rs_actioninfoarea.h | 99 +-- src/actions/rs_actioninfodist.cpp | 299 ++++---- src/actions/rs_actioninfodist.h | 90 +-- src/actions/rs_actioninfodist2.cpp | 265 ++++--- src/actions/rs_actioninfodist2.h | 87 +-- src/actions/rs_actioninfoinside.cpp | 160 ++-- src/actions/rs_actioninfoinside.h | 58 +- src/actions/rs_actioninfototallength.cpp | 153 ++-- src/actions/rs_actioninfototallength.h | 60 +- src/actions/rs_actionlayersadd.cpp | 88 +-- src/actions/rs_actionlayersadd.h | 46 +- src/actions/rs_actionlayersedit.cpp | 120 ++- src/actions/rs_actionlayersedit.h | 47 +- src/actions/rs_actionlayersfreezeall.cpp | 54 +- src/actions/rs_actionlayersfreezeall.h | 8 +- src/actions/rs_actionlayersremove.cpp | 118 ++- src/actions/rs_actionlayersremove.h | 44 +- src/actions/rs_actionlayerstogglelock.cpp | 125 ++-- src/actions/rs_actionlayerstogglelock.h | 47 +- src/actions/rs_actionlayerstoggleview.cpp | 84 +-- src/actions/rs_actionlayerstoggleview.h | 47 +- src/actions/rs_actionlibraryinsert.cpp | 133 ++-- src/actions/rs_actionlibraryinsert.h | 184 ++--- src/actions/rs_actionlockrelativezero.cpp | 79 +- src/actions/rs_actionlockrelativezero.h | 49 +- src/actions/rs_actionmodifyattributes.cpp | 165 ++--- src/actions/rs_actionmodifyattributes.h | 64 +- src/actions/rs_actionmodifybevel.cpp | 514 ++++++------- src/actions/rs_actionmodifybevel.h | 145 ++-- src/actions/rs_actionmodifycut.cpp | 302 ++++---- src/actions/rs_actionmodifycut.h | 84 +-- src/actions/rs_actionmodifydelete.cpp | 148 ++-- src/actions/rs_actionmodifydelete.h | 68 +- src/actions/rs_actionmodifydeletefree.cpp | 309 ++++---- src/actions/rs_actionmodifydeletefree.h | 66 +- src/actions/rs_actionmodifydeletequick.cpp | 155 ++-- src/actions/rs_actionmodifydeletequick.h | 56 +- src/actions/rs_actionmodifyentity.cpp | 138 ++-- src/actions/rs_actionmodifyentity.h | 49 +- src/actions/rs_actionmodifyexplodetext.cpp | 84 +-- src/actions/rs_actionmodifyexplodetext.h | 50 +- src/actions/rs_actionmodifymirror.cpp | 310 ++++---- src/actions/rs_actionmodifymirror.h | 91 +-- src/actions/rs_actionmodifymove.cpp | 298 ++++---- src/actions/rs_actionmodifymove.h | 95 +-- src/actions/rs_actionmodifymoverotate.cpp | 285 +++---- src/actions/rs_actionmodifymoverotate.h | 136 ++-- src/actions/rs_actionmodifyrotate.cpp | 235 +++--- src/actions/rs_actionmodifyrotate.h | 93 +-- src/actions/rs_actionmodifyrotate2.cpp | 296 ++++---- src/actions/rs_actionmodifyrotate2.h | 95 +-- src/actions/rs_actionmodifyround.cpp | 568 +++++++------- src/actions/rs_actionmodifyround.h | 137 ++-- src/actions/rs_actionmodifyscale.cpp | 233 +++--- src/actions/rs_actionmodifyscale.h | 87 +-- src/actions/rs_actionmodifystretch.cpp | 407 +++++----- src/actions/rs_actionmodifystretch.h | 95 +-- src/actions/rs_actionmodifytrim.cpp | 291 ++++---- src/actions/rs_actionmodifytrim.h | 65 +- src/actions/rs_actionmodifytrimamount.cpp | 315 ++++---- src/actions/rs_actionmodifytrimamount.h | 120 +-- src/actions/rs_actionoptionsdrawing.cpp | 84 +-- src/actions/rs_actionoptionsdrawing.h | 54 +- src/actions/rs_actionprintpreview.cpp | 271 ++++--- src/actions/rs_actionprintpreview.h | 123 ++-- src/actions/rs_actionselect.cpp | 50 +- src/actions/rs_actionselect.h | 50 +- src/actions/rs_actionselectall.cpp | 38 +- src/actions/rs_actionselectall.h | 32 +- src/actions/rs_actionselectbase.cpp | 72 +- src/actions/rs_actionselectbase.h | 43 +- src/actions/rs_actionselectcontour.cpp | 125 ++-- src/actions/rs_actionselectcontour.h | 59 +- src/actions/rs_actionselectintersected.cpp | 209 +++--- src/actions/rs_actionselectintersected.h | 71 +- src/actions/rs_actionselectinvert.cpp | 80 +- src/actions/rs_actionselectinvert.h | 51 +- src/actions/rs_actionselectlayer.cpp | 102 ++- src/actions/rs_actionselectlayer.h | 59 +- src/actions/rs_actionselectsingle.cpp | 116 ++- src/actions/rs_actionselectsingle.h | 61 +- src/actions/rs_actionselectwindow.cpp | 234 +++--- src/actions/rs_actionselectwindow.h | 71 +- src/actions/rs_actionsetrelativezero.cpp | 171 ++--- src/actions/rs_actionsetrelativezero.h | 70 +- src/actions/rs_actionsetsnapmode.cpp | 59 +- src/actions/rs_actionsetsnapmode.h | 48 +- src/actions/rs_actionsetsnaprestriction.cpp | 52 +- src/actions/rs_actionsetsnaprestriction.h | 48 +- .../rs_actionsnapintersectionmanual.cpp | 299 ++++---- src/actions/rs_actionsnapintersectionmanual.h | 85 +-- .../rs_actiontoolregeneratedimensions.cpp | 73 +- .../rs_actiontoolregeneratedimensions.h | 44 +- src/actions/rs_actionzoomauto.cpp | 57 +- src/actions/rs_actionzoomauto.h | 49 +- src/actions/rs_actionzoomautoy.cpp | 50 +- src/actions/rs_actionzoomautoy.h | 42 +- src/actions/rs_actionzoomin.cpp | 41 +- src/actions/rs_actionzoomin.h | 13 +- src/actions/rs_actionzoompan.cpp | 157 ++-- src/actions/rs_actionzoompan.h | 68 +- src/actions/rs_actionzoomprevious.cpp | 62 +- src/actions/rs_actionzoomprevious.h | 46 +- src/actions/rs_actionzoomredraw.cpp | 56 +- src/actions/rs_actionzoomredraw.h | 44 +- src/actions/rs_actionzoomscroll.cpp | 49 +- src/actions/rs_actionzoomscroll.h | 47 +- src/actions/rs_actionzoomwindow.cpp | 69 +- src/actions/rs_actionzoomwindow.h | 70 +- src/base/rs.h | 2 + src/base/rs_actioninterface.cpp | 10 +- src/base/rs_actioninterface.h | 97 +-- ...{rs_application.h => rs_application.h.old} | 0 src/base/rs_commandevent.cpp | 52 ++ src/base/rs_commandevent.h | 2 + ...dinateevent.h => rs_coordinateevent.h.old} | 0 src/base/rs_creation.cpp | 49 +- src/base/rs_creation.h | 22 +- src/base/rs_eventhandler.cpp | 42 +- src/base/rs_graphicview.cpp | 4 +- src/base/rs_graphicview.h | 580 +++++++-------- src/base/rs_previewactioninterface.cpp | 4 + src/base/rs_previewactioninterface.h | 1 + src/base/rs_snapper.cpp | 13 +- src/base/rs_snapper.h | 6 +- 229 files changed, 14710 insertions(+), 19206 deletions(-) rename src/base/{rs_application.h => rs_application.h.old} (100%) create mode 100644 src/base/rs_commandevent.cpp rename src/base/{rs_coordinateevent.h => rs_coordinateevent.h.old} (100%) diff --git a/architektonas.pro b/architektonas.pro index b147164..7c4f4ba 100644 --- a/architektonas.pro +++ b/architektonas.pro @@ -34,7 +34,6 @@ HEADERS = \ src/base/rs_creation.h \ src/base/rs_debug.h \ src/base/rs.h \ - src/base/rs_application.h \ src/base/rs_arc.h \ src/base/rs_atomicentity.h \ src/base/rs_block.h \ @@ -91,7 +90,6 @@ HEADERS = \ src/base/rs_filterdxf1.h \ src/base/rs_filterinterface.h \ src/base/rs_commandevent.h \ - src/base/rs_coordinateevent.h \ src/base/rs_dialogfactory.h \ src/base/rs_dialogfactoryinterface.h \ src/base/rs_dialogfactoryadapter.h \ diff --git a/src/actions/rs_actionblocksadd.cpp b/src/actions/rs_actionblocksadd.cpp index d6705fe..a0ca3d6 100644 --- a/src/actions/rs_actionblocksadd.cpp +++ b/src/actions/rs_actionblocksadd.cpp @@ -10,7 +10,7 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** -** Licensees holding valid qcadlib Professional Edition licenses may use +** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License ** Agreement provided with the Software. ** @@ -29,9 +29,8 @@ #include "drawing.h" #include "rs_dialogfactory.h" -RS_ActionBlocksAdd::RS_ActionBlocksAdd(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Add Block", container, graphicView) +RS_ActionBlocksAdd::RS_ActionBlocksAdd(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Add Block", container, graphicView) { } @@ -41,17 +40,17 @@ QAction * RS_ActionBlocksAdd::createGUIAction(RS2::ActionType /*type*/, QObject // QAction * action = new QAction(tr("Add Block"), tr("&Add Block"), // QKeySequence(), NULL); QAction * action = new QAction(tr("&Add Block"), 0); - action->setStatusTip(tr("Add Block")); - return action; + action->setStatusTip(tr("Add Block")); + return action; } void RS_ActionBlocksAdd::trigger() { - RS_DEBUG->print("adding block"); - //RS_Block* block = new RS_Block(container, "", Vector(0.0,0.0)); + RS_DEBUG->print("adding block"); + //RS_Block* block = new RS_Block(container, "", Vector(0.0,0.0)); - if (graphic != NULL) - { + if (graphic != NULL) + { RS_BlockList * blockList = graphic->getBlockList(); if (blockList != NULL) @@ -59,21 +58,17 @@ void RS_ActionBlocksAdd::trigger() RS_BlockData d = RS_DIALOGFACTORY->requestNewBlockDialog(blockList); if (d.isValid()) - { - graphic->addBlock(new RS_Block(container, d)); - } + graphic->addBlock(new RS_Block(container, d)); } - } + } - finish(); + finish(); } - - void RS_ActionBlocksAdd::init(int status) { - RS_ActionInterface::init(status); - trigger(); + RS_ActionInterface::init(status); + trigger(); } // EOF diff --git a/src/actions/rs_actionblocksadd.h b/src/actions/rs_actionblocksadd.h index 70f4caf..c2b2e0c 100644 --- a/src/actions/rs_actionblocksadd.h +++ b/src/actions/rs_actionblocksadd.h @@ -10,7 +10,7 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** -** Licensees holding valid qcadlib Professional Edition licenses may use +** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License ** Agreement provided with the Software. ** @@ -34,18 +34,19 @@ * * @author Andrew Mustun */ -class RS_ActionBlocksAdd : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionBlocksAdd(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionBlocksAdd() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionBlocksAdd: public RS_ActionInterface +{ + //Q_OBJECT + public: + RS_ActionBlocksAdd(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionBlocksAdd() + { + } - virtual void init(int status=0); - virtual void trigger(); + static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionblocksattributes.cpp b/src/actions/rs_actionblocksattributes.cpp index 9c363e3..67ef48b 100644 --- a/src/actions/rs_actionblocksattributes.cpp +++ b/src/actions/rs_actionblocksattributes.cpp @@ -10,7 +10,7 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** -** Licensees holding valid qcadlib Professional Edition licenses may use +** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License ** Agreement provided with the Software. ** @@ -29,66 +29,58 @@ #include "drawing.h" #include "rs_dialogfactory.h" - - RS_ActionBlocksAttributes::RS_ActionBlocksAttributes( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Edit Block Attributes", container, graphicView) + RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Edit Block Attributes", container, graphicView) { } - - -QAction* RS_ActionBlocksAttributes::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +QAction * RS_ActionBlocksAttributes::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) { - - QAction * action = new QAction(tr("&Rename Block"), 0); + QAction * action = new QAction(tr("&Rename Block"), 0); // QAction* action = new QAction(tr("Rename Block"), // tr("&Rename Block"), // QKeySequence(), NULL); - action->setStatusTip(tr("Rename Block and all Inserts")); - return action; + action->setStatusTip(tr("Rename Block and all Inserts")); + return action; } - - void RS_ActionBlocksAttributes::trigger() { - RS_DEBUG->print("editing block attributes"); - - if (graphic!=NULL && RS_DIALOGFACTORY!=NULL) { - RS_Block* block = graphic->getActiveBlock(); - RS_BlockList* blockList = graphic->getBlockList(); - if (blockList!=NULL && block!=NULL) { - QString oldName = block->getName(); - - RS_BlockData d; - d = RS_DIALOGFACTORY->requestBlockAttributesDialog( - blockList); - - if (d.isValid()) { - - QString newName = d.name; - blockList->rename(block, newName); - - // update the name of all inserts: - graphic->renameInserts(oldName, newName); - - graphic->addBlockNotification(); - } - } - - } - finish(); + RS_DEBUG->print("editing block attributes"); + + if (graphic != NULL && RS_DIALOGFACTORY != NULL) + { + RS_Block * block = graphic->getActiveBlock(); + RS_BlockList * blockList = graphic->getBlockList(); + + if (blockList != NULL && block != NULL) + { + QString oldName = block->getName(); + + RS_BlockData d; + d = RS_DIALOGFACTORY->requestBlockAttributesDialog( + blockList); + + if (d.isValid()) + { + QString newName = d.name; + blockList->rename(block, newName); + + // update the name of all inserts: + graphic->renameInserts(oldName, newName); + + graphic->addBlockNotification(); + } + } + } + finish(); } - - void RS_ActionBlocksAttributes::init(int status) { - RS_ActionInterface::init(status); - trigger(); + RS_ActionInterface::init(status); + trigger(); } // EOF diff --git a/src/actions/rs_actionblocksattributes.h b/src/actions/rs_actionblocksattributes.h index 9c36281..80dc698 100644 --- a/src/actions/rs_actionblocksattributes.h +++ b/src/actions/rs_actionblocksattributes.h @@ -10,7 +10,7 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** -** Licensees holding valid qcadlib Professional Edition licenses may use +** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License ** Agreement provided with the Software. ** @@ -34,18 +34,19 @@ * * @author Andrew Mustun */ -class RS_ActionBlocksAttributes : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionBlocksAttributes(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionBlocksAttributes() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionBlocksAttributes: public RS_ActionInterface +{ + //Q_OBJECT + public: + RS_ActionBlocksAttributes(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionBlocksAttributes() + { + } - virtual void init(int status=0); - virtual void trigger(); + static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionblockscreate.cpp b/src/actions/rs_actionblockscreate.cpp index 77f0126..083f2fe 100644 --- a/src/actions/rs_actionblockscreate.cpp +++ b/src/actions/rs_actionblockscreate.cpp @@ -1,192 +1,181 @@ -/**************************************************************************** -** $Id: rs_actionblockscreate.cpp 1134 2004-07-13 23:26:13Z 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_actionblockscreate.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/03/2010 Added this text. :-) +// JLH 06/03/2010 Scrubbed out all occurances of RS_CoordinateEvent +// #include "rs_actionblockscreate.h" #include "rs_creation.h" +#include "rs_dialogfactory.h" #include "rs_insert.h" #include "rs_modification.h" /** * Constructor. */ -RS_ActionBlocksCreate::RS_ActionBlocksCreate(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Blocks Create", - container, graphicView) +RS_ActionBlocksCreate::RS_ActionBlocksCreate(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Blocks Create", container, graphicView) { - referencePoint = Vector(false); + referencePoint = Vector(false); } +RS_ActionBlocksCreate::~RS_ActionBlocksCreate() +{ +} - -RS_ActionBlocksCreate::~RS_ActionBlocksCreate() {} - - - -QAction* RS_ActionBlocksCreate::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +#if 0 +QAction * RS_ActionBlocksCreate::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) { - QAction * action = new QAction(tr("&Create Block"), 0); + QAction * action = new QAction(tr("&Create Block"), 0); // QAction* action = new QAction(tr("Create Block"), // tr("&Create Block"), // QKeySequence(), NULL); - action->setStatusTip(tr("Create Block")); + action->setStatusTip(tr("Create Block")); - return action; + return action; } +#endif - -void RS_ActionBlocksCreate::init(int status) { - RS_PreviewActionInterface::init(status); - +/*virtual*/ RS2::ActionType RS_ActionBlocksCreate::rtti() +{ + return RS2::ActionBlocksCreate; } - - -void RS_ActionBlocksCreate::trigger() { - deleteSnapper(); - //deletePreview(); - //clearPreview(); - - //RS_Modification m(*container, graphicView); - //m.paste(data.insertionPoint); - //std::cout << *RS_Clipboard::instance(); - - if (graphic!=NULL) { - RS_BlockList* blockList = graphic->getBlockList(); - if (blockList!=NULL) { - RS_BlockData d = - RS_DIALOGFACTORY->requestNewBlockDialog(blockList); - - if (!d.name.isEmpty()) { - RS_Creation creation(container, graphicView); - creation.createBlock(d, referencePoint, true); - - RS_InsertData id( - d.name, - referencePoint, - Vector(1.0,1.0), - 0.0, - 1, 1, Vector(0.0,0.0) - ); - creation.createInsert(id); - } - } - } - - graphicView->redraw(); - finish(); - graphicView->killSelectActions(); +void RS_ActionBlocksCreate::init(int status) +{ + RS_PreviewActionInterface::init(status); } - -void RS_ActionBlocksCreate::mouseMoveEvent(QMouseEvent* e) { - snapPoint(e); - - switch (getStatus()) { - case SetReferencePoint: - //data.insertionPoint = snapPoint(e); - - /*if (block!=NULL) { - deletePreview(); - clearPreview(); - //preview->addAllFrom(*block); - //preview->move(data.insertionPoint); - RS_Creation creation(preview, NULL, false); - creation.createInsert(data); - drawPreview(); - }*/ - break; - - default: - break; - } +void RS_ActionBlocksCreate::trigger() +{ + deleteSnapper(); + //deletePreview(); + //clearPreview(); + + //RS_Modification m(*container, graphicView); + //m.paste(data.insertionPoint); + //std::cout << *RS_Clipboard::instance(); + + if (graphic != NULL) + { + RS_BlockList * blockList = graphic->getBlockList(); + + if (blockList != NULL) + { + RS_BlockData d = RS_DIALOGFACTORY->requestNewBlockDialog(blockList); + + if (!d.name.isEmpty()) + { + RS_Creation creation(container, graphicView); + creation.createBlock(d, referencePoint, true); + + RS_InsertData id(d.name, referencePoint, Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0)); + creation.createInsert(id); + } + } + } + + graphicView->redraw(); + finish(); + graphicView->killSelectActions(); } - - -void RS_ActionBlocksCreate::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionBlocksCreate::mouseMoveEvent(QMouseEvent * e) +{ + snapPoint(e); + + switch (getStatus()) + { + case SetReferencePoint: + //data.insertionPoint = snapPoint(e); + + /*if (block!=NULL) { + deletePreview(); + clearPreview(); + //preview->addAllFrom(*block); + //preview->move(data.insertionPoint); + RS_Creation creation(preview, NULL, false); + creation.createInsert(data); + drawPreview(); + }*/ + break; + + default: + break; + } } - - -void RS_ActionBlocksCreate::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - switch (getStatus()) { - case SetReferencePoint: - referencePoint = e->getCoordinate(); - trigger(); - break; - - default: - break; - - } +void RS_ActionBlocksCreate::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { +// Vector ce(snapPoint(e)); +// coordinateEvent(&ce); + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } +// else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionBlocksCreate::updateMouseButtonHints() { - switch (getStatus()) { - case SetReferencePoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), - tr("Cancel")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +//void RS_ActionBlocksCreate::coordinateEvent(Vector * e) +void RS_ActionBlocksCreate::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + switch (getStatus()) + { + case SetReferencePoint: +// referencePoint = e->getCoordinate(); + referencePoint = *e; + trigger(); + break; + + default: + break; + } } - - -void RS_ActionBlocksCreate::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionBlocksCreate::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetReferencePoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionBlocksCreate::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } +void RS_ActionBlocksCreate::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionBlocksCreate::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); +} -// EOF diff --git a/src/actions/rs_actionblockscreate.h b/src/actions/rs_actionblockscreate.h index 6e09a3c..021c47c 100644 --- a/src/actions/rs_actionblockscreate.h +++ b/src/actions/rs_actionblockscreate.h @@ -1,83 +1,48 @@ -/**************************************************************************** -** $Id: rs_actionblockscreate.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONBLOCKSCREATE_H #define RS_ACTIONBLOCKSCREATE_H #include "rs_previewactioninterface.h" -#include "rs_insert.h" +//#include "rs_insert.h" /** - * This action class can handle user events for creating blocks from + * This action class can handle user events for creating blocks from * existing entities. * * @author Andrew Mustun */ -class RS_ActionBlocksCreate : public RS_PreviewActionInterface { +class RS_ActionBlocksCreate: public RS_PreviewActionInterface +{ //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetReferencePoint, /**< Setting the reference point. */ - ShowDialog /**< Showing dialog for name. */ - }; - -public: - RS_ActionBlocksCreate(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionBlocksCreate(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionBlocksCreate; - } - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - //virtual void commandEvent(RS_CommandEvent* e); - //virtual QStringList getAvailableCommands(); - - //virtual void showOptions(); - //virtual void hideOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - Vector referencePoint; + public: + /** + * Action States. + */ + enum Status { + SetReferencePoint, /**< Setting the reference point. */ + ShowDialog /**< Showing dialog for name. */ + }; + + public: + RS_ActionBlocksCreate(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionBlocksCreate(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); +// virtual void coordinateEvent(Vector * e); + virtual void coordinateEvent(Vector * e); + //virtual void commandEvent(RS_CommandEvent * e); + //virtual QStringList getAvailableCommands(); + //virtual void showOptions(); + //virtual void hideOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + Vector referencePoint; }; #endif diff --git a/src/actions/rs_actionblocksedit.cpp b/src/actions/rs_actionblocksedit.cpp index e63c7a2..c8b163c 100644 --- a/src/actions/rs_actionblocksedit.cpp +++ b/src/actions/rs_actionblocksedit.cpp @@ -10,7 +10,7 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** -** Licensees holding valid qcadlib Professional Edition licenses may use +** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License ** Agreement provided with the Software. ** @@ -29,40 +29,38 @@ #include "drawing.h" #include "rs_dialogfactory.h" +RS_ActionBlocksEdit::RS_ActionBlocksEdit(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Edit Block", container, graphicView) +{ +} - -RS_ActionBlocksEdit::RS_ActionBlocksEdit(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Edit Block", container, graphicView) {} - - -QAction* RS_ActionBlocksEdit::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +QAction * RS_ActionBlocksEdit::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) { - QAction* action = new QAction(tr("&Edit Block"), 0); + QAction * action = new QAction(tr("&Edit Block"), 0); // QAction* action = new QAction(tr("Edit Block"), tr("&Edit Block"), // QKeySequence(), NULL); - action->setStatusTip(tr("Edit Block")); - return action; + action->setStatusTip(tr("Edit Block")); + return action; } +void RS_ActionBlocksEdit::trigger() +{ + RS_DEBUG->print("edit block"); -void RS_ActionBlocksEdit::trigger() { - RS_DEBUG->print("edit block"); - if (graphic!=NULL) { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestEditBlockWindow(graphic->getBlockList()); - } - } else { - RS_DEBUG->print(RS_Debug::D_WARNING, - "RS_ActionBlocksEdit::trigger(): graphic is NULL"); - } - finish(); + if (graphic != NULL) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestEditBlockWindow(graphic->getBlockList()); + } + else + RS_DEBUG->print(RS_Debug::D_WARNING, + "RS_ActionBlocksEdit::trigger(): graphic is NULL"); + finish(); } - - -void RS_ActionBlocksEdit::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionBlocksEdit::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } diff --git a/src/actions/rs_actionblocksedit.h b/src/actions/rs_actionblocksedit.h index 845cdfa..764e036 100644 --- a/src/actions/rs_actionblocksedit.h +++ b/src/actions/rs_actionblocksedit.h @@ -10,7 +10,7 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** -** Licensees holding valid qcadlib Professional Edition licenses may use +** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License ** Agreement provided with the Software. ** @@ -34,18 +34,19 @@ * * @author Andrew Mustun */ -class RS_ActionBlocksEdit : public RS_ActionInterface { +class RS_ActionBlocksEdit: public RS_ActionInterface +{ //Q_OBJECT -public: - RS_ActionBlocksEdit(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionBlocksEdit() {} + public: + RS_ActionBlocksEdit(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionBlocksEdit() + { + } - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); + static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionblocksexplode.cpp b/src/actions/rs_actionblocksexplode.cpp index 969e097..f0de0d6 100644 --- a/src/actions/rs_actionblocksexplode.cpp +++ b/src/actions/rs_actionblocksexplode.cpp @@ -10,7 +10,7 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** -** Licensees holding valid qcadlib Professional Edition licenses may use +** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License ** Agreement provided with the Software. ** @@ -31,42 +31,39 @@ /** * Constructor. */ -RS_ActionBlocksExplode::RS_ActionBlocksExplode(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Blocks Explode", - container, graphicView) { +RS_ActionBlocksExplode::RS_ActionBlocksExplode(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_PreviewActionInterface("Blocks Explode", + container, graphicView) +{ } +RS_ActionBlocksExplode::~RS_ActionBlocksExplode() +{ +} - -RS_ActionBlocksExplode::~RS_ActionBlocksExplode() {} - - -QAction* RS_ActionBlocksExplode::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +QAction * RS_ActionBlocksExplode::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) { - QAction * action = new QAction(tr("&Explode"), 0); + QAction * action = new QAction(tr("&Explode"), 0); // QAction* action = new QAction(tr("Explode"), // tr("&Explode"), // QKeySequence(), NULL); - action->setStatusTip(tr("Explode Blocks and other Entity Groups")); + action->setStatusTip(tr("Explode Blocks and other Entity Groups")); - return action; + return action; } +void RS_ActionBlocksExplode::init(int status) +{ + RS_PreviewActionInterface::init(status); -void RS_ActionBlocksExplode::init(int status) { - RS_PreviewActionInterface::init(status); - - trigger(); - finish(); + trigger(); + finish(); } - - -void RS_ActionBlocksExplode::trigger() { - RS_Modification m(*container, graphicView); - m.explode(); +void RS_ActionBlocksExplode::trigger() +{ + RS_Modification m(*container, graphicView); + m.explode(); } - // EOF diff --git a/src/actions/rs_actionblocksexplode.h b/src/actions/rs_actionblocksexplode.h index e6cf422..ed2de13 100644 --- a/src/actions/rs_actionblocksexplode.h +++ b/src/actions/rs_actionblocksexplode.h @@ -10,7 +10,7 @@ ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. ** -** Licensees holding valid qcadlib Professional Edition licenses may use +** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License ** Agreement provided with the Software. ** @@ -36,22 +36,23 @@ * * @author Andrew Mustun */ -class RS_ActionBlocksExplode : public RS_PreviewActionInterface { +class RS_ActionBlocksExplode: public RS_PreviewActionInterface +{ //Q_OBJECT -public: - RS_ActionBlocksExplode(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionBlocksExplode(); + public: + RS_ActionBlocksExplode(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionBlocksExplode(); - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionBlocksExplode; - } + static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); - virtual void init(int status=0); + virtual RS2::ActionType rtti() + { + return RS2::ActionBlocksExplode; + } - virtual void trigger(); + virtual void init(int status = 0); + + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionblocksfreezeall.cpp b/src/actions/rs_actionblocksfreezeall.cpp index 13305d3..90313f7 100644 --- a/src/actions/rs_actionblocksfreezeall.cpp +++ b/src/actions/rs_actionblocksfreezeall.cpp @@ -15,41 +15,23 @@ #include "rs_actionblocksfreezeall.h" #include "drawing.h" +#include "rs_graphicview.h" -RS_ActionBlocksFreezeAll::RS_ActionBlocksFreezeAll(bool freeze, RS_EntityContainer & container, - RS_GraphicView& graphicView): RS_ActionInterface("Freeze all Blocks", - container, graphicView) +RS_ActionBlocksFreezeAll::RS_ActionBlocksFreezeAll(bool freeze, RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Freeze all Blocks", + container, graphicView) { this->freeze = freeze; } -QAction * RS_ActionBlocksFreezeAll::createGUIAction(RS2::ActionType type, QObject* /*parent*/) +RS_ActionBlocksFreezeAll::~RS_ActionBlocksFreezeAll() { - QAction * action = NULL; - - if (type == RS2::ActionBlocksFreezeAll) - { - action = new QAction(tr("&Freeze all"), 0); -// action= new QAction(tr("Freeze all"), tr("&Freeze all"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Freeze all blocks")); - } - else if (type == RS2::ActionBlocksDefreezeAll) - { - action = new QAction(tr("&Defreeze all"), 0); -// action = new QAction(tr("Defreeze all"), tr("&Defreeze all"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Defreeze all blocks")); - } - - return action; } void RS_ActionBlocksFreezeAll::trigger() { RS_DEBUG->print("RS_ActionBlocksFreezeAll::trigger"); - if (graphic!=NULL) + if (graphic != NULL) graphic->freezeAllBlocks(freeze); graphicView->redraw(); @@ -61,3 +43,4 @@ void RS_ActionBlocksFreezeAll::init(int status) RS_ActionInterface::init(status); trigger(); } + diff --git a/src/actions/rs_actionblocksfreezeall.h b/src/actions/rs_actionblocksfreezeall.h index 4192b62..32a04b7 100644 --- a/src/actions/rs_actionblocksfreezeall.h +++ b/src/actions/rs_actionblocksfreezeall.h @@ -1,55 +1,25 @@ -/**************************************************************************** -** $Id: rs_actionblocksfreezeall.h 1092 2004-03-16 18:01:08Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONBLOCKSFREEZEALL_H #define RS_ACTIONBLOCKSFREEZEALL_H #include "rs_actioninterface.h" - /** * This action class can handle user events to edit layers. * * @author Andrew Mustun */ -class RS_ActionBlocksFreezeAll : public RS_ActionInterface { +class RS_ActionBlocksFreezeAll: public RS_ActionInterface +{ //Q_OBJECT -public: - RS_ActionBlocksFreezeAll(bool freeze, - RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionBlocksFreezeAll() {} - - static QAction* createGUIAction(RS2::ActionType type, QObject* /*parent*/); + public: + RS_ActionBlocksFreezeAll(bool freeze, RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionBlocksFreezeAll(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); -private: - bool freeze; + private: + bool freeze; }; #endif diff --git a/src/actions/rs_actionblocksinsert.cpp b/src/actions/rs_actionblocksinsert.cpp index 5312c31..390485c 100644 --- a/src/actions/rs_actionblocksinsert.cpp +++ b/src/actions/rs_actionblocksinsert.cpp @@ -1,378 +1,448 @@ -/**************************************************************************** -** $Id: rs_actionblocksinsert.cpp 1148 2004-09-11 21:38:11Z 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_actionblocksinsert.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/03/2010 Added this text. :-) +// JLH 06/03/2010 Scrubbed out all occurances of RS_CoordinateEvent +// #include "rs_actionblocksinsert.h" -#include "rs_creation.h" #include "commands.h" +#include "rs_creation.h" +#include "rs_dialogfactory.h" #include "rs_modification.h" - +#include "rs_preview.h" /** * Constructor. */ -RS_ActionBlocksInsert::RS_ActionBlocksInsert(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Blocks Insert", - container, graphicView) {} - - +RS_ActionBlocksInsert::RS_ActionBlocksInsert(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Blocks Insert", + container, graphicView) +{ +} -RS_ActionBlocksInsert::~RS_ActionBlocksInsert() {} +RS_ActionBlocksInsert::~RS_ActionBlocksInsert() +{ +} -QAction* RS_ActionBlocksInsert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +#if 0 +QAction * RS_ActionBlocksInsert::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) { - QAction * action = new QAction(tr("&Insert Block"), 0); + QAction * action = new QAction(tr("&Insert Block"), 0); // QAction* action = new QAction(tr("Insert Block"), tr("&Insert Block"), // QKeySequence(), NULL); - action->setStatusTip(tr("Insert Block")); + action->setStatusTip(tr("Insert Block")); - return action; + return action; } -void RS_ActionBlocksInsert::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); +#endif - if (graphic!=NULL) { - block = graphic->getActiveBlock(); - if (block!=NULL) { - data.name = block->getName(); - } else { - finish(); - } - } +/*virtual*/ RS2::ActionType RS_ActionBlocksInsert::rtti() +{ + return RS2::ActionBlocksInsert; } +void RS_ActionBlocksInsert::init(int status /*= 0*/) +{ + RS_PreviewActionInterface::init(status); + + reset(); + if (graphic != NULL) + { + block = graphic->getActiveBlock(); -void RS_ActionBlocksInsert::reset() { - data = RS_InsertData("", - Vector(0.0,0.0), - Vector(1.0,1.0), - 0.0, - 1, 1, - Vector(1.0,1.0), - NULL, - RS2::Update); + if (block != NULL) + data.name = block->getName(); + else + finish(); + } } +void RS_ActionBlocksInsert::reset() +{ + data = RS_InsertData("", Vector(0.0, 0.0), Vector(1.0, 1.0), 0.0, + 1, 1, Vector(1.0, 1.0), NULL, RS2::Update); +} +void RS_ActionBlocksInsert::trigger() +{ + deleteSnapper(); + deletePreview(); + clearPreview(); -void RS_ActionBlocksInsert::trigger() { - deleteSnapper(); - deletePreview(); - clearPreview(); - - //RS_Modification m(*container, graphicView); - //m.paste(data.insertionPoint); - //std::cout << *RS_Clipboard::instance(); + //RS_Modification m(*container, graphicView); + //m.paste(data.insertionPoint); + //std::cout << *RS_Clipboard::instance(); - if (block!=NULL) { - RS_Creation creation(container, graphicView); + if (block != NULL) + { + RS_Creation creation(container, graphicView); data.updateMode = RS2::Update; - creation.createInsert(data); - } + creation.createInsert(data); + } - graphicView->redraw(); - //finish(); + graphicView->redraw(); + //finish(); } - -void RS_ActionBlocksInsert::mouseMoveEvent(QMouseEvent* e) { - switch (getStatus()) { - case SetTargetPoint: - data.insertionPoint = snapPoint(e); - - if (block!=NULL) { - deletePreview(); - clearPreview(); - //preview->addAllFrom(*block); - //preview->move(data.insertionPoint); - RS_Creation creation(preview, NULL, false); +void RS_ActionBlocksInsert::mouseMoveEvent(QMouseEvent * e) +{ + switch (getStatus()) + { + case SetTargetPoint: + data.insertionPoint = snapPoint(e); + + if (block != NULL) + { + deletePreview(); + clearPreview(); + //preview->addAllFrom(*block); + //preview->move(data.insertionPoint); + RS_Creation creation(preview, NULL, false); // Create insert as preview only data.updateMode = RS2::PreviewUpdate; - creation.createInsert(data); - drawPreview(); - } - break; - - default: - break; - } + creation.createInsert(data); + drawPreview(); + } + break; + + default: + break; + } } - - -void RS_ActionBlocksInsert::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionBlocksInsert::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + deleteSnapper(); + init(getStatus() - 1); + } } +void RS_ActionBlocksInsert::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; - -void RS_ActionBlocksInsert::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - data.insertionPoint = e->getCoordinate(); - trigger(); +// data.insertionPoint = e->getCoordinate(); + data.insertionPoint = *e; + trigger(); } - - -void RS_ActionBlocksInsert::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - switch (getStatus()) { - case SetTargetPoint: - if (checkCommand("angle", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetAngle); - } else if (checkCommand("factor", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetFactor); - } else if (checkCommand("columns", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetColumns); - } else if (checkCommand("rows", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetRows); - } else if (checkCommand("columnspacing", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetColumnSpacing); - } else if (checkCommand("rowspacing", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetRowSpacing); - } - break; - - case SetAngle: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - data.angle = RS_Math::deg2rad(a); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - case SetFactor: { - bool ok; - double f = RS_Math::eval(c, &ok); - if (ok==true) { - setFactor(f); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - case SetColumns: { - bool ok; - int cols = (int)RS_Math::eval(c, &ok); - if (ok==true) { - data.cols = cols; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - case SetRows: { - bool ok; - int rows = (int)RS_Math::eval(c, &ok); - if (ok==true) { - data.rows = rows; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - case SetColumnSpacing: { - bool ok; - double cs = (int)RS_Math::eval(c, &ok); - if (ok==true) { - data.spacing.x = cs; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - case SetRowSpacing: { - bool ok; - int rs = (int)RS_Math::eval(c, &ok); - if (ok==true) { - data.spacing.y = rs; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - default: - break; - } +void RS_ActionBlocksInsert::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + switch (getStatus()) + { + case SetTargetPoint: + + if (checkCommand("angle", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetAngle); + } + else if (checkCommand("factor", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetFactor); + } + else if (checkCommand("columns", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetColumns); + } + else if (checkCommand("rows", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetRows); + } + else if (checkCommand("columnspacing", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetColumnSpacing); + } + else if (checkCommand("rowspacing", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetRowSpacing); + } + break; + + case SetAngle: + { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + data.angle = RS_Math::deg2rad(a); + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + case SetFactor: + { + bool ok; + double f = RS_Math::eval(c, &ok); + + if (ok == true) + setFactor(f); + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + case SetColumns: + { + bool ok; + int cols = (int)RS_Math::eval(c, &ok); + + if (ok == true) + data.cols = cols; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + case SetRows: + { + bool ok; + int rows = (int)RS_Math::eval(c, &ok); + + if (ok == true) + data.rows = rows; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + case SetColumnSpacing: + { + bool ok; + double cs = (int)RS_Math::eval(c, &ok); + + if (ok == true) + data.spacing.x = cs; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + case SetRowSpacing: + { + bool ok; + int rs = (int)RS_Math::eval(c, &ok); + + if (ok == true) + data.spacing.y = rs; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + default: + break; + } } +QStringList RS_ActionBlocksInsert::getAvailableCommands() +{ + QStringList cmd; + + switch (getStatus()) + { + case SetTargetPoint: + cmd += command("angle"); + cmd += command("factor"); + cmd += command("columns"); + cmd += command("rows"); + cmd += command("columnspacing"); + cmd += command("rowspacing"); + break; + + default: + break; + } + + return cmd; +} - -QStringList RS_ActionBlocksInsert::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetTargetPoint: - cmd += command("angle"); - cmd += command("factor"); - ; - cmd += command("columns"); - cmd += command("rows"); - cmd += command("columnspacing"); - cmd += command("rowspacing"); - break; - default: - break; - } - - return cmd; +void RS_ActionBlocksInsert::showOptions() +{ + RS_ActionInterface::showOptions(); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionBlocksInsert::hideOptions() +{ + RS_ActionInterface::hideOptions(); + RS_DIALOGFACTORY->requestOptions(this, false); +} -void RS_ActionBlocksInsert::showOptions() { - RS_ActionInterface::showOptions(); +void RS_ActionBlocksInsert::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetTargetPoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel")); + break; + + case SetAngle: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), ""); + break; + + case SetFactor: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), ""); + break; + + case SetColumns: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter columns:"), ""); + break; + + case SetRows: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rows:"), ""); + break; + + case SetColumnSpacing: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter column spacing:"), ""); + break; + + case SetRowSpacing: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter row spacing:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } +} - RS_DIALOGFACTORY->requestOptions(this, true); +void RS_ActionBlocksInsert::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionBlocksInsert::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); +} +double RS_ActionBlocksInsert::getAngle() +{ + return data.angle; +} -void RS_ActionBlocksInsert::hideOptions() { - RS_ActionInterface::hideOptions(); +void RS_ActionBlocksInsert::setAngle(double a) +{ + data.angle = a; +} - RS_DIALOGFACTORY->requestOptions(this, false); +double RS_ActionBlocksInsert::getFactor() +{ + return data.scaleFactor.x; } +void RS_ActionBlocksInsert::setFactor(double f) +{ + data.scaleFactor = Vector(f, f); +} -void RS_ActionBlocksInsert::updateMouseButtonHints() { - switch (getStatus()) { - case SetTargetPoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), - tr("Cancel")); - break; - case SetAngle: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), - ""); - break; - case SetFactor: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), - ""); - break; - case SetColumns: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter columns:"), - ""); - break; - case SetRows: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rows:"), - ""); - break; - case SetColumnSpacing: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter column spacing:"), - ""); - break; - case SetRowSpacing: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter row spacing:"), - ""); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +int RS_ActionBlocksInsert::getColumns() +{ + return data.cols; } +void RS_ActionBlocksInsert::setColumns(int c) +{ + data.cols = c; +} +int RS_ActionBlocksInsert::getRows() +{ + return data.rows; +} -void RS_ActionBlocksInsert::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionBlocksInsert::setRows(int r) +{ + data.rows = r; } +double RS_ActionBlocksInsert::getColumnSpacing() +{ + return data.spacing.x; +} +void RS_ActionBlocksInsert::setColumnSpacing(double cs) +{ + data.spacing.x = cs; +} -void RS_ActionBlocksInsert::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } +double RS_ActionBlocksInsert::getRowSpacing() +{ + return data.spacing.y; } +void RS_ActionBlocksInsert::setRowSpacing(double rs) +{ + data.spacing.y = rs; +} -// EOF diff --git a/src/actions/rs_actionblocksinsert.h b/src/actions/rs_actionblocksinsert.h index 433dc9f..5ef4095 100644 --- a/src/actions/rs_actionblocksinsert.h +++ b/src/actions/rs_actionblocksinsert.h @@ -1,29 +1,3 @@ -/**************************************************************************** -** $Id: rs_actionblocksinsert.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONBLOCKSINSERT_H #define RS_ACTIONBLOCKSINSERT_H @@ -36,107 +10,60 @@ * * @author Andrew Mustun */ -class RS_ActionBlocksInsert : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetTargetPoint, /**< Setting the reference point. */ - SetAngle, /**< Setting angle in the command line. */ - SetFactor, /**< Setting factor in the command line. */ - SetColumns, /**< Setting columns in the command line. */ - SetRows, /**< Setting rows in the command line. */ - SetColumnSpacing, /**< Setting column spacing in the command line. */ - SetRowSpacing /**< Setting row spacing in the command line. */ - }; - -public: - RS_ActionBlocksInsert(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionBlocksInsert(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionBlocksInsert; - } - - virtual void init(int status=0); - - void reset(); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void showOptions(); - virtual void hideOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - double getAngle() { - return data.angle; - } - - void setAngle(double a) { - data.angle = a; - } - - double getFactor() { - return data.scaleFactor.x; - } - - void setFactor(double f) { - data.scaleFactor = Vector(f, f); - } - - int getColumns() { - return data.cols; - } - - void setColumns(int c) { - data.cols = c; - } - - int getRows() { - return data.rows; - } - - void setRows(int r) { - data.rows = r; - } - - double getColumnSpacing() { - return data.spacing.x; - } - - void setColumnSpacing(double cs) { - data.spacing.x = cs; - } - - double getRowSpacing() { - return data.spacing.y; - } - - void setRowSpacing(double rs) { - data.spacing.y = rs; - } - -protected: - RS_Block* block; - RS_InsertData data; - - /** Last status before entering option. */ - Status lastStatus; +class RS_ActionBlocksInsert: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetTargetPoint, /**< Setting the reference point. */ + SetAngle, /**< Setting angle in the command line. */ + SetFactor, /**< Setting factor in the command line. */ + SetColumns, /**< Setting columns in the command line. */ + SetRows, /**< Setting rows in the command line. */ + SetColumnSpacing, /**< Setting column spacing in the command line. */ + SetRowSpacing /**< Setting row spacing in the command line. */ + }; + + public: + RS_ActionBlocksInsert(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionBlocksInsert(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + void reset(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void showOptions(); + virtual void hideOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + double getAngle(); + void setAngle(double a); + double getFactor(); + void setFactor(double f); + int getColumns(); + void setColumns(int c); + int getRows(); + void setRows(int r); + double getColumnSpacing(); + void setColumnSpacing(double cs); + double getRowSpacing(); + void setRowSpacing(double rs); + + protected: + RS_Block * block; + RS_InsertData data; + + /** Last status before entering option. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actionblocksremove.cpp b/src/actions/rs_actionblocksremove.cpp index d51e5b0..0fae7c7 100644 --- a/src/actions/rs_actionblocksremove.cpp +++ b/src/actions/rs_actionblocksremove.cpp @@ -1,57 +1,39 @@ -/**************************************************************************** -** $Id: rs_actionblocksremove.cpp 2372 2005-04-29 11:44:54Z 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_actionblocksremove.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/03/2010 Added this text. :-) +// #include "rs_actionblocksremove.h" #include "rs_block.h" +#include "rs_dialogfactory.h" #include "drawing.h" +#include "rs_graphicview.h" #include "rs_insert.h" -#include "rs_dialogfactory.h" -RS_ActionBlocksRemove::RS_ActionBlocksRemove(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionBlocksRemove::RS_ActionBlocksRemove(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Remove Block", container, graphicView) { } -QAction * RS_ActionBlocksRemove::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionBlocksRemove::~RS_ActionBlocksRemove() { - QAction * action = new QAction(tr("&Remove Block"), 0); -// QAction* action = new QAction(tr("Remove Block"), tr("&Remove Block"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Remove Block")); - - return action; } void RS_ActionBlocksRemove::trigger() { RS_DEBUG->print("RS_ActionBlocksRemove::trigger"); - if (graphic!=NULL) + if (graphic != NULL) { RS_Block * block = RS_DIALOGFACTORY->requestBlockRemovalDialog(graphic->getBlockList()); @@ -61,14 +43,14 @@ void RS_ActionBlocksRemove::trigger() containerList.append(graphic); RS_BlockList * blkLst = graphic->getBlockList(); - for(uint bi=0; bicount(); bi++) + for (uint bi = 0; bi < blkLst->count(); bi++) containerList.append(blkLst->at(bi)); if (block != NULL) { // for (RS_EntityContainer * cont=containerList.first(); cont!=NULL; // cont=containerList.next()) - for(int i=0; ifirstEntity(RS2::ResolveNone); e!=NULL; - e=cont->nextEntity(RS2::ResolveNone)) - { + for (RS_Entity * e = cont->firstEntity(RS2::ResolveNone); e != NULL; + e = cont->nextEntity(RS2::ResolveNone)) if (e->rtti() == RS2::EntityInsert) { RS_Insert * ins = (RS_Insert *)e; @@ -92,7 +73,6 @@ void RS_ActionBlocksRemove::trigger() break; } } - } } while (!done); } @@ -117,3 +97,4 @@ void RS_ActionBlocksRemove::init(int status) RS_ActionInterface::init(status); trigger(); } + diff --git a/src/actions/rs_actionblocksremove.h b/src/actions/rs_actionblocksremove.h index 1400d88..4ad441e 100644 --- a/src/actions/rs_actionblocksremove.h +++ b/src/actions/rs_actionblocksremove.h @@ -1,29 +1,3 @@ -/**************************************************************************** -** $Id: rs_actionblocksremove.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONBLOCKSREMOVE_H #define RS_ACTIONBLOCKSREMOVE_H @@ -36,12 +10,9 @@ */ class RS_ActionBlocksRemove: public RS_ActionInterface { -// //Q_OBJECT public: RS_ActionBlocksRemove(RS_EntityContainer & container, RS_GraphicView & graphicView); - ~RS_ActionBlocksRemove() {} - - static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); + ~RS_ActionBlocksRemove(); virtual void init(int status = 0); virtual void trigger(); diff --git a/src/actions/rs_actionblockstoggleview.cpp b/src/actions/rs_actionblockstoggleview.cpp index 66fd128..f596ceb 100644 --- a/src/actions/rs_actionblockstoggleview.cpp +++ b/src/actions/rs_actionblockstoggleview.cpp @@ -1,69 +1,48 @@ -/**************************************************************************** -** $Id: rs_actionblockstoggleview.cpp 1062 2004-01-16 21:51:20Z 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_actionblockstoggleview.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/03/2010 Added this text. :-) +// #include "rs_actionblockstoggleview.h" #include "drawing.h" +#include "rs_graphicview.h" - - -RS_ActionBlocksToggleView::RS_ActionBlocksToggleView( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Toggle Block Visibility", - container, graphicView) {} - - -QAction * RS_ActionBlocksToggleView::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionBlocksToggleView::RS_ActionBlocksToggleView(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Toggle Block Visibility", + container, graphicView) { - QAction * action = new QAction(tr("&Toggle Block"), 0); -// QAction* action = new QAction(tr("Toggle Block Visibility"), -// tr("&Toggle Block"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Toggle Block")); +} - return action; +RS_ActionBlocksToggleView::~RS_ActionBlocksToggleView() +{ } +void RS_ActionBlocksToggleView::trigger() +{ + RS_DEBUG->print("toggle block"); + + if (graphic != NULL) + { + RS_Block * block = graphic->getActiveBlock(); + graphic->toggleBlock(block); + } -void RS_ActionBlocksToggleView::trigger() { - RS_DEBUG->print("toggle block"); - if (graphic!=NULL) { - RS_Block* block = graphic->getActiveBlock(); - graphic->toggleBlock(block); - } graphicView->redraw(); - finish(); + finish(); } - - -void RS_ActionBlocksToggleView::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionBlocksToggleView::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } -// EOF diff --git a/src/actions/rs_actionblockstoggleview.h b/src/actions/rs_actionblockstoggleview.h index 1a69d67..9009d34 100644 --- a/src/actions/rs_actionblockstoggleview.h +++ b/src/actions/rs_actionblockstoggleview.h @@ -1,52 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionblockstoggleview.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONBLOCKSTOGGLEVIEW_H #define RS_ACTIONBLOCKSTOGGLEVIEW_H #include "rs_actioninterface.h" - /** * This action class can handle user events to edit layers. * * @author Andrew Mustun */ -class RS_ActionBlocksToggleView : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionBlocksToggleView(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionBlocksToggleView() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); +class RS_ActionBlocksToggleView: public RS_ActionInterface +{ + public: + RS_ActionBlocksToggleView(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionBlocksToggleView(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actiondefault.cpp b/src/actions/rs_actiondefault.cpp index 62aa5a3..9159eee 100644 --- a/src/actions/rs_actiondefault.cpp +++ b/src/actions/rs_actiondefault.cpp @@ -1,412 +1,388 @@ -/**************************************************************************** -** $Id: rs_actiondefault.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_actiondefault.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/03/2010 Added this text. :-) +// #include "rs_actiondefault.h" #include "rs.h" +#include "rs_dialogfactory.h" +#include "rs_line.h" #include "rs_modification.h" +#include "rs_preview.h" #include "rs_snapper.h" #include "rs_selection.h" - - /** * Constructor. */ -RS_ActionDefault::RS_ActionDefault(RS_EntityContainer& container, - RS_GraphicView& graphicView) - : RS_PreviewActionInterface("Default", - container, graphicView) { - +RS_ActionDefault::RS_ActionDefault(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Default", + container, graphicView) +{ RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault"); RS_DEBUG->print("RS_ActionDefault::RS_ActionDefault: OK"); } - - -RS_ActionDefault::~RS_ActionDefault() { +RS_ActionDefault::~RS_ActionDefault() +{ } - - -QAction* RS_ActionDefault::createGUIAction(RS2::ActionType /*type*/, - QObject* /*parent*/) { - - return NULL; -} - - -void RS_ActionDefault::init(int status) { +void RS_ActionDefault::init(int status) +{ RS_DEBUG->print("RS_ActionDefault::init"); - + RS_PreviewActionInterface::init(status); - v1 = v2 = Vector(false); - snapMode = RS2::SnapFree; - snapRes = RS2::RestrictNothing; - restrBak = RS2::RestrictNothing; + v1 = v2 = Vector(false); + snapMode = RS2::SnapFree; + snapRes = RS2::RestrictNothing; + restrBak = RS2::RestrictNothing; RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - + RS_DEBUG->print("RS_ActionDefault::init: OK"); } - - -void RS_ActionDefault::trigger() { - RS_PreviewActionInterface::trigger(); - +void RS_ActionDefault::trigger() +{ + RS_PreviewActionInterface::trigger(); } -void RS_ActionDefault::keyPressEvent(QKeyEvent* e) { - if (e->key()==Qt::Key_Shift) { +void RS_ActionDefault::keyPressEvent(QKeyEvent * e) +{ + if (e->key() == Qt::Key_Shift) + { restrBak = snapRes; setSnapRestriction(RS2::RestrictOrthogonal); } } -void RS_ActionDefault::keyReleaseEvent(QKeyEvent* e) { - if (e->key()==Qt::Key_Shift) { +void RS_ActionDefault::keyReleaseEvent(QKeyEvent * e) +{ + if (e->key() == Qt::Key_Shift) setSnapRestriction(restrBak); - } } +void RS_ActionDefault::mouseMoveEvent(QMouseEvent * e) +{ + Vector mouse = graphicView->toGraph(Vector(e->x(), e->y())); + Vector relMouse = mouse - graphicView->getRelativeZero(); -void RS_ActionDefault::mouseMoveEvent(QMouseEvent* e) { - - Vector mouse = graphicView->toGraph(Vector(e->x(), e->y())); - Vector relMouse = mouse - graphicView->getRelativeZero(); + RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse); - RS_DIALOGFACTORY->updateCoordinateWidget(mouse, relMouse); + switch (getStatus()) + { + case Dragging: + //v2 = graphicView->toGraph(e->x(), e->y()); + v2 = mouse; - switch (getStatus()) { - case Dragging: - //v2 = graphicView->toGraph(e->x(), e->y()); - v2 = mouse; + if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10) + { + // look for reference points to drag: + double dist; + Vector ref = container->getNearestSelectedRef(v1, &dist); - if (graphicView->toGuiDX(v1.distanceTo(v2))>10) { - // look for reference points to drag: - double dist; - Vector ref = container->getNearestSelectedRef(v1, &dist); - if (ref.valid==true && graphicView->toGuiDX(dist)<8) { + if (ref.valid == true && graphicView->toGuiDX(dist) < 8) + { RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: " "moving reference point"); - setStatus(MovingRef); - v1 = ref; - graphicView->moveRelativeZero(v1); - } - else { - // test for an entity to drag: - RS_Entity* en = catchEntity(v1); - if (en!=NULL && en->isSelected()) { + setStatus(MovingRef); + v1 = ref; + graphicView->moveRelativeZero(v1); + } + else + { + // test for an entity to drag: + RS_Entity * en = catchEntity(v1); + + if (en != NULL && en->isSelected()) + { RS_DEBUG->print("RS_ActionDefault::mouseMoveEvent: " "moving entity"); - setStatus(Moving); - v1 = en->getNearestRef(v1); - graphicView->moveRelativeZero(v1); - } - - // no entity found. start area selection: - else { - setStatus(SetCorner2); - } - } - } - break; - - case MovingRef: - v2 = snapPoint(e); - - deletePreview(); - clearPreview(); - preview->addSelectionFrom(*container); - preview->moveRef(v1, v2-v1); - drawPreview(); - break; - - case Moving: - v2 = snapPoint(e); - - deletePreview(); - clearPreview(); - preview->addSelectionFrom(*container); - preview->move(v2-v1); - drawPreview(); - break; - - case SetCorner2: - if (v1.valid) { - //v2 = snapPoint(e); - v2 = mouse; - - //deleteSnapper(); - deletePreview(); - clearPreview(); - - preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v1.x, v1.y), - Vector(v2.x, v1.y)))); - preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v2.x, v1.y), - Vector(v2.x, v2.y)))); - preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v2.x, v2.y), - Vector(v1.x, v2.y)))); - preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v1.x, v2.y), - Vector(v1.x, v1.y)))); - drawPreview(); - } - - default: - break; - } -} - - - -void RS_ActionDefault::mousePressEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case Neutral: - v1 = graphicView->toGraph(e->x(), e->y()); - setStatus(Dragging); - break; - - case Moving: { - v2 = snapPoint(e); - deleteSnapper(); - deletePreview(); - clearPreview(); - RS_Modification m(*container, graphicView); - RS_MoveData data; - data.number = 0; - data.useCurrentLayer = false; - data.useCurrentAttributes = false; - data.offset = v2-v1; - m.move(data); - setStatus(Neutral); - RS_DIALOGFACTORY->updateSelectionWidget( - container->countSelected()); - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } - break; - - case MovingRef: { - v2 = snapPoint(e); - deleteSnapper(); - deletePreview(); - clearPreview(); - RS_Modification m(*container, graphicView); - RS_MoveRefData data; - data.ref = v1; - data.offset = v2-v1; - m.moveRef(data); - //container->moveSelectedRef(v1, v2-v2); - setStatus(Neutral); - RS_DIALOGFACTORY->updateSelectionWidget( - container->countSelected()); - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } - break; - - default: - break; - } - } -} - + setStatus(Moving); + v1 = en->getNearestRef(v1); + graphicView->moveRelativeZero(v1); + } + // no entity found. start area selection: + else + setStatus(SetCorner2); + } + } + break; + case MovingRef: + v2 = snapPoint(e); -void RS_ActionDefault::mouseReleaseEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDefault::mouseReleaseEvent()"); + deletePreview(); + clearPreview(); + preview->addSelectionFrom(*container); + preview->moveRef(v1, v2 - v1); + drawPreview(); + break; - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - v2 = graphicView->toGraph(e->x(), e->y()); - switch (getStatus()) { - case Dragging: { - // select single entity: - RS_Entity* en = catchEntity(e); + case Moving: + v2 = snapPoint(e); - if (en!=NULL) { - deleteSnapper(); - deletePreview(); - clearPreview(); + deletePreview(); + clearPreview(); + preview->addSelectionFrom(*container); + preview->move(v2 - v1); + drawPreview(); + break; - RS_Selection s(*container, graphicView); - s.selectSingle(en); + case SetCorner2: + + if (v1.valid) + { + //v2 = snapPoint(e); + v2 = mouse; + + //deleteSnapper(); + deletePreview(); + clearPreview(); + + preview->addEntity(new RS_Line(preview, + RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y)))); + preview->addEntity(new RS_Line(preview, + RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y)))); + preview->addEntity(new RS_Line(preview, + RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y)))); + preview->addEntity(new RS_Line(preview, + RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y)))); + drawPreview(); + } - RS_DIALOGFACTORY->updateSelectionWidget( - container->countSelected()); + default: + break; + } +} - //deleteSnapper(); -#if QT_VERSION>=0x030000 - e->accept(); -#endif +void RS_ActionDefault::mousePressEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case Neutral: + v1 = graphicView->toGraph(e->x(), e->y()); + setStatus(Dragging); + break; - setStatus(Neutral); - } else { - setStatus(SetCorner2); - } - } - break; + case Moving: + { + v2 = snapPoint(e); + deleteSnapper(); + deletePreview(); + clearPreview(); + RS_Modification m(*container, graphicView); + RS_MoveData data; + data.number = 0; + data.useCurrentLayer = false; + data.useCurrentAttributes = false; + data.offset = v2 - v1; + m.move(data); + setStatus(Neutral); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); + } + break; - case SetCorner2: { - //v2 = snapPoint(e); - v2 = graphicView->toGraph(e->x(), e->y()); + case MovingRef: + { + v2 = snapPoint(e); + deleteSnapper(); + deletePreview(); + clearPreview(); + RS_Modification m(*container, graphicView); + RS_MoveRefData data; + data.ref = v1; + data.offset = v2 - v1; + m.moveRef(data); + //container->moveSelectedRef(v1, v2-v2); + setStatus(Neutral); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); + } + break; - // select window: - //if (graphicView->toGuiDX(v1.distanceTo(v2))>20) { - deleteSnapper(); - deletePreview(); - clearPreview(); + default: + break; + } + } +} - bool cross = (v2.y>v1.y); - RS_Selection s(*container, graphicView); - s.selectWindow(v1, v2, true, cross); +void RS_ActionDefault::mouseReleaseEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDefault::mouseReleaseEvent()"); + + if (e->button() == Qt::LeftButton) + { + v2 = graphicView->toGraph(e->x(), e->y()); + + switch (getStatus()) + { + case Dragging: + { + // select single entity: + RS_Entity * en = catchEntity(e); + + if (en != NULL) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + + RS_Selection s(*container, graphicView); + s.selectSingle(en); + + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + + //deleteSnapper(); + e->accept(); + setStatus(Neutral); + } + else + setStatus(SetCorner2); + } + break; - RS_DIALOGFACTORY->updateSelectionWidget( - container->countSelected()); + case SetCorner2: + { + //v2 = snapPoint(e); + v2 = graphicView->toGraph(e->x(), e->y()); - setStatus(Neutral); -#if QT_VERSION>=0x030000 + // select window: + //if (graphicView->toGuiDX(v1.distanceTo(v2))>20) { + deleteSnapper(); + deletePreview(); + clearPreview(); - e->accept(); -#endif - //} - } - break; + bool cross = (v2.y > v1.y); + RS_Selection s(*container, graphicView); + s.selectWindow(v1, v2, true, cross); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - default: - break; + setStatus(Neutral); + e->accept(); + //} + } + break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - switch (getStatus()) { + default: + break; + } + } + else if (e->button() == Qt::RightButton) + { + switch (getStatus()) + { case SetCorner2: case Moving: case MovingRef: - deletePreview(); - clearPreview(); - deleteSnapper(); - setStatus(Neutral); + deletePreview(); + clearPreview(); + deleteSnapper(); + setStatus(Neutral); RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); -#if QT_VERSION>=0x030000 - - e->accept(); -#endif + e->accept(); break; default: - deleteSnapper(); - RS_DIALOGFACTORY->requestPreviousMenu(); -#if QT_VERSION>=0x030000 - - e->accept(); -#endif + deleteSnapper(); + RS_DIALOGFACTORY->requestPreviousMenu(); + e->accept(); break; } - } + } } - - -void RS_ActionDefault::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - // if the current action can't deal with the command, - // it might be intended to launch a new command - //if (!e.isAccepted()) { - // command for new action: - //RS2::ActionType type = RS_COMMANDS->cmdToAction(c); - //if (type!=RS2::ActionNone) { - //graphicView->setCurrentAction(type); - //return true; - //} - //} +void RS_ActionDefault::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + // if the current action can't deal with the command, + // it might be intended to launch a new command + //if (!e.isAccepted()) { + // command for new action: + //RS2::ActionType type = RS_COMMANDS->cmdToAction(c); + //if (type!=RS2::ActionNone) { + //graphicView->setCurrentAction(type); + //return true; + //} + //} } +QStringList RS_ActionDefault::getAvailableCommands() +{ + QStringList cmd; + //cmd += "line"; + //cmd += "rectangle"; -QStringList RS_ActionDefault::getAvailableCommands() { - QStringList cmd; - - //cmd += "line"; - //cmd += "rectangle"; - - return cmd; + return cmd; } +void RS_ActionDefault::updateMouseButtonHints() +{ + switch (getStatus()) + { + case Neutral: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; -void RS_ActionDefault::updateMouseButtonHints() { - switch (getStatus()) { - case Neutral: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - case SetCorner2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } -} - + case SetCorner2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back")); + break; + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } +} -void RS_ActionDefault::updateMouseCursor() { - switch (getStatus()) { +void RS_ActionDefault::updateMouseCursor() +{ + switch (getStatus()) + { case Neutral: - graphicView->setMouseCursor(RS2::ArrowCursor); + graphicView->setMouseCursor(RS2::ArrowCursor); break; + case Moving: case MovingRef: - graphicView->setMouseCursor(RS2::SelectCursor); + graphicView->setMouseCursor(RS2::SelectCursor); break; + default: break; } } - - -void RS_ActionDefault::updateToolBar() { - //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - switch (getStatus()) { +void RS_ActionDefault::updateToolBar() +{ + //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); + switch (getStatus()) + { case Neutral: // would switch back to main in edit / measure / .. modes //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); break; + case Moving: case MovingRef: RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); break; + default: break; } } -// EOF diff --git a/src/actions/rs_actiondefault.h b/src/actions/rs_actiondefault.h index 6c505ab..53e56ab 100644 --- a/src/actions/rs_actiondefault.h +++ b/src/actions/rs_actiondefault.h @@ -1,91 +1,64 @@ -/**************************************************************************** -** $Id: rs_actiondefault.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSELECTWINDOW_H #define RS_ACTIONSELECTWINDOW_H #include "rs_previewactioninterface.h" #include "vector.h" - /** * This action class can handle user events to select all entities. * * @author Andrew Mustun */ -class RS_ActionDefault : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - Neutral, /**< we don't know what we do yet. */ - Dragging, /**< dragging (either an entity or the - first part of a selection window) */ - SetCorner2, /**< Setting the 2nd corner of a selection window. */ - Moving, /**< Moving entities (drag'n'drop) */ - MovingRef /**< Moving a reference point of one or more selected - entities */ - }; +class RS_ActionDefault: public RS_PreviewActionInterface +{ + //Q_OBJECT + public: + /** + * Action States. + */ + enum Status { + Neutral, /**< we don't know what we do yet. */ + Dragging, /**< dragging (either an entity or the + first part of a selection window) */ + SetCorner2, /**< Setting the 2nd corner of a selection window. */ + Moving, /**< Moving entities (drag'n'drop) */ + MovingRef /**< Moving a reference point of one or more selected + entities */ + }; -public: - RS_ActionDefault(RS_EntityContainer& container, - RS_GraphicView& graphicView); - virtual ~RS_ActionDefault(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); + public: + RS_ActionDefault(RS_EntityContainer & container, RS_GraphicView & graphicView); + virtual ~RS_ActionDefault(); - virtual RS2::ActionType rtti() { - return RS2::ActionDefault; - } + static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); - virtual void init(int status=0); + virtual RS2::ActionType rtti() + { + return RS2::ActionDefault; + } - virtual void trigger(); + virtual void init(int status = 0); - virtual void keyPressEvent(QKeyEvent* e); - virtual void keyReleaseEvent(QKeyEvent* e); + virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mousePressEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); + virtual void keyPressEvent(QKeyEvent * e); + virtual void keyReleaseEvent(QKeyEvent * e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mousePressEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); -protected: - Vector v1; - Vector v2; - RS2::SnapRestriction restrBak; + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + protected: + Vector v1; + Vector v2; + RS2::SnapRestriction restrBak; }; #endif diff --git a/src/actions/rs_actiondimaligned.cpp b/src/actions/rs_actiondimaligned.cpp index 63ee67b..90401f4 100644 --- a/src/actions/rs_actiondimaligned.cpp +++ b/src/actions/rs_actiondimaligned.cpp @@ -1,317 +1,285 @@ -/**************************************************************************** -** $Id: rs_actiondimaligned.cpp 1134 2004-07-13 23:26:13Z 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_actiondimaligned.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/03/2010 Added this text. :-) +// #include "rs_actiondimaligned.h" -#include "rs_snapper.h" #include "rs_constructionline.h" #include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" +#include "rs_snapper.h" - - -RS_ActionDimAligned::RS_ActionDimAligned(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionDimension("Draw aligned dimensions", - container, graphicView) +RS_ActionDimAligned::RS_ActionDimAligned(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionDimension("Draw aligned dimensions", + container, graphicView) { - reset(); + reset(); } RS_ActionDimAligned::~RS_ActionDimAligned() { } -QAction * RS_ActionDimAligned::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +/*virtual*/ RS2::ActionType RS_ActionDimAligned::rtti() { - QAction * action = new QAction(tr("&Aligned"), 0); -// QAction* action = new QAction(tr("Aligned"), tr("&Aligned"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Aligned Dimension")); - - return action; + return RS2::ActionDimAligned; } - void RS_ActionDimAligned::reset() { - RS_ActionDimension::reset(); - edata = RS_DimAlignedData(Vector(false), Vector(false)); - lastStatus = SetExtPoint1; + RS_ActionDimension::reset(); + edata = RS_DimAlignedData(Vector(false), Vector(false)); + lastStatus = SetExtPoint1; if (RS_DIALOGFACTORY != NULL) - RS_DIALOGFACTORY->requestOptions(this, true, true); + RS_DIALOGFACTORY->requestOptions(this, true, true); } - - void RS_ActionDimAligned::trigger() { - RS_ActionDimension::trigger(); - - preparePreview(); - graphicView->moveRelativeZero(data.definitionPoint); + RS_ActionDimension::trigger(); + preparePreview(); + graphicView->moveRelativeZero(data.definitionPoint); //data.text = getText(); - RS_DimAligned* dim = - new RS_DimAligned(container, data, edata); - dim->setLayerToActive(); - dim->setPenToActive(); - dim->update(); - container->addEntity(dim); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(dim); - document->endUndoCycle(); - } - - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(dim); - graphicView->moveRelativeZero(rz); - drawSnapper(); - - RS_DEBUG->print("RS_ActionDimAligned::trigger():" - " dim added: %d", dim->getId()); + RS_DimAligned * dim = new RS_DimAligned(container, data, edata); + dim->setLayerToActive(); + dim->setPenToActive(); + dim->update(); + container->addEntity(dim); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(dim); + document->endUndoCycle(); + } + + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(dim); + graphicView->moveRelativeZero(rz); + drawSnapper(); + + RS_DEBUG->print("RS_ActionDimAligned::trigger(): dim added: %d", dim->getId()); } - - -void RS_ActionDimAligned::preparePreview() { - Vector dirV; - dirV.setPolar(100.0, - edata.extensionPoint1.angleTo( - edata.extensionPoint2) - +M_PI/2.0); - RS_ConstructionLine cl(NULL, - RS_ConstructionLineData( - edata.extensionPoint2, - edata.extensionPoint2+dirV)); - - data.definitionPoint = - cl.getNearestPointOnEntity(data.definitionPoint); +void RS_ActionDimAligned::preparePreview() +{ + Vector dirV; + dirV.setPolar(100.0, edata.extensionPoint1.angleTo(edata.extensionPoint2) + M_PI / 2.0); + RS_ConstructionLine cl(NULL, RS_ConstructionLineData(edata.extensionPoint2, + edata.extensionPoint2 + dirV)); + data.definitionPoint = cl.getNearestPointOnEntity(data.definitionPoint); } +void RS_ActionDimAligned::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDimAligned::mouseMoveEvent begin"); + Vector mouse = snapPoint(e); + switch (getStatus()) + { + case SetExtPoint1: + break; -void RS_ActionDimAligned::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDimAligned::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); + case SetExtPoint2: - switch (getStatus()) { - case SetExtPoint1: - break; + if (edata.extensionPoint1.valid) + { + deletePreview(); + clearPreview(); + preview->addEntity(new RS_Line(preview, + RS_LineData(edata.extensionPoint1, mouse))); + drawPreview(); + } + break; - case SetExtPoint2: - if (edata.extensionPoint1.valid) { - deletePreview(); - clearPreview(); - preview->addEntity( - new RS_Line(preview, - RS_LineData(edata.extensionPoint1, mouse)) - ); - drawPreview(); - } - break; + case SetDefPoint: - case SetDefPoint: - if (edata.extensionPoint1.valid && edata.extensionPoint2.valid) { - deletePreview(); - clearPreview(); - data.definitionPoint = mouse; + if (edata.extensionPoint1.valid && edata.extensionPoint2.valid) + { + deletePreview(); + clearPreview(); + data.definitionPoint = mouse; - preparePreview(); + preparePreview(); //data.text = getText(); - RS_DimAligned* dim = new RS_DimAligned(preview, data, edata); - dim->update(); - preview->addEntity(dim); - drawPreview(); - } - break; + RS_DimAligned * dim = new RS_DimAligned(preview, data, edata); + dim->update(); + preview->addEntity(dim); + drawPreview(); + } + break; default: break; - } + } - RS_DEBUG->print("RS_ActionDimAligned::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDimAligned::mouseMoveEvent end"); } - - -void RS_ActionDimAligned::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDimAligned::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } +void RS_ActionDimAligned::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + Vector pos = *e; //->getCoordinate(); -void RS_ActionDimAligned::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector pos = e->getCoordinate(); - - switch (getStatus()) { - case SetExtPoint1: - edata.extensionPoint1 = pos; - graphicView->moveRelativeZero(pos); - setStatus(SetExtPoint2); - break; + switch (getStatus()) + { + case SetExtPoint1: + edata.extensionPoint1 = pos; + graphicView->moveRelativeZero(pos); + setStatus(SetExtPoint2); + break; - case SetExtPoint2: - edata.extensionPoint2 = pos; - graphicView->moveRelativeZero(pos); - setStatus(SetDefPoint); - break; + case SetExtPoint2: + edata.extensionPoint2 = pos; + graphicView->moveRelativeZero(pos); + setStatus(SetDefPoint); + break; - case SetDefPoint: - data.definitionPoint = pos; - trigger(); - reset(); - setStatus(SetExtPoint1); - break; + case SetDefPoint: + data.definitionPoint = pos; + trigger(); + reset(); + setStatus(SetExtPoint1); + break; - default: - break; - } + default: + break; + } } +void RS_ActionDimAligned::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + if (checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); -void RS_ActionDimAligned::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 SetText: { - setText(c); - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - setStatus(lastStatus); - graphicView->enableCoordinateInput(); - } - break; - - default: - if (checkCommand("text", c)) { - lastStatus = (Status)getStatus(); - graphicView->disableCoordinateInput(); - setStatus(SetText); - } - break; - } -} - + return; + } + switch (getStatus()) + { + case SetText: + setText(c); -QStringList RS_ActionDimAligned::getAvailableCommands() { - QStringList cmd; + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); - switch (getStatus()) { - case SetExtPoint1: - case SetExtPoint2: - case SetDefPoint: - cmd += command("text"); - break; + setStatus(lastStatus); + graphicView->enableCoordinateInput(); + break; - default: - break; - } + default: - return cmd; + if (checkCommand("text", c)) + { + lastStatus = (Status)getStatus(); + graphicView->disableCoordinateInput(); + setStatus(SetText); + } + break; + } } +QStringList RS_ActionDimAligned::getAvailableCommands() +{ + QStringList cmd; + + switch (getStatus()) + { + case SetExtPoint1: + case SetExtPoint2: + case SetDefPoint: + cmd += command("text"); + break; + default: + break; + } -void RS_ActionDimAligned::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetExtPoint1: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify first extension line origin"), - tr("Cancel")); - break; - case SetExtPoint2: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify second extension line origin"), - tr("Back")); - break; - case SetDefPoint: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify dimension line location"), - tr("Back")); - break; - case SetText: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } + return cmd; } - - -void RS_ActionDimAligned::hideOptions() { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } - - RS_ActionDimension::hideOptions(); +void RS_ActionDimAligned::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetExtPoint1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first extension line origin"), tr("Cancel")); + break; + + case SetExtPoint2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second extension line origin"), tr("Back")); + break; + + case SetDefPoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify dimension line location"), tr("Back")); + break; + + case SetText: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } +void RS_ActionDimAligned::hideOptions() +{ + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); + RS_ActionDimension::hideOptions(); +} -void RS_ActionDimAligned::showOptions() { - RS_ActionDimension::showOptions(); +void RS_ActionDimAligned::showOptions() +{ + RS_ActionDimension::showOptions(); - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); } - -// EOF diff --git a/src/actions/rs_actiondimaligned.h b/src/actions/rs_actiondimaligned.h index 4936143..8e6b958 100644 --- a/src/actions/rs_actiondimaligned.h +++ b/src/actions/rs_actiondimaligned.h @@ -1,29 +1,3 @@ -/**************************************************************************** -** $Id: rs_actiondimaligned.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDIMALIGNED_H #define RS_ACTIONDIMALIGNED_H @@ -31,61 +5,49 @@ #include "rs_dimaligned.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * aligned dimensions. * * @author Andrew Mustun */ -class RS_ActionDimAligned : public RS_ActionDimension { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetExtPoint1, /**< Setting the 1st ext point. */ - SetExtPoint2, /**< Setting the 2nd ext point. */ - SetDefPoint, /**< Setting the common def point */ - SetText /**< Setting the text label in command line */ - }; - -public: - RS_ActionDimAligned(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDimAligned(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDimAligned; - } - - virtual void reset(); - - virtual void trigger(); - void preparePreview(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - -protected: - /** - * Aligned dimension data. - */ - RS_DimAlignedData edata; - - /** Last status before entering text. */ - Status lastStatus; -} -; +class RS_ActionDimAligned: public RS_ActionDimension +{ + public: + /** + * Action States. + */ + enum Status { + SetExtPoint1, /**< Setting the 1st ext point. */ + SetExtPoint2, /**< Setting the 2nd ext point. */ + SetDefPoint, /**< Setting the common def point */ + SetText /**< Setting the text label in command line */ + }; + + public: + RS_ActionDimAligned(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDimAligned(); + + virtual RS2::ActionType rtti(); + virtual void reset(); + virtual void trigger(); + void preparePreview(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + + protected: + /** + * Aligned dimension data. + */ + RS_DimAlignedData edata; + + /** Last status before entering text. */ + Status lastStatus; +}; #endif diff --git a/src/actions/rs_actiondimangular.cpp b/src/actions/rs_actiondimangular.cpp index 57c16b4..31bb89e 100644 --- a/src/actions/rs_actiondimangular.cpp +++ b/src/actions/rs_actiondimangular.cpp @@ -1,316 +1,310 @@ -/**************************************************************************** -** $Id: rs_actiondimangular.cpp 1134 2004-07-13 23:26:13Z 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_actiondimangular.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/03/2010 Added this text. :-) +// #include "rs_actiondimangular.h" -#include "rs_creation.h" -#include "rs_information.h" -#include "rs_snapper.h" #include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_information.h" +#include "rs_preview.h" - - -RS_ActionDimAngular::RS_ActionDimAngular( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionDimension("Draw Angular Dimensions", - container, graphicView) { - reset(); +RS_ActionDimAngular::RS_ActionDimAngular(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionDimension("Draw Angular Dimensions", + container, graphicView) +{ + reset(); } -QAction * RS_ActionDimAngular::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDimAngular::~RS_ActionDimAngular() { - QAction * action = new QAction(tr("&Angular"), 0); -// QAction* action = new QAction(tr("Angular"), tr("&Angular"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Angular Dimension")); - - return action; } - -void RS_ActionDimAngular::reset() { - RS_ActionDimension::reset(); - - edata = RS_DimAngularData(Vector(false), - Vector(false), - Vector(false), - Vector(false)); - line1 = NULL; - line2 = NULL; - center = Vector(false); - RS_DIALOGFACTORY->requestOptions(this, true, true); +/*virtual*/ RS2::ActionType RS_ActionDimAngular::rtti() +{ + return RS2::ActionDimAngular; } - - -void RS_ActionDimAngular::trigger() { - RS_PreviewActionInterface::trigger(); - - if (line1!=NULL && line2!=NULL) { - RS_DimAngular* newEntity = NULL; - - newEntity = new RS_DimAngular(container, - data, - edata); - - newEntity->setLayerToActive(); - newEntity->setPenToActive(); - newEntity->update(); - container->addEntity(newEntity); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(newEntity); - document->endUndoCycle(); - } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(newEntity); - graphicView->moveRelativeZero(rz); - - } else { - RS_DEBUG->print("RS_ActionDimAngular::trigger:" - " Entity is NULL\n"); - } +void RS_ActionDimAngular::reset() +{ + RS_ActionDimension::reset(); + edata = RS_DimAngularData(Vector(false), Vector(false), Vector(false), Vector(false)); + line1 = NULL; + line2 = NULL; + center = Vector(false); + RS_DIALOGFACTORY->requestOptions(this, true, true); } +void RS_ActionDimAngular::trigger() +{ + RS_PreviewActionInterface::trigger(); + + if (line1 != NULL && line2 != NULL) + { + RS_DimAngular * newEntity = NULL; + + newEntity = new RS_DimAngular(container, + data, + edata); + + newEntity->setLayerToActive(); + newEntity->setPenToActive(); + newEntity->update(); + container->addEntity(newEntity); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(newEntity); + document->endUndoCycle(); + } + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(newEntity); + graphicView->moveRelativeZero(rz); + } + else + RS_DEBUG->print("RS_ActionDimAngular::trigger:" + " Entity is NULL\n"); +} +void RS_ActionDimAngular::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent begin"); -void RS_ActionDimAngular::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent begin"); + Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); - Vector mouse(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); + switch (getStatus()) + { + case SetLine1: + break; - switch (getStatus()) { - case SetLine1: - break; + case SetLine2: + break; - case SetLine2: - break; + case SetPos: - case SetPos: - if (line1!=NULL && line2!=NULL && center.valid) { - Vector mouse = snapPoint(e); - edata.definitionPoint4 = mouse; + if (line1 != NULL && line2 != NULL && center.valid) + { + Vector mouse = snapPoint(e); + edata.definitionPoint4 = mouse; - RS_DimAngular* d = new RS_DimAngular(preview, data, edata); - d->update(); + RS_DimAngular * d = new RS_DimAngular(preview, data, edata); + d->update(); - deletePreview(); - clearPreview(); - preview->addEntity(d); - drawPreview(); - } - break; + deletePreview(); + clearPreview(); + preview->addEntity(d); + drawPreview(); + } + break; - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDimAngular::mouseMoveEvent end"); } - - -void RS_ActionDimAngular::mouseReleaseEvent(QMouseEvent* e) { - - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetLine1: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && - en->rtti()==RS2::EntityLine) { - line1 = (RS_Line*)en; - setStatus(SetLine2); - } - } - break; - - case SetLine2: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && - en->rtti()==RS2::EntityLine) { - line2 = (RS_Line*)en; - - VectorSolutions sol = - RS_Information::getIntersectionLineLine(line1, line2); - - if (sol.get(0).valid) { - center = sol.get(0); - - if (center.distanceTo(line1->getStartpoint()) < - center.distanceTo(line1->getEndpoint())) { - edata.definitionPoint1 = line1->getStartpoint(); - edata.definitionPoint2 = line1->getEndpoint(); - } else { - edata.definitionPoint1 = line1->getEndpoint(); - edata.definitionPoint2 = line1->getStartpoint(); - } - - if (center.distanceTo(line2->getStartpoint()) < - center.distanceTo(line2->getEndpoint())) { - edata.definitionPoint3 = line2->getStartpoint(); - data.definitionPoint = line2->getEndpoint(); - } else { - edata.definitionPoint3 = line2->getEndpoint(); - data.definitionPoint = line2->getStartpoint(); - } - graphicView->moveRelativeZero(center); - setStatus(SetPos); - } - } - } - break; - - case SetPos: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - clearPreview(); - init(getStatus()-1); - } - +void RS_ActionDimAngular::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case SetLine1: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL + && en->rtti() == RS2::EntityLine) + { + line1 = (RS_Line *)en; + setStatus(SetLine2); + } + } + break; + + case SetLine2: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL + && en->rtti() == RS2::EntityLine) + { + line2 = (RS_Line *)en; + + VectorSolutions sol = + RS_Information::getIntersectionLineLine(line1, line2); + + if (sol.get(0).valid) + { + center = sol.get(0); + + if (center.distanceTo(line1->getStartpoint()) + < center.distanceTo(line1->getEndpoint())) + { + edata.definitionPoint1 = line1->getStartpoint(); + edata.definitionPoint2 = line1->getEndpoint(); + } + else + { + edata.definitionPoint1 = line1->getEndpoint(); + edata.definitionPoint2 = line1->getStartpoint(); + } + + if (center.distanceTo(line2->getStartpoint()) + < center.distanceTo(line2->getEndpoint())) + { + edata.definitionPoint3 = line2->getStartpoint(); + data.definitionPoint = line2->getEndpoint(); + } + else + { + edata.definitionPoint3 = line2->getEndpoint(); + data.definitionPoint = line2->getStartpoint(); + } + graphicView->moveRelativeZero(center); + setStatus(SetPos); + } + } + } + break; + + case SetPos: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + clearPreview(); + init(getStatus() - 1); + } } - - -void RS_ActionDimAngular::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - switch (getStatus()) { - case SetPos: - edata.definitionPoint4 = e->getCoordinate(); - trigger(); - reset(); - setStatus(SetLine1); - break; - - default: - break; - } +void RS_ActionDimAngular::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + switch (getStatus()) + { + case SetPos: + edata.definitionPoint4 = *e; + trigger(); + reset(); + setStatus(SetLine1); + break; + + default: + break; + } } - -void RS_ActionDimAngular::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - // setting new text label: - if (getStatus()==SetText) { - setText(c); - RS_DIALOGFACTORY->requestOptions(this, true, true); - graphicView->enableCoordinateInput(); - setStatus(lastStatus); - return; - } - - // command: text - if (checkCommand("text", c)) { - lastStatus = (Status)getStatus(); - graphicView->disableCoordinateInput(); - setStatus(SetText); - } +void RS_ActionDimAngular::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + // setting new text label: + if (getStatus() == SetText) + { + setText(c); + RS_DIALOGFACTORY->requestOptions(this, true, true); + graphicView->enableCoordinateInput(); + setStatus(lastStatus); + return; + } + + // command: text + if (checkCommand("text", c)) + { + lastStatus = (Status)getStatus(); + graphicView->disableCoordinateInput(); + setStatus(SetText); + } } +QStringList RS_ActionDimAngular::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetLine1: + case SetLine2: + case SetPos: + cmd += command("text"); + break; -QStringList RS_ActionDimAngular::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetLine1: - case SetLine2: - case SetPos: - cmd += command("text"); - break; - - default: - break; - } + default: + break; + } - return cmd; + return cmd; } +void RS_ActionDimAngular::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDimAngular::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDimAngular::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDimAngular::hideOptions() { - RS_ActionInterface::hideOptions(); - - RS_DIALOGFACTORY->requestOptions(this, false); + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionDimAngular::updateMouseButtonHints() { - switch (getStatus()) { - case SetLine1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"), - tr("Cancel")); - break; - case SetLine2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"), - tr("Cancel")); - break; - case SetPos: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify dimension arc line location"), tr("Cancel")); - break; - case SetText: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDimAngular::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetLine1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"), + tr("Cancel")); + break; + + case SetLine2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"), + tr("Cancel")); + break; + + case SetPos: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify dimension arc line location"), tr("Cancel")); + break; + + case SetText: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - // EOF diff --git a/src/actions/rs_actiondimangular.h b/src/actions/rs_actiondimangular.h index b558254..a8e9a52 100644 --- a/src/actions/rs_actiondimangular.h +++ b/src/actions/rs_actiondimangular.h @@ -1,89 +1,54 @@ -/**************************************************************************** -** $Id: rs_actiondimangular.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDIMANGULAR_H #define RS_ACTIONDIMANGULAR_H #include "rs_actiondimension.h" #include "rs_dimangular.h" +#include "vector.h" +class RS_Line; /** * This action class can handle user events to draw angular dimensions. * * @author Andrew Mustun */ -class RS_ActionDimAngular : public RS_ActionDimension { - //Q_OBJECT -private: - enum Status { - SetLine1, /**< Choose 1st line. */ - SetLine2, /**< Choose 2nd line. */ - SetPos, /**< Choose position. */ - SetText /**< Setting text label in consle. */ - }; - -public: - RS_ActionDimAngular(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDimAngular() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDimAngular; - } - - virtual void reset(); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - -private: - /** 1st chosen line */ - RS_Line* line1; - /** 2nd chosen line */ - RS_Line* line2; - /** Center of arc */ - Vector center; - /** Data of new dimension */ - RS_DimAngularData edata; - /** Last status before entering text. */ - Status lastStatus; +class RS_ActionDimAngular: public RS_ActionDimension +{ + private: + enum Status { + SetLine1, /**< Choose 1st line. */ + SetLine2, /**< Choose 2nd line. */ + SetPos, /**< Choose position. */ + SetText /**< Setting text label in consle. */ + }; + + public: + RS_ActionDimAngular(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDimAngular(); + + virtual RS2::ActionType rtti(); + virtual void reset(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + + private: + /** 1st chosen line */ + RS_Line * line1; + /** 2nd chosen line */ + RS_Line * line2; + /** Center of arc */ + Vector center; + /** Data of new dimension */ + RS_DimAngularData edata; + /** Last status before entering text. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actiondimdiametric.cpp b/src/actions/rs_actiondimdiametric.cpp index 18b7aa5..07bfa2b 100644 --- a/src/actions/rs_actiondimdiametric.cpp +++ b/src/actions/rs_actiondimdiametric.cpp @@ -1,334 +1,322 @@ -/**************************************************************************** -** $Id: rs_actiondimdiametric.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_actiondimdiametric.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/03/2010 Added this text. :-) +// #include "rs_actiondimdiametric.h" -#include "rs_creation.h" -#include "rs_snapper.h" +#include "rs_graphicview.h" #include "rs_dialogfactory.h" +#include "rs_preview.h" - - -RS_ActionDimDiametric::RS_ActionDimDiametric( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionDimension("Draw Diametric Dimensions", - container, graphicView) +RS_ActionDimDiametric::RS_ActionDimDiametric(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionDimension("Draw Diametric Dimensions", + container, graphicView) { reset(); } - -QAction * RS_ActionDimDiametric::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionDimDiametric::~RS_ActionDimDiametric() { - QAction * action = new QAction(tr("&Diametric"), 0); -// QAction* action = new QAction(tr("Diametric"), tr("&Diametric"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Diametric Dimension")); +} - return action; +/*virtual*/ RS2::ActionType RS_ActionDimDiametric::rtti() +{ + return RS2::ActionDimDiametric; } void RS_ActionDimDiametric::reset() { - RS_ActionDimension::reset(); - - edata = RS_DimDiametricData(Vector(false), - 0.0); - entity = NULL; - pos = Vector(false); - RS_DIALOGFACTORY->requestOptions(this, true, true); + RS_ActionDimension::reset(); + edata = RS_DimDiametricData(Vector(false), 0.0); + entity = NULL; + pos = Vector(false); + RS_DIALOGFACTORY->requestOptions(this, true, true); } - - void RS_ActionDimDiametric::trigger() { - RS_PreviewActionInterface::trigger(); - - preparePreview(); - if (entity!=NULL) { - RS_DimDiametric* newEntity = NULL; - - newEntity = new RS_DimDiametric(container, - data, - edata); - - newEntity->setLayerToActive(); - newEntity->setPenToActive(); - newEntity->update(); - container->addEntity(newEntity); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(newEntity); - document->endUndoCycle(); - } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(newEntity); - graphicView->moveRelativeZero(rz); - - } else { - RS_DEBUG->print("RS_ActionDimDiametric::trigger:" - " Entity is NULL\n"); - } + RS_PreviewActionInterface::trigger(); + + preparePreview(); + + if (entity != NULL) + { + RS_DimDiametric * newEntity = NULL; + + newEntity = new RS_DimDiametric(container, + data, + edata); + + newEntity->setLayerToActive(); + newEntity->setPenToActive(); + newEntity->update(); + container->addEntity(newEntity); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(newEntity); + document->endUndoCycle(); + } + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(newEntity); + graphicView->moveRelativeZero(rz); + } + else + RS_DEBUG->print("RS_ActionDimDiametric::trigger:" + " Entity is NULL\n"); } - - void RS_ActionDimDiametric::preparePreview() { - if (entity!=NULL) { - double radius=0.0; - Vector center = Vector(false); - if (entity->rtti()==RS2::EntityArc) { - radius = ((RS_Arc*)entity)->getRadius(); - center = ((RS_Arc*)entity)->getCenter(); - } else if (entity->rtti()==RS2::EntityCircle) { - radius = ((RS_Circle*)entity)->getRadius(); - center = ((RS_Circle*)entity)->getCenter(); - } - double angle = center.angleTo(pos); - - data.definitionPoint.setPolar(radius, angle+M_PI); - data.definitionPoint += center; - - edata.definitionPoint.setPolar(radius, angle); - edata.definitionPoint += center; - } + if (entity != NULL) + { + double radius = 0.0; + Vector center = Vector(false); + + if (entity->rtti() == RS2::EntityArc) + { + radius = ((RS_Arc *)entity)->getRadius(); + center = ((RS_Arc *)entity)->getCenter(); + } + else if (entity->rtti() == RS2::EntityCircle) + { + radius = ((RS_Circle *)entity)->getRadius(); + center = ((RS_Circle *)entity)->getCenter(); + } + double angle = center.angleTo(pos); + + data.definitionPoint.setPolar(radius, angle + M_PI); + data.definitionPoint += center; + + edata.definitionPoint.setPolar(radius, angle); + edata.definitionPoint += center; + } } - - -void RS_ActionDimDiametric::mouseMoveEvent(QMouseEvent* e) +void RS_ActionDimDiametric::mouseMoveEvent(QMouseEvent * e) { - RS_DEBUG->print("RS_ActionDimDiametric::mouseMoveEvent begin"); + RS_DEBUG->print("RS_ActionDimDiametric::mouseMoveEvent begin"); - Vector mouse(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); + Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); - switch (getStatus()) { - case SetEntity: - entity = catchEntity(e, RS2::ResolveAll); - break; + switch (getStatus()) + { + case SetEntity: + entity = catchEntity(e, RS2::ResolveAll); + break; - case SetPos: - if (entity!=NULL) { - pos = snapPoint(e); + case SetPos: - preparePreview(); - RS_DimDiametric* d = new RS_DimDiametric(preview, data, edata); - d->update(); + if (entity != NULL) + { + pos = snapPoint(e); - deletePreview(); - clearPreview(); - preview->addEntity(d); - drawPreview(); - } - break; + preparePreview(); + RS_DimDiametric * d = new RS_DimDiametric(preview, data, edata); + d->update(); - default: - break; - } - - RS_DEBUG->print("RS_ActionDimDiametric::mouseMoveEvent end"); -} + deletePreview(); + clearPreview(); + preview->addEntity(d); + drawPreview(); + } + break; + default: + break; + } + RS_DEBUG->print("RS_ActionDimDiametric::mouseMoveEvent end"); +} -void RS_ActionDimDiametric::mouseReleaseEvent(QMouseEvent* e) +void RS_ActionDimDiametric::mouseReleaseEvent(QMouseEvent * e) { - - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetEntity: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL) { - if (en->rtti()==RS2::EntityArc || - en->rtti()==RS2::EntityCircle) { - - entity = en; - Vector center; - if (entity->rtti()==RS2::EntityArc) { - center = - ((RS_Arc*)entity)->getCenter(); - } else if (entity->rtti()==RS2::EntityCircle) { - center = - ((RS_Circle*)entity)->getCenter(); - } - graphicView->moveRelativeZero(center); - setStatus(SetPos); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a circle " - "or arc entity")); - } - } - } - break; - - case SetPos: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - clearPreview(); - init(getStatus()-1); - } - + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case SetEntity: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL) + { + if (en->rtti() == RS2::EntityArc + || en->rtti() == RS2::EntityCircle) + { + entity = en; + Vector center; + + if (entity->rtti() == RS2::EntityArc) + center = + ((RS_Arc *)entity)->getCenter(); + else if (entity->rtti() == RS2::EntityCircle) + center = + ((RS_Circle *)entity)->getCenter(); + graphicView->moveRelativeZero(center); + setStatus(SetPos); + } + else + RS_DIALOGFACTORY->commandMessage(tr("Not a circle " + "or arc entity")); + } + } + break; + + case SetPos: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + clearPreview(); + init(getStatus() - 1); + } } - -void RS_ActionDimDiametric::coordinateEvent(RS_CoordinateEvent* e) +void RS_ActionDimDiametric::coordinateEvent(Vector * e) { - if (e==NULL) { - return; - } - - switch (getStatus()) { - case SetPos: - pos = e->getCoordinate(); - trigger(); - reset(); - setStatus(SetEntity); - break; - - default: - break; - } + if (e == NULL) + return; + + switch (getStatus()) + { + case SetPos: + pos = *e; + trigger(); + reset(); + setStatus(SetEntity); + break; + + default: + break; + } } - -void RS_ActionDimDiametric::commandEvent(RS_CommandEvent* e) +void RS_ActionDimDiametric::commandEvent(RS_CommandEvent * e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - // setting new text label: - if (getStatus()==SetText) { - setText(c); - RS_DIALOGFACTORY->requestOptions(this, true, true); - graphicView->enableCoordinateInput(); - setStatus(lastStatus); - return; - } - - // command: text - if (checkCommand("text", c)) { - lastStatus = (Status)getStatus(); - graphicView->disableCoordinateInput(); - setStatus(SetText); - } - - // setting angle - if (getStatus()==SetPos) { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - pos.setPolar(1.0, RS_Math::deg2rad(a)); - pos += data.definitionPoint; - trigger(); - reset(); - setStatus(SetEntity); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - return; - } + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + // setting new text label: + if (getStatus() == SetText) + { + setText(c); + RS_DIALOGFACTORY->requestOptions(this, true, true); + graphicView->enableCoordinateInput(); + setStatus(lastStatus); + return; + } + + // command: text + if (checkCommand("text", c)) + { + lastStatus = (Status)getStatus(); + graphicView->disableCoordinateInput(); + setStatus(SetText); + } + + // setting angle + if (getStatus() == SetPos) + { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + { + pos.setPolar(1.0, RS_Math::deg2rad(a)); + pos += data.definitionPoint; + trigger(); + reset(); + setStatus(SetEntity); + } + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + return; + } } +QStringList RS_ActionDimDiametric::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetEntity: + case SetPos: + cmd += command("text"); + break; -QStringList RS_ActionDimDiametric::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetEntity: - case SetPos: - cmd += command("text"); - break; - - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - -void RS_ActionDimDiametric::updateMouseButtonHints() { - switch (getStatus()) { - case SetEntity: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"), - tr("Cancel")); - break; - case SetPos: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify dimension line location"), tr("Cancel")); - break; - case SetText: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDimDiametric::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetEntity: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"), + tr("Cancel")); + break; + + case SetPos: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify dimension line location"), tr("Cancel")); + break; + + case SetText: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } +void RS_ActionDimDiametric::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDimDiametric::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDimDiametric::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDimDiametric::hideOptions() { - RS_ActionInterface::hideOptions(); - - //RS_DIALOGFACTORY->requestDimDiametricOptions(edata, false); - RS_DIALOGFACTORY->requestOptions(this, false); + //RS_DIALOGFACTORY->requestDimDiametricOptions(edata, false); + RS_DIALOGFACTORY->requestOptions(this, false); } - - // EOF diff --git a/src/actions/rs_actiondimdiametric.h b/src/actions/rs_actiondimdiametric.h index 00e9ded..1515b02 100644 --- a/src/actions/rs_actiondimdiametric.h +++ b/src/actions/rs_actiondimdiametric.h @@ -1,87 +1,52 @@ -/**************************************************************************** -** $Id: rs_actiondimdiametric.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDIMDIAMETRIC_H #define RS_ACTIONDIMDIAMETRIC_H #include "rs_actiondimension.h" #include "rs_dimdiametric.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to draw diametric dimensions. * * @author Andrew Mustun */ -class RS_ActionDimDiametric : public RS_ActionDimension { - //Q_OBJECT -private: - enum Status { - SetEntity, /**< Choose entity. */ - SetPos, /**< Choose point. */ - SetText /**< Setting text label in the command line. */ - }; - -public: - RS_ActionDimDiametric(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDimDiametric() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDimDiametric; - } - - virtual void reset(); - - virtual void trigger(); - void preparePreview(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - -private: - /** Chosen entity (arc / circle) */ - RS_Entity* entity; - /** Chosen position */ - Vector pos; - /** Data of new dimension */ - RS_DimDiametricData edata; - /** Last status before entering text. */ - Status lastStatus; +class RS_ActionDimDiametric: public RS_ActionDimension +{ + private: + enum Status { + SetEntity, /**< Choose entity. */ + SetPos, /**< Choose point. */ + SetText /**< Setting text label in the command line. */ + }; + + public: + RS_ActionDimDiametric(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDimDiametric(); + + virtual RS2::ActionType rtti(); + virtual void reset(); + virtual void trigger(); + void preparePreview(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + + private: + /** Chosen entity (arc / circle) */ + RS_Entity * entity; + /** Chosen position */ + Vector pos; + /** Data of new dimension */ + RS_DimDiametricData edata; + /** Last status before entering text. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actiondimension.cpp b/src/actions/rs_actiondimension.cpp index cbedac1..89af7a5 100644 --- a/src/actions/rs_actiondimension.cpp +++ b/src/actions/rs_actiondimension.cpp @@ -1,40 +1,26 @@ -/**************************************************************************** -** $Id: rs_actiondimension.cpp 1141 2004-07-29 20:32:39Z 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. -** -**********************************************************************/ - -#include "rs_actiondimaligned.h" - -#include "rs_snapper.h" -#include "rs_constructionline.h" +// rs_actiondimension.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/03/2010 Added this text. :-) +// + +#include "rs_actiondimension.h" + #include "rs_dialogfactory.h" +#include "rs_graphicview.h" -RS_ActionDimension::RS_ActionDimension(const char * name, - RS_EntityContainer & container, RS_GraphicView & graphicView): +RS_ActionDimension::RS_ActionDimension(const char * name, RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface(name, container, graphicView) { - reset(); + reset(); } RS_ActionDimension::~RS_ActionDimension() @@ -43,22 +29,14 @@ RS_ActionDimension::~RS_ActionDimension() void RS_ActionDimension::reset() { - data = RS_DimensionData(Vector(false), - Vector(false), - RS2::VAlignMiddle, - RS2::HAlignCenter, - RS2::Exact, - 1.0, - "", - "Standard", - 0.0); + data = RS_DimensionData(Vector(false), Vector(false), RS2::VAlignMiddle, + RS2::HAlignCenter, RS2::Exact, 1.0, "", "Standard", 0.0); diameter = false; } void RS_ActionDimension::init(int status) { RS_PreviewActionInterface::init(status); - //reset(); } void RS_ActionDimension::hideOptions() @@ -66,9 +44,7 @@ void RS_ActionDimension::hideOptions() RS_ActionInterface::hideOptions(); if (RS_DIALOGFACTORY != NULL) - { RS_DIALOGFACTORY->requestOptions(this, false); - } } void RS_ActionDimension::showOptions() @@ -76,9 +52,7 @@ void RS_ActionDimension::showOptions() RS_ActionInterface::showOptions(); if (RS_DIALOGFACTORY != NULL) - { RS_DIALOGFACTORY->requestOptions(this, true, true); - } } void RS_ActionDimension::updateMouseCursor() @@ -88,17 +62,85 @@ void RS_ActionDimension::updateMouseCursor() void RS_ActionDimension::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) + if (RS_DIALOGFACTORY != NULL) { if (!isFinished()) - { RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else - { RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim); - } } } -// EOF +QString RS_ActionDimension::getText() +{ + if (!data.text.isEmpty()) + return data.text; + + QString l = label; + + if (l.isEmpty() && (diameter || !tol1.isEmpty() || !tol2.isEmpty())) + l = "<>"; + + if (diameter) + l = QChar(0x2205) + l; + + if (!tol1.isEmpty() || !tol2.isEmpty()) + l += QString("\\S%1\\%2;").arg(tol1).arg(tol2); + + return l; +} + +void RS_ActionDimension::setText(const QString & t) +{ + data.text = t; +} + +QString RS_ActionDimension::getLabel() +{ + return label; +} + +void RS_ActionDimension::setLabel(const QString & t) +{ + label = t; +} + +QString RS_ActionDimension::getTol1() +{ + return tol1; +} + +void RS_ActionDimension::setTol1(const QString & t) +{ + tol1 = t; +} + +QString RS_ActionDimension::getTol2() +{ + return tol2; +} + +void RS_ActionDimension::setTol2(const QString & t) +{ + tol2 = t; +} + +bool RS_ActionDimension::getDiameter() +{ + return diameter; +} + +void RS_ActionDimension::setDiameter(bool d) +{ + diameter = d; +} + +/*static*/ bool RS_ActionDimension::isDimensionAction(RS2::ActionType type) +{ + return (type == RS2::ActionDimAligned + || type == RS2::ActionDimLinear + || type == RS2::ActionDimAngular + || type == RS2::ActionDimDiametric + || type == RS2::ActionDimRadial); +} + diff --git a/src/actions/rs_actiondimension.h b/src/actions/rs_actiondimension.h index f207d86..1c4735b 100644 --- a/src/actions/rs_actiondimension.h +++ b/src/actions/rs_actiondimension.h @@ -1,138 +1,49 @@ -/**************************************************************************** -** $Id: rs_actiondimension.h 1119 2004-04-12 22:44:04Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDIMENSION_H #define RS_ACTIONDIMENSION_H -#include "rs_previewactioninterface.h" +#include #include "rs_dimension.h" +#include "rs_previewactioninterface.h" /** * Base class for dimension actions. * * @author Andrew Mustun */ -class RS_ActionDimension : public RS_PreviewActionInterface { - //Q_OBJECT -public: - RS_ActionDimension(const char* name, - RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDimension(); - - virtual void reset(); - - virtual void init(int status=0); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - QString getText() { - if (!data.text.isEmpty()) { - return data.text; - } - - QString l = label; - - if (l.isEmpty() && - (diameter==true || !tol1.isEmpty() || !tol2.isEmpty())) { - l = "<>"; - } - - if (diameter==true) { - l = QChar(0x2205) + l; - } - - if (!tol1.isEmpty() || !tol2.isEmpty()) { - l += QString("\\S%1\\%2;").arg(tol1).arg(tol2); - } - - return l; - } - - void setText(const QString& t) { - data.text = t; - } - - QString getLabel() { - return label; - } - void setLabel(const QString& t) { - //data.text = t; - label = t; - } - QString getTol1() { - return tol1; - } - void setTol1(const QString& t) { - tol1 = t; - } - QString getTol2() { - return tol2; - } - void setTol2(const QString& t) { - tol2 = t; - } - bool getDiameter() { - return diameter; - } - void setDiameter(bool d) { - diameter = d; - } - - static bool isDimensionAction(RS2::ActionType type) { - return (type==RS2::ActionDimAligned || - type==RS2::ActionDimLinear || - type==RS2::ActionDimAngular || - type==RS2::ActionDimDiametric || - type==RS2::ActionDimRadial); - } - -protected: - /** - * Generic dimension data. - */ - RS_DimensionData data; - - QString label; - QString tol1; - QString tol2; - bool diameter; - - - /** - * Commands. - */ - /* - QString cmdText; - QString cmdText2; - */ +class RS_ActionDimension: public RS_PreviewActionInterface +{ + public: + RS_ActionDimension(const char * name, RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDimension(); + + virtual void reset(); + virtual void init(int status = 0); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + QString getText(); + void setText(const QString & t); + QString getLabel(); + void setLabel(const QString & t); + QString getTol1(); + void setTol1(const QString & t); + QString getTol2(); + void setTol2(const QString & t); + bool getDiameter(); + void setDiameter(bool d); + static bool isDimensionAction(RS2::ActionType type); + + protected: + /** + * Generic dimension data. + */ + RS_DimensionData data; + + QString label; + QString tol1; + QString tol2; + bool diameter; }; #endif diff --git a/src/actions/rs_actiondimleader.cpp b/src/actions/rs_actiondimleader.cpp index d1793d1..c1d2aa9 100644 --- a/src/actions/rs_actiondimleader.cpp +++ b/src/actions/rs_actiondimleader.cpp @@ -1,35 +1,24 @@ -/**************************************************************************** -** $Id: rs_actiondimleader.cpp 1134 2004-07-13 23:26:13Z 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_actiondimleader.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/03/2010 Added this text. :-) +// #include "rs_actiondimleader.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -RS_ActionDimLeader::RS_ActionDimLeader(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionDimLeader::RS_ActionDimLeader(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw leaders", container, graphicView) { reset(); @@ -44,16 +33,6 @@ RS_ActionDimLeader::~RS_ActionDimLeader() return RS2::ActionDimLeader; } -QAction * RS_ActionDimLeader::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) -{ - QAction * action = new QAction(tr("&Leader"), 0); -// QAction* action = new QAction(tr("Leader"), tr("&Leader"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Leader Dimension")); - - return action; -} - void RS_ActionDimLeader::reset() { //data = RS_LineData(Vector(false), Vector(false)); @@ -81,7 +60,7 @@ void RS_ActionDimLeader::trigger() // for(Vector * v=points.first(); v!=NULL; v=points.next()) // leader->addVertex(*v); - for(int i=0; iaddVertex(*(points[i])); container->addEntity(leader); @@ -113,7 +92,7 @@ void RS_ActionDimLeader::mouseMoveEvent(QMouseEvent * e) Vector mouse = snapPoint(e); - if (getStatus()==SetEndpoint && points.last()!=NULL) + if (getStatus() == SetEndpoint && points.last() != NULL) { deletePreview(); clearPreview(); @@ -122,7 +101,7 @@ void RS_ActionDimLeader::mouseMoveEvent(QMouseEvent * e) Vector last(false); // for(Vector * v=points.first(); v!=NULL; v=points.next()) - for(int i=0; ibutton()) == RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) @@ -174,12 +153,12 @@ void RS_ActionDimLeader::keyPressEvent(QKeyEvent * e) } } -void RS_ActionDimLeader::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionDimLeader::coordinateEvent(Vector * e) { if (e == NULL) return; - Vector mouse = e->getCoordinate(); + Vector mouse = *e; switch (getStatus()) { @@ -212,10 +191,8 @@ void RS_ActionDimLeader::commandEvent(RS_CommandEvent * e) if (checkCommand("help", c)) { if (RS_DIALOGFACTORY != NULL) - { RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", ")); - } return; } @@ -246,9 +223,11 @@ void RS_ActionDimLeader::updateMouseButtonHints() case SetStartpoint: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Cancel")); break; + case SetEndpoint: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Finish")); break; + default: RS_DIALOGFACTORY->updateMouseWidget("", ""); break; @@ -285,3 +264,4 @@ void RS_ActionDimLeader::updateToolBar() RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarDim); } } + diff --git a/src/actions/rs_actiondimleader.h b/src/actions/rs_actiondimleader.h index 3bf5750..545bff6 100644 --- a/src/actions/rs_actiondimleader.h +++ b/src/actions/rs_actiondimleader.h @@ -1,34 +1,11 @@ -/**************************************************************************** -** $Id: rs_actiondimleader.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDIMLEADER_H #define RS_ACTIONDIMLEADER_H -#include "rs_previewactioninterface.h" +#include #include "rs_leader.h" +#include "rs_previewactioninterface.h" + +class Vector; /** * This action class can handle user events to draw @@ -38,11 +15,10 @@ */ class RS_ActionDimLeader: public RS_PreviewActionInterface { -//hm //Q_OBJECT public: /** - * Action States. - */ + * Action States. + */ enum Status { SetStartpoint, /**< Setting the startpoint. */ SetEndpoint /**< Setting the endpoint. */ @@ -52,7 +28,7 @@ class RS_ActionDimLeader: public RS_PreviewActionInterface RS_ActionDimLeader(RS_EntityContainer & container, RS_GraphicView & graphicView); ~RS_ActionDimLeader(); - static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); + //static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); virtual RS2::ActionType rtti(); void reset(); @@ -61,7 +37,7 @@ class RS_ActionDimLeader: public RS_PreviewActionInterface virtual void mouseMoveEvent(QMouseEvent * e); virtual void mouseReleaseEvent(QMouseEvent * e); virtual void keyPressEvent(QKeyEvent *); - virtual void coordinateEvent(RS_CoordinateEvent * e); + virtual void coordinateEvent(Vector * e); virtual void commandEvent(RS_CommandEvent * e); virtual QStringList getAvailableCommands(); virtual void showOptions(); @@ -78,7 +54,7 @@ class RS_ActionDimLeader: public RS_PreviewActionInterface /** * Points set so far. */ - // Q3PtrList points; + // Q3PtrList points; QList points; }; diff --git a/src/actions/rs_actiondimlinear.cpp b/src/actions/rs_actiondimlinear.cpp index cac9a5b..db10186 100644 --- a/src/actions/rs_actiondimlinear.cpp +++ b/src/actions/rs_actiondimlinear.cpp @@ -14,9 +14,10 @@ #include "rs_actiondimlinear.h" -#include "rs_snapper.h" #include "rs_constructionline.h" #include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" /** * Constructor. @@ -25,15 +26,12 @@ * @param fixedAngle true: The user can't change the angle. * false: The user can change the angle in a option widget. */ -RS_ActionDimLinear::RS_ActionDimLinear(RS_EntityContainer& container, - RS_GraphicView& graphicView, double angle, bool fixedAngle): +RS_ActionDimLinear::RS_ActionDimLinear(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle, bool fixedAngle): RS_ActionDimension("Draw linear dimensions", container, graphicView) { edata.angle = angle; this->fixedAngle = fixedAngle; - lastStatus = SetExtPoint1; - reset(); } @@ -41,316 +39,297 @@ RS_ActionDimLinear::~RS_ActionDimLinear() { } -QAction * RS_ActionDimLinear::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +/*virtual*/ RS2::ActionType RS_ActionDimLinear::rtti() { - QAction * action; - - switch (type) - { - default: - case RS2::ActionDimLinear: - action = new QAction(tr("&Linear"), 0); -// action = new QAction(tr("Linear"), tr("&Linear"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Linear Dimension")); - break; - - case RS2::ActionDimLinearHor: - action = new QAction(tr("&Horizontal"), 0); -// action = new QAction(tr("Horizontal"), tr("&Horizontal"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Horizontal Dimension")); - break; - - case RS2::ActionDimLinearVer: - action = new QAction(tr("&Vertical"), 0); -// action = new QAction(tr("Vertical"), tr("&Vertical"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Vertical Dimension")); - break; - } - - return action; + return RS2::ActionDimLinear; } +void RS_ActionDimLinear::reset() +{ + RS_ActionDimension::reset(); + edata = RS_DimLinearData(Vector(false), Vector(false), (fixedAngle ? edata.angle : 0.0), 0.0); -void RS_ActionDimLinear::reset() { - RS_ActionDimension::reset(); - - edata = RS_DimLinearData(Vector(false), - Vector(false), - (fixedAngle ? edata.angle : 0.0), 0.0); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); } +void RS_ActionDimLinear::trigger() +{ + RS_ActionDimension::trigger(); + preparePreview(); + RS_DimLinear * dim = new RS_DimLinear(container, data, edata); + dim->setLayerToActive(); + dim->setPenToActive(); + dim->update(); + container->addEntity(dim); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(dim); + document->endUndoCycle(); + } + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(dim); + graphicView->moveRelativeZero(rz); + drawSnapper(); -void RS_ActionDimLinear::trigger() { - RS_ActionDimension::trigger(); - - preparePreview(); - RS_DimLinear* dim = new RS_DimLinear(container, data, edata); - dim->setLayerToActive(); - dim->setPenToActive(); - dim->update(); - container->addEntity(dim); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(dim); - document->endUndoCycle(); - } - - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(dim); - graphicView->moveRelativeZero(rz); - drawSnapper(); - - RS_DEBUG->print("RS_ActionDimLinear::trigger():" - " dim added: %d", dim->getId()); + RS_DEBUG->print("RS_ActionDimLinear::trigger(): dim added: %d", dim->getId()); } +void RS_ActionDimLinear::preparePreview() +{ + Vector dirV; + dirV.setPolar(100.0, edata.angle + M_PI / 2.0); -void RS_ActionDimLinear::preparePreview() { - Vector dirV; - dirV.setPolar(100.0, edata.angle+M_PI/2.0); - - RS_ConstructionLine cl( - NULL, - RS_ConstructionLineData( - edata.extensionPoint2, - edata.extensionPoint2+dirV)); - - data.definitionPoint = - cl.getNearestPointOnEntity(data.definitionPoint); + RS_ConstructionLine cl( + NULL, RS_ConstructionLineData( + edata.extensionPoint2, + edata.extensionPoint2 + dirV)); + data.definitionPoint = + cl.getNearestPointOnEntity(data.definitionPoint); } +void RS_ActionDimLinear::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDimLinear::mouseMoveEvent begin"); + Vector mouse = snapPoint(e); -void RS_ActionDimLinear::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDimLinear::mouseMoveEvent begin"); + switch (getStatus()) + { + case SetExtPoint1: + break; - Vector mouse = snapPoint(e); + case SetExtPoint2: + + if (edata.extensionPoint1.valid) + { + deletePreview(); + clearPreview(); + preview->addEntity(new RS_Line(preview, + RS_LineData(edata.extensionPoint1, + mouse))); + drawPreview(); + } + break; - switch (getStatus()) { - case SetExtPoint1: - break; + case SetDefPoint: - case SetExtPoint2: - if (edata.extensionPoint1.valid) { - deletePreview(); - clearPreview(); - preview->addEntity(new RS_Line(preview, - RS_LineData(edata.extensionPoint1, - mouse))); - drawPreview(); - } - break; + if (edata.extensionPoint1.valid && edata.extensionPoint2.valid) + { + deletePreview(); + clearPreview(); + data.definitionPoint = mouse; - case SetDefPoint: - if (edata.extensionPoint1.valid && edata.extensionPoint2.valid) { - deletePreview(); - clearPreview(); - data.definitionPoint = mouse; + preparePreview(); - preparePreview(); + RS_DimLinear * dim = new RS_DimLinear(preview, data, edata); + dim->update(); + preview->addEntity(dim); + drawPreview(); + } + break; + } - RS_DimLinear* dim = new RS_DimLinear(preview, data, edata); - dim->update(); - preview->addEntity(dim); - drawPreview(); - } - break; - } + RS_DEBUG->print("RS_ActionDimLinear::mouseMoveEvent end"); +} - RS_DEBUG->print("RS_ActionDimLinear::mouseMoveEvent end"); +void RS_ActionDimLinear::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } +void RS_ActionDimLinear::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + Vector pos = *e; -void RS_ActionDimLinear::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } -} + switch (getStatus()) + { + case SetExtPoint1: + edata.extensionPoint1 = pos; + graphicView->moveRelativeZero(pos); + setStatus(SetExtPoint2); + break; + case SetExtPoint2: + edata.extensionPoint2 = pos; + graphicView->moveRelativeZero(pos); + setStatus(SetDefPoint); + break; + case SetDefPoint: + data.definitionPoint = pos; + trigger(); + reset(); + setStatus(SetExtPoint1); + break; -void RS_ActionDimLinear::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } + default: + break; + } +} - Vector pos = e->getCoordinate(); +void RS_ActionDimLinear::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); - switch (getStatus()) { - case SetExtPoint1: - edata.extensionPoint1 = pos; - graphicView->moveRelativeZero(pos); - setStatus(SetExtPoint2); - break; + if (checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } - case SetExtPoint2: - edata.extensionPoint2 = pos; - graphicView->moveRelativeZero(pos); - setStatus(SetDefPoint); - break; + switch (getStatus()) + { + case SetText: + setText(c); - case SetDefPoint: - data.definitionPoint = pos; - trigger(); - reset(); - setStatus(SetExtPoint1); - break; + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + graphicView->enableCoordinateInput(); + setStatus(lastStatus); + break; - default: - break; - } -} + case SetAngle: { + bool ok; + double a = RS_Math::eval(c, &ok); + if (ok == true) + setAngle(RS_Math::deg2rad(a)); + 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; -void RS_ActionDimLinear::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 SetText: - setText(c); - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - graphicView->enableCoordinateInput(); - setStatus(lastStatus); - break; - - case SetAngle: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - setAngle(RS_Math::deg2rad(a)); - } 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; - - default: - lastStatus = (Status)getStatus(); - deleteSnapper(); - deletePreview(); - clearPreview(); - if (checkCommand("text", c)) { - graphicView->disableCoordinateInput(); - setStatus(SetText); - return; - } else if (!fixedAngle && (checkCommand("angle", c))) { - setStatus(SetAngle); - } - break; - } + default: + lastStatus = (Status)getStatus(); + deleteSnapper(); + deletePreview(); + clearPreview(); + + if (checkCommand("text", c)) + { + graphicView->disableCoordinateInput(); + setStatus(SetText); + return; + } + else if (!fixedAngle && (checkCommand("angle", c))) + setStatus(SetAngle); + break; + } } +QStringList RS_ActionDimLinear::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetExtPoint1: + case SetExtPoint2: + case SetDefPoint: + cmd += command("text"); -QStringList RS_ActionDimLinear::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetExtPoint1: - case SetExtPoint2: - case SetDefPoint: - cmd += command("text"); - if (!fixedAngle) { - cmd += command("angle"); - } - break; + if (!fixedAngle) + cmd += command("angle"); + break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - -void RS_ActionDimLinear::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetExtPoint1: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify first extension line origin"), - tr("Cancel")); - break; - case SetExtPoint2: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify second extension line origin"), - tr("Back")); - break; - case SetDefPoint: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify dimension line location"), - tr("Back")); - break; - case SetText: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); - break; - case SetAngle: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Enter dimension line angle:"), ""); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDimLinear::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetExtPoint1: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify first extension line origin"), tr("Cancel")); + break; + + case SetExtPoint2: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify second extension line origin"), tr("Back")); + break; + + case SetDefPoint: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify dimension line location"), tr("Back")); + break; + + case SetText: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); + break; + + case SetAngle: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension line angle:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } +void RS_ActionDimLinear::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDimLinear::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); } +void RS_ActionDimLinear::hideOptions() +{ + RS_ActionInterface::hideOptions(); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); +} -void RS_ActionDimLinear::hideOptions() { - RS_ActionInterface::hideOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } +double RS_ActionDimLinear::getAngle() +{ + return edata.angle; } +void RS_ActionDimLinear::setAngle(double a) +{ + edata.angle = a; +} +bool RS_ActionDimLinear::hasFixedAngle() +{ + return fixedAngle; +} -// EOF diff --git a/src/actions/rs_actiondimlinear.h b/src/actions/rs_actiondimlinear.h index 3827fe4..471c03b 100644 --- a/src/actions/rs_actiondimlinear.h +++ b/src/actions/rs_actiondimlinear.h @@ -1,29 +1,3 @@ -/**************************************************************************** -** $Id: rs_actiondimlinear.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDIMLINEAR_H #define RS_ACTIONDIMLINEAR_H @@ -31,87 +5,66 @@ #include "rs_dimlinear.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * aligned dimensions. * * @author Andrew Mustun */ -class RS_ActionDimLinear : public RS_ActionDimension { - //Q_OBJECT -public: - /** - * Varitions of this action. - */ - enum Variation { - AnyAngle, - Horizontal, - Vertical - }; - - /** - * Action States. - */ - enum Status { - SetExtPoint1, /**< Setting the 1st ext point. */ - SetExtPoint2, /**< Setting the 2nd ext point. */ - SetDefPoint, /**< Setting the common def point. */ - SetText, /**< Setting the text label in the command line. */ - SetAngle /**< Setting the angle in the command line. */ - }; - -public: - RS_ActionDimLinear(RS_EntityContainer& container, - RS_GraphicView& graphicView, - double angle=0.0, bool fixedAngle=false); - ~RS_ActionDimLinear(); - - static QAction* createGUIAction(RS2::ActionType type, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDimLinear; - } - - void reset(); - - virtual void trigger(); - void preparePreview(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); +class RS_ActionDimLinear: public RS_ActionDimension +{ + public: + /** + * Varitions of this action. + */ + enum Variation { + AnyAngle, + Horizontal, + Vertical + }; - double getAngle() { - return edata.angle; - } + /** + * Action States. + */ + enum Status { + SetExtPoint1, /**< Setting the 1st ext point. */ + SetExtPoint2, /**< Setting the 2nd ext point. */ + SetDefPoint, /**< Setting the common def point. */ + SetText, /**< Setting the text label in the command line. */ + SetAngle /**< Setting the angle in the command line. */ + }; - void setAngle(double a) { - edata.angle = a; - } + public: + RS_ActionDimLinear(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle = 0.0, bool fixedAngle = false); + ~RS_ActionDimLinear(); - bool hasFixedAngle() { - return fixedAngle; - } + virtual RS2::ActionType rtti(); + void reset(); + virtual void trigger(); + void preparePreview(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + double getAngle(); + void setAngle(double a); + bool hasFixedAngle(); -protected: - /** - * Aligned dimension data. - */ - RS_DimLinearData edata; - /** - * Is the angle fixed? - */ - bool fixedAngle; + protected: + /** + * Aligned dimension data. + */ + RS_DimLinearData edata; + /** + * Is the angle fixed? + */ + bool fixedAngle; - /** Last status before entering text or angle. */ - Status lastStatus; + /** Last status before entering text or angle. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actiondimradial.cpp b/src/actions/rs_actiondimradial.cpp index ce13832..9d3bebf 100644 --- a/src/actions/rs_actiondimradial.cpp +++ b/src/actions/rs_actiondimradial.cpp @@ -1,324 +1,319 @@ -/**************************************************************************** -** $Id: rs_actiondimradial.cpp 1134 2004-07-13 23:26:13Z 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_actiondimradial.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/03/2010 Added this text. :-) +// #include "rs_actiondimradial.h" -#include "rs_creation.h" -#include "rs_snapper.h" #include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionDimRadial::RS_ActionDimRadial( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionDimension("Draw Radial Dimensions", - container, graphicView) { - reset(); +RS_ActionDimRadial::RS_ActionDimRadial(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionDimension("Draw Radial Dimensions", + container, graphicView) +{ + reset(); } - -QAction * RS_ActionDimRadial::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionDimRadial::~RS_ActionDimRadial() { - QAction * action = new QAction(tr("&Radial"), 0); -// QAction * action = new QAction(tr("Radial"), tr("&Radial"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Radial Dimension")); +} - return action; +/*virtual*/ RS2::ActionType RS_ActionDimRadial::rtti() +{ + return RS2::ActionDimRadial; } void RS_ActionDimRadial::reset() { - RS_ActionDimension::reset(); + RS_ActionDimension::reset(); - edata = RS_DimRadialData(Vector(false), - 0.0); - entity = NULL; - pos = Vector(false); - RS_DIALOGFACTORY->requestOptions(this, true, true); + edata = RS_DimRadialData(Vector(false), + 0.0); + entity = NULL; + pos = Vector(false); + RS_DIALOGFACTORY->requestOptions(this, true, true); } - - -void RS_ActionDimRadial::trigger() { - RS_ActionDimension::trigger(); - - preparePreview(); - if (entity!=NULL) { - RS_DimRadial* newEntity = NULL; - - newEntity = new RS_DimRadial(container, - data, - edata); - - newEntity->setLayerToActive(); - newEntity->setPenToActive(); - newEntity->update(); - container->addEntity(newEntity); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(newEntity); - document->endUndoCycle(); - } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(newEntity); - graphicView->moveRelativeZero(rz); - //drawSnapper(); - - } - else { - RS_DEBUG->print("RS_ActionDimRadial::trigger:" - " Entity is NULL\n"); - } +void RS_ActionDimRadial::trigger() +{ + RS_ActionDimension::trigger(); + + preparePreview(); + + if (entity != NULL) + { + RS_DimRadial * newEntity = NULL; + + newEntity = new RS_DimRadial(container, + data, + edata); + + newEntity->setLayerToActive(); + newEntity->setPenToActive(); + newEntity->update(); + container->addEntity(newEntity); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(newEntity); + document->endUndoCycle(); + } + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(newEntity); + graphicView->moveRelativeZero(rz); + //drawSnapper(); + } + else + RS_DEBUG->print("RS_ActionDimRadial::trigger:" + " Entity is NULL\n"); } - -void RS_ActionDimRadial::preparePreview() { - if (entity!=NULL) { - double angle = data.definitionPoint.angleTo(pos); - double radius=0.0; - if (entity->rtti()==RS2::EntityArc) { - radius = ((RS_Arc*)entity)->getRadius(); - } else if (entity->rtti()==RS2::EntityCircle) { - radius = ((RS_Circle*)entity)->getRadius(); - } - - edata.definitionPoint.setPolar(radius, angle); - edata.definitionPoint += data.definitionPoint; - } +void RS_ActionDimRadial::preparePreview() +{ + if (entity != NULL) + { + double angle = data.definitionPoint.angleTo(pos); + double radius = 0.0; + + if (entity->rtti() == RS2::EntityArc) + radius = ((RS_Arc *)entity)->getRadius(); + else if (entity->rtti() == RS2::EntityCircle) + radius = ((RS_Circle *)entity)->getRadius(); + + edata.definitionPoint.setPolar(radius, angle); + edata.definitionPoint += data.definitionPoint; + } } +void RS_ActionDimRadial::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent begin"); + //Vector mouse(graphicView->toGraphX(e->x()), + // graphicView->toGraphY(e->y())); -void RS_ActionDimRadial::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent begin"); - - //Vector mouse(graphicView->toGraphX(e->x()), - // graphicView->toGraphY(e->y())); + switch (getStatus()) + { + case SetEntity: + entity = catchEntity(e, RS2::ResolveAll); + break; - switch (getStatus()) { - case SetEntity: - entity = catchEntity(e, RS2::ResolveAll); - break; + case SetPos: - case SetPos: - if (entity!=NULL) { - pos = snapPoint(e); + if (entity != NULL) + { + pos = snapPoint(e); - preparePreview(); + preparePreview(); - RS_DimRadial* d = new RS_DimRadial(preview, data, edata); - d->update(); + RS_DimRadial * d = new RS_DimRadial(preview, data, edata); + d->update(); - deletePreview(); - clearPreview(); - preview->addEntity(d); - drawPreview(); - } - break; + deletePreview(); + clearPreview(); + preview->addEntity(d); + drawPreview(); + } + break; - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDimRadial::mouseMoveEvent end"); } - - -void RS_ActionDimRadial::mouseReleaseEvent(QMouseEvent* e) { - - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetEntity: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL) { - if (en->rtti()==RS2::EntityArc || - en->rtti()==RS2::EntityCircle) { - entity = en; - if (entity->rtti()==RS2::EntityArc) { - data.definitionPoint = - ((RS_Arc*)entity)->getCenter(); - } else if (entity->rtti()==RS2::EntityCircle) { - data.definitionPoint = - ((RS_Circle*)entity)->getCenter(); - } - graphicView->moveRelativeZero(data.definitionPoint); - setStatus(SetPos); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a circle " - "or arc entity")); - } - } - } - break; - - case SetPos: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - clearPreview(); - init(getStatus()-1); - } +void RS_ActionDimRadial::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case SetEntity: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL) + { + if (en->rtti() == RS2::EntityArc + || en->rtti() == RS2::EntityCircle) + { + entity = en; + + if (entity->rtti() == RS2::EntityArc) + data.definitionPoint = + ((RS_Arc *)entity)->getCenter(); + else if (entity->rtti() == RS2::EntityCircle) + data.definitionPoint = + ((RS_Circle *)entity)->getCenter(); + graphicView->moveRelativeZero(data.definitionPoint); + setStatus(SetPos); + } + else + RS_DIALOGFACTORY->commandMessage(tr("Not a circle " + "or arc entity")); + } + } + break; + + case SetPos: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + clearPreview(); + init(getStatus() - 1); + } } - - -void RS_ActionDimRadial::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - switch (getStatus()) { - case SetPos: - pos = e->getCoordinate(); - trigger(); - reset(); - setStatus(SetEntity); - break; - - default: - break; - } +void RS_ActionDimRadial::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + switch (getStatus()) + { + case SetPos: + pos = *e; + trigger(); + reset(); + setStatus(SetEntity); + break; + + default: + break; + } } - - -void RS_ActionDimRadial::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - // setting new text label: - if (getStatus()==SetText) { - setText(c); - RS_DIALOGFACTORY->requestOptions(this, true, true); - graphicView->enableCoordinateInput(); - setStatus(lastStatus); - return; - } - - // command: text - if (checkCommand("text", c)) { - lastStatus = (Status)getStatus(); - graphicView->disableCoordinateInput(); - setStatus(SetText); - } - - // setting angle - if (getStatus()==SetPos) { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - pos.setPolar(1.0, RS_Math::deg2rad(a)); - pos += data.definitionPoint; - trigger(); - reset(); - setStatus(SetEntity); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - return; - } +void RS_ActionDimRadial::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + // setting new text label: + if (getStatus() == SetText) + { + setText(c); + RS_DIALOGFACTORY->requestOptions(this, true, true); + graphicView->enableCoordinateInput(); + setStatus(lastStatus); + return; + } + + // command: text + if (checkCommand("text", c)) + { + lastStatus = (Status)getStatus(); + graphicView->disableCoordinateInput(); + setStatus(SetText); + } + + // setting angle + if (getStatus() == SetPos) + { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + { + pos.setPolar(1.0, RS_Math::deg2rad(a)); + pos += data.definitionPoint; + trigger(); + reset(); + setStatus(SetEntity); + } + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + return; + } } +QStringList RS_ActionDimRadial::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetEntity: + case SetPos: + cmd += command("text"); + break; -QStringList RS_ActionDimRadial::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetEntity: - case SetPos: - cmd += command("text"); - break; - - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - -void RS_ActionDimRadial::updateMouseButtonHints() { - switch (getStatus()) { - case SetEntity: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"), - tr("Cancel")); - break; - case SetPos: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify dimension line position or enter angle:"), - tr("Cancel")); - break; - case SetText: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDimRadial::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetEntity: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select arc or circle entity"), + tr("Cancel")); + break; + + case SetPos: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify dimension line position or enter angle:"), + tr("Cancel")); + break; + + case SetText: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter dimension text:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } +void RS_ActionDimRadial::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDimRadial::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); - //RS_DIALOGFACTORY->requestDimRadialOptions(edata, true); + RS_DIALOGFACTORY->requestOptions(this, true); + //RS_DIALOGFACTORY->requestDimRadialOptions(edata, true); } +void RS_ActionDimRadial::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDimRadial::hideOptions() { - RS_ActionInterface::hideOptions(); - - //RS_DIALOGFACTORY->requestDimRadialOptions(edata, false); - RS_DIALOGFACTORY->requestOptions(this, false); + //RS_DIALOGFACTORY->requestDimRadialOptions(edata, false); + RS_DIALOGFACTORY->requestOptions(this, false); } - - // EOF diff --git a/src/actions/rs_actiondimradial.h b/src/actions/rs_actiondimradial.h index ed8053f..475aa94 100644 --- a/src/actions/rs_actiondimradial.h +++ b/src/actions/rs_actiondimradial.h @@ -1,88 +1,52 @@ -/**************************************************************************** -** $Id: rs_actiondimradial.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDIMRADIAL_H #define RS_ACTIONDIMRADIAL_H #include "rs_actiondimension.h" #include "rs_dimradial.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to draw radial dimensions. * * @author Andrew Mustun */ -class RS_ActionDimRadial : public RS_ActionDimension { - //Q_OBJECT -private: - enum Status { - SetEntity, /**< Choose entity. */ - SetPos, /**< Choose point. */ - SetText /**< Setting text label in the command line. */ - }; - -public: - RS_ActionDimRadial(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDimRadial() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDimRadial; - } - - virtual void reset(); - - virtual void trigger(); - void preparePreview(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - - -private: - /** Chosen entity (arc / circle) */ - RS_Entity* entity; - /** Chosen position */ - Vector pos; - /** Data of new dimension */ - RS_DimRadialData edata; - /** Last status before entering text. */ - Status lastStatus; +class RS_ActionDimRadial: public RS_ActionDimension +{ + private: + enum Status { + SetEntity, /**< Choose entity. */ + SetPos, /**< Choose point. */ + SetText /**< Setting text label in the command line. */ + }; + + public: + RS_ActionDimRadial(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDimRadial(); + + virtual RS2::ActionType rtti(); + virtual void reset(); + virtual void trigger(); + void preparePreview(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + + private: + /** Chosen entity (arc / circle) */ + RS_Entity * entity; + /** Chosen position */ + Vector pos; + /** Data of new dimension */ + RS_DimRadialData edata; + /** Last status before entering text. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actiondrawarc.cpp b/src/actions/rs_actiondrawarc.cpp index 2064d71..c4fded9 100644 --- a/src/actions/rs_actiondrawarc.cpp +++ b/src/actions/rs_actiondrawarc.cpp @@ -1,55 +1,34 @@ -/**************************************************************************** -** $Id: rs_actiondrawarc.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_actiondrawarc.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/03/2010 Added this text. :-) +// #include "rs_actiondrawarc.h" #include "commands.h" -#include "rs_snapper.h" #include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" RS_ActionDrawArc::RS_ActionDrawArc(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw arcs", container, graphicView) { - reset(); + reset(); } RS_ActionDrawArc::~RS_ActionDrawArc() { } -QAction * RS_ActionDrawArc::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) -{ - QAction * action = new QAction(tr("&Center, Point, Angles"), 0); -// QAction* action = new QAction(tr("Arc: Center, Point, Angles"), -// tr("&Center, Point, Angles"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw arcs")); - return action; -} - RS2::ActionType RS_ActionDrawArc::rtti() { return RS2::ActionDrawArc; @@ -112,6 +91,7 @@ void RS_ActionDrawArc::mouseMoveEvent(QMouseEvent * e) break; case SetRadius: + if (data.center.valid) { data.radius = data.center.distanceTo(mouse); @@ -155,6 +135,7 @@ void RS_ActionDrawArc::mouseMoveEvent(QMouseEvent * e) case SetChordLength: { double x = data.center.distanceTo(mouse); + if (fabs(x / (2 * data.radius)) <= 1.0) { data.angle2 = data.angle1 + asin(x / (2 * data.radius)) * 2; @@ -164,11 +145,10 @@ void RS_ActionDrawArc::mouseMoveEvent(QMouseEvent * e) drawPreview(); } } - break; + break; default: break; - } RS_DEBUG->print("RS_ActionDrawArc::mouseMoveEvent end"); @@ -178,7 +158,7 @@ void RS_ActionDrawArc::mouseReleaseEvent(QMouseEvent * e) { if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) @@ -189,45 +169,46 @@ void RS_ActionDrawArc::mouseReleaseEvent(QMouseEvent * e) } } -void RS_ActionDrawArc::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionDrawArc::coordinateEvent(Vector * e) { - if (e == NULL) - return; + if (e == NULL) + return; - Vector mouse = e->getCoordinate(); + Vector mouse = *e; - switch (getStatus()) + switch (getStatus()) { - case SetCenter: - data.center = mouse; - graphicView->moveRelativeZero(mouse); - //deleteSnapper(); - setStatus(SetRadius); - break; + case SetCenter: + data.center = mouse; + graphicView->moveRelativeZero(mouse); + //deleteSnapper(); + setStatus(SetRadius); + break; - case SetRadius: - if (data.center.valid) - data.radius = data.center.distanceTo(mouse); + case SetRadius: + + if (data.center.valid) + data.radius = data.center.distanceTo(mouse); setStatus(SetAngle1); - break; + break; - case SetAngle1: - data.angle1 = data.center.angleTo(mouse); - setStatus(SetAngle2); - break; + case SetAngle1: + data.angle1 = data.center.angleTo(mouse); + setStatus(SetAngle2); + break; - case SetAngle2: - data.angle2 = data.center.angleTo(mouse); - trigger(); - break; + case SetAngle2: + data.angle2 = data.center.angleTo(mouse); + trigger(); + break; - case SetIncAngle: - data.angle2 = data.angle1 + data.center.angleTo(mouse); - trigger(); - break; + case SetIncAngle: + data.angle2 = data.angle1 + data.center.angleTo(mouse); + trigger(); + break; - case SetChordLength: + case SetChordLength: { double x = data.center.distanceTo(mouse); @@ -237,187 +218,199 @@ void RS_ActionDrawArc::coordinateEvent(RS_CoordinateEvent * e) trigger(); } } - break; + break; - default: - break; - } + default: + break; + } } void RS_ActionDrawArc::commandEvent(RS_CommandEvent * e) { - QString c = e->getCommand().toLower(); - - if (RS_COMMANDS->checkCommand("help", c)) { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - } - return; - } - - if (RS_COMMANDS->checkCommand("reversed", c)) { - e->accept(); - setReversed(!isReversed()); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - return; - } - - switch (getStatus()) { - - case SetRadius: { - bool ok; - double r = RS_Math::eval(c, &ok); - if (ok==true) { - data.radius = r; - setStatus(SetAngle1); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - case SetAngle1: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - data.angle1 = RS_Math::deg2rad(a); - setStatus(SetAngle2); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - case SetAngle2: { - if (RS_COMMANDS->checkCommand("angle", c)) { - setStatus(SetIncAngle); - } else if (RS_COMMANDS->checkCommand("chord length", c)) { - setStatus(SetChordLength); - } else { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - data.angle2 = RS_Math::deg2rad(a); - trigger(); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - } - break; - - case SetIncAngle: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - data.angle2 = data.angle1 + RS_Math::deg2rad(a); - trigger(); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - case SetChordLength: { - bool ok; - double l = RS_Math::eval(c, &ok); - if (ok==true) { - if (fabs(l/(2*data.radius))<=1.0) { - data.angle2 = data.angle1 + asin(l/(2*data.radius)) * 2; - trigger(); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage( - tr("Not a valid chord length")); - } - } - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - default: - break; - } + QString c = e->getCommand().toLower(); + + if (RS_COMMANDS->checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + if (RS_COMMANDS->checkCommand("reversed", c)) + { + e->accept(); + setReversed(!isReversed()); + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + return; + } + + switch (getStatus()) + { + case SetRadius: { + bool ok; + double r = RS_Math::eval(c, &ok); + + if (ok == true) + { + data.radius = r; + setStatus(SetAngle1); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + case SetAngle1: { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + { + data.angle1 = RS_Math::deg2rad(a); + setStatus(SetAngle2); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + case SetAngle2: + + if (RS_COMMANDS->checkCommand("angle", c)) + setStatus(SetIncAngle); + else if (RS_COMMANDS->checkCommand("chord length", c)) + setStatus(SetChordLength); + else + { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + { + data.angle2 = RS_Math::deg2rad(a); + trigger(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + case SetIncAngle: { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + { + data.angle2 = data.angle1 + RS_Math::deg2rad(a); + trigger(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + case SetChordLength: { + bool ok; + double l = RS_Math::eval(c, &ok); + + if (ok == true) + { + if (fabs(l / (2 * data.radius)) <= 1.0) + { + data.angle2 = data.angle1 + asin(l / (2 * data.radius)) * 2; + trigger(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage( + tr("Not a valid chord length")); + + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + } + break; + + default: + break; + } } QStringList RS_ActionDrawArc::getAvailableCommands() { - QStringList cmd; - cmd += RS_COMMANDS->command("reversed"); - return cmd; + QStringList cmd; + cmd += RS_COMMANDS->command("reversed"); + return cmd; } void RS_ActionDrawArc::updateMouseButtonHints() { - if (RS_DIALOGFACTORY != NULL) + if (RS_DIALOGFACTORY != NULL) { - switch (getStatus()) + switch (getStatus()) { - case SetCenter: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), tr("Cancel")); - break; - case SetRadius: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back")); - break; - case SetAngle1: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify start angle:"), tr("Back")); - break; - case SetAngle2: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify end angle or [Angle/chord Length]"), - tr("Back")); - break; - case SetIncAngle: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify included angle:"), - tr("Back")); - break; - case SetChordLength: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify chord length:"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } + case SetCenter: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), tr("Cancel")); + break; + + case SetRadius: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back")); + break; + + case SetAngle1: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify start angle:"), tr("Back")); + break; + + case SetAngle2: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify end angle or [Angle/chord Length]"), + tr("Back")); + break; + + case SetIncAngle: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify included angle:"), + tr("Back")); + break; + + case SetChordLength: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify chord length:"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } void RS_ActionDrawArc::showOptions() { - RS_ActionInterface::showOptions(); + RS_ActionInterface::showOptions(); - if (RS_DIALOGFACTORY != NULL) - RS_DIALOGFACTORY->requestOptions(this, true); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); } void RS_ActionDrawArc::hideOptions() { - RS_ActionInterface::hideOptions(); + RS_ActionInterface::hideOptions(); - if (RS_DIALOGFACTORY != NULL) - RS_DIALOGFACTORY->requestOptions(this, false); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } void RS_ActionDrawArc::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); + graphicView->setMouseCursor(RS2::CadCursor); } void RS_ActionDrawArc::updateToolBar() @@ -440,3 +433,4 @@ void RS_ActionDrawArc::setReversed(bool r) { data.reversed = r; } + diff --git a/src/actions/rs_actiondrawarc.h b/src/actions/rs_actiondrawarc.h index e12c59e..6edc795 100644 --- a/src/actions/rs_actiondrawarc.h +++ b/src/actions/rs_actiondrawarc.h @@ -1,29 +1,3 @@ -/**************************************************************************** -** $Id: rs_actiondrawarc.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWARC_H #define RS_ACTIONDRAWARC_H @@ -38,11 +12,10 @@ */ class RS_ActionDrawArc: public RS_PreviewActionInterface { -// //Q_OBJECT public: /** - * Action States. - */ + * Action States. + */ enum Status { SetCenter, /**< Setting the center point. */ SetRadius, /**< Setting the radius. */ @@ -56,42 +29,28 @@ class RS_ActionDrawArc: public RS_PreviewActionInterface RS_ActionDrawArc(RS_EntityContainer & container, RS_GraphicView & graphicView); ~RS_ActionDrawArc(); - static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); virtual RS2::ActionType rtti(); void reset(); - virtual void init(int status = 0); virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent * e); virtual void mouseReleaseEvent(QMouseEvent * e); - - virtual void coordinateEvent(RS_CoordinateEvent * e); + virtual void coordinateEvent(Vector * e); virtual void commandEvent(RS_CommandEvent * e); virtual QStringList getAvailableCommands(); - virtual void hideOptions(); virtual void showOptions(); - virtual void updateMouseButtonHints(); virtual void updateMouseCursor(); virtual void updateToolBar(); - bool isReversed(); - void setReversed(bool r); + void setReversed(bool r); protected: /** * Arc data defined so far. */ RS_ArcData data; - /** - * Commands - */ - /*QString cmdReversed; - QString cmdReversed2; - QString cmdReversed3; - */ }; #endif diff --git a/src/actions/rs_actiondrawarc3p.cpp b/src/actions/rs_actiondrawarc3p.cpp index 9c80b67..6f5d641 100644 --- a/src/actions/rs_actiondrawarc3p.cpp +++ b/src/actions/rs_actiondrawarc3p.cpp @@ -1,55 +1,35 @@ -/**************************************************************************** -** $Id: rs_actiondrawarc3p.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawarc3p.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/03/2010 Added this text. :-) +// #include "rs_actiondrawarc3p.h" #include "rs_actiondrawarc.h" #include "commands.h" -#include "rs_snapper.h" #include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -RS_ActionDrawArc3P::RS_ActionDrawArc3P(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionDrawArc3P::RS_ActionDrawArc3P(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw arcs 3P", container, graphicView) { - reset(); + reset(); } RS_ActionDrawArc3P::~RS_ActionDrawArc3P() { } -QAction * RS_ActionDrawArc3P::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) -{ - QAction * action = new QAction(tr("&3 Points"), 0); -// QAction* action = new QAction(tr("Arc: 3 Points"), tr("&3 Points"), QKeySequence(), NULL); - action->setStatusTip(tr("Draw arcs with 3 points")); - return action; -} - void RS_ActionDrawArc3P::reset() { data.reset(); @@ -95,9 +75,7 @@ void RS_ActionDrawArc3P::trigger() reset(); } else - { RS_DIALOGFACTORY->commandMessage(tr("Invalid arc data.")); - } } void RS_ActionDrawArc3P::preparePreview() @@ -162,7 +140,7 @@ void RS_ActionDrawArc3P::mouseReleaseEvent(QMouseEvent * e) { if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) @@ -173,12 +151,12 @@ void RS_ActionDrawArc3P::mouseReleaseEvent(QMouseEvent * e) } } -void RS_ActionDrawArc3P::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionDrawArc3P::coordinateEvent(Vector * e) { if (e == NULL) return; - Vector mouse = e->getCoordinate(); + Vector mouse = *e; switch (getStatus()) { @@ -235,12 +213,15 @@ void RS_ActionDrawArc3P::updateMouseButtonHints() case SetPoint1: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify startpoint or [Center]"), tr("Cancel")); break; + case SetPoint2: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), tr("Back")); break; + case SetPoint3: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify endpoint"), tr("Back")); break; + default: RS_DIALOGFACTORY->updateMouseWidget("", ""); break; @@ -259,3 +240,4 @@ void RS_ActionDrawArc3P::updateToolBar() else RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs); } + diff --git a/src/actions/rs_actiondrawarc3p.h b/src/actions/rs_actiondrawarc3p.h index 8851220..052c095 100644 --- a/src/actions/rs_actiondrawarc3p.h +++ b/src/actions/rs_actiondrawarc3p.h @@ -1,95 +1,62 @@ -/**************************************************************************** -** $Id: rs_actiondrawarc3p.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWARC3P_H #define RS_ACTIONDRAWARC3P_H -#include "rs_previewactioninterface.h" #include "rs_arc.h" +#include "rs_previewactioninterface.h" +#include "vector.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * arcs with three points given. * * @author Andrew Mustun */ -class RS_ActionDrawArc3P : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetPoint1, /**< Setting the 1st point. */ - SetPoint2, /**< Setting the 2nd point. */ - SetPoint3 /**< Setting the 3rd point. */ - }; - -public: - RS_ActionDrawArc3P(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawArc3P(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - void reset(); - - virtual void init(int status=0); - - virtual void trigger(); - void preparePreview(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - /** - * Arc data defined so far. - */ - RS_ArcData data; - /** - * 1st point. - */ - Vector point1; - /** - * 2nd point. - */ - Vector point2; - /** - * 3nd point. - */ - Vector point3; +class RS_ActionDrawArc3P: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetPoint1, /**< Setting the 1st point. */ + SetPoint2, /**< Setting the 2nd point. */ + SetPoint3 /**< Setting the 3rd point. */ + }; + + public: + RS_ActionDrawArc3P(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawArc3P(); + + void reset(); + virtual void init(int status = 0); + virtual void trigger(); + void preparePreview(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + /** + * Arc data defined so far. + */ + RS_ArcData data; + /** + * 1st point. + */ + Vector point1; + /** + * 2nd point. + */ + Vector point2; + /** + * 3nd point. + */ + Vector point3; }; #endif diff --git a/src/actions/rs_actiondrawarctangential.cpp b/src/actions/rs_actiondrawarctangential.cpp index 8095104..25d52bc 100644 --- a/src/actions/rs_actiondrawarctangential.cpp +++ b/src/actions/rs_actiondrawarctangential.cpp @@ -1,295 +1,287 @@ -/**************************************************************************** -** $Id: rs_actiondrawarctangential.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_actiondrawarctangential.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/03/2010 Added this text. :-) +// #include "rs_actiondrawarctangential.h" -#include "commands.h" -#include "rs_snapper.h" #include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionDrawArcTangential::RS_ActionDrawArcTangential(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw arcs tangential", - container, graphicView) { - reset(); +RS_ActionDrawArcTangential::RS_ActionDrawArcTangential(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw arcs tangential", + container, graphicView) +{ + reset(); } - - -RS_ActionDrawArcTangential::~RS_ActionDrawArcTangential() {} - - -QAction* RS_ActionDrawArcTangential::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawArcTangential::~RS_ActionDrawArcTangential() { - QAction * action = new QAction(tr("&Tangential"), 0); -// QAction* action = new QAction(tr("Arc: Tangential"), -// tr("&Tangential"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw arcs tangential to base entity")); - return action; } - -void RS_ActionDrawArcTangential::reset() { - baseEntity = NULL; - isStartPoint = false; - point = Vector(false); +/*virtual*/ RS2::ActionType RS_ActionDrawArcTangential::rtti() +{ + return RS2::ActionDrawArcTangential; } - - -void RS_ActionDrawArcTangential::init(int status) { - RS_PreviewActionInterface::init(status); - - //reset(); +void RS_ActionDrawArcTangential::reset() +{ + baseEntity = NULL; + isStartPoint = false; + point = Vector(false); } - - -void RS_ActionDrawArcTangential::trigger() { - RS_PreviewActionInterface::trigger(); - - if (point.valid==false || baseEntity==NULL) { - RS_DEBUG->print("RS_ActionDrawArcTangential::trigger: " - "conditions not met"); - return; - } - - preparePreview(); - RS_Arc* arc = new RS_Arc(container, data); - arc->setLayerToActive(); - arc->setPenToActive(); - container->addEntity(arc); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(arc); - document->endUndoCycle(); - } - - deleteSnapper(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(arc); - graphicView->moveRelativeZero(arc->getCenter()); - drawSnapper(); - - setStatus(SetBaseEntity); - reset(); +void RS_ActionDrawArcTangential::init(int status) +{ + RS_PreviewActionInterface::init(status); + //reset(); } - - -void RS_ActionDrawArcTangential::preparePreview() { - if (baseEntity!=NULL && point.valid) { - Vector startPoint; - double direction; - if (isStartPoint) { - startPoint = baseEntity->getStartpoint(); - direction = RS_Math::correctAngle(baseEntity->getDirection1()+M_PI); - } else { - startPoint = baseEntity->getEndpoint(); - direction = RS_Math::correctAngle(baseEntity->getDirection2()+M_PI); - } - - RS_Arc arc(NULL, RS_ArcData()); - bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius); - if (suc) { - data = arc.getData(); - } - } +void RS_ActionDrawArcTangential::trigger() +{ + RS_PreviewActionInterface::trigger(); + + if (point.valid == false || baseEntity == NULL) + { + RS_DEBUG->print("RS_ActionDrawArcTangential::trigger: " + "conditions not met"); + return; + } + + preparePreview(); + RS_Arc * arc = new RS_Arc(container, data); + arc->setLayerToActive(); + arc->setPenToActive(); + container->addEntity(arc); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(arc); + document->endUndoCycle(); + } + + deleteSnapper(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(arc); + graphicView->moveRelativeZero(arc->getCenter()); + drawSnapper(); + + setStatus(SetBaseEntity); + reset(); } - -void RS_ActionDrawArcTangential::mouseMoveEvent(QMouseEvent* e) { - switch (getStatus()) { - case SetBaseEntity: - break; - - case SetEndAngle: { - point = snapPoint(e); - preparePreview(); - if (data.isValid()) { - RS_Arc* arc = new RS_Arc(preview, data); - deletePreview(); - clearPreview(); - preview->addEntity(arc); - drawPreview(); - } - } - break; - - default: - break; - } +void RS_ActionDrawArcTangential::preparePreview() +{ + if (baseEntity != NULL && point.valid) + { + Vector startPoint; + double direction; + + if (isStartPoint) + { + startPoint = baseEntity->getStartpoint(); + direction = RS_Math::correctAngle(baseEntity->getDirection1() + M_PI); + } + else + { + startPoint = baseEntity->getEndpoint(); + direction = RS_Math::correctAngle(baseEntity->getDirection2() + M_PI); + } + + RS_Arc arc(NULL, RS_ArcData()); + bool suc = arc.createFrom2PDirectionRadius(startPoint, point, direction, data.radius); + + if (suc) + data = arc.getData(); + } } - - -void RS_ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - - // set base entity: - case SetBaseEntity: { - Vector coord = graphicView->toGraph(e->x(), e->y()); - RS_Entity* entity = catchEntity(coord, RS2::ResolveAll); - if (entity!=NULL) { - if (entity->isAtomic()) { - baseEntity = (RS_AtomicEntity*)entity; - if (baseEntity->getStartpoint().distanceTo(coord) < - baseEntity->getEndpoint().distanceTo(coord)) { - isStartPoint = true; - } else { - isStartPoint = false; - } - setStatus(SetEndAngle); - updateMouseButtonHints(); - } else { - // TODO: warning - } - } - else { - deleteSnapper(); - } - } - break; - - // set angle (point that defines the angle) - case SetEndAngle: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawArcTangential::mouseMoveEvent(QMouseEvent * e) +{ + switch (getStatus()) + { + case SetBaseEntity: + break; + + case SetEndAngle: + point = snapPoint(e); + preparePreview(); + + if (data.isValid()) + { + RS_Arc * arc = new RS_Arc(preview, data); + deletePreview(); + clearPreview(); + preview->addEntity(arc); + drawPreview(); + } + break; + + default: + break; + } } +void RS_ActionDrawArcTangential::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + // set base entity: + case SetBaseEntity: { + Vector coord = graphicView->toGraph(e->x(), e->y()); + RS_Entity * entity = catchEntity(coord, RS2::ResolveAll); + + if (entity != NULL) + { + if (entity->isAtomic()) + { + baseEntity = (RS_AtomicEntity *)entity; + + if (baseEntity->getStartpoint().distanceTo(coord) + < baseEntity->getEndpoint().distanceTo(coord)) + isStartPoint = true; + else + isStartPoint = false; + setStatus(SetEndAngle); + updateMouseButtonHints(); + } + else + { + // TODO: warning + } + } + else + deleteSnapper(); + } + break; + + // set angle (point that defines the angle) + case SetEndAngle: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } +} +void RS_ActionDrawArcTangential::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; -void RS_ActionDrawArcTangential::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - Vector mouse = e->getCoordinate(); + Vector mouse = *e; - switch (getStatus()) { - case SetBaseEntity: - break; + switch (getStatus()) + { + case SetBaseEntity: + break; - case SetEndAngle: - point = mouse; - trigger(); - break; + case SetEndAngle: + point = mouse; + trigger(); + break; - default: - break; - } + default: + break; + } } - - -void RS_ActionDrawArcTangential::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } +void RS_ActionDrawArcTangential::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } } - - -QStringList RS_ActionDrawArcTangential::getAvailableCommands() { - QStringList cmd; - return cmd; +QStringList RS_ActionDrawArcTangential::getAvailableCommands() +{ + QStringList cmd; + return cmd; } +void RS_ActionDrawArcTangential::showOptions() +{ + RS_ActionInterface::showOptions(); -void RS_ActionDrawArcTangential::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } - updateMouseButtonHints(); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); + updateMouseButtonHints(); } +void RS_ActionDrawArcTangential::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawArcTangential::hideOptions() { - RS_ActionInterface::hideOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionDrawArcTangential::updateMouseButtonHints() { - switch (getStatus()) { - case SetBaseEntity: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify base entity"), - tr("Cancel")); - break; - case SetEndAngle: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify end angle"), tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDrawArcTangential::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetBaseEntity: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify base entity"), + tr("Cancel")); + break; + + case SetEndAngle: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify end angle"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionDrawArcTangential::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawArcTangential::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionDrawArcTangential::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs); - } +void RS_ActionDrawArcTangential::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarArcs); } +void RS_ActionDrawArcTangential::setRadius(double r) +{ + data.radius = r; +} -// EOF +double RS_ActionDrawArcTangential::getRadius() +{ + return data.radius; +} diff --git a/src/actions/rs_actiondrawarctangential.h b/src/actions/rs_actiondrawarctangential.h index 5a90dcb..bca26bd 100644 --- a/src/actions/rs_actiondrawarctangential.h +++ b/src/actions/rs_actiondrawarctangential.h @@ -1,109 +1,68 @@ -/**************************************************************************** -** $Id: rs_actiondrawarctangential.h 1155 2004-11-18 16:01:06Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWARCTANGENTIAL_H #define RS_ACTIONDRAWARCTANGENTIAL_H #include "rs_previewactioninterface.h" #include "rs_arc.h" +#include "vector.h" + +class RS_AtomicEntity; /** - * This action class can handle user events to draw + * This action class can handle user events to draw * arcs with three points given. * * @author Andrew Mustun */ -class RS_ActionDrawArcTangential : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetBaseEntity, /**< Setting base entity. */ - SetEndAngle /**< Setting end angle. */ - }; - -public: - RS_ActionDrawArcTangential(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawArcTangential(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawArcTangential; - } - - void reset(); - - virtual void init(int status=0); - - virtual void trigger(); - void preparePreview(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); +class RS_ActionDrawArcTangential: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetBaseEntity, /**< Setting base entity. */ + SetEndAngle /**< Setting end angle. */ + }; - void setRadius(double r) { - data.radius = r; - } + public: + RS_ActionDrawArcTangential(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawArcTangential(); - double getRadius() { - return data.radius; - } + virtual RS2::ActionType rtti(); + void reset(); + virtual void init(int status = 0); + virtual void trigger(); + void preparePreview(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + void setRadius(double r); + double getRadius(); -protected: - /** - * Base entity. - */ - RS_AtomicEntity* baseEntity; - /** - * Start point of base entity clicked? - */ - bool isStartPoint; - /** - * Point that determines end angle. - */ - Vector point; - /** - * Arc data calculated. - */ - RS_ArcData data; + protected: + /** + * Base entity. + */ + RS_AtomicEntity * baseEntity; + /** + * Start point of base entity clicked? + */ + bool isStartPoint; + /** + * Point that determines end angle. + */ + Vector point; + /** + * Arc data calculated. + */ + RS_ArcData data; }; #endif diff --git a/src/actions/rs_actiondrawcircle.cpp b/src/actions/rs_actiondrawcircle.cpp index 1c4da96..54baf31 100644 --- a/src/actions/rs_actiondrawcircle.cpp +++ b/src/actions/rs_actiondrawcircle.cpp @@ -1,262 +1,246 @@ -/**************************************************************************** -** $Id: rs_actiondrawcircle.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawcircle.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/03/2010 Added this text. :-) +// #include "rs_actiondrawcircle.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -RS_ActionDrawCircle::RS_ActionDrawCircle(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionDrawCircle::RS_ActionDrawCircle(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw circles", container, graphicView) { - reset(); + reset(); } -RS_ActionDrawCircle::~RS_ActionDrawCircle() {} - -QAction * RS_ActionDrawCircle::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionDrawCircle::~RS_ActionDrawCircle() { - QAction * action = new QAction(tr("Center, &Point"), 0); -// QAction* action = new QAction(tr("Circle: Center, Point"), -// tr("Center, &Point"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw circles with center and point")); - return action; } -void RS_ActionDrawCircle::reset() +/*virtual*/ RS2::ActionType RS_ActionDrawCircle::rtti() { - data = RS_CircleData(Vector(false), 0.0); + return RS2::ActionDrawCircle; } - - -void RS_ActionDrawCircle::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); +void RS_ActionDrawCircle::reset() +{ + data = RS_CircleData(Vector(false), 0.0); } +void RS_ActionDrawCircle::init(int status) +{ + RS_PreviewActionInterface::init(status); - -void RS_ActionDrawCircle::trigger() { - RS_PreviewActionInterface::trigger(); - - RS_Circle* circle = new RS_Circle(container, - data); - circle->setLayerToActive(); - circle->setPenToActive(); - container->addEntity(circle); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(circle); - document->endUndoCycle(); - } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(circle); - graphicView->moveRelativeZero(circle->getCenter()); - drawSnapper(); - - setStatus(SetCenter); - reset(); - - RS_DEBUG->print("RS_ActionDrawCircle::trigger(): circle added: %d", - circle->getId()); + reset(); } - - -void RS_ActionDrawCircle::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetCenter: - data.center = mouse; - break; - - case SetRadius: - if (data.center.valid) { - data.radius = data.center.distanceTo(mouse); - deletePreview(); - clearPreview(); - preview->addEntity(new RS_Circle(preview, - data)); - drawPreview(); - } - break; - } - - RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent end"); +void RS_ActionDrawCircle::trigger() +{ + RS_PreviewActionInterface::trigger(); + + RS_Circle * circle = new RS_Circle(container, data); + circle->setLayerToActive(); + circle->setPenToActive(); + container->addEntity(circle); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(circle); + document->endUndoCycle(); + } + + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(circle); + graphicView->moveRelativeZero(circle->getCenter()); + drawSnapper(); + + setStatus(SetCenter); + reset(); + + RS_DEBUG->print("RS_ActionDrawCircle::trigger(): circle added: %d", circle->getId()); } - - -void RS_ActionDrawCircle::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawCircle::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent begin"); + + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetCenter: + data.center = mouse; + break; + + case SetRadius: + + if (data.center.valid) + { + data.radius = data.center.distanceTo(mouse); + deletePreview(); + clearPreview(); + preview->addEntity(new RS_Circle(preview, + data)); + drawPreview(); + } + break; + } + + RS_DEBUG->print("RS_ActionDrawCircle::mouseMoveEvent end"); } - - -void RS_ActionDrawCircle::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetCenter: - data.center = mouse; - graphicView->moveRelativeZero(mouse); - setStatus(SetRadius); - break; - - case SetRadius: - if (data.center.valid) { - graphicView->moveRelativeZero(mouse); - data.radius = data.center.distanceTo(mouse); - trigger(); - } - //setStatus(SetCenter); - break; - - default: - break; - } +void RS_ActionDrawCircle::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawCircle::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 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")); - } - } - trigger(); - //setStatus(SetCenter); - } - break; - - default: - break; - } +void RS_ActionDrawCircle::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetCenter: + data.center = mouse; + graphicView->moveRelativeZero(mouse); + setStatus(SetRadius); + break; + + case SetRadius: + + if (data.center.valid) + { + graphicView->moveRelativeZero(mouse); + data.radius = data.center.distanceTo(mouse); + trigger(); + } + //setStatus(SetCenter); + break; + + default: + break; + } } - - -QStringList RS_ActionDrawCircle::getAvailableCommands() { - QStringList cmd; - return cmd; +void RS_ActionDrawCircle::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 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")); + + trigger(); + //setStatus(SetCenter); + } + break; + + default: + break; + } } - -void RS_ActionDrawCircle::updateMouseButtonHints() { - switch (getStatus()) { - case SetCenter: - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify center"), tr("Cancel")); - } - break; - case SetRadius: - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back")); - } - break; - default: - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateMouseWidget("", ""); - } - break; - } +QStringList RS_ActionDrawCircle::getAvailableCommands() +{ + QStringList cmd; + return cmd; } +void RS_ActionDrawCircle::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetCenter: + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify center"), tr("Cancel")); + break; -void RS_ActionDrawCircle::showOptions() { - RS_ActionInterface::showOptions(); -} + case SetRadius: + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify radius"), tr("Back")); + break; + default: -void RS_ActionDrawCircle::hideOptions() { - RS_ActionInterface::hideOptions(); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } +void RS_ActionDrawCircle::showOptions() +{ + RS_ActionInterface::showOptions(); +} - -void RS_ActionDrawCircle::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawCircle::hideOptions() +{ + RS_ActionInterface::hideOptions(); } +void RS_ActionDrawCircle::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} +void RS_ActionDrawCircle::updateToolBar() +{ + if (!isFinished()) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); -void RS_ActionDrawCircle::updateToolBar() { - if (!isFinished()) { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); - } - } } - // EOF diff --git a/src/actions/rs_actiondrawcircle.h b/src/actions/rs_actiondrawcircle.h index 63452c7..8757275 100644 --- a/src/actions/rs_actiondrawcircle.h +++ b/src/actions/rs_actiondrawcircle.h @@ -1,88 +1,50 @@ -/**************************************************************************** -** $Id: rs_actiondrawcircle.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWCIRCLE_H #define RS_ACTIONDRAWCIRCLE_H -#include "rs_previewactioninterface.h" #include "rs_circle.h" +#include "rs_previewactioninterface.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * circles with a given center and a point on the circle line. * * @author Andrew Mustun */ -class RS_ActionDrawCircle : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetCenter, /**< Setting the center point. */ - SetRadius /**< Setting the radius. */ - }; - -public: - RS_ActionDrawCircle(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawCircle(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawCircle; - } - - void reset(); - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - /** - * Circle data defined so far. - */ - RS_CircleData data; +class RS_ActionDrawCircle: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetCenter, /**< Setting the center point. */ + SetRadius /**< Setting the radius. */ + }; + + public: + RS_ActionDrawCircle(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawCircle(); + + virtual RS2::ActionType rtti(); + void reset(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + /** + * Circle data defined so far. + */ + RS_CircleData data; }; #endif diff --git a/src/actions/rs_actiondrawcircle2p.cpp b/src/actions/rs_actiondrawcircle2p.cpp index 7721e05..71c410a 100644 --- a/src/actions/rs_actiondrawcircle2p.cpp +++ b/src/actions/rs_actiondrawcircle2p.cpp @@ -1,245 +1,225 @@ -/**************************************************************************** -** $Id: rs_actiondrawcircle2p.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawcircle2p.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/03/2010 Added this text. :-) +// #include "rs_actiondrawcircle2p.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - -RS_ActionDrawCircle2P::RS_ActionDrawCircle2P(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw circles", - container, graphicView) { - reset(); +RS_ActionDrawCircle2P::RS_ActionDrawCircle2P(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw circles", + container, graphicView) +{ + reset(); } - - -RS_ActionDrawCircle2P::~RS_ActionDrawCircle2P() {} - - -QAction* RS_ActionDrawCircle2P::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawCircle2P::~RS_ActionDrawCircle2P() { - QAction * action = new QAction(tr("2 Points"), 0); -// QAction* action = new QAction(tr("Circle: 2 Points"), tr("2 Points"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw circles with 2 points")); - - return action; } - -void RS_ActionDrawCircle2P::reset() { - data.reset(); - point1 = Vector(false); - point2 = Vector(false); +void RS_ActionDrawCircle2P::reset() +{ + data.reset(); + point1 = Vector(false); + point2 = Vector(false); } +void RS_ActionDrawCircle2P::init(int status) +{ + RS_PreviewActionInterface::init(status); - -void RS_ActionDrawCircle2P::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); + reset(); } - - -void RS_ActionDrawCircle2P::trigger() { - RS_PreviewActionInterface::trigger(); - - preparePreview(); - if (data.isValid()) { - RS_Circle* circle = new RS_Circle(container, - data); - circle->setLayerToActive(); - circle->setPenToActive(); - container->addEntity(circle); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(circle); - document->endUndoCycle(); - } - - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(circle); - graphicView->moveRelativeZero(rz); - drawSnapper(); - - setStatus(SetPoint1); - reset(); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid Circle data.")); - } - } +void RS_ActionDrawCircle2P::trigger() +{ + RS_PreviewActionInterface::trigger(); + + preparePreview(); + + if (data.isValid()) + { + RS_Circle * circle = new RS_Circle(container, data); + circle->setLayerToActive(); + circle->setPenToActive(); + container->addEntity(circle); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(circle); + document->endUndoCycle(); + } + + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(circle); + graphicView->moveRelativeZero(rz); + drawSnapper(); + + setStatus(SetPoint1); + reset(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid Circle data.")); } +void RS_ActionDrawCircle2P::preparePreview() +{ + data.reset(); + if (point1.valid && point2.valid) + { + RS_Circle circle(NULL, data); + bool suc = circle.createFrom2P(point1, point2); -void RS_ActionDrawCircle2P::preparePreview() { - data.reset(); - if (point1.valid && point2.valid) { - RS_Circle circle(NULL, data); - bool suc = circle.createFrom2P(point1, point2); - if (suc) { - data = circle.getData(); - } - } + if (suc) + data = circle.getData(); + } } - -void RS_ActionDrawCircle2P::mouseMoveEvent(QMouseEvent* e) { - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetPoint1: - point1 = mouse; - break; - - case SetPoint2: - point2 = mouse; - preparePreview(); - if (data.isValid()) { - RS_Circle* circle = new RS_Circle(preview, data); - deletePreview(); - clearPreview(); - preview->addEntity(circle); - drawPreview(); - } - break; - - default: - break; - } +void RS_ActionDrawCircle2P::mouseMoveEvent(QMouseEvent * e) +{ + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetPoint1: + point1 = mouse; + break; + + case SetPoint2: + point2 = mouse; + preparePreview(); + + if (data.isValid()) + { + RS_Circle * circle = new RS_Circle(preview, data); + deletePreview(); + clearPreview(); + preview->addEntity(circle); + drawPreview(); + } + break; + + default: + break; + } } - - -void RS_ActionDrawCircle2P::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawCircle2P::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawCircle2P::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetPoint1: - point1 = mouse; - graphicView->moveRelativeZero(mouse); - setStatus(SetPoint2); - break; - - case SetPoint2: - point2 = mouse; - graphicView->moveRelativeZero(mouse); - trigger(); - break; - - default: - break; - } +void RS_ActionDrawCircle2P::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetPoint1: + point1 = mouse; + graphicView->moveRelativeZero(mouse); + setStatus(SetPoint2); + break; + + case SetPoint2: + point2 = mouse; + graphicView->moveRelativeZero(mouse); + trigger(); + break; + + default: + break; + } } - - -void RS_ActionDrawCircle2P::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_ActionDrawCircle2P::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } } - - -QStringList RS_ActionDrawCircle2P::getAvailableCommands() { - QStringList cmd; - return cmd; +QStringList RS_ActionDrawCircle2P::getAvailableCommands() +{ + QStringList cmd; + return cmd; } - - -void RS_ActionDrawCircle2P::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetPoint1: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify first point"), tr("Cancel")); - break; - case SetPoint2: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify second point"), tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDrawCircle2P::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetPoint1: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify first point"), tr("Cancel")); + break; + + case SetPoint2: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify second point"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } - - -void RS_ActionDrawCircle2P::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawCircle2P::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionDrawCircle2P::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); - } - } +void RS_ActionDrawCircle2P::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); + } } - // EOF diff --git a/src/actions/rs_actiondrawcircle2p.h b/src/actions/rs_actiondrawcircle2p.h index 6f95f5b..97c0ef5 100644 --- a/src/actions/rs_actiondrawcircle2p.h +++ b/src/actions/rs_actiondrawcircle2p.h @@ -1,90 +1,57 @@ -/**************************************************************************** -** $Id: rs_actiondrawcircle2p.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWCIRCLE2P_H #define RS_ACTIONDRAWCIRCLE2P_H -#include "rs_previewactioninterface.h" #include "rs_circle.h" +#include "rs_previewactioninterface.h" +#include "vector.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * simple arcs with the center, radius, start- and endangle given. * * @author Andrew Mustun */ -class RS_ActionDrawCircle2P : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetPoint1, /**< Setting the 1st point. */ - SetPoint2 /**< Setting the 2nd point. */ - }; - -public: - RS_ActionDrawCircle2P(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawCircle2P(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - void reset(); - - virtual void init(int status=0); - - virtual void trigger(); - void preparePreview(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - /** - * Circle data defined so far. - */ - RS_CircleData data; - /** - * 1st point. - */ - Vector point1; - /** - * 2nd point. - */ - Vector point2; +class RS_ActionDrawCircle2P: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetPoint1, /**< Setting the 1st point. */ + SetPoint2 /**< Setting the 2nd point. */ + }; + + public: + RS_ActionDrawCircle2P(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawCircle2P(); + + void reset(); + virtual void init(int status = 0); + virtual void trigger(); + void preparePreview(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + /** + * Circle data defined so far. + */ + RS_CircleData data; + /** + * 1st point. + */ + Vector point1; + /** + * 2nd point. + */ + Vector point2; }; #endif diff --git a/src/actions/rs_actiondrawcircle3p.cpp b/src/actions/rs_actiondrawcircle3p.cpp index ce4f29e..a659543 100644 --- a/src/actions/rs_actiondrawcircle3p.cpp +++ b/src/actions/rs_actiondrawcircle3p.cpp @@ -1,248 +1,231 @@ -/**************************************************************************** -** $Id: rs_actiondrawcircle3p.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawcircle3p.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/03/2010 Added this text. :-) +// #include "rs_actiondrawcircle3p.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionDrawCircle3P::RS_ActionDrawCircle3P(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw circles", - container, graphicView) { - reset(); -} - - - -RS_ActionDrawCircle3P::~RS_ActionDrawCircle3P() {} - - -QAction* RS_ActionDrawCircle3P::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawCircle3P::RS_ActionDrawCircle3P(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw circles", + container, graphicView) { - QAction * action = new QAction(tr("3 Points"), 0); -// QAction* action = new QAction(tr("Circle: 3 Points"), tr("3 Points"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw circles with 3 points")); - - return action; + reset(); } - - -void RS_ActionDrawCircle3P::reset() { - data.reset(); - point1 = Vector(false); - point2 = Vector(false); - point3 = Vector(false); +RS_ActionDrawCircle3P::~RS_ActionDrawCircle3P() +{ } - - -void RS_ActionDrawCircle3P::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); +void RS_ActionDrawCircle3P::reset() +{ + data.reset(); + point1 = Vector(false); + point2 = Vector(false); + point3 = Vector(false); } +void RS_ActionDrawCircle3P::init(int status) +{ + RS_PreviewActionInterface::init(status); - -void RS_ActionDrawCircle3P::trigger() { - RS_PreviewActionInterface::trigger(); - - preparePreview(); - if (data.isValid()) { - RS_Circle* circle = new RS_Circle(container, - data); - circle->setLayerToActive(); - circle->setPenToActive(); - container->addEntity(circle); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(circle); - document->endUndoCycle(); - } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(circle); - graphicView->moveRelativeZero(rz); - drawSnapper(); - - setStatus(SetPoint1); - reset(); - } else { - RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid circle data.")); - } + reset(); } - -void RS_ActionDrawCircle3P::preparePreview() { - data.reset(); - if (point1.valid && point2.valid && point3.valid) { - RS_Circle circle(NULL, data); - bool suc = circle.createFrom3P(point1, point2, point3); - if (suc) { - data = circle.getData(); - } - } +void RS_ActionDrawCircle3P::trigger() +{ + RS_PreviewActionInterface::trigger(); + + preparePreview(); + + if (data.isValid()) + { + RS_Circle * circle = new RS_Circle(container, + data); + circle->setLayerToActive(); + circle->setPenToActive(); + container->addEntity(circle); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(circle); + document->endUndoCycle(); + } + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(circle); + graphicView->moveRelativeZero(rz); + drawSnapper(); + + setStatus(SetPoint1); + reset(); + } + else + RS_DIALOGFACTORY->requestWarningDialog(tr("Invalid circle data.")); } +void RS_ActionDrawCircle3P::preparePreview() +{ + data.reset(); + if (point1.valid && point2.valid && point3.valid) + { + RS_Circle circle(NULL, data); + bool suc = circle.createFrom3P(point1, point2, point3); -void RS_ActionDrawCircle3P::mouseMoveEvent(QMouseEvent* e) { - Vector mouse = snapPoint(e); - - switch (getStatus()) { - case SetPoint1: - point1 = mouse; - break; - - case SetPoint2: - point2 = mouse; - break; - - case SetPoint3: - point3 = mouse; - preparePreview(); - if (data.isValid()) { - RS_Circle* circle = new RS_Circle(preview, data); - - deletePreview(); - clearPreview(); - preview->addEntity(circle); - drawPreview(); - } - break; - } + if (suc) + data = circle.getData(); + } } - - -void RS_ActionDrawCircle3P::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawCircle3P::mouseMoveEvent(QMouseEvent * e) +{ + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetPoint1: + point1 = mouse; + break; + + case SetPoint2: + point2 = mouse; + break; + + case SetPoint3: + point3 = mouse; + preparePreview(); + + if (data.isValid()) + { + RS_Circle * circle = new RS_Circle(preview, data); + + deletePreview(); + clearPreview(); + preview->addEntity(circle); + drawPreview(); + } + break; + } } - - -void RS_ActionDrawCircle3P::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetPoint1: - point1 = mouse; - graphicView->moveRelativeZero(mouse); - setStatus(SetPoint2); - break; - - case SetPoint2: - point2 = mouse; - graphicView->moveRelativeZero(mouse); - setStatus(SetPoint3); - break; - - case SetPoint3: - point3 = mouse; - trigger(); - break; - - default: - break; - } +void RS_ActionDrawCircle3P::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawCircle3P::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } +void RS_ActionDrawCircle3P::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetPoint1: + point1 = mouse; + graphicView->moveRelativeZero(mouse); + setStatus(SetPoint2); + break; + + case SetPoint2: + point2 = mouse; + graphicView->moveRelativeZero(mouse); + setStatus(SetPoint3); + break; + + case SetPoint3: + point3 = mouse; + trigger(); + break; + + default: + break; + } } - - -QStringList RS_ActionDrawCircle3P::getAvailableCommands() { - QStringList cmd; - return cmd; +void RS_ActionDrawCircle3P::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } } - -void RS_ActionDrawCircle3P::updateMouseButtonHints() { - switch (getStatus()) { - case SetPoint1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), - tr("Cancel")); - break; - case SetPoint2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), - tr("Back")); - break; - case SetPoint3: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify third point"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +QStringList RS_ActionDrawCircle3P::getAvailableCommands() +{ + QStringList cmd; + return cmd; } - - -void RS_ActionDrawCircle3P::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawCircle3P::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetPoint1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), + tr("Cancel")); + break; + + case SetPoint2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), + tr("Back")); + break; + + case SetPoint3: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify third point"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionDrawCircle3P::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); - } +void RS_ActionDrawCircle3P::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionDrawCircle3P::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); +} // EOF diff --git a/src/actions/rs_actiondrawcircle3p.h b/src/actions/rs_actiondrawcircle3p.h index 7ae4d97..695cc2f 100644 --- a/src/actions/rs_actiondrawcircle3p.h +++ b/src/actions/rs_actiondrawcircle3p.h @@ -1,95 +1,62 @@ -/**************************************************************************** -** $Id: rs_actiondrawcircle3p.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWCIRCLE3P_H #define RS_ACTIONDRAWCIRCLE3P_H -#include "rs_previewactioninterface.h" #include "rs_circle.h" +#include "rs_previewactioninterface.h" +#include "vector.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * circles with three points given. * * @author Andrew Mustun */ -class RS_ActionDrawCircle3P : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetPoint1, /**< Setting the 1st point. */ - SetPoint2, /**< Setting the 2nd point. */ - SetPoint3 /**< Setting the 3rd point. */ - }; - -public: - RS_ActionDrawCircle3P(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawCircle3P(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - void reset(); - - virtual void init(int status=0); - - virtual void trigger(); - void preparePreview(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - /** - * Circle data defined so far. - */ - RS_CircleData data; - /** - * 1st point. - */ - Vector point1; - /** - * 2nd point. - */ - Vector point2; - /** - * 3nd point. - */ - Vector point3; +class RS_ActionDrawCircle3P: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetPoint1, /**< Setting the 1st point. */ + SetPoint2, /**< Setting the 2nd point. */ + SetPoint3 /**< Setting the 3rd point. */ + }; + + public: + RS_ActionDrawCircle3P(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawCircle3P(); + + void reset(); + virtual void init(int status = 0); + virtual void trigger(); + void preparePreview(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + /** + * Circle data defined so far. + */ + RS_CircleData data; + /** + * 1st point. + */ + Vector point1; + /** + * 2nd point. + */ + Vector point2; + /** + * 3nd point. + */ + Vector point3; }; #endif diff --git a/src/actions/rs_actiondrawcirclecr.cpp b/src/actions/rs_actiondrawcirclecr.cpp index 085c6e6..1825b4f 100644 --- a/src/actions/rs_actiondrawcirclecr.cpp +++ b/src/actions/rs_actiondrawcirclecr.cpp @@ -1,255 +1,248 @@ -/**************************************************************************** -** $Id: rs_actiondrawcirclecr.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawcirclecr.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/03/2010 Added this text. :-) +// #include "rs_actiondrawcirclecr.h" -#include "rs_snapper.h" + +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" /** * Constructor. */ -RS_ActionDrawCircleCR::RS_ActionDrawCircleCR(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw circles CR", - container, graphicView) { - - reset(); +RS_ActionDrawCircleCR::RS_ActionDrawCircleCR(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw circles CR", + container, graphicView) +{ + reset(); } - - -RS_ActionDrawCircleCR::~RS_ActionDrawCircleCR() {} - - -QAction* RS_ActionDrawCircleCR::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawCircleCR::~RS_ActionDrawCircleCR() { - QAction * action = new QAction(tr("Center, &Radius"), 0); -// QAction* action = new QAction(tr("Circle: Center, Radius"), -// tr("Center, &Radius"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw circles with center and radius")); - return action; } - -void RS_ActionDrawCircleCR::reset() { - data = RS_CircleData(Vector(false), 0.0); +/*virtual*/ RS2::ActionType RS_ActionDrawCircleCR::rtti() +{ + return RS2::ActionDrawCircleCR; } - - -void RS_ActionDrawCircleCR::init(int status) { - RS_PreviewActionInterface::init(status); +void RS_ActionDrawCircleCR::reset() +{ + data = RS_CircleData(Vector(false), 0.0); } - - -void RS_ActionDrawCircleCR::trigger() { - RS_PreviewActionInterface::trigger(); - - RS_Circle* circle = new RS_Circle(container, - data); - circle->setLayerToActive(); - circle->setPenToActive(); - container->addEntity(circle); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(circle); - document->endUndoCycle(); - } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(circle); - graphicView->moveRelativeZero(circle->getCenter()); - drawSnapper(); - - setStatus(SetCenter); - - RS_DEBUG->print("RS_ActionDrawCircleCR::trigger(): circle added: %d", - circle->getId()); +void RS_ActionDrawCircleCR::init(int status) +{ + RS_PreviewActionInterface::init(status); } - - -void RS_ActionDrawCircleCR::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawCircleCR::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetCenter: - data.center = mouse; - deletePreview(); - clearPreview(); - preview->addEntity(new RS_Circle(preview, - data)); - drawPreview(); - break; - } - - RS_DEBUG->print("RS_ActionDrawCircleCR::mouseMoveEvent end"); +void RS_ActionDrawCircleCR::trigger() +{ + RS_PreviewActionInterface::trigger(); + + RS_Circle * circle = new RS_Circle(container, data); + circle->setLayerToActive(); + circle->setPenToActive(); + container->addEntity(circle); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(circle); + document->endUndoCycle(); + } + + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(circle); + graphicView->moveRelativeZero(circle->getCenter()); + drawSnapper(); + + setStatus(SetCenter); + + RS_DEBUG->print("RS_ActionDrawCircleCR::trigger(): circle added: %d", circle->getId()); } - - -void RS_ActionDrawCircleCR::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawCircleCR::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawCircleCR::mouseMoveEvent begin"); + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetCenter: + data.center = mouse; + deletePreview(); + clearPreview(); + preview->addEntity(new RS_Circle(preview, data)); + drawPreview(); + break; + } + + RS_DEBUG->print("RS_ActionDrawCircleCR::mouseMoveEvent end"); } - - -void RS_ActionDrawCircleCR::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetCenter: - data.center = mouse; - trigger(); - break; - - default: - break; - } +void RS_ActionDrawCircleCR::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } +void RS_ActionDrawCircleCR::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + Vector mouse = *e; -void RS_ActionDrawCircleCR::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - switch (getStatus()) { - case SetCenter: - if (checkCommand("radius", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetRadius); - } - break; - - case SetRadius: { - bool ok; - double r = RS_Math::eval(c, &ok); - if (ok==true) { - data.radius = r; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(SetCenter); - } - break; + switch (getStatus()) + { + case SetCenter: + data.center = mouse; + trigger(); + break; - default: - break; - } + default: + break; + } } +void RS_ActionDrawCircleCR::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + switch (getStatus()) + { + case SetCenter: + + if (checkCommand("radius", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetRadius); + } + break; + + case SetRadius: + { + bool ok; + double r = RS_Math::eval(c, &ok); + + if (ok == true) + data.radius = r; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(SetCenter); + } + break; + + default: + break; + } +} +QStringList RS_ActionDrawCircleCR::getAvailableCommands() +{ + QStringList cmd; -QStringList RS_ActionDrawCircleCR::getAvailableCommands() { - QStringList cmd; + switch (getStatus()) + { + case SetCenter: + cmd += command("radius"); + break; - switch (getStatus()) { - case SetCenter: - cmd += command("radius"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } -void RS_ActionDrawCircleCR::updateMouseButtonHints() { - switch (getStatus()) { - case SetCenter: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle center"), - tr("Cancel")); - break; - case SetRadius: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle radius"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDrawCircleCR::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetCenter: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle center"), tr("Cancel")); + break; + + case SetRadius: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify circle radius"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } +void RS_ActionDrawCircleCR::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDrawCircleCR::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDrawCircleCR::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawCircleCR::hideOptions() { - RS_ActionInterface::hideOptions(); - - RS_DIALOGFACTORY->requestOptions(this, false); + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionDrawCircleCR::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawCircleCR::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionDrawCircleCR::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); - } +void RS_ActionDrawCircleCR::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarCircles); } +double RS_ActionDrawCircleCR::getRadius() +{ + return data.radius; +} -// EOF +void RS_ActionDrawCircleCR::setRadius(double r) +{ + data.radius = r; +} diff --git a/src/actions/rs_actiondrawcirclecr.h b/src/actions/rs_actiondrawcirclecr.h index 940f2a5..f60f461 100644 --- a/src/actions/rs_actiondrawcirclecr.h +++ b/src/actions/rs_actiondrawcirclecr.h @@ -1,97 +1,52 @@ -/**************************************************************************** -** $Id: rs_actiondrawcirclecr.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWCIRCLECR_H #define RS_ACTIONDRAWCIRCLECR_H -#include "rs_previewactioninterface.h" #include "rs_circle.h" +#include "rs_previewactioninterface.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * simple arcs with the center, radius, start- and endangle given. * * @author Andrew Mustun */ -class RS_ActionDrawCircleCR : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetCenter, /**< Setting the center point. */ - SetRadius /**< Setting radius in command line. */ - }; - -public: - RS_ActionDrawCircleCR(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawCircleCR(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawCircleCR; - } - - void reset(); - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - double getRadius() { - return data.radius; - } - - void setRadius(double r) { - data.radius = r; - } - -protected: - /** - * Circle data defined so far. - */ - RS_CircleData data; - +class RS_ActionDrawCircleCR: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetCenter, /**< Setting the center point. */ + SetRadius /**< Setting radius in command line. */ + }; + + public: + RS_ActionDrawCircleCR(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawCircleCR(); + + virtual RS2::ActionType rtti(); + void reset(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + double getRadius(); + void setRadius(double r); + + protected: + /** + * Circle data defined so far. + */ + RS_CircleData data; }; #endif diff --git a/src/actions/rs_actiondrawellipseaxis.cpp b/src/actions/rs_actiondrawellipseaxis.cpp index 35c3bb4..a262fa1 100644 --- a/src/actions/rs_actiondrawellipseaxis.cpp +++ b/src/actions/rs_actiondrawellipseaxis.cpp @@ -13,7 +13,10 @@ // #include "rs_actiondrawellipseaxis.h" -#include "rs_snapper.h" + +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" /** * Constructor. @@ -21,401 +24,374 @@ * @param isArc true if this action will produce an ellipse arc. * false if it will produce a full ellipse. */ -RS_ActionDrawEllipseAxis::RS_ActionDrawEllipseAxis( - RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool isArc) - :RS_PreviewActionInterface("Draw ellipse with axis", - container, graphicView) { - - this->isArc = isArc; - center = Vector(false); - major = Vector(false); - ratio = 0.5; - angle1 = 0.0; - angle2 = 2*M_PI; +RS_ActionDrawEllipseAxis::RS_ActionDrawEllipseAxis(RS_EntityContainer & container, RS_GraphicView & graphicView, bool isArc): RS_PreviewActionInterface("Draw ellipse with axis", + container, graphicView) +{ + this->isArc = isArc; + center = Vector(false); + major = Vector(false); + ratio = 0.5; + angle1 = 0.0; + angle2 = 2 * M_PI; } RS_ActionDrawEllipseAxis::~RS_ActionDrawEllipseAxis() { } -QAction * RS_ActionDrawEllipseAxis::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +void RS_ActionDrawEllipseAxis::init(int status) { - QAction * action; + RS_PreviewActionInterface::init(status); - if (type==RS2::ActionDrawEllipseArcAxis) - { - action = new QAction(tr("&Ellipse Arc (Axis)"), 0); -// action = new QAction(tr("Ellipse Arc with Axis"), -// tr("&Ellipse Arc (Axis)"), QKeySequence(), NULL); - action->setStatusTip(tr("Draw Ellipse Arcs")); - } - else - { - action = new QAction(tr("&Ellipse (Axis)"), 0); -// action = new QAction(tr("Ellipse with Axis"), -// tr("&Ellipse (Axis)"), QKeySequence(), NULL); - action->setStatusTip(tr("Draw Ellipses")); - } - return action; -} + if (status == SetCenter) + center = Vector(false); -void RS_ActionDrawEllipseAxis::init(int status) -{ - RS_PreviewActionInterface::init(status); + if (status <= SetMajor) + major = Vector(false); - if (status==SetCenter) - { - center = Vector(false); - } - if (status<=SetMajor) - { - major = Vector(false); - } - if (status<=SetMinor) - { - ratio = 0.5; - } - if (status<=SetAngle1) - { - angle1 = 0.0; - } - if (status<=SetAngle2) - { - angle2 = 2*M_PI; - } -} + if (status <= SetMinor) + ratio = 0.5; + if (status <= SetAngle1) + angle1 = 0.0; + if (status <= SetAngle2) + angle2 = 2 * M_PI; +} -void RS_ActionDrawEllipseAxis::trigger() { - RS_PreviewActionInterface::trigger(); +void RS_ActionDrawEllipseAxis::trigger() +{ + RS_PreviewActionInterface::trigger(); - RS_EllipseData ellipseData(center, major, - ratio, - angle1, angle2, - false); - RS_Ellipse* ellipse = new RS_Ellipse(container, ellipseData); - ellipse->setLayerToActive(); - ellipse->setPenToActive(); + RS_EllipseData ellipseData(center, major, ratio, angle1, angle2, false); + RS_Ellipse * ellipse = new RS_Ellipse(container, ellipseData); + ellipse->setLayerToActive(); + ellipse->setPenToActive(); - container->addEntity(ellipse); + container->addEntity(ellipse); - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(ellipse); - document->endUndoCycle(); - } + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(ellipse); + document->endUndoCycle(); + } - deleteSnapper(); - Vector rz = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(ellipse); - graphicView->moveRelativeZero(rz); - drawSnapper(); + deleteSnapper(); + Vector rz = graphicView->getRelativeZero(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(ellipse); + graphicView->moveRelativeZero(rz); + drawSnapper(); - setStatus(SetCenter); + setStatus(SetCenter); - RS_DEBUG->print("RS_ActionDrawEllipseAxis::trigger():" - " entity added: %d", ellipse->getId()); + RS_DEBUG->print("RS_ActionDrawEllipseAxis::trigger():" + " entity added: %d", ellipse->getId()); } +void RS_ActionDrawEllipseAxis::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawEllipseAxis::mouseMoveEvent begin"); + Vector mouse = snapPoint(e); -void RS_ActionDrawEllipseAxis::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawEllipseAxis::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); - - switch (getStatus()) { - case SetCenter: - break; - - case SetMajor: - if (center.valid) { - deletePreview(); - clearPreview(); - RS_EllipseData ed(center, mouse-center, - 0.5, - 0.0, 2*M_PI, - false); - preview->addEntity(new RS_Ellipse(preview, ed)); - drawPreview(); - } - break; - - case SetMinor: - if (center.valid && major.valid) { - deletePreview(); - clearPreview(); - RS_Line line(NULL, RS_LineData(center-major, center+major)); - double d = line.getDistanceToPoint(mouse); - ratio = d/(line.getLength()/2); - RS_EllipseData ed(center, major, - ratio, - 0.0, 2*M_PI, - false); - preview->addEntity(new RS_Ellipse(preview, ed)); - drawPreview(); - } - break; - - case SetAngle1: - if (center.valid && major.valid) { - deletePreview(); - clearPreview(); - - //angle1 = center.angleTo(mouse); + switch (getStatus()) + { + case SetCenter: + break; + + case SetMajor: + + if (center.valid) + { + deletePreview(); + clearPreview(); + RS_EllipseData ed(center, mouse - center, 0.5, 0.0, 2 * M_PI, false); + preview->addEntity(new RS_Ellipse(preview, ed)); + drawPreview(); + } + break; + + case SetMinor: + + if (center.valid && major.valid) + { + deletePreview(); + clearPreview(); + RS_Line line(NULL, RS_LineData(center - major, center + major)); + double d = line.getDistanceToPoint(mouse); + ratio = d / (line.getLength() / 2); + RS_EllipseData ed(center, major, ratio, 0.0, 2 * M_PI, false); + preview->addEntity(new RS_Ellipse(preview, ed)); + drawPreview(); + } + break; + + case SetAngle1: + + if (center.valid && major.valid) + { + deletePreview(); + clearPreview(); + + //angle1 = center.angleTo(mouse); Vector m = mouse; m.rotate(center, -major.angle()); - Vector v = m-center; - v.scale(Vector(1.0, 1.0/ratio)); + Vector v = m - center; + v.scale(Vector(1.0, 1.0 / ratio)); angle1 = v.angle(); // + major.angle(); - preview->addEntity(new RS_Line(preview, RS_LineData(center, mouse))); + preview->addEntity(new RS_Line(preview, RS_LineData(center, mouse))); - RS_EllipseData ed(center, major, - ratio, - angle1, angle1+1.0, - false); - preview->addEntity(new RS_Ellipse(preview, ed)); - drawPreview(); - } - break; + RS_EllipseData ed(center, major, ratio, angle1, angle1 + 1.0, false); + preview->addEntity(new RS_Ellipse(preview, ed)); + drawPreview(); + } + break; - case SetAngle2: - if (center.valid && major.valid) { - deletePreview(); - clearPreview(); - //angle2 = center.angleTo(mouse); + case SetAngle2: + + if (center.valid && major.valid) + { + deletePreview(); + clearPreview(); + //angle2 = center.angleTo(mouse); Vector m = mouse; m.rotate(center, -major.angle()); - Vector v = m-center; - v.scale(Vector(1.0, 1.0/ratio)); + Vector v = m - center; + v.scale(Vector(1.0, 1.0 / ratio)); angle2 = v.angle(); // + major.angle(); - preview->addEntity(new RS_Line(preview, RS_LineData(center, mouse))); + preview->addEntity(new RS_Line(preview, RS_LineData(center, mouse))); - RS_EllipseData ed( - center, major, - ratio, - angle1, angle2, - false); - preview->addEntity(new RS_Ellipse(preview, ed)); - drawPreview(); - } + RS_EllipseData ed( + center, major, ratio, angle1, angle2, false); + preview->addEntity(new RS_Ellipse(preview, ed)); + drawPreview(); + } - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionDrawEllipseAxis::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDrawEllipseAxis::mouseMoveEvent end"); } +void RS_ActionDrawEllipseAxis::mouseReleaseEvent(QMouseEvent * e) +{ + // Proceed to next status +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + // Return to last status: +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } +} +void RS_ActionDrawEllipseAxis::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; -void RS_ActionDrawEllipseAxis::mouseReleaseEvent(QMouseEvent* e) { - // Proceed to next status - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - - // Return to last status: - else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } -} + Vector mouse = *e; + switch (getStatus()) + { + case SetCenter: + center = mouse; + graphicView->moveRelativeZero(mouse); + setStatus(SetMajor); + break; + + case SetMajor: + major = mouse - center; + setStatus(SetMinor); + break; + + case SetMinor: + { + RS_Line line(NULL, RS_LineData(center - major, center + major)); + double d = line.getDistanceToPoint(mouse); + ratio = d / (line.getLength() / 2); + + if (!isArc) + { + trigger(); + setStatus(SetCenter); + } + else + setStatus(SetAngle1); + } + break; -void RS_ActionDrawEllipseAxis::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetCenter: - center = mouse; - graphicView->moveRelativeZero(mouse); - setStatus(SetMajor); - break; - - case SetMajor: - major = mouse-center; - setStatus(SetMinor); - break; - - case SetMinor: { - RS_Line line(NULL, RS_LineData(center-major, center+major)); - double d = line.getDistanceToPoint(mouse); - ratio = d/(line.getLength()/2); - if (!isArc) { - trigger(); - setStatus(SetCenter); - } else { - setStatus(SetAngle1); - } - } - break; - - case SetAngle1: { - //angle1 = center.angleTo(mouse); + case SetAngle1: + { + //angle1 = center.angleTo(mouse); Vector m = mouse; m.rotate(center, -major.angle()); - Vector v = m-center; - v.scale(Vector(1.0, 1.0/ratio)); + Vector v = m - center; + v.scale(Vector(1.0, 1.0 / ratio)); angle1 = v.angle(); - setStatus(SetAngle2); - } break; + setStatus(SetAngle2); + } + break; - case SetAngle2: { - //angle2 = center.angleTo(mouse); + case SetAngle2: + { + //angle2 = center.angleTo(mouse); Vector m = mouse; m.rotate(center, -major.angle()); - Vector v = m-center; - v.scale(Vector(1.0, 1.0/ratio)); + Vector v = m - center; + v.scale(Vector(1.0, 1.0 / ratio)); angle2 = v.angle(); - trigger(); - } break; + trigger(); + } + break; - default: - break; - } + default: + break; + } } +void RS_ActionDrawEllipseAxis::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_ActionDrawEllipseAxis::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 SetMinor: { - bool ok; - double m = RS_Math::eval(c, &ok); - if (ok==true) { - ratio = m / major.magnitude(); - if (!isArc) { - trigger(); - } else { - setStatus(SetAngle1); - } - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - case SetAngle1: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - angle1 = RS_Math::deg2rad(a); - setStatus(SetAngle2); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - case SetAngle2: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - angle2 = RS_Math::deg2rad(a); - trigger(); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - } - break; - - default: - break; - } -} + switch (getStatus()) + { + case SetMinor: { + bool ok; + double m = RS_Math::eval(c, &ok); + + if (ok == true) + { + ratio = m / major.magnitude(); + + if (!isArc) + trigger(); + else + setStatus(SetAngle1); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + } + break; + case SetAngle1: { + bool ok; + double a = RS_Math::eval(c, &ok); -QStringList RS_ActionDrawEllipseAxis::getAvailableCommands() { - QStringList cmd; - return cmd; -} + if (ok == true) + { + angle1 = RS_Math::deg2rad(a); + setStatus(SetAngle2); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + } + break; + case SetAngle2: { + bool ok; + double a = RS_Math::eval(c, &ok); -void RS_ActionDrawEllipseAxis::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetCenter: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify ellipse center"), - tr("Cancel")); - break; - - case SetMajor: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify endpoint of major axis"), - tr("Back")); - break; - - case SetMinor: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify endpoint or length of minor axis:"), - tr("Back")); - break; - - case SetAngle1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify start angle"), - tr("Back")); - break; - - case SetAngle2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify end angle"), - tr("Back")); - break; - - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } -} + if (ok == true) + { + angle2 = RS_Math::deg2rad(a); + trigger(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + } + break; + default: + break; + } +} -void RS_ActionDrawEllipseAxis::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +QStringList RS_ActionDrawEllipseAxis::getAvailableCommands() +{ + QStringList cmd; + return cmd; } +void RS_ActionDrawEllipseAxis::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetCenter: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify ellipse center"), + tr("Cancel")); + break; + + case SetMajor: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify endpoint of major axis"), + tr("Back")); + break; + + case SetMinor: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify endpoint or length of minor axis:"), + tr("Back")); + break; + + case SetAngle1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify start angle"), + tr("Back")); + break; + + case SetAngle2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify end angle"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } +} +void RS_ActionDrawEllipseAxis::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} -void RS_ActionDrawEllipseAxis::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarEllipses); - } - } +void RS_ActionDrawEllipseAxis::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarEllipses); + } } // EOF diff --git a/src/actions/rs_actiondrawellipseaxis.h b/src/actions/rs_actiondrawellipseaxis.h index 04917f0..67796f7 100644 --- a/src/actions/rs_actiondrawellipseaxis.h +++ b/src/actions/rs_actiondrawellipseaxis.h @@ -1,34 +1,8 @@ -/**************************************************************************** -** $Id: rs_actiondrawellipseaxis.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWELLIPSEAXIS_H #define RS_ACTIONDRAWELLIPSEAXIS_H -#include "rs_previewactioninterface.h" #include "rs_ellipse.h" +#include "rs_previewactioninterface.h" /** * This action class can handle user events to draw ellipses @@ -36,56 +10,48 @@ * * @author Andrew Mustun */ -class RS_ActionDrawEllipseAxis : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetCenter, /**< Settinge the center. */ - SetMajor, /**< Setting endpoint of major axis. */ - SetMinor, /**< Setting minor/major ratio. */ - SetAngle1, /**< Setting start angle. */ - SetAngle2 /**< Setting end angle. */ - }; - -public: - RS_ActionDrawEllipseAxis(RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool isArc); - ~RS_ActionDrawEllipseAxis(); - - static QAction* createGUIAction(RS2::ActionType type, QObject* /*parent*/); - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - /** Center of ellipse */ - Vector center; - /** Endpoint of major axis */ - Vector major; - /** Ratio major / minor */ - double ratio; - /** Start angle */ - double angle1; - /** End angle */ - double angle2; - /** Do we produce an arc (true) or full ellipse (false) */ - bool isArc; +class RS_ActionDrawEllipseAxis: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetCenter, /**< Settinge the center. */ + SetMajor, /**< Setting endpoint of major axis. */ + SetMinor, /**< Setting minor/major ratio. */ + SetAngle1, /**< Setting start angle. */ + SetAngle2 /**< Setting end angle. */ + }; + + public: + RS_ActionDrawEllipseAxis(RS_EntityContainer & container, RS_GraphicView & graphicView, bool isArc); + ~RS_ActionDrawEllipseAxis(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + /** Center of ellipse */ + Vector center; + /** Endpoint of major axis */ + Vector major; + /** Ratio major / minor */ + double ratio; + /** Start angle */ + double angle1; + /** End angle */ + double angle2; + /** Do we produce an arc (true) or full ellipse (false) */ + bool isArc; }; #endif diff --git a/src/actions/rs_actiondrawhatch.cpp b/src/actions/rs_actiondrawhatch.cpp index 8d01bf5..096d959 100644 --- a/src/actions/rs_actiondrawhatch.cpp +++ b/src/actions/rs_actiondrawhatch.cpp @@ -1,147 +1,129 @@ -/**************************************************************************** -** $Id: rs_actiondrawhatch.cpp 2381 2005-05-16 17:05:44Z 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_actiondrawhatch.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 05/22/2010 Added this text. :-) +// #include "rs_actiondrawhatch.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" #include "rs_graphicview.h" #include "rs_information.h" -RS_ActionDrawHatch::RS_ActionDrawHatch(RS_EntityContainer& container, - RS_GraphicView& graphicView): +RS_ActionDrawHatch::RS_ActionDrawHatch(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Hatch", container, graphicView) { - hatch = NULL; + hatch = NULL; } -QAction * RS_ActionDrawHatch::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawHatch::~RS_ActionDrawHatch() { - QAction * action = new QAction(tr("&Hatch"), 0); -// QAction* action = new QAction(tr("Hatch"), tr("&Hatch"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw Hatches and Solid Fills")); - return action; } void RS_ActionDrawHatch::init(int status) { - RS_ActionInterface::init(status); - - clearPreview(); - - RS_Hatch tmp(container, data); - tmp.setLayerToActive(); - tmp.setPenToActive(); - if (RS_DIALOGFACTORY->requestHatchDialog(&tmp)) { - data = tmp.getData(); - trigger(); - finish(); - graphicView->redraw(); - } else { - finish(); - } + RS_ActionInterface::init(status); + clearPreview(); + + RS_Hatch tmp(container, data); + tmp.setLayerToActive(); + tmp.setPenToActive(); + + if (RS_DIALOGFACTORY->requestHatchDialog(&tmp)) + { + data = tmp.getData(); + trigger(); + finish(); + graphicView->redraw(); + } + else + finish(); } +void RS_ActionDrawHatch::trigger() +{ + RS_DEBUG->print("RS_ActionDrawHatch::trigger()"); - -void RS_ActionDrawHatch::trigger() { - - RS_DEBUG->print("RS_ActionDrawHatch::trigger()"); - - //if (pos.valid) { - //deletePreview(); - deleteSnapper(); - RS_Entity* e; + //if (pos.valid) { + //deletePreview(); + deleteSnapper(); + RS_Entity * e; // deselect unhatchable entities: - for (e=container->firstEntity(RS2::ResolveNone); e!=NULL; - e=container->nextEntity(RS2::ResolveNone)) { - if (e->isSelected() && - (e->rtti()==RS2::EntityHatch || - e->rtti()==RS2::EntityEllipse || e->rtti()==RS2::EntityPoint || - e->rtti()==RS2::EntityText || - RS_Information::isDimension(e->rtti()))) { + for (e = container->firstEntity(RS2::ResolveNone); e != NULL; + e = container->nextEntity(RS2::ResolveNone)) + if (e->isSelected() + && (e->rtti() == RS2::EntityHatch + || e->rtti() == RS2::EntityEllipse || e->rtti() == RS2::EntityPoint + || e->rtti() == RS2::EntityText + || RS_Information::isDimension(e->rtti()))) e->setSelected(false); - } - } - for (e=container->firstEntity(RS2::ResolveAll); e!=NULL; - e=container->nextEntity(RS2::ResolveAll)) { - if (e->isSelected() && - (e->rtti()==RS2::EntityHatch || - e->rtti()==RS2::EntityEllipse || e->rtti()==RS2::EntityPoint || - e->rtti()==RS2::EntityText || - RS_Information::isDimension(e->rtti()))) { + + + for (e = container->firstEntity(RS2::ResolveAll); e != NULL; + e = container->nextEntity(RS2::ResolveAll)) + if (e->isSelected() + && (e->rtti() == RS2::EntityHatch + || e->rtti() == RS2::EntityEllipse || e->rtti() == RS2::EntityPoint + || e->rtti() == RS2::EntityText + || RS_Information::isDimension(e->rtti()))) e->setSelected(false); - } - } // look for selected contours: - bool haveContour = false; - for (e=container->firstEntity(RS2::ResolveAll); e!=NULL; - e=container->nextEntity(RS2::ResolveAll)) { - if (e->isSelected()) { - haveContour = true; - } - } - - if (!haveContour) { - std::cerr << "no contour selected\n"; - return; - } - - hatch = new RS_Hatch(container, data); - hatch->setLayerToActive(); - hatch->setPenToActive(); - RS_EntityContainer* loop = new RS_EntityContainer(hatch); - loop->setPen(RS_Pen(RS2::FlagInvalid)); - - // add selected contour: - for (RS_Entity* e=container->firstEntity(RS2::ResolveAll); e!=NULL; - e=container->nextEntity(RS2::ResolveAll)) { - - if (e->isSelected()) { - e->setSelected(false); + bool haveContour = false; + + for (e = container->firstEntity(RS2::ResolveAll); e != NULL; + e = container->nextEntity(RS2::ResolveAll)) + if (e->isSelected()) + haveContour = true; + + if (!haveContour) + { + std::cerr << "no contour selected\n"; + return; + } + + hatch = new RS_Hatch(container, data); + hatch->setLayerToActive(); + hatch->setPenToActive(); + RS_EntityContainer * loop = new RS_EntityContainer(hatch); + loop->setPen(RS_Pen(RS2::FlagInvalid)); + + // add selected contour: + for (RS_Entity * e = container->firstEntity(RS2::ResolveAll); e != NULL; + e = container->nextEntity(RS2::ResolveAll)) + + if (e->isSelected()) + { + e->setSelected(false); + // entity is part of a complex entity (spline, polyline, ..): - if (e->getParent()!=NULL && - (e->getParent()->rtti()==RS2::EntitySpline || - e->getParent()->rtti()==RS2::EntityPolyline)) { + if (e->getParent() != NULL + && (e->getParent()->rtti() == RS2::EntitySpline + || e->getParent()->rtti() == RS2::EntityPolyline)) e->getParent()->setSelected(false); - } - RS_Entity* cp = e->clone(); - cp->setPen(RS_Pen(RS2::FlagInvalid)); - cp->reparent(loop); - loop->addEntity(cp); - } - } - - hatch->addEntity(loop); - if (hatch->validate()) { + RS_Entity * cp = e->clone(); + cp->setPen(RS_Pen(RS2::FlagInvalid)); + cp->reparent(loop); + loop->addEntity(cp); + } + + hatch->addEntity(loop); + + if (hatch->validate()) + { container->addEntity(hatch); - if (document) { + if (document) + { document->startUndoCycle(); document->addUndoable(hatch); document->endUndoCycle(); @@ -152,74 +134,74 @@ void RS_ActionDrawHatch::trigger() { RS_DIALOGFACTORY->commandMessage(tr("Hatch created successfully.")); } - else { + else + { delete hatch; hatch = NULL; RS_DIALOGFACTORY->commandMessage(tr("Invalid hatch area. Please check that " - "the entities chosen form one or more closed contours.")); + "the entities chosen form one or more closed contours.")); } - //} + //} } +void RS_ActionDrawHatch::mouseMoveEvent(QMouseEvent *) +{ + RS_DEBUG->print("RS_ActionDrawHatch::mouseMoveEvent begin"); - -void RS_ActionDrawHatch::mouseMoveEvent(QMouseEvent*) { - RS_DEBUG->print("RS_ActionDrawHatch::mouseMoveEvent begin"); - - /*if (getStatus()==SetPos) { - Vector mouse = snapPoint(e); - pos = mouse; + /*if (getStatus()==SetPos) { + Vector mouse = snapPoint(e); + pos = mouse; - deletePreview(); - if (hatch!=NULL && !hatch->isVisible()) { - hatch->setVisible(true); - } - offset = Vector(graphicView->toGuiDX(pos.x), - -graphicView->toGuiDY(pos.y)); - drawPreview(); -}*/ + deletePreview(); + if (hatch!=NULL && !hatch->isVisible()) { + hatch->setVisible(true); + } + offset = Vector(graphicView->toGuiDX(pos.x), + -graphicView->toGuiDY(pos.y)); + drawPreview(); + }*/ - RS_DEBUG->print("RS_ActionDrawHatch::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDrawHatch::mouseMoveEvent end"); } - - -void RS_ActionDrawHatch::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - Vector mouse = snapPoint(e); - - switch (getStatus()) { - case ShowDialog: - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - //deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawHatch::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case ShowDialog: + break; + + default: + break; + } + } +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + //deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawHatch::updateMouseButtonHints() { - RS_DIALOGFACTORY->updateMouseWidget("", ""); +void RS_ActionDrawHatch::updateMouseButtonHints() +{ + RS_DIALOGFACTORY->updateMouseWidget("", ""); } - - -void RS_ActionDrawHatch::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawHatch::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionDrawHatch::updateToolBar() { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); +void RS_ActionDrawHatch::updateToolBar() +{ + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); } - -// EOF diff --git a/src/actions/rs_actiondrawhatch.h b/src/actions/rs_actiondrawhatch.h index 618f66e..c632753 100644 --- a/src/actions/rs_actiondrawhatch.h +++ b/src/actions/rs_actiondrawhatch.h @@ -1,69 +1,39 @@ -/**************************************************************************** -** $Id: rs_actiondrawhatch.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWHATCH_H #define RS_ACTIONDRAWHATCH_H -#include "rs_previewactioninterface.h" #include "rs_hatch.h" - +#include "rs_previewactioninterface.h" /** * This action class can handle user events to draw hatches. * * @author Andrew Mustun */ -class RS_ActionDrawHatch : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - ShowDialog /**< Showing the hatch dialog. */ - }; - -public: - RS_ActionDrawHatch(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawHatch() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_HatchData data; - RS_Hatch* hatch; +class RS_ActionDrawHatch: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + ShowDialog /**< Showing the hatch dialog. */ + }; + + public: + RS_ActionDrawHatch(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawHatch(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_HatchData data; + RS_Hatch * hatch; }; #endif diff --git a/src/actions/rs_actiondrawimage.cpp b/src/actions/rs_actiondrawimage.cpp index 65ae1c9..d68e5b5 100644 --- a/src/actions/rs_actiondrawimage.cpp +++ b/src/actions/rs_actiondrawimage.cpp @@ -1,40 +1,28 @@ -/**************************************************************************** -** $Id: rs_actiondrawimage.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawimage.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 05/22/2010 Added this text. :-) +// #include "rs_actiondrawimage.h" #include "rs_creation.h" -#include "commands.h" -#include "rs_modification.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" /** * Constructor. */ -RS_ActionDrawImage::RS_ActionDrawImage(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionDrawImage::RS_ActionDrawImage(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Image", container, graphicView) { } @@ -43,13 +31,9 @@ RS_ActionDrawImage::~RS_ActionDrawImage() { } -QAction * RS_ActionDrawImage::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +/*virtual*/ RS2::ActionType RS_ActionDrawImage::rtti() { - QAction * action = new QAction(tr("&Image"), 0); -// QAction* action = new QAction(tr("Image"), tr("&Image"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Insert Image (Bitmap)")); - return action; + return RS2::ActionDrawImage; } void RS_ActionDrawImage::init(int status) @@ -79,12 +63,12 @@ void RS_ActionDrawImage::init(int status) void RS_ActionDrawImage::reset() { data = RS_ImageData(0, - Vector(0.0,0.0), - Vector(1.0,0.0), - Vector(0.0,1.0), - Vector(1.0,1.0), - "", - 50, 50, 0); + Vector(0.0, 0.0), + Vector(1.0, 0.0), + Vector(0.0, 1.0), + Vector(1.0, 1.0), + "", + 50, 50, 0); } void RS_ActionDrawImage::trigger() @@ -120,15 +104,15 @@ void RS_ActionDrawImage::mouseMoveEvent(QMouseEvent * e) line = new RS_Line(preview, RS_LineData(Vector(0, 0), Vector(img.width(), 0))); preview->addEntity(line); line = new RS_Line(preview, - RS_LineData(Vector(img.width(), 0), Vector(img.width(), img.height()))); + RS_LineData(Vector(img.width(), 0), Vector(img.width(), img.height()))); preview->addEntity(line); line = new RS_Line(preview, - RS_LineData(Vector(img.width(), img.height()), Vector(0, img.height()))); + RS_LineData(Vector(img.width(), img.height()), Vector(0, img.height()))); preview->addEntity(line); line = new RS_Line(preview, RS_LineData(Vector(0, img.height()), Vector(0, 0))); preview->addEntity(line); - preview->scale(Vector(0,0), Vector(data.uVector.magnitude(), data.uVector.magnitude())); - preview->rotate(Vector(0,0), data.uVector.angle()); + preview->scale(Vector(0, 0), Vector(data.uVector.magnitude(), data.uVector.magnitude())); + preview->rotate(Vector(0, 0), data.uVector.angle()); preview->move(data.insertionPoint); drawPreview(); @@ -141,12 +125,14 @@ void RS_ActionDrawImage::mouseMoveEvent(QMouseEvent * e) void RS_ActionDrawImage::mouseReleaseEvent(QMouseEvent * e) { - if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) +// if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + if (e->button() == Qt::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } - else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) +// else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + else if (e->button() == Qt::RightButton) { deleteSnapper(); //init(getStatus()-1); @@ -154,12 +140,12 @@ void RS_ActionDrawImage::mouseReleaseEvent(QMouseEvent * e) } } -void RS_ActionDrawImage::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionDrawImage::coordinateEvent(Vector * e) { if (e == NULL) return; - data.insertionPoint = e->getCoordinate(); + data.insertionPoint = *e; trigger(); } @@ -177,6 +163,7 @@ void RS_ActionDrawImage::commandEvent(RS_CommandEvent * e) switch (getStatus()) { case SetTargetPoint: + if (checkCommand("angle", c)) { deleteSnapper(); @@ -197,31 +184,31 @@ void RS_ActionDrawImage::commandEvent(RS_CommandEvent * e) case SetAngle: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - setAngle(RS_Math::deg2rad(a)); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + setAngle(RS_Math::deg2rad(a)); + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); } - break; + break; case SetFactor: { - bool ok; - double f = RS_Math::eval(c, &ok); - if (ok==true) { - setFactor(f); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); + bool ok; + double f = RS_Math::eval(c, &ok); + + if (ok == true) + setFactor(f); + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); } - break; + break; default: break; @@ -238,6 +225,7 @@ QStringList RS_ActionDrawImage::getAvailableCommands() cmd += command("angle"); cmd += command("factor"); break; + default: break; } @@ -266,12 +254,15 @@ void RS_ActionDrawImage::updateMouseButtonHints() case SetTargetPoint: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel")); break; + case SetAngle: RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), ""); break; + case SetFactor: RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), ""); break; + default: RS_DIALOGFACTORY->updateMouseWidget("", ""); break; @@ -285,9 +276,33 @@ void RS_ActionDrawImage::updateMouseCursor() void RS_ActionDrawImage::updateToolBar() { - if (!isFinished()) { + if (!isFinished()) RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { + else RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } } + +double RS_ActionDrawImage::getAngle() +{ + return data.uVector.angle(); +} + +void RS_ActionDrawImage::setAngle(double a) +{ + double l = data.uVector.magnitude(); + data.uVector.setPolar(l, a); + data.vVector.setPolar(l, a + M_PI / 2); +} + +double RS_ActionDrawImage::getFactor() +{ + return data.uVector.magnitude(); +} + +void RS_ActionDrawImage::setFactor(double f) +{ + double a = data.uVector.angle(); + data.uVector.setPolar(f, a); + data.vVector.setPolar(f, a + M_PI / 2); +} + diff --git a/src/actions/rs_actiondrawimage.h b/src/actions/rs_actiondrawimage.h index aa5061f..284208d 100644 --- a/src/actions/rs_actiondrawimage.h +++ b/src/actions/rs_actiondrawimage.h @@ -1,34 +1,9 @@ -/**************************************************************************** -** $Id: rs_actiondrawimage.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWIMAGE_H #define RS_ACTIONDRAWIMAGE_H -#include "rs_previewactioninterface.h" +#include #include "rs_image.h" +#include "rs_previewactioninterface.h" /** * This action class can handle user events for inserting bitmaps into the @@ -36,80 +11,52 @@ * * @author Andrew Mustun */ -class RS_ActionDrawImage : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - ShowDialog, /**< Dialog. */ - SetTargetPoint, /**< Setting the reference point. */ - SetAngle, /**< Setting angle in the command line. */ - SetFactor /**< Setting factor in the command line. */ - //SetColumns, /**< Setting columns in the command line. */ - //SetRows, /**< Setting rows in the command line. */ - //SetColumnSpacing, /**< Setting column spacing in the command line. */ - //SetRowSpacing /**< Setting row spacing in the command line. */ - }; - -public: - RS_ActionDrawImage(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawImage(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawImage; - } - - virtual void init(int status=0); - - void reset(); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void showOptions(); - virtual void hideOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - double getAngle() { - return data.uVector.angle(); - } - - void setAngle(double a) { - double l = data.uVector.magnitude(); - data.uVector.setPolar(l, a); - data.vVector.setPolar(l, a+M_PI/2); - } - - double getFactor() { - return data.uVector.magnitude(); - } - - void setFactor(double f) { - double a = data.uVector.angle(); - data.uVector.setPolar(f, a); - data.vVector.setPolar(f, a+M_PI/2); - } - -protected: - RS_ImageData data; - QImage img; - - /** Last status before entering option. */ - Status lastStatus; +class RS_ActionDrawImage: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + ShowDialog, /**< Dialog. */ + SetTargetPoint, /**< Setting the reference point. */ + SetAngle, /**< Setting angle in the command line. */ + SetFactor /**< Setting factor in the command line. */ + //SetColumns, /**< Setting columns in the command line. */ + //SetRows, /**< Setting rows in the command line. */ + //SetColumnSpacing, /**< Setting column spacing in the command line. */ + //SetRowSpacing /**< Setting row spacing in the command line. */ + }; + + public: + RS_ActionDrawImage(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawImage(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + void reset(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void showOptions(); + virtual void hideOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + double getAngle(); + void setAngle(double a); + double getFactor(); + void setFactor(double f); + + protected: + RS_ImageData data; + QImage img; + + /** Last status before entering option. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actiondrawline.cpp b/src/actions/rs_actiondrawline.cpp index 27c8006..89a8ea5 100644 --- a/src/actions/rs_actiondrawline.cpp +++ b/src/actions/rs_actiondrawline.cpp @@ -14,10 +14,12 @@ #include "rs_actiondrawline.h" #include "rs_actioneditundo.h" -#include "rs_snapper.h" +#include "commands.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -RS_ActionDrawLine::RS_ActionDrawLine(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionDrawLine::RS_ActionDrawLine(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw lines", container, graphicView) { RS_DEBUG->print("RS_ActionDrawLine::RS_ActionDrawLine"); @@ -37,16 +39,6 @@ RS_ActionDrawLine::~RS_ActionDrawLine() return RS2::ActionDrawLine; } -/*static*/ QAction * RS_ActionDrawLine::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) -{ - QAction * action = new QAction(tr("&2 Points"), 0); - action->setEnabled(true); -// QAction* action = new QAction(tr("Line: 2 Points"), tr("&2 Points"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw lines")); - return action; -} - void RS_ActionDrawLine::reset() { RS_DEBUG->print("RS_ActionDrawLine::reset"); @@ -123,7 +115,7 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e) { if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) @@ -135,7 +127,7 @@ void RS_ActionDrawLine::mouseReleaseEvent(QMouseEvent * e) } } -void RS_ActionDrawLine::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionDrawLine::coordinateEvent(Vector * e) { RS_DEBUG->print("RS_ActionDrawLine::coordinateEvent"); @@ -145,7 +137,7 @@ void RS_ActionDrawLine::coordinateEvent(RS_CoordinateEvent * e) return; } - Vector mouse = e->getCoordinate(); + Vector mouse = *e; switch (getStatus()) { @@ -183,6 +175,7 @@ void RS_ActionDrawLine::commandEvent(RS_CommandEvent * e) switch (getStatus()) { case SetStartpoint: + if (checkCommand("help", c)) { RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() @@ -192,6 +185,7 @@ void RS_ActionDrawLine::commandEvent(RS_CommandEvent * e) break; case SetEndpoint: + if (checkCommand("close", c)) { close(); @@ -222,7 +216,9 @@ QStringList RS_ActionDrawLine::getAvailableCommands() { case SetStartpoint: break; + case SetEndpoint: + if (history.count() >= 2) cmd += command("undo"); @@ -230,6 +226,7 @@ QStringList RS_ActionDrawLine::getAvailableCommands() cmd += command("close"); break; + default: break; } @@ -244,6 +241,7 @@ void RS_ActionDrawLine::updateMouseButtonHints() case SetStartpoint: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), tr("Cancel")); break; + case SetEndpoint: { QString msg = ""; @@ -255,16 +253,15 @@ void RS_ActionDrawLine::updateMouseButtonHints() } if (history.count() >= 2) - { msg += RS_COMMANDS->command("undo"); - } if (history.count() >= 2) RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point or [%1]").arg(msg), tr("Back")); else RS_DIALOGFACTORY->updateMouseWidget(tr("Specify next point"), tr("Back")); } - break; + break; + default: RS_DIALOGFACTORY->updateMouseWidget("", ""); break; @@ -310,9 +307,7 @@ void RS_ActionDrawLine::close() graphicView->moveRelativeZero(start); } else - { RS_DIALOGFACTORY->commandMessage(tr("Cannot close sequence of lines: Not enough entities defined yet.")); - } } void RS_ActionDrawLine::undo() @@ -327,9 +322,7 @@ void RS_ActionDrawLine::undo() graphicView->moveRelativeZero(data.startpoint); } else - { RS_DIALOGFACTORY->commandMessage(tr("Cannot undo: Not enough entities defined yet.")); - } } void RS_ActionDrawLine::ClearHistory(void) @@ -337,3 +330,4 @@ void RS_ActionDrawLine::ClearHistory(void) while (!history.isEmpty()) delete history.takeFirst(); } + diff --git a/src/actions/rs_actiondrawline.h b/src/actions/rs_actiondrawline.h index 10710e1..ef3d668 100644 --- a/src/actions/rs_actiondrawline.h +++ b/src/actions/rs_actiondrawline.h @@ -13,12 +13,10 @@ */ class RS_ActionDrawLine: public RS_PreviewActionInterface { -//No slots/signals... //Q_OBJECT - public: /** - * Action States. - */ + * Action States. + */ enum Status { SetStartpoint = 0, /**< Setting the startpoint. */ @@ -30,26 +28,19 @@ class RS_ActionDrawLine: public RS_PreviewActionInterface virtual ~RS_ActionDrawLine(); virtual RS2::ActionType rtti(); - static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); void reset(); - virtual void init(int status = 0); virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent * e); virtual void mouseReleaseEvent(QMouseEvent * e); - - virtual void coordinateEvent(RS_CoordinateEvent * e); + virtual void coordinateEvent(Vector * e); virtual void commandEvent(RS_CommandEvent * e); virtual QStringList getAvailableCommands(); - virtual void showOptions(); virtual void hideOptions(); - virtual void updateMouseButtonHints(); virtual void updateMouseCursor(); virtual void updateToolBar(); - void close(); void undo(); @@ -68,7 +59,6 @@ class RS_ActionDrawLine: public RS_PreviewActionInterface /** * Point history (for undo) */ -// Q3PtrList history; QList history; }; diff --git a/src/actions/rs_actiondrawlineangle.cpp b/src/actions/rs_actiondrawlineangle.cpp index de3036d..188d8c4 100644 --- a/src/actions/rs_actiondrawlineangle.cpp +++ b/src/actions/rs_actiondrawlineangle.cpp @@ -10,57 +10,34 @@ // Who When What // --- ---------- ----------------------------------------------------------- // JLH 05/22/2010 Added this text. :-) +// JLH 06/03/2010 Moved implementation from header to this file // #include "rs_actiondrawlineangle.h" -#include "rs_snapper.h" - -RS_ActionDrawLineAngle::RS_ActionDrawLineAngle(RS_EntityContainer& container, - RS_GraphicView& graphicView, - double angle, - bool fixedAngle) - :RS_PreviewActionInterface("Draw lines with given angle", - container, graphicView) + +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" + +RS_ActionDrawLineAngle::RS_ActionDrawLineAngle(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle, bool fixedAngle): + RS_PreviewActionInterface("Draw lines with given angle", + container, graphicView) { - this->angle = angle; - length = 1.0; - snpPoint = 0; - this->fixedAngle = fixedAngle; - pos = Vector(false); - reset(); + this->angle = angle; + length = 1.0; + snpPoint = 0; + this->fixedAngle = fixedAngle; + pos = Vector(false); + reset(); } RS_ActionDrawLineAngle::~RS_ActionDrawLineAngle() { } -QAction * RS_ActionDrawLineAngle::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +/*virtual*/ RS2::ActionType RS_ActionDrawLineAngle::rtti() { - QAction * action = NULL; - - if (type == RS2::ActionDrawLineAngle) - { - action = new QAction(tr("&Angle"), 0); -// action = new QAction(tr("Line: Angle"), tr("&Angle"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw lines with a given angle")); - } - else if (type == RS2::ActionDrawLineHorizontal) - { - action = new QAction(tr("&Horizontal"), 0); -// action = new QAction(tr("Line: Horizontal"), tr("&Horizontal"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw horizontal lines")); - } - else if (type == RS2::ActionDrawLineVertical) - { - action = new QAction(tr("H&orizontal / Vertical"), 0); -// action = new QAction(tr("hor./vert. line"), tr("H&orizontal / Vertical"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw horizontal/vertical lines")); - } - - return action; + return RS2::ActionDrawLineAngle; } void RS_ActionDrawLineAngle::reset() @@ -68,238 +45,275 @@ void RS_ActionDrawLineAngle::reset() data = RS_LineData(Vector(false), Vector(false)); } +void RS_ActionDrawLineAngle::init(int status) +{ + RS_PreviewActionInterface::init(status); - -void RS_ActionDrawLineAngle::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); + reset(); } +void RS_ActionDrawLineAngle::trigger() +{ + RS_PreviewActionInterface::trigger(); + preparePreview(); + RS_Line * line = new RS_Line(container, + data); + line->setLayerToActive(); + line->setPenToActive(); + container->addEntity(line); -void RS_ActionDrawLineAngle::trigger() { - RS_PreviewActionInterface::trigger(); - - preparePreview(); - RS_Line* line = new RS_Line(container, - data); - line->setLayerToActive(); - line->setPenToActive(); - container->addEntity(line); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(line); - document->endUndoCycle(); - } - deleteSnapper(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(line); - graphicView->moveRelativeZero(data.startpoint); - RS_DEBUG->print("RS_ActionDrawLineAngle::trigger(): line added: %d", - line->getId()); + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(line); + document->endUndoCycle(); + } + deleteSnapper(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(line); + graphicView->moveRelativeZero(data.startpoint); + RS_DEBUG->print("RS_ActionDrawLineAngle::trigger(): line added: %d", + line->getId()); } +void RS_ActionDrawLineAngle::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent begin"); + if (getStatus() == SetPos) + { + pos = snapPoint(e); + deletePreview(); + clearPreview(); + preparePreview(); + preview->addEntity(new RS_Line(preview, + data)); + drawPreview(); + } -void RS_ActionDrawLineAngle::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent begin"); - - if (getStatus()==SetPos) { - pos = snapPoint(e); - deletePreview(); - clearPreview(); - preparePreview(); - preview->addEntity(new RS_Line(preview, - data)); - drawPreview(); - } - - RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDrawLineAngle::mouseMoveEvent end"); } - - -void RS_ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - if (getStatus()==SetPos) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawLineAngle::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + if (getStatus() == SetPos) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - -void RS_ActionDrawLineAngle::preparePreview() { - Vector p1, p2; - // End: - if (snpPoint == 2) { - p2.setPolar(length * -1, angle); - } else { - p2.setPolar(length, angle); - } - - // Middle: - if (snpPoint == 1) { - p1 = pos - (p2 / 2); - } else { - p1 = pos; - } - - p2 += p1; - data = RS_LineData(p1, p2); +void RS_ActionDrawLineAngle::preparePreview() +{ + Vector p1, p2; + + // End: + if (snpPoint == 2) + p2.setPolar(length * -1, angle); + else + p2.setPolar(length, angle); + + // Middle: + if (snpPoint == 1) + p1 = pos - (p2 / 2); + else + p1 = pos; + + p2 += p1; + data = RS_LineData(p1, p2); } +void RS_ActionDrawLineAngle::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; -void RS_ActionDrawLineAngle::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - switch (getStatus()) { - case SetPos: - pos = e->getCoordinate(); - trigger(); - break; + switch (getStatus()) + { + case SetPos: + pos = *e; + trigger(); + break; - default: - break; - } + default: + break; + } } +void RS_ActionDrawLineAngle::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } -void RS_ActionDrawLineAngle::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - switch (getStatus()) { - case SetPos: - if (!fixedAngle && checkCommand("angle", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetAngle); - } else if (checkCommand("length", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetLength); - } - break; - - case SetAngle: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - angle = RS_Math::deg2rad(a); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(SetPos); - } - break; - - case SetLength: { - bool ok; - double l = RS_Math::eval(c, &ok); - if (ok==true) { - length = l; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(SetPos); - } - break; - - default: - break; - } + switch (getStatus()) + { + case SetPos: + + if (!fixedAngle && checkCommand("angle", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetAngle); + } + else if (checkCommand("length", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetLength); + } + break; + + case SetAngle: { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + angle = RS_Math::deg2rad(a); + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(SetPos); + } + break; + + case SetLength: { + bool ok; + double l = RS_Math::eval(c, &ok); + + if (ok == true) + length = l; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(SetPos); + } + break; + + default: + break; + } } +QStringList RS_ActionDrawLineAngle::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetPos: -QStringList RS_ActionDrawLineAngle::getAvailableCommands() { - QStringList cmd; + if (!fixedAngle) + cmd += command("angle"); + cmd += command("length"); + break; - switch (getStatus()) { - case SetPos: - if (!fixedAngle) { - cmd += command("angle"); - } - cmd += command("length"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } +void RS_ActionDrawLineAngle::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetPos: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"), + tr("Cancel")); + break; -void RS_ActionDrawLineAngle::updateMouseButtonHints() { - switch (getStatus()) { - case SetPos: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"), - tr("Cancel")); - break; - - case SetAngle: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back")); - break; + case SetAngle: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), tr("Back")); + break; - case SetLength: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back")); - break; + case SetLength: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length:"), tr("Back")); + break; - default: - break; - } + default: + break; + } } +void RS_ActionDrawLineAngle::showOptions() +{ + RS_ActionInterface::showOptions(); + RS_DIALOGFACTORY->requestOptions(this, true); +} -void RS_ActionDrawLineAngle::showOptions() { - RS_ActionInterface::showOptions(); +void RS_ActionDrawLineAngle::hideOptions() +{ + RS_ActionInterface::hideOptions(); - RS_DIALOGFACTORY->requestOptions(this, true); + RS_DIALOGFACTORY->requestOptions(this, false); } +void RS_ActionDrawLineAngle::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} +void RS_ActionDrawLineAngle::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); +} -void RS_ActionDrawLineAngle::hideOptions() { - RS_ActionInterface::hideOptions(); - - RS_DIALOGFACTORY->requestOptions(this, false); +void RS_ActionDrawLineAngle::setSnapPoint(int sp) +{ + snpPoint = sp; } +int RS_ActionDrawLineAngle::getSnapPoint() +{ + return snpPoint; +} +void RS_ActionDrawLineAngle::setAngle(double a) +{ + angle = a; +} -void RS_ActionDrawLineAngle::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +double RS_ActionDrawLineAngle::getAngle() +{ + return angle; } +void RS_ActionDrawLineAngle::setLength(double l) +{ + length = l; +} +double RS_ActionDrawLineAngle::getLength() +{ + return length; +} -void RS_ActionDrawLineAngle::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } +bool RS_ActionDrawLineAngle::hasFixedAngle() +{ + return fixedAngle; } -// EOF diff --git a/src/actions/rs_actiondrawlineangle.h b/src/actions/rs_actiondrawlineangle.h index 537a635..71c5ec4 100644 --- a/src/actions/rs_actiondrawlineangle.h +++ b/src/actions/rs_actiondrawlineangle.h @@ -1,139 +1,79 @@ -/**************************************************************************** -** $Id: rs_actiondrawlineangle.h 1092 2004-03-16 18:01:08Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINEANGLE_H #define RS_ACTIONDRAWLINEANGLE_H -#include "rs_previewactioninterface.h" #include "rs_line.h" +#include "rs_previewactioninterface.h" +#include "vector.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * simple lines at a gien angle. * * @author Andrew Mustun */ -class RS_ActionDrawLineAngle : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetPos, /**< Setting the position. */ - SetAngle, /**< Setting angle in the command line. */ - SetLength /**< Setting length in the command line. */ - }; - - RS_ActionDrawLineAngle(RS_EntityContainer& container, - RS_GraphicView& graphicView, - double angle=0.0, - bool fixedAngle=false); - ~RS_ActionDrawLineAngle(); - - static QAction* createGUIAction(RS2::ActionType type, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawLineAngle; - } - - void reset(); - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - void preparePreview(); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - void setSnapPoint(int sp) { - snpPoint = sp; - } - - int getSnapPoint() { - return snpPoint; - } - - void setAngle(double a) { - angle = a; - } - - double getAngle() { - return angle; - } - - void setLength(double l) { - length = l; - } - - double getLength() { - return length; - } - - bool hasFixedAngle() { - return fixedAngle; - } - -protected: - /** - * Line data defined so far. - */ - RS_LineData data; - /** - * Position. - */ - Vector pos; - /** - * Line angle. - */ - double angle; - /** - * Line length. - */ - double length; - /** - * Is the angle fixed? - */ - bool fixedAngle; - /** - * Snap point (start, middle, end). - */ - int snpPoint; +class RS_ActionDrawLineAngle: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetPos, /**< Setting the position. */ + SetAngle, /**< Setting angle in the command line. */ + SetLength /**< Setting length in the command line. */ + }; + + RS_ActionDrawLineAngle(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle = 0.0, bool fixedAngle = false); + ~RS_ActionDrawLineAngle(); + + virtual RS2::ActionType rtti(); + void reset(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + void preparePreview(); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + void setSnapPoint(int sp); + int getSnapPoint(); + void setAngle(double a); + double getAngle(); + void setLength(double l); + double getLength(); + bool hasFixedAngle(); + + protected: + /** + * Line data defined so far. + */ + RS_LineData data; + /** + * Position. + */ + Vector pos; + /** + * Line angle. + */ + double angle; + /** + * Line length. + */ + double length; + /** + * Is the angle fixed? + */ + bool fixedAngle; + /** + * Snap point (start, middle, end). + */ + int snpPoint; }; #endif diff --git a/src/actions/rs_actiondrawlinebisector.cpp b/src/actions/rs_actiondrawlinebisector.cpp index d5c03f5..c376095 100644 --- a/src/actions/rs_actiondrawlinebisector.cpp +++ b/src/actions/rs_actiondrawlinebisector.cpp @@ -1,305 +1,317 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinebisector.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinebisector.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/03/2010 Added this text. :-) +// #include "rs_actiondrawlinebisector.h" #include "rs_creation.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionDrawLineBisector::RS_ActionDrawLineBisector( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw Bisectors", container, graphicView) { - - bisector = NULL; - length = 10.0; - line1 = NULL; - line2 = NULL; - number = 1; - coord1 = Vector(false); - coord2 = Vector(false); - lastStatus = SetLine1; +RS_ActionDrawLineBisector::RS_ActionDrawLineBisector(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_PreviewActionInterface("Draw Bisectors", container, graphicView) +{ + bisector = NULL; + length = 10.0; + line1 = NULL; + line2 = NULL; + number = 1; + coord1 = Vector(false); + coord2 = Vector(false); + lastStatus = SetLine1; } -QAction* RS_ActionDrawLineBisector::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLineBisector::~RS_ActionDrawLineBisector() { - QAction * action = new QAction(tr("&Bisector"), 0); -// QAction* action = new QAction(tr("Bisector"), tr("&Bisector"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw bisectors")); - return action; } - -void RS_ActionDrawLineBisector::trigger() { - RS_PreviewActionInterface::trigger(); - - //if (bisector!=NULL) { - RS_Creation creation(container, graphicView); - creation.createBisector(coord1, - coord2, - length, - number, - line1, - line2); - /*RS_Entity* newEntity = NULL; - - newEntity = new RS_Line(container, - bisector->getData()); - - if (newEntity!=NULL) { - newEntity->setLayerToActive(); - newEntity->setPenToActive(); - container->addEntity(newEntity); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(newEntity); - document->endUndoCycle(); - } - graphicView->drawEntity(newEntity); - setStatus(SetLine1); -} - //reset(); - delete bisector; - bisector = NULL; - */ - /*} else { - RS_DEBUG->print("RS_ActionDrawLineBisector::trigger:" - " Entity is NULL\n"); -}*/ +/*virtual*/ RS2::ActionType RS_ActionDrawLineBisector::rtti() +{ + return RS2::ActionDrawLineBisector; } - - -void RS_ActionDrawLineBisector::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent begin"); - - Vector mouse = Vector(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); - - switch (getStatus()) { - case SetLine1: - break; - - case SetLine2: { - coord2 = mouse; - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && en->rtti()==RS2::EntityLine) { - line2 = (RS_Line*)en; - - deletePreview(); - clearPreview(); - - RS_Creation creation(preview, NULL, false); - creation.createBisector(coord1, - coord2, - length, - number, - line1, - line2); - drawPreview(); - } - } - break; - - default: - break; - } - - RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent end"); +void RS_ActionDrawLineBisector::trigger() +{ + RS_PreviewActionInterface::trigger(); + + //if (bisector!=NULL) { + RS_Creation creation(container, graphicView); + creation.createBisector(coord1, + coord2, + length, + number, + line1, + line2); + /*RS_Entity* newEntity = NULL; + + newEntity = new RS_Line(container, + bisector->getData()); + + if (newEntity!=NULL) { + newEntity->setLayerToActive(); + newEntity->setPenToActive(); + container->addEntity(newEntity); + + // upd. undo list: + if (document!=NULL) { + document->startUndoCycle(); + document->addUndoable(newEntity); + document->endUndoCycle(); + } + graphicView->drawEntity(newEntity); + setStatus(SetLine1); + } + //reset(); + delete bisector; + bisector = NULL; + */ + /*} else { + RS_DEBUG->print("RS_ActionDrawLineBisector::trigger:" + " Entity is NULL\n"); + }*/ } - - -void RS_ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent* e) { - - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - clearPreview(); - init(getStatus()-1); - } else { - - Vector mouse = Vector(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); - - switch (getStatus()) { - case SetLine1: { - coord1 = mouse; - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && en->rtti()==RS2::EntityLine) { - line1 = (RS_Line*)en; - } - } - setStatus(SetLine2); - break; - - case SetLine2: - coord2 = mouse; - trigger(); - setStatus(SetLine1); - break; - } - } - +void RS_ActionDrawLineBisector::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent begin"); + + Vector mouse = Vector(graphicView->toGraphX(e->x()), + graphicView->toGraphY(e->y())); + + switch (getStatus()) + { + case SetLine1: + break; + + case SetLine2: { + coord2 = mouse; + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL && en->rtti() == RS2::EntityLine) + { + line2 = (RS_Line *)en; + + deletePreview(); + clearPreview(); + + RS_Creation creation(preview, NULL, false); + creation.createBisector(coord1, + coord2, + length, + number, + line1, + line2); + drawPreview(); + } + } + break; + + default: + break; + } + + RS_DEBUG->print("RS_ActionDrawLineBisector::mouseMoveEvent end"); } - -void RS_ActionDrawLineBisector::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - switch (getStatus()) { - case SetLine1: - case SetLine2: - lastStatus = (Status)getStatus(); - if (checkCommand("length", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetLength); - } else if (checkCommand("number", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetNumber); - } - break; - - case SetLength: { - bool ok; - double l = RS_Math::eval(c, &ok); - if (ok==true) { - length = l; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - case SetNumber: { - bool ok; - int n = (int)RS_Math::eval(c, &ok); - if (ok==true) { - number = n; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - - default: - break; - } +void RS_ActionDrawLineBisector::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + clearPreview(); + init(getStatus() - 1); + } + else + { + Vector mouse = Vector(graphicView->toGraphX(e->x()), + graphicView->toGraphY(e->y())); + + switch (getStatus()) + { + case SetLine1: { + coord1 = mouse; + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL && en->rtti() == RS2::EntityLine) + line1 = (RS_Line *)en; + } + setStatus(SetLine2); + break; + + case SetLine2: + coord2 = mouse; + trigger(); + setStatus(SetLine1); + break; + } + } } +void RS_ActionDrawLineBisector::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + switch (getStatus()) + { + case SetLine1: + case SetLine2: + lastStatus = (Status)getStatus(); + + if (checkCommand("length", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetLength); + } + else if (checkCommand("number", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetNumber); + } + break; + + case SetLength: { + bool ok; + double l = RS_Math::eval(c, &ok); + + if (ok == true) + length = l; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + case SetNumber: { + bool ok; + int n = (int)RS_Math::eval(c, &ok); + + if (ok == true) + number = n; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + default: + break; + } +} +QStringList RS_ActionDrawLineBisector::getAvailableCommands() +{ + QStringList cmd; -QStringList RS_ActionDrawLineBisector::getAvailableCommands() { - QStringList cmd; + switch (getStatus()) + { + case SetLine1: + case SetLine2: + cmd += command("length"); + cmd += command("number"); + break; - switch (getStatus()) { - case SetLine1: - case SetLine2: - cmd += command("length"); - cmd += command("number"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - -void RS_ActionDrawLineBisector::updateMouseButtonHints() { - switch (getStatus()) { - case SetLine1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"), - tr("Cancel")); - break; - case SetLine2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"), - tr("Back")); - break; - case SetLength: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"), - tr("Back")); - break; - case SetNumber: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDrawLineBisector::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetLine1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select first line"), + tr("Cancel")); + break; + + case SetLine2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select second line"), + tr("Back")); + break; + + case SetLength: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter bisector length:"), + tr("Back")); + break; + + case SetNumber: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number of bisectors:"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } +void RS_ActionDrawLineBisector::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDrawLineBisector::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDrawLineBisector::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawLineBisector::hideOptions() { - RS_ActionInterface::hideOptions(); - - RS_DIALOGFACTORY->requestOptions(this, false); + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionDrawLineBisector::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineBisector::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionDrawLineBisector::updateToolBar() +{ + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); +} +void RS_ActionDrawLineBisector::setLength(double l) +{ + length = l; +} -void RS_ActionDrawLineBisector::updateToolBar() { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); +double RS_ActionDrawLineBisector::getLength() +{ + return length; } +void RS_ActionDrawLineBisector::setNumber(int n) +{ + number = n; +} +int RS_ActionDrawLineBisector::getNumber() +{ + return number; +} -// EOF diff --git a/src/actions/rs_actiondrawlinebisector.h b/src/actions/rs_actiondrawlinebisector.h index dfd3e14..2caf564 100644 --- a/src/actions/rs_actiondrawlinebisector.h +++ b/src/actions/rs_actiondrawlinebisector.h @@ -1,110 +1,66 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinebisector.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINEBISECTOR_H #define RS_ACTIONDRAWLINEBISECTOR_H +#include "rs_line.h" #include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Line; /** * This action class can handle user events to draw bisectors. * * @author Andrew Mustun */ -class RS_ActionDrawLineBisector : public RS_PreviewActionInterface { - //Q_OBJECT -private: - enum Status { - SetLine1, /**< Choose the 1st line. */ - SetLine2, /**< Choose the 2nd line. */ - SetLength, /**< Set length in command line. */ - SetNumber /**< Set number in command line. */ - }; - -public: - RS_ActionDrawLineBisector(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLineBisector() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawLineBisector; - } - - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - void setLength(double l) { - length = l; - } +class RS_ActionDrawLineBisector: public RS_PreviewActionInterface +{ + private: + enum Status { + SetLine1, /**< Choose the 1st line. */ + SetLine2, /**< Choose the 2nd line. */ + SetLength, /**< Set length in command line. */ + SetNumber /**< Set number in command line. */ + }; - double getLength() { - return length; - } - - void setNumber(int n) { - number = n; - } + public: + RS_ActionDrawLineBisector(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLineBisector(); - int getNumber() { - return number; - } + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + void setLength(double l); + double getLength(); + void setNumber(int n); + int getNumber(); -private: - /** Closest bisector. */ - RS_Line* bisector; - /** First chosen entity */ - RS_Line* line1; - /** Second chosen entity */ - RS_Line* line2; - /** Data of new bisector */ - RS_LineData data; - /** Length of the bisector. */ - double length; - /** Number of bisectors to create. */ - int number; - /** Mouse pos when choosing the 1st line */ - Vector coord1; - /** Mouse pos when choosing the 2nd line */ - Vector coord2; - /** Last status before entering length or number. */ - Status lastStatus; + private: + /** Closest bisector. */ + RS_Line * bisector; + /** First chosen entity */ + RS_Line * line1; + /** Second chosen entity */ + RS_Line * line2; + /** Data of new bisector */ + RS_LineData data; + /** Length of the bisector. */ + double length; + /** Number of bisectors to create. */ + int number; + /** Mouse pos when choosing the 1st line */ + Vector coord1; + /** Mouse pos when choosing the 2nd line */ + Vector coord2; + /** Last status before entering length or number. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actiondrawlinefree.cpp b/src/actions/rs_actiondrawlinefree.cpp index 05aeb83..f2d18e7 100644 --- a/src/actions/rs_actiondrawlinefree.cpp +++ b/src/actions/rs_actiondrawlinefree.cpp @@ -1,153 +1,136 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinefree.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinefree.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_actiondrawlinefree.h" -#include "rs_snapper.h" -#include "rs_point.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_polyline.h" - -RS_ActionDrawLineFree::RS_ActionDrawLineFree(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Draw freehand lines", - container, graphicView) { - vertex = Vector(false); - polyline = NULL; -} - -RS_ActionDrawLineFree::~RS_ActionDrawLineFree() { - if (polyline!=NULL) { - delete polyline; - } +RS_ActionDrawLineFree::RS_ActionDrawLineFree(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Draw freehand lines", + container, graphicView) +{ + vertex = Vector(false); + polyline = NULL; } -QAction* RS_ActionDrawLineFree::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLineFree::~RS_ActionDrawLineFree() { - QAction * action = new QAction(tr("&Freehand Line"), 0); -// QAction* action = new QAction(tr("Line: Freehand"), tr("&Freehand Line"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw freehand lines")); - return action; + if (polyline != NULL) + delete polyline; } -void RS_ActionDrawLineFree::trigger() { - if (polyline!=NULL) { - container->addEntity(polyline); - deleteSnapper(); - - if (document) { - document->startUndoCycle(); - document->addUndoable(polyline); - document->endUndoCycle(); - } - - RS_DEBUG->print("RS_ActionDrawLineFree::trigger():" - " polyline added: %d", polyline->getId()); - polyline = NULL; - } +void RS_ActionDrawLineFree::trigger() +{ + if (polyline != NULL) + { + container->addEntity(polyline); + deleteSnapper(); + + if (document) + { + document->startUndoCycle(); + document->addUndoable(polyline); + document->endUndoCycle(); + } + + RS_DEBUG->print("RS_ActionDrawLineFree::trigger():" + " polyline added: %d", polyline->getId()); + polyline = NULL; + } } - - -void RS_ActionDrawLineFree::mouseMoveEvent(QMouseEvent* e) { - if (vertex.valid && polyline!=NULL) { - Vector v = snapPoint(e); - RS_Entity* ent = polyline->addVertex(v); - ent->setLayerToActive(); - ent->setPenToActive(); - - deleteSnapper(); - graphicView->drawEntity(ent); - drawSnapper(); - - vertex = v; - - RS_DEBUG->print("RS_ActionDrawLineFree::mouseMoveEvent():" - " line added: %d", ent->getId()); - } +void RS_ActionDrawLineFree::mouseMoveEvent(QMouseEvent * e) +{ + if (vertex.valid && polyline != NULL) + { + Vector v = snapPoint(e); + RS_Entity * ent = polyline->addVertex(v); + ent->setLayerToActive(); + ent->setPenToActive(); + + deleteSnapper(); + graphicView->drawEntity(ent); + drawSnapper(); + + vertex = v; + + RS_DEBUG->print("RS_ActionDrawLineFree::mouseMoveEvent():" + " line added: %d", ent->getId()); + } } - - -void RS_ActionDrawLineFree::mousePressEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - vertex = snapPoint(e); - polyline = new RS_Polyline(container, - RS_PolylineData(vertex, vertex, 0)); - polyline->setLayerToActive(); - polyline->setPenToActive(); - } - //else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton && !vertex.valid) { - //} +void RS_ActionDrawLineFree::mousePressEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + vertex = snapPoint(e); + polyline = new RS_Polyline(container, RS_PolylineData(vertex, vertex, 0)); + polyline->setLayerToActive(); + polyline->setPenToActive(); + } + //else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton && !vertex.valid) { + //} } - - -void RS_ActionDrawLineFree::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - vertex = Vector(false); - trigger(); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - if (polyline!=NULL) { - delete polyline; - polyline = NULL; - } - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawLineFree::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + vertex = Vector(false); + trigger(); + } +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + if (polyline != NULL) + { + delete polyline; + polyline = NULL; + } + + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawLineFree::updateMouseButtonHints() { - switch (getStatus()) { - case 0: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Click and drag to draw a line"), tr("Cancel")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDrawLineFree::updateMouseButtonHints() +{ + switch (getStatus()) + { + case 0: + RS_DIALOGFACTORY->updateMouseWidget(tr("Click and drag to draw a line"), tr("Cancel")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionDrawLineFree::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineFree::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionDrawLineFree::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } +void RS_ActionDrawLineFree::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); } -// EOF diff --git a/src/actions/rs_actiondrawlinefree.h b/src/actions/rs_actiondrawlinefree.h index b78af4a..b8e01ed 100644 --- a/src/actions/rs_actiondrawlinefree.h +++ b/src/actions/rs_actiondrawlinefree.h @@ -1,60 +1,33 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinefree.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINEFREE_H #define RS_ACTIONDRAWLINEFREE_H #include "rs_actioninterface.h" -#include "rs_polyline.h" +#include "vector.h" + +class RS_Polyline; /** * This action class can handle user events to draw freehand lines. * * @author Andrew Mustun */ -class RS_ActionDrawLineFree : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionDrawLineFree(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLineFree(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionDrawLineFree: public RS_ActionInterface +{ + public: + RS_ActionDrawLineFree(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLineFree(); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mousePressEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mousePressEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); -protected: - Vector vertex; - RS_Polyline* polyline; + protected: + Vector vertex; + RS_Polyline * polyline; }; #endif diff --git a/src/actions/rs_actiondrawlinehorvert.cpp b/src/actions/rs_actiondrawlinehorvert.cpp index d8e41e1..67be5e2 100644 --- a/src/actions/rs_actiondrawlinehorvert.cpp +++ b/src/actions/rs_actiondrawlinehorvert.cpp @@ -1,179 +1,158 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinehorvert.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinehorvert.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_actiondrawlinehorvert.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - -RS_ActionDrawLineHorVert::RS_ActionDrawLineHorVert( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw horizontal/vertical lines", - container, graphicView) { - reset(); - RS_DEBUG->print("RS_ActionDrawLineHorVert::constructor"); -} - - - -RS_ActionDrawLineHorVert::~RS_ActionDrawLineHorVert() {} - - -QAction* RS_ActionDrawLineHorVert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLineHorVert::RS_ActionDrawLineHorVert(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw horizontal/vertical lines", + container, graphicView) { - QAction * action = new QAction(tr("H&orizontal / Vertical"), 0); -// QAction* action = new QAction(tr("hor./vert. line"), -// tr("H&orizontal / Vertical"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw horizontal/vertical lines")); - return action; + reset(); + RS_DEBUG->print("RS_ActionDrawLineHorVert::constructor"); } -void RS_ActionDrawLineHorVert::reset() { - data = RS_LineData(Vector(false), - Vector(false)); +RS_ActionDrawLineHorVert::~RS_ActionDrawLineHorVert() +{ } - - -void RS_ActionDrawLineHorVert::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); - RS_DEBUG->print("RS_ActionDrawLineHorVert::init"); +void RS_ActionDrawLineHorVert::reset() +{ + data = RS_LineData(Vector(false), Vector(false)); } - - -void RS_ActionDrawLineHorVert::trigger() { - RS_PreviewActionInterface::trigger(); - - RS_Line* line = new RS_Line(container, data); - line->setLayerToActive(); - line->setPenToActive(); - container->addEntity(line); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(line); - document->endUndoCycle(); - } - - deleteSnapper(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(line); - graphicView->moveRelativeZero(line->getMiddlepoint()); - RS_DEBUG->print("RS_ActionDrawLineHorVert::trigger():" - " line added: %d", line->getId()); - +void RS_ActionDrawLineHorVert::init(int status) +{ + RS_PreviewActionInterface::init(status); + reset(); + RS_DEBUG->print("RS_ActionDrawLineHorVert::init"); } - - -void RS_ActionDrawLineHorVert::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); - if (getStatus()==SetEndpoint && p1.valid) { - Vector p2x = Vector(mouse.x, p1.y); - Vector p2y = Vector(p1.x, mouse.y); - if (mouse.distanceTo(p2y) > mouse.distanceTo(p2x)) - p2 = p2x; - else - p2 = p2y; - deletePreview(); - clearPreview(); - data = RS_LineData(p1, p2); - preview->addEntity(new RS_Line(preview, data)); - drawPreview(); - } - - RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent end"); +void RS_ActionDrawLineHorVert::trigger() +{ + RS_PreviewActionInterface::trigger(); + + RS_Line * line = new RS_Line(container, data); + line->setLayerToActive(); + line->setPenToActive(); + container->addEntity(line); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(line); + document->endUndoCycle(); + } + + deleteSnapper(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(line); + graphicView->moveRelativeZero(line->getMiddlepoint()); + RS_DEBUG->print("RS_ActionDrawLineHorVert::trigger():" + " line added: %d", line->getId()); } +void RS_ActionDrawLineHorVert::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent begin"); + Vector mouse = snapPoint(e); -void RS_ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - Vector mouse = snapPoint(e); + if (getStatus() == SetEndpoint && p1.valid) + { + Vector p2x = Vector(mouse.x, p1.y); + Vector p2y = Vector(p1.x, mouse.y); - switch (getStatus()) { - case SetStartpoint: - p1 = mouse; - setStatus(SetEndpoint); - break; + if (mouse.distanceTo(p2y) > mouse.distanceTo(p2x)) + p2 = p2x; + else + p2 = p2y; - case SetEndpoint: - p2 = mouse; - trigger(); - setStatus(SetStartpoint); - break; + deletePreview(); + clearPreview(); + data = RS_LineData(p1, p2); + preview->addEntity(new RS_Line(preview, data)); + drawPreview(); + } - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } + RS_DEBUG->print("RS_ActionDrawLineHorVert::mouseMoveEvent end"); } - - -void RS_ActionDrawLineHorVert::updateMouseButtonHints() { - switch (getStatus()) { - case SetStartpoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), - tr("Cancel")); - break; - case SetEndpoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionDrawLineHorVert::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetStartpoint: + p1 = mouse; + setStatus(SetEndpoint); + break; + + case SetEndpoint: + p2 = mouse; + trigger(); + setStatus(SetStartpoint); + break; + + default: + break; + } + } +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - -void RS_ActionDrawLineHorVert::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineHorVert::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetStartpoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first point"), tr("Cancel")); + break; + + case SetEndpoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second point"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } +void RS_ActionDrawLineHorVert::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} -void RS_ActionDrawLineHorVert::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } +void RS_ActionDrawLineHorVert::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); } -// EOF diff --git a/src/actions/rs_actiondrawlinehorvert.h b/src/actions/rs_actiondrawlinehorvert.h index 2254c15..618ed84 100644 --- a/src/actions/rs_actiondrawlinehorvert.h +++ b/src/actions/rs_actiondrawlinehorvert.h @@ -1,81 +1,52 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinehorvert.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINEHORVERT_H #define RS_ACTIONDRAWLINEHORVERT_H -#include "rs_previewactioninterface.h" #include "rs_line.h" +#include "rs_previewactioninterface.h" +#include "vector.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * horizontal/vertical lines from a given startpoint * to an endpoint closest to a second given point. * OBSOLETE * * @author Ulf Lehnert */ -class RS_ActionDrawLineHorVert : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetStartpoint, /**< Setting the 1st point. */ - SetEndpoint /**< Setting the 2nd point. */ - }; - -public: - RS_ActionDrawLineHorVert(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLineHorVert(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - void reset(); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - /** - * Line data. - */ - RS_LineData data; - /** - * 2 points - */ - Vector p1; - Vector p2; +class RS_ActionDrawLineHorVert: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetStartpoint, /**< Setting the 1st point. */ + SetEndpoint /**< Setting the 2nd point. */ + }; + + public: + RS_ActionDrawLineHorVert(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLineHorVert(); + + void reset(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + /** + * Line data. + */ + RS_LineData data; + /** + * 2 points + */ + Vector p1; + Vector p2; }; #endif diff --git a/src/actions/rs_actiondrawlineparallel.cpp b/src/actions/rs_actiondrawlineparallel.cpp index 769f73a..03ab268 100644 --- a/src/actions/rs_actiondrawlineparallel.cpp +++ b/src/actions/rs_actiondrawlineparallel.cpp @@ -14,252 +14,242 @@ #include "rs_actiondrawlineparallel.h" -#include "rs_creation.h" -#include "rs_snapper.h" #include "rs_actiondrawlineparallelthrough.h" +#include "commands.h" +#include "rs_creation.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -RS_ActionDrawLineParallel::RS_ActionDrawLineParallel( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw Parallels", container, graphicView) +RS_ActionDrawLineParallel::RS_ActionDrawLineParallel(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Parallels", + container, graphicView) { - parallel = NULL; - entity = NULL; - distance = 1.0; - number = 1; - coord = Vector(false); + parallel = NULL; + entity = NULL; + distance = 1.0; + number = 1; + coord = Vector(false); } -QAction * RS_ActionDrawLineParallel::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +RS_ActionDrawLineParallel::~RS_ActionDrawLineParallel() { - QAction * action = NULL; - - if (type == RS2::ActionDrawLineParallel) - { - action = new QAction(tr("Para&llel"), 0); -// action = new QAction(tr("Parallel"), tr("Para&llel"), -// QKeySequence(), NULL); - } - else if (type == RS2::ActionDrawArcParallel) - { - action = new QAction(tr("&Concentric"), 0); -// action = new QAction(tr("Concentric"), tr("&Concentric"), -// QKeySequence(), NULL); - } - else if (type == RS2::ActionDrawCircleParallel) - { - action = new QAction(tr("&Concentric"), 0); -// action = new QAction(tr("Concentric"), tr("&Concentric"), -// QKeySequence(), NULL); - } +} - action->setStatusTip(tr("Draw parallels to existing lines, arcs, circles")); - return action; +/*virtual*/ RS2::ActionType RS_ActionDrawLineParallel::rtti() +{ + return RS2::ActionDrawLineParallel; } void RS_ActionDrawLineParallel::trigger() { - RS_PreviewActionInterface::trigger(); + RS_PreviewActionInterface::trigger(); - RS_Creation creation(container, graphicView); - RS_Entity* e = creation.createParallel(coord, - distance, number, - entity); + RS_Creation creation(container, graphicView); + RS_Entity * e = creation.createParallel(coord, distance, number, entity); - if (e==NULL) { - RS_DEBUG->print("RS_ActionDrawLineParallel::trigger:" - " No parallels added\n"); - } + if (e == NULL) + RS_DEBUG->print("RS_ActionDrawLineParallel::trigger: No parallels added\n"); } +void RS_ActionDrawLineParallel::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent begin"); + coord = Vector(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); + entity = catchEntity(e, RS2::ResolveAll); + switch (getStatus()) + { + case SetEntity: + { + deletePreview(); + clearPreview(); + RS_Creation creation(preview, NULL, false); + creation.createParallel(coord, distance, number, entity); + drawPreview(); + } + break; -void RS_ActionDrawLineParallel::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent begin"); - - coord = Vector(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); - - entity = catchEntity(e, RS2::ResolveAll); - - switch (getStatus()) { - case SetEntity: { - deletePreview(); - clearPreview(); - - RS_Creation creation(preview, NULL, false); - creation.createParallel(coord, - distance, number, - entity); - - drawPreview(); - } - break; - - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDrawLineParallel::mouseMoveEvent end"); } +void RS_ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + if (e->button() == Qt::RightButton) + init(getStatus() - 1); + else + trigger(); +} - -void RS_ActionDrawLineParallel::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - init(getStatus()-1); - } else { - trigger(); - } +void RS_ActionDrawLineParallel::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetEntity: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify Distance <%1> or select entity or [%2]") + .arg(distance).arg(RS_COMMANDS->command("through")), + tr("Cancel")); + break; + + case SetNumber: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } +void RS_ActionDrawLineParallel::showOptions() +{ + RS_ActionInterface::showOptions(); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); -void RS_ActionDrawLineParallel::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetEntity: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify Distance <%1> or select entity or [%2]") - .arg(distance).arg(RS_COMMANDS->command("through")), - tr("Cancel")); - break; + updateMouseButtonHints(); +} - case SetNumber: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), ""); - break; +void RS_ActionDrawLineParallel::hideOptions() +{ + RS_ActionInterface::hideOptions(); - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } +void RS_ActionDrawLineParallel::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + if (checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); -void RS_ActionDrawLineParallel::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } - updateMouseButtonHints(); -} + return; + } + switch (getStatus()) + { + case SetEntity: + if (checkCommand("through", c)) + { + finish(); + graphicView->setCurrentAction(new RS_ActionDrawLineParallelThrough(*container, + *graphicView)); + } + else if (checkCommand("number", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetNumber); + } + else + { + bool ok; + double d = RS_Math::eval(c, &ok); + + if (ok && d > 1.0e-10) + distance = d; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + + updateMouseButtonHints(); + //setStatus(SetEntity); + } + break; + + case SetNumber: + { + bool ok; + int n = c.toInt(&ok); + if (ok) + { + if (n > 0 && n < 100) + number = n; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. Try 1..99")); -void RS_ActionDrawLineParallel::hideOptions() { - RS_ActionInterface::hideOptions(); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } -} + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(SetEntity); + } + break; -void RS_ActionDrawLineParallel::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 SetEntity: { - if (checkCommand("through", c)) { - finish(); - graphicView->setCurrentAction( - new RS_ActionDrawLineParallelThrough(*container, - *graphicView)); - } else if (checkCommand("number", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetNumber); - } else { - bool ok; - double d = RS_Math::eval(c, &ok); - if (ok==true && d>1.0e-10) { - distance = d; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - updateMouseButtonHints(); - //setStatus(SetEntity); - } - } - break; - - case SetNumber: { - bool ok; - int n = c.toInt(&ok); - if (ok==true) { - if (n>0 && n<100) { - number = n; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " - "Try 1..99")); - } - } - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - setStatus(SetEntity); - } - break; - - default: - break; - } + default: + break; + } } +QStringList RS_ActionDrawLineParallel::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetEntity: + cmd += command("number"); + cmd += command("through"); + break; -QStringList RS_ActionDrawLineParallel::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetEntity: - cmd += command("number"); - cmd += command("through"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } +void RS_ActionDrawLineParallel::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} - -void RS_ActionDrawLineParallel::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineParallel::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); } +double RS_ActionDrawLineParallel::getDistance() +{ + return distance; +} +void RS_ActionDrawLineParallel::setDistance(double d) +{ + distance = d; +} -void RS_ActionDrawLineParallel::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } +int RS_ActionDrawLineParallel::getNumber() +{ + return number; } +void RS_ActionDrawLineParallel::setNumber(int n) +{ + number = n; +} -// EOF diff --git a/src/actions/rs_actiondrawlineparallel.h b/src/actions/rs_actiondrawlineparallel.h index d357e0a..162e2de 100644 --- a/src/actions/rs_actiondrawlineparallel.h +++ b/src/actions/rs_actiondrawlineparallel.h @@ -1,8 +1,11 @@ #ifndef RS_ACTIONDRAWLINEPARALLEL_H #define RS_ACTIONDRAWLINEPARALLEL_H +#include "rs_line.h" #include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to draw parallel @@ -10,83 +13,49 @@ * * @author Andrew Mustun */ -class RS_ActionDrawLineParallel : public RS_PreviewActionInterface { - //Q_OBJECT -private: - enum Status { - SetEntity, /**< Choose original entity. */ - //SetDistance, /**< Setting distance in the command line. */ - SetNumber /**< Setting number in the command line. */ - //SetThrough /**< Setting a point for the parallel to go through. */ - }; - -public: - RS_ActionDrawLineParallel(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLineParallel() {} - - static QAction* createGUIAction(RS2::ActionType type, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawLineParallel; - } - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - double getDistance() { - return distance; - } - - void setDistance(double d) { - distance = d; - } - - int getNumber() { - return number; - } - - void setNumber(int n) { - number = n; - } - -private: - /** Closest parallel. */ - RS_Entity* parallel; - /** Data of new line */ - RS_LineData data; - /** Distance of the parallel. */ - double distance; - /** Number of parallels. */ - int number; - /** Coordinate of the mouse. */ - Vector coord; - /** Original entity. */ - RS_Entity* entity; - /** - * Commands - */ - /* - QString cmdDistance; - QString cmdDistance2; - QString cmdDistance3; - - QString cmdNumber; - QString cmdNumber2; - QString cmdNumber3; - */ +class RS_ActionDrawLineParallel: public RS_PreviewActionInterface +{ + private: + enum Status { + SetEntity, /**< Choose original entity. */ + //SetDistance, /**< Setting distance in the command line. */ + SetNumber /**< Setting number in the command line. */ + //SetThrough /**< Setting a point for the parallel to go through. */ + }; + + public: + RS_ActionDrawLineParallel(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLineParallel(); + + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + double getDistance(); + void setDistance(double d); + int getNumber(); + void setNumber(int n); + + private: + /** Closest parallel. */ + RS_Entity * parallel; + /** Data of new line */ + RS_LineData data; + /** Distance of the parallel. */ + double distance; + /** Number of parallels. */ + int number; + /** Coordinate of the mouse. */ + Vector coord; + /** Original entity. */ + RS_Entity * entity; }; #endif diff --git a/src/actions/rs_actiondrawlineparallelthrough.cpp b/src/actions/rs_actiondrawlineparallelthrough.cpp index 79203c8..aa9db00 100644 --- a/src/actions/rs_actiondrawlineparallelthrough.cpp +++ b/src/actions/rs_actiondrawlineparallelthrough.cpp @@ -1,291 +1,293 @@ -/**************************************************************************** -** $Id: rs_actiondrawlineparallelthrough.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlineparallelthrough.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_actiondrawlineparallelthrough.h" #include "rs_creation.h" -#include "rs_snapper.h" - - +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" RS_ActionDrawLineParallelThrough::RS_ActionDrawLineParallelThrough( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw Parallels", container, graphicView) { - - parallel = NULL; - entity = NULL; - distance = 1.0; - number = 1; - coord = Vector(false); + RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_PreviewActionInterface("Draw Parallels", container, graphicView) +{ + parallel = NULL; + entity = NULL; + distance = 1.0; + number = 1; + coord = Vector(false); } - -QAction* RS_ActionDrawLineParallelThrough::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLineParallelThrough::~RS_ActionDrawLineParallelThrough() { - QAction * action = new QAction(tr("Par&allel through point"), 0); -// QAction* action = new QAction(tr("Parallel through point"), -// tr("Par&allel through point"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw parallel through a given point")); - return action; } -void RS_ActionDrawLineParallelThrough::trigger() { - RS_PreviewActionInterface::trigger(); - deleteSnapper(); - - if (entity!=NULL) { - RS_Creation creation(container, graphicView); - RS_Entity* e = creation.createParallelThrough(coord, - number, - entity); - - if (e==NULL) { - RS_DEBUG->print("RS_ActionDrawLineParallelThrough::trigger:" - " No parallels added\n"); - } - } +/*virtual*/ RS2::ActionType RS_ActionDrawLineParallelThrough::rtti() +{ + return RS2::ActionDrawLineParallelThrough; } - - -void RS_ActionDrawLineParallelThrough::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent begin"); - - - switch (getStatus()) { - case SetEntity: { - entity = catchEntity(e, RS2::ResolveAll); - /*deletePreview(); - clearPreview(); - - RS_Creation creation(preview, NULL, false); - creation.createParallelThrough(coord, - number, - entity); - - drawPreview();*/ - } - break; - - case SetPos: { - coord = snapPoint(e); - //Vector(graphicView->toGraphX(e->x()), - // graphicView->toGraphY(e->y())); - deletePreview(); - clearPreview(); - - RS_Creation creation(preview, NULL, false); - creation.createParallelThrough(coord, - number, - entity); - - drawPreview(); - } - break; - - default: - break; - } - - RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent end"); +void RS_ActionDrawLineParallelThrough::trigger() +{ + RS_PreviewActionInterface::trigger(); + deleteSnapper(); + + if (entity != NULL) + { + RS_Creation creation(container, graphicView); + RS_Entity * e = creation.createParallelThrough(coord, number, entity); + + if (e == NULL) + RS_DEBUG->print("RS_ActionDrawLineParallelThrough::trigger:" + " No parallels added\n"); + } } - - -void RS_ActionDrawLineParallelThrough::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetEntity: - entity = catchEntity(e, RS2::ResolveAll); - if (entity!=NULL) { - entity->setHighlighted(true); - graphicView->drawEntity(entity); - setStatus(SetPos); - } - break; - case SetPos: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - if (entity!=NULL) { - entity->setHighlighted(false); - graphicView->drawEntity(entity); - entity=NULL; - } - init(getStatus()-1); - } +void RS_ActionDrawLineParallelThrough::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent begin"); + + switch (getStatus()) + { + case SetEntity: + entity = catchEntity(e, RS2::ResolveAll); + /*deletePreview(); + clearPreview(); + + RS_Creation creation(preview, NULL, false); + creation.createParallelThrough(coord, + number, + entity); + + drawPreview();*/ + break; + + case SetPos: + { + coord = snapPoint(e); + //Vector(graphicView->toGraphX(e->x()), + // graphicView->toGraphY(e->y())); + deletePreview(); + clearPreview(); + + RS_Creation creation(preview, NULL, false); + creation.createParallelThrough(coord, + number, + entity); + + drawPreview(); + } + break; + + default: + break; + } + + RS_DEBUG->print("RS_ActionDrawLineParallelThrough::mouseMoveEvent end"); } - - -void RS_ActionDrawLineParallelThrough::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetPos: - coord = mouse; - trigger(); - break; - - default: - break; - } +void RS_ActionDrawLineParallelThrough::mouseReleaseEvent(QMouseEvent * e) +{ +// if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) + if (e->button() == Qt::LeftButton) + { + switch (getStatus()) + { + case SetEntity: + entity = catchEntity(e, RS2::ResolveAll); + + if (entity != NULL) + { + entity->setHighlighted(true); + graphicView->drawEntity(entity); + setStatus(SetPos); + } + + break; + + case SetPos: + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + + default: + break; + } + } +// else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) + else if (e->button() == Qt::RightButton) + { + deletePreview(); + deleteSnapper(); + + if (entity != NULL) + { + entity->setHighlighted(false); + graphicView->drawEntity(entity); + entity = NULL; + } + + init(getStatus() - 1); + } } +void RS_ActionDrawLineParallelThrough::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + Vector mouse = *e; -void RS_ActionDrawLineParallelThrough::updateMouseButtonHints() { - switch (getStatus()) { - case SetEntity: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity"), tr("Cancel")); - break; - - case SetPos: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify through point"), - tr("Back")); - break; - - case SetNumber: - RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back")); - break; + switch (getStatus()) + { + case SetPos: + coord = mouse; + trigger(); + break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } + default: + break; + } } - - -void RS_ActionDrawLineParallelThrough::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); - updateMouseButtonHints(); +void RS_ActionDrawLineParallelThrough::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetEntity: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity"), tr("Cancel")); + break; + + case SetPos: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify through point"), tr("Back")); + break; + + case SetNumber: + RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } +void RS_ActionDrawLineParallelThrough::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDrawLineParallelThrough::hideOptions() { - RS_ActionInterface::hideOptions(); - - RS_DIALOGFACTORY->requestOptions(this, false); + RS_DIALOGFACTORY->requestOptions(this, true); + updateMouseButtonHints(); } +void RS_ActionDrawLineParallelThrough::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawLineParallelThrough::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - switch (getStatus()) { - case SetEntity: - case SetPos: { - if (checkCommand("number", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetNumber); - } - } - break; - - case SetNumber: { - bool ok; - int n = c.toInt(&ok); - if (ok==true) { - if (n>0 && n<100) { - number = n; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " - "Try 1..99")); - } - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - default: - break; - } + RS_DIALOGFACTORY->requestOptions(this, false); } +void RS_ActionDrawLineParallelThrough::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + switch (getStatus()) + { + case SetEntity: + case SetPos: + + if (checkCommand("number", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetNumber); + } + break; + + case SetNumber: { + bool ok; + int n = c.toInt(&ok); + + if (ok == true) + { + if (n > 0 && n < 100) + number = n; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " + "Try 1..99")); + } + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + default: + break; + } +} +QStringList RS_ActionDrawLineParallelThrough::getAvailableCommands() +{ + QStringList cmd; -QStringList RS_ActionDrawLineParallelThrough::getAvailableCommands() { - QStringList cmd; + switch (getStatus()) + { + case SetEntity: + cmd += command("number"); + break; - switch (getStatus()) { - case SetEntity: - cmd += command("number"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - - -void RS_ActionDrawLineParallelThrough::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineParallelThrough::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionDrawLineParallelThrough::updateToolBar() +{ + if (getStatus() == SetPos && !isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); +} - -void RS_ActionDrawLineParallelThrough::updateToolBar() { - if (getStatus()==SetPos && !isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } +int RS_ActionDrawLineParallelThrough::getNumber() +{ + return number; } +void RS_ActionDrawLineParallelThrough::setNumber(int n) +{ + number = n; +} -// EOF diff --git a/src/actions/rs_actiondrawlineparallelthrough.h b/src/actions/rs_actiondrawlineparallelthrough.h index d71d1a5..4963bc8 100644 --- a/src/actions/rs_actiondrawlineparallelthrough.h +++ b/src/actions/rs_actiondrawlineparallelthrough.h @@ -1,110 +1,59 @@ -/**************************************************************************** -** $Id: rs_actiondrawlineparallelthrough.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINEPARALLELTHROUGH_H #define RS_ACTIONDRAWLINEPARALLELTHROUGH_H +#include "rs_line.h" #include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Entity; /** - * This action class can handle user events to draw parallel + * This action class can handle user events to draw parallel * lines, arcs and circles. * * @author Andrew Mustun */ -class RS_ActionDrawLineParallelThrough : public RS_PreviewActionInterface { - //Q_OBJECT -private: - enum Status { - SetEntity, /**< Choose original entity. */ - SetPos, /**< Setting point for this parallel to go through. */ - SetNumber /**< Setting number in the command line. */ - }; - -public: - RS_ActionDrawLineParallelThrough(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLineParallelThrough() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawLineParallelThrough; - } - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - int getNumber() { - return number; - } - - void setNumber(int n) { - number = n; - } - -private: - /** Closest parallel. */ - RS_Entity* parallel; - /** Data of new line */ - RS_LineData data; - /** Number of parallels. */ - int number; - /** Coordinate of the mouse. */ - Vector coord; - /** Original entity. */ - RS_Entity* entity; - /** Last status before entering length or number. */ - Status lastStatus; - /** - * Commands - */ - /* - QString cmdDistance; - QString cmdDistance2; - QString cmdDistance3; - - QString cmdNumber; - QString cmdNumber2; - QString cmdNumber3; - */ +class RS_ActionDrawLineParallelThrough: public RS_PreviewActionInterface +{ + private: + enum Status { + SetEntity, /**< Choose original entity. */ + SetPos, /**< Setting point for this parallel to go through. */ + SetNumber /**< Setting number in the command line. */ + }; + + public: + RS_ActionDrawLineParallelThrough(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLineParallelThrough(); + + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + int getNumber(); + void setNumber(int n); + + private: + /** Closest parallel. */ + RS_Entity * parallel; + /** Data of new line */ + RS_LineData data; + /** Number of parallels. */ + int number; + /** Coordinate of the mouse. */ + Vector coord; + /** Original entity. */ + RS_Entity * entity; + /** Last status before entering length or number. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actiondrawlinepolygon.cpp b/src/actions/rs_actiondrawlinepolygon.cpp index 2a43957..c32d062 100644 --- a/src/actions/rs_actiondrawlinepolygon.cpp +++ b/src/actions/rs_actiondrawlinepolygon.cpp @@ -1,275 +1,266 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinepolygon.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinepolygon.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_actiondrawlinepolygon.h" #include "rs_creation.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" +RS_ActionDrawLinePolygon::RS_ActionDrawLinePolygon(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Polygons", + container, graphicView) +{ + center = Vector(false); + corner = Vector(false); - -RS_ActionDrawLinePolygon::RS_ActionDrawLinePolygon( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw Polygons", container, graphicView) { - - center = Vector(false); - corner = Vector(false); - - number = 3; + number = 3; } -QAction* RS_ActionDrawLinePolygon::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLinePolygon::~RS_ActionDrawLinePolygon() { - QAction * action = new QAction(tr("Pol&ygon (Cen,Cor)"), 0); -// QAction* action = new QAction(tr("Polygon"), tr("Pol&ygon (Cen,Cor)"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw polygon with center and corner")); - return action; } +/*virtual*/ RS2::ActionType RS_ActionDrawLinePolygon::rtti() +{ + return RS2::ActionDrawLinePolygon; +} -void RS_ActionDrawLinePolygon::trigger() { - RS_PreviewActionInterface::trigger(); +void RS_ActionDrawLinePolygon::trigger() +{ + RS_PreviewActionInterface::trigger(); - deleteSnapper(); - deletePreview(); - clearPreview(); + deleteSnapper(); + deletePreview(); + clearPreview(); - RS_Creation creation(container, graphicView); - bool ok = creation.createPolygon(center, corner, number); + RS_Creation creation(container, graphicView); + bool ok = creation.createPolygon(center, corner, number); - if (!ok) { - RS_DEBUG->print("RS_ActionDrawLinePolygon::trigger:" - " No polygon added\n"); - } + if (!ok) + RS_DEBUG->print("RS_ActionDrawLinePolygon::trigger: No polygon added\n"); } +void RS_ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLinePolygon::mouseMoveEvent begin"); + Vector mouse = snapPoint(e); -void RS_ActionDrawLinePolygon::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLinePolygon::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); + switch (getStatus()) + { + case SetCenter: + break; - switch (getStatus()) { - case SetCenter: - break; + case SetCorner: - case SetCorner: - if (center.valid) { - corner = mouse; - deletePreview(); - clearPreview(); + if (center.valid) + { + corner = mouse; + deletePreview(); + clearPreview(); - RS_Creation creation(preview, NULL, false); - creation.createPolygon(center, corner, number); + RS_Creation creation(preview, NULL, false); + creation.createPolygon(center, corner, number); - drawPreview(); - } - break; + drawPreview(); + } + break; - default: - break; - } + default: + break; + } } - - -void RS_ActionDrawLinePolygon::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - clearPreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawLinePolygon::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + clearPreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawLinePolygon::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetCenter: - center = mouse; - setStatus(SetCorner); - graphicView->moveRelativeZero(mouse); - break; - - case SetCorner: - corner = mouse; - trigger(); - break; - - default: - break; - } +void RS_ActionDrawLinePolygon::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetCenter: + center = mouse; + setStatus(SetCorner); + graphicView->moveRelativeZero(mouse); + break; + + case SetCorner: + corner = mouse; + trigger(); + break; + + default: + break; + } } - - -void RS_ActionDrawLinePolygon::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetCenter: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), - ""); - break; - - case SetCorner: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), ""); - break; - - case SetNumber: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), ""); - break; - - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDrawLinePolygon::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetCenter: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify center"), + ""); + break; + + case SetCorner: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify a corner"), ""); + break; + + case SetNumber: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter number:"), ""); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } +void RS_ActionDrawLinePolygon::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDrawLinePolygon::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDrawLinePolygon::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawLinePolygon::hideOptions() { - RS_ActionInterface::hideOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionDrawLinePolygon::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 SetCenter: - case SetCorner: - if (checkCommand("number", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetNumber); - } - break; - - case SetNumber: { - bool ok; - int n = c.toInt(&ok); - if (ok==true) { - if (n>0 && n<10000) { - number = n; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " - "Try 1..9999")); - } - } - } 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; - - default: - break; - } +void RS_ActionDrawLinePolygon::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 SetCenter: + case SetCorner: + + if (checkCommand("number", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetNumber); + } + break; + + case SetNumber: { + bool ok; + int n = c.toInt(&ok); + + if (ok == true) + { + if (n > 0 && n < 10000) + number = n; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " + "Try 1..9999")); + + } + 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; + + default: + break; + } } +QStringList RS_ActionDrawLinePolygon::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetCenter: + case SetCorner: + cmd += command("number"); + break; -QStringList RS_ActionDrawLinePolygon::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetCenter: - case SetCorner: - cmd += command("number"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - - -void RS_ActionDrawLinePolygon::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLinePolygon::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionDrawLinePolygon::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); + } +} - -void RS_ActionDrawLinePolygon::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } - } +int RS_ActionDrawLinePolygon::getNumber() +{ + return number; } +void RS_ActionDrawLinePolygon::setNumber(int n) +{ + number = n; +} -// EOF diff --git a/src/actions/rs_actiondrawlinepolygon.h b/src/actions/rs_actiondrawlinepolygon.h index dd588ad..13a377e 100644 --- a/src/actions/rs_actiondrawlinepolygon.h +++ b/src/actions/rs_actiondrawlinepolygon.h @@ -1,93 +1,51 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinepolygon.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINEPOLYGON_H #define RS_ACTIONDRAWLINEPOLYGON_H #include "rs_previewactioninterface.h" - +#include "vector.h" /** * This action class can handle user events to draw polygons. * * @author Andrew Mustun */ -class RS_ActionDrawLinePolygon : public RS_PreviewActionInterface { - //Q_OBJECT -private: - enum Status { - SetCenter, /**< Setting center. */ - SetCorner, /**< Setting corner. */ - SetNumber /**< Setting number in the command line. */ - }; - -public: - RS_ActionDrawLinePolygon(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLinePolygon() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawLinePolygon; - } - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - int getNumber() { - return number; - } - - void setNumber(int n) { - number = n; - } - -private: - /** Center of polygon */ - Vector center; - /** Edge */ - Vector corner; - /** Number of edges. */ - int number; - /** Last status before entering text. */ - Status lastStatus; +class RS_ActionDrawLinePolygon: public RS_PreviewActionInterface +{ + private: + enum Status { + SetCenter, /**< Setting center. */ + SetCorner, /**< Setting corner. */ + SetNumber /**< Setting number in the command line. */ + }; + + public: + RS_ActionDrawLinePolygon(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLinePolygon(); + + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + int getNumber(); + void setNumber(int n); + + private: + /** Center of polygon */ + Vector center; + /** Edge */ + Vector corner; + /** Number of edges. */ + int number; + /** Last status before entering text. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actiondrawlinepolygon2.cpp b/src/actions/rs_actiondrawlinepolygon2.cpp index 3489ab4..feaa99f 100644 --- a/src/actions/rs_actiondrawlinepolygon2.cpp +++ b/src/actions/rs_actiondrawlinepolygon2.cpp @@ -1,276 +1,267 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinepolygon2.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinepolygon2.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_actiondrawlinepolygon2.h" #include "rs_creation.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" +RS_ActionDrawLinePolygon2::RS_ActionDrawLinePolygon2(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Polygons", + container, graphicView) +{ + corner1 = Vector(false); + corner2 = Vector(false); - -RS_ActionDrawLinePolygon2::RS_ActionDrawLinePolygon2( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw Polygons", container, graphicView) { - - corner1 = Vector(false); - corner2 = Vector(false); - - number = 3; + number = 3; } -QAction* RS_ActionDrawLinePolygon2::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLinePolygon2::~RS_ActionDrawLinePolygon2() { - QAction * action = new QAction(tr("Polygo&n (Cor,Cor)"), 0); -// QAction* action = new QAction(tr("Polygon"), tr("Polygo&n (Cor,Cor)"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw polygon with two corners")); - return action; } +/*virtual*/ RS2::ActionType RS_ActionDrawLinePolygon2::rtti() +{ + return RS2::ActionDrawLinePolygon2; +} -void RS_ActionDrawLinePolygon2::trigger() { - RS_PreviewActionInterface::trigger(); +void RS_ActionDrawLinePolygon2::trigger() +{ + RS_PreviewActionInterface::trigger(); - deleteSnapper(); - deletePreview(); - clearPreview(); + deleteSnapper(); + deletePreview(); + clearPreview(); - RS_Creation creation(container, graphicView); - bool ok = creation.createPolygon2(corner1, corner2, number); + RS_Creation creation(container, graphicView); + bool ok = creation.createPolygon2(corner1, corner2, number); - if (!ok) { - RS_DEBUG->print("RS_ActionDrawLinePolygon2::trigger:" - " No polygon added\n"); - } + if (!ok) + RS_DEBUG->print("RS_ActionDrawLinePolygon2::trigger: No polygon added\n"); } +void RS_ActionDrawLinePolygon2::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLinePolygon2::mouseMoveEvent begin"); + Vector mouse = snapPoint(e); -void RS_ActionDrawLinePolygon2::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLinePolygon2::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); + switch (getStatus()) + { + case SetCorner1: + break; - switch (getStatus()) { - case SetCorner1: - break; + case SetCorner2: - case SetCorner2: - if (corner1.valid) { - corner2 = mouse; - deletePreview(); - clearPreview(); + if (corner1.valid) + { + corner2 = mouse; + deletePreview(); + clearPreview(); - RS_Creation creation(preview, NULL, false); - creation.createPolygon2(corner1, corner2, number); + RS_Creation creation(preview, NULL, false); + creation.createPolygon2(corner1, corner2, number); - drawPreview(); - } - break; + drawPreview(); + } + break; - default: - break; - } + default: + break; + } } - - -void RS_ActionDrawLinePolygon2::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - clearPreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawLinePolygon2::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + clearPreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawLinePolygon2::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetCorner1: - corner1 = mouse; - setStatus(SetCorner2); - graphicView->moveRelativeZero(mouse); - break; - - case SetCorner2: - corner2 = mouse; - trigger(); - break; - - default: - break; - } +void RS_ActionDrawLinePolygon2::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetCorner1: + corner1 = mouse; + setStatus(SetCorner2); + graphicView->moveRelativeZero(mouse); + break; + + case SetCorner2: + corner2 = mouse; + trigger(); + break; + + default: + break; + } } - - -void RS_ActionDrawLinePolygon2::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetCorner1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"), - tr("Cancel")); - break; - - case SetCorner2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"), - tr("Back")); - break; - - case SetNumber: - RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back")); - break; - - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDrawLinePolygon2::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetCorner1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"), + tr("Cancel")); + break; + + case SetCorner2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"), + tr("Back")); + break; + + case SetNumber: + RS_DIALOGFACTORY->updateMouseWidget(tr("Number:"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } +void RS_ActionDrawLinePolygon2::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDrawLinePolygon2::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDrawLinePolygon2::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawLinePolygon2::hideOptions() { - RS_ActionInterface::hideOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionDrawLinePolygon2::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 SetCorner1: - case SetCorner2: - if (checkCommand("number", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetNumber); - } - break; - - case SetNumber: { - bool ok; - int n = c.toInt(&ok); - if (ok==true) { - if (n>0 && n<10000) { - number = n; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " - "Try 1..9999")); - } - } - } 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; - - default: - break; - } +void RS_ActionDrawLinePolygon2::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 SetCorner1: + case SetCorner2: + + if (checkCommand("number", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetNumber); + } + break; + + case SetNumber: { + bool ok; + int n = c.toInt(&ok); + + if (ok == true) + { + if (n > 0 && n < 10000) + number = n; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid number. " + "Try 1..9999")); + + } + 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; + + default: + break; + } } +QStringList RS_ActionDrawLinePolygon2::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetCorner1: + case SetCorner2: + cmd += command("number"); + break; -QStringList RS_ActionDrawLinePolygon2::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case SetCorner1: - case SetCorner2: - cmd += command("number"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - - -void RS_ActionDrawLinePolygon2::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLinePolygon2::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionDrawLinePolygon2::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); + } +} - -void RS_ActionDrawLinePolygon2::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } - } +int RS_ActionDrawLinePolygon2::getNumber() +{ + return number; } +void RS_ActionDrawLinePolygon2::setNumber(int n) +{ + number = n; +} -// EOF diff --git a/src/actions/rs_actiondrawlinepolygon2.h b/src/actions/rs_actiondrawlinepolygon2.h index 24b15b2..e856976 100644 --- a/src/actions/rs_actiondrawlinepolygon2.h +++ b/src/actions/rs_actiondrawlinepolygon2.h @@ -1,93 +1,51 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinepolygon2.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINEPOLYGON2_H #define RS_ACTIONDRAWLINEPOLYGON2_H #include "rs_previewactioninterface.h" - +#include "vector.h" /** * This action class can handle user events to draw polygons. * * @author Andrew Mustun */ -class RS_ActionDrawLinePolygon2 : public RS_PreviewActionInterface { - //Q_OBJECT -private: - enum Status { - SetCorner1, /**< Setting center 1. */ - SetCorner2, /**< Setting corner 2. */ - SetNumber /**< Setting number in the command line. */ - }; - -public: - RS_ActionDrawLinePolygon2(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLinePolygon2() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawLinePolygon2; - } - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - int getNumber() { - return number; - } - - void setNumber(int n) { - number = n; - } - -private: - /** 1st corner */ - Vector corner1; - /** 2nd corner */ - Vector corner2; - /** Number of edges. */ - int number; - /** Last status before entering text. */ - Status lastStatus; +class RS_ActionDrawLinePolygon2: public RS_PreviewActionInterface +{ + private: + enum Status { + SetCorner1, /**< Setting center 1. */ + SetCorner2, /**< Setting corner 2. */ + SetNumber /**< Setting number in the command line. */ + }; + + public: + RS_ActionDrawLinePolygon2(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLinePolygon2(); + + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + int getNumber(); + void setNumber(int n); + + private: + /** 1st corner */ + Vector corner1; + /** 2nd corner */ + Vector corner2; + /** Number of edges. */ + int number; + /** Last status before entering text. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actiondrawlinerectangle.cpp b/src/actions/rs_actiondrawlinerectangle.cpp index e8ef45c..3dc5b2d 100644 --- a/src/actions/rs_actiondrawlinerectangle.cpp +++ b/src/actions/rs_actiondrawlinerectangle.cpp @@ -1,232 +1,214 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinerectangle.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinerectangle.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_actiondrawlinerectangle.h" -#include "rs_snapper.h" - +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" RS_ActionDrawLineRectangle::RS_ActionDrawLineRectangle( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw rectangles", - container, graphicView) { - reset(); + RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_PreviewActionInterface("Draw rectangles", container, graphicView) +{ + reset(); } - - -RS_ActionDrawLineRectangle::~RS_ActionDrawLineRectangle() {} - -QAction* RS_ActionDrawLineRectangle::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLineRectangle::~RS_ActionDrawLineRectangle() { - QAction * action = new QAction(tr("&Rectangle"), 0); -// QAction* action = new QAction(tr("Rectangle"), tr("&Rectangle"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw rectangles")); - return action; } - -void RS_ActionDrawLineRectangle::reset() { - for (int i=0; i<4; ++i) { - data[i] = RS_LineData(Vector(false), - Vector(false)); - } +void RS_ActionDrawLineRectangle::reset() +{ + for (int i = 0; i < 4; ++i) + data[i] = RS_LineData(Vector(false), Vector(false)); } - - -void RS_ActionDrawLineRectangle::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); +void RS_ActionDrawLineRectangle::init(int status) +{ + RS_PreviewActionInterface::init(status); + reset(); } - - -void RS_ActionDrawLineRectangle::trigger() { - RS_PreviewActionInterface::trigger(); - - RS_Line* line[4]; - preparePreview(); - - // create and add rectangle: - for (int i=0; i<4; ++i) { - line[i] = new RS_Line(container, - data[i]); - line[i]->setLayerToActive(); - line[i]->setPenToActive(); - container->addEntity(line[i]); - } - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - for (int i=0; i<4; ++i) { - document->addUndoable(line[i]); - } - document->endUndoCycle(); - } - - // upd. view - deleteSnapper(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - for (int i=0; i<4; ++i) { - graphicView->drawEntity(line[i]); - RS_DEBUG->print("RS_ActionDrawLineRectangle::trigger():" - " line added: %d", - line[i]->getId()); - } - graphicView->moveRelativeZero(corner2); +void RS_ActionDrawLineRectangle::trigger() +{ + RS_PreviewActionInterface::trigger(); + + RS_Line * line[4]; + preparePreview(); + + // create and add rectangle: + for (int i = 0; i < 4; ++i) + { + line[i] = new RS_Line(container, + data[i]); + line[i]->setLayerToActive(); + line[i]->setPenToActive(); + container->addEntity(line[i]); + } + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + + for (int i = 0; i < 4; ++i) + document->addUndoable(line[i]); + document->endUndoCycle(); + } + + // upd. view + deleteSnapper(); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + + for (int i = 0; i < 4; ++i) + { + graphicView->drawEntity(line[i]); + RS_DEBUG->print("RS_ActionDrawLineRectangle::trigger():" + " line added: %d", + line[i]->getId()); + } + graphicView->moveRelativeZero(corner2); } +void RS_ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent begin"); + Vector mouse = snapPoint(e); -void RS_ActionDrawLineRectangle::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); - if (getStatus()==SetCorner2 && corner1.valid) { - corner2 = mouse; - deletePreview(); - clearPreview(); + if (getStatus() == SetCorner2 && corner1.valid) + { + corner2 = mouse; + deletePreview(); + clearPreview(); - preparePreview(); + preparePreview(); - for (int i=0; i<4; ++i) { - preview->addEntity(new RS_Line(preview, data[i])); - } - drawPreview(); - } + for (int i = 0; i < 4; ++i) + preview->addEntity(new RS_Line(preview, data[i])); + drawPreview(); + } - RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionDrawLineRectangle::mouseMoveEvent end"); } - -void RS_ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionDrawLineRectangle::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionDrawLineRectangle::preparePreview() { - data[0] = RS_LineData(corner1, Vector(corner2.x, corner1.y)); - data[1] = RS_LineData(Vector(corner2.x, corner1.y), corner2); - data[2] = RS_LineData(corner2, Vector(corner1.x, corner2.y)); - data[3] = RS_LineData(Vector(corner1.x, corner2.y), corner1); +void RS_ActionDrawLineRectangle::preparePreview() +{ + data[0] = RS_LineData(corner1, Vector(corner2.x, corner1.y)); + data[1] = RS_LineData(Vector(corner2.x, corner1.y), corner2); + data[2] = RS_LineData(corner2, Vector(corner1.x, corner2.y)); + data[3] = RS_LineData(Vector(corner1.x, corner2.y), corner1); } - -void RS_ActionDrawLineRectangle::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetCorner1: - corner1 = mouse; - graphicView->moveRelativeZero(mouse); - setStatus(SetCorner2); - break; - - case SetCorner2: - corner2 = mouse; - trigger(); - setStatus(SetCorner1); - break; - - default: - break; - } +void RS_ActionDrawLineRectangle::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetCorner1: + corner1 = mouse; + graphicView->moveRelativeZero(mouse); + setStatus(SetCorner2); + break; + + case SetCorner2: + corner2 = mouse; + trigger(); + setStatus(SetCorner1); + break; + + default: + break; + } } - - -void RS_ActionDrawLineRectangle::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_ActionDrawLineRectangle::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } } - - -QStringList RS_ActionDrawLineRectangle::getAvailableCommands() { - QStringList cmd; - return cmd; +QStringList RS_ActionDrawLineRectangle::getAvailableCommands() +{ + QStringList cmd; + return cmd; } - -void RS_ActionDrawLineRectangle::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetCorner1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"), - tr("Cancel")); - break; - case SetCorner2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDrawLineRectangle::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetCorner1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"), + tr("Cancel")); + break; + + case SetCorner2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } - -void RS_ActionDrawLineRectangle::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineRectangle::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - -void RS_ActionDrawLineRectangle::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } - } +void RS_ActionDrawLineRectangle::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); + } } // EOF diff --git a/src/actions/rs_actiondrawlinerectangle.h b/src/actions/rs_actiondrawlinerectangle.h index d74ef74..6097a15 100644 --- a/src/actions/rs_actiondrawlinerectangle.h +++ b/src/actions/rs_actiondrawlinerectangle.h @@ -1,88 +1,57 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinerectangle.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINERECTANGLE_H #define RS_ACTIONDRAWLINERECTANGLE_H -#include "rs_previewactioninterface.h" #include "rs_line.h" +#include "rs_previewactioninterface.h" +#include "vector.h" /** - * This action class can handle user events to draw + * This action class can handle user events to draw * rectangles with two corners given. * * @author Andrew Mustun */ -class RS_ActionDrawLineRectangle : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetCorner1, /**< Setting the 1st corner. */ - SetCorner2 /**< Setting the 2nd corner. */ - }; - -public: - RS_ActionDrawLineRectangle(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLineRectangle(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - void reset(); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - void preparePreview(); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - /** - * Line data for the 4 lines. - */ - RS_LineData data[4]; - /** - * 1st corner. - */ - Vector corner1; - /** - * 2nd corner. - */ - Vector corner2; +class RS_ActionDrawLineRectangle: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetCorner1, /**< Setting the 1st corner. */ + SetCorner2 /**< Setting the 2nd corner. */ + }; + + public: + RS_ActionDrawLineRectangle(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLineRectangle(); + + void reset(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + void preparePreview(); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + /** + * Line data for the 4 lines. + */ + RS_LineData data[4]; + /** + * 1st corner. + */ + Vector corner1; + /** + * 2nd corner. + */ + Vector corner2; }; #endif diff --git a/src/actions/rs_actiondrawlinerelangle.cpp b/src/actions/rs_actiondrawlinerelangle.cpp index 3ac5f82..4e69092 100644 --- a/src/actions/rs_actiondrawlinerelangle.cpp +++ b/src/actions/rs_actiondrawlinerelangle.cpp @@ -15,353 +15,363 @@ #include "rs_actiondrawlinerelangle.h" #include "rs_creation.h" -#include "rs_snapper.h" - -RS_ActionDrawLineRelAngle::RS_ActionDrawLineRelAngle( - RS_EntityContainer& container, - RS_GraphicView& graphicView, - double angle, - bool fixedAngle) - :RS_PreviewActionInterface("Draw Lines with relative angles", - container, graphicView) { - - entity = NULL; - this->angle = angle; - this->fixedAngle = fixedAngle; - length = 10.0; - pos = Vector(false); -} +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -QAction * RS_ActionDrawLineRelAngle::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +RS_ActionDrawLineRelAngle::RS_ActionDrawLineRelAngle(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle, bool fixedAngle): + RS_PreviewActionInterface("Draw Lines with relative angles", + container, graphicView) { - QAction * action = NULL; + entity = NULL; + this->angle = angle; + this->fixedAngle = fixedAngle; + length = 10.0; + pos = Vector(false); +} - if (type == RS2::ActionDrawLineRelAngle) - { - action = new QAction(tr("R&elative angle"), 0); -// action = new QAction(tr("Relative angle"), tr("R&elative angle"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw line with relative angle")); - } - else if (type == RS2::ActionDrawLineOrthogonal) - { - action = new QAction(tr("&Orthogonal"), 0); -// action = new QAction(tr("Orthogonal"), tr("&Orthogonal"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw orthogonal line")); - } +RS_ActionDrawLineRelAngle::~RS_ActionDrawLineRelAngle() +{ +} - return action; +/*virtual*/ RS2::ActionType RS_ActionDrawLineRelAngle::rtti() +{ + return RS2::ActionDrawLineRelAngle; } void RS_ActionDrawLineRelAngle::trigger() { - RS_PreviewActionInterface::trigger(); - - deleteSnapper(); - deletePreview(); - clearPreview(); - - RS_Creation creation(container, graphicView); - creation.createLineRelAngle(pos, - entity, - angle, - length); - - /* - if (line!=NULL) { - RS_Entity* newEntity = NULL; - - newEntity = new RS_Line(container, - line->getData()); - - if (newEntity!=NULL) { - newEntity->setLayerToActive(); - newEntity->setPenToActive(); - container->addEntity(newEntity); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(newEntity); - document->endUndoCycle(); - } - deleteSnapper(); - graphicView->drawEntity(newEntity); - setStatus(SetEntity); - } - //reset(); - delete line; - line = NULL; - } else { - RS_DEBUG->print("RS_ActionDrawLineRelAngle::trigger:" - " Line is NULL\n"); - } - */ + RS_PreviewActionInterface::trigger(); + + deleteSnapper(); + deletePreview(); + clearPreview(); + + RS_Creation creation(container, graphicView); + creation.createLineRelAngle(pos, + entity, + angle, + length); + + /* + if (line!=NULL) { + RS_Entity* newEntity = NULL; + + newEntity = new RS_Line(container, + line->getData()); + + if (newEntity!=NULL) { + newEntity->setLayerToActive(); + newEntity->setPenToActive(); + container->addEntity(newEntity); + + // upd. undo list: + if (document!=NULL) { + document->startUndoCycle(); + document->addUndoable(newEntity); + document->endUndoCycle(); + } + deleteSnapper(); + graphicView->drawEntity(newEntity); + setStatus(SetEntity); + } + //reset(); + delete line; + line = NULL; + } else { + RS_DEBUG->print("RS_ActionDrawLineRelAngle::trigger:" + " Line is NULL\n"); + } + */ } +void RS_ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent begin"); + Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); -void RS_ActionDrawLineRelAngle::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent begin"); - - Vector mouse(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); - - switch (getStatus()) { - case SetEntity: - entity = catchEntity(e, RS2::ResolveAll); - break; - - case SetPos: { - //length = graphicView->toGraphDX(graphicView->getWidth()); - //Vector mouse = snapPoint(e); - pos = snapPoint(e); - - /*RS_Creation creation(NULL, NULL); - RS_Line* l = creation.createLineRelAngle(mouse, - entity, - angle, - length);*/ - - deletePreview(); - clearPreview(); - - RS_Creation creation(preview, NULL, false); - creation.createLineRelAngle(pos, - entity, - angle, - length); - - drawPreview(); - - /*if (l!=NULL) { - if (line!=NULL) { - delete line; - } - line = (RS_Line*)l->clone(); + switch (getStatus()) + { + case SetEntity: + entity = catchEntity(e, RS2::ResolveAll); + break; + + case SetPos: { + //length = graphicView->toGraphDX(graphicView->getWidth()); + //Vector mouse = snapPoint(e); + pos = snapPoint(e); + + /*RS_Creation creation(NULL, NULL); + RS_Line* l = creation.createLineRelAngle(mouse, + entity, + angle, + length);*/ + + deletePreview(); + clearPreview(); + + RS_Creation creation(preview, NULL, false); + creation.createLineRelAngle(pos, + entity, + angle, + length); + + drawPreview(); + + /*if (l!=NULL) { + if (line!=NULL) { + delete line; + } + line = (RS_Line*)l->clone(); + + deletePreview(); + clearPreview(); + preview->addEntity(l); + drawPreview(); + }*/ + } + break; - deletePreview(); - clearPreview(); - preview->addEntity(l); - drawPreview(); - }*/ - } - break; + default: + break; + } - default: - break; - } + RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent end"); +} - RS_DEBUG->print("RS_ActionDrawLineRelAngle::mouseMoveEvent end"); +void RS_ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case SetEntity: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL + && (en->rtti() == RS2::EntityLine + || en->rtti() == RS2::EntityArc + || en->rtti() == RS2::EntityCircle)) + { + entity = en; + + entity->setHighlighted(true); + graphicView->drawEntity(entity); + + setStatus(SetPos); + } + } + break; + + case SetPos: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + clearPreview(); + + if (entity != NULL) + { + entity->setHighlighted(false); + graphicView->drawEntity(entity); + } + init(getStatus() - 1); + } } +void RS_ActionDrawLineRelAngle::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + switch (getStatus()) + { + case SetPos: + pos = *e; + trigger(); + break; -void RS_ActionDrawLineRelAngle::mouseReleaseEvent(QMouseEvent* e) { - - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetEntity: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && - (en->rtti()==RS2::EntityLine || - en->rtti()==RS2::EntityArc || - en->rtti()==RS2::EntityCircle)) { - entity = en; - - entity->setHighlighted(true); - graphicView->drawEntity(entity); - - setStatus(SetPos); - } - } - break; - - case SetPos: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - clearPreview(); - if (entity!=NULL) { - entity->setHighlighted(false); - graphicView->drawEntity(entity); - } - init(getStatus()-1); - } + default: + break; + } } +void RS_ActionDrawLineRelAngle::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_ActionDrawLineRelAngle::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - switch (getStatus()) { - case SetPos: - pos = e->getCoordinate(); - trigger(); - break; + switch (getStatus()) + { + case SetEntity: + case SetPos: + + if (!fixedAngle && checkCommand("angle", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetAngle); + } + else if (checkCommand("length", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + setStatus(SetLength); + } + break; + + case SetAngle: { + bool ok; + double a = RS_Math::eval(c, &ok); + + if (ok == true) + angle = RS_Math::deg2rad(a); + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(SetPos); + } + break; - default: - break; - } -} + case SetLength: { + bool ok; + double l = RS_Math::eval(c, &ok); + if (ok == true) + length = l; + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(SetPos); + } + break; -void RS_ActionDrawLineRelAngle::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 SetEntity: - case SetPos: - if (!fixedAngle && checkCommand("angle", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetAngle); - } else if (checkCommand("length", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - setStatus(SetLength); - } - break; - - case SetAngle: { - bool ok; - double a = RS_Math::eval(c, &ok); - if (ok==true) { - angle = RS_Math::deg2rad(a); - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - setStatus(SetPos); - } - break; - - case SetLength: { - bool ok; - double l = RS_Math::eval(c, &ok); - if (ok==true) { - length = l; - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - } - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - setStatus(SetPos); - } - break; - - default: - break; - } + default: + break; + } } +QStringList RS_ActionDrawLineRelAngle::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetPos: + case SetLength: -QStringList RS_ActionDrawLineRelAngle::getAvailableCommands() { - QStringList cmd; + if (!fixedAngle) + cmd += command("angle"); + cmd += command("length"); + break; - switch (getStatus()) { - case SetPos: - case SetLength: - if (!fixedAngle) { - cmd += command("angle"); - } - cmd += command("length"); - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } - -void RS_ActionDrawLineRelAngle::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetEntity: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select base entity"), - tr("Cancel")); - break; - case SetPos: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDrawLineRelAngle::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetEntity: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select base entity"), + tr("Cancel")); + break; + + case SetPos: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify position"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } +void RS_ActionDrawLineRelAngle::showOptions() +{ + RS_ActionInterface::showOptions(); - -void RS_ActionDrawLineRelAngle::showOptions() { - RS_ActionInterface::showOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, true); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDrawLineRelAngle::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionDrawLineRelAngle::hideOptions() { - RS_ActionInterface::hideOptions(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestOptions(this, false); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestOptions(this, false); } +void RS_ActionDrawLineRelAngle::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} - -void RS_ActionDrawLineRelAngle::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineRelAngle::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); + } } +void RS_ActionDrawLineRelAngle::setAngle(double a) +{ + angle = a; +} +double RS_ActionDrawLineRelAngle::getAngle() +{ + return angle; +} -void RS_ActionDrawLineRelAngle::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } - } +void RS_ActionDrawLineRelAngle::setLength(double l) +{ + length = l; } +double RS_ActionDrawLineRelAngle::getLength() +{ + return length; +} +bool RS_ActionDrawLineRelAngle::hasFixedAngle() +{ + return fixedAngle; +} -// EOF diff --git a/src/actions/rs_actiondrawlinerelangle.h b/src/actions/rs_actiondrawlinerelangle.h index 9bd1ca5..6908afa 100644 --- a/src/actions/rs_actiondrawlinerelangle.h +++ b/src/actions/rs_actiondrawlinerelangle.h @@ -1,8 +1,11 @@ #ifndef RS_ACTIONDRAWLINERELANGLE_H #define RS_ACTIONDRAWLINERELANGLE_H +#include "rs_line.h" #include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to draw lines with a given angle @@ -10,86 +13,57 @@ * * @author Andrew Mustun */ -class RS_ActionDrawLineRelAngle : public RS_PreviewActionInterface { - //Q_OBJECT -private: - enum Status { - SetEntity, /**< Choose entity. */ - SetPos, /**< Choose position. */ - SetAngle, /**< Set angle in console. */ - SetLength /**< Set length in console. */ - }; - -public: - RS_ActionDrawLineRelAngle(RS_EntityContainer& container, - RS_GraphicView& graphicView, - double angle=0.0, - bool fixedAngle=false); - ~RS_ActionDrawLineRelAngle() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionDrawLineRelAngle; - } - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - void setAngle(double a) { - angle = a; - } - - double getAngle() { - return angle; - } - - void setLength(double l) { - length = l; - } - - double getLength() { - return length; - } - - bool hasFixedAngle() { - return fixedAngle; - } - -private: - /** new line */ - //RS_Line* line; - /** Chosen entity */ - RS_Entity* entity; - /** Chosen position */ - Vector pos; - /** Data of new line */ - RS_LineData data; - /** - * Line angle. - */ - double angle; - /** - * Line length. - */ - double length; - /** - * Is the angle fixed? - */ - bool fixedAngle; +class RS_ActionDrawLineRelAngle: public RS_PreviewActionInterface +{ + private: + enum Status { + SetEntity, /**< Choose entity. */ + SetPos, /**< Choose position. */ + SetAngle, /**< Set angle in console. */ + SetLength /**< Set length in console. */ + }; + + public: + RS_ActionDrawLineRelAngle(RS_EntityContainer & container, RS_GraphicView & graphicView, double angle = 0.0, bool fixedAngle = false); + ~RS_ActionDrawLineRelAngle(); + + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + void setAngle(double a); + double getAngle(); + void setLength(double l); + double getLength(); + bool hasFixedAngle(); + + private: + /** Chosen entity */ + RS_Entity * entity; + /** Chosen position */ + Vector pos; + /** Data of new line */ + RS_LineData data; + /** + * Line angle. + */ + double angle; + /** + * Line length. + */ + double length; + /** + * Is the angle fixed? + */ + bool fixedAngle; }; #endif diff --git a/src/actions/rs_actiondrawlinetangent1.cpp b/src/actions/rs_actiondrawlinetangent1.cpp index 37dd3fd..a39f4df 100644 --- a/src/actions/rs_actiondrawlinetangent1.cpp +++ b/src/actions/rs_actiondrawlinetangent1.cpp @@ -1,218 +1,203 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinetangent1.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinetangent1.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_actiondrawlinetangent1.h" #include "rs_creation.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionDrawLineTangent1::RS_ActionDrawLineTangent1( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw Tangents 1", container, graphicView) { - - tangent = NULL; - point = Vector(false); - circle = NULL; +RS_ActionDrawLineTangent1::RS_ActionDrawLineTangent1(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Tangents 1", + container, graphicView) +{ + tangent = NULL; + point = Vector(false); + circle = NULL; } - -QAction* RS_ActionDrawLineTangent1::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLineTangent1::~RS_ActionDrawLineTangent1() { - QAction * action = new QAction(tr("&Tangent (P,C)"), 0); -// QAction* action = new QAction(tr("Tangent (P,C)"), tr("&Tangent (P,C)"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw tangent (point, circle)")); - return action; } -void RS_ActionDrawLineTangent1::trigger() { - RS_PreviewActionInterface::trigger(); - - if (tangent!=NULL) { - RS_Entity* newEntity = NULL; - - newEntity = new RS_Line(container, - tangent->getData()); - - if (newEntity!=NULL) { - newEntity->setLayerToActive(); - newEntity->setPenToActive(); - container->addEntity(newEntity); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(newEntity); - document->endUndoCycle(); - } - - deleteSnapper(); - graphicView->drawEntity(newEntity); - - setStatus(SetPoint); - } - delete tangent; - tangent = NULL; - } else { - RS_DEBUG->print("RS_ActionDrawLineTangent1::trigger:" - " Entity is NULL\n"); - } +void RS_ActionDrawLineTangent1::trigger() +{ + RS_PreviewActionInterface::trigger(); + + if (tangent != NULL) + { + RS_Entity * newEntity = NULL; + newEntity = new RS_Line(container, tangent->getData()); + + if (newEntity != NULL) + { + newEntity->setLayerToActive(); + newEntity->setPenToActive(); + container->addEntity(newEntity); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(newEntity); + document->endUndoCycle(); + } + + deleteSnapper(); + graphicView->drawEntity(newEntity); + + setStatus(SetPoint); + } + + delete tangent; + tangent = NULL; + } + else + RS_DEBUG->print("RS_ActionDrawLineTangent1::trigger:" + " Entity is NULL\n"); } - - -void RS_ActionDrawLineTangent1::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent begin"); - - Vector mouse(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); - - switch (getStatus()) { - case SetPoint: - point = snapPoint(e); - break; - - case SetCircle: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && (en->rtti()==RS2::EntityCircle || - en->rtti()==RS2::EntityArc || - en->rtti()==RS2::EntityEllipse)) { - circle = en; - - RS_Creation creation(NULL, NULL); - RS_Line* t = creation.createTangent1(mouse, - point, - circle); - - if (t!=NULL) { - if (tangent!=NULL) { - delete tangent; - } - tangent = (RS_Line*)t->clone(); - - deletePreview(); - clearPreview(); - preview->addEntity(t); - drawPreview(); - } - } - } - break; - - default: - break; - } - - RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent end"); +void RS_ActionDrawLineTangent1::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent begin"); + + Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); + + switch (getStatus()) + { + case SetPoint: + point = snapPoint(e); + break; + + case SetCircle: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL && (en->rtti() == RS2::EntityCircle + || en->rtti() == RS2::EntityArc + || en->rtti() == RS2::EntityEllipse)) + { + circle = en; + + RS_Creation creation(NULL, NULL); + RS_Line * t = creation.createTangent1(mouse, + point, + circle); + + if (t != NULL) + { + if (tangent != NULL) + delete tangent; + tangent = (RS_Line *)t->clone(); + + deletePreview(); + clearPreview(); + preview->addEntity(t); + drawPreview(); + } + } + } + break; + + default: + break; + } + + RS_DEBUG->print("RS_ActionDrawLineTangent1::mouseMoveEvent end"); } - - -void RS_ActionDrawLineTangent1::mouseReleaseEvent(QMouseEvent* e) { - - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - clearPreview(); - deleteSnapper(); - init(getStatus()-1); - } else { - switch (getStatus()) { - case SetPoint: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - - case SetCircle: - trigger(); - break; - } - } - +void RS_ActionDrawLineTangent1::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + clearPreview(); + deleteSnapper(); + init(getStatus() - 1); + } + else + { + switch (getStatus()) + { + case SetPoint: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + + case SetCircle: + trigger(); + break; + } + } } - -void RS_ActionDrawLineTangent1::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - switch (getStatus()) { - case SetPoint: - point = e->getCoordinate(); - deleteSnapper(); - graphicView->moveRelativeZero(point); - setStatus(SetCircle); - break; - - default: - break; - } +void RS_ActionDrawLineTangent1::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + switch (getStatus()) + { + case SetPoint: + point = *e; + deleteSnapper(); + graphicView->moveRelativeZero(point); + setStatus(SetCircle); + break; + + default: + break; + } } - -void RS_ActionDrawLineTangent1::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetPoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify point"), - tr("Cancel")); - break; - case SetCircle: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select circle, arc or ellipse"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDrawLineTangent1::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetPoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify point"), + tr("Cancel")); + break; + + case SetCircle: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select circle, arc or ellipse"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } - - -void RS_ActionDrawLineTangent1::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineTangent1::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionDrawLineTangent1::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } - } +void RS_ActionDrawLineTangent1::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); + } } - - // EOF diff --git a/src/actions/rs_actiondrawlinetangent1.h b/src/actions/rs_actiondrawlinetangent1.h index 51cd304..0269434 100644 --- a/src/actions/rs_actiondrawlinetangent1.h +++ b/src/actions/rs_actiondrawlinetangent1.h @@ -1,34 +1,12 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinetangent1.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINETANGENT1_H #define RS_ACTIONDRAWLINETANGENT1_H +#include "rs_line.h" #include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Line; +class RS_Entity; /** * This action class can handle user events to draw tangents from points @@ -36,41 +14,35 @@ * * @author Andrew Mustun */ -class RS_ActionDrawLineTangent1 : public RS_PreviewActionInterface { - //Q_OBJECT -private: - enum Status { - SetPoint, /**< Choose the startpoint. */ - SetCircle /**< Choose the circle / arc. */ - }; - -public: - RS_ActionDrawLineTangent1(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLineTangent1() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - /** Closest tangent. */ - RS_Line* tangent; - /** Chosen startpoint */ - Vector point; - /** Chosen entity */ - RS_Entity* circle; - /** Data of new tangent */ - RS_LineData data; +class RS_ActionDrawLineTangent1: public RS_PreviewActionInterface +{ + private: + enum Status { + SetPoint, /**< Choose the startpoint. */ + SetCircle /**< Choose the circle / arc. */ + }; + + public: + RS_ActionDrawLineTangent1(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLineTangent1(); + + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + /** Closest tangent. */ + RS_Line * tangent; + /** Chosen startpoint */ + Vector point; + /** Chosen entity */ + RS_Entity * circle; + /** Data of new tangent */ + RS_LineData data; }; #endif diff --git a/src/actions/rs_actiondrawlinetangent2.cpp b/src/actions/rs_actiondrawlinetangent2.cpp index 3d759b4..98027d3 100644 --- a/src/actions/rs_actiondrawlinetangent2.cpp +++ b/src/actions/rs_actiondrawlinetangent2.cpp @@ -1,195 +1,178 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinetangent2.cpp 1134 2004-07-13 23:26:13Z 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_actiondrawlinetangent2.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_actiondrawlinetangent2.h" #include "rs_creation.h" -#include "rs_snapper.h" - - +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" RS_ActionDrawLineTangent2::RS_ActionDrawLineTangent2( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Draw Tangents 2", container, graphicView) { - - tangent = NULL; - circle1 = NULL; - circle2 = NULL; + RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_PreviewActionInterface("Draw Tangents 2", container, graphicView) +{ + tangent = NULL; + circle1 = NULL; + circle2 = NULL; } -QAction* RS_ActionDrawLineTangent2::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionDrawLineTangent2::~RS_ActionDrawLineTangent2() { - QAction * action = new QAction(tr("Tan&gent (C,C)"), 0); -// QAction* action = new QAction(tr("Tangent (C,C)"), tr("Tan&gent (C,C)"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw tangent (circle, circle)")); - - return action; } - -void RS_ActionDrawLineTangent2::trigger() { - RS_PreviewActionInterface::trigger(); - - if (tangent!=NULL) { - RS_Entity* newEntity = NULL; - - newEntity = new RS_Line(container, - tangent->getData()); - - if (newEntity!=NULL) { - newEntity->setLayerToActive(); - newEntity->setPenToActive(); - container->addEntity(newEntity); - - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(newEntity); - document->endUndoCycle(); - } - graphicView->drawEntity(newEntity); - setStatus(SetCircle1); - } - delete tangent; - tangent = NULL; - } else { - RS_DEBUG->print("RS_ActionDrawLineTangent2::trigger:" - " Entity is NULL\n"); - } +void RS_ActionDrawLineTangent2::trigger() +{ + RS_PreviewActionInterface::trigger(); + + if (tangent != NULL) + { + RS_Entity * newEntity = NULL; + newEntity = new RS_Line(container, tangent->getData()); + + if (newEntity != NULL) + { + newEntity->setLayerToActive(); + newEntity->setPenToActive(); + container->addEntity(newEntity); + + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(newEntity); + document->endUndoCycle(); + } + graphicView->drawEntity(newEntity); + setStatus(SetCircle1); + } + + delete tangent; + tangent = NULL; + } + else + RS_DEBUG->print("RS_ActionDrawLineTangent2::trigger:" + " Entity is NULL\n"); } - - -void RS_ActionDrawLineTangent2::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionDrawLineTangent2::mouseMoveEvent begin"); - - Vector mouse(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); - - switch (getStatus()) { - case SetCircle1: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && (en->rtti()==RS2::EntityCircle || - en->rtti()==RS2::EntityArc)) { - circle1 = en; - } - } - break; - - case SetCircle2: { - RS_Entity* en = catchEntity(e, RS2::ResolveAll); - if (en!=NULL && (en->rtti()==RS2::EntityCircle || - en->rtti()==RS2::EntityArc)) { - circle2 = en; - - RS_Creation creation(NULL, NULL); - RS_Line* t = creation.createTangent2(mouse, - circle1, - circle2); - - if (t!=NULL) { - if (tangent!=NULL) { - delete tangent; - } - tangent = (RS_Line*)t->clone(); - - deletePreview(); - clearPreview(); - preview->addEntity(t); - drawPreview(); - } - } - } - break; - - default: - break; - } - - RS_DEBUG->print("RS_ActionDrawLineTangent2::mouseMoveEvent end"); +void RS_ActionDrawLineTangent2::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionDrawLineTangent2::mouseMoveEvent begin"); + + Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); + + switch (getStatus()) + { + case SetCircle1: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL && (en->rtti() == RS2::EntityCircle + || en->rtti() == RS2::EntityArc)) + circle1 = en; + } + break; + + case SetCircle2: { + RS_Entity * en = catchEntity(e, RS2::ResolveAll); + + if (en != NULL && (en->rtti() == RS2::EntityCircle + || en->rtti() == RS2::EntityArc)) + { + circle2 = en; + + RS_Creation creation(NULL, NULL); + RS_Line * t = creation.createTangent2(mouse, + circle1, + circle2); + + if (t != NULL) + { + if (tangent != NULL) + delete tangent; + tangent = (RS_Line *)t->clone(); + + deletePreview(); + clearPreview(); + preview->addEntity(t); + drawPreview(); + } + } + } + break; + + default: + break; + } + + RS_DEBUG->print("RS_ActionDrawLineTangent2::mouseMoveEvent end"); } - - -void RS_ActionDrawLineTangent2::mouseReleaseEvent(QMouseEvent* e) { - - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - clearPreview(); - init(getStatus()-1); - } else { - switch (getStatus()) { - case SetCircle1: - setStatus(SetCircle2); - break; - - case SetCircle2: - trigger(); - break; - } - } - +void RS_ActionDrawLineTangent2::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + clearPreview(); + init(getStatus() - 1); + } + else + { + switch (getStatus()) + { + case SetCircle1: + setStatus(SetCircle2); + break; + + case SetCircle2: + trigger(); + break; + } + } } - - -void RS_ActionDrawLineTangent2::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetCircle1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select first circle or arc"), - tr("Cancel")); - break; - case SetCircle2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select second circle or arc"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionDrawLineTangent2::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetCircle1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select first circle or arc"), + tr("Cancel")); + break; + + case SetCircle2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select second circle or arc"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } - - -void RS_ActionDrawLineTangent2::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawLineTangent2::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionDrawLineTangent2::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); - } +void RS_ActionDrawLineTangent2::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarLines); } - - // EOF diff --git a/src/actions/rs_actiondrawlinetangent2.h b/src/actions/rs_actiondrawlinetangent2.h index 665b5a3..7b7cd5c 100644 --- a/src/actions/rs_actiondrawlinetangent2.h +++ b/src/actions/rs_actiondrawlinetangent2.h @@ -1,74 +1,46 @@ -/**************************************************************************** -** $Id: rs_actiondrawlinetangent2.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWLINETANGENT2_H #define RS_ACTIONDRAWLINETANGENT2_H +#include "rs_line.h" #include "rs_previewactioninterface.h" - +class RS_Entity; /** * This action class can handle user events to draw tangents from circle to * circle. * * @author Andrew Mustun */ -class RS_ActionDrawLineTangent2 : public RS_PreviewActionInterface { - //Q_OBJECT -private: - enum Status { - SetCircle1, /**< Choose the startpoint. */ - SetCircle2 /**< Choose the circle / arc. */ - }; - -public: - RS_ActionDrawLineTangent2(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionDrawLineTangent2() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - //virtual void hideOptions(); - //virtual void showOptions(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - /** Closest tangent. */ - RS_Line* tangent; - /** 1st chosen entity */ - RS_Entity* circle1; - /** 2nd chosen entity */ - RS_Entity* circle2; - /** Data of new tangent */ - RS_LineData data; +class RS_ActionDrawLineTangent2: public RS_PreviewActionInterface +{ + private: + enum Status { + SetCircle1, /**< Choose the startpoint. */ + SetCircle2 /**< Choose the circle / arc. */ + }; + + public: + RS_ActionDrawLineTangent2(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionDrawLineTangent2(); + + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + //virtual void hideOptions(); + //virtual void showOptions(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + /** Closest tangent. */ + RS_Line * tangent; + /** 1st chosen entity */ + RS_Entity * circle1; + /** 2nd chosen entity */ + RS_Entity * circle2; + /** Data of new tangent */ + RS_LineData data; }; #endif diff --git a/src/actions/rs_actiondrawpoint.cpp b/src/actions/rs_actiondrawpoint.cpp index 79e5994..8ec3a81 100644 --- a/src/actions/rs_actiondrawpoint.cpp +++ b/src/actions/rs_actiondrawpoint.cpp @@ -14,11 +14,11 @@ #include "rs_actiondrawpoint.h" -#include "rs_snapper.h" -#include "rs_point.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -RS_ActionDrawPoint::RS_ActionDrawPoint(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionDrawPoint::RS_ActionDrawPoint(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Points", container, graphicView) { } @@ -27,16 +27,6 @@ RS_ActionDrawPoint::~RS_ActionDrawPoint() { } -QAction * RS_ActionDrawPoint::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) -{ - QAction * action = new QAction(tr("&Points") + QString("\tpo"), 0); -// QAction* action = new QAction(tr("Points"), tr("&Points"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw Points")); - - return action; -} - void RS_ActionDrawPoint::trigger() { if (pt.valid) @@ -61,14 +51,14 @@ void RS_ActionDrawPoint::trigger() void RS_ActionDrawPoint::mouseMoveEvent(QMouseEvent * e) { - snapPoint(e); + snapPoint(e); } void RS_ActionDrawPoint::mouseReleaseEvent(QMouseEvent * e) { if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) @@ -78,12 +68,12 @@ void RS_ActionDrawPoint::mouseReleaseEvent(QMouseEvent * e) } } -void RS_ActionDrawPoint::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionDrawPoint::coordinateEvent(Vector * e) { if (e == NULL) return; - Vector mouse = e->getCoordinate(); + Vector mouse = *e; pt = mouse; trigger(); @@ -118,6 +108,7 @@ void RS_ActionDrawPoint::updateMouseButtonHints() case 0: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify location"), tr("Cancel")); break; + default: RS_DIALOGFACTORY->updateMouseWidget("", ""); break; @@ -125,8 +116,9 @@ void RS_ActionDrawPoint::updateMouseButtonHints() } } -void RS_ActionDrawPoint::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionDrawPoint::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } void RS_ActionDrawPoint::updateToolBar() @@ -139,3 +131,4 @@ void RS_ActionDrawPoint::updateToolBar() RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarPoints); } } + diff --git a/src/actions/rs_actiondrawpoint.h b/src/actions/rs_actiondrawpoint.h index 84035ed..be4fb01 100644 --- a/src/actions/rs_actiondrawpoint.h +++ b/src/actions/rs_actiondrawpoint.h @@ -2,31 +2,25 @@ #define RS_ACTIONDRAWPOINT_H #include "rs_previewactioninterface.h" +#include "vector.h" /** * This action class can handle user events to draw points. * * @author Andrew Mustun */ -class RS_ActionDrawPoint : public RS_PreviewActionInterface +class RS_ActionDrawPoint: public RS_PreviewActionInterface { - //Q_OBJECT public: - RS_ActionDrawPoint(RS_EntityContainer& container, - RS_GraphicView& graphicView); + RS_ActionDrawPoint(RS_EntityContainer & container, RS_GraphicView & graphicView); ~RS_ActionDrawPoint(); - static QAction * createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); virtual QStringList getAvailableCommands(); - virtual void updateMouseButtonHints(); virtual void updateMouseCursor(); virtual void updateToolBar(); diff --git a/src/actions/rs_actiondrawspline.cpp b/src/actions/rs_actiondrawspline.cpp index f62a252..ba4e681 100644 --- a/src/actions/rs_actiondrawspline.cpp +++ b/src/actions/rs_actiondrawspline.cpp @@ -1,36 +1,25 @@ -/**************************************************************************** -** $Id: rs_actiondrawspline.cpp 1140 2004-07-24 23:14:15Z 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_actiondrawspline.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_actiondrawspline.h" -#include "rs_actioneditundo.h" -#include "rs_snapper.h" +#include "commands.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" -RS_ActionDrawSpline::RS_ActionDrawSpline(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionDrawSpline::RS_ActionDrawSpline(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw splines", container, graphicView) { reset(); @@ -49,65 +38,54 @@ RS_ActionDrawSpline::~RS_ActionDrawSpline() return RS2::ActionDrawSpline; } -QAction * RS_ActionDrawSpline::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) -{ - QAction * action = new QAction(tr("&Spline"), 0); -// QAction* action = new QAction(tr("Spline"), tr("&Spline"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Draw splines")); - return action; -} - void RS_ActionDrawSpline::reset() { spline = NULL; - //start = Vector(false); - history.clear(); - //bHistory.clear(); + //start = Vector(false); + history.clear(); + //bHistory.clear(); } +void RS_ActionDrawSpline::init(int status) +{ + RS_PreviewActionInterface::init(status); - -void RS_ActionDrawSpline::init(int status) { - RS_PreviewActionInterface::init(status); - - reset(); + reset(); } +void RS_ActionDrawSpline::trigger() +{ + RS_PreviewActionInterface::trigger(); - -void RS_ActionDrawSpline::trigger() { - RS_PreviewActionInterface::trigger(); - - if (spline==NULL) { + if (spline == NULL) return; - } // add the entity - //RS_Spline* spline = new RS_Spline(container, data); - spline->setLayerToActive(); - spline->setPenToActive(); + //RS_Spline* spline = new RS_Spline(container, data); + spline->setLayerToActive(); + spline->setPenToActive(); spline->update(); - container->addEntity(spline); + container->addEntity(spline); - // upd. undo list: - if (document!=NULL) { - document->startUndoCycle(); - document->addUndoable(spline); - document->endUndoCycle(); - } + // upd. undo list: + if (document != NULL) + { + document->startUndoCycle(); + document->addUndoable(spline); + document->endUndoCycle(); + } // upd view - deleteSnapper(); + deleteSnapper(); Vector r = graphicView->getRelativeZero(); - graphicView->moveRelativeZero(Vector(0.0,0.0)); - graphicView->drawEntity(spline); - graphicView->moveRelativeZero(r); - drawSnapper(); - RS_DEBUG->print("RS_ActionDrawSpline::trigger(): spline added: %d", spline->getId()); + graphicView->moveRelativeZero(Vector(0.0, 0.0)); + graphicView->drawEntity(spline); + graphicView->moveRelativeZero(r); + drawSnapper(); + RS_DEBUG->print("RS_ActionDrawSpline::trigger(): spline added: %d", spline->getId()); spline = NULL; - //history.clear(); + //history.clear(); } void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent * e) @@ -131,7 +109,7 @@ void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent * e) QList cpts = tmpSpline->getControlPoints(); QList::iterator it; - for(it=cpts.begin(); it!=cpts.end(); ++it) + for (it = cpts.begin(); it != cpts.end(); ++it) preview->addEntity(new RS_Point(preview, RS_PointData(*it))); drawPreview(); @@ -142,64 +120,66 @@ void RS_ActionDrawSpline::mouseMoveEvent(QMouseEvent * e) void RS_ActionDrawSpline::mouseReleaseEvent(QMouseEvent * e) { - if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) { if (getStatus() == SetNextPoint) - { trigger(); - } - deletePreview(); - clearPreview(); - deleteSnapper(); - init(getStatus()-1); - } + deletePreview(); + clearPreview(); + deleteSnapper(); + init(getStatus() - 1); + } } +void RS_ActionDrawSpline::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + Vector mouse = *e; -void RS_ActionDrawSpline::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetStartpoint: + switch (getStatus()) + { + case SetStartpoint: //data.startpoint = mouse; - //point = mouse; - history.clear(); - history.append(new Vector(mouse)); - if (spline==NULL) { + //point = mouse; + history.clear(); + history.append(new Vector(mouse)); + + if (spline == NULL) + { spline = new RS_Spline(container, data); spline->addControlPoint(mouse); } - //bHistory.clear(); - //bHistory.append(new double(0.0)); - //start = mouse; - setStatus(SetNextPoint); - graphicView->moveRelativeZero(mouse); - updateMouseButtonHints(); - break; - - case SetNextPoint: - graphicView->moveRelativeZero(mouse); - //point = mouse; - history.append(new Vector(mouse)); - //bHistory.append(new double(0.0)); - if (spline!=NULL) { + + //bHistory.clear(); + //bHistory.append(new double(0.0)); + //start = mouse; + setStatus(SetNextPoint); + graphicView->moveRelativeZero(mouse); + updateMouseButtonHints(); + break; + + case SetNextPoint: + graphicView->moveRelativeZero(mouse); + //point = mouse; + history.append(new Vector(mouse)); + //bHistory.append(new double(0.0)); + + if (spline != NULL) + { //graphicView->deleteEntity(spline); spline->addControlPoint(mouse); //spline->setEndpoint(mouse); //if (spline->count()==1) { - //spline->setLayerToActive(); - //spline->setPenToActive(); - //container->addEntity(spline); + //spline->setLayerToActive(); + //spline->setPenToActive(); + //container->addEntity(spline); //} deletePreview(); clearPreview(); @@ -207,150 +187,156 @@ void RS_ActionDrawSpline::coordinateEvent(RS_CoordinateEvent* e) { //graphicView->drawEntity(spline); drawSnapper(); } - //trigger(); - //data.startpoint = data.endpoint; - updateMouseButtonHints(); - //graphicView->moveRelativeZero(mouse); - break; - default: - break; - } -} + //trigger(); + //data.startpoint = data.endpoint; + updateMouseButtonHints(); + //graphicView->moveRelativeZero(mouse); + break; + default: + break; + } +} +void RS_ActionDrawSpline::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); -void RS_ActionDrawSpline::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); + switch (getStatus()) + { + case SetStartpoint: - switch (getStatus()) { - case SetStartpoint: - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - break; + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + break; - case SetNextPoint: - /*if (checkCommand("close", c)) { - close(); - updateMouseButtonHints(); - return; - }*/ + case SetNextPoint: + /*if (checkCommand("close", c)) { + close(); + updateMouseButtonHints(); + return; + }*/ - if (checkCommand("undo", c)) { - undo(); - updateMouseButtonHints(); - return; - } - break; + if (checkCommand("undo", c)) + { + undo(); + updateMouseButtonHints(); + return; + } + break; - default: - break; - } + default: + break; + } } +QStringList RS_ActionDrawSpline::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case SetStartpoint: + break; -QStringList RS_ActionDrawSpline::getAvailableCommands() { - QStringList cmd; + case SetNextPoint: - switch (getStatus()) { - case SetStartpoint: - break; - case SetNextPoint: - if (history.count()>=2) { - cmd += command("undo"); - } - if (history.count()>=3) { - cmd += command("close"); - } - break; - default: - break; - } + if (history.count() >= 2) + cmd += command("undo"); - return cmd; -} + if (history.count() >= 3) + cmd += command("close"); + break; + default: + break; + } -void RS_ActionDrawSpline::updateMouseButtonHints() { - switch (getStatus()) { - case SetStartpoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first control point"), - tr("Cancel")); - break; - case SetNextPoint: { - QString msg = ""; - - if (history.count()>=3) { - msg += RS_COMMANDS->command("close"); - msg += "/"; - } - if (history.count()>=2) { - msg += RS_COMMANDS->command("undo"); - } - - if (history.count()>=2) { - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify next control point or [%1]").arg(msg), - tr("Back")); - } else { - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify next control point"), - tr("Back")); - } - } - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } + return cmd; } +void RS_ActionDrawSpline::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetStartpoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first control point"), + tr("Cancel")); + break; -void RS_ActionDrawSpline::showOptions() { - RS_ActionInterface::showOptions(); + case SetNextPoint: { + QString msg = ""; - RS_DIALOGFACTORY->requestOptions(this, true); -} + if (history.count() >= 3) + { + msg += RS_COMMANDS->command("close"); + msg += "/"; + } + if (history.count() >= 2) + msg += RS_COMMANDS->command("undo"); + + if (history.count() >= 2) + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify next control point or [%1]").arg(msg), + tr("Back")); + else + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify next control point"), + tr("Back")); + } + break; + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } +} -void RS_ActionDrawSpline::hideOptions() { - RS_ActionInterface::hideOptions(); +void RS_ActionDrawSpline::showOptions() +{ + RS_ActionInterface::showOptions(); - RS_DIALOGFACTORY->requestOptions(this, false); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionDrawSpline::hideOptions() +{ + RS_ActionInterface::hideOptions(); -void RS_ActionDrawSpline::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); + RS_DIALOGFACTORY->requestOptions(this, false); } - -void RS_ActionDrawSpline::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSplines); - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } +void RS_ActionDrawSpline::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionDrawSpline::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSplines); + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); +} /* -void RS_ActionDrawSpline::close() { + void RS_ActionDrawSpline::close() { if (history.count()>2 && start.valid) { //data.endpoint = start; //trigger(); - if (spline!=NULL) { - RS_CoordinateEvent e(spline->getStartpoint()); - coordinateEvent(&e); - } - trigger(); + if (spline!=NULL) { + Vector e(spline->getStartpoint()); + coordinateEvent(&e); + } + trigger(); setStatus(SetStartpoint); graphicView->moveRelativeZero(start); } else { @@ -358,55 +344,64 @@ void RS_ActionDrawSpline::close() { tr("Cannot close sequence of lines: " "Not enough entities defined yet.")); } -} -*/ - -void RS_ActionDrawSpline::undo() { - if (history.count()>1) { - history.removeLast(); - //bHistory.removeLast(); - deletePreview(); - clearPreview(); - //graphicView->setCurrentAction( - // new RS_ActionEditUndo(true, *container, *graphicView)); - if (history.last()!=NULL) { - //point = *history.last(); + } + */ + +void RS_ActionDrawSpline::undo() +{ + if (history.count() > 1) + { + history.removeLast(); + //bHistory.removeLast(); + deletePreview(); + clearPreview(); + + //graphicView->setCurrentAction( + // new RS_ActionEditUndo(true, *container, *graphicView)); + if (history.last() != NULL) + { + //point = *history.last(); } - if (spline!=NULL) { + + if (spline != NULL) + { spline->removeLastControlPoint(); - Vector* v = history.last(); - if (v!=NULL) { - graphicView->moveRelativeZero(*v); - } + Vector * v = history.last(); + + if (v != NULL) + graphicView->moveRelativeZero(*v); graphicView->redraw(); } - } else { - RS_DIALOGFACTORY->commandMessage( - tr("Cannot undo: " - "Not enough entities defined yet.")); - } + } + else + RS_DIALOGFACTORY->commandMessage( + tr("Cannot undo: " + "Not enough entities defined yet.")); } - -void RS_ActionDrawSpline::setDegree(int deg) { +void RS_ActionDrawSpline::setDegree(int deg) +{ data.degree = deg; - if (spline!=NULL) { + + if (spline != NULL) spline->setDegree(deg); - } } -int RS_ActionDrawSpline::getDegree() { +int RS_ActionDrawSpline::getDegree() +{ return data.degree; } -void RS_ActionDrawSpline::setClosed(bool c) { +void RS_ActionDrawSpline::setClosed(bool c) +{ data.closed = c; - if (spline!=NULL) { + + if (spline != NULL) spline->setClosed(c); - } } -bool RS_ActionDrawSpline::isClosed() { +bool RS_ActionDrawSpline::isClosed() +{ return data.closed; } diff --git a/src/actions/rs_actiondrawspline.h b/src/actions/rs_actiondrawspline.h index 9b1cc7e..4e484ca 100644 --- a/src/actions/rs_actiondrawspline.h +++ b/src/actions/rs_actiondrawspline.h @@ -1,29 +1,3 @@ -/**************************************************************************** -** $Id: rs_actiondrawspline.h 1155 2004-11-18 16:01:06Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONDRAWSPLINE_H #define RS_ACTIONDRAWSPLINE_H @@ -38,11 +12,10 @@ */ class RS_ActionDrawSpline: public RS_PreviewActionInterface { -//hm //Q_OBJECT public: /** - * Action States. - */ + * Action States. + */ enum Status { SetStartpoint, /**< Setting the startpoint. */ SetNextPoint /**< Setting the next point. */ @@ -53,13 +26,13 @@ class RS_ActionDrawSpline: public RS_PreviewActionInterface virtual ~RS_ActionDrawSpline(); virtual RS2::ActionType rtti(); - static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); + //static QAction * createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/); void reset(); - virtual void init(int status=0); + virtual void init(int status = 0); virtual void trigger(); virtual void mouseMoveEvent(QMouseEvent * e); virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void coordinateEvent(RS_CoordinateEvent * e); + virtual void coordinateEvent(Vector * e); virtual void commandEvent(RS_CommandEvent * e); virtual QStringList getAvailableCommands(); virtual void showOptions(); @@ -77,35 +50,19 @@ class RS_ActionDrawSpline: public RS_PreviewActionInterface protected: /** - * Spline data defined so far. - */ + * Spline data defined so far. + */ RS_SplineData data; /** - * Polyline entity we're working on. - */ + * Polyline entity we're working on. + */ RS_Spline * spline; /** - * last point. - */ - //Vector point; - - /** - * Start point of the series of nodes. Used for close function. - */ - //Vector start; - - /** - * Point history (for undo) - */ -// Q3PtrList history; + * Point history (for undo) + */ QList history; - - /** - * Bulge history (for undo) - */ - //Q3PtrList bHistory; }; #endif diff --git a/src/actions/rs_actiondrawtext.cpp b/src/actions/rs_actiondrawtext.cpp index c4f2d24..55b9ae6 100644 --- a/src/actions/rs_actiondrawtext.cpp +++ b/src/actions/rs_actiondrawtext.cpp @@ -16,11 +16,11 @@ #include "rs_actiondrawtext.h" +#include "rs_dialogfactory.h" #include "rs_graphicview.h" -#include "rs_snapper.h" +#include "rs_preview.h" -RS_ActionDrawText::RS_ActionDrawText(RS_EntityContainer & container, - RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Text", container, graphicView) +RS_ActionDrawText::RS_ActionDrawText(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Draw Text", container, graphicView) { pos = Vector(false); textChanged = true; @@ -68,7 +68,7 @@ void RS_ActionDrawText::init(int status) graphicView->redraw(); } - break; + break; case SetPos: RS_DIALOGFACTORY->requestOptions(this, true, true); @@ -81,9 +81,9 @@ void RS_ActionDrawText::init(int status) void RS_ActionDrawText::reset() { - data = RS_TextData(Vector(0.0, 0.0), 1.0, 100.0, RS2::VAlignTop, - RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, data.text, - "standard", 0.0, RS2::Update); + data = RS_TextData(Vector(0.0, 0.0), 1.0, 100.0, RS2::VAlignTop, + RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, data.text, + "standard", 0.0, RS2::Update); } void RS_ActionDrawText::trigger() @@ -158,7 +158,7 @@ void RS_ActionDrawText::mouseReleaseEvent(QMouseEvent * e) { if (e->button() == Qt::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } else if (e->button() == Qt::RightButton) @@ -176,12 +176,12 @@ void RS_ActionDrawText::mouseReleaseEvent(QMouseEvent * e) } } -void RS_ActionDrawText::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionDrawText::coordinateEvent(Vector * e) { if (e == NULL) return; - Vector mouse = e->getCoordinate(); + Vector mouse = *e; switch (getStatus()) { @@ -205,16 +205,15 @@ void RS_ActionDrawText::commandEvent(RS_CommandEvent * e) if (checkCommand("help", c)) { if (RS_DIALOGFACTORY != NULL) - { RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + getAvailableCommands().join(", ")); - } return; } switch (getStatus()) { case SetPos: + if (checkCommand("text", c)) { deleteSnapper(); @@ -277,9 +276,11 @@ void RS_ActionDrawText::updateMouseButtonHints() case SetPos: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify insertion point"), tr("Cancel")); break; + case SetText: RS_DIALOGFACTORY->updateMouseWidget(tr("Enter text:"), tr("Back")); break; + default: RS_DIALOGFACTORY->updateMouseWidget("", ""); break; @@ -288,12 +289,12 @@ void RS_ActionDrawText::updateMouseButtonHints() void RS_ActionDrawText::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); + graphicView->setMouseCursor(RS2::CadCursor); } void RS_ActionDrawText::updateToolBar() { - if (RS_DIALOGFACTORY == NULL) + if (RS_DIALOGFACTORY == NULL) return; switch (getStatus()) @@ -301,6 +302,7 @@ void RS_ActionDrawText::updateToolBar() case SetPos: RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); break; + default: RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); break; @@ -309,22 +311,23 @@ void RS_ActionDrawText::updateToolBar() void RS_ActionDrawText::setText(const QString & t) { - data.text = t; - textChanged = true; + data.text = t; + textChanged = true; } QString RS_ActionDrawText::getText() { - return data.text; + return data.text; } void RS_ActionDrawText::setAngle(double a) { - data.angle = a; - textChanged = true; + data.angle = a; + textChanged = true; } double RS_ActionDrawText::getAngle() { - return data.angle; + return data.angle; } + diff --git a/src/actions/rs_actiondrawtext.h b/src/actions/rs_actiondrawtext.h index 7e8cebf..dcafd56 100644 --- a/src/actions/rs_actiondrawtext.h +++ b/src/actions/rs_actiondrawtext.h @@ -33,7 +33,7 @@ class RS_ActionDrawText: public RS_PreviewActionInterface void preparePreview(); virtual void mouseMoveEvent(QMouseEvent * e); virtual void mouseReleaseEvent(QMouseEvent * e); - virtual void coordinateEvent(RS_CoordinateEvent * e); + virtual void coordinateEvent(Vector * e); virtual void commandEvent(RS_CommandEvent * e); virtual QStringList getAvailableCommands(); virtual void hideOptions(); diff --git a/src/actions/rs_actioneditcopy.cpp b/src/actions/rs_actioneditcopy.cpp index 64f139a..bbb70d6 100644 --- a/src/actions/rs_actioneditcopy.cpp +++ b/src/actions/rs_actioneditcopy.cpp @@ -14,6 +14,7 @@ #include "rs_actioneditcopy.h" +#include "rs_dialogfactory.h" #include "rs_modification.h" /** @@ -21,122 +22,90 @@ * * @param undo true for undo and false for redo. */ -RS_ActionEditCopy::RS_ActionEditCopy(bool copy, - RS_EntityContainer& container, RS_GraphicView& graphicView): +RS_ActionEditCopy::RS_ActionEditCopy(bool copy, RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Edit Copy", container, graphicView) { - this->copy = copy; + this->copy = copy; } RS_ActionEditCopy::~RS_ActionEditCopy() { } -QAction * RS_ActionEditCopy::createGUIAction(RS2::ActionType type, QObject * parent) -{ - QAction * action; - - if (type == RS2::ActionEditCopy) - { - //QPixmap icon = QPixmap(editcopy_xpm); - action = new QAction(QIcon(":/res/editcopy2.png"), tr("&Copy"), parent); - action->setShortcut(Qt::CTRL + Qt::Key_C); -// action = new QAction(tr("Copy"), QPixmap::fromMimeSource("editcopy2.png"), tr("&Copy"), -// CTRL+Key_C, parent); - action->setStatusTip(tr("Copies entities to the clipboard")); - } - else - { - //icon = QPixmap(editcut_xpm); - action = new QAction(QIcon(":/res/editcut2.png"), tr("Cu&t"), parent); - action->setShortcut(Qt::CTRL + Qt::Key_X); -// action = new QAction(tr("Cut"), QPixmap::fromMimeSource("editcut2.png"), tr("Cu&t"), -// CTRL+Key_X, parent); - action->setStatusTip(tr("Cuts entities to the clipboard")); - } - - return action; -} - void RS_ActionEditCopy::init(int status) { - RS_ActionInterface::init(status); - //trigger(); + RS_ActionInterface::init(status); + //trigger(); } +void RS_ActionEditCopy::trigger() +{ + deleteSnapper(); + RS_Modification m(*container, graphicView); + m.copy(referencePoint, !copy); -void RS_ActionEditCopy::trigger() { - - deleteSnapper(); - - RS_Modification m(*container, graphicView); - m.copy(referencePoint, !copy); - - //graphicView->redraw(); - finish(); - graphicView->killSelectActions(); - //init(getStatus()-1); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + //graphicView->redraw(); + finish(); + graphicView->killSelectActions(); + //init(getStatus()-1); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } - -void RS_ActionEditCopy::mouseMoveEvent(QMouseEvent* e) { - snapPoint(e); +void RS_ActionEditCopy::mouseMoveEvent(QMouseEvent * e) +{ + snapPoint(e); } - - -void RS_ActionEditCopy::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionEditCopy::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deleteSnapper(); + init(getStatus() - 1); + } } +void RS_ActionEditCopy::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; - -void RS_ActionEditCopy::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - referencePoint = e->getCoordinate(); - trigger(); + referencePoint = *e; + trigger(); } - - -void RS_ActionEditCopy::updateMouseButtonHints() { - switch (getStatus()) { - case SetReferencePoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), - tr("Cancel")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionEditCopy::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetReferencePoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), + tr("Cancel")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionEditCopy::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionEditCopy::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionEditCopy::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } +void RS_ActionEditCopy::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); } - // EOF diff --git a/src/actions/rs_actioneditcopy.h b/src/actions/rs_actioneditcopy.h index 94d0ca5..98033ac 100644 --- a/src/actions/rs_actioneditcopy.h +++ b/src/actions/rs_actioneditcopy.h @@ -2,6 +2,7 @@ #define RS_ACTIONEDITCOPY_H #include "rs_actioninterface.h" +#include "vector.h" /** * This action class can handle user events for copying or cutting entities @@ -11,32 +12,23 @@ */ class RS_ActionEditCopy: public RS_ActionInterface { - //Q_OBJECT public: /** - * Action States. - */ + * Action States. + */ enum Status { SetReferencePoint /**< Setting the reference point. */ }; public: - RS_ActionEditCopy(bool copy, - RS_EntityContainer& container, - RS_GraphicView& graphicView); + RS_ActionEditCopy(bool copy, RS_EntityContainer & container, RS_GraphicView & graphicView); ~RS_ActionEditCopy(); - static QAction* createGUIAction(RS2::ActionType type, QObject* parent); - - virtual void init(int status=0); - + virtual void init(int status = 0); virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent * e); virtual void mouseReleaseEvent(QMouseEvent * e); - - virtual void coordinateEvent(RS_CoordinateEvent * e); - + virtual void coordinateEvent(Vector * e); virtual void updateMouseButtonHints(); virtual void updateMouseCursor(); virtual void updateToolBar(); diff --git a/src/actions/rs_actioneditpaste.cpp b/src/actions/rs_actioneditpaste.cpp index 78514c3..f4b7aa9 100644 --- a/src/actions/rs_actioneditpaste.cpp +++ b/src/actions/rs_actioneditpaste.cpp @@ -1,33 +1,23 @@ -/**************************************************************************** -** $Id: rs_actioneditpaste.cpp 1134 2004-07-13 23:26:13Z 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_actioneditpaste.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_actioneditpaste.h" #include "rs_clipboard.h" +#include "rs_dialogfactory.h" #include "rs_modification.h" +#include "rs_preview.h" #include "rs_units.h" /** @@ -35,10 +25,8 @@ * * @param undo true for undo and false for redo. */ -RS_ActionEditPaste::RS_ActionEditPaste( RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Edit Paste", - container, graphicView) +RS_ActionEditPaste::RS_ActionEditPaste(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Edit Paste", + container, graphicView) { } @@ -46,115 +34,102 @@ RS_ActionEditPaste::~RS_ActionEditPaste() { } -QAction* RS_ActionEditPaste::createGUIAction(RS2::ActionType /*type*/, QObject* parent) -{ - //icon = QPixmap(editpaste_xpm); - QAction * action = new QAction(QIcon(":/res/editpaste2.png"), tr("&Paste"), parent); - action->setShortcut(Qt::CTRL + Qt::Key_V); -// QAction* action = new QAction(tr("Paste"), -// qPixmapFromMimeSource("editpaste2.png"), tr("&Paste"), -// Qt::CTRL+Qt::Key_V, parent); - action->setStatusTip(tr("Pastes the clipboard contents")); - return action; -} - void RS_ActionEditPaste::init(int status) { - RS_PreviewActionInterface::init(status); - //trigger(); + RS_PreviewActionInterface::init(status); + //trigger(); } void RS_ActionEditPaste::trigger() { - deleteSnapper(); - deletePreview(); - clearPreview(); + deleteSnapper(); + deletePreview(); + clearPreview(); - RS_Modification m(*container, graphicView); - m.paste(RS_PasteData(targetPoint, 1.0, 0.0, false, "")); - //std::cout << *RS_Clipboard::instance(); + RS_Modification m(*container, graphicView); + m.paste(RS_PasteData(targetPoint, 1.0, 0.0, false, "")); + //std::cout << *RS_Clipboard::instance(); - graphicView->redraw(); - finish(); + graphicView->redraw(); + finish(); } - -void RS_ActionEditPaste::mouseMoveEvent(QMouseEvent* e) { - switch (getStatus()) { - case SetTargetPoint: - targetPoint = snapPoint(e); - - deletePreview(); - clearPreview(); - preview->addAllFrom(*RS_CLIPBOARD->getGraphic()); - preview->move(targetPoint); - - if (graphic!=NULL) { +void RS_ActionEditPaste::mouseMoveEvent(QMouseEvent * e) +{ + switch (getStatus()) + { + case SetTargetPoint: + targetPoint = snapPoint(e); + + deletePreview(); + clearPreview(); + preview->addAllFrom(*RS_CLIPBOARD->getGraphic()); + preview->move(targetPoint); + + if (graphic != NULL) + { RS2::Unit sourceUnit = RS_CLIPBOARD->getGraphic()->getUnit(); RS2::Unit targetUnit = graphic->getUnit(); double f = RS_Units::convert(1.0, sourceUnit, targetUnit); - preview->scale(targetPoint, Vector(f,f)); + preview->scale(targetPoint, Vector(f, f)); } - drawPreview(); - break; + drawPreview(); + break; - default: - break; - } + default: + break; + } } - - -void RS_ActionEditPaste::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionEditPaste::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deleteSnapper(); + init(getStatus() - 1); + } } +void RS_ActionEditPaste::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; - -void RS_ActionEditPaste::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - targetPoint = e->getCoordinate(); - trigger(); + targetPoint = *e; + trigger(); } - - -void RS_ActionEditPaste::updateMouseButtonHints() { - switch (getStatus()) { - case SetTargetPoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Set reference point"), - tr("Cancel")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionEditPaste::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetTargetPoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Set reference point"), + tr("Cancel")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionEditPaste::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionEditPaste::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionEditPaste::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } +void RS_ActionEditPaste::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); } - // EOF diff --git a/src/actions/rs_actioneditpaste.h b/src/actions/rs_actioneditpaste.h index 34dc0db..decb09d 100644 --- a/src/actions/rs_actioneditpaste.h +++ b/src/actions/rs_actioneditpaste.h @@ -1,33 +1,8 @@ -/**************************************************************************** -** $Id: rs_actioneditpaste.h 1155 2004-11-18 16:01:06Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONEDITPASTE_H #define RS_ACTIONEDITPASTE_H #include "rs_previewactioninterface.h" +#include "vector.h" /** * This action class can handle user events for pasting entities from @@ -35,38 +10,31 @@ * * @author Andrew Mustun */ -class RS_ActionEditPaste : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetTargetPoint /**< Setting the reference point. */ - }; - -public: - RS_ActionEditPaste( RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionEditPaste(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - Vector targetPoint; +class RS_ActionEditPaste: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetTargetPoint /**< Setting the reference point. */ + }; + + public: + RS_ActionEditPaste(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionEditPaste(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + Vector targetPoint; }; #endif diff --git a/src/actions/rs_actioneditundo.cpp b/src/actions/rs_actioneditundo.cpp index 939fe95..3a9cfea 100644 --- a/src/actions/rs_actioneditundo.cpp +++ b/src/actions/rs_actioneditundo.cpp @@ -13,17 +13,16 @@ // #include "rs_actioneditundo.h" -#include "rs_snapper.h" -//Added by qt3to4: -//#include //needed??? + +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" /** * Constructor. * * @param undo true for undo and false for redo. */ -RS_ActionEditUndo::RS_ActionEditUndo(bool undo, RS_EntityContainer & container, - RS_GraphicView & graphicView): RS_ActionInterface("Edit Undo", container, graphicView) +RS_ActionEditUndo::RS_ActionEditUndo(bool undo, RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Edit Undo", container, graphicView) { this->undo = undo; } @@ -32,34 +31,6 @@ RS_ActionEditUndo::~RS_ActionEditUndo() { } -QAction * RS_ActionEditUndo::createGUIAction(RS2::ActionType type, QObject * parent) -{ - QAction * action; - - if (type == RS2::ActionEditUndo) - { - action = new QAction(QIcon(":/res/undo2.png"), tr("&Undo")/*+ QString("\too")*/, parent); - QList ks; - ks.append(QKeySequence(tr("o, o", "Edit|Undo"))); - ks.append(Qt::CTRL + Qt::Key_Z); -// action->setShortcut(Qt::CTRL + Qt::Key_Z); - action->setShortcuts(ks); - action->setStatusTip(tr("Undoes last action")); - } - else - { - action = new QAction(QIcon(":/res/redo2.png"), tr("&Redo")/* + QString("\tuu")*/, parent); - QList ks; - ks.append(QKeySequence(tr("u, u", "Edit|Redo"))); - ks.append(Qt::CTRL + Qt::SHIFT + Qt::Key_Z); -// action->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_Z); - action->setShortcuts(ks); - action->setStatusTip(tr("Redoes last action")); - } - - return action; -} - void RS_ActionEditUndo::init(int status) { RS_ActionInterface::init(status); @@ -80,3 +51,4 @@ void RS_ActionEditUndo::trigger() finish(); RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } + diff --git a/src/actions/rs_actioneditundo.h b/src/actions/rs_actioneditundo.h index 2e8bb7c..6ae1c62 100644 --- a/src/actions/rs_actioneditundo.h +++ b/src/actions/rs_actioneditundo.h @@ -2,23 +2,18 @@ #define RS_ACTIONEDITUNDO_H #include "rs_actioninterface.h" -#include "rs_undo.h" /** * This action class can handle user events for undo / redo. * * @author Andrew Mustun */ -class RS_ActionEditUndo : public RS_ActionInterface +class RS_ActionEditUndo: public RS_ActionInterface { - //Q_OBJECT public: - RS_ActionEditUndo(bool undo, RS_EntityContainer & container, - RS_GraphicView & graphicView); + RS_ActionEditUndo(bool undo, RS_EntityContainer & container, RS_GraphicView & graphicView); ~RS_ActionEditUndo(); - static QAction * createGUIAction(RS2::ActionType type, QObject * parent); - virtual void init(int status = 0); virtual void trigger(); diff --git a/src/actions/rs_actionfilenew.cpp b/src/actions/rs_actionfilenew.cpp index 7c9c5ec..980e4b9 100644 --- a/src/actions/rs_actionfilenew.cpp +++ b/src/actions/rs_actionfilenew.cpp @@ -1,68 +1,47 @@ -/**************************************************************************** -** $Id: rs_actionfilenew.cpp 1090 2004-03-16 10:02:59Z js $ -** -** 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_actionfilenew.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_actionfilenew.h" -#include "drawing.h" +//#include "drawing.h" -RS_ActionFileNew::RS_ActionFileNew(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionFileNew::RS_ActionFileNew(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("File New", container, graphicView) { } -QAction * RS_ActionFileNew::createGUIAction(RS2::ActionType /*type*/, QObject * parent) +RS_ActionFileNew::~RS_ActionFileNew() { - QAction * action = new QAction(QIcon(":/res/filenew.png"), tr("&New"), parent); - action->setShortcut(Qt::CTRL + Qt::Key_N); -// QAction* action = new QAction(tr("New Drawing"), QPixmap::fromMimeSource("filenew.png"), -// tr("&New"), CTRL+Key_N, parent); - action->setStatusTip(tr("Creates a new drawing")); - return action; } void RS_ActionFileNew::trigger() { - /* - // Not supported currently - RS_DEBUG->print("RS_ActionFileNew::trigger"); - - QString fileName; //= RS_DIALOGFACTORY->requestFileNewDialog(); - if (graphic!=NULL && !fileName.isEmpty()) { - graphic->open(fileName, ); -} - */ - finish(); + /* + // Not supported currently + RS_DEBUG->print("RS_ActionFileNew::trigger"); + + QString fileName; //= RS_DIALOGFACTORY->requestFileNewDialog(); + if (graphic!=NULL && !fileName.isEmpty()) { + graphic->open(fileName, ); + } + */ + finish(); } - void RS_ActionFileNew::init(int status) { - RS_ActionInterface::init(status); - trigger(); + RS_ActionInterface::init(status); + trigger(); } -// EOF diff --git a/src/actions/rs_actionfilenew.h b/src/actions/rs_actionfilenew.h index 9c1474f..fe8ddc6 100644 --- a/src/actions/rs_actionfilenew.h +++ b/src/actions/rs_actionfilenew.h @@ -1,51 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionfilenew.h 1155 2004-11-18 16:01:06Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONFILENEW_H #define RS_ACTIONFILENEW_H #include "rs_actioninterface.h" - /** * This action class can handle user events to create new blank documents. * * @author Andrew Mustun */ -class RS_ActionFileNew : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionFileNew(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionFileNew() {} - - static QAction* createGUIAction(RS2::ActionType type, QObject* parent); +class RS_ActionFileNew: public RS_ActionInterface +{ + public: + RS_ActionFileNew(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionFileNew(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionfileopen.cpp b/src/actions/rs_actionfileopen.cpp index 7093bbc..517670f 100644 --- a/src/actions/rs_actionfileopen.cpp +++ b/src/actions/rs_actionfileopen.cpp @@ -1,10 +1,22 @@ +// rs_actionfileopen.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_actionfileopen.h" -#include "drawing.h" +//#include "drawing.h" -RS_ActionFileOpen::RS_ActionFileOpen(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionFileOpen::RS_ActionFileOpen(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("File Open", container, graphicView) { } @@ -13,34 +25,23 @@ RS_ActionFileOpen::~RS_ActionFileOpen() { } -QAction * RS_ActionFileOpen::createGUIAction(RS2::ActionType /*type*/, QObject * parent) -{ - //icon = QPixmap(fileopen_xpm); - QAction * action = new QAction(QIcon(":/res/fileopen2.png"), tr("&Open..."), parent); - action->setShortcut(Qt::CTRL + Qt::Key_O); -// QAction* action = new QAction(tr("Open Drawing"), -// QPixmap::fromMimeSource("fileopen2.png"), -// tr("&Open..."), CTRL+Key_O, parent); - action->setStatusTip(tr("Opens an existing drawing")); - return action; -} - void RS_ActionFileOpen::trigger() { - /* - // Not supported currently - RS_DEBUG->print("RS_ActionFileOpen::trigger"); - - QString fileName; //= RS_DIALOGFACTORY->requestFileOpenDialog(); - if (graphic!=NULL && !fileName.isEmpty()) { - graphic->open(fileName, ); -} - */ - finish(); + /* + // Not supported currently + RS_DEBUG->print("RS_ActionFileOpen::trigger"); + + QString fileName; //= RS_DIALOGFACTORY->requestFileOpenDialog(); + if (graphic!=NULL && !fileName.isEmpty()) { + graphic->open(fileName, ); + } + */ + finish(); } void RS_ActionFileOpen::init(int status) { - RS_ActionInterface::init(status); - trigger(); + RS_ActionInterface::init(status); + trigger(); } + diff --git a/src/actions/rs_actionfileopen.h b/src/actions/rs_actionfileopen.h index 955292c..110a30c 100644 --- a/src/actions/rs_actionfileopen.h +++ b/src/actions/rs_actionfileopen.h @@ -10,13 +10,10 @@ */ class RS_ActionFileOpen: public RS_ActionInterface { - //Q_OBJECT public: RS_ActionFileOpen(RS_EntityContainer & container, RS_GraphicView & graphicView); ~RS_ActionFileOpen(); - static QAction * createGUIAction(RS2::ActionType type, QObject * parent); - virtual void init(int status = 0); virtual void trigger(); }; diff --git a/src/actions/rs_actionfilesave.cpp b/src/actions/rs_actionfilesave.cpp index 4446afc..dc040c8 100644 --- a/src/actions/rs_actionfilesave.cpp +++ b/src/actions/rs_actionfilesave.cpp @@ -1,51 +1,28 @@ -/**************************************************************************** -** $Id: rs_actionfilesave.cpp 1096 2004-03-17 11:54:02Z 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_actionfilesave.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_actionfilesave.h" #include "drawing.h" -//Added by qt3to4: -//#include -RS_ActionFileSave::RS_ActionFileSave(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionFileSave::RS_ActionFileSave(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("File Save", container, graphicView) { } -QAction* RS_ActionFileSave::createGUIAction(RS2::ActionType /*type*/, QObject* parent) +RS_ActionFileSave::~RS_ActionFileSave() { - //icon = QPixmap(filesave_xpm); - QAction * action = new QAction(QIcon(":/res/filesave2.png"), tr("&Save"), parent); - action->setShortcut(Qt::CTRL + Qt::Key_S); -// QAction* action = new QAction(tr("Save Drawing"), -// QPixmap::fromMimeSource("filesave2.png"), -// tr("&Save"), CTRL+Key_S, parent); - action->setStatusTip(tr("Saves the current drawing")); - return action; } void RS_ActionFileSave::trigger() @@ -53,18 +30,14 @@ void RS_ActionFileSave::trigger() RS_DEBUG->print("RS_ActionFileSave::trigger"); if (graphic != NULL) - { graphic->save(); - } finish(); } - - -void RS_ActionFileSave::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionFileSave::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } -// EOF diff --git a/src/actions/rs_actionfilesave.h b/src/actions/rs_actionfilesave.h index 49b59e9..c5463fd 100644 --- a/src/actions/rs_actionfilesave.h +++ b/src/actions/rs_actionfilesave.h @@ -1,51 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionfilesave.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONFILESAVE_H #define RS_ACTIONFILESAVE_H #include "rs_actioninterface.h" - /** * This action class can handle user events to save the current file. * * @author Andrew Mustun */ -class RS_ActionFileSave : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionFileSave(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionFileSave() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* parent); +class RS_ActionFileSave: public RS_ActionInterface +{ + public: + RS_ActionFileSave(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionFileSave(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionfilesaveas.cpp b/src/actions/rs_actionfilesaveas.cpp index 8a5d23e..6f2b656 100644 --- a/src/actions/rs_actionfilesaveas.cpp +++ b/src/actions/rs_actionfilesaveas.cpp @@ -1,66 +1,44 @@ -/**************************************************************************** -** $Id: rs_actionfilesaveas.cpp 1090 2004-03-16 10:02:59Z js $ -** -** 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_actionfilesaveas.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_actionfilesaveas.h" #include "drawing.h" -//Added by qt3to4: -//#include -RS_ActionFileSaveAs::RS_ActionFileSaveAs(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionFileSaveAs::RS_ActionFileSaveAs(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Add Layer", container, graphicView) { } -QAction * RS_ActionFileSaveAs::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionFileSaveAs::~RS_ActionFileSaveAs() { - QAction * action = new QAction(QIcon("filesaveas.png"), tr("Save &as..."), 0); -// QAction* action = new QAction(tr("Save Drawing As"), QPixmap::fromMimeSource("filesaveas.png"), tr("Save &as..."), -// QKeySequence(), NULL); - action->setStatusTip(tr("Saves the current drawing under a new filename")); - return action; } void RS_ActionFileSaveAs::trigger() { - RS_DEBUG->print("RS_ActionFileSaveAs::trigger"); - - QString fileName; // = RS_DIALOGFACTORY->requestFileSaveAsDialog(); - if (graphic!=NULL && !fileName.isEmpty()) { - graphic->saveAs(fileName, RS2::FormatUnknown); - } - finish(); -} + RS_DEBUG->print("RS_ActionFileSaveAs::trigger"); + QString fileName; // = RS_DIALOGFACTORY->requestFileSaveAsDialog(); + if (graphic != NULL && !fileName.isEmpty()) + graphic->saveAs(fileName, RS2::FormatUnknown); + finish(); +} -void RS_ActionFileSaveAs::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionFileSaveAs::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } -// EOF diff --git a/src/actions/rs_actionfilesaveas.h b/src/actions/rs_actionfilesaveas.h index 071efb9..8df2c4f 100644 --- a/src/actions/rs_actionfilesaveas.h +++ b/src/actions/rs_actionfilesaveas.h @@ -1,52 +1,22 @@ -/**************************************************************************** -** $Id: rs_actionfilesaveas.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONFILESAVEAS_H #define RS_ACTIONFILESAVEAS_H #include "rs_actioninterface.h" - /** * This action class can handle user events to export files * in various formats. * * @author Andrew Mustun */ -class RS_ActionFileSaveAs : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionFileSaveAs(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionFileSaveAs() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionFileSaveAs: public RS_ActionInterface +{ + public: + RS_ActionFileSaveAs(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionFileSaveAs(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actioninfoangle.cpp b/src/actions/rs_actioninfoangle.cpp index 70abb78..c6fa7dd 100644 --- a/src/actions/rs_actioninfoangle.cpp +++ b/src/actions/rs_actioninfoangle.cpp @@ -1,182 +1,165 @@ -/**************************************************************************** -** $Id: rs_actioninfoangle.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_actioninfoangle.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_actioninfoangle.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" #include "rs_information.h" -#include "rs_snapper.h" - - -RS_ActionInfoAngle::RS_ActionInfoAngle(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Info Angle", - container, graphicView) {} - - -QAction * RS_ActionInfoAngle::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionInfoAngle::RS_ActionInfoAngle(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Info Angle", + container, graphicView) { - QAction * action = new QAction(tr("&Angle between two lines"), 0); -// QAction* action = new QAction(tr("Angle between two lines"), -// tr("&Angle between two lines"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Measures the angle between two lines")); - return action; } - -void RS_ActionInfoAngle::init(int status) { - RS_ActionInterface::init(status); - +RS_ActionInfoAngle::~RS_ActionInfoAngle() +{ } - - -void RS_ActionInfoAngle::trigger() { - - RS_DEBUG->print("RS_ActionInfoAngle::trigger()"); - deleteSnapper(); - - if (entity1!=NULL && entity2!=NULL) { - VectorSolutions sol = - RS_Information::getIntersection(entity1, entity2, false); - - if (sol.hasValid()) { - intersection = sol.get(0); - - if (intersection.valid && point1.valid && point2.valid) { - double angle1 = intersection.angleTo(point1); - double angle2 = intersection.angleTo(point2); - double angle = fabs(angle2-angle1); - - QString str; - str.sprintf("%.6f", RS_Math::rad2deg(angle)); - RS_DIALOGFACTORY->commandMessage(tr("Angle: %1%2") - .arg(str).arg(QChar(0xB0))); - } - } else { - RS_DIALOGFACTORY->commandMessage(tr("Lines are parallel")); - } - } +void RS_ActionInfoAngle::init(int status) +{ + RS_ActionInterface::init(status); } +void RS_ActionInfoAngle::trigger() +{ + RS_DEBUG->print("RS_ActionInfoAngle::trigger()"); + deleteSnapper(); + + if (entity1 != NULL && entity2 != NULL) + { + VectorSolutions sol = RS_Information::getIntersection(entity1, entity2, false); + + if (sol.hasValid()) + { + intersection = sol.get(0); + + if (intersection.valid && point1.valid && point2.valid) + { + double angle1 = intersection.angleTo(point1); + double angle2 = intersection.angleTo(point2); + double angle = fabs(angle2 - angle1); + + QString str; + str.sprintf("%.6f", RS_Math::rad2deg(angle)); + RS_DIALOGFACTORY->commandMessage(tr("Angle: %1%2").arg(str).arg(QChar(0xB0))); + } + } + else + RS_DIALOGFACTORY->commandMessage(tr("Lines are parallel")); + } +} +void RS_ActionInfoAngle::mouseMoveEvent(QMouseEvent * /*e*/) +{ + RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent begin"); -void RS_ActionInfoAngle::mouseMoveEvent(QMouseEvent* /*e*/) { - RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent begin"); - - switch (getStatus()) { - case SetEntity1: - break; + switch (getStatus()) + { + case SetEntity1: + break; - case SetEntity2: - break; + case SetEntity2: + break; - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionInfoAngle::mouseMoveEvent end"); } - - -void RS_ActionInfoAngle::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - - Vector mouse(graphicView->toGraphX(e->x()), - graphicView->toGraphY(e->y())); - - switch (getStatus()) { - case SetEntity1: - entity1 = catchEntity(e); - if (entity1!=NULL && entity1->rtti()==RS2::EntityLine) { - point1 = entity1->getNearestPointOnEntity(mouse); - setStatus(SetEntity2); - } - break; - - case SetEntity2: - entity2 = catchEntity(e); - if (entity2!=NULL && entity2->rtti()==RS2::EntityLine) { - point2 = entity2->getNearestPointOnEntity(mouse); - trigger(); - setStatus(SetEntity1); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionInfoAngle::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector mouse(graphicView->toGraphX(e->x()), graphicView->toGraphY(e->y())); + + switch (getStatus()) + { + case SetEntity1: + entity1 = catchEntity(e); + + if (entity1 != NULL && entity1->rtti() == RS2::EntityLine) + { + point1 = entity1->getNearestPointOnEntity(mouse); + setStatus(SetEntity2); + } + + break; + + case SetEntity2: + entity2 = catchEntity(e); + + if (entity2 != NULL && entity2->rtti() == RS2::EntityLine) + { + point2 = entity2->getNearestPointOnEntity(mouse); + trigger(); + setStatus(SetEntity1); + } + + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionInfoAngle::updateMouseButtonHints() { - switch (getStatus()) { - case SetEntity1: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify first line"), - tr("Cancel")); - break; - case SetEntity2: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify second line"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionInfoAngle::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetEntity1: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify first line"), tr("Cancel")); + break; + + case SetEntity2: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify second line"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionInfoAngle::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionInfoAngle::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionInfoAngle::updateToolBar() { - switch (getStatus()) { - case SetEntity1: - case SetEntity2: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); - break; - } +void RS_ActionInfoAngle::updateToolBar() +{ + switch (getStatus()) + { + case SetEntity1: + case SetEntity2: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); + break; + } } - -// EOF diff --git a/src/actions/rs_actioninfoangle.h b/src/actions/rs_actioninfoangle.h index b3486ed..ca33687 100644 --- a/src/actions/rs_actioninfoangle.h +++ b/src/actions/rs_actioninfoangle.h @@ -1,74 +1,47 @@ -/**************************************************************************** -** $Id: rs_actioninfoangle.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONINFOANGLE_H #define RS_ACTIONINFOANGLE_H #include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to measure angles. * * @author Andrew Mustun */ -class RS_ActionInfoAngle : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetEntity1, /**< Setting the 1st entity. */ - SetEntity2 /**< Setting the 2nd entity. */ - }; - -public: - RS_ActionInfoAngle(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionInfoAngle() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_Entity* entity1; - Vector point1; - - RS_Entity* entity2; - Vector point2; - - Vector intersection; +class RS_ActionInfoAngle: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetEntity1, /**< Setting the 1st entity. */ + SetEntity2 /**< Setting the 2nd entity. */ + }; + + public: + RS_ActionInfoAngle(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionInfoAngle(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_Entity * entity1; + Vector point1; + + RS_Entity * entity2; + Vector point2; + + Vector intersection; }; #endif diff --git a/src/actions/rs_actioninfoarea.cpp b/src/actions/rs_actioninfoarea.cpp index 9d09a4b..34e1646 100644 --- a/src/actions/rs_actioninfoarea.cpp +++ b/src/actions/rs_actioninfoarea.cpp @@ -1,272 +1,268 @@ -/**************************************************************************** -** $Id: rs_actioninfoarea.cpp 1134 2004-07-13 23:26:13Z 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_actioninfoarea.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_actioninfoarea.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionInfoArea::RS_ActionInfoArea(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Info Area", - container, graphicView) {} - - -QAction* RS_ActionInfoArea::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionInfoArea::RS_ActionInfoArea(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Info Area", + container, graphicView) { - QAction * action = new QAction(tr("&Polygonal Area"), 0); -// QAction* action = new QAction(tr("Polygonal Area"), -// tr("&Polygonal Area"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Measures the area of a polygon")); - return action; } - -void RS_ActionInfoArea::init(int status) { - RS_ActionInterface::init(status); - - currentLine = NULL; - closingLine = NULL; - - //std::cout << "RS_ActionInfoArea::init: " << status << "\n"; +RS_ActionInfoArea::~RS_ActionInfoArea() +{ } +void RS_ActionInfoArea::init(int status) +{ + RS_ActionInterface::init(status); + currentLine = NULL; + closingLine = NULL; -void RS_ActionInfoArea::trigger() { - - RS_DEBUG->print("RS_ActionInfoArea::trigger()"); - if (ia.isValid()) { - ia.close(); - ia.calculate(); - double area = ia.getArea(); - double circ = ia.getCircumference(); - - RS_DEBUG->print("RS_ActionInfoArea::trigger: area: %f", area); - RS_DIALOGFACTORY->commandMessage(tr("Area: %1").arg(area)); - RS_DIALOGFACTORY->commandMessage(tr("Circumference: %1").arg(circ)); - } - - ia.reset(); - - /* - if (point1.valid && point2.valid) { - double dist = point1.distanceTo(point2); - QString str; - str.sprintf("%.6f", dist); - RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str)); + //std::cout << "RS_ActionInfoArea::init: " << status << "\n"; } - */ + +void RS_ActionInfoArea::trigger() +{ + RS_DEBUG->print("RS_ActionInfoArea::trigger()"); + + if (ia.isValid()) + { + ia.close(); + ia.calculate(); + double area = ia.getArea(); + double circ = ia.getCircumference(); + + RS_DEBUG->print("RS_ActionInfoArea::trigger: area: %f", area); + RS_DIALOGFACTORY->commandMessage(tr("Area: %1").arg(area)); + RS_DIALOGFACTORY->commandMessage(tr("Circumference: %1").arg(circ)); + } + + ia.reset(); + + /* + if (point1.valid && point2.valid) { + double dist = point1.distanceTo(point2); + QString str; + str.sprintf("%.6f", dist); + RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str)); + } + */ } +void RS_ActionInfoArea::mouseMoveEvent(QMouseEvent * e) +{ + //RS_DEBUG->print("RS_ActionInfoArea::mouseMoveEvent begin"); + if (getStatus() == SetFirstPoint + || getStatus() == SetNextPoint) + { + Vector mouse = snapPoint(e); -void RS_ActionInfoArea::mouseMoveEvent(QMouseEvent* e) { - //RS_DEBUG->print("RS_ActionInfoArea::mouseMoveEvent begin"); + switch (getStatus()) + { + case SetFirstPoint: + break; - if (getStatus()==SetFirstPoint || - getStatus()==SetNextPoint) { + case SetNextPoint: - Vector mouse = snapPoint(e); + if (prev.valid) + { + deletePreview(); - switch (getStatus()) { - case SetFirstPoint: - break; + if (currentLine != NULL) + { + preview->removeEntity(currentLine); + currentLine = NULL; + } - case SetNextPoint: - if (prev.valid) { - deletePreview(); - if (currentLine!=NULL) { - preview->removeEntity(currentLine); - currentLine = NULL; - } - if (closingLine!=NULL) { - preview->removeEntity(closingLine); - closingLine = NULL; - } + if (closingLine != NULL) + { + preview->removeEntity(closingLine); + closingLine = NULL; + } - currentLine = new RS_Line(preview, - RS_LineData(prev, - mouse)); - preview->addEntity(currentLine); + currentLine = new RS_Line(preview, + RS_LineData(prev, + mouse)); + preview->addEntity(currentLine); - if (preview->count()>1) { - closingLine = new RS_Line(preview, - RS_LineData(mouse, - point1)); + if (preview->count() > 1) + { + closingLine = new RS_Line(preview, + RS_LineData(mouse, + point1)); - preview->addEntity(closingLine); + preview->addEntity(closingLine); } - drawPreview(); - } - break; + drawPreview(); + } + break; - default: - break; - } - } + default: + break; + } + } - //RS_DEBUG->print("RS_ActionInfoArea::mouseMoveEvent end"); + //RS_DEBUG->print("RS_ActionInfoArea::mouseMoveEvent end"); } - - -void RS_ActionInfoArea::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - //deletePreview(); - //clearPreview(); - - // close the polygon (preview) - if (getStatus()==SetNextPoint && prev.valid) { - deletePreview(); - - if (currentLine!=NULL) { - preview->removeEntity(currentLine); - currentLine = NULL; - } - if (closingLine!=NULL) { - preview->removeEntity(closingLine); - closingLine = NULL; - } - - currentLine = new RS_Line(preview, - RS_LineData(prev, - point1)); - - preview->addEntity(currentLine); - - drawPreview(); - } - - deleteSnapper(); - trigger(); - init(getStatus()-1); - } +void RS_ActionInfoArea::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + //deletePreview(); + //clearPreview(); + + // close the polygon (preview) + if (getStatus() == SetNextPoint && prev.valid) + { + deletePreview(); + + if (currentLine != NULL) + { + preview->removeEntity(currentLine); + currentLine = NULL; + } + + if (closingLine != NULL) + { + preview->removeEntity(closingLine); + closingLine = NULL; + } + + currentLine = new RS_Line(preview, + RS_LineData(prev, + point1)); + + preview->addEntity(currentLine); + + drawPreview(); + } + + deleteSnapper(); + trigger(); + init(getStatus() - 1); + } } - - -void RS_ActionInfoArea::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetFirstPoint: - point1 = mouse; - - deletePreview(); - clearPreview(); - - ia.addPoint(mouse); - RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2") - .arg(mouse.x).arg(mouse.y)); - - graphicView->moveRelativeZero(point1); - prev = mouse; - - setStatus(SetNextPoint); - break; - - case SetNextPoint: - if (point1.valid) { - //point2 = mouse; - /*deletePreview(); - clearPreview(); - */ - ia.addPoint(mouse); - RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2") - .arg(mouse.x).arg(mouse.y)); - - currentLine = NULL; - - graphicView->moveRelativeZero(mouse); - prev = mouse; - - // automatically detect that the polyline is now closed - if (ia.isClosed()) { - trigger(); - setStatus(SetFirstPoint); - } - //trigger(); - //setStatus(SetFirstPoint); - } - break; - - default: - break; - } +void RS_ActionInfoArea::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetFirstPoint: + point1 = mouse; + + deletePreview(); + clearPreview(); + + ia.addPoint(mouse); + RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y)); + + graphicView->moveRelativeZero(point1); + prev = mouse; + + setStatus(SetNextPoint); + break; + + case SetNextPoint: + + if (point1.valid) + { + //point2 = mouse; + /*deletePreview(); + clearPreview(); + */ + ia.addPoint(mouse); + RS_DIALOGFACTORY->commandMessage(tr("Point: %1/%2").arg(mouse.x).arg(mouse.y)); + + currentLine = NULL; + + graphicView->moveRelativeZero(mouse); + prev = mouse; + + // automatically detect that the polyline is now closed + if (ia.isClosed()) + { + trigger(); + setStatus(SetFirstPoint); + } + //trigger(); + //setStatus(SetFirstPoint); + } + break; + + default: + break; + } } - -void RS_ActionInfoArea::updateMouseButtonHints() { - switch (getStatus()) { - case SetFirstPoint: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify first point of polygon"), - tr("Cancel")); - break; - case SetNextPoint: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify next point of polygon"), - tr("Terminate")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionInfoArea::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetFirstPoint: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify first point of polygon"), + tr("Cancel")); + break; + + case SetNextPoint: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify next point of polygon"), + tr("Terminate")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionInfoArea::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionInfoArea::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionInfoArea::updateToolBar() { - switch (getStatus()) { - case SetFirstPoint: - case SetNextPoint: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); - break; - } +void RS_ActionInfoArea::updateToolBar() +{ + switch (getStatus()) + { + case SetFirstPoint: + case SetNextPoint: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); + break; + } } - // EOF diff --git a/src/actions/rs_actioninfoarea.h b/src/actions/rs_actioninfoarea.h index 1437ca7..0f701ac 100644 --- a/src/actions/rs_actioninfoarea.h +++ b/src/actions/rs_actioninfoarea.h @@ -1,79 +1,48 @@ -/**************************************************************************** -** $Id: rs_actioninfoarea.h 1133 2004-07-11 20:42:18Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONINFOAREA_H #define RS_ACTIONINFOAREA_H -#include "rs_previewactioninterface.h" #include "rs_infoarea.h" +#include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Entity; /** - * This action class can handle user events to measure distances between + * This action class can handle user events to measure distances between * two points. * * @author Andrew Mustun */ -class RS_ActionInfoArea : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetFirstPoint, /**< Setting the 1st point of the polygon. */ - SetNextPoint /**< Setting a next point. */ - }; - -public: - RS_ActionInfoArea(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionInfoArea() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - Vector point1; - Vector prev; - RS_Entity* currentLine; - RS_Entity* closingLine; - //Vector point2; - RS_InfoArea ia; +class RS_ActionInfoArea: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetFirstPoint, /**< Setting the 1st point of the polygon. */ + SetNextPoint /**< Setting a next point. */ + }; + + public: + RS_ActionInfoArea(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionInfoArea(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + Vector point1; + Vector prev; + RS_Entity * currentLine; + RS_Entity * closingLine; + RS_InfoArea ia; }; #endif diff --git a/src/actions/rs_actioninfodist.cpp b/src/actions/rs_actioninfodist.cpp index a3c2e8f..2c3a6ad 100644 --- a/src/actions/rs_actioninfodist.cpp +++ b/src/actions/rs_actioninfodist.cpp @@ -1,190 +1,177 @@ -/**************************************************************************** -** $Id: rs_actioninfodist.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_actioninfodist.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_actioninfodist.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionInfoDist::RS_ActionInfoDist(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Info Dist", - container, graphicView) {} - - -QAction* RS_ActionInfoDist::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionInfoDist::RS_ActionInfoDist(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Info Dist", + container, graphicView) { - QAction * action = new QAction(tr("&Distance Point to Point"), 0); -// QAction* action = new QAction(tr("Distance Point to Point"), -// tr("&Distance Point to Point"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Measures the distance between two points")); - return action; } - -void RS_ActionInfoDist::init(int status) { - RS_ActionInterface::init(status); - +RS_ActionInfoDist::~RS_ActionInfoDist() +{ } - - -void RS_ActionInfoDist::trigger() { - - RS_DEBUG->print("RS_ActionInfoDist::trigger()"); - - if (point1.valid && point2.valid) { - double dist = point1.distanceTo(point2); - QString str; - str.sprintf("%.6f", dist); - RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str)); - } +void RS_ActionInfoDist::init(int status) +{ + RS_ActionInterface::init(status); } +void RS_ActionInfoDist::trigger() +{ + RS_DEBUG->print("RS_ActionInfoDist::trigger()"); + + if (point1.valid && point2.valid) + { + double dist = point1.distanceTo(point2); + QString str; + str.sprintf("%.6f", dist); + RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str)); + } +} +void RS_ActionInfoDist::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent begin"); -void RS_ActionInfoDist::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent begin"); + if (getStatus() == SetPoint1 + || getStatus() == SetPoint2) + { + Vector mouse = snapPoint(e); - if (getStatus()==SetPoint1 || - getStatus()==SetPoint2) { + switch (getStatus()) + { + case SetPoint1: + break; - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetPoint1: - break; + case SetPoint2: - case SetPoint2: - if (point1.valid) { - point2 = mouse; + if (point1.valid) + { + point2 = mouse; - deletePreview(); - clearPreview(); + deletePreview(); + clearPreview(); - preview->addEntity(new RS_Line(preview, - RS_LineData(point1, - point2))); + preview->addEntity(new RS_Line(preview, + RS_LineData(point1, + point2))); - drawPreview(); - } - break; + drawPreview(); + } + break; - default: - break; - } - } + default: + break; + } + } - RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionInfoDist::mouseMoveEvent end"); } - - -void RS_ActionInfoDist::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionInfoDist::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionInfoDist::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetPoint1: - point1 = mouse; - graphicView->moveRelativeZero(point1); - setStatus(SetPoint2); - break; - - case SetPoint2: - if (point1.valid) { - point2 = mouse; - deletePreview(); - clearPreview(); - graphicView->moveRelativeZero(point2); - trigger(); - setStatus(SetPoint1); - } - break; - - default: - break; - } +void RS_ActionInfoDist::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetPoint1: + point1 = mouse; + graphicView->moveRelativeZero(point1); + setStatus(SetPoint2); + break; + + case SetPoint2: + + if (point1.valid) + { + point2 = mouse; + deletePreview(); + clearPreview(); + graphicView->moveRelativeZero(point2); + trigger(); + setStatus(SetPoint1); + } + break; + + default: + break; + } } - -void RS_ActionInfoDist::updateMouseButtonHints() { - switch (getStatus()) { - case SetPoint1: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify first point of distance"), - tr("Cancel")); - break; - case SetPoint2: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify second point of distance"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionInfoDist::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetPoint1: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify first point of distance"), + tr("Cancel")); + break; + + case SetPoint2: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify second point of distance"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionInfoDist::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionInfoDist::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionInfoDist::updateToolBar() { - switch (getStatus()) { - case SetPoint1: - case SetPoint2: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); - break; - } +void RS_ActionInfoDist::updateToolBar() +{ + switch (getStatus()) + { + case SetPoint1: + case SetPoint2: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); + break; + } } - // EOF diff --git a/src/actions/rs_actioninfodist.h b/src/actions/rs_actioninfodist.h index 7c7f7f9..91e02cb 100644 --- a/src/actions/rs_actioninfodist.h +++ b/src/actions/rs_actioninfodist.h @@ -1,74 +1,42 @@ -/**************************************************************************** -** $Id: rs_actioninfodist.h 1113 2004-04-01 20:53:39Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONINFODIST_H #define RS_ACTIONINFODIST_H #include "rs_previewactioninterface.h" - +#include "vector.h" /** - * This action class can handle user events to measure distances between + * This action class can handle user events to measure distances between * two points. * * @author Andrew Mustun */ -class RS_ActionInfoDist : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetPoint1, /**< Setting the 1st point of the distance. */ - SetPoint2 /**< Setting the 2nd point of the distance. */ - }; - -public: - RS_ActionInfoDist(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionInfoDist() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - Vector point1; - Vector point2; +class RS_ActionInfoDist: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetPoint1, /**< Setting the 1st point of the distance. */ + SetPoint2 /**< Setting the 2nd point of the distance. */ + }; + + public: + RS_ActionInfoDist(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionInfoDist(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + Vector point1; + Vector point2; }; #endif diff --git a/src/actions/rs_actioninfodist2.cpp b/src/actions/rs_actioninfodist2.cpp index 95bbb3f..f051c92 100644 --- a/src/actions/rs_actioninfodist2.cpp +++ b/src/actions/rs_actioninfodist2.cpp @@ -1,176 +1,159 @@ -/**************************************************************************** -** $Id: rs_actioninfodist2.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_actioninfodist2.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_actioninfodist2.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" - - -RS_ActionInfoDist2::RS_ActionInfoDist2(RS_EntityContainer& container, - RS_GraphicView& graphicView): +RS_ActionInfoDist2::RS_ActionInfoDist2(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Info Dist2", container, graphicView) { } -QAction * RS_ActionInfoDist2::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionInfoDist2::~RS_ActionInfoDist2() { - QAction * action = new QAction(tr("&Distance Entity to Point"), 0); -// QAction* action = new QAction(tr("Distance Entity to Point"), -// tr("&Distance Entity to Point"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Measures the distance between an entity and a point")); - return action; } void RS_ActionInfoDist2::init(int status) { - RS_ActionInterface::init(status); + RS_ActionInterface::init(status); } - - -void RS_ActionInfoDist2::trigger() { - - RS_DEBUG->print("RS_ActionInfoDist2::trigger()"); - deleteSnapper(); - - if (point.valid && entity!=NULL) { - double dist = entity->getDistanceToPoint(point); - QString str; - str.sprintf("%.6f", dist); - RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str)); - } +void RS_ActionInfoDist2::trigger() +{ + RS_DEBUG->print("RS_ActionInfoDist2::trigger()"); + deleteSnapper(); + + if (point.valid && entity != NULL) + { + double dist = entity->getDistanceToPoint(point); + QString str; + str.sprintf("%.6f", dist); + RS_DIALOGFACTORY->commandMessage(tr("Distance: %1").arg(str)); + } } +void RS_ActionInfoDist2::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent begin"); + switch (getStatus()) + { + case SetEntity: + //entity = catchEntity(e); + break; -void RS_ActionInfoDist2::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent begin"); - - switch (getStatus()) { - case SetEntity: - //entity = catchEntity(e); - break; + case SetPoint: - case SetPoint: - if (entity!=NULL) { - point = snapPoint(e); - } - break; + if (entity != NULL) + point = snapPoint(e); + break; - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionInfoDist2::mouseMoveEvent end"); } - - -void RS_ActionInfoDist2::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - - switch (getStatus()) { - case SetEntity: - entity = catchEntity(e); - if (entity!=NULL) { - setStatus(SetPoint); - } - break; - - case SetPoint: { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionInfoDist2::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case SetEntity: + entity = catchEntity(e); + + if (entity != NULL) + setStatus(SetPoint); + break; + + case SetPoint: { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - -void RS_ActionInfoDist2::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - if (getStatus()==SetPoint && entity!=NULL) { - point = e->getCoordinate(); - graphicView->moveRelativeZero(point); - trigger(); - setStatus(SetEntity); - } +void RS_ActionInfoDist2::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + if (getStatus() == SetPoint && entity != NULL) + { + point = *e; + graphicView->moveRelativeZero(point); + trigger(); + setStatus(SetEntity); + } } - - -void RS_ActionInfoDist2::updateMouseButtonHints() { - switch (getStatus()) { - case SetEntity: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify entity"), - tr("Cancel")); - break; - case SetPoint: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify point"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionInfoDist2::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetEntity: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify entity"), + tr("Cancel")); + break; + + case SetPoint: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify point"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionInfoDist2::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionInfoDist2::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionInfoDist2::updateToolBar() { - switch (getStatus()) { - case SetPoint: - case SetEntity: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); - break; - } +void RS_ActionInfoDist2::updateToolBar() +{ + switch (getStatus()) + { + case SetPoint: + case SetEntity: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); + break; + } } - // EOF diff --git a/src/actions/rs_actioninfodist2.h b/src/actions/rs_actioninfodist2.h index edfc53d..a5de1ab 100644 --- a/src/actions/rs_actioninfodist2.h +++ b/src/actions/rs_actioninfodist2.h @@ -1,34 +1,10 @@ -/**************************************************************************** -** $Id: rs_actioninfodist2.h 1113 2004-04-01 20:53:39Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONINFODIST2_H #define RS_ACTIONINFODIST2_H #include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to measure distances between @@ -36,38 +12,33 @@ * * @author Andrew Mustun */ -class RS_ActionInfoDist2 : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetEntity, /**< Setting the entity. */ - SetPoint /**< Setting the point of the distance. */ - }; - -public: - RS_ActionInfoDist2(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionInfoDist2() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void coordinateEvent(RS_CoordinateEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_Entity* entity; - Vector point; +class RS_ActionInfoDist2: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetEntity, /**< Setting the entity. */ + SetPoint /**< Setting the point of the distance. */ + }; + + public: + RS_ActionInfoDist2(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionInfoDist2(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_Entity * entity; + Vector point; }; #endif diff --git a/src/actions/rs_actioninfoinside.cpp b/src/actions/rs_actioninfoinside.cpp index 2af49c9..9417b4d 100644 --- a/src/actions/rs_actioninfoinside.cpp +++ b/src/actions/rs_actioninfoinside.cpp @@ -1,126 +1,98 @@ -/**************************************************************************** -** $Id: rs_actioninfoinside.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_actioninfoinside.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_actioninfoinside.h" + +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" #include "rs_information.h" -#include "rs_snapper.h" -RS_ActionInfoInside::RS_ActionInfoInside(RS_EntityContainer& container, - RS_GraphicView& graphicView): +RS_ActionInfoInside::RS_ActionInfoInside(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Info Inside", container, graphicView) { contour = new RS_EntityContainer(NULL, false); - for(RS_Entity* e=container.firstEntity(); e!=NULL; e=container.nextEntity()) - { + for (RS_Entity * e = container.firstEntity(); e != NULL; e = container.nextEntity()) if (e->isSelected()) - { contour->addEntity(e); - } - } } RS_ActionInfoInside::~RS_ActionInfoInside() { - delete contour; -} - -QAction* RS_ActionInfoInside::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) -{ - QAction * action = new QAction(tr("&Point inside contour"), 0); -// QAction* action = new QAction(tr("Point inside contour"), -// tr("&Point inside contour"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Checks if a given point is inside the selected contour")); - - return action; + delete contour; } void RS_ActionInfoInside::trigger() { - deleteSnapper(); - bool onContour = false; - if (RS_Information::isPointInsideContour(pt, contour, &onContour)) { - RS_DIALOGFACTORY->commandMessage(tr("Point is inside selected contour.")); - } else { - RS_DIALOGFACTORY->commandMessage(tr("Point is outside selected contour.")); - } - finish(); -} - + deleteSnapper(); + bool onContour = false; + if (RS_Information::isPointInsideContour(pt, contour, &onContour)) + RS_DIALOGFACTORY->commandMessage(tr("Point is inside selected contour.")); + else + RS_DIALOGFACTORY->commandMessage(tr("Point is outside selected contour.")); -void RS_ActionInfoInside::mouseMoveEvent(QMouseEvent* e) { - //Vector mouse = snapPoint(e); - //bool onContour = false; - /*if (RS_Information::isPointInsideContour(mouse, contour, &onContour)) { - } else { - }*/ + finish(); } - - -void RS_ActionInfoInside::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deleteSnapper(); - init(getStatus()-1); - } else { - pt = snapPoint(e); - trigger(); - } +void RS_ActionInfoInside::mouseMoveEvent(QMouseEvent * /*e*/) +{ + //Vector mouse = snapPoint(e); + //bool onContour = false; + /*if (RS_Information::isPointInsideContour(mouse, contour, &onContour)) { + } else { + }*/ } - - -void RS_ActionInfoInside::updateMouseButtonHints() { - switch (getStatus()) { - case 0: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify point"), - tr("Cancel")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionInfoInside::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deleteSnapper(); + init(getStatus() - 1); + } + else + { + pt = snapPoint(e); + trigger(); + } } +void RS_ActionInfoInside::updateMouseButtonHints() +{ + switch (getStatus()) + { + case 0: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify point"), tr("Cancel")); + break; - -void RS_ActionInfoInside::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } +void RS_ActionInfoInside::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} - -void RS_ActionInfoInside::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); - } +void RS_ActionInfoInside::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); } -// EOF diff --git a/src/actions/rs_actioninfoinside.h b/src/actions/rs_actioninfoinside.h index 1494e44..a1f1a08 100644 --- a/src/actions/rs_actioninfoinside.h +++ b/src/actions/rs_actioninfoinside.h @@ -1,60 +1,30 @@ -/**************************************************************************** -** $Id: rs_actioninfoinside.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONINFOINSIDE_H #define RS_ACTIONINFOINSIDE_H #include "rs_actioninterface.h" - /** * This action class can handle user events for checking if * a given point is inside or outside the selected contour. * * @author Andrew Mustun */ -class RS_ActionInfoInside : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionInfoInside(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionInfoInside(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionInfoInside: public RS_ActionInterface +{ + public: + RS_ActionInfoInside(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionInfoInside(); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); -private: - Vector pt; - RS_EntityContainer* contour; + private: + Vector pt; + RS_EntityContainer * contour; }; #endif diff --git a/src/actions/rs_actioninfototallength.cpp b/src/actions/rs_actioninfototallength.cpp index b1acd76..5b96dac 100644 --- a/src/actions/rs_actioninfototallength.cpp +++ b/src/actions/rs_actioninfototallength.cpp @@ -1,105 +1,78 @@ -/**************************************************************************** -** $Id: rs_actioninfototallength.cpp 1072 2004-02-18 16:03:20Z 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_actioninfototallength.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_actioninfototallength.h" -#include "rs_actionselectsingle.h" -#include "rs_modification.h" -#include "rs_snapper.h" -#include "rs_point.h" +#include "rs_dialogfactory.h" - - -RS_ActionInfoTotalLength::RS_ActionInfoTotalLength(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Info Total Length", - container, graphicView) {} - - -QAction* RS_ActionInfoTotalLength::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionInfoTotalLength::RS_ActionInfoTotalLength(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Info Total Length", + container, graphicView) { - QAction * action = new QAction(tr("&Total length of selected entities"), 0); -// QAction* action = new QAction(tr("Total length of selected entities"), -// tr("&Total length of selected entities"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Measures the total length of all selected entities")); - - return action; } -void RS_ActionInfoTotalLength::init(int status) { - RS_ActionInterface::init(status); - - trigger(); +RS_ActionInfoTotalLength::~RS_ActionInfoTotalLength() +{ } - - -void RS_ActionInfoTotalLength::trigger() { - - RS_DEBUG->print("RS_ActionInfoTotalLength::trigger()"); - - double len = 0.0; - for (RS_Entity* e = container->firstEntity(RS2::ResolveNone); - e != NULL; - e = container->nextEntity(RS2::ResolveNone)) { - - if (e->isVisible() && e->isSelected()) { - double l = e->getLength(); - if (l<0.0) { - len = -1.0; - break; - } else { - len += l; - } - } - } - - if (len>0.0) { - RS_DIALOGFACTORY->commandMessage( - tr("Total Length of selected entities: %1").arg(len)); - } else { - RS_DIALOGFACTORY->commandMessage(tr("At least one of the selected " - "entities cannot be measured.")); - } - - finish(); +void RS_ActionInfoTotalLength::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } - - -void RS_ActionInfoTotalLength::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } - } +void RS_ActionInfoTotalLength::trigger() +{ + RS_DEBUG->print("RS_ActionInfoTotalLength::trigger()"); + + double len = 0.0; + + for (RS_Entity * e = container->firstEntity(RS2::ResolveNone); + e != NULL; + e = container->nextEntity(RS2::ResolveNone)) + + if (e->isVisible() && e->isSelected()) + { + double l = e->getLength(); + + if (l < 0.0) + { + len = -1.0; + break; + } + else + len += l; + } + + if (len > 0.0) + RS_DIALOGFACTORY->commandMessage( + tr("Total Length of selected entities: %1").arg(len)); + else + RS_DIALOGFACTORY->commandMessage(tr("At least one of the selected " + "entities cannot be measured.")); + + finish(); } +void RS_ActionInfoTotalLength::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); + } +} // EOF diff --git a/src/actions/rs_actioninfototallength.h b/src/actions/rs_actioninfototallength.h index 723b894..cd75db9 100644 --- a/src/actions/rs_actioninfototallength.h +++ b/src/actions/rs_actioninfototallength.h @@ -1,60 +1,30 @@ -/**************************************************************************** -** $Id: rs_actioninfototallength.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONINFOTOTALLENGTH_H #define RS_ACTIONINFOTOTALLENGTH_H #include "rs_actioninterface.h" - /** * This action class can handle user events to delete entities. * * @author Andrew Mustun */ -class RS_ActionInfoTotalLength : public RS_ActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - Acknowledge /**< Acknowledge or cancel. */ - }; +class RS_ActionInfoTotalLength: public RS_ActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + Acknowledge /**< Acknowledge or cancel. */ + }; -public: - RS_ActionInfoTotalLength(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionInfoTotalLength() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); + public: + RS_ActionInfoTotalLength(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionInfoTotalLength(); - virtual void init(int status=0); - virtual void trigger(); - virtual void updateToolBar(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void updateToolBar(); }; #endif diff --git a/src/actions/rs_actionlayersadd.cpp b/src/actions/rs_actionlayersadd.cpp index f200b94..594e824 100644 --- a/src/actions/rs_actionlayersadd.cpp +++ b/src/actions/rs_actionlayersadd.cpp @@ -1,69 +1,49 @@ -/**************************************************************************** -** $Id: rs_actionlayersadd.cpp 1062 2004-01-16 21:51:20Z 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_actionlayersadd.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_actionlayersadd.h" +#include "rs_dialogfactory.h" #include "drawing.h" - - -RS_ActionLayersAdd::RS_ActionLayersAdd(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Add Layer", container, graphicView) {} - - -QAction* RS_ActionLayersAdd::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionLayersAdd::RS_ActionLayersAdd(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Add Layer", container, graphicView) { - QAction * action = new QAction(tr("&Add Layer"), 0); -// QAction* action = new QAction(tr("Add Layer"), tr("&Add Layer"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Add Layer")); +} - return action; +RS_ActionLayersAdd::~RS_ActionLayersAdd() +{ } -void RS_ActionLayersAdd::trigger() { - RS_DEBUG->print("add layer"); +void RS_ActionLayersAdd::trigger() +{ + RS_DEBUG->print("add layer"); - if (RS_DIALOGFACTORY!=NULL) { - if (graphic) { - RS_Layer* layer = RS_DIALOGFACTORY->requestNewLayerDialog( - graphic->getLayerList()); - if (layer!=NULL) - graphic->addLayer(layer); - } - } - finish(); -} + if (RS_DIALOGFACTORY != NULL && graphic) + { + RS_Layer * layer = RS_DIALOGFACTORY->requestNewLayerDialog(graphic->getLayerList()); + if (layer != NULL) + graphic->addLayer(layer); + } + finish(); +} -void RS_ActionLayersAdd::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionLayersAdd::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } -// EOF diff --git a/src/actions/rs_actionlayersadd.h b/src/actions/rs_actionlayersadd.h index 221a7e8..d650279 100644 --- a/src/actions/rs_actionlayersadd.h +++ b/src/actions/rs_actionlayersadd.h @@ -1,53 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionlayersadd.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONLAYERSADD_H #define RS_ACTIONLAYERSADD_H #include "rs_actioninterface.h" - /** * This action class can handle user events to add layers. * * @author Andrew Mustun */ -class RS_ActionLayersAdd : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionLayersAdd(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionLayersAdd() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); +class RS_ActionLayersAdd: public RS_ActionInterface +{ + public: + RS_ActionLayersAdd(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionLayersAdd(); -private: + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionlayersedit.cpp b/src/actions/rs_actionlayersedit.cpp index 879da01..cd55b24 100644 --- a/src/actions/rs_actionlayersedit.cpp +++ b/src/actions/rs_actionlayersedit.cpp @@ -1,83 +1,65 @@ -/**************************************************************************** -** $Id: rs_actionlayersedit.cpp 1062 2004-01-16 21:51:20Z 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_actionlayersedit.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_actionlayersedit.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" #include "drawing.h" - - -RS_ActionLayersEdit::RS_ActionLayersEdit(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Edit Layer", container, graphicView) {} - - -QAction* RS_ActionLayersEdit::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionLayersEdit::RS_ActionLayersEdit(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Edit Layer", container, graphicView) { - QAction * action = new QAction(tr("&Edit Layer"), 0); -// QAction* action = new QAction(tr("Edit Layer"), tr("&Edit Layer"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Edit Layer")); - return action; } -void RS_ActionLayersEdit::trigger() { - RS_DEBUG->print("RS_ActionLayersEdit::trigger"); - - RS_Layer* layer = NULL; - - if (graphic!=NULL) { - layer = - RS_DIALOGFACTORY->requestEditLayerDialog(graphic->getLayerList()); - - if (layer!=NULL) { - graphic->editLayer(graphic->getActiveLayer(), *layer); - - // update updateable entities on the layer that has changed - for (RS_Entity* e=graphic->firstEntity(RS2::ResolveNone); - e!=NULL; - e=graphic->nextEntity(RS2::ResolveNone)) { - - RS_Layer* l = e->getLayer(); - if (l!=NULL && l->getName()==layer->getName()) { - e->update(); - } - } - } - } - finish(); - - graphicView->redraw(); +RS_ActionLayersEdit::~RS_ActionLayersEdit() +{ } +void RS_ActionLayersEdit::trigger() +{ + RS_DEBUG->print("RS_ActionLayersEdit::trigger"); + RS_Layer * layer = NULL; + + if (graphic != NULL) + { + layer = RS_DIALOGFACTORY->requestEditLayerDialog(graphic->getLayerList()); + + if (layer != NULL) + { + graphic->editLayer(graphic->getActiveLayer(), *layer); + + // update updateable entities on the layer that has changed + for (RS_Entity * e = graphic->firstEntity(RS2::ResolveNone); + e != NULL; e = graphic->nextEntity(RS2::ResolveNone)) + { + RS_Layer * l = e->getLayer(); + + if (l != NULL && l->getName() == layer->getName()) + e->update(); + } + } + } + + finish(); + graphicView->redraw(); +} - -void RS_ActionLayersEdit::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionLayersEdit::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } // EOF diff --git a/src/actions/rs_actionlayersedit.h b/src/actions/rs_actionlayersedit.h index 98d3988..415afdc 100644 --- a/src/actions/rs_actionlayersedit.h +++ b/src/actions/rs_actionlayersedit.h @@ -1,52 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionlayersedit.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONLAYERSEDIT_H #define RS_ACTIONLAYERSEDIT_H #include "rs_actioninterface.h" - /** * This action class can handle user events to edit layers. * * @author Andrew Mustun */ -class RS_ActionLayersEdit : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionLayersEdit(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionLayersEdit() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - +class RS_ActionLayersEdit: public RS_ActionInterface +{ + public: + RS_ActionLayersEdit(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionLayersEdit(); + + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionlayersfreezeall.cpp b/src/actions/rs_actionlayersfreezeall.cpp index 7e7dc90..d94ffc8 100644 --- a/src/actions/rs_actionlayersfreezeall.cpp +++ b/src/actions/rs_actionlayersfreezeall.cpp @@ -16,54 +16,30 @@ #include "drawing.h" -RS_ActionLayersFreezeAll::RS_ActionLayersFreezeAll(bool freeze, - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Freeze all Layers", - container, graphicView) { - - this->freeze = freeze; +RS_ActionLayersFreezeAll::RS_ActionLayersFreezeAll(bool freeze, RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Freeze all Layers", container, graphicView) +{ + this->freeze = freeze; } -QAction * RS_ActionLayersFreezeAll::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +RS_ActionLayersFreezeAll::~RS_ActionLayersFreezeAll() { - QAction * action = NULL; - - if (type == RS2::ActionLayersFreezeAll) - { - action = new QAction(tr("&Freeze all"), 0); -// action = new QAction(tr("Freeze all"), tr("&Freeze all"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Freeze all layers")); - } - else if (type == RS2::ActionLayersDefreezeAll) - { - action = new QAction(tr("&Defreeze all"), 0); -// action = new QAction(tr("Defreeze all"), tr("&Defreeze all"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Defreeze all layers")); - } - - return action; } - void RS_ActionLayersFreezeAll::trigger() { - RS_DEBUG->print("RS_ActionLayersFreezeAll::trigger"); - if (graphic!=NULL) - { - //RS_Layer* layer = graphic->getActiveLayer(); - graphic->freezeAllLayers(freeze); - } - finish(); -} + RS_DEBUG->print("RS_ActionLayersFreezeAll::trigger"); + if (graphic != NULL) + //RS_Layer* layer = graphic->getActiveLayer(); + graphic->freezeAllLayers(freeze); + finish(); +} -void RS_ActionLayersFreezeAll::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionLayersFreezeAll::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } -// EOF diff --git a/src/actions/rs_actionlayersfreezeall.h b/src/actions/rs_actionlayersfreezeall.h index de08405..ac6c29d 100644 --- a/src/actions/rs_actionlayersfreezeall.h +++ b/src/actions/rs_actionlayersfreezeall.h @@ -10,13 +10,9 @@ */ class RS_ActionLayersFreezeAll: public RS_ActionInterface { - //Q_OBJECT public: - RS_ActionLayersFreezeAll(bool freeze, RS_EntityContainer & container, - RS_GraphicView & graphicView); - ~RS_ActionLayersFreezeAll() {} - - static QAction * createGUIAction(RS2::ActionType type, QObject* /*parent*/); + RS_ActionLayersFreezeAll(bool freeze, RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionLayersFreezeAll(); virtual void init(int status = 0); virtual void trigger(); diff --git a/src/actions/rs_actionlayersremove.cpp b/src/actions/rs_actionlayersremove.cpp index 937dda1..82aaa47 100644 --- a/src/actions/rs_actionlayersremove.cpp +++ b/src/actions/rs_actionlayersremove.cpp @@ -1,90 +1,72 @@ -/**************************************************************************** -** $Id: rs_actionlayersremove.cpp 1062 2004-01-16 21:51:20Z 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_actionlayersedit.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_actionlayersremove.h" +#include "rs_dialogfactory.h" #include "drawing.h" - - -RS_ActionLayersRemove::RS_ActionLayersRemove(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Remove Layer", container, graphicView) {} - - -QAction * RS_ActionLayersRemove::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionLayersRemove::RS_ActionLayersRemove(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Remove Layer", container, graphicView) { - QAction * action = new QAction(tr("&Remove Layer"), 0); -// QAction * action = new QAction(tr("Remove Layer"), tr("&Remove Layer"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Remove Layer")); - return action; } +RS_ActionLayersRemove::~RS_ActionLayersRemove() +{ +} -void RS_ActionLayersRemove::trigger() { - RS_DEBUG->print("RS_ActionLayersRemove::trigger"); +void RS_ActionLayersRemove::trigger() +{ + RS_DEBUG->print("RS_ActionLayersRemove::trigger"); - if (graphic!=NULL) { - RS_Layer* layer = - RS_DIALOGFACTORY->requestLayerRemovalDialog(graphic->getLayerList()); + if (graphic != NULL) + { + RS_Layer * layer = + RS_DIALOGFACTORY->requestLayerRemovalDialog(graphic->getLayerList()); - /* - if (layer!=NULL && layer->getName()!="0") { + /* + if (layer!=NULL && layer->getName()!="0") { - graphic->startUndoCycle(); - for (RS_Entity* e=graphic->firstEntity(RS2::ResolveNone); - e!=NULL; - e=graphic->nextEntity(RS2::ResolveNone)) { + graphic->startUndoCycle(); + for (RS_Entity* e=graphic->firstEntity(RS2::ResolveNone); + e!=NULL; + e=graphic->nextEntity(RS2::ResolveNone)) { - if (e->getLayer()!=NULL && - e->getLayer()->getName()==layer->getName()) { + if (e->getLayer()!=NULL && + e->getLayer()->getName()==layer->getName()) { - e->setUndoState(true); - e->setLayer("0"); - graphic->addUndoable(e); - } - } + e->setUndoState(true); + e->setLayer("0"); + graphic->addUndoable(e); + } + } - graphic->endUndoCycle(); - */ + graphic->endUndoCycle(); + */ - // Now remove the layer from the layer list: - graphic->removeLayer(layer); - } - finish(); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + // Now remove the layer from the layer list: + graphic->removeLayer(layer); + } + finish(); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } - - -void RS_ActionLayersRemove::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionLayersRemove::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } // EOF diff --git a/src/actions/rs_actionlayersremove.h b/src/actions/rs_actionlayersremove.h index 76c8c2a..a737703 100644 --- a/src/actions/rs_actionlayersremove.h +++ b/src/actions/rs_actionlayersremove.h @@ -1,51 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionlayersremove.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONLAYERSREMOVE_H #define RS_ACTIONLAYERSREMOVE_H #include "rs_actioninterface.h" - /** * This action class can handle user events to remove layers. * * @author Andrew Mustun */ -class RS_ActionLayersRemove : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionLayersRemove(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionLayersRemove() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionLayersRemove: public RS_ActionInterface +{ + public: + RS_ActionLayersRemove(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionLayersRemove(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionlayerstogglelock.cpp b/src/actions/rs_actionlayerstogglelock.cpp index fe09a12..b8ac389 100644 --- a/src/actions/rs_actionlayerstogglelock.cpp +++ b/src/actions/rs_actionlayerstogglelock.cpp @@ -1,89 +1,66 @@ -/**************************************************************************** -** $Id: rs_actionlayerstogglelock.cpp 1062 2004-01-16 21:51:20Z 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_actionlayerstogglelock.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_actionlayerstogglelock.h" +#include "rs_graphicview.h" #include "drawing.h" +RS_ActionLayersToggleLock::RS_ActionLayersToggleLock(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Toggle Layer Visibility", + container, graphicView) +{ +} - -RS_ActionLayersToggleLock::RS_ActionLayersToggleLock( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Toggle Layer Visibility", - container, graphicView) {} - - -QAction* RS_ActionLayersToggleLock::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionLayersToggleLock::~RS_ActionLayersToggleLock() { - QAction * action = new QAction(tr("&Toggle Lock"), 0); -// QAction* action = new QAction(tr("Toggle Layer Lock"), -// tr("&Toggle Lock"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Toggle Lock")); - return action; } void RS_ActionLayersToggleLock::trigger() { - RS_DEBUG->print("toggle layer"); - if (graphic!=NULL) { - RS_Layer* layer = graphic->getActiveLayer(); - if (layer!=NULL) { - graphic->toggleLayerLock(layer); - - // deselect entities on locked layer: - if (layer->isLocked()) { - for (RS_Entity* e=container->firstEntity(); e!=NULL; - e=container->nextEntity()) { - if (e!=NULL && e->isVisible() && e->getLayer()==layer) { - - if (graphicView!=NULL) { - graphicView->deleteEntity(e); - } - - e->setSelected(false); - - if (graphicView!=NULL) { - graphicView->drawEntity(e); - } - } - } - } - } - - } - finish(); + RS_DEBUG->print("toggle layer"); + + if (graphic != NULL) + { + RS_Layer * layer = graphic->getActiveLayer(); + + if (layer != NULL) + { + graphic->toggleLayerLock(layer); + + // deselect entities on locked layer: + if (layer->isLocked()) + for (RS_Entity * e = container->firstEntity(); e != NULL; + e = container->nextEntity()) + if (e != NULL && e->isVisible() && e->getLayer() == layer) + { + if (graphicView != NULL) + graphicView->deleteEntity(e); + + e->setSelected(false); + + if (graphicView != NULL) + graphicView->drawEntity(e); + } + } + } + + finish(); } - - -void RS_ActionLayersToggleLock::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionLayersToggleLock::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } -// EOF diff --git a/src/actions/rs_actionlayerstogglelock.h b/src/actions/rs_actionlayerstogglelock.h index a41f199..b27c9e2 100644 --- a/src/actions/rs_actionlayerstogglelock.h +++ b/src/actions/rs_actionlayerstogglelock.h @@ -1,52 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionlayerstogglelock.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONLAYERSTOGGLELOCK_H #define RS_ACTIONLAYERSTOGGLELOCK_H #include "rs_actioninterface.h" - /** * This action class can handle user events to edit layers. * * @author Andrew Mustun */ -class RS_ActionLayersToggleLock : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionLayersToggleLock(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionLayersToggleLock() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - +class RS_ActionLayersToggleLock: public RS_ActionInterface +{ + public: + RS_ActionLayersToggleLock(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionLayersToggleLock(); + + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionlayerstoggleview.cpp b/src/actions/rs_actionlayerstoggleview.cpp index 14e8990..e61ce40 100644 --- a/src/actions/rs_actionlayerstoggleview.cpp +++ b/src/actions/rs_actionlayerstoggleview.cpp @@ -1,66 +1,46 @@ -/**************************************************************************** -** $Id: rs_actionlayerstoggleview.cpp 1062 2004-01-16 21:51:20Z 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_actionlayerstoggleview.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_actionlayerstoggleview.h" #include "drawing.h" - - -RS_ActionLayersToggleView::RS_ActionLayersToggleView( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Toggle Layer Visibility", - container, graphicView) {} - - -QAction* RS_ActionLayersToggleView::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionLayersToggleView::RS_ActionLayersToggleView(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Toggle Layer Visibility", + container, graphicView) { - QAction * action = new QAction(tr("&Toggle Layer"), 0); -// QAction* action = new QAction(tr("Toggle Layer Visibility"), -// tr("&Toggle Layer"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Toggle Layer")); - return action; } -void RS_ActionLayersToggleView::trigger() { - RS_DEBUG->print("toggle layer"); - if (graphic!=NULL) { - RS_Layer* layer = graphic->getActiveLayer(); - graphic->toggleLayer(layer); - } - finish(); +RS_ActionLayersToggleView::~RS_ActionLayersToggleView() +{ } +void RS_ActionLayersToggleView::trigger() +{ + RS_DEBUG->print("toggle layer"); + + if (graphic != NULL) + { + RS_Layer * layer = graphic->getActiveLayer(); + graphic->toggleLayer(layer); + } + finish(); +} -void RS_ActionLayersToggleView::init(int status) { - RS_ActionInterface::init(status); - trigger(); +void RS_ActionLayersToggleView::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } -// EOF diff --git a/src/actions/rs_actionlayerstoggleview.h b/src/actions/rs_actionlayerstoggleview.h index 56ded2c..202a769 100644 --- a/src/actions/rs_actionlayerstoggleview.h +++ b/src/actions/rs_actionlayerstoggleview.h @@ -1,52 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionlayerstoggleview.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONLAYERSTOGGLEVIEW_H #define RS_ACTIONLAYERSTOGGLEVIEW_H #include "rs_actioninterface.h" - /** * This action class can handle user events to edit layers. * * @author Andrew Mustun */ -class RS_ActionLayersToggleView : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionLayersToggleView(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionLayersToggleView() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - +class RS_ActionLayersToggleView: public RS_ActionInterface +{ + public: + RS_ActionLayersToggleView(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionLayersToggleView(); + + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionlibraryinsert.cpp b/src/actions/rs_actionlibraryinsert.cpp index e6881cd..4fdab2f 100644 --- a/src/actions/rs_actionlibraryinsert.cpp +++ b/src/actions/rs_actionlibraryinsert.cpp @@ -1,41 +1,28 @@ -/**************************************************************************** -** $Id: rs_actionlibraryinsert.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_actionlibraryinsert.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_actionlibraryinsert.h" -#include "commands.h" -#include "rs_creation.h" -#include "rs_modification.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" #include "rs_units.h" /** * Constructor. */ -RS_ActionLibraryInsert::RS_ActionLibraryInsert(RS_EntityContainer & container, - RS_GraphicView & graphicView): +RS_ActionLibraryInsert::RS_ActionLibraryInsert(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Library Insert", container, graphicView) { } @@ -44,14 +31,9 @@ RS_ActionLibraryInsert::~RS_ActionLibraryInsert() { } -QAction * RS_ActionLibraryInsert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +/*virtual*/ RS2::ActionType RS_ActionLibraryInsert::rtti() { - QAction * action = new QAction(tr("&Insert Library Object"), 0); -// QAction* action = new QAction(tr("Insert Library Object"), -// tr("&Insert Library Object"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Inserts an Object from the part library.")); - return action; + return RS2::ActionLibraryInsert; } void RS_ActionLibraryInsert::init(int status) @@ -60,13 +42,13 @@ void RS_ActionLibraryInsert::init(int status) reset(); - /*if (graphic!=NULL) { - block = graphic->getActiveBlock(); - if (block!=NULL) { - data.name = block->getName(); - } -}*/ - //trigger(); + /*if (graphic!=NULL) { + block = graphic->getActiveBlock(); + if (block!=NULL) { + data.name = block->getName(); + } + }*/ + //trigger(); } void RS_ActionLibraryInsert::setFile(const QString & file) @@ -79,14 +61,14 @@ void RS_ActionLibraryInsert::setFile(const QString & file) void RS_ActionLibraryInsert::reset() { - /*data = RS_InsertData("", - Vector(0.0,0.0), - Vector(1.0,1.0), - 0.0, - 1, 1, - Vector(1.0,1.0), - NULL, - RS2::Update);*/ + /*data = RS_InsertData("", + Vector(0.0,0.0), + Vector(1.0,1.0), + 0.0, + 1, 1, + Vector(1.0,1.0), + NULL, + RS2::Update);*/ data.insertionPoint = Vector(false); data.factor = 1.0; @@ -118,7 +100,8 @@ void RS_ActionLibraryInsert::mouseMoveEvent(QMouseEvent * e) preview->addAllFrom(prev); preview->move(data.insertionPoint); preview->scale(data.insertionPoint, - Vector(data.factor, data.factor)); + Vector(data.factor, data.factor)); + // unit conversion: if (graphic != NULL) { @@ -143,7 +126,7 @@ void RS_ActionLibraryInsert::mouseReleaseEvent(QMouseEvent * e) { if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) @@ -153,12 +136,12 @@ void RS_ActionLibraryInsert::mouseReleaseEvent(QMouseEvent * e) } } -void RS_ActionLibraryInsert::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionLibraryInsert::coordinateEvent(Vector * e) { if (e == NULL) return; - data.insertionPoint = e->getCoordinate(); + data.insertionPoint = *e; trigger(); } @@ -175,6 +158,7 @@ void RS_ActionLibraryInsert::commandEvent(RS_CommandEvent * e) switch (getStatus()) { case SetTargetPoint: + if (checkCommand("angle", c)) { deleteSnapper(); @@ -199,18 +183,14 @@ void RS_ActionLibraryInsert::commandEvent(RS_CommandEvent * e) double a = RS_Math::eval(c, &ok); if (ok == true) - { data.angle = RS_Math::deg2rad(a); - } else - { RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } RS_DIALOGFACTORY->requestOptions(this, true, true); setStatus(lastStatus); } - break; + break; case SetFactor: { @@ -218,18 +198,14 @@ void RS_ActionLibraryInsert::commandEvent(RS_CommandEvent * e) double f = RS_Math::eval(c, &ok); if (ok == true) - { setFactor(f); - } else - { RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } RS_DIALOGFACTORY->requestOptions(this, true, true); setStatus(lastStatus); } - break; + break; default: break; @@ -245,8 +221,8 @@ QStringList RS_ActionLibraryInsert::getAvailableCommands() case SetTargetPoint: cmd += command("angle"); cmd += command("factor"); - ; break; + default: break; } @@ -275,12 +251,15 @@ void RS_ActionLibraryInsert::updateMouseButtonHints() case SetTargetPoint: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel")); break; + case SetAngle: RS_DIALOGFACTORY->updateMouseWidget(tr("Enter angle:"), ""); break; + case SetFactor: RS_DIALOGFACTORY->updateMouseWidget(tr("Enter factor:"), ""); break; + default: RS_DIALOGFACTORY->updateMouseWidget("", ""); break; @@ -300,3 +279,23 @@ void RS_ActionLibraryInsert::updateToolBar() RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); } +double RS_ActionLibraryInsert::getAngle() +{ + return data.angle; +} + +void RS_ActionLibraryInsert::setAngle(double a) +{ + data.angle = a; +} + +double RS_ActionLibraryInsert::getFactor() +{ + return data.factor; +} + +void RS_ActionLibraryInsert::setFactor(double f) +{ + data.factor = f; +} + diff --git a/src/actions/rs_actionlibraryinsert.h b/src/actions/rs_actionlibraryinsert.h index fa8ec4e..c64f8db 100644 --- a/src/actions/rs_actionlibraryinsert.h +++ b/src/actions/rs_actionlibraryinsert.h @@ -1,148 +1,62 @@ -/**************************************************************************** -** $Id: rs_actionlibraryinsert.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONLIBRARYINSERT_H #define RS_ACTIONLIBRARYINSERT_H -#include "rs_previewactioninterface.h" - #include "rs_creation.h" -#include "rs_insert.h" +#include "drawing.h" +#include "rs_previewactioninterface.h" /** - * This action class can handle user events for inserting library items + * This action class can handle user events for inserting library items * (or any other DXF files) into the current drawing (as block/insert). * * @author Andrew Mustun */ -class RS_ActionLibraryInsert : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetTargetPoint, /**< Setting the reference point. */ - SetAngle, /**< Setting angle in the command line. */ - SetFactor /**< Setting factor in the command line. */ - //SetColumns, /**< Setting columns in the command line. */ - //SetRows, /**< Setting rows in the command line. */ - //SetColumnSpacing, /**< Setting column spacing in the command line. */ - //SetRowSpacing /**< Setting row spacing in the command line. */ - }; - -public: - RS_ActionLibraryInsert(RS_EntityContainer& container, - RS_GraphicView& graphicView); - virtual ~RS_ActionLibraryInsert(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionLibraryInsert; - } - - virtual void init(int status=0); - - void reset(); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void showOptions(); - virtual void hideOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - void setFile(const QString& file); - - double getAngle() { - return data.angle; - } - - void setAngle(double a) { - data.angle = a; - } - - double getFactor() { - return data.factor; - } - - void setFactor(double f) { - data.factor = f; - } - - /*int getColumns() { - return data.cols; - } - - void setColumns(int c) { - data.cols = c; - } - - int getRows() { - return data.rows; - } - - void setRows(int r) { - data.rows = r; - } - - double getColumnSpacing() { - return data.spacing.x; - } - - void setColumnSpacing(double cs) { - data.spacing.x = cs; - } - - double getRowSpacing() { - return data.spacing.y; - } - - void setRowSpacing(double rs) { - data.spacing.y = rs; - }*/ - -protected: - //RS_Block* block; - //RS_InsertData data; - Drawing prev; - RS_LibraryInsertData data; - - /** Last status before entering option. */ - Status lastStatus; +class RS_ActionLibraryInsert: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetTargetPoint, /**< Setting the reference point. */ + SetAngle, /**< Setting angle in the command line. */ + SetFactor /**< Setting factor in the command line. */ + //SetColumns, /**< Setting columns in the command line. */ + //SetRows, /**< Setting rows in the command line. */ + //SetColumnSpacing, /**< Setting column spacing in the command line. */ + //SetRowSpacing /**< Setting row spacing in the command line. */ + }; + + public: + RS_ActionLibraryInsert(RS_EntityContainer & container, RS_GraphicView & graphicView); + virtual ~RS_ActionLibraryInsert(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + void reset(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void showOptions(); + virtual void hideOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + void setFile(const QString & file); + double getAngle(); + void setAngle(double a); + double getFactor(); + void setFactor(double f); + + protected: + Drawing prev; + RS_LibraryInsertData data; + + /** Last status before entering option. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actionlockrelativezero.cpp b/src/actions/rs_actionlockrelativezero.cpp index 51bbaef..6f7f641 100644 --- a/src/actions/rs_actionlockrelativezero.cpp +++ b/src/actions/rs_actionlockrelativezero.cpp @@ -1,66 +1,41 @@ -/**************************************************************************** -** $Id: rs_actionlockrelativezero.cpp 1062 2004-01-16 21:51:20Z 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_actionlockrelativezero.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_actionlockrelativezero.h" -#include "rs_snapper.h" -#include "rs_point.h" - - +#include "rs_graphicview.h" RS_ActionLockRelativeZero::RS_ActionLockRelativeZero( - RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool on) - :RS_ActionInterface("(Un-)lock the relative Zero", - container, graphicView) { - - this->on = on; + RS_EntityContainer & container, RS_GraphicView & graphicView, bool on): + RS_ActionInterface("(Un-)lock the relative Zero", container, graphicView) +{ + this->on = on; } - -QAction* RS_ActionLockRelativeZero::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionLockRelativeZero::~RS_ActionLockRelativeZero() { - QAction * action = new QAction(tr("(Un-)&Lock Relative Zero"), 0); - action->setCheckable(true); -// QAction* action = new QAction(tr("(Un-)Lock Relative Zero"), -// tr("(Un-)&Lock Relative Zero"), -// QKeySequence(), NULL, 0, true); - action->setStatusTip(tr("(Un-)Lock relative Zero")); - return action; } -void RS_ActionLockRelativeZero::init(int status) { - RS_ActionInterface::init(status); - trigger(); - finish(); +void RS_ActionLockRelativeZero::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); + finish(); } -void RS_ActionLockRelativeZero::trigger() { - graphicView->lockRelativeZero(on); +void RS_ActionLockRelativeZero::trigger() +{ + graphicView->lockRelativeZero(on); } -// EOF diff --git a/src/actions/rs_actionlockrelativezero.h b/src/actions/rs_actionlockrelativezero.h index 9cd4782..146d654 100644 --- a/src/actions/rs_actionlockrelativezero.h +++ b/src/actions/rs_actionlockrelativezero.h @@ -1,35 +1,8 @@ -/**************************************************************************** -** $Id: rs_actionlockrelativezero.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONLOCKRELATIVEZERO_H #define RS_ACTIONLOCKRELATIVEZERO_H #include "rs_previewactioninterface.h" - /** * This action class can handle user events to lock or unlock * the relative Zero point. @@ -37,21 +10,17 @@ * * @author Ulf Lehnert */ -class RS_ActionLockRelativeZero : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionLockRelativeZero(RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool on); - ~RS_ActionLockRelativeZero() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionLockRelativeZero: public RS_ActionInterface +{ + public: + RS_ActionLockRelativeZero(RS_EntityContainer & container, RS_GraphicView & graphicView, bool on); + ~RS_ActionLockRelativeZero(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); -private: - bool on; + private: + bool on; }; #endif diff --git a/src/actions/rs_actionmodifyattributes.cpp b/src/actions/rs_actionmodifyattributes.cpp index b04de7e..50b54a6 100644 --- a/src/actions/rs_actionmodifyattributes.cpp +++ b/src/actions/rs_actionmodifyattributes.cpp @@ -1,116 +1,89 @@ -/**************************************************************************** -** $Id: rs_actionmodifyattributes.cpp 1062 2004-01-16 21:51:20Z 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_actionmodifyattributes.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_actionmodifyattributes.h" +#include "rs_dialogfactory.h" +#include "drawing.h" +#include "rs_graphicview.h" #include "rs_modification.h" -#include "rs_snapper.h" - - RS_ActionModifyAttributes::RS_ActionModifyAttributes( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Change Attributes", - container, graphicView) {} - - -QAction* RS_ActionModifyAttributes::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) + RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Change Attributes", container, graphicView) { - QAction * action = new QAction(tr("&Attributes"), 0); -// QAction* action = new QAction(tr("Attributes"), tr("&Attributes"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Modify Entity Attributes")); - - return action; } - -void RS_ActionModifyAttributes::init(int status) { - RS_ActionInterface::init(status); - - trigger(); +RS_ActionModifyAttributes::~RS_ActionModifyAttributes() +{ } - - -void RS_ActionModifyAttributes::trigger() { - - RS_DEBUG->print("RS_ActionModifyAttributes::trigger()"); - - RS_AttributesData data; - data.pen = RS_Pen(); - data.layer = "0"; - data.changeColor = false; - data.changeLineType = false; - data.changeWidth = false; - data.changeLayer = false; - - if (graphic!=NULL) { - if (RS_DIALOGFACTORY->requestAttributesDialog(data, - *graphic->getLayerList())) { - RS_Modification m(*container, graphicView); - m.changeAttributes(data); - } - } - - finish(); - graphicView->killSelectActions(); - - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); +void RS_ActionModifyAttributes::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } - - -void RS_ActionModifyAttributes::updateMouseButtonHints() { - switch (getStatus()) { - //case Acknowledge: - //RS_DIALOGFACTORY->updateMouseWidget(tr("Acknowledge"), tr("Cancel")); - //break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyAttributes::trigger() +{ + RS_DEBUG->print("RS_ActionModifyAttributes::trigger()"); + + RS_AttributesData data; + data.pen = RS_Pen(); + data.layer = "0"; + data.changeColor = false; + data.changeLineType = false; + data.changeWidth = false; + data.changeLayer = false; + + if (graphic != NULL) + if (RS_DIALOGFACTORY->requestAttributesDialog(data, + *graphic->getLayerList())) + { + RS_Modification m(*container, graphicView); + m.changeAttributes(data); + } + + finish(); + graphicView->killSelectActions(); + + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } - - -void RS_ActionModifyAttributes::updateMouseCursor() { - graphicView->setMouseCursor(RS2::DelCursor); +void RS_ActionModifyAttributes::updateMouseButtonHints() +{ + switch (getStatus()) + { + //case Acknowledge: + //RS_DIALOGFACTORY->updateMouseWidget(tr("Acknowledge"), tr("Cancel")); + //break; + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyAttributes::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } +void RS_ActionModifyAttributes::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::DelCursor); } +void RS_ActionModifyAttributes::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); +} -// EOF diff --git a/src/actions/rs_actionmodifyattributes.h b/src/actions/rs_actionmodifyattributes.h index 2f62ba6..af0858d 100644 --- a/src/actions/rs_actionmodifyattributes.h +++ b/src/actions/rs_actionmodifyattributes.h @@ -1,63 +1,33 @@ -/**************************************************************************** -** $Id: rs_actionmodifyattributes.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYATTRIBUTES_H #define RS_ACTIONMODIFYATTRIBUTES_H #include "rs_actioninterface.h" - /** * This action class can handle user events to change the attributes of * entities. * * @author Andrew Mustun */ -class RS_ActionModifyAttributes : public RS_ActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - Acknowledge /**< Acknowledge or cancel. */ - }; +class RS_ActionModifyAttributes: public RS_ActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + Acknowledge /**< Acknowledge or cancel. */ + }; -public: - RS_ActionModifyAttributes(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyAttributes() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); + public: + RS_ActionModifyAttributes(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyAttributes(); - virtual void init(int status=0); - virtual void trigger(); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); }; #endif diff --git a/src/actions/rs_actionmodifybevel.cpp b/src/actions/rs_actionmodifybevel.cpp index a16beff..34fce8d 100644 --- a/src/actions/rs_actionmodifybevel.cpp +++ b/src/actions/rs_actionmodifybevel.cpp @@ -1,298 +1,322 @@ -/**************************************************************************** -** $Id: rs_actionmodifybevel.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_actionmodifybevel.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_actionmodifybevel.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" #include "rs_information.h" - -RS_ActionModifyBevel::RS_ActionModifyBevel(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Bevel Entities", - container, graphicView) { - - entity1 = NULL; - coord1 = Vector(false); - entity2 = NULL; - coord2 = Vector(false); +RS_ActionModifyBevel::RS_ActionModifyBevel(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Bevel Entities", + container, graphicView) +{ + entity1 = NULL; + coord1 = Vector(false); + entity2 = NULL; + coord2 = Vector(false); } - -QAction* RS_ActionModifyBevel::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyBevel::~RS_ActionModifyBevel() { - QAction * action = new QAction(tr("&Bevel"), 0); -// QAction* action = new QAction(tr("Bevel"), tr("&Bevel"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Bevel Entities")); - return action; } +/*virtual*/ RS2::ActionType RS_ActionModifyBevel::rtti() +{ + return RS2::ActionModifyBevel; +} -void RS_ActionModifyBevel::init(int status) { - RS_ActionInterface::init(status); +void RS_ActionModifyBevel::init(int status) +{ + RS_ActionInterface::init(status); - snapMode = RS2::SnapFree; - snapRes = RS2::RestrictNothing; + snapMode = RS2::SnapFree; + snapRes = RS2::RestrictNothing; } +void RS_ActionModifyBevel::trigger() +{ + RS_DEBUG->print("RS_ActionModifyBevel::trigger()"); + + if (entity1 != NULL && entity1->isAtomic() + && entity2 != NULL && entity2->isAtomic()) + { + RS_Modification m(*container, graphicView); + m.bevel(coord1, (RS_AtomicEntity *)entity1, + coord2, (RS_AtomicEntity *)entity2, + data); + + entity1 = NULL; + entity2 = NULL; + setStatus(SetEntity1); + + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } +} +void RS_ActionModifyBevel::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent begin"); -void RS_ActionModifyBevel::trigger() { + Vector mouse = graphicView->toGraph(e->x(), e->y()); + RS_Entity * se = catchEntity(e, RS2::ResolveAll); - RS_DEBUG->print("RS_ActionModifyBevel::trigger()"); + switch (getStatus()) + { + case SetEntity1: + coord1 = mouse; + entity1 = se; + break; - if (entity1!=NULL && entity1->isAtomic() && - entity2!=NULL && entity2->isAtomic()) { + case SetEntity2: - RS_Modification m(*container, graphicView); - m.bevel(coord1, (RS_AtomicEntity*)entity1, - coord2, (RS_AtomicEntity*)entity2, - data); + if (entity1 != NULL && RS_Information::isTrimmable(entity1)) + { + coord2 = mouse; + entity2 = se; + } + break; - entity1 = NULL; - entity2 = NULL; - setStatus(SetEntity1); + default: + break; + } - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } + RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent end"); } +void RS_ActionModifyBevel::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case SetEntity1: + if (entity1 != NULL && entity1->isAtomic()) + setStatus(SetEntity2); + break; -void RS_ActionModifyBevel::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent begin"); - - Vector mouse = graphicView->toGraph(e->x(), e->y()); - RS_Entity* se = catchEntity(e, RS2::ResolveAll); + case SetEntity2: - switch (getStatus()) { - case SetEntity1: - coord1 = mouse; - entity1 = se; - break; + if (entity2 != NULL && entity2->isAtomic() + && RS_Information::isTrimmable(entity1, entity2)) + trigger(); + break; - case SetEntity2: - if (entity1!=NULL && RS_Information::isTrimmable(entity1)) { - coord2 = mouse; - entity2 = se; + default: + break; } - break; - - default: - break; - } - - RS_DEBUG->print("RS_ActionModifyBevel::mouseMoveEvent end"); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionModifyBevel::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetEntity1: - if (entity1!=NULL && entity1->isAtomic()) { - setStatus(SetEntity2); - } - break; - - case SetEntity2: - if (entity2!=NULL && entity2->isAtomic() && - RS_Information::isTrimmable(entity1, entity2)) { - trigger(); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionModifyBevel::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + switch (getStatus()) + { + case SetEntity1: + case SetEntity2: + + if (checkCommand("length1", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetLength1); + } + else if (checkCommand("length2", c)) + { + deleteSnapper(); + deletePreview(); + clearPreview(); + lastStatus = (Status)getStatus(); + setStatus(SetLength2); + } + else if (checkCommand("trim", c)) + { + //deleteSnapper(); + //deletePreview(); + //clearPreview(); + //lastStatus = (Status)getStatus(); + //setStatus(SetTrim); + data.trim = !data.trim; + RS_DIALOGFACTORY->requestOptions(this, true, true); + } + break; + + case SetLength1: { + bool ok; + double l = RS_Math::eval(c, &ok); + + if (ok == true) + data.length1 = l; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + case SetLength2: { + bool ok; + double l = RS_Math::eval(c, &ok); + + if (ok == true) + data.length2 = l; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; + + /*case SetTrim: { + if (checkCommand()) { + 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; + } } - - -void RS_ActionModifyBevel::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - switch (getStatus()) { - case SetEntity1: - case SetEntity2: - if (checkCommand("length1", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetLength1); - } else if (checkCommand("length2", c)) { - deleteSnapper(); - deletePreview(); - clearPreview(); - lastStatus = (Status)getStatus(); - setStatus(SetLength2); - } else if (checkCommand("trim", c)) { - //deleteSnapper(); - //deletePreview(); - //clearPreview(); - //lastStatus = (Status)getStatus(); - //setStatus(SetTrim); - data.trim = !data.trim; - RS_DIALOGFACTORY->requestOptions(this, true, true); - } - break; - - case SetLength1: { - bool ok; - double l = RS_Math::eval(c, &ok); - if (ok==true) { - data.length1 = l; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - case SetLength2: { - bool ok; - double l = RS_Math::eval(c, &ok); - if (ok==true) { - data.length2 = l; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; - - /*case SetTrim: { - if (checkCommand()) { - 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_ActionModifyBevel::getAvailableCommands() +{ + QStringList cmd; + + switch (getStatus()) + { + case SetEntity1: + case SetEntity2: + cmd += command("length1"); + cmd += command("length2"); + cmd += command("trim"); + break; + + default: + break; + } + return cmd; } +void RS_ActionModifyBevel::showOptions() +{ + RS_ActionInterface::showOptions(); - -QStringList RS_ActionModifyBevel::getAvailableCommands() { - QStringList cmd; - switch (getStatus()) { - case SetEntity1: - case SetEntity2: - cmd += command("length1"); - cmd += command("length2"); - cmd += command("trim"); - break; - default: - break; - } - return cmd; + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionModifyBevel::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionModifyBevel::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); + RS_DIALOGFACTORY->requestOptions(this, false); } - - -void RS_ActionModifyBevel::hideOptions() { - RS_ActionInterface::hideOptions(); - - RS_DIALOGFACTORY->requestOptions(this, false); +void RS_ActionModifyBevel::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetEntity1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"), + tr("Cancel")); + break; + + case SetEntity2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"), + tr("Back")); + break; + + case SetLength1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 1:"), + tr("Back")); + break; + + case SetLength2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 2:"), + tr("Back")); + break; + + /*case SetTrim: + RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"), + ""); + break;*/ + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyBevel::updateMouseButtonHints() { - switch (getStatus()) { - case SetEntity1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"), - tr("Cancel")); - break; - case SetEntity2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"), - tr("Back")); - break; - case SetLength1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 1:"), - tr("Back")); - break; - case SetLength2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter length 2:"), - tr("Back")); - break; - /*case SetTrim: - RS_DIALOGFACTORY->updateMouseWidget(tr("Trim on? (yes/no):"), - ""); - break;*/ - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyBevel::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionModifyBevel::updateToolBar() +{ + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); +} +void RS_ActionModifyBevel::setLength1(double l1) +{ + data.length1 = l1; +} -void RS_ActionModifyBevel::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +double RS_ActionModifyBevel::getLength1() +{ + return data.length1; } +void RS_ActionModifyBevel::setLength2(double l2) +{ + data.length2 = l2; +} +double RS_ActionModifyBevel::getLength2() +{ + return data.length2; +} -void RS_ActionModifyBevel::updateToolBar() { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); +void RS_ActionModifyBevel::setTrim(bool t) +{ + data.trim = t; } +bool RS_ActionModifyBevel::isTrimOn() +{ + return data.trim; +} -// EOF diff --git a/src/actions/rs_actionmodifybevel.h b/src/actions/rs_actionmodifybevel.h index e02b79b..8a6d05e 100644 --- a/src/actions/rs_actionmodifybevel.h +++ b/src/actions/rs_actionmodifybevel.h @@ -1,114 +1,59 @@ -/**************************************************************************** -** $Id: rs_actionmodifybevel.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYBEVEL_H #define RS_ACTIONMODIFYBEVEL_H #include "rs_previewactioninterface.h" #include "rs_modification.h" - /** * This action class can handle user events to bevel corners. * * @author Andrew Mustun */ -class RS_ActionModifyBevel : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetEntity1, /**< Choosing the 1st entity. */ - SetEntity2, /**< Choosing the 2nd entity. */ - SetLength1, /**< Setting length 1 in command line. */ - SetLength2 /**< Setting length 2 in command line. */ - //SetTrim /**< Setting trim flag in command line. */ - }; - -public: - RS_ActionModifyBevel(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyBevel() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionModifyBevel; - } - - virtual void init(int status=0); - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - void setLength1(double l1) { - data.length1 = l1; - } - - double getLength1() { - return data.length1; - } - - void setLength2(double l2) { - data.length2 = l2; - } - - double getLength2() { - return data.length2; - } - - void setTrim(bool t) { - data.trim = t; - } - - bool isTrimOn() { - return data.trim; - } - -private: - RS_Entity* entity1; - Vector coord1; - RS_Entity* entity2; - Vector coord2; - RS_BevelData data; - /** Last status before entering angle. */ - Status lastStatus; +class RS_ActionModifyBevel: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetEntity1, /**< Choosing the 1st entity. */ + SetEntity2, /**< Choosing the 2nd entity. */ + SetLength1, /**< Setting length 1 in command line. */ + SetLength2 /**< Setting length 2 in command line. */ + //SetTrim /**< Setting trim flag in command line. */ + }; + + public: + RS_ActionModifyBevel(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyBevel(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + void setLength1(double l1); + double getLength1(); + void setLength2(double l2); + double getLength2(); + void setTrim(bool t); + bool isTrimOn(); + + private: + RS_Entity * entity1; + Vector coord1; + RS_Entity * entity2; + Vector coord2; + RS_BevelData data; + /** Last status before entering angle. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actionmodifycut.cpp b/src/actions/rs_actionmodifycut.cpp index dc762a2..54c7214 100644 --- a/src/actions/rs_actionmodifycut.cpp +++ b/src/actions/rs_actionmodifycut.cpp @@ -1,189 +1,177 @@ -/**************************************************************************** -** $Id: rs_actionmodifycut.cpp 2420 2005-07-01 16:47:35Z 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_actionmodifycut.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_actionmodifycut.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_modification.h" - -RS_ActionModifyCut::RS_ActionModifyCut(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Cut Entity", - container, graphicView) { - - cutEntity = NULL; - cutCoord = Vector(false); +RS_ActionModifyCut::RS_ActionModifyCut(RS_EntityContainer & container, + RS_GraphicView & graphicView): RS_ActionInterface("Cut Entity", + container, graphicView) +{ + cutEntity = NULL; + cutCoord = Vector(false); } -QAction* RS_ActionModifyCut::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyCut::~RS_ActionModifyCut() { - QAction * action = new QAction(tr("&Divide"), 0); -// QAction* action = new QAction(tr("Divide"), tr("&Divide"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Cut Entities")); - return action; } - void RS_ActionModifyCut::init(int status) { - RS_ActionInterface::init(status); + RS_ActionInterface::init(status); } +void RS_ActionModifyCut::trigger() +{ + RS_DEBUG->print("RS_ActionModifyCut::trigger()"); + if (cutEntity != NULL && cutEntity->isAtomic() && cutCoord.valid + && cutEntity->isPointOnEntity(cutCoord)) + { + cutEntity->setHighlighted(false); + graphicView->drawEntity(cutEntity); -void RS_ActionModifyCut::trigger() { - - RS_DEBUG->print("RS_ActionModifyCut::trigger()"); - - if (cutEntity!=NULL && cutEntity->isAtomic() && cutCoord.valid && - cutEntity->isPointOnEntity(cutCoord)) { - - cutEntity->setHighlighted(false); - graphicView->drawEntity(cutEntity); - - RS_Modification m(*container, graphicView); - m.cut(cutCoord, (RS_AtomicEntity*)cutEntity); + RS_Modification m(*container, graphicView); + m.cut(cutCoord, (RS_AtomicEntity *)cutEntity); - cutEntity = NULL; - cutCoord = Vector(false); - setStatus(ChooseCutEntity); + cutEntity = NULL; + cutCoord = Vector(false); + setStatus(ChooseCutEntity); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } } +void RS_ActionModifyCut::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyCut::mouseMoveEvent begin"); + switch (getStatus()) + { + case ChooseCutEntity: + break; -void RS_ActionModifyCut::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyCut::mouseMoveEvent begin"); - - switch (getStatus()) { - case ChooseCutEntity: - break; - - case SetCutCoord: - snapPoint(e); - break; + case SetCutCoord: + snapPoint(e); + break; - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end"); } - -void RS_ActionModifyCut::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case ChooseCutEntity: - cutEntity = catchEntity(e); - if (cutEntity==NULL) { - RS_DIALOGFACTORY->commandMessage(tr("No Entity found.")); - } else if (cutEntity->rtti()!=RS2::EntityLine && - cutEntity->rtti()!=RS2::EntityArc && - cutEntity->rtti()!=RS2::EntityCircle && - cutEntity->rtti()!=RS2::EntityEllipse) { - - RS_DIALOGFACTORY->commandMessage( - tr("Entity must be a line, arc, circle or ellipse.")); - } else { - cutEntity->setHighlighted(true); - graphicView->drawEntity(cutEntity); - setStatus(SetCutCoord); - } - break; - - case SetCutCoord: - cutCoord = snapPoint(e); - if (cutEntity==NULL) { - RS_DIALOGFACTORY->commandMessage(tr("No Entity found.")); - } else if (!cutCoord.valid) { - RS_DIALOGFACTORY->commandMessage(tr("Cutting point is invalid.")); - } else if (!cutEntity->isPointOnEntity(cutCoord)) { - RS_DIALOGFACTORY->commandMessage( - tr("Cutting point is not on entity.")); - } else { - deleteSnapper(); - trigger(); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deleteSnapper(); - if (cutEntity!=NULL) { - cutEntity->setHighlighted(false); - graphicView->drawEntity(cutEntity); - } - init(getStatus()-1); - } +void RS_ActionModifyCut::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case ChooseCutEntity: + cutEntity = catchEntity(e); + + if (cutEntity == NULL) + RS_DIALOGFACTORY->commandMessage(tr("No Entity found.")); + else if (cutEntity->rtti() != RS2::EntityLine + && cutEntity->rtti() != RS2::EntityArc + && cutEntity->rtti() != RS2::EntityCircle + && cutEntity->rtti() != RS2::EntityEllipse) + + RS_DIALOGFACTORY->commandMessage( + tr("Entity must be a line, arc, circle or ellipse.")); + else + { + cutEntity->setHighlighted(true); + graphicView->drawEntity(cutEntity); + setStatus(SetCutCoord); + } + break; + + case SetCutCoord: + cutCoord = snapPoint(e); + + if (cutEntity == NULL) + RS_DIALOGFACTORY->commandMessage(tr("No Entity found.")); + else if (!cutCoord.valid) + RS_DIALOGFACTORY->commandMessage(tr("Cutting point is invalid.")); + else if (!cutEntity->isPointOnEntity(cutCoord)) + RS_DIALOGFACTORY->commandMessage( + tr("Cutting point is not on entity.")); + else + { + deleteSnapper(); + trigger(); + } + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deleteSnapper(); + + if (cutEntity != NULL) + { + cutEntity->setHighlighted(false); + graphicView->drawEntity(cutEntity); + } + init(getStatus() - 1); + } } - - -void RS_ActionModifyCut::updateMouseButtonHints() { - switch (getStatus()) { - case ChooseCutEntity: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify entity to cut"), - tr("Cancel")); - break; - case SetCutCoord: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify cutting point"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyCut::updateMouseButtonHints() +{ + switch (getStatus()) + { + case ChooseCutEntity: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify entity to cut"), + tr("Cancel")); + break; + + case SetCutCoord: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify cutting point"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyCut::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionModifyCut::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionModifyCut::updateToolBar() { - - switch (getStatus()) { - case SetCutCoord: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - case ChooseCutEntity: - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - break; - } +void RS_ActionModifyCut::updateToolBar() +{ + switch (getStatus()) + { + case SetCutCoord: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + case ChooseCutEntity: + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); + break; + } } - - -// EOF diff --git a/src/actions/rs_actionmodifycut.h b/src/actions/rs_actionmodifycut.h index e54f460..041f3be 100644 --- a/src/actions/rs_actionmodifycut.h +++ b/src/actions/rs_actionmodifycut.h @@ -1,70 +1,42 @@ -/**************************************************************************** -** $Id: rs_actionmodifycut.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYCUT_H #define RS_ACTIONMODIFYCUT_H #include "rs_actioninterface.h" -#include "rs_modification.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to divide entities. * * @author Andrew Mustun */ -class RS_ActionModifyCut : public RS_ActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - ChooseCutEntity, /**< Choosing the entity to cut in two. */ - SetCutCoord /**< Choosing the cutting point. */ - }; - -public: - RS_ActionModifyCut(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyCut() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_Entity* cutEntity; - Vector cutCoord; +class RS_ActionModifyCut: public RS_ActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + ChooseCutEntity, /**< Choosing the entity to cut in two. */ + SetCutCoord /**< Choosing the cutting point. */ + }; + + public: + RS_ActionModifyCut(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyCut(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_Entity * cutEntity; + Vector cutCoord; }; #endif diff --git a/src/actions/rs_actionmodifydelete.cpp b/src/actions/rs_actionmodifydelete.cpp index bae0196..15668e7 100644 --- a/src/actions/rs_actionmodifydelete.cpp +++ b/src/actions/rs_actionmodifydelete.cpp @@ -1,108 +1,80 @@ -/**************************************************************************** -** $Id: rs_actionmodifydelete.cpp 1062 2004-01-16 21:51:20Z 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_actionmodifydelete.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_actionmodifydelete.h" -#include "rs_actionselectsingle.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" #include "rs_modification.h" -#include "rs_snapper.h" -#include "rs_point.h" - - -RS_ActionModifyDelete::RS_ActionModifyDelete(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Delete Entities", - container, graphicView) {} - -QAction* RS_ActionModifyDelete::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyDelete::RS_ActionModifyDelete(RS_EntityContainer & container, + RS_GraphicView & graphicView): RS_ActionInterface("Delete Entities", + container, graphicView) { - QAction * action = new QAction(tr("&Delete"), 0); -// QAction* action = new QAction(tr("Delete"), tr("&Delete"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Delete Entities")); - return action; } - -void RS_ActionModifyDelete::init(int status) { - RS_ActionInterface::init(status); - - trigger(); +RS_ActionModifyDelete::~RS_ActionModifyDelete() +{ } - - -void RS_ActionModifyDelete::trigger() { - - RS_DEBUG->print("RS_ActionModifyDelete::trigger()"); - - RS_Modification m(*container, graphicView); - m.remove(); - - finish(); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } +void RS_ActionModifyDelete::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); } +void RS_ActionModifyDelete::trigger() +{ + RS_DEBUG->print("RS_ActionModifyDelete::trigger()"); + RS_Modification m(*container, graphicView); + m.remove(); + finish(); - -void RS_ActionModifyDelete::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - //case Acknowledge: - // RS_DIALOGFACTORY->updateMouseWidget(tr("Acknowledge"), - // tr("Cancel")); - // break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } - - -void RS_ActionModifyDelete::updateMouseCursor() { - graphicView->setMouseCursor(RS2::DelCursor); +void RS_ActionModifyDelete::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + //case Acknowledge: + // RS_DIALOGFACTORY->updateMouseWidget(tr("Acknowledge"), + // tr("Cancel")); + // break; + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } - - -void RS_ActionModifyDelete::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); - } - } +void RS_ActionModifyDelete::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::DelCursor); } +void RS_ActionModifyDelete::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); + } +} -// EOF diff --git a/src/actions/rs_actionmodifydelete.h b/src/actions/rs_actionmodifydelete.h index a25b3b7..dafa14c 100644 --- a/src/actions/rs_actionmodifydelete.h +++ b/src/actions/rs_actionmodifydelete.h @@ -1,62 +1,32 @@ -/**************************************************************************** -** $Id: rs_actionmodifydelete.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYDELETE_H #define RS_ACTIONMODIFYDELETE_H #include "rs_actioninterface.h" - /** * This action class can handle user events to delete entities. * * @author Andrew Mustun */ -class RS_ActionModifyDelete : public RS_ActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - Acknowledge /**< Acknowledge or cancel. */ - }; - -public: - RS_ActionModifyDelete(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyDelete() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); +class RS_ActionModifyDelete: public RS_ActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + Acknowledge /**< Acknowledge or cancel. */ + }; + + public: + RS_ActionModifyDelete(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyDelete(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); }; #endif diff --git a/src/actions/rs_actionmodifydeletefree.cpp b/src/actions/rs_actionmodifydeletefree.cpp index 8d2275c..e7715ae 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 "rs_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, RS_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 (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::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 diff --git a/src/actions/rs_actionmodifydeletefree.h b/src/actions/rs_actionmodifydeletefree.h index 4a6d941..c7fd4fe 100644 --- a/src/actions/rs_actionmodifydeletefree.h +++ b/src/actions/rs_actionmodifydeletefree.h @@ -1,60 +1,34 @@ -/**************************************************************************** -** $Id: rs_actionmodifydeletefree.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYDELETEFREE_H #define RS_ACTIONMODIFYDELETEFREE_H #include "rs_actioninterface.h" +#include "vector.h" +class RS_Entity; +class RS_Polyline; /** * This action class can handle user events to delete entities. * * @author Andrew Mustun */ -class RS_ActionModifyDeleteFree : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionModifyDeleteFree(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyDeleteFree() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - -private: - RS_Polyline* polyline; - RS_Entity* e1; - Vector v1; - RS_Entity* e2; - Vector v2; +class RS_ActionModifyDeleteFree: public RS_ActionInterface +{ + public: + RS_ActionModifyDeleteFree(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyDeleteFree(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + + private: + RS_Polyline * polyline; + RS_Entity * e1; + Vector v1; + RS_Entity * e2; + Vector v2; }; #endif diff --git a/src/actions/rs_actionmodifydeletequick.cpp b/src/actions/rs_actionmodifydeletequick.cpp index 1ffb127..89f001b 100644 --- a/src/actions/rs_actionmodifydeletequick.cpp +++ b/src/actions/rs_actionmodifydeletequick.cpp @@ -1,55 +1,31 @@ -/**************************************************************************** -** $Id: rs_actionmodifydeletequick.cpp 1144 2004-08-18 17:07:54Z 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_actionmodifydeletequick.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_actionmodifydeletequick.h" -#include "rs_actionselectsingle.h" -#include "rs_snapper.h" -#include "rs_point.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" RS_ActionModifyDeleteQuick::RS_ActionModifyDeleteQuick( - RS_EntityContainer& container, RS_GraphicView& graphicView): + RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Quick Delete Entities", container, graphicView) { - en = NULL; + en = NULL; } -QAction * RS_ActionModifyDeleteQuick::createGUIAction(RS2::ActionType /*type*/, QObject * parent) +RS_ActionModifyDeleteQuick::~RS_ActionModifyDeleteQuick() { - QAction * action = new QAction(tr("&Delete selected"), parent); -#ifdef __APPLE__ - action->setShortcut(Qt::Key_Backspace); -#else - action->setShortcut(Qt::Key_Delete); -#endif -// QAction* action = new QAction(tr("Delete selected"), -// tr("&Delete selected"), -// s, parent); - action->setStatusTip(tr("Delete selected entities")); - return action; } /** @@ -57,60 +33,63 @@ QAction * RS_ActionModifyDeleteQuick::createGUIAction(RS2::ActionType /*type*/, */ void RS_ActionModifyDeleteQuick::trigger() { - RS_DEBUG->print("RS_ActionModifyDeleteQuick::trigger()"); + RS_DEBUG->print("RS_ActionModifyDeleteQuick::trigger()"); - if (en!=NULL) + if (en != NULL) { - RS_DEBUG->print("Entity found"); - RS_EntityContainer* parent = en->getParent(); - if (parent!=NULL) { - en->setSelected(false); - graphicView->deleteEntity(en); - en->changeUndoState(); - - if (document) { - document->startUndoCycle(); - document->addUndoable(en); - document->endUndoCycle(); - } - } - - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } else { - RS_DEBUG->print("RS_ActionModifyDeleteQuick::mousePressEvent:" - " Entity is NULL\n"); - } + RS_DEBUG->print("Entity found"); + RS_EntityContainer * parent = en->getParent(); + + if (parent != NULL) + { + en->setSelected(false); + graphicView->deleteEntity(en); + en->changeUndoState(); + + if (document) + { + document->startUndoCycle(); + document->addUndoable(en); + document->endUndoCycle(); + } + } + + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } + else + RS_DEBUG->print("RS_ActionModifyDeleteQuick::mousePressEvent:" + " Entity is NULL\n"); } - - -void RS_ActionModifyDeleteQuick::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - init(getStatus()-1); - } else { - en = catchEntity(e); - trigger(); - } +void RS_ActionModifyDeleteQuick::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + init(getStatus() - 1); + else + { + en = catchEntity(e); + trigger(); + } } - - -void RS_ActionModifyDeleteQuick::updateMouseButtonHints() { - switch (getStatus()) { - case 0: - RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entity to delete"), - tr("Cancel")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyDeleteQuick::updateMouseButtonHints() +{ + switch (getStatus()) + { + case 0: + RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entity to delete"), + tr("Cancel")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyDeleteQuick::updateMouseCursor() { - graphicView->setMouseCursor(RS2::DelCursor); +void RS_ActionModifyDeleteQuick::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::DelCursor); } // EOF diff --git a/src/actions/rs_actionmodifydeletequick.h b/src/actions/rs_actionmodifydeletequick.h index 6f6b819..25b732d 100644 --- a/src/actions/rs_actionmodifydeletequick.h +++ b/src/actions/rs_actionmodifydeletequick.h @@ -1,34 +1,9 @@ -/**************************************************************************** -** $Id: rs_actionmodifydeletequick.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYDELETEQUICK_H #define RS_ACTIONMODIFYDELETEQUICK_H #include "rs_actioninterface.h" +class RS_Entity; /** * This action class can handle user events to delete entities @@ -36,22 +11,19 @@ * * @author Andrew Mustun */ -class RS_ActionModifyDeleteQuick : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionModifyDeleteQuick(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyDeleteQuick() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* parent); - - virtual void trigger(); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - -private: - RS_Entity* en; +class RS_ActionModifyDeleteQuick: public RS_ActionInterface +{ + public: + RS_ActionModifyDeleteQuick(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyDeleteQuick(); + + virtual void trigger(); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + + private: + RS_Entity * en; }; #endif diff --git a/src/actions/rs_actionmodifyentity.cpp b/src/actions/rs_actionmodifyentity.cpp index 74912ab..0513046 100644 --- a/src/actions/rs_actionmodifyentity.cpp +++ b/src/actions/rs_actionmodifyentity.cpp @@ -1,99 +1,83 @@ -/**************************************************************************** -** $Id: rs_actionmodifyentity.cpp 1149 2004-09-19 11:06:35Z 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_actionmodifyentity.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_actionmodifyentity.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" - - -RS_ActionModifyEntity::RS_ActionModifyEntity(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Modify Entity", container, graphicView) { - - en = NULL; +RS_ActionModifyEntity::RS_ActionModifyEntity(RS_EntityContainer & container, + RS_GraphicView & graphicView): + RS_ActionInterface("Modify Entity", container, graphicView) +{ + en = NULL; } - -QAction* RS_ActionModifyEntity::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyEntity::~RS_ActionModifyEntity() { - QAction * action = new QAction(tr("&Properties"), 0); -// QAction* action = new QAction(tr("Properties"), tr("&Properties"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Modify Entity Properties")); - return action; } void RS_ActionModifyEntity::trigger() { - if (en!=NULL) { - RS_Entity* clone = en->clone(); - if (RS_DIALOGFACTORY->requestModifyEntityDialog(clone)) { - container->addEntity(clone); + if (en != NULL) + { + RS_Entity * clone = en->clone(); + + if (RS_DIALOGFACTORY->requestModifyEntityDialog(clone)) + { + container->addEntity(clone); - graphicView->deleteEntity(en); + graphicView->deleteEntity(en); en->setSelected(false); clone->setSelected(false); - graphicView->drawEntity(clone); - - if (document!=NULL) { - document->startUndoCycle(); - - document->addUndoable(clone); - en->setUndoState(true); - document->addUndoable(en); - - document->endUndoCycle(); - } - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } else { - delete clone; - } - - } else { - RS_DEBUG->print("RS_ActionModifyEntity::trigger: Entity is NULL\n"); - } + graphicView->drawEntity(clone); + + if (document != NULL) + { + document->startUndoCycle(); + + document->addUndoable(clone); + en->setUndoState(true); + document->addUndoable(en); + + document->endUndoCycle(); + } + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } + else + delete clone; + + } + else + RS_DEBUG->print("RS_ActionModifyEntity::trigger: Entity is NULL\n"); } - - -void RS_ActionModifyEntity::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - init(getStatus()-1); - } else { - en = catchEntity(e); - trigger(); - } +void RS_ActionModifyEntity::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + init(getStatus() - 1); + else + { + en = catchEntity(e); + trigger(); + } } - - -void RS_ActionModifyEntity::updateMouseCursor() { - graphicView->setMouseCursor(RS2::SelectCursor); +void RS_ActionModifyEntity::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::SelectCursor); } // EOF diff --git a/src/actions/rs_actionmodifyentity.h b/src/actions/rs_actionmodifyentity.h index 323f9df..f790bc4 100644 --- a/src/actions/rs_actionmodifyentity.h +++ b/src/actions/rs_actionmodifyentity.h @@ -1,55 +1,28 @@ -/**************************************************************************** -** $Id: rs_actionmodifyentity.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYENTITY_H #define RS_ACTIONMODIFYENTITY_H #include "rs_actioninterface.h" +class RS_Entity; /** * This action class can handle user events to select entities. * * @author Andrew Mustun */ -class RS_ActionModifyEntity : public RS_ActionInterface { +class RS_ActionModifyEntity: public RS_ActionInterface +{ //Q_OBJECT -public: - RS_ActionModifyEntity(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyEntity() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); + public: + RS_ActionModifyEntity(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyEntity(); - virtual void trigger(); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseCursor(); + virtual void trigger(); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseCursor(); -private: - RS_Entity* en; + private: + RS_Entity * en; }; #endif diff --git a/src/actions/rs_actionmodifyexplodetext.cpp b/src/actions/rs_actionmodifyexplodetext.cpp index bfe7af7..a5037a2 100644 --- a/src/actions/rs_actionmodifyexplodetext.cpp +++ b/src/actions/rs_actionmodifyexplodetext.cpp @@ -1,28 +1,16 @@ -/**************************************************************************** -** $Id: rs_actionmodifyexplodetext.cpp 1077 2004-03-03 19:06:45Z 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_actionmodifyexplodetext.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_actionmodifyexplodetext.h" @@ -31,41 +19,31 @@ /** * Constructor. */ -RS_ActionModifyExplodeText::RS_ActionModifyExplodeText(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Blocks Explode", - container, graphicView) { +RS_ActionModifyExplodeText::RS_ActionModifyExplodeText(RS_EntityContainer & container, + RS_GraphicView & graphicView): RS_PreviewActionInterface("Blocks Explode", + container, graphicView) +{ } - - -RS_ActionModifyExplodeText::~RS_ActionModifyExplodeText() {} - - -QAction* RS_ActionModifyExplodeText::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyExplodeText::~RS_ActionModifyExplodeText() { - QAction * action = new QAction(tr("&Explode Text into Letters"), 0); -// QAction* action = new QAction(tr("Explode Text"), -// tr("&Explode Text into Letters"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Explodes Text Entities into single Letters")); - return action; } - -void RS_ActionModifyExplodeText::init(int status) { - RS_PreviewActionInterface::init(status); - - trigger(); - finish(); +/*virtual*/ RS2::ActionType RS_ActionModifyExplodeText::rtti() +{ + return RS2::ActionModifyExplodeText; } +void RS_ActionModifyExplodeText::init(int status) +{ + RS_PreviewActionInterface::init(status); - -void RS_ActionModifyExplodeText::trigger() { - RS_Modification m(*container, graphicView); - m.explodeTextIntoLetters(); + trigger(); + finish(); } - -// EOF +void RS_ActionModifyExplodeText::trigger() +{ + RS_Modification m(*container, graphicView); + m.explodeTextIntoLetters(); +} diff --git a/src/actions/rs_actionmodifyexplodetext.h b/src/actions/rs_actionmodifyexplodetext.h index b4a76fa..d0ebe74 100644 --- a/src/actions/rs_actionmodifyexplodetext.h +++ b/src/actions/rs_actionmodifyexplodetext.h @@ -1,34 +1,7 @@ -/**************************************************************************** -** $Id: rs_actionmodifyexplodetext.h 1077 2004-03-03 19:06:45Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYEXPLODETEXT_H #define RS_ACTIONMODIFYEXPLODETEXT_H #include "rs_previewactioninterface.h" -#include "rs_insert.h" /** * This action class can handle user events for exploding blocks and @@ -36,22 +9,15 @@ * * @author Andrew Mustun */ -class RS_ActionModifyExplodeText : public RS_PreviewActionInterface { - //Q_OBJECT -public: - RS_ActionModifyExplodeText(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyExplodeText(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionModifyExplodeText; - } - - virtual void init(int status=0); +class RS_ActionModifyExplodeText: public RS_PreviewActionInterface +{ + public: + RS_ActionModifyExplodeText(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyExplodeText(); - virtual void trigger(); + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionmodifymirror.cpp b/src/actions/rs_actionmodifymirror.cpp index 1f45971..fab05b2 100644 --- a/src/actions/rs_actionmodifymirror.cpp +++ b/src/actions/rs_actionmodifymirror.cpp @@ -1,203 +1,193 @@ -/**************************************************************************** -** $Id: rs_actionmodifymirror.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_actionmodifymirror.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_actionmodifymirror.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_preview.h" -RS_ActionModifyMirror::RS_ActionModifyMirror(RS_EntityContainer& container, - RS_GraphicView& graphicView): +RS_ActionModifyMirror::RS_ActionModifyMirror(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Mirror Entities", container, graphicView) { } -QAction * RS_ActionModifyMirror::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionModifyMirror::~RS_ActionModifyMirror() { - QAction * action = new QAction(tr("&Mirror"), 0); -// QAction* action = new QAction(tr("Mirror"), tr("&Mirror"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Mirror Entities")); - return action; } void RS_ActionModifyMirror::init(int status) { - RS_ActionInterface::init(status); + RS_ActionInterface::init(status); } void RS_ActionModifyMirror::trigger() { + RS_DEBUG->print("RS_ActionModifyMirror::trigger()"); - RS_DEBUG->print("RS_ActionModifyMirror::trigger()"); + RS_Modification m(*container, graphicView); + m.mirror(data); - RS_Modification m(*container, graphicView); - m.mirror(data); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } +void RS_ActionModifyMirror::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyMirror::mouseMoveEvent begin"); + if (getStatus() == SetAxisPoint1 + || getStatus() == SetAxisPoint2) + { + Vector mouse = snapPoint(e); -void RS_ActionModifyMirror::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyMirror::mouseMoveEvent begin"); - - if (getStatus()==SetAxisPoint1 || - getStatus()==SetAxisPoint2) { + switch (getStatus()) + { + case SetAxisPoint1: + axisPoint1 = mouse; + break; - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetAxisPoint1: - axisPoint1 = mouse; - break; + case SetAxisPoint2: - case SetAxisPoint2: - if (axisPoint1.valid) { - axisPoint2 = mouse; + if (axisPoint1.valid) + { + axisPoint2 = mouse; - deletePreview(); - clearPreview(); - preview->addSelectionFrom(*container); - preview->mirror(axisPoint1, axisPoint2); + deletePreview(); + clearPreview(); + preview->addSelectionFrom(*container); + preview->mirror(axisPoint1, axisPoint2); - preview->addEntity(new RS_Line(preview, - RS_LineData(axisPoint1, - axisPoint2))); + preview->addEntity(new RS_Line(preview, + RS_LineData(axisPoint1, + axisPoint2))); - drawPreview(); - } - break; + drawPreview(); + } + break; - default: - break; - } - } + default: + break; + } + } - RS_DEBUG->print("RS_ActionModifyMirror::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionModifyMirror::mouseMoveEvent end"); } - - -void RS_ActionModifyMirror::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionModifyMirror::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionModifyMirror::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetAxisPoint1: - axisPoint1 = mouse; - setStatus(SetAxisPoint2); - graphicView->moveRelativeZero(mouse); - break; - - case SetAxisPoint2: - axisPoint2 = mouse; - setStatus(ShowDialog); - graphicView->moveRelativeZero(mouse); - if (RS_DIALOGFACTORY!=NULL) { - if (RS_DIALOGFACTORY->requestMirrorDialog(data)) { - data.axisPoint1 = axisPoint1; - data.axisPoint2 = axisPoint2; - deletePreview(); - clearPreview(); - trigger(); - finish(); - } - } - break; - - default: - break; - } +void RS_ActionModifyMirror::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetAxisPoint1: + axisPoint1 = mouse; + setStatus(SetAxisPoint2); + graphicView->moveRelativeZero(mouse); + break; + + case SetAxisPoint2: + axisPoint2 = mouse; + setStatus(ShowDialog); + graphicView->moveRelativeZero(mouse); + + if (RS_DIALOGFACTORY != NULL) + { + if (RS_DIALOGFACTORY->requestMirrorDialog(data)) + { + data.axisPoint1 = axisPoint1; + data.axisPoint2 = axisPoint2; + deletePreview(); + clearPreview(); + trigger(); + finish(); + } + } + break; + + default: + break; + } } - - -void RS_ActionModifyMirror::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - /*case Select: - RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to move"), - tr("Cancel")); - break;*/ - case SetAxisPoint1: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify first point of mirror line"), - tr("Cancel")); - break; - case SetAxisPoint2: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Specify second point of mirror line"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionModifyMirror::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + /*case Select: + RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to move"), + tr("Cancel")); + break;*/ + case SetAxisPoint1: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify first point of mirror line"), + tr("Cancel")); + break; + + case SetAxisPoint2: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Specify second point of mirror line"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } - - -void RS_ActionModifyMirror::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionModifyMirror::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionModifyMirror::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetAxisPoint1: - case SetAxisPoint2: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - break; - } - } +void RS_ActionModifyMirror::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetAxisPoint1: + case SetAxisPoint2: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); + break; + } + } } - // EOF diff --git a/src/actions/rs_actionmodifymirror.h b/src/actions/rs_actionmodifymirror.h index 06045f6..83aeb56 100644 --- a/src/actions/rs_actionmodifymirror.h +++ b/src/actions/rs_actionmodifymirror.h @@ -1,73 +1,44 @@ -/**************************************************************************** -** $Id: rs_actionmodifymirror.h 1106 2004-03-24 16:34:24Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYMIRROR_H #define RS_ACTIONMODIFYMIRROR_H -#include "rs_previewactioninterface.h" #include "rs_modification.h" - +#include "rs_previewactioninterface.h" +#include "vector.h" /** * This action class can handle user events to mirror entities. * * @author Andrew Mustun */ -class RS_ActionModifyMirror : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetAxisPoint1, /**< Setting the 1st point of the axis. */ - SetAxisPoint2, /**< Setting the 2nd point of the axis. */ - ShowDialog /**< Showing the options dialog. */ - }; - -public: - RS_ActionModifyMirror(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyMirror() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_MirrorData data; - Vector axisPoint1; - Vector axisPoint2; +class RS_ActionModifyMirror: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetAxisPoint1, /**< Setting the 1st point of the axis. */ + SetAxisPoint2, /**< Setting the 2nd point of the axis. */ + ShowDialog /**< Showing the options dialog. */ + }; + + public: + RS_ActionModifyMirror(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyMirror(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void coordinateEvent(Vector * e); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_MirrorData data; + Vector axisPoint1; + Vector axisPoint2; }; #endif diff --git a/src/actions/rs_actionmodifymove.cpp b/src/actions/rs_actionmodifymove.cpp index f38e236..c5f43c9 100644 --- a/src/actions/rs_actionmodifymove.cpp +++ b/src/actions/rs_actionmodifymove.cpp @@ -1,189 +1,177 @@ -/**************************************************************************** -** $Id: rs_actionmodifymove.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_actionmodifymove.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_actionmodifymove.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_preview.h" - - -RS_ActionModifyMove::RS_ActionModifyMove(RS_EntityContainer& container, - RS_GraphicView& graphicView): +RS_ActionModifyMove::RS_ActionModifyMove(RS_EntityContainer & container, + RS_GraphicView & graphicView): RS_PreviewActionInterface("Move Entities", container, graphicView) { } -QAction* RS_ActionModifyMove::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyMove::~RS_ActionModifyMove() { - QAction * action = new QAction(tr("&Move / Copy"), 0); -// QAction* action = new QAction(tr("Move / Copy"), tr("&Move / Copy"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Move or copy entities one or multiple times")); - return action; } void RS_ActionModifyMove::init(int status) { - RS_ActionInterface::init(status); + RS_ActionInterface::init(status); } - - void RS_ActionModifyMove::trigger() { + RS_DEBUG->print("RS_ActionModifyMove::trigger()"); - RS_DEBUG->print("RS_ActionModifyMove::trigger()"); + RS_Modification m(*container, graphicView); + m.move(data); - RS_Modification m(*container, graphicView); - m.move(data); - - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } - - -void RS_ActionModifyMove::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyMove::mouseMoveEvent begin"); - - if (getStatus()==SetReferencePoint || - getStatus()==SetTargetPoint) { - - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetReferencePoint: - referencePoint = mouse; - break; - - case SetTargetPoint: - if (referencePoint.valid) { - targetPoint = mouse; - - deletePreview(); - clearPreview(); - preview->addSelectionFrom(*container); - preview->move(targetPoint-referencePoint); - drawPreview(); - } - break; - - default: - break; - } - } - - RS_DEBUG->print("RS_ActionModifyMove::mouseMoveEvent end"); +void RS_ActionModifyMove::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyMove::mouseMoveEvent begin"); + + if (getStatus() == SetReferencePoint + || getStatus() == SetTargetPoint) + { + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetReferencePoint: + referencePoint = mouse; + break; + + case SetTargetPoint: + + if (referencePoint.valid) + { + targetPoint = mouse; + + deletePreview(); + clearPreview(); + preview->addSelectionFrom(*container); + preview->move(targetPoint - referencePoint); + drawPreview(); + } + break; + + default: + break; + } + } + + RS_DEBUG->print("RS_ActionModifyMove::mouseMoveEvent end"); } - - -void RS_ActionModifyMove::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionModifyMove::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } -void RS_ActionModifyMove::coordinateEvent(RS_CoordinateEvent* e) { - - if (e==NULL) { - return; - } - - Vector pos = e->getCoordinate(); - - switch (getStatus()) { - case SetReferencePoint: - referencePoint = pos; - graphicView->moveRelativeZero(referencePoint); - setStatus(SetTargetPoint); - break; - - case SetTargetPoint: - targetPoint = pos; - graphicView->moveRelativeZero(targetPoint); - setStatus(ShowDialog); - if (RS_DIALOGFACTORY->requestMoveDialog(data)) { - data.offset = targetPoint - referencePoint; - trigger(); - finish(); - } - break; - - default: - break; - } +void RS_ActionModifyMove::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector pos = *e; + + switch (getStatus()) + { + case SetReferencePoint: + referencePoint = pos; + graphicView->moveRelativeZero(referencePoint); + setStatus(SetTargetPoint); + break; + + case SetTargetPoint: + targetPoint = pos; + graphicView->moveRelativeZero(targetPoint); + setStatus(ShowDialog); + + if (RS_DIALOGFACTORY->requestMoveDialog(data)) + { + data.offset = targetPoint - referencePoint; + trigger(); + finish(); + } + break; + + default: + break; + } } - -void RS_ActionModifyMove::updateMouseButtonHints() { - switch (getStatus()) { - /*case Select: - RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to move"), - tr("Cancel")); - break;*/ - case SetReferencePoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), - tr("Cancel")); - break; - case SetTargetPoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyMove::updateMouseButtonHints() +{ + switch (getStatus()) + { + /*case Select: + RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to move"), + tr("Cancel")); + break;*/ + case SetReferencePoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), + tr("Cancel")); + break; + + case SetTargetPoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyMove::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionModifyMove::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionModifyMove::updateToolBar() { - switch (getStatus()) { - /*case Select: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); - break;*/ - case SetReferencePoint: - case SetTargetPoint: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - break; - } +void RS_ActionModifyMove::updateToolBar() +{ + switch (getStatus()) + { + /*case Select: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); + break;*/ + case SetReferencePoint: + case SetTargetPoint: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); + break; + } } - // EOF diff --git a/src/actions/rs_actionmodifymove.h b/src/actions/rs_actionmodifymove.h index 019f267..2610aab 100644 --- a/src/actions/rs_actionmodifymove.h +++ b/src/actions/rs_actionmodifymove.h @@ -1,77 +1,44 @@ -/**************************************************************************** -** $Id: rs_actionmodifymove.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYMOVE_H #define RS_ACTIONMODIFYMOVE_H -#include "rs_previewactioninterface.h" #include "rs_modification.h" - +#include "rs_previewactioninterface.h" +#include "vector.h" /** * This action class can handle user events to move entities. * * @author Andrew Mustun */ -class RS_ActionModifyMove : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetReferencePoint, /**< Setting the reference point. */ - SetTargetPoint, /**< Setting the target point. */ - ShowDialog /**< Showing the options dialog. */ - }; - -public: - RS_ActionModifyMove(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyMove() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_MoveData data; - Vector referencePoint; - Vector targetPoint; +class RS_ActionModifyMove: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetReferencePoint, /**< Setting the reference point. */ + SetTargetPoint, /**< Setting the target point. */ + ShowDialog /**< Showing the options dialog. */ + }; + + public: + RS_ActionModifyMove(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyMove(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_MoveData data; + Vector referencePoint; + Vector targetPoint; }; #endif diff --git a/src/actions/rs_actionmodifymoverotate.cpp b/src/actions/rs_actionmodifymoverotate.cpp index d105c7c..a241d79 100644 --- a/src/actions/rs_actionmodifymoverotate.cpp +++ b/src/actions/rs_actionmodifymoverotate.cpp @@ -1,107 +1,97 @@ -/**************************************************************************** -** $Id: rs_actionmodifymoverotate.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_actionmodifymoverotate.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_actionmodifymoverotate.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_preview.h" RS_ActionModifyMoveRotate::RS_ActionModifyMoveRotate( - RS_EntityContainer& container, RS_GraphicView& graphicView): + RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Move and Rotate Entities", container, graphicView) { } -QAction * RS_ActionModifyMoveRotate::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionModifyMoveRotate::~RS_ActionModifyMoveRotate() { - QAction * action = new QAction(tr("M&ove and Rotate"), 0); -// QAction* action = new QAction(tr("Move and Rotate"), tr("M&ove and Rotate"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Move and Rotate Entities")); - return action; +} + +/*virtual*/ RS2::ActionType RS_ActionModifyMoveRotate::rtti() +{ + return RS2::ActionModifyMoveRotate; } void RS_ActionModifyMoveRotate::init(int status) { - RS_ActionInterface::init(status); + RS_ActionInterface::init(status); } void RS_ActionModifyMoveRotate::trigger() { - RS_DEBUG->print("RS_ActionModifyMoveRotate::trigger()"); + RS_DEBUG->print("RS_ActionModifyMoveRotate::trigger()"); - RS_Modification m(*container, graphicView); - m.moveRotate(data); + RS_Modification m(*container, graphicView); + m.moveRotate(data); - finish(); + finish(); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } void RS_ActionModifyMoveRotate::mouseMoveEvent(QMouseEvent * e) { - RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent begin"); + RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent begin"); - if (getStatus() == SetReferencePoint || getStatus() == SetTargetPoint) + if (getStatus() == SetReferencePoint || getStatus() == SetTargetPoint) { + Vector mouse = snapPoint(e); - Vector mouse = snapPoint(e); - switch (getStatus()) + switch (getStatus()) { - case SetReferencePoint: - data.referencePoint = mouse; - break; + case SetReferencePoint: + data.referencePoint = mouse; + break; + + case SetTargetPoint: - case SetTargetPoint: - if (data.referencePoint.valid) + if (data.referencePoint.valid) { - targetPoint = mouse; - data.offset = targetPoint-data.referencePoint; - - deletePreview(); - clearPreview(); - preview->addSelectionFrom(*container); - preview->rotate(data.referencePoint, data.angle); - preview->move(data.offset); - drawPreview(); - } - break; - - default: - break; - } - } - - RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent end"); + targetPoint = mouse; + data.offset = targetPoint - data.referencePoint; + + deletePreview(); + clearPreview(); + preview->addSelectionFrom(*container); + preview->rotate(data.referencePoint, data.angle); + preview->move(data.offset); + drawPreview(); + } + break; + + default: + break; + } + } + + RS_DEBUG->print("RS_ActionModifyMoveRotate::mouseMoveEvent end"); } void RS_ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent * e) { if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); + Vector ce(snapPoint(e)); coordinateEvent(&ce); } else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) @@ -112,35 +102,34 @@ void RS_ActionModifyMoveRotate::mouseReleaseEvent(QMouseEvent * e) } } -void RS_ActionModifyMoveRotate::coordinateEvent(RS_CoordinateEvent * e) +void RS_ActionModifyMoveRotate::coordinateEvent(Vector * e) { - if (e == NULL) - return; + if (e == NULL) + return; - Vector pos = e->getCoordinate(); + Vector pos = *e; - switch (getStatus()) + switch (getStatus()) { - case SetReferencePoint: - data.referencePoint = pos; - setStatus(SetTargetPoint); - break; + case SetReferencePoint: + data.referencePoint = pos; + setStatus(SetTargetPoint); + break; - case SetTargetPoint: - targetPoint = pos; + case SetTargetPoint: + targetPoint = pos; - setStatus(ShowDialog); - data.offset = targetPoint - data.referencePoint; - if (RS_DIALOGFACTORY->requestMoveRotateDialog(data)) - { - trigger(); - //finish(); - } - break; - - default: - break; - } + setStatus(ShowDialog); + data.offset = targetPoint - data.referencePoint; + + if (RS_DIALOGFACTORY->requestMoveRotateDialog(data)) + trigger(); + //finish(); + break; + + default: + break; + } } void RS_ActionModifyMoveRotate::commandEvent(RS_CommandEvent * e) @@ -158,6 +147,7 @@ void RS_ActionModifyMoveRotate::commandEvent(RS_CommandEvent * e) case SetReferencePoint: case SetTargetPoint: #warning "Bad comparison (in checkCommand -> rs_actioninterface)... !!! FIX !!!" + if (!c.isEmpty() && checkCommand("angle", c)) // if (c == checkCommand("angle", c)) { @@ -170,95 +160,106 @@ void RS_ActionModifyMoveRotate::commandEvent(RS_CommandEvent * e) break; case SetAngle: - { - bool ok; - double a = RS_Math::eval(c, &ok); + { + bool ok; + double a = RS_Math::eval(c, &ok); - if (ok) - data.angle = RS_Math::deg2rad(a); - else - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + if (ok) + data.angle = RS_Math::deg2rad(a); + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(lastStatus); - } - break; + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(lastStatus); + } + break; } } QStringList RS_ActionModifyMoveRotate::getAvailableCommands() { - QStringList cmd; + QStringList cmd; - switch (getStatus()) + switch (getStatus()) { - case SetReferencePoint: - case SetTargetPoint: - cmd += command("angle"); - break; + case SetReferencePoint: + case SetTargetPoint: + cmd += command("angle"); + break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } void RS_ActionModifyMoveRotate::showOptions() { - //std::cout << "RS_ActionModifyMoveRotate::showOptions()\n"; + //std::cout << "RS_ActionModifyMoveRotate::showOptions()\n"; - RS_ActionInterface::showOptions(); + RS_ActionInterface::showOptions(); - RS_DIALOGFACTORY->requestOptions(this, true); + RS_DIALOGFACTORY->requestOptions(this, true); } void RS_ActionModifyMoveRotate::hideOptions() { - //std::cout << "RS_ActionModifyMoveRotate::hideOptions()\n"; + //std::cout << "RS_ActionModifyMoveRotate::hideOptions()\n"; - RS_ActionInterface::hideOptions(); + RS_ActionInterface::hideOptions(); - RS_DIALOGFACTORY->requestOptions(this, false); + RS_DIALOGFACTORY->requestOptions(this, false); } void RS_ActionModifyMoveRotate::updateMouseButtonHints() { - switch (getStatus()) + switch (getStatus()) { - case SetReferencePoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel")); - break; - case SetTargetPoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Back")); - break; - case SetAngle: - RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"), tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } + case SetReferencePoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), tr("Cancel")); + break; + + case SetTargetPoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), tr("Back")); + break; + + case SetAngle: + RS_DIALOGFACTORY->updateMouseWidget(tr("Enter rotation angle:"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } void RS_ActionModifyMoveRotate::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); + graphicView->setMouseCursor(RS2::CadCursor); } void RS_ActionModifyMoveRotate::updateToolBar() { - switch (getStatus()) + switch (getStatus()) { - case SetReferencePoint: - case SetTargetPoint: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - break; - } + case SetReferencePoint: + case SetTargetPoint: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); + break; + } } +void RS_ActionModifyMoveRotate::setAngle(double a) +{ + data.angle = a; +} -// EOF +double RS_ActionModifyMoveRotate::getAngle() +{ + return data.angle; +} diff --git a/src/actions/rs_actionmodifymoverotate.h b/src/actions/rs_actionmodifymoverotate.h index 542abbb..f370566 100644 --- a/src/actions/rs_actionmodifymoverotate.h +++ b/src/actions/rs_actionmodifymoverotate.h @@ -1,35 +1,9 @@ -/**************************************************************************** -** $Id: rs_actionmodifymoverotate.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYMOVEROTATE_H #define RS_ACTIONMODIFYMOVEROTATE_H -#include "rs_previewactioninterface.h" #include "rs_modification.h" - +#include "rs_previewactioninterface.h" +#include "vector.h" /** * This action class can handle user events to move and at the same @@ -37,67 +11,51 @@ * * @author Andrew Mustun */ -class RS_ActionModifyMoveRotate : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetReferencePoint, /**< Setting the reference point. */ - SetTargetPoint, /**< Setting the target point. */ - ShowDialog, /**< Showing the options dialog. */ - SetAngle /**< Setting angle in command line. */ - }; - -public: - RS_ActionModifyMoveRotate(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyMoveRotate() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionModifyMoveRotate; - } - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - void setAngle(double a) { - data.angle = a; - } - double getAngle() { - return data.angle; - } - -private: - RS_MoveRotateData data; - Vector targetPoint; - - /** Last status before entering angle. */ - Status lastStatus; - /** - * Commands - */ - QString cmdAngle; - QString cmdAngle2; - QString cmdAngle3; +class RS_ActionModifyMoveRotate: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetReferencePoint, /**< Setting the reference point. */ + SetTargetPoint, /**< Setting the target point. */ + ShowDialog, /**< Showing the options dialog. */ + SetAngle /**< Setting angle in command line. */ + }; + + public: + RS_ActionModifyMoveRotate(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyMoveRotate(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + void setAngle(double a); + double getAngle(); + + private: + RS_MoveRotateData data; + Vector targetPoint; + + /** Last status before entering angle. */ + Status lastStatus; + /** + * Commands + */ + QString cmdAngle; + QString cmdAngle2; + QString cmdAngle3; }; #endif diff --git a/src/actions/rs_actionmodifyrotate.cpp b/src/actions/rs_actionmodifyrotate.cpp index bbaf5a0..77c102b 100644 --- a/src/actions/rs_actionmodifyrotate.cpp +++ b/src/actions/rs_actionmodifyrotate.cpp @@ -1,156 +1,141 @@ -/**************************************************************************** -** $Id: rs_actionmodifyrotate.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_actionmodifyrotate.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_actionmodifyrotate.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" - - -RS_ActionModifyRotate::RS_ActionModifyRotate(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Rotate Entities", - container, graphicView) {} - - -QAction* RS_ActionModifyRotate::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyRotate::RS_ActionModifyRotate(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_PreviewActionInterface("Rotate Entities", + container, graphicView) { - QAction * action = new QAction(tr("&Rotate"), 0); -// QAction* action = new QAction(tr("Rotate"), tr("&Rotate"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Rotate Entities")); - return action; } -void RS_ActionModifyRotate::init(int status) { - RS_ActionInterface::init(status); +RS_ActionModifyRotate::~RS_ActionModifyRotate() +{ } +void RS_ActionModifyRotate::init(int status) +{ + RS_ActionInterface::init(status); +} +void RS_ActionModifyRotate::trigger() +{ + RS_DEBUG->print("RS_ActionModifyRotate::trigger()"); -void RS_ActionModifyRotate::trigger() { - - RS_DEBUG->print("RS_ActionModifyRotate::trigger()"); - - RS_Modification m(*container, graphicView); - m.rotate(data); + RS_Modification m(*container, graphicView); + m.rotate(data); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } +void RS_ActionModifyRotate::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyRotate::mouseMoveEvent begin"); + if (getStatus() == SetReferencePoint) + { + Vector mouse = snapPoint(e); -void RS_ActionModifyRotate::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyRotate::mouseMoveEvent begin"); - - if (getStatus()==SetReferencePoint) { - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetReferencePoint: - referencePoint = mouse; - break; + switch (getStatus()) + { + case SetReferencePoint: + referencePoint = mouse; + break; - default: - break; - } - } + default: + break; + } + } - RS_DEBUG->print("RS_ActionModifyRotate::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionModifyRotate::mouseMoveEvent end"); } - - -void RS_ActionModifyRotate::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionModifyRotate::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionModifyRotate::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector pos = e->getCoordinate(); - - switch (getStatus()) { - case SetReferencePoint: - referencePoint = pos; - setStatus(ShowDialog); - if (RS_DIALOGFACTORY->requestRotateDialog(data)) { - data.center = referencePoint; - trigger(); - finish(); - } - break; - - default: - break; - } +void RS_ActionModifyRotate::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector pos = *e; + + switch (getStatus()) + { + case SetReferencePoint: + referencePoint = pos; + setStatus(ShowDialog); + + if (RS_DIALOGFACTORY->requestRotateDialog(data)) + { + data.center = referencePoint; + trigger(); + finish(); + } + break; + + default: + break; + } } - - -void RS_ActionModifyRotate::updateMouseButtonHints() { - switch (getStatus()) { - case SetReferencePoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyRotate::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetReferencePoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyRotate::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionModifyRotate::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionModifyRotate::updateToolBar() { - switch (getStatus()) { - case SetReferencePoint: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - break; - } +void RS_ActionModifyRotate::updateToolBar() +{ + switch (getStatus()) + { + case SetReferencePoint: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); + break; + } } - // EOF diff --git a/src/actions/rs_actionmodifyrotate.h b/src/actions/rs_actionmodifyrotate.h index 0f861c2..ef99098 100644 --- a/src/actions/rs_actionmodifyrotate.h +++ b/src/actions/rs_actionmodifyrotate.h @@ -1,76 +1,43 @@ -/**************************************************************************** -** $Id: rs_actionmodifyrotate.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYROTATE_H #define RS_ACTIONMODIFYROTATE_H -#include "rs_previewactioninterface.h" #include "rs_modification.h" - +#include "rs_previewactioninterface.h" +#include "vector.h" /** * This action class can handle user events to move entities. * * @author Andrew Mustun */ -class RS_ActionModifyRotate : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetReferencePoint, /**< Setting the reference point. */ - ShowDialog /**< Showing the options dialog. */ - }; - -public: - RS_ActionModifyRotate(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyRotate() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_RotateData data; - Vector referencePoint; - Vector targetPoint; +class RS_ActionModifyRotate: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetReferencePoint, /**< Setting the reference point. */ + ShowDialog /**< Showing the options dialog. */ + }; + + public: + RS_ActionModifyRotate(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyRotate(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_RotateData data; + Vector referencePoint; + Vector targetPoint; }; #endif diff --git a/src/actions/rs_actionmodifyrotate2.cpp b/src/actions/rs_actionmodifyrotate2.cpp index 96ba972..b627045 100644 --- a/src/actions/rs_actionmodifyrotate2.cpp +++ b/src/actions/rs_actionmodifyrotate2.cpp @@ -1,195 +1,177 @@ -/**************************************************************************** -** $Id: rs_actionmodifyrotate2.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_actionmodifyrotate2.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_actionmodifyrotate2.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" RS_ActionModifyRotate2::RS_ActionModifyRotate2( - RS_EntityContainer& container, RS_GraphicView& graphicView): + RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Rotate Entities around two centers", container, graphicView) { } -QAction* RS_ActionModifyRotate2::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyRotate2::~RS_ActionModifyRotate2() { - QAction * action = new QAction(tr("Rotate T&wo"), 0); -// QAction* action = new QAction(tr("Rotate Two"), tr("Rotate T&wo"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Rotate Entities around two centers")); - return action; } void RS_ActionModifyRotate2::init(int status) { - RS_ActionInterface::init(status); + RS_ActionInterface::init(status); } +void RS_ActionModifyRotate2::trigger() +{ + RS_DEBUG->print("RS_ActionModifyRotate2::trigger()"); + RS_Modification m(*container, graphicView); + m.rotate2(data); -void RS_ActionModifyRotate2::trigger() { - - RS_DEBUG->print("RS_ActionModifyRotate2::trigger()"); - - RS_Modification m(*container, graphicView); - m.rotate2(data); - - finish(); + finish(); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } - - -void RS_ActionModifyRotate2::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyRotate2::mouseMoveEvent begin"); - - if (getStatus()==SetReferencePoint1 || - getStatus()==SetReferencePoint2) { - - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetReferencePoint1: - data.center1 = mouse; - break; - - case SetReferencePoint2: - if (data.center1.valid) { - data.center2 = mouse; - //data.offset = data.center2-data.center1; - - /*deletePreview(); - clearPreview(); - preview->addSelectionFrom(*container); - preview->rotate(data.center1, data.angle); - preview->move(data.offset); - drawPreview(); - */ - } - break; - - default: - break; - } - } - - RS_DEBUG->print("RS_ActionModifyRotate2::mouseMoveEvent end"); +void RS_ActionModifyRotate2::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyRotate2::mouseMoveEvent begin"); + + if (getStatus() == SetReferencePoint1 + || getStatus() == SetReferencePoint2) + { + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetReferencePoint1: + data.center1 = mouse; + break; + + case SetReferencePoint2: + + if (data.center1.valid) + data.center2 = mouse; + //data.offset = data.center2-data.center1; + + /*deletePreview(); + clearPreview(); + preview->addSelectionFrom(*container); + preview->rotate(data.center1, data.angle); + preview->move(data.offset); + drawPreview(); + */ + break; + + default: + break; + } + } + + RS_DEBUG->print("RS_ActionModifyRotate2::mouseMoveEvent end"); } - - -void RS_ActionModifyRotate2::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionModifyRotate2::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionModifyRotate2::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector pos = e->getCoordinate(); - - switch (getStatus()) { - case SetReferencePoint1: - data.center1 = pos; - setStatus(SetReferencePoint2); - break; - - case SetReferencePoint2: - data.center2 = pos; - setStatus(ShowDialog); - if (RS_DIALOGFACTORY->requestRotate2Dialog(data)) { - trigger(); - //finish(); - } - break; - - default: - break; - } +void RS_ActionModifyRotate2::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector pos = *e; + + switch (getStatus()) + { + case SetReferencePoint1: + data.center1 = pos; + setStatus(SetReferencePoint2); + break; + + case SetReferencePoint2: + data.center2 = pos; + setStatus(ShowDialog); + + if (RS_DIALOGFACTORY->requestRotate2Dialog(data)) + trigger(); + //finish(); + break; + + default: + break; + } } - -void RS_ActionModifyRotate2::commandEvent(RS_CommandEvent* /*e*/) { +void RS_ActionModifyRotate2::commandEvent(RS_CommandEvent * /*e*/) +{ } - - -QStringList RS_ActionModifyRotate2::getAvailableCommands() { - QStringList cmd; - return cmd; +QStringList RS_ActionModifyRotate2::getAvailableCommands() +{ + QStringList cmd; + return cmd; } - - - -void RS_ActionModifyRotate2::updateMouseButtonHints() { - switch (getStatus()) { - case SetReferencePoint1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify absolute reference point"), - tr("Cancel")); - break; - case SetReferencePoint2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify relative reference point"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyRotate2::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetReferencePoint1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify absolute reference point"), + tr("Cancel")); + break; + + case SetReferencePoint2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify relative reference point"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyRotate2::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionModifyRotate2::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionModifyRotate2::updateToolBar() { - switch (getStatus()) { - case SetReferencePoint1: - case SetReferencePoint2: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - break; - } +void RS_ActionModifyRotate2::updateToolBar() +{ + switch (getStatus()) + { + case SetReferencePoint1: + case SetReferencePoint2: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); + break; + } } - // EOF diff --git a/src/actions/rs_actionmodifyrotate2.h b/src/actions/rs_actionmodifyrotate2.h index 9b8d18d..af0a254 100644 --- a/src/actions/rs_actionmodifyrotate2.h +++ b/src/actions/rs_actionmodifyrotate2.h @@ -1,35 +1,8 @@ -/**************************************************************************** -** $Id: rs_actionmodifyrotate2.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYROTATE2_H #define RS_ACTIONMODIFYROTATE2_H -#include "rs_previewactioninterface.h" #include "rs_modification.h" - +#include "rs_previewactioninterface.h" /** * This action class can handle user events to rotate entities around @@ -37,43 +10,35 @@ * * @author Andrew Mustun */ -class RS_ActionModifyRotate2 : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetReferencePoint1, /**< Setting the reference point. */ - SetReferencePoint2, /**< Setting the target point. */ - ShowDialog /**< Showing the options dialog. */ - }; - -public: - RS_ActionModifyRotate2(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyRotate2() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - //virtual void hideOptions(); - //virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_Rotate2Data data; +class RS_ActionModifyRotate2: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetReferencePoint1, /**< Setting the reference point. */ + SetReferencePoint2, /**< Setting the target point. */ + ShowDialog /**< Showing the options dialog. */ + }; + + public: + RS_ActionModifyRotate2(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyRotate2(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_Rotate2Data data; }; #endif diff --git a/src/actions/rs_actionmodifyround.cpp b/src/actions/rs_actionmodifyround.cpp index 8311997..67c0503 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 (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); + } } +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; +} diff --git a/src/actions/rs_actionmodifyround.h b/src/actions/rs_actionmodifyround.h index 1bff4d1..37f79c2 100644 --- a/src/actions/rs_actionmodifyround.h +++ b/src/actions/rs_actionmodifyround.h @@ -1,106 +1,59 @@ -/**************************************************************************** -** $Id: rs_actionmodifyround.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYROUND_H #define RS_ACTIONMODIFYROUND_H -#include "rs_previewactioninterface.h" #include "rs_modification.h" +#include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to round corners. * * @author Andrew Mustun */ -class RS_ActionModifyRound : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetEntity1, /**< Choosing the 1st entity. */ - SetEntity2, /**< Choosing the 2nd entity. */ - SetRadius, /**< Setting radius in command line. */ - SetTrim /**< Setting trim flag in command line. */ - }; - -public: - RS_ActionModifyRound(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyRound() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionModifyRound; - } - - virtual void init(int status=0); - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - void setRadius(double r) { - data.radius = r; - } - - double getRadius() { - return data.radius; - } - - void setTrim(bool t) { - data.trim = t; - } - - bool isTrimOn() { - return data.trim; - } - -private: - //Vector coord; - Vector coord1; - RS_Entity* entity1; - Vector coord2; - RS_Entity* entity2; - RS_RoundData data; - /** Last status before entering angle. */ - Status lastStatus; +class RS_ActionModifyRound: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetEntity1, /**< Choosing the 1st entity. */ + SetEntity2, /**< Choosing the 2nd entity. */ + SetRadius, /**< Setting radius in command line. */ + SetTrim /**< Setting trim flag in command line. */ + }; + + public: + RS_ActionModifyRound(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyRound(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + void setRadius(double r); + double getRadius(); + void setTrim(bool t); + bool isTrimOn(); + + private: + Vector coord1; + RS_Entity * entity1; + Vector coord2; + RS_Entity * entity2; + RS_RoundData data; + /** Last status before entering angle. */ + Status lastStatus; }; #endif diff --git a/src/actions/rs_actionmodifyscale.cpp b/src/actions/rs_actionmodifyscale.cpp index 0697ae3..38e3a5b 100644 --- a/src/actions/rs_actionmodifyscale.cpp +++ b/src/actions/rs_actionmodifyscale.cpp @@ -1,153 +1,138 @@ -/**************************************************************************** -** $Id: rs_actionmodifyscale.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_actionmodifyscale.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_actionmodifyscale.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" - - -RS_ActionModifyScale::RS_ActionModifyScale(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Scale Entities", - container, graphicView) {} - - -QAction* RS_ActionModifyScale::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyScale::RS_ActionModifyScale(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_PreviewActionInterface("Scale Entities", + container, graphicView) { - QAction * action = new QAction(tr("&Scale"), 0); -// QAction* action = new QAction(tr("Scale"), tr("&Scale"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Scale Entities")); - return action; } -void RS_ActionModifyScale::init(int status) { - RS_ActionInterface::init(status); - +RS_ActionModifyScale::~RS_ActionModifyScale() +{ } +void RS_ActionModifyScale::init(int status) +{ + RS_ActionInterface::init(status); +} +void RS_ActionModifyScale::trigger() +{ + RS_DEBUG->print("RS_ActionModifyScale::trigger()"); -void RS_ActionModifyScale::trigger() { - - RS_DEBUG->print("RS_ActionModifyScale::trigger()"); - - RS_Modification m(*container, graphicView); - m.scale(data); + RS_Modification m(*container, graphicView); + m.scale(data); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } +void RS_ActionModifyScale::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyScale::mouseMoveEvent begin"); + if (getStatus() == SetReferencePoint) + { + Vector mouse = snapPoint(e); -void RS_ActionModifyScale::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyScale::mouseMoveEvent begin"); - - if (getStatus()==SetReferencePoint) { - - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetReferencePoint: - referencePoint = mouse; - break; + switch (getStatus()) + { + case SetReferencePoint: + referencePoint = mouse; + break; - default: - break; - } - } + default: + break; + } + } - RS_DEBUG->print("RS_ActionModifyScale::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionModifyScale::mouseMoveEvent end"); } - - -void RS_ActionModifyScale::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - Vector mouse = snapPoint(e); - - switch (getStatus()) { - case SetReferencePoint: - setStatus(ShowDialog); - if (RS_DIALOGFACTORY->requestScaleDialog(data)) { - data.referencePoint = referencePoint; - trigger(); - finish(); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionModifyScale::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetReferencePoint: + setStatus(ShowDialog); + + if (RS_DIALOGFACTORY->requestScaleDialog(data)) + { + data.referencePoint = referencePoint; + trigger(); + finish(); + } + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionModifyScale::updateMouseButtonHints() { - switch (getStatus()) { - /*case Select: - RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to scale"), - tr("Cancel")); - break;*/ - case SetReferencePoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), - tr("Cancel")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyScale::updateMouseButtonHints() +{ + switch (getStatus()) + { + /*case Select: + RS_DIALOGFACTORY->updateMouseWidget(tr("Pick entities to scale"), + tr("Cancel")); + break;*/ + case SetReferencePoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), + tr("Cancel")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyScale::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionModifyScale::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionModifyScale::updateToolBar() { - switch (getStatus()) { - /*case Select: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); - break;*/ - case SetReferencePoint: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - break; - default: - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - break; - } +void RS_ActionModifyScale::updateToolBar() +{ + switch (getStatus()) + { + /*case Select: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); + break;*/ + case SetReferencePoint: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + break; + + default: + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); + break; + } } - // EOF diff --git a/src/actions/rs_actionmodifyscale.h b/src/actions/rs_actionmodifyscale.h index 048ffc6..0b98a4a 100644 --- a/src/actions/rs_actionmodifyscale.h +++ b/src/actions/rs_actionmodifyscale.h @@ -1,71 +1,42 @@ -/**************************************************************************** -** $Id: rs_actionmodifyscale.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYSCALE_H #define RS_ACTIONMODIFYSCALE_H -#include "rs_previewactioninterface.h" #include "rs_modification.h" - +#include "rs_previewactioninterface.h" +#include "vector.h" /** * This action class can handle user events to move entities. * * @author Andrew Mustun */ -class RS_ActionModifyScale : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetReferencePoint, /**< Setting the reference point. */ - ShowDialog /**< Showing the options dialog. */ - }; - -public: - RS_ActionModifyScale(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyScale() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_ScaleData data; - Vector referencePoint; - Vector targetPoint; +class RS_ActionModifyScale: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetReferencePoint, /**< Setting the reference point. */ + ShowDialog /**< Showing the options dialog. */ + }; + + public: + RS_ActionModifyScale(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyScale(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_ScaleData data; + Vector referencePoint; + Vector targetPoint; }; #endif diff --git a/src/actions/rs_actionmodifystretch.cpp b/src/actions/rs_actionmodifystretch.cpp index aeeecb9..f71e107 100644 --- a/src/actions/rs_actionmodifystretch.cpp +++ b/src/actions/rs_actionmodifystretch.cpp @@ -1,243 +1,228 @@ -/**************************************************************************** -** $Id: rs_actionmodifystretch.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_actionmodifystretch.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_actionmodifystretch.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_modification.h" +#include "rs_preview.h" - - -RS_ActionModifyStretch::RS_ActionModifyStretch(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Stretch Entities", - container, graphicView) { - - firstCorner = Vector(false); - secondCorner = Vector(false); - referencePoint = Vector(false); - targetPoint = Vector(false); +RS_ActionModifyStretch::RS_ActionModifyStretch(RS_EntityContainer & container, + RS_GraphicView & graphicView): RS_PreviewActionInterface("Stretch Entities", + container, graphicView) +{ + firstCorner = Vector(false); + secondCorner = Vector(false); + referencePoint = Vector(false); + targetPoint = Vector(false); } -QAction* RS_ActionModifyStretch::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyStretch::~RS_ActionModifyStretch() { - QAction * action = new QAction(tr("&Stretch"), 0); -// QAction* action = new QAction(tr("Stretch"), tr("&Stretch"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Stretch Entities")); - return action; } - -void RS_ActionModifyStretch::init(int status) { - RS_ActionInterface::init(status); - +void RS_ActionModifyStretch::init(int status) +{ + RS_ActionInterface::init(status); } +void RS_ActionModifyStretch::trigger() +{ + RS_DEBUG->print("RS_ActionModifyStretch::trigger()"); + deletePreview(); + clearPreview(); -void RS_ActionModifyStretch::trigger() { - - RS_DEBUG->print("RS_ActionModifyStretch::trigger()"); - - deletePreview(); - clearPreview(); - - deleteSnapper(); + deleteSnapper(); - RS_Modification m(*container, graphicView); - m.stretch(firstCorner, secondCorner, targetPoint-referencePoint); + RS_Modification m(*container, graphicView); + m.stretch(firstCorner, secondCorner, targetPoint - referencePoint); - drawSnapper(); + drawSnapper(); - setStatus(SetFirstCorner); + setStatus(SetFirstCorner); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } - - -void RS_ActionModifyStretch::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent begin"); - - Vector mouse = snapPoint(e); - switch (getStatus()) { - case SetFirstCorner: - break; - - case SetSecondCorner: - if (firstCorner.valid) { - secondCorner = snapPoint(e); - deletePreview(); - clearPreview(); - preview->addEntity( - new RS_Line(preview, - RS_LineData(Vector(firstCorner.x, - firstCorner.y), - Vector(secondCorner.x, - firstCorner.y)))); - preview->addEntity( - new RS_Line(preview, - RS_LineData(Vector(secondCorner.x, - firstCorner.y), - Vector(secondCorner.x, - secondCorner.y)))); - preview->addEntity( - new RS_Line(preview, - RS_LineData(Vector(secondCorner.x, - secondCorner.y), - Vector(firstCorner.x, - secondCorner.y)))); - preview->addEntity( - new RS_Line(preview, - RS_LineData(Vector(firstCorner.x, - secondCorner.y), - Vector(firstCorner.x, - firstCorner.y)))); - drawPreview(); - } - break; - - case SetReferencePoint: - break; - - case SetTargetPoint: - if (referencePoint.valid) { - targetPoint = mouse; - - deletePreview(); - clearPreview(); - preview->addStretchablesFrom(*container, firstCorner, secondCorner); - //preview->move(targetPoint-referencePoint); - preview->stretch(firstCorner, secondCorner, - targetPoint-referencePoint); - drawPreview(); - } - break; - - default: - break; - } - - RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent end"); +void RS_ActionModifyStretch::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent begin"); + + Vector mouse = snapPoint(e); + + switch (getStatus()) + { + case SetFirstCorner: + break; + + case SetSecondCorner: + + if (firstCorner.valid) + { + secondCorner = snapPoint(e); + deletePreview(); + clearPreview(); + preview->addEntity( + new RS_Line(preview, + RS_LineData(Vector(firstCorner.x, + firstCorner.y), + Vector(secondCorner.x, + firstCorner.y)))); + preview->addEntity( + new RS_Line(preview, + RS_LineData(Vector(secondCorner.x, + firstCorner.y), + Vector(secondCorner.x, + secondCorner.y)))); + preview->addEntity( + new RS_Line(preview, + RS_LineData(Vector(secondCorner.x, + secondCorner.y), + Vector(firstCorner.x, + secondCorner.y)))); + preview->addEntity( + new RS_Line(preview, + RS_LineData(Vector(firstCorner.x, + secondCorner.y), + Vector(firstCorner.x, + firstCorner.y)))); + drawPreview(); + } + break; + + case SetReferencePoint: + break; + + case SetTargetPoint: + + if (referencePoint.valid) + { + targetPoint = mouse; + + deletePreview(); + clearPreview(); + preview->addStretchablesFrom(*container, firstCorner, secondCorner); + //preview->move(targetPoint-referencePoint); + preview->stretch(firstCorner, secondCorner, + targetPoint - referencePoint); + drawPreview(); + } + break; + + default: + break; + } + + RS_DEBUG->print("RS_ActionModifyStretch::mouseMoveEvent end"); } - - -void RS_ActionModifyStretch::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionModifyStretch::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionModifyStretch::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - Vector mouse = e->getCoordinate(); - - switch (getStatus()) { - case SetFirstCorner: - firstCorner = mouse; - setStatus(SetSecondCorner); - break; - - case SetSecondCorner: - secondCorner = mouse; - deletePreview(); - clearPreview(); - setStatus(SetReferencePoint); - break; - - case SetReferencePoint: - referencePoint = mouse; - graphicView->moveRelativeZero(referencePoint); - setStatus(SetTargetPoint); - break; - - case SetTargetPoint: - targetPoint = mouse; - graphicView->moveRelativeZero(targetPoint); - trigger(); - //finish(); - break; - - default: - break; - } - +void RS_ActionModifyStretch::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; + + Vector mouse = *e; + + switch (getStatus()) + { + case SetFirstCorner: + firstCorner = mouse; + setStatus(SetSecondCorner); + break; + + case SetSecondCorner: + secondCorner = mouse; + deletePreview(); + clearPreview(); + setStatus(SetReferencePoint); + break; + + case SetReferencePoint: + referencePoint = mouse; + graphicView->moveRelativeZero(referencePoint); + setStatus(SetTargetPoint); + break; + + case SetTargetPoint: + targetPoint = mouse; + graphicView->moveRelativeZero(targetPoint); + trigger(); + //finish(); + break; + + default: + break; + } } - -void RS_ActionModifyStretch::updateMouseButtonHints() { - switch (getStatus()) { - case SetFirstCorner: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"), - tr("Cancel")); - break; - case SetSecondCorner: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"), - tr("Back")); - break; - case SetReferencePoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), - tr("Back")); - break; - case SetTargetPoint: - RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyStretch::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetFirstCorner: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first corner"), + tr("Cancel")); + break; + + case SetSecondCorner: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second corner"), + tr("Back")); + break; + + case SetReferencePoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify reference point"), + tr("Back")); + break; + + case SetTargetPoint: + RS_DIALOGFACTORY->updateMouseWidget(tr("Specify target point"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyStretch::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionModifyStretch::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionModifyStretch::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); - } +void RS_ActionModifyStretch::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); } - // EOF diff --git a/src/actions/rs_actionmodifystretch.h b/src/actions/rs_actionmodifystretch.h index efa0074..f4c4849 100644 --- a/src/actions/rs_actionmodifystretch.h +++ b/src/actions/rs_actionmodifystretch.h @@ -1,77 +1,46 @@ -/**************************************************************************** -** $Id: rs_actionmodifystretch.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYSTRETCH_H #define RS_ACTIONMODIFYSTRETCH_H #include "rs_previewactioninterface.h" -#include "rs_modification.h" - +#include "vector.h" /** * This action class can handle user events to move entities. * * @author Andrew Mustun */ -class RS_ActionModifyStretch : public RS_PreviewActionInterface { +class RS_ActionModifyStretch: public RS_PreviewActionInterface +{ //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetFirstCorner, /**< Setting first corner of selection. */ - SetSecondCorner, /**< Setting second corner of selection. */ - SetReferencePoint, /**< Setting the reference point. */ - SetTargetPoint /**< Setting the target point. */ - }; - -public: - RS_ActionModifyStretch(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyStretch() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - Vector firstCorner; - Vector secondCorner; - Vector referencePoint; - Vector targetPoint; + public: + /** + * Action States. + */ + enum Status { + SetFirstCorner, /**< Setting first corner of selection. */ + SetSecondCorner, /**< Setting second corner of selection. */ + SetReferencePoint, /**< Setting the reference point. */ + SetTargetPoint /**< Setting the target point. */ + }; + + public: + RS_ActionModifyStretch(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyStretch(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void coordinateEvent(Vector * e); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + Vector firstCorner; + Vector secondCorner; + Vector referencePoint; + Vector targetPoint; }; #endif diff --git a/src/actions/rs_actionmodifytrim.cpp b/src/actions/rs_actionmodifytrim.cpp index 281a455..611d012 100644 --- a/src/actions/rs_actionmodifytrim.cpp +++ b/src/actions/rs_actionmodifytrim.cpp @@ -14,189 +14,172 @@ #include "rs_actionmodifytrim.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_modification.h" /** * @param both Trim both entities. */ -RS_ActionModifyTrim::RS_ActionModifyTrim(RS_EntityContainer& container, - RS_GraphicView& graphicView, bool both) - :RS_PreviewActionInterface("Trim Entity", - container, graphicView) { - - trimEntity = NULL; - trimCoord = Vector(false); - limitEntity = NULL; - limitCoord = Vector(false); - this->both = both; +RS_ActionModifyTrim::RS_ActionModifyTrim(RS_EntityContainer & container, + RS_GraphicView & graphicView, bool both): RS_PreviewActionInterface("Trim Entity", + container, graphicView) +{ + trimEntity = NULL; + trimCoord = Vector(false); + limitEntity = NULL; + limitCoord = Vector(false); + this->both = both; } -QAction * RS_ActionModifyTrim::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +RS_ActionModifyTrim::~RS_ActionModifyTrim() { - QAction * action; - - switch (type) - { - default: - case RS2::ActionModifyTrim: - action = new QAction(tr("&Trim"), 0); -// action = new QAction(tr("Trim"), tr("&Trim"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Trim Entities")); - break; - - case RS2::ActionModifyTrim2: - action = new QAction(tr("&Trim Two"), 0); -// action = new QAction(tr("Trim Two"), tr("&Trim Two"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Trim two Entities")); - break; - } - - return action; } +void RS_ActionModifyTrim::init(int status) +{ + RS_ActionInterface::init(status); -void RS_ActionModifyTrim::init(int status) { - RS_ActionInterface::init(status); - - snapMode = RS2::SnapFree; - snapRes = RS2::RestrictNothing; - + snapMode = RS2::SnapFree; + snapRes = RS2::RestrictNothing; } +void RS_ActionModifyTrim::trigger() +{ + RS_DEBUG->print("RS_ActionModifyTrim::trigger()"); - -void RS_ActionModifyTrim::trigger() { - - RS_DEBUG->print("RS_ActionModifyTrim::trigger()"); - - if (trimEntity!=NULL && trimEntity->isAtomic() && - limitEntity!=NULL /* && limitEntity->isAtomic()*/) { - - RS_Modification m(*container, graphicView); - m.trim(trimCoord, (RS_AtomicEntity*)trimEntity, - limitCoord, /*(RS_AtomicEntity*)*/limitEntity, - both); - - trimEntity = NULL; - if (both) { - limitEntity->setHighlighted(false); - graphicView->drawEntity(limitEntity); - setStatus(ChooseLimitEntity); - } else { - setStatus(ChooseTrimEntity); - } - - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } + if (trimEntity != NULL && trimEntity->isAtomic() + && limitEntity != NULL /* && limitEntity->isAtomic()*/) + { + RS_Modification m(*container, graphicView); + m.trim(trimCoord, (RS_AtomicEntity *)trimEntity, + limitCoord, /*(RS_AtomicEntity*)*/ limitEntity, + both); + + trimEntity = NULL; + + if (both) + { + limitEntity->setHighlighted(false); + graphicView->drawEntity(limitEntity); + setStatus(ChooseLimitEntity); + } + else + setStatus(ChooseTrimEntity); + + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } } +void RS_ActionModifyTrim::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent begin"); + Vector mouse = graphicView->toGraph(e->x(), e->y()); + RS_Entity * se = catchEntity(e); -void RS_ActionModifyTrim::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent begin"); - - Vector mouse = graphicView->toGraph(e->x(), e->y()); - RS_Entity* se = catchEntity(e); - - switch (getStatus()) { - case ChooseLimitEntity: - limitCoord = mouse; - limitEntity = se; - break; + switch (getStatus()) + { + case ChooseLimitEntity: + limitCoord = mouse; + limitEntity = se; + break; - case ChooseTrimEntity: - trimCoord = mouse; - trimEntity = se; - break; + case ChooseTrimEntity: + trimCoord = mouse; + trimEntity = se; + break; - default: - break; - } + default: + break; + } - RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end"); + RS_DEBUG->print("RS_ActionModifyTrim::mouseMoveEvent end"); } - - -void RS_ActionModifyTrim::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - - Vector mouse = graphicView->toGraph(e->x(), e->y()); - RS_Entity* se = catchEntity(e); - - switch (getStatus()) { - case ChooseLimitEntity: - limitCoord = mouse; - limitEntity = se; - if (limitEntity!=NULL /*&& limitEntity->isAtomic()*/) { - limitEntity->setHighlighted(true); - graphicView->drawEntity(limitEntity); - setStatus(ChooseTrimEntity); - } - break; - - case ChooseTrimEntity: - trimCoord = mouse; - trimEntity = se; - if (trimEntity!=NULL && trimEntity->isAtomic()) { - trigger(); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - if (limitEntity!=NULL) { - limitEntity->setHighlighted(false); - graphicView->drawEntity(limitEntity); - } - init(getStatus()-1); - } +void RS_ActionModifyTrim::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector mouse = graphicView->toGraph(e->x(), e->y()); + RS_Entity * se = catchEntity(e); + + switch (getStatus()) + { + case ChooseLimitEntity: + limitCoord = mouse; + limitEntity = se; + + if (limitEntity != NULL /*&& limitEntity->isAtomic()*/) + { + limitEntity->setHighlighted(true); + graphicView->drawEntity(limitEntity); + setStatus(ChooseTrimEntity); + } + break; + + case ChooseTrimEntity: + trimCoord = mouse; + trimEntity = se; + + if (trimEntity != NULL && trimEntity->isAtomic()) + trigger(); + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + + if (limitEntity != NULL) + { + limitEntity->setHighlighted(false); + graphicView->drawEntity(limitEntity); + } + init(getStatus() - 1); + } } +void RS_ActionModifyTrim::updateMouseButtonHints() +{ + switch (getStatus()) + { + case ChooseLimitEntity: + + if (both) + RS_DIALOGFACTORY->updateMouseWidget(tr("Select first trim entity"), + tr("Cancel")); + else + RS_DIALOGFACTORY->updateMouseWidget(tr("Select limiting entity"), + tr("Back")); + break; + case ChooseTrimEntity: -void RS_ActionModifyTrim::updateMouseButtonHints() { - switch (getStatus()) { - case ChooseLimitEntity: - if (both) { - RS_DIALOGFACTORY->updateMouseWidget(tr("Select first trim entity"), - tr("Cancel")); - } else { - RS_DIALOGFACTORY->updateMouseWidget(tr("Select limiting entity"), - tr("Back")); - } - break; - case ChooseTrimEntity: - if (both) { - RS_DIALOGFACTORY->updateMouseWidget(tr("Select second trim entity"), - tr("Cancel")); - } else { - RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity to trim"), - tr("Back")); - } - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } -} - - + if (both) + RS_DIALOGFACTORY->updateMouseWidget(tr("Select second trim entity"), + tr("Cancel")); + else + RS_DIALOGFACTORY->updateMouseWidget(tr("Select entity to trim"), + tr("Back")); + break; -void RS_ActionModifyTrim::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyTrim::updateToolBar() { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); +void RS_ActionModifyTrim::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } +void RS_ActionModifyTrim::updateToolBar() +{ + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); +} diff --git a/src/actions/rs_actionmodifytrim.h b/src/actions/rs_actionmodifytrim.h index b66b8b4..5c37406 100644 --- a/src/actions/rs_actionmodifytrim.h +++ b/src/actions/rs_actionmodifytrim.h @@ -2,47 +2,44 @@ #define RS_ACTIONMODIFYTRIM_H #include "rs_previewactioninterface.h" -#include "rs_modification.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to trim entities. * * @author Andrew Mustun */ -class RS_ActionModifyTrim : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - ChooseLimitEntity, /**< Choosing the limiting entity. */ - ChooseTrimEntity /**< Choosing the entity to trim. */ - }; - -public: - RS_ActionModifyTrim(RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool both=false); - ~RS_ActionModifyTrim() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_Entity* limitEntity; - Vector limitCoord; - RS_Entity* trimEntity; - Vector trimCoord; - bool both; +class RS_ActionModifyTrim: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + ChooseLimitEntity, /**< Choosing the limiting entity. */ + ChooseTrimEntity /**< Choosing the entity to trim. */ + }; + + public: + RS_ActionModifyTrim(RS_EntityContainer & container, RS_GraphicView & graphicView, bool both = false); + ~RS_ActionModifyTrim(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_Entity * limitEntity; + Vector limitCoord; + RS_Entity * trimEntity; + Vector trimCoord; + bool both; }; #endif diff --git a/src/actions/rs_actionmodifytrimamount.cpp b/src/actions/rs_actionmodifytrimamount.cpp index 9513135..65666c8 100644 --- a/src/actions/rs_actionmodifytrimamount.cpp +++ b/src/actions/rs_actionmodifytrimamount.cpp @@ -1,201 +1,198 @@ -/**************************************************************************** -** $Id: rs_actionmodifytrimamount.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_actionmodifytrimamount.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_actionmodifytrimamount.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" +#include "rs_modification.h" RS_ActionModifyTrimAmount::RS_ActionModifyTrimAmount( - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Trim Entity by a given amount", - container, graphicView) { - - trimEntity = NULL; - trimCoord = Vector(false); - distance = 0.0; + RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Trim Entity by a given amount", + container, graphicView) +{ + trimEntity = NULL; + trimCoord = Vector(false); + distance = 0.0; } -QAction* RS_ActionModifyTrimAmount::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionModifyTrimAmount::~RS_ActionModifyTrimAmount() { - QAction * action = new QAction(tr("&Lengthen"), 0); -// QAction* action = new QAction(tr("Lengthen"), tr("&Lengthen"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Lengthen by a given amount")); - return action; } -void RS_ActionModifyTrimAmount::init(int status) +/*virtual*/ RS2::ActionType RS_ActionModifyTrimAmount::rtti() { - RS_ActionInterface::init(status); - - snapMode = RS2::SnapFree; - snapRes = RS2::RestrictNothing; + return RS2::ActionModifyTrimAmount; } +void RS_ActionModifyTrimAmount::init(int status) +{ + RS_ActionInterface::init(status); + snapMode = RS2::SnapFree; + snapRes = RS2::RestrictNothing; +} -void RS_ActionModifyTrimAmount::trigger() { - - RS_DEBUG->print("RS_ActionModifyTrimAmount::trigger()"); - - if (trimEntity!=NULL && trimEntity->isAtomic()) { +void RS_ActionModifyTrimAmount::trigger() +{ + RS_DEBUG->print("RS_ActionModifyTrimAmount::trigger()"); - RS_Modification m(*container, graphicView); - m.trimAmount(trimCoord, (RS_AtomicEntity*)trimEntity, distance); + if (trimEntity != NULL && trimEntity->isAtomic()) + { + RS_Modification m(*container, graphicView); + m.trimAmount(trimCoord, (RS_AtomicEntity *)trimEntity, distance); - trimEntity = NULL; - setStatus(ChooseTrimEntity); + trimEntity = NULL; + setStatus(ChooseTrimEntity); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } } - - -void RS_ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent* e) { - - trimCoord = graphicView->toGraph(e->x(), e->y()); - trimEntity = catchEntity(e); - - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case ChooseTrimEntity: - if (trimEntity!=NULL && trimEntity->isAtomic()) { - trigger(); - } else { - if (trimEntity==NULL) { - RS_DIALOGFACTORY->commandMessage( - tr("No entity found. ")); - } else if (trimEntity->rtti()==RS2::EntityInsert) { - RS_DIALOGFACTORY->commandMessage( - tr("The chosen Entity is in a block. " - "Please edit the block.")); - } else { - RS_DIALOGFACTORY->commandMessage( - tr("The chosen Entity is not an atomic entity " - "or cannot be trimmed.")); - } - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionModifyTrimAmount::mouseReleaseEvent(QMouseEvent * e) +{ + trimCoord = graphicView->toGraph(e->x(), e->y()); + trimEntity = catchEntity(e); + + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case ChooseTrimEntity: + + if (trimEntity != NULL && trimEntity->isAtomic()) + trigger(); + else + { + if (trimEntity == NULL) + RS_DIALOGFACTORY->commandMessage( + tr("No entity found. ")); + else if (trimEntity->rtti() == RS2::EntityInsert) + RS_DIALOGFACTORY->commandMessage( + tr("The chosen Entity is in a block. " + "Please edit the block.")); + else + RS_DIALOGFACTORY->commandMessage( + tr("The chosen Entity is not an atomic entity " + "or cannot be trimmed.")); + } + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionModifyTrimAmount::commandEvent(RS_CommandEvent* e) { - QString c = e->getCommand().toLower(); - - if (checkCommand("help", c)) { - RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() - + getAvailableCommands().join(", ")); - return; - } - - switch (getStatus()) { - case ChooseTrimEntity: { - bool ok; - double d = RS_Math::eval(c, &ok); - if (ok==true) { - distance = d; - } else { - RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); - } - RS_DIALOGFACTORY->requestOptions(this, true, true); - setStatus(ChooseTrimEntity); - } - break; - - default: - break; - } +void RS_ActionModifyTrimAmount::commandEvent(RS_CommandEvent * e) +{ + QString c = e->getCommand().toLower(); + + if (checkCommand("help", c)) + { + RS_DIALOGFACTORY->commandMessage(msgAvailableCommands() + + getAvailableCommands().join(", ")); + return; + } + + switch (getStatus()) + { + case ChooseTrimEntity: { + bool ok; + double d = RS_Math::eval(c, &ok); + + if (ok == true) + distance = d; + else + RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression")); + RS_DIALOGFACTORY->requestOptions(this, true, true); + setStatus(ChooseTrimEntity); + } + break; + + default: + break; + } } +QStringList RS_ActionModifyTrimAmount::getAvailableCommands() +{ + QStringList cmd; + switch (getStatus()) + { + case ChooseTrimEntity: + break; -QStringList RS_ActionModifyTrimAmount::getAvailableCommands() { - QStringList cmd; - - switch (getStatus()) { - case ChooseTrimEntity: - break; - default: - break; - } + default: + break; + } - return cmd; + return cmd; } +void RS_ActionModifyTrimAmount::showOptions() +{ + RS_ActionInterface::showOptions(); -void RS_ActionModifyTrimAmount::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionModifyTrimAmount::hideOptions() +{ + RS_ActionInterface::hideOptions(); - -void RS_ActionModifyTrimAmount::hideOptions() { - RS_ActionInterface::hideOptions(); - - RS_DIALOGFACTORY->requestOptions(this, false); + RS_DIALOGFACTORY->requestOptions(this, false); } - -void RS_ActionModifyTrimAmount::updateMouseButtonHints() { - switch (getStatus()) { - case ChooseTrimEntity: - RS_DIALOGFACTORY->updateMouseWidget( - tr("Select entity to trim or enter distance:"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionModifyTrimAmount::updateMouseButtonHints() +{ + switch (getStatus()) + { + case ChooseTrimEntity: + RS_DIALOGFACTORY->updateMouseWidget( + tr("Select entity to trim or enter distance:"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionModifyTrimAmount::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionModifyTrimAmount::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionModifyTrimAmount::updateToolBar() { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); +void RS_ActionModifyTrimAmount::updateToolBar() +{ + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarModify); } +double RS_ActionModifyTrimAmount::getDistance() +{ + return distance; +} -// EOF +void RS_ActionModifyTrimAmount::setDistance(double d) +{ + distance = d; +} diff --git a/src/actions/rs_actionmodifytrimamount.h b/src/actions/rs_actionmodifytrimamount.h index a26e33f..3cb02c0 100644 --- a/src/actions/rs_actionmodifytrimamount.h +++ b/src/actions/rs_actionmodifytrimamount.h @@ -1,35 +1,10 @@ -/**************************************************************************** -** $Id: rs_actionmodifytrimamount.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONMODIFYTRIMAMOUNT_H #define RS_ACTIONMODIFYTRIMAMOUNT_H #include "rs_previewactioninterface.h" -#include "rs_modification.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to trim entities by a given @@ -37,64 +12,39 @@ * * @author Andrew Mustun */ -class RS_ActionModifyTrimAmount : public RS_ActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - ChooseTrimEntity /**< Choosing the entity to trim. */ - }; - -public: - RS_ActionModifyTrimAmount(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionModifyTrimAmount() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionModifyTrimAmount; - } - - virtual void init(int status=0); - - virtual void trigger(); - - //virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void hideOptions(); - virtual void showOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - double getDistance() { - return distance; - } - - void setDistance(double d) { - distance = d; - } - -private: - RS_Entity* trimEntity; - Vector trimCoord; - double distance; - /** - * Commands - */ - /* - QString cmdDistance; - QString cmdDistance2; - QString cmdDistance3; - */ +class RS_ActionModifyTrimAmount: public RS_ActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + ChooseTrimEntity /**< Choosing the entity to trim. */ + }; + + public: + RS_ActionModifyTrimAmount(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionModifyTrimAmount(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); + //virtual void mouseMoveEvent(QMouseEvent* e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void hideOptions(); + virtual void showOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + double getDistance(); + void setDistance(double d); + + private: + RS_Entity * trimEntity; + Vector trimCoord; + double distance; }; #endif diff --git a/src/actions/rs_actionoptionsdrawing.cpp b/src/actions/rs_actionoptionsdrawing.cpp index 4b220d9..54c866f 100644 --- a/src/actions/rs_actionoptionsdrawing.cpp +++ b/src/actions/rs_actionoptionsdrawing.cpp @@ -1,69 +1,55 @@ -/**************************************************************************** -** $Id: rs_actionoptionsdrawing.cpp 1090 2004-03-16 10:02:59Z js $ -** -** 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_actionoptionsdrawing.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_actionoptionsdrawing.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" #include "rs_graphicview.h" -RS_ActionOptionsDrawing::RS_ActionOptionsDrawing(RS_EntityContainer& container, - RS_GraphicView& graphicView): +RS_ActionOptionsDrawing::RS_ActionOptionsDrawing(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Drawing Options", container, graphicView) { } -QAction* RS_ActionOptionsDrawing::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionOptionsDrawing::~RS_ActionOptionsDrawing() { - QAction * action = new QAction(tr("Current &Drawing Preferences..."), 0); -// QAction* action = new QAction(tr("Drawing"), tr("Current &Drawing Preferences")+"...", -// QKeySequence(), NULL); - action->setStatusTip(tr("Settings for the current Drawing")); - return action; } -void RS_ActionOptionsDrawing::init(int status) +/*virtual*/ RS2::ActionType RS_ActionOptionsDrawing::rtti() { - RS_ActionInterface::init(status); - - trigger(); + return RS2::ActionOptionsDrawing; } +void RS_ActionOptionsDrawing::init(int status) +{ + RS_ActionInterface::init(status); - -void RS_ActionOptionsDrawing::trigger() { - if (graphic!=NULL) { - RS_DIALOGFACTORY->requestOptionsDrawingDialog(*graphic); - RS_DIALOGFACTORY->updateCoordinateWidget(Vector(0.0,0.0), - Vector(0.0,0.0), - true); - graphicView->updateGrid(); - graphicView->redraw(); - } - finish(); + trigger(); } +void RS_ActionOptionsDrawing::trigger() +{ + if (graphic != NULL) + { + RS_DIALOGFACTORY->requestOptionsDrawingDialog(*graphic); + RS_DIALOGFACTORY->updateCoordinateWidget(Vector(0.0, 0.0), + Vector(0.0, 0.0), + true); + graphicView->updateGrid(); + graphicView->redraw(); + } + finish(); +} // EOF diff --git a/src/actions/rs_actionoptionsdrawing.h b/src/actions/rs_actionoptionsdrawing.h index 0fcf434..d9bfc58 100644 --- a/src/actions/rs_actionoptionsdrawing.h +++ b/src/actions/rs_actionoptionsdrawing.h @@ -1,57 +1,23 @@ -/**************************************************************************** -** $Id: rs_actionoptionsdrawing.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONOPTIONSDRAWING_H #define RS_ACTIONOPTIONSDRAWING_H #include "rs_actioninterface.h" - /** - * This action class can handle user events to change general + * This action class can handle user events to change general * application options. * * @author Andrew Mustun */ -class RS_ActionOptionsDrawing : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionOptionsDrawing(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionOptionsDrawing() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionOptionsDrawing; - } - - virtual void init(int status=0); - - virtual void trigger(); +class RS_ActionOptionsDrawing: public RS_ActionInterface +{ + public: + RS_ActionOptionsDrawing(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionOptionsDrawing(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionprintpreview.cpp b/src/actions/rs_actionprintpreview.cpp index 22dc058..e280e57 100644 --- a/src/actions/rs_actionprintpreview.cpp +++ b/src/actions/rs_actionprintpreview.cpp @@ -1,81 +1,66 @@ -/**************************************************************************** -** $Id: rs_actionprintpreview.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_actionprintpreview.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_actionprintpreview.h" -//Added by qt3to4: -#include + +#include "rs_dialogfactory.h" +#include "drawing.h" +#include "rs_graphicview.h" /** * Constructor. */ -RS_ActionPrintPreview::RS_ActionPrintPreview(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Print Preview", - container, graphicView) { - showOptions(); +RS_ActionPrintPreview::RS_ActionPrintPreview(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Print Preview", + container, graphicView) +{ + showOptions(); } - - -RS_ActionPrintPreview::~RS_ActionPrintPreview() { +RS_ActionPrintPreview::~RS_ActionPrintPreview() +{ } - -QAction* RS_ActionPrintPreview::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +/*virtual*/ RS2::ActionType RS_ActionPrintPreview::rtti() { - QAction * action = new QAction(QIcon(":/res/fileprintpreview.png"), tr("Print Pre&view"), 0); -// QAction* action = new QAction(tr("Print Preview"), QPixmap::fromMimeSource("fileprintpreview.png"), tr("Print Pre&view"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Shows a preview of a print")); - return action; + return RS2::ActionPrintPreview; } - -void RS_ActionPrintPreview::init(int status) { - RS_ActionInterface::init(status); - showOptions(); +void RS_ActionPrintPreview::init(int status) +{ + RS_ActionInterface::init(status); + showOptions(); } +void RS_ActionPrintPreview::trigger() +{ +} - - -void RS_ActionPrintPreview::trigger() {} - - - -void RS_ActionPrintPreview::mouseMoveEvent(QMouseEvent* e) { - switch (getStatus()) { +void RS_ActionPrintPreview::mouseMoveEvent(QMouseEvent * e) +{ + switch (getStatus()) + { case Moving: v2 = graphicView->toGraph(e->x(), e->y()); - if (graphic!=NULL) { + + if (graphic != NULL) + { Vector pinsbase = graphic->getPaperInsertionBase(); double scale = graphic->getPaperScale(); - graphic->setPaperInsertionBase(pinsbase-v2*scale+v1*scale); + graphic->setPaperInsertionBase(pinsbase - v2 * scale + v1 * scale); } v1 = v2; graphicView->redraw(); @@ -86,137 +71,133 @@ void RS_ActionPrintPreview::mouseMoveEvent(QMouseEvent* e) { } } - - -void RS_ActionPrintPreview::mousePressEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case Neutral: - v1 = graphicView->toGraph(e->x(), e->y()); - setStatus(Moving); - break; - - default: - break; - } - } +void RS_ActionPrintPreview::mousePressEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case Neutral: + v1 = graphicView->toGraph(e->x(), e->y()); + setStatus(Moving); + break; + + default: + break; + } + } } - -void RS_ActionPrintPreview::mouseReleaseEvent(QMouseEvent* e) { - switch (getStatus()) { +void RS_ActionPrintPreview::mouseReleaseEvent(QMouseEvent * e) +{ + switch (getStatus()) + { case Moving: setStatus(Neutral); break; - default: - //deleteSnapper(); - RS_DIALOGFACTORY->requestPreviousMenu(); -#if QT_VERSION>=0x030000 - e->accept(); + default: + //deleteSnapper(); + RS_DIALOGFACTORY->requestPreviousMenu(); +#if QT_VERSION >= 0x030000 + e->accept(); #endif - break; + break; } } - - -void RS_ActionPrintPreview::coordinateEvent(RS_CoordinateEvent* ) {} - - - -void RS_ActionPrintPreview::commandEvent(RS_CommandEvent* ) {} - - - -QStringList RS_ActionPrintPreview::getAvailableCommands() { - QStringList cmd; - return cmd; +void RS_ActionPrintPreview::coordinateEvent(Vector *) +{ } - -void RS_ActionPrintPreview::showOptions() { - RS_ActionInterface::showOptions(); - - RS_DIALOGFACTORY->requestOptions(this, true); +void RS_ActionPrintPreview::commandEvent(RS_CommandEvent *) +{ } - - -void RS_ActionPrintPreview::hideOptions() { - RS_ActionInterface::hideOptions(); - - RS_DIALOGFACTORY->requestOptions(this, false); +QStringList RS_ActionPrintPreview::getAvailableCommands() +{ + QStringList cmd; + return cmd; } +void RS_ActionPrintPreview::showOptions() +{ + RS_ActionInterface::showOptions(); -void RS_ActionPrintPreview::updateMouseButtonHints() {} - - - -void RS_ActionPrintPreview::updateMouseCursor() { - graphicView->setMouseCursor(RS2::MovingHandCursor); + RS_DIALOGFACTORY->requestOptions(this, true); } +void RS_ActionPrintPreview::hideOptions() +{ + RS_ActionInterface::hideOptions(); + RS_DIALOGFACTORY->requestOptions(this, false); +} -void RS_ActionPrintPreview::updateToolBar() {} - +void RS_ActionPrintPreview::updateMouseButtonHints() +{ +} -void RS_ActionPrintPreview::center() { - if (graphic!=NULL) { - graphic->centerToPage(); - graphicView->redraw(); - } +void RS_ActionPrintPreview::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::MovingHandCursor); } +void RS_ActionPrintPreview::updateToolBar() +{ +} -void RS_ActionPrintPreview::fit() { - if (graphic!=NULL) { - graphic->fitToPage(); - graphicView->redraw(); - } +void RS_ActionPrintPreview::center() +{ + if (graphic != NULL) + { + graphic->centerToPage(); + graphicView->redraw(); + } } +void RS_ActionPrintPreview::fit() +{ + if (graphic != NULL) + { + graphic->fitToPage(); + graphicView->redraw(); + } +} -void RS_ActionPrintPreview::setScale(double f) { - if (graphic!=NULL) { +void RS_ActionPrintPreview::setScale(double f) +{ + if (graphic != NULL) + { graphic->setPaperScale(f); - graphicView->redraw(); + graphicView->redraw(); } } - - -double RS_ActionPrintPreview::getScale() { +double RS_ActionPrintPreview::getScale() +{ double ret = 1.0; - if (graphic!=NULL) { + + if (graphic != NULL) ret = graphic->getPaperScale(); - } return ret; } - - -void RS_ActionPrintPreview::setBlackWhite(bool bw) { - if (bw) { - graphicView->setDrawingMode(RS2::ModeBW); - } - else { - graphicView->setDrawingMode(RS2::ModeFull); - } +void RS_ActionPrintPreview::setBlackWhite(bool bw) +{ + if (bw) + graphicView->setDrawingMode(RS2::ModeBW); + else + graphicView->setDrawingMode(RS2::ModeFull); graphicView->redraw(); } - -RS2::Unit RS_ActionPrintPreview::getUnit() { - if (graphic!=NULL) { +RS2::Unit RS_ActionPrintPreview::getUnit() +{ + if (graphic != NULL) return graphic->getUnit(); - } - else { + else return RS2::None; - } } - // EOF diff --git a/src/actions/rs_actionprintpreview.h b/src/actions/rs_actionprintpreview.h index c6970f9..3e94eac 100644 --- a/src/actions/rs_actionprintpreview.h +++ b/src/actions/rs_actionprintpreview.h @@ -1,95 +1,54 @@ -/**************************************************************************** -** $Id: rs_actionprintpreview.h 1117 2004-04-09 19:57:47Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONPRINTPREVIEW_H #define RS_ACTIONPRINTPREVIEW_H +#include "rs.h" #include "rs_actioninterface.h" +#include "vector.h" /** * Default action for print preview. * * @author Andrew Mustun */ -class RS_ActionPrintPreview : public RS_ActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - Neutral, - Moving - }; - -public: - RS_ActionPrintPreview(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionPrintPreview(); - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionPrintPreview; - } - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mousePressEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - virtual void commandEvent(RS_CommandEvent* e); - virtual QStringList getAvailableCommands(); - - virtual void showOptions(); - virtual void hideOptions(); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - - void center(); - void fit(); - void setScale(double f); - double getScale(); - - void setBlackWhite(bool bw); - //bool isBlackWhite() { - // return blackWhite; - //} - RS2::Unit getUnit(); - -protected: - //bool blackWhite; - Vector v1; - Vector v2; +class RS_ActionPrintPreview: public RS_ActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + Neutral, + Moving + }; + + public: + RS_ActionPrintPreview(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionPrintPreview(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mousePressEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void commandEvent(RS_CommandEvent * e); + virtual QStringList getAvailableCommands(); + virtual void showOptions(); + virtual void hideOptions(); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + void center(); + void fit(); + void setScale(double f); + double getScale(); + void setBlackWhite(bool bw); + RS2::Unit getUnit(); + + protected: + Vector v1; + Vector v2; }; #endif diff --git a/src/actions/rs_actionselect.cpp b/src/actions/rs_actionselect.cpp index 9f9f04f..88d73b7 100644 --- a/src/actions/rs_actionselect.cpp +++ b/src/actions/rs_actionselect.cpp @@ -1,41 +1,33 @@ -/**************************************************************************** -** $Id: rs_actionselect.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_actionselect.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_actionselect.h" -#include "rs_snapper.h" #include "rs_actionselectsingle.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" -RS_ActionSelect::RS_ActionSelect(RS_EntityContainer & container, - RS_GraphicView & graphicView, RS2::ActionType nextAction): +RS_ActionSelect::RS_ActionSelect(RS_EntityContainer & container, RS_GraphicView & graphicView, RS2::ActionType nextAction): RS_ActionInterface("Select Entities", container, graphicView) { this->nextAction = nextAction; } +RS_ActionSelect::~RS_ActionSelect() +{ +} + void RS_ActionSelect::init(int status) { RS_ActionInterface::init(status); @@ -58,5 +50,3 @@ void RS_ActionSelect::updateToolBar() RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain); } } - -// EOF diff --git a/src/actions/rs_actionselect.h b/src/actions/rs_actionselect.h index cf64298..eb400a4 100644 --- a/src/actions/rs_actionselect.h +++ b/src/actions/rs_actionselect.h @@ -1,55 +1,25 @@ -/**************************************************************************** -** $Id: rs_actionselect.h 1047 2003-11-26 18:14:32Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSELECT_H #define RS_ACTIONSELECT_H #include "rs_actioninterface.h" - /** * This action class can handle user events to select entities. * * @author Andrew Mustun */ -class RS_ActionSelect : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionSelect(RS_EntityContainer& container, - RS_GraphicView& graphicView, - RS2::ActionType nextAction); - ~RS_ActionSelect() {} +class RS_ActionSelect: public RS_ActionInterface +{ + public: + RS_ActionSelect(RS_EntityContainer & container, RS_GraphicView & graphicView, RS2::ActionType nextAction); + ~RS_ActionSelect(); - void init(int status); - //virtual void keyPressEvent(QKeyEvent* e); - void mouseReleaseEvent(QMouseEvent* e); - void updateToolBar(); + void init(int status); + void mouseReleaseEvent(QMouseEvent * e); + void updateToolBar(); -private: - RS2::ActionType nextAction; + private: + RS2::ActionType nextAction; }; #endif diff --git a/src/actions/rs_actionselectall.cpp b/src/actions/rs_actionselectall.cpp index b3a0e22..9a58bfe 100644 --- a/src/actions/rs_actionselectall.cpp +++ b/src/actions/rs_actionselectall.cpp @@ -9,43 +9,29 @@ // // Who When What // --- ---------- ----------------------------------------------------------- -// JLH 05/22/2010 Added this text. :-) +// JLH 06/22/2010 Added this text. :-) // #include "rs_actionselectall.h" + +#include "rs_dialogfactory.h" #include "rs_selection.h" -RS_ActionSelectAll::RS_ActionSelectAll(RS_EntityContainer& container, - RS_GraphicView& graphicView, bool select): +RS_ActionSelectAll::RS_ActionSelectAll(RS_EntityContainer & container, + RS_GraphicView & graphicView, bool select): RS_ActionInterface("Select All Entities", container, graphicView) { - this->select = select; + this->select = select; } -QAction * RS_ActionSelectAll::createGUIAction(RS2::ActionType type, QObject * parent) +RS_ActionSelectAll::~RS_ActionSelectAll() { - QAction * action; - - if (type == RS2::ActionSelectAll) - { - action = new QAction(tr("Select &All"), parent); - action->setShortcut(Qt::CTRL + Qt::Key_A); -// action = new QAction(tr("Select All"), tr("Select &All"), -// CTRL+Key_A, parent); - action->setStatusTip(tr("Selects all Entities")); - } - else - { - action = new QAction(tr("Deselect &all"), parent); - action->setShortcut(Qt::CTRL + Qt::Key_K); -// action = new QAction(tr("Deselect all"), tr("Deselect &all"), -// CTRL+Key_K, parent); - action->setStatusTip(tr("Deselects all Entities")); - } - - return action; } +/*virtual*/ RS2::ActionType RS_ActionSelectAll::rtti() +{ + return RS2::ActionSelectAll; +} void RS_ActionSelectAll::init(int status) { @@ -61,5 +47,3 @@ void RS_ActionSelectAll::trigger() RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } - -// EOF diff --git a/src/actions/rs_actionselectall.h b/src/actions/rs_actionselectall.h index d032c43..c12d028 100644 --- a/src/actions/rs_actionselectall.h +++ b/src/actions/rs_actionselectall.h @@ -3,31 +3,23 @@ #include "rs_actioninterface.h" - /** * This action class can handle user events to select all entities. * * @author Andrew Mustun */ -class RS_ActionSelectAll : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionSelectAll(RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool select); - ~RS_ActionSelectAll() {} - - static QAction* createGUIAction(RS2::ActionType type, QObject* parent); - - virtual RS2::ActionType rtti() { - return RS2::ActionSelectAll; - } - - void init(int status); - virtual void trigger(); - -protected: - bool select; +class RS_ActionSelectAll: public RS_ActionInterface +{ + public: + RS_ActionSelectAll(RS_EntityContainer & container, RS_GraphicView & graphicView, bool select); + ~RS_ActionSelectAll(); + + virtual RS2::ActionType rtti(); + void init(int status); + virtual void trigger(); + + protected: + bool select; }; #endif diff --git a/src/actions/rs_actionselectbase.cpp b/src/actions/rs_actionselectbase.cpp index d8a3d49..c065235 100644 --- a/src/actions/rs_actionselectbase.cpp +++ b/src/actions/rs_actionselectbase.cpp @@ -1,56 +1,42 @@ -/**************************************************************************** -** $Id: rs_actionselectbase.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_actionselectbase.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_actionselectbase.h" +#include "rs_graphicview.h" +RS_ActionSelectBase::RS_ActionSelectBase(const char * name, + RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface(name, container, graphicView) +{ +} -RS_ActionSelectBase::RS_ActionSelectBase(const char* name, - RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface(name, - container, graphicView) {} - - +RS_ActionSelectBase::~RS_ActionSelectBase() +{ +} /** * Default behaviour of this method is triggering the predecesing * action and finishing this one when the enter key is pressed. */ -void RS_ActionSelectBase::keyReleaseEvent(QKeyEvent* e) { - if (e->key()==Qt::Key_Return && predecessor!=NULL) { - finish(); - } +void RS_ActionSelectBase::keyReleaseEvent(QKeyEvent * e) +{ + if (e->key() == Qt::Key_Return && predecessor != NULL) + finish(); } - - -void RS_ActionSelectBase::updateMouseCursor() { - graphicView->setMouseCursor(RS2::SelectCursor); +void RS_ActionSelectBase::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::SelectCursor); } - - -// EOF diff --git a/src/actions/rs_actionselectbase.h b/src/actions/rs_actionselectbase.h index 9cf25ef..0908ffc 100644 --- a/src/actions/rs_actionselectbase.h +++ b/src/actions/rs_actionselectbase.h @@ -1,50 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionselectbase.h 973 2003-08-09 22:39:50Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSELECTBASE_H #define RS_ACTIONSELECTBASE_H #include "rs_actioninterface.h" - /** * This class is the base class to all select actions. * * @author Andrew Mustun */ -class RS_ActionSelectBase : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionSelectBase(const char* name, - RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionSelectBase() {} +class RS_ActionSelectBase: public RS_ActionInterface +{ + public: + RS_ActionSelectBase(const char * name, RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionSelectBase(); - virtual void keyReleaseEvent(QKeyEvent* e); - virtual void updateMouseCursor(); + virtual void keyReleaseEvent(QKeyEvent * e); + virtual void updateMouseCursor(); }; #endif diff --git a/src/actions/rs_actionselectcontour.cpp b/src/actions/rs_actionselectcontour.cpp index ccad43a..378a905 100644 --- a/src/actions/rs_actionselectcontour.cpp +++ b/src/actions/rs_actionselectcontour.cpp @@ -1,88 +1,73 @@ -/**************************************************************************** -** $Id: rs_actionselectcontour.cpp 1134 2004-07-13 23:26:13Z 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_actionselectcontour.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_actionselectcontour.h" +#include "rs_dialogfactory.h" #include "rs_selection.h" -#include "rs_snapper.h" - - -RS_ActionSelectContour::RS_ActionSelectContour(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Select Contours", container, graphicView) { - - en = NULL; +RS_ActionSelectContour::RS_ActionSelectContour(RS_EntityContainer & container, + RS_GraphicView & graphicView): + RS_ActionInterface("Select Contours", container, graphicView) +{ + en = NULL; } -QAction* RS_ActionSelectContour::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionSelectContour::~RS_ActionSelectContour() { - QAction * action = new QAction(tr("(De-)Select &Contour"), 0); -// QAction* action = new QAction(tr("(De-)Select Contour"), tr("(De-)Select &Contour"), -// QKeySequence(), NULL); - action->setStatusTip(tr("(De-)Selects connected entities")); - return action; } - -void RS_ActionSelectContour::trigger() { - if (en!=NULL) { - if (en->isAtomic()) { - RS_Selection s(*container, graphicView); - s.selectContour(en); - - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } - } else { - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->commandMessage( - tr("Entity must be an Atomic Entity.")); - } - } - } else { - RS_DEBUG->print("RS_ActionSelectContour::trigger: Entity is NULL\n"); - } +/*virtual*/ RS2::ActionType RS_ActionSelectContour::rtti() +{ + return RS2::ActionSelectContour; } - - -void RS_ActionSelectContour::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - init(getStatus()-1); - } else { - en = catchEntity(e); - trigger(); - } +void RS_ActionSelectContour::trigger() +{ + if (en != NULL) + { + if (en->isAtomic()) + { + RS_Selection s(*container, graphicView); + s.selectContour(en); + + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } + else if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->commandMessage( + tr("Entity must be an Atomic Entity.")); + + } + else + RS_DEBUG->print("RS_ActionSelectContour::trigger: Entity is NULL\n"); } +void RS_ActionSelectContour::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + init(getStatus() - 1); + else + { + en = catchEntity(e); + trigger(); + } +} - -void RS_ActionSelectContour::updateMouseCursor() { - graphicView->setMouseCursor(RS2::SelectCursor); +void RS_ActionSelectContour::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::SelectCursor); } // EOF diff --git a/src/actions/rs_actionselectcontour.h b/src/actions/rs_actionselectcontour.h index 63947a0..7e32c54 100644 --- a/src/actions/rs_actionselectcontour.h +++ b/src/actions/rs_actionselectcontour.h @@ -1,59 +1,28 @@ -/**************************************************************************** -** $Id: rs_actionselectcontour.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSELECTCONTOURS_H #define RS_ACTIONSELECTCONTOURS_H #include "rs_actioninterface.h" +class RS_Entity; /** * This action class can handle user events to select contours. * * @author Andrew Mustun */ -class RS_ActionSelectContour : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionSelectContour(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionSelectContour() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionSelectContour; - } - - virtual void trigger(); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseCursor(); - -private: - RS_Entity* en; +class RS_ActionSelectContour: public RS_ActionInterface +{ + public: + RS_ActionSelectContour(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionSelectContour(); + + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseCursor(); + + private: + RS_Entity * en; }; #endif diff --git a/src/actions/rs_actionselectintersected.cpp b/src/actions/rs_actionselectintersected.cpp index 7d6e25c..dc158d5 100644 --- a/src/actions/rs_actionselectintersected.cpp +++ b/src/actions/rs_actionselectintersected.cpp @@ -14,9 +14,9 @@ #include "rs_actionselectintersected.h" -#include "rs.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" #include "rs_selection.h" +#include "rs_preview.h" /** * Constructor. @@ -24,149 +24,138 @@ * @param select true: select window. false: deselect window */ RS_ActionSelectIntersected::RS_ActionSelectIntersected( - RS_EntityContainer& container, RS_GraphicView& graphicView, bool select): + RS_EntityContainer & container, RS_GraphicView & graphicView, bool select): RS_PreviewActionInterface("Select Intersected", container, graphicView) { this->select = select; } -QAction * RS_ActionSelectIntersected::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +RS_ActionSelectIntersected::~RS_ActionSelectIntersected() { - QAction * action; - - if (type == RS2::ActionSelectIntersected) - { - action = new QAction(tr("In&tersected Entities"), 0); -// action = new QAction(tr("Select Intersected Entities"), tr("In&tersected Entities"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Selects all entities intersected by a line")); - } - else - { - action = new QAction(tr("Deselect Inte&rsected Entities"), 0); -// action = new QAction(tr("Deselect Intersected Entities"), -// tr("Deselect Inte&rsected Entities"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Deselects all entities intersected by a line")); - } +} - return action; +/*virtual*/ RS2::ActionType RS_ActionSelectIntersected::rtti() +{ + return RS2::ActionSelectIntersected; } void RS_ActionSelectIntersected::init(int status) { - RS_PreviewActionInterface::init(status); + RS_PreviewActionInterface::init(status); - v1 = v2 = Vector(false); - snapMode = RS2::SnapFree; - snapRes = RS2::RestrictNothing; + v1 = v2 = Vector(false); + snapMode = RS2::SnapFree; + snapRes = RS2::RestrictNothing; } void RS_ActionSelectIntersected::trigger() { - RS_PreviewActionInterface::trigger(); + RS_PreviewActionInterface::trigger(); - if (v1.valid && v2.valid) { - if (graphicView->toGuiDX(v1.distanceTo(v2))>10) { - deleteSnapper(); + if (v1.valid && v2.valid) + if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10) + { + deleteSnapper(); - RS_Selection s(*container, graphicView); - s.selectIntersected(v1, v2, select); + RS_Selection s(*container, graphicView); + s.selectIntersected(v1, v2, select); - if (RS_DIALOGFACTORY!=NULL) { - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - init(); - } - } + init(); + } } -void RS_ActionSelectIntersected::mouseMoveEvent(QMouseEvent* e) +void RS_ActionSelectIntersected::mouseMoveEvent(QMouseEvent * e) { - if (getStatus()==SetPoint2 && v1.valid) { - v2 = snapPoint(e); - deletePreview(); - clearPreview(); - preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v1.x, v1.y), - Vector(v2.x, v2.y)))); - drawPreview(); - } + if (getStatus() == SetPoint2 && v1.valid) + { + v2 = snapPoint(e); + deletePreview(); + clearPreview(); + preview->addEntity(new RS_Line(preview, + RS_LineData(Vector(v1.x, v1.y), + Vector(v2.x, v2.y)))); + drawPreview(); + } } +void RS_ActionSelectIntersected::mousePressEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case SetPoint1: + v1 = snapPoint(e); + setStatus(SetPoint2); + break; + + default: + break; + } + } - -void RS_ActionSelectIntersected::mousePressEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetPoint1: - v1 = snapPoint(e); - setStatus(SetPoint2); - break; - - default: - break; - } - } - - RS_DEBUG->print("RS_ActionSelectIntersected::mousePressEvent(): %f %f", - v1.x, v1.y); + RS_DEBUG->print("RS_ActionSelectIntersected::mousePressEvent(): %f %f", + v1.x, v1.y); } +void RS_ActionSelectIntersected::mouseReleaseEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionSelectIntersected::mouseReleaseEvent()"); - -void RS_ActionSelectIntersected::mouseReleaseEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionSelectIntersected::mouseReleaseEvent()"); - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - if (getStatus()==SetPoint2) { - deletePreview(); - } - deleteSnapper(); - init(getStatus()-1); - } else if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - if (getStatus()==SetPoint2) { - v2 = snapPoint(e); - trigger(); - } - } + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + if (getStatus() == SetPoint2) + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + if (getStatus() == SetPoint2) + { + v2 = snapPoint(e); + trigger(); + } } - - -void RS_ActionSelectIntersected::updateMouseButtonHints() { - if (RS_DIALOGFACTORY!=NULL) { - switch (getStatus()) { - case SetPoint1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first point of intersection line"), tr("Cancel")); - break; - case SetPoint2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second point of intersection line"), tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } - } +void RS_ActionSelectIntersected::updateMouseButtonHints() +{ + if (RS_DIALOGFACTORY != NULL) + { + switch (getStatus()) + { + case SetPoint1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first point of intersection line"), tr("Cancel")); + break; + + case SetPoint2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second point of intersection line"), tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } + } } - - -void RS_ActionSelectIntersected::updateMouseCursor() { - graphicView->setMouseCursor(RS2::SelectCursor); +void RS_ActionSelectIntersected::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::SelectCursor); } - - -void RS_ActionSelectIntersected::updateToolBar() { - if (RS_DIALOGFACTORY!=NULL) { - if (!isFinished()) { - //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); - } - } +void RS_ActionSelectIntersected::updateToolBar() +{ + if (RS_DIALOGFACTORY != NULL) + { + if (!isFinished()) + //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); + } } // EOF diff --git a/src/actions/rs_actionselectintersected.h b/src/actions/rs_actionselectintersected.h index 4217c85..9697d1e 100644 --- a/src/actions/rs_actionselectintersected.h +++ b/src/actions/rs_actionselectintersected.h @@ -4,52 +4,41 @@ #include "rs_previewactioninterface.h" #include "vector.h" - /** * This action class can handle user events to select all entities. * * @author Andrew Mustun */ -class RS_ActionSelectIntersected : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetPoint1, /**< Setting the 1st corner of the window. */ - SetPoint2 /**< Setting the 2nd corner of the window. */ - }; - -public: - RS_ActionSelectIntersected(RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool select); - ~RS_ActionSelectIntersected() {} - - static QAction* createGUIAction(RS2::ActionType type, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionSelectIntersected; - } - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mousePressEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - Vector v1; - Vector v2; - - bool select; +class RS_ActionSelectIntersected: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetPoint1, /**< Setting the 1st corner of the window. */ + SetPoint2 /**< Setting the 2nd corner of the window. */ + }; + + public: + RS_ActionSelectIntersected(RS_EntityContainer & container, RS_GraphicView & graphicView, bool select); + ~RS_ActionSelectIntersected(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mousePressEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + Vector v1; + Vector v2; + + bool select; }; #endif diff --git a/src/actions/rs_actionselectinvert.cpp b/src/actions/rs_actionselectinvert.cpp index ff31d27..8451e14 100644 --- a/src/actions/rs_actionselectinvert.cpp +++ b/src/actions/rs_actionselectinvert.cpp @@ -1,60 +1,48 @@ -/**************************************************************************** -** $Id: rs_actionselectinvert.cpp 1062 2004-01-16 21:51:20Z 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_actionselectinvert.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/05/2010 Added this text. :-) +// #include "rs_actionselectinvert.h" + +#include "rs_dialogfactory.h" #include "rs_selection.h" -RS_ActionSelectInvert::RS_ActionSelectInvert(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Invert Selection", - container, graphicView) { +RS_ActionSelectInvert::RS_ActionSelectInvert(RS_EntityContainer & container, + RS_GraphicView & graphicView): RS_ActionInterface("Invert Selection", + container, graphicView) +{ } - -QAction* RS_ActionSelectInvert::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionSelectInvert::~RS_ActionSelectInvert() { - QAction * action = new QAction(tr("&Invert Selection"), 0); -// QAction* action = new QAction(tr("Invert Selection"), tr("&Invert Selection"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Inverts the current selection")); - return action; } +/*virtual*/ RS2::ActionType RS_ActionSelectInvert::rtti() +{ + return RS2::ActionSelectInvert; +} -void RS_ActionSelectInvert::init(int status) { - RS_ActionInterface::init(status); - trigger(); - finish(); +void RS_ActionSelectInvert::init(int status) +{ + RS_ActionInterface::init(status); + trigger(); + finish(); } -void RS_ActionSelectInvert::trigger() { - RS_Selection s(*container, graphicView); - s.invertSelection(); +void RS_ActionSelectInvert::trigger() +{ + RS_Selection s(*container, graphicView); + s.invertSelection(); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); } - -// EOF diff --git a/src/actions/rs_actionselectinvert.h b/src/actions/rs_actionselectinvert.h index a55ba95..5a4a2bb 100644 --- a/src/actions/rs_actionselectinvert.h +++ b/src/actions/rs_actionselectinvert.h @@ -1,55 +1,22 @@ -/**************************************************************************** -** $Id: rs_actionselectinvert.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSELECTINVERT_H #define RS_ACTIONSELECTINVERT_H #include "rs_actioninterface.h" - /** * This action class can handle user events to select all entities. * * @author Andrew Mustun */ -class RS_ActionSelectInvert : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionSelectInvert(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionSelectInvert() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionSelectInvert; - } - - void init(int status); - virtual void trigger(); +class RS_ActionSelectInvert: public RS_ActionInterface +{ + public: + RS_ActionSelectInvert(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionSelectInvert(); + + virtual RS2::ActionType rtti(); + void init(int status); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionselectlayer.cpp b/src/actions/rs_actionselectlayer.cpp index 8832416..933d012 100644 --- a/src/actions/rs_actionselectlayer.cpp +++ b/src/actions/rs_actionselectlayer.cpp @@ -1,79 +1,65 @@ -/**************************************************************************** -** $Id: rs_actionselectlayer.cpp 1134 2004-07-13 23:26:13Z 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_actionselectlayer.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/05/2010 Added this text. :-) +// #include "rs_actionselectlayer.h" +#include "rs_dialogfactory.h" #include "rs_selection.h" -RS_ActionSelectLayer::RS_ActionSelectLayer(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Select Layers", container, graphicView) { +RS_ActionSelectLayer::RS_ActionSelectLayer(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Select Layers", container, graphicView) +{ + en = NULL; +} - en = NULL; +RS_ActionSelectLayer::~RS_ActionSelectLayer() +{ } -QAction* RS_ActionSelectLayer::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +/*virtual*/ RS2::ActionType RS_ActionSelectLayer::rtti() { - QAction * action = new QAction(tr("(De-)Select Layer"), 0); -// QAction* action = new QAction(tr("(De-)Select Layer"), tr("(De-)Select Layer"), -// QKeySequence(), NULL); - action->setStatusTip(tr("(De-)Selects layers")); - return action; + return RS2::ActionSelectLayer; } void RS_ActionSelectLayer::trigger() { - if (en != NULL) + if (en != NULL) { - RS_Selection s(*container, graphicView); - s.selectLayer(en); - if (RS_DIALOGFACTORY!=NULL) - { - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } - } else { - RS_DEBUG->print("RS_ActionSelectLayer::trigger: Entity is NULL\n"); - } -} - - + RS_Selection s(*container, graphicView); + s.selectLayer(en); -void RS_ActionSelectLayer::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - init(getStatus()-1); - } else { - en = catchEntity(e); - trigger(); - } + if (RS_DIALOGFACTORY != NULL) + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } + else + RS_DEBUG->print("RS_ActionSelectLayer::trigger: Entity is NULL\n"); } +void RS_ActionSelectLayer::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + init(getStatus() - 1); + else + { + en = catchEntity(e); + trigger(); + } +} - -void RS_ActionSelectLayer::updateMouseCursor() { - graphicView->setMouseCursor(RS2::SelectCursor); +void RS_ActionSelectLayer::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::SelectCursor); } // EOF diff --git a/src/actions/rs_actionselectlayer.h b/src/actions/rs_actionselectlayer.h index 049ca79..6c6e714 100644 --- a/src/actions/rs_actionselectlayer.h +++ b/src/actions/rs_actionselectlayer.h @@ -1,59 +1,28 @@ -/**************************************************************************** -** $Id: rs_actionselectlayer.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSELECTLAYER_H #define RS_ACTIONSELECTLAYER_H #include "rs_actioninterface.h" +class RS_Entity; /** * This action class can handle user events to select contours. * * @author Andrew Mustun */ -class RS_ActionSelectLayer : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionSelectLayer(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionSelectLayer() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionSelectLayer; - } - - virtual void trigger(); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseCursor(); - -private: - RS_Entity* en; +class RS_ActionSelectLayer: public RS_ActionInterface +{ + public: + RS_ActionSelectLayer(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionSelectLayer(); + + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseCursor(); + + private: + RS_Entity * en; }; #endif diff --git a/src/actions/rs_actionselectsingle.cpp b/src/actions/rs_actionselectsingle.cpp index 7f1fac0..507b11c 100644 --- a/src/actions/rs_actionselectsingle.cpp +++ b/src/actions/rs_actionselectsingle.cpp @@ -1,86 +1,70 @@ -/**************************************************************************** -** $Id: rs_actionselectsingle.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_actionselectsingle.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/05/2010 Added this text. :-) +// #include "rs_actionselectsingle.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" #include "rs_selection.h" - - -RS_ActionSelectSingle::RS_ActionSelectSingle(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Select Entities", container, graphicView) { - - en = NULL; +RS_ActionSelectSingle::RS_ActionSelectSingle(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Select Entities", container, graphicView) +{ + en = NULL; } - -QAction* RS_ActionSelectSingle::createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/) +RS_ActionSelectSingle::~RS_ActionSelectSingle() { - QAction * action = new QAction(tr("(De-)&Select Entity"), 0); -// QAction* action = new QAction(tr("Select Entity"), tr("(De-)&Select Entity"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Selects single Entities")); - return action; } - -void RS_ActionSelectSingle::trigger() { - if (en!=NULL) { - RS_Selection s(*container, graphicView); - s.selectSingle(en); - - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - } else { - RS_DEBUG->print("RS_ActionSelectSingle::trigger: Entity is NULL\n"); - } +/*virtual*/ RS2::ActionType RS_ActionSelectSingle::rtti() +{ + return RS2::ActionSelectSingle; } - -void RS_ActionSelectSingle::keyPressEvent(QKeyEvent* e) { - if (e->key()==Qt::Key_Enter) { - finish(); - } +void RS_ActionSelectSingle::trigger() +{ + if (en != NULL) + { + RS_Selection s(*container, graphicView); + s.selectSingle(en); + + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + } + else + RS_DEBUG->print("RS_ActionSelectSingle::trigger: Entity is NULL\n"); } - -void RS_ActionSelectSingle::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - init(getStatus()-1); - } else { - en = catchEntity(e); - trigger(); - } +void RS_ActionSelectSingle::keyPressEvent(QKeyEvent * e) +{ + if (e->key() == Qt::Key_Enter) + finish(); } +void RS_ActionSelectSingle::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + init(getStatus() - 1); + else + { + en = catchEntity(e); + trigger(); + } +} - -void RS_ActionSelectSingle::updateMouseCursor() { - graphicView->setMouseCursor(RS2::SelectCursor); +void RS_ActionSelectSingle::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::SelectCursor); } // EOF diff --git a/src/actions/rs_actionselectsingle.h b/src/actions/rs_actionselectsingle.h index e822374..17e9547 100644 --- a/src/actions/rs_actionselectsingle.h +++ b/src/actions/rs_actionselectsingle.h @@ -1,60 +1,29 @@ -/**************************************************************************** -** $Id: rs_actionselectsingle.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSELECTSINGLE_H #define RS_ACTIONSELECTSINGLE_H #include "rs_actioninterface.h" +class RS_Entity; /** * This action class can handle user events to select entities. * * @author Andrew Mustun */ -class RS_ActionSelectSingle : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionSelectSingle(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionSelectSingle() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionSelectSingle; - } - - virtual void trigger(); - virtual void keyPressEvent(QKeyEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseCursor(); - -private: - RS_Entity* en; +class RS_ActionSelectSingle: public RS_ActionInterface +{ + public: + RS_ActionSelectSingle(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionSelectSingle(); + + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void keyPressEvent(QKeyEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseCursor(); + + private: + RS_Entity * en; }; #endif diff --git a/src/actions/rs_actionselectwindow.cpp b/src/actions/rs_actionselectwindow.cpp index 8351f85..f0da9bf 100644 --- a/src/actions/rs_actionselectwindow.cpp +++ b/src/actions/rs_actionselectwindow.cpp @@ -14,167 +14,155 @@ #include "rs_actionselectwindow.h" -#include "rs.h" -#include "rs_snapper.h" +#include "rs_dialogfactory.h" #include "rs_selection.h" +#include "rs_preview.h" /** * Constructor. * * @param select true: select window. false: deselect window */ -RS_ActionSelectWindow::RS_ActionSelectWindow(RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool select) - : RS_PreviewActionInterface("Select Window", - container, graphicView) { - - this->select = select; +RS_ActionSelectWindow::RS_ActionSelectWindow(RS_EntityContainer & container, + RS_GraphicView & graphicView, bool select): + RS_PreviewActionInterface("Select Window", container, graphicView) +{ + this->select = select; } -QAction * RS_ActionSelectWindow::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +RS_ActionSelectWindow::~RS_ActionSelectWindow() { - QAction * action; - - if (type == RS2::ActionSelectWindow) - { - action = new QAction(tr("Select &Window"), 0); -// action = new QAction(tr("Select Window"), tr("Select &Window"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Selects all Entities in a given Window")); - } - else - { - action = new QAction(tr("Deselect &Window"), 0); -// action = new QAction(tr("Deselect Window"), tr("Deselect &Window"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Deselects all Entities in a given Window")); - } +} - return action; +/*virtual*/ RS2::ActionType RS_ActionSelectWindow::rtti() +{ + return RS2::ActionSelectWindow; } void RS_ActionSelectWindow::init(int status) { - RS_PreviewActionInterface::init(status); - v1 = v2 = Vector(false); - snapMode = RS2::SnapFree; - snapRes = RS2::RestrictNothing; + RS_PreviewActionInterface::init(status); + v1 = v2 = Vector(false); + snapMode = RS2::SnapFree; + snapRes = RS2::RestrictNothing; } +void RS_ActionSelectWindow::trigger() +{ + RS_PreviewActionInterface::trigger(); + if (v1.valid && v2.valid) + { + if (graphicView->toGuiDX(v1.distanceTo(v2)) > 10) + { + deleteSnapper(); -void RS_ActionSelectWindow::trigger() { - RS_PreviewActionInterface::trigger(); - - if (v1.valid && v2.valid) { - if (graphicView->toGuiDX(v1.distanceTo(v2))>10) { - deleteSnapper(); - - bool cross = (v2.y>v1.y); + bool cross = (v2.y > v1.y); - RS_Selection s(*container, graphicView); - s.selectWindow(v1, v2, select, cross); + RS_Selection s(*container, graphicView); + s.selectWindow(v1, v2, select, cross); - RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); + RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected()); - init(); - } - } + init(); + } + } } - - -void RS_ActionSelectWindow::mouseMoveEvent(QMouseEvent* e) { - if (getStatus()==SetCorner2 && v1.valid) { - v2 = snapPoint(e); - deletePreview(); - clearPreview(); - preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v1.x, v1.y), - Vector(v2.x, v1.y)))); - preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v2.x, v1.y), - Vector(v2.x, v2.y)))); - preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v2.x, v2.y), - Vector(v1.x, v2.y)))); - preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v1.x, v2.y), - Vector(v1.x, v1.y)))); - drawPreview(); - } +void RS_ActionSelectWindow::mouseMoveEvent(QMouseEvent * e) +{ + if (getStatus() == SetCorner2 && v1.valid) + { + v2 = snapPoint(e); + deletePreview(); + clearPreview(); + preview->addEntity(new RS_Line(preview, + RS_LineData(Vector(v1.x, v1.y), + Vector(v2.x, v1.y)))); + preview->addEntity(new RS_Line(preview, + RS_LineData(Vector(v2.x, v1.y), + Vector(v2.x, v2.y)))); + preview->addEntity(new RS_Line(preview, + RS_LineData(Vector(v2.x, v2.y), + Vector(v1.x, v2.y)))); + preview->addEntity(new RS_Line(preview, + RS_LineData(Vector(v1.x, v2.y), + Vector(v1.x, v1.y)))); + drawPreview(); + } } +void RS_ActionSelectWindow::mousePressEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + switch (getStatus()) + { + case SetCorner1: + v1 = snapPoint(e); + setStatus(SetCorner2); + break; + + default: + break; + } + } - -void RS_ActionSelectWindow::mousePressEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - switch (getStatus()) { - case SetCorner1: - v1 = snapPoint(e); - setStatus(SetCorner2); - break; - - default: - break; - } - } - - RS_DEBUG->print("RS_ActionSelectWindow::mousePressEvent(): %f %f", - v1.x, v1.y); + RS_DEBUG->print("RS_ActionSelectWindow::mousePressEvent(): %f %f", + v1.x, v1.y); } +void RS_ActionSelectWindow::mouseReleaseEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionSelectWindow::mouseReleaseEvent()"); - -void RS_ActionSelectWindow::mouseReleaseEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionSelectWindow::mouseReleaseEvent()"); - - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - if (getStatus()==SetCorner2) { - v2 = snapPoint(e); - trigger(); - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - if (getStatus()==SetCorner2) { - deletePreview(); - } - deleteSnapper(); - init(getStatus()-1); - } + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + if (getStatus() == SetCorner2) + { + v2 = snapPoint(e); + trigger(); + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + if (getStatus() == SetCorner2) + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } +void RS_ActionSelectWindow::updateMouseButtonHints() +{ + switch (getStatus()) + { + case SetCorner1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first edge"), tr("Cancel")); + break; + case SetCorner2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back")); + break; -void RS_ActionSelectWindow::updateMouseButtonHints() { - switch (getStatus()) { - case SetCorner1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Choose first edge"), tr("Cancel")); - break; - case SetCorner2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Choose second edge"), tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionSelectWindow::updateMouseCursor() { - graphicView->setMouseCursor(RS2::SelectCursor); +void RS_ActionSelectWindow::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::SelectCursor); } - - -void RS_ActionSelectWindow::updateToolBar() { - if (!isFinished()) { - //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); - } +void RS_ActionSelectWindow::updateToolBar() +{ + if (!isFinished()) + //RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSelect); } // EOF diff --git a/src/actions/rs_actionselectwindow.h b/src/actions/rs_actionselectwindow.h index 7a38550..856281d 100644 --- a/src/actions/rs_actionselectwindow.h +++ b/src/actions/rs_actionselectwindow.h @@ -4,52 +4,41 @@ #include "rs_previewactioninterface.h" #include "vector.h" - /** * This action class can handle user events to select all entities. * * @author Andrew Mustun */ -class RS_ActionSelectWindow : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - SetCorner1, /**< Setting the 1st corner of the window. */ - SetCorner2 /**< Setting the 2nd corner of the window. */ - }; - -public: - RS_ActionSelectWindow(RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool select); - ~RS_ActionSelectWindow() {} - - static QAction* createGUIAction(RS2::ActionType type, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionSelectWindow; - } - - virtual void init(int status=0); - - virtual void trigger(); - - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mousePressEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -protected: - Vector v1; - Vector v2; - - bool select; +class RS_ActionSelectWindow: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + SetCorner1, /**< Setting the 1st corner of the window. */ + SetCorner2 /**< Setting the 2nd corner of the window. */ + }; + + public: + RS_ActionSelectWindow(RS_EntityContainer & container, RS_GraphicView & graphicView, bool select); + ~RS_ActionSelectWindow(); + + virtual RS2::ActionType rtti(); + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mousePressEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + protected: + Vector v1; + Vector v2; + + bool select; }; #endif diff --git a/src/actions/rs_actionsetrelativezero.cpp b/src/actions/rs_actionsetrelativezero.cpp index f1b2cc4..14c6ff7 100644 --- a/src/actions/rs_actionsetrelativezero.cpp +++ b/src/actions/rs_actionsetrelativezero.cpp @@ -1,118 +1,103 @@ -/**************************************************************************** -** $Id: rs_actionsetrelativezero.cpp 1134 2004-07-13 23:26:13Z 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_actionsetrelativezero.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/05/2010 Added this text. :-) +// #include "rs_actionsetrelativezero.h" -#include "rs_snapper.h" -#include "rs_point.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" - - -RS_ActionSetRelativeZero::RS_ActionSetRelativeZero(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_PreviewActionInterface("Set the relative Zero", - container, graphicView) {} - - -QAction * RS_ActionSetRelativeZero::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionSetRelativeZero::RS_ActionSetRelativeZero(RS_EntityContainer & container, + RS_GraphicView & graphicView): RS_PreviewActionInterface("Set the relative Zero", + container, graphicView) { - QAction * action = new QAction(tr("&Set Relative Zero"), 0); -// QAction* action = new QAction(tr("Set Relative Zero"), tr("&Set Relative Zero"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Set position of the Relative Zero point")); - return action; } - -void RS_ActionSetRelativeZero::trigger() { - bool wasLocked = graphicView->isRelativeZeroLocked(); - if (pt.valid) { - graphicView->lockRelativeZero(false); - graphicView->moveRelativeZero(pt); - graphicView->lockRelativeZero(wasLocked); - } - finish(); +RS_ActionSetRelativeZero::~RS_ActionSetRelativeZero() +{ } - - -void RS_ActionSetRelativeZero::mouseMoveEvent(QMouseEvent* e) { - snapPoint(e); +/*virtual*/ RS2::ActionType RS_ActionSetRelativeZero::rtti() +{ + return RS2::ActionSetRelativeZero; } - - -void RS_ActionSetRelativeZero::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deleteSnapper(); - init(getStatus()-1); - } else { - RS_CoordinateEvent ce(snapPoint(e)); - coordinateEvent(&ce); - } +void RS_ActionSetRelativeZero::trigger() +{ + bool wasLocked = graphicView->isRelativeZeroLocked(); + + if (pt.valid) + { + graphicView->lockRelativeZero(false); + graphicView->moveRelativeZero(pt); + graphicView->lockRelativeZero(wasLocked); + } + finish(); } - - -void RS_ActionSetRelativeZero::coordinateEvent(RS_CoordinateEvent* e) { - if (e==NULL) { - return; - } - - pt = e->getCoordinate(); - trigger(); +void RS_ActionSetRelativeZero::mouseMoveEvent(QMouseEvent * e) +{ + snapPoint(e); } - - -void RS_ActionSetRelativeZero::updateMouseButtonHints() { - switch (getStatus()) { - case 0: - RS_DIALOGFACTORY->updateMouseWidget(tr("Set relative Zero"), tr("Cancel")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionSetRelativeZero::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deleteSnapper(); + init(getStatus() - 1); + } + else + { + Vector ce(snapPoint(e)); + coordinateEvent(&ce); + } } +void RS_ActionSetRelativeZero::coordinateEvent(Vector * e) +{ + if (e == NULL) + return; - -void RS_ActionSetRelativeZero::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); + pt = *e; + trigger(); } +void RS_ActionSetRelativeZero::updateMouseButtonHints() +{ + switch (getStatus()) + { + case 0: + RS_DIALOGFACTORY->updateMouseWidget(tr("Set relative Zero"), tr("Cancel")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } +} +void RS_ActionSetRelativeZero::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); +} -void RS_ActionSetRelativeZero::updateToolBar() { - if (!isFinished()) { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } else { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); - } +void RS_ActionSetRelativeZero::updateToolBar() +{ + if (!isFinished()) + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); + else + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); } // EOF diff --git a/src/actions/rs_actionsetrelativezero.h b/src/actions/rs_actionsetrelativezero.h index ddbaf12..d79978e 100644 --- a/src/actions/rs_actionsetrelativezero.h +++ b/src/actions/rs_actionsetrelativezero.h @@ -1,34 +1,8 @@ -/**************************************************************************** -** $Id: rs_actionsetrelativezero.h 1114 2004-04-04 22:49:45Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSETRELATIVEZERO_H #define RS_ACTIONSETRELATIVEZERO_H #include "rs_previewactioninterface.h" - +#include "vector.h" /** * This action class can handle user events to set @@ -37,31 +11,23 @@ * * @author Ulf Lehnert */ -class RS_ActionSetRelativeZero : public RS_PreviewActionInterface { - //Q_OBJECT -public: - RS_ActionSetRelativeZero(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionSetRelativeZero() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual RS2::ActionType rtti() { - return RS2::ActionSetRelativeZero; - } - - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - - virtual void coordinateEvent(RS_CoordinateEvent* e); - - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - Vector pt; +class RS_ActionSetRelativeZero: public RS_PreviewActionInterface +{ + public: + RS_ActionSetRelativeZero(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionSetRelativeZero(); + + virtual RS2::ActionType rtti(); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void coordinateEvent(Vector * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + Vector pt; }; #endif diff --git a/src/actions/rs_actionsetsnapmode.cpp b/src/actions/rs_actionsetsnapmode.cpp index 089d4a8..3819e44 100644 --- a/src/actions/rs_actionsetsnapmode.cpp +++ b/src/actions/rs_actionsetsnapmode.cpp @@ -1,53 +1,44 @@ -/**************************************************************************** -** $Id: rs_actionsetsnapmode.cpp 945 2003-06-11 06:56:54Z 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_actionsetsnapmode.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/05/2010 Added this text. :-) +// #include "rs_actionsetsnapmode.h" +#include "rs_graphicview.h" + /** * Constructor. * * @param snapMode The new snap mode used from now on. */ -RS_ActionSetSnapMode::RS_ActionSetSnapMode(RS_EntityContainer & container, - RS_GraphicView & graphicView, RS2::SnapMode snapMode): +RS_ActionSetSnapMode::RS_ActionSetSnapMode(RS_EntityContainer & container, RS_GraphicView & graphicView, RS2::SnapMode snapMode): RS_ActionInterface("Set Snap Mode", container, graphicView) { - this->snapMode = snapMode; + this->snapMode = snapMode; +} + +RS_ActionSetSnapMode::~RS_ActionSetSnapMode() +{ } void RS_ActionSetSnapMode::trigger() { - graphicView->setDefaultSnapMode(snapMode); - finish(); + graphicView->setDefaultSnapMode(snapMode); + finish(); } void RS_ActionSetSnapMode::init(int status) { - RS_ActionInterface::init(status); - trigger(); + RS_ActionInterface::init(status); + trigger(); } - -// EOF diff --git a/src/actions/rs_actionsetsnapmode.h b/src/actions/rs_actionsetsnapmode.h index a78e2cd..ebe0c2c 100644 --- a/src/actions/rs_actionsetsnapmode.h +++ b/src/actions/rs_actionsetsnapmode.h @@ -1,53 +1,25 @@ -/**************************************************************************** -** $Id: rs_actionsetsnapmode.h 973 2003-08-09 22:39:50Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSETSNAPMODE_H #define RS_ACTIONSETSNAPMODE_H +#include "rs.h" #include "rs_actioninterface.h" - /** * This action changes the current snap mode. * * @author Andrew Mustun */ -class RS_ActionSetSnapMode : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionSetSnapMode(RS_EntityContainer& container, - RS_GraphicView& graphicView, - RS2::SnapMode snapMode); - ~RS_ActionSetSnapMode() {} +class RS_ActionSetSnapMode: public RS_ActionInterface +{ + public: + RS_ActionSetSnapMode(RS_EntityContainer & container, RS_GraphicView & graphicView, RS2::SnapMode snapMode); + ~RS_ActionSetSnapMode(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); -protected: - RS2::SnapMode snapMode; + protected: + RS2::SnapMode snapMode; }; #endif diff --git a/src/actions/rs_actionsetsnaprestriction.cpp b/src/actions/rs_actionsetsnaprestriction.cpp index 3f8428c..8da558d 100644 --- a/src/actions/rs_actionsetsnaprestriction.cpp +++ b/src/actions/rs_actionsetsnaprestriction.cpp @@ -1,42 +1,36 @@ -/**************************************************************************** -** $Id: rs_actionsetsnaprestriction.cpp 945 2003-06-11 06:56:54Z 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_actionsetsnaprestriction.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/05/2010 Added this text. :-) +// #include "rs_actionsetsnaprestriction.h" +#include "rs_graphicview.h" + /** * Constructor. * * @param snapRes The new snap mode used from now on. * @param set true: set additional snap mode / false: unset */ -RS_ActionSetSnapRestriction::RS_ActionSetSnapRestriction(RS_EntityContainer& container, - RS_GraphicView& graphicView, RS2::SnapRestriction snapRes): +RS_ActionSetSnapRestriction::RS_ActionSetSnapRestriction( + RS_EntityContainer & container, RS_GraphicView & graphicView, RS2::SnapRestriction snapRes): RS_ActionInterface("Set Additional Snap Mode", container, graphicView) { - this->snapRes = snapRes; + this->snapRes = snapRes; +} + +RS_ActionSetSnapRestriction::~RS_ActionSetSnapRestriction() +{ } void RS_ActionSetSnapRestriction::trigger() @@ -50,5 +44,3 @@ void RS_ActionSetSnapRestriction::init(int status) RS_ActionInterface::init(status); trigger(); } - -// EOF diff --git a/src/actions/rs_actionsetsnaprestriction.h b/src/actions/rs_actionsetsnaprestriction.h index ccc4a50..4d3f67d 100644 --- a/src/actions/rs_actionsetsnaprestriction.h +++ b/src/actions/rs_actionsetsnaprestriction.h @@ -1,53 +1,25 @@ -/**************************************************************************** -** $Id: rs_actionsetsnaprestriction.h 973 2003-08-09 22:39:50Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSETSNAPRESTRICTION_H #define RS_ACTIONSETSNAPRESTRICTION_H +#include "rs.h" #include "rs_actioninterface.h" - /** * This action changes the current additional snap mode. * * @author Andrew Mustun */ -class RS_ActionSetSnapRestriction : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionSetSnapRestriction(RS_EntityContainer& container, - RS_GraphicView& graphicView, - RS2::SnapRestriction snapRes); - ~RS_ActionSetSnapRestriction() {} +class RS_ActionSetSnapRestriction: public RS_ActionInterface +{ + public: + RS_ActionSetSnapRestriction(RS_EntityContainer & container, RS_GraphicView & graphicView, RS2::SnapRestriction snapRes); + ~RS_ActionSetSnapRestriction(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); -protected: - RS2::SnapRestriction snapRes; + protected: + RS2::SnapRestriction snapRes; }; #endif diff --git a/src/actions/rs_actionsnapintersectionmanual.cpp b/src/actions/rs_actionsnapintersectionmanual.cpp index 85b16f9..78330b5 100644 --- a/src/actions/rs_actionsnapintersectionmanual.cpp +++ b/src/actions/rs_actionsnapintersectionmanual.cpp @@ -1,39 +1,29 @@ -/**************************************************************************** -** $Id: rs_actionsnapintersectionmanual.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_actionsetsnapintersectionmanual.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/05/2010 Added this text. :-) +// #include "rs_actionsnapintersectionmanual.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" #include "rs_information.h" -#include "rs_snapper.h" +#include "rs_preview.h" /** * @param both Trim both entities. */ RS_ActionSnapIntersectionManual::RS_ActionSnapIntersectionManual( - RS_EntityContainer& container, RS_GraphicView& graphicView): + RS_EntityContainer & container, RS_GraphicView & graphicView): RS_PreviewActionInterface("Trim Entity", container, graphicView) { entity2 = NULL; @@ -41,14 +31,8 @@ RS_ActionSnapIntersectionManual::RS_ActionSnapIntersectionManual( coord = Vector(false); } -QAction * RS_ActionSnapIntersectionManual::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionSnapIntersectionManual::~RS_ActionSnapIntersectionManual() { - QAction * action = new QAction(tr("I&ntersection Manually"), 0); - action->setCheckable(true); -// QAction* action = new QAction(tr("Intersection Manually"), tr("I&ntersection Manually"), -// QKeySequence(), NULL, 0, true); - action->setStatusTip(tr("Snap to intersection points manually")); - return action; } void RS_ActionSnapIntersectionManual::init(int status) @@ -61,142 +45,145 @@ void RS_ActionSnapIntersectionManual::init(int status) void RS_ActionSnapIntersectionManual::trigger() { - RS_DEBUG->print("RS_ActionSnapIntersectionManual::trigger()"); + RS_DEBUG->print("RS_ActionSnapIntersectionManual::trigger()"); - if (entity2!=NULL && entity2->isAtomic() && - entity1!=NULL && entity1->isAtomic()) + if (entity2 != NULL && entity2->isAtomic() + && entity1 != NULL && entity1->isAtomic()) { - VectorSolutions sol = - RS_Information::getIntersection(entity1, entity2, false); - - entity2 = NULL; - entity1 = NULL; - if (predecessor!=NULL) { - Vector ip = sol.getClosest(coord); - - if (ip.valid) { - RS_CoordinateEvent e(ip); - predecessor->coordinateEvent(&e); - } - } - finish(); - } + VectorSolutions sol = RS_Information::getIntersection(entity1, entity2, false); + + entity2 = NULL; + entity1 = NULL; + + if (predecessor != NULL) + { + Vector ip = sol.getClosest(coord); + + if (ip.valid) + { + Vector e(ip); + predecessor->coordinateEvent(&e); + } + } + finish(); + } } +void RS_ActionSnapIntersectionManual::mouseMoveEvent(QMouseEvent * e) +{ + RS_DEBUG->print("RS_ActionSnapIntersectionManual::mouseMoveEvent begin"); + RS_Entity * se = catchEntity(e); + Vector mouse = graphicView->toGraph(e->x(), e->y()); -void RS_ActionSnapIntersectionManual::mouseMoveEvent(QMouseEvent* e) { - RS_DEBUG->print("RS_ActionSnapIntersectionManual::mouseMoveEvent begin"); - - RS_Entity* se = catchEntity(e); - Vector mouse = graphicView->toGraph(e->x(), e->y()); - - switch (getStatus()) { - case ChooseEntity1: - entity1 = se; - break; - - case ChooseEntity2: { - entity2 = se; - coord = mouse; - - VectorSolutions sol = - RS_Information::getIntersection(entity1, entity2, false); - - //for (int i=0; iaddEntity( - new RS_Circle(preview, - RS_CircleData( - ip, - graphicView->toGraphDX(4)))); - drawPreview(); - - RS_DIALOGFACTORY->updateCoordinateWidget(ip, - ip - graphicView->getRelativeZero()); - - } - } - break; - - default: - break; - } - - RS_DEBUG->print("RS_ActionSnapIntersectionManual::mouseMoveEvent end"); + switch (getStatus()) + { + case ChooseEntity1: + entity1 = se; + break; + + case ChooseEntity2: { + entity2 = se; + coord = mouse; + + VectorSolutions sol = + RS_Information::getIntersection(entity1, entity2, false); + + //for (int i=0; iaddEntity( + new RS_Circle(preview, + RS_CircleData( + ip, + graphicView->toGraphDX(4)))); + drawPreview(); + + RS_DIALOGFACTORY->updateCoordinateWidget(ip, + ip - graphicView->getRelativeZero()); + } + } + break; + + default: + break; + } + + RS_DEBUG->print("RS_ActionSnapIntersectionManual::mouseMoveEvent end"); } - - -void RS_ActionSnapIntersectionManual::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - - Vector mouse = graphicView->toGraph(e->x(), e->y()); - RS_Entity* se = catchEntity(e); - - switch (getStatus()) { - case ChooseEntity1: - entity1 = se; - if (entity1!=NULL && entity1->isAtomic()) { - setStatus(ChooseEntity2); - } - break; - - case ChooseEntity2: - entity2 = se; - coord = mouse; - if (entity2!=NULL && entity2->isAtomic() && coord.valid) { - trigger(); - } - break; - - default: - break; - } - } else if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - deletePreview(); - deleteSnapper(); - init(getStatus()-1); - } +void RS_ActionSnapIntersectionManual::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + Vector mouse = graphicView->toGraph(e->x(), e->y()); + RS_Entity * se = catchEntity(e); + + switch (getStatus()) + { + case ChooseEntity1: + entity1 = se; + + if (entity1 != NULL && entity1->isAtomic()) + setStatus(ChooseEntity2); + break; + + case ChooseEntity2: + entity2 = se; + coord = mouse; + + if (entity2 != NULL && entity2->isAtomic() && coord.valid) + trigger(); + break; + + default: + break; + } + } + else if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + { + deletePreview(); + deleteSnapper(); + init(getStatus() - 1); + } } - - -void RS_ActionSnapIntersectionManual::updateMouseButtonHints() { - switch (getStatus()) { - case ChooseEntity1: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"), - tr("Back")); - break; - case ChooseEntity2: - RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"), - tr("Back")); - break; - default: - RS_DIALOGFACTORY->updateMouseWidget("", ""); - break; - } +void RS_ActionSnapIntersectionManual::updateMouseButtonHints() +{ + switch (getStatus()) + { + case ChooseEntity1: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select first entity"), + tr("Back")); + break; + + case ChooseEntity2: + RS_DIALOGFACTORY->updateMouseWidget(tr("Select second entity"), + tr("Back")); + break; + + default: + RS_DIALOGFACTORY->updateMouseWidget("", ""); + break; + } } - - -void RS_ActionSnapIntersectionManual::updateMouseCursor() { - graphicView->setMouseCursor(RS2::CadCursor); +void RS_ActionSnapIntersectionManual::updateMouseCursor() +{ + graphicView->setMouseCursor(RS2::CadCursor); } - - -void RS_ActionSnapIntersectionManual::updateToolBar() { - RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); +void RS_ActionSnapIntersectionManual::updateToolBar() +{ + RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarSnap); } - // EOF diff --git a/src/actions/rs_actionsnapintersectionmanual.h b/src/actions/rs_actionsnapintersectionmanual.h index 467ed32..fca9b25 100644 --- a/src/actions/rs_actionsnapintersectionmanual.h +++ b/src/actions/rs_actionsnapintersectionmanual.h @@ -1,70 +1,43 @@ -/**************************************************************************** -** $Id: rs_actionsnapintersectionmanual.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONSNAPINTERSECTIONMANUAL_H #define RS_ACTIONSNAPINTERSECTIONMANUAL_H #include "rs_previewactioninterface.h" +#include "vector.h" +class RS_Entity; /** * This action class can handle user events to trim entities. * * @author Andrew Mustun */ -class RS_ActionSnapIntersectionManual : public RS_PreviewActionInterface { - //Q_OBJECT -public: - /** - * Action States. - */ - enum Status { - ChooseEntity1, /**< Choosing the 1st entity. */ - ChooseEntity2 /**< Choosing the 2nd entity. */ - }; - -public: - RS_ActionSnapIntersectionManual(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionSnapIntersectionManual() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - virtual void updateToolBar(); - -private: - RS_Entity* entity1; - RS_Entity* entity2; - Vector coord; +class RS_ActionSnapIntersectionManual: public RS_PreviewActionInterface +{ + public: + /** + * Action States. + */ + enum Status { + ChooseEntity1, /**< Choosing the 1st entity. */ + ChooseEntity2 /**< Choosing the 2nd entity. */ + }; + + public: + RS_ActionSnapIntersectionManual(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionSnapIntersectionManual(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + virtual void updateToolBar(); + + private: + RS_Entity * entity1; + RS_Entity * entity2; + Vector coord; }; #endif diff --git a/src/actions/rs_actiontoolregeneratedimensions.cpp b/src/actions/rs_actiontoolregeneratedimensions.cpp index d59f7ee..2ad2048 100644 --- a/src/actions/rs_actiontoolregeneratedimensions.cpp +++ b/src/actions/rs_actiontoolregeneratedimensions.cpp @@ -1,55 +1,36 @@ -/**************************************************************************** -** $Id: rs_actiontoolregeneratedimensions.cpp 1074 2004-02-29 00:30:50Z 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_actiontoolregeneratedimensions.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/05/2010 Added this text. :-) +// #include "rs_actiontoolregeneratedimensions.h" -#include "rs_information.h" +#include "rs_dialogfactory.h" #include "rs_dimension.h" +#include "rs_graphicview.h" +#include "rs_information.h" -RS_ActionToolRegenerateDimensions::RS_ActionToolRegenerateDimensions(RS_EntityContainer& container, - RS_GraphicView& graphicView): +RS_ActionToolRegenerateDimensions::RS_ActionToolRegenerateDimensions(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Tool Regen Dim", container, graphicView) { } -QAction * RS_ActionToolRegenerateDimensions::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionToolRegenerateDimensions::~RS_ActionToolRegenerateDimensions() { - QAction * action = new QAction(tr("&Regenerate Dimension Entities"), 0); -// QAction* action = new QAction(tr("Regenerate Dimension Entities"), -// tr("&Regenerate Dimension Entities"), -// QKeySequence(), NULL); - action->setStatusTip(tr("Regenerates all Dimension Entities")); - - return action; } void RS_ActionToolRegenerateDimensions::init(int status) { RS_ActionInterface::init(status); - trigger(); } @@ -58,19 +39,18 @@ void RS_ActionToolRegenerateDimensions::trigger() RS_DEBUG->print("RS_ActionToolRegenerateDimensions::trigger()"); int num = 0; - for (RS_Entity* e = container->firstEntity(RS2::ResolveNone); - e != NULL; - e = container->nextEntity(RS2::ResolveNone)) + + for(RS_Entity * e = container->firstEntity(RS2::ResolveNone); + e != NULL; e = container->nextEntity(RS2::ResolveNone)) { if (RS_Information::isDimension(e->rtti()) && e->isVisible()) { num++; - if (((RS_Dimension*)e)->getLabel()==";;") - { - ((RS_Dimension*)e)->setLabel(""); - } - ((RS_Dimension*)e)->update(true); + if (((RS_Dimension *)e)->getLabel() == ";;") + ((RS_Dimension *)e)->setLabel(""); + + ((RS_Dimension *)e)->update(true); } } @@ -80,12 +60,9 @@ void RS_ActionToolRegenerateDimensions::trigger() RS_DIALOGFACTORY->commandMessage(tr("Regenerated %1 dimension entities").arg(num)); } else - { RS_DIALOGFACTORY->commandMessage(tr("No dimension entities found")); - } finish(); } - // EOF diff --git a/src/actions/rs_actiontoolregeneratedimensions.h b/src/actions/rs_actiontoolregeneratedimensions.h index 5289e1f..92dd955 100644 --- a/src/actions/rs_actiontoolregeneratedimensions.h +++ b/src/actions/rs_actiontoolregeneratedimensions.h @@ -1,51 +1,21 @@ -/**************************************************************************** -** $Id: rs_actiontoolregeneratedimensions.h 1063 2004-01-18 10:59:32Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONTOOLREGENERATEDIMENSIONS_H #define RS_ACTIONTOOLREGENERATEDIMENSIONS_H #include "rs_actioninterface.h" - /** * This action class can handle user events to regenerate dimensions. * * @author Andrew Mustun */ -class RS_ActionToolRegenerateDimensions : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionToolRegenerateDimensions(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionToolRegenerateDimensions() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionToolRegenerateDimensions: public RS_ActionInterface +{ + public: + RS_ActionToolRegenerateDimensions(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionToolRegenerateDimensions(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionzoomauto.cpp b/src/actions/rs_actionzoomauto.cpp index b75503a..6d1942b 100644 --- a/src/actions/rs_actionzoomauto.cpp +++ b/src/actions/rs_actionzoomauto.cpp @@ -1,32 +1,20 @@ -/**************************************************************************** -** $Id: rs_actionzoomauto.cpp 1090 2004-03-16 10:02:59Z js $ -** -** 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_actionzoomauto.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/05/2010 Added this text. :-) +// #include "rs_actionzoomauto.h" -//Added by qt3to4: -//#include + +#include "rs_graphicview.h" /** * Constructor. @@ -34,20 +22,15 @@ * @param keepAspectRatio true: keep same zoom value for x/y. * false: adjust both x and y individually */ -RS_ActionZoomAuto::RS_ActionZoomAuto(RS_EntityContainer& container, - RS_GraphicView& graphicView, bool keepAspectRatio): +RS_ActionZoomAuto::RS_ActionZoomAuto(RS_EntityContainer & container, + RS_GraphicView & graphicView, bool keepAspectRatio): RS_ActionInterface("Auto zoom", container, graphicView) { - this->keepAspectRatio = keepAspectRatio; + this->keepAspectRatio = keepAspectRatio; } -QAction * RS_ActionZoomAuto::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionZoomAuto::~RS_ActionZoomAuto() { - QAction * action = new QAction(QIcon(":/res/zoomauto.png"), tr("&Auto Zoom"), 0); -// QAction* action = new QAction(tr("Auto Zoom"), QPixmap::fromMimeSource("zoomauto.png"), -// tr("&Auto Zoom"), QKeySequence(), NULL); - action->setStatusTip(tr("Zooms automatic")); - return action; } void RS_ActionZoomAuto::init(int status) @@ -61,5 +44,3 @@ void RS_ActionZoomAuto::trigger() graphicView->zoomAuto(false, keepAspectRatio); finish(); } - -// EOF diff --git a/src/actions/rs_actionzoomauto.h b/src/actions/rs_actionzoomauto.h index 35a4c94..73d5437 100644 --- a/src/actions/rs_actionzoomauto.h +++ b/src/actions/rs_actionzoomauto.h @@ -1,55 +1,24 @@ -/**************************************************************************** -** $Id: rs_actionzoomauto.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONZOOMAUTO_H #define RS_ACTIONZOOMAUTO_H #include "rs_actioninterface.h" - /** * This action triggers an auto zoom. * * @author Andrew Mustun */ -class RS_ActionZoomAuto : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionZoomAuto(RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool keepAspectRatio=true); - ~RS_ActionZoomAuto() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionZoomAuto: public RS_ActionInterface +{ + public: + RS_ActionZoomAuto(RS_EntityContainer & container, RS_GraphicView & graphicView, bool keepAspectRatio = true); + ~RS_ActionZoomAuto(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); -protected: - bool keepAspectRatio; + protected: + bool keepAspectRatio; }; #endif diff --git a/src/actions/rs_actionzoomautoy.cpp b/src/actions/rs_actionzoomautoy.cpp index 7501793..01868f6 100644 --- a/src/actions/rs_actionzoomautoy.cpp +++ b/src/actions/rs_actionzoomautoy.cpp @@ -1,39 +1,29 @@ -/**************************************************************************** -** $Id: rs_actionzoomautoy.cpp 945 2003-06-11 06:56:54Z 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_actionzoomautoy.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/05/2010 Added this text. :-) +// #include "rs_actionzoomautoy.h" +#include "rs_graphicview.h" - -RS_ActionZoomAutoY::RS_ActionZoomAutoY(RS_EntityContainer& container, - RS_GraphicView& graphicView): +RS_ActionZoomAutoY::RS_ActionZoomAutoY(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Auto zoom Y", container, graphicView) { } +RS_ActionZoomAutoY::~RS_ActionZoomAutoY() +{ +} void RS_ActionZoomAutoY::trigger() { @@ -41,12 +31,8 @@ void RS_ActionZoomAutoY::trigger() finish(); } - - void RS_ActionZoomAutoY::init(int status) { RS_ActionInterface::init(status); trigger(); } - -// EOF diff --git a/src/actions/rs_actionzoomautoy.h b/src/actions/rs_actionzoomautoy.h index c6c62c9..c0a32e3 100644 --- a/src/actions/rs_actionzoomautoy.h +++ b/src/actions/rs_actionzoomautoy.h @@ -1,49 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionzoomautoy.h 973 2003-08-09 22:39:50Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONZOOMAUTOY_H #define RS_ACTIONZOOMAUTOY_H #include "rs_actioninterface.h" - /** * This action triggers an auto zoom in Y only. * * @author Andrew Mustun */ -class RS_ActionZoomAutoY : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionZoomAutoY(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionZoomAutoY() {} +class RS_ActionZoomAutoY: public RS_ActionInterface +{ + public: + RS_ActionZoomAutoY(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionZoomAutoY(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionzoomin.cpp b/src/actions/rs_actionzoomin.cpp index d0db01f..56cb9ef 100644 --- a/src/actions/rs_actionzoomin.cpp +++ b/src/actions/rs_actionzoomin.cpp @@ -14,15 +14,15 @@ #include "rs_actionzoomin.h" +#include "rs_graphicview.h" + /** * Default constructor. * * @param direction In for zooming in, Out for zooming out. * @param axis Axis that are affected by the zoom (OnlyX, OnlyY or Both) */ -RS_ActionZoomIn::RS_ActionZoomIn(RS_EntityContainer& container, - RS_GraphicView& graphicView, RS2::ZoomDirection direction, - RS2::Axis axis, const Vector& center): +RS_ActionZoomIn::RS_ActionZoomIn(RS_EntityContainer & container, RS_GraphicView & graphicView, RS2::ZoomDirection direction, RS2::Axis axis, const Vector & center): RS_ActionInterface("Zoom in", container, graphicView) { this->direction = direction; @@ -30,26 +30,8 @@ RS_ActionZoomIn::RS_ActionZoomIn(RS_EntityContainer& container, this->center = center; } -QAction * RS_ActionZoomIn::createGUIAction(RS2::ActionType type, QObject * /*parent*/) +RS_ActionZoomIn::~RS_ActionZoomIn() { - QAction * action; - - if (type == RS2::ActionZoomIn) - { - action = new QAction(QIcon(":/res/zoomin.png"), tr("Zoom &In"), 0); -// action = new QAction(tr("Zoom in"), QPixmap::fromMimeSource("zoomin.png"), -// tr("Zoom &In"), QKeySequence(), NULL); - action->setStatusTip(tr("Zooms in")); - } - else - { - action = new QAction(QIcon(":/res/zoomout.png"), tr("Zoom &Out"), 0); -// action = new QAction(tr("Zoom out"), QPixmap::fromMimeSource("zoomout.png"), -// tr("Zoom &Out"), QKeySequence(), NULL); - action->setStatusTip(tr("Zooms out")); - } - - return action; } void RS_ActionZoomIn::init(int status) @@ -63,36 +45,27 @@ void RS_ActionZoomIn::trigger() switch (axis) { case RS2::OnlyX: + if (direction == RS2::In) - { graphicView->zoomInX(); - } else - { graphicView->zoomOutX(); - } break; case RS2::OnlyY: + if (direction == RS2::In) - { graphicView->zoomInY(); - } else - { graphicView->zoomOutY(); - } break; case RS2::Both: + if (direction == RS2::In) - { graphicView->zoomIn(1.25, center); - } else - { graphicView->zoomOut(1.25, center); - } break; } diff --git a/src/actions/rs_actionzoomin.h b/src/actions/rs_actionzoomin.h index 64e1bab..68abaeb 100644 --- a/src/actions/rs_actionzoomin.h +++ b/src/actions/rs_actionzoomin.h @@ -1,23 +1,20 @@ #ifndef RS_ACTIONZOOMIN_H #define RS_ACTIONZOOMIN_H +#include "rs.h" #include "rs_actioninterface.h" +#include "vector.h" /** * This action triggers zoom increase. * * @author Andrew Mustun */ -class RS_ActionZoomIn : public RS_ActionInterface +class RS_ActionZoomIn: public RS_ActionInterface { - //Q_OBJECT public: - RS_ActionZoomIn(RS_EntityContainer& container, RS_GraphicView& graphicView, - RS2::ZoomDirection direction = RS2::In, RS2::Axis axis = RS2::Both, - const Vector& center = Vector(false)); - ~RS_ActionZoomIn() {} - - static QAction * createGUIAction(RS2::ActionType type, QObject * /*parent*/); + RS_ActionZoomIn(RS_EntityContainer & container, RS_GraphicView & graphicView, RS2::ZoomDirection direction = RS2::In, RS2::Axis axis = RS2::Both, const Vector & center = Vector(false)); + ~RS_ActionZoomIn(); virtual void init(int status = 0); virtual void trigger(); diff --git a/src/actions/rs_actionzoompan.cpp b/src/actions/rs_actionzoompan.cpp index 6f700e4..0795666 100644 --- a/src/actions/rs_actionzoompan.cpp +++ b/src/actions/rs_actionzoompan.cpp @@ -1,119 +1,94 @@ -/**************************************************************************** -** $Id: rs_actionzoompan.cpp 1134 2004-07-13 23:26:13Z 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_actionzoompan.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/05/2010 Added this text. :-) +// #include "rs_actionzoompan.h" -#include "rs_snapper.h" -#include "rs_point.h" -//Added by qt3to4: -//#include -RS_ActionZoomPan::RS_ActionZoomPan(RS_EntityContainer& container, - RS_GraphicView& graphicView): +#include "rs_graphicview.h" + +RS_ActionZoomPan::RS_ActionZoomPan(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Zoom Pan", container, graphicView) { } -QAction * RS_ActionZoomPan::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionZoomPan::~RS_ActionZoomPan() { - QAction * action = new QAction(QIcon(":/res/zoompan.png"), tr("&Pan Zoom"), 0); -// QAction* action = new QAction(tr("Pan Zoom"), QPixmap::fromMimeSource("zoompan.png"), -// tr("&Pan Zoom"), QKeySequence(), NULL); - action->setStatusTip(tr("Realtime Panning")); - return action; } void RS_ActionZoomPan::init(int status) { - RS_ActionInterface::init(status); - snapMode = RS2::SnapFree; - snapRes = RS2::RestrictNothing; - //v1 = v2 = Vector(false); - x1 = y1 = x2 = y2 = -1; - //graphicView->saveView(); + RS_ActionInterface::init(status); + snapMode = RS2::SnapFree; + snapRes = RS2::RestrictNothing; + //v1 = v2 = Vector(false); + x1 = y1 = x2 = y2 = -1; + //graphicView->saveView(); } - - -void RS_ActionZoomPan::trigger() { - /*if (v1.valid && v2.valid) { - graphicView->zoomPan(v2-v1); - v1 = v2; -}*/ - if (x1>=0) { - graphicView->zoomPan(x2-x1, y2-y1); - x1 = x2; - y1 = y2; - } +void RS_ActionZoomPan::trigger() +{ + /*if (v1.valid && v2.valid) { + graphicView->zoomPan(v2-v1); + v1 = v2; + }*/ + if (x1 >= 0) + { + graphicView->zoomPan(x2 - x1, y2 - y1); + x1 = x2; + y1 = y2; + } } +void RS_ActionZoomPan::mouseMoveEvent(QMouseEvent * e) +{ + //v2 = snapPoint(e); + x2 = e->x(); + y2 = e->y(); - -void RS_ActionZoomPan::mouseMoveEvent(QMouseEvent* e) { - //v2 = snapPoint(e); - x2 = e->x(); - y2 = e->y(); - //if (getStatus()==1 && graphicView->toGuiDX((v2-v1).magnitude())>10) { - if (getStatus()==1 && (abs(x2-x1)>7 || abs(y2-y1)>7)) { - trigger(); - } + //if (getStatus()==1 && graphicView->toGuiDX((v2-v1).magnitude())>10) { + if (getStatus() == 1 && (abs(x2 - x1) > 7 || abs(y2 - y1) > 7)) + trigger(); } - - -void RS_ActionZoomPan::mousePressEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::MidButton || - RS2::qtToRsButtonState(e->button())==RS2::LeftButton) { - //v1 = snapPoint(e); - x1 = e->x(); - y1 = e->y(); - setStatus(1); - } +void RS_ActionZoomPan::mousePressEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::MidButton + || RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) + { + //v1 = snapPoint(e); + x1 = e->x(); + y1 = e->y(); + setStatus(1); + } } - - -void RS_ActionZoomPan::mouseReleaseEvent(QMouseEvent* e) { - if (RS2::qtToRsButtonState(e->button())==RS2::RightButton) { - init(getStatus()-1); - } else if (RS2::qtToRsButtonState(e->button())==RS2::MidButton) { - init(-1); - } else { - setStatus(0); - } - - //RS_DEBUG->print("RS_ActionZoomPan::mousePressEvent(): %f %f", v1.x, v1.y); +void RS_ActionZoomPan::mouseReleaseEvent(QMouseEvent * e) +{ + if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) + init(getStatus() - 1); + else if (RS2::qtToRsButtonState(e->button()) == RS2::MidButton) + init(-1); + else + setStatus(0); + + //RS_DEBUG->print("RS_ActionZoomPan::mousePressEvent(): %f %f", v1.x, v1.y); } - - -void RS_ActionZoomPan::updateMouseCursor() { +void RS_ActionZoomPan::updateMouseCursor() +{ #ifndef __APPLE__ - graphicView->setMouseCursor(RS2::SizeAllCursor); + graphicView->setMouseCursor(RS2::SizeAllCursor); #endif } - // EOF diff --git a/src/actions/rs_actionzoompan.h b/src/actions/rs_actionzoompan.h index f0c002b..d9019e9 100644 --- a/src/actions/rs_actionzoompan.h +++ b/src/actions/rs_actionzoompan.h @@ -1,63 +1,31 @@ -/**************************************************************************** -** $Id: rs_actionzoompan.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONZOOMPAN_H #define RS_ACTIONZOOMPAN_H #include "rs_actioninterface.h" - /** * This action class can handle user events to zoom in a window. * * @author Andrew Mustun */ -class RS_ActionZoomPan : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionZoomPan(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionZoomPan() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mousePressEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseCursor(); - -protected: - //Vector v1; - //Vector v2; - int x1; - int y1; - int x2; - int y2; +class RS_ActionZoomPan: public RS_ActionInterface +{ + public: + RS_ActionZoomPan(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionZoomPan(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mousePressEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseCursor(); + + protected: + int x1; + int y1; + int x2; + int y2; }; #endif diff --git a/src/actions/rs_actionzoomprevious.cpp b/src/actions/rs_actionzoomprevious.cpp index 2cf3e67..3b6ee3b 100644 --- a/src/actions/rs_actionzoomprevious.cpp +++ b/src/actions/rs_actionzoomprevious.cpp @@ -1,61 +1,41 @@ -/**************************************************************************** -** $Id: rs_actionzoomprevious.cpp 1115 2004-04-05 16:47:51Z 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_actionzoomprevious.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/05/2010 Added this text. :-) +// #include "rs_actionzoomprevious.h" -//Added by qt3to4: -//#include + +#include "rs_graphicview.h" /** * Constructor. */ -RS_ActionZoomPrevious::RS_ActionZoomPrevious(RS_EntityContainer& container, - RS_GraphicView& graphicView): +RS_ActionZoomPrevious::RS_ActionZoomPrevious(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Previous zoom", container, graphicView) { } -QAction * RS_ActionZoomPrevious::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionZoomPrevious::~RS_ActionZoomPrevious() { - QAction * action = new QAction(QIcon(":/res/zoomprevious.png"), tr("&Previous View"), 0); -// QAction* action = new QAction(tr("Previous View"), QPixmap::fromMimeSource("zoomprevious.png"), -// tr("&Previous View"), QKeySequence(), NULL); - action->setStatusTip(tr("Shows previous view")); - return action; } void RS_ActionZoomPrevious::init(int status) { - RS_ActionInterface::init(status); - trigger(); + RS_ActionInterface::init(status); + trigger(); } void RS_ActionZoomPrevious::trigger() { - graphicView->zoomPrevious(); - finish(); + graphicView->zoomPrevious(); + finish(); } - -// EOF diff --git a/src/actions/rs_actionzoomprevious.h b/src/actions/rs_actionzoomprevious.h index ac63b71..bc6b8ce 100644 --- a/src/actions/rs_actionzoomprevious.h +++ b/src/actions/rs_actionzoomprevious.h @@ -1,53 +1,23 @@ -/**************************************************************************** -** $Id: rs_actionzoomprevious.h 1115 2004-04-05 16:47:51Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONZOOMPREVIOUS_H #define RS_ACTIONZOOMPREVIOUS_H #include "rs_actioninterface.h" - /** * This action switches back to the previously used view.. * * @author Andrew Mustun */ -class RS_ActionZoomPrevious : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionZoomPrevious(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionZoomPrevious() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionZoomPrevious: public RS_ActionInterface +{ + public: + RS_ActionZoomPrevious(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionZoomPrevious(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); -protected: + protected: }; #endif diff --git a/src/actions/rs_actionzoomredraw.cpp b/src/actions/rs_actionzoomredraw.cpp index 9ef3961..f884539 100644 --- a/src/actions/rs_actionzoomredraw.cpp +++ b/src/actions/rs_actionzoomredraw.cpp @@ -1,32 +1,20 @@ -/**************************************************************************** -** $Id: rs_actionzoomredraw.cpp 1090 2004-03-16 10:02:59Z js $ -** -** 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_actionzoomredraw.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/05/2010 Added this text. :-) +// #include "rs_actionzoomredraw.h" -//Added by qt3to4: -//#include + +#include "rs_graphicview.h" /** * Constructor. @@ -34,19 +22,13 @@ * @param keepAspectRatio true: keep same zoom value for x/y. * false: adjust both x and y individually */ -RS_ActionZoomRedraw::RS_ActionZoomRedraw(RS_EntityContainer& container, - RS_GraphicView& graphicView) - :RS_ActionInterface("Redraw", container, graphicView) +RS_ActionZoomRedraw::RS_ActionZoomRedraw(RS_EntityContainer & container, RS_GraphicView & graphicView): + RS_ActionInterface("Redraw", container, graphicView) { } -QAction * RS_ActionZoomRedraw::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionZoomRedraw::~RS_ActionZoomRedraw() { - QAction * action = new QAction(QIcon(":/res/zoomredraw.png"), tr("&Redraw"), 0); -// QAction* action = new QAction(tr("Redraw"), QPixmap::fromMimeSource("zoomredraw.png"), -// tr("&Redraw"), QKeySequence(), NULL); - action->setStatusTip(tr("Redraw")); - return action; } void RS_ActionZoomRedraw::init(int status) @@ -60,5 +42,3 @@ void RS_ActionZoomRedraw::trigger() graphicView->redraw(); finish(); } - -// EOF diff --git a/src/actions/rs_actionzoomredraw.h b/src/actions/rs_actionzoomredraw.h index 071f7c9..712c900 100644 --- a/src/actions/rs_actionzoomredraw.h +++ b/src/actions/rs_actionzoomredraw.h @@ -1,51 +1,21 @@ -/**************************************************************************** -** $Id: rs_actionzoomredraw.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONZOOMREDRAW_H #define RS_ACTIONZOOMREDRAW_H #include "rs_actioninterface.h" - /** * This action triggers an auto zoom. * * @author Andrew Mustun */ -class RS_ActionZoomRedraw : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionZoomRedraw(RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionZoomRedraw() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); +class RS_ActionZoomRedraw: public RS_ActionInterface +{ + public: + RS_ActionZoomRedraw(RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionZoomRedraw(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); }; #endif diff --git a/src/actions/rs_actionzoomscroll.cpp b/src/actions/rs_actionzoomscroll.cpp index ce28400..621e916 100644 --- a/src/actions/rs_actionzoomscroll.cpp +++ b/src/actions/rs_actionzoomscroll.cpp @@ -1,38 +1,31 @@ -/**************************************************************************** -** $Id: rs_actionzoomscroll.cpp 945 2003-06-11 06:56:54Z 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_actionzoomscroll.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/05/2010 Added this text. :-) +// #include "rs_actionzoomscroll.h" -RS_ActionZoomScroll::RS_ActionZoomScroll(RS2::Direction direction, - RS_EntityContainer& container, RS_GraphicView& graphicView): +#include "rs_graphicview.h" + +RS_ActionZoomScroll::RS_ActionZoomScroll(RS2::Direction direction, RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Zoom scroll", container, graphicView) { this->direction = direction; } +RS_ActionZoomScroll::~RS_ActionZoomScroll() +{ +} + void RS_ActionZoomScroll::trigger() { graphicView->zoomScroll(direction); @@ -44,5 +37,3 @@ void RS_ActionZoomScroll::init(int status) RS_ActionInterface::init(status); trigger(); } - -// EOF diff --git a/src/actions/rs_actionzoomscroll.h b/src/actions/rs_actionzoomscroll.h index bb8b5dd..f461d5f 100644 --- a/src/actions/rs_actionzoomscroll.h +++ b/src/actions/rs_actionzoomscroll.h @@ -1,53 +1,24 @@ -/**************************************************************************** -** $Id: rs_actionzoomscroll.h 973 2003-08-09 22:39:50Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONZOOMSCROLL_H #define RS_ACTIONZOOMSCROLL_H #include "rs_actioninterface.h" - /** * This action triggers a scrolling. * * @author Andrew Mustun */ -class RS_ActionZoomScroll : public RS_ActionInterface { - //Q_OBJECT -public: - RS_ActionZoomScroll(RS2::Direction direction, - RS_EntityContainer& container, - RS_GraphicView& graphicView); - ~RS_ActionZoomScroll() {} +class RS_ActionZoomScroll: public RS_ActionInterface +{ + public: + RS_ActionZoomScroll(RS2::Direction direction, RS_EntityContainer & container, RS_GraphicView & graphicView); + ~RS_ActionZoomScroll(); - virtual void init(int status=0); - virtual void trigger(); + virtual void init(int status = 0); + virtual void trigger(); -protected: - RS2::Direction direction; + protected: + RS2::Direction direction; }; #endif diff --git a/src/actions/rs_actionzoomwindow.cpp b/src/actions/rs_actionzoomwindow.cpp index 65c09ff..5ef6118 100644 --- a/src/actions/rs_actionzoomwindow.cpp +++ b/src/actions/rs_actionzoomwindow.cpp @@ -1,36 +1,22 @@ -/**************************************************************************** -** $Id: rs_actionzoomwindow.cpp 1134 2004-07-13 23:26:13Z 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_actionzoomwindow.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/05/2010 Added this text. :-) +// #include "rs_actionzoomwindow.h" -#include "rs.h" -#include "rs_snapper.h" -#include "rs_point.h" -//Added by qt3to4: -//#include +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_preview.h" /** * Default constructor. @@ -40,19 +26,14 @@ * area will be fit to the viewport. */ RS_ActionZoomWindow::RS_ActionZoomWindow(RS_EntityContainer & container, - RS_GraphicView& graphicView, bool keepAspectRatio): + RS_GraphicView & graphicView, bool keepAspectRatio): RS_PreviewActionInterface("Zoom Window", container, graphicView) { this->keepAspectRatio = keepAspectRatio; } -QAction* RS_ActionZoomWindow::createGUIAction(RS2::ActionType /*type*/, QObject * /*parent*/) +RS_ActionZoomWindow::~RS_ActionZoomWindow() { - QAction * action = new QAction(QIcon(":/res/zoomwindow.png"), tr("&Window Zoom"), 0); -// QAction* action = new QAction(tr("Window Zoom"), QPixmap::fromMimeSource("zoomwindow.png"), -// tr("&Window Zoom"), QKeySequence(), NULL); - action->setStatusTip(tr("Zooms in a window")); - return action; } void RS_ActionZoomWindow::init(int status) @@ -92,13 +73,13 @@ void RS_ActionZoomWindow::mouseMoveEvent(QMouseEvent * e) deletePreview(); clearPreview(); preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y)))); + RS_LineData(Vector(v1.x, v1.y), Vector(v2.x, v1.y)))); preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y)))); + RS_LineData(Vector(v2.x, v1.y), Vector(v2.x, v2.y)))); preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y)))); + RS_LineData(Vector(v2.x, v2.y), Vector(v1.x, v2.y)))); preview->addEntity(new RS_Line(preview, - RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y)))); + RS_LineData(Vector(v1.x, v2.y), Vector(v1.x, v1.y)))); drawPreview(); } } @@ -129,20 +110,16 @@ void RS_ActionZoomWindow::mouseReleaseEvent(QMouseEvent * e) if (RS2::qtToRsButtonState(e->button()) == RS2::RightButton) { if (getStatus() == 1) - { deletePreview(); - } init(getStatus() - 1); } else if (RS2::qtToRsButtonState(e->button()) == RS2::LeftButton) - { if (getStatus() == 1) { v2 = snapPoint(e); trigger(); } - } } void RS_ActionZoomWindow::updateMouseButtonHints() @@ -154,9 +131,11 @@ void RS_ActionZoomWindow::updateMouseButtonHints() case 0: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify first edge"), tr("Cancel")); break; + case 1: RS_DIALOGFACTORY->updateMouseWidget(tr("Specify second edge"), tr("Back")); break; + default: RS_DIALOGFACTORY->updateMouseWidget("", ""); break; diff --git a/src/actions/rs_actionzoomwindow.h b/src/actions/rs_actionzoomwindow.h index b51d310..aca5cd6 100644 --- a/src/actions/rs_actionzoomwindow.h +++ b/src/actions/rs_actionzoomwindow.h @@ -1,63 +1,33 @@ -/**************************************************************************** -** $Id: rs_actionzoomwindow.h 1062 2004-01-16 21:51:20Z 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. -** -**********************************************************************/ - #ifndef RS_ACTIONZOOMWINDOW_H #define RS_ACTIONZOOMWINDOW_H #include "rs_previewactioninterface.h" +#include "vector.h" /** * This action class can handle user events to zoom in a window. * * @author Andrew Mustun */ -class RS_ActionZoomWindow : public RS_PreviewActionInterface { - //Q_OBJECT -public: - RS_ActionZoomWindow(RS_EntityContainer& container, - RS_GraphicView& graphicView, - bool keepAspectRatio=true); - - ~RS_ActionZoomWindow() {} - - static QAction* createGUIAction(RS2::ActionType /*type*/, QObject* /*parent*/); - - virtual void init(int status=0); - virtual void trigger(); - virtual void mouseMoveEvent(QMouseEvent* e); - virtual void mousePressEvent(QMouseEvent* e); - virtual void mouseReleaseEvent(QMouseEvent* e); - virtual void updateMouseButtonHints(); - virtual void updateMouseCursor(); - -protected: - Vector v1; - Vector v2; - - bool keepAspectRatio; +class RS_ActionZoomWindow: public RS_PreviewActionInterface +{ + public: + RS_ActionZoomWindow(RS_EntityContainer & container, RS_GraphicView & graphicView, bool keepAspectRatio = true); + ~RS_ActionZoomWindow(); + + virtual void init(int status = 0); + virtual void trigger(); + virtual void mouseMoveEvent(QMouseEvent * e); + virtual void mousePressEvent(QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + virtual void updateMouseButtonHints(); + virtual void updateMouseCursor(); + + protected: + Vector v1; + Vector v2; + + bool keepAspectRatio; }; #endif diff --git a/src/base/rs.h b/src/base/rs.h index 60a8f05..a17cad6 100644 --- a/src/base/rs.h +++ b/src/base/rs.h @@ -586,6 +586,7 @@ Qt::KeyButtonMask Qt::KeyboardModifierMask Keypad = Qt::KeypadModifier }; +#if 1 /** * Wrapper for Qt */ @@ -601,6 +602,7 @@ Qt::KeyButtonMask Qt::KeyboardModifierMask // return (RS2::ButtonState)t; // } static RS2::ButtonState qtToRsButtonState(int t) { return (RS2::ButtonState)t; } +#endif /** * Enum of line styles: diff --git a/src/base/rs_actioninterface.cpp b/src/base/rs_actioninterface.cpp index 9d4f4e5..9557d31 100644 --- a/src/base/rs_actioninterface.cpp +++ b/src/base/rs_actioninterface.cpp @@ -14,6 +14,11 @@ #include "rs_actioninterface.h" +#include "commands.h" +#include "rs_debug.h" +#include "rs_entitycontainer.h" +#include "rs_graphicview.h" + /** * Constructor. * @@ -60,9 +65,9 @@ RS_ActionInterface::RS_ActionInterface(const char * name, */ RS_ActionInterface::~RS_ActionInterface() { -//JLH: Only it isn't pure virtual... // would be pure virtual now: // hideOptions(); +//JLH: Only it isn't pure virtual... } /** @@ -158,7 +163,8 @@ void RS_ActionInterface::keyReleaseEvent(QKeyEvent * e) * This function can be overwritten by the implementing action. * The default implementation does nothing. */ -void RS_ActionInterface::coordinateEvent(RS_CoordinateEvent *) +//void RS_ActionInterface::coordinateEvent(RS_CoordinateEvent *) +void RS_ActionInterface::coordinateEvent(Vector *) { } diff --git a/src/base/rs_actioninterface.h b/src/base/rs_actioninterface.h index ed76836..8b16095 100644 --- a/src/base/rs_actioninterface.h +++ b/src/base/rs_actioninterface.h @@ -1,26 +1,15 @@ #ifndef RS_ACTIONINTERFACE_H #define RS_ACTIONINTERFACE_H -#include - -#include "rs_entitycontainer.h" -#include "rs_commandevent.h" -//#include "rs_event.h" -#include "drawing.h" -#include "rs_graphicview.h" +#include #include "rs_snapper.h" -#include "rs_preview.h" -#include "rs_dialogfactory.h" - -#ifndef RS_NO_QCADCMD -#include "commands.h" -#endif -//template T* instantiate(RS_EntityContainer& container, RS_GraphicView& graphicView) { -// return new T(container, graphicView); - //void (*function)() = T::instantiate; - //return (*function)(); -//} +class RS_CommandEvent; +class RS_Document; +class Drawing; +class RS_EntityContainer; +class RS_GraphicView; +class Vector; /** * This is the interface that must be implemented for all @@ -34,24 +23,23 @@ class RS_ActionInterface: public QObject, public RS_Snapper { //huh? no slots/signals here... Q_OBJECT - +//WHY derive from QObject??? +//for the TR macro??? public: RS_ActionInterface(const char * name, RS_EntityContainer & container, RS_GraphicView & graphicView); virtual ~RS_ActionInterface(); virtual RS2::ActionType rtti(); - QString getName(); - virtual void init(int status = 0); virtual void mouseMoveEvent(QMouseEvent *); virtual void mousePressEvent(QMouseEvent *); - virtual void mouseReleaseEvent(QMouseEvent *); virtual void keyPressEvent(QKeyEvent * e); virtual void keyReleaseEvent(QKeyEvent * e); - virtual void coordinateEvent(RS_CoordinateEvent *); +// virtual void coordinateEvent(RS_CoordinateEvent *); + virtual void coordinateEvent(Vector *); virtual void commandEvent(RS_CommandEvent *); virtual QStringList getAvailableCommands(); virtual void setStatus(int status); @@ -75,14 +63,14 @@ class RS_ActionInterface: public QObject, public RS_Snapper private: /** - * Current status of the action. After an action has - * been created the action status is set to 0. Actions - * that are terminated have a status of -1. Other status - * numbers can be used to describe the stage this action - * is in. E.g. a window zoom consists of selecting the - * first corner (status 0), and selecting the second - * corner (status 1). - */ + * Current status of the action. After an action has + * been created the action status is set to 0. Actions + * that are terminated have a status of -1. Other status + * numbers can be used to describe the stage this action + * is in. E.g. a window zoom consists of selecting the + * first corner (status 0), and selecting the second + * corner (status 1). + */ int status; protected: @@ -90,53 +78,26 @@ class RS_ActionInterface: public QObject, public RS_Snapper QString name; /** - * This flag is set when the action has terminated and - * can be deleted. - */ + * This flag is set when the action has terminated and + * can be deleted. + */ bool finished; /** - * Pointer to the graphic is this container is a graphic. - * NULL otherwise - */ + * Pointer to the graphic is this container is a graphic. + * NULL otherwise + */ Drawing * graphic; /** - * Pointer to the document (graphic or block) or NULL. - */ + * Pointer to the document (graphic or block) or NULL. + */ RS_Document * document; /** - * Pointer to the default mouse cursor for this action or NULL. - */ - //RS2::CursorType cursor; - - /** - * Predecessor of this action or NULL. - */ + * Predecessor of this action or NULL. + */ RS_ActionInterface * predecessor; - - /** - * String prepended to the help text for currently available commands. - */ - //static QString msgAvailableCommands; - - /** - * Command used for showing help for every action. - */ - //static QString cmdHelp; - - /** - * Command for answering yes to a question. - */ - //static QString cmdYes; - //static QString cmdYes2; - - /** - * Command for answering no to a question. - */ - //static QString cmdNo; - //static QString cmdNo2; }; #endif diff --git a/src/base/rs_application.h b/src/base/rs_application.h.old similarity index 100% rename from src/base/rs_application.h rename to src/base/rs_application.h.old diff --git a/src/base/rs_commandevent.cpp b/src/base/rs_commandevent.cpp new file mode 100644 index 0000000..519f7ec --- /dev/null +++ b/src/base/rs_commandevent.cpp @@ -0,0 +1,52 @@ +// rs_commandevent.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/02/2010 Added this text. :-) +// JLH 06/02/2010 Moved implementation from header to here WHERE IT BELONGS. +// + +#include "rs_commandevent.h" + +/** + * Creates a new command event that is not yet accepted. + * + * @param cmd the command that was triggered. + */ +RS_CommandEvent::RS_CommandEvent(const QString & cmd) +{ + this->cmd = cmd; + accepted = false; +} + +/** + * @return the command that was triggered, usually by + * the user. + */ +QString RS_CommandEvent::getCommand() +{ + return cmd; +} + +/** + * Sets the event state to accepted. + */ +void RS_CommandEvent::accept() +{ + accepted = true; +} + +/** + * @return Whether the event was already accepted or not. + */ +bool RS_CommandEvent::isAccepted() +{ + return accepted; +} diff --git a/src/base/rs_commandevent.h b/src/base/rs_commandevent.h index 6d6ca7c..d766588 100644 --- a/src/base/rs_commandevent.h +++ b/src/base/rs_commandevent.h @@ -1,6 +1,8 @@ #ifndef RS_COMMANDEVENT_H #define RS_COMMANDEVENT_H +#include + /** * Command Events. */ diff --git a/src/base/rs_coordinateevent.h b/src/base/rs_coordinateevent.h.old similarity index 100% rename from src/base/rs_coordinateevent.h rename to src/base/rs_coordinateevent.h.old diff --git a/src/base/rs_creation.cpp b/src/base/rs_creation.cpp index fb99b2f..a8a14e0 100644 --- a/src/base/rs_creation.cpp +++ b/src/base/rs_creation.cpp @@ -14,11 +14,12 @@ #include "rs_creation.h" -#include #include "rs_constructionline.h" #include "drawing.h" #include "rs_graphicview.h" +#include "rs_image.h" #include "rs_information.h" +#include "rs_insert.h" #include "rs_modification.h" #include "rs_units.h" @@ -1056,43 +1057,39 @@ RS_Line* RS_Creation::createPolygon2(const Vector& corner1, return ret; } - - /** * Creates an insert with the given data. * * @param data Insert data (position, block name, ..) */ -RS_Insert* RS_Creation::createInsert(RS_InsertData& data) { - - RS_DEBUG->print("RS_Creation::createInsert"); +RS_Insert* RS_Creation::createInsert(RS_InsertData & data) +{ + RS_DEBUG->print("RS_Creation::createInsert"); - if (document!=NULL && handleUndo) { - document->startUndoCycle(); - } + if (document != NULL && handleUndo) + document->startUndoCycle(); - RS_Insert* ins = new RS_Insert(container, data); - // inserts are also on layers - ins->setLayerToActive(); - ins->setPenToActive(); + RS_Insert * ins = new RS_Insert(container, data); + // inserts are also on layers + ins->setLayerToActive(); + ins->setPenToActive(); - if (container!=NULL) { - container->addEntity(ins); - } - if (document!=NULL && handleUndo) { - document->addUndoable(ins); - document->endUndoCycle(); - } - if (graphicView!=NULL) { - graphicView->drawEntity(ins); - } + if (container != NULL) + container->addEntity(ins); - RS_DEBUG->print("RS_Creation::createInsert: OK"); + if (document != NULL && handleUndo) + { + document->addUndoable(ins); + document->endUndoCycle(); + } - return ins; -} + if (graphicView != NULL) + graphicView->drawEntity(ins); + RS_DEBUG->print("RS_Creation::createInsert: OK"); + return ins; +} /** * Creates an image with the given data. diff --git a/src/base/rs_creation.h b/src/base/rs_creation.h index e2a6c88..64b4a89 100644 --- a/src/base/rs_creation.h +++ b/src/base/rs_creation.h @@ -1,11 +1,23 @@ #ifndef RS_CREATION_H #define RS_CREATION_H -#include "rs_entitycontainer.h" -#include "rs_line.h" -#include "rs_polyline.h" -#include "rs_insert.h" -#include "rs_image.h" +#include +#include "vector.h" + +class RS_EntityContainer; +class RS_GraphicView; +class RS_Entity; +class RS_Line; +class RS_Circle; +class RS_Arc; +class RS_Image; +class RS_Block; +class RS_Insert; +class Drawing; +class RS_Document; +class RS_ImageData; +class RS_InsertData; +class RS_BlockData; /** * Data needed to insert library items. diff --git a/src/base/rs_eventhandler.cpp b/src/base/rs_eventhandler.cpp index 29e0318..2961ff7 100644 --- a/src/base/rs_eventhandler.cpp +++ b/src/base/rs_eventhandler.cpp @@ -16,7 +16,11 @@ #include #include "rs_actioninterface.h" -#include "rs_coordinateevent.h" +#include "rs_commandevent.h" +#include "rs_debug.h" +#include "rs_dialogfactory.h" +#include "rs_graphicview.h" +#include "rs_math.h" /** * Constructor. @@ -218,23 +222,20 @@ void RS_EventHandler::keyPressEvent(QKeyEvent * e) /** * Called by RS_GraphicView */ -void RS_EventHandler::keyReleaseEvent(QKeyEvent* e) +void RS_EventHandler::keyReleaseEvent(QKeyEvent * e) { - if (actionIndex >= 0 && currentActions[actionIndex] != NULL && - !currentActions[actionIndex]->isFinished()) + if (actionIndex >= 0 && currentActions[actionIndex] != NULL + && !currentActions[actionIndex]->isFinished()) { currentActions[actionIndex]->keyReleaseEvent(e); } else { if (defaultAction != NULL) - { defaultAction->keyReleaseEvent(e); - } else - { e->ignore(); - } + //RS_DEBUG->print("currently no action defined"); } } @@ -268,9 +269,11 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) if (ok1 && ok2) { - RS_DEBUG->print("RS_EventHandler::commandEvent: 005"); - RS_CoordinateEvent ce(Vector(x, y)); +// RS_DEBUG->print("RS_EventHandler::commandEvent: 005"); +// RS_CoordinateEvent ce(Vector(x, y)); RS_DEBUG->print("RS_EventHandler::commandEvent: 006"); +// currentActions[actionIndex]->coordinateEvent(&ce); + Vector ce(x, y); currentActions[actionIndex]->coordinateEvent(&ce); } else @@ -292,7 +295,6 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) if (actionIndex >= 0 && currentActions[actionIndex] != NULL && !currentActions[actionIndex]->isFinished()) { -// int commaPos = cmd.find(','); int commaPos = cmd.indexOf(','); bool ok1, ok2; double x = RS_Math::eval(cmd.mid(1, commaPos - 1), &ok1); @@ -300,8 +302,9 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) if (ok1 && ok2) { - RS_CoordinateEvent ce(Vector(x,y) + - graphicView->getRelativeZero()); +// RS_CoordinateEvent ce(Vector(x,y) + graphicView->getRelativeZero()); +// currentActions[actionIndex]->coordinateEvent(&ce); + Vector ce(Vector(x,y) + graphicView->getRelativeZero()); currentActions[actionIndex]->coordinateEvent(&ce); } else @@ -333,8 +336,9 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) { Vector pos; pos.setPolar(r,RS_Math::deg2rad(a)); - RS_CoordinateEvent ce(pos); - currentActions[actionIndex]->coordinateEvent(&ce); +// RS_CoordinateEvent ce(pos); +// currentActions[actionIndex]->coordinateEvent(&ce); + currentActions[actionIndex]->coordinateEvent(&pos); } else { @@ -365,8 +369,9 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) { Vector pos; pos.setPolar(r,RS_Math::deg2rad(a)); - RS_CoordinateEvent ce(pos + - graphicView->getRelativeZero()); +// RS_CoordinateEvent ce(pos + graphicView->getRelativeZero()); +// currentActions[actionIndex]->coordinateEvent(&ce); + Vector ce(pos + graphicView->getRelativeZero()); currentActions[actionIndex]->coordinateEvent(&ce); } else @@ -393,10 +398,7 @@ void RS_EventHandler::commandEvent(RS_CommandEvent * e) else { if (defaultAction != NULL) - { defaultAction->commandEvent(e); - //e->accept(); - } } } diff --git a/src/base/rs_graphicview.cpp b/src/base/rs_graphicview.cpp index 28d86c9..4dd3e13 100644 --- a/src/base/rs_graphicview.cpp +++ b/src/base/rs_graphicview.cpp @@ -16,10 +16,10 @@ #include #include "rs_actioninterface.h" -#include "rs_application.h" #include "rs_block.h" -#include "rs_eventhandler.h" +#include "rs_dialogfactory.h" #include "drawing.h" +#include "rs_eventhandler.h" #include "rs_grid.h" #include "rs_insert.h" #include "rs_layer.h" diff --git a/src/base/rs_graphicview.h b/src/base/rs_graphicview.h index d4bcdf0..9ba6a1e 100644 --- a/src/base/rs_graphicview.h +++ b/src/base/rs_graphicview.h @@ -26,296 +26,296 @@ class PaintInterface; */ class RS_GraphicView { -public: - RS_GraphicView(); - virtual ~RS_GraphicView(); - - void cleanUp(); - - Drawing * getGraphic(); - void setDrawingMode(RS2::DrawingMode m); - RS2::DrawingMode getDrawingMode(); - void setDeleteMode(bool m); - bool getDeleteMode(); - - /** This virtual method must be overwritten to return - the width of the widget the graphic is shown in */ - virtual int getWidth() = 0; - /** This virtual method must be overwritten to return - the height of the widget the graphic is shown in */ - virtual int getHeight() = 0; - /** This virtual method must be overwritten to redraw - the widget. */ - virtual void redraw() = 0; - /** This virtual method must be overwritten and is then - called whenever the view changed */ - virtual void adjustOffsetControls(); - /** This virtual method must be overwritten and is then - called whenever the view changed */ - virtual void adjustZoomControls(); - /** - * Sets an external painter device. - */ - virtual void setPainter(PaintInterface * p); -// virtual void setPainter(RS_Painter * p); - /** This virtual method must be overwritten and must return - the painter device for the buffer of this widget */ - virtual PaintInterface * createPainter() = 0; -// virtual RS_Painter * createPainter() = 0; - /** - * This virtual method must be overwritten and must return - * the direct painter device for this widget - */ - virtual PaintInterface * createDirectPainter() = 0; -// virtual RS_Painter * createDirectPainter() = 0; - /** - * This virtual method must be overwritten and must destroy - * the painter device and point 'painter' to NULL. If the painter - * is static during the whole life of the application, it might - * just do nothing. - */ - virtual void destroyPainter() = 0; - - virtual void setBackground(const RS_Color & bg); - RS_Color getBackground(); - RS_Color getForeground(); - void setGridColor(const RS_Color & c); - void setMetaGridColor(const RS_Color & c); - void setSelectedColor(const RS_Color & c); - void setHighlightedColor(const RS_Color & c); - virtual void setMouseCursor(RS2::CursorType /*c*/); - void setContainer(RS_EntityContainer * container); - RS_EntityContainer* getContainer(); - void setFactor(double f); - void setFactorX(double f); - void setFactorY(double f); - Vector getFactor(); - void setOffset(int ox, int oy); - void setOffsetX(int ox); - void setOffsetY(int oy); - int getOffsetX(); - int getOffsetY(); - void centerOffsetX(); - void centerOffsetY(); - void centerX(double x); - void centerY(double y); - virtual void updateView(); - void setBorders(int left, int top, int right, int bottom); - int getBorderLeft(); - int getBorderTop(); - int getBorderRight(); - int getBorderBottom(); - void disableUpdate(); - void enableUpdate(); - bool isUpdateEnabled(); - void freezeZoom(bool freeze); - bool isZoomFrozen(); - - void setDefaultAction(RS_ActionInterface * action); - RS_ActionInterface * getDefaultAction(); - void setCurrentAction(RS_ActionInterface * action); - RS_ActionInterface * getCurrentAction(); - - void killSelectActions(); - void killAllActions(); - - /** - * Must be overwritten to emulate a mouse move event with - * the last known mouse position. - * - * @see mx, my - */ - virtual void emulateMouseMoveEvent() = 0; - - void back(); - void enter(); - - void mousePressEvent(QMouseEvent * e); - void mouseReleaseEvent(QMouseEvent * e); - void mouseMoveEvent(QMouseEvent * e); - void mouseLeaveEvent(); - void mouseEnterEvent(); - void keyPressEvent(QKeyEvent * e); - void keyReleaseEvent(QKeyEvent * e); - void commandEvent(RS_CommandEvent * e); - void enableCoordinateInput(); - void disableCoordinateInput(); - - virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false)); - virtual void zoomInX(double f = 1.5); - virtual void zoomInY(double f = 1.5); - virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false)); - virtual void zoomOutX(double f = 1.5); - virtual void zoomOutY(double f = 1.5); - virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true); - virtual void zoomAutoY(bool axis = true); - virtual void zoomPrevious(); - virtual void saveView(); - virtual void restoreView(); - virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true); - //virtual void zoomPan(Vector v1); - virtual void zoomPan(int dx, int dy); - virtual void zoomScroll(RS2::Direction direction); - virtual void zoomPage(); - - virtual void drawWindow(Vector v1, Vector v2); - virtual void drawIt(); - virtual void deleteEntity(RS_Entity * e); - virtual void drawEntity(RS_Entity * e, double patternOffset = 0.0, bool db = false); - virtual void drawEntityPlain(RS_Entity * e, double patternOffset = 0.0); - virtual void setPenForEntity(RS_Entity * e); - - void simulateIt(); - void simulateEntity(RS_Entity * e, const RS_Pen & pen); - void drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen); - void drawArcSmooth(const Vector & center, double radius, - double a1, double a2, bool rev, const RS_Pen & pen); - void simulationDelay(bool step = false); - - virtual RS_LineTypePattern * getPattern(RS2::LineType t); - - virtual void drawAbsoluteZero(); - virtual void drawRelativeZero(); - virtual void drawPaper(); - virtual void drawGrid(); - virtual void drawMetaGrid(); - virtual void updateGrid(); - RS_Grid * getGrid(); - virtual void updateGridStatusWidget(const QString & /*text*/); - - void setDefaultSnapMode(RS2::SnapMode sm); - RS2::SnapMode getDefaultSnapMode(); - void setSnapRestriction(RS2::SnapRestriction sr); - RS2::SnapRestriction getSnapRestriction(); - bool isGridOn(); - - Vector toGui(Vector v); - double toGuiX(double x, bool * visible = NULL); - double toGuiY(double y); - double toGuiDX(double d); - double toGuiDY(double d); - - Vector toGraph(Vector v); - Vector toGraph(int x, int y); - double toGraphX(int x); - double toGraphY(int y); - double toGraphDX(int d); - double toGraphDY(int d); - - void lockRelativeZero(bool lock); - bool isRelativeZeroLocked(); - Vector getRelativeZero(); - void setRelativeZero(const Vector & pos); - void moveRelativeZero(const Vector & pos); - - RS_EventHandler * getEventHandler(); - void setPrintPreview(bool pv); - bool isPrintPreview(); - void setPrinting(bool p); - bool isPrinting(); - bool isDraftMode(); - void setSimulationSpeed(int s); - int getSimulationSpeed(); - void setSimulationSmooth(bool s); - void setSimulationRapid(bool r); - bool getSimulationRapid(); - - //this is here because of crappy braindead infrastructure - void SetPreviewMode(bool mode = true); - void SetPreviewEntity(RS_Preview *); - void SetPreviewOffset(Vector); - void SetSnapperDraw(bool); - void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs); - -protected: - RS_EntityContainer * container; - RS_EventHandler * eventHandler; - - int mx; //!< Last known mouse cursor position - int my; //!< Last known mouse cursor position - -// RS_Painter * painter; - PaintInterface * painter; - /** background color (any color) */ - RS_Color background; - /** foreground color (black or white) */ - RS_Color foreground; - /** grid color */ - RS_Color gridColor; - /** meta grid color */ - RS_Color metaGridColor; - /** selected color */ - RS_Color selectedColor; - /** highlighted color */ - RS_Color highlightedColor; - /** Grid */ - RS_Grid * grid; - /** - * Current default snap mode for this graphic view. Used for new - * actions. - */ - RS2::SnapMode defaultSnapMode; - /** - * Current default snap restriction for this graphic view. Used for new - * actions. - */ - RS2::SnapRestriction defaultSnapRes; - - RS2::DrawingMode drawingMode; - - /** - * Delete mode. If true, all drawing actions will delete in background color - * instead. - */ - bool deleteMode; - //! If true, the simulation is currectly running - bool simulationRunning; - -private: - int updateEnabled; - bool zoomFrozen; - //bool gridVisible; - bool draftMode; - - Vector factor; - int offsetX; - int offsetY; - - Vector previousFactor; - int previousOffsetX; - int previousOffsetY; - - int borderLeft; - int borderTop; - int borderRight; - int borderBottom; - - Vector relativeZero; - bool relativeZeroLocked; - //! Print preview flag - bool printPreview; - //! Active when printing only: - bool printing; - //int drawRecursion; - - //! Simulation speed in percentage - int simulationSpeed; - //! If true, the entity is drawn slowly (pixel by pixel). - bool simulationSmooth; - //! If true, the way between entities is also shown. - bool simulationRapid; - //! Last position (for rapid move) - Vector simulationLast; - -protected: - // crap to make painting with update() possible - RS_Preview * previewEntity; - bool previewMode; - Vector previewOffset; - bool snapperDraw; - Vector snapSpot1; - Vector snapCoord1; - bool showCrosshairs1; + public: + RS_GraphicView(); + virtual ~RS_GraphicView(); + + void cleanUp(); + + Drawing * getGraphic(); + void setDrawingMode(RS2::DrawingMode m); + RS2::DrawingMode getDrawingMode(); + void setDeleteMode(bool m); + bool getDeleteMode(); + + /** This virtual method must be overwritten to return + the width of the widget the graphic is shown in */ + virtual int getWidth() = 0; + /** This virtual method must be overwritten to return + the height of the widget the graphic is shown in */ + virtual int getHeight() = 0; + /** This virtual method must be overwritten to redraw + the widget. */ + virtual void redraw() = 0; + /** This virtual method must be overwritten and is then + called whenever the view changed */ + virtual void adjustOffsetControls(); + /** This virtual method must be overwritten and is then + called whenever the view changed */ + virtual void adjustZoomControls(); + /** + * Sets an external painter device. + */ + virtual void setPainter(PaintInterface * p); + // virtual void setPainter(RS_Painter * p); + /** This virtual method must be overwritten and must return + the painter device for the buffer of this widget */ + virtual PaintInterface * createPainter() = 0; + // virtual RS_Painter * createPainter() = 0; + /** + * This virtual method must be overwritten and must return + * the direct painter device for this widget + */ + virtual PaintInterface * createDirectPainter() = 0; + // virtual RS_Painter * createDirectPainter() = 0; + /** + * This virtual method must be overwritten and must destroy + * the painter device and point 'painter' to NULL. If the painter + * is static during the whole life of the application, it might + * just do nothing. + */ + virtual void destroyPainter() = 0; + + virtual void setBackground(const RS_Color & bg); + RS_Color getBackground(); + RS_Color getForeground(); + void setGridColor(const RS_Color & c); + void setMetaGridColor(const RS_Color & c); + void setSelectedColor(const RS_Color & c); + void setHighlightedColor(const RS_Color & c); + virtual void setMouseCursor(RS2::CursorType /*c*/); + void setContainer(RS_EntityContainer * container); + RS_EntityContainer * getContainer(); + void setFactor(double f); + void setFactorX(double f); + void setFactorY(double f); + Vector getFactor(); + void setOffset(int ox, int oy); + void setOffsetX(int ox); + void setOffsetY(int oy); + int getOffsetX(); + int getOffsetY(); + void centerOffsetX(); + void centerOffsetY(); + void centerX(double x); + void centerY(double y); + virtual void updateView(); + void setBorders(int left, int top, int right, int bottom); + int getBorderLeft(); + int getBorderTop(); + int getBorderRight(); + int getBorderBottom(); + void disableUpdate(); + void enableUpdate(); + bool isUpdateEnabled(); + void freezeZoom(bool freeze); + bool isZoomFrozen(); + + void setDefaultAction(RS_ActionInterface * action); + RS_ActionInterface * getDefaultAction(); + void setCurrentAction(RS_ActionInterface * action); + RS_ActionInterface * getCurrentAction(); + + void killSelectActions(); + void killAllActions(); + + /** + * Must be overwritten to emulate a mouse move event with + * the last known mouse position. + * + * @see mx, my + */ + virtual void emulateMouseMoveEvent() = 0; + + void back(); + void enter(); + + void mousePressEvent(QMouseEvent * e); + void mouseReleaseEvent(QMouseEvent * e); + void mouseMoveEvent(QMouseEvent * e); + void mouseLeaveEvent(); + void mouseEnterEvent(); + void keyPressEvent(QKeyEvent * e); + void keyReleaseEvent(QKeyEvent * e); + void commandEvent(RS_CommandEvent * e); + void enableCoordinateInput(); + void disableCoordinateInput(); + + virtual void zoomIn(double f = 1.5, const Vector & center = Vector(false)); + virtual void zoomInX(double f = 1.5); + virtual void zoomInY(double f = 1.5); + virtual void zoomOut(double f = 1.5, const Vector & center = Vector(false)); + virtual void zoomOutX(double f = 1.5); + virtual void zoomOutY(double f = 1.5); + virtual void zoomAuto(bool axis = true, bool keepAspectRatio = true); + virtual void zoomAutoY(bool axis = true); + virtual void zoomPrevious(); + virtual void saveView(); + virtual void restoreView(); + virtual void zoomWindow(Vector v1, Vector v2, bool keepAspectRatio = true); + //virtual void zoomPan(Vector v1); + virtual void zoomPan(int dx, int dy); + virtual void zoomScroll(RS2::Direction direction); + virtual void zoomPage(); + + virtual void drawWindow(Vector v1, Vector v2); + virtual void drawIt(); + virtual void deleteEntity(RS_Entity * e); + virtual void drawEntity(RS_Entity * e, double patternOffset = 0.0, bool db = false); + virtual void drawEntityPlain(RS_Entity * e, double patternOffset = 0.0); + virtual void setPenForEntity(RS_Entity * e); + + void simulateIt(); + void simulateEntity(RS_Entity * e, const RS_Pen & pen); + void drawLineSmooth(const Vector & p1, const Vector & p2, const RS_Pen & pen); + void drawArcSmooth(const Vector & center, double radius, + double a1, double a2, bool rev, const RS_Pen & pen); + void simulationDelay(bool step = false); + + virtual RS_LineTypePattern * getPattern(RS2::LineType t); + + virtual void drawAbsoluteZero(); + virtual void drawRelativeZero(); + virtual void drawPaper(); + virtual void drawGrid(); + virtual void drawMetaGrid(); + virtual void updateGrid(); + RS_Grid * getGrid(); + virtual void updateGridStatusWidget(const QString & /*text*/); + + void setDefaultSnapMode(RS2::SnapMode sm); + RS2::SnapMode getDefaultSnapMode(); + void setSnapRestriction(RS2::SnapRestriction sr); + RS2::SnapRestriction getSnapRestriction(); + bool isGridOn(); + + Vector toGui(Vector v); + double toGuiX(double x, bool * visible = NULL); + double toGuiY(double y); + double toGuiDX(double d); + double toGuiDY(double d); + + Vector toGraph(Vector v); + Vector toGraph(int x, int y); + double toGraphX(int x); + double toGraphY(int y); + double toGraphDX(int d); + double toGraphDY(int d); + + void lockRelativeZero(bool lock); + bool isRelativeZeroLocked(); + Vector getRelativeZero(); + void setRelativeZero(const Vector & pos); + void moveRelativeZero(const Vector & pos); + + RS_EventHandler * getEventHandler(); + void setPrintPreview(bool pv); + bool isPrintPreview(); + void setPrinting(bool p); + bool isPrinting(); + bool isDraftMode(); + void setSimulationSpeed(int s); + int getSimulationSpeed(); + void setSimulationSmooth(bool s); + void setSimulationRapid(bool r); + bool getSimulationRapid(); + + //this is here because of crappy braindead infrastructure + void SetPreviewMode(bool mode = true); + void SetPreviewEntity(RS_Preview *); + void SetPreviewOffset(Vector); + void SetSnapperDraw(bool); + void SetSnapperVars(Vector snapSpot, Vector snapCoord, bool showCrosshairs); + + protected: + RS_EntityContainer * container; + RS_EventHandler * eventHandler; + + int mx; //!< Last known mouse cursor position + int my; //!< Last known mouse cursor position + + // RS_Painter * painter; + PaintInterface * painter; + /** background color (any color) */ + RS_Color background; + /** foreground color (black or white) */ + RS_Color foreground; + /** grid color */ + RS_Color gridColor; + /** meta grid color */ + RS_Color metaGridColor; + /** selected color */ + RS_Color selectedColor; + /** highlighted color */ + RS_Color highlightedColor; + /** Grid */ + RS_Grid * grid; + /** + * Current default snap mode for this graphic view. Used for new + * actions. + */ + RS2::SnapMode defaultSnapMode; + /** + * Current default snap restriction for this graphic view. Used for new + * actions. + */ + RS2::SnapRestriction defaultSnapRes; + + RS2::DrawingMode drawingMode; + + /** + * Delete mode. If true, all drawing actions will delete in background color + * instead. + */ + bool deleteMode; + //! If true, the simulation is currectly running + bool simulationRunning; + + private: + int updateEnabled; + bool zoomFrozen; + //bool gridVisible; + bool draftMode; + + Vector factor; + int offsetX; + int offsetY; + + Vector previousFactor; + int previousOffsetX; + int previousOffsetY; + + int borderLeft; + int borderTop; + int borderRight; + int borderBottom; + + Vector relativeZero; + bool relativeZeroLocked; + //! Print preview flag + bool printPreview; + //! Active when printing only: + bool printing; + //int drawRecursion; + + //! Simulation speed in percentage + int simulationSpeed; + //! If true, the entity is drawn slowly (pixel by pixel). + bool simulationSmooth; + //! If true, the way between entities is also shown. + bool simulationRapid; + //! Last position (for rapid move) + Vector simulationLast; + + protected: + // crap to make painting with update() possible + RS_Preview * previewEntity; + bool previewMode; + Vector previewOffset; + bool snapperDraw; + Vector snapSpot1; + Vector snapCoord1; + bool showCrosshairs1; }; #endif diff --git a/src/base/rs_previewactioninterface.cpp b/src/base/rs_previewactioninterface.cpp index eb6a5c2..b35fed1 100644 --- a/src/base/rs_previewactioninterface.cpp +++ b/src/base/rs_previewactioninterface.cpp @@ -14,6 +14,10 @@ #include "rs_previewactioninterface.h" +#include "rs_debug.h" +#include "rs_graphicview.h" +#include "rs_preview.h" + /** * Constructor. * diff --git a/src/base/rs_previewactioninterface.h b/src/base/rs_previewactioninterface.h index 61424a8..f29c3a9 100644 --- a/src/base/rs_previewactioninterface.h +++ b/src/base/rs_previewactioninterface.h @@ -2,6 +2,7 @@ #define RS_PREVIEWACTIONINTERFACE_H #include "rs_actioninterface.h" +#include "vector.h" class RS_Preview; diff --git a/src/base/rs_snapper.cpp b/src/base/rs_snapper.cpp index 1ee3007..cc58b1a 100644 --- a/src/base/rs_snapper.cpp +++ b/src/base/rs_snapper.cpp @@ -15,8 +15,8 @@ #include "rs_snapper.h" #include "rs_dialogfactory.h" -#include "rs_entitycontainer.h" #include "drawing.h" +#include "rs_entitycontainer.h" #include "rs_graphicview.h" #include "rs_grid.h" #include "rs_information.h" @@ -212,8 +212,8 @@ Vector RS_Snapper::snapFree(Vector coord) Vector RS_Snapper::snapEndpoint(Vector coord) { Vector vec(false); - vec = container->getNearestEndpoint(coord, NULL/*, &keyEntity*/); + return vec; } @@ -279,6 +279,7 @@ Vector RS_Snapper::snapOnEntity(Vector coord) { Vector vec(false); vec = container->getNearestPointOnEntity(coord, true, NULL, &keyEntity); + return vec; } @@ -291,8 +292,8 @@ Vector RS_Snapper::snapOnEntity(Vector coord) Vector RS_Snapper::snapCenter(Vector coord) { Vector vec(false); - vec = container->getNearestCenter(coord, NULL); + return vec; } @@ -305,8 +306,8 @@ Vector RS_Snapper::snapCenter(Vector coord) Vector RS_Snapper::snapMiddle(Vector coord) { Vector vec(false); - vec = container->getNearestMiddle(coord, NULL); + return vec; } @@ -319,8 +320,8 @@ Vector RS_Snapper::snapMiddle(Vector coord) Vector RS_Snapper::snapDist(Vector coord) { Vector vec(false); - vec = container->getNearestDist(distance, coord, NULL); + return vec; } @@ -333,8 +334,8 @@ Vector RS_Snapper::snapDist(Vector coord) Vector RS_Snapper::snapIntersection(Vector coord) { Vector vec(false); - vec = container->getNearestIntersection(coord, NULL); + return vec; } diff --git a/src/base/rs_snapper.h b/src/base/rs_snapper.h index baceae4..89351d6 100644 --- a/src/base/rs_snapper.h +++ b/src/base/rs_snapper.h @@ -2,14 +2,12 @@ #define RS_SNAPPER_H #include - #include "rs.h" -#include "rs_entitycontainer.h" -#include "rs_coordinateevent.h" +#include "vector.h" class RS_Entity; +class RS_EntityContainer; class RS_GraphicView; -class Vector; /** * This class is used for snapping functions in a graphic view. -- 2.37.2