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
79de0bed
Commit
79de0bed
authored
Mar 09, 2021
by
Robin Eschbach
Browse files
[ADD
#77
] toggle undo actions
parent
6a03ae8f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
192 additions
and
20 deletions
+192
-20
src/modules/pointConnector/WFiberHandler.cpp
src/modules/pointConnector/WFiberHandler.cpp
+21
-10
src/modules/pointConnector/WFiberHandler.h
src/modules/pointConnector/WFiberHandler.h
+4
-3
src/modules/pointConnector/WMPointConnector.cpp
src/modules/pointConnector/WMPointConnector.cpp
+26
-2
src/modules/pointConnector/action/WFiberActionRemoveFiber.cpp
...modules/pointConnector/action/WFiberActionRemoveFiber.cpp
+4
-2
src/modules/pointConnector/action/WFiberActionRemoveFiber.h
src/modules/pointConnector/action/WFiberActionRemoveFiber.h
+7
-1
src/modules/pointConnector/action/WFiberActionRemoveVertex.h
src/modules/pointConnector/action/WFiberActionRemoveVertex.h
+1
-1
src/modules/pointConnector/action/WFiberActionToggle.cpp
src/modules/pointConnector/action/WFiberActionToggle.cpp
+47
-0
src/modules/pointConnector/action/WFiberActionToggle.h
src/modules/pointConnector/action/WFiberActionToggle.h
+81
-0
src/modules/pointRenderer/shaders/WMPointRenderer-fragment.glsl
...dules/pointRenderer/shaders/WMPointRenderer-fragment.glsl
+1
-1
No files found.
src/modules/pointConnector/WFiberHandler.cpp
View file @
79de0bed
...
...
@@ -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
)
...
...
src/modules/pointConnector/WFiberHandler.h
View file @
79de0bed
...
...
@@ -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
o
f the
hidden fiber indecie
s.
* Vector f
or
the
visibility of the fiber
s.
*/
std
::
vector
<
size_t
>
m_hidden
;
boost
::
shared_ptr
<
std
::
vector
<
bool
>
>
m_hidden
;
};
#endif // WFIBERHANDLER_H
src/modules/pointConnector/WMPointConnector.cpp
View file @
79de0bed
...
...
@@ -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
);
}
...
...
src/modules/pointConnector/action/WFiberActionRemoveFiber.cpp
View file @
79de0bed
...
...
@@ -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
()
...
...
src/modules/pointConnector/action/WFiberActionRemoveFiber.h
View file @
79de0bed
...
...
@@ -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.
*/
...
...
src/modules/pointConnector/action/WFiberActionRemoveVertex.h
View file @
79de0bed
...
...
@@ -34,7 +34,7 @@
#include "../WFiberHandler.h"
/**
* The action when
add
ing a Vertex.
* The action when
remov
ing a Vertex.
*/
class
WFiberActionRemoveVertex
:
public
WFiberAction
{
...
...
src/modules/pointConnector/action/WFiberActionToggle.cpp
0 → 100644
View file @
79de0bed
//---------------------------------------------------------------------------
//
// 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
);
}
src/modules/pointConnector/action/WFiberActionToggle.h
0 → 100644
View file @
79de0bed
//---------------------------------------------------------------------------
//
// 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
src/modules/pointRenderer/shaders/WMPointRenderer-fragment.glsl
View file @
79de0bed
...
...
@@ -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
...
...
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