Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #271 from speckleworks/Dimitrie/dev/popup-flow
Browse files Browse the repository at this point in the history
Dimitrie/dev/popup flow
  • Loading branch information
didimitrie authored Aug 13, 2019
2 parents d99c8c3 + 1751283 commit 757af25
Show file tree
Hide file tree
Showing 8 changed files with 558 additions and 443 deletions.
83 changes: 47 additions & 36 deletions SpeckleGrasshopper/BaseComponents/GhReceiverCoreClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override bool Write( GH_IWriter writer )
formatter.Serialize( ms, Client );
writer.SetByteArray( "speckleclient", ms.ToArray() );
}
writer.SetBoolean("deserialize", this.Deserialize);
writer.SetBoolean( "deserialize", this.Deserialize );
}
catch { }
return base.Write( writer );
Expand All @@ -101,7 +101,7 @@ public override bool Read( GH_IReader reader )
InitReceiverEventsAndGlobals();
}

this.Deserialize = reader.GetBoolean("deserialize");
this.Deserialize = reader.GetBoolean( "deserialize" );
}
catch
{
Expand All @@ -117,23 +117,34 @@ public override void AddedToDocument( GH_Document document )

if ( Client == null )
{
var myForm = new SpecklePopup.MainWindow( false, true );

var some = new System.Windows.Interop.WindowInteropHelper( myForm );
some.Owner = Rhino.RhinoApp.MainWindowHandle();

myForm.ShowDialog();

if ( myForm.restApi != null && myForm.apitoken != null )
Account account = null;
try
{
RestApi = myForm.restApi;
AuthToken = myForm.apitoken;
account = LocalContext.GetDefaultAccount();
}
else
catch ( Exception err )
{
AddRuntimeMessage( GH_RuntimeMessageLevel.Error, "Account selection failed." );
return;
}

if ( account == null )
{
var signInWindow = new SpecklePopup.SignInWindow( true );
var helper = new System.Windows.Interop.WindowInteropHelper( signInWindow );
helper.Owner = Rhino.RhinoApp.MainWindowHandle();

signInWindow.ShowDialog();

if ( signInWindow.AccountListBox.SelectedIndex != -1 )
account = signInWindow.accounts[ signInWindow.AccountListBox.SelectedIndex ];
else
{
AddRuntimeMessage( GH_RuntimeMessageLevel.Error, "Account selection failed." );
return;
}
}

RestApi = account.RestApi;
AuthToken = account.Token;
}

StreamIdChanger = new System.Timers.Timer( 1000 ); StreamIdChanger.Enabled = false;
Expand Down Expand Up @@ -185,15 +196,15 @@ public override void AppendAdditionalMenuItems( ToolStripDropDown menu )
GH_DocumentObject.Menu_AppendSeparator( menu );

base.AppendAdditionalMenuItems( menu );
var toggleItem = new ToolStripMenuItem("Deserialize objects.") { Name = "Deserialize objects.", Checked = this.Deserialize, CheckOnClick = true };
toggleItem.CheckStateChanged += (sender, e) =>
var toggleItem = new ToolStripMenuItem( "Deserialize objects." ) { Name = "Deserialize objects.", Checked = this.Deserialize, CheckOnClick = true };
toggleItem.CheckStateChanged += ( sender, e ) =>
{
this.Deserialize = ((ToolStripMenuItem)sender).Checked;
Rhino.RhinoApp.MainApplicationWindow.Invoke(expireComponentAction);
this.Deserialize = ( ( ToolStripMenuItem ) sender ).Checked;
Rhino.RhinoApp.InvokeOnUiThread( expireComponentAction );
};
menu.Items.Add(toggleItem);
menu.Items.Add( toggleItem );

GH_DocumentObject.Menu_AppendSeparator(menu);
GH_DocumentObject.Menu_AppendSeparator( menu );

GH_DocumentObject.Menu_AppendItem( menu, "Force refresh.", ( sender, e ) =>
{
Expand All @@ -206,7 +217,7 @@ public override void AppendAdditionalMenuItems( ToolStripDropDown menu )
GH_DocumentObject.Menu_AppendItem( menu, "View stream.", ( sender, e ) =>
{
if ( StreamId == null ) return;
System.Diagnostics.Process.Start(RestApi.Replace("/api/v1", "/#/view").Replace("/api", "/#/view") + @"/" + StreamId);
System.Diagnostics.Process.Start( RestApi.Replace( "/api/v1", "/#/view" ).Replace( "/api", "/#/view" ) + @"/" + StreamId );
} );

GH_DocumentObject.Menu_AppendItem( menu, "(API) View stream data.", ( sender, e ) =>
Expand Down Expand Up @@ -326,14 +337,14 @@ public virtual void UpdateGlobal( )
this.Message = SNJ.JsonConvert.SerializeObject( String.Format( "{0}/{1}", i, payload.Length ) );
}

foreach( var obj in newObjects )
foreach ( var obj in newObjects )
{
var matches = Client.Stream.Objects.FindAll( o => o._id == obj._id );

//TODO: Do this efficiently, this is rather brute force
for( int i = Client.Stream.Objects.Count - 1; i >= 0; i-- )
for ( int i = Client.Stream.Objects.Count - 1; i >= 0; i-- )
{
if(Client.Stream.Objects[i]._id == obj._id)
if ( Client.Stream.Objects[ i ]._id == obj._id )
{
Client.Stream.Objects[ i ] = obj;
}
Expand All @@ -356,14 +367,14 @@ public virtual void UpdateGlobal( )

SpeckleObjects.Clear();

Task.Run(() =>
{
ConvertedObjects = SpeckleCore.Converter.Deserialise(Client.Stream.Objects);
IsUpdating = false;
Rhino.RhinoApp.MainApplicationWindow.Invoke(expireComponentAction);
Task.Run( ( ) =>
{
ConvertedObjects = SpeckleCore.Converter.Deserialise( Client.Stream.Objects );
IsUpdating = false;
Rhino.RhinoApp.InvokeOnUiThread( expireComponentAction );

this.Message = "Got data\n@" + DateTime.Now.ToString("hh:mm:ss");
});
this.Message = "Got data\n@" + DateTime.Now.ToString( "hh:mm:ss" );
} );
}

public virtual void UpdateMeta( )
Expand Down Expand Up @@ -471,7 +482,7 @@ public void UpdateOutputStructure( )
foreach ( var layer in toAdd )
{
Param_GenericObject newParam = getGhParameter( layer );
Params.RegisterOutputParam( newParam, layer.OrderIndex != null ? ( int ) layer.OrderIndex : k );
Params.RegisterOutputParam( newParam, layer.OrderIndex != null ? ( int ) layer.OrderIndex : k );
k++;
}

Expand All @@ -487,10 +498,10 @@ public void SetObjects( IGH_DataAccess DA )
{
if ( Layers == null ) return;
if ( ConvertedObjects.Count == 0 && this.Deserialize ) return;
if ( Client.Stream.Objects.Count == 0 && !this.Deserialize) return;
if ( Client.Stream.Objects.Count == 0 && !this.Deserialize ) return;

List<object> chosenObjects;
if (this.Deserialize)
if ( this.Deserialize )
chosenObjects = ConvertedObjects;
else
chosenObjects = Client.Stream.Objects.Cast<object>().ToList();
Expand Down Expand Up @@ -528,7 +539,7 @@ public void SetObjects( IGH_DataAccess DA )
subsetCount += elCount;
}
}
DA.SetDataTree( layer.OrderIndex!=null ? ( int ) layer.OrderIndex : k, tree );
DA.SetDataTree( layer.OrderIndex != null ? ( int ) layer.OrderIndex : k, tree );
k++;
}
}
Expand Down
Loading

0 comments on commit 757af25

Please sign in to comment.