Commit a3fa1064 authored by Christian Schulte zu Berge's avatar Christian Schulte zu Berge Committed by Hossain Mahmud

Added AutoEvaluationPipeline also monitoring PropertyCollection's...

Added AutoEvaluationPipeline also monitoring PropertyCollection's s_propertyAdded and s_propertyRemoved signals.
parent 65cc4f5f
......@@ -150,6 +150,10 @@ namespace campvis {
void AutoEvaluationPipeline::findDataNamePropertiesAndAddToPortMap(const HasPropertyCollection* hpc) {
const PropertyCollection& pc = hpc->getProperties();
// const_cast okay, since we're just connecting to signals
const_cast<HasPropertyCollection*>(hpc)->s_propertyAdded.connect(this, &AutoEvaluationPipeline::onPropertyCollectionPropertyAdded);
const_cast<HasPropertyCollection*>(hpc)->s_propertyRemoved.connect(this, &AutoEvaluationPipeline::onPropertyCollectionPropertyRemoved);
// traverse property collection
for (size_t i = 0; i < pc.size(); ++i) {
if (DataNameProperty* dnp = dynamic_cast<DataNameProperty*>(pc[i])) {
......@@ -171,4 +175,56 @@ namespace campvis {
}
}
void AutoEvaluationPipeline::onPropertyCollectionPropertyAdded(AbstractProperty* property) {
// check whether the incoming property is of the correct type (we only care about DataNameProperties)
if (DataNameProperty* dnp = dynamic_cast<DataNameProperty*>(property)) {
// check whether this property is already present in the port map
IteratorMapType::iterator it = _iteratorMap.find(dnp);
if (it == _iteratorMap.end()) {
// add to port map and register to changed signal
if (dnp->getAccessInfo() == DataNameProperty::READ) {
tbb::spin_rw_mutex::scoped_lock lock(_pmMutex, false);
std::pair<PortMapType::iterator, bool> result = _portMap.insert(std::make_pair(dnp->getValue(), dnp));
cgtAssert(result.second, "Could not insert Property into port map!");
if (result.second) {
_iteratorMap[dnp] = result.first;
dnp->s_changed.connect(this, &AutoEvaluationPipeline::onDataNamePropertyChanged);
}
}
}
else {
// this should not happen, otherwise we did something wrong before.
cgtAssert(false, "This property is already in iterator map!");
}
}
}
void AutoEvaluationPipeline::onPropertyCollectionPropertyRemoved(AbstractProperty* property) {
// check whether the incoming property is of the correct type (we only care about DataNameProperties)
if (DataNameProperty* dnp = dynamic_cast<DataNameProperty*>(property)) {
// find string-iterator pair for the given property
IteratorMapType::iterator it = _iteratorMap.find(dnp);
if (it != _iteratorMap.end()) {
if (dnp->getAccessInfo() == DataNameProperty::READ) {
// remove from port map and deregister from changed signal
dnp->s_changed.disconnect(this);
// acquire a write-lock since we erase the old value from our port map
tbb::spin_rw_mutex::scoped_lock lock(_pmMutex, true);
// remove the property from the port map
_portMap.unsafe_erase(it->second);
_iteratorMap.unsafe_erase(it);
}
}
else {
// this should not happen, otherwise we did something wrong before.
cgtAssert(false, "Could not find Property in iterator map!");
}
}
}
}
......@@ -92,6 +92,20 @@ namespace campvis {
*/
virtual void onDataContainerDataAdded(std::string name, DataHandle dh);
/**
* Callback when a property was added to one of the PropertyCollections.
* This property will be added to the port map.
* \param property Property that was added to the collection.
*/
virtual void onPropertyCollectionPropertyAdded(AbstractProperty* property);
/**
* Callback when a property was removed from one of the PropertyCollections.
* This property will be removed from the port map.
* \param property Property that was added removed from collection.
*/
virtual void onPropertyCollectionPropertyRemoved(AbstractProperty* property);
/**
* Recursively looks for all DataNameProperties in \a pc and adds them to the port map.
* If \a pc contains a MetaProperty, it will be seached recursively.
......
......@@ -142,7 +142,7 @@ namespace campvis {
void HasPropertyCollection::clearProperties() {
for (auto it = _properties.begin(); it != _properties.end(); ++it) {
(*it)->s_changed.disconnect(this);
s_propertyRemoved.emitSignal(*it);
s_propertyRemoved.triggerSignal(*it);
}
_properties.clear();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment