15 |
import binascii |
import binascii |
16 |
import unittest |
import unittest |
17 |
|
|
18 |
|
from mockgeo import SimpleShapeStore |
19 |
import support |
import support |
20 |
support.initthuban() |
support.initthuban() |
21 |
|
|
22 |
from Thuban.Model.color import Transparent, Color |
from Thuban.Model.color import Transparent, Color |
23 |
from Thuban.Model.data import Shape, SHAPETYPE_ARC, SHAPETYPE_POLYGON, \ |
from Thuban.Model.data import SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT |
|
SHAPETYPE_POINT |
|
24 |
from Thuban.Model.map import Map |
from Thuban.Model.map import Map |
25 |
from Thuban.Model.layer import Layer, RasterLayer |
from Thuban.Model.layer import Layer, RasterLayer |
26 |
from Thuban.Model.table import MemoryTable, \ |
from Thuban.Model.table import MemoryTable, \ |
27 |
FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING |
FIELDTYPE_DOUBLE, FIELDTYPE_INT, FIELDTYPE_STRING |
28 |
|
from Thuban.Model.classification import ClassGroupSingleton |
29 |
import Thuban.Model.resource |
import Thuban.Model.resource |
30 |
|
|
31 |
|
|
32 |
from Thuban.UI.baserenderer import BaseRenderer |
from Thuban.UI.baserenderer import BaseRenderer |
33 |
|
|
34 |
|
|
91 |
def draw_raster_data(self, data): |
def draw_raster_data(self, data): |
92 |
self.raster_data = data |
self.raster_data = data |
93 |
|
|
|
class SimpleShapeStore: |
|
|
|
|
|
def __init__(self, shapetype, shapes, table): |
|
|
self.shapetype = shapetype |
|
|
self.shapes = shapes |
|
|
self.table = table |
|
|
assert table.NumRows() == len(shapes) |
|
|
|
|
|
def ShapeType(self): |
|
|
return self.shapetype |
|
|
|
|
|
def Table(self): |
|
|
return self.table |
|
|
|
|
|
def NumShapes(self): |
|
|
return len(self.shapes) |
|
|
|
|
|
def Shape(self, index): |
|
|
return Shape(self.shapes[index]) |
|
|
|
|
94 |
|
|
95 |
class MockProjection: |
class MockProjection: |
96 |
|
|
416 |
('EndDrawing',)]) |
('EndDrawing',)]) |
417 |
|
|
418 |
|
|
419 |
|
def test_point_with_classification(self): |
420 |
|
"""Test BaseRenderer with point layer and classification""" |
421 |
|
table = MemoryTable([("type", FIELDTYPE_STRING), |
422 |
|
("value", FIELDTYPE_DOUBLE), |
423 |
|
("code", FIELDTYPE_INT)], |
424 |
|
[("UNKNOWN", 0.0, 0), |
425 |
|
("UNKNOWN", 0.0, 1)]) |
426 |
|
shapes = [[[(0, 0)]], [[(10, 10)]]] |
427 |
|
store = SimpleShapeStore(SHAPETYPE_POINT, shapes, table) |
428 |
|
|
429 |
|
map = Map("TestBaseRenderer") |
430 |
|
layer = Layer("point layer", store) |
431 |
|
group = ClassGroupSingleton(1) |
432 |
|
group.GetProperties().SetFill(Color(0, 0, 1)) |
433 |
|
layer.GetClassification().AppendGroup(group) |
434 |
|
layer.SetClassificationColumn("code") |
435 |
|
|
436 |
|
map.AddLayer(layer) |
437 |
|
self.to_destroy.append(map) |
438 |
|
|
439 |
|
dc = MockDC() |
440 |
|
renderer = SimpleRenderer(dc, 2, (10, 10)) |
441 |
|
|
442 |
|
renderer.render_map(map) |
443 |
|
|
444 |
|
self.assertEquals(dc.calls, |
445 |
|
[('BeginDrawing',), |
446 |
|
('SetBrush', ('brush', Transparent)), |
447 |
|
('SetPen', ('pen', Color(0, 0, 0), 1)), |
448 |
|
('DrawEllipse', 5, 5, 10, 10), |
449 |
|
('SetBrush', ('brush', Color(0, 0, 1))), |
450 |
|
('SetPen', ('pen', Color(0, 0, 0), 1)), |
451 |
|
('DrawEllipse', 25, -15, 10, 10), |
452 |
|
('SetFont', "label font"), |
453 |
|
('EndDrawing',)]) |
454 |
|
|
455 |
|
|
456 |
if __name__ == "__main__": |
if __name__ == "__main__": |
457 |
support.run_tests() |
support.run_tests() |