private async Task <bool> UpdatePolygonResultPreviewAsync( bool nonDefaultSide, [NotNull] Polyline sketchPolyline, [NotNull] List <Feature> polygonSelection) { ReshapeResult reshapeResult = null; if (polygonSelection.Count != 0) { // Idea: ReshapeOperation class that contains the options to build the rpc, cancellation token, time out settings and logging. // TODO: Keep this source and cancel in case finish sketch happens var cancellationTokenSource = new CancellationTokenSource(3000); reshapeResult = MicroserviceClient.TryReshape( polygonSelection, sketchPolyline, null, false, true, nonDefaultSide, cancellationTokenSource.Token); } // TODO: discard result if the user has since clicked again or some other event (finish / esc) happened // TODO in 2.6 and higher try: //FrameworkApplication.QueueIdleAction( // () => _feedback?.UpdatePreview(reshapeResult.ResultFeatures)); return(await QueuedTaskUtils.Run( () => _feedback?.UpdatePreview(reshapeResult?.ResultFeatures))); }
//protected override void OnKeyUpCore(MapViewKeyEventArgs k) //{ // _msg.VerboseDebug("OnKeyUpCore"); // if (k.Key == _keyToggleNonDefaultSide) // { // _nonDefaultSideMode = ! _nonDefaultSideMode; // k.Handled = true; // } // else if (k.Key == Key.Space) // { // k.Handled = true; // } // base.OnKeyUpCore(k); //} //protected override async Task HandleKeyUpAsync(MapViewKeyEventArgs k) //{ // // At 2.5 this is never called (despite setting k.Handled = true above). // TODO: Test in 2.6/2.7 // try // { // if (k.Key == _keyToggleNonDefaultSide || // k.Key == Key.Space) // { // _updateFeedbackTask = UpdateFeedbackAsync(_nonDefaultSideMode); // await _updateFeedbackTask; // } // } // catch (Exception e) // { // _msg.Warn("Error generating preview", e); // } // finally // { // _updateFeedbackTask = null; // } //} protected override async Task <bool> OnEditSketchCompleteCoreAsync( Geometry sketchGeometry, EditingTemplate editTemplate, MapView activeView, CancelableProgressor cancelableProgressor = null) { _feedback.Clear(); // TODO: cancel all running background tasks... var polyline = (Polyline)sketchGeometry; List <Feature> selection; // Or allow selecting next feature already? SetCursor(Cursors.Wait); bool success = await QueuedTaskUtils.Run(async() => { selection = GetApplicableSelectedFeatures(activeView).ToList(); var potentiallyAffectedFeatures = GetAdjacentFeatures(selection, cancelableProgressor); // This timout should be enough even in extreme circumstances: int timeout = selection.Count * 10000; _cancellationTokenSource = new CancellationTokenSource(timeout); ReshapeResult result = MicroserviceClient.Reshape( selection, polyline, potentiallyAffectedFeatures, true, true, _nonDefaultSideMode, _cancellationTokenSource.Token); if (result == null) { return(false); } Dictionary <Feature, Geometry> resultFeatures = result.ResultFeatures.ToDictionary(r => r.Feature, r => r.UpdatedGeometry); LogReshapeResults(result, selection.Count); success = await SaveAsync(resultFeatures); // At some point, hopefully, read-only operations on the CIM model can run in parallel await ToolUtils.FlashResultPolygonsAsync(activeView, resultFeatures); return(success); }); _nonDefaultSideMode = false; //if (!_advancedReshapeOptions.RemainInSketchMode) { StartSelectionPhase(); } return(success); // taskSave.Result; }
private void LogReshapeResults(ReshapeResult reshapeResult, int applicableSelectionCount) { var result = new Dictionary <Feature, Geometry>(); foreach (var resultFeature in reshapeResult.ResultFeatures) { var feature = resultFeature.Feature; result.Add(feature, resultFeature.NewGeometry); string message = StringUtils.Concatenate(resultFeature.Messages, ". "); if (!string.IsNullOrEmpty(message)) { message = $"{feature.GetTable().GetDefinition().GetAliasName()} <oid> {feature.GetObjectID()}: {message}"; if (resultFeature.HasWarningMessage) { _msg.Warn(message); } else { _msg.Info(message); } } } if (result.Count == 0) { _msg.Warn(reshapeResult.FailureMessage); } else { // Currently the non-reshaped failures (for several features) are in the global message: if (applicableSelectionCount > 1 && !string.IsNullOrEmpty(reshapeResult.FailureMessage)) { _msg.Warn(reshapeResult.FailureMessage); } // Log individual reshape messages string titleMessage = string.Empty; if (applicableSelectionCount > 1) { titleMessage = $"Reshaped {reshapeResult.ResultFeatures.Count} " + $"of {applicableSelectionCount} selected features:"; } LogSuccessfulReshape(titleMessage, result); } }