// 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 <jlhamm@acm.org>
//
#include "rs_constructionline.h"
#include "rs_debug.h"
-#include "rs_graphicview.h"
-#include "paintintf.h"
+#include "graphicview.h"
+#include "rs_line.h"
+#include "paintinterface.h"
/**
* Constructor.
RS_Image::~RS_Image()
{
/*if (img!=NULL) {
- delete[] img;
- }*/
+ delete[] img;
+ }*/
}
RS_Entity * RS_Image::clone()
return i;
}
+/** @return RS2::EntityImage */
+/*virtual*/ RS2::EntityType RS_Image::rtti() const
+{
+ return RS2::EntityImage;
+}
+
void RS_Image::update()
{
RS_DEBUG->print("RS_Image::update");
RS_DEBUG->print("RS_Image::update: OK");
/*
- // number of small images:
- nx = image.width()/100;
- ny = image.height()/100;
-
- // create small images:
- img = new QImage*[nx];
- RS_Pixmap pm;
- int w,h;
- for (int x = 0; x<nx; ++x) {
- img[x] = new QImage[ny];
- for (int y = 0; y<ny; ++y) {
- if (x<nx-1) {
- w = 100;
- }
- else {
- w = image.width()%100;
- }
-
- if (y<ny-1) {
- h = 100;
- }
- else {
- h = image.height()%100;
- }
-
- pm = RS_Pixmap(w, h);
- RS_PainterQt painter(&pm);
- painter.drawImage(-x*100, -y*100, image);
- img[x][y] = pm.convertToImage();
- }
- }
- */
+ // number of small images:
+ nx = image.width()/100;
+ ny = image.height()/100;
+
+ // create small images:
+ img = new QImage*[nx];
+ RS_Pixmap pm;
+ int w,h;
+ for (int x = 0; x<nx; ++x) {
+ img[x] = new QImage[ny];
+ for (int y = 0; y<ny; ++y) {
+ if (x<nx-1) {
+ w = 100;
+ }
+ else {
+ w = image.width()%100;
+ }
+
+ if (y<ny-1) {
+ h = 100;
+ }
+ else {
+ h = image.height()%100;
+ }
+
+ pm = RS_Pixmap(w, h);
+ RS_PainterQt painter(&pm);
+ painter.drawImage(-x*100, -y*100, image);
+ img[x][y] = pm.convertToImage();
+ }
+ }
+ */
+}
+
+/** @return Copy of data that defines the image. */
+RS_ImageData RS_Image::getData() const
+{
+ return data;
+}
+
+/** @return Insertion point of the entity */
+/*virtual*/ Vector RS_Image::getInsertionPoint() const
+{
+ return data.insertionPoint;
+}
+
+/** Sets the insertion point for the image. */
+void RS_Image::setInsertionPoint(Vector ip)
+{
+ data.insertionPoint = ip;
+ calculateBorders();
+}
+
+/** @return File name of the image. */
+QString RS_Image::getFile() const
+{
+ return data.file;
+}
+
+/** Sets the file name of the image. */
+void RS_Image::setFile(const QString & file)
+{
+ data.file = file;
+}
+
+/** @return u Vector. Points along bottom, 1 pixel long. */
+Vector RS_Image::getUVector() const
+{
+ return data.uVector;
+}
+
+/** @return v Vector. Points along left, 1 pixel long. */
+Vector RS_Image::getVVector() const
+{
+ return data.vVector;
+}
+
+/** @return Width of image in pixels. */
+int RS_Image::getWidth() const
+{
+ return (int)data.size.x;
+}
+
+/** @return Height of image in pixels. */
+int RS_Image::getHeight() const
+{
+ return (int)data.size.y;
+}
+
+/** @return Brightness. */
+int RS_Image::getBrightness() const
+{
+ return data.brightness;
+}
+
+/** @return Contrast. */
+int RS_Image::getContrast() const
+{
+ return data.contrast;
+}
+
+/** @return Fade. */
+int RS_Image::getFade() const
+{
+ return data.fade;
+}
+
+/** @return Image definition handle. */
+int RS_Image::getHandle() const
+{
+ return data.handle;
+}
+
+/** Sets the image definition handle. */
+void RS_Image::setHandle(int h)
+{
+ data.handle = h;
+}
+
+/** @return The four corners. **/
+VectorSolutions RS_Image::getCorners()
+{
+ VectorSolutions sol(4);
+
+ sol.set(0, data.insertionPoint);
+ sol.set(1,
+ data.insertionPoint + data.uVector * RS_Math::round(data.size.x));
+ sol.set(3,
+ data.insertionPoint + data.vVector * RS_Math::round(data.size.y));
+ sol.set(2, sol.get(3) + data.uVector * RS_Math::round(data.size.x));
+
+ return sol;
+}
+
+/**
+ * @return image with in graphic units.
+ */
+double RS_Image::getImageWidth()
+{
+ return data.size.x * data.uVector.magnitude();
+}
+
+/**
+ * @return image height in graphic units.
+ */
+double RS_Image::getImageHeight()
+{
+ return data.size.y * data.vVector.magnitude();
}
void RS_Image::calculateBorders()
resetBorders();
VectorSolutions sol = getCorners();
- for(int i=0; i<4; ++i)
+ for (int i = 0; i < 4; ++i)
{
minV = Vector::minimum(minV, sol.get(i));
maxV = Vector::maximum(maxV, sol.get(i));
return corners.getClosest(coord, dist);
}
-Vector RS_Image::getNearestPointOnEntity(const Vector & coord, bool onEntity, double * dist,
- RS_Entity ** entity)
+Vector RS_Image::getNearestPointOnEntity(const Vector & coord, bool onEntity, double * dist, RS_Entity * * entity)
{
if (entity != NULL)
*entity = this;
RS_Line(NULL, RS_LineData(corners.get(3), corners.get(0)))
};
- for(int i=0; i<4; ++i)
+ for (int i = 0; i < 4; ++i)
points.set(i, l[i].getNearestPointOnEntity(coord, onEntity));
return points.getClosest(coord, dist);
VectorSolutions points(4);
VectorSolutions corners = getCorners();
- points.set(0, (corners.get(0) + corners.get(1))/2.0);
- points.set(1, (corners.get(1) + corners.get(2))/2.0);
- points.set(2, (corners.get(2) + corners.get(3))/2.0);
- points.set(3, (corners.get(3) + corners.get(0))/2.0);
+ points.set(0, (corners.get(0) + corners.get(1)) / 2.0);
+ points.set(1, (corners.get(1) + corners.get(2)) / 2.0);
+ points.set(2, (corners.get(2) + corners.get(3)) / 2.0);
+ points.set(3, (corners.get(3) + corners.get(0)) / 2.0);
return points.getClosest(coord, dist);
}
-
-
-Vector RS_Image::getNearestMiddle(const Vector& coord,
- double* dist) {
- return getNearestCenter(coord, dist);
+Vector RS_Image::getNearestMiddle(const Vector & coord, double * dist)
+{
+ return getNearestCenter(coord, dist);
}
+Vector RS_Image::getNearestDist(double distance, const Vector & coord, double * dist)
+{
+ VectorSolutions corners = getCorners();
+ VectorSolutions points(4);
+ RS_Line l[] =
+ {
+ RS_Line(NULL, RS_LineData(corners.get(0), corners.get(1))),
+ RS_Line(NULL, RS_LineData(corners.get(1), corners.get(2))),
+ RS_Line(NULL, RS_LineData(corners.get(2), corners.get(3))),
+ RS_Line(NULL, RS_LineData(corners.get(3), corners.get(0)))
+ };
-Vector RS_Image::getNearestDist(double distance,
- const Vector& coord,
- double* dist) {
-
- VectorSolutions corners = getCorners();
- VectorSolutions points(4);
-
- RS_Line l[] =
- {
- RS_Line(NULL, RS_LineData(corners.get(0), corners.get(1))),
- RS_Line(NULL, RS_LineData(corners.get(1), corners.get(2))),
- RS_Line(NULL, RS_LineData(corners.get(2), corners.get(3))),
- RS_Line(NULL, RS_LineData(corners.get(3), corners.get(0)))
- };
-
- for (int i=0; i<4; ++i) {
- points.set(i, l[i].getNearestDist(distance, coord, dist));
- }
+ for (int i = 0; i < 4; ++i)
+ points.set(i, l[i].getNearestDist(distance, coord, dist));
- return points.getClosest(coord, dist);
+ return points.getClosest(coord, dist);
}
+double RS_Image::getDistanceToPoint(const Vector & coord, RS_Entity * * entity, RS2::ResolveLevel /*level*/, double /*solidDist*/)
+{
+ if (entity != NULL)
+ *entity = this;
+ VectorSolutions corners = getCorners();
+ double dist;
+ double minDist = RS_MAXDOUBLE;
-double RS_Image::getDistanceToPoint(const Vector& coord,
- RS_Entity** entity,
- RS2::ResolveLevel /*level*/,
- double /*solidDist*/) {
- if (entity!=NULL) {
- *entity = this;
- }
-
- VectorSolutions corners = getCorners();
- double dist;
- double minDist = RS_MAXDOUBLE;
+ RS_Line l[] =
+ {
+ RS_Line(NULL, RS_LineData(corners.get(0), corners.get(1))),
+ RS_Line(NULL, RS_LineData(corners.get(1), corners.get(2))),
+ RS_Line(NULL, RS_LineData(corners.get(2), corners.get(3))),
+ RS_Line(NULL, RS_LineData(corners.get(3), corners.get(0)))
+ };
- RS_Line l[] =
- {
- RS_Line(NULL, RS_LineData(corners.get(0), corners.get(1))),
- RS_Line(NULL, RS_LineData(corners.get(1), corners.get(2))),
- RS_Line(NULL, RS_LineData(corners.get(2), corners.get(3))),
- RS_Line(NULL, RS_LineData(corners.get(3), corners.get(0)))
- };
+ for (int i = 0; i < 4; ++i)
+ {
+ dist = l[i].getDistanceToPoint(coord, NULL);
- for (int i=0; i<4; ++i) {
- dist = l[i].getDistanceToPoint(coord, NULL);
- if (dist<minDist) {
- minDist = dist;
- }
- }
+ if (dist < minDist)
+ minDist = dist;
+ }
- return minDist;
+ return minDist;
}
-
-
-void RS_Image::move(Vector offset) {
- data.insertionPoint.move(offset);
- calculateBorders();
+/*virtual*/ double RS_Image::getLength()
+{
+ return -1.0;
}
-
-
-void RS_Image::rotate(Vector center, double angle) {
- data.insertionPoint.rotate(center, angle);
- data.uVector.rotate(angle);
- data.vVector.rotate(angle);
- calculateBorders();
+void RS_Image::move(Vector offset)
+{
+ data.insertionPoint.move(offset);
+ calculateBorders();
}
-
-
-void RS_Image::scale(Vector center, Vector factor) {
- data.insertionPoint.scale(center, factor);
- data.uVector.scale(factor);
- data.vVector.scale(factor);
- calculateBorders();
+void RS_Image::rotate(Vector center, double angle)
+{
+ data.insertionPoint.rotate(center, angle);
+ data.uVector.rotate(angle);
+ data.vVector.rotate(angle);
+ calculateBorders();
}
+void RS_Image::scale(Vector center, Vector factor)
+{
+ data.insertionPoint.scale(center, factor);
+ data.uVector.scale(factor);
+ data.vVector.scale(factor);
+ calculateBorders();
+}
-
-void RS_Image::mirror(Vector axisPoint1, Vector axisPoint2) {
- data.insertionPoint.mirror(axisPoint1, axisPoint2);
- data.uVector.mirror(Vector(0.0,0.0), axisPoint2-axisPoint1);
- data.vVector.mirror(Vector(0.0,0.0), axisPoint2-axisPoint1);
- calculateBorders();
+void RS_Image::mirror(Vector axisPoint1, Vector axisPoint2)
+{
+ data.insertionPoint.mirror(axisPoint1, axisPoint2);
+ data.uVector.mirror(Vector(0.0, 0.0), axisPoint2 - axisPoint1);
+ data.vVector.mirror(Vector(0.0, 0.0), axisPoint2 - axisPoint1);
+ calculateBorders();
}
-//void RS_Image::draw(RS_Painter* painter, RS_GraphicView* view, double /*patternOffset*/) {
-void RS_Image::draw(PaintInterface * painter, RS_GraphicView * view, double /*patternOffset*/)
+void RS_Image::draw(PaintInterface * painter, GraphicView * view, double /*patternOffset*/)
{
if (painter == NULL || view == NULL || img.isNull())
return;
int height = view->getHeight();
Vector scale = Vector(view->toGuiDX(data.uVector.magnitude()),
- view->toGuiDY(data.vVector.magnitude()));
+ view->toGuiDY(data.vVector.magnitude()));
double angle = data.uVector.angle();
int startX, stopX, startY, stopY;
if (data.uVector.x > 1.0e-6 && data.vVector.y > 1.0e-6)
{
- startX = (int)((view->toGraphX(ox)-data.insertionPoint.x) / data.uVector.x) - 1;
+ startX = (int)((view->toGraphX(ox) - data.insertionPoint.x) / data.uVector.x) - 1;
if (startX < 0)
- {
startX = 0;
- }
- stopX = (int)((view->toGraphX(width)-data.insertionPoint.x) / data.uVector.x) + 1;
+ stopX = (int)((view->toGraphX(width) - data.insertionPoint.x) / data.uVector.x) + 1;
if (stopX > (int)data.size.x)
- {
stopX = (int)data.size.x;
- }
- startY = -(int)((view->toGraphY(oy) - (data.insertionPoint.y+getImageHeight())) /
- data.vVector.y) - 1;
+ startY = -(int)((view->toGraphY(oy) - (data.insertionPoint.y + getImageHeight()))
+ / data.vVector.y) - 1;
- if (startY<0)
- {
+ if (startY < 0)
startY = 0;
- }
- stopY = -(int)((view->toGraphY(height) - (data.insertionPoint.y+getImageHeight())) /
- data.vVector.y) + 1;
+ stopY = -(int)((view->toGraphY(height) - (data.insertionPoint.y + getImageHeight()))
+ / data.vVector.y) + 1;
- if (stopY>(int)data.size.y)
- {
+ if (stopY > (int)data.size.y)
stopY = (int)data.size.y;
- }
}
else
{
}
painter->drawImg(img, view->toGui(data.insertionPoint), angle, scale,
- startX, startY, stopX-startX, stopY-startY);
+ startX, startY, stopX - startX, stopY - startY);
if (isSelected())
{
os << " Image: " << i.getData() << "\n";
return os;
}
-