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
2b62a852
Commit
2b62a852
authored
Feb 14, 2014
by
Maciej Suminski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring: made VIEW, VIEW_CONTROLS, BOARD and PCB_EDIT_FRAME fields in DRAWING_TOOL.
parent
597e98db
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
155 deletions
+146
-155
drawing_tool.cpp
pcbnew/tools/drawing_tool.cpp
+132
-153
drawing_tool.h
pcbnew/tools/drawing_tool.h
+14
-2
No files found.
pcbnew/tools/drawing_tool.cpp
View file @
2b62a852
...
...
@@ -55,6 +55,12 @@ DRAWING_TOOL::~DRAWING_TOOL()
void
DRAWING_TOOL
::
Reset
(
RESET_REASON
aReason
)
{
// Init variables used by every drawing tool
m_view
=
getView
();
m_controls
=
getViewControls
();
m_board
=
getModel
<
BOARD
>
(
PCB_T
);
m_frame
=
getEditFrame
<
PCB_EDIT_FRAME
>
();
setTransitions
();
}
...
...
@@ -81,9 +87,6 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
int
step
=
0
;
KIGFX
::
VIEW
*
view
=
getView
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
BOARD
*
board
=
getModel
<
BOARD
>
(
PCB_T
);
DRAWSEGMENT
graphic
;
DRAWSEGMENT
helperLine
;
bool
positive
=
true
;
...
...
@@ -91,25 +94,25 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
// Init the new item attributes
graphic
.
SetShape
(
S_ARC
);
graphic
.
SetAngle
(
0.0
);
graphic
.
SetWidth
(
board
->
GetDesignSettings
().
m_DrawSegmentWidth
);
graphic
.
SetWidth
(
m_
board
->
GetDesignSettings
().
m_DrawSegmentWidth
);
helperLine
.
SetShape
(
S_SEGMENT
);
helperLine
.
SetLayer
(
DRAW_N
);
helperLine
.
SetWidth
(
1
);
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX
::
VIEW_GROUP
preview
(
view
);
view
->
Add
(
&
preview
);
KIGFX
::
VIEW_GROUP
preview
(
m_
view
);
m_
view
->
Add
(
&
preview
);
controls
->
ShowCursor
(
true
);
controls
->
SetSnapping
(
true
);
m_
controls
->
ShowCursor
(
true
);
m_
controls
->
SetSnapping
(
true
);
Activate
();
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
VECTOR2I
cursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_
controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
break
;
...
...
@@ -151,7 +154,7 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
else
{
controls
->
SetAutoPan
(
true
);
m_
controls
->
SetAutoPan
(
true
);
helperLine
.
SetStart
(
graphic
.
GetCenter
()
);
graphic
.
SetLayer
(
layer
);
...
...
@@ -166,8 +169,8 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
graphic
.
GetCenter
()
)
{
DRAWSEGMENT
*
newItem
=
new
DRAWSEGMENT
(
graphic
);
view
->
Add
(
newItem
);
board
->
Add
(
newItem
);
m_
view
->
Add
(
newItem
);
m_
board
->
Add
(
newItem
);
newItem
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
}
...
...
@@ -217,10 +220,10 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
}
controls
->
ShowCursor
(
false
);
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
view
->
Remove
(
&
preview
);
m_
controls
->
ShowCursor
(
false
);
m_
controls
->
SetSnapping
(
false
);
m_
controls
->
SetAutoPan
(
false
);
m_
view
->
Remove
(
&
preview
);
setTransitions
();
...
...
@@ -228,24 +231,21 @@ int DRAWING_TOOL::DrawArc( TOOL_EVENT& aEvent )
}
int
DRAWING_TOOL
::
draw
(
STROKE_T
aShape
)
int
DRAWING_TOOL
::
draw
(
int
aShape
)
{
bool
started
=
false
;
KIGFX
::
VIEW
*
view
=
getView
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
BOARD
*
board
=
getModel
<
BOARD
>
(
PCB_T
);
DRAWSEGMENT
graphic
;
// Init the new item attributes
graphic
.
SetShape
(
aShape
);
graphic
.
SetWidth
(
board
->
GetDesignSettings
().
m_DrawSegmentWidth
);
graphic
.
SetShape
(
(
STROKE_T
)
aShape
);
graphic
.
SetWidth
(
m_
board
->
GetDesignSettings
().
m_DrawSegmentWidth
);
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX
::
VIEW_GROUP
preview
(
view
);
view
->
Add
(
&
preview
);
KIGFX
::
VIEW_GROUP
preview
(
m_
view
);
m_
view
->
Add
(
&
preview
);
controls
->
ShowCursor
(
true
);
controls
->
SetSnapping
(
true
);
m_
controls
->
ShowCursor
(
true
);
m_
controls
->
SetSnapping
(
true
);
Activate
();
...
...
@@ -254,7 +254,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
{
// Enable 45 degrees lines only mode by holding shift
bool
linesAngle45
=
evt
->
Modifier
(
MD_SHIFT
);
VECTOR2I
cursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_
controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
break
;
...
...
@@ -276,7 +276,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
{
if
(
!
started
)
{
LAYER_NUM
layer
=
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
GetScreen
()
->
m_Active_Layer
;
LAYER_NUM
layer
=
m_frame
->
GetScreen
()
->
m_Active_Layer
;
if
(
IsCopperLayer
(
layer
)
)
{
...
...
@@ -284,7 +284,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
}
else
{
controls
->
SetAutoPan
(
true
);
m_
controls
->
SetAutoPan
(
true
);
graphic
.
SetStart
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
graphic
.
SetLayer
(
layer
);
...
...
@@ -298,8 +298,8 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
graphic
.
GetStart
()
)
{
DRAWSEGMENT
*
newItem
=
new
DRAWSEGMENT
(
graphic
);
view
->
Add
(
newItem
);
board
->
Add
(
newItem
);
m_
view
->
Add
(
newItem
);
m_
board
->
Add
(
newItem
);
newItem
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
if
(
m_continous
)
...
...
@@ -325,7 +325,7 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
// Snap the new line to the grid // TODO fix it, does not work good..
VECTOR2D
newLineEnd
=
VECTOR2D
(
graphic
.
GetStart
()
)
+
newLineVector
;
VECTOR2D
snapped
=
view
->
GetGAL
()
->
GetGridPoint
(
newLineEnd
);
VECTOR2D
snapped
=
m_
view
->
GetGAL
()
->
GetGridPoint
(
newLineEnd
);
graphic
.
SetEnd
(
wxPoint
(
snapped
.
x
,
snapped
.
y
)
);
}
...
...
@@ -339,10 +339,10 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
}
}
controls
->
ShowCursor
(
false
);
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
view
->
Remove
(
&
preview
);
m_
controls
->
ShowCursor
(
false
);
m_
controls
->
SetSnapping
(
false
);
m_
controls
->
SetAutoPan
(
false
);
m_
view
->
Remove
(
&
preview
);
setTransitions
();
return
0
;
...
...
@@ -351,11 +351,8 @@ int DRAWING_TOOL::draw( STROKE_T aShape )
int
DRAWING_TOOL
::
DrawText
(
TOOL_EVENT
&
aEvent
)
{
KIGFX
::
VIEW
*
view
=
getView
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
// Init the new item attributes
TEXTE_PCB
*
newText
=
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
CreateTextePcb
(
NULL
);
TEXTE_PCB
*
newText
=
m_frame
->
CreateTextePcb
(
NULL
);
if
(
newText
==
NULL
)
{
setTransitions
();
...
...
@@ -363,25 +360,25 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
}
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX
::
VIEW_GROUP
preview
(
view
);
KIGFX
::
VIEW_GROUP
preview
(
m_
view
);
preview
.
Add
(
newText
);
view
->
Add
(
&
preview
);
m_
view
->
Add
(
&
preview
);
controls
->
ShowCursor
(
true
);
controls
->
SetSnapping
(
true
);
controls
->
SetAutoPan
(
true
);
m_
controls
->
ShowCursor
(
true
);
m_
controls
->
SetSnapping
(
true
);
m_
controls
->
SetAutoPan
(
true
);
Activate
();
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
VECTOR2I
cursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_
controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
{
// it was already added by CreateTextPcb()
getModel
<
BOARD
>
(
PCB_T
)
->
Delete
(
newText
);
m_board
->
Delete
(
newText
);
break
;
}
...
...
@@ -389,7 +386,7 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
{
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
rotate
)
)
{
newText
->
Rotate
(
newText
->
GetPosition
(),
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
GetRotationAngle
()
);
newText
->
Rotate
(
newText
->
GetPosition
(),
m_frame
->
GetRotationAngle
()
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
else
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
flip
)
)
...
...
@@ -402,8 +399,8 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
else
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
{
newText
->
ClearFlags
();
view
->
Add
(
newText
);
// board->Add( newText ); // it is already added by CreateTextePcb()
m_
view
->
Add
(
newText
);
//
m_
board->Add( newText ); // it is already added by CreateTextePcb()
newText
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
break
;
}
...
...
@@ -417,10 +414,10 @@ int DRAWING_TOOL::DrawText( TOOL_EVENT& aEvent )
}
}
controls
->
ShowCursor
(
false
);
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
view
->
Remove
(
&
preview
);
m_
controls
->
ShowCursor
(
false
);
m_
controls
->
SetSnapping
(
false
);
m_
controls
->
SetAutoPan
(
false
);
m_
view
->
Remove
(
&
preview
);
setTransitions
();
...
...
@@ -434,14 +431,11 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
int
step
=
0
;
KIGFX
::
VIEW
*
view
=
getView
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
BOARD
*
board
=
getModel
<
BOARD
>
(
PCB_T
);
DIMENSION
*
dimension
=
new
DIMENSION
(
board
);
DIMENSION
*
dimension
=
new
DIMENSION
(
m_board
);
// Init the new item attributes
dimension
->
Text
().
SetSize
(
board
->
GetDesignSettings
().
m_PcbTextSize
);
int
width
=
board
->
GetDesignSettings
().
m_PcbTextWidth
;
dimension
->
Text
().
SetSize
(
m_
board
->
GetDesignSettings
().
m_PcbTextSize
);
int
width
=
m_
board
->
GetDesignSettings
().
m_PcbTextWidth
;
int
maxthickness
=
Clamp_Text_PenSize
(
width
,
dimension
->
Text
().
GetSize
()
);
if
(
width
>
maxthickness
)
...
...
@@ -453,18 +447,18 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
dimension
->
AdjustDimensionDetails
();
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX
::
VIEW_GROUP
preview
(
view
);
view
->
Add
(
&
preview
);
KIGFX
::
VIEW_GROUP
preview
(
m_
view
);
m_
view
->
Add
(
&
preview
);
controls
->
ShowCursor
(
true
);
controls
->
SetSnapping
(
true
);
m_
controls
->
ShowCursor
(
true
);
m_
controls
->
SetSnapping
(
true
);
Activate
();
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
VECTOR2I
cursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_
controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
{
...
...
@@ -491,7 +485,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
{
case
0
:
{
LAYER_NUM
layer
=
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
GetScreen
()
->
m_Active_Layer
;
LAYER_NUM
layer
=
m_frame
->
GetScreen
()
->
m_Active_Layer
;
if
(
IsCopperLayer
(
layer
)
)
{
...
...
@@ -500,7 +494,7 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
}
else
{
controls
->
SetAutoPan
(
true
);
m_
controls
->
SetAutoPan
(
true
);
dimension
->
SetLayer
(
layer
);
dimension
->
SetOrigin
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
...
...
@@ -514,8 +508,8 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
{
if
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
!=
dimension
->
GetPosition
()
)
{
view
->
Add
(
dimension
);
board
->
Add
(
dimension
);
m_
view
->
Add
(
dimension
);
m_
board
->
Add
(
dimension
);
dimension
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
}
...
...
@@ -552,10 +546,10 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
}
}
controls
->
ShowCursor
(
false
);
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
view
->
Remove
(
&
preview
);
m_
controls
->
ShowCursor
(
false
);
m_
controls
->
SetSnapping
(
false
);
m_
controls
->
SetAutoPan
(
false
);
m_
view
->
Remove
(
&
preview
);
setTransitions
();
...
...
@@ -565,20 +559,16 @@ int DRAWING_TOOL::DrawDimension( TOOL_EVENT& aEvent )
int
DRAWING_TOOL
::
DrawZone
(
TOOL_EVENT
&
aEvent
)
{
KIGFX
::
VIEW
*
view
=
getView
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
BOARD
*
board
=
getModel
<
BOARD
>
(
PCB_T
);
ZONE_CONTAINER
*
zone
=
new
ZONE_CONTAINER
(
board
);
PCB_EDIT_FRAME
*
editFrame
=
getEditFrame
<
PCB_EDIT_FRAME
>
();
ZONE_CONTAINER
*
zone
=
new
ZONE_CONTAINER
(
m_board
);
// Get the current, default settings for zones
ZONE_SETTINGS
zoneInfo
=
editF
rame
->
GetZoneSettings
();
ZONE_SETTINGS
zoneInfo
=
m_f
rame
->
GetZoneSettings
();
ZONE_EDIT_T
dialogResult
;
if
(
IsCopperLayer
(
editF
rame
->
GetScreen
()
->
m_Active_Layer
)
)
dialogResult
=
InvokeCopperZonesEditor
(
editF
rame
,
&
zoneInfo
);
if
(
IsCopperLayer
(
m_f
rame
->
GetScreen
()
->
m_Active_Layer
)
)
dialogResult
=
InvokeCopperZonesEditor
(
m_f
rame
,
&
zoneInfo
);
else
dialogResult
=
InvokeNonCopperZonesEditor
(
editF
rame
,
zone
,
&
zoneInfo
);
dialogResult
=
InvokeNonCopperZonesEditor
(
m_f
rame
,
zone
,
&
zoneInfo
);
if
(
dialogResult
==
ZONE_ABORT
)
{
...
...
@@ -588,7 +578,7 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
}
zoneInfo
.
ExportSetting
(
*
zone
);
editF
rame
->
SetTopLayer
(
zoneInfo
.
m_CurrentZone_Layer
);
m_f
rame
->
SetTopLayer
(
zoneInfo
.
m_CurrentZone_Layer
);
DRAWSEGMENT
*
helperLine
=
new
DRAWSEGMENT
;
helperLine
->
SetShape
(
S_SEGMENT
);
...
...
@@ -596,23 +586,23 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
helperLine
->
SetWidth
(
1
);
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX
::
VIEW_GROUP
preview
(
view
);
view
->
Add
(
&
preview
);
KIGFX
::
VIEW_GROUP
preview
(
m_
view
);
m_
view
->
Add
(
&
preview
);
controls
->
ShowCursor
(
true
);
controls
->
SetSnapping
(
true
);
controls
->
SetAutoPan
(
true
);
m_
controls
->
ShowCursor
(
true
);
m_
controls
->
SetSnapping
(
true
);
m_
controls
->
SetAutoPan
(
true
);
Activate
();
VECTOR2I
lastCursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
lastCursorPos
=
m_
controls
->
GetCursorPosition
();
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
// Enable 45 degrees lines only mode by holding shift
bool
linesAngle45
=
evt
->
Modifier
(
MD_SHIFT
);
VECTOR2I
cursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_
controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
{
...
...
@@ -631,10 +621,10 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
zone
->
Outline
()
->
CloseLastContour
();
zone
->
Outline
()
->
RemoveNullSegments
();
board
->
Add
(
zone
);
view
->
Add
(
zone
);
m_
board
->
Add
(
zone
);
m_
view
->
Add
(
zone
);
editF
rame
->
Fill_Zone
(
zone
);
m_f
rame
->
Fill_Zone
(
zone
);
zone
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
else
...
...
@@ -684,7 +674,7 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
// Snap the new line to the grid // TODO fix it, does not work good..
VECTOR2D
newLineEnd
=
VECTOR2D
(
helperLine
->
GetStart
()
)
+
newLineVector
;
VECTOR2D
snapped
=
view
->
GetGAL
()
->
GetGridPoint
(
newLineEnd
);
VECTOR2D
snapped
=
m_
view
->
GetGAL
()
->
GetGridPoint
(
newLineEnd
);
helperLine
->
SetEnd
(
wxPoint
(
snapped
.
x
,
snapped
.
y
)
);
}
...
...
@@ -698,10 +688,10 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
}
}
controls
->
ShowCursor
(
false
);
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
view
->
Remove
(
&
preview
);
m_
controls
->
ShowCursor
(
false
);
m_
controls
->
SetSnapping
(
false
);
m_
controls
->
SetAutoPan
(
false
);
m_
view
->
Remove
(
&
preview
);
// delete helper lines
preview
.
FreeItems
();
...
...
@@ -714,16 +704,12 @@ int DRAWING_TOOL::DrawZone( TOOL_EVENT& aEvent )
int
DRAWING_TOOL
::
DrawKeepout
(
TOOL_EVENT
&
aEvent
)
{
KIGFX
::
VIEW
*
view
=
getView
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
BOARD
*
board
=
getModel
<
BOARD
>
(
PCB_T
);
ZONE_CONTAINER
*
keepout
=
new
ZONE_CONTAINER
(
board
);
PCB_EDIT_FRAME
*
editFrame
=
getEditFrame
<
PCB_EDIT_FRAME
>
();
ZONE_CONTAINER
*
keepout
=
new
ZONE_CONTAINER
(
m_board
);
// Get the current, default settings for zones
ZONE_SETTINGS
zoneInfo
=
editF
rame
->
GetZoneSettings
();
ZONE_SETTINGS
zoneInfo
=
m_f
rame
->
GetZoneSettings
();
ZONE_EDIT_T
dialogResult
=
InvokeKeepoutAreaEditor
(
editF
rame
,
&
zoneInfo
);
ZONE_EDIT_T
dialogResult
=
InvokeKeepoutAreaEditor
(
m_f
rame
,
&
zoneInfo
);
if
(
dialogResult
==
ZONE_ABORT
)
{
delete
keepout
;
...
...
@@ -732,7 +718,7 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
}
zoneInfo
.
ExportSetting
(
*
keepout
);
editF
rame
->
SetTopLayer
(
zoneInfo
.
m_CurrentZone_Layer
);
m_f
rame
->
SetTopLayer
(
zoneInfo
.
m_CurrentZone_Layer
);
DRAWSEGMENT
*
helperLine
=
new
DRAWSEGMENT
;
helperLine
->
SetShape
(
S_SEGMENT
);
...
...
@@ -740,23 +726,23 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
helperLine
->
SetWidth
(
1
);
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX
::
VIEW_GROUP
preview
(
view
);
view
->
Add
(
&
preview
);
KIGFX
::
VIEW_GROUP
preview
(
m_
view
);
m_
view
->
Add
(
&
preview
);
controls
->
ShowCursor
(
true
);
controls
->
SetSnapping
(
true
);
controls
->
SetAutoPan
(
true
);
m_
controls
->
ShowCursor
(
true
);
m_
controls
->
SetSnapping
(
true
);
m_
controls
->
SetAutoPan
(
true
);
Activate
();
VECTOR2I
lastCursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
lastCursorPos
=
m_
controls
->
GetCursorPosition
();
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
// Enable 45 degrees lines only mode by holding shift
bool
linesAngle45
=
evt
->
Modifier
(
MD_SHIFT
);
VECTOR2I
cursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_
controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
{
...
...
@@ -775,8 +761,8 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
keepout
->
Outline
()
->
CloseLastContour
();
keepout
->
Outline
()
->
RemoveNullSegments
();
board
->
Add
(
keepout
);
view
->
Add
(
keepout
);
m_
board
->
Add
(
keepout
);
m_
view
->
Add
(
keepout
);
keepout
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
...
...
@@ -827,7 +813,7 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
// Snap the new line to the grid // TODO fix it, does not work good..
VECTOR2D
newLineEnd
=
VECTOR2D
(
helperLine
->
GetStart
()
)
+
newLineVector
;
VECTOR2D
snapped
=
view
->
GetGAL
()
->
GetGridPoint
(
newLineEnd
);
VECTOR2D
snapped
=
m_
view
->
GetGAL
()
->
GetGridPoint
(
newLineEnd
);
helperLine
->
SetEnd
(
wxPoint
(
snapped
.
x
,
snapped
.
y
)
);
}
...
...
@@ -841,10 +827,10 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
}
}
controls
->
ShowCursor
(
false
);
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
view
->
Remove
(
&
preview
);
m_
controls
->
ShowCursor
(
false
);
m_
controls
->
SetSnapping
(
false
);
m_
controls
->
SetAutoPan
(
false
);
m_
view
->
Remove
(
&
preview
);
// delete helper lines
preview
.
FreeItems
();
...
...
@@ -857,32 +843,29 @@ int DRAWING_TOOL::DrawKeepout( TOOL_EVENT& aEvent )
int
DRAWING_TOOL
::
PlaceTarget
(
TOOL_EVENT
&
aEvent
)
{
KIGFX
::
VIEW
*
view
=
getView
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
BOARD
*
board
=
getModel
<
BOARD
>
(
PCB_T
);
PCB_TARGET
*
target
=
new
PCB_TARGET
(
board
);
PCB_TARGET
*
target
=
new
PCB_TARGET
(
m_board
);
// Init the new item attributes
target
->
SetLayer
(
EDGE_N
);
target
->
SetWidth
(
board
->
GetDesignSettings
().
m_EdgeSegmentWidth
);
target
->
SetWidth
(
m_
board
->
GetDesignSettings
().
m_EdgeSegmentWidth
);
target
->
SetSize
(
Millimeter2iu
(
5
)
);
VECTOR2I
cursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_
controls
->
GetCursorPosition
();
target
->
SetPosition
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX
::
VIEW_GROUP
preview
(
view
);
KIGFX
::
VIEW_GROUP
preview
(
m_
view
);
preview
.
Add
(
target
);
view
->
Add
(
&
preview
);
m_
view
->
Add
(
&
preview
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
controls
->
SetSnapping
(
true
);
m_
controls
->
SetSnapping
(
true
);
Activate
();
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
VECTOR2I
cursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_
controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
{
...
...
@@ -905,8 +888,8 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
else
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
{
view
->
Add
(
target
);
board
->
Add
(
target
);
m_
view
->
Add
(
target
);
m_
board
->
Add
(
target
);
target
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
break
;
}
...
...
@@ -918,9 +901,9 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
}
}
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
view
->
Remove
(
&
preview
);
m_
controls
->
SetSnapping
(
false
);
m_
controls
->
SetAutoPan
(
false
);
m_
view
->
Remove
(
&
preview
);
setTransitions
();
...
...
@@ -930,12 +913,8 @@ int DRAWING_TOOL::PlaceTarget( TOOL_EVENT& aEvent )
int
DRAWING_TOOL
::
PlaceModule
(
TOOL_EVENT
&
aEvent
)
{
KIGFX
::
VIEW
*
view
=
getView
();
KIGFX
::
VIEW_CONTROLS
*
controls
=
getViewControls
();
BOARD
*
board
=
getModel
<
BOARD
>
(
PCB_T
);
PCB_EDIT_FRAME
*
editFrame
=
getEditFrame
<
PCB_EDIT_FRAME
>
();
MODULE
*
module
=
editFrame
->
LoadModuleFromLibrary
(
wxEmptyString
,
editFrame
->
GetFootprintLibraryTable
(),
true
,
NULL
);
MODULE
*
module
=
m_frame
->
LoadModuleFromLibrary
(
wxEmptyString
,
m_frame
->
GetFootprintLibraryTable
(),
true
,
NULL
);
if
(
module
==
NULL
)
{
setTransitions
();
...
...
@@ -943,28 +922,28 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
}
// Init the new item attributes
VECTOR2I
cursorPos
=
controls
->
GetCursorPosition
();
VECTOR2I
cursorPos
=
m_
controls
->
GetCursorPosition
();
module
->
SetPosition
(
wxPoint
(
cursorPos
.
x
,
cursorPos
.
y
)
);
// Add a VIEW_GROUP that serves as a preview for the new item
KIGFX
::
VIEW_GROUP
preview
(
view
);
KIGFX
::
VIEW_GROUP
preview
(
m_
view
);
preview
.
Add
(
module
);
module
->
RunOnChildren
(
std
::
bind1st
(
std
::
mem_fun
(
&
KIGFX
::
VIEW_GROUP
::
Add
),
&
preview
)
);
view
->
Add
(
&
preview
);
m_
view
->
Add
(
&
preview
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
controls
->
SetSnapping
(
true
);
m_
controls
->
SetSnapping
(
true
);
Activate
();
// Main loop: keep receiving events
while
(
OPT_TOOL_EVENT
evt
=
Wait
()
)
{
cursorPos
=
controls
->
GetCursorPosition
();
cursorPos
=
m_
controls
->
GetCursorPosition
();
if
(
evt
->
IsCancel
()
)
{
board
->
Delete
(
module
);
m_
board
->
Delete
(
module
);
break
;
}
...
...
@@ -972,7 +951,7 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
{
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
rotate
)
)
{
module
->
Rotate
(
module
->
GetPosition
(),
getEditFrame
<
PCB_EDIT_FRAME
>
()
->
GetRotationAngle
()
);
module
->
Rotate
(
module
->
GetPosition
(),
m_frame
->
GetRotationAngle
()
);
preview
.
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
}
else
if
(
evt
->
IsAction
(
&
COMMON_ACTIONS
::
flip
)
)
...
...
@@ -984,8 +963,8 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
else
if
(
evt
->
IsClick
(
BUT_LEFT
)
)
{
module
->
RunOnChildren
(
std
::
bind1st
(
std
::
mem_fun
(
&
KIGFX
::
VIEW
::
Add
),
view
)
);
view
->
Add
(
module
);
module
->
RunOnChildren
(
std
::
bind1st
(
std
::
mem_fun
(
&
KIGFX
::
VIEW
::
Add
),
m_
view
)
);
m_
view
->
Add
(
module
);
module
->
ViewUpdate
(
KIGFX
::
VIEW_ITEM
::
GEOMETRY
);
break
;
}
...
...
@@ -997,9 +976,9 @@ int DRAWING_TOOL::PlaceModule( TOOL_EVENT& aEvent )
}
}
controls
->
SetSnapping
(
false
);
controls
->
SetAutoPan
(
false
);
view
->
Remove
(
&
preview
);
m_
controls
->
SetSnapping
(
false
);
m_
controls
->
SetAutoPan
(
false
);
m_
view
->
Remove
(
&
preview
);
setTransitions
();
...
...
pcbnew/tools/drawing_tool.h
View file @
2b62a852
...
...
@@ -26,7 +26,14 @@
#define __DRAWING_TOOL_H
#include <tool/tool_interactive.h>
#include <class_board_item.h>
namespace
KIGFX
{
class
VIEW
;
class
VIEW_CONTROLS
;
}
class
BOARD
;
class
PCB_EDIT_FRAME
;
/**
* Class DRAWING_TOOL
...
...
@@ -69,7 +76,7 @@ public:
private
:
///> Starts drawing a selected shape.
int
draw
(
STROKE_T
aShape
);
int
draw
(
int
aShape
);
///> Sets up handlers for various events.
void
setTransitions
();
...
...
@@ -77,6 +84,11 @@ private:
///> 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
;
PCB_EDIT_FRAME
*
m_frame
;
// How does line width change after one -/+ key press.
static
const
int
WIDTH_STEP
=
100000
;
};
...
...
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