⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs_hatch.cpp

📁 qcad2.05可用于windows和linux的源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        for (RS_Vector* v1 = is2.first(); v1!=NULL;) {            RS_Vector* v2 = is2.next();            if (v1!=NULL && v2!=NULL) {                if (line!=NULL) {                    tmp2.addEntity(new RS_Line(&tmp2,                                               RS_LineData(*v1, *v2)));                } else if (arc!=NULL || circle!=NULL) {                    tmp2.addEntity(new RS_Arc(&tmp2,                                              RS_ArcData(center,                                                         center.distanceTo(*v1),                                                         center.angleTo(*v1),                                                         center.angleTo(*v2),                                                         reversed)));                }            }            v1 = v2;        }    }    // updating hatch / adding entities that are inside    RS_DEBUG->print("RS_Hatch::update: cutting pattern carpet: OK");    //RS_EntityContainer* rubbish = new RS_EntityContainer(getGraphic());    // the hatch pattern entities:    hatch = new RS_EntityContainer(this);    hatch->setPen(RS_Pen(RS2::FlagInvalid));    hatch->setLayer(NULL);    hatch->setFlag(RS2::FlagTemp);    //calculateBorders();    for (RS_Entity* e=tmp2.firstEntity(); e!=NULL;            e=tmp2.nextEntity()) {        RS_Vector middlePoint;        RS_Vector middlePoint2;        if (e->rtti()==RS2::EntityLine) {            RS_Line* line = (RS_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;            middlePoint = arc->getMiddlepoint();            middlePoint2 = arc->getNearestDist(arc->getLength()/2.1,                                               arc->getStartpoint());        } else {            middlePoint = RS_Vector(false);            middlePoint2 = RS_Vector(false);        }        if (middlePoint.valid) {            bool onContour=false;            if (RS_Information::isPointInsideContour(                        middlePoint,                        this, &onContour) ||                    RS_Information::isPointInsideContour(middlePoint2, this)) {                RS_Entity* te = e->clone();                te->setPen(RS_Pen(RS2::FlagInvalid));                te->setLayer(NULL);                te->reparent(hatch);                hatch->addEntity(te);            }        }    }    addEntity(hatch);    //getGraphic()->addEntity(rubbish);    forcedCalculateBorders();    // deactivate contour:    activateContour(false);    updateRunning = false;    RS_DEBUG->print("RS_Hatch::update: OK");#endif}/** * Activates of deactivates the hatch boundary. */void RS_Hatch::activateContour(bool on) {	RS_DEBUG->print("RS_Hatch::activateContour: %d", (int)on);    for (RS_Entity* e=firstEntity(); e!=NULL;            e=nextEntity()) {        if (!e->isUndone()) {            if (!e->getFlag(RS2::FlagTemp)) {				RS_DEBUG->print("RS_Hatch::activateContour: set visible");                e->setVisible(on);            }			else {				RS_DEBUG->print("RS_Hatch::activateContour: entity temp");			}        }		else {			RS_DEBUG->print("RS_Hatch::activateContour: entity undone");		}    }	RS_DEBUG->print("RS_Hatch::activateContour: OK");}/** * Overrides drawing of subentities. This is only ever called for solid fills. */void RS_Hatch::draw(RS_Painter* painter, RS_GraphicView* view, 	double /*patternOffset*/) {    if (!data.solid) {        for (RS_Entity* se=firstEntity();                se!=NULL;                se = nextEntity()) {            view->drawEntity(se);        }        return;    }#if QT_VERSION>=0x030000    RS_PointArray pa;    RS_PointArray jp;   // jump points    uint s=0;    uint sj=0;    int lastX=0;    int lastY=0;    bool lastValid=false;    // loops:    if (needOptimization==true) {        for (RS_Entity* l=firstEntity(RS2::ResolveNone);                l!=NULL;                l=nextEntity(RS2::ResolveNone)) {            if (l->rtti()==RS2::EntityContainer) {                RS_EntityContainer* loop = (RS_EntityContainer*)l;                loop->optimizeContours();            }        }        needOptimization = false;    }    // loops:    for (RS_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;            // edges:            for (RS_Entity* e=loop->firstEntity(RS2::ResolveNone);                    e!=NULL;                    e=loop->nextEntity(RS2::ResolveNone)) {                e->setLayer(getLayer());                switch (e->rtti()) {                case RS2::EntityLine: {                        RS_Line* line = (RS_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));                        if (lastValid && (lastX!=x1 || lastY!=y1)) {                            jp.resize(++sj);                            jp.setPoint(sj-1, x1, y1);                        }                        pa.resize(++s);                        pa.setPoint(s-1, x1, y1);                        pa.resize(++s);                        pa.setPoint(s-1, x2, y2);                        lastX = x2;                        lastY = y2;                        lastValid=true;                    }                    break;                case RS2::EntityArc: {                        RS_Arc* arc = (RS_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));                        if (lastValid && (lastX!=x1 || lastY!=y1)) {                            jp.resize(++sj);                            jp.setPoint(sj-1, x1, y1);                        }                        pa.resize(++s);                        pa.setPoint(s-1, x1, y1);                        RS_PointArray pa2;                        painter->createArc(pa2, view->toGui(arc->getCenter()),                                           view->toGuiDX(arc->getRadius()),                                           arc->getAngle1(),                                           arc->getAngle2(),                                           arc->isReversed());                        pa.resize(s+pa2.size());                        pa.putPoints(s, pa2.size(), pa2);                        s+=pa2.size()-1;                        pa.resize(++s);                        pa.setPoint(s-1, x2, y2);                        lastX = x2;                        lastY = y2;                        lastValid=true;                    }                    break;                case RS2::EntityCircle: {                        RS_Circle* circle = (RS_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 x2 = x1;                        int y2 = y1;                        if (lastValid && (lastX!=x1 || lastY!=y1)) {                            jp.resize(++sj);                            jp.setPoint(sj-1, x1, y1);                        }                        pa.resize(++s);                        pa.setPoint(s-1, x1, y1);                        RS_PointArray pa2;                        painter->createArc(pa2, view->toGui(circle->getCenter()),                                           view->toGuiDX(circle->getRadius()),                                           0.0,                                           2*M_PI,                                           false);                        pa.resize(s+pa2.size());                        pa.putPoints(s, pa2.size(), pa2);                        s+=pa2.size()-1;                        pa.resize(++s);                        pa.setPoint(s-1, x2, y2);                        lastX = x2;                        lastY = y2;                        lastValid=true;                    }                    break;                default:                    break;                }            }        }    }    for (int i=(int)jp.count()-1; i>=0; --i) {        pa.resize(++s);        pa.setPoint(s-1, jp.point(i));    }    painter->setBrush(painter->getPen().getColor());    painter->disablePen();    painter->drawPolygon(pa);#endif}double RS_Hatch::getDistanceToPoint(    const RS_Vector& coord,    RS_Entity** entity,    RS2::ResolveLevel level,    double solidDist) {    if (data.solid==true) {        if (entity!=NULL) {            *entity = this;        }        bool onContour;        if (RS_Information::isPointInsideContour(                    coord,                    this, &onContour)) {            // distance is the snap range:            return solidDist;        }        return RS_MAXDOUBLE;    } else {        return RS_EntityContainer::getDistanceToPoint(coord, entity,                level, solidDist);    }}void RS_Hatch::move(RS_Vector offset) {    RS_EntityContainer::move(offset);    update();}void RS_Hatch::rotate(RS_Vector center, double angle) {    RS_EntityContainer::rotate(center, angle);    data.angle = RS_Math::correctAngle(data.angle+angle);    update();}void RS_Hatch::scale(RS_Vector center, RS_Vector factor) {    RS_EntityContainer::scale(center, factor);    data.scale *= factor.x;    update();}void RS_Hatch::mirror(RS_Vector axisPoint1, RS_Vector axisPoint2) {    RS_EntityContainer::mirror(axisPoint1, axisPoint2);    double ang = axisPoint1.angleTo(axisPoint2);    data.angle = RS_Math::correctAngle(data.angle + ang*2.0);    update();}void RS_Hatch::stretch(RS_Vector firstCorner,                       RS_Vector secondCorner,                       RS_Vector offset) {    RS_EntityContainer::stretch(firstCorner, secondCorner, offset);    update();}/** * Dumps the point's data to stdout. */std::ostream& operator << (std::ostream& os, const RS_Hatch& p) {    os << " Hatch: " << p.getData() << "\n";    return os;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -