Skip to content

Commit e474914

Browse files
committed
Better Unicode handling in the 3ds max importer
Don't initiate progress handler until valid file is opened
1 parent 4f26622 commit e474914

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/ifcmax/IfcMax.cpp

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
* *
1818
********************************************************************************/
1919

20-
#include "Max.h"
21-
#include "stdmat.h"
22-
#include "istdplug.h"
20+
#include <Max.h>
21+
#include <stdmat.h>
22+
#include <istdplug.h>
2323

2424
#include "../ifcmax/IfcMax.h"
2525
#include "../ifcmax/MaxMaterials.h"
@@ -103,28 +103,47 @@ DWORD WINAPI fn(LPVOID arg) { return 0; }
103103

104104
int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc, BOOL suppressPrompts) {
105105

106-
itfc->ProgressStart("Importing file...", TRUE, fn, NULL);
107-
108106
IfcGeomObjects::Settings(IfcGeomObjects::USE_WORLD_COORDS,false);
109107
IfcGeomObjects::Settings(IfcGeomObjects::WELD_VERTICES,true);
110108
IfcGeomObjects::Settings(IfcGeomObjects::SEW_SHELLS,true);
111109

112-
if ( ! IfcGeomObjects::Init((char*)name,0,0) ) return false;
110+
#ifdef _UNICODE
111+
int fn_buffer_size = WideCharToMultiByte(CP_UTF8, 0, name, -1, 0, 0, 0, 0);
112+
char* fn_mb = new char[fn_buffer_size];
113+
WideCharToMultiByte(CP_UTF8, 0, name, -1, fn_mb, fn_buffer_size, 0, 0);
114+
#else
115+
const char* fn_mb = name;
116+
#endif
117+
118+
if ( ! IfcGeomObjects::Init(fn_mb,0,0) ) return false;
119+
120+
itfc->ProgressStart(_T("Importing file..."), TRUE, fn, NULL);
113121

114122
//std::map<int, TriObject*> dict;
115123
MtlBaseLib* mats = itfc->GetSceneMtls();
116124
int slot = mats->Count();
117125

118126
do{
119127

120-
const IfcGeomObjects::IfcGeomObject* o = IfcGeomObjects::Get();
128+
const IfcGeomObjects::IfcGeomObject* o = IfcGeomObjects::Get();
121129

130+
#if MAX_RELEASE > MAX_RELEASE_R14
131+
TSTR o_type = TSTR::FromCStr(o->type.c_str());
132+
TSTR o_guid = TSTR::FromCStr(o->guid.c_str());
133+
#elif defined(_UNICODE)
134+
TSTR o_type = WStr(o->type.c_str());
135+
TSTR o_guid = WStr(o->guid.c_str());
136+
#else
137+
TSTR o_type = CStr(o->type.c_str());
138+
TSTR o_guid = CStr(o->guid.c_str());
139+
#endif
140+
122141
Mtl *m;
123-
const int matIndex = mats->FindMtlByName(MSTR(o->type.c_str()));
142+
const int matIndex = mats->FindMtlByName(o_type);
124143
if ( matIndex == -1 ) {
125144
StdMat2* stdm = GetMaterial(o->type);
126145
m = stdm;
127-
m->SetName(o->type.c_str());
146+
m->SetName(o_type);
128147
mats->Add(m);
129148
itfc->PutMtlToMtlEditor(m,slot++);
130149
} else {
@@ -169,13 +188,13 @@ int IFCImp::DoImport(const TCHAR *name, ImpInterface *impitfc, Interface *itfc,
169188

170189
ImpNode* node = impitfc->CreateNode();
171190
node->Reference(tri);
172-
node->SetName(o->guid.c_str());
191+
node->SetName(o_guid);
173192
node->GetINode()->SetMtl(m);
174193
node->SetTransform(0,Matrix3 ( Point3(o->matrix[0],o->matrix[1],o->matrix[2]),Point3(o->matrix[3],o->matrix[4],o->matrix[5]),
175194
Point3(o->matrix[6],o->matrix[7],o->matrix[8]),Point3(o->matrix[9],o->matrix[10],o->matrix[11]) ));
176195
impitfc->AddNodeToScene(node);
177196

178-
itfc->ProgressUpdate(IfcGeomObjects::Progress(),true,"");
197+
itfc->ProgressUpdate(IfcGeomObjects::Progress(),true,_T(""));
179198

180199
} while ( IfcGeomObjects::Next() );
181200

0 commit comments

Comments
 (0)