| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| | #include "lc_graphicviewportrenderer.h" |
| |
|
| | #include "lc_defaults.h" |
| | #include "lc_graphicviewport.h" |
| | #include "lc_linemath.h" |
| | #include "rs_entity.h" |
| | #include "rs_graphic.h" |
| | #include "rs_painter.h" |
| | #include "rs_units.h" |
| |
|
| | LC_GraphicViewportRenderer::LC_GraphicViewportRenderer(LC_GraphicViewport* v, QPaintDevice* painterDevice): |
| | pd{painterDevice} |
| | , viewport{v} |
| | , graphic {viewport->getGraphic()} |
| | { |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::render() { |
| | renderBoundingClipRect = prepareBoundingClipRect(); |
| | doRender(); |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::renderEntityAsChild(RS_Painter *painter, RS_Entity *e) { |
| | #ifdef DEBUG_RENDERING |
| | drawEntityCount++; |
| | drawTimer.start(); |
| | #endif |
| | e->drawAsChild(painter); |
| | #ifdef DEBUG_RENDERING |
| | qint64 elapsed = drawTimer.nsecsElapsed(); |
| | entityDrawTime+= elapsed; |
| | #endif |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::loadSettings() { |
| | auto g = getGraphic(); |
| | if (g != nullptr){ |
| | updateGraphicRelatedSettings(g); |
| | } |
| | } |
| |
|
| | LC_Rect LC_GraphicViewportRenderer::prepareBoundingClipRect(){ |
| | int width = viewport->getWidth(); |
| | int height = viewport->getHeight(); |
| | const RS_Vector ucsViewportLeftBottom = viewport->toUCSFromGui(0, 0); |
| | const RS_Vector ucsViewportRightTop = viewport->toUCSFromGui(width, height); |
| |
|
| | if (viewport->hasUCS()){ |
| | |
| | |
| |
|
| | RS_Vector wcsViewportMin; |
| | RS_Vector wcsViewportMax; |
| |
|
| | viewport->worldBoundingBox(ucsViewportLeftBottom, ucsViewportRightTop, wcsViewportMin, wcsViewportMax); |
| |
|
| | return LC_Rect(wcsViewportMin, wcsViewportMax); |
| | } |
| | else{ |
| | |
| | return LC_Rect(ucsViewportLeftBottom, ucsViewportRightTop); |
| | } |
| | } |
| |
|
| | bool LC_GraphicViewportRenderer::isOutsideOfBoundingClipRect(RS_Entity* e, bool constructionEntity){ |
| | |
| | switch (e->rtti()){ |
| | |
| | |
| | case RS2::EntityLine:{ |
| | if (constructionEntity){ |
| | if (!LC_LineMath::hasIntersectionLineRect(e->getMin(), e->getMax(), renderBoundingClipRect.minP(), renderBoundingClipRect.maxP())){ |
| | return true; |
| | } |
| | } |
| | else{ |
| | if (e->getMax().x < renderBoundingClipRect.minP().x || e->getMin().x > renderBoundingClipRect.maxP().x || |
| | e->getMin().y > renderBoundingClipRect.maxP().y || e->getMax().y < renderBoundingClipRect.minP().y){ |
| | return true; |
| | } |
| | } |
| | break; |
| | } |
| | default: |
| | if (e->getMax().x < renderBoundingClipRect.minP().x || e->getMin().x > renderBoundingClipRect.maxP().x || |
| | e->getMin().y > renderBoundingClipRect.maxP().y || e->getMax().y < renderBoundingClipRect.minP().y){ |
| | return true; |
| | } |
| | } |
| | return false; |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | void LC_GraphicViewportRenderer::justDrawEntity(RS_Painter *painter, RS_Entity *e) { |
| | #ifdef DEBUG_RENDERING |
| | drawEntityCount++; |
| | drawTimer.start(); |
| | #endif |
| | e->draw(painter); |
| | #ifdef DEBUG_RENDERING |
| | qint64 elapsed = drawTimer.nsecsElapsed(); |
| | entityDrawTime+= elapsed; |
| | #endif |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::updateEndCapsStyle(const RS_Graphic *graphic) { |
| | |
| | int endCaps = graphic->getGraphicVariableInt("$ENDCAPS", 1); |
| | switch (endCaps){ |
| | case 0: |
| | penCapStyle = Qt::FlatCap; |
| | break; |
| | case 1: |
| | penCapStyle = Qt::RoundCap; |
| | break; |
| | case 2: |
| | penCapStyle = Qt::MPenCapStyle; |
| | break; |
| | case 3: |
| | penCapStyle = Qt::SquareCap; |
| | break; |
| | default: |
| | penCapStyle = Qt::FlatCap; |
| | } |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::updatePointEntitiesStyle(RS_Graphic *graphic) { |
| | pdmode = graphic->getGraphicVariableInt("$PDMODE", LC_DEFAULTS_PDMode); |
| | pdsize = graphic->getGraphicVariableDouble("$PDSIZE", LC_DEFAULTS_PDSize); |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::updateJoinStyle(const RS_Graphic *graphic) { |
| | int joinStyle = graphic->getGraphicVariableInt("$JOINSTYLE", 1); |
| |
|
| | switch (joinStyle){ |
| | case 0: |
| | penJoinStyle = Qt::BevelJoin; |
| | break; |
| | case 1: |
| | penJoinStyle = Qt::RoundJoin; |
| | break; |
| | case 2: |
| | penJoinStyle = Qt::MiterJoin; |
| | break; |
| | case 3: |
| | penJoinStyle = Qt::BevelJoin; |
| | break; |
| | default: |
| | penJoinStyle = Qt::RoundJoin; |
| | } |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::setBackground(const RS_Color &bg) { |
| | m_colorBackground = bg; |
| |
|
| | RS_Color black(0, 0, 0); |
| | if (black.colorDistance(bg) >= RS_Color::MinColorDistance) { |
| | m_colorForeground = black; |
| | } else { |
| | m_colorForeground = RS_Color(255, 255, 255); |
| | } |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::updateGraphicRelatedSettings(RS_Graphic *g) { |
| | updateUnitAndDefaultWidthFactors(g); |
| | updatePointEntitiesStyle(g); |
| | updateEndCapsStyle(g); |
| | updateJoinStyle(g); |
| | updateAnglesBasis(g); |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::updateUnitAndDefaultWidthFactors(const RS_Graphic *g) { |
| | unitFactor = RS_Units::convert(1.0, RS2::Millimeter, g->getUnit()); |
| | unitFactor100 = unitFactor / 100.0; |
| | defaultWidthFactor = g->getVariableDouble("$DIMSCALE", 1.0); |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::setupPainter(RS_Painter *painter) { |
| | painter->setRenderer(this); |
| | painter->setViewPort(viewport); |
| | painter->updatePointsScreenSize(pdsize); |
| | painter->setPointsMode(pdmode); |
| | painter->setDefaultWidthFactor(defaultWidthFactor); |
| | painter->setWorldBoundingRect(renderBoundingClipRect); |
| | } |
| |
|
| | bool LC_GraphicViewportRenderer::isTextLineNotRenderable([[maybe_unused]]double d) const { |
| | return false; |
| | } |
| |
|
| | void LC_GraphicViewportRenderer::updateAnglesBasis(RS_Graphic *g) { |
| | m_angleBasisBaseAngle = g->getAnglesBase(); |
| | m_angleBasisCounterClockwise = g->areAnglesCounterClockWise(); |
| | } |
| |
|