void MetavoxelEditor::selectedAttributeChanged() {
    _toolBox->clear();
    
    QString selected = getSelectedAttribute();
    if (selected.isNull()) {
        _deleteAttribute->setEnabled(false);
        _toolBox->setEnabled(false); 
        _value->setVisible(false);
        return;
    }
    _deleteAttribute->setEnabled(true);
    _toolBox->setEnabled(true);
    
    AttributePointer attribute = AttributeRegistry::getInstance()->getAttribute(selected);
    foreach (MetavoxelTool* tool, _tools) {
        if (tool->appliesTo(attribute)) {
            _toolBox->addItem(tool->objectName(), QVariant::fromValue(tool));
        }
    }
    _value->setVisible(true);
    
    if (_valueArea->widget()) {
        delete _valueArea->widget();
    }
    QWidget* editor = attribute->createEditor();
    if (editor) {
        editor->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Preferred);
        _valueArea->setWidget(editor);
    }
}
Beispiel #2
0
void MetavoxelNode::readDelta(const AttributePointer& attribute, const MetavoxelNode& reference, Bitstream& in) {
    clearChildren(attribute);

    bool leaf;
    in >> leaf;
    attribute->readDelta(in, _attributeValue, reference._attributeValue, leaf);
    if (!leaf) {
        if (reference.isLeaf()) {
            for (int i = 0; i < CHILD_COUNT; i++) {
                _children[i] = new MetavoxelNode(attribute);
                _children[i]->read(attribute, in);
            }
        } else {
            for (int i = 0; i < CHILD_COUNT; i++) {
                bool changed;
                in >> changed;
                if (changed) {
                    _children[i] = new MetavoxelNode(attribute);
                    _children[i]->readDelta(attribute, *reference._children[i], in);
                } else {
                    _children[i] = reference._children[i];
                    _children[i]->incrementReferenceCount();
                }
            }
        }  
    }
}
AttributePointer AttributeRegistry::registerAttribute(AttributePointer attribute) {
    AttributePointer& pointer = _attributes[attribute->getName()];
    if (!pointer) {
        pointer = attribute;
    }
    return pointer;
}
Beispiel #4
0
void MetavoxelNode::destroy(const AttributePointer& attribute) {
    attribute->destroy(_attributeValue);
    for (int i = 0; i < CHILD_COUNT; i++) {
        if (_children[i]) {
            _children[i]->decrementReferenceCount(attribute);
        }
    }
}
Beispiel #5
0
MetavoxelNode::MetavoxelNode(const AttributePointer& attribute, const MetavoxelNode* copy) : _referenceCount(1) {
    _attributeValue = attribute->create(copy->_attributeValue);
    for (int i = 0; i < CHILD_COUNT; i++) {
        if ((_children[i] = copy->_children[i])) {
            _children[i]->incrementReferenceCount();
        }
    }
}
Beispiel #6
0
void MetavoxelNode::write(const AttributePointer& attribute, Bitstream& out) const {
    bool leaf = isLeaf();
    out << leaf;
    attribute->write(out, _attributeValue, leaf);
    if (!leaf) {
        for (int i = 0; i < CHILD_COUNT; i++) {
            _children[i]->write(attribute, out);
        }
    }
}
Beispiel #7
0
AttributePointer AttributeRegistry::registerAttribute(AttributePointer attribute) {
    if (!attribute) {
        return attribute;
    }
    QWriteLocker locker(&_attributesLock);
    AttributePointer& pointer = _attributes[attribute->getName()];
    if (!pointer) {
        pointer = attribute;
    }
    return pointer;
}
Beispiel #8
0
void MetavoxelNode::mergeChildren(const AttributePointer& attribute) {
    void* childValues[CHILD_COUNT];
    bool allLeaves = true;
    for (int i = 0; i < CHILD_COUNT; i++) {
        childValues[i] = _children[i]->_attributeValue;
        allLeaves &= _children[i]->isLeaf();
    }
    if (attribute->merge(_attributeValue, childValues) && allLeaves) {
        clearChildren(attribute);
    }
}
Beispiel #9
0
void MetavoxelNode::read(const AttributePointer& attribute, Bitstream& in) {
    clearChildren(attribute);
    
    bool leaf;
    in >> leaf;
    attribute->read(in, _attributeValue, leaf);
    if (!leaf) {
        for (int i = 0; i < CHILD_COUNT; i++) {
            _children[i] = new MetavoxelNode(attribute);
            _children[i]->read(attribute, in);
        }
    }
}
Beispiel #10
0
void MetavoxelNode::writeDelta(const AttributePointer& attribute, const MetavoxelNode& reference, Bitstream& out) const {
    bool leaf = isLeaf();
    out << leaf;
    attribute->writeDelta(out, _attributeValue, reference._attributeValue, leaf);
    if (!leaf) {
        if (reference.isLeaf()) {
            for (int i = 0; i < CHILD_COUNT; i++) {
                _children[i]->write(attribute, out);
            }
        } else {
            for (int i = 0; i < CHILD_COUNT; i++) {
                if (_children[i] == reference._children[i]) {
                    out << false;
                } else {
                    out << true;
                    _children[i]->writeDelta(attribute, *reference._children[i], out);
                }
            }
        }
    }
}
OwnedAttributeValue::OwnedAttributeValue(const AttributePointer& attribute, void* value) :
    AttributeValue(attribute, attribute ? attribute->create(value) : NULL) {
}
AttributeValue::AttributeValue(const AttributePointer& attribute) :
    _attribute(attribute), _value(attribute ? attribute->getDefaultValue() : NULL) {
}