示例#1
0
/**
 * Draws the grid.
 *
 * @see drawIt()
 */
void RS_GraphicView::drawGrid(RS_Painter *painter) {

	if (!(grid && isGridOn())) return;


	// draw grid:
	//painter->setPen(Qt::gray);
	painter->setPen(gridColor);

	//grid->updatePointArray();
	auto const& pts = grid->getPoints();
	for(auto const& v: pts){
		painter->drawGridPoint(toGui(v));
	}

	// draw grid info:
	//painter->setPen(Qt::white);
	QString info = grid->getInfo();
	//info = QString("%1 / %2")
	//       .arg(grid->getSpacing())
	//       .arg(grid->getMetaSpacing());

	updateGridStatusWidget(info);


}
/**
 * Draws the grid.
 *
 * @see drawIt()
 */
void RS_GraphicView::drawGrid(RS_Painter *painter) {

    if (grid==NULL || isGridOn()==false) {
        return;
    }


    // draw grid:
    //painter->setPen(Qt::gray);
    painter->setPen(gridColor);

//    grid->updatePointArray();
    RS_Vector* pts = grid->getPoints();
    if (pts!=NULL) {
        for (int i=0; i<grid->count(); ++i) {
            painter->drawGridPoint(toGui(pts[i]));
        }
    }

    // draw grid info:
    //painter->setPen(Qt::white);
    QString info = grid->getInfo();
    //info = QString("%1 / %2")
    //       .arg(grid->getSpacing())
    //       .arg(grid->getMetaSpacing());

    updateGridStatusWidget(info);


}
示例#3
0
/**
 * Draws the paper border (for print previews).
 * This function can ONLY be called from within a paintEvent because it will
 * use the painter
 *
 * @see drawIt()
 */
void RS_GraphicView::drawPaper(RS_Painter *painter) {

	if (!container) {
		return;
	}

	RS_Graphic* graphic = container->getGraphic();
	if (graphic->getPaperScale()<1.0e-6) {
		return;
	}

	// draw paper:
	// RVT_PORT rewritten from     painter->setPen(Qt::gray);
	painter->setPen(QColor(Qt::gray));

	RS_Vector pinsbase = graphic->getPaperInsertionBase();
	RS_Vector size = graphic->getPaperSize();
	double scale = graphic->getPaperScale();

	RS_Vector v1 = toGui((RS_Vector(0,0)-pinsbase)/scale);
	RS_Vector v2 = toGui((size-pinsbase)/scale);

	// gray background:
	painter->fillRect(0,0, getWidth(), getHeight(),
					  RS_Color(200,200,200));

	// shadow
	painter->fillRect(
				(int)(v1.x)+6, (int)(v1.y)+6,
				(int)((v2.x-v1.x)), (int)((v2.y-v1.y)),
				RS_Color(64,64,64));

	// border:
	painter->fillRect(
				(int)(v1.x), (int)(v1.y),
				(int)((v2.x-v1.x)), (int)((v2.y-v1.y)),
				RS_Color(64,64,64));

	// paper
	painter->fillRect(
				(int)(v1.x)+1, (int)(v1.y)-1,
				(int)((v2.x-v1.x))-2, (int)((v2.y-v1.y))+2,
				RS_Color(255,255,255));

}
示例#4
0
/**
 * This virtual method can be overwritten to draw the absolute
 * zero. It's called from within drawIt(). The default implemetation
 * draws a simple red cross on the zero of thge sheet
 * THis function can ONLY be called from within a paintEvent because it will
 * use the painter
 *
 * @see drawIt()
 */
void RS_GraphicView::drawAbsoluteZero(RS_Painter *painter) {

    int const zr = 20;

    RS_Pen p(RS_Color(255,0,0), RS2::Width00, RS2::SolidLine);
	p.setScreenWidth(0);
	painter->setPen(p);
	//painter->setBrush(Qt::NoBrush);
    auto vp=toGui(RS_Vector(0,0));
    if( vp.x +zr<0 || vp.x-zr>getWidth()) return;
    if( vp.y +zr<0 || vp.y-zr>getHeight()) return;

    painter->drawLine(RS_Vector(vp.x-zr, vp.y),
                      RS_Vector(vp.x+zr, vp.y)
                      );
    painter->drawLine(RS_Vector(vp.x, vp.y-zr),
                      RS_Vector(vp.x, vp.y+zr)
                      );
}
示例#5
0
/**
 * This virtual method can be overwritten to draw the relative
 * zero point. It's called from within drawIt(). The default implemetation
 * draws a simple red round zero point. This is the point that was last created by the user, end of a line for example
 * THis function can ONLY be called from within a paintEvent because it will
 * use the painter
 *
 * @see drawIt()
 */
void RS_GraphicView::drawRelativeZero(RS_Painter *painter) {

    if (!relativeZero.valid) {
		return;
	}

    RS_Pen p(RS_Color(255,0,0), RS2::Width00, RS2::SolidLine);
	p.setScreenWidth(0);
	painter->setPen(p);

    int const zr=5;
    auto vp=toGui(relativeZero);
    if( vp.x +zr<0 || vp.x-zr>getWidth()) return;
    if( vp.y +zr<0 || vp.y-zr>getHeight()) return;

    painter->drawLine(RS_Vector(vp.x-zr, vp.y),
                      RS_Vector(vp.x+zr, vp.y)
                      );
    painter->drawLine(RS_Vector(vp.x, vp.y-zr),
                      RS_Vector(vp.x, vp.y+zr)
                      );

    painter->drawCircle(vp, 5);
}
/**
 * This virtual method can be overwritten to draw the relative
 * zero point. It's called from within drawIt(). The default implemetation
 * draws a simple red round zero point. This is the point that was last created by the user, end of a line for example
 * THis function can ONLY be called from within a paintEvent because it will
 * use the painter
 *
 * @see drawIt()
 */
void RS_GraphicView::drawRelativeZero(RS_Painter *painter) {

    if (relativeZero.valid==false) {
        return;
    }

    RS_Pen p(RS_Color(255, 0, 0), RS2::Width00, RS2::SolidLine);
    p.setScreenWidth(0);
    painter->setPen(p);

    int zr=5;

    painter->drawLine(RS_Vector(toGuiX(relativeZero.x)-zr,
                                toGuiY(relativeZero.y)),
                      RS_Vector(toGuiX(relativeZero.x)+zr,
                                toGuiY(relativeZero.y)));

    painter->drawLine(RS_Vector(toGuiX(relativeZero.x),
                                toGuiY(relativeZero.y)-zr),
                      RS_Vector(toGuiX(relativeZero.x),
                                toGuiY(relativeZero.y)+zr));

    painter->drawCircle(toGui(relativeZero), 5);
}
示例#7
0
/**
 * Draws the meta grid.
 *
 * @see drawIt()
 */
void RS_GraphicView::drawMetaGrid(RS_Painter *painter) {

	if (!(grid && isGridOn()) /*|| grid->getMetaSpacing()<0.0*/) {
		return;
	}

	//draw grid after metaGrid to avoid overwriting grid points by metaGrid lines
	//bug# 3430258
	grid->updatePointArray();
	RS_Pen pen(metaGridColor,
			   RS2::Width00,
			   RS2::DotLine);
	painter->setPen(pen);

	RS_Vector dv=grid->getMetaGridWidth().scale(factor);
	double dx=fabs(dv.x);
	double dy=fabs(dv.y); //potential bug, need to recover metaGrid.width
	// draw meta grid:
	auto mx = grid->getMetaX();
	for(auto const& x: mx){
		painter->drawLine(RS_Vector(toGuiX(x), 0),
						  RS_Vector(toGuiX(x), getHeight()));
		if(grid->isIsometric()){
			painter->drawLine(RS_Vector(toGuiX(x)+0.5*dx, 0),
							  RS_Vector(toGuiX(x)+0.5*dx, getHeight()));
		}
	}
	auto my = grid->getMetaY();
	if(grid->isIsometric()){//isometric metaGrid
		dx=fabs(dx);
		dy=fabs(dy);
		if(!my.size()|| dx<1||dy<1) return;
		RS_Vector baseMeta(toGui(RS_Vector(mx[0],my[0])));
		// x-x0=k*dx, x-remainder(x-x0,dx)
		RS_Vector vp0(-remainder(-baseMeta.x,dx)-dx,getHeight()-remainder(getHeight()-baseMeta.y,dy)+dy);
		RS_Vector vp1(vp0);
		RS_Vector vp2(getWidth()-remainder(getWidth()-baseMeta.x,dx)+dx,vp0.y);
		RS_Vector vp3(vp2);
		int cmx = round((vp2.x - vp0.x)/dx);
		int cmy = round((vp0.y +remainder(-baseMeta.y,dy)+dy)/dy);
		for(int i=cmx+cmy+2;i>=0;i--){
			if ( i <= cmx ) {
				vp0.x += dx;
				vp2.y -= dy;
			}else{
				vp0.y -= dy;
				vp2.x -= dx;
			}
			if ( i <= cmy ) {
				vp1.y -= dy;
				vp3.x -= dx;
			}else{
				vp1.x += dx;
				vp3.y -= dy;
			}
			painter->drawLine(vp0,vp1);
			painter->drawLine(vp2,vp3);
		}

	}else{//orthogonal

		for(auto const& y: my){
			painter->drawLine(RS_Vector(0, toGuiY(y)),
							  RS_Vector(getWidth(), toGuiY(y)));
		}
	}


}
示例#8
0
void RS_GraphicView::drawEntity(RS_Painter *painter, RS_Entity* e, double& patternOffset) {

	// update is diabled:
    // given entity is nullptr:
	if (!e) {
		return;
	}

	// entity is not visible:
	if (!e->isVisible()) {
		return;
	}
	if( isPrintPreview() || isPrinting() ) {
		// do not draw construction layer on print preview or print
		if( ! e->isPrint()
				||  e->isConstruction())
			return;
	}

	// test if the entity is in the viewport
	/* temporary disabled so rs_overlaylien can be drawn
	if (!e->isContainer() && !isPrinting() &&
            (painter==nullptr || !painter->isPreviewMode()) &&
			(toGuiX(e->getMax().x)<0 || toGuiX(e->getMin().x)>getWidth() ||
			 toGuiY(e->getMin().y)<0 || toGuiY(e->getMax().y)>getHeight())) {
		return;
	} */

	// set pen (color):
	setPenForEntity(painter, e );

	//RS_DEBUG->print("draw plain");
	if (isDraftMode()) {
        switch(e->rtti()){
        case RS2::EntityMText:
        case RS2::EntityText:
            if (toGuiDX(((RS_MText*)e)->getHeight())<4 || e->countDeep()>100) {
                // large or tiny texts as rectangles:
                painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
            } else {
                drawEntityPlain(painter, e, patternOffset);
            }
            break;
        case RS2::EntityImage:
            // all images as rectangles:
            painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
            break;
        case RS2::EntityHatch:
            //skip hatches
            break;
        default:
            drawEntityPlain(painter, e, patternOffset);
        }
	} else {
		drawEntityPlain(painter, e, patternOffset);
	}

	// draw reference points:
	if (e->isSelected()) {
		if (!e->isParentSelected()) {
			RS_VectorSolutions const& s = e->getRefPoints();

			for (size_t i=0; i<s.getNumber(); ++i) {
				int sz = -1;
				RS_Color col = handleColor;
				if (i == 0) {
					col = startHandleColor;
				}
				else if (i == s.getNumber() - 1) {
					col = endHandleColor;
				}
				if (getDeleteMode()) {
					painter->drawHandle(toGui(s.get(i)), background, sz);
				} else {
					painter->drawHandle(toGui(s.get(i)), col, sz);
				}
			}
		}
	}

	//RS_DEBUG->print("draw plain OK");


	//RS_DEBUG->print("RS_GraphicView::drawEntity() end");
}
void RS_GraphicView::drawEntity(RS_Painter *painter, RS_Entity* e, double& patternOffset) {

    // update is diabled:
    // given entity is NULL:
    if (e==NULL) {
        return;
    }

    // entity is not visible:
    if (!e->isVisible()) {
        return;
    }
    if( isPrintPreview() ) {
        //do not draw help layer on print preview
            if(e->isHelpLayer()) return;
    }

    // test if the entity is in the viewport
    /* temporary disabled so rs_overlaylien can be drawn
    if (!e->isContainer() && !isPrinting() &&
            (painter==NULL || !painter->isPreviewMode()) &&
            (toGuiX(e->getMax().x)<0 || toGuiX(e->getMin().x)>getWidth() ||
             toGuiY(e->getMin().y)<0 || toGuiY(e->getMax().y)>getHeight())) {
        return;
    } */

    // set pen (color):
    setPenForEntity(painter, e );

    //RS_DEBUG->print("draw plain");
    if (isDraftMode()) {
        // large mtexts as rectangles:
        if (e->rtti()==RS2::EntityMText) {
            if (toGuiDX(((RS_MText*)e)->getHeight())<4 || e->countDeep()>100) {
                painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
            } else {
                drawEntityPlain(painter, e, patternOffset);
            }
        }
        // large texts as rectangles:
        else if (e->rtti()==RS2::EntityText) {
            if (toGuiDX(((RS_Text*)e)->getHeight())<4 || e->countDeep()>100) {
                painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
            } else {
                drawEntityPlain(painter, e, patternOffset);
            }
        }

        // all images as rectangles:
        else if (e->rtti()==RS2::EntityImage) {
            painter->drawRect(toGui(e->getMin()), toGui(e->getMax()));
        }

        // hide hatches:
        else if (e->rtti()==RS2::EntityHatch) {
            // nothing
        }

        else {
            drawEntityPlain(painter, e, patternOffset);
        }
    } else {
        drawEntityPlain(painter, e, patternOffset);
    }

    // draw reference points:
    if (e->isSelected()) {
        if (!e->isParentSelected()) {
            RS_VectorSolutions s = e->getRefPoints();

            for (int i=0; i<s.getNumber(); ++i) {
                int sz = -1;
                RS_Color col = RS_Color(0,0,255);
                if (e->rtti()==RS2::EntityPolyline) {
                    if (i==0 || i==s.getNumber()-1) {
                        if (i==0) {
                            sz = 4;
                            col = QColor(0,64,255);
                        }
                        else {
                            sz = 3;
                            col = QColor(0,0,128);
                        }
                    }
                }
                if (getDeleteMode()) {
                    painter->drawHandle(toGui(s.get(i)), background, sz);
                } else {
                    painter->drawHandle(toGui(s.get(i)), col, sz);
                }
            }
        }
    }

    //RS_DEBUG->print("draw plain OK");


    //RS_DEBUG->print("RS_GraphicView::drawEntity() end");
}