Added the possibility of restoring a selection with an Or or an And wrt to the current selection (quite useful to preserve something and combine multiple selections)

This commit is contained in:
Paolo Cignoni 2017-06-16 01:37:37 +02:00
parent 25a1801c98
commit f8c6030b2a
1 changed files with 32 additions and 24 deletions

View File

@ -69,10 +69,19 @@ public:
bool popOr() bool popOr()
{ {
return pop(true); return pop(true,false);
} }
bool pop(bool mergeFlag=false) bool popAnd()
{
return pop(false,true);
}
/// It restore a saved selection.
/// The process can be done or in a straightforward manner (e.g. selection values are substituted)
/// or preserving selected or unselected elements (e.g. the restoring is combined in OR/AND)
///
bool pop(bool orFlag=false, bool andFlag=false)
{ {
if(vsV.empty()) return false; if(vsV.empty()) return false;
vsHandle vsH = vsV.back(); vsHandle vsH = vsV.back();
@ -80,37 +89,36 @@ public:
fsHandle fsH = fsV.back(); fsHandle fsH = fsV.back();
if(! (Allocator<ComputeMeshType>::template IsValidHandle(*_m, vsH))) return false; if(! (Allocator<ComputeMeshType>::template IsValidHandle(*_m, vsH))) return false;
typename ComputeMeshType::VertexIterator vi; for(auto vi = _m->vert.begin(); vi != _m->vert.end(); ++vi)
for(vi = _m->vert.begin(); vi != _m->vert.end(); ++vi)
if( !(*vi).IsD() ) if( !(*vi).IsD() )
{ {
if(vsH[*vi]) if(vsH[*vi]) {
(*vi).SetS(); if(!andFlag) (*vi).SetS();
else } else {
if(!mergeFlag) if(!orFlag) (*vi).ClearS();
(*vi).ClearS(); }
} }
typename ComputeMeshType::EdgeIterator ei; for(auto ei = _m->edge.begin(); ei != _m->edge.end(); ++ei)
for(ei = _m->edge.begin(); ei != _m->edge.end(); ++ei)
if( !(*ei).IsD() ) if( !(*ei).IsD() )
{ {
if(esH[*ei]) if(vsH[*ei]) {
(*ei).SetS(); if(!andFlag) (*ei).SetS();
else } else {
if(!mergeFlag) if(!orFlag) (*ei).ClearS();
(*ei).ClearS(); }
} }
typename ComputeMeshType::FaceIterator fi;
for(fi = _m->face.begin(); fi != _m->face.end(); ++fi)
for(auto fi = _m->face.begin(); fi != _m->face.end(); ++fi)
if( !(*fi).IsD() ) if( !(*fi).IsD() )
{ {
if(fsH[*fi]) if(vsH[*fi]) {
(*fi).SetS(); if(!andFlag) (*fi).SetS();
else } else {
if(!mergeFlag) if(!orFlag) (*fi).ClearS();
(*fi).ClearS(); }
} }
Allocator<ComputeMeshType>::template DeletePerVertexAttribute<bool>(*_m,vsH); Allocator<ComputeMeshType>::template DeletePerVertexAttribute<bool>(*_m,vsH);
Allocator<ComputeMeshType>::template DeletePerEdgeAttribute<bool>(*_m,esH); Allocator<ComputeMeshType>::template DeletePerEdgeAttribute<bool>(*_m,esH);