X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Finsert.cpp;fp=src%2Fbase%2Finsert.cpp;h=0000000000000000000000000000000000000000;hb=9f6ad3fe0b9cb30115a5d38e8af3aebed0d70c08;hp=7cc6a9ac63d2149e1ec17ccbca7e15438234efd4;hpb=43c13b052d069ba435277d93867380d00c04931f;p=architektonas diff --git a/src/base/insert.cpp b/src/base/insert.cpp deleted file mode 100644 index 7cc6a9a..0000000 --- a/src/base/insert.cpp +++ /dev/null @@ -1,399 +0,0 @@ -// insert.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 "insert.h" - -#include "block.h" -#include "drawing.h" - -/** - * @param parent The graphic this block belongs to. - */ -Insert::Insert(EntityContainer * parent, const InsertData & d): - EntityContainer(parent), data(d) -{ - block = NULL; - - if (data.updateMode != RS2::NoUpdate) - { - update(); - //calculateBorders(); - } -} - -/** - * Destructor. - */ -Insert::~Insert() -{ -} - -/*virtual*/ Entity * Insert::clone() -{ - Insert * i = new Insert(*this); -#warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!" -// i->entities.setAutoDelete(entities.autoDelete()); - i->initId(); - i->detach(); - return i; -} - -/** @return RS2::EntityInsert */ -/*virtual*/ RS2::EntityType Insert::rtti() const -{ - return RS2::EntityInsert; -} - -/** @return Copy of data that defines the insert. **/ -InsertData Insert::getData() const -{ - return data; -} - -/** - * Reimplementation of reparent. Invalidates block cache pointer. - */ -/*virtual*/ void Insert::reparent(EntityContainer * parent) -{ - Entity::reparent(parent); - block = NULL; -} - -/** - * @return Pointer to the block associated with this Insert or - * NULL if the block couldn't be found. Blocks are requested - * from the blockSource if one was supplied and otherwise from - * the closest parent graphic. - */ -Block * Insert::getBlockForInsert() -{ - if (block) - return block; - - BlockList * blkList; - - if (!data.blockSource) - blkList = (GetDrawing() ? GetDrawing()->getBlockList() : NULL); - else - blkList = data.blockSource; - - Block * blk = NULL; - - if (blkList) - blk = blkList->find(data.name); - - block = blk; - - return blk; -} - -/** - * Updates the entity buffer of this insert entity. This method - * needs to be called whenever the block this insert is based on changes. - */ -void Insert::update() -{ - DEBUG->print("Insert::update"); - DEBUG->print("Insert::update: name: %s", data.name.toLatin1().data()); - DEBUG->print("Insert::update: insertionPoint: %f/%f", - data.insertionPoint.x, data.insertionPoint.y); - - if (!updateEnabled) - return; - - clear(); - Block * blk = getBlockForInsert(); - - if (!blk) - { - DEBUG->print("Insert::update: Block is NULL"); - return; - } - - if (isUndone()) - { - DEBUG->print("Insert::update: Insert is in undo list"); - return; - } - - if (fabs(data.scaleFactor.x) < 1.0e-6 || fabs(data.scaleFactor.y) < 1.0e-6) - { - DEBUG->print("Insert::update: scale factor is 0"); - return; - } - - Pen tmpPen; - - /*Q3PtrListIterator it = createIterator(); - Entity* e; - while ( (e = it.current()) != NULL ) { - ++it;*/ - - DEBUG->print("Insert::update: cols: %d, rows: %d", data.cols, data.rows); - DEBUG->print("Insert::update: block has %d entities", blk->count()); - - for(Entity * e=blk->firstEntity(); e!=NULL; e=blk->nextEntity()) - { - for(int c=0; cprint("Insert::update: col %d", c); - - for(int r=0; rprint("Insert::update: row %d", r); - - if (e->rtti() == RS2::EntityInsert && data.updateMode != RS2::PreviewUpdate) - { - DEBUG->print("Insert::update: updating sub-insert"); - ((Insert *)e)->update(); - } - - DEBUG->print("Insert::update: cloning entity"); - - Entity * ne = e->clone(); - ne->initId(); - ne->setUpdateEnabled(false); - ne->setParent(this); - ne->setVisible(getFlag(RS2::FlagVisible)); - - DEBUG->print("Insert::update: transforming entity"); - - // Move: - DEBUG->print("Insert::update: move 1"); - if (fabs(data.scaleFactor.x) > 1.0e-6 && fabs(data.scaleFactor.y) > 1.0e-6) - { - ne->move(data.insertionPoint + Vector(data.spacing.x / data.scaleFactor.x * c, data.spacing.y / data.scaleFactor.y * r)); - } - else - { - ne->move(data.insertionPoint); - } - - // Move because of block base point: - DEBUG->print("Insert::update: move 2"); - ne->move(blk->getBasePoint() * -1); - // Scale: - DEBUG->print("Insert::update: scale"); - ne->scale(data.insertionPoint, data.scaleFactor); - // Rotate: - DEBUG->print("Insert::update: rotate"); - ne->rotate(data.insertionPoint, data.angle); - // Select: - ne->setSelected(isSelected()); - - // individual entities can be on indiv. layers - tmpPen = ne->getPen(false); - - // color from block (free floating): - if (tmpPen.getColor() == Color(RS2::FlagByBlock)) - tmpPen.setColor(getPen().getColor()); - - // line width from block (free floating): - if (tmpPen.getWidth() == RS2::WidthByBlock) - tmpPen.setWidth(getPen().getWidth()); - - // line type from block (free floating): - if (tmpPen.getLineType() == RS2::LineByBlock) - tmpPen.setLineType(getPen().getLineType()); - - // now that we've evaluated all flags, let's strip them: - // TODO: strip all flags (width, line type) - //tmpPen.setColor(tmpPen.getColor().stripFlags()); - - ne->setPen(tmpPen); - - ne->setUpdateEnabled(true); - - if (data.updateMode != RS2::PreviewUpdate) - { - DEBUG->print("Insert::update: updating new entity"); - ne->update(); - } - - DEBUG->print("Insert::update: adding new entity"); - addEntity(ne); - } - } - } - - calculateBorders(); - - DEBUG->print("Insert::update: OK"); -} - -QString Insert::getName() const -{ - return data.name; -} - -void Insert::setName(const QString & newName) -{ - data.name = newName; - update(); -} - -Vector Insert::getInsertionPoint() const -{ - return data.insertionPoint; -} - -void Insert::setInsertionPoint(const Vector & i) -{ - data.insertionPoint = i; -} - -Vector Insert::getScale() const -{ - return data.scaleFactor; -} - -void Insert::setScale(const Vector & s) -{ - data.scaleFactor = s; -} - -double Insert::getAngle() const -{ - return data.angle; -} - -void Insert::setAngle(double a) -{ - data.angle = a; -} - -int Insert::getCols() const -{ - return data.cols; -} - -void Insert::setCols(int c) -{ - data.cols = c; -} - -int Insert::getRows() const -{ - return data.rows; -} - -void Insert::setRows(int r) -{ - data.rows = r; -} - -Vector Insert::getSpacing() const -{ - return data.spacing; -} - -void Insert::setSpacing(const Vector & s) -{ - data.spacing = s; -} - -/** - * Is this insert visible? (re-implementation from Entity) - * - * @return true Only if the entity and the block and the layer it is on - * are visible. - * The Layer might also be NULL. In that case the layer visiblity - * is ignored. - * The Block might also be NULL. In that case the block visiblity - * is ignored. - */ -bool Insert::isVisible() -{ - Block * blk = getBlockForInsert(); - - if (blk != NULL) - { - if (blk->isFrozen()) - { - return false; - } - } - - return Entity::isVisible(); -} - -VectorSolutions Insert::getRefPoints() -{ - VectorSolutions ret(data.insertionPoint); - return ret; -} - -Vector Insert::getNearestRef(const Vector & coord, double * dist) -{ - return getRefPoints().getClosest(coord, dist); -} - -void Insert::move(Vector offset) -{ - DEBUG->print("Insert::move: offset: %f/%f", - offset.x, offset.y); - DEBUG->print("Insert::move1: insertionPoint: %f/%f", - data.insertionPoint.x, data.insertionPoint.y); - data.insertionPoint.move(offset); - DEBUG->print("Insert::move2: insertionPoint: %f/%f", - data.insertionPoint.x, data.insertionPoint.y); - update(); -} - -void Insert::rotate(Vector center, double angle) -{ - DEBUG->print("Insert::rotate1: insertionPoint: %f/%f " - "/ center: %f/%f", - data.insertionPoint.x, data.insertionPoint.y, - center.x, center.y); - data.insertionPoint.rotate(center, angle); - data.angle = Math::correctAngle(data.angle + angle); - DEBUG->print("Insert::rotate2: insertionPoint: %f/%f", - data.insertionPoint.x, data.insertionPoint.y); - update(); -} - -void Insert::scale(Vector center, Vector factor) -{ - DEBUG->print("Insert::scale1: insertionPoint: %f/%f", - data.insertionPoint.x, data.insertionPoint.y); - data.insertionPoint.scale(center, factor); - data.scaleFactor.scale(Vector(0.0, 0.0), factor); - data.spacing.scale(Vector(0.0, 0.0), factor); - DEBUG->print("Insert::scale2: insertionPoint: %f/%f", - data.insertionPoint.x, data.insertionPoint.y); - update(); -} - -void Insert::mirror(Vector axisPoint1, Vector axisPoint2) -{ - data.insertionPoint.mirror(axisPoint1, axisPoint2); - - Vector vec; - vec.setPolar(1.0, data.angle); - vec.mirror(Vector(0.0, 0.0), axisPoint2 - axisPoint1); - data.angle = vec.angle(); - - data.scaleFactor.y *= -1; - - update(); -} - -std::ostream & operator<<(std::ostream & os, const Insert & i) -{ - os << " Insert: " << i.getData() << std::endl; - return os; -}