Beispiel #1
0
void RS_GraphicView::setPenForEntity(RS_Painter *painter,RS_Entity *e)
{
	if (draftMode) {
		painter->setPen(RS_Pen(foreground,
							   RS2::Width00, RS2::SolidLine));
	}

	// Getting pen from entity (or layer)
	RS_Pen pen = e->getPen(true);

	int w = pen.getWidth();
	if (w<0) {
		w = 0;
	}

#if 1 /*TRUE*/
	// - Scale pen width.
	// - Notes: pen width is not scaled on print and print preview.
	//   This is the standard (AutoCAD like) behaviour.
	// bug# 3437941
	// ------------------------------------------------------------
	if (!draftMode)
	{
		double	uf = 1.0;	// Unit factor.
		double	wf = 1.0;	// Width factor.

		RS_Graphic* graphic = container->getGraphic();

        if (graphic)
		{
			uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit());

			if (	(isPrinting() || isPrintPreview()) &&
					graphic->getPaperScale() > RS_TOLERANCE )
			{
				wf = 1.0 / graphic->getPaperScale();
			}
		}

		pen.setScreenWidth(toGuiDX(w / 100.0 * uf * wf));
	}
	else
	{
		//		pen.setWidth(RS2::Width00);
		pen.setScreenWidth(0);
	}

#else

	// - Scale pen width.
	// - Notes: pen width is scaled on print and print preview.
	//   This is not the standard (AutoCAD like) behaviour.
	// --------------------------------------------------------
	if (!draftMode)
	{
		double	uf = 1.0;	//	Unit factor.

		RS_Graphic* graphic = container->getGraphic();

        if (graphic)
			uf = RS_Units::convert(1.0, RS2::Millimeter, graphic->getUnit());

		pen.setScreenWidth(toGuiDX(w / 100.0 * uf));
	}
	else
		pen.setScreenWidth(0);
#endif

	// prevent drawing with 1-width which is slow:
	if (RS_Math::round(pen.getScreenWidth())==1) {
		pen.setScreenWidth(0.0);
	}

	// prevent background color on background drawing:
	if (pen.getColor().stripFlags()==background.stripFlags()) {
		pen.setColor(foreground);
	}

	// this entity is selected:
	if (e->isSelected()) {
		pen.setLineType(RS2::DotLine);
		pen.setColor(selectedColor);
	}

	// this entity is highlighted:
	if (e->isHighlighted()) {
		pen.setColor(highlightedColor);
	}

	// deleting not drawing:
	if (getDeleteMode()) {
		pen.setColor(background);
	}

	painter->setPen(pen);
}
/**
 * Called whenever the graphic view has changed.
 * Adjusts the scrollbar ranges / steps.
 */
void QG_GraphicView::adjustOffsetControls() {
        static bool running = false;

        if (running) {
                return;
        }

        running = true;

    RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() begin");

    if (container==NULL || hScrollBar==NULL || vScrollBar==NULL) {
        return;
    }

    int ox = getOffsetX();
    int oy = getOffsetY();

    RS_Vector min = container->getMin();
    RS_Vector max = container->getMax();

    // no drawing yet - still allow to scroll
    if (max.x < min.x+1.0e-6 ||
            max.y < min.y+1.0e-6 ||
                max.x > RS_MAXDOUBLE ||
                max.x < RS_MINDOUBLE ||
                min.x > RS_MAXDOUBLE ||
                min.x < RS_MINDOUBLE ||
                max.y > RS_MAXDOUBLE ||
                max.y < RS_MINDOUBLE ||
                min.y > RS_MAXDOUBLE ||
                min.y < RS_MINDOUBLE ) {
        min = RS_Vector(-10,-10);
        max = RS_Vector(100,100);
    }

        int minVal = (int)(-ox-toGuiDX(getWidth())*0.5
                        - QG_SCROLLMARGIN - getBorderLeft());
        int maxVal = (int)(-ox+toGuiDX(getWidth())*0.5
                        + QG_SCROLLMARGIN + getBorderRight());

        hScrollBar->setValue(0);
        if (minVal<=maxVal) {
                hScrollBar->setRange(minVal, maxVal);
        }
    //hScrollBar->setMinValue(minVal);

        //hScrollBar->setMaxValue(maxVal);

        minVal = (int)(oy-toGuiDY(getHeight())*0.5
                        - QG_SCROLLMARGIN - getBorderTop());
        maxVal = (int)(oy+toGuiDY(getHeight())*0.5
                       +QG_SCROLLMARGIN + getBorderBottom());

        if (minVal<=maxVal) {
                vScrollBar->setRange(minVal, maxVal);
        }
    //vScrollBar->setMaxValue((int)(QG_SCROLLMARGIN + getBorderBottom()
     //                             - (min.y * getFactor().y)));


    //vScrollBar->setMinValue((int)(getHeight() -
     //                             max.y * getFactor().y
     //                             - QG_SCROLLMARGIN - getBorderTop()));


    hScrollBar->setPageStep((int)(getWidth()));
    vScrollBar->setPageStep((int)(getHeight()));

    hScrollBar->setValue(-ox);
    vScrollBar->setValue(oy);


    slotHScrolled(-ox);
    slotVScrolled(oy);


    RS_DEBUG->print("H min: %d / max: %d / step: %d / value: %d\n",
                    hScrollBar->minimum(), hScrollBar->maximum(),
                    hScrollBar->pageStep(), ox);
//    DEBUG_HEADER();
    RS_DEBUG->print(/*RS_Debug::D_WARNING, */"V min: %d / max: %d / step: %d / value: %d\n",
                    vScrollBar->minimum(), vScrollBar->maximum(),
                    vScrollBar->pageStep(), oy);

    RS_DEBUG->print("QG_GraphicView::adjustOffsetControls() end");

        running = false;
}
Beispiel #3
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");
}