Commit 8dfd8683 authored by Jan Möbius's avatar Jan Möbius

Modified drawmodes for better support of the xor



git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15663 383ad7c9-94d9-4d36-a494-682f7c89f535
parent be6adfd3
......@@ -276,6 +276,8 @@ DrawMode& DrawMode::operator|=( const DrawMode& _mode2 ) {
for (unsigned int i = 0; i < _mode2.getNumLayers(); ++i)
addLayer(_mode2.getLayer(i));
assert(checkConsistency());
return (*this);
}
......@@ -290,6 +292,8 @@ DrawMode& DrawMode::operator&=( const DrawMode& _mode2 ) {
if (layerIndex2 < 0)
removeLayer(i);
}
assert(checkConsistency());
return (*this);
}
......@@ -370,9 +374,12 @@ DrawMode DrawMode::operator^( const DrawMode& _mode2 ) const {
// copy to temporary drawmode and return
xorMode.setDrawModeProperties(tmpLayers[0]);
for (unsigned int i = 0; i < tmpLayers.size(); ++i)
for (unsigned int i = 1; i < tmpLayers.size(); ++i)
xorMode.addLayer(tmpLayers[i]);
// assert(xorMode.checkConsistency());
return xorMode;
}
......@@ -411,6 +418,36 @@ std::string DrawMode::description() const
//----------------------------------------------------------------------------
void DrawMode::filter( DrawMode _filter )
{
modeFlags_ = (modeFlags_ | _filter.modeFlags_) ^ _filter.modeFlags_;
for (unsigned int i = 0; i < _filter.getNumLayers(); ++i)
{
int idx = getLayerIndex(_filter.getLayer(i));
removeLayer((unsigned int)idx);
}
}
//----------------------------------------------------------------------------
void DrawMode::combine( DrawMode _mode )
{
// XOR on bitflag
modeFlags_ = (modeFlags_ ^ _mode.modeFlags_);
// addLayer does redundancy check here
for (unsigned int i = 0; i < _mode.getNumLayers(); ++i)
addLayer(_mode.getLayer(i));
// assert(checkConsistency());
}
//----------------------------------------------------------------------------
std::vector< DrawMode >
DrawMode::getAtomicDrawModes() const
{
......@@ -467,8 +504,13 @@ void DrawMode::addLayer( const DrawModeProperties* _props )
bool DrawMode::removeLayer( unsigned int _i )
{
layers_.erase(layers_.begin() + _i);
return true;
if (_i < layers_.size())
{
layers_.erase(layers_.begin() + _i);
return true;
}
return false;
}
const DrawModeProperties* DrawMode::getDrawModeProperties() const
......@@ -479,10 +521,14 @@ const DrawModeProperties* DrawMode::getDrawModeProperties() const
bool DrawMode::checkConsistency() const
{
// PRIMITIVE_CELL is the last primitive count (currently)
//int count[PRIMITIVE_CELL+1] = {0};
for (unsigned int i = 0; i < layers_.size(); ++i)
{
for (unsigned int k = i+1; k < layers_.size(); ++k)
{
if (layers_[i].primitive() == layers_[k].primitive())
return false;
}
}
return true;
}
......
......@@ -364,6 +364,17 @@ namespace DrawModes {
* Otherwise the internal flag index will be returned
*/
unsigned int getIndex() const;
/** \brief filter out one drawmode
*
* This removes one or more drawmodes if this drawode is not atomic.
*/
void filter( DrawMode _filter );
/** \brief combine with another drawmode
*/
void combine( DrawMode _mode );
/** Get a description string for this DrawMode
* An empty string is returned if this is not a valid draw mode.
......
......@@ -697,12 +697,12 @@ void ViewControlPlugin::slotDrawModeSelected( QAction * _action) {
//======================================================================================
if ( _action->text() != USEGLOBALDRAWMODE ) {
// As this is not the global draw mode, filter out default as draw mode or it will interfere with the other modes!
activeDrawModes_ = ( ( activeDrawModes_ | ACG::SceneGraph::DrawModes::DEFAULT ) ^ ACG::SceneGraph::DrawModes::DEFAULT );
activeDrawModes_.filter(ACG::SceneGraph::DrawModes::DEFAULT);
// If shift is pressed, we combine the modes (and toggle therefore xor)
// Otherwise we directly take the new mode
if ( qApp->keyboardModifiers() & Qt::ShiftModifier )
activeDrawModes_ = ( activeDrawModes_ ^ mode);
activeDrawModes_.combine(mode);
else
{
emit hideContextMenu();
......
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