[Thuban-commits] r2710 - in trunk/thuban: . Thuban/Model Thuban/UI
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Oct 10 10:31:45 CEST 2006
Author: dpinte
Date: 2006-10-10 10:31:44 +0200 (Tue, 10 Oct 2006)
New Revision: 2710
Modified:
trunk/thuban/ChangeLog
trunk/thuban/Thuban/Model/layer.py
trunk/thuban/Thuban/UI/viewport.py
Log:
2006-10-10 Didrik Pinte <dpinte at itae.be>
* Thuban/Model/layer.py (Layer.GetLabelPosFromShape): new method
extracted from Thuban/UI/viewport.py
* Thuban/UI/viewport.py (Viewport.LabelShapeAt): uses new method
Modified: trunk/thuban/ChangeLog
===================================================================
--- trunk/thuban/ChangeLog 2006-10-03 09:34:51 UTC (rev 2709)
+++ trunk/thuban/ChangeLog 2006-10-10 08:31:44 UTC (rev 2710)
@@ -1,3 +1,8 @@
+2006-10-10 Didrik Pinte <dpinte at itae.be>
+ * Thuban/Model/layer.py (Layer.GetLabelPosFromShape): new method
+ extracted from Thuban/UI/viewport.py
+ * Thuban/UI/viewport.py (Viewport.LabelShapeAt): uses new method
+
2006-09-28 Didrik Pinte <dpinte at itae.be>
* Thuban/UI/classgen.py: bugfix due to wx2.6 update
Modified: trunk/thuban/Thuban/Model/layer.py
===================================================================
--- trunk/thuban/Thuban/Model/layer.py 2006-10-03 09:34:51 UTC (rev 2709)
+++ trunk/thuban/Thuban/Model/layer.py 2006-10-10 08:31:44 UTC (rev 2710)
@@ -12,6 +12,8 @@
import os
import warnings
+from wxproj import point_in_polygon_shape, shape_centroid
+
from Thuban import _
from messages import LAYER_PROJECTION_CHANGED, LAYER_VISIBILITY_CHANGED, \
@@ -22,6 +24,8 @@
from color import Transparent, Black
from base import TitledObject, Modifiable
from data import SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT
+from label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
+ ALIGN_LEFT, ALIGN_RIGHT
import resource
@@ -343,7 +347,53 @@
return (left, bottom, right, top)
+ def GetLabelPosFromShape(self, cmap, shape_index):
+ '''
+ Return the label position parameters (x, y, halign, valign) from the
+ shape object
+ '''
+ proj = cmap.projection
+ if proj is not None:
+ map_proj = proj
+ else:
+ map_proj = None
+ proj = self.projection
+ if proj is not None:
+ layer_proj = proj
+ else:
+ layer_proj = None
+ shapetype = self.ShapeType()
+ if shapetype == SHAPETYPE_POLYGON:
+ shapefile = self.ShapeStore().Shapefile().cobject()
+ x, y = shape_centroid(shapefile, shape_index,
+ map_proj, layer_proj, 1, 1, 0, 0)
+ if map_proj is not None:
+ x, y = map_proj.Inverse(x, y)
+ else:
+ shape = self.Shape(shape_index)
+ if shapetype == SHAPETYPE_POINT:
+ x, y = shape.Points()[0][0]
+ else:
+ # assume SHAPETYPE_ARC
+ points = shape.Points()[0]
+ x, y = points[len(points) / 2]
+ if layer_proj is not None:
+ x, y = layer_proj.Inverse(x, y)
+ if shapetype == SHAPETYPE_POINT:
+ halign = ALIGN_LEFT
+ valign = ALIGN_CENTER
+ elif shapetype == SHAPETYPE_POLYGON:
+ halign = ALIGN_CENTER
+ valign = ALIGN_CENTER
+ elif shapetype == SHAPETYPE_ARC:
+ halign = ALIGN_LEFT
+ valign = ALIGN_CENTER
+
+ return (x, y, halign, valign)
+
+
+
if resource.has_gdal_support():
import gdal
from gdalconst import GA_ReadOnly
Modified: trunk/thuban/Thuban/UI/viewport.py
===================================================================
--- trunk/thuban/Thuban/UI/viewport.py 2006-10-03 09:34:51 UTC (rev 2709)
+++ trunk/thuban/Thuban/UI/viewport.py 2006-10-10 08:31:44 UTC (rev 2710)
@@ -963,43 +963,8 @@
label_layer.RemoveLabel(shape_index)
return True
elif layer is not None and text:
- proj = self.map.projection
- if proj is not None:
- map_proj = proj
- else:
- map_proj = None
- proj = layer.projection
- if proj is not None:
- layer_proj = proj
- else:
- layer_proj = None
-
- shapetype = layer.ShapeType()
- if shapetype == SHAPETYPE_POLYGON:
- shapefile = layer.ShapeStore().Shapefile().cobject()
- x, y = shape_centroid(shapefile, shape_index,
- map_proj, layer_proj, 1, 1, 0, 0)
- if map_proj is not None:
- x, y = map_proj.Inverse(x, y)
- else:
- shape = layer.Shape(shape_index)
- if shapetype == SHAPETYPE_POINT:
- x, y = shape.Points()[0][0]
- else:
- # assume SHAPETYPE_ARC
- points = shape.Points()[0]
- x, y = points[len(points) / 2]
- if layer_proj is not None:
- x, y = layer_proj.Inverse(x, y)
- if shapetype == SHAPETYPE_POINT:
- halign = ALIGN_LEFT
- valign = ALIGN_CENTER
- elif shapetype == SHAPETYPE_POLYGON:
- halign = ALIGN_CENTER
- valign = ALIGN_CENTER
- elif shapetype == SHAPETYPE_ARC:
- halign = ALIGN_LEFT
- valign = ALIGN_CENTER
+ (x, y, halign, valign) = layer.GetLabelPosFromShape(self.map, \
+ shape_index)
label_layer.AddLabel(x, y, text,
halign = halign, valign = valign)
return True
More information about the Thuban-commits
mailing list