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
b582162c
Commit
b582162c
authored
Dec 03, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split rotate and flip operations into separate functions.
Added Properties action (display properties windows)
parent
ad3cb1f3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
164 additions
and
45 deletions
+164
-45
common_actions.cpp
pcbnew/tools/common_actions.cpp
+5
-1
common_actions.h
pcbnew/tools/common_actions.h
+4
-1
move_tool.cpp
pcbnew/tools/move_tool.cpp
+107
-37
move_tool.h
pcbnew/tools/move_tool.h
+31
-4
pcb_tools.cpp
pcbnew/tools/pcb_tools.cpp
+1
-0
selection_tool.cpp
pcbnew/tools/selection_tool.cpp
+16
-2
No files found.
pcbnew/tools/common_actions.cpp
View file @
b582162c
...
@@ -36,9 +36,13 @@ TOOL_ACTION COMMON_ACTIONS::moveActivate( "pcbnew.InteractiveMove",
...
@@ -36,9 +36,13 @@ TOOL_ACTION COMMON_ACTIONS::moveActivate( "pcbnew.InteractiveMove",
"Move"
,
"Moves the selected item(s)"
);
"Move"
,
"Moves the selected item(s)"
);
TOOL_ACTION
COMMON_ACTIONS
::
rotate
(
"pcbnew.InteractiveMove.rotate"
,
TOOL_ACTION
COMMON_ACTIONS
::
rotate
(
"pcbnew.InteractiveMove.rotate"
,
AS_CONTEXT
,
'
'
,
AS_CONTEXT
,
'
R
'
,
"Rotate"
,
"Rotates selected item(s)"
);
"Rotate"
,
"Rotates selected item(s)"
);
TOOL_ACTION
COMMON_ACTIONS
::
flip
(
"pcbnew.InteractiveMove.flip"
,
TOOL_ACTION
COMMON_ACTIONS
::
flip
(
"pcbnew.InteractiveMove.flip"
,
AS_CONTEXT
,
'F'
,
AS_CONTEXT
,
'F'
,
"Flip"
,
"Flips selected item(s)"
);
"Flip"
,
"Flips selected item(s)"
);
TOOL_ACTION
COMMON_ACTIONS
::
properties
(
"pcbnew.InteractiveMove.properties"
,
AS_GLOBAL
,
'E'
,
"Properties..."
,
"Displays properties window"
);
pcbnew/tools/common_actions.h
View file @
b582162c
...
@@ -24,7 +24,7 @@
...
@@ -24,7 +24,7 @@
#include <tool/tool_action.h>
#include <tool/tool_action.h>
class
ACTION_MANAGER
;
//
class ACTION_MANAGER;
/**
/**
* Class COMMON_ACTIONS
* Class COMMON_ACTIONS
...
@@ -46,4 +46,7 @@ public:
...
@@ -46,4 +46,7 @@ public:
/// Flipping of selected objects
/// Flipping of selected objects
static
TOOL_ACTION
flip
;
static
TOOL_ACTION
flip
;
/// Activation of the edit tool
static
TOOL_ACTION
properties
;
};
};
pcbnew/tools/move_tool.cpp
View file @
b582162c
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include <class_board.h>
#include <class_board.h>
#include <class_module.h>
#include <class_module.h>
#include <wxPcbStruct.h>
#include <tool/tool_manager.h>
#include <tool/tool_manager.h>
#include <view/view_controls.h>
#include <view/view_controls.h>
#include <confirm.h>
#include <confirm.h>
...
@@ -41,37 +42,25 @@ MOVE_TOOL::MOVE_TOOL() :
...
@@ -41,37 +42,25 @@ MOVE_TOOL::MOVE_TOOL() :
}
}
MOVE_TOOL
::~
MOVE_TOOL
()
{
}
void
MOVE_TOOL
::
Reset
()
{
// The tool launches upon reception of action event ("pcbnew.InteractiveMove")
Go
(
&
MOVE_TOOL
::
Main
,
COMMON_ACTIONS
::
moveActivate
.
MakeEvent
()
);
}
bool
MOVE_TOOL
::
Init
()
bool
MOVE_TOOL
::
Init
()
{
{
// Find the selection tool, so they can cooperate
// Find the selection tool, so they can cooperate
TOOL_BASE
*
selectionTool
=
m_toolMgr
->
FindTool
(
"pcbnew.InteractiveSelection"
);
TOOL_BASE
*
selectionTool
=
m_toolMgr
->
FindTool
(
"pcbnew.InteractiveSelection"
);
if
(
selectionTool
)
{
m_selectionTool
=
static_cast
<
SELECTION_TOOL
*>
(
selectionTool
);
m_selectionTool
=
static_cast
<
SELECTION_TOOL
*>
(
selectionTool
);
if
(
!
selectionTool
)
{
DisplayError
(
NULL
,
wxT
(
"pcbnew.InteractiveSelection tool is not available"
)
);
return
false
;
}
// Add context menu entries that are displayed when selection tool is active
// Add context menu entries that are displayed when selection tool is active
m_selectionTool
->
AddMenuItem
(
COMMON_ACTIONS
::
moveActivate
);
m_selectionTool
->
AddMenuItem
(
COMMON_ACTIONS
::
moveActivate
);
m_selectionTool
->
AddMenuItem
(
COMMON_ACTIONS
::
rotate
);
m_selectionTool
->
AddMenuItem
(
COMMON_ACTIONS
::
rotate
);
m_selectionTool
->
AddMenuItem
(
COMMON_ACTIONS
::
flip
);
m_selectionTool
->
AddMenuItem
(
COMMON_ACTIONS
::
flip
);
}
m_selectionTool
->
AddMenuItem
(
COMMON_ACTIONS
::
properties
);
else
{
setTransitions
();
DisplayError
(
NULL
,
wxT
(
"pcbnew.InteractiveSelection tool is not available"
)
);
return
false
;
}
return
true
;
return
true
;
}
}
...
@@ -85,7 +74,7 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent )
...
@@ -85,7 +74,7 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent )
return
0
;
// there are no items to operate on
return
0
;
// there are no items to operate on
VECTOR2D
dragPosition
;
VECTOR2D
dragPosition
;
bool
dragging
=
false
;
m_
dragging
=
false
;
bool
restore
=
false
;
// Should items' state be restored when finishing the tool?
bool
restore
=
false
;
// Should items' state be restored when finishing the tool?
VIEW_CONTROLS
*
controls
=
getViewControls
();
VIEW_CONTROLS
*
controls
=
getViewControls
();
...
@@ -105,23 +94,15 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent )
...
@@ -105,23 +94,15 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent )
// Dispatch TOOL_ACTIONs
// Dispatch TOOL_ACTIONs
else
if
(
evt
->
Category
()
==
TC_COMMAND
)
else
if
(
evt
->
Category
()
==
TC_COMMAND
)
{
{
VECTOR2D
cursorPos
=
getView
()
->
ToWorld
(
getViewControls
()
->
GetCursorPosition
()
);
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
rotate
)
)
Rotate
(
aEvent
);
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
rotate
)
)
// got rotation event?
else
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
flip
)
)
{
Flip
(
aEvent
);
m_state
.
Rotate
(
cursorPos
,
900.0
);
selection
.
group
->
ViewUpdate
(
VIEW_ITEM
::
GEOMETRY
);
}
else
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
flip
)
)
// got flip event?
{
m_state
.
Flip
(
cursorPos
);
selection
.
group
->
ViewUpdate
(
VIEW_ITEM
::
GEOMETRY
);
}
}
}
else
if
(
evt
->
IsMotion
()
||
evt
->
IsDrag
(
BUT_LEFT
)
)
else
if
(
evt
->
IsMotion
()
||
evt
->
IsDrag
(
BUT_LEFT
)
)
{
{
if
(
dragging
)
if
(
m_
dragging
)
{
{
// Drag items to the current cursor position
// Drag items to the current cursor position
VECTOR2D
movement
=
(
evt
->
Position
()
-
dragPosition
);
VECTOR2D
movement
=
(
evt
->
Position
()
-
dragPosition
);
...
@@ -138,16 +119,19 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent )
...
@@ -138,16 +119,19 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent )
m_state
.
Save
(
*
it
);
m_state
.
Save
(
*
it
);
}
}
dragging
=
true
;
m_
dragging
=
true
;
}
}
selection
.
group
->
ViewUpdate
(
VIEW_ITEM
::
GEOMETRY
);
selection
.
group
->
ViewUpdate
(
VIEW_ITEM
::
GEOMETRY
);
dragPosition
=
evt
->
Position
();
dragPosition
=
evt
->
Position
();
}
}
else
if
(
evt
->
IsMouseUp
(
BUT_LEFT
)
||
evt
->
IsClick
(
BUT_LEFT
)
)
else
if
(
evt
->
IsMouseUp
(
BUT_LEFT
)
||
evt
->
IsClick
(
BUT_LEFT
)
)
break
;
// Finish
break
;
// Finish
}
}
m_dragging
=
false
;
if
(
restore
)
if
(
restore
)
{
{
// Modifications has to be rollbacked, so restore the previous state of items
// Modifications has to be rollbacked, so restore the previous state of items
...
@@ -165,5 +149,91 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent )
...
@@ -165,5 +149,91 @@ int MOVE_TOOL::Main( TOOL_EVENT& aEvent )
controls
->
SetSnapping
(
false
);
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
controls
->
SetAutoPan
(
false
);
setTransitions
();
return
0
;
}
int
MOVE_TOOL
::
Properties
(
TOOL_EVENT
&
aEvent
)
{
const
SELECTION_TOOL
::
SELECTION
&
selection
=
m_selectionTool
->
GetSelection
();
// Properties are displayed when there is only one item selected
if
(
selection
.
items
.
size
()
==
1
)
{
// Display properties dialog
PCB_EDIT_FRAME
*
editFrame
=
static_cast
<
PCB_EDIT_FRAME
*>
(
m_toolMgr
->
GetEditFrame
()
);
BOARD_ITEM
*
item
=
*
selection
.
items
.
begin
();
editFrame
->
OnEditItemRequest
(
NULL
,
item
);
item
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
setTransitions
();
return
0
;
return
0
;
}
}
int
MOVE_TOOL
::
Rotate
(
TOOL_EVENT
&
aEvent
)
{
const
SELECTION_TOOL
::
SELECTION
&
selection
=
m_selectionTool
->
GetSelection
();
VECTOR2D
cursorPos
=
getView
()
->
ToWorld
(
getViewControls
()
->
GetCursorPosition
()
);
if
(
m_dragging
)
{
m_state
.
Rotate
(
cursorPos
,
900.0
);
selection
.
group
->
ViewUpdate
(
VIEW_ITEM
::
GEOMETRY
);
}
else
{
std
::
set
<
BOARD_ITEM
*>::
iterator
it
;
for
(
it
=
selection
.
items
.
begin
();
it
!=
selection
.
items
.
end
();
++
it
)
{
(
*
it
)
->
Rotate
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
),
900.0
);
(
*
it
)
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
setTransitions
();
}
return
0
;
}
int
MOVE_TOOL
::
Flip
(
TOOL_EVENT
&
aEvent
)
{
const
SELECTION_TOOL
::
SELECTION
&
selection
=
m_selectionTool
->
GetSelection
();
VECTOR2D
cursorPos
=
getView
()
->
ToWorld
(
getViewControls
()
->
GetCursorPosition
()
);
if
(
m_dragging
)
{
m_state
.
Flip
(
cursorPos
);
selection
.
group
->
ViewUpdate
(
VIEW_ITEM
::
GEOMETRY
);
}
else
{
std
::
set
<
BOARD_ITEM
*>::
iterator
it
;
for
(
it
=
selection
.
items
.
begin
();
it
!=
selection
.
items
.
end
();
++
it
)
{
(
*
it
)
->
Flip
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
(
*
it
)
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
LAYERS
);
}
setTransitions
();
}
return
0
;
}
void
MOVE_TOOL
::
setTransitions
()
{
Go
(
&
MOVE_TOOL
::
Main
,
COMMON_ACTIONS
::
moveActivate
.
MakeEvent
()
);
Go
(
&
MOVE_TOOL
::
Rotate
,
COMMON_ACTIONS
::
rotate
.
MakeEvent
()
);
Go
(
&
MOVE_TOOL
::
Flip
,
COMMON_ACTIONS
::
flip
.
MakeEvent
()
);
Go
(
&
MOVE_TOOL
::
Properties
,
COMMON_ACTIONS
::
properties
.
MakeEvent
()
);
}
pcbnew/tools/move_tool.h
View file @
b582162c
...
@@ -49,10 +49,9 @@ class MOVE_TOOL : public TOOL_INTERACTIVE
...
@@ -49,10 +49,9 @@ class MOVE_TOOL : public TOOL_INTERACTIVE
{
{
public
:
public
:
MOVE_TOOL
();
MOVE_TOOL
();
~
MOVE_TOOL
();
/// @copydoc TOOL_INTERACTIVE::Reset()
/// @copydoc TOOL_INTERACTIVE::Reset()
void
Reset
();
void
Reset
()
{}
;
/// @copydoc TOOL_INTERACTIVE::Init()
/// @copydoc TOOL_INTERACTIVE::Init()
bool
Init
();
bool
Init
();
...
@@ -61,15 +60,43 @@ public:
...
@@ -61,15 +60,43 @@ public:
* Function Main()
* Function Main()
*
*
* Main loop in which events are handled.
* Main loop in which events are handled.
* @param aEvent is the handled event.
*/
*/
int
Main
(
TOOL_EVENT
&
aEvent
);
int
Main
(
TOOL_EVENT
&
aEvent
);
/**
* Function Edit()
*
* Displays properties window for the selected object.
*/
int
Properties
(
TOOL_EVENT
&
aEvent
);
/**
* Function Rotate()
*
* Rotates currently selected items.
*/
int
Rotate
(
TOOL_EVENT
&
aEvent
);
/**
* Function Flip()
*
* Rotates currently selected items. The rotation point is the current cursor position.
*/
int
Flip
(
TOOL_EVENT
&
aEvent
);
private
:
private
:
/// Saves the state of items and allows to restore them
///
>
Saves the state of items and allows to restore them
ITEM_STATE
m_state
;
ITEM_STATE
m_state
;
/// Selection tool used for obtaining selected items
///
>
Selection tool used for obtaining selected items
SELECTION_TOOL
*
m_selectionTool
;
SELECTION_TOOL
*
m_selectionTool
;
///> Flag determining if anything is being dragged right now
bool
m_dragging
;
///> Sets up handlers for various events
void
setTransitions
();
};
};
#endif
#endif
pcbnew/tools/pcb_tools.cpp
View file @
b582162c
...
@@ -51,6 +51,7 @@ void PCB_EDIT_FRAME::setupTools()
...
@@ -51,6 +51,7 @@ void PCB_EDIT_FRAME::setupTools()
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
selectionActivate
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
selectionActivate
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
rotate
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
rotate
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
flip
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
flip
);
m_toolManager
->
RegisterAction
(
&
COMMON_ACTIONS
::
properties
);
// Register tools
// Register tools
m_toolManager
->
RegisterTool
(
new
SELECTION_TOOL
);
m_toolManager
->
RegisterTool
(
new
SELECTION_TOOL
);
...
...
pcbnew/tools/selection_tool.cpp
View file @
b582162c
...
@@ -102,11 +102,25 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
...
@@ -102,11 +102,25 @@ int SELECTION_TOOL::Main( TOOL_EVENT& aEvent )
}
}
// single click? Select single object
// single click? Select single object
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
else
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
{
if
(
!
m_additive
&&
m_selection
.
Size
()
>
1
)
clearSelection
();
selectSingle
(
evt
->
Position
()
);
selectSingle
(
evt
->
Position
()
);
}
else
if
(
evt
->
IsDblClick
(
BUT_LEFT
)
)
{
if
(
m_selection
.
Empty
()
)
selectSingle
(
evt
->
Position
()
);
// Display properties window
m_toolMgr
->
RunAction
(
"pcbnew.InteractiveMove.properties"
);
}
// drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
// drag with LMB? Select multiple objects (or at least draw a selection box) or drag them
if
(
evt
->
IsDrag
(
BUT_LEFT
)
)
else
if
(
evt
->
IsDrag
(
BUT_LEFT
)
)
{
{
if
(
m_selection
.
Empty
()
||
m_additive
)
if
(
m_selection
.
Empty
()
||
m_additive
)
{
{
...
...
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