mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-19 02:54:36 +00:00
fixed bug in NameDisambiguator, made label name checking more coherent between project loading / mesh loading / mesh creation
TO BE TESTED
This commit is contained in:
parent
ff0686e2ac
commit
ecfeaee1d7
@ -140,24 +140,42 @@ void MeshDocument::setCurrentRaster( int i)
|
||||
template <class LayerElement>
|
||||
QString NameDisambiguator(QList<LayerElement*> &elemList, QString meshLabel )
|
||||
{
|
||||
QFileInfo info(meshLabel);
|
||||
QString newName=info.fileName();
|
||||
QString newName=meshLabel;
|
||||
typename QList<LayerElement*>::iterator mmi;
|
||||
|
||||
for(mmi=elemList.begin(); mmi!=elemList.end(); ++mmi)
|
||||
{
|
||||
if((*mmi)->label() == newName)
|
||||
if((*mmi)->label() == newName) // if duplicated name found
|
||||
{
|
||||
QFileInfo fi((*mmi)->label());
|
||||
QString baseName = fi.baseName(); // all characters in the file up to the first '.' Eg "/tmp/archive.tar.gz" -> "archive"
|
||||
int lastNum = baseName.right(1).toInt();
|
||||
if( baseName.right(2).toInt() >= 10)
|
||||
lastNum = baseName.right(2).toInt();
|
||||
if(lastNum)
|
||||
newName = baseName.left(baseName.length()-(lastNum<10?1:2))+QString::number(lastNum+1);
|
||||
QString suffix = fi.suffix();
|
||||
bool ok;
|
||||
|
||||
// if name ends with a number between parenthesis (XXX),
|
||||
// it was himself a duplicated name, and we need to
|
||||
// just increase the number between parenthesis
|
||||
int numDisamb;
|
||||
int startDisamb;
|
||||
int endDisamb;
|
||||
|
||||
startDisamb = baseName.lastIndexOf("(");
|
||||
endDisamb = baseName.lastIndexOf(")");
|
||||
if((startDisamb!=-1)&&(endDisamb!=-1))
|
||||
numDisamb = (baseName.mid((startDisamb+1),(endDisamb-startDisamb-1))).toInt(&ok);
|
||||
else
|
||||
newName = baseName+"_1";
|
||||
if (info.suffix() != QString(""))
|
||||
newName = newName + "." + info.suffix();
|
||||
numDisamb = 0;
|
||||
|
||||
if(startDisamb!=-1)
|
||||
newName = baseName.left(startDisamb)+ "(" + QString::number(numDisamb+1) + ")";
|
||||
else
|
||||
newName = baseName + "(" + QString::number(numDisamb+1) + ")";
|
||||
|
||||
if (suffix != QString(""))
|
||||
newName = newName + "." + suffix;
|
||||
|
||||
// now recurse to see if the new name is free
|
||||
newName = NameDisambiguator(elemList, newName);
|
||||
}
|
||||
}
|
||||
return newName;
|
||||
|
||||
@ -2065,7 +2065,8 @@ bool MainWindow::importMesh(QString fileName)
|
||||
}
|
||||
int mask = 0;
|
||||
//MeshModel *mm= new MeshModel(gla->meshDoc);
|
||||
MeshModel *mm=meshDoc()->addNewMesh(qPrintable(fileName),"");
|
||||
QFileInfo info(fileName);
|
||||
MeshModel *mm=meshDoc()->addNewMesh(qPrintable(fileName),info.fileName());
|
||||
qb->show();
|
||||
QTime t;t.start();
|
||||
bool open = loadMesh(fileName,pCurrentIOPlugin,mm,mask,&prePar);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user