//wrapper of pure C++ classes to ref classes
#include <NCollection_Haft.h>
+#include <vcclr.h>
+
// list of required OCCT libraries
#pragma comment(lib, "TKernel.lib")
#pragma comment(lib, "TKMath.lib")
#pragma comment(lib, "TKStl.lib")
#pragma comment(lib, "TKVrml.lib")
+//! Auxiliary tool for converting C# string into UTF-8 string.
+static TCollection_AsciiString toAsciiString (String^ theString)
+{
+ if (theString == nullptr)
+ {
+ return TCollection_AsciiString();
+ }
+
+ pin_ptr<const wchar_t> aPinChars = PtrToStringChars (theString);
+ const wchar_t* aWCharPtr = aPinChars;
+ if (aWCharPtr == NULL
+ || *aWCharPtr == L'\0')
+ {
+ return TCollection_AsciiString();
+ }
+ return TCollection_AsciiString (aWCharPtr);
+}
+
/// <summary>
/// Proxy class encapsulating calls to OCCT C++ classes within
/// C++/CLI class visible from .Net (CSharp)
/// Make dump of current view to file
/// </summary>
/// <param name="theFileName">Name of dump file</param>
- bool Dump(char *theFileName)
+ bool Dump(const TCollection_AsciiString& theFileName)
{
if (myView().IsNull())
{
return false;
}
myView()->Redraw();
- return myView()->Dump(theFileName) != Standard_False;
+ return myView()->Dump(theFileName.ToCString()) != Standard_False;
}
/// <summary>
/// <param name="theFileName">Name of import file</param>
bool ImportBrep(System::String^ theFileName)
{
- bool isResult = false;
- int aLength = theFileName->Length;
- char* aFilename = new char[aLength+1];
- for(int i = 0; i<aLength; i++)
- {
- aFilename[i] = (char)theFileName->ToCharArray()[i];
- }
- aFilename[aLength] = '\0';
- isResult = ImportBrep(aFilename);
- return isResult;
+ return ImportBrep (toAsciiString (theFileName));
}
/// <summary>
///Import BRep file
/// </summary>
/// <param name="theFileName">Name of import file</param>
- bool ImportBrep(char* theFileName)
+ bool ImportBrep (const TCollection_AsciiString& theFileName)
{
- Standard_CString aFileName = (Standard_CString) theFileName;
TopoDS_Shape aShape;
BRep_Builder aBuilder;
- Standard_Boolean isResult = BRepTools::Read(aShape,aFileName,aBuilder);
+ Standard_Boolean isResult = BRepTools::Read(aShape,theFileName.ToCString(),aBuilder);
if (!isResult)
{
return false;
///Import Step file
/// </summary>
/// <param name="theFileName">Name of import file</param>
- bool ImportStep(char* theFileName)
+ bool ImportStep(const TCollection_AsciiString& theFileName)
{
- Standard_CString aFileName = (Standard_CString) theFileName;
STEPControl_Reader aReader;
- IFSelect_ReturnStatus aStatus = aReader.ReadFile(aFileName);
+ IFSelect_ReturnStatus aStatus = aReader.ReadFile(theFileName.ToCString());
if ( aStatus == IFSelect_RetDone )
{
bool isFailsonly = false;
///Import Iges file
/// </summary>
/// <param name="theFileName">Name of import file</param>
- bool ImportIges(char* theFileName)
+ bool ImportIges(const TCollection_AsciiString& theFileName)
{
- Standard_CString aFileName = (Standard_CString) theFileName;
IGESControl_Reader aReader;
- int aStatus = aReader.ReadFile( aFileName );
+ int aStatus = aReader.ReadFile( theFileName.ToCString() );
if ( aStatus == IFSelect_RetDone )
{
///Export BRep file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportBRep(char* theFileName)
+ bool ExportBRep(const TCollection_AsciiString& theFileName)
{
myAISContext()->InitSelected();
if (!myAISContext()->MoreSelected())
Handle(AIS_InteractiveObject) anIO = myAISContext()->SelectedInteractive();
Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast(anIO);
- return BRepTools::Write (anIS->Shape(), (Standard_CString)theFileName) != Standard_False;
+ return BRepTools::Write (anIS->Shape(), theFileName.ToCString()) != Standard_False;
}
/// <summary>
///Export Step file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportStep(char* theFileName)
+ bool ExportStep(const TCollection_AsciiString& theFileName)
{
STEPControl_StepModelType aType = STEPControl_AsIs;
IFSelect_ReturnStatus aStatus;
}
}
- aStatus = aWriter.Write( (Standard_CString)theFileName );
+ aStatus = aWriter.Write(theFileName.ToCString());
if ( aStatus != IFSelect_RetDone )
{
return false;
///Export Iges file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportIges(char* theFileName)
+ bool ExportIges(const TCollection_AsciiString& theFileName)
{
IGESControl_Controller::Init();
IGESControl_Writer aWriter( Interface_Static::CVal( "XSTEP.iges.unit" ),
}
aWriter.ComputeModel();
- return aWriter.Write( (Standard_CString)theFileName) != Standard_False;
+ return aWriter.Write(theFileName.ToCString()) != Standard_False;
}
/// <summary>
///Export Vrml file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportVrml(char* theFileName)
+ bool ExportVrml(const TCollection_AsciiString& theFileName)
{
TopoDS_Compound aRes;
BRep_Builder aBuilder;
}
VrmlAPI_Writer aWriter;
- aWriter.Write( aRes, (Standard_CString)theFileName );
+ aWriter.Write(aRes, theFileName.ToCString());
return true;
}
///Export Stl file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportStl(char* theFileName)
+ bool ExportStl(const TCollection_AsciiString& theFileName)
{
TopoDS_Compound aComp;
BRep_Builder aBuilder;
}
StlAPI_Writer aWriter;
- aWriter.Write( aComp, (Standard_CString)theFileName );
+ aWriter.Write(aComp, theFileName.ToCString());
return true;
}
bool TranslateModel(System::String^ theFileName, int theFormat, bool theIsImport)
{
bool isResult;
- int aLength = theFileName->Length;
- char* aFilename = new char[aLength+1];
- for(int i = 0; i<aLength; i++)
- {
- aFilename[i] = (char)theFileName->ToCharArray()[i];
- }
- aFilename[aLength] = '\0';
+ const TCollection_AsciiString aFilename = toAsciiString (theFileName);
if (theIsImport)
{
switch(theFormat)
//wrapper of pure C++ classes to ref classes
#include <NCollection_Haft.h>
+#include <vcclr.h>
+
// list of required OCCT libraries
#pragma comment(lib, "TKernel.lib")
#pragma comment(lib, "TKMath.lib")
#pragma comment(lib, "D3D9.lib")
+//! Auxiliary tool for converting C# string into UTF-8 string.
+static TCollection_AsciiString toAsciiString (String^ theString)
+{
+ if (theString == nullptr)
+ {
+ return TCollection_AsciiString();
+ }
+
+ pin_ptr<const wchar_t> aPinChars = PtrToStringChars (theString);
+ const wchar_t* aWCharPtr = aPinChars;
+ if (aWCharPtr == NULL
+ || *aWCharPtr == L'\0')
+ {
+ return TCollection_AsciiString();
+ }
+ return TCollection_AsciiString (aWCharPtr);
+}
+
/// <summary>
/// Proxy class encapsulating calls to OCCT C++ classes within
/// C++/CLI class visible from .Net (CSharp)
/// Make dump of current view to file
/// </summary>
/// <param name="theFileName">Name of dump file</param>
- bool Dump (const char* theFileName)
+ bool Dump (const TCollection_AsciiString& theFileName)
{
if (myView().IsNull())
{
return false;
}
myView()->Redraw();
- return myView()->Dump (theFileName) != Standard_False;
+ return myView()->Dump (theFileName.ToCString()) != Standard_False;
}
/// <summary>
/// <param name="theFileName">Name of import file</param>
bool ImportBrep (System::String^ theFileName)
{
- bool isResult = false;
- int aLength = theFileName->Length;
- char* aFilename = new char[aLength + 1];
- for(int i = 0; i < aLength; ++i)
- {
- aFilename[i] = (char )theFileName->ToCharArray()[i];
- }
- aFilename[aLength] = '\0';
- isResult = ImportBrep (aFilename);
- delete[] aFilename;
- return isResult;
+ return ImportBrep (toAsciiString (theFileName));
}
/// <summary>
///Import BRep file
/// </summary>
/// <param name="theFileName">Name of import file</param>
- bool ImportBrep (char* theFileName)
+ bool ImportBrep (const TCollection_AsciiString& theFileName)
{
TopoDS_Shape aShape;
BRep_Builder aBuilder;
- if (!BRepTools::Read (aShape, theFileName, aBuilder))
+ if (!BRepTools::Read (aShape, theFileName.ToCString(), aBuilder))
{
return false;
}
///Import Step file
/// </summary>
/// <param name="theFileName">Name of import file</param>
- bool ImportStep (char* theFileName)
+ bool ImportStep (const TCollection_AsciiString& theFileName)
{
STEPControl_Reader aReader;
- if (aReader.ReadFile (theFileName) != IFSelect_RetDone)
+ if (aReader.ReadFile (theFileName.ToCString()) != IFSelect_RetDone)
{
return false;
}
///Import Iges file
/// </summary>
/// <param name="theFileName">Name of import file</param>
- bool ImportIges (char* theFileName)
+ bool ImportIges (const TCollection_AsciiString& theFileName)
{
IGESControl_Reader aReader;
- if (aReader.ReadFile (theFileName) != IFSelect_RetDone)
+ if (aReader.ReadFile (theFileName.ToCString()) != IFSelect_RetDone)
{
return false;
}
///Export BRep file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportBRep (char* theFileName)
+ bool ExportBRep (const TCollection_AsciiString& theFileName)
{
myAISContext()->InitSelected();
if (!myAISContext()->MoreSelected())
Handle(AIS_Shape) anIS = Handle(AIS_Shape)::DownCast (myAISContext()->SelectedInteractive());
return !anIS.IsNull()
- && BRepTools::Write (anIS->Shape(), theFileName);
+ && BRepTools::Write (anIS->Shape(), theFileName.ToCString());
}
/// <summary>
///Export Step file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportStep (char* theFileName)
+ bool ExportStep (const TCollection_AsciiString& theFileName)
{
STEPControl_StepModelType aType = STEPControl_AsIs;
STEPControl_Writer aWriter;
return false;
}
}
- return aWriter.Write (theFileName) == IFSelect_RetDone;
+ return aWriter.Write (theFileName.ToCString()) == IFSelect_RetDone;
}
/// <summary>
///Export Iges file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportIges (char* theFileName)
+ bool ExportIges (const TCollection_AsciiString& theFileName)
{
IGESControl_Controller::Init();
IGESControl_Writer aWriter (Interface_Static::CVal ("XSTEP.iges.unit"),
}
aWriter.ComputeModel();
- return aWriter.Write (theFileName) != Standard_False;
+ return aWriter.Write (theFileName.ToCString()) != Standard_False;
}
/// <summary>
///Export Vrml file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportVrml (char* theFileName)
+ bool ExportVrml (const TCollection_AsciiString& theFileName)
{
TopoDS_Compound aRes;
BRep_Builder aBuilder;
}
VrmlAPI_Writer aWriter;
- aWriter.Write (aRes, theFileName);
+ aWriter.Write (aRes, theFileName.ToCString());
return true;
}
///Export Stl file
/// </summary>
/// <param name="theFileName">Name of export file</param>
- bool ExportStl (char* theFileName)
+ bool ExportStl (const TCollection_AsciiString& theFileName)
{
TopoDS_Compound aComp;
BRep_Builder aBuilder;
}
StlAPI_Writer aWriter;
- aWriter.Write (aComp, theFileName);
+ aWriter.Write (aComp, theFileName.ToCString());
return true;
}
bool TranslateModel (System::String^ theFileName, int theFormat, bool theIsImport)
{
bool isResult = false;
- int aLength = theFileName->Length;
- char* aFilename = new char[aLength + 1];
- for (int aCharIter = 0; aCharIter < aLength; ++aCharIter)
- {
- aFilename[aCharIter] = (char)theFileName->ToCharArray()[aCharIter];
- }
- aFilename[aLength] = '\0';
-
+ const TCollection_AsciiString aFilename = toAsciiString (theFileName);
if (theIsImport)
{
switch (theFormat)
case 5: isResult = Dump (aFilename); break;
}
}
- delete[] aFilename;
return isResult;
}