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
31f7ecc1
Commit
31f7ecc1
authored
Sep 09, 2013
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First version of the move tool.
parent
f1b0ffd3
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
303 additions
and
17 deletions
+303
-17
view_group.cpp
common/view/view_group.cpp
+0
-12
view_group.h
include/view/view_group.h
+0
-3
CMakeLists.txt
pcbnew/CMakeLists.txt
+1
-0
move_tool.cpp
pcbnew/tools/move_tool.cpp
+185
-0
move_tool.h
pcbnew/tools/move_tool.h
+113
-0
pcb_tools.cpp
pcbnew/tools/pcb_tools.cpp
+4
-2
No files found.
common/view/view_group.cpp
View file @
31f7ecc1
...
...
@@ -56,21 +56,18 @@ VIEW_GROUP::~VIEW_GROUP()
void
VIEW_GROUP
::
Add
(
VIEW_ITEM
*
aItem
)
{
m_items
.
insert
(
aItem
);
updateBbox
();
}
void
VIEW_GROUP
::
Remove
(
VIEW_ITEM
*
aItem
)
{
m_items
.
erase
(
aItem
);
updateBbox
();
}
void
VIEW_GROUP
::
Clear
()
{
m_items
.
clear
();
updateBbox
();
}
...
...
@@ -121,15 +118,6 @@ void VIEW_GROUP::ViewGetLayers( int aLayers[], int& aCount ) const
}
/*void VIEW_GROUP::ViewUpdate( int aUpdateFlags, bool aForceImmediateRedraw )
{
BOOST_FOREACH( VIEW_ITEM* item, m_items )
{
item->ViewUpdate( aUpdateFlags, aForceImmediateRedraw );
}
}*/
void
VIEW_GROUP
::
updateBbox
()
{
// Save the used VIEW, as it used nulled during Remove()
...
...
include/view/view_group.h
View file @
31f7ecc1
...
...
@@ -120,9 +120,6 @@ public:
*/
virtual
void
ViewGetLayers
(
int
aLayers
[],
int
&
aCount
)
const
;
/// @copydoc VIEW_ITEM::ViewUpdate()
virtual
void
ViewUpdate
(
int
aUpdateFlags
,
bool
aForceImmediateRedraw
);
/**
* Function SetLayer()
* Sets layer used to draw the group.
...
...
pcbnew/CMakeLists.txt
View file @
31f7ecc1
...
...
@@ -219,6 +219,7 @@ set(PCBNEW_CLASS_SRCS
tools/selection_tool.cpp
tools/selection_area.cpp
tools/move_tool.cpp
tools/pcb_tools.cpp
)
...
...
pcbnew/tools/move_tool.cpp
0 → 100644
View file @
31f7ecc1
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <class_board.h>
#include <class_module.h>
#include <tool/tool_manager.h>
#include <view/view_group.h>
#include "selection_tool.h"
#include "move_tool.h"
using
namespace
KiGfx
;
using
boost
::
optional
;
MOVE_TOOL
::
MOVE_TOOL
()
:
TOOL_INTERACTIVE
(
"pcbnew.InteractiveMove"
),
m_selectionTool
(
NULL
)
{
}
MOVE_TOOL
::~
MOVE_TOOL
()
{
}
void
MOVE_TOOL
::
Reset
()
{
// Find the selection tool, so they can cooperate
TOOL_BASE
*
selectionTool
=
m_toolMgr
->
FindTool
(
std
::
string
(
"pcbnew.InteractiveSelection"
)
);
if
(
selectionTool
)
{
m_selectionTool
=
static_cast
<
SELECTION_TOOL
*>
(
selectionTool
);
}
else
{
wxLogError
(
"pcbnew.InteractiveSelection tool is not available"
);
return
;
}
// the tool launches upon reception of activate ("pcbnew.InteractiveMove")
Go
(
&
MOVE_TOOL
::
Main
,
TOOL_EVENT
(
TC_Command
,
TA_ActivateTool
,
GetName
()
)
);
//"pcbnew.InteractiveMove"));
}
int
MOVE_TOOL
::
Main
(
TOOL_EVENT
&
aEvent
)
{
VECTOR2D
dragPosition
;
bool
dragging
=
false
;
bool
restore
=
false
;
VIEW
*
view
=
m_toolMgr
->
GetView
();
std
::
set
<
BOARD_ITEM
*>
selection
;
VIEW_GROUP
items
(
view
);
view
->
Add
(
&
items
);
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
if
(
evt
->
IsCancel
()
)
{
restore
=
true
;
m_toolMgr
->
PassEvent
();
break
;
// Finish
}
if
(
evt
->
IsDrag
(
MB_Left
)
)
{
if
(
dragging
)
{
// Dragging is alre
VECTOR2D
movement
=
(
evt
->
Position
()
-
dragPosition
);
std
::
set
<
BOARD_ITEM
*>::
iterator
it
,
it_end
;
for
(
it
=
selection
.
begin
(),
it_end
=
selection
.
end
();
it
!=
it_end
;
++
it
)
{
(
*
it
)
->
Move
(
wxPoint
(
movement
.
x
,
movement
.
y
)
);
}
items
.
ViewUpdate
(
VIEW_ITEM
::
GEOMETRY
);
}
else
{
// Begin dragging
selection
=
m_selectionTool
->
GetSelection
();
std
::
set
<
BOARD_ITEM
*>::
iterator
it
;
for
(
it
=
selection
.
begin
();
it
!=
selection
.
end
();
++
it
)
{
viewGroupAdd
(
*
it
,
&
items
);
// but if a MODULE was selected, then we need to redraw all of it's parts
if
(
(
*
it
)
->
Type
()
==
PCB_MODULE_T
)
{
MODULE
*
module
=
static_cast
<
MODULE
*>
(
*
it
);
// Move everything that belongs to the module
for
(
D_PAD
*
pad
=
module
->
Pads
().
GetFirst
();
pad
;
pad
=
pad
->
Next
()
)
viewGroupAdd
(
pad
,
&
items
);
for
(
BOARD_ITEM
*
drawing
=
module
->
GraphicalItems
().
GetFirst
();
drawing
;
drawing
=
drawing
->
Next
()
)
viewGroupAdd
(
drawing
,
&
items
);
viewGroupAdd
(
&
module
->
Reference
(),
&
items
);
viewGroupAdd
(
&
module
->
Value
(),
&
items
);
}
}
items
.
ViewUpdate
(
VIEW_ITEM
::
GEOMETRY
);
dragging
=
true
;
}
dragPosition
=
evt
->
Position
();
}
else
if
(
evt
->
Category
()
==
TC_Mouse
)
// Filter out other events
{
if
(
dragging
)
{
break
;
// Finish
}
}
}
// Clean-up after movement
std
::
deque
<
ITEM_STATE
>::
iterator
it
,
it_end
;
if
(
restore
)
{
// Movement has to be rollbacked, so restore previous state of items
for
(
it
=
m_itemsState
.
begin
(),
it_end
=
m_itemsState
.
end
();
it
!=
it_end
;
++
it
)
it
->
Restore
();
}
else
{
// Apply changes
for
(
it
=
m_itemsState
.
begin
(),
it_end
=
m_itemsState
.
end
();
it
!=
it_end
;
++
it
)
{
it
->
RestoreVisibility
();
it
->
item
->
ViewUpdate
(
VIEW_ITEM
::
GEOMETRY
);
}
}
m_itemsState
.
clear
();
items
.
Clear
();
view
->
Remove
(
&
items
);
return
0
;
}
void
MOVE_TOOL
::
viewGroupAdd
(
BOARD_ITEM
*
aItem
,
KiGfx
::
VIEW_GROUP
*
aGroup
)
{
// Save the state of the selected items, in case it has to be restored
ITEM_STATE
state
;
state
.
Save
(
aItem
);
m_itemsState
.
push_back
(
state
);
// Add items to the VIEW_GROUP, so they will be displayed on the overlay
// while dragging
aGroup
->
Add
(
aItem
);
// Set the original item as invisible
aItem
->
ViewSetVisible
(
false
);
}
pcbnew/tools/move_tool.h
0 → 100644
View file @
31f7ecc1
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2013 CERN
* @author @author Maciej Suminski <maciej.suminski@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __MOVE_TOOL_H
#define __MOVE_TOOL_H
#include <math/vector2d.h>
#include <tool/tool_interactive.h>
class
BOARD_ITEM
;
class
SELECTION_TOOL
;
namespace
KiGfx
{
class
VIEW_GROUP
;
}
/**
* Class MOVE_TOOL
* /// TODO DOCS!!
* Our sample move tool: currently supports:
* - pick single objects (click LMB)
* - add objects to existing move (Shift+LMB)
* - draw move box (drag LMB)
*
* WORK IN PROGRESS. CONSIDER AS A DEMO!
*/
class
MOVE_TOOL
:
public
TOOL_INTERACTIVE
{
public
:
MOVE_TOOL
();
~
MOVE_TOOL
();
/**
* Function Reset()
*
* Resets the tool and initializes it.
*/
void
Reset
();
/**
* Function Main()
*
* Main loop in which events are handled.
*/
int
Main
(
TOOL_EVENT
&
aEvent
);
private
:
void
viewGroupAdd
(
BOARD_ITEM
*
aItem
,
KiGfx
::
VIEW_GROUP
*
aGroup
);
/// Structure for (re)storing BOARD_ITEM state
typedef
struct
{
BOARD_ITEM
*
item
;
/// Pointer to the item
VECTOR2D
position
;
/// Original position of the item
bool
visible
;
/// Original visibility flag
void
Save
(
BOARD_ITEM
*
aItem
)
{
wxPoint
pos
=
aItem
->
GetPosition
();
item
=
aItem
;
position
.
x
=
pos
.
x
;
position
.
y
=
pos
.
y
;
visible
=
aItem
->
ViewIsVisible
();
}
void
RestorePosition
()
{
item
->
SetPosition
(
wxPoint
(
position
.
x
,
position
.
y
)
);
}
void
RestoreVisibility
()
{
item
->
ViewSetVisible
(
visible
);
}
void
Restore
()
{
RestorePosition
();
RestoreVisibility
();
}
}
ITEM_STATE
;
/// Selection tool used for obtaining selected items
SELECTION_TOOL
*
m_selectionTool
;
std
::
deque
<
ITEM_STATE
>
m_itemsState
;
};
#endif
pcbnew/tools/pcb_tools.cpp
View file @
31f7ecc1
...
...
@@ -35,16 +35,18 @@
#include <pcbnew_id.h>
#include "selection_tool.h"
#include "move_tool.h"
void
PCB_EDIT_FRAME
::
setupTools
()
{
//
create the manager and dispatcher. Route draw panel events to the dispatcher.
//
Create the manager and dispatcher. Route draw panel events to the dispatcher
m_toolManager
=
new
TOOL_MANAGER
;
m_toolDispatcher
=
new
TOOL_DISPATCHER
(
m_toolManager
,
this
);
m_galCanvas
->
SetEventDispatcher
(
m_toolDispatcher
);
//
register our selection tool.
//
Register tools
m_toolManager
->
RegisterTool
(
new
SELECTION_TOOL
);
m_toolManager
->
RegisterTool
(
new
MOVE_TOOL
);
}
...
...
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