]> Shamusworld >> Repos - architektonas/blobdiff - src/base/rs_insert.cpp
Changed RS_Graphic to Drawing; this is less confusing as a drawing is
[architektonas] / src / base / rs_insert.cpp
index 6c17ba427f8127d91484485e35b369e84f39efd9..ec12668880de62312f7f09ce27535ef896b0e6ae 100644 (file)
@@ -1,33 +1,21 @@
-/****************************************************************************
-** $Id: rs_insert.cpp 2371 2005-04-29 11:44: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.
-**
-**********************************************************************/
+// rs_insert.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 <jlhamm@acm.org>
+//
+// Who  When        What
+// ---  ----------  -----------------------------------------------------------
+// JLH  06/01/2010  Added this text. :-)
+//
 
 #include "rs_insert.h"
 
 #include "rs_block.h"
-#include "rs_graphic.h"
+#include "drawing.h"
 
 /**
  * @param parent The graphic this block belongs to.
@@ -141,22 +129,22 @@ void RS_Insert::update()
        if (updateEnabled == false)
                return;
 
-    clear();
+       clear();
 
-    RS_Block * blk = getBlockForInsert();
+       RS_Block * blk = getBlockForInsert();
 
        if (blk == NULL)
        {
-        //return NULL;
+               //return NULL;
                RS_DEBUG->print("RS_Insert::update: Block is NULL");
-        return;
-    }
+               return;
+       }
 
-    if (isUndone())
+       if (isUndone())
        {
                RS_DEBUG->print("RS_Insert::update: Insert is in undo list");
-        return;
-    }
+               return;
+       }
 
        if (fabs(data.scaleFactor.x) < 1.0e-6 || fabs(data.scaleFactor.y) < 1.0e-6)
        {
@@ -164,86 +152,86 @@ void RS_Insert::update()
                return;
        }
 
-    RS_Pen tmpPen;
+       RS_Pen tmpPen;
 
        /*Q3PtrListIterator<RS_Entity> it = createIterator();
-    RS_Entity* e;
-    while ( (e = it.current()) != NULL ) {
-        ++it;*/
+       RS_Entity* e;
+       while ( (e = it.current()) != NULL ) {
+               ++it;*/
 
        RS_DEBUG->print("RS_Insert::update: cols: %d, rows: %d", data.cols, data.rows);
        RS_DEBUG->print("RS_Insert::update: block has %d entities", blk->count());
 
-    for(RS_Entity * e=blk->firstEntity(); e!=NULL; e=blk->nextEntity())
+       for(RS_Entity * e=blk->firstEntity(); e!=NULL; e=blk->nextEntity())
        {
-        for(int c=0; c<data.cols; ++c)
+               for(int c=0; c<data.cols; ++c)
                {
-            RS_DEBUG->print("RS_Insert::update: col %d", c);
+                       RS_DEBUG->print("RS_Insert::update: col %d", c);
 
                        for(int r=0; r<data.rows; ++r)
                        {
-                RS_DEBUG->print("RS_Insert::update: row %d", r);
+                               RS_DEBUG->print("RS_Insert::update: row %d", r);
 
-                if (e->rtti() == RS2::EntityInsert && data.updateMode != RS2::PreviewUpdate)
+                               if (e->rtti() == RS2::EntityInsert && data.updateMode != RS2::PreviewUpdate)
                                {
                                        RS_DEBUG->print("RS_Insert::update: updating sub-insert");
-                    ((RS_Insert *)e)->update();
-                }
+                                       ((RS_Insert *)e)->update();
+                               }
 
                                RS_DEBUG->print("RS_Insert::update: cloning entity");
 
-                RS_Entity * ne = e->clone();
-                ne->initId();
+                               RS_Entity * ne = e->clone();
+                               ne->initId();
                                ne->setUpdateEnabled(false);
-                ne->setParent(this);
-                ne->setVisible(getFlag(RS2::FlagVisible));
+                               ne->setParent(this);
+                               ne->setVisible(getFlag(RS2::FlagVisible));
 
                                RS_DEBUG->print("RS_Insert::update: transforming entity");
 
-                // Move:
+                               // Move:
                                RS_DEBUG->print("RS_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,
+                                       ne->move(data.insertionPoint + Vector(data.spacing.x / data.scaleFactor.x * c,
                                                data.spacing.y / data.scaleFactor.y * r));
                                }
                                else
                                {
-                       ne->move(data.insertionPoint);
+                                       ne->move(data.insertionPoint);
                                }
 
                                // Move because of block base point:
                                RS_DEBUG->print("RS_Insert::update: move 2");
-                ne->move(blk->getBasePoint() * -1);
-                // Scale:
+                               ne->move(blk->getBasePoint() * -1);
+                               // Scale:
                                RS_DEBUG->print("RS_Insert::update: scale");
-                ne->scale(data.insertionPoint, data.scaleFactor);
-                // Rotate:
+                               ne->scale(data.insertionPoint, data.scaleFactor);
+                               // Rotate:
                                RS_DEBUG->print("RS_Insert::update: rotate");
-                ne->rotate(data.insertionPoint, data.angle);
-                // Select:
-                ne->setSelected(isSelected());
+                               ne->rotate(data.insertionPoint, data.angle);
+                               // Select:
+                               ne->setSelected(isSelected());
 
-                // individual entities can be on indiv. layers
-                tmpPen = ne->getPen(false);
+                               // individual entities can be on indiv. layers
+                               tmpPen = ne->getPen(false);
 
-                // color from block (free floating):
-                if (tmpPen.getColor() == RS_Color(RS2::FlagByBlock))
-                    tmpPen.setColor(getPen().getColor());
+                               // color from block (free floating):
+                               if (tmpPen.getColor() == RS_Color(RS2::FlagByBlock))
+                                       tmpPen.setColor(getPen().getColor());
 
-                // line width from block (free floating):
-                if (tmpPen.getWidth() == RS2::WidthByBlock)
-                    tmpPen.setWidth(getPen().getWidth());
+                               // 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());
+                               // 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());
+                               // 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->setPen(tmpPen);
 
                                ne->setUpdateEnabled(true);
 
@@ -254,10 +242,10 @@ void RS_Insert::update()
                                }
 
                                RS_DEBUG->print("RS_Insert::update: adding new entity");
-                addEntity(ne);
-            }
-        }
-    }
+                               addEntity(ne);
+                       }
+               }
+       }
 
        calculateBorders();
 
@@ -383,23 +371,21 @@ void RS_Insert::move(Vector offset)
     update();
 }
 
-
-
-void RS_Insert::rotate(Vector center, double angle) {
+void RS_Insert::rotate(Vector center, double angle)
+{
        RS_DEBUG->print("RS_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 = RS_Math::correctAngle(data.angle+angle);
+    data.angle = RS_Math::correctAngle(data.angle + angle);
        RS_DEBUG->print("RS_Insert::rotate2: insertionPoint: %f/%f",
                data.insertionPoint.x, data.insertionPoint.y);
     update();
 }
 
-
-
-void RS_Insert::scale(Vector center, Vector factor) {
+void RS_Insert::scale(Vector center, Vector factor)
+{
        RS_DEBUG->print("RS_Insert::scale1: insertionPoint: %f/%f",
                data.insertionPoint.x, data.insertionPoint.y);
     data.insertionPoint.scale(center, factor);
@@ -410,24 +396,22 @@ void RS_Insert::scale(Vector center, Vector factor) {
     update();
 }
 
-
-
-void RS_Insert::mirror(Vector axisPoint1, Vector axisPoint2) {
-    data.insertionPoint.mirror(axisPoint1, axisPoint2);
+void RS_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);
+       vec.mirror(Vector(0.0, 0.0), axisPoint2 - axisPoint1);
        data.angle = vec.angle();
 
-       data.scaleFactor.y*=-1;
+       data.scaleFactor.y *= -1;
 
     update();
 }
 
-
-std::ostream& operator << (std::ostream& os, const RS_Insert& i) {
+std::ostream & operator<<(std::ostream & os, const RS_Insert & i)
+{
     os << " Insert: " << i.getData() << std::endl;
     return os;
 }
-