Commit 4580209e authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum

[MERGE]

parents 06b44e86 7370d3f2
......@@ -7,7 +7,7 @@ INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )
# Libraries for linking:
SET( QT_LIBS ${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
${QT_QTOPENGL_LIBRARY}
${QT_QTOPENGL_LIBRARY}
${QT_QTWEBKIT_LIBRARY} )
# add here all classes that inherit from QObject
......@@ -55,8 +55,10 @@ ENDIF()
QT4_WRAP_CPP(GUI_QT4_MOC_SRCS ${GUI_QT4_MOC_HDRS} )
FILE(GLOB GUI_QT4_SRC "*.cpp" "guiElements/*.cpp" "controlPanel/*.cpp" "events/*.cpp" "networkEditor/*.cpp" "*.h" "guiElements/*.h"
"controlPanel/*.h" "events/*.h" "networkEditor/*.h" "../icons/WIcons.h" "commandPrompt/*.h" "commandPrompt/*.cpp" )
FILE(GLOB GUI_QT4_SRC "*.cpp" "guiElements/*.cpp" "controlPanel/*.cpp" "events/*.cpp"
"networkEditor/*.cpp" "*.h" "guiElements/*.h" "networkEditor/layout/*.cpp"
"controlPanel/*.h" "events/*.h" "networkEditor/*.h" "../icons/WIcons.h" "commandPrompt/*.h"
"commandPrompt/*.cpp" "networkEditor/layout/*.h" )
IF( CMAKE_HOST_SYSTEM MATCHES Darwin )
FILE( GLOB GUIQT4_PLATFORMDEPENDENT_SRC
"platformDependent/WQtGLWidgetMac.cpp"
......
......@@ -157,3 +157,4 @@ void WQtNetworkArrow::changeColor( QColor color )
m_color = color;
setPen( QPen( m_color, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
}
......@@ -117,6 +117,7 @@ public:
*/
QVariant itemChange( GraphicsItemChange change, const QVariant &value );
protected:
/**
......
......@@ -28,8 +28,6 @@
#include <boost/shared_ptr.hpp>
#include <QtGui/QDockWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QKeyEvent>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsItem>
......@@ -59,27 +57,27 @@ WQtNetworkEditor::WQtNetworkEditor( WMainWindow* parent )
setObjectName( "Module Graph Dock" );
m_mainWindow = parent;
m_panel = new QWidget( this );
QWidget *panel = new QWidget( this );
m_view = new QGraphicsView();
m_view->setDragMode( QGraphicsView::RubberBandDrag );
m_view->setRenderHint( QPainter::Antialiasing );
m_view->setMinimumSize( 20, 20 );
QGraphicsView *view = new QGraphicsView();
view->setDragMode( QGraphicsView::RubberBandDrag );
view->setRenderHint( QPainter::Antialiasing );
view->setMinimumSize( 20, 20 );
m_scene = new WQtNetworkScene();
// m_scene->setSceneRect( -200.0, -200.0, 400.0, 400.0 );
m_scene->setSceneRect( m_scene->itemsBoundingRect() );
m_view->setScene( m_scene );
view->setScene( m_scene );
m_layout = new QVBoxLayout;
m_layout->addWidget( m_view );
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget( view );
m_panel->setLayout( m_layout );
panel->setLayout( layout );
this->setAllowedAreas( Qt::AllDockWidgetAreas );
this->setFeatures( QDockWidget::DockWidgetClosable |QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable );
setWidget( m_panel );
setWidget( panel );
connect( m_scene, SIGNAL( selectionChanged() ), this, SLOT( selectItem() ) );
// this fakeitem is added to the scene to get a better behavior of the forced
......@@ -92,10 +90,13 @@ WQtNetworkEditor::WQtNetworkEditor( WMainWindow* parent )
fake->setFlag( QGraphicsItem::ItemIsMovable, true );
m_scene->addItem( fake );
m_scene->setFakeItem( fake );
m_layout = new WNetworkLayout();
}
WQtNetworkEditor::~WQtNetworkEditor()
{
delete m_layout;
}
void WQtNetworkEditor::selectItem()
......@@ -180,7 +181,7 @@ void WQtNetworkEditor::addModule( boost::shared_ptr< WModule > module )
m_scene->addItem( netItem );
itemMoved();
//itemMoved();
}
bool WQtNetworkEditor::event( QEvent* event )
......@@ -194,7 +195,11 @@ bool WQtNetworkEditor::event( QEvent* event )
{
WLogger::getLogger()->addLogMessage( "Inserting \"" + e1->getModule()->getName() + "\".",
"NetworkEditor", LL_DEBUG );
addModule( e1->getModule() );
//addModule( e1->getModule() );
WQtNetworkItem *item = new WQtNetworkItem( this, e1->getModule() );
m_items.push_back( item );
m_layout->addItem( item );
m_scene->addItem( item );
}
//TODO(skiunke): disablen des moduls solange nicht rdy!
......@@ -240,8 +245,8 @@ bool WQtNetworkEditor::event( QEvent* event )
return true;
}
WLogger::getLogger()->addLogMessage( "Connecting \"" + e->getInput()->getModule()->getName() + "\" and \"" +
e->getOutput()->getModule()->getName() + "\".", "NetworkEditor", LL_DEBUG );
WLogger::getLogger()->addLogMessage( "Connecting \"" + e->getInput()->getModule()->getName() +
"\" and \"" + e->getOutput()->getModule()->getName() + "\".", "NetworkEditor", LL_DEBUG );
boost::shared_ptr< WModule > mIn;
boost::shared_ptr< WModule > mOut;
......@@ -303,6 +308,8 @@ bool WQtNetworkEditor::event( QEvent* event )
arrow->updatePosition();
m_scene->addItem( arrow );
m_layout->connectItems( outItem, inItem );
}
}
......@@ -388,6 +395,8 @@ bool WQtNetworkEditor::event( QEvent* event )
}
if ( ar )
{
m_layout->disconnectItem( inItem );
op->removeArrow( ar );
ip->removeArrow( ar );
if( ar->scene() != NULL )
......@@ -450,6 +459,8 @@ bool WQtNetworkEditor::event( QEvent* event )
if( item != 0 )
{
m_layout->removeItem( item );
if( item->scene() != NULL )
{
m_scene->removeItem( item );
......@@ -469,8 +480,7 @@ WQtNetworkItem* WQtNetworkEditor::findItemByModule( boost::shared_ptr< WModule >
for( QList< WQtNetworkItem* >::const_iterator iter = m_items.begin(); iter != m_items.end(); ++iter )
{
WQtNetworkItem *itemModule = dynamic_cast< WQtNetworkItem* >( *iter );
if( itemModule &&
itemModule->getModule() == module )
if( itemModule && itemModule->getModule() == module )
{
return itemModule;
}
......@@ -486,29 +496,29 @@ void WQtNetworkEditor::itemMoved()
void WQtNetworkEditor::timerEvent( QTimerEvent *event )
{
Q_UNUSED( event );
QList< WQtNetworkItem *> items;
foreach( QGraphicsItem *item, m_scene->items() )
{
if ( WQtNetworkItem *netItem = dynamic_cast< WQtNetworkItem *>( item ) )
items << netItem;
}
foreach( WQtNetworkItem *netItem, items )
netItem->calculateForces();
bool itemsMoved = false;
foreach( WQtNetworkItem *netItem, items )
{
if ( netItem->advance() )
itemsMoved = true;
}
if ( !itemsMoved )
{
killTimer( timerId );
timerId = 0;
}
//Q_UNUSED( event );
//QList< WQtNetworkItem *> items;
//foreach( QGraphicsItem *item, m_scene->items() )
//{
// if ( WQtNetworkItem *netItem = dynamic_cast< WQtNetworkItem *>( item ) )
// items << netItem;
//}
//foreach( WQtNetworkItem *netItem, items )
// netItem->calculateForces();
//bool itemsMoved = false;
//foreach( WQtNetworkItem *netItem, items )
//{
// if ( netItem->advance() )
// itemsMoved = true;
//}
//if ( !itemsMoved )
//{
// killTimer( timerId );
// timerId = 0;
//}
}
......@@ -37,11 +37,13 @@
#include "../../../kernel/modules/data/WMData.h"
#include "../WQtCombinerToolbar.h"
#include "WQtNetworkScene.h"
#include "layout/WNetworkLayout.h"
#include "WQtNetworkItem.h"
#include "WQtNetworkScene.h"
// forward declaration
class WMainWindow;
class WNetworkLayout;
/**
* Container widget to hold the WQtNetworkScene
......@@ -121,11 +123,13 @@ private:
WQtNetworkScene* m_scene; //!< QGraphicsScene
QGraphicsView* m_view; //!< QGraphicsView
//QGraphicsView* m_view; //!< QGraphicsView
WNetworkLayout *m_layout; //!< the object that handels the layout
QWidget* m_panel; //!< panel
//QWidget* m_panel; //!< panel
QVBoxLayout* m_layout; //!< layout
//QVBoxLayout* m_layout; //!< layout
QList< WQtNetworkItem* > m_items; //!< a list of the WQtNetworkItems in the WQtNetworkScene
......
......@@ -235,6 +235,11 @@ QList< WQtNetworkOutputPort *> WQtNetworkItem::getOutPorts()
return m_outPorts;
}
WNetworkLayoutItem * WQtNetworkItem::getLayoutItem()
{
return m_layoutItem;
}
void WQtNetworkItem::fitLook()
{
if( m_text != 0)
......@@ -425,3 +430,4 @@ bool WQtNetworkItem::advance()
return true;
}
......@@ -29,11 +29,14 @@
#include <QtGui/QGraphicsTextItem>
#include <QtGui/QPainter>
#include <QtGui/QColor>
#include "../../../kernel/WModule.h"
#include "layout/WNetworkLayoutItem.h"
#include "WQtNetworkInputPort.h"
#include "WQtNetworkOutputPort.h"
class WNetworkLayoutItem;
class WQtNetworkEditor;
class QGraphicsWidget;
......@@ -43,6 +46,7 @@ class QGraphicsWidget;
*/
class WQtNetworkItem : public QGraphicsRectItem
{
friend class WNetworkLayoutItem;
public:
/**
* Constructs new item in the network scene.
......@@ -123,6 +127,11 @@ public:
*/
boost::shared_ptr< WModule > getModule();
/**
* returns the layout item for this network item, layout item is set through the layout item (friend)
**/
WNetworkLayoutItem * getLayoutItem();
/**
* Here the module can be enabled when the WModule is ready.
* \param active true if module is ready.
......@@ -200,7 +209,6 @@ protected:
*/
void paint( QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* w );
private:
boost::shared_ptr< WModule > m_module; //!< the module
......@@ -221,10 +229,12 @@ private:
QGraphicsTextItem* m_text; //!< the caption
QGraphicsTextItem* m_subtitle; //!< the caption
QGraphicsTextItem *m_subtitle; //!< the caption
QPointF m_newPos; //!< the new position in the WQtNetworkScene
WQtNetworkEditor* m_networkEditor; //!< the related WQtNetworkEditor
WNetworkLayoutItem *m_layoutItem; //!< the layout item
};
#endif // WQTNETWORKITEM_H
//---------------------------------------------------------------------------
//
// 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 "WNetworkLayoutGlobals.h"
#include "WNetworkLayout.h"
WNetworkLayout::WNetworkLayout()
{
}
WNetworkLayout::~WNetworkLayout()
{
for( std::list< WNetworkLayoutItem * >::iterator iter = laneList.begin(); iter != laneList.end(); ++iter )
{
delete *iter;
}
}
void WNetworkLayout::addItem( WQtNetworkItem *item )
{
WNetworkLayoutItem *layoutItem = new WNetworkLayoutItem( item );
if( laneList.size() != 0 )
{
laneList.back()->setNeighbour( layoutItem );
QPointF pos( laneList.back()->getPos() );
pos.setX( pos.x() + laneList.back()->getWidth() );
layoutItem->setPos( pos );
}
else
{
layoutItem->setPos( QPointF( 0, 0 ) );
}
laneList.push_back( layoutItem );
}
void WNetworkLayout::connectItems( WQtNetworkItem *parent, WQtNetworkItem *child )
{
if( child->getLayoutItem()->getParent() == NULL )
{
// update linked list & move item into the parents lane
for( std::list< WNetworkLayoutItem * >::iterator iter = laneList.begin(); iter != laneList.end();
++iter )
{
if( ( *iter )->getNeighbour() == child->getLayoutItem() )
{
( *iter )->setNeighbour( child->getLayoutItem()->getNeighbour() );
}
}
}
child->getLayoutItem()->setParent( parent->getLayoutItem() );
laneList.pop_back();
}
void WNetworkLayout::disconnectItem( WQtNetworkItem *child )
{
// disconnect items
// move child to new lane
laneList.back()->setNeighbour( child->getLayoutItem() );
QPointF pos( laneList.back()->getPos() );
pos.setX( pos.x() + laneList.back()->getWidth() );
child->getLayoutItem()->disconnectFromParent( pos );
laneList.push_back( child->getLayoutItem() );
}
void WNetworkLayout::removeItem( WQtNetworkItem *item )
{
// remove the item:
// update lane info
if( item->getLayoutItem() == laneList.front() )
{
if( laneList.size() > 1 )
{
item->getLayoutItem()->getNeighbour()->setPos( item->getLayoutItem()->getPos() );
}
laneList.pop_front();
}
else
{
for( std::list< WNetworkLayoutItem * >::iterator iter = laneList.begin(); iter != laneList.end(); ++iter )
{
if( ( *iter )->getNeighbour() == item->getLayoutItem() )
{
( *iter )->setNeighbour( item->getLayoutItem()->getNeighbour() );
if( item->getLayoutItem()->getNeighbour() != NULL )
{
// update the position of all lanes( -> items ) following the removed item
( *iter )->getNeighbour()->setPos( item->getLayoutItem()->getPos() );
}
laneList.erase( ++iter );
break;
}
}
}
}
//---------------------------------------------------------------------------
//
// 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 WNETWORKLAYOUT_H
#define WNETWORKLAYOUT_H
#include <list>
#include "WNetworkLayoutItem.h"
/**
* TODO
**/
class WNetworkLayout
{
public:
/**
* constructor
**/
WNetworkLayout();
/**
* destructor
**/
~WNetworkLayout();
/**
* add an item to the layout, creates new network layout item
*
* /param item the new network item
**/
void addItem( WQtNetworkItem *item );
/**
* connect the two items, moves the 'end' item to the lane of 'start'
**/
void connectItems( WQtNetworkItem *start, WQtNetworkItem *end );
/**
* disconnects the child from the parent item and moves the item to a new, empty lane
**/
void disconnectItem( WQtNetworkItem *child );
/**
* remove an item from the layout, should only be called when in- and out-degree of the item
* equals zero, if this is not the case disconnect items beforehand
*
* \param item the item thats going to be removed
**/
void removeItem( WQtNetworkItem *item );
protected:
private:
//std::pair< WNetworkLayoutItem *, WNetworkLayoutItem * > laneList; //<! list allows iteration over lanes
bool m_array[30][1000];
std::list< WNetworkLayoutItem * > laneList; //<! list allows iteration over lanes
};
#endif // WNETWORKLAYOUT_H
//---------------------------------------------------------------------------
//
// 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 WNETWORKLAYOUTGLOBALS_H
#define WNETWORKLAYOUTGLOBALS_H
// The size of the grid
#define WNETWORKLAYOUT_GRIDSIZE 240
#endif // WNETWORKLAYOUTGLOBALS_H
//---------------------------------------------------------------------------
//
// 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 <QtCore/QPointF>
#include "WNetworkLayoutGlobals.h"
#include "WNetworkLayoutItem.h"
WNetworkLayoutItem::WNetworkLayoutItem( WQtNetworkItem *item )
{
m_item = item;
m_width = m_item->m_width * 1.2; // 20% is boarder
m_parent = NULL;
m_neighbour = NULL;
m_item->m_layoutItem = this;
}
WNetworkLayoutItem::~WNetworkLayoutItem()
{
for( std::list< WNetworkLayoutItem * >::iterator iter = children.begin(); iter != children.end(); ++iter )
{
delete *iter;
}
m_item->m_layoutItem = NULL;
}
void WNetworkLayoutItem::addChild( WNetworkLayoutItem *child, float width )
{
children.push_back( child );
if( children.size() > 1 )
{
m_width += width;
updateLayoutPos();
}
else
{
if( m_width != width )
{
m_width = width;
updateLayoutPos();
}
}
}
void WNetworkLayoutItem::disconnectFromParent( QPointF newPos )
{
m_parent->removeChild( this );
m_parent = NULL;
setPos( newPos );
}
WNetworkLayoutItem * WNetworkLayoutItem::getParent()
{
return m_parent;
}
WNetworkLayoutItem * WNetworkLayoutItem::getNeighbour()
{
return m_neighbour;