Ejemplo n.º 1
0
QString
GenericMediaDevice::fileName( const MetaBundle &bundle )
{
    QString result = cleanPath( bundle.artist() );

    if( !result.isEmpty() )
    {
        if( m_spacesToUnderscores )
            result += "_-_";
        else
            result += " - ";
    }

    if( bundle.track() )
    {
        result.sprintf( "%02d", bundle.track() );

        if( m_spacesToUnderscores )
            result += '_';
        else
            result += ' ';
    }

    result += cleanPath( bundle.title() + '.' + bundle.type() );

    return result;
}
Document* FileManager::openDocument(const QString& filename, QString* error) {
    QFileInfo fi(filename);
    QFile file(filename);

    if (!(fi.exists() && fi.isFile())){
        if(error)
            *error = tr("The file <br>\"%0\" <br>does not "
                        "exist or is no file.")
                        .arg(fi.absolutePath());
        return 0;
    }

    if (!file.open(QIODevice::ReadOnly|QIODevice::Text)){
        if(error)
            *error = tr("Unable to open the file<br>\"%0\" <br>"
                        "Check permissions or wether other programs "
                        "are locking the file.")
                        .arg(fi.absolutePath());
        return 0;
    }

    QByteArray contents = file.readAll();
    EncodingDetector detector(contents);
    QTextCodec* codec = detector.GetFontEncoding();//TODO:Delete?
    DocumentInfo docinfo(cleanPath(filename),codec->name(),fi.size());

    Document* doc = new Document(docinfo, codec->toUnicode(contents));
    file.close();

    m_documents.append(doc);
    m_documentMap.insert(cleanPath(filename), doc);

    emit documentOpened(doc);
    return doc;
}
Ejemplo n.º 3
0
int WsUser::createNode(const string& path, NodeType type)
{
  switch (type) {
  case File:
    return m_client->createNode(cleanPath(path), 0);
  case Directory:
    return m_client->createNode(cleanPath(path), 1);
  }
}
Ejemplo n.º 4
0
void FileLocator::addPath(const char* newPathBegin,const char* newPathEnd)
	{
	/* Check if the path is fully-qualified: */
	if(newPathEnd-newPathBegin>1&&newPathBegin[0]=='/')
		pathList.push_back(cleanPath(newPathBegin,newPathEnd));
	else if(newPathEnd-newPathBegin>0)
		{
		/* Prefix relative paths with the current working directory: */
		std::string absPath=getCurrentDirectory();
		absPath.push_back('/');
		absPath.append(newPathBegin,newPathEnd);
		pathList.push_back(cleanPath(absPath.c_str()));
		}
	}
///Regarding Projects
Project* FileManager::newProject(const QString& name, const QString& rootPath, QString* error) {
    QString filename = cleanPath(rootPath + "/" + name);
    QFile file(filename);
    if(m_documentMap.contains(filename) || m_projectMap.contains(filename)) {
        if(error)
            *error = tr("A file with the name <br>\"%0\" <br>is already open.").arg(filename);
        return 0;
    }
    if(!file.open(QIODevice::Truncate|QIODevice::WriteOnly|QIODevice::Text)) {
        if(error)
            *error = tr("Unable to open the file <br>\"%0\"").arg(filename);
        return 0;
    }
    Project* project = new Project(name, rootPath);
    if(!project->isValid()) {
        delete project;
        if(error)
            *error = tr("Invalid project parameters.");
    }
    project->setFilename(filename);
    project->toXml(&file);
    file.close();
    m_projects.append(project);
    m_projectMap.insert(filename, project);
    emit projectOpened(project);
    return project;
}
Ejemplo n.º 6
0
void
QResourcePrivate::ensureChildren() const
{
    ensureInitialized();
    if(!children.isEmpty() || !container || related.isEmpty())
        return;

    QString path = absoluteFilePath, k;
    if(path.startsWith(QLatin1Char(':')))
        path = path.mid(1);
    QSet<QString> kids;
    QString cleaned = cleanPath(path);
    for(int i = 0; i < related.size(); ++i) {
        QResourceRoot *res = related.at(i);
        if(res->mappingRootSubdir(path, &k) && !k.isEmpty()) {
            if(!kids.contains(k)) {
                children += k;
                kids.insert(k);
            }
        } else {
            const int node = res->findNode(cleaned);
            if(node != -1) {
                QStringList related_children = res->children(node);
                for(int kid = 0; kid < related_children.size(); ++kid) {
                    k = related_children.at(kid);
                    if(!kids.contains(k)) {
                        children += k;
                        kids.insert(k);
                    }
                }
            }
        }
    }
}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------
void SMBUrl::updateCache()
  //-----------------------------------------------------------------------
{
    cleanPath();

    // SMB URLs are UTF-8 encoded
    kdDebug(KIO_SMB) << "updateCache " << KURL::path() << endl;
    if (KURL::url() == "smb:/")
        m_surl = "smb://";
    else {
        QString surl = "smb://";
        if (KURL::hasUser()) {
            surl += KURL::encode_string(KURL::user(), 106);
            if (KURL::hasPass()) {
                surl += ":" + KURL::encode_string(KURL::pass(), 106);
            }
            surl += "@";
        }
        surl += KURL::encode_string(KURL::host().upper(), 106);
        surl += KURL::encode_string(KURL::path(), 106);
        m_surl = surl.utf8();
    }
    m_type = SMBURLTYPE_UNKNOWN;
    // update m_type
    (void)getType();
}
Ejemplo n.º 8
0
Id ReadKkit::buildTable( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head ); // Name of xtab

	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );
	Id tab;

	int mode = atoi( args[ tableMap_[ "step_mode" ] ].c_str() );
	if ( mode == TAB_IO ) {
	} else if ( mode == TAB_LOOP || mode == TAB_ONCE ) {
		tab = shell_->doCreate( "StimulusTable", pa, tail, 1 );
		assert( tab != Id() );
		double stepSize = atof( args[ tableMap_[ "stepsize" ] ].c_str() );
		Field< double >::set( tab, "stepSize", stepSize );
		if ( mode == TAB_LOOP )
			Field< bool >::set( tab, "doLoop", 1 );
		double input = atof( args[ tableMap_[ "input" ] ].c_str() );
		Field< double >::set( tab, "startTime", -input );
		// The other StimulusTable parameters will have to wait till the
		// loadTab is invoked.
	}


	string temp = clean.substr( 10 );
	tabIds_[ temp ] = tab; 

	Id info = buildInfo( tab, tableMap_, args );

	return tab;
}
Ejemplo n.º 9
0
Id ReadKkit::buildReac( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	double kf = atof( args[ reacMap_[ "kf" ] ].c_str() );
	double kb = atof( args[ reacMap_[ "kb" ] ].c_str() );

	// We have a slight problem because MOOSE has a more precise value for
	// NA than does kkit. Here we assume that the conc units from Kkit are
	// meant to be OK, so they override the #/cell (lower case k) units.
	// So we convert all the Kfs and Kbs in the entire system after
	// the model has been created, once we know the order of each reac.

	Id reac = shell_->doCreate( "Reac", pa, tail, 1 );
	reacIds_[ clean.substr( 10 ) ] = reac; 
	// Here is another hack: The native values stored in the reac are
	// Kf and Kb, in conc units. However the 'clean' values from kkit
	// are the number values numKf and numKb. In the 
	// function convertReacRatesToNumUnits we take the numKf and numKb and
	// do proper conc scaling.
	Field< double >::set( reac, "Kf", kf );
	Field< double >::set( reac, "Kb", kb );

	Id info = buildInfo( reac, reacMap_, args );
	numReacs_++;
	return reac;
}
Ejemplo n.º 10
0
/**
 * Build a Stim entry in simulation, i.e., a PulseGen
 */
Id ReadKkit::buildStim( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	double level1 = atof( args[ stimMap_[ "firstLevel" ] ].c_str() ); 
	double width1 = atof( args[ stimMap_[ "firstWidth" ] ].c_str() ); 
	double delay1 = atof( args[ stimMap_[ "firstDelay" ] ].c_str() ); 
	double level2 = atof( args[ stimMap_[ "secondLevel" ] ].c_str() ); 
	double width2 = atof( args[ stimMap_[ "secondWidth" ] ].c_str() ); 
	double delay2 = atof( args[ stimMap_[ "secondLevel" ] ].c_str() ); 
	double baselevel = atof( args[ stimMap_[ "baseLevel" ] ].c_str() );

	Id stim = shell_->doCreate( "PulseGen", pa, tail, 1 );
	assert( stim != Id() );
	string stimPath = clean.substr( 10 );
	stimIds_[ stimPath ] = stim;
	Field< double >::set( stim, "firstLevel", level1 );
	Field< double >::set( stim, "firstWidth", width1 );
	Field< double >::set( stim, "firstDelay", delay1 );
	Field< double >::set( stim, "secondLevel", level2 );
	Field< double >::set( stim, "secondWidth", width2 );
	Field< double >::set( stim, "secondDelay", delay2 );
	Field< double >::set( stim, "baseLevel", baselevel );

	numStim_++;
	return stim;
}
Ejemplo n.º 11
0
bool goBack( string& path ){

	// Defaulting back to the wd not desired!
	if( path == string( "/" ) )
		return true;

	cleanPath( path );

	char removed;
	while( path.size( ) > 0 and ( removed =
		path.at( path.size( )-1 ) ) == '/' )
		path.erase( path.end( )-1 );
	if( removed == '.' ){
		if( path.empty( ) )
			path = string( "/" );
		return false;
	}
	for( int i = path.size( )-1; i > 0; i-- ){
		removed = path.at( path.size( )-1 );
		path.erase( path.end( )-1 );
		if( removed == '/' )
			break;
	}
	if( path.empty( ) )
		path = string( "/" );
	return true;

}
Ejemplo n.º 12
0
static ALWAYS_INLINE void visitedURLInline(const KURL& base, const AtomicString& attributeURL, Vector<UChar, 512>& buffer)
{
    if (attributeURL.isNull())
        return;

    const UChar* characters = attributeURL.characters();
    unsigned length = attributeURL.length();

    // This is a poor man's completeURL. Faster with less memory allocation.
    // FIXME: It's missing a lot of what completeURL does and a lot of what KURL does.
    // For example, it does not handle international domain names properly.

    // FIXME: It is wrong that we do not do further processing on strings that have "://" in them:
    //    1) The "://" could be in the query or anchor.
    //    2) The URL's path could have a "/./" or a "/../" or a "//" sequence in it.

    // FIXME: needsTrailingSlash does not properly return true for a URL that has no path, but does
    // have a query or anchor.

    bool hasColonSlashSlash = containsColonSlashSlash(characters, length);

    if (hasColonSlashSlash && !needsTrailingSlash(characters, length)) {
        buffer.append(attributeURL.characters(), attributeURL.length());
        return;
    }


    if (hasColonSlashSlash) {
        // FIXME: This is incorrect for URLs that have a query or anchor; the "/" needs to go at the
        // end of the path, *before* the query or anchor.
        buffer.append(characters, length);
        buffer.append('/');
        return;
    }

    if (!length)
        buffer.append(base.string().characters(), base.string().length());
    else {
        switch (characters[0]) {
            case '/':
                buffer.append(base.string().characters(), base.pathStart());
                break;
            case '#':
                buffer.append(base.string().characters(), base.pathEnd());
                break;
            default:
                buffer.append(base.string().characters(), base.pathAfterLastSlash());
                break;
        }
    }
    buffer.append(characters, length);
    cleanPath(buffer);
    if (needsTrailingSlash(buffer.data(), buffer.size())) {
        // FIXME: This is incorrect for URLs that have a query or anchor; the "/" needs to go at the
        // end of the path, *before* the query or anchor.
        buffer.append('/');
    }

    return;
}
Ejemplo n.º 13
0
string WsUser::getProperty(const string& path, const string& section, const string& attr, const string& def)
{
  /* Return the property found if not empty string otherwise return def */
  string ret = m_client->getProperty(section, cleanPath(path), attr);
  if ( ret.size() > 0 ) return ret;
  return def;
}
Ejemplo n.º 14
0
bool CommanderWindow::Up()
{
	cleanPath();

	if ( strcmp( input->Text(), "/" ) == 0 ) return true;

	char *path = strdup( input->Text() );
	int len = strlen( path ) - 2;

		while ( len >= 0 )
		{
			if ( path[len] == '/' ) break;
			path[len] = 0;
			len -= 1;
		}
	
	if ( len < 0 ) input->SetText("/");
	else
	{
		input->SetText( path );
	}
		

	free( path );
	return true;
}
Ejemplo n.º 15
0
Archivo: Path.cpp Proyecto: kutabar/of
bool Path::find(StringVec::const_iterator it, StringVec::const_iterator end, const std::string& name, Path& path)
{
	while (it != end)
	{
#if defined(WIN32)
		std::string cleanPath(*it);
		if (cleanPath.size() > 1 && cleanPath[0] == '"' && cleanPath[cleanPath.size() - 1] == '"')
		{
			cleanPath = cleanPath.substr(1, cleanPath.size() - 2);
		}
		Path p(cleanPath);
#else
		Path p(*it);
#endif
		p.makeDirectory();
		p.resolve(Path(name));
		File f(p);
		if (f.exists())
		{
			path = p;
			return true;
		}
		++it;
	}
	return false;
}
Ejemplo n.º 16
0
/**
 * There is a problem with this conversion, because of the discrepancy of
 * the correct NA and the version (6e23) used in kkit. I take the 
 * concentration as authoritative, not the # of molecules. This is because
 * I use conc units for the rates as well, and to use n for pools and
 * conc for reactions will always introduce errors. This is still not
 * a great solution, because, for example, simulations involving receptor
 * traffic are originally framed in terms of number of receptors, not conc.
 */
Id ReadKkit::buildPool( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	double nInit = atof( args[ poolMap_[ "nInit" ] ].c_str() );
	double vsf = atof( args[ poolMap_[ "vol" ] ].c_str() ); 
	/**
	 * vsf is vol scale factor, which is what GENESIS stores in 'vol' field
	 * n = vsf * conc( uM )
	 * Also, n = ( conc (uM) / 1e6 ) * NA * vol
	 * so, vol = 1e6 * vsf / NA
	 */
	double vol = 1.0e3 * vsf / KKIT_NA; // Converts volscale to actual vol in m^3
	int slaveEnable = atoi( args[ poolMap_[ "slave_enable" ] ].c_str() );
	double diffConst = atof( args[ poolMap_[ "DiffConst" ] ].c_str() );

	// I used -ve D as a flag to replace pool-specific D 
	// with the global value of D. Here we just ignore it.
	if ( diffConst < 0 ) 
		diffConst = 0;

	Id pool;
	if ( slaveEnable == 0 ) {
		pool = shell_->doCreate( "Pool", pa, tail, 1 );
	} else if ( slaveEnable & 4 ) {
		pool = shell_->doCreate( "BufPool", pa, tail, 1 );
	} else {
		pool = shell_->doCreate( "Pool", pa, tail, 1 );
		/*
		cout << "ReadKkit::buildPool: Unknown slave_enable flag '" << 
			slaveEnable << "' on " << clean << "\n";
			*/
		poolFlags_[pool] = slaveEnable;
	}
	assert( pool != Id() );
	// skip the 10 chars of "/kinetics/"
	poolIds_[ clean.substr( 10 ) ] = pool; 

	Field< double >::set( pool, "nInit", nInit );
	Field< double >::set( pool, "diffConst", diffConst );
	// SetGet1< double >::set( pool, "setVolume", vol );
	separateVols( pool, vol );
	poolVols_[pool] = vol;

	Id info = buildInfo( pool, poolMap_, args );

	/*
	cout << setw( 20 ) << head << setw( 15 ) << tail << "	" << 
		setw( 12 ) << nInit << "	" << 
		vol << "	" << diffConst << "	" <<
		slaveEnable << endl;
		*/
	numPools_++;
	return pool;
}
Ejemplo n.º 17
0
Project* FileManager::openProject(QString filename, QString* error) {
    filename = cleanPath(filename);
    QFileInfo fi(filename);
    QFile file(filename);

    if(!fi.exists()) {
        if(error)
            *error = tr("The file \"%0\"<br>does not exist.").arg(filename);
        return 0;
    }
    if(!fi.isFile()) {
        if(error)
            *error = tr("\"%0\"<br>is not a file.").arg(filename);
        return 0;
    }
    if(m_documentMap.contains(filename) || m_projectMap.contains(filename)) {
        if(error)
            *error = tr("A file with the name <br>\"%0\" <br>is already open.").arg(filename);
        return 0;
    }
    if(!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
        if(error)
            *error = tr("Unable to open the file <br>\"%0\".").arg(filename);
        return 0;
    }
    Project* project = Project::fromXml(&file,cleanPath(fi.absolutePath()));
    file.close();
    if(!project) {
        if(error)
            *error = tr("Unable to read the project file <br>\"%0\".").arg(filename);
        return 0;
    }
    if(!project->isValid()) {
        delete project;
        if(error)
            *error = tr("Invalid project.");
    }
    project->setFilename(filename);
    m_projects.append(project);
    m_projectMap.insert(filename, project);
    emit projectOpened(project);
    return project;
}
Ejemplo n.º 18
0
Id ReadKkit::buildGraph( const vector< string >& args )
{
	string head;
	string tail = pathTail( cleanPath( args[2] ), head );

	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );
	Id graph = shell_->doCreate( "Neutral", pa, tail, 1 );
	assert( graph != Id() );
	numOthers_++;
	return graph;
}
Ejemplo n.º 19
0
Id ReadKkit::buildGroup( const vector< string >& args )
{
	string head;
	string tail = pathTail( cleanPath( args[2] ), head );

	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );
	Id group = shell_->doCreate( "Neutral", pa, tail, 1 );
	assert( group != Id() );
	Id info = buildInfo( group, groupMap_, args );

	numOthers_++;
	return group;
}
Ejemplo n.º 20
0
/**
 * Build a Kchan entry in simulation. For now a dummy Neutral.
 */
Id ReadKkit::buildChan( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	cout << "Warning: Kchan not yet supported in MOOSE, creating dummy:\n"
		<< "	" << clean << "\n";
	Id chan = shell_->doCreate( "Neutral", pa, tail, 1 );
	assert( chan != Id() );
	string chanPath = clean.substr( 10 );
	chanIds_[ chanPath ] = chan;
	return chan;
}
Ejemplo n.º 21
0
//Makes a copy of the passed DiskItem:
Directory::Directory(Directory* dir)
{
	//Copies the passed directory's data:
	_size = dir->getSize();
	_path = dir->getPath();
	_files = dir->getFiles();
	_isCut = false;

	if(getName() == "../")
		cleanPath();

	//Reads the directory's attributes into '_attr':
	_attr = new struct stat;
	if(stat(_path.c_str(), _attr) != 0)
		throw errno;
}
Ejemplo n.º 22
0
bool CommanderWindow::Refresh()
{
	cleanPath();
	list->Empty();
		
	const char *path = input->Text();

	Directory *dir = new Directory( path );
    if ( dir->Exists() == false )  
    {
	  delete dir;
	  Draw( Bounds() );
	  return false;
    }
  
     char *entry = NULL;
     while ((entry = dir->NextEntry()) != NULL )
     {

	   char *complete = (char*)malloc( strlen(path) + strlen(entry) + 2 );

		   strcpy( complete, path );
		   strcat( complete, entry );
		   
		   int size = -1;
		   File *temp = new File( complete );
		   if ( temp->Open() >= 0 )
		   {
		     size = temp->Size();
			 temp->Close();
		   }
		   delete temp;
			 

	   list->AddItem( new StringItem( entry ) );
	   free( complete );
     }

	Draw( Bounds() );
    delete dir;

	return true;
}
Ejemplo n.º 23
0
Id ReadKkit::buildPlot( const vector< string >& args )
{
	string head;
	string tail = pathTail( cleanPath( args[2] ), head ); // Name of plot
	string temp;
	string graph = pathTail( head, temp ); // Name of graph

	Id pa = shell_->doFind( head ).id;
	assert( pa != Id() );

	Id plot = shell_->doCreate( "Table", pa, tail, 1 );
	assert( plot != Id() );

	temp = graph + "/" + tail;
	plotIds_[ temp ] = plot; 

	numPlot_++;
	return plot;
}
Ejemplo n.º 24
0
bool CMainWindow::copyFiles(const std::vector<CFileSystemObject> & files, const QString & destDir)
{
	if (files.empty() || destDir.isEmpty())
		return false;

	const QString destPath = files.size() == 1 && files.front().isFile() ? cleanPath(destDir % toNativeSeparators("/") % files.front().fullName()) : destDir;
	CFileOperationConfirmationPrompt prompt(tr("Copy files"), tr("Copy %1 %2 to").arg(files.size()).arg(files.size() > 1 ? "files" : "file"), destPath, this);
	if (CSettings().value(KEY_OPERATIONS_ASK_FOR_COPY_MOVE_CONFIRMATION, true).toBool())
	{
		if (prompt.exec() != QDialog::Accepted)
			return false;
	}

	CCopyMoveDialog * dialog = new CCopyMoveDialog(operationCopy, files, prompt.text(), this);
	connect(this, &CMainWindow::closed, dialog, &CCopyMoveDialog::deleteLater);
	dialog->connect(dialog, &CCopyMoveDialog::closed, this, &CMainWindow::deleteLater);
	dialog->show();

	return true;
}
Ejemplo n.º 25
0
bool pActionsModel::addAction( const QString& _path, QAction* action )
{
    Q_ASSERT( action );

    if ( !action || !path( action ).isEmpty() || this->action( _path ) ) {
        return false;
    }

    const QString path = cleanPath( _path );
    const QString subPath = path.section( QL1C( '/' ), 0, -2 );
    QAction* parentAction = createCompletePathNode( subPath );

    if ( !parentAction ) {
        return false;
    }

    const int row = children( parentAction ).count();
    insertAction( path, action, parentAction, row );
    return true;
}
Ejemplo n.º 26
0
bool FileManager::saveDocument(Document* doc, const QString& filename, QString* error) {
//    QFileInfo fi(filename);//doc->documentInfo()->absoluteFilePath());
    QString path = cleanPath(filename);
    QFile file(path);
    if(!file.open(QIODevice::WriteOnly|QIODevice::Text)){
        if(error)
            *error = tr("Unable to open <br>\"%0\" <br>for writing.")
                        .arg(path);
        return false;
    }
    QTextCodec* codec = QTextCodec::codecForName(doc->documentInfo()->encodingName().toAscii());//TODO:Delete?
    if(-1 == file.write(codec->fromUnicode(doc->text()))){
        if(error)
            *error = tr("Writing to <br>\"%0\" <br>failed.")
                        .arg(path);
        return false;
    }
    file.close();
    doc->documentInfo()->setAbsoluteFilePath(path);
    return true;
}
Ejemplo n.º 27
0
bool
QResourcePrivate::load(const QString &file)
{
    related.clear();
    QMutexLocker lock(resourceMutex());
    const ResourceList *list = resourceList();
    QString cleaned = cleanPath(file);
    for(int i = 0; i < list->size(); ++i) {
        QResourceRoot *res = list->at(i);
        const int node = res->findNode(cleaned, locale);
        if(node != -1) {
            if(related.isEmpty()) {
                container = res->isContainer(node);
                if(!container) {
                    data = res->data(node, &size);
                    compressed = res->isCompressed(node);
                } else {
                    data = 0;
                    size = 0;
                    compressed = 0;
                }
            } else if(res->isContainer(node) != container) {
                qWarning("QResourceInfo: Resource [%s] has both data and children!", file.toLatin1().constData());
            }
            res->ref.ref();
            related.append(res);
        } else if(res->mappingRootSubdir(file)) {
            container = true;
            data = 0;
            size = 0;
            compressed = 0;
            res->ref.ref();
            related.append(res);
        }
    }
    return !related.isEmpty();
}
Ejemplo n.º 28
0
bool FileManager::saveProject(Project* project, QString* error) {
    Q_ASSERT(project);

    //Prepare file
    QString filename = cleanPath(project->filename());
    QFile file(filename);
    if(!file.open(QIODevice::WriteOnly|QIODevice::Text)) {
        if(error)
            *error = tr("Unable to open the file <br>\"%0\".").arg(filename);
        return false;
    }

    //Save project
    project->toXml(&file);
    file.close();

    //Store new filename
    if(filename != project->filename()) {
        project->setFilename(filename);
        m_projectMap.remove(project->filename());
        m_projectMap.insert(filename, project);
    }
    return true;
}
Ejemplo n.º 29
0
void ReadKkit::call( const vector< string >& args)
{
	/// call /kinetics/foo/notes LOAD notes_string_here
	if ( args.size() > 3 ) {
		unsigned int len = args[1].length();
		if ( ( args[1].substr( len - 5 ) ==  "notes" ) &&
			args[2] == "LOAD" ) {
			if ( args[3].length() == 0 )
				return;
			//HARSHA: Added CleanPath.
			string objName = cleanPath(args[1].substr( 0, len - 5 ));
		        Id test(basePath_+objName);
			Id obj( basePath_ + objName + "info" );
			if ( obj != Id() ) {
				string notes = "";
				string space = "";
				for ( unsigned int i = 3; i < args.size(); ++i ) {
					unsigned int innerLength = args[i].length();
					if ( innerLength == 0 )
						continue;
					unsigned int start = 0;
					unsigned int end = innerLength;
					if ( args[i][0] == '\"' )
						start = 1;
					if ( args[i][innerLength - 1] == '\"' )
						end = innerLength - 1 - start;

					notes += space + args[i].substr( start, end );
					space = " ";
				}
				bool OK = Field< string >::set( obj, "notes", notes );
				assert( OK );
			}
		}
	}
}
Ejemplo n.º 30
0
Id ReadKkit::buildEnz( const vector< string >& args )
{
	string head;
	string clean = cleanPath( args[2] );
	string tail = pathTail( clean, head );
	Id pa = shell_->doFind( head ).id;
	assert ( pa != Id() );

	double k1 = atof( args[ enzMap_[ "k1" ] ].c_str() );
	double k2 = atof( args[ enzMap_[ "k2" ] ].c_str() );
	double k3 = atof( args[ enzMap_[ "k3" ] ].c_str() );
	// double volscale = atof( args[ enzMap_[ "vol" ] ].c_str() );
	double nComplexInit = 
		atof( args[ enzMap_[ "nComplexInit" ] ].c_str() );
	// double vol = atof( args[ enzMap_[ "vol" ] ].c_str());
	bool isMM = atoi( args[ enzMap_[ "usecomplex" ] ].c_str());
	assert( poolVols_.find( pa ) != poolVols_.end() );
	// double vol = poolVols_[ pa ];
	
	/**
	 * vsf is vol scale factor, which is what GENESIS stores in 'vol' field
	 * n = vsf * conc( uM )
	 * Also, n = ( conc (uM) / 1e6 ) * NA * vol
	 * so, vol = 1e6 * vsf / NA
	 */

	if ( isMM ) {
		Id enz = shell_->doCreate( "MMenz", pa, tail, 1 );
		assert( enz != Id () );
		string mmEnzPath = clean.substr( 10 );
		mmEnzIds_[ mmEnzPath ] = enz; 

		assert( k1 > EPSILON );
		double Km = ( k2 + k3 ) / k1;

		Field< double >::set( enz, "Km", Km );
		Field< double >::set( enz, "kcat", k3 );
		Id info = buildInfo( enz, enzMap_, args );
		numMMenz_++;
		return enz;
	} else {
		Id enz = shell_->doCreate( "Enz", pa, tail, 1 );
		// double parentVol = Field< double >::get( pa, "volume" );
		assert( enz != Id () );
		string enzPath = clean.substr( 10 );
		enzIds_[ enzPath ] = enz; 

		// Need to figure out what to do about these. Perhaps it is OK
		// to do this assignments in raw #/cell units.
		Field< double >::set( enz, "k3", k3 );
		Field< double >::set( enz, "k2", k2 );
		Field< double >::set( enz, "k1", k1 );

		string cplxName = tail + "_cplx";
		string cplxPath = enzPath + "/" + cplxName;
		Id cplx = shell_->doCreate( "Pool", enz, cplxName, 1 );
		assert( cplx != Id () );
		poolIds_[ cplxPath ] = cplx; 
		// Field< double >::set( cplx, "nInit", nComplexInit );
		Field< double >::set( cplx, "nInit", nComplexInit );

		// Use this later to assign mesh entries to enz cplx.
		enzCplxMols_.push_back( pair< Id, Id >(  pa, cplx ) );
		separateVols( cplx, -1 ); // -1 vol is a flag to defer mesh assignment for the cplx pool.

		ObjId ret = shell_->doAddMsg( "OneToAll", 
			ObjId( enz, 0 ), "cplx",
			ObjId( cplx, 0 ), "reac" ); 
		assert( ret != ObjId() );

		// cplx()->showFields();
		// enz()->showFields();
		// pa()->showFields();
		Id info = buildInfo( enz, enzMap_, args );
		numEnz_++;
		return enz;
	}
}