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
12e10fd4
Commit
12e10fd4
authored
Aug 08, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reformatting.
parent
282995ea
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
171 additions
and
179 deletions
+171
-179
context_menu.cpp
common/tool/context_menu.cpp
+1
-1
tool_manager.cpp
common/tool/tool_manager.cpp
+2
-0
coroutine.h
include/tool/coroutine.h
+47
-56
tool_manager.h
include/tool/tool_manager.h
+120
-121
selection_tool.h
pcbnew/tools/selection_tool.h
+1
-1
No files found.
common/tool/context_menu.cpp
View file @
12e10fd4
...
@@ -35,7 +35,7 @@ class CONTEXT_MENU::CMEventHandler : public wxEvtHandler
...
@@ -35,7 +35,7 @@ class CONTEXT_MENU::CMEventHandler : public wxEvtHandler
{
{
public
:
public
:
CMEventHandler
(
CONTEXT_MENU
*
aMenu
)
:
CMEventHandler
(
CONTEXT_MENU
*
aMenu
)
:
m_menu
(
aMenu
)
{};
m_menu
(
aMenu
)
{};
void
onEvent
(
wxEvent
&
aEvent
)
void
onEvent
(
wxEvent
&
aEvent
)
{
{
...
...
common/tool/tool_manager.cpp
View file @
12e10fd4
...
@@ -64,10 +64,12 @@ struct TOOL_MANAGER::ToolState
...
@@ -64,10 +64,12 @@ struct TOOL_MANAGER::ToolState
std
::
vector
<
Transition
>
transitions
;
std
::
vector
<
Transition
>
transitions
;
};
};
TOOL_MANAGER
::
TOOL_MANAGER
()
TOOL_MANAGER
::
TOOL_MANAGER
()
{
{
}
}
void
TOOL_MANAGER
::
RegisterTool
(
TOOL_BASE
*
aTool
)
void
TOOL_MANAGER
::
RegisterTool
(
TOOL_BASE
*
aTool
)
{
{
ToolState
*
st
=
new
ToolState
;
ToolState
*
st
=
new
ToolState
;
...
...
include/tool/coroutine.h
View file @
12e10fd4
...
@@ -52,12 +52,11 @@
...
@@ -52,12 +52,11 @@
See coroutine_example.cpp for sample code.
See coroutine_example.cpp for sample code.
*/
*/
template
<
class
ReturnType
,
class
ArgType
>
template
<
class
ReturnType
,
class
ArgType
>
class
COROUTINE
{
class
COROUTINE
{
public
:
public
:
COROUTINE
()
COROUTINE
(
)
{
{
m_stackSize
=
c_defaultStackSize
;
m_stackSize
=
c_defaultStackSize
;
m_stack
=
NULL
;
m_stack
=
NULL
;
...
@@ -68,34 +67,26 @@ public:
...
@@ -68,34 +67,26 @@ public:
* Constructor
* Constructor
* Creates a coroutine from a member method of an object
* Creates a coroutine from a member method of an object
*/
*/
template
<
class
T
>
template
<
class
T
>
COROUTINE
(
T
*
object
,
ReturnType
(
T
::*
ptr
)(
ArgType
)
)
:
COROUTINE
(
T
*
object
,
ReturnType
(
T
::*
ptr
)(
ArgType
)
)
:
m_func
(
object
,
ptr
),
m_func
(
object
,
ptr
),
m_saved
(
NULL
),
m_stack
(
NULL
),
m_stackSize
(
c_defaultStackSize
)
m_saved
(
NULL
),
m_stack
(
NULL
),
m_stackSize
(
c_defaultStackSize
)
{
{
}
}
/**
/**
* Constructor
* Constructor
* Creates a coroutine from a delegate object
* Creates a coroutine from a delegate object
*/
*/
COROUTINE
(
DELEGATE
<
ReturnType
,
ArgType
>
aEntry
)
:
COROUTINE
(
DELEGATE
<
ReturnType
,
ArgType
>
aEntry
)
:
m_func
(
aEntry
),
m_func
(
aEntry
),
m_saved
(
NULL
),
m_stack
(
NULL
),
m_stackSize
(
c_defaultStackSize
)
m_saved
(
NULL
),
m_stack
(
NULL
),
m_stackSize
(
c_defaultStackSize
)
{};
{};
~
COROUTINE
()
~
COROUTINE
()
{
{
if
(
m_saved
)
if
(
m_saved
)
delete
m_saved
;
delete
m_saved
;
if
(
m_stack
)
if
(
m_stack
)
free
(
m_stack
);
free
(
m_stack
);
}
}
/**
/**
...
@@ -105,9 +96,9 @@ public:
...
@@ -105,9 +96,9 @@ public:
* After a yield, Call() or Resume() methods invoked by the caller will
* After a yield, Call() or Resume() methods invoked by the caller will
* immediately return true, indicating that we are not done yet, just asleep.
* immediately return true, indicating that we are not done yet, just asleep.
*/
*/
void
Yield
(
)
void
Yield
()
{
{
jump_fcontext
(
m_self
,
m_saved
,
0
);
jump_fcontext
(
m_self
,
m_saved
,
0
);
}
}
/**
/**
...
@@ -119,7 +110,7 @@ public:
...
@@ -119,7 +110,7 @@ public:
void
Yield
(
ReturnType
&
retVal
)
void
Yield
(
ReturnType
&
retVal
)
{
{
m_retVal
=
retVal
;
m_retVal
=
retVal
;
jump_fcontext
(
m_self
,
m_saved
,
0
);
jump_fcontext
(
m_self
,
m_saved
,
0
);
}
}
/**
/**
...
@@ -127,7 +118,7 @@ public:
...
@@ -127,7 +118,7 @@ public:
*
*
* Defines the entry point for the coroutine, if not set in the constructor.
* Defines the entry point for the coroutine, if not set in the constructor.
*/
*/
void
SetEntry
(
DELEGATE
<
ReturnType
,
ArgType
>
aEntry
)
void
SetEntry
(
DELEGATE
<
ReturnType
,
ArgType
>
aEntry
)
{
{
m_func
=
aEntry
;
m_func
=
aEntry
;
}
}
...
@@ -141,19 +132,19 @@ public:
...
@@ -141,19 +132,19 @@ public:
bool
Call
(
ArgType
args
)
bool
Call
(
ArgType
args
)
{
{
// fixme: Clean up stack stuff. Add a guard
// fixme: Clean up stack stuff. Add a guard
m_stack
=
malloc
(
c_defaultStackSize
);
m_stack
=
malloc
(
c_defaultStackSize
);
// align to 16 bytes
// align to 16 bytes
void
*
sp
=
(
void
*
)
((((
ptrdiff_t
)
m_stack
)
+
m_stackSize
-
0xf
)
&
0xfffffff0
);
void
*
sp
=
(
void
*
)
(
(
(
(
ptrdiff_t
)
m_stack
)
+
m_stackSize
-
0xf
)
&
0xfffffff0
);
m_args
=
&
args
;
m_args
=
&
args
;
m_self
=
boost
::
context
::
make_fcontext
(
sp
,
m_stackSize
,
callerStub
);
m_self
=
boost
::
context
::
make_fcontext
(
sp
,
m_stackSize
,
callerStub
);
m_saved
=
new
boost
::
context
::
fcontext_t
();
m_saved
=
new
boost
::
context
::
fcontext_t
();
m_running
=
true
;
m_running
=
true
;
// off we go!
// off we go!
boost
::
context
::
jump_fcontext
(
m_saved
,
m_self
,
reinterpret_cast
<
intptr_t
>
(
this
)
);
boost
::
context
::
jump_fcontext
(
m_saved
,
m_self
,
reinterpret_cast
<
intptr_t
>
(
this
)
);
return
m_running
;
return
m_running
;
}
}
/**
/**
...
@@ -163,10 +154,10 @@ public:
...
@@ -163,10 +154,10 @@ public:
* @return true, if the coroutine has yielded again and false if it has finished its
* @return true, if the coroutine has yielded again and false if it has finished its
* execution (returned).
* execution (returned).
*/
*/
bool
Resume
(
)
bool
Resume
()
{
{
jump_fcontext
(
m_saved
,
m_self
,
0
);
jump_fcontext
(
m_saved
,
m_self
,
0
);
return
m_running
;
return
m_running
;
}
}
/**
/**
...
@@ -190,47 +181,47 @@ public:
...
@@ -190,47 +181,47 @@ public:
}
}
private
:
private
:
static
const
int
c_defaultStackSize
=
2000000
;
static
const
int
c_defaultStackSize
=
2000000
;
/* real entry point of the coroutine */
/* real entry point of the coroutine */
static
void
callerStub
(
intptr_t
data
)
static
void
callerStub
(
intptr_t
data
)
{
{
// get pointer to self
// get pointer to self
COROUTINE
<
ReturnType
,
ArgType
>
*
cor
=
reinterpret_cast
<
COROUTINE
<
ReturnType
,
ArgType
>
*>
(
data
);
COROUTINE
<
ReturnType
,
ArgType
>
*
cor
=
reinterpret_cast
<
COROUTINE
<
ReturnType
,
ArgType
>*>
(
data
);
// call the coroutine method
// call the coroutine method
cor
->
m_retVal
=
cor
->
m_func
(
*
cor
->
m_args
);
cor
->
m_retVal
=
cor
->
m_func
(
*
cor
->
m_args
);
cor
->
m_running
=
false
;
cor
->
m_running
=
false
;
// go back to wherever we came from.
// go back to wherever we came from.
boost
::
context
::
jump_fcontext
(
cor
->
m_self
,
cor
->
m_saved
,
0
);
//reinterpret_cast<intptr_t> (this
));
boost
::
context
::
jump_fcontext
(
cor
->
m_self
,
cor
->
m_saved
,
0
);
//reinterpret_cast<intptr_t>( this
));
}
}
template
<
typename
T
>
struct
strip_ref
{
template
<
typename
T
>
struct
strip_ref
typedef
T
result
;
{
typedef
T
result
;
};
};
template
<
typename
T
>
struct
strip_ref
<
T
&>
{
template
<
typename
T
>
struct
strip_ref
<
T
&>
typedef
T
result
;
{
typedef
T
result
;
};
};
DELEGATE
<
ReturnType
,
ArgType
>
m_func
;
DELEGATE
<
ReturnType
,
ArgType
>
m_func
;
///< pointer to coroutine entry arguments. Stripped of references
///< pointer to coroutine entry arguments. Stripped of references
///< to avoid compiler errors.
///< to avoid compiler errors.
typename
strip_ref
<
ArgType
>::
result
*
m_args
;
typename
strip_ref
<
ArgType
>::
result
*
m_args
;
ReturnType
m_retVal
;
ReturnType
m_retVal
;
///< saved caller context
///< saved caller context
boost
::
context
::
fcontext_t
*
m_saved
;
boost
::
context
::
fcontext_t
*
m_saved
;
///< saved coroutine context
///< saved coroutine context
boost
::
context
::
fcontext_t
*
m_self
;
boost
::
context
::
fcontext_t
*
m_self
;
///< coroutine stack
///< coroutine stack
void
*
m_stack
;
void
*
m_stack
;
size_t
m_stackSize
;
size_t
m_stackSize
;
...
...
include/tool/tool_manager.h
View file @
12e10fd4
...
@@ -50,127 +50,126 @@ class wxWindow;
...
@@ -50,127 +50,126 @@ class wxWindow;
*/
*/
class
TOOL_MANAGER
class
TOOL_MANAGER
{
{
public
:
public
:
TOOL_MANAGER
();
TOOL_MANAGER
();
~
TOOL_MANAGER
();
~
TOOL_MANAGER
();
/**
/**
* Generates an unique ID from for a tool with given name.
* Generates an unique ID from for a tool with given name.
*/
*/
static
TOOL_ID
MakeToolId
(
const
std
::
string
&
aToolName
);
static
TOOL_ID
MakeToolId
(
const
std
::
string
&
aToolName
);
/**
/**
* Function RegisterTool()
* Function RegisterTool()
* Adds a tool to the manager set and sets it up. Called once for
* Adds a tool to the manager set and sets it up. Called once for
* each tool during application initialization.
* each tool during application initialization.
* @param aTool: tool to be added. Ownership is transferred.
* @param aTool: tool to be added. Ownership is transferred.
*/
*/
void
RegisterTool
(
TOOL_BASE
*
aTool
);
void
RegisterTool
(
TOOL_BASE
*
aTool
);
/**
/**
* Function InvokeTool()
* Function InvokeTool()
* Calls a tool by sending a tool activation event to tool of given ID or name.
* Calls a tool by sending a tool activation event to tool of given ID or name.
* An user-defined parameter object can be also passed
* An user-defined parameter object can be also passed
*/
*/
void
InvokeTool
(
TOOL_ID
aToolId
);
void
InvokeTool
(
TOOL_ID
aToolId
);
void
InvokeTool
(
const
std
::
string
&
name
);
void
InvokeTool
(
const
std
::
string
&
name
);
template
<
class
Parameters
>
template
<
class
Parameters
>
void
InvokeTool
(
const
std
::
string
&
name
,
const
Parameters
&
aToolParams
);
void
InvokeTool
(
const
std
::
string
&
name
,
const
Parameters
&
aToolParams
);
/**
/**
* Function FindTool()
* Function FindTool()
* Searches for a tool with given name or ID
* Searches for a tool with given name or ID
*/
*/
TOOL_BASE
*
FindTool
(
int
aId
);
TOOL_BASE
*
FindTool
(
int
aId
);
TOOL_BASE
*
FindTool
(
const
std
::
string
&
aName
);
TOOL_BASE
*
FindTool
(
const
std
::
string
&
aName
);
/**
/**
* Resets the state of a given tool by clearing its wait and
* Resets the state of a given tool by clearing its wait and
* transition lists and calling tool's internal Reset() method.
* transition lists and calling tool's internal Reset() method.
*/
*/
void
ResetTool
(
TOOL_BASE
*
aTool
);
void
ResetTool
(
TOOL_BASE
*
aTool
);
/**
/**
* Takes an event from the TOOL_DISPATCHER and propagates it to
* Takes an event from the TOOL_DISPATCHER and propagates it to
* tools that requested events of matching type(s)
* tools that requested events of matching type(s)
*/
*/
bool
ProcessEvent
(
TOOL_EVENT
&
aEvent
);
bool
ProcessEvent
(
TOOL_EVENT
&
aEvent
);
/**
/**
* Sets the work environment (model, view, view controls and the parent window).
* Sets the work environment (model, view, view controls and the parent window).
* These are made available to the tool. Called by the parent frame (PCB_EDIT_FRAME)
* These are made available to the tool. Called by the parent frame (PCB_EDIT_FRAME)
* when the board is set up
* when the board is set up
*/
*/
void
SetEnvironment
(
EDA_ITEM
*
aModel
,
KiGfx
::
VIEW
*
aView
,
void
SetEnvironment
(
EDA_ITEM
*
aModel
,
KiGfx
::
VIEW
*
aView
,
KiGfx
::
VIEW_CONTROLS
*
aViewControls
,
wxWindow
*
aFrame
);
KiGfx
::
VIEW_CONTROLS
*
aViewControls
,
wxWindow
*
aFrame
);
/* Accessors for the environment objects (view, model, etc.) */
/* Accessors for the environment objects (view, model, etc.) */
KiGfx
::
VIEW
*
GetView
()
KiGfx
::
VIEW
*
GetView
()
{
{
return
m_view
;
return
m_view
;
}
}
KiGfx
::
VIEW_CONTROLS
*
GetViewControls
()
KiGfx
::
VIEW_CONTROLS
*
GetViewControls
()
{
{
return
m_viewControls
;
return
m_viewControls
;
}
}
EDA_ITEM
*
GetModel
()
EDA_ITEM
*
GetModel
()
{
{
return
m_model
;
return
m_model
;
}
}
wxWindow
*
GetEditFrame
()
wxWindow
*
GetEditFrame
()
{
{
return
m_editFrame
;
return
m_editFrame
;
}
}
/**
/**
* Defines a state transition - the events that cause a given handler method in the tool
* Defines a state transition - the events that cause a given handler method in the tool
* to be called. Called by TOOL_INTERACTIVE::Go(). May be called from a coroutine context.
* to be called. Called by TOOL_INTERACTIVE::Go(). May be called from a coroutine context.
*/
*/
void
ScheduleNextState
(
TOOL_BASE
*
aTool
,
TOOL_STATE_FUNC
&
aHandler
,
void
ScheduleNextState
(
TOOL_BASE
*
aTool
,
TOOL_STATE_FUNC
&
aHandler
,
const
TOOL_EVENT_LIST
&
aConditions
);
const
TOOL_EVENT_LIST
&
aConditions
);
/**
/**
* Pauses execution of a given tool until one or more events matching aConditions arrives.
* Pauses execution of a given tool until one or more events matching aConditions arrives.
* The pause/resume operation is done through COROUTINE object.
* The pause/resume operation is done through COROUTINE object.
* Called only from coroutines.
* Called only from coroutines.
*/
*/
boost
::
optional
<
TOOL_EVENT
>
ScheduleWait
(
TOOL_BASE
*
aTool
,
boost
::
optional
<
TOOL_EVENT
>
ScheduleWait
(
TOOL_BASE
*
aTool
,
const
TOOL_EVENT_LIST
&
aConditions
);
const
TOOL_EVENT_LIST
&
aConditions
);
/**
/**
* Sets behaviour of the tool's context popup menu.
* Sets behaviour of the tool's context popup menu.
* @param aMenu - the menu structure, defined by the tool
* @param aMenu - the menu structure, defined by the tool
* @param aTrigger - when the menu is activated:
* @param aTrigger - when the menu is activated:
* CMENU_NOW: opens the menu right now
* CMENU_NOW: opens the menu right now
* CMENU_BUTTON: opens the menu when RMB is pressed
* CMENU_BUTTON: opens the menu when RMB is pressed
* CMENU_OFF: menu is disabled.
* CMENU_OFF: menu is disabled.
* May be called from a coroutine context.
* May be called from a coroutine context.
*/
*/
void
ScheduleContextMenu
(
TOOL_BASE
*
aTool
,
CONTEXT_MENU
*
aMenu
,
void
ScheduleContextMenu
(
TOOL_BASE
*
aTool
,
CONTEXT_MENU
*
aMenu
,
TOOL_ContextMenuTrigger
aTrigger
);
TOOL_ContextMenuTrigger
aTrigger
);
private
:
private
:
void
dispatchInternal
(
TOOL_EVENT
&
aEvent
);
void
dispatchInternal
(
TOOL_EVENT
&
aEvent
);
struct
ToolState
;
struct
ToolState
;
typedef
std
::
pair
<
TOOL_EVENT_LIST
,
TOOL_STATE_FUNC
>
Transition
;
typedef
std
::
pair
<
TOOL_EVENT_LIST
,
TOOL_STATE_FUNC
>
Transition
;
std
::
map
<
TOOL_BASE
*
,
ToolState
*>
m_toolState
;
std
::
map
<
TOOL_BASE
*
,
ToolState
*>
m_toolState
;
std
::
map
<
std
::
string
,
ToolState
*>
m_toolNameIndex
;
std
::
map
<
std
::
string
,
ToolState
*>
m_toolNameIndex
;
std
::
map
<
TOOL_ID
,
ToolState
*>
m_toolIdIndex
;
std
::
map
<
TOOL_ID
,
ToolState
*>
m_toolIdIndex
;
EDA_ITEM
*
m_model
;
EDA_ITEM
*
m_model
;
KiGfx
::
VIEW
*
m_view
;
KiGfx
::
VIEW
*
m_view
;
KiGfx
::
VIEW_CONTROLS
*
m_viewControls
;
KiGfx
::
VIEW_CONTROLS
*
m_viewControls
;
wxWindow
*
m_editFrame
;
wxWindow
*
m_editFrame
;
ToolState
*
m_currentTool
;
ToolState
*
m_currentTool
;
};
};
#endif
#endif
pcbnew/tools/selection_tool.h
View file @
12e10fd4
...
@@ -54,7 +54,7 @@ public:
...
@@ -54,7 +54,7 @@ public:
~
SELECTION_TOOL
();
~
SELECTION_TOOL
();
void
Reset
();
void
Reset
();
int
Main
(
TOOL_EVENT
&
aEvent
);
int
Main
(
TOOL_EVENT
&
aEvent
);
private
:
private
:
void
selectSingle
(
const
VECTOR2I
&
aWhere
,
bool
aAdditive
);
void
selectSingle
(
const
VECTOR2I
&
aWhere
,
bool
aAdditive
);
...
...
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