//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;
}