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
a7cb90de
Commit
a7cb90de
authored
Feb 14, 2014
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some more minor refactorization.
parent
b7d43776
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
61 deletions
+68
-61
drawing_tool.cpp
pcbnew/tools/drawing_tool.cpp
+66
-57
drawing_tool.h
pcbnew/tools/drawing_tool.h
+2
-4
No files found.
pcbnew/tools/drawing_tool.cpp
View file @
a7cb90de
...
...
@@ -67,35 +67,30 @@ void DRAWING_TOOL::Reset( RESET_REASON aReason )
int
DRAWING_TOOL
::
DrawLine
(
TOOL_EVENT
&
aEvent
)
{
m_continous
=
true
;
return
draw
(
S_SEGMENT
);
return
drawSegment
(
S_SEGMENT
,
true
);
}
int
DRAWING_TOOL
::
DrawCircle
(
TOOL_EVENT
&
aEvent
)
{
m_continous
=
false
;
return
draw
(
S_CIRCLE
);
return
drawSegment
(
S_CIRCLE
,
false
);
}
int
DRAWING_TOOL
::
DrawArc
(
TOOL_EVENT
&
aEvent
)
{
m_continous
=
false
;
int
step
=
0
;
DRAWSEGMENT
graphic
;
DRAWSEGMENT
helperLine
;
bool
positive
=
true
;
bool
clockwise
=
true
;
double
startAngle
;
// angle of the first arc line
VECTOR2I
cursorPos
=
m_controls
->
GetCursorPosition
();
// Init the new item attributes
DRAWSEGMENT
graphic
;
graphic
.
SetShape
(
S_ARC
);
graphic
.
SetAngle
(
0.0
);
graphic
.
SetWidth
(
m_board
->
GetDesignSettings
().
m_DrawSegmentWidth
);
graphic
.
SetCenter
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
DRAWSEGMENT
helperLine
;
helperLine
.
SetShape
(
S_SEGMENT
);
helperLine
.
SetLayer
(
DRAW_N
);
helperLine
.
SetWidth
(
1
);
...
...
@@ -106,13 +101,23 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
m_controls
->
ShowCursor
(
true
);
m_controls
->
SetSnapping
(
true
);
m_controls
->
SetAutoPan
(
true
);
Activate
();
enum
ARC_STEPS
{
SET_ORIGIN
=
0
,
SET_END
,
SET_ANGLE
,
FINISHED
};
int
step
=
SET_ORIGIN
;
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
VECTOR2I
cursorPos
=
m_controls
->
GetCursorPosition
();
cursorPos
=
m_controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
break
;
...
...
@@ -126,14 +131,14 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
graphic
.
SetWidth
(
width
-
WIDTH_STEP
);
else
if
(
evt
->
KeyCode
()
==
'='
)
graphic
.
SetWidth
(
width
+
WIDTH_STEP
);
else
if
(
evt
->
KeyCode
()
==
'
'
)
else
if
(
evt
->
KeyCode
()
==
'
/
'
)
{
if
(
positiv
e
)
if
(
clockwis
e
)
graphic
.
SetAngle
(
graphic
.
GetAngle
()
-
3600.0
);
else
graphic
.
SetAngle
(
graphic
.
GetAngle
()
+
3600.0
);
positive
=
!
positiv
e
;
clockwise
=
!
clockwis
e
;
}
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
...
...
@@ -143,9 +148,9 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
{
switch
(
step
)
{
case
0
:
case
SET_ORIGIN
:
{
LAYER_NUM
layer
=
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
GetScreen
()
->
m_Active_Layer
;
LAYER_NUM
layer
=
m_frame
->
GetScreen
()
->
m_Active_Layer
;
if
(
IsCopperLayer
(
layer
)
)
{
...
...
@@ -154,8 +159,6 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
else
{
m_controls
->
SetAutoPan
(
true
);
helperLine
.
SetStart
(
graphic
.
GetCenter
()
);
graphic
.
SetLayer
(
layer
);
preview
.
Add
(
&
graphic
);
...
...
@@ -164,7 +167,14 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
break
;
case
2
:
case
SET_END
:
{
VECTOR2D
startLine
(
graphic
.
GetArcStart
()
-
graphic
.
GetCenter
()
);
startAngle
=
startLine
.
Angle
();
}
break
;
case
SET_ANGLE
:
{
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
graphic
.
GetCenter
()
)
{
...
...
@@ -175,10 +185,9 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
}
break
;
}
if
(
++
step
==
3
)
if
(
++
step
==
FINISHED
)
break
;
}
...
...
@@ -186,31 +195,27 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
{
switch
(
step
)
{
case
0
:
case
SET_ORIGIN
:
graphic
.
SetCenter
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
break
;
case
1
:
case
SET_END
:
helperLine
.
SetEnd
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
graphic
.
SetArcStart
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
break
;
case
2
:
case
SET_ANGLE
:
{
VECTOR2D
firstLine
(
graphic
.
GetArcStart
()
-
graphic
.
GetCenter
()
);
double
firstAngle
=
firstLine
.
Angle
();
VECTOR2D
secondLine
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
-
graphic
.
GetCenter
()
);
double
secondAngle
=
secondLine
.
Angle
();
// Compute the current angle
VECTOR2D
endLine
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
-
graphic
.
GetCenter
()
);
double
newAngle
=
RAD2DECIDEG
(
endLine
.
Angle
()
-
startAngle
);
double
angle
=
RAD2DECIDEG
(
secondAngle
-
firstAngle
);
if
(
clockwise
&&
newAngle
<
0.0
)
newAngle
+=
3600.0
;
else
if
(
!
clockwise
&&
newAngle
>
0.0
)
newAngle
-=
3600.0
;
if
(
positive
&&
angle
<
0.0
)
angle
+=
3600.0
;
else
if
(
!
positive
&&
angle
>
0.0
)
angle
-=
3600.0
;
graphic
.
SetAngle
(
angle
);
graphic
.
SetAngle
(
newAngle
);
}
break
;
}
...
...
@@ -309,23 +314,18 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
int
DRAWING_TOOL
::
DrawDimension
(
TOOL_EVENT
&
aEvent
)
{
m_continous
=
false
;
int
step
=
0
;
DIMENSION
*
dimension
=
new
DIMENSION
(
m_board
);
// Init the new item attributes
dimension
->
Text
().
SetSize
(
m_board
->
GetDesignSettings
().
m_PcbTextSize
);
int
width
=
m_board
->
GetDesignSettings
().
m_PcbTextWidth
;
int
max
t
hickness
=
Clamp_Text_PenSize
(
width
,
dimension
->
Text
().
GetSize
()
);
int
max
T
hickness
=
Clamp_Text_PenSize
(
width
,
dimension
->
Text
().
GetSize
()
);
if
(
width
>
max
t
hickness
)
width
=
max
t
hickness
;
if
(
width
>
max
T
hickness
)
width
=
max
T
hickness
;
dimension
->
Text
().
SetThickness
(
width
);
dimension
->
SetWidth
(
width
);
dimension
->
SetFlags
(
IS_NEW
);
dimension
->
AdjustDimensionDetails
();
// Add a VIEW_GROUP that serves as a preview for the new item
...
...
@@ -337,6 +337,15 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
Activate
();
enum
DIMENSION_STEPS
{
SET_ORIGIN
=
0
,
SET_END
,
SET_HEIGHT
,
FINISHED
};
int
step
=
SET_ORIGIN
;
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
...
...
@@ -350,7 +359,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
else
if
(
evt
->
IsKeyUp
()
)
{
int
width
=
dimension
->
GetWidth
();
width
=
dimension
->
GetWidth
();
// Modify the new item width
if
(
evt
->
KeyCode
()
==
'-'
&&
width
>
WIDTH_STEP
)
...
...
@@ -365,7 +374,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
{
switch
(
step
)
{
case
0
:
case
SET_ORIGIN
:
{
LAYER_NUM
layer
=
m_frame
->
GetScreen
()
->
m_Active_Layer
;
...
...
@@ -386,7 +395,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
}
break
;
case
2
:
case
SET_HEIGHT
:
{
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
dimension
->
GetPosition
()
)
{
...
...
@@ -398,7 +407,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
break
;
}
if
(
++
step
==
3
)
if
(
++
step
==
FINISHED
)
break
;
}
...
...
@@ -406,13 +415,13 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
{
switch
(
step
)
{
case
1
:
case
SET_END
:
dimension
->
SetEnd
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
break
;
case
2
:
case
SET_HEIGHT
:
{
/
* Calculating the direction of travel perpendicular to the selected axis. */
/
/ Calculating the direction of travel perpendicular to the selected axis
double
angle
=
dimension
->
GetAngle
()
+
(
M_PI
/
2
);
wxPoint
pos
(
cursorPos
.
x
,
cursorPos
.
y
);
...
...
@@ -475,7 +484,7 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
VECTOR2I
cursorPos
=
m_controls
->
GetCursorPosition
();
cursorPos
=
m_controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
{
...
...
@@ -596,7 +605,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
}
int
DRAWING_TOOL
::
draw
(
int
aShape
)
int
DRAWING_TOOL
::
draw
Segment
(
int
aShape
,
bool
aContinous
)
{
// Only two shapes are currently supported
assert
(
aShape
==
S_SEGMENT
||
aShape
==
S_CIRCLE
);
...
...
@@ -670,7 +679,7 @@ int DRAWING_TOOL::draw( int aShape )
m_board
->
Add
(
newItem
);
newItem
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
if
(
m_c
ontinous
)
if
(
aC
ontinous
)
graphic
.
SetStart
(
graphic
.
GetEnd
()
);
// This is the origin point for a new item
else
break
;
...
...
pcbnew/tools/drawing_tool.h
View file @
a7cb90de
...
...
@@ -77,7 +77,8 @@ public:
private
:
///> Starts drawing a selected shape (i.e. DRAWSEGMENT).
///> @param aShape is the type of created shape (@see STROKE_T).
int
draw
(
int
aShape
);
///> @param aContinous decides if there is only one or multiple shapes to draw.
int
drawSegment
(
int
aShape
,
bool
aContinous
);
///> Draws a polygon, that is added as a zone or a keepout area.
///> @param aKeepout decides if the drawn polygon is a zone or a keepout area.
...
...
@@ -86,9 +87,6 @@ private:
///> Sets up handlers for various events.
void
setTransitions
();
///> Should drawing be stopped after drawing one object or should it continue with another one.
bool
m_continous
;
KIGFX
::
VIEW
*
m_view
;
KIGFX
::
VIEW_CONTROLS
*
m_controls
;
BOARD
*
m_board
;
...
...
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