void MoleculeURLListProperty::loadMolecules(bool selectedOnly /*= false*/, bool removeOnFailure /*= false*/) {

    std::vector<std::string> failedURLs;

    for (size_t i=0; i<value_.size(); i++) {
        std::string url = value_[i];
        if (selectedOnly && !isSelected(url))
            continue;
        if (getMolecule(url))
            continue;

        try {
            loadMolecule(url);
        }
        catch (tgt::FileException& e) {
            LERROR(e.what());
            failedURLs.push_back(url);
        }
        catch (std::bad_alloc&) {
            LERROR("bad allocation while loading molecule: " << url);
            failedURLs.push_back(url);
        }
        catch (tgt::Exception& e) {
            LERROR("unknown exception while loading molecule '" << url << "':" << e.what());
            failedURLs.push_back(url);
        }
    }

    if (removeOnFailure) {
        for (size_t i=0; i<failedURLs.size(); i++)
            removeURL(failedURLs.at(i));
    }
}
void MoleculeURLListProperty::loadMolecule(const std::string& url)
        throw (tgt::FileException, std::bad_alloc) {

    if (!containsURL(url)) {
        LWARNING("loadMolecule(): passed URL not contained by this property: " << url);
        return;
    }

    // delete molecule, if already loaded and owned by the property
    if (getMolecule(url) && isOwner(url))
        delete getMolecule(url);
    handleMap_.erase(url);
    ownerMap_.erase(url);

    ProgressBar* progressBar = getProgressBar();
    if (progressBar) {
        progressBar->setTitle("Loading molecule");
        progressBar->setMessage("Loading molecule ...");
    }

    Molecule* handle = MoleculeIO::read(MoleculeURL(url));

    if (handle) {
        // url may have been altered by loading routine
        if (url != handle->getOrigin().getURL()) {
            bool selected = isSelected(url);
            selectionMap_.erase(url);
            selectionMap_[handle->getOrigin().getURL()] = selected;

            for (size_t i=0; i<value_.size(); i++) {
                if (value_[i] == url) {
                    value_[i] = handle->getOrigin().getURL();
                    break;

                }
            }
        }

        handleMap_[handle->getOrigin().getURL()] = handle;
        ownerMap_[handle->getOrigin().getURL()] = true;
    }

    invalidate();
}
void MoleculeURLListProperty::removeMolecule(Molecule* handle) {
    tgtAssert(handle, "null pointer passed");
    std::string url = handle->getOrigin().getURL();
    if (!containsURL(url)) {
        LWARNING("removeMolecule(): passed handle's URL not contained by this property: " << url);
        return;
    }

    if ((getMolecule(url) == handle) && isOwner(url)) {
        delete handle;
    }

    handleMap_.erase(url);
    ownerMap_[url] = false;

    invalidate();
}
void MoleculeURLListProperty::removeURL(const std::string& url) {
    if (!containsURL(url)) {
        LWARNING("removeURL(): passed URL not contained by this property: " << url);
        return;
    }

    // free corresponding molecule, if owned by the property
    Molecule* handle = getMolecule(url);
    if (handle)
        removeMolecule(handle);

    // remove url from url list
    std::vector<std::string>::iterator it = std::find(value_.begin(), value_.end(), url);
    tgtAssert(it != value_.end(), "url not found");
    value_.erase(it);

    // remove url from maps
    handleMap_.erase(url);
    selectionMap_.erase(url);
    ownerMap_.erase(url);

    invalidate();
}
Example #5
0
const char * IndigoCdxMolecule::getName ()
{
   return getMolecule().name.ptr();
}
Example #6
0
BaseMolecule & IndigoCdxMolecule::getBaseMolecule ()
{
   return getMolecule();
}
Example #7
0
const char * IndigoSmilesMolecule::getName ()
{
   if (getMolecule().name.ptr() == 0)
      return "";
   return getMolecule().name.ptr();
}
Example #8
0
BaseMolecule & IndigoSmilesMolecule::getBaseMolecule ()
{
   return getMolecule();
}
Example #9
0
BaseMolecule & IndigoRdfMolecule::getBaseMolecule ()
{
   return getMolecule();
}