X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Frs_modification.cpp;h=c43ae64b1eff4dc141fabdd8e1947d006d504fe8;hb=bd2b29c8735d83ab48df13c3efee53f63570473e;hp=1c1b19becb922aa848df8b0f7baadec7df8dc0f6;hpb=16ce54abf01ca3032e42a5bb11a4afcf9014dcca;p=architektonas diff --git a/src/base/rs_modification.cpp b/src/base/rs_modification.cpp index 1c1b19b..c43ae64 100644 --- a/src/base/rs_modification.cpp +++ b/src/base/rs_modification.cpp @@ -1,10 +1,25 @@ +// rs_modification.cpp +// +// Part of the Architektonas Project +// Originally part of QCad Community Edition by Andrew Mustun +// Extensively rewritten and refactored by James L. Hammons +// Portions copyright (C) 2001-2003 RibbonSoft +// Copyright (C) 2010 Underground Software +// See the README and GPLv2 files for licensing and warranty information +// +// JLH = James L. Hammons +// +// Who When What +// --- ---------- ----------------------------------------------------------- +// JLH 06/01/2010 Added this text. :-) +// #include "rs_modification.h" #include "rs_clipboard.h" #include "rs_creation.h" #include "rs_entity.h" -#include "rs_graphic.h" +#include "drawing.h" #include "rs_information.h" #include "rs_insert.h" #include "rs_polyline.h" @@ -15,14 +30,14 @@ * Default constructor. * * @param container The container to which we will add - * entities. Usually that's an RS_Graphic entity but + * entities. Usually that's an Drawing entity but * it can also be a polyline, text, ... * @param graphicView Pointer to graphic view or NULL if you don't want the * any views to be updated. * @param handleUndo true: Handle undo functionalitiy. */ RS_Modification::RS_Modification(RS_EntityContainer & container, - RS_GraphicView * graphicView, bool handleUndo) + GraphicView * graphicView, bool handleUndo) { this->container = &container; this->graphicView = graphicView; @@ -69,24 +84,22 @@ void RS_Modification::remove() */ bool RS_Modification::changeAttributes(RS_AttributesData & data) { - if (container == NULL) + if (!container) { RS_DEBUG->print("RS_Modification::changeAttributes: no valid container", RS_Debug::D_WARNING); return false; } -// Q3PtrList addList; -// addList.setAutoDelete(false); QList addList; - if (document != NULL) + if (document) document->startUndoCycle(); for(RS_Entity * e=container->firstEntity(); e!=NULL; e=container->nextEntity()) { //for (uint i=0; icount(); ++i) { //RS_Entity* e = container->entityAt(i); - if (e != NULL && e->isSelected()) + if (e && e->isSelected()) { RS_Entity * ec = e->clone(); ec->setSelected(false); @@ -124,10 +137,10 @@ bool RS_Modification::changeAttributes(RS_AttributesData & data) deselectOriginals(true); addNewEntities(addList); - if (document != NULL) + if (document) document->endUndoCycle(); - if (graphicView != NULL) + if (graphicView) graphicView->redraw(); return true; @@ -137,7 +150,7 @@ bool RS_Modification::changeAttributes(RS_AttributesData & data) /** * Copies all selected entities from the given container to the clipboard. * Layers and blocks that are needed are also copied if the container is - * or is part of an RS_Graphic. + * or is part of an Drawing. * * @param container The entity container. * @param ref Reference point. The entities will be moved by -ref. @@ -184,70 +197,82 @@ void RS_Modification::copy(const Vector& ref, const bool cut) { /** * Copies the given entity from the given container to the clipboard. * Layers and blocks that are needed are also copied if the container is - * or is part of an RS_Graphic. + * or is part of an Drawing. * * @param e The entity. * @param ref Reference point. The entities will be moved by -ref. * @param cut true: cut instead of copying, false: copy */ -void RS_Modification::copyEntity(RS_Entity* e, const Vector& ref, - const bool cut) { - - if (e!=NULL && e->isSelected()) { - // delete entity in graphic view: - if (cut) { - if (graphicView!=NULL) { - graphicView->deleteEntity(e); - } - e->setSelected(false); - } else { - if (graphicView!=NULL) { - graphicView->deleteEntity(e); - } - e->setSelected(false); - if (graphicView!=NULL) { - graphicView->drawEntity(e); - } - } +void RS_Modification::copyEntity(RS_Entity * e, const Vector & ref, const bool cut) +{ + if (e && e->isSelected()) + { + // delete entity in graphic view: + if (cut) + { +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) + graphicView->deleteEntity(e); +#endif - // add entity to clipboard: - RS_Entity* c = e->clone(); - c->move(-ref); - RS_CLIPBOARD->addEntity(c); + e->setSelected(false); + } + else + { +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) + graphicView->deleteEntity(e); +#endif - copyLayers(e); - copyBlocks(e); + e->setSelected(false); - // set layer to the layer clone: - RS_Layer* l = e->getLayer(); - if (l!=NULL) { - c->setLayer(l->getName()); - } +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) + graphicView->drawEntity(e); +#endif + } - // make sure all sub entities point to layers of the clipboard - if (c->isContainer()) { - RS_EntityContainer* ec = (RS_EntityContainer*)c; + // add entity to clipboard: + RS_Entity * c = e->clone(); + c->move(-ref); + RS_CLIPBOARD->addEntity(c); - for (RS_Entity* e2 = ec->firstEntity(RS2::ResolveAll); e2!=NULL; - e2 = ec->nextEntity(RS2::ResolveAll)) { + copyLayers(e); + copyBlocks(e); - //RS_Entity* e2 = ec->entityAt(i); - RS_Layer* l2 = e2->getLayer(); + // set layer to the layer clone: + RS_Layer * l = e->getLayer(); - if (l2!=NULL) { - e2->setLayer(l2->getName()); - } - } - } + if (l) + c->setLayer(l->getName()); - if (cut) { - e->changeUndoState(); - if (document!=NULL) { - document->addUndoable(e); - } - } - } + // make sure all sub entities point to layers of the clipboard + if (c->isContainer()) + { + RS_EntityContainer * ec = (RS_EntityContainer *)c; + for(RS_Entity * e2=ec->firstEntity(RS2::ResolveAll); e2!=NULL; + e2=ec->nextEntity(RS2::ResolveAll)) + { + //RS_Entity* e2 = ec->entityAt(i); + RS_Layer * l2 = e2->getLayer(); + + if (l2) + e2->setLayer(l2->getName()); + } + } + + if (cut) + { + e->changeUndoState(); + + if (document) + document->addUndoable(e); + } + } } @@ -322,13 +347,13 @@ void RS_Modification::copyBlocks(RS_Entity* e) { /** * Pastes all entities from the clipboard into the container. * Layers and blocks that are needed are also copied if the container is - * or is part of an RS_Graphic. + * or is part of an Drawing. * * @param data Paste data. * @param source The source from where to paste. NULL means the source * is the clipboard. */ -void RS_Modification::paste(const RS_PasteData& data, RS_Graphic* source) { +void RS_Modification::paste(const RS_PasteData& data, Drawing* source) { if (graphic==NULL) { RS_DEBUG->print(RS_Debug::D_WARNING, @@ -1860,39 +1885,47 @@ bool RS_Modification::trim(const Vector& trimCoord, RS_AtomicEntity* trimEntity, } } - if (sol.hasValid()==false) { - return false; - } + if (!sol.hasValid()) + return false; - RS_AtomicEntity* trimmed1 = NULL; - RS_AtomicEntity* trimmed2 = NULL; + RS_AtomicEntity * trimmed1 = NULL; + RS_AtomicEntity * trimmed2 = NULL; - // remove trim entity from view: - if (trimEntity->rtti()==RS2::EntityCircle) { - // convert a circle into a trimmable arc - RS_Circle* c = (RS_Circle*)trimEntity; - double am = c->getCenter().angleTo(trimCoord); - RS_ArcData d(c->getCenter(), - c->getRadius(), - RS_Math::correctAngle(am-M_PI/2), - RS_Math::correctAngle(am+M_PI/2), false); - trimmed1 = new RS_Arc(trimEntity->getParent(), d); - } else { - trimmed1 = (RS_AtomicEntity*)trimEntity->clone(); - trimmed1->setHighlighted(false); - } - if (graphicView!=NULL) { - graphicView->deleteEntity(trimEntity); - } + // remove trim entity from view: + if (trimEntity->rtti() == RS2::EntityCircle) + { + // convert a circle into a trimmable arc + RS_Circle * c = (RS_Circle *)trimEntity; + double am = c->getCenter().angleTo(trimCoord); + RS_ArcData d(c->getCenter(), c->getRadius(), + RS_Math::correctAngle(am - M_PI / 2), + RS_Math::correctAngle(am + M_PI / 2), false); + trimmed1 = new RS_Arc(trimEntity->getParent(), d); + } + else + { + trimmed1 = (RS_AtomicEntity *)trimEntity->clone(); + trimmed1->setHighlighted(false); + } - // remove limit entity from view: - if (both) { - trimmed2 = (RS_AtomicEntity*)limitEntity->clone(); - trimmed2->setHighlighted(false); - if (graphicView!=NULL) { - graphicView->deleteEntity(limitEntity); - } - } +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) + graphicView->deleteEntity(trimEntity); +#endif + + // remove limit entity from view: + if (both) + { + trimmed2 = (RS_AtomicEntity *)limitEntity->clone(); + trimmed2->setHighlighted(false); + +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) + graphicView->deleteEntity(limitEntity); +#endif + } // trim trim entity int ind = 0; @@ -1984,49 +2017,57 @@ bool RS_Modification::trim(const Vector& trimCoord, RS_AtomicEntity* trimEntity, * @param trimEntity Entity which will be trimmed. * @param dist Amount to trim by. */ -bool RS_Modification::trimAmount(const Vector& trimCoord, - RS_AtomicEntity* trimEntity, - double dist) { +bool RS_Modification::trimAmount(const Vector & trimCoord, + RS_AtomicEntity * trimEntity, double dist) +{ + if (!trimEntity) + { + RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Modification::trimAmount: Entity is NULL"); + return false; + } - if (trimEntity==NULL) { - RS_DEBUG->print(RS_Debug::D_WARNING, - "RS_Modification::trimAmount: Entity is NULL"); - return false; - } + RS_AtomicEntity * trimmed = NULL; - RS_AtomicEntity* trimmed = NULL; + // remove trim entity: + trimmed = (RS_AtomicEntity*)trimEntity->clone(); - // remove trim entity: - trimmed = (RS_AtomicEntity*)trimEntity->clone(); - if (graphicView!=NULL) { - graphicView->deleteEntity(trimEntity); - } +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) + graphicView->deleteEntity(trimEntity); +#endif - // trim trim entity - Vector is = trimmed->getNearestDist(-dist, trimCoord); - if (trimCoord.distanceTo(trimmed->getStartpoint()) < - trimCoord.distanceTo(trimmed->getEndpoint())) { - trimmed->trimStartpoint(is); - } else { - trimmed->trimEndpoint(is); - } + // trim trim entity + Vector is = trimmed->getNearestDist(-dist, trimCoord); + if (trimCoord.distanceTo(trimmed->getStartpoint()) < + trimCoord.distanceTo(trimmed->getEndpoint())) + { + trimmed->trimStartpoint(is); + } + else + { + trimmed->trimEndpoint(is); + } - // add new trimmed trim entity: - container->addEntity(trimmed); + // add new trimmed trim entity: + container->addEntity(trimmed); - if (graphicView!=NULL) { - graphicView->drawEntity(trimmed); - } +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) + graphicView->drawEntity(trimmed); +#endif - if (document!=NULL && handleUndo) { - document->startUndoCycle(); - document->addUndoable(trimmed); - trimEntity->setUndoState(true); - document->addUndoable(trimEntity); - document->endUndoCycle(); - } + if (document && handleUndo) + { + document->startUndoCycle(); + document->addUndoable(trimmed); + trimEntity->setUndoState(true); + document->addUndoable(trimEntity); + document->endUndoCycle(); + } - return true; + return true; } @@ -2057,17 +2098,20 @@ bool RS_Modification::cut(const Vector& cutCoord, return false; } - // delete cut entity on the screen: - if (graphicView!=NULL) { - graphicView->deleteEntity(cutEntity); - } +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + // delete cut entity on the screen: + if (graphicView) + graphicView->deleteEntity(cutEntity); +#endif - RS_AtomicEntity* cut1 = NULL; - RS_AtomicEntity* cut2 = NULL; + RS_AtomicEntity * cut1 = NULL; + RS_AtomicEntity * cut2 = NULL; // create new two halves: - if (cutEntity->rtti()==RS2::EntityCircle) { - RS_Circle* c = (RS_Circle*)cutEntity; + if (cutEntity->rtti() == RS2::EntityCircle) + { + RS_Circle * c = (RS_Circle *)cutEntity; cut1 = new RS_Arc(cutEntity->getParent(), RS_ArcData(c->getCenter(), c->getRadius(), @@ -2078,7 +2122,9 @@ bool RS_Modification::cut(const Vector& cutCoord, cut1->trimEndpoint(cutCoord); cut1->trimStartpoint(cutCoord); - } else { + } + else + { cut1 = (RS_AtomicEntity*)cutEntity->clone(); cut2 = (RS_AtomicEntity*)cutEntity->clone(); @@ -2249,17 +2295,25 @@ bool RS_Modification::bevel(const Vector& coord1, RS_AtomicEntity* entity1, trimmed2 = (RS_AtomicEntity*)entity2->clone(); } - // remove trim entity (on screen): - if (data.trim==true || isPolyline) { - if (graphicView!=NULL) { - if (isPolyline) { - graphicView->deleteEntity(baseContainer); - } else { - graphicView->deleteEntity(entity1); - graphicView->deleteEntity(entity2); - } - } - } +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + // remove trim entity (on screen): + if (data.trim || isPolyline) + { + if (graphicView) + { + if (isPolyline) + { + graphicView->deleteEntity(baseContainer); + } + else + { + graphicView->deleteEntity(entity1); + graphicView->deleteEntity(entity2); + } + } + } +#endif // trim entities to intersection RS_DEBUG->print("RS_Modification::bevel: trim entities to intersection 01"); @@ -2536,15 +2590,22 @@ bool RS_Modification::round(const Vector& coord, trimmed2 = (RS_AtomicEntity*)entity2->clone(); } - // remove trim entity: - if (graphicView!=NULL) { - if (isPolyline) { - graphicView->deleteEntity(baseContainer); - } else { - graphicView->deleteEntity(entity1); - graphicView->deleteEntity(entity2); - } - } +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + // remove trim entity: + if (graphicView!=NULL) + { + if (isPolyline) + { + graphicView->deleteEntity(baseContainer); + } + else + { + graphicView->deleteEntity(entity1); + graphicView->deleteEntity(entity2); + } + } +#endif // trim entities to intersection Vector is2 = sol2.getClosest(coord2);