コード例 #1
0
ファイル: FeatureInfoRenderer.cpp プロジェクト: asir6/Colt
void MgdFeatureInfoRenderer::ProcessMarker(LineBuffer*   lb,
                                        RS_MarkerDef& mdef,
                                        bool          allowOverpost,
                                        RS_Bounds*    bounds)
{
    if(m_pointTest && m_featurePending)
    {
        double scale_factor;
        if (mdef.units() == RS_Units_Device)
            scale_factor = m_mapScale / m_metersPerUnit;
        else
            scale_factor = 1.0 / m_metersPerUnit;

        double cx = mdef.width() * scale_factor;
        double cy = mdef.height() * scale_factor;
        double ix = mdef.insx() * cx;
        double iy = mdef.insy() * cy;
        double angleRad = mdef.rotation() * M_PI180;
        double angleCos = cos(angleRad);
        double angleSin = sin(angleRad);

        for (int i = 0; i < lb->point_count(); i++)
        {
            double ox = lb->x_coord(i), oy = lb->y_coord(i);
            double x0 = ox - ix, x1 = x0 + cx;
            double y0 = oy - iy, y1 = y0 + cy;
            double sx = m_point[0] - ox, sy = m_point[1] - oy;
            double rx = sx * angleCos + sy * angleSin;
            double ry = sy * angleCos - sx * angleSin;
            double dx = rx + ox, dy = ry + oy;

            if(dx > x0 && dx < x1 && dy > y0 && dy < y1)
            {
                SetSelected();
                break;
            }
        }
    }
}
コード例 #2
0
ファイル: GeometryAdapter.cpp プロジェクト: asir6/Colt
bool GeometryAdapter::ConvertSymbol(MdfModel::Symbol* symbol, RS_MarkerDef& mdef)
{
    SymbolVisitor::eSymbolType type = SymbolVisitor::DetermineSymbolType(symbol);

    mdef.units() = (symbol->GetSizeContext() == MdfModel::MappingUnits)? RS_Units_Model : RS_Units_Device;

    double val;
    bool cacheable = true;

    // width
    cacheable = EvalDouble(symbol->GetSizeX(), val) && cacheable;
    mdef.width() = MdfModel::LengthConverter::UnitToMeters(symbol->GetUnit(), val);
    if (mdef.width() < 0.0)
    {
        // should not get negative width and height
        _ASSERT(false);
        mdef.width() = -mdef.width();
    }

    // height
    cacheable = EvalDouble(symbol->GetSizeY(), val) && cacheable;
    mdef.height() = MdfModel::LengthConverter::UnitToMeters(symbol->GetUnit(), val);
    if (mdef.height() < 0.0)
    {
        // should not get negative width and height
        _ASSERT(false);
        mdef.height() = -mdef.height();
    }

    // rotation + insertion point
    cacheable = EvalDouble(symbol->GetRotation(), mdef.rotation()) && cacheable;
    cacheable = EvalDouble(symbol->GetInsertionPointX(), mdef.insx()) && cacheable;
    cacheable = EvalDouble(symbol->GetInsertionPointY(), mdef.insy()) && cacheable;
    mdef.rotation() = fmod(mdef.rotation(), 360.0);

    if (type == SymbolVisitor::stMark)
    {
        MdfModel::MarkSymbol* marksym = (MdfModel::MarkSymbol*)symbol;

        mdef.type() = RS_MarkerType_Marker;

        // shape
        MdfModel::MarkSymbol::Shape shape = marksym->GetShape();
        switch (shape)
        {
            case MdfModel::MarkSymbol::Square:   mdef.markernum() = SLDType_Square;   break;
            case MdfModel::MarkSymbol::Circle:   mdef.markernum() = SLDType_Circle;   break;
            case MdfModel::MarkSymbol::Triangle: mdef.markernum() = SLDType_Triangle; break;
            case MdfModel::MarkSymbol::Star:     mdef.markernum() = SLDType_Star;     break;
            case MdfModel::MarkSymbol::Cross:    mdef.markernum() = SLDType_Cross;    break;
            case MdfModel::MarkSymbol::X:        mdef.markernum() = SLDType_X;        break;
            default: break;
        }

        // fill and edge colors
        cacheable = ConvertFill(marksym->GetFill(), mdef.style()) && cacheable;
        cacheable = ConvertStroke(marksym->GetEdge(), mdef.style().outline()) && cacheable;
    }
    else if (type == SymbolVisitor::stBlock)
    {
        MdfModel::BlockSymbol* blocksym = (MdfModel::BlockSymbol*)symbol;

        mdef.type()    = RS_MarkerType_Block;
        mdef.library() = blocksym->GetDrawingName();
        mdef.name()    = blocksym->GetBlockName();

        // block and layer override colors
        cacheable = EvalColor(blocksym->GetBlockColor(), mdef.style().color()) && cacheable;
        cacheable = EvalColor(blocksym->GetLayerColor(), mdef.style().outline().color()) && cacheable;
    }
    else if (type == SymbolVisitor::stW2D)
    {
        MdfModel::W2DSymbol* w2dsym = (MdfModel::W2DSymbol*)symbol;

        mdef.type()    = RS_MarkerType_W2D;
        mdef.library() = w2dsym->GetSymbolLibrary();
        mdef.name()    = w2dsym->GetSymbolName();

        // fill, line, and text override colors
        cacheable = EvalColor(w2dsym->GetFillColor(), mdef.style().color()) && cacheable;
        cacheable = EvalColor(w2dsym->GetLineColor(), mdef.style().outline().color()) && cacheable;
        cacheable = EvalColor(w2dsym->GetTextColor(), mdef.style().background()) && cacheable;
    }
    else if (type == SymbolVisitor::stFont)
    {
        MdfModel::FontSymbol* fontSym = (MdfModel::FontSymbol*)symbol;

        mdef.type() = RS_MarkerType_Font;

        // store the font name as the library string
        mdef.library() = fontSym->GetFontName();

        // store the marker character as the symbol name
        mdef.name() = (wchar_t)fontSym->GetCharacter();

        // font style
        RS_FontStyle_Mask style = RS_FontStyle_Regular;

        bool setting = false;
        cacheable = EvalBoolean(fontSym->GetBold(), setting) && cacheable;
        if (setting)
            style = (RS_FontStyle_Mask)(style | RS_FontStyle_Bold);

        cacheable = EvalBoolean(fontSym->GetItalic(), setting) && cacheable;
        if (setting)
            style = (RS_FontStyle_Mask)(style | RS_FontStyle_Italic);

        cacheable = EvalBoolean(fontSym->GetUnderlined(), setting) && cacheable;
        if (setting)
            style = (RS_FontStyle_Mask)(style | RS_FontStyle_Underline);

        mdef.fontstyle() = style;

        // foreground color
        cacheable = EvalColor(fontSym->GetForegroundColor(), mdef.style().color()) && cacheable;
    }
    else if (type == SymbolVisitor::stImage)
    {
        // TODO: not currently supported
        _ASSERT(false);
    }

    return cacheable;
}