Skip to content

Commit

Permalink
Merge branch 'dui3/alpha' into DUI3-124-Receiving-Curves-Arcs-Ellipse…
Browse files Browse the repository at this point in the history
…s-Nurbs-Curves
  • Loading branch information
KatKatKateryna committed Jul 1, 2024
2 parents bcb7e99 + b6141ff commit 3112dcb
Show file tree
Hide file tree
Showing 19 changed files with 163 additions and 71 deletions.
4 changes: 2 additions & 2 deletions All.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3044,8 +3044,6 @@ Global
{11F7D41B-AFCA-4D29-BC08-285A14BF3A3B} = {2E00592E-558D-492D-88F9-3ECEE4C0C7DA}
{804E065F-914C-414A-AF84-009312C3CFF6} = {1FE3C60E-7865-40A5-9794-55ECB64F6489}
{9ADD1B7A-6401-4202-8613-F668E2FBC0A4} = {804E065F-914C-414A-AF84-009312C3CFF6}
{631C295A-7CCF-4B42-8686-7034E31469E7} = {804E065F-914C-414A-AF84-009312C3CFF6}
{D940853C-003A-482C-BDB0-665367F274A0} = {804E065F-914C-414A-AF84-009312C3CFF6}
{7420652C-3046-4F38-BE64-9B9E69D76FA2} = {FD4D6594-D81E-456F-8F2E-35B09E04A755}
{3973D572-5E24-476F-B058-8022D826B793} = {326ECEE0-D009-4A65-B24C-00FA343D8B99}
{7B02BACC-D9B6-4FFE-A450-7ECB5F71F209} = {C73C19B5-72A3-4C63-8D56-0A7E7DB46CA5}
Expand All @@ -3056,6 +3054,8 @@ Global
{70DEAA13-6DC8-44A0-B287-9E806A8054F1} = {890F3257-FCC2-4ED8-9180-22B3641B494C}
{F06E4C37-4076-4272-9CA6-FB505E02CD31} = {BE521908-7944-46F3-98BF-B47D34509934}
{DDBBA313-69A6-40DE-AB3A-79EE5BF32A7E} = {743489BF-1941-43D5-8AF9-35C56D0DCC34}
{631C295A-7CCF-4B42-8686-7034E31469E7} = {804E065F-914C-414A-AF84-009312C3CFF6}
{D940853C-003A-482C-BDB0-665367F274A0} = {804E065F-914C-414A-AF84-009312C3CFF6}
{C9C28F31-1367-438C-83B0-049C3B3A3E3B} = {804E065F-914C-414A-AF84-009312C3CFF6}
{06082BAA-98E8-49B1-9D33-252B126A0561} = {804E065F-914C-414A-AF84-009312C3CFF6}
EndGlobalSection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Reflection;
using ArcGIS.Core.Data;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using Speckle.Connectors.ArcGIS.HostApp;
using Speckle.Connectors.ArcGIS.Utils;
using Speckle.Connectors.DUI.Bindings;
using Speckle.Connectors.DUI.Bridge;
using Speckle.Connectors.DUI.Models;
Expand Down Expand Up @@ -58,7 +60,8 @@ public BasicConnectorBinding(DocumentModelStore store, ArcGISSettings settings,

public void RemoveModel(ModelCard model) => _store.RemoveModel(model);

public void HighlightObjects(List<string> objectIds) => HighlightObjectsOnView(objectIds);
public void HighlightObjects(List<string> objectIds) =>
HighlightObjectsOnView(objectIds.Select(x => new ObjectID(x)).ToList());

public void HighlightModel(string modelCardId)
{
Expand All @@ -69,16 +72,16 @@ public void HighlightModel(string modelCardId)
return;
}

var objectIds = new List<string>();
var objectIds = new List<ObjectID>();

if (model is SenderModelCard senderModelCard)
{
objectIds = senderModelCard.SendFilter.NotNull().GetObjectIds();
objectIds = senderModelCard.SendFilter.NotNull().GetObjectIds().Select(x => new ObjectID(x)).ToList();
}

if (model is ReceiverModelCard receiverModelCard)
{
objectIds = receiverModelCard.BakedObjectIds.NotNull();
objectIds = receiverModelCard.BakedObjectIds.NotNull().Select(x => new ObjectID(x)).ToList();
}

if (objectIds is null)
Expand All @@ -88,42 +91,42 @@ public void HighlightModel(string modelCardId)
HighlightObjectsOnView(objectIds);
}

private async void HighlightObjectsOnView(List<string> objectIds)
private async void HighlightObjectsOnView(List<ObjectID> objectIds)
{
MapView mapView = MapView.Active;

await QueuedTask
.Run(() =>
{
List<MapMember> mapMembers = GetMapMembers(objectIds, mapView);
List<MapMemberFeature> mapMembersFeatures = GetMapMembers(objectIds, mapView);
ClearSelectionInTOC();
ClearSelection();
SelectMapMembersInTOC(mapMembers);
SelectMapMembers(mapMembers);
SelectMapMembersInTOC(mapMembersFeatures);
SelectMapMembersAndFeatures(mapMembersFeatures);
mapView.ZoomToSelected();
})
.ConfigureAwait(false);
}

private List<MapMember> GetMapMembers(List<string> objectIds, MapView mapView)
private List<MapMemberFeature> GetMapMembers(List<ObjectID> objectIds, MapView mapView)
{
List<MapMember> mapMembers = new();
// find the layer on the map (from the objectID) and add the featureID is available
List<MapMemberFeature> mapMembersFeatures = new();

foreach (string objectId in objectIds)
foreach (ObjectID objectId in objectIds)
{
MapMember mapMember = mapView.Map.FindLayer(objectId);
MapMember mapMember = mapView.Map.FindLayer(objectId.MappedLayerURI, true);
if (mapMember is null)
{
mapMember = mapView.Map.FindStandaloneTable(objectId);
mapMember = mapView.Map.FindStandaloneTable(objectId.MappedLayerURI);
}
if (mapMember is null)
if (mapMember is not null)
{
continue;
MapMemberFeature mapMembersFeat = new(mapMember, objectId.FeatureId);
mapMembersFeatures.Add(mapMembersFeat);
}
mapMembers.Add(mapMember);
}

return mapMembers;
return mapMembersFeatures;
}

private void ClearSelection()
Expand All @@ -143,24 +146,39 @@ private void ClearSelectionInTOC()
MapView.Active.ClearTOCSelection();
}

private void SelectMapMembers(List<MapMember> mapMembers)
private void SelectMapMembersAndFeatures(List<MapMemberFeature> mapMembersFeatures)
{
foreach (var member in mapMembers)
foreach (MapMemberFeature mapMemberFeat in mapMembersFeatures)
{
MapMember member = mapMemberFeat.MapMember;
if (member is FeatureLayer layer)
{
layer.Select();
if (mapMemberFeat.FeatureId == null)
{
// select full layer if featureID not specified
layer.Select();
}
else
{
// query features by ID
var objectIDfield = layer.GetFeatureClass().GetDefinition().GetObjectIDField();

// FeatureID range starts from 0, but auto-assigned IDs in the layer start from 1
QueryFilter anotherQueryFilter = new() { WhereClause = $"{objectIDfield} = {mapMemberFeat.FeatureId + 1}" };
using (Selection onlyOneSelection = layer.Select(anotherQueryFilter, SelectionCombinationMethod.New)) { }
}
}
}
}

private void SelectMapMembersInTOC(List<MapMember> mapMembers)
private void SelectMapMembersInTOC(List<MapMemberFeature> mapMembersFeatures)
{
List<Layer> layers = new();
List<StandaloneTable> tables = new();

foreach (MapMember member in mapMembers)
foreach (MapMemberFeature mapMemberFeat in mapMembersFeatures)
{
MapMember member = mapMemberFeat.MapMember;
if (member is Layer layer)
{
if (member is not GroupLayer) // group layer selection clears other layers selection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Speckle.Core.Models.GraphTraversal;
using Speckle.Converters.ArcGIS3;
using RasterLayer = Objects.GIS.RasterLayer;
using Speckle.Connectors.ArcGIS.Utils;

namespace Speckle.Connectors.ArcGIS.Operations.Receive;

Expand Down Expand Up @@ -116,21 +117,33 @@ CancellationToken cancellationToken
else if (trackerItem.DatasetId == null)
{
results.Add(
new(Status.ERROR, trackerItem.Base, null, null, new ArgumentException("Unknown error: Dataset not created"))
new(
Status.ERROR,
trackerItem.Base,
null,
null,
new ArgumentException($"Unknown error: Dataset not created for {trackerItem.Base.speckle_type}")
)
);
}
else if (bakedMapMembers.TryGetValue(trackerItem.DatasetId, out MapMember? value))
{
// add layer and layer URI to tracker
trackerItem.AddConvertedMapMember(value);
trackerItem.AddLayerURI(value.URI);
conversionTracker[item.Key] = trackerItem; // not necessary atm, but needed if we use conversionTracker further
// only add a report item
AddResultsFromTracker(trackerItem, results);
}
else
{
// add layer and layer URI to tracker
// add layer to Map
MapMember mapMember = AddDatasetsToMap(trackerItem, createdLayerGroups);

// add layer and layer URI to tracker
trackerItem.AddConvertedMapMember(mapMember);
trackerItem.AddLayerURI(mapMember.URI);
conversionTracker[item.Key] = trackerItem;
conversionTracker[item.Key] = trackerItem; // not necessary atm, but needed if we use conversionTracker further

// add layer URI to bakedIds
bakedObjectIds.Add(trackerItem.MappedLayerURI == null ? "" : trackerItem.MappedLayerURI);
Expand All @@ -151,24 +164,45 @@ CancellationToken cancellationToken

private void AddResultsFromTracker(ObjectConversionTracker trackerItem, List<ReceiveConversionResult> results)
{
// prioritize individual hostAppGeometry type, if available:
if (trackerItem.HostAppGeom != null)
{
results.Add(
new(Status.SUCCESS, trackerItem.Base, trackerItem.MappedLayerURI, trackerItem.HostAppGeom.GetType().ToString())
);
}
else
if (trackerItem.MappedLayerURI == null) // should not happen
{
results.Add(
new(
Status.SUCCESS,
Status.ERROR,
trackerItem.Base,
trackerItem.MappedLayerURI,
trackerItem.HostAppMapMember?.GetType().ToString()
null,
null,
new ArgumentException($"Created Layer URI not found for {trackerItem.Base.speckle_type}")
)
);
}
else
{
// encode layer ID and ID of its feature in 1 object represented as string
ObjectID objectId = new(trackerItem.MappedLayerURI, trackerItem.DatasetRow);
if (trackerItem.HostAppGeom != null) // individual hostAppGeometry
{
results.Add(
new(
Status.SUCCESS,
trackerItem.Base,
objectId.ObjectIdToString(),
trackerItem.HostAppGeom.GetType().ToString()
)
);
}
else // hostApp Layers
{
results.Add(
new(
Status.SUCCESS,
trackerItem.Base,
objectId.ObjectIdToString(),
trackerItem.HostAppMapMember?.GetType().ToString()
)
);
}
}
}

private MapMember AddDatasetsToMap(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using ArcGIS.Desktop.Mapping;

namespace Speckle.Connectors.ArcGIS.Utils;

// bind together a layer object on the map, and auto-assigned ID if the specific feature
public readonly struct MapMemberFeature
{
public int? FeatureId { get; } // unique feature id (start from 0) of a feature in the layer
public MapMember MapMember { get; } // layer object on the Map

public MapMemberFeature(MapMember mapMember, int? featureId)
{
MapMember = mapMember;
FeatureId = featureId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Speckle.Connectors.ArcGIS.Utils;

// this struct is needed to be able to parse single-string value into IDs of both a layer, and it's individual feature
public struct ObjectID
{
private const string FEATURE_ID_SEPARATOR = "__speckleFeatureId__";
public string MappedLayerURI { get; } // unique ID of the layer on the map
public int? FeatureId { get; } // unique feature id (start from 0) of a feature in the layer

public ObjectID(string encodedId)
{
List<string> stringParts = encodedId.Split(FEATURE_ID_SEPARATOR).ToList();
MappedLayerURI = stringParts[0];
FeatureId = null;
if (stringParts.Count > 1)
{
FeatureId = Convert.ToInt32(stringParts[1]);
}
}

public ObjectID(string layerId, int? featureId)
{
MappedLayerURI = layerId;
FeatureId = featureId;
}

public readonly string ObjectIdToString()
{
if (FeatureId == null)
{
return $"{MappedLayerURI}";
}
else
{
return $"{MappedLayerURI}{FEATURE_ID_SEPARATOR}{FeatureId}";
}
}
}
6 changes: 0 additions & 6 deletions DUI3-DX/Connectors/Autocad/Directory.Packages.props

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="Speckle.AutoCAD.API" OverrideVersion="2023.0.0" />

<PackageReference Include="Speckle.AutoCAD.API" VersionOverride="2023.0.0" />
</ItemGroup>
<Import Project="..\Speckle.Connectors.AutocadShared\Speckle.Connectors.AutocadShared.projitems" Label="Shared" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="RhinoCommon" IncludeAssets="compile;build" />
<PackageReference Include="RhinoWindows" IncludeAssets="compile;build" />
<PackageReference Include="RhinoCommon" IncludeAssets="compile;build" VersionOverride="7.13.21348.13001" />
<PackageReference Include="RhinoWindows" IncludeAssets="compile;build" VersionOverride="7.13.21348.13001" />
<PackageReference Include="System.Resources.Extensions" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ is not MapPoint reprojectedPt
)
{
throw new SpeckleConversionException(
$"Conversion to Spatial Reference {_contextStack.Current.Document.Map.SpatialReference} failed"
$"Conversion to Spatial Reference {_contextStack.Current.Document.Map.SpatialReference.Name} failed"
);
}
return new(reprojectedPt.X, reprojectedPt.Y, reprojectedPt.Z, _contextStack.Current.SpeckleUnits);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ public ACG.GeometryType GetLayerGeometryType(VectorLayer target)
GISLayerGeometryType.POLYLINE => ACG.GeometryType.Polyline,
GISLayerGeometryType.MULTIPATCH => ACG.GeometryType.Multipatch,
GISLayerGeometryType.POLYGON3D => ACG.GeometryType.Multipatch,
_ => throw new ArgumentOutOfRangeException(nameof(target)),
_
=> throw new ArgumentOutOfRangeException(
nameof(target),
$"Geometry type '{originalGeomType}' is not recognized."
),
};
}
}
6 changes: 0 additions & 6 deletions DUI3-DX/Converters/Autocad/2023/Directory.Packages.props

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Speckle.AutoCAD.API" />
<PackageReference Include="Speckle.AutoCAD.API" VersionOverride="2023.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 0 additions & 6 deletions DUI3-DX/Converters/Autocad/2024/Directory.Packages.props

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@
},
"Speckle.AutoCAD.API": {
"type": "CentralTransitive",
"requested": "[2024.0.0, )",
"requested": "[2023.0.0, )",
"resolved": "2024.0.0",
"contentHash": "pZZ5uI+NXhZaQnsqRkgp/rywqBAjDObDJ9XNFGJvemT5k2OthDpHzlK/mKxz8QDCYie7uImQ8dv3uWj2QUFDPw=="
},
Expand Down
Loading

0 comments on commit 3112dcb

Please sign in to comment.