Esempio n. 1
0
void Scene::removeEdge(PlugEdge* edge)
{
    Plug* fromPlug = edge->getStartPlug();
    Plug* toPlug = edge->getEndPlug();
    QPair<Plug*, Plug*> edgeKey(fromPlug, toPlug);
#ifdef QT_DEBUG
    Q_ASSERT(m_edges.contains(edgeKey));
#else
    if(!m_edges.contains(edgeKey)){
        return;
    }
#endif

    // unregister from the connected plugs
    fromPlug->removeEdge(edge);
    toPlug->removeEdge(edge);

    // remove the edge from the Scene's register
    m_edges.remove(edgeKey);

    // remove the edge from its group
    EdgeGroup* edgeGroup  = edge->getGroup();
    edgeGroup->removeEdge(edge);

    // if the group is now empty, we can only delete it if the other group in the pair is also empty
    EdgeGroupPair* edgeGroupPair = edgeGroup->getEdgeGroupPair();
    if(edgeGroupPair->isEmpty()){
        uint firstHash = edgeGroupPair->getFirstGroup()->getHash();
        uint secondHash = edgeGroupPair->getSecondGroup()->getHash();
        Q_ASSERT(m_edgeGroups.contains(firstHash));
        Q_ASSERT(m_edgeGroups.contains(secondHash));
        m_edgeGroups.remove(firstHash);
        m_edgeGroups.remove(secondHash);
        m_edgeGroupPairs.remove(edgeGroupPair);
        delete edgeGroupPair; // also deletes the EdgeGroups
        edgeGroupPair = nullptr;
    }

    // lastly, remove the QGraphicsItem from the scene, thereby taking possession of the last pointer to the edge
    removeItem(edge);

    // delete the edge from memory (automatically deletes all Qt-children as well)
    edge->deleteLater();

    // emit signals
    emit fromPlug->getNode()->outputDisconnected(fromPlug, toPlug);
    emit toPlug->getNode()->inputDisconnected(toPlug, fromPlug);
}
void Geometry::addEdge(Table<EdgeHash,int>& edgeTable, std::vector<Edge>& edgeVector, int v0, int v1, int face)
{    
    EdgeHash edgeKey( v0, v1, _vertices );

    if( edgeTable.containsKey(edgeKey) ) 
    {
        // if this is the second face referencing this edge
        int edgeIndex = edgeTable[edgeKey];
        Edge& existingEdge = edgeVector[edgeIndex];

        // make sure the vertices are wound correctly
        // (ie in opposite directions for the two different faces)
        assert( fuzzyEq( _vertices + existingEdge.vertexId[0], _vertices + v1 ) );
        assert( fuzzyEq( _vertices + existingEdge.vertexId[1], _vertices + v0 ) );

        // make sure this is only the second face to reference this edge
        assert( existingEdge.triangleId[0] >= 0 );
        assert( existingEdge.triangleId[0] != face );
        assert( existingEdge.triangleId[1] == -1 );

        // set second face
        existingEdge.triangleId[1] = face;
    } 
    else 
    {
        // if this is the first face referencing this edge
        Edge newEdge;
        newEdge.vertexId[0] = v0;
        newEdge.vertexId[1] = v1;
        newEdge.triangleId[0] = face;
        newEdge.triangleId[1] = -1;
        // add edge to lookup table and array
        edgeTable.set( edgeKey, edgeVector.size() );
        edgeVector.push_back(newEdge);
    }
}
Esempio n. 3
0
PlugEdge* Scene::getEdge(Plug* fromPlug, Plug* toPlug)
{
    QPair<Plug*, Plug*> edgeKey(fromPlug, toPlug);
    return m_edges.value(edgeKey, nullptr);
}