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
e8083ae8
Commit
e8083ae8
authored
Sep 02, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some comments and changed names of classes to match the coding rules.
parent
fef50dd8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
28 deletions
+44
-28
tool_interactive.cpp
common/tool/tool_interactive.cpp
+1
-1
tool_manager.cpp
common/tool/tool_manager.cpp
+33
-17
tool_event.h
include/tool/tool_event.h
+1
-1
tool_interactive.h
include/tool/tool_interactive.h
+1
-1
tool_manager.h
include/tool/tool_manager.h
+8
-8
No files found.
common/tool/tool_interactive.cpp
View file @
e8083ae8
...
...
@@ -56,7 +56,7 @@ void TOOL_INTERACTIVE::goInternal( TOOL_STATE_FUNC& aState, const TOOL_EVENT_LIS
}
void
TOOL_INTERACTIVE
::
SetContextMenu
(
CONTEXT_MENU
*
aMenu
,
TOOL_ContextMenuTrigger
aTrigger
)
void
TOOL_INTERACTIVE
::
SetContextMenu
(
CONTEXT_MENU
*
aMenu
,
CONTEXT_MENU_TRIGGER
aTrigger
)
{
aMenu
->
setTool
(
this
);
m_toolMgr
->
ScheduleContextMenu
(
this
,
aMenu
,
aTrigger
);
...
...
common/tool/tool_manager.cpp
View file @
e8083ae8
...
...
@@ -45,23 +45,39 @@
using
boost
::
optional
;
using
namespace
std
;
struct
TOOL_MANAGER
::
ToolState
/// Struct describing the current state of a TOOL
struct
TOOL_MANAGER
::
TOOL_STATE
{
/// The tool itself
TOOL_BASE
*
theTool
;
/// Is the tool active or idle at the moment
bool
idle
;
/// Flag defining if the tool is waiting for any event
bool
pendingWait
;
/// Is there a context menu to be displayed
bool
pendingContextMenu
;
/// Context menu used by the tool
CONTEXT_MENU
*
contextMenu
;
TOOL_ContextMenuTrigger
contextMenuTrigger
;
/// Defines when a context menu is opened
CONTEXT_MENU_TRIGGER
contextMenuTrigger
;
/// Coroutine launched upon an event trigger
COROUTINE
<
int
,
TOOL_EVENT
&>*
cofunc
;
/// The event that triggered the coroutine
TOOL_EVENT
wakeupEvent
;
/// List of events that are triggering the coroutine
TOOL_EVENT_LIST
waitEvents
;
std
::
vector
<
Transition
>
transitions
;
/// List of possible transitions (ie. association of events and functions that are executed
/// upon the event reception
std
::
vector
<
TRANSITION
>
transitions
;
};
...
...
@@ -72,7 +88,7 @@ TOOL_MANAGER::TOOL_MANAGER()
void
TOOL_MANAGER
::
RegisterTool
(
TOOL_BASE
*
aTool
)
{
T
oolState
*
st
=
new
ToolState
;
T
OOL_STATE
*
st
=
new
TOOL_STATE
;
st
->
theTool
=
aTool
;
st
->
idle
=
true
;
...
...
@@ -131,7 +147,7 @@ bool TOOL_MANAGER::InvokeTool( const std::string& aName )
TOOL_BASE
*
TOOL_MANAGER
::
FindTool
(
int
aId
)
const
{
std
::
map
<
TOOL_ID
,
T
oolState
*>::
const_iterator
it
=
m_toolIdIndex
.
find
(
aId
);
std
::
map
<
TOOL_ID
,
T
OOL_STATE
*>::
const_iterator
it
=
m_toolIdIndex
.
find
(
aId
);
if
(
it
!=
m_toolIdIndex
.
end
()
)
return
it
->
second
->
theTool
;
...
...
@@ -142,7 +158,7 @@ TOOL_BASE* TOOL_MANAGER::FindTool( int aId ) const
TOOL_BASE
*
TOOL_MANAGER
::
FindTool
(
const
std
::
string
&
aName
)
const
{
std
::
map
<
std
::
string
,
T
oolState
*>::
const_iterator
it
=
m_toolNameIndex
.
find
(
aName
);
std
::
map
<
std
::
string
,
T
OOL_STATE
*>::
const_iterator
it
=
m_toolNameIndex
.
find
(
aName
);
if
(
it
!=
m_toolNameIndex
.
end
()
)
return
it
->
second
->
theTool
;
...
...
@@ -154,15 +170,15 @@ TOOL_BASE* TOOL_MANAGER::FindTool( const std::string& aName ) const
void
TOOL_MANAGER
::
ScheduleNextState
(
TOOL_BASE
*
aTool
,
TOOL_STATE_FUNC
&
aHandler
,
const
TOOL_EVENT_LIST
&
aConditions
)
{
T
oolState
*
st
=
m_toolState
[
aTool
];
st
->
transitions
.
push_back
(
T
ransition
(
aConditions
,
aHandler
)
);
T
OOL_STATE
*
st
=
m_toolState
[
aTool
];
st
->
transitions
.
push_back
(
T
RANSITION
(
aConditions
,
aHandler
)
);
}
optional
<
TOOL_EVENT
>
TOOL_MANAGER
::
ScheduleWait
(
TOOL_BASE
*
aTool
,
const
TOOL_EVENT_LIST
&
aConditions
)
{
T
oolState
*
st
=
m_toolState
[
aTool
];
T
OOL_STATE
*
st
=
m_toolState
[
aTool
];
st
->
pendingWait
=
true
;
st
->
waitEvents
=
aConditions
;
...
...
@@ -177,7 +193,7 @@ void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )
// iterate over all registered tools
BOOST_FOREACH
(
TOOL_ID
toolId
,
m_activeTools
)
{
T
oolState
*
st
=
m_toolIdIndex
[
toolId
];
T
OOL_STATE
*
st
=
m_toolIdIndex
[
toolId
];
// the tool state handler is waiting for events (i.e. called Wait() method)
if
(
st
->
pendingWait
)
...
...
@@ -204,7 +220,7 @@ void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )
}
}
BOOST_FOREACH
(
T
oolState
*
st
,
m_toolState
|
boost
::
adaptors
::
map_values
)
BOOST_FOREACH
(
T
OOL_STATE
*
st
,
m_toolState
|
boost
::
adaptors
::
map_values
)
{
if
(
!
st
->
pendingWait
)
{
...
...
@@ -212,7 +228,7 @@ void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )
// Go() method that match the event.
if
(
st
->
transitions
.
size
()
)
{
BOOST_FOREACH
(
T
ransition
tr
,
st
->
transitions
)
BOOST_FOREACH
(
T
RANSITION
tr
,
st
->
transitions
)
{
if
(
tr
.
first
.
Matches
(
aEvent
)
)
{
...
...
@@ -238,7 +254,7 @@ void TOOL_MANAGER::dispatchInternal( TOOL_EVENT& aEvent )
}
void
TOOL_MANAGER
::
finishTool
(
T
oolState
*
aState
)
void
TOOL_MANAGER
::
finishTool
(
T
OOL_STATE
*
aState
)
{
wxASSERT
(
m_activeTools
.
front
()
==
aState
->
theTool
->
GetId
()
);
...
...
@@ -252,13 +268,13 @@ void TOOL_MANAGER::finishTool( ToolState* aState )
bool
TOOL_MANAGER
::
ProcessEvent
(
TOOL_EVENT
&
aEvent
)
{
wxLogDebug
(
"event: %s"
,
aEvent
.
Format
().
c_str
()
);
//
wxLogDebug( "event: %s", aEvent.Format().c_str() );
dispatchInternal
(
aEvent
);
BOOST_FOREACH
(
TOOL_ID
toolId
,
m_activeTools
)
{
T
oolState
*
st
=
m_toolIdIndex
[
toolId
];
T
OOL_STATE
*
st
=
m_toolIdIndex
[
toolId
];
if
(
st
->
contextMenuTrigger
==
CMENU_NOW
)
{
...
...
@@ -285,9 +301,9 @@ bool TOOL_MANAGER::ProcessEvent( TOOL_EVENT& aEvent )
void
TOOL_MANAGER
::
ScheduleContextMenu
(
TOOL_BASE
*
aTool
,
CONTEXT_MENU
*
aMenu
,
TOOL_ContextMenuTrigger
aTrigger
)
CONTEXT_MENU_TRIGGER
aTrigger
)
{
T
oolState
*
st
=
m_toolState
[
aTool
];
T
OOL_STATE
*
st
=
m_toolState
[
aTool
];
st
->
contextMenu
=
aMenu
;
st
->
contextMenuTrigger
=
aTrigger
;
...
...
include/tool/tool_event.h
View file @
e8083ae8
...
...
@@ -105,7 +105,7 @@ enum TOOL_Modifiers
};
// Defines when a context menu is opened.
enum
TOOL_ContextMenuTrigger
enum
CONTEXT_MENU_TRIGGER
{
CMENU_BUTTON
=
0
,
// On the right button
CMENU_NOW
,
// Right now (after TOOL_INTERACTIVE::SetContextMenu)
...
...
include/tool/tool_interactive.h
View file @
e8083ae8
...
...
@@ -56,7 +56,7 @@ public:
*
* Assigns a context menu and tells when it should be activated
*/
void
SetContextMenu
(
CONTEXT_MENU
*
aMenu
,
TOOL_ContextMenuTrigger
aTrigger
=
CMENU_BUTTON
);
void
SetContextMenu
(
CONTEXT_MENU
*
aMenu
,
CONTEXT_MENU_TRIGGER
aTrigger
=
CMENU_BUTTON
);
/**
* Function Go()
...
...
include/tool/tool_manager.h
View file @
e8083ae8
...
...
@@ -151,7 +151,7 @@ public:
* May be called from a coroutine context.
*/
void
ScheduleContextMenu
(
TOOL_BASE
*
aTool
,
CONTEXT_MENU
*
aMenu
,
TOOL_ContextMenuTrigger
aTrigger
);
CONTEXT_MENU_TRIGGER
aTrigger
);
/**
* Allows a tool pass the already handled event to be passed to the next tool on the stack.
...
...
@@ -162,15 +162,15 @@ public:
}
private
:
struct
T
oolState
;
typedef
std
::
pair
<
TOOL_EVENT_LIST
,
TOOL_STATE_FUNC
>
T
ransition
;
struct
T
OOL_STATE
;
typedef
std
::
pair
<
TOOL_EVENT_LIST
,
TOOL_STATE_FUNC
>
T
RANSITION
;
void
dispatchInternal
(
TOOL_EVENT
&
aEvent
);
void
finishTool
(
T
oolState
*
aState
);
void
finishTool
(
T
OOL_STATE
*
aState
);
std
::
map
<
TOOL_BASE
*
,
T
oolState
*>
m_toolState
;
std
::
map
<
std
::
string
,
T
oolState
*>
m_toolNameIndex
;
std
::
map
<
TOOL_ID
,
T
oolState
*>
m_toolIdIndex
;
std
::
map
<
TOOL_BASE
*
,
T
OOL_STATE
*>
m_toolState
;
std
::
map
<
std
::
string
,
T
OOL_STATE
*>
m_toolNameIndex
;
std
::
map
<
TOOL_ID
,
T
OOL_STATE
*>
m_toolIdIndex
;
std
::
deque
<
TOOL_ID
>
m_activeTools
;
EDA_ITEM
*
m_model
;
...
...
@@ -179,7 +179,7 @@ private:
wxWindow
*
m_editFrame
;
bool
m_passEvent
;
T
oolState
*
m_currentTool
;
T
OOL_STATE
*
m_currentTool
;
};
#endif
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