Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
d299dae5
Commit
d299dae5
authored
Apr 05, 2013
by
Mathias Goldau
Browse files
[MERGE]
parents
84dfec01
f5015eb1
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
248 additions
and
14 deletions
+248
-14
src/core/graphicsEngine/WROI.h
src/core/graphicsEngine/WROI.h
+5
-0
src/core/kernel/WRMBranch.cpp
src/core/kernel/WRMBranch.cpp
+5
-6
src/core/kernel/WRMBranch.h
src/core/kernel/WRMBranch.h
+20
-3
src/qt4gui/controlPanel/WQtBranchTreeItem.cpp
src/qt4gui/controlPanel/WQtBranchTreeItem.cpp
+51
-0
src/qt4gui/controlPanel/WQtBranchTreeItem.h
src/qt4gui/controlPanel/WQtBranchTreeItem.h
+4
-0
src/qt4gui/controlPanel/WQtControlPanel.cpp
src/qt4gui/controlPanel/WQtControlPanel.cpp
+49
-5
src/qt4gui/events/WEventTypes.h
src/qt4gui/events/WEventTypes.h
+4
-0
src/qt4gui/events/WRoiSortEvent.cpp
src/qt4gui/events/WRoiSortEvent.cpp
+44
-0
src/qt4gui/events/WRoiSortEvent.h
src/qt4gui/events/WRoiSortEvent.h
+66
-0
No files found.
src/core/graphicsEngine/WROI.h
View file @
d299dae5
...
...
@@ -43,6 +43,11 @@ class WPickHandler;
class
WROI
:
public
osg
::
Geode
{
public:
/**
* Ref Pointer type.
*/
typedef
osg
::
ref_ptr
<
WROI
>
RefPtr
;
WROI
();
/**
...
...
src/core/kernel/WRMBranch.cpp
View file @
d299dae5
...
...
@@ -85,13 +85,12 @@ void WRMBranch::addRoi( osg::ref_ptr< WROI > roi )
{
m_rois
.
push_back
(
roi
);
roi
->
addROIChangeNotifier
(
m_changeRoiSignal
);
setDirty
();
}
bool
WRMBranch
::
contains
(
osg
::
ref_ptr
<
WROI
>
roi
)
{
for
(
std
::
list
<
osg
::
ref_ptr
<
WROI
>
>::
iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
for
(
std
::
vector
<
osg
::
ref_ptr
<
WROI
>
>::
iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
{
if
(
(
*
iter
)
==
roi
)
{
...
...
@@ -104,7 +103,7 @@ bool WRMBranch::contains( osg::ref_ptr< WROI > roi )
void
WRMBranch
::
removeRoi
(
osg
::
ref_ptr
<
WROI
>
roi
)
{
roi
->
removeROIChangeNotifier
(
m_changeRoiSignal
);
for
(
std
::
list
<
osg
::
ref_ptr
<
WROI
>
>::
iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
for
(
std
::
vector
<
osg
::
ref_ptr
<
WROI
>
>::
iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
{
if
(
(
*
iter
)
==
roi
)
{
...
...
@@ -117,7 +116,7 @@ void WRMBranch::removeRoi( osg::ref_ptr< WROI > roi )
void
WRMBranch
::
getRois
(
std
::
vector
<
osg
::
ref_ptr
<
WROI
>
>&
roiVec
)
// NOLINT
{
for
(
std
::
list
<
osg
::
ref_ptr
<
WROI
>
>::
iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
for
(
std
::
vector
<
osg
::
ref_ptr
<
WROI
>
>::
iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
{
roiVec
.
push_back
(
(
*
iter
)
);
}
...
...
@@ -126,7 +125,7 @@ void WRMBranch::getRois( std::vector< osg::ref_ptr< WROI > >& roiVec ) // NOLINT
WROIManager
::
ROIs
WRMBranch
::
getRois
()
const
{
WROIManager
::
ROIs
ret
;
for
(
std
::
list
<
osg
::
ref_ptr
<
WROI
>
>::
const_iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
for
(
std
::
vector
<
osg
::
ref_ptr
<
WROI
>
>::
const_iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
{
ret
.
push_back
(
(
*
iter
)
);
}
...
...
@@ -135,7 +134,7 @@ WROIManager::ROIs WRMBranch::getRois() const
void
WRMBranch
::
removeAllRois
()
{
for
(
std
::
list
<
osg
::
ref_ptr
<
WROI
>
>::
iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
for
(
std
::
vector
<
osg
::
ref_ptr
<
WROI
>
>::
iterator
iter
=
m_rois
.
begin
();
iter
!=
m_rois
.
end
();
++
iter
)
{
WGraphicsEngine
::
getGraphicsEngine
()
->
getScene
()
->
remove
(
(
*
iter
)
);
}
...
...
src/core/kernel/WRMBranch.h
View file @
d299dae5
...
...
@@ -25,6 +25,7 @@
#ifndef WRMBRANCH_H
#define WRMBRANCH_H
#include <algorithm>
#include <list>
#include <string>
#include <vector>
...
...
@@ -186,7 +187,6 @@ public:
*/
void
addChangeNotifier
(
boost
::
shared_ptr
<
boost
::
function
<
void
()
>
>
notifier
);
/**
* Remove a specified notifier from the list of default notifiers which get connected to each branch
*
...
...
@@ -194,6 +194,15 @@ public:
*/
void
removeChangeNotifier
(
boost
::
shared_ptr
<
boost
::
function
<
void
()
>
>
notifier
);
/**
* Resorts the ROIs using the specified comparator from its begin to its end.
*
* \tparam Comparator the comparator type. Usually a boost::function or class providing the operator<().
*
* \param comp the comparator
*/
template
<
typename
Comparator
>
void
sort
(
Comparator
comp
);
protected:
/**
...
...
@@ -209,8 +218,8 @@ protected:
private:
boost
::
shared_ptr
<
WROIManager
>
m_roiManager
;
//!< stores a pointer to the roi manager
std
::
list
<
osg
::
ref_ptr
<
WROI
>
>
m_rois
;
//!< list of rois in this this branch,
// first in the list is the master roi
std
::
vector
<
osg
::
ref_ptr
<
WROI
>
>
m_rois
;
//!< list of rois in this this branch,
// first in the list is the master roi
/**
* the property object for the module
*/
...
...
@@ -265,4 +274,12 @@ inline bool WRMBranch::isNot()
{
return
m_isNot
->
get
();
}
template
<
typename
Comparator
>
void
WRMBranch
::
sort
(
Comparator
comp
)
{
// NOTE: technically, we need not setDirty here as the order of the ROIs has no influence
return
std
::
sort
(
m_rois
.
begin
(),
m_rois
.
end
(),
comp
);
}
#endif // WRMBRANCH_H
src/qt4gui/controlPanel/WQtBranchTreeItem.cpp
View file @
d299dae5
...
...
@@ -23,6 +23,7 @@
//---------------------------------------------------------------------------
#include <string>
#include <map>
#include <QtCore/QList>
#include <QtGui/QScrollArea>
...
...
@@ -143,3 +144,53 @@ QWidget* WQtBranchTreeItem::getWidget() const
return
m_itemWidget
;
}
/**
* Simple comparator class for sorting ROIs in the Roi Manager.
*/
class
RoiSort
{
public:
/**
* COnstructor.
*
* \param indexMap the map is used to compare each ROI with their Qt index.
*/
explicit
RoiSort
(
std
::
map
<
WROI
::
RefPtr
,
int
>
indexMap
)
:
m_indexMap
(
indexMap
)
{
// nothing else to initialize
}
/**
* Operator to compare the order of two ROIs
*
* \param a first ROI
* \param b second ROI
*
* \return true if first is in front of second
*/
bool
operator
()(
WROI
::
RefPtr
a
,
WROI
::
RefPtr
b
)
{
return
(
m_indexMap
[
a
]
<
m_indexMap
[
b
]
);
}
private:
/**
* Map needed to know the index in the GUI representation
*/
std
::
map
<
WROI
::
RefPtr
,
int
>
m_indexMap
;
};
void
WQtBranchTreeItem
::
updateRoiManagerSorting
()
{
std
::
map
<
WROI
::
RefPtr
,
int
>
indexMap
;
// build an index map for each roi to its item
for
(
int
i
=
0
;
i
<
childCount
();
++
i
)
{
WQtRoiTreeItem
*
rti
=
dynamic_cast
<
WQtRoiTreeItem
*
>
(
child
(
i
)
);
WAssert
(
rti
,
"All children of a branch item need to be ROI items."
);
indexMap
[
rti
->
getRoi
()
]
=
i
;
}
// this map now allows to start a comparator
m_branch
->
sort
(
RoiSort
(
indexMap
)
);
}
src/qt4gui/controlPanel/WQtBranchTreeItem.h
View file @
d299dae5
...
...
@@ -77,6 +77,10 @@ public:
*/
QWidget
*
getWidget
()
const
;
/**
* Update internal Roi Manager sorting using the sorting of the children of this tree item.
*/
void
updateRoiManagerSorting
();
protected:
private:
boost
::
shared_ptr
<
WRMBranch
>
m_branch
;
//!< ROI
...
...
src/qt4gui/controlPanel/WQtControlPanel.cpp
View file @
d299dae5
...
...
@@ -30,6 +30,7 @@
#include <vector>
#include <QtCore/QList>
#include <QtCore/QCoreApplication>
#include <QtGui/QMenu>
#include <QtGui/QScrollArea>
#include <QtGui/QShortcut>
...
...
@@ -59,6 +60,7 @@
#include "../events/WModuleRemovedEvent.h"
#include "../events/WRoiAssocEvent.h"
#include "../events/WRoiRemoveEvent.h"
#include "../events/WRoiSortEvent.h"
#include "../guiElements/WQtModuleMetaInfo.h"
#include "../guiElements/WQtMenuFiltered.h"
#include "../networkEditor/WQtNetworkEditor.h"
...
...
@@ -276,6 +278,16 @@ bool WQtControlPanel::event( QEvent* event )
return
true
;
}
if
(
event
->
type
()
==
WQT_ROI_SORT_EVENT
)
{
WRoiSortEvent
*
e3
=
dynamic_cast
<
WRoiSortEvent
*
>
(
event
);
if
(
e3
)
{
e3
->
getBranch
()
->
updateRoiManagerSorting
();
}
return
true
;
}
// a module got associated with the root container -> add it to the list
if
(
event
->
type
()
==
WQT_ASSOC_EVENT
)
...
...
@@ -1247,11 +1259,17 @@ void WQtControlPanel::selectUpperMostEntry()
m_tiModules
->
setSelected
(
true
);
}
void
WQtControlPanel
::
handleRoiDragDrop
(
QDropEvent
*
event
)
void
WQtControlPanel
::
handleRoiDragDrop
(
QDropEvent
*
/*
event
*/
)
{
WROI
::
RefPtr
droppedRoi
;
WRMBranch
::
SPtr
droppedBranch
;
WQtBranchTreeItem
*
droppedBranchTreeItem
=
NULL
;
for
(
int
branchID
=
0
;
branchID
<
m_tiRois
->
childCount
();
++
branchID
)
{
QTreeWidgetItem
*
branchTreeItem
=
m_tiRois
->
child
(
branchID
);
WQtBranchTreeItem
*
branchTreeItem
=
dynamic_cast
<
WQtBranchTreeItem
*
>
(
m_tiRois
->
child
(
branchID
)
);
// go through each roi
for
(
int
roiID
=
0
;
roiID
<
branchTreeItem
->
childCount
();
++
roiID
)
{
WQtRoiTreeItem
*
roiTreeItem
=
dynamic_cast
<
WQtRoiTreeItem
*
>
(
branchTreeItem
->
child
(
roiID
)
);
...
...
@@ -1260,18 +1278,44 @@ void WQtControlPanel::handleRoiDragDrop( QDropEvent* event )
QWidget
*
w
=
m_roiTreeWidget
->
itemWidget
(
roiTreeItem
,
0
);
if
(
!
w
)
{
// let us hope that this really is the dropped item
w
=
roiTreeItem
->
createWidget
();
m_roiTreeWidget
->
setItemWidget
(
roiTreeItem
,
0
,
w
);
m_roiTreeWidget
->
setCurrentItem
(
roiTreeItem
);
// NOTE: there is a bug. After setting the new widget. the treewidget does not update the size of the item. To force this, we
// collapse and expand the branch here
// we need this later: the dropped ROI
droppedRoi
=
roiTreeItem
->
getRoi
();
droppedBranch
=
branchTreeItem
->
getBranch
();
droppedBranchTreeItem
=
branchTreeItem
;
// NOTE: there is a bug. After setting the new widget, the treewidget does not update the size of the item. To force this, we
// collapse and expand the branch here. It looks like expanding is enough.
// roiTreeItem->setSizeHint( 0, w->sizeHint() );
//roiTreeItem->parent()->setExpanded( false );
//
roiTreeItem->parent()->setExpanded( false );
roiTreeItem
->
parent
()
->
setExpanded
(
true
);
}
}
}
// something went wrong
if
(
!
(
droppedBranch
&&
droppedBranchTreeItem
)
)
{
wlog
::
error
(
"WQtControlPanel::handleRoiDragDrop"
)
<<
"Was not able to find dropped ROI item. This should not happen!"
;
}
// as the current branch/Roi code is quite ugly ... we need some manual re-sorting and re-inserting stuff
WRMBranch
::
SPtr
realParent
=
WKernel
::
getRunningKernel
()
->
getRoiManager
()
->
getBranch
(
droppedRoi
);
if
(
realParent
!=
droppedBranch
)
{
// ROI changed in branch:
realParent
->
removeRoi
(
droppedRoi
);
droppedBranch
->
addRoi
(
droppedRoi
);
}
// initiate re-sorting the widget items. We cannot do this directly, as we might have changed the ROI parent in the lines above. The GUI has
// not yet been updated so that the sorting would fail.
// NOTE: it is enough to re-sort the target branch of a cross-branch moved item.
QCoreApplication
::
postEvent
(
this
,
new
WRoiSortEvent
(
droppedBranchTreeItem
)
);
}
WQtDockWidget
*
WQtControlPanel
::
getRoiDock
()
const
...
...
src/qt4gui/events/WEventTypes.h
View file @
d299dae5
...
...
@@ -86,4 +86,8 @@
// Log entry added
#define WQT_LOG_EVENT QEvent::User + 18
// re-sort a branch
#define WQT_ROI_SORT_EVENT QEvent::User + 19
#endif // WEVENTTYPES_H
src/qt4gui/events/WRoiSortEvent.cpp
0 → 100644
View file @
d299dae5
//---------------------------------------------------------------------------
//
// 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 "WEventTypes.h"
#include "WRoiSortEvent.h"
WRoiSortEvent
::
WRoiSortEvent
(
WQtBranchTreeItem
*
branch
)
:
QEvent
(
static_cast
<
QEvent
::
Type
>
(
WQT_ROI_SORT_EVENT
)
),
m_branch
(
branch
)
{
// initialize members
}
WRoiSortEvent
::~
WRoiSortEvent
()
{
// cleanup
}
WQtBranchTreeItem
*
WRoiSortEvent
::
getBranch
()
{
return
m_branch
;
}
src/qt4gui/events/WRoiSortEvent.h
0 → 100644
View file @
d299dae5
//---------------------------------------------------------------------------
//
// 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 WROISORTEVENT_H
#define WROISORTEVENT_H
#include <boost/shared_ptr.hpp>
#include <QtCore/QEvent>
#include "../controlPanel/WQtBranchTreeItem.h"
/**
* Event signalling that a sorting of the ROIs needs to be done.
*/
class
WRoiSortEvent
:
public
QEvent
{
public:
/**
* Constructor
* \param branch the branch to sort.
*/
explicit
WRoiSortEvent
(
WQtBranchTreeItem
*
branch
);
/**
* Destructor
*/
virtual
~
WRoiSortEvent
();
/**
* Getter for the branch.
*
* \return the branch.
*/
WQtBranchTreeItem
*
getBranch
();
protected:
/**
* The branch to re-sort.
*/
WQtBranchTreeItem
*
m_branch
;
private:
};
#endif // WROISORTEVENT_H
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment