////////////////////////////////////////////////////////////////////////////// // Checks if a style is already cached and returns it if it is. // Otherwise evaluates a style and if it is constant, caches it // in a hashtable. void PolygonAdapter::ObtainStyle(MdfModel::AreaSymbolization2D* asym, RS_FillStyle& fillStyle) { bool cacheable = ConvertFill(asym, fillStyle); if (cacheable) { RS_FillStyle* rsfill = new RS_FillStyle(); *rsfill = fillStyle; m_hAreaSymCache[asym] = rsfill; } }
bool GeometryAdapter::ConvertFill(MdfModel::AreaSymbolization2D* fill, RS_FillStyle& rsfill) { if (fill == NULL) return false; // can also return true - this really is an error condition MdfModel::Fill* mdffill = fill->GetFill(); bool const1 = ConvertFill(mdffill, rsfill); bool const2 = ConvertStroke(fill->GetEdge(), rsfill.outline()); return const1 && const2; }
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; }