Commit 79de0bed authored by Robin Eschbach's avatar Robin Eschbach
Browse files

[ADD #77] toggle undo actions

parent 6a03ae8f
......@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <string>
#include <vector>
#include "WConnectorData.h"
......@@ -30,17 +31,16 @@
#include "action/WFiberActionAddFiber.h"
#include "action/WFiberActionRemoveVertex.h"
#include "action/WFiberActionRemoveFiber.h"
#include "action/WFiberActionToggle.h"
#include "WFiberHandler.h"
WFiberHandler::WFiberHandler( WMPointConnector* pointConnector )
{
m_pointConnector = pointConnector;
m_actionHandler = WActionHandler::SPtr( new WActionHandler() );
m_fibers = PCFiberListSPtr( new PCFiberList() );
m_fibers->push_back( PCFiber() );
m_hidden = boost::shared_ptr< std::vector< bool > >( new std::vector< bool >() );
m_selectedFiber = 0;
m_fiberCount = 1;
......@@ -105,10 +105,11 @@ void WFiberHandler::createProperties( WPropertyGroup::SPtr properties )
WPropertyGroup::SPtr undoGroup = properties->addPropertyGroup( "Undo | Redo", "Property group for undo and redo." );
m_possibleFiberSelections = WItemSelection::SPtr( new WItemSelection() );
m_possibleFiberSelections->addItem( ItemType::create( "Fiber 1", "Fiber 1", "", NULL ) );
m_fiberSelection = fiberGroup->addProperty(
"Selected Line", "The line to which the points are added", m_possibleFiberSelections->getSelectorFirst(), notifier );
"Selected Line", "The line to which the points are added", m_possibleFiberSelections->getSelectorNone(), notifier );
addFiber( "Fiber 1", true );
WPropertyHelper::PC_SELECTONLYONE::addTo( m_fiberSelection );
WPropertyHelper::PC_NOTEMPTY::addTo( m_fiberSelection );
......@@ -129,6 +130,8 @@ static bool sortComparator( boost::shared_ptr< WItemSelectionItem > a, boost::sh
void WFiberHandler::addFiber( std::string name, bool silent )
{
m_fibers->push_back( PCFiber() );
m_hidden->push_back( false );
m_possibleFiberSelections->addItem( ItemType::create( name, name, "", NULL ) );
m_fiberSelection->set( m_possibleFiberSelections->getSelectorLast() );
......@@ -138,9 +141,10 @@ void WFiberHandler::addFiber( std::string name, bool silent )
}
}
void WFiberHandler::addFiberAt( std::string name, size_t position, bool silent, PCFiber fiber )
void WFiberHandler::addFiberAt( std::string name, size_t position, bool hidden, bool silent, PCFiber fiber )
{
m_fibers->emplace( m_fibers->begin() + position, fiber );
m_hidden->emplace( m_hidden->begin() + position, hidden );
m_possibleFiberSelections->addItem( ItemType::create( name, name, "", NULL ) );
m_possibleFiberSelections->stableSort( &sortComparator );
......@@ -168,7 +172,10 @@ void WFiberHandler::removeFiber( size_t idx, bool silent )
std::string name = m_possibleFiberSelections->at( idx )->getName();
PCFiber fiber = m_fibers->at( idx );
bool hidden = m_hidden->at( idx );
m_fibers->erase( m_fibers->begin() + idx );
m_hidden->erase( m_hidden->begin() + idx );
m_possibleFiberSelections->remove( m_possibleFiberSelections->at( idx ) );
m_fiberSelection->set( m_possibleFiberSelections->getSelectorLast() );
......@@ -177,7 +184,7 @@ void WFiberHandler::removeFiber( size_t idx, bool silent )
if( !silent )
{
m_actionHandler->pushAction( WFiberActionRemoveFiber::SPtr( new WFiberActionRemoveFiber( name, idx, fiber , this ) ) );
m_actionHandler->pushAction( WFiberActionRemoveFiber::SPtr( new WFiberActionRemoveFiber( name, idx, fiber, hidden, this ) ) );
}
}
......@@ -188,24 +195,28 @@ void WFiberHandler::toggleFiber( size_t idx, bool silent )
if( isHidden( idx ) )
{
name = name.substr( 0, name.size() - 2 );
m_hidden.erase( std::remove( m_hidden.begin(), m_hidden.end(), idx ), m_hidden.end() );
}
else
{
name = name + " *";
m_hidden.push_back( idx );
}
m_hidden->at( idx ) = !( m_hidden->at( idx ) );
m_possibleFiberSelections->replace( selection, ItemType::create( name, name, "", NULL ) );
m_fiberSelection->set( m_possibleFiberSelections->getSelector( idx ) );
m_pointConnector->updatePoints();
m_pointConnector->updateOutput();
if( !silent )
{
m_actionHandler->pushAction( WFiberActionToggle::SPtr( new WFiberActionToggle( idx , this ) ) );
}
}
bool WFiberHandler::isHidden( size_t idx )
{
return std::find( m_hidden.begin(), m_hidden.end(), idx ) != m_hidden.end();
return m_hidden->at( idx );
}
void WFiberHandler::selectFiber( size_t idx )
......
......@@ -120,10 +120,11 @@ public:
* Adds a new or an old fiber at a specific position.
* \param name The name of the fiber.
* \param position The position of the fiber.
* \param hidden Whether the fiber is hidden or not.
* \param silent Whether or not this should add to the undo stack.
* \param fiber The fiber to add.
*/
void addFiberAt( std::string name, size_t position, bool silent = false, PCFiber fiber = PCFiber() );
void addFiberAt( std::string name, size_t position, bool hidden, bool silent = false, PCFiber fiber = PCFiber() );
/**
* Removes a fiber at an index in the fibers vector.
......@@ -263,9 +264,9 @@ private:
PCFiberListSPtr m_fibers;
/**
* Vector of the hidden fiber indecies.
* Vector for the visibility of the fibers.
*/
std::vector< size_t > m_hidden;
boost::shared_ptr< std::vector< bool > > m_hidden;
};
#endif // WFIBERHANDLER_H
......@@ -180,6 +180,17 @@ void WMPointConnector::handleInput()
void WMPointConnector::updatePoints()
{
if( m_pointRenderer == NULL )
{
return;
}
if( m_connectorData->getVertices()->size() == 0 )
{
m_pointOutput->updateData( NULL );
return;
}
WDataSetPoints::VertexArray vertices( new std::vector< float > );
WDataSetPoints::VertexArray colors( new std::vector< float > );
......@@ -200,7 +211,8 @@ void WMPointConnector::updatePoints()
{
colors->push_back( 0.0 );
}
else {
else
{
colors->push_back( color.w() );
}
}
......@@ -302,6 +314,11 @@ float WMPointConnector::hitVertex( osg::Vec3 rayStart, osg::Vec3 rayDir, osg::Ve
void WMPointConnector::updateOutput()
{
if( m_fiberDisplay == NULL )
{
return;
}
boost::shared_ptr< std::vector< float > > vertices = boost::shared_ptr< std::vector< float > >( new std::vector< float >() );
boost::shared_ptr< std::vector< float > > colors = boost::shared_ptr< std::vector< float > >( new std::vector< float >() );
boost::shared_ptr< std::vector< size_t > > lineStartIndexes = boost::shared_ptr< std::vector< size_t > >( new std::vector< size_t >() );
......@@ -319,6 +336,7 @@ void WMPointConnector::updateOutput()
{
color[1] = 1.0;
}
if( m_fiberHandler->isHidden( idx ) )
{
color[3] = 0.0;
......@@ -349,7 +367,13 @@ void WMPointConnector::updateOutput()
)
);
fibers->addColorScheme( colors, "Energy deposition", "Color fibers based on their energy." );
if( vertices->size() == 0 )
{
m_fiberOutput->updateData( NULL );
return;
}
fibers->addColorScheme( colors, "Connection", "Color fibers based on their connection." );
fibers->setSelectedColorScheme( 3 );
m_fiberOutput->updateData( fibers );
}
......
......@@ -26,10 +26,12 @@
#include "WFiberActionRemoveFiber.h"
WFiberActionRemoveFiber::WFiberActionRemoveFiber( std::string name, size_t position, WFiberHandler::PCFiber fiber, WFiberHandler* fiberHandler ):
WFiberActionRemoveFiber::WFiberActionRemoveFiber(
std::string name, size_t position, WFiberHandler::PCFiber fiber, bool hidden, WFiberHandler* fiberHandler ):
m_name( name ),
m_position( position ),
m_fiber( fiber ),
m_hidden( hidden ),
m_fiberHandler( fiberHandler )
{
}
......@@ -40,7 +42,7 @@ WFiberActionRemoveFiber::~WFiberActionRemoveFiber()
void WFiberActionRemoveFiber::undo()
{
m_fiberHandler->addFiberAt( m_name, m_position, true, m_fiber );
m_fiberHandler->addFiberAt( m_name, m_position, m_hidden, true, m_fiber );
}
void WFiberActionRemoveFiber::redo()
......
......@@ -49,9 +49,10 @@ public:
* \param name The name of the fiber.
* \param position The position of this fiber in the fibers vector.
* \param fiber The fiber that was removed.
* \param hidden If the fiber was hidden.
* \param fiberHandler The WFiberHandler of the action.
*/
WFiberActionRemoveFiber( std::string name, size_t position, WFiberHandler::PCFiber fiber, WFiberHandler* fiberHandler );
WFiberActionRemoveFiber( std::string name, size_t position, WFiberHandler::PCFiber fiber, bool hidden, WFiberHandler* fiberHandler );
/**
* Empty destructor.
......@@ -84,6 +85,11 @@ private:
*/
WFiberHandler::PCFiber m_fiber;
/**
* Whether the fiber is hidden.
*/
bool m_hidden;
/**
* The WFiberHandler of the action.
*/
......
......@@ -34,7 +34,7 @@
#include "../WFiberHandler.h"
/**
* The action when adding a Vertex.
* The action when removing a Vertex.
*/
class WFiberActionRemoveVertex : public WFiberAction
{
......
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#include <string>
#include "WFiberActionToggle.h"
WFiberActionToggle::WFiberActionToggle( size_t position, WFiberHandler* fiberHandler ):
m_position( position ),
m_fiberHandler( fiberHandler )
{
}
WFiberActionToggle::~WFiberActionToggle()
{
}
void WFiberActionToggle::undo()
{
m_fiberHandler->toggleFiber( m_position, true );
}
void WFiberActionToggle::redo()
{
m_fiberHandler->toggleFiber( m_position, true );
}
//---------------------------------------------------------------------------
//
// Project: OpenWalnut ( http://www.openwalnut.org )
//
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------
#ifndef WFIBERACTIONTOGGLE_H
#define WFIBERACTIONTOGGLE_H
#include <string>
#include <boost/shared_ptr.hpp>
#include <osg/Geode>
#include "WFiberAction.h"
#include "../WFiberHandler.h"
/**
* The action when toggling a fiber.
*/
class WFiberActionToggle : public WFiberAction
{
public:
/**
* A shared_ptr to this class.
*/
typedef boost::shared_ptr< WFiberActionToggle > SPtr;
/**
* Creates this action.
* \param position The position of this fiber in the fibers vector.
* \param fiberHandler The WFiberHandler of the action.
*/
WFiberActionToggle( size_t position, WFiberHandler* fiberHandler );
/**
* Empty destructor.
*/
~WFiberActionToggle();
/**
* Undos this action.
*/
virtual void undo();
/**
* Redos this action.
*/
virtual void redo();
private:
/**
* The position of this fiber in the fibers vector.
*/
size_t m_position;
/**
* The WFiberHandler of the action.
*/
WFiberHandler* m_fiberHandler;
};
#endif // WFIBERACTIONTOGGLE_H
......@@ -103,7 +103,7 @@ varying float v_vertexDepthDiff;
*/
void main()
{
if ( gl_Color.a == 0.0 )
if( gl_Color.a == 0.0 )
discard;
// create a sphere
......
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