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
8c43c216
Commit
8c43c216
authored
Mar 06, 2014
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
45 degrees mode for POINT_EDITOR.
parent
2889a7a1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
22 deletions
+106
-22
edit_points.cpp
pcbnew/tools/edit_points.cpp
+1
-6
edit_points.h
pcbnew/tools/edit_points.h
+72
-7
point_editor.cpp
pcbnew/tools/point_editor.cpp
+33
-9
No files found.
pcbnew/tools/edit_points.cpp
View file @
8c43c216
...
...
@@ -35,11 +35,6 @@ EDIT_POINTS::EDIT_POINTS( EDA_ITEM* aParent ) :
}
EDIT_POINTS
::~
EDIT_POINTS
()
{
}
EDIT_POINT
*
EDIT_POINTS
::
FindPoint
(
const
VECTOR2I
&
aLocation
)
{
float
size
=
m_view
->
ToWorld
(
EDIT_POINT
::
POINT_SIZE
);
...
...
@@ -59,7 +54,7 @@ EDIT_POINT* EDIT_POINTS::FindPoint( const VECTOR2I& aLocation )
void
EDIT_POINTS
::
ViewDraw
(
int
aLayer
,
KIGFX
::
GAL
*
aGal
)
const
{
aGal
->
SetFillColor
(
KIGFX
::
COLOR4D
(
1.0
,
1.0
,
1.0
,
1.0
)
);
// TODO dynamic color depending on parent's color
aGal
->
SetFillColor
(
KIGFX
::
COLOR4D
(
1.0
,
1.0
,
1.0
,
1.0
)
);
aGal
->
SetIsFill
(
true
);
aGal
->
SetIsStroke
(
false
);
aGal
->
PushDepth
();
...
...
pcbnew/tools/edit_points.h
View file @
8c43c216
...
...
@@ -80,10 +80,13 @@ public:
void
SetConstraint
(
EDIT_POINT_CONSTRAINT
*
aConstraint
)
{
if
(
m_constraint
)
delete
m_constraint
;
m_constraint
=
aConstraint
;
}
void
ClearConstraint
(
EDIT_POINT_CONSTRAINT
*
aConstraint
)
void
ClearConstraint
()
{
delete
m_constraint
;
m_constraint
=
NULL
;
...
...
@@ -94,12 +97,22 @@ public:
return
m_constraint
;
}
bool
IsConstrained
()
const
{
return
m_constraint
!=
NULL
;
}
void
ApplyConstraint
()
{
if
(
m_constraint
)
m_constraint
->
Apply
();
}
bool
operator
==
(
const
EDIT_POINT
&
aOther
)
const
{
return
m_point
==
aOther
.
m_point
;
}
///> Single point size in pixels
static
const
int
POINT_SIZE
=
10
;
...
...
@@ -113,7 +126,6 @@ class EDIT_POINTS : public EDA_ITEM
{
public
:
EDIT_POINTS
(
EDA_ITEM
*
aParent
);
~
EDIT_POINTS
();
/**
* Function FindPoint
...
...
@@ -134,7 +146,39 @@ public:
void
Add
(
const
VECTOR2I
&
aPoint
)
{
m_points
.
push_back
(
EDIT_POINT
(
aPoint
)
);
Add
(
EDIT_POINT
(
aPoint
)
);
}
EDIT_POINT
*
Previous
(
const
EDIT_POINT
&
aPoint
)
{
for
(
unsigned
int
i
=
0
;
i
<
m_points
.
size
();
++
i
)
{
if
(
m_points
[
i
]
==
aPoint
)
{
if
(
i
==
0
)
return
&
m_points
[
m_points
.
size
()
-
1
];
else
return
&
m_points
[
i
-
1
];
}
}
return
NULL
;
}
EDIT_POINT
*
Next
(
const
EDIT_POINT
&
aPoint
)
{
for
(
unsigned
int
i
=
0
;
i
<
m_points
.
size
();
++
i
)
{
if
(
m_points
[
i
]
==
aPoint
)
{
if
(
i
==
m_points
.
size
()
-
1
)
return
&
m_points
[
0
];
else
return
&
m_points
[
i
+
1
];
}
}
return
NULL
;
}
EDIT_POINT
&
operator
[](
unsigned
int
aIndex
)
...
...
@@ -182,8 +226,6 @@ public:
EDIT_POINT_CONSTRAINT
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{}
virtual
~
EPC_VERTICAL
()
{};
virtual
void
Apply
()
{
VECTOR2I
point
=
m_constrained
.
GetPosition
();
...
...
@@ -208,8 +250,6 @@ public:
EDIT_POINT_CONSTRAINT
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{}
virtual
~
EPC_HORIZONTAL
()
{};
virtual
void
Apply
()
{
VECTOR2I
point
=
m_constrained
.
GetPosition
();
...
...
@@ -222,6 +262,31 @@ private:
};
class
EPC_45DEGREE
:
public
EDIT_POINT_CONSTRAINT
{
public
:
EPC_45DEGREE
(
EDIT_POINT
&
aConstrained
,
const
EDIT_POINT
&
aConstrainer
)
:
EDIT_POINT_CONSTRAINT
(
aConstrained
),
m_constrainer
(
aConstrainer
)
{}
virtual
void
Apply
()
{
// Current line vector
VECTOR2I
lineVector
(
m_constrained
.
GetPosition
()
-
m_constrainer
.
GetPosition
()
);
double
angle
=
lineVector
.
Angle
();
// Find the closest angle, which is a multiple of 45 degrees
double
newAngle
=
round
(
angle
/
(
M_PI
/
4
.
0
)
)
*
M_PI
/
4
.
0
;
VECTOR2I
newLineVector
=
lineVector
.
Rotate
(
newAngle
-
angle
);
m_constrained
.
SetPosition
(
m_constrainer
.
GetPosition
()
+
newLineVector
);
}
private
:
const
EDIT_POINT
&
m_constrainer
;
};
class
EPC_CIRCLE
:
public
EDIT_POINT_CONSTRAINT
{
public
:
...
...
pcbnew/tools/point_editor.cpp
View file @
8c43c216
...
...
@@ -26,6 +26,7 @@
#include <tool/tool_manager.h>
#include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <confirm.h>
#include "common_actions.h"
...
...
@@ -96,6 +97,7 @@ public:
}
default
:
points
.
reset
();
break
;
}
...
...
@@ -139,19 +141,27 @@ bool POINT_EDITOR::Init()
int
POINT_EDITOR
::
OnSelectionChange
(
TOOL_EVENT
&
aEvent
)
{
const
SELECTION_TOOL
::
SELECTION
&
selection
=
m_selectionTool
->
GetSelection
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
if
(
selection
.
Size
()
==
1
)
{
Activate
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
KIGFX
::
VIEW
*
view
=
getView
();
// TODO should be updated on canvas switch?
PCB_EDIT_FRAME
*
editFrame
=
getEditFrame
<
PCB_EDIT_FRAME
>
();
EDA_ITEM
*
item
=
selection
.
items
.
GetPickedItem
(
0
);
m_editPoints
=
EDIT_POINTS_FACTORY
::
Make
(
item
);
m_toolMgr
->
GetView
()
->
Add
(
m_editPoints
.
get
()
);
if
(
!
m_editPoints
)
{
setTransitions
();
return
0
;
}
view
->
Add
(
m_editPoints
.
get
()
);
m_dragPoint
=
NULL
;
bool
modified
=
false
;
Activate
();
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
...
...
@@ -196,6 +206,20 @@ int POINT_EDITOR::OnSelectionChange( TOOL_EVENT& aEvent )
modified
=
true
;
}
if
(
evt
->
Modifier
(
MD_CTRL
)
)
// 45 degrees mode
{
if
(
!
m_dragPoint
->
IsConstrained
()
)
{
// Find the previous point to be used as constrainer
EDIT_POINT
*
constrainer
=
m_editPoints
->
Previous
(
*
m_dragPoint
);
m_dragPoint
->
SetConstraint
(
new
EPC_45DEGREE
(
*
m_dragPoint
,
*
constrainer
)
);
}
}
else
{
m_dragPoint
->
ClearConstraint
();
}
m_dragPoint
->
SetPosition
(
controls
->
GetCursorPosition
()
);
m_dragPoint
->
ApplyConstraint
();
updateItem
();
...
...
@@ -238,14 +262,14 @@ int POINT_EDITOR::OnSelectionChange( TOOL_EVENT& aEvent )
{
finishItem
();
item
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
m_toolMgr
->
GetView
()
->
Remove
(
m_editPoints
.
get
()
);
view
->
Remove
(
m_editPoints
.
get
()
);
m_editPoints
.
reset
();
}
}
controls
->
ShowCursor
(
false
);
controls
->
SetAutoPan
(
false
);
controls
->
SetSnapping
(
false
);
controls
->
ShowCursor
(
false
);
controls
->
SetAutoPan
(
false
);
controls
->
SetSnapping
(
false
);
}
setTransitions
();
...
...
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