X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fbase%2Fhatch.cpp;h=f7442deb5eb6e5658f421713be0c67e820558e5c;hb=2ee84c5948ede7fc2f7b4435c5edef42a030ac05;hp=1ff09027d1520d598dd7fa39c4b03ce25c335482;hpb=3239ef39dcee08fa6e8cd68cdf2727fc68cc7a8c;p=architektonas diff --git a/src/base/hatch.cpp b/src/base/hatch.cpp index 1ff0902..f7442de 100644 --- a/src/base/hatch.cpp +++ b/src/base/hatch.cpp @@ -27,21 +27,21 @@ /** * Constructor. */ -RS_Hatch::RS_Hatch(RS_EntityContainer * parent, const RS_HatchData & d): - RS_EntityContainer(parent), data(d) +Hatch::Hatch(EntityContainer * parent, const HatchData & d): + EntityContainer(parent), data(d) { hatch = NULL; updateRunning = false; needOptimization = true; } -/*virtual*/ RS_Hatch::~RS_Hatch() +/*virtual*/ Hatch::~Hatch() { } -RS_Entity * RS_Hatch::clone() +Entity * Hatch::clone() { - RS_Hatch * t = new RS_Hatch(*this); + Hatch * t = new Hatch(*this); #warning "!!! Need to deal with setAutoDelete() Qt3->Qt4 !!!" // t->entities.setAutoDelete(entities.autoDelete()); t->initId(); @@ -51,7 +51,7 @@ RS_Entity * RS_Hatch::clone() } /** @return RS2::EntityHatch */ -/*virtual*/ RS2::EntityType RS_Hatch::rtti() const +/*virtual*/ RS2::EntityType Hatch::rtti() const { return RS2::EntityHatch; } @@ -60,7 +60,7 @@ RS_Entity * RS_Hatch::clone() * @return true: if this is a hatch with lines (hatch pattern), * false: if this is filled with a solid color. */ -/*virtual*/ bool RS_Hatch::isContainer() const +/*virtual*/ bool Hatch::isContainer() const { if (isSolid()) return false; @@ -69,7 +69,7 @@ RS_Entity * RS_Hatch::clone() } /** @return Copy of data that defines the hatch. */ -RS_HatchData RS_Hatch::getData() const +HatchData Hatch::getData() const { return data; } @@ -77,16 +77,16 @@ RS_HatchData RS_Hatch::getData() const /** * Validates the hatch. */ -bool RS_Hatch::validate() +bool Hatch::validate() { bool ret = true; // loops: - for(RS_Entity * l=firstEntity(RS2::ResolveNone); l!=NULL; l=nextEntity(RS2::ResolveNone)) + for(Entity * l=firstEntity(RS2::ResolveNone); l!=NULL; l=nextEntity(RS2::ResolveNone)) { if (l->rtti() == RS2::EntityContainer) { - RS_EntityContainer * loop = (RS_EntityContainer *)l; + EntityContainer * loop = (EntityContainer *)l; ret = loop->optimizeContours() && ret; } } @@ -97,7 +97,7 @@ bool RS_Hatch::validate() /** * @return Number of loops. */ -int RS_Hatch::countLoops() +int Hatch::countLoops() { if (data.solid) return count(); @@ -106,42 +106,42 @@ int RS_Hatch::countLoops() } /** @return true if this is a solid fill. false if it is a pattern hatch. */ -bool RS_Hatch::isSolid() const +bool Hatch::isSolid() const { return data.solid; } -void RS_Hatch::setSolid(bool solid) +void Hatch::setSolid(bool solid) { data.solid = solid; } -QString RS_Hatch::getPattern() +QString Hatch::getPattern() { return data.pattern; } -void RS_Hatch::setPattern(const QString & pattern) +void Hatch::setPattern(const QString & pattern) { data.pattern = pattern; } -double RS_Hatch::getScale() +double Hatch::getScale() { return data.scale; } -void RS_Hatch::setScale(double scale) +void Hatch::setScale(double scale) { data.scale = scale; } -double RS_Hatch::getAngle() +double Hatch::getAngle() { return data.angle; } -void RS_Hatch::setAngle(double angle) +void Hatch::setAngle(double angle) { data.angle = angle; } @@ -149,14 +149,14 @@ void RS_Hatch::setAngle(double angle) /** * Recalculates the borders of this hatch. */ -void RS_Hatch::calculateBorders() +void Hatch::calculateBorders() { - RS_DEBUG->print("RS_Hatch::calculateBorders"); + DEBUG->print("Hatch::calculateBorders"); activateContour(true); - RS_EntityContainer::calculateBorders(); + EntityContainer::calculateBorders(); - RS_DEBUG->print("RS_Hatch::calculateBorders: size: %f,%f", getSize().x, getSize().y); + DEBUG->print("Hatch::calculateBorders: size: %f,%f", getSize().x, getSize().y); activateContour(false); } @@ -165,10 +165,10 @@ void RS_Hatch::calculateBorders() * Updates the Hatch. Called when the * hatch or it's data, position, alignment, .. changes. */ -void RS_Hatch::update() +void Hatch::update() { - RS_DEBUG->print("RS_Hatch::update"); - RS_DEBUG->print("RS_Hatch::update: contour has %d loops", count()); + DEBUG->print("Hatch::update"); + DEBUG->print("Hatch::update: contour has %d loops", count()); if (updateRunning) return; @@ -179,7 +179,7 @@ void RS_Hatch::update() if (data.solid == true) return; - RS_DEBUG->print("RS_Hatch::update"); + DEBUG->print("Hatch::update"); updateRunning = true; // delete old hatch: @@ -197,39 +197,39 @@ void RS_Hatch::update() if (!validate()) { - RS_DEBUG->print(RS_Debug::D_WARNING, "RS_Hatch::update: invalid contour in hatch found"); + DEBUG->print(Debug::D_WARNING, "Hatch::update: invalid contour in hatch found"); updateRunning = false; return; } // search pattern: - RS_DEBUG->print("RS_Hatch::update: requesting pattern"); - RS_Pattern * pat = RS_PATTERNLIST->requestPattern(data.pattern); + DEBUG->print("Hatch::update: requesting pattern"); + Pattern * pat = PATTERNLIST->requestPattern(data.pattern); if (pat == NULL) { updateRunning = false; - RS_DEBUG->print("RS_Hatch::update: requesting pattern: not found"); + DEBUG->print("Hatch::update: requesting pattern: not found"); return; } - RS_DEBUG->print("RS_Hatch::update: requesting pattern: OK"); + DEBUG->print("Hatch::update: requesting pattern: OK"); - RS_DEBUG->print("RS_Hatch::update: cloning pattern"); - pat = (RS_Pattern*)pat->clone(); - RS_DEBUG->print("RS_Hatch::update: cloning pattern: OK"); + DEBUG->print("Hatch::update: cloning pattern"); + pat = (Pattern*)pat->clone(); + DEBUG->print("Hatch::update: cloning pattern: OK"); // scale pattern - RS_DEBUG->print("RS_Hatch::update: scaling pattern"); + DEBUG->print("Hatch::update: scaling pattern"); pat->scale(Vector(0.0,0.0), Vector(data.scale, data.scale)); pat->calculateBorders(); forcedCalculateBorders(); - RS_DEBUG->print("RS_Hatch::update: scaling pattern: OK"); + DEBUG->print("Hatch::update: scaling pattern: OK"); // find out how many pattern-instances we need in x/y: int px1, py1, px2, py2; double f; - RS_Hatch * copy = (RS_Hatch *)this->clone(); + Hatch * copy = (Hatch *)this->clone(); copy->rotate(Vector(0.0, 0.0), -data.angle); copy->forcedCalculateBorders(); @@ -238,8 +238,8 @@ void RS_Hatch::update() Vector cPos = getMin(); Vector cSize = getSize(); - RS_DEBUG->print("RS_Hatch::update: pattern size: %f/%f", pSize.x, pSize.y); - RS_DEBUG->print("RS_Hatch::update: contour size: %f/%f", cSize.x, cSize.y); + DEBUG->print("Hatch::update: pattern size: %f/%f", pSize.x, pSize.y); + DEBUG->print("Hatch::update: contour size: %f/%f", cSize.x, cSize.y); if (cSize.x < 1.0e-6 || cSize.y < 1.0e-6 || pSize.x < 1.0e-6 || pSize.y < 1.0e-6 || cSize.x > RS_MAXDOUBLE - 1 || cSize.y > RS_MAXDOUBLE - 1 @@ -248,13 +248,13 @@ void RS_Hatch::update() delete pat; delete copy; updateRunning = false; - RS_DEBUG->print("RS_Hatch::update: contour size or pattern size too small"); + DEBUG->print("Hatch::update: contour size or pattern size too small"); return; } // avoid huge memory consumption: else if (cSize.x / pSize.x > 100 || cSize.y / pSize.y > 100) { - RS_DEBUG->print("RS_Hatch::update: contour size too large or pattern size too small"); + DEBUG->print("Hatch::update: contour size too large or pattern size too small"); return; } @@ -267,18 +267,18 @@ void RS_Hatch::update() f = copy->getMax().y/pat->getSize().y; py2 = (int)ceil(f) - 1; - RS_EntityContainer tmp; // container for untrimmed lines + EntityContainer tmp; // container for untrimmed lines // adding array of patterns to tmp: - RS_DEBUG->print("RS_Hatch::update: creating pattern carpet"); + DEBUG->print("Hatch::update: creating pattern carpet"); for(int px=px1; px<=px2; px++) { for(int py=py1; py<=py2; py++) { - for(RS_Entity * e=pat->firstEntity(); e!=NULL; e=pat->nextEntity()) + for(Entity * e=pat->firstEntity(); e!=NULL; e=pat->nextEntity()) { - RS_Entity * te = e->clone(); + Entity * te = e->clone(); te->rotate(Vector(0.0, 0.0), data.angle); Vector v1, v2; v1.setPolar(px * pSize.x, data.angle); @@ -291,16 +291,16 @@ void RS_Hatch::update() delete pat; pat = NULL; - RS_DEBUG->print("RS_Hatch::update: creating pattern carpet: OK"); + DEBUG->print("Hatch::update: creating pattern carpet: OK"); - RS_DEBUG->print("RS_Hatch::update: cutting pattern carpet"); + DEBUG->print("Hatch::update: cutting pattern carpet"); // cut pattern to contour shape: - RS_EntityContainer tmp2; // container for small cut lines - RS_Line * line = NULL; - RS_Arc * arc = NULL; - RS_Circle * circle = NULL; + EntityContainer tmp2; // container for small cut lines + Line * line = NULL; + Arc * arc = NULL; + Circle * circle = NULL; - for(RS_Entity * e=tmp.firstEntity(); e!=NULL; e=tmp.nextEntity()) + for(Entity * e=tmp.firstEntity(); e!=NULL; e=tmp.nextEntity()) { Vector startPoint; Vector endPoint; @@ -309,7 +309,7 @@ void RS_Hatch::update() if (e->rtti() == RS2::EntityLine) { - line = (RS_Line *)e; + line = (Line *)e; arc = NULL; circle = NULL; startPoint = line->getStartpoint(); @@ -319,7 +319,7 @@ void RS_Hatch::update() } else if (e->rtti() == RS2::EntityArc) { - arc = (RS_Arc *)e; + arc = (Arc *)e; line = NULL; circle = NULL; startPoint = arc->getStartpoint(); @@ -329,7 +329,7 @@ void RS_Hatch::update() } else if (e->rtti() == RS2::EntityCircle) { - circle = (RS_Circle *)e; + circle = (Circle *)e; line = NULL; arc = NULL; startPoint = circle->getCenter() + Vector(circle->getRadius(), 0.0); @@ -348,20 +348,20 @@ void RS_Hatch::update() // is.setAutoDelete(true); is.append(new Vector(startPoint)); - for(RS_Entity * loop=firstEntity(); loop!=NULL; loop=nextEntity()) + for(Entity * loop=firstEntity(); loop!=NULL; loop=nextEntity()) { if (loop->isContainer()) { - for(RS_Entity * p=((RS_EntityContainer *)loop)->firstEntity(); p!=NULL; p=((RS_EntityContainer*)loop)->nextEntity()) + for(Entity * p=((EntityContainer *)loop)->firstEntity(); p!=NULL; p=((EntityContainer*)loop)->nextEntity()) { - VectorSolutions sol = RS_Information::getIntersection(e, p, true); + VectorSolutions sol = Information::getIntersection(e, p, true); for(int i=0; i<=1; ++i) { if (sol.get(i).valid) { is.append(new Vector(sol.get(i))); - RS_DEBUG->print(" pattern line intersection: %f/%f", sol.get(i).x, sol.get(i).y); + DEBUG->print(" pattern line intersection: %f/%f", sol.get(i).x, sol.get(i).y); } } } @@ -469,11 +469,11 @@ void RS_Hatch::update() { if (line != NULL) { - tmp2.addEntity(new RS_Line(&tmp2, RS_LineData(*v1, *v2))); + tmp2.addEntity(new Line(&tmp2, LineData(*v1, *v2))); } else if (arc != NULL || circle != NULL) { - tmp2.addEntity(new RS_Arc(&tmp2, RS_ArcData(center, center.distanceTo(*v1), + tmp2.addEntity(new Arc(&tmp2, ArcData(center, center.distanceTo(*v1), center.angleTo(*v1), center.angleTo(*v2), reversed))); } } @@ -483,30 +483,30 @@ void RS_Hatch::update() } // updating hatch / adding entities that are inside - RS_DEBUG->print("RS_Hatch::update: cutting pattern carpet: OK"); + DEBUG->print("Hatch::update: cutting pattern carpet: OK"); // the hatch pattern entities: - hatch = new RS_EntityContainer(this); - hatch->setPen(RS_Pen(RS2::FlagInvalid)); + hatch = new EntityContainer(this); + hatch->setPen(Pen(RS2::FlagInvalid)); hatch->setLayer(NULL); hatch->setFlag(RS2::FlagTemp); //calculateBorders(); - for(RS_Entity * e=tmp2.firstEntity(); e!=NULL; e=tmp2.nextEntity()) + for(Entity * e=tmp2.firstEntity(); e!=NULL; e=tmp2.nextEntity()) { Vector middlePoint; Vector middlePoint2; if (e->rtti() == RS2::EntityLine) { - RS_Line * line = (RS_Line *)e; + Line * line = (Line *)e; middlePoint = line->getMiddlepoint(); middlePoint2 = line->getNearestDist(line->getLength() / 2.1, line->getStartpoint()); } else if (e->rtti() == RS2::EntityArc) { - RS_Arc * arc = (RS_Arc *)e; + Arc * arc = (Arc *)e; middlePoint = arc->getMiddlepoint(); middlePoint2 = arc->getNearestDist(arc->getLength() / 2.1, arc->getStartpoint()); } @@ -520,11 +520,11 @@ void RS_Hatch::update() { bool onContour = false; - if (RS_Information::isPointInsideContour(middlePoint, this, &onContour) - || RS_Information::isPointInsideContour(middlePoint2, this)) + if (Information::isPointInsideContour(middlePoint, this, &onContour) + || Information::isPointInsideContour(middlePoint2, this)) { - RS_Entity * te = e->clone(); - te->setPen(RS_Pen(RS2::FlagInvalid)); + Entity * te = e->clone(); + te->setPen(Pen(RS2::FlagInvalid)); te->setLayer(NULL); te->reparent(hatch); hatch->addEntity(te); @@ -542,47 +542,47 @@ void RS_Hatch::update() updateRunning = false; - RS_DEBUG->print("RS_Hatch::update: OK"); + DEBUG->print("Hatch::update: OK"); } /** * Activates of deactivates the hatch boundary. */ -void RS_Hatch::activateContour(bool on) +void Hatch::activateContour(bool on) { - RS_DEBUG->print("RS_Hatch::activateContour: %d", (int)on); + DEBUG->print("Hatch::activateContour: %d", (int)on); - for(RS_Entity * e=firstEntity(); e!=NULL; e=nextEntity()) + for(Entity * e=firstEntity(); e!=NULL; e=nextEntity()) { if (!e->isUndone()) { if (!e->getFlag(RS2::FlagTemp)) { - RS_DEBUG->print("RS_Hatch::activateContour: set visible"); + DEBUG->print("Hatch::activateContour: set visible"); e->setVisible(on); } else { - RS_DEBUG->print("RS_Hatch::activateContour: entity temp"); + DEBUG->print("Hatch::activateContour: entity temp"); } } else { - RS_DEBUG->print("RS_Hatch::activateContour: entity undone"); + DEBUG->print("Hatch::activateContour: entity undone"); } } - RS_DEBUG->print("RS_Hatch::activateContour: OK"); + DEBUG->print("Hatch::activateContour: OK"); } /** * Overrides drawing of subentities. This is only ever called for solid fills. */ -void RS_Hatch::draw(PaintInterface * painter, GraphicView * view, double /*patternOffset*/) +void Hatch::draw(PaintInterface * painter, GraphicView * view, double /*patternOffset*/) { if (!data.solid) { - for(RS_Entity * se=firstEntity(); se!=NULL; se = nextEntity()) + for(Entity * se=firstEntity(); se!=NULL; se = nextEntity()) view->drawEntity(se); return; @@ -601,11 +601,11 @@ void RS_Hatch::draw(PaintInterface * painter, GraphicView * view, double /*patte // loops: if (needOptimization == true) { - for(RS_Entity * l=firstEntity(RS2::ResolveNone); l!=NULL; l=nextEntity(RS2::ResolveNone)) + for(Entity * l=firstEntity(RS2::ResolveNone); l!=NULL; l=nextEntity(RS2::ResolveNone)) { if (l->rtti() == RS2::EntityContainer) { - RS_EntityContainer * loop = (RS_EntityContainer *)l; + EntityContainer * loop = (EntityContainer *)l; loop->optimizeContours(); } } @@ -614,16 +614,16 @@ void RS_Hatch::draw(PaintInterface * painter, GraphicView * view, double /*patte } // loops: - for(RS_Entity * l=firstEntity(RS2::ResolveNone); l!=NULL; l=nextEntity(RS2::ResolveNone)) + for(Entity * l=firstEntity(RS2::ResolveNone); l!=NULL; l=nextEntity(RS2::ResolveNone)) { l->setLayer(getLayer()); if (l->rtti() == RS2::EntityContainer) { - RS_EntityContainer * loop = (RS_EntityContainer *)l; + EntityContainer * loop = (EntityContainer *)l; // edges: - for(RS_Entity * e=loop->firstEntity(RS2::ResolveNone); e!=NULL; e=loop->nextEntity(RS2::ResolveNone)) + for(Entity * e=loop->firstEntity(RS2::ResolveNone); e!=NULL; e=loop->nextEntity(RS2::ResolveNone)) { e->setLayer(getLayer()); @@ -631,12 +631,12 @@ void RS_Hatch::draw(PaintInterface * painter, GraphicView * view, double /*patte { case RS2::EntityLine: { - RS_Line * line = (RS_Line *)e; + Line * line = (Line *)e; - int x1 = RS_Math::round(view->toGuiX(line->getStartpoint().x)); - int y1 = RS_Math::round(view->toGuiY(line->getStartpoint().y)); - int x2 = RS_Math::round(view->toGuiX(line->getEndpoint().x)); - int y2 = RS_Math::round(view->toGuiY(line->getEndpoint().y)); + int x1 = Math::round(view->toGuiX(line->getStartpoint().x)); + int y1 = Math::round(view->toGuiY(line->getStartpoint().y)); + int x2 = Math::round(view->toGuiX(line->getEndpoint().x)); + int y2 = Math::round(view->toGuiY(line->getEndpoint().y)); if (lastValid && (lastX != x1 || lastY != y1)) { @@ -658,12 +658,12 @@ void RS_Hatch::draw(PaintInterface * painter, GraphicView * view, double /*patte case RS2::EntityArc: { - RS_Arc * arc = (RS_Arc *)e; + Arc * arc = (Arc *)e; - int x1 = RS_Math::round(view->toGuiX(arc->getStartpoint().x)); - int y1 = RS_Math::round(view->toGuiY(arc->getStartpoint().y)); - int x2 = RS_Math::round(view->toGuiX(arc->getEndpoint().x)); - int y2 = RS_Math::round(view->toGuiY(arc->getEndpoint().y)); + int x1 = Math::round(view->toGuiX(arc->getStartpoint().x)); + int y1 = Math::round(view->toGuiY(arc->getStartpoint().y)); + int x2 = Math::round(view->toGuiX(arc->getEndpoint().x)); + int y2 = Math::round(view->toGuiY(arc->getEndpoint().y)); if (lastValid && (lastX != x1 || lastY != y1)) { @@ -695,10 +695,10 @@ void RS_Hatch::draw(PaintInterface * painter, GraphicView * view, double /*patte case RS2::EntityCircle: { - RS_Circle * circle = (RS_Circle *)e; + Circle * circle = (Circle *)e; - int x1 = RS_Math::round(view->toGuiX(circle->getCenter().x + circle->getRadius())); - int y1 = RS_Math::round(view->toGuiY(circle->getCenter().y)); + int x1 = Math::round(view->toGuiX(circle->getCenter().x + circle->getRadius())); + int y1 = Math::round(view->toGuiY(circle->getCenter().y)); int x2 = x1; int y2 = y1; @@ -747,12 +747,12 @@ void RS_Hatch::draw(PaintInterface * painter, GraphicView * view, double /*patte painter->drawPolygon(pa); } -/*virtual*/ double RS_Hatch::getLength() +/*virtual*/ double Hatch::getLength() { return -1.0; } -double RS_Hatch::getDistanceToPoint(const Vector & coord, RS_Entity ** entity, +double Hatch::getDistanceToPoint(const Vector & coord, Entity ** entity, RS2::ResolveLevel level, double solidDist) { if (data.solid == true) @@ -762,7 +762,7 @@ double RS_Hatch::getDistanceToPoint(const Vector & coord, RS_Entity ** entity, bool onContour; - if (RS_Information::isPointInsideContour(coord, this, &onContour)) + if (Information::isPointInsideContour(coord, this, &onContour)) // distance is the snap range: return solidDist; @@ -770,48 +770,48 @@ double RS_Hatch::getDistanceToPoint(const Vector & coord, RS_Entity ** entity, } else { - return RS_EntityContainer::getDistanceToPoint(coord, entity, level, solidDist); + return EntityContainer::getDistanceToPoint(coord, entity, level, solidDist); } } -void RS_Hatch::move(Vector offset) +void Hatch::move(Vector offset) { - RS_EntityContainer::move(offset); + EntityContainer::move(offset); update(); } -void RS_Hatch::rotate(Vector center, double angle) +void Hatch::rotate(Vector center, double angle) { - RS_EntityContainer::rotate(center, angle); - data.angle = RS_Math::correctAngle(data.angle + angle); + EntityContainer::rotate(center, angle); + data.angle = Math::correctAngle(data.angle + angle); update(); } -void RS_Hatch::scale(Vector center, Vector factor) +void Hatch::scale(Vector center, Vector factor) { - RS_EntityContainer::scale(center, factor); + EntityContainer::scale(center, factor); data.scale *= factor.x; update(); } -void RS_Hatch::mirror(Vector axisPoint1, Vector axisPoint2) +void Hatch::mirror(Vector axisPoint1, Vector axisPoint2) { - RS_EntityContainer::mirror(axisPoint1, axisPoint2); + EntityContainer::mirror(axisPoint1, axisPoint2); double ang = axisPoint1.angleTo(axisPoint2); - data.angle = RS_Math::correctAngle(data.angle + ang*2.0); + data.angle = Math::correctAngle(data.angle + ang*2.0); update(); } -void RS_Hatch::stretch(Vector firstCorner, Vector secondCorner, Vector offset) +void Hatch::stretch(Vector firstCorner, Vector secondCorner, Vector offset) { - RS_EntityContainer::stretch(firstCorner, secondCorner, offset); + EntityContainer::stretch(firstCorner, secondCorner, offset); update(); } /** * Dumps the point's data to stdout. */ -std::ostream & operator<<(std::ostream & os, const RS_Hatch & p) +std::ostream & operator<<(std::ostream & os, const Hatch & p) { os << " Hatch: " << p.getData() << "\n"; return os;