This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from CBenghi/master
Initial implementation of BCFier plugin for XbimXplorer.
- Loading branch information
Showing
19 changed files
with
1,001 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<Window | ||
x:Class="Bcfier.XbimXplorer.AddViewXbim" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:ctr="clr-namespace:Bcfier.UserControls;assembly=Bcfier" | ||
Title="Add View" | ||
Icon="Assets/icon.ico" | ||
SizeToContent="WidthAndHeight"> | ||
<Grid> | ||
<ctr:AddView | ||
x:Name="AddViewControl" | ||
HorizontalAlignment="Stretch" | ||
HorizontalContentAlignment="Stretch" /> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System; | ||
using System.IO; | ||
using System.Windows; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Imaging; | ||
using Bcfier.Bcf.Bcf2; | ||
using log4net; | ||
using Xbim.Presentation; | ||
|
||
namespace Bcfier.XbimXplorer | ||
{ | ||
/// <summary> | ||
/// Interaction logic for AddViewRevit.xaml | ||
/// </summary> | ||
public partial class AddViewXbim | ||
{ | ||
private static readonly ILog Log = LogManager.GetLogger(nameof(AddViewXbim)); | ||
private readonly DrawingControl3D _control; | ||
|
||
public AddViewXbim(Markup issue, string bcfTempFolder, DrawingControl3D control) | ||
{ | ||
try | ||
{ | ||
InitializeComponent(); | ||
AddViewControl.Issue = issue; | ||
AddViewControl.TempFolder = bcfTempFolder; | ||
_control = control; | ||
|
||
AddViewControl.TextBlockInfo.Text = | ||
"3D/2D information of the current view will be included in the viewpoint"; | ||
|
||
GetRevitSnapshot(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show("Error!", "exception: " + ex); | ||
} | ||
} | ||
|
||
private static RenderTargetBitmap Get3DVisual(FrameworkElement element) | ||
{ | ||
var width = element.ActualWidth; | ||
|
||
var height = element.ActualHeight; | ||
var bmpCopied = new RenderTargetBitmap((int) Math.Round(width), (int) Math.Round(height), 96, 96, | ||
PixelFormats.Default); | ||
var dv = new DrawingVisual(); | ||
using (var dc = dv.RenderOpen()) | ||
{ | ||
var vb = new VisualBrush(element); | ||
dc.DrawRectangle(vb, null, new Rect(new System.Windows.Point(), new Size(width, height))); | ||
} | ||
bmpCopied.Render(dv); | ||
return bmpCopied; | ||
} | ||
|
||
private bool SaveControlPng(FrameworkElement control, string outFile) | ||
{ | ||
try | ||
{ | ||
var renderTargetBitmap = Get3DVisual(control); | ||
|
||
var bitmapEncoder = new PngBitmapEncoder(); | ||
bitmapEncoder.Frames.Add(BitmapFrame.Create(renderTargetBitmap)); | ||
|
||
using (var stream = File.Create(outFile)) | ||
{ | ||
bitmapEncoder.Save(stream); | ||
stream.Seek(0, SeekOrigin.Begin); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Error("Counld not create screenshot from model.", ex); | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private void GetRevitSnapshot() | ||
{ | ||
try | ||
{ | ||
var tempImg = Path.Combine(Path.GetTempPath(), "BCFier", Path.GetTempFileName() + ".png"); | ||
|
||
var success = SaveControlPng(_control, tempImg); | ||
if (!success) | ||
{ | ||
return; | ||
} | ||
AddViewControl.AddViewpoint(tempImg); | ||
File.Delete(tempImg); | ||
} | ||
catch (Exception ex) | ||
{ | ||
MessageBox.Show("Error!", "exception: " + ex); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Application x:Class="Bcfier.XbimXplorer.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
|
||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Bcfier.XbimXplorer | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App | ||
{ | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.