Ejemplo n.º 1
0
void CWorkspacePage::insertPS()
{
	QString fileName = QFileDialog::getOpenFileName(this,
					   tr("Open NeL data file"), ".",
					   tr("Particle System file (*.ps);;"));

	if (!fileName.isEmpty())
	{
		// TODO: create method particle editor insertNewPS and multiple add
		CWorkspaceNode *node = Modules::psEdit().getParticleWorkspace()->addNode(NLMISC::CFile::getFilename(fileName.toUtf8().constData()));
		if (node != 0)
		{
			try
			{
				node->loadPS();
			}
			catch(NLMISC::EStream &e)
			{
				QMessageBox::critical(this, tr("NeL particle system editor"),
									  QString(e.what()),
									  QMessageBox::Ok);
			}
			if (!node->isLoaded())
				Modules::psEdit().getParticleWorkspace()->removeNode(Modules::psEdit().getParticleWorkspace()->getNumNode() - 1);
			else
			{
				QModelIndex index = _treeModel->index(0, 0);
				_treeModel->insertRows(node, static_cast<CParticleTreeItem *>(index.internalPointer())->childCount(), index);
			}
		}
	}
}
void CParticleEditor::loadWorkspace(const std::string &fullPath)
{
	// Add to the path
	std::auto_ptr<CParticleWorkspace> newPW(new CParticleWorkspace);
	newPW->init(fullPath);
	
	// save empty workspace
	try
	{
		newPW->load();
	}
	catch(NLMISC::EStream &e)
	{
		nlerror(e.what());
		return;
	}	
	
	// try to load each ps
	CWorkspaceNode *firstLoadedNode = NULL;
	TPWNodeItr itr = newPW->getNodeList().begin();
	while(itr != newPW->getNodeList().end())
	{
		CWorkspaceNode *node = (*itr);
		try
		{
			node->loadPS();
		}
		catch(NLMISC::EStream &e)
		{
			nlwarning(e.what());
		}
		if (node->isLoaded() && !firstLoadedNode)
			firstLoadedNode = node;
		itr++;
	}
	closeWorkspace();
	_PW = newPW.release();
	setActiveNode(firstLoadedNode);
}