Skip to content
This repository has been archived by the owner on May 8, 2019. It is now read-only.

Commit

Permalink
Merge pull request #17 from speckleworks/Luis/CefSharpWPF
Browse files Browse the repository at this point in the history
Luis/cef sharp wpf
  • Loading branch information
fraguada authored Mar 10, 2018
2 parents 662015c + 33cee2d commit 478c3c5
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 97 deletions.
66 changes: 3 additions & 63 deletions SpeckleRevitPlugin/Entry/ExtCmd.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
#region Namespaces
using System;
using System.Collections.Generic;
using System.Diagnostics;

using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;

//using CefSharp;
using System.IO;
using System.Reflection;
//using CefSharp.WinForms;
using System.Windows.Forms;
#endregion

namespace SpeckleRevitPlugin
{
[Transaction(TransactionMode.Manual)]
public class ExtCmd : IExternalCommand
{
// public static ChromiumWebBrowser Browser;
//public static ChromiumWebBrowser Browser;

public Result Execute(
ExternalCommandData commandData,
Expand All @@ -35,60 +25,10 @@ public Result Execute(
// SHOW DOCKABLE WINDOW
DockablePaneId m_dpID = GlobalHelper.MainDockablePaneId;
DockablePane m_dp = commandData.Application.GetDockablePane(m_dpID);
var path = Directory.GetParent(Assembly.GetExecutingAssembly().Location);
Debug.WriteLine(path, "SPK");

var indexPath = string.Format(@"{0}\app\index.html", path);

if (!File.Exists(indexPath))
Debug.WriteLine("Speckle for Revit: Error. The html file doesn't exists : {0}", "SPK");

indexPath = indexPath.Replace("\\", "/");
AppMain.MainDock.webBrowser.Source = new Uri( indexPath);
m_dp.Show();


// initialise one browser instance
//InitializeChromium();

//var form = new SpeckleRevitForm();

//form.Controls.Add(Browser);
//form.Show();
m_dp.Show();

return Result.Succeeded;
}


public void InitializeChromium()
{

#if DEBUG

// Browser = new ChromiumWebBrowser(@"http://localhost:9090/");

#else
var path = Directory.GetParent(Assembly.GetExecutingAssembly().Location);
Debug.WriteLine(path, "SPK");

var indexPath = string.Format(@"{0}\app\index.html", path);

if (!File.Exists(indexPath))
Debug.WriteLine("Speckle for Revit: Error. The html file doesn't exists : {0}", "SPK");

indexPath = indexPath.Replace("\\", "/");

Browser = new ChromiumWebBrowser(indexPath);
#endif
// Allow the use of local resources in the browser
//Browser.BrowserSettings = new BrowserSettings
//{
// FileAccessFromFileUrls = CefState.Enabled,
// UniversalAccessFromFileUrls = CefState.Enabled
//};


//Browser.Dock = DockStyle.Fill;
}
}
}
}
33 changes: 12 additions & 21 deletions SpeckleRevitPlugin/SpeckleRevitPlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,26 @@
<Compile Include="UI\form_MainDock.xaml.cs">
<DependentUpon>form_MainDock.xaml</DependentUpon>
</Compile>
<Compile Include="UI\SpeckleRevitForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UI\SpeckleRevitForm.designer.cs">
<DependentUpon>SpeckleRevitForm.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Content Include="Resources\Template_16.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="Resources\Template_16.png" />
<Content Include="SpeckleRevitPlugin.addin">
<SubType>Designer</SubType>
</Content>
<EmbeddedResource Include="Resources\Template_32.png" />
<EmbeddedResource Include="Properties\Resources.resx" />
<EmbeddedResource Include="UI\SpeckleRevitForm.resx">
<DependentUpon>SpeckleRevitForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup />
<ItemGroup>
<PackageReference Include="CefSharp.Wpf">
<Version>63.0.2</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>11.0.1</Version>
</PackageReference>
<PackageReference Include="Revit-2018.1-x64.Base">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Page Include="UI\form_Main.xaml">
<SubType>Designer</SubType>
Expand All @@ -93,14 +92,6 @@
<SubType>Designer</SubType>
</Page>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json">
<Version>11.0.1</Version>
</PackageReference>
<PackageReference Include="Revit-2018.1-x64.Base" IncludeAssets="build;compile">
<Version>1.0.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. -->
Expand Down
11 changes: 1 addition & 10 deletions SpeckleRevitPlugin/UI/SpeckleRevitForm.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms;

namespace SpeckleRevitPlugin
{
Expand Down
1 change: 1 addition & 0 deletions SpeckleRevitPlugin/UI/SpeckleRevitForm.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions SpeckleRevitPlugin/UI/form_MainDock.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf"
mc:Ignorable="d"
Background="White" >
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<cefSharp:ChromiumWebBrowser Name="Browser" Grid.Row="0" Address="http://google.com" />
<!--<ScrollViewer VerticalScrollBarVisibility="Auto">
<WebBrowser Name="webBrowser" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"></WebBrowser>
</ScrollViewer>
</ScrollViewer>-->
</Grid>
</Page>
62 changes: 61 additions & 1 deletion SpeckleRevitPlugin/UI/form_MainDock.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -17,8 +18,11 @@
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Events;

using CefSharp;
using Visibility = System.Windows.Visibility;
using Path = System.IO.Path;
using System.IO;
using System.Diagnostics;
#endregion

namespace SpeckleRevitPlugin
Expand All @@ -36,10 +40,66 @@ public partial class form_MainDock : Page, IDockablePaneProvider
/// </summary>
public form_MainDock()
{
InitializeCef();
InitializeComponent();
InitializeChromium();
_extEvent = ExternalEvent.Create(_handler);
}


void InitializeCef()
{

Cef.EnableHighDPISupport();

var assemblyLocation = Assembly.GetExecutingAssembly().Location;
var assemblyPath = Path.GetDirectoryName(assemblyLocation);
var pathSubprocess = Path.Combine(assemblyPath, "CefSharp.BrowserSubprocess.exe");
CefSharpSettings.LegacyJavascriptBindingEnabled = true;
var settings = new CefSettings
{
LogSeverity = LogSeverity.Verbose,
LogFile = "ceflog.txt",
BrowserSubprocessPath = pathSubprocess
};

// Initialize cef with the provided settings

Cef.Initialize(settings);

}
public void InitializeChromium()
{

#if DEBUG

Browser.Address = @"http://localhost:9090/";

#else
var path = Directory.GetParent(Assembly.GetExecutingAssembly().Location);
Debug.WriteLine(path, "SPK");

var indexPath = string.Format(@"{0}\app\index.html", path);

if (!File.Exists(indexPath))
Debug.WriteLine("Speckle for Revit: Error. The html file doesn't exists : {0}", "SPK");

indexPath = indexPath.Replace("\\", "/");

Browser.Address = indexPath;
#endif
//Allow the use of local resources in the browser
Browser.BrowserSettings = new BrowserSettings
{
FileAccessFromFileUrls = CefState.Enabled,
UniversalAccessFromFileUrls = CefState.Enabled
};


//Browser.Dock = DockStyle.Fill;
}


#region Form Events
/// <summary>
/// Safely raise an external command transaction event (for modeless)
Expand Down

0 comments on commit 478c3c5

Please sign in to comment.