Skip to content

Commit

Permalink
Roomedit3dApp transformation works, updating BIM from viewer live
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Tammik committed May 26, 2016
1 parent 60cbb0f commit e8b272f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
32 changes: 29 additions & 3 deletions Roomedit3dApp/App.cs
@@ -1,5 +1,7 @@
#region Namespaces
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Newtonsoft.Json.Linq;
using Quobject.SocketIoClientDotNet.Client;
#endregion

Expand Down Expand Up @@ -46,8 +48,28 @@ public static ExternalEvent Event
/// </summary>
static void Enqueue( object data )
{
Util.Log( "Enqueue task" );
_bimUpdater.Enqueue( data );
JObject data2 = JObject.FromObject( data );

string s = string.Format(
"transform: uid={0} ({1:0.00},{2:0.00},{3:0.00})",
data2["externalId"], data2["offset"]["x"],
data2["offset"]["y"], data2["offset"]["z"] );

Util.Log( "Enqueue task " + s );

string uid1 = data2["externalId"].ToString();
XYZ offset1 = new XYZ(
double.Parse( data2["offset"]["x"].ToString() ),
double.Parse( data2["offset"]["y"].ToString() ),
double.Parse( data2["offset"]["z"].ToString() ) );

string uid = (string) data2["externalId"];
XYZ offset = new XYZ(
(double) data2["offset"]["x"],
(double) data2["offset"]["y"],
(double) data2["offset"]["z"] );

_bimUpdater.Enqueue( uid, offset );
_event.Raise();
}

Expand Down Expand Up @@ -86,7 +108,11 @@ public static bool ToggleSubscription()

_socket = IO.Socket( _url, options );

_socket.On( "transform", data => Enqueue( data ) );
_socket.On( Socket.EVENT_CONNECT, ()
=> Util.Log( "Connected" ) );

_socket.On( "transform", data
=> Enqueue( data ) );

_event = ExternalEvent.Create( _bimUpdater );

Expand Down
28 changes: 19 additions & 9 deletions Roomedit3dApp/BimUpdater.cs
Expand Up @@ -15,13 +15,14 @@ namespace Roomedit3dApp
class BimUpdater : IExternalEventHandler
{
/// <summary>
/// The queue of pending tasks.
/// The queue of pending tasks consisting
/// of UniqueID and translation offset vector.
/// </summary>
Queue<object> _queue = null;
Queue<Tuple<string,XYZ>> _queue = null;

public BimUpdater()
{
_queue = new Queue<object>();
_queue = new Queue<Tuple<string, XYZ>>();
}

/// <summary>
Expand All @@ -39,9 +40,15 @@ public void Execute( UIApplication a )

while ( 0 < _queue.Count )
{
Debug.Print( _queue.Dequeue().ToString() );
}
Tuple<string, XYZ> task = _queue.Dequeue();

Debug.Print( "Translating {0} by {1}",
task.Item1, Util.PointString( task.Item2 ) );

Element e = doc.GetElement( task.Item1 );
ElementTransformUtils.MoveElement(
doc, e.Id, task.Item2 );
}
t.Commit();
}
}
Expand All @@ -56,12 +63,15 @@ public string GetName()
}

/// <summary>
/// Enqueue a BIM update action to be performed.
/// Enqueue a BIM update action to be performed,
/// consisting of UniqueID and translation
/// offset vector.
/// </summary>
/// <param name="data"></param>
public void Enqueue( object data )
public void Enqueue( string uid, XYZ offset )
{
_queue.Enqueue( data );
_queue.Enqueue(
new Tuple<string, XYZ>(
uid, offset ) );
}
}
}
5 changes: 3 additions & 2 deletions Roomedit3dApp/Properties/AssemblyInfo.cs
Expand Up @@ -41,6 +41,7 @@
// 2016-05-19 2017.0.0.2 initial experimental socket and removed architecture mismatch warning
// 2016-05-19 2017.0.0.2 Roomedit3dSocketTest works, receiving messages from roomedit3d web server
// 2016-05-26 2017.0.0.3 Roomedit3dApp socket connection works, receiving messages from roomedit3d web server
// 2016-05-26 2017.0.0.4 Roomedit3dApp transformation works, updating BIM from viewer live
//
[assembly: AssemblyVersion( "2017.0.0.3" )]
[assembly: AssemblyFileVersion( "2017.0.0.3" )]
[assembly: AssemblyVersion( "2017.0.0.4" )]
[assembly: AssemblyFileVersion( "2017.0.0.4" )]
20 changes: 20 additions & 0 deletions Roomedit3dApp/Util.cs
Expand Up @@ -22,6 +22,26 @@ public static string PluralSuffix( int n )
return 1 == n ? "" : "s";
}

/// <summary>
/// Format a real number and return
/// its string representation.
/// </summary>
public static string RealString( double a )
{
return a.ToString( "0.##" );
}

/// <summary>
/// Format a point or vector and return
/// its string representation.
/// </summary>
public static string PointString( XYZ p )
{
return string.Format( "({0},{1},{2})",
RealString( p.X ), RealString( p.Y ),
RealString( p.Z ) );
}

/// <summary>
/// Display a short big message.
/// </summary>
Expand Down
4 changes: 1 addition & 3 deletions Roomedit3dSocketTest/Program.cs
Expand Up @@ -21,9 +21,7 @@ static void Main( string[] args )
Socket socket = IO.Socket( _url, options );

socket.On( Socket.EVENT_CONNECT, () =>
{
Console.WriteLine( "Connected" );
} );
Console.WriteLine( "Connected" ) );

socket.On( "transform", (data) =>
{
Expand Down

0 comments on commit e8b272f

Please sign in to comment.