Replace ad-hoc implementations of Basename with calls to it.
This commit is contained in:
parent
f2f37aeed8
commit
dbf66639aa
@ -822,8 +822,7 @@ void SolveSpaceUI::ExportMeshTo(const std::string &filename) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string mtlBasename = mtlFilename.substr(mtlFilename.rfind(PATH_SEP) + 1);
|
fprintf(f, "mtllib %s\n", Basename(mtlFilename).c_str());
|
||||||
fprintf(f, "mtllib %s\n", mtlBasename.c_str());
|
|
||||||
ExportMeshAsObjTo(f, fMtl, m);
|
ExportMeshAsObjTo(f, fMtl, m);
|
||||||
|
|
||||||
fclose(fMtl);
|
fclose(fMtl);
|
||||||
@ -987,24 +986,14 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
|||||||
double largerBoundXY = max((bndh.x - bndl.x), (bndh.y - bndl.y));
|
double largerBoundXY = max((bndh.x - bndl.x), (bndh.y - bndl.y));
|
||||||
double largerBoundZ = max(largerBoundXY, (bndh.z - bndl.z + 1));
|
double largerBoundZ = max(largerBoundXY, (bndh.z - bndl.z + 1));
|
||||||
|
|
||||||
std::string extension = filename,
|
std::string basename = Basename(filename, /*stripExtension=*/true);
|
||||||
noExtFilename = filename;
|
for(size_t i = 0; i < basename.length(); i++) {
|
||||||
size_t dot = noExtFilename.rfind('.');
|
if(!(isalnum(basename[i]) || ((unsigned)basename[i] >= 0x80))) {
|
||||||
extension.erase(0, dot + 1);
|
basename[i] = '_';
|
||||||
noExtFilename.erase(dot);
|
}
|
||||||
|
|
||||||
std::string baseFilename = noExtFilename;
|
|
||||||
size_t lastSlash = baseFilename.rfind(PATH_SEP);
|
|
||||||
ssassert(lastSlash != std::string::npos, "Expected at least one path separator");
|
|
||||||
baseFilename.erase(0, lastSlash + 1);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < baseFilename.length(); i++) {
|
|
||||||
if(!isalpha(baseFilename[i]) &&
|
|
||||||
/* also permit UTF-8 */ !((unsigned char)baseFilename[i] >= 0x80))
|
|
||||||
baseFilename[i] = '_';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(extension == "html") {
|
if(FilenameHasExtension(filename, "html")) {
|
||||||
fprintf(f, htmlbegin,
|
fprintf(f, htmlbegin,
|
||||||
LoadStringFromGzip("threejs/three-r76.js.gz").c_str(),
|
LoadStringFromGzip("threejs/three-r76.js.gz").c_str(),
|
||||||
LoadStringFromGzip("threejs/hammer-2.0.8.js.gz").c_str(),
|
LoadStringFromGzip("threejs/hammer-2.0.8.js.gz").c_str(),
|
||||||
@ -1015,7 +1004,7 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
|||||||
" bounds: {\n"
|
" bounds: {\n"
|
||||||
" x: %f, y: %f, near: %f, far: %f, z: %f, edgeBias: %f\n"
|
" x: %f, y: %f, near: %f, far: %f, z: %f, edgeBias: %f\n"
|
||||||
" },\n",
|
" },\n",
|
||||||
baseFilename.c_str(),
|
basename.c_str(),
|
||||||
largerBoundXY,
|
largerBoundXY,
|
||||||
largerBoundXY,
|
largerBoundXY,
|
||||||
1.0,
|
1.0,
|
||||||
@ -1029,8 +1018,7 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
|||||||
|
|
||||||
// Directional.
|
// Directional.
|
||||||
int lightCount;
|
int lightCount;
|
||||||
for(lightCount = 0; lightCount < 2; lightCount++)
|
for(lightCount = 0; lightCount < 2; lightCount++) {
|
||||||
{
|
|
||||||
fprintf(f, " {\n"
|
fprintf(f, " {\n"
|
||||||
" intensity: %f, direction: [%f, %f, %f]\n"
|
" intensity: %f, direction: [%f, %f, %f]\n"
|
||||||
" },\n",
|
" },\n",
|
||||||
@ -1101,13 +1089,14 @@ void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
|||||||
|
|
||||||
fputs(" ]\n};\n", f);
|
fputs(" ]\n};\n", f);
|
||||||
|
|
||||||
if(extension == "html")
|
if(FilenameHasExtension(filename, "html")) {
|
||||||
fprintf(f, htmlend,
|
fprintf(f, htmlend,
|
||||||
baseFilename.c_str(),
|
basename.c_str(),
|
||||||
SS.GW.scale,
|
SS.GW.scale,
|
||||||
CO(SS.GW.offset),
|
CO(SS.GW.offset),
|
||||||
CO(SS.GW.projUp),
|
CO(SS.GW.projUp),
|
||||||
CO(SS.GW.projRight));
|
CO(SS.GW.projRight));
|
||||||
|
}
|
||||||
|
|
||||||
spl.Clear();
|
spl.Clear();
|
||||||
}
|
}
|
||||||
|
@ -228,37 +228,20 @@ void Group::MenuGroup(Command id) {
|
|||||||
|
|
||||||
case Command::GROUP_LINK: {
|
case Command::GROUP_LINK: {
|
||||||
g.type = Type::LINKED;
|
g.type = Type::LINKED;
|
||||||
|
g.meshCombine = CombineAs::ASSEMBLE;
|
||||||
if(g.linkFile.empty()) {
|
if(g.linkFile.empty()) {
|
||||||
if(!GetOpenFile(&g.linkFile, "", SlvsFileFilter)) return;
|
if(!GetOpenFile(&g.linkFile, "", SlvsFileFilter)) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Assign the default name of the group based on the name of
|
// Assign the default name of the group based on the name of
|
||||||
// the linked file.
|
// the linked file.
|
||||||
std::string groupName = g.linkFile;
|
g.name = Basename(g.linkFile, /*stripExtension=*/true);
|
||||||
size_t pos;
|
for(size_t i = 0; i < g.name.length(); i++) {
|
||||||
|
if(!(isalnum(g.name[i]) || (unsigned)g.name[i] >= 0x80)) {
|
||||||
pos = groupName.rfind(PATH_SEP);
|
|
||||||
if(pos != std::string::npos)
|
|
||||||
groupName.erase(0, pos + 1);
|
|
||||||
|
|
||||||
pos = groupName.rfind('.');
|
|
||||||
if(pos != std::string::npos)
|
|
||||||
groupName.erase(pos);
|
|
||||||
|
|
||||||
for(size_t i = 0; i < groupName.length(); i++) {
|
|
||||||
if(!(isalnum(groupName[i]) || (unsigned)groupName[i] >= 0x80)) {
|
|
||||||
// convert punctuation to dashes
|
// convert punctuation to dashes
|
||||||
groupName[i] = '-';
|
g.name[i] = '-';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(groupName.length() > 0) {
|
|
||||||
g.name = groupName;
|
|
||||||
} else {
|
|
||||||
g.name = C_("group-name", "link");
|
|
||||||
}
|
|
||||||
|
|
||||||
g.meshCombine = CombineAs::ASSEMBLE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,11 +127,7 @@ double TtfFontList::AspectRatio(const std::string &font, const std::string &str)
|
|||||||
// entities that reference us will store it.
|
// entities that reference us will store it.
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
std::string TtfFont::FontFileBaseName() const {
|
std::string TtfFont::FontFileBaseName() const {
|
||||||
std::string baseName = fontFile;
|
return Basename(fontFile);
|
||||||
size_t pos = baseName.rfind(PATH_SEP);
|
|
||||||
if(pos != std::string::npos)
|
|
||||||
return baseName.erase(0, pos + 1);
|
|
||||||
return "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user