X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Frs_creation.cpp;h=be969ef3dd5309d2b945021c45712dd6125d50a3;hb=bd2b29c8735d83ab48df13c3efee53f63570473e;hp=fb99b2f25e215529f007e0f334f823d462d950e6;hpb=89e127aa3dbd74d3158e6dbe0ca1703420c04395;p=architektonas diff --git a/src/base/rs_creation.cpp b/src/base/rs_creation.cpp index fb99b2f..be969ef 100644 --- a/src/base/rs_creation.cpp +++ b/src/base/rs_creation.cpp @@ -3,7 +3,9 @@ // 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 +// 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 // @@ -14,11 +16,12 @@ #include "rs_creation.h" -#include #include "rs_constructionline.h" #include "drawing.h" -#include "rs_graphicview.h" +#include "graphicview.h" +#include "rs_image.h" #include "rs_information.h" +#include "rs_insert.h" #include "rs_modification.h" #include "rs_units.h" @@ -29,7 +32,7 @@ * entities. Usually that's an Drawing entity but * it can also be a polyline, text, ... */ -RS_Creation::RS_Creation(RS_EntityContainer * container, RS_GraphicView * graphicView, +RS_Creation::RS_Creation(RS_EntityContainer * container, GraphicView * graphicView, bool handleUndo) { this->container = container; @@ -477,73 +480,61 @@ RS_Circle* RS_Creation::createParallelCircle(const Vector& coord, * @return Pointer to the first bisector created or NULL if no bisectors * were created. */ -RS_Line* RS_Creation::createBisector(const Vector& coord1, - const Vector& coord2, - double length, - int num, - RS_Line* l1, - RS_Line* l2) { +RS_Line * RS_Creation::createBisector(const Vector & coord1, const Vector & coord2, + double length, int num, RS_Line * l1, RS_Line * l2) +{ + // check given entities: + if (!l1 || !l2 || l1->rtti() != RS2::EntityLine || l2->rtti() != RS2::EntityLine) + return NULL; - VectorSolutions sol; + // intersection between entities: + VectorSolutions sol = RS_Information::getIntersection(l1, l2, false); + Vector inters = sol.get(0); - // check given entities: - if (l1==NULL || l2==NULL || - l1->rtti()!=RS2::EntityLine || l2->rtti()!=RS2::EntityLine) { - return NULL; - } + if (!inters.valid) + return NULL; - // intersection between entities: - sol = RS_Information::getIntersection(l1, l2, false); - Vector inters = sol.get(0); - if (inters.valid==false) { - return NULL; - } + double angle1 = inters.angleTo(l1->getNearestPointOnEntity(coord1)); + double angle2 = inters.angleTo(l2->getNearestPointOnEntity(coord2)); + double angleDiff = RS_Math::getAngleDifference(angle1, angle2); - double angle1 = inters.angleTo(l1->getNearestPointOnEntity(coord1)); - double angle2 = inters.angleTo(l2->getNearestPointOnEntity(coord2)); - double angleDiff = RS_Math::getAngleDifference(angle1, angle2); - if (angleDiff>M_PI) { - angleDiff = angleDiff - 2*M_PI; - } - RS_Line* ret = NULL; + if (angleDiff > M_PI) + angleDiff = angleDiff - 2 * M_PI; - if (document!=NULL && handleUndo) { - document->startUndoCycle(); - } + RS_Line * ret = NULL; - for (int n=1; n<=num; ++n) { + if (document && handleUndo) + document->startUndoCycle(); - double angle = angle1 + - (angleDiff / (num+1) * n); + for(int n=1; n<=num; n++) + { + double angle = angle1 + (angleDiff / (num + 1) * n); + Vector v; + v.setPolar(length, angle); + RS_LineData d = RS_LineData(inters, inters + v); + RS_Line * newLine = new RS_Line(container, d); - RS_LineData d; - Vector v; + if (container) + { + newLine->setLayerToActive(); + newLine->setPenToActive(); + container->addEntity(newLine); + } - Vector c; - v.setPolar(length, angle); - d = RS_LineData(inters, inters + v); + if (document && handleUndo) + document->addUndoable(newLine); - RS_Line* newLine = new RS_Line(container, d); - if (container!=NULL) { - newLine->setLayerToActive(); - newLine->setPenToActive(); - container->addEntity(newLine); - } - if (document!=NULL && handleUndo) { - document->addUndoable(newLine); - } - if (graphicView!=NULL) { - graphicView->drawEntity(newLine); - } - if (ret==NULL) { - ret = newLine; - } - } - if (document!=NULL && handleUndo) { - document->endUndoCycle(); - } + if (graphicView) + graphicView->drawEntity(newLine); - return ret; + if (!ret) + ret = newLine; + } + + if (document && handleUndo) + document->endUndoCycle(); + + return ret; } @@ -1056,43 +1047,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. @@ -1147,25 +1134,33 @@ RS_Block * RS_Creation::createBlock(const RS_BlockData & data, //for (uint i=0; icount(); ++i) { //RS_Entity* e = container->entityAt(i); - if (e != NULL && e->isSelected()) + if (e && e->isSelected()) { // delete / redraw entity in graphic view: if (remove) { - if (graphicView != NULL) +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) graphicView->deleteEntity(e); +#endif e->setSelected(false); } else { - if (graphicView != NULL) +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) graphicView->deleteEntity(e); - +#endif e->setSelected(false); - if (graphicView != NULL) +#warning "!!! Old rendering path needs upgrading !!!" +#if 0 + if (graphicView) graphicView->drawEntity(e); +#endif } // add entity to block: @@ -1179,7 +1174,7 @@ RS_Block * RS_Creation::createBlock(const RS_BlockData & data, //i=0; e->changeUndoState(); - if (document != NULL) + if (document) document->addUndoable(e); } }