mirror of
https://github.com/lucaspalomodevelop/meshlab.git
synced 2026-03-17 01:54:42 +00:00
Cleaned up the interface for name and paths for mesh and raster
This commit is contained in:
parent
c5697b8a79
commit
fee09e5674
@ -55,7 +55,7 @@ MeshModel *MeshDocument::getMesh(int i)
|
||||
return 0;
|
||||
}
|
||||
|
||||
MeshModel *MeshDocument::getMesh(const char *name)
|
||||
MeshModel *MeshDocument::getMesh(QString name)
|
||||
{
|
||||
foreach(MeshModel *mmp, meshList)
|
||||
{
|
||||
@ -114,29 +114,35 @@ void MeshDocument::setCurrentRaster( int i)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
MeshModel * MeshDocument::addNewMesh(const char *meshLabel, MeshModel *newMesh, bool setAsCurrent)
|
||||
template <class LayerElement>
|
||||
QString NameDisambiguator(QList<LayerElement*> &elemList, QString meshLabel )
|
||||
{
|
||||
QFileInfo info(meshLabel);
|
||||
QString newName=info.fileName();
|
||||
for(QList<MeshModel*>::iterator mmi=meshList.begin();mmi!=meshList.end();++mmi)
|
||||
{
|
||||
if((*mmi)->fullName() == newName)
|
||||
{
|
||||
QFileInfo fi((*mmi)->fullName());
|
||||
QString baseName = fi.baseName();
|
||||
int lastNum = baseName.right(1).toInt();
|
||||
if( baseName.right(2).toInt() >= 10)
|
||||
lastNum = baseName.right(1).toInt();
|
||||
if(lastNum)
|
||||
newName = baseName.left(baseName.length()-1)+QString::number(lastNum+1);
|
||||
else
|
||||
newName = baseName+"_1";
|
||||
if (info.suffix() != QString(""))
|
||||
newName = newName + "." + info.suffix();
|
||||
}
|
||||
}
|
||||
QString newName=info.fileName();
|
||||
typename QList<LayerElement*>::iterator mmi;
|
||||
for(mmi=elemList.begin(); mmi!=elemList.end(); ++mmi)
|
||||
{
|
||||
if((*mmi)->label() == newName)
|
||||
{
|
||||
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(1).toInt();
|
||||
if(lastNum)
|
||||
newName = baseName.left(baseName.length()-1)+QString::number(lastNum+1);
|
||||
else
|
||||
newName = baseName+"_1";
|
||||
if (info.suffix() != QString(""))
|
||||
newName = newName + "." + info.suffix();
|
||||
}
|
||||
}
|
||||
return newName;
|
||||
}
|
||||
|
||||
MeshModel * MeshDocument::addNewMesh(QString meshLabel, MeshModel *newMesh, bool setAsCurrent)
|
||||
{
|
||||
QString newName = NameDisambiguator(this->meshList,meshLabel);
|
||||
if(newMesh==0)
|
||||
newMesh=new MeshModel(this,qPrintable(newName));
|
||||
else
|
||||
@ -154,72 +160,32 @@ MeshModel * MeshDocument::addNewMesh(const char *meshLabel, MeshModel *newMesh,
|
||||
bool MeshDocument::delMesh(MeshModel *mmToDel)
|
||||
{
|
||||
if(meshList.size()==1) return false;
|
||||
if(!meshList.removeOne(mmToDel)) return false;
|
||||
if(currentMesh == mmToDel)
|
||||
setCurrentMesh(this->meshList.at(0)->id());
|
||||
|
||||
QMutableListIterator<MeshModel *> i(meshList);
|
||||
|
||||
while (i.hasNext())
|
||||
{
|
||||
MeshModel *md = i.next();
|
||||
|
||||
if (md==mmToDel)
|
||||
{
|
||||
i.remove();
|
||||
delete mmToDel;
|
||||
}
|
||||
}
|
||||
|
||||
if(currentMesh == mmToDel)
|
||||
{
|
||||
if (!meshList.isEmpty())
|
||||
setCurrentMesh(this->meshList.at(0)->id());
|
||||
else
|
||||
{
|
||||
this->Log.Logf(GLLogStream::SYSTEM,"Empty MeshDocument: should never happened!");
|
||||
}
|
||||
}
|
||||
|
||||
emit meshSetChanged();
|
||||
delete mmToDel;
|
||||
|
||||
emit meshSetChanged();
|
||||
return true;
|
||||
}
|
||||
|
||||
RasterModel * MeshDocument::addNewRaster(const char *rasterName, RasterModel *newRaster)
|
||||
RasterModel * MeshDocument::addNewRaster(QString fullPathFilename)
|
||||
{
|
||||
QFileInfo info(rasterName);
|
||||
QString newName=info.fileName();
|
||||
for(QList<RasterModel*>::iterator ri=rasterList.begin();ri!=rasterList.end();++ri)
|
||||
{
|
||||
if((*ri)->getName() == newName)
|
||||
{
|
||||
QFileInfo fi((*ri)->getName());
|
||||
QString baseName = fi.baseName();
|
||||
int lastNum = baseName.right(1).toInt();
|
||||
if( baseName.right(2).toInt() >= 10)
|
||||
lastNum = baseName.right(1).toInt();
|
||||
if(lastNum)
|
||||
newName = baseName.left(baseName.length()-1)+QString::number(lastNum+1);
|
||||
else
|
||||
newName = baseName+"_1";
|
||||
if (info.suffix() != QString(""))
|
||||
newName = newName + "." + info.suffix();
|
||||
}
|
||||
}
|
||||
|
||||
if(newRaster==0)
|
||||
newRaster=new RasterModel(this,qPrintable(newName));
|
||||
else
|
||||
newRaster->setRasterName(newName);
|
||||
QFileInfo info(fullPathFilename);
|
||||
QString newLabel=info.fileName();
|
||||
QString newName = NameDisambiguator(this->rasterList, newLabel);
|
||||
|
||||
RasterModel *newRaster=new RasterModel(this, newLabel);
|
||||
rasterList.push_back(newRaster);
|
||||
|
||||
emit rasterSetChanged();
|
||||
|
||||
//Add new plane
|
||||
Plane *plane = new Plane(newRaster, rasterName, QString());
|
||||
Plane *plane = new Plane(newRaster, fullPathFilename, QString());
|
||||
newRaster->addPlane(plane);
|
||||
|
||||
this->setCurrentRaster(newRaster->id());
|
||||
|
||||
emit rasterSetChanged();
|
||||
return newRaster;
|
||||
}
|
||||
|
||||
@ -261,7 +227,7 @@ void MeshDocument::removeTag(int id){
|
||||
}
|
||||
}
|
||||
|
||||
MeshModel::MeshModel(MeshDocument *parent, const char *meshName) {
|
||||
MeshModel::MeshModel(MeshDocument *parent, QString meshName) {
|
||||
glw.m=&cm;
|
||||
_id=parent->newMeshId();
|
||||
// These data are always active on the mesh
|
||||
@ -273,7 +239,7 @@ MeshModel::MeshModel(MeshDocument *parent, const char *meshName) {
|
||||
cm.Tr.SetIdentity();
|
||||
cm.sfn=0;
|
||||
cm.svn=0;
|
||||
if(meshName)
|
||||
if(!meshName.isEmpty())
|
||||
fullPathFileName=meshName;
|
||||
//parent->addNewMesh(qPrintable(fullPathFileName),this);
|
||||
}
|
||||
@ -389,9 +355,9 @@ Plane::Plane(RasterModel *_parent, const QString pathName, const QString _semant
|
||||
image = QImage(pathName);
|
||||
}
|
||||
|
||||
RasterModel::RasterModel(MeshDocument *parent, const char *_rasterName) {
|
||||
RasterModel::RasterModel(MeshDocument *parent, QString _rasterName) {
|
||||
_id=parent->newRasterId();
|
||||
rasterName= _rasterName;
|
||||
this->_label= _rasterName;
|
||||
visible=false;
|
||||
}
|
||||
|
||||
|
||||
@ -252,14 +252,14 @@ public:
|
||||
const QString suffixName() const {QFileInfo fi(fullName()); return fi.suffix();}
|
||||
|
||||
/// the relative path with respect to the current project
|
||||
const QString relativeName() const {QFileInfo fi(fullName()); return fi.suffix();}
|
||||
const QString relativeName() const {QFileInfo fi(fullName()); assert(0); return fi.suffix();}
|
||||
|
||||
void setFileName(QString newFileName) {fullPathFileName = newFileName;}
|
||||
|
||||
public:
|
||||
bool visible; // used in rendering; Needed for toggling on and off the meshes
|
||||
|
||||
MeshModel(MeshDocument *parent, const char *meshName=0);
|
||||
MeshModel(MeshDocument *parent, QString meshName=QString());
|
||||
bool Render(vcg::GLW::DrawMode _dm, vcg::GLW::ColorMode _cm, vcg::GLW::TextureMode _tm);
|
||||
bool RenderSelectedFace();
|
||||
bool RenderSelectedVert();
|
||||
@ -292,6 +292,11 @@ public:
|
||||
QString fullPathFileName;
|
||||
QImage image;
|
||||
|
||||
/// The whole full path name of the mesh
|
||||
const QString fullName() const {return fullPathFileName;}
|
||||
/// just the name of the file
|
||||
const QString shortName() const { return QFileInfo(fullPathFileName).fileName(); }
|
||||
|
||||
Plane(RasterModel *parent, const QString pathName, const QString _semantic);
|
||||
}; //end class Plane
|
||||
|
||||
@ -307,8 +312,7 @@ class RasterModel
|
||||
|
||||
public:
|
||||
vcg::Shotf shot;
|
||||
QString rasterName;
|
||||
bool visible; // used in rendering; Needed for switching from mesh view mode to raster view mode and vice versa.
|
||||
bool visible; // used in rendering; Needed for switching from mesh view mode to raster view mode and vice versa.
|
||||
|
||||
///The list of the registered images
|
||||
QList<Plane *> planeList;
|
||||
@ -316,17 +320,22 @@ public:
|
||||
|
||||
private:
|
||||
int _id;
|
||||
QString _label;
|
||||
|
||||
public:
|
||||
inline int id() const {return _id;}
|
||||
|
||||
RasterModel(MeshDocument *parent, const char *_rasterName=0);
|
||||
RasterModel(MeshDocument *parent, QString _rasterName=QString());
|
||||
|
||||
void setRasterName(QString newFileName) {rasterName = newFileName;};
|
||||
const QString getName() const {return rasterName;}
|
||||
void setLabel(QString newLabel) {_label = newLabel;};
|
||||
|
||||
const QString label() const {
|
||||
if(!_label.isEmpty()) return _label;
|
||||
if(!planeList.empty()) return planeList.first()->shortName();
|
||||
return "Error!";
|
||||
}
|
||||
void addPlane(Plane * plane);
|
||||
|
||||
|
||||
};// end class RasterModel
|
||||
|
||||
class MeshDocument;
|
||||
@ -412,7 +421,7 @@ public:
|
||||
|
||||
//returns the mesh ata given position in the list
|
||||
MeshModel *getMesh(int i);
|
||||
MeshModel *getMesh(const char *name);
|
||||
MeshModel *getMesh(QString name);
|
||||
|
||||
|
||||
|
||||
@ -474,13 +483,13 @@ public:
|
||||
QList<TagBase *> getMeshTags(int meshId);
|
||||
|
||||
///add a new mesh with the given name
|
||||
MeshModel *addNewMesh(const char *meshLabel, MeshModel *newMesh=0, bool setAsCurrent=true);
|
||||
MeshModel *addNewMesh(QString meshLabel, MeshModel *newMesh=0, bool setAsCurrent=true);
|
||||
|
||||
///remove the mesh from the list and delete it from memory
|
||||
bool delMesh(MeshModel *mmToDel);
|
||||
|
||||
///add a new raster model
|
||||
RasterModel *addNewRaster(const char *rasterName,RasterModel *newRaster=0);
|
||||
RasterModel *addNewRaster(QString rasterName);
|
||||
|
||||
///remove the raster from the list and delete it from memory
|
||||
bool delRaster(RasterModel *rasterToDel);
|
||||
|
||||
@ -476,7 +476,7 @@ RasterTreeWidgetItem::RasterTreeWidgetItem(RasterModel *rasterModel)
|
||||
|
||||
setText(1, QString::number(rasterModel->id()));
|
||||
|
||||
QString rasterName = rasterModel->getName();
|
||||
QString rasterName = rasterModel->label();
|
||||
setText(2, rasterName);
|
||||
|
||||
r=rasterModel;
|
||||
|
||||
@ -1242,10 +1242,8 @@ bool MainWindow::open(QString fileName, GLArea *gla)
|
||||
if(!GLA())
|
||||
newDocument();
|
||||
|
||||
RasterModel *rm= new RasterModel(GLA()->meshDoc);
|
||||
|
||||
GLA()->meshDoc->setBusy(true);
|
||||
GLA()->meshDoc->addNewRaster(qPrintable(fileName),rm);
|
||||
RasterModel *rm= GLA()->meshDoc->addNewRaster(qPrintable(fileName));
|
||||
meshDoc()->setBusy(false);
|
||||
|
||||
if(mdiarea->isVisible()) GLA()->mvc->showMaximized();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user