Refer to Basic Viewer Example.
BaseViewer.xaml
<UserControl x:Class="baseviewer.BaseViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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:cadex="clr-namespace:cadex;assembly=CadExViewWPF"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition ></RowDefinition>
</Grid.RowDefinitions>
<Menu x:Name="myMenu" HorizontalAlignment="Stretch" Grid.Row="0">
<MenuItem x:Name="myFileMenuItem" Header="File">
<MenuItem Header="Import" Click="onImport"/>
<Separator />
<MenuItem Header="Quit" Click="onQuit"/>
</MenuItem>
</Menu>
<cadex:ModelPrsWPF_ViewPort x:Name="myViewport" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="1">
<TextBox x:Name="myLoadingItem" Text="Loading..." VerticalAlignment="Bottom" HorizontalAlignment="Left" FontSize="20" Visibility="Hidden"/>
</cadex:ModelPrsWPF_ViewPort>
</Grid>
</UserControl>
BaseViewer.xaml.cs
using Microsoft.Win32;
using System;
using System.Windows;
using System.Windows.Controls;
namespace baseviewer
{
public partial class BaseViewer : UserControl
{
public BaseViewer()
{
InitializeComponent();
}
public ModelPrsWPF_ViewPort Viewport
{
get { return myViewport; }
}
public bool loading
{
get { return myLoadingItem.Visibility == Visibility.Visible; }
set { myLoadingItem.Visibility = value ? Visibility.Visible : Visibility.Hidden; }
}
public BaseViewerApplication ViewerApplication
{
get { return myApp; }
set {
myApp = value;
myApp.ErrorMessage += OnErrorMessage;
myApp.LoadingChanged += OnLoadingChanged;
}
}
private void onImport(object sender, System.EventArgs e)
{
var aFilename = ShowFileDialog();
if (aFilename != string.Empty)
{
foreach (Window aWindow in Application.Current.Windows)
{
if (aWindow.IsActive)
{
aWindow.Title = "CAD Exchanger [" + aFilename + "]";
break;
}
}
myApp.Import(aFilename);
}
}
private static string ShowFileDialog()
{
OpenFileDialog anOpenFileDialog = new OpenFileDialog
{
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop),
CheckFileExists = true,
CheckPathExists = true,
Filter = "STEP Files (*.step)|*.stp",
FilterIndex = 2,
RestoreDirectory = true,
ShowReadOnly = true
};
try
{
var result = anOpenFileDialog.ShowDialog();
if (result == true & anOpenFileDialog.OpenFile() != null)
{
return anOpenFileDialog.FileName;
}
}
catch (Exception ex)
{
if (anOpenFileDialog.FileName != String.Empty)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
return string.Empty;
}
private void onQuit(object sender, RoutedEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
private void OnErrorMessage(string theMessage)
{
MessageBox.Show(theMessage);
}
private void OnLoadingChanged(bool theLoading)
{
loading = theLoading;
}
protected BaseViewerApplication myApp;
}
}
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22
BaseViewerApplication.cs
using System.ComponentModel;
namespace baseviewer
{
public class BaseViewerApplication
{
public delegate void LoadingDelegate(bool theLoading);
public delegate void ErrorMessageDelegate(string theMessage);
public event LoadingDelegate LoadingChanged;
public event ErrorMessageDelegate ErrorMessage;
public BaseViewerApplication(BaseViewer theViewer)
{
myViewer = theViewer;
myViewer.Viewport.AttachToScene(myScene);
myScene.AddRoot(myRoot);
myWorker.DoWork += OnDoWork;
myWorker.RunWorkerCompleted += OnImportCompleted;
}
public bool IsBusy
{
get { return myWorker.IsBusy; }
}
public void Import(string theFilename)
{
if (IsBusy)
{
return;
}
Clear();
myWorker.RunWorkerAsync(theFilename);
LoadingChanged (true);
}
private void OnDoWork(object sender, DoWorkEventArgs e)
{
var aFilename = e.Argument as string;
Read(aFilename);
DisplayModel();
e.Result = true;
}
private void Read(string theFilename)
{
{
return;
}
}
private void DisplayModel()
{
CreateSceneNodes();
myScene.Update();
myScene.Wait();
}
private void Clear()
{
myRoot.RemoveChildrenNodes();
myScene.Update();
myModel.Clear();
}
protected virtual void CreateSceneNodes()
{
myRoot.AddChildNode(aRoot);
}
private void OnImportCompleted(object theSender, RunWorkerCompletedEventArgs theEvent)
{
if (!theEvent.Cancelled && !(bool)theEvent.Result)
{
ErrorMessage(theEvent.Error.Message);
}
LoadingChanged(false);
myViewer.Viewport.AnimatedFitAll();
}
protected BaseViewer myViewer;
private BackgroundWorker myWorker = new BackgroundWorker();
}
}
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
void SetReaderParameters(const Base_ReaderParameters &theParameters)
Sets reader parameters.
Definition: ModelData_ModelReader.cxx:216
bool Read(const Base_UTF16String &theFilePath, ModelData_Model &theModel)
Reads the file at the specified path into the specified model.
Definition: ModelData_ModelReader.cxx:182
Provides CAD Exchanger visualization structure.
Definition: ModelPrs_Scene.hxx:39
Creates a scene nodes and its children from input data model objects.
Definition: ModelPrs_SceneNodeFactory.hxx:53
ModelPrs_SceneNode CreateGraph(const ModelData_Model &theModel, ModelData_RepresentationMask theRepresentationMask)
Creates scene graph using ModelData_Model.
Definition: ModelPrs_SceneNodeFactory.cxx:735
Represents a node in the visual scene graph.
Definition: ModelPrs_SceneNode.hxx:44
Defines parameters of the STEP_Reader.
Definition: STEP_ReaderParameters.hxx:27
ModelData_RepresentationMask
Defines a mask to filter part representations.
Definition: ModelData_RepresentationMask.hxx:25
BaseViewerWindow.xaml
<Window x:Class="baseviewer.BaseViewerWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:baseviewer="clr-namespace:baseviewer"
mc:Ignorable="d"
Title="CAD Exchanger" Height="600" Width="1000">
<baseviewer:BaseViewer x:Name="myViewer"></baseviewer:BaseViewer>
</Window>
BaseViewerWindow.xaml.cs
using System.Windows;
namespace baseviewer
{
public partial class BaseViewerWindow : Window
{
public BaseViewerWindow()
{
InitializeComponent();
myViewer.ViewerApplication = new BaseViewerApplication(myViewer);
}
}
}
App.xaml
<Application x:Class="baseviewer.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="BaseViewerWindow.xaml">
</Application>
App.xaml.cs
using System.Runtime.InteropServices;
using System.Windows;
namespace baseviewer
{
public partial class App : Application
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
public App()
{
SetDllDirectory("../../../../../../../win64/vc14.1/bin");
string aKey = LicenseKey.Value();
if (!LicenseManager.Activate(aKey))
{
MessageBox.Show("Failed to activate CAD Exchanger license.");
Shutdown();
}
}
}
}