Refer to Basic Viewer Example.
BaseViewer.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace baseviewer
{
public partial class BaseViewer : Form
{
public BaseViewer()
{
InitializeComponent();
}
public BaseViewerApplication ViewerApplication
{
get { return myApp; }
set {
myApp = value;
myApp.ErrorMessage += OnErrorMessage;
myApp.LoadingChanged += OnLoadingChanged;
}
}
public ModelPrsWinForms_ViewPort Viewport
{
get { return myViewPort; }
}
public void OnLoadingChanged(bool theLoading)
{
myLoadingItem.Visible = theLoading;
}
private void OnErrorMessage(string theMessage)
{
MessageBox.Show(theMessage);
}
private void OnQuit (object sender, EventArgs es)
{
Application.Exit();
}
private void OnImport(object sender, EventArgs es)
{
var aFilename = ShowFileDialog();
if (aFilename != string.Empty)
{
Parent.Text = "CAD Exchanger [" + aFilename + "]";
myApp.Import(aFilename);
}
}
private static string ShowFileDialog()
{
OpenFileDialog aFileDialog = 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 = aFileDialog.ShowDialog();
if (result == DialogResult.OK & aFileDialog.OpenFile() != null)
{
return aFileDialog.FileName;
}
}
catch (Exception ex)
{
if (aFileDialog.FileName != string.Empty)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
return string.Empty;
}
protected BaseViewerApplication myApp;
protected ModelPrsWinForms_ViewPort myViewPort;
}
}
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22
BaseViewer.Designer.cs
using System.Windows.Forms;
using System.Drawing;
namespace baseviewer
{
partial class BaseViewer
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.SuspendLayout();
this.TopLevel = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Size = new System.Drawing.Size(1000, 600);
myMenu = new MenuStrip();
myMenu.Dock = DockStyle.Fill;
var aFileMenu = new ToolStripMenuItem("&File");
myMenu.Items.Add(aFileMenu);
var anImportMenuItem = new ToolStripMenuItem("&Import");
anImportMenuItem.Click += OnImport;
aFileMenu.DropDownItems.Add(anImportMenuItem);
var anExitMenuItem = new ToolStripMenuItem("&Quit");
anExitMenuItem.Click += OnQuit;
aFileMenu.DropDownItems.Add(anExitMenuItem);
myViewPort = new ModelPrsWinForms_ViewPort();
myViewPort.Dock = DockStyle.Fill;
TableLayoutPanel aLayout = new TableLayoutPanel();
aLayout.RowStyles.Clear();
aLayout.ColumnStyles.Clear();
aLayout.RowCount += 2;
aLayout.ColumnCount += 1;
aLayout.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100.0F));
aLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, myMenu.Height));
aLayout.RowStyles.Add(new RowStyle(SizeType.AutoSize));
aLayout.Controls.Add(myMenu, 0, 0);
aLayout.Controls.Add(myViewPort, 0, 1);
aLayout.Dock = DockStyle.Fill;
myLoadingItem = new System.Windows.Forms.Label();
myLoadingItem.Text = "Loading...";
myLoadingItem.TextAlign = ContentAlignment.MiddleCenter;
myLoadingItem.Font = new Font(Font.Name, 13, FontStyle.Regular);
myLoadingItem.Size = new Size(myLoadingItem.PreferredWidth, myLoadingItem.PreferredHeight);
myLoadingItem.MaximumSize = myLoadingItem.Size;
myLoadingItem.BackColor = Color.White;
myLoadingItem.Visible = false;
myLoadingItem.Dock = DockStyle.Bottom;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(myLoadingItem);
this.Controls.Add(aLayout);
this.MainMenuStrip = this.myMenu;
this.Name = "BaseViewer";
this.Text = "CAD Exchanger";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.MenuStrip myMenu;
private System.Windows.Forms.Label myLoadingItem;
}
}
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.cs
using System;
using System.Windows.Forms;
namespace baseviewer
{
public partial class BaseViewerWindow : Form
{
public BaseViewerWindow()
{
InitializeComponent();
myViewer.ViewerApplication = new BaseViewerApplication(myViewer);
myViewer.Show();
}
}
}
BaseViewerWindow.Designer.cs
using System.Windows.Forms;
using System.Drawing;
namespace baseviewer
{
partial class BaseViewerWindow
{
private System.ComponentModel.IContainer components = null;
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.SuspendLayout();
this.Text = "CAD Exchanger";
this.IsMdiContainer = false;
this.ClientSize = new System.Drawing.Size(1000, 600);
myViewer = new BaseViewer();
myViewer.ClientSize = this.ClientSize;
myViewer.Dock = DockStyle.Fill;
this.Controls.Add(myViewer);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private BaseViewer myViewer;
}
}
Program.cs
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace baseviewer
{
static class Program
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern bool SetDllDirectory(string lpPathName);
[STAThread]
static void Main()
{
SetDllDirectory("../../../../../../../win64/vc14.1/bin");
string aKey = LicenseKey.Value();
if (!LicenseManager.Activate(aKey))
{
MessageBox.Show("Failed to activate CAD Exchanger license.");
Application.Exit();
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new BaseViewerWindow());
}
}
}