Skip to content

Commit

Permalink
Merge pull request #223 from specklesystems/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
KatKatKateryna authored Dec 10, 2024
2 parents a5d6729 + 9183664 commit 658ed58
Show file tree
Hide file tree
Showing 23 changed files with 1,384 additions and 828 deletions.
2 changes: 1 addition & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[general]
name=Speckle
qgisMinimumVersion=3.34.6
qgisMaximumVersion=3.38.2
qgisMaximumVersion=3.43.0
description=Speckle 2.0 Connector for QGIS
version=0.0.99
author=Speckle Systems
Expand Down
4 changes: 2 additions & 2 deletions plugin_utils/debugging_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
##################### debug serverInfo
def getServerInfo():
from specklepy.core.api.client import SpeckleClient
from specklepy.core.api.resources.server import Resource as ServerResource
from specklepy.core.api.resources import server
from specklepy_qt_ui.qt_ui.DataStorage import DataStorage
d = DataStorage()
d.check_for_accounts()
acc = d.accounts[0]
clientSpeckle = SpeckleClient(
acc.serverInfo.url, acc.serverInfo.url.startswith("https")
)
r = ServerResource(
r = server.Resource(
acc,
r"C:\Users\katri\AppData\Roaming\Speckle\Accounts",
clientSpeckle.httpclient,
Expand Down
22 changes: 21 additions & 1 deletion plugin_utils/helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
from typing import List
from typing import List, Optional
from textwrap import wrap

import inspect
from difflib import SequenceMatcher

from specklepy.objects.units import get_units_from_string
from specklepy.objects.units import get_scale_factor_to_meters
from specklepy.core.api.client import SpeckleClient


SYMBOL = "_x_x_"
UNSUPPORTED_PROVIDERS = ["WFS", "wms", "wcs", "vectortile"]
Expand Down Expand Up @@ -212,3 +214,21 @@ def findFeatColors(fetColors: List, f):
if colorFound == 0:
fetColors.append(None)
return fetColors


def get_project_workspace_id(client: SpeckleClient, project_id: str) -> Optional[str]:
workspace_id = None
server_version = client.project.server_version or client.server.version()

# Local yarn builds of server will report a server version of "dev"
# We'll assume that local builds are up-to-date with the latest features
if server_version[0] == "dev":
maj = 999
min = 999
else:
maj = server_version[0]
min = server_version[1]

if maj > 2 or (maj == 2 and min > 20):
workspace_id = client.project.get(project_id).workspaceId
return workspace_id
10 changes: 8 additions & 2 deletions plugin_utils/object_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"Objects.Geometry.",
"Objects.BuiltElements.",
"IFC",
"Objects.Other.Hatch",
] # will properly traverse and check for displayValue


Expand Down Expand Up @@ -261,7 +262,9 @@ def loopVal(
):
return

if not value.speckle_type.startswith("Objects.Geometry."):
if not value.speckle_type.startswith(
"Objects.Geometry."
) and not value.speckle_type.endswith(".Hatch"):
loopObj(value, name, streamBranch, plugin, used_ids, matrix)
elif value.id not in used_ids: # if geometry
used_ids.append(value.id)
Expand Down Expand Up @@ -338,7 +341,10 @@ def loopVal(
item.speckle_type
and item.speckle_type != "Objects.Geometry.Mesh"
and item.speckle_type != "Objects.Geometry.Brep"
and item.speckle_type.startswith("Objects.Geometry.")
and (
item.speckle_type.startswith("Objects.Geometry.")
or item.speckle_type.endswith(".Hatch")
)
): # or item.speckle_type == 'Objects.BuiltElements.Alignment'):
geometryLayerToNative(value, name, val_id, streamBranch, plugin)
time.sleep(0.3)
Expand Down
10 changes: 4 additions & 6 deletions plugin_utils/requirements_mac.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
geopandas==0.8.1
geovoronoi==0.4.0
gql==3.4.1
pandas==1.3.3
pyproj==3.2.0
pyshp==2.3.1
python-dateutil==2.8.0
requests-toolbelt==0.10.1
requests==2.31.0
specklepy==2.17.12
urllib3==1.26.16
specklepy==2.21.0
earcut==1.1.5
numpy==1.22.4
pandas==1.3.3
1,418 changes: 791 additions & 627 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
[tool.poetry.dependencies]
python = ">=3.9, <4.0"
numpy = "1.26.4"
specklepy = "2.19.3"
specklepy = "2.21.0"
pyshp = "2.3.1"
requests = "2.31.0"
requests-toolbelt = "1.0.0"
Expand Down
80 changes: 51 additions & 29 deletions speckle/converter/features/feature_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
)
from speckle.converter.geometry.mesh import constructMeshFromRaster
from speckle.converter.geometry.utils import apply_pt_offsets_rotation_on_send
from speckle.converter.layers.symbology import get_a_r_g_b
from speckle.converter.layers.symbology import (
featureColorfromNativeRenderer,
get_a_r_g_b,
)
from speckle.converter.layers.utils import (
generate_qgis_app_id,
getArrayIndicesFromXY,
Expand All @@ -37,6 +40,7 @@
GisNonGeometryElement,
GisTopography,
)
from specklepy.objects.other import DisplayStyle

from specklepy.objects import Base

Expand Down Expand Up @@ -103,12 +107,15 @@ def featureToSpeckle(
# geom is GisPointElement, GisLineElement, GisPolygonElement
new_geom = GisFeature()
new_geom.geometry = []
new_geom.displayValue = []
for g in geom.geometry:
obj = g
if isinstance(g, GisPolygonGeometry):
new_geom.displayValue = []
obj = GisPolygonGeometry(boundary=g.boundary, voids=g.voids)
new_geom.geometry.append(obj)
obj = GisPolygonGeometry(
units=g.units, boundary=g.boundary, voids=g.voids
) # exclude displayValue
new_geom.geometry.append(obj)
else:
new_geom.geometry.append(g)

all_errors = ""
for g in geom.geometry:
Expand Down Expand Up @@ -139,6 +146,9 @@ def featureToSpeckle(
else:
new_geom.displayValue.extend(g.displayValue)

else: # Points and Lines
new_geom.displayValue.append(g)

if len(geom.geometry) == 0:
all_errors = "No geometry converted"
new_report.update(
Expand All @@ -148,7 +158,8 @@ def featureToSpeckle(
else: # geom is None, should not happen, but we should pass the object with attributes anyway
new_report = {"obj_type": "", "errors": skipped_msg}
logToUser(skipped_msg, level=2, func=inspect.stack()[0][3])
geom = GisNonGeometryElement()
# geom = GisNonGeometryElement()
new_geom = GisNonGeometryElement()
except Exception as error:
new_report = {
"obj_type": "",
Expand Down Expand Up @@ -177,8 +188,17 @@ def featureToSpeckle(
attributes[corrected] = f_val

# if geom is not None and geom!="None":
geom.attributes = attributes
# geom.attributes = attributes
new_geom.attributes = attributes
try:
if len(new_geom.displayValue) > 0:
col = featureColorfromNativeRenderer(f, selectedLayer)
new_geom["displayStyle"] = DisplayStyle()
new_geom["displayStyle"].color = col
new_geom["displayStyle"].name = ""
new_geom["displayStyle"].linetype = ""
except Exception as e: # e.g. KeyError for Polygons
pass

dataStorage.latestActionFeaturesReport[
len(dataStorage.latestActionFeaturesReport) - 1
Expand All @@ -196,13 +216,18 @@ def featureToSpeckle(

def show_progress(current_row: int, rows: int, layer_name: str, plugin: "SpeckleQGIS"):
"""Updates UI with raster conversion %."""
percentage: int = int(current_row / rows) # i = percentage
if percentage % 10 == 0 or percentage == 5:
logToUser(
f"Converting layer '{layer_name}': {percentage}%...",
level=0,
plugin=plugin.dockwidget,
)
percentage: int = int(current_row / rows * 100)
if current_row == 0 or (percentage > 0 and percentage % 10 == 0) or percentage == 5:
# make sure repeated status is not logged
percentage_before: int = int((current_row - 1) / rows * 100)
if current_row == 0 or (
percentage_before > 0 and percentage != percentage_before
):
logToUser(
f"Converting layer '{layer_name}': {percentage}%...",
level=0,
plugin=plugin.dockwidget,
)


def reproject_raster(layer, crs, resolutionX, resolutionY):
Expand Down Expand Up @@ -1131,14 +1156,16 @@ def rasterFeatureToSpeckle(
list_nested = [
(4, 4 * ind, 4 * ind + 1, 4 * ind + 2, 4 * ind + 3)
for ind, _ in enumerate(band1_values)
]
faces_filtered = [item for sublist in list_nested for item in sublist]
] # heavy function
faces_filtered = [
item for sublist in list_nested for item in sublist
] # heavy function
vertices_filtered = get_raster_mesh_coords(
reprojected_raster_stats,
rasterResXY_reprojected,
band1_values,
dataStorage,
)
) # fast
rendererType = selectedLayer.renderer().type()
colors_filtered, have_transparent_cells = get_raster_colors(
selectedLayer,
Expand All @@ -1148,7 +1175,7 @@ def rasterFeatureToSpeckle(
rasterBandMaxVal,
rendererType,
plugin,
)
) # fast
###############################################################################
if texture_transform is True or terrain_transform is True:
for v in range(rasterDimensions[1]): # each row, Y
Expand Down Expand Up @@ -1344,22 +1371,17 @@ def featureToNative(feature: Base, fields: "QgsFields", dataStorage):
try:
qgsGeom = None

if isinstance(feature, GisNonGeometryElement) or (
isinstance(feature, GisFeature) and feature.geometry is None
if (
isinstance(feature, GisNonGeometryElement)
or feature.speckle_type.endswith("GisNonGeometricFeature")
or (isinstance(feature, GisFeature) and feature.geometry is None)
):
pass
else:
try:
speckle_geom = (
feature.geometry
) # for QGIS / ArcGIS Layer type from 2.14
speckle_geom = feature.geometry
except:
try:
speckle_geom = feature[
"geometry"
] # for QGIS / ArcGIS Layer type before 2.14
except:
speckle_geom = feature # for created in other software
speckle_geom = feature.displayValue

if not isinstance(speckle_geom, list):
qgsGeom = convertToNative(speckle_geom, dataStorage)
Expand Down
6 changes: 6 additions & 0 deletions speckle/converter/geometry/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
isFlat,
polygonToSpeckle,
polygonToNative,
hatchToNative,
)
from speckle.converter.geometry.polyline import (
compoudCurveToSpeckle,
Expand Down Expand Up @@ -324,6 +325,11 @@ def convertToNative(base: Base, dataStorage) -> Union["QgsGeometry", None]:
for conversion in conversions:
# distinguish normal QGIS polygons and the ones sent as Mesh only
try:
# detect hatch
if base.speckle_type.endswith(".Hatch"):
converted = hatchToNative(base, dataStorage)
break

if isinstance(base, GisPolygonGeometry):
if base.boundary is None:
try:
Expand Down
Loading

0 comments on commit 658ed58

Please sign in to comment.