Exemplo n.º 1
0
QSegMesh * QMeshDoc::importObject(QString fileName)
{
	// Get object name from file path
	QFileInfo fInfo (fileName);

	if(!fileName.size() || !fInfo.exists())
	{
		emit(printMessage(QString("Error: invalid file (%1).").arg(fileName)));
		return NULL;
	}

	QString newObjId = fInfo.fileName();
	newObjId.chop(4);
	global_id++;
	newObjId += QString("-%1").arg(global_id);

	// Create a new QSegMesh
	QSegMesh * newMesh = new QSegMesh();
	all_objects[ newObjId ] = newMesh;

	// Reading QSegMesh
	newMesh->read(fileName);

	// Set global ID for the mesh and all its segments
	newMesh->setObjectName(newObjId);
	
	// Try to load the controller and groups with the same filename
	// Setup controller file name
	fileName.chop(3);fileName += "ctrl";

	if(QFileInfo(fileName).exists())
	{
		// Load controller
		newMesh->ptr["controller"] = new Controller(newMesh, true, fileName);
		Controller * ctrl = (Controller *)newMesh->ptr["controller"];

		fileName.chop(4);fileName += "grp";
		if(QFileInfo(fileName).exists())
		{
			std::ifstream inF(qPrintable(fileName), std::ios::in);
			ctrl->loadGroups(inF);
			inF.close();
		}
	}
	else
	{
		newMesh->ptr["controller"] = new Controller(newMesh);
	}

	return newMesh;
}
Exemplo n.º 2
0
void QMeshDoc::importObject(QString fileName)
{
    Workspace * workspace = (Workspace *) parent();
    if(workspace->activeScene == NULL) return;

    // Get object name from file path
    QFileInfo fInfo (fileName);

    if(!fileName.size() || !fInfo.exists())
    {
        emit(printMessage(QString("Error: invalid file (%1).").arg(fileName)));
        return;
    }

    QString newObjId = fInfo.fileName();
    newObjId.chop(4);
    global_id++;
    newObjId += QString("-%1").arg(global_id);

    // Create a new QSegMesh
    QSegMesh * newMesh = new QSegMesh();
    all_objects[ newObjId ] = newMesh;

    // Reading QSegMesh
    newMesh->read(fileName);

    // Set global ID for the mesh and all its segments
    newMesh->setObjectName(newObjId);

    // Focus active scene
    workspace->activeScene->setFocus();
    workspace->activeScene->print(newObjId + " has been imported.");
    workspace->activeScene->setActiveObject(newMesh);

    DEFAULT_FILE_PATH = QFileInfo(fileName).absolutePath();
}