using System;
using System.Collections.Generic;
using System.Windows.Forms;
using devDept.Eyeshot;
using devDept.Eyeshot.Translators;
using devDept.Eyeshot.Entities;
using devDept.Geometry;
namespace conversion
{
public partial class MainForm : Form
{
private IList<devDept.WorkUnit> workUnits;
public MainForm()
{
workUnits = new List<devDept.WorkUnit>();
InitializeComponent();
design1.ProgressChanged += design1_ProgressChanged;
design1.WorkCancelled += design1_WorkCancelled;
design1.WorkCompleted += design1_WorkCompleted;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
design1.ProgressBar.Visible = false;
}
private bool startWork()
{
bool aHasWorks = workUnits.Count > 0;
if (aHasWorks)
{
design1.StartWork(workUnits[0]);
}
return aHasWorks;
}
private bool startWork(devDept.WorkUnit theWorker)
{
bool aHasWorks = workUnits.Count > 0;
workUnits.Add(theWorker);
if (!aHasWorks)
startWork();
return true;
}
void design1_ProgressChanged(object theSender, devDept.WorkUnit.ProgressChangedEventArgs theEventArgs)
{
labelProgressBar.Text = design1.ProgressBar.Text;
progressBar1.Value = theEventArgs.Progress;
}
private void design1_WorkCancelled(object theSender, EventArgs theEventArgs)
{
Text = TitleName(Text);
labelProgressBar.Text = "Canceled";
progressBar1.Value = 0;
}
void design1_WorkCompleted(object theSender, devDept.WorkCompletedEventArgs theEventArgs)
{
workUnits.Remove(theEventArgs.WorkUnit);
if (!startWork())
{
ReadFileAsync aReadAsync = theEventArgs.WorkUnit as ReadFileAsync;
if (aReadAsync != null)
{
aReadAsync.AddTo(design1);
foreach (Material aMaterial in design1.Materials)
{
aMaterial.LoadTexture(design1.RenderContext);
}
}
design1.ZoomFit();
if (design1.Entities.Count > 0)
{
labelProgressBar.Text = "Completed";
labelProgressBar.ForeColor = System.Drawing.Color.Black;
}
else
{
Text = TitleName(Text);
labelProgressBar.Text = "Failed";
labelProgressBar.ForeColor = System.Drawing.Color.Red;
}
}
}
private void buttonCancel_Click(object theSender, EventArgs theEventArgs)
{
design1.CancelWork();
}
private void buttonBRep_Click(object theSender, EventArgs theEventArgs)
{
}
private void buttonPoly_Click(object theSender, EventArgs theEventArgs)
{
}
{
OpenFileDialog aDialog = new OpenFileDialog();
aDialog.CheckFileExists = true;
aDialog.Multiselect = false;
aDialog.Filter = ImportFilter();
if (aDialog.ShowDialog() != DialogResult.OK)
{
return;
}
string aFilePath = aDialog.FileName;
design1.Clear();
startWork(new ReadFileCadEx(aFilePath, theMask));
Text = TitleName(Text) + " - " + aFilePath;
}
private string TitleName(string theFormTitle)
{
return theFormTitle.Split('-')[0].Trim(' ');
}
private string ImportFilter()
{
return "All files (*.*)|*.*";
}
public class ReadFileCadEx : ReadFileAsync
{
: base(fileName)
{
myMask = theMask;
}
public override supportedLinearUnitsType SupportedLinearUnitsType
{
get
{
return supportedLinearUnitsType.Millimeters;
}
}
public override void DoWork(System.ComponentModel.BackgroundWorker theWorker, System.ComponentModel.DoWorkEventArgs theDoWorkEventArgs)
{
string aFileName = FileName;
BlockReference aRoot = Process(aFileName, myMask);
if (aRoot != null)
{
Entities = new Entity[] { aRoot };
}
UpdateProgress(1, 1, "Convert the model", theWorker);
}
public override void AddTo(DesignDocument theDoc, RegenOptions theRegenOptions = null)
{
if (myFactory != null && theDoc != null && Entities.Length > 0)
{
myFactory.AddTo(theDoc);
theDoc.Entities.AddRange(Entities);
}
}
private BlockReference Process(string theFileName,
Eyeshot_EntityMapping theMap = null)
{
{
Console.WriteLine("Failed to open and convert the file");
return null;
}
myFactory.Parameters().SetRepSelector(theMask);
return myFactory.Create(aModel, theMap);
}
}
}
}
The Base_Settings class defines a container of global CAD Exchanger parameters.
Definition: Base_Settings.hxx:33
static const std::shared_ptr< Base_Settings > & Default()
Returns global settings object.
Definition: Base_Settings.cxx:541
Id
Describes values used to identify CAD Exchanger settings.
Definition: Base_Settings.hxx:36
Defines a Unicode (UTF-16) string wrapping a standard string.
Definition: Base_UTF16String.hxx:34
Creates EyeShot document data from ModelData_Model.
Definition: Eyeshot_EntityFactory.cs:31
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Reads any format that CAD Exchanger can import.
Definition: ModelData_ModelReader.hxx:33
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
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22
ModelData_RepresentationMask
Defines a mask to filter part representations.
Definition: ModelData_RepresentationMask.hxx:25