Skip to content

Commit

Permalink
add Polyline domain on send
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Oct 24, 2024
1 parent 189223b commit 654c752
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
4 changes: 2 additions & 2 deletions speckle/converter/geometry/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
isFlat,
polygonToSpeckle,
polygonToNative,
hatchToNative
hatchToNative,
)
from speckle.converter.geometry.polyline import (
compoudCurveToSpeckle,
Expand Down Expand Up @@ -326,7 +326,7 @@ def convertToNative(base: Base, dataStorage) -> Union["QgsGeometry", None]:
# distinguish normal QGIS polygons and the ones sent as Mesh only
try:
# detect hatch
if base.speckle_type.endswith('.Hatch'):
if base.speckle_type.endswith(".Hatch"):
converted = hatchToNative(base, dataStorage)
break

Expand Down
55 changes: 50 additions & 5 deletions speckle/converter/geometry/polyline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Ellipse,
Polycurve,
Plane,
Interval,
)
from speckle.converter.geometry.point import pointToNative, pointToSpeckle

Expand Down Expand Up @@ -92,6 +93,7 @@ def polylineFromVerticesToSpeckle(
polyline.value.extend([point.x, point.y, point.z])

col = featureColorfromNativeRenderer(feature, layer)
polyline["domain"] = Interval.from_list([0, 1])
polyline["displayStyle"] = {}
polyline["displayStyle"]["color"] = col
return polyline
Expand All @@ -113,24 +115,34 @@ def unknownLineToSpeckle(
poly_original = poly_original.constGet()
poly = poly_original.clone()

result = None

if poly.wkbType() == 10: # CurvePolygon
# actualGeom = poly.constGet()
actualGeom = actualGeom.segmentize()
if xform is not None:
actualGeom.transform(xform)
return polylineToSpeckle(actualGeom, feature, layer, dataStorage)
result = polylineToSpeckle(actualGeom, feature, layer, dataStorage)

elif isinstance(poly, QgsCompoundCurve):
return compoudCurveToSpeckle(poly, feature, layer, dataStorage, xform)
result = compoudCurveToSpeckle(poly, feature, layer, dataStorage, xform)
elif isinstance(poly, QgsCircularString):
return arcToSpeckle(poly, feature, layer, dataStorage, xform)
result = arcToSpeckle(poly, feature, layer, dataStorage, xform)
else:
if xform is not None:
poly.transform(xform)
return polylineFromVerticesToSpeckle(
result = polylineFromVerticesToSpeckle(
poly.vertices(), closed, feature, layer, dataStorage
) # initial method

if result is None:
logToUser(
"LineString conversion failed", level=2, func=inspect.stack()[0][3]
)
return
result["domain"] = Interval.from_list([0, 1])
return result

except Exception as e:
logToUser(e, level=2, func=inspect.stack()[0][3])
return
Expand All @@ -151,7 +163,16 @@ def compoudCurveToSpeckle(
new_poly = poly.curveToLine()
if xform is not None:
new_poly.transform(xform)
return polylineToSpeckle(new_poly, feature, layer, dataStorage)
polyline = polylineToSpeckle(new_poly, feature, layer, dataStorage)

if polyline is None:
logToUser(
"LineString conversion failed", level=2, func=inspect.stack()[0][3]
)
return

polyline["domain"] = Interval.from_list([0, 1])
return polyline

except Exception as e:
logToUser(e, level=2, func=inspect.stack()[0][3])
Expand All @@ -162,6 +183,7 @@ def anyLineToSpeckle(geom_original, feature, layer, dataStorage, xform=None):
if isinstance(geom_original, QgsGeometry):
geom_original = geom_original.constGet()
geom = geom_original.clone()
result = None

type = geom.wkbType()
if (
Expand Down Expand Up @@ -196,7 +218,13 @@ def anyLineToSpeckle(geom_original, feature, layer, dataStorage, xform=None):
geom.transform(xform)
result = polylineToSpeckle(geom, feature, layer, dataStorage)

if result is None:
logToUser("LineString conversion failed", level=2, func=inspect.stack()[0][3])
return

result = addCorrectUnits(result, dataStorage)
result["domain"] = Interval.from_list([0, 1])

return result


Expand All @@ -217,7 +245,15 @@ def polylineToSpeckle(
poly.vertices(), closed, feature, layer, dataStorage
)

if polyline is None:
logToUser(
"LineString conversion failed", level=2, func=inspect.stack()[0][3]
)
return

polyline["domain"] = Interval.from_list([0, 1])
return polyline

except Exception as e:
logToUser(e, level=2, func=inspect.stack()[0][3])
return
Expand All @@ -242,6 +278,15 @@ def arcToSpeckle(
if xform is not None:
linestring.transform(xform)
arc = polylineToSpeckle(linestring, feature, layer, dataStorage)

if arc is None:
logToUser(
"LineString conversion failed", level=2, func=inspect.stack()[0][3]
)
return

arc["domain"] = Interval.from_list([0, 1])

col = featureColorfromNativeRenderer(feature, layer)
arc["displayStyle"] = {}
arc["displayStyle"]["color"] = col
Expand Down

0 comments on commit 654c752

Please sign in to comment.