Beispiel #1
0
void QGIViewPart::drawSectionLine(TechDraw::DrawViewSection* viewSection, bool b)
{
    TechDraw::DrawViewPart *viewPart = static_cast<TechDraw::DrawViewPart *>(getViewObject());
    if (!viewPart ||
        !viewSection)  {
        return;
    }
    if (b) {
        QGISectionLine* sectionLine = new QGISectionLine();
        addToGroup(sectionLine);
        sectionLine->setSymbol(const_cast<char*>(viewSection->SectionSymbol.getValue()));

        //TODO: handle oblique section lines?
        //find smallest internal angle(normalDir,get?Dir()) and use -1*get?Dir() +/- angle
        //Base::Vector3d normalDir = viewSection->SectionNormal.getValue();
        Base::Vector3d arrowDir(0,1,0);                //for drawing only, not geom
        Base::Vector3d lineDir(1,0,0);
        bool horiz = false;
        if (viewSection->SectionDirection.isValue("Right")) {
            arrowDir = Base::Vector3d(1,0,0);
            lineDir = Base::Vector3d(0,1,0);
        } else if (viewSection->SectionDirection.isValue("Left")) {
            arrowDir = Base::Vector3d(-1,0,0);
            lineDir = Base::Vector3d(0,-1,0);
        } else if (viewSection->SectionDirection.isValue("Up")) {
            arrowDir = Base::Vector3d(0,1,0);
            lineDir = Base::Vector3d(1,0,0);
            horiz = true;
        } else if (viewSection->SectionDirection.isValue("Down")) {
            arrowDir = Base::Vector3d(0,-1,0);
            lineDir = Base::Vector3d(-1,0,0);
            horiz = true;
        }
        sectionLine->setDirection(arrowDir.x,arrowDir.y);

        Base::Vector3d org = viewSection->SectionOrigin.getValue();
        double scale = viewPart->Scale.getValue();
        Base::Vector3d pOrg = scale * viewPart->projectPoint(org);
        //pOrg.y = -1 * pOrg.y;
        //now project pOrg onto arrowDir
        Base::Vector3d displace;
        displace.ProjectToLine(pOrg, arrowDir);
        Base::Vector3d offset = pOrg + displace;

        sectionLine->setPos(offset.x,offset.y);
        double sectionSpan;
        double sectionFudge = 10.0;
        double xVal, yVal;
        if (horiz)  {
            sectionSpan = m_border->rect().width() + sectionFudge;
            xVal = sectionSpan / 2.0;
            yVal = 0.0;
        } else {
            sectionSpan = (m_border->rect().height() - m_label->boundingRect().height()) + sectionFudge;
            xVal = 0.0;
            yVal = sectionSpan / 2.0;
        }
        sectionLine->setBounds(-xVal,-yVal,xVal,yVal);
        sectionLine->setWidth(viewPart->LineWidth.getValue());          //TODO: add fudge to make sectionLine thinner than reg lines?
        sectionLine->setFont(m_font,6.0);
        sectionLine->setZValue(ZVALUE::SECTIONLINE);
        sectionLine->draw();
    }
}