Style

class axioma.render.Style

Базовый класс стиля оформления векторных объектов. Позволяет нарисовать геометрический объект на карте или в отчете.

Унаследован от: Serializable

От него наследуются: PointStyle, PolygonFillStyle, LineStringStyle, CollectionStyle, MapInfoPolygonStyle, MapInfoTextStyleBase

draw(geom, context)

Отрисовка геометрии. Предполагается, что геометрия имеет координаты устройства рисования.

Параметры:
  • geom (GeometryInterface) – Геометрия
  • context (Context) – Контекст, в котором будет отрисована геометрия
isEqual(style)

Производит сравнение стилей на идентичность

Параметры:style (Style) – Сравниваемый стиль
Результат:True, если стили эквивалентны. В противном случае False
Тип результата:bool

GeometryWithStyle

class axioma.render.GeometryWithStyle

Класс, объединяющий геометрию и стиль

geom

Геометрия

Type:Geometry
style

Стиль

Type:Style

HasStyles

class axioma.render.HasStyles

Это интерфейс для предоставления всех используемых стилей в объекте данных.

От него наследуются: child

usedStyles()

Получение списка используемых стилей

Результат:Список со стилями
Тип результата:list [Style]

Пример использования. Отрисовывает в окне диалога геометрии разного типа с различными стилями:

# Импорт
from axioma.cs import *
from axioma.core.geometry import *
from axioma.mapinfo import *
from axioma.render import *

from PyQt5.QtCore import  *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

# Координатная система
cs_ne = CoordSysFactory.defaultCoordSysFactory().createFromPRJ("CoordSys Nonearth Units \"m\"" )

# Преобразование цвета в формат MapBasic
def colorToMapbasic(color):
                return QColor(color).rgb() - 0xFF000000

# Создание полилинии
def createLineString():
                poly = QPolygonF();
                poly << QPointF(110,10) << QPointF(110,100) << QPointF(150,50) << QPointF(200,100) << QPointF(200,10)
                ls = LineString(cs_ne, poly)
                return ls

# Создание полигона
def createPolygon():
                poly = QPolygonF();
                poly << QPointF(10,10) << QPointF(10,100) << QPointF(50,50) << QPointF(100,100) << QPointF(100,10) << QPointF(10,10)
                polygon = Polygon(cs_ne, poly)
                return polygon

# Создание точки
def createPoint():
                return Point(cs_ne, 250, 50)

# Создание текста
def createText():
                text = Text(cs_ne, "Sample text", QPointF(300,50) )
                return text


class Example(QDialog):

                def __init__(self, parent):
                                QDialog.__init__(self, parent)
                                self.initUI()

                def initUI(self):
                                self.setGeometry(200, 200, 600, 400)
                                self.setWindowTitle('Пример отрисовки геометрии со стилем')

# Преобразование координат геометрии из координат карты в координаты окна
                def transformGeomerty(self, geom, context):
                                return geom.transformed(context.sceneToDeviceTransform())

# Отрисовка геометрии с соответствующим стилем
                def drawGeometry(self, context, style, geom):
                        if style is not None:
                                                geom_trans = self.transformGeomerty(geom, context)
                                                style.draw(geom_trans, context)

                def drawPolygon(self, context, num, color):
                        style = MapBasicStyle().styleFromString("Pen (1, 5, 16711935) Brush (%d, 255, %d)"  % (num, color))
                        self.drawGeometry(context, style, createPolygon())

                def drawLineString(self, context, num, color):
                        style = MapBasicStyle().styleFromString("Pen (2, %d,%d)"  % (num, color))
                        self.drawGeometry(context, style, createLineString())

                def drawPoint(self, context, num, color):
                        style = MapBasicStyle().styleFromString("Symbol (%d,%d, 24)"  % (num, color))
                        self.drawGeometry(context, style, createPoint())

                def drawText(self, context):
                                style = MapBasicStyle().styleFromString("Font (\"Arial\",1,9,16711680)")
                                self.drawGeometry(context, style, createText())

# Создание контекста
                def createContext(self, painter, deviceRect):
                                sceneRect = QRectF(0,0,100,100)
                                viewport = MapViewport (deviceRect,sceneRect,cs_ne)
                                return MapContext(painter, viewport)

# Отрисовка
                def paintEvent(self, event):
                                try:
                                                painter = QPainter(self)
                                                painter.fillRect(event.rect(), Qt.white)
# Создание контекста
                                                context1 = self.createContext(painter, QRectF(0,10,100,100))
# И отрисовка его (С использованием строки mapbasic)
                                                self.drawPolygon(context1, 8, colorToMapbasic(Qt.red))
                                                self.drawLineString(context1, 2, colorToMapbasic(Qt.green))
                                                self.drawPoint(context1, 36, colorToMapbasic(Qt.red))
                                                self.drawText(context1)
# Сдвинем вниз
                                                context2 = self.createContext(painter, QRectF(0,140,100,100))
                                                self.drawPolygon(context2, 2, colorToMapbasic(Qt.blue))
                                                self.drawLineString(context2, 90, colorToMapbasic(Qt.black))
# Еще раз сдвинем вниз
                                                context3 = self.createContext(painter, QRectF(0,270,100,100))
# Полигон (создаем явно через конструктор)
                                                pstyle = MapInfoPolygonStyle()
                                                p_fill = MapInfoFillStyle(4, Qt.darkRed)
                                                pstyle.setAreaStyle(p_fill)
                                                p_pen= MapInfoLineStyle()
                                                p_pen.setPattern(8)
                                                p_pen.setColor(Qt.darkBlue)
                                                pstyle.setPeripheryStyle(p_pen)
                                                self.drawGeometry(context3, pstyle, createPolygon())
# Полилиния
                                                pen= MapInfoLineStyle()
                                                pen.setPattern(56)
                                                pen.setColor(Qt.darkGreen)
                                                pen.setWidth(UnitValue(Unit.pixel(), 4))
                                                self.drawGeometry(context3, pen, createLineString())
# Точка
                                                fs = FontSymbolStyle()
                                                fs.setFont(QFont("Mapinfo Symbols", 32))
                                                fs.setSymbolMapinfo(37)
                                                fs.setColor(Qt.blue)
                                                self.drawGeometry(context3, fs, createPoint())
# Текст
                                                ts = OverrideMapInfoTextStyle() # Стиль
                                                style_data = MapInfoTextStyleData() # Данные для стиля
                                                renderer = TextRenderer() # Оформление текста
                                                font =  QFont("Arial")
                                                font.setBold(True)
                                                renderer.setFont(font)
                                                renderer.setColor(Qt.blue)
                                                style_data.setFontSize(24)
                                                style_data.setTextRenderer(renderer) # Установка оформления
                                                ts.setMapInfoTextStyleData(style_data)  # Установка данных со стилем
                                                text = createText() # Непосредственно сама геометрия
                                                text.setAngle(45)
                                                text.setTextStyleData(style_data) # Устанавливаем данные
                                                self.drawGeometry(context3, ts, text)
                                except Exception as ex:
                                                print(ex)

dlg = Example(axioma.app.mainWindow)
dlg.exec()