Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kicad-source-mirror
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Elphel
kicad-source-mirror
Commits
dfc052d5
Commit
dfc052d5
authored
Jul 09, 2014
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an alternative way to reach tools in the Tool Framework.
parent
b5b20ef4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
7 deletions
+30
-7
tool_manager.cpp
common/tool/tool_manager.cpp
+7
-3
tool_manager.h
include/tool/tool_manager.h
+23
-4
No files found.
common/tool/tool_manager.cpp
View file @
dfc052d5
...
...
@@ -109,7 +109,7 @@ TOOL_MANAGER::TOOL_MANAGER() :
TOOL_MANAGER
::~
TOOL_MANAGER
()
{
std
::
map
<
TOOL_BASE
*
,
TOOL_STATE
*>::
iterator
it
,
it_end
;
boost
::
unordered_
map
<
TOOL_BASE
*
,
TOOL_STATE
*>::
iterator
it
,
it_end
;
for
(
it
=
m_toolState
.
begin
(),
it_end
=
m_toolState
.
end
();
it
!=
it_end
;
++
it
)
{
...
...
@@ -129,6 +129,8 @@ void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool )
wxT
(
"Adding two tools with the same name may result in unexpected behaviour."
)
);
wxASSERT_MSG
(
m_toolIdIndex
.
find
(
aTool
->
GetId
()
)
==
m_toolIdIndex
.
end
(),
wxT
(
"Adding two tools with the same ID may result in unexpected behaviour."
)
);
wxASSERT_MSG
(
m_toolTypes
.
find
(
typeid
(
*
aTool
).
name
()
)
==
m_toolTypes
.
end
(),
wxT
(
"Adding two tools of the same type may result in unexpected behaviour."
)
);
TOOL_STATE
*
st
=
new
TOOL_STATE
;
...
...
@@ -141,6 +143,7 @@ void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool )
m_toolState
[
aTool
]
=
st
;
m_toolNameIndex
[
aTool
->
GetName
()]
=
st
;
m_toolIdIndex
[
aTool
->
GetId
()]
=
st
;
m_toolTypes
[
typeid
(
*
aTool
).
name
()]
=
st
->
theTool
;
aTool
->
m_toolMgr
=
this
;
...
...
@@ -155,6 +158,7 @@ void TOOL_MANAGER::RegisterTool( TOOL_BASE* aTool )
m_toolState
.
erase
(
aTool
);
m_toolNameIndex
.
erase
(
aTool
->
GetName
()
);
m_toolIdIndex
.
erase
(
aTool
->
GetId
()
);
m_toolTypes
.
erase
(
typeid
(
*
aTool
).
name
()
);
delete
st
;
delete
aTool
;
...
...
@@ -272,7 +276,7 @@ bool TOOL_MANAGER::runTool( TOOL_BASE* aTool )
TOOL_BASE
*
TOOL_MANAGER
::
FindTool
(
int
aId
)
const
{
std
::
map
<
TOOL_ID
,
TOOL_STATE
*>::
const_iterator
it
=
m_toolIdIndex
.
find
(
aId
);
boost
::
unordered_
map
<
TOOL_ID
,
TOOL_STATE
*>::
const_iterator
it
=
m_toolIdIndex
.
find
(
aId
);
if
(
it
!=
m_toolIdIndex
.
end
()
)
return
it
->
second
->
theTool
;
...
...
@@ -283,7 +287,7 @@ TOOL_BASE* TOOL_MANAGER::FindTool( int aId ) const
TOOL_BASE
*
TOOL_MANAGER
::
FindTool
(
const
std
::
string
&
aName
)
const
{
std
::
map
<
std
::
string
,
TOOL_STATE
*>::
const_iterator
it
=
m_toolNameIndex
.
find
(
aName
);
boost
::
unordered_
map
<
std
::
string
,
TOOL_STATE
*>::
const_iterator
it
=
m_toolNameIndex
.
find
(
aName
);
if
(
it
!=
m_toolNameIndex
.
end
()
)
return
it
->
second
->
theTool
;
...
...
include/tool/tool_manager.h
View file @
dfc052d5
...
...
@@ -26,8 +26,9 @@
#ifndef __TOOL_MANAGER_H
#define __TOOL_MANAGER_H
#include <map>
#include <deque>
#include <typeinfo>
#include <boost/unordered_map.hpp>
#include <math/vector2d.h>
...
...
@@ -135,6 +136,21 @@ public:
*/
TOOL_BASE
*
FindTool
(
const
std
::
string
&
aName
)
const
;
/*
* Function GetTool()
* Returns the tool of given type or NULL if there is no such tool registered.
*/
template
<
typename
T
>
T
*
GetTool
()
{
boost
::
unordered_map
<
const
char
*
,
TOOL_BASE
*>::
iterator
tool
=
m_toolTypes
.
find
(
typeid
(
T
).
name
()
);
if
(
tool
!=
m_toolTypes
.
end
()
)
return
static_cast
<
T
*>
(
tool
->
second
);
return
NULL
;
}
/**
* Function ResetTools()
* Resets all tools (i.e. calls their Reset() method).
...
...
@@ -344,13 +360,16 @@ private:
bool
isActive
(
TOOL_BASE
*
aTool
);
/// Index of registered tools current states, associated by tools' objects.
std
::
map
<
TOOL_BASE
*
,
TOOL_STATE
*>
m_toolState
;
boost
::
unordered_
map
<
TOOL_BASE
*
,
TOOL_STATE
*>
m_toolState
;
/// Index of the registered tools current states, associated by tools' names.
std
::
map
<
std
::
string
,
TOOL_STATE
*>
m_toolNameIndex
;
boost
::
unordered_map
<
std
::
string
,
TOOL_STATE
*>
m_toolNameIndex
;
/// Index of the registered tools to easily lookup by their type.
boost
::
unordered_map
<
const
char
*
,
TOOL_BASE
*>
m_toolTypes
;
/// Index of the registered tools current states, associated by tools' ID numbers.
std
::
map
<
TOOL_ID
,
TOOL_STATE
*>
m_toolIdIndex
;
boost
::
unordered_
map
<
TOOL_ID
,
TOOL_STATE
*>
m_toolIdIndex
;
/// Stack of the active tools
std
::
deque
<
TOOL_ID
>
m_activeTools
;
...
...
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